@payloadcms/db-postgres 4.0.0-internal.af6aad0 → 4.0.0-internal.b8e7c89
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/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +5 -0
- package/dist/connect.js.map +1 -1
- package/package.json +5 -5
package/dist/connect.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAa,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAa,MAAM,SAAS,CAAA;AAoDjD,eAAO,MAAM,OAAO,EAAE,OA2FrB,CAAA"}
|
package/dist/connect.js
CHANGED
|
@@ -36,6 +36,11 @@ const connectWithReconnect = async function({ adapter, pool, reconnect = false }
|
|
|
36
36
|
// swallow error
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
|
+
// The client was only checked out to verify connectivity and to attach the
|
|
40
|
+
// listener above, both of which outlive the checkout. Holding on to it pins one
|
|
41
|
+
// connection for the lifetime of the pool, so `pool.end()` can never drain -
|
|
42
|
+
// including after `payload.destroy()`.
|
|
43
|
+
result.release();
|
|
39
44
|
};
|
|
40
45
|
export const connect = async function connect(options = {
|
|
41
46
|
hotReload: false
|
package/dist/connect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { DrizzleAdapter } from '@payloadcms/drizzle'\nimport type { Connect, Migration } from 'payload'\n\nimport { pushDevSchema } from '@payloadcms/drizzle'\nimport { assertOperatorHandlerExtensionsInstalled } from '@payloadcms/drizzle/postgres'\nimport { drizzle } from 'drizzle-orm/node-postgres'\nimport { withReplicas } from 'drizzle-orm/pg-core'\n\nimport type { PostgresAdapter } from './types.js'\n\nconst connectWithReconnect = async function ({\n adapter,\n pool,\n reconnect = false,\n}: {\n adapter: PostgresAdapter\n pool: PostgresAdapter['pool']\n reconnect?: boolean\n}) {\n let result\n\n if (!reconnect) {\n result = await pool.connect()\n } else {\n try {\n result = await pool.connect()\n } catch (ignore) {\n setTimeout(() => {\n adapter.payload.logger.info('Reconnecting to postgres')\n void connectWithReconnect({ adapter, pool, reconnect: true })\n }, 1000)\n }\n }\n if (!result) {\n return\n }\n result.prependListener('error', (err) => {\n try {\n if (err.code === 'ECONNRESET') {\n void connectWithReconnect({ adapter, pool, reconnect: true })\n }\n } catch (ignore) {\n // swallow error\n }\n })\n}\n\nexport const connect: Connect = async function connect(\n this: PostgresAdapter,\n options = {\n hotReload: false,\n },\n) {\n const { hotReload } = options\n\n try {\n if (!this.pool) {\n this.pool = new this.pg.Pool(this.poolOptions)\n await connectWithReconnect({ adapter: this, pool: this.pool })\n }\n\n const logger = this.logger || false\n this.drizzle = drizzle({ client: this.pool, logger, schema: this.schema })\n\n if (this.readReplicaOptions) {\n this.primaryDrizzle = this.drizzle as any\n const readReplicas = this.readReplicaOptions.map((connectionString) => {\n const options = {\n ...this.poolOptions,\n connectionString,\n }\n const pool = new this.pg.Pool(options)\n void connectWithReconnect({\n adapter: this,\n pool,\n })\n return drizzle({ client: pool, logger, schema: this.schema })\n })\n const myReplicas = withReplicas(this.drizzle, readReplicas as any)\n this.drizzle = myReplicas\n }\n\n if (!hotReload) {\n if (process.env.PAYLOAD_DROP_DATABASE === 'true') {\n this.payload.logger.info(`---- DROPPING TABLES SCHEMA(${this.schemaName || 'public'}) ----`)\n await this.dropDatabase({ adapter: this })\n this.payload.logger.info('---- DROPPED TABLES ----')\n }\n }\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error))\n if (err.message?.match(/database .* does not exist/i) && !this.disableCreateDatabase) {\n // capitalize first char of the err msg\n this.payload.logger.info(\n `${err.message.charAt(0).toUpperCase() + err.message.slice(1)}, creating...`,\n )\n const isCreated = await this.createDatabase()\n\n if (isCreated && this.connect) {\n await this.connect(options)\n return\n }\n } else {\n this.payload.logger.error({\n err,\n msg: `Error: cannot connect to Postgres. Details: ${err.message}`,\n })\n }\n\n if (typeof this.rejectInitializing === 'function') {\n this.rejectInitializing()\n }\n throw new Error(`Error: cannot connect to Postgres: ${err.message}`)\n }\n\n await this.createExtensions()\n\n await assertOperatorHandlerExtensionsInstalled({\n drizzle: this.drizzle,\n operatorHandlers: this.operatorHandlers,\n })\n\n // Only push schema if not in production\n if (\n process.env.NODE_ENV !== 'production' &&\n process.env.PAYLOAD_MIGRATING !== 'true' &&\n this.push !== false\n ) {\n await pushDevSchema(this as unknown as DrizzleAdapter)\n }\n\n if (typeof this.resolveInitializing === 'function') {\n this.resolveInitializing()\n }\n\n if (process.env.NODE_ENV === 'production' && this.prodMigrations) {\n await this.migrate({ migrations: this.prodMigrations as unknown as Migration[] })\n }\n}\n"],"names":["pushDevSchema","assertOperatorHandlerExtensionsInstalled","drizzle","withReplicas","connectWithReconnect","adapter","pool","reconnect","result","connect","ignore","setTimeout","payload","logger","info","prependListener","err","code","options","hotReload","pg","Pool","poolOptions","client","schema","readReplicaOptions","primaryDrizzle","readReplicas","map","connectionString","myReplicas","process","env","PAYLOAD_DROP_DATABASE","schemaName","dropDatabase","error","Error","String","message","match","disableCreateDatabase","charAt","toUpperCase","slice","isCreated","createDatabase","msg","rejectInitializing","createExtensions","operatorHandlers","NODE_ENV","PAYLOAD_MIGRATING","push","resolveInitializing","prodMigrations","migrate","migrations"],"mappings":"AAGA,SAASA,aAAa,QAAQ,sBAAqB;AACnD,SAASC,wCAAwC,QAAQ,+BAA8B;AACvF,SAASC,OAAO,QAAQ,4BAA2B;AACnD,SAASC,YAAY,QAAQ,sBAAqB;AAIlD,MAAMC,uBAAuB,eAAgB,EAC3CC,OAAO,EACPC,IAAI,EACJC,YAAY,KAAK,EAKlB;IACC,IAAIC;IAEJ,IAAI,CAACD,WAAW;QACdC,SAAS,MAAMF,KAAKG,OAAO;IAC7B,OAAO;QACL,IAAI;YACFD,SAAS,MAAMF,KAAKG,OAAO;QAC7B,EAAE,OAAOC,QAAQ;YACfC,WAAW;gBACTN,QAAQO,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;gBAC5B,KAAKV,qBAAqB;oBAAEC;oBAASC;oBAAMC,WAAW;gBAAK;YAC7D,GAAG;QACL;IACF;IACA,IAAI,CAACC,QAAQ;QACX;IACF;IACAA,OAAOO,eAAe,CAAC,SAAS,CAACC;QAC/B,IAAI;YACF,IAAIA,IAAIC,IAAI,KAAK,cAAc;gBAC7B,KAAKb,qBAAqB;oBAAEC;oBAASC;oBAAMC,WAAW;gBAAK;YAC7D;QACF,EAAE,OAAOG,QAAQ;QACf,gBAAgB;QAClB;IACF;
|
|
1
|
+
{"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { DrizzleAdapter } from '@payloadcms/drizzle'\nimport type { Connect, Migration } from 'payload'\n\nimport { pushDevSchema } from '@payloadcms/drizzle'\nimport { assertOperatorHandlerExtensionsInstalled } from '@payloadcms/drizzle/postgres'\nimport { drizzle } from 'drizzle-orm/node-postgres'\nimport { withReplicas } from 'drizzle-orm/pg-core'\n\nimport type { PostgresAdapter } from './types.js'\n\nconst connectWithReconnect = async function ({\n adapter,\n pool,\n reconnect = false,\n}: {\n adapter: PostgresAdapter\n pool: PostgresAdapter['pool']\n reconnect?: boolean\n}) {\n let result\n\n if (!reconnect) {\n result = await pool.connect()\n } else {\n try {\n result = await pool.connect()\n } catch (ignore) {\n setTimeout(() => {\n adapter.payload.logger.info('Reconnecting to postgres')\n void connectWithReconnect({ adapter, pool, reconnect: true })\n }, 1000)\n }\n }\n if (!result) {\n return\n }\n result.prependListener('error', (err) => {\n try {\n if (err.code === 'ECONNRESET') {\n void connectWithReconnect({ adapter, pool, reconnect: true })\n }\n } catch (ignore) {\n // swallow error\n }\n })\n\n // The client was only checked out to verify connectivity and to attach the\n // listener above, both of which outlive the checkout. Holding on to it pins one\n // connection for the lifetime of the pool, so `pool.end()` can never drain -\n // including after `payload.destroy()`.\n result.release()\n}\n\nexport const connect: Connect = async function connect(\n this: PostgresAdapter,\n options = {\n hotReload: false,\n },\n) {\n const { hotReload } = options\n\n try {\n if (!this.pool) {\n this.pool = new this.pg.Pool(this.poolOptions)\n await connectWithReconnect({ adapter: this, pool: this.pool })\n }\n\n const logger = this.logger || false\n this.drizzle = drizzle({ client: this.pool, logger, schema: this.schema })\n\n if (this.readReplicaOptions) {\n this.primaryDrizzle = this.drizzle as any\n const readReplicas = this.readReplicaOptions.map((connectionString) => {\n const options = {\n ...this.poolOptions,\n connectionString,\n }\n const pool = new this.pg.Pool(options)\n void connectWithReconnect({\n adapter: this,\n pool,\n })\n return drizzle({ client: pool, logger, schema: this.schema })\n })\n const myReplicas = withReplicas(this.drizzle, readReplicas as any)\n this.drizzle = myReplicas\n }\n\n if (!hotReload) {\n if (process.env.PAYLOAD_DROP_DATABASE === 'true') {\n this.payload.logger.info(`---- DROPPING TABLES SCHEMA(${this.schemaName || 'public'}) ----`)\n await this.dropDatabase({ adapter: this })\n this.payload.logger.info('---- DROPPED TABLES ----')\n }\n }\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error))\n if (err.message?.match(/database .* does not exist/i) && !this.disableCreateDatabase) {\n // capitalize first char of the err msg\n this.payload.logger.info(\n `${err.message.charAt(0).toUpperCase() + err.message.slice(1)}, creating...`,\n )\n const isCreated = await this.createDatabase()\n\n if (isCreated && this.connect) {\n await this.connect(options)\n return\n }\n } else {\n this.payload.logger.error({\n err,\n msg: `Error: cannot connect to Postgres. Details: ${err.message}`,\n })\n }\n\n if (typeof this.rejectInitializing === 'function') {\n this.rejectInitializing()\n }\n throw new Error(`Error: cannot connect to Postgres: ${err.message}`)\n }\n\n await this.createExtensions()\n\n await assertOperatorHandlerExtensionsInstalled({\n drizzle: this.drizzle,\n operatorHandlers: this.operatorHandlers,\n })\n\n // Only push schema if not in production\n if (\n process.env.NODE_ENV !== 'production' &&\n process.env.PAYLOAD_MIGRATING !== 'true' &&\n this.push !== false\n ) {\n await pushDevSchema(this as unknown as DrizzleAdapter)\n }\n\n if (typeof this.resolveInitializing === 'function') {\n this.resolveInitializing()\n }\n\n if (process.env.NODE_ENV === 'production' && this.prodMigrations) {\n await this.migrate({ migrations: this.prodMigrations as unknown as Migration[] })\n }\n}\n"],"names":["pushDevSchema","assertOperatorHandlerExtensionsInstalled","drizzle","withReplicas","connectWithReconnect","adapter","pool","reconnect","result","connect","ignore","setTimeout","payload","logger","info","prependListener","err","code","release","options","hotReload","pg","Pool","poolOptions","client","schema","readReplicaOptions","primaryDrizzle","readReplicas","map","connectionString","myReplicas","process","env","PAYLOAD_DROP_DATABASE","schemaName","dropDatabase","error","Error","String","message","match","disableCreateDatabase","charAt","toUpperCase","slice","isCreated","createDatabase","msg","rejectInitializing","createExtensions","operatorHandlers","NODE_ENV","PAYLOAD_MIGRATING","push","resolveInitializing","prodMigrations","migrate","migrations"],"mappings":"AAGA,SAASA,aAAa,QAAQ,sBAAqB;AACnD,SAASC,wCAAwC,QAAQ,+BAA8B;AACvF,SAASC,OAAO,QAAQ,4BAA2B;AACnD,SAASC,YAAY,QAAQ,sBAAqB;AAIlD,MAAMC,uBAAuB,eAAgB,EAC3CC,OAAO,EACPC,IAAI,EACJC,YAAY,KAAK,EAKlB;IACC,IAAIC;IAEJ,IAAI,CAACD,WAAW;QACdC,SAAS,MAAMF,KAAKG,OAAO;IAC7B,OAAO;QACL,IAAI;YACFD,SAAS,MAAMF,KAAKG,OAAO;QAC7B,EAAE,OAAOC,QAAQ;YACfC,WAAW;gBACTN,QAAQO,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;gBAC5B,KAAKV,qBAAqB;oBAAEC;oBAASC;oBAAMC,WAAW;gBAAK;YAC7D,GAAG;QACL;IACF;IACA,IAAI,CAACC,QAAQ;QACX;IACF;IACAA,OAAOO,eAAe,CAAC,SAAS,CAACC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AAMjD,yCAAyC;QAC7CC,SAAS,IAAI,CAACA,OAAO;QACrBiD,kBAAkB,IAAI,CAACA,gBAAgB;IACzC;IAEA,wCAAwC;IACxC,IACEnB,QAAQC,GAAG,CAACmB,QAAQ,KAAK,gBACzBpB,QAAQC,GAAG,CAACoB,iBAAiB,KAAK,UAClC,IAAI,CAACC,IAAI,KAAK,OACd;QACA,MAAMtD,cAAc,IAAI;IAC1B;IAEA,IAAI,OAAO,IAAI,CAACuD,mBAAmB,KAAK,YAAY;QAClD,IAAI,CAACA,mBAAmB;IAC1B;IAEA,IAAIvB,QAAQC,GAAG,CAACmB,QAAQ,KAAK,gBAAgB,IAAI,CAACI,cAAc,EAAE;QAChE,MAAM,IAAI,CAACC,OAAO,CAAC;YAAEC,YAAY,IAAI,CAACF,cAAc;QAA2B;IACjF;AACF,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/db-postgres",
|
|
3
|
-
"version": "4.0.0-internal.
|
|
3
|
+
"version": "4.0.0-internal.b8e7c89",
|
|
4
4
|
"description": "The officially supported Postgres database adapter for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -66,17 +66,17 @@
|
|
|
66
66
|
"prompts": "2.4.2",
|
|
67
67
|
"to-snake-case": "1.0.0",
|
|
68
68
|
"uuid": "14.0.0",
|
|
69
|
-
"@payloadcms/drizzle": "4.0.0-internal.
|
|
69
|
+
"@payloadcms/drizzle": "4.0.0-internal.b8e7c89"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@hyrious/esbuild-plugin-commonjs": "0.2.6",
|
|
73
73
|
"@types/to-snake-case": "1.0.0",
|
|
74
74
|
"esbuild": "0.27.1",
|
|
75
|
-
"
|
|
76
|
-
"
|
|
75
|
+
"payload": "4.0.0-internal.b8e7c89",
|
|
76
|
+
"@payloadcms/eslint-config": "3.28.0"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
|
-
"payload": "4.0.0-internal.
|
|
79
|
+
"payload": "4.0.0-internal.b8e7c89"
|
|
80
80
|
},
|
|
81
81
|
"scripts": {
|
|
82
82
|
"build": "rimraf .dist && rimraf tsconfig.tsbuildinfo && pnpm build:types && pnpm build:swc && pnpm build:esbuild && pnpm renamePredefinedMigrations",
|