@payloadcms/db-postgres 3.65.0-canary.4 → 3.65.0-canary.5

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.js CHANGED
@@ -102,7 +102,7 @@ export const connect = async function connect(options = {
102
102
  if (typeof this.rejectInitializing === 'function') {
103
103
  this.rejectInitializing();
104
104
  }
105
- process.exit(1);
105
+ throw new Error(`Error: cannot connect to Postgres: ${err.message}`);
106
106
  }
107
107
  await this.createExtensions();
108
108
  // Only push schema if not in production
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { DrizzleAdapter } from '@payloadcms/drizzle/types'\nimport type { Connect, Migration } from 'payload'\n\nimport { pushDevSchema } from '@payloadcms/drizzle'\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 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 process.exit(1)\n }\n\n await this.createExtensions()\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","drizzle","withReplicas","connectWithReconnect","adapter","pool","reconnect","result","connect","ignore","setTimeout","payload","logger","info","prependListener","err","code","options","hotReload","pg","Pool","poolOptions","client","schema","readReplicaOptions","readReplicas","map","connectionString","myReplicas","process","env","PAYLOAD_DROP_DATABASE","schemaName","dropDatabase","error","Error","String","message","match","disableCreateDatabase","charAt","toUpperCase","slice","isCreated","createDatabase","msg","rejectInitializing","exit","createExtensions","NODE_ENV","PAYLOAD_MIGRATING","push","resolveInitializing","prodMigrations","migrate","migrations"],"mappings":"AAGA,SAASA,aAAa,QAAQ,sBAAqB;AACnD,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;AACF;AAEA,OAAO,MAAMD,UAAmB,eAAeA,QAE7CS,UAAU;IACRC,WAAW;AACb,CAAC;IAED,MAAM,EAAEA,SAAS,EAAE,GAAGD;IAEtB,IAAI;QACF,IAAI,CAAC,IAAI,CAACZ,IAAI,EAAE;YACd,IAAI,CAACA,IAAI,GAAG,IAAI,IAAI,CAACc,EAAE,CAACC,IAAI,CAAC,IAAI,CAACC,WAAW;YAC7C,MAAMlB,qBAAqB;gBAAEC,SAAS,IAAI;gBAAEC,MAAM,IAAI,CAACA,IAAI;YAAC;QAC9D;QAEA,MAAMO,SAAS,IAAI,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AC,GAAGC,WAAW,KAAK1B,IAAIsB,OAAO,CAACK,KAAK,CAAC,GAAG,aAAa,CAAC;YAE9E,MAAMC,YAAY,MAAM,IAAI,CAACC,cAAc;YAE3C,IAAID,aAAa,IAAI,CAACnC,OAAO,EAAE;gBAC7B,MAAM,IAAI,CAACA,OAAO,CAACS;gBACnB;YACF;QACF,OAAO;YACL,IAAI,CAACN,OAAO,CAACC,MAAM,CAACsB,KAAK,CAAC;gBACxBnB;gBACA8B,KAAK,CAAC,4CAA4C,EAAE9B,IAAIsB,OAAO,EAAE;YACnE;QACF;QAEA,IAAI,OAAO,IAAI,CAACS,kBAAkB,KAAK,YAAY;YACjD,IAAI,CAACA,kBAAkB;QACzB;QACAjB,QAAQkB,IAAI,CAAC;IACf;IAEA,MAAM,IAAI,CAACC,gBAAgB;IAE3B,wCAAwC;IACxC,IACEnB,QAAQC,GAAG,CAACmB,QAAQ,KAAK,gBACzBpB,QAAQC,GAAG,CAACoB,iBAAiB,KAAK,UAClC,IAAI,CAACC,IAAI,KAAK,OACd;QACA,MAAMnD,cAAc,IAAI;IAC1B;IAEA,IAAI,OAAO,IAAI,CAACoD,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"}
1
+ {"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { DrizzleAdapter } from '@payloadcms/drizzle/types'\nimport type { Connect, Migration } from 'payload'\n\nimport { pushDevSchema } from '@payloadcms/drizzle'\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 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 // 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","drizzle","withReplicas","connectWithReconnect","adapter","pool","reconnect","result","connect","ignore","setTimeout","payload","logger","info","prependListener","err","code","options","hotReload","pg","Pool","poolOptions","client","schema","readReplicaOptions","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","NODE_ENV","PAYLOAD_MIGRATING","push","resolveInitializing","prodMigrations","migrate","migrations"],"mappings":"AAGA,SAASA,aAAa,QAAQ,sBAAqB;AACnD,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;IAC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QC,GAAG,CAACmB,iBAAiB,KAAK,UAClC,IAAI,CAACC,IAAI,KAAK,OACd;QACA,MAAMlD,cAAc,IAAI;IAC1B;IAEA,IAAI,OAAO,IAAI,CAACmD,mBAAmB,KAAK,YAAY;QAClD,IAAI,CAACA,mBAAmB;IAC1B;IAEA,IAAItB,QAAQC,GAAG,CAACkB,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": "3.65.0-canary.4",
3
+ "version": "3.65.0-canary.5",
4
4
  "description": "The officially supported Postgres database adapter for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -71,17 +71,17 @@
71
71
  "prompts": "2.4.2",
72
72
  "to-snake-case": "1.0.0",
73
73
  "uuid": "10.0.0",
74
- "@payloadcms/drizzle": "3.65.0-canary.4"
74
+ "@payloadcms/drizzle": "3.65.0-canary.5"
75
75
  },
76
76
  "devDependencies": {
77
77
  "@hyrious/esbuild-plugin-commonjs": "0.2.6",
78
78
  "@types/to-snake-case": "1.0.0",
79
79
  "esbuild": "0.25.5",
80
80
  "@payloadcms/eslint-config": "3.28.0",
81
- "payload": "3.65.0-canary.4"
81
+ "payload": "3.65.0-canary.5"
82
82
  },
83
83
  "peerDependencies": {
84
- "payload": "3.65.0-canary.4"
84
+ "payload": "3.65.0-canary.5"
85
85
  },
86
86
  "scripts": {
87
87
  "build": "rimraf .dist && rimraf tsconfig.tsbuildinfo && pnpm build:types && pnpm build:swc && pnpm build:esbuild && pnpm renamePredefinedMigrations",