@webiny/api-storage-pg 6.6.0-alpha.12 → 6.6.0-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/createPgConnection.d.ts +1 -1
- package/createPgConnection.js.map +1 -1
- package/package.json +12 -12
package/createPgConnection.d.ts
CHANGED
|
@@ -22,6 +22,6 @@ export interface CreatePgConnectionOptions {
|
|
|
22
22
|
* env vars `<Infra.Postgres>` sets, with explicit options taking precedence. A connection string
|
|
23
23
|
* (`WEBINY_PG_CONNECTION_STRING` or `options.connection.connectionString`) is enough on its own:
|
|
24
24
|
* node-postgres reads host, port, user, password and database from it. On AWS Lambda, use
|
|
25
|
-
* `createLambdaPgConnection` (`@webiny/api-
|
|
25
|
+
* `createLambdaPgConnection` (`@webiny/api-composition-aws-pg`) instead.
|
|
26
26
|
*/
|
|
27
27
|
export declare function createPgConnection(options?: CreatePgConnectionOptions): Knex;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPgConnection.js","sources":["../src/createPgConnection.ts"],"sourcesContent":["import knex, { type Knex } from \"knex\";\nimport { withPgConnectionRetry } from \"@webiny/api-core-sql\";\nimport { DEFAULT_PG_RETRY_MS, readPgConnectionEnv } from \"./readPgConnectionEnv.js\";\nimport { applyToPgConnectionString } from \"./applyToPgConnectionString.js\";\n\nconst definedOnly = <T extends Record<string, unknown>>(values: T): Partial<T> => {\n return Object.fromEntries(Object.entries(values).filter(([, value]) => !!value)) as Partial<T>;\n};\n\nconst assertSet = (value: unknown, message: string): void => {\n if (!value) {\n throw new Error(message);\n }\n};\n\nexport interface CreatePgConnectionOptions {\n host?: string;\n port?: number;\n user?: string;\n password?: string;\n database?: string;\n /**\n * Optional additional Knex connection config (SSL, pool size, etc.).\n * Overrides values from env vars when both are set.\n */\n connection?: Partial<Knex.PgConnectionConfig>;\n /**\n * How long to retry a read or transaction that lost its connection (failover, restart), in\n * milliseconds; 0 turns retries off. Default: `WEBINY_PG_RETRY_MS`, else 15,000.\n */\n retryMs?: number;\n}\n\n/**\n * A Knex client for Postgres, for a long-running process (the standalone server): Postgres, PGlite\n * (`<Infra.Pglite>`) or Aurora from a server. Connection parameters are read from the `WEBINY_PG_*`\n * env vars `<Infra.Postgres>` sets, with explicit options taking precedence. A connection string\n * (`WEBINY_PG_CONNECTION_STRING` or `options.connection.connectionString`) is enough on its own:\n * node-postgres reads host, port, user, password and database from it. On AWS Lambda, use\n * `createLambdaPgConnection` (`@webiny/api-
|
|
1
|
+
{"version":3,"file":"createPgConnection.js","sources":["../src/createPgConnection.ts"],"sourcesContent":["import knex, { type Knex } from \"knex\";\nimport { withPgConnectionRetry } from \"@webiny/api-core-sql\";\nimport { DEFAULT_PG_RETRY_MS, readPgConnectionEnv } from \"./readPgConnectionEnv.js\";\nimport { applyToPgConnectionString } from \"./applyToPgConnectionString.js\";\n\nconst definedOnly = <T extends Record<string, unknown>>(values: T): Partial<T> => {\n return Object.fromEntries(Object.entries(values).filter(([, value]) => !!value)) as Partial<T>;\n};\n\nconst assertSet = (value: unknown, message: string): void => {\n if (!value) {\n throw new Error(message);\n }\n};\n\nexport interface CreatePgConnectionOptions {\n host?: string;\n port?: number;\n user?: string;\n password?: string;\n database?: string;\n /**\n * Optional additional Knex connection config (SSL, pool size, etc.).\n * Overrides values from env vars when both are set.\n */\n connection?: Partial<Knex.PgConnectionConfig>;\n /**\n * How long to retry a read or transaction that lost its connection (failover, restart), in\n * milliseconds; 0 turns retries off. Default: `WEBINY_PG_RETRY_MS`, else 15,000.\n */\n retryMs?: number;\n}\n\n/**\n * A Knex client for Postgres, for a long-running process (the standalone server): Postgres, PGlite\n * (`<Infra.Pglite>`) or Aurora from a server. Connection parameters are read from the `WEBINY_PG_*`\n * env vars `<Infra.Postgres>` sets, with explicit options taking precedence. A connection string\n * (`WEBINY_PG_CONNECTION_STRING` or `options.connection.connectionString`) is enough on its own:\n * node-postgres reads host, port, user, password and database from it. On AWS Lambda, use\n * `createLambdaPgConnection` (`@webiny/api-composition-aws-pg`) instead.\n */\nexport function createPgConnection(options: CreatePgConnectionOptions = {}): Knex {\n const env = readPgConnectionEnv();\n const explicitConnection = options.connection || {};\n // The connection parts the caller set: the options, then `options.connection`.\n const explicit = {\n ...definedOnly({\n host: options.host,\n port: options.port,\n user: options.user,\n password: options.password,\n database: options.database\n }),\n ...definedOnly({\n host: explicitConnection.host,\n port: explicitConnection.port,\n user: explicitConnection.user,\n // A password function can't go into a connection string.\n password:\n typeof explicitConnection.password === \"string\"\n ? explicitConnection.password\n : undefined,\n database: explicitConnection.database\n })\n };\n // Env first, then the explicit options, then `options.connection`: validated as Knex gets it.\n const connectionConfig: Knex.PgConnectionConfig = {\n ...env.connection,\n ...explicit,\n ...explicitConnection\n };\n // node-postgres reads a connection string over the separate parts, so the parts the caller set\n // go into the string too (the env's own parts don't: the string is the env's whole connection).\n if (connectionConfig.connectionString && Object.keys(explicit).length > 0) {\n connectionConfig.connectionString = applyToPgConnectionString(\n connectionConfig.connectionString,\n explicit\n );\n }\n\n // A connection string holds the whole connection; otherwise each part must be set.\n if (!connectionConfig.connectionString) {\n assertSet(\n connectionConfig.host,\n 'Postgres host is not set. Configure via <Infra.Postgres host=\"...\" /> in webiny.config.'\n );\n assertSet(\n connectionConfig.port,\n \"Postgres port is not set. Configure via <Infra.Postgres port={...} /> in webiny.config.\"\n );\n assertSet(\n connectionConfig.user,\n 'Postgres user is not set. Configure via <Infra.Postgres user=\"...\" /> in webiny.config.'\n );\n assertSet(\n connectionConfig.password,\n 'Postgres password is not set. Configure via <Infra.Postgres password=\"...\" /> in webiny.config.'\n );\n assertSet(\n connectionConfig.database,\n 'Postgres database is not set. Configure via <Infra.Postgres database=\"...\" /> in webiny.config.'\n );\n }\n\n const poolMax = env.poolMax;\n\n const client = knex({\n client: \"pg\",\n connection: connectionConfig,\n // knex's default minimum (2) must not exceed the maximum.\n ...(poolMax !== undefined ? { pool: { min: Math.min(2, poolMax), max: poolMax } } : {})\n });\n\n // Reads and transactions that lose their connection run again on a new one (see\n // withPgConnectionRetry); writes outside a transaction are not retried.\n const retryMs = options.retryMs ?? env.retryMs ?? DEFAULT_PG_RETRY_MS;\n if (retryMs > 0) {\n withPgConnectionRetry(client, { maxRetryMs: retryMs });\n }\n return client;\n}\n"],"names":["definedOnly","values","Object","value","assertSet","message","Error","createPgConnection","options","env","readPgConnectionEnv","explicitConnection","explicit","undefined","connectionConfig","applyToPgConnectionString","poolMax","client","knex","Math","retryMs","DEFAULT_PG_RETRY_MS","withPgConnectionRetry"],"mappings":";;;;AAKA,MAAMA,cAAc,CAAoCC,SAC7CC,OAAO,WAAW,CAACA,OAAO,OAAO,CAACD,QAAQ,MAAM,CAAC,CAAC,GAAGE,MAAM,GAAK,CAAC,CAACA;AAG7E,MAAMC,YAAY,CAACD,OAAgBE;IAC/B,IAAI,CAACF,OACD,MAAM,IAAIG,MAAMD;AAExB;AA4BO,SAASE,mBAAmBC,UAAqC,CAAC,CAAC;IACtE,MAAMC,MAAMC;IACZ,MAAMC,qBAAqBH,QAAQ,UAAU,IAAI,CAAC;IAElD,MAAMI,WAAW;QACb,GAAGZ,YAAY;YACX,MAAMQ,QAAQ,IAAI;YAClB,MAAMA,QAAQ,IAAI;YAClB,MAAMA,QAAQ,IAAI;YAClB,UAAUA,QAAQ,QAAQ;YAC1B,UAAUA,QAAQ,QAAQ;QAC9B,EAAE;QACF,GAAGR,YAAY;YACX,MAAMW,mBAAmB,IAAI;YAC7B,MAAMA,mBAAmB,IAAI;YAC7B,MAAMA,mBAAmB,IAAI;YAE7B,UACI,AAAuC,YAAvC,OAAOA,mBAAmB,QAAQ,GAC5BA,mBAAmB,QAAQ,GAC3BE;YACV,UAAUF,mBAAmB,QAAQ;QACzC,EAAE;IACN;IAEA,MAAMG,mBAA4C;QAC9C,GAAGL,IAAI,UAAU;QACjB,GAAGG,QAAQ;QACX,GAAGD,kBAAkB;IACzB;IAGA,IAAIG,iBAAiB,gBAAgB,IAAIZ,OAAO,IAAI,CAACU,UAAU,MAAM,GAAG,GACpEE,iBAAiB,gBAAgB,GAAGC,0BAChCD,iBAAiB,gBAAgB,EACjCF;IAKR,IAAI,CAACE,iBAAiB,gBAAgB,EAAE;QACpCV,UACIU,iBAAiB,IAAI,EACrB;QAEJV,UACIU,iBAAiB,IAAI,EACrB;QAEJV,UACIU,iBAAiB,IAAI,EACrB;QAEJV,UACIU,iBAAiB,QAAQ,EACzB;QAEJV,UACIU,iBAAiB,QAAQ,EACzB;IAER;IAEA,MAAME,UAAUP,IAAI,OAAO;IAE3B,MAAMQ,SAASC,KAAK;QAChB,QAAQ;QACR,YAAYJ;QAEZ,GAAIE,AAAYH,WAAZG,UAAwB;YAAE,MAAM;gBAAE,KAAKG,KAAK,GAAG,CAAC,GAAGH;gBAAU,KAAKA;YAAQ;QAAE,IAAI,CAAC,CAAC;IAC1F;IAIA,MAAMI,UAAUZ,QAAQ,OAAO,IAAIC,IAAI,OAAO,IAAIY;IAClD,IAAID,UAAU,GACVE,sBAAsBL,QAAQ;QAAE,YAAYG;IAAQ;IAExD,OAAOH;AACX"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-storage-pg",
|
|
3
|
-
"version": "6.6.0-alpha.
|
|
3
|
+
"version": "6.6.0-alpha.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"exports": {
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
],
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@webiny/api-audit-logs-sql": "6.6.0-alpha.
|
|
22
|
-
"@webiny/api-core": "6.6.0-alpha.
|
|
23
|
-
"@webiny/api-core-sql": "6.6.0-alpha.
|
|
24
|
-
"@webiny/api-websockets-sql": "6.6.0-alpha.
|
|
21
|
+
"@webiny/api-audit-logs-sql": "6.6.0-alpha.13",
|
|
22
|
+
"@webiny/api-core": "6.6.0-alpha.13",
|
|
23
|
+
"@webiny/api-core-sql": "6.6.0-alpha.13",
|
|
24
|
+
"@webiny/api-websockets-sql": "6.6.0-alpha.13",
|
|
25
25
|
"@webiny/stdlib": "0.0.21",
|
|
26
26
|
"knex": "3.3.0",
|
|
27
27
|
"pg": "8.23.1"
|
|
@@ -30,15 +30,15 @@
|
|
|
30
30
|
"@webiny/di": "^2.0.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@electric-sql/pglite": "0.5.
|
|
34
|
-
"@electric-sql/pglite-socket": "0.2.
|
|
35
|
-
"@webiny/api-audit-logs": "6.6.0-alpha.
|
|
36
|
-
"@webiny/api-websockets": "6.6.0-alpha.
|
|
37
|
-
"@webiny/build-tools": "6.6.0-alpha.
|
|
33
|
+
"@electric-sql/pglite": "0.5.17",
|
|
34
|
+
"@electric-sql/pglite-socket": "0.2.20",
|
|
35
|
+
"@webiny/api-audit-logs": "6.6.0-alpha.13",
|
|
36
|
+
"@webiny/api-websockets": "6.6.0-alpha.13",
|
|
37
|
+
"@webiny/build-tools": "6.6.0-alpha.13",
|
|
38
38
|
"@webiny/di": "2.0.0",
|
|
39
|
-
"rimraf": "6.1.
|
|
39
|
+
"rimraf": "6.1.4",
|
|
40
40
|
"typescript": "7.0.2",
|
|
41
|
-
"vitest": "5.
|
|
41
|
+
"vitest": "5.1.1"
|
|
42
42
|
},
|
|
43
43
|
"adio": {
|
|
44
44
|
"ignore": {
|