Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

get-db

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-db - npm Package Compare versions

Comparing version
0.10.0
to
0.11.0
+4
-4
dist/lib/utils/fs.js

@@ -53,6 +53,6 @@ import { messages } from "../texts.js";

const openedFile = openSync(dotEnvFile, "a");
writeSync(openedFile, `# Claimable DB expires at: ${claimExpiresAt.toUTCString()}
# Claim it now to your account: ${claimUrl.href}
${dotEnvKey}=${connString}
${dotEnvKey}_POOLER=${poolerString}
writeSync(openedFile, `${dotEnvKey}=${poolerString}
${dotEnvKey}_DIRECT=${connString}
# Claimable DB expires at: ${claimExpiresAt.toUTCString()}
# Claim it now to your account using the link below:
${envPrefix}INSTAGRES_CLAIM_URL=${claimUrl.href}

@@ -59,0 +59,0 @@ `);

@@ -1,1 +0,1 @@

{"version":3,"file":"fs.js","names":[],"sources":["../../../src/lib/utils/fs.ts"],"sourcesContent":["import {\n\tcloseSync,\n\texistsSync,\n\tmkdirSync,\n\topenSync,\n\treadFileSync,\n\twriteSync,\n} from \"node:fs\";\nimport { dirname } from \"node:path\";\nimport { log, outro } from \"@clack/prompts\";\nimport { parse } from \"dotenv\";\nimport { messages } from \"../texts.js\";\n\nfunction splitCommands(schema: string) {\n\treturn schema\n\t\t.split(\";\")\n\t\t.map((cmd) => cmd.trim())\n\t\t.filter(Boolean);\n}\n\nfunction validateSql(sql: string) {\n\tconst openParens = (sql.match(/\\(/g) || []).length;\n\tconst closeParens = (sql.match(/\\)/g) || []).length;\n\tif (openParens !== closeParens) {\n\t\tthrow new Error(\"SQL has unbalanced parentheses\");\n\t}\n\n\treturn sql;\n}\n\nexport function getSqlCommands(path: string) {\n\ttry {\n\t\tconst sql = validateSql(readFileSync(path, \"utf8\"));\n\t\treturn splitCommands(sql);\n\t} catch (error) {\n\t\tlog.error(\n\t\t\terror instanceof Error ? error.message : \"Failed to read SQL file.\",\n\t\t);\n\t\tprocess.exit(1);\n\t}\n}\n\nexport function getDotEnvContent(dotEnvFile: string): Record<string, string> {\n\tif (!existsSync(dotEnvFile)) {\n\t\tlog.info(messages.info.dotEnvFileNotFound);\n\t\treturn {};\n\t}\n\n\ttry {\n\t\tconst content = readFileSync(dotEnvFile);\n\t\treturn parse(content);\n\t} catch {\n\t\tthrow new Error(messages.errors.failedToParseEnvFile);\n\t}\n}\n\nexport function prepEnv(dotEnvFile: string, dotEnvKey: string) {\n\ttry {\n\t\tconst dotEnvContent = getDotEnvContent(dotEnvFile);\n\n\t\tif (dotEnvContent[dotEnvKey]) {\n\t\t\tlog.warn(messages.errors.envKeyExists(dotEnvKey, dotEnvFile));\n\t\t\toutro(messages.envKeyExistsExit);\n\t\t\tprocess.exit(0);\n\t\t}\n\n\t\treturn;\n\t} catch (error) {\n\t\t// getDotEnvContent will create empty file if it doesn't exist\n\t\t// or throw if parsing fails\n\t\tif (\n\t\t\terror instanceof Error &&\n\t\t\terror.message === messages.errors.failedToParseEnvFile\n\t\t) {\n\t\t\tconsole.error(error);\n\t\t\tlog.error(messages.errors.invalidEnvFile);\n\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n}\n\nexport async function writeToEnv(\n\tdotEnvFile: string,\n\tdotEnvKey: string,\n\tclaimExpiresAt: Date,\n\tclaimUrl: URL,\n\tconnString: string,\n\tpoolerString: string,\n\tenvPrefix: string = \"PUBLIC_\",\n) {\n\tif (!existsSync(dirname(dotEnvFile))) {\n\t\tmkdirSync(dirname(dotEnvFile), { recursive: true });\n\t}\n\n\tconst openedFile = openSync(dotEnvFile, \"a\");\n\twriteSync(\n\t\topenedFile,\n\t\t`# Claimable DB expires at: ${claimExpiresAt.toUTCString()}\n# Claim it now to your account: ${claimUrl.href}\n${dotEnvKey}=${connString}\n${dotEnvKey}_POOLER=${poolerString}\n${envPrefix}INSTA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,CACnC,WAAU,QAAQ,WAAW,EAAE,EAAE,WAAW,MAAM,CAAC;CAGpD,MAAM,aAAa,SAAS,YAAY,IAAI;AAC5C,WACC,YACA,8BAA8B,eAAe,aAAa,CAAC;kCAC3B,SAAS,KAAK;EAC9C,UAAU,GAAG,WAAW;EACxB,UAAU,UAAU,aAAa;EACjC,UAAU,sBAAsB,SAAS,KAAK;EAE9C;AACD,WAAU,WAAW"}
{"version":3,"file":"fs.js","names":[],"sources":["../../../src/lib/utils/fs.ts"],"sourcesContent":["import {\n\tcloseSync,\n\texistsSync,\n\tmkdirSync,\n\topenSync,\n\treadFileSync,\n\twriteSync,\n} from \"node:fs\";\nimport { dirname } from \"node:path\";\nimport { log, outro } from \"@clack/prompts\";\nimport { parse } from \"dotenv\";\nimport { messages } from \"../texts.js\";\n\nfunction splitCommands(schema: string) {\n\treturn schema\n\t\t.split(\";\")\n\t\t.map((cmd) => cmd.trim())\n\t\t.filter(Boolean);\n}\n\nfunction validateSql(sql: string) {\n\tconst openParens = (sql.match(/\\(/g) || []).length;\n\tconst closeParens = (sql.match(/\\)/g) || []).length;\n\tif (openParens !== closeParens) {\n\t\tthrow new Error(\"SQL has unbalanced parentheses\");\n\t}\n\n\treturn sql;\n}\n\nexport function getSqlCommands(path: string) {\n\ttry {\n\t\tconst sql = validateSql(readFileSync(path, \"utf8\"));\n\t\treturn splitCommands(sql);\n\t} catch (error) {\n\t\tlog.error(\n\t\t\terror instanceof Error ? error.message : \"Failed to read SQL file.\",\n\t\t);\n\t\tprocess.exit(1);\n\t}\n}\n\nexport function getDotEnvContent(dotEnvFile: string): Record<string, string> {\n\tif (!existsSync(dotEnvFile)) {\n\t\tlog.info(messages.info.dotEnvFileNotFound);\n\t\treturn {};\n\t}\n\n\ttry {\n\t\tconst content = readFileSync(dotEnvFile);\n\t\treturn parse(content);\n\t} catch {\n\t\tthrow new Error(messages.errors.failedToParseEnvFile);\n\t}\n}\n\nexport function prepEnv(dotEnvFile: string, dotEnvKey: string) {\n\ttry {\n\t\tconst dotEnvContent = getDotEnvContent(dotEnvFile);\n\n\t\tif (dotEnvContent[dotEnvKey]) {\n\t\t\tlog.warn(messages.errors.envKeyExists(dotEnvKey, dotEnvFile));\n\t\t\toutro(messages.envKeyExistsExit);\n\t\t\tprocess.exit(0);\n\t\t}\n\n\t\treturn;\n\t} catch (error) {\n\t\t// getDotEnvContent will create empty file if it doesn't exist\n\t\t// or throw if parsing fails\n\t\tif (\n\t\t\terror instanceof Error &&\n\t\t\terror.message === messages.errors.failedToParseEnvFile\n\t\t) {\n\t\t\tconsole.error(error);\n\t\t\tlog.error(messages.errors.invalidEnvFile);\n\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n}\n\nexport async function writeToEnv(\n\tdotEnvFile: string,\n\tdotEnvKey: string,\n\tclaimExpiresAt: Date,\n\tclaimUrl: URL,\n\tconnString: string,\n\tpoolerString: string,\n\tenvPrefix: string = \"PUBLIC_\",\n) {\n\tif (!existsSync(dirname(dotEnvFile))) {\n\t\tmkdirSync(dirname(dotEnvFile), { recursive: true });\n\t}\n\n\tconst openedFile = openSync(dotEnvFile, \"a\");\n\twriteSync(\n\t\topenedFile,\n\t\t`${dotEnvKey}=${poolerString}\n${dotEnvKey}_DIRECT=${connString}\n# Claimable DB expires at: ${claimExpiresAt.toUTCString()}\n# Claim it now to your account using the link below:\n${envPrefix}INSTAGRES_CLAIM_URL=${claimUrl.href}\n`,\n\t);\n\tcloseSync(openedFile);\n}\n"],"mappings":";;;;;;;AAaA,SAAS,cAAc,QAAgB;AACtC,QAAO,OACL,MAAM,IAAI,CACV,KAAK,QAAQ,IAAI,MAAM,CAAC,CACxB,OAAO,QAAQ;;AAGlB,SAAS,YAAY,KAAa;AAGjC,MAFoB,IAAI,MAAM,MAAM,IAAI,EAAE,EAAE,YACvB,IAAI,MAAM,MAAM,IAAI,EAAE,EAAE,OAE5C,OAAM,IAAI,MAAM,iCAAiC;AAGlD,QAAO;;AAGR,SAAgB,eAAe,MAAc;AAC5C,KAAI;AAEH,SAAO,cADK,YAAY,aAAa,MAAM,OAAO,CAAC,CAC1B;UACjB,OAAO;AACf,MAAI,MACH,iBAAiB,QAAQ,MAAM,UAAU,2BACzC;AACD,UAAQ,KAAK,EAAE;;;AAIjB,SAAgB,iBAAiB,YAA4C;AAC5E,KAAI,CAAC,WAAW,WAAW,EAAE;AAC5B,MAAI,KAAK,SAAS,KAAK,mBAAmB;AAC1C,SAAO,EAAE;;AAGV,KAAI;AAEH,SAAO,MADS,aAAa,WAAW,CACnB;SACd;AACP,QAAM,IAAI,MAAM,SAAS,OAAO,qBAAqB;;;AAIvD,SAAgB,QAAQ,YAAoB,WAAmB;AAC9D,KAAI;AAGH,MAFsB,iBAAiB,WAAW,CAEhC,YAAY;AAC7B,OAAI,KAAK,SAAS,OAAO,aAAa,WAAW,WAAW,CAAC;AAC7D,SAAM,SAAS,iBAAiB;AAChC,WAAQ,KAAK,EAAE;;AAGhB;UACQ,OAAO;AAGf,MACC,iBAAiB,SACjB,MAAM,YAAY,SAAS,OAAO,sBACjC;AACD,WAAQ,MAAM,MAAM;AACpB,OAAI,MAAM,SAAS,OAAO,eAAe;AAEzC,WAAQ,KAAK,EAAE;;;;AAKlB,eAAsB,WACrB,YACA,WACA,gBACA,UACA,YACA,cACA,YAAoB,WACnB;AACD,KAAI,CAAC,WAAW,QAAQ,WAAW,CAAC,CACnC,WAAU,QAAQ,WAAW,EAAE,EAAE,WAAW,MAAM,CAAC;CAGpD,MAAM,aAAa,SAAS,YAAY,IAAI;AAC5C,WACC,YACA,GAAG,UAAU,GAAG,aAAa;EAC7B,UAAU,UAAU,WAAW;6BACJ,eAAe,aAAa,CAAC;;EAExD,UAAU,sBAAsB,SAAS,KAAK;EAE9C;AACD,WAAU,WAAW"}
{
"name": "get-db",
"version": "0.10.0",
"version": "0.11.0",
"description": "create a claimable Neon database in seconds!",

@@ -55,3 +55,3 @@ "keywords": [

"engines": {
"node": ">=20.19.0"
"node": "22"
},

@@ -58,0 +58,0 @@ "publishConfig": {

@@ -73,2 +73,14 @@ <h1 align="center">get-db</h1>

### Environment Variables Written
When you run `get-db`, the following environment variables are written to your `.env` file:
| Variable | Description |
| ---------------------------------- | ---------------------------------------------------------- |
| `DATABASE_URL` | The **pooler** connection string (default connection) |
| `DATABASE_URL_DIRECT` | The direct connection string |
| `{envPrefix}INSTAGRES_CLAIM_URL` | Claim URL (valid for 7 days) to take ownership of the DB |
> **Note:** The pooler connection is now the default for `DATABASE_URL` (as of the latest version). The pooler provides connection pooling and is recommended for most use cases, especially serverless environments.
---

@@ -75,0 +87,0 @@