@payloadcms/db-postgres 3.0.0-alpha.41 → 3.0.0-alpha.43
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/connect.js +1 -1
- package/dist/connect.js.map +1 -0
- package/dist/create.js +1 -1
- package/dist/create.js.map +1 -0
- package/dist/createGlobal.js +1 -1
- package/dist/createGlobal.js.map +1 -0
- package/dist/createGlobalVersion.js +1 -1
- package/dist/createGlobalVersion.js.map +1 -0
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +4 -2
- package/dist/createMigration.js.map +1 -0
- package/dist/createVersion.js +1 -1
- package/dist/createVersion.js.map +1 -0
- package/dist/deleteMany.js +1 -1
- package/dist/deleteMany.js.map +1 -0
- package/dist/deleteOne.js +1 -1
- package/dist/deleteOne.js.map +1 -0
- package/dist/deleteVersions.js +1 -1
- package/dist/deleteVersions.js.map +1 -0
- package/dist/destroy.js +1 -1
- package/dist/destroy.js.map +1 -0
- package/dist/find/buildFindManyArgs.js +1 -1
- package/dist/find/buildFindManyArgs.js.map +1 -0
- package/dist/find/chainMethods.js +1 -1
- package/dist/find/chainMethods.js.map +1 -0
- package/dist/find/findMany.js +1 -1
- package/dist/find/findMany.js.map +1 -0
- package/dist/find/traverseFields.js +1 -1
- package/dist/find/traverseFields.js.map +1 -0
- package/dist/find.js +1 -1
- package/dist/find.js.map +1 -0
- package/dist/findGlobal.js +1 -1
- package/dist/findGlobal.js.map +1 -0
- package/dist/findGlobalVersions.js +1 -1
- package/dist/findGlobalVersions.js.map +1 -0
- package/dist/findOne.js +1 -1
- package/dist/findOne.js.map +1 -0
- package/dist/findVersions.js +1 -1
- package/dist/findVersions.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -0
- package/dist/init.js +1 -1
- package/dist/init.js.map +1 -0
- package/dist/migrate.d.ts.map +1 -1
- package/dist/migrate.js +5 -3
- package/dist/migrate.js.map +1 -0
- package/dist/migrateDown.js +1 -1
- package/dist/migrateDown.js.map +1 -0
- package/dist/migrateFresh.js +1 -1
- package/dist/migrateFresh.js.map +1 -0
- package/dist/migrateRefresh.js +1 -1
- package/dist/migrateRefresh.js.map +1 -0
- package/dist/migrateReset.js +1 -1
- package/dist/migrateReset.js.map +1 -0
- package/dist/migrateStatus.js +1 -1
- package/dist/migrateStatus.js.map +1 -0
- package/dist/queries/buildAndOrConditions.js +1 -1
- package/dist/queries/buildAndOrConditions.js.map +1 -0
- package/dist/queries/buildQuery.js +1 -1
- package/dist/queries/buildQuery.js.map +1 -0
- package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js +1 -1
- package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js.map +1 -0
- package/dist/queries/createJSONQuery/formatJSONPathSegment.js +1 -1
- package/dist/queries/createJSONQuery/formatJSONPathSegment.js.map +1 -0
- package/dist/queries/createJSONQuery/index.js +1 -1
- package/dist/queries/createJSONQuery/index.js.map +1 -0
- package/dist/queries/getTableColumnFromPath.js +1 -1
- package/dist/queries/getTableColumnFromPath.js.map +1 -0
- package/dist/queries/operatorMap.js +1 -1
- package/dist/queries/operatorMap.js.map +1 -0
- package/dist/queries/parseParams.js +1 -1
- package/dist/queries/parseParams.js.map +1 -0
- package/dist/queries/sanitizeQueryValue.js +1 -1
- package/dist/queries/sanitizeQueryValue.js.map +1 -0
- package/dist/queryDrafts.js +1 -1
- package/dist/queryDrafts.js.map +1 -0
- package/dist/schema/build.js +1 -1
- package/dist/schema/build.js.map +1 -0
- package/dist/schema/createIndex.js +1 -1
- package/dist/schema/createIndex.js.map +1 -0
- package/dist/schema/idToUUID.js +1 -1
- package/dist/schema/idToUUID.js.map +1 -0
- package/dist/schema/parentIDColumnMap.js +1 -1
- package/dist/schema/parentIDColumnMap.js.map +1 -0
- package/dist/schema/setColumnID.js +1 -1
- package/dist/schema/setColumnID.js.map +1 -0
- package/dist/schema/traverseFields.js +1 -1
- package/dist/schema/traverseFields.js.map +1 -0
- package/dist/schema/validateExistingBlockIsIdentical.js +1 -1
- package/dist/schema/validateExistingBlockIsIdentical.js.map +1 -0
- package/dist/transactions/beginTransaction.js +1 -1
- package/dist/transactions/beginTransaction.js.map +1 -0
- package/dist/transactions/commitTransaction.js +1 -1
- package/dist/transactions/commitTransaction.js.map +1 -0
- package/dist/transactions/rollbackTransaction.js +1 -1
- package/dist/transactions/rollbackTransaction.js.map +1 -0
- package/dist/transform/read/hasManyNumber.js +1 -1
- package/dist/transform/read/hasManyNumber.js.map +1 -0
- package/dist/transform/read/hasManyText.js +1 -1
- package/dist/transform/read/hasManyText.js.map +1 -0
- package/dist/transform/read/index.js +1 -1
- package/dist/transform/read/index.js.map +1 -0
- package/dist/transform/read/relationship.js +1 -1
- package/dist/transform/read/relationship.js.map +1 -0
- package/dist/transform/read/traverseFields.js +1 -1
- package/dist/transform/read/traverseFields.js.map +1 -0
- package/dist/transform/write/array.js +1 -1
- package/dist/transform/write/array.js.map +1 -0
- package/dist/transform/write/blocks.js +1 -1
- package/dist/transform/write/blocks.js.map +1 -0
- package/dist/transform/write/index.js +1 -1
- package/dist/transform/write/index.js.map +1 -0
- package/dist/transform/write/numbers.js +1 -1
- package/dist/transform/write/numbers.js.map +1 -0
- package/dist/transform/write/relationships.js +1 -1
- package/dist/transform/write/relationships.js.map +1 -0
- package/dist/transform/write/selects.js +1 -1
- package/dist/transform/write/selects.js.map +1 -0
- package/dist/transform/write/texts.js +1 -1
- package/dist/transform/write/texts.js.map +1 -0
- package/dist/transform/write/traverseFields.js +1 -1
- package/dist/transform/write/traverseFields.js.map +1 -0
- package/dist/transform/write/types.js +1 -1
- package/dist/transform/write/types.js.map +1 -0
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -0
- package/dist/update.js +1 -1
- package/dist/update.js.map +1 -0
- package/dist/updateGlobal.js +1 -1
- package/dist/updateGlobal.js.map +1 -0
- package/dist/updateGlobalVersion.js +1 -1
- package/dist/updateGlobalVersion.js.map +1 -0
- package/dist/updateVersion.js +1 -1
- package/dist/updateVersion.js.map +1 -0
- package/dist/upsertRow/deleteExistingArrayRows.js +1 -1
- package/dist/upsertRow/deleteExistingArrayRows.js.map +1 -0
- package/dist/upsertRow/deleteExistingRowsByPath.js +1 -1
- package/dist/upsertRow/deleteExistingRowsByPath.js.map +1 -0
- package/dist/upsertRow/index.js +1 -1
- package/dist/upsertRow/index.js.map +1 -0
- package/dist/upsertRow/insertArrays.js +1 -1
- package/dist/upsertRow/insertArrays.js.map +1 -0
- package/dist/upsertRow/types.js +1 -1
- package/dist/upsertRow/types.js.map +1 -0
- package/dist/utilities/appendPrefixToKeys.js +1 -1
- package/dist/utilities/appendPrefixToKeys.js.map +1 -0
- package/dist/utilities/createBlocksMap.js +1 -1
- package/dist/utilities/createBlocksMap.js.map +1 -0
- package/dist/utilities/createMigrationTable.js +1 -1
- package/dist/utilities/createMigrationTable.js.map +1 -0
- package/dist/utilities/createRelationshipMap.js +1 -1
- package/dist/utilities/createRelationshipMap.js.map +1 -0
- package/dist/utilities/hasLocalesTable.js +1 -1
- package/dist/utilities/hasLocalesTable.js.map +1 -0
- package/dist/utilities/isArrayOfRows.js +1 -1
- package/dist/utilities/isArrayOfRows.js.map +1 -0
- package/dist/utilities/migrationTableExists.js +1 -1
- package/dist/utilities/migrationTableExists.js.map +1 -0
- package/dist/utilities/parseError.js +1 -1
- package/dist/utilities/parseError.js.map +1 -0
- package/dist/utilities/pushDevSchema.d.ts.map +1 -1
- package/dist/utilities/pushDevSchema.js +4 -2
- package/dist/utilities/pushDevSchema.js.map +1 -0
- package/package.json +3 -3
package/dist/connect.js
CHANGED
@@ -76,4 +76,4 @@ export const connect = async function connect(options = {
|
|
76
76
|
await pushDevSchema(this);
|
77
77
|
};
|
78
78
|
|
79
|
-
//# sourceMappingURL=
|
79
|
+
//# sourceMappingURL=connect.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport type { Connect } from 'payload/database'\n\nimport { sql } from 'drizzle-orm'\nimport { drizzle } from 'drizzle-orm/node-postgres'\nimport pg from 'pg'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { pushDevSchema } from './utilities/pushDevSchema.js'\n\nconst connectWithReconnect = async function ({\n adapter,\n payload,\n reconnect = false,\n}: {\n adapter: PostgresAdapter\n payload: Payload\n reconnect?: boolean\n}) {\n let result\n\n if (!reconnect) {\n result = await adapter.pool.connect()\n } else {\n try {\n result = await adapter.pool.connect()\n } catch (err) {\n setTimeout(() => {\n payload.logger.info('Reconnecting to postgres')\n void connectWithReconnect({ adapter, payload, 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, payload, reconnect: true })\n }\n } catch (err) {\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 this.schema = {\n ...this.tables,\n ...this.relations,\n ...this.enums,\n }\n\n try {\n this.pool = new pg.Pool(this.poolOptions)\n await connectWithReconnect({ adapter: this, payload: this.payload })\n\n const logger = this.logger || false\n\n this.drizzle = drizzle(this.pool, { logger, schema: this.schema })\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.drizzle.execute(\n sql.raw(`\n drop schema if exists ${this.schemaName || 'public'} cascade;\n create schema ${this.schemaName || 'public'};\n `),\n )\n this.payload.logger.info('---- DROPPED TABLES ----')\n }\n }\n } catch (err) {\n this.payload.logger.error(`Error: cannot connect to Postgres. Details: ${err.message}`, err)\n process.exit(1)\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 return\n\n await pushDevSchema(this)\n}\n"],"names":["sql","drizzle","pg","pushDevSchema","connectWithReconnect","adapter","payload","reconnect","result","pool","connect","err","setTimeout","logger","info","prependListener","code","options","hotReload","schema","tables","relations","enums","Pool","poolOptions","process","env","PAYLOAD_DROP_DATABASE","schemaName","execute","raw","error","message","exit","NODE_ENV","PAYLOAD_MIGRATING","push"],"mappings":"AAGA,SAASA,GAAG,QAAQ,cAAa;AACjC,SAASC,OAAO,QAAQ,4BAA2B;AACnD,OAAOC,QAAQ,KAAI;AAInB,SAASC,aAAa,QAAQ,+BAA8B;AAE5D,MAAMC,uBAAuB,eAAgB,EAC3CC,OAAO,EACPC,OAAO,EACPC,YAAY,KAAK,EAKlB;IACC,IAAIC;IAEJ,IAAI,CAACD,WAAW;QACdC,SAAS,MAAMH,QAAQI,IAAI,CAACC,OAAO;IACrC,OAAO;QACL,IAAI;YACFF,SAAS,MAAMH,QAAQI,IAAI,CAACC,OAAO;QACrC,EAAE,OAAOC,KAAK;YACZC,WAAW;gBACTN,QAAQO,MAAM,CAACC,IAAI,CAAC;gBACpB,KAAKV,qBAAqB;oBAAEC;oBAASC;oBAASC,WAAW;gBAAK;YAChE,GAAG;QACL;IACF;IACA,IAAI,CAACC,QAAQ;QACX;IACF;IACAA,OAAOO,eAAe,CAAC,SAAS,CAACJ;QAC/B,IAAI;YACF,IAAIA,IAAIK,IAAI,KAAK,cAAc;gBAC7B,KAAKZ,qBAAqB;oBAAEC;oBAASC;oBAASC,WAAW;gBAAK;YAChE;QACF,EAAE,OAAOI,KAAK;QACZ,gBAAgB;QAClB;IACF;AACF;AAEA,OAAO,MAAMD,UAAmB,eAAeA,QAE7CO,UAAU;IACRC,WAAW;AACb,CAAC;IAED,MAAM,EAAEA,SAAS,EAAE,GAAGD;IAEtB,IAAI,CAACE,MAAM,GAAG;QACZ,GAAG,IAAI,CAACC,MAAM;QACd,GAAG,IAAI,CAACC,SAAS;QACjB,GAAG,IAAI,CAACC,KAAK;IACf;IAEA,IAAI;QACF,IAAI,CAACb,IAAI,GAAG,IAAIP,GAAGqB,IAAI,CAAC,IAAI,CAACC,WAAW;QACxC,MAAMpB,qBAAqB;YAAEC,SAAS,IAAI;YAAEC,SAAS,IAAI,CAACA,OAAO;QAAC;QAElE,MAAMO,SAAS,IAAI,CAACA,MAAM,IAAI;QAE9B,IAAI,CAACZ,OAAO,GAAGA,QAAQ,IAAI,CAACQ,IAAI,EAAE;YAAEI;YAAQM,QAAQ,IAAI,CAACA,MAAM;QAAC;QAEhE,IAAI,CAACD,WAAW;YACd,IAAIO,QAAQC,GAAG,CAACC,qBAAqB,KAAK,QAAQ;gBAChD,IAAI,CAACrB,OAAO,CAACO,MAAM,CAACC,IAAI,CAAC,CAAC,4BAA4B,EAAE,IAAI,CAACc,UAAU,IAAI,SAAS,MAAM,CAAC;gBAC3F,MAAM,IAAI,CAAC3B,OAAO,CAAC4B,OAAO,CACxB7B,IAAI8B,GAAG,CAAC,CAAC;gCACa,EAAE,IAAI,CAACF,UAAU,IAAI,SAAS;wBACtC,EAAE,IAAI,CAACA,UAAU,IAAI,SAAS;QAC9C,CAAC;gBAED,IAAI,CAACtB,OAAO,CAACO,MAAM,CAACC,IAAI,CAAC;YAC3B;QACF;IACF,EAAE,OAAOH,KAAK;QACZ,IAAI,CAACL,OAAO,CAACO,MAAM,CAACkB,KAAK,CAAC,CAAC,4CAA4C,EAAEpB,IAAIqB,OAAO,CAAC,CAAC,EAAErB;QACxFc,QAAQQ,IAAI,CAAC;IACf;IAEA,wCAAwC;IACxC,IACER,QAAQC,GAAG,CAACQ,QAAQ,KAAK,gBACzBT,QAAQC,GAAG,CAACS,iBAAiB,KAAK,UAClC,IAAI,CAACC,IAAI,KAAK,OAEd;IAEF,MAAMjC,cAAc,IAAI;AAC1B,EAAC"}
|
package/dist/create.js
CHANGED
@@ -15,4 +15,4 @@ export const create = async function create({ collection: collectionSlug, data,
|
|
15
15
|
return result;
|
16
16
|
};
|
17
17
|
|
18
|
-
//# sourceMappingURL=
|
18
|
+
//# sourceMappingURL=create.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { Create } from 'payload/database'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\n\nexport const create: Create = async function create(\n this: PostgresAdapter,\n { collection: collectionSlug, data, req },\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const collection = this.payload.collections[collectionSlug].config\n\n const result = await upsertRow({\n adapter: this,\n data,\n db,\n fields: collection.fields,\n operation: 'create',\n tableName: toSnakeCase(collectionSlug),\n req,\n })\n\n return result\n}\n"],"names":["toSnakeCase","upsertRow","create","collection","collectionSlug","data","req","db","sessions","transactionID","drizzle","payload","collections","config","result","adapter","fields","operation","tableName"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,SAAS,QAAQ,uBAAsB;AAEhD,OAAO,MAAMC,SAAiB,eAAeA,OAE3C,EAAEC,YAAYC,cAAc,EAAEC,IAAI,EAAEC,GAAG,EAAE;IAEzC,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACF,IAAIG,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMP,aAAa,IAAI,CAACQ,OAAO,CAACC,WAAW,CAACR,eAAe,CAACS,MAAM;IAElE,MAAMC,SAAS,MAAMb,UAAU;QAC7Bc,SAAS,IAAI;QACbV;QACAE;QACAS,QAAQb,WAAWa,MAAM;QACzBC,WAAW;QACXC,WAAWlB,YAAYI;QACvBE;IACF;IAEA,OAAOQ;AACT,EAAC"}
|
package/dist/createGlobal.js
CHANGED
@@ -15,4 +15,4 @@ export async function createGlobal({ data, req = {}, slug }) {
|
|
15
15
|
return result;
|
16
16
|
}
|
17
17
|
|
18
|
-
//# sourceMappingURL=
|
18
|
+
//# sourceMappingURL=createGlobal.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/createGlobal.ts"],"sourcesContent":["import type { CreateGlobalArgs } from 'payload/database'\nimport type { PayloadRequest, TypeWithID } from 'payload/types'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\n\nexport async function createGlobal<T extends TypeWithID>(\n this: PostgresAdapter,\n { data, req = {} as PayloadRequest, slug }: CreateGlobalArgs,\n): Promise<T> {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const globalConfig = this.payload.globals.config.find((config) => config.slug === slug)\n\n const result = await upsertRow<T>({\n adapter: this,\n data,\n db,\n fields: globalConfig.fields,\n operation: 'create',\n tableName: toSnakeCase(slug),\n req,\n })\n\n return result\n}\n"],"names":["toSnakeCase","upsertRow","createGlobal","data","req","slug","db","sessions","transactionID","drizzle","globalConfig","payload","globals","config","find","result","adapter","fields","operation","tableName"],"mappings":"AAGA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,SAAS,QAAQ,uBAAsB;AAEhD,OAAO,eAAeC,aAEpB,EAAEC,IAAI,EAAEC,MAAM,CAAC,CAAmB,EAAEC,IAAI,EAAoB;IAE5D,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACH,IAAII,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMC,eAAe,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAACD,SAAWA,OAAOR,IAAI,KAAKA;IAElF,MAAMU,SAAS,MAAMd,UAAa;QAChCe,SAAS,IAAI;QACbb;QACAG;QACAW,QAAQP,aAAaO,MAAM;QAC3BC,WAAW;QACXC,WAAWnB,YAAYK;QACvBD;IACF;IAEA,OAAOW;AACT"}
|
@@ -31,4 +31,4 @@ export async function createGlobalVersion({ autosave, globalSlug, req = {}, vers
|
|
31
31
|
return result;
|
32
32
|
}
|
33
33
|
|
34
|
-
//# sourceMappingURL=
|
34
|
+
//# sourceMappingURL=createGlobalVersion.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import type { TypeWithVersion } from 'payload/database'\nimport { type CreateGlobalVersionArgs } from 'payload/database'\nimport type { PayloadRequest, TypeWithID } from 'payload/types'\n\nimport { sql } from 'drizzle-orm'\nimport { buildVersionGlobalFields } from 'payload/versions'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\n\nexport async function createGlobalVersion<T extends TypeWithID>(\n this: PostgresAdapter,\n { autosave, globalSlug, req = {} as PayloadRequest, versionData }: CreateGlobalVersionArgs,\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const global = this.payload.globals.config.find(({ slug }) => slug === globalSlug)\n const globalTableName = toSnakeCase(globalSlug)\n const tableName = `_${globalTableName}_v`\n\n const result = await upsertRow<TypeWithVersion<T>>({\n adapter: this,\n data: {\n autosave,\n latest: true,\n version: versionData,\n },\n db,\n fields: buildVersionGlobalFields(global),\n operation: 'create',\n tableName,\n req,\n })\n\n const table = this.tables[tableName]\n\n if (global.versions.drafts) {\n await db.execute(sql`\n UPDATE ${table}\n SET latest = false\n WHERE ${table.id} != ${result.id};\n `)\n }\n\n return result\n}\n"],"names":["sql","buildVersionGlobalFields","toSnakeCase","upsertRow","createGlobalVersion","autosave","globalSlug","req","versionData","db","sessions","transactionID","drizzle","global","payload","globals","config","find","slug","globalTableName","tableName","result","adapter","data","latest","version","fields","operation","table","tables","versions","drafts","execute","id"],"mappings":"AAIA,SAASA,GAAG,QAAQ,cAAa;AACjC,SAASC,wBAAwB,QAAQ,mBAAkB;AAC3D,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,SAAS,QAAQ,uBAAsB;AAEhD,OAAO,eAAeC,oBAEpB,EAAEC,QAAQ,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,WAAW,EAA2B;IAE1F,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACH,IAAII,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMC,SAAS,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASZ;IACvE,MAAMa,kBAAkBjB,YAAYI;IACpC,MAAMc,YAAY,CAAC,CAAC,EAAED,gBAAgB,EAAE,CAAC;IAEzC,MAAME,SAAS,MAAMlB,UAA8B;QACjDmB,SAAS,IAAI;QACbC,MAAM;YACJlB;YACAmB,QAAQ;YACRC,SAASjB;QACX;QACAC;QACAiB,QAAQzB,yBAAyBY;QACjCc,WAAW;QACXP;QACAb;IACF;IAEA,MAAMqB,QAAQ,IAAI,CAACC,MAAM,CAACT,UAAU;IAEpC,IAAIP,OAAOiB,QAAQ,CAACC,MAAM,EAAE;QAC1B,MAAMtB,GAAGuB,OAAO,CAAChC,GAAG,CAAC;aACZ,EAAE4B,MAAM;;YAET,EAAEA,MAAMK,EAAE,CAAC,IAAI,EAAEZ,OAAOY,EAAE,CAAC;IACnC,CAAC;IACH;IAEA,OAAOZ;AACT"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"createMigration.d.ts","sourceRoot":"","sources":["../src/createMigration.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;
|
1
|
+
{"version":3,"file":"createMigration.d.ts","sourceRoot":"","sources":["../src/createMigration.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAsDvD,eAAO,MAAM,eAAe,EAAE,eA4E7B,CAAA"}
|
package/dist/createMigration.js
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
/* eslint-disable no-restricted-syntax, no-await-in-loop */ import fs from 'fs';
|
2
|
+
import { createRequire } from 'module';
|
2
3
|
import prompts from 'prompts';
|
4
|
+
const require = createRequire(import.meta.url);
|
3
5
|
const migrationTemplate = (upSQL, downSQL)=>`import { MigrateUpArgs, MigrateDownArgs } from '@payloadcms/db-postgres'
|
4
6
|
import { sql } from 'drizzle-orm'
|
5
7
|
|
@@ -36,7 +38,7 @@ export const createMigration = async function createMigration({ forceAcceptWarni
|
|
36
38
|
if (!fs.existsSync(dir)) {
|
37
39
|
fs.mkdirSync(dir);
|
38
40
|
}
|
39
|
-
const { generateDrizzleJson, generateMigration } =
|
41
|
+
const { generateDrizzleJson, generateMigration } = require('drizzle-kit/payload');
|
40
42
|
const [yyymmdd, hhmmss] = new Date().toISOString().split('T');
|
41
43
|
const formattedDate = yyymmdd.replace(/\D/g, '');
|
42
44
|
const formattedTime = hhmmss.split('.')[0].replace(/\D/g, '');
|
@@ -77,4 +79,4 @@ export const createMigration = async function createMigration({ forceAcceptWarni
|
|
77
79
|
});
|
78
80
|
};
|
79
81
|
|
80
|
-
//# sourceMappingURL=
|
82
|
+
//# sourceMappingURL=createMigration.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/createMigration.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax, no-await-in-loop */\nimport type { DrizzleSnapshotJSON } from 'drizzle-kit/payload'\nimport type { CreateMigration } from 'payload/database'\n\nimport fs from 'fs'\nimport { createRequire } from 'module'\nimport prompts from 'prompts'\n\nimport type { PostgresAdapter } from './types.js'\n\nconst require = createRequire(import.meta.url)\n\nconst migrationTemplate = (\n upSQL?: string,\n downSQL?: string,\n) => `import { MigrateUpArgs, MigrateDownArgs } from '@payloadcms/db-postgres'\nimport { sql } from 'drizzle-orm'\n\nexport async function up({ payload }: MigrateUpArgs): Promise<void> {\n${\n upSQL\n ? `await payload.db.drizzle.execute(sql\\`\n\n${upSQL}\\`);\n`\n : '// Migration code'\n}\n};\n\nexport async function down({ payload }: MigrateDownArgs): Promise<void> {\n${\n downSQL\n ? `await payload.db.drizzle.execute(sql\\`\n\n${downSQL}\\`);\n`\n : '// Migration code'\n}\n};\n`\n\nconst getDefaultDrizzleSnapshot = (): DrizzleSnapshotJSON => ({\n id: '00000000-0000-0000-0000-000000000000',\n _meta: {\n columns: {},\n schemas: {},\n tables: {},\n },\n dialect: 'pg',\n enums: {},\n prevId: '00000000-0000-0000-0000-00000000000',\n schemas: {},\n tables: {},\n version: '5',\n})\n\nexport const createMigration: CreateMigration = async function createMigration(\n this: PostgresAdapter,\n { forceAcceptWarning, migrationName, payload },\n) {\n const dir = payload.db.migrationDir\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir)\n }\n\n const { generateDrizzleJson, generateMigration } = require('drizzle-kit/payload')\n\n const [yyymmdd, hhmmss] = new Date().toISOString().split('T')\n const formattedDate = yyymmdd.replace(/\\D/g, '')\n const formattedTime = hhmmss.split('.')[0].replace(/\\D/g, '')\n\n const timestamp = `${formattedDate}_${formattedTime}`\n\n const fileName = migrationName\n ? `${timestamp}_${migrationName.replace(/\\W/g, '_')}`\n : `${timestamp}`\n\n const filePath = `${dir}/${fileName}`\n\n let drizzleJsonBefore = getDefaultDrizzleSnapshot()\n\n // Get latest migration snapshot\n const latestSnapshot = fs\n .readdirSync(dir)\n .filter((file) => file.endsWith('.json'))\n .sort()\n .reverse()?.[0]\n\n if (latestSnapshot) {\n const latestSnapshotJSON = JSON.parse(\n fs.readFileSync(`${dir}/${latestSnapshot}`, 'utf8'),\n ) as DrizzleSnapshotJSON\n\n drizzleJsonBefore = latestSnapshotJSON\n }\n\n const drizzleJsonAfter = generateDrizzleJson(this.schema)\n const sqlStatementsUp = await generateMigration(drizzleJsonBefore, drizzleJsonAfter)\n const sqlStatementsDown = await generateMigration(drizzleJsonAfter, drizzleJsonBefore)\n\n if (!sqlStatementsUp.length && !sqlStatementsDown.length && !forceAcceptWarning) {\n const { confirm: shouldCreateBlankMigration } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message: 'No schema changes detected. Would you like to create a blank migration file?',\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!shouldCreateBlankMigration) {\n process.exit(0)\n }\n }\n\n // write schema\n fs.writeFileSync(`${filePath}.json`, JSON.stringify(drizzleJsonAfter, null, 2))\n\n // write migration\n fs.writeFileSync(\n `${filePath}.ts`,\n migrationTemplate(\n sqlStatementsUp.length ? sqlStatementsUp?.join('\\n') : undefined,\n sqlStatementsDown.length ? sqlStatementsDown?.join('\\n') : undefined,\n ),\n )\n payload.logger.info({ msg: `Migration created at ${filePath}.ts` })\n}\n"],"names":["fs","createRequire","prompts","require","url","migrationTemplate","upSQL","downSQL","getDefaultDrizzleSnapshot","id","_meta","columns","schemas","tables","dialect","enums","prevId","version","createMigration","forceAcceptWarning","migrationName","payload","dir","db","migrationDir","existsSync","mkdirSync","generateDrizzleJson","generateMigration","yyymmdd","hhmmss","Date","toISOString","split","formattedDate","replace","formattedTime","timestamp","fileName","filePath","drizzleJsonBefore","latestSnapshot","readdirSync","filter","file","endsWith","sort","reverse","latestSnapshotJSON","JSON","parse","readFileSync","drizzleJsonAfter","schema","sqlStatementsUp","sqlStatementsDown","length","confirm","shouldCreateBlankMigration","name","type","initial","message","onCancel","process","exit","writeFileSync","stringify","join","undefined","logger","info","msg"],"mappings":"AAAA,yDAAyD,GAIzD,OAAOA,QAAQ,KAAI;AACnB,SAASC,aAAa,QAAQ,SAAQ;AACtC,OAAOC,aAAa,UAAS;AAI7B,MAAMC,UAAUF,cAAc,YAAYG,GAAG;AAE7C,MAAMC,oBAAoB,CACxBC,OACAC,UACG,CAAC;;;;AAIN,EACED,QACI,CAAC;;AAEP,EAAEA,MAAM;AACR,CAAC,GACK,oBACL;;;;AAID,EACEC,UACI,CAAC;;AAEP,EAAEA,QAAQ;AACV,CAAC,GACK,oBACL;;AAED,CAAC;AAED,MAAMC,4BAA4B,IAA4B,CAAA;QAC5DC,IAAI;QACJC,OAAO;YACLC,SAAS,CAAC;YACVC,SAAS,CAAC;YACVC,QAAQ,CAAC;QACX;QACAC,SAAS;QACTC,OAAO,CAAC;QACRC,QAAQ;QACRJ,SAAS,CAAC;QACVC,QAAQ,CAAC;QACTI,SAAS;IACX,CAAA;AAEA,OAA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B,kBAAkBZ;IAEpE,IAAI,CAACc,gBAAgBE,MAAM,IAAI,CAACD,kBAAkBC,MAAM,IAAI,CAACrC,oBAAoB;QAC/E,MAAM,EAAEsC,SAASC,0BAA0B,EAAE,GAAG,MAAMxD,QACpD;YACEyD,MAAM;YACNC,MAAM;YACNC,SAAS;YACTC,SAAS;QACX,GACA;YACEC,UAAU;gBACRC,QAAQC,IAAI,CAAC;YACf;QACF;QAGF,IAAI,CAACP,4BAA4B;YAC/BM,QAAQC,IAAI,CAAC;QACf;IACF;IAEA,eAAe;IACfjE,GAAGkE,aAAa,CAAC,CAAC,EAAE3B,SAAS,KAAK,CAAC,EAAEU,KAAKkB,SAAS,CAACf,kBAAkB,MAAM;IAE5E,kBAAkB;IAClBpD,GAAGkE,aAAa,CACd,CAAC,EAAE3B,SAAS,GAAG,CAAC,EAChBlC,kBACEiD,gBAAgBE,MAAM,GAAGF,iBAAiBc,KAAK,QAAQC,WACvDd,kBAAkBC,MAAM,GAAGD,mBAAmBa,KAAK,QAAQC;IAG/DhD,QAAQiD,MAAM,CAACC,IAAI,CAAC;QAAEC,KAAK,CAAC,qBAAqB,EAAEjC,SAAS,GAAG,CAAC;IAAC;AACnE,EAAC"}
|
package/dist/createVersion.js
CHANGED
@@ -37,4 +37,4 @@ export async function createVersion({ autosave, collectionSlug, parent, req = {}
|
|
37
37
|
return result;
|
38
38
|
}
|
39
39
|
|
40
|
-
//# sourceMappingURL=
|
40
|
+
//# sourceMappingURL=createVersion.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import type { CreateVersionArgs, TypeWithVersion } from 'payload/database'\nimport type { PayloadRequest, TypeWithID } from 'payload/types'\n\nimport { sql } from 'drizzle-orm'\nimport { buildVersionCollectionFields } from 'payload/versions'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\n\nexport async function createVersion<T extends TypeWithID>(\n this: PostgresAdapter,\n {\n autosave,\n collectionSlug,\n parent,\n req = {} as PayloadRequest,\n versionData,\n }: CreateVersionArgs<T>,\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const collection = this.payload.collections[collectionSlug].config\n const collectionTableName = toSnakeCase(collectionSlug)\n const tableName = `_${collectionTableName}_v`\n\n const result = await upsertRow<TypeWithVersion<T>>({\n adapter: this,\n data: {\n autosave,\n latest: true,\n parent,\n version: versionData,\n },\n db,\n fields: buildVersionCollectionFields(collection),\n operation: 'create',\n tableName,\n req,\n })\n\n const table = this.tables[tableName]\n const relationshipsTable = this.tables[`${tableName}_rels`]\n\n if (collection.versions.drafts) {\n await db.execute(sql`\n UPDATE ${table}\n SET latest = false\n FROM ${relationshipsTable}\n WHERE ${table.id} = ${relationshipsTable.parent}\n AND ${relationshipsTable.path} = ${'parent'}\n AND ${relationshipsTable[`${collectionSlug}ID`]} = ${parent}\n AND ${table.id} != ${result.id};\n `)\n }\n\n return result\n}\n"],"names":["sql","buildVersionCollectionFields","toSnakeCase","upsertRow","createVersion","autosave","collectionSlug","parent","req","versionData","db","sessions","transactionID","drizzle","collection","payload","collections","config","collectionTableName","tableName","result","adapter","data","latest","version","fields","operation","table","tables","relationshipsTable","versions","drafts","execute","id","path"],"mappings":"AAGA,SAASA,GAAG,QAAQ,cAAa;AACjC,SAASC,4BAA4B,QAAQ,mBAAkB;AAC/D,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,SAAS,QAAQ,uBAAsB;AAEhD,OAAO,eAAeC,cAEpB,EACEC,QAAQ,EACRC,cAAc,EACdC,MAAM,EACNC,MAAM,CAAC,CAAmB,EAC1BC,WAAW,EACU;IAEvB,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACH,IAAII,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMC,aAAa,IAAI,CAACC,OAAO,CAACC,WAAW,CAACV,eAAe,CAACW,MAAM;IAClE,MAAMC,sBAAsBhB,YAAYI;IACxC,MAAMa,YAAY,CAAC,CAAC,EAAED,oBAAoB,EAAE,CAAC;IAE7C,MAAME,SAAS,MAAMjB,UAA8B;QACjDkB,SAAS,IAAI;QACbC,MAAM;YACJjB;YACAkB,QAAQ;YACRhB;YACAiB,SAASf;QACX;QACAC;QACAe,QAAQxB,6BAA6Ba;QACrCY,WAAW;QACXP;QACAX;IACF;IAEA,MAAMmB,QAAQ,IAAI,CAACC,MAAM,CAACT,UAAU;IACpC,MAAMU,qBAAqB,IAAI,CAACD,MAAM,CAAC,CAAC,EAAET,UAAU,KAAK,CAAC,CAAC;IAE3D,IAAIL,WAAWgB,QAAQ,CAACC,MAAM,EAAE;QAC9B,MAAMrB,GAAGsB,OAAO,CAAChC,GAAG,CAAC;aACZ,EAAE2B,MAAM;;WAEV,EAAEE,mBAAmB;YACpB,EAAEF,MAAMM,EAAE,CAAC,GAAG,EAAEJ,mBAAmBtB,MAAM,CAAC;YAC1C,EAAEsB,mBAAmBK,IAAI,CAAC,GAAG,EAAE,SAAS;YACxC,EAAEL,kBAAkB,CAAC,CAAC,EAAEvB,eAAe,EAAE,CAAC,CAAC,CAAC,GAAG,EAAEC,OAAO;YACxD,EAAEoB,MAAMM,EAAE,CAAC,IAAI,EAAEb,OAAOa,EAAE,CAAC;IACnC,CAAC;IACH;IAEA,OAAOb;AACT"}
|
package/dist/deleteMany.js
CHANGED
@@ -25,4 +25,4 @@ export const deleteMany = async function deleteMany({ collection, req = {}, wher
|
|
25
25
|
}
|
26
26
|
};
|
27
27
|
|
28
|
-
//# sourceMappingURL=
|
28
|
+
//# sourceMappingURL=deleteMany.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteMany } from 'payload/database'\nimport type { PayloadRequest } from 'payload/types'\n\nimport { inArray } from 'drizzle-orm'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: PostgresAdapter,\n { collection, req = {} as PayloadRequest, where },\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const collectionConfig = this.payload.collections[collection].config\n const tableName = toSnakeCase(collection)\n\n const result = await findMany({\n adapter: this,\n fields: collectionConfig.fields,\n limit: 0,\n locale: req.locale,\n page: 1,\n pagination: false,\n req,\n tableName,\n where,\n })\n\n const ids = []\n\n result.docs.forEach((data) => {\n ids.push(data.id)\n })\n\n if (ids.length > 0) {\n await db.delete(this.tables[tableName]).where(inArray(this.tables[tableName].id, ids))\n }\n}\n"],"names":["inArray","toSnakeCase","findMany","deleteMany","collection","req","where","db","sessions","transactionID","drizzle","collectionConfig","payload","collections","config","tableName","result","adapter","fields","limit","locale","page","pagination","ids","docs","forEach","data","push","id","length","delete","tables"],"mappings":"AAGA,SAASA,OAAO,QAAQ,cAAa;AACrC,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEjD,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACH,IAAII,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMC,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACT,WAAW,CAACU,MAAM;IACpE,MAAMC,YAAYd,YAAYG;IAE9B,MAAMY,SAAS,MAAMd,SAAS;QAC5Be,SAAS,IAAI;QACbC,QAAQP,iBAAiBO,MAAM;QAC/BC,OAAO;QACPC,QAAQf,IAAIe,MAAM;QAClBC,MAAM;QACNC,YAAY;QACZjB;QACAU;QACAT;IACF;IAEA,MAAMiB,MAAM,EAAE;IAEdP,OAAOQ,IAAI,CAACC,OAAO,CAAC,CAACC;QACnBH,IAAII,IAAI,CAACD,KAAKE,EAAE;IAClB;IAEA,IAAIL,IAAIM,MAAM,GAAG,GAAG;QAClB,MAAMtB,GAAGuB,MAAM,CAAC,IAAI,CAACC,MAAM,CAAChB,UAAU,EAAET,KAAK,CAACN,QAAQ,IAAI,CAAC+B,MAAM,CAAChB,UAAU,CAACa,EAAE,EAAEL;IACnF;AACF,EAAC"}
|
package/dist/deleteOne.js
CHANGED
@@ -29,4 +29,4 @@ export const deleteOne = async function deleteOne({ collection, req = {}, where:
|
|
29
29
|
return result;
|
30
30
|
};
|
31
31
|
|
32
|
-
//# sourceMappingURL=
|
32
|
+
//# sourceMappingURL=deleteOne.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { DeleteOne } from 'payload/database'\nimport type { PayloadRequest } from 'payload/types'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { buildFindManyArgs } from './find/buildFindManyArgs.js'\nimport buildQuery from './queries/buildQuery.js'\nimport { transform } from './transform/read/index.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: PostgresAdapter,\n { collection, req = {} as PayloadRequest, where: incomingWhere },\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const collectionConfig = this.payload.collections[collection].config\n const tableName = toSnakeCase(collection)\n\n const { where } = await buildQuery({\n adapter: this,\n fields: collectionConfig.fields,\n tableName,\n where: incomingWhere,\n })\n\n const findManyArgs = buildFindManyArgs({\n adapter: this,\n depth: 0,\n fields: collectionConfig.fields,\n tableName,\n })\n\n findManyArgs.where = where\n\n const docToDelete = await db.query[tableName].findFirst(findManyArgs)\n\n const result = transform({\n config: this.payload.config,\n data: docToDelete,\n fields: collectionConfig.fields,\n })\n\n await db.delete(this.tables[tableName]).where(where)\n\n return result\n}\n"],"names":["toSnakeCase","buildFindManyArgs","buildQuery","transform","deleteOne","collection","req","where","incomingWhere","db","sessions","transactionID","drizzle","collectionConfig","payload","collections","config","tableName","adapter","fields","findManyArgs","depth","docToDelete","query","findFirst","result","data","delete","tables"],"mappings":"AAGA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,iBAAiB,QAAQ,8BAA6B;AAC/D,OAAOC,gBAAgB,0BAAyB;AAChD,SAASC,SAAS,QAAQ,4BAA2B;AAErD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,OAAOC,aAAa,EAAE;IAEhE,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACJ,IAAIK,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMC,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACV,WAAW,CAACW,MAAM;IACpE,MAAMC,YAAYjB,YAAYK;IAE9B,MAAM,EAAEE,KAAK,EAAE,GAAG,MAAML,WAAW;QACjCgB,SAAS,IAAI;QACbC,QAAQN,iBAAiBM,MAAM;QAC/BF;QACAV,OAAOC;IACT;IAEA,MAAMY,eAAenB,kBAAkB;QACrCiB,SAAS,IAAI;QACbG,OAAO;QACPF,QAAQN,iBAAiBM,MAAM;QAC/BF;IACF;IAEAG,aAAab,KAAK,GAAGA;IAErB,MAAMe,cAAc,MAAMb,GAAGc,KAAK,CAACN,UAAU,CAACO,SAAS,CAACJ;IAExD,MAAMK,SAAStB,UAAU;QACvBa,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;QAC3BU,MAAMJ;QACNH,QAAQN,iBAAiBM,MAAM;IACjC;IAEA,MAAMV,GAAGkB,MAAM,CAAC,IAAI,CAACC,MAAM,CAACX,UAAU,EAAEV,KAAK,CAACA;IAE9C,OAAOkB;AACT,EAAC"}
|
package/dist/deleteVersions.js
CHANGED
@@ -28,4 +28,4 @@ export const deleteVersions = async function deleteVersion({ collection, locale,
|
|
28
28
|
return docs;
|
29
29
|
};
|
30
30
|
|
31
|
-
//# sourceMappingURL=
|
31
|
+
//# sourceMappingURL=deleteVersions.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions } from 'payload/database'\nimport type { PayloadRequest, SanitizedCollectionConfig } from 'payload/types'\n\nimport { inArray } from 'drizzle-orm'\nimport { buildVersionCollectionFields } from 'payload/versions'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const deleteVersions: DeleteVersions = async function deleteVersion(\n this: PostgresAdapter,\n { collection, locale, req = {} as PayloadRequest, where: where },\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n\n const tableName = `_${toSnakeCase(collection)}_v`\n const fields = buildVersionCollectionFields(collectionConfig)\n\n const { docs } = await findMany({\n adapter: this,\n fields,\n limit: 0,\n locale,\n page: 1,\n pagination: false,\n req,\n tableName,\n where,\n })\n\n const ids = []\n\n docs.forEach((doc) => {\n ids.push(doc.id)\n })\n\n if (ids.length > 0) {\n await db.delete(this.tables[tableName]).where(inArray(this.tables[tableName].id, ids))\n }\n\n return docs\n}\n"],"names":["inArray","buildVersionCollectionFields","toSnakeCase","findMany","deleteVersions","deleteVersion","collection","locale","req","where","db","sessions","transactionID","drizzle","collectionConfig","payload","collections","config","tableName","fields","docs","adapter","limit","page","pagination","ids","forEach","doc","push","id","length","delete","tables"],"mappings":"AAGA,SAASA,OAAO,QAAQ,cAAa;AACrC,SAASC,4BAA4B,QAAQ,mBAAkB;AAC/D,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,MAAMC,iBAAiC,eAAeC,cAE3D,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,OAAOA,KAAK,EAAE;IAEhE,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACH,IAAII,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACV,WAAW,CAACW,MAAM;IAE/F,MAAMC,YAAY,CAAC,CAAC,EAAEhB,YAAYI,YAAY,EAAE,CAAC;IACjD,MAAMa,SAASlB,6BAA6Ba;IAE5C,MAAM,EAAEM,IAAI,EAAE,GAAG,MAAMjB,SAAS;QAC9BkB,SAAS,IAAI;QACbF;QACAG,OAAO;QACPf;QACAgB,MAAM;QACNC,YAAY;QACZhB;QACAU;QACAT;IACF;IAEA,MAAMgB,MAAM,EAAE;IAEdL,KAAKM,OAAO,CAAC,CAACC;QACZF,IAAIG,IAAI,CAACD,IAAIE,EAAE;IACjB;IAEA,IAAIJ,IAAIK,MAAM,GAAG,GAAG;QAClB,MAAMpB,GAAGqB,MAAM,CAAC,IAAI,CAACC,MAAM,CAACd,UAAU,EAAET,KAAK,CAACT,QAAQ,IAAI,CAACgC,MAAM,CAACd,UAAU,CAACW,EAAE,EAAEJ;IACnF;IAEA,OAAOL;AACT,EAAC"}
|
package/dist/destroy.js
CHANGED
@@ -8,4 +8,4 @@ export const destroy = async function destroy() {
|
|
8
8
|
}
|
9
9
|
};
|
10
10
|
|
11
|
-
//# sourceMappingURL=
|
11
|
+
//# sourceMappingURL=destroy.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/destroy.ts"],"sourcesContent":["import type { Destroy } from 'payload/database'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { pushDevSchema } from './utilities/pushDevSchema.js'\n\nexport const destroy: Destroy = async function destroy(this: PostgresAdapter) {\n if (process.env.NODE_ENV !== 'production') {\n await pushDevSchema(this)\n } else {\n // TODO: this hangs test suite for some reason\n // await this.pool.end()\n }\n}\n"],"names":["pushDevSchema","destroy","process","env","NODE_ENV"],"mappings":"AAIA,SAASA,aAAa,QAAQ,+BAA8B;AAE5D,OAAO,MAAMC,UAAmB,eAAeA;IAC7C,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,MAAMJ,cAAc,IAAI;IAC1B,OAAO;IACL,8CAA8C;IAC9C,wBAAwB;IAC1B;AACF,EAAC"}
|
@@ -61,4 +61,4 @@ export const buildFindManyArgs = ({ adapter, depth, fields, tableName })=>{
|
|
61
61
|
return result;
|
62
62
|
};
|
63
63
|
|
64
|
-
//# sourceMappingURL=
|
64
|
+
//# sourceMappingURL=buildFindManyArgs.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/find/buildFindManyArgs.ts"],"sourcesContent":["import type { DBQueryConfig } from 'drizzle-orm'\nimport type { Field } from 'payload/types'\n\nimport type { PostgresAdapter } from '../types.js'\n\nimport { traverseFields } from './traverseFields.js'\n\ntype BuildFindQueryArgs = {\n adapter: PostgresAdapter\n depth: number\n fields: Field[]\n tableName: string\n}\n\nexport type Result = DBQueryConfig<'many', true, any, any>\n\n// Generate the Drizzle query for findMany based on\n// a collection field structure\nexport const buildFindManyArgs = ({\n adapter,\n depth,\n fields,\n tableName,\n}: BuildFindQueryArgs): Record<string, unknown> => {\n const result: Result = {\n with: {},\n }\n\n const _locales: Result = {\n columns: {\n id: false,\n _parentID: false,\n },\n }\n\n if (adapter.tables[`${tableName}_texts`]) {\n result.with._texts = {\n columns: {\n id: false,\n parent: false,\n },\n orderBy: ({ order }, { asc: ASC }) => [ASC(order)],\n }\n }\n\n if (adapter.tables[`${tableName}_numbers`]) {\n result.with._numbers = {\n columns: {\n id: false,\n parent: false,\n },\n orderBy: ({ order }, { asc: ASC }) => [ASC(order)],\n }\n }\n\n if (adapter.tables[`${tableName}_rels`]) {\n result.with._rels = {\n columns: {\n id: false,\n parent: false,\n },\n orderBy: ({ order }, { asc: ASC }) => [ASC(order)],\n }\n }\n\n if (adapter.tables[`${tableName}_locales`]) {\n result.with._locales = _locales\n }\n\n traverseFields({\n _locales,\n adapter,\n currentArgs: result,\n currentTableName: tableName,\n depth,\n fields,\n path: '',\n topLevelArgs: result,\n topLevelTableName: tableName,\n })\n\n return result\n}\n"],"names":["traverseFields","buildFindManyArgs","adapter","depth","fields","tableName","result","with","_locales","columns","id","_parentID","tables","_texts","parent","orderBy","order","asc","ASC","_numbers","_rels","currentArgs","currentTableName","path","topLevelArgs","topLevelTableName"],"mappings":"AAKA,SAASA,cAAc,QAAQ,sBAAqB;AAWpD,mDAAmD;AACnD,+BAA+B;AAC/B,OAAO,MAAMC,oBAAoB,CAAC,EAChCC,OAAO,EACPC,KAAK,EACLC,MAAM,EACNC,SAAS,EACU;IACnB,MAAMC,SAAiB;QACrBC,MAAM,CAAC;IACT;IAEA,MAAMC,WAAmB;QACvBC,SAAS;YACPC,IAAI;YACJC,WAAW;QACb;IACF;IAEA,IAAIT,QAAQU,MAAM,CAAC,CAAC,EAAEP,UAAU,MAAM,CAAC,CAAC,EAAE;QACxCC,OAAOC,IAAI,CAACM,MAAM,GAAG;YACnBJ,SAAS;gBACPC,IAAI;gBACJI,QAAQ;YACV;YACAC,SAAS,CAAC,EAAEC,KAAK,EAAE,EAAE,EAAEC,KAAKC,GAAG,EAAE,GAAK;oBAACA,IAAIF;iBAAO;QACpD;IACF;IAEA,IAAId,QAAQU,MAAM,CAAC,CAAC,EAAEP,UAAU,QAAQ,CAAC,CAAC,EAAE;QAC1CC,OAAOC,IAAI,CAACY,QAAQ,GAAG;YACrBV,SAAS;gBACPC,IAAI;gBACJI,QAAQ;YACV;YACAC,SAAS,CAAC,EAAEC,KAAK,EAAE,EAAE,EAAEC,KAAKC,GAAG,EAAE,GAAK;oBAACA,IAAIF;iBAAO;QACpD;IACF;IAEA,IAAId,QAAQU,MAAM,CAAC,CAAC,EAAEP,UAAU,KAAK,CAAC,CAAC,EAAE;QACvCC,OAAOC,IAAI,CAACa,KAAK,GAAG;YAClBX,SAAS;gBACPC,IAAI;gBACJI,QAAQ;YACV;YACAC,SAAS,CAAC,EAAEC,KAAK,EAAE,EAAE,EAAEC,KAAKC,GAAG,EAAE,GAAK;oBAACA,IAAIF;iBAAO;QACpD;IACF;IAEA,IAAId,QAAQU,MAAM,CAAC,CAAC,EAAEP,UAAU,QAAQ,CAAC,CAAC,EAAE;QAC1CC,OAAOC,IAAI,CAACC,QAAQ,GAAGA;IACzB;IAEAR,eAAe;QACbQ;QACAN;QACAmB,aAAaf;QACbgB,kBAAkBjB;QAClBF;QACAC;QACAmB,MAAM;QACNC,cAAclB;QACdmB,mBAAmBpB;IACrB;IAEA,OAAOC;AACT,EAAC"}
|
@@ -9,4 +9,4 @@
|
|
9
9
|
};
|
10
10
|
export { chainMethods };
|
11
11
|
|
12
|
-
//# sourceMappingURL=
|
12
|
+
//# sourceMappingURL=chainMethods.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/find/chainMethods.ts"],"sourcesContent":["export type ChainedMethods = {\n args: unknown[]\n method: string\n}[]\n\n/**\n * Call and returning methods that would normally be chained together but cannot be because of control logic\n * @param methods\n * @param query\n */\nconst chainMethods = ({ methods, query }): Promise<unknown> => {\n return methods.reduce((query, { args, method }) => {\n return query[method](...args)\n }, query)\n}\n\nexport { chainMethods }\n"],"names":["chainMethods","methods","query","reduce","args","method"],"mappings":"AAKA;;;;CAIC,GACD,MAAMA,eAAe,CAAC,EAAEC,OAAO,EAAEC,KAAK,EAAE;IACtC,OAAOD,QAAQE,MAAM,CAAC,CAACD,OAAO,EAAEE,IAAI,EAAEC,MAAM,EAAE;QAC5C,OAAOH,KAAK,CAACG,OAAO,IAAID;IAC1B,GAAGF;AACL;AAEA,SAASF,YAAY,GAAE"}
|
package/dist/find/findMany.js
CHANGED
@@ -182,4 +182,4 @@ export const findMany = async function find({ adapter, fields, limit: limitArg,
|
|
182
182
|
};
|
183
183
|
};
|
184
184
|
|
185
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9maW5kL2ZpbmRNYW55LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB0eXBlIHsgRmluZEFyZ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|
1
|
+
{"version":3,"sources":["../../src/find/findMany.ts"],"sourcesContent":["import type { FindArgs } from 'payload/database'\nimport type { Field, PayloadRequest, TypeWithID } from 'payload/types'\n\nimport { inArray, sql } from 'drizzle-orm'\n\nimport type { PostgresAdapter } from '../types.js'\nimport type { ChainedMethods } from './chainMethods.js'\n\nimport buildQuery from '../queries/buildQuery.js'\nimport { transform } from '../transform/read/index.js'\nimport { buildFindManyArgs } from './buildFindManyArgs.js'\nimport { chainMethods } from './chainMethods.js'\n\ntype Args = Omit<FindArgs, 'collection'> & {\n adapter: PostgresAdapter\n fields: Field[]\n tableName: string\n}\n\nexport const findMany = async function find({\n adapter,\n fields,\n limit: limitArg,\n locale,\n page = 1,\n pagination,\n req = {} as PayloadRequest,\n skip,\n sort,\n tableName,\n where: whereArg,\n}: Args) {\n const db = adapter.sessions[req.transactionID]?.db || adapter.drizzle\n const table = adapter.tables[tableName]\n\n const limit = limitArg ?? 10\n let totalDocs: number\n let totalPages: number\n let hasPrevPage: boolean\n let hasNextPage: boolean\n let pagingCounter: number\n let selectDistinctResult\n\n const { joinAliases, joins, orderBy, selectFields, where } = await buildQuery({\n adapter,\n fields,\n locale,\n sort,\n tableName,\n where: whereArg,\n })\n\n const orderedIDMap: Record<number | string, number> = {}\n let orderedIDs: (number | string)[]\n\n const selectDistinctMethods: ChainedMethods = []\n\n if (orderBy?.order && orderBy?.column) {\n selectDistinctMethods.push({\n args: [orderBy.order(orderBy.column)],\n method: 'orderBy',\n })\n }\n\n const findManyArgs = buildFindManyArgs({\n adapter,\n depth: 0,\n fields,\n tableName,\n })\n\n // only fetch IDs when a sort or where query is used that needs to be done on join tables, otherwise these can be done directly on the table in findMany\n if (Object.keys(joins).length > 0 || joinAliases.length > 0) {\n if (where) {\n selectDistinctMethods.push({ args: [where], method: 'where' })\n }\n\n joinAliases.forEach(({ condition, table }) => {\n selectDistinctMethods.push({\n args: [table, condition],\n method: 'leftJoin',\n })\n })\n\n Object.entries(joins).forEach(([joinTable, condition]) => {\n if (joinTable) {\n selectDistinctMethods.push({\n args: [adapter.tables[joinTable], condition],\n method: 'leftJoin',\n })\n }\n })\n\n selectDistinctMethods.push({ args: [skip || (page - 1) * limit], method: 'offset' })\n selectDistinctMethods.push({ args: [limit === 0 ? undefined : limit], method: 'limit' })\n\n selectDistinctResult = await chainMethods({\n methods: selectDistinctMethods,\n query: db.selectDistinct(selectFields).from(table),\n })\n\n if (selectDistinctResult.length === 0) {\n return {\n docs: [],\n hasNextPage: false,\n hasPrevPage: false,\n limit,\n nextPage: null,\n page: 1,\n pagingCounter: 0,\n prevPage: null,\n totalDocs: 0,\n totalPages: 0,\n }\n }\n // set the id in an object for sorting later\n selectDistinctResult.forEach(({ id }, i) => {\n orderedIDMap[id as number | string] = i\n })\n orderedIDs = Object.keys(orderedIDMap)\n findManyArgs.where = inArray(adapter.tables[tableName].id, orderedIDs)\n } else {\n findManyArgs.limit = limitArg === 0 ? undefined : limitArg\n\n const offset = skip || (page - 1) * limitArg\n\n if (!Number.isNaN(offset)) findManyArgs.offset = offset\n\n if (where) {\n findManyArgs.where = where\n }\n findManyArgs.orderBy = orderBy.order(orderBy.column)\n }\n\n const findPromise = db.query[tableName].findMany(findManyArgs)\n\n if (pagination !== false && (orderedIDs ? orderedIDs?.length >= limit : true)) {\n const selectCountMethods: ChainedMethods = []\n\n joinAliases.forEach(({ condition, table }) => {\n selectCountMethods.push({\n args: [table, condition],\n method: 'leftJoin',\n })\n })\n\n Object.entries(joins).forEach(([joinTable, condition]) => {\n if (joinTable) {\n selectCountMethods.push({\n args: [adapter.tables[joinTable], condition],\n method: 'leftJoin',\n })\n }\n })\n\n const countResult = await chainMethods({\n methods: selectCountMethods,\n query: db\n .select({\n count: sql<number>`count\n (DISTINCT ${adapter.tables[tableName].id})`,\n })\n .from(table)\n .where(where),\n })\n totalDocs = Number(countResult[0].count)\n totalPages = typeof limit === 'number' && limit !== 0 ? Math.ceil(totalDocs / limit) : 1\n hasPrevPage = page > 1\n hasNextPage = totalPages > page\n pagingCounter = (page - 1) * limit + 1\n }\n\n const rawDocs = await findPromise\n // sort rawDocs from selectQuery\n if (Object.keys(orderedIDMap).length > 0) {\n rawDocs.sort((a, b) => orderedIDMap[a.id] - orderedIDMap[b.id])\n }\n\n if (pagination === false || !totalDocs) {\n totalDocs = rawDocs.length\n totalPages = 1\n pagingCounter = 1\n hasPrevPage = false\n hasNextPage = false\n }\n\n const docs = rawDocs.map((data: TypeWithID) => {\n return transform({\n config: adapter.payload.config,\n data,\n fields,\n })\n })\n\n return {\n docs,\n hasNextPage,\n hasPrevPage,\n limit,\n nextPage: hasNextPage ? page + 1 : null,\n page,\n pagingCounter,\n prevPage: hasPrevPage ? page - 1 : null,\n totalDocs,\n totalPages,\n }\n}\n"],"names":["inArray","sql","buildQuery","transform","buildFindManyArgs","chainMethods","findMany","find","adapter","fields","limit","limitArg","locale","page","pagination","req","skip","sort","tableName","where","whereArg","db","sessions","transactionID","drizzle","table","tables","totalDocs","totalPages","hasPrevPage","hasNextPage","pagingCounter","selectDistinctResult","joinAliases","joins","orderBy","selectFields","orderedIDMap","orderedIDs","selectDistinctMethods","order","column","push","args","method","findManyArgs","depth","Object","keys","length","forEach","condition","entries","joinTable","undefined","methods","query","selectDistinct","from","docs","nextPage","prevPage","id","i","offset","Number","isNaN","findPromise","selectCountMethods","countResult","select","count","Math","ceil","rawDocs","a","b","map","data","config","payload"],"mappings":"AAGA,SAASA,OAAO,EAAEC,GAAG,QAAQ,cAAa;AAK1C,OAAOC,gBAAgB,2BAA0B;AACjD,SAASC,SAAS,QAAQ,6BAA4B;AACtD,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,YAAY,QAAQ,oBAAmB;AAQhD,OAAO,MAAMC,WAAW,eAAeC,KAAK,EAC1CC,OAAO,EACPC,MAAM,EACNC,OAAOC,QAAQ,EACfC,MAAM,EACNC,OAAO,CAAC,EACRC,UAAU,EACVC,MAAM,CAAC,CAAmB,EAC1BC,IAAI,EACJC,IA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EAAE,CAAC;IAChE;IAEA,IAAIhD,eAAe,SAAS,CAACa,WAAW;QACtCA,YAAY+C,QAAQzB,MAAM;QAC1BrB,aAAa;QACbG,gBAAgB;QAChBF,cAAc;QACdC,cAAc;IAChB;IAEA,MAAM6B,OAAOe,QAAQG,GAAG,CAAC,CAACC;QACxB,OAAO3E,UAAU;YACf4E,QAAQvE,QAAQwE,OAAO,CAACD,MAAM;YAC9BD;YACArE;QACF;IACF;IAEA,OAAO;QACLkD;QACA7B;QACAD;QACAnB;QACAkD,UAAU9B,cAAcjB,OAAO,IAAI;QACnCA;QACAkB;QACA8B,UAAUhC,cAAchB,OAAO,IAAI;QACnCc;QACAC;IACF;AACF,EAAC"}
|
@@ -132,4 +132,4 @@ export const traverseFields = ({ _locales, adapter, currentArgs, currentTableNam
|
|
132
132
|
return topLevelArgs;
|
133
133
|
};
|
134
134
|
|
135
|
-
//# sourceMappingURL=
|
135
|
+
//# sourceMappingURL=traverseFields.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/find/traverseFields.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Field } from 'payload/types'\n\nimport { fieldAffectsData, tabHasName } from 'payload/types'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../types.js'\nimport type { Result } from './buildFindManyArgs.js'\n\ntype TraverseFieldArgs = {\n _locales: Record<string, unknown>\n adapter: PostgresAdapter\n currentArgs: Record<string, unknown>\n currentTableName: string\n depth?: number\n fields: Field[]\n path: string\n topLevelArgs: Record<string, unknown>\n topLevelTableName: string\n}\n\nexport const traverseFields = ({\n _locales,\n adapter,\n currentArgs,\n currentTableName,\n depth,\n fields,\n path,\n topLevelArgs,\n topLevelTableName,\n}: TraverseFieldArgs) => {\n fields.forEach((field) => {\n if (field.type === 'collapsible' || field.type === 'row') {\n traverseFields({\n _locales,\n adapter,\n currentArgs,\n currentTableName,\n depth,\n fields: field.fields,\n path,\n topLevelArgs,\n topLevelTableName,\n })\n\n return\n }\n\n if (field.type === 'tabs') {\n field.tabs.forEach((tab) => {\n const tabPath = tabHasName(tab) ? `${path}${tab.name}_` : path\n\n traverseFields({\n _locales,\n adapter,\n currentArgs,\n currentTableName,\n depth,\n fields: tab.fields,\n path: tabPath,\n topLevelArgs,\n topLevelTableName,\n })\n })\n\n return\n }\n\n if (fieldAffectsData(field)) {\n switch (field.type) {\n case 'array': {\n const withArray: Result = {\n columns: {\n _parentID: false,\n },\n orderBy: ({ _order }, { asc }) => [asc(_order)],\n with: {},\n }\n\n const arrayTableName = `${currentTableName}_${path}${toSnakeCase(field.name)}`\n\n if (adapter.tables[`${arrayTableName}_locales`]) withArray.with._locales = _locales\n currentArgs.with[`${path}${field.name}`] = withArray\n\n traverseFields({\n _locales,\n adapter,\n currentArgs: withArray,\n currentTableName: arrayTableName,\n depth,\n fields: field.fields,\n path: '',\n topLevelArgs,\n topLevelTableName,\n })\n\n break\n }\n\n case 'select': {\n if (field.hasMany) {\n const withSelect: Result = {\n columns: {\n id: false,\n order: false,\n parent: false,\n },\n orderBy: ({ order }, { asc }) => [asc(order)],\n }\n\n currentArgs.with[`${path}${field.name}`] = withSelect\n }\n\n break\n }\n\n case 'blocks':\n field.blocks.forEach((block) => {\n const blockKey = `_blocks_${block.slug}`\n\n if (!topLevelArgs[blockKey]) {\n const withBlock: Result = {\n columns: {\n _parentID: false,\n },\n orderBy: ({ _order }, { asc }) => [asc(_order)],\n with: {},\n }\n\n const tableName = `${topLevelTableName}_blocks_${toSnakeCase(block.slug)}`\n\n if (adapter.tables[`${tableName}_locales`]) withBlock.with._locales = _locales\n topLevelArgs.with[blockKey] = withBlock\n\n traverseFields({\n _locales,\n adapter,\n currentArgs: withBlock,\n currentTableName: tableName,\n depth,\n fields: block.fields,\n path: '',\n topLevelArgs,\n topLevelTableName,\n })\n }\n })\n\n break\n\n case 'group':\n traverseFields({\n _locales,\n adapter,\n currentArgs,\n currentTableName,\n depth,\n fields: field.fields,\n path: `${path}${field.name}_`,\n topLevelArgs,\n topLevelTableName,\n })\n\n break\n\n default: {\n break\n }\n }\n }\n })\n\n return topLevelArgs\n}\n"],"names":["fieldAffectsData","tabHasName","toSnakeCase","traverseFields","_locales","adapter","currentArgs","currentTableName","depth","fields","path","topLevelArgs","topLevelTableName","forEach","field","type","tabs","tab","tabPath","name","withArray","columns","_parentID","orderBy","_order","asc","with","arrayTableName","tables","hasMany","withSelect","id","order","parent","blocks","block","blockKey","slug","withBlock","tableName"],"mappings":"AAAA,oCAAoC,GAGpC,SAASA,gBAAgB,EAAEC,UAAU,QAAQ,gBAAe;AAC5D,OAAOC,iBAAiB,gBAAe;AAiBvC,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,QAAQ,EACRC,OAAO,EACPC,WAAW,EACXC,gBAAgB,EAChBC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,YAAY,EACZC,iBAAiB,EACC;IAClBH,OAAOI,OAAO,CAAC,CAACC;QACd,IAAIA,MAAMC,IAAI,KAAK,iBAAiBD,MAAMC,IAAI,KAAK,OAAO;YACxDZ,eAAe;gBACbC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC,QAAQK,MAAML,MAAM;gBACpBC;gBACAC;gBACAC;YACF;YAEA;QACF;QAEA,IAAIE,MAAMC,IAAI,KAAK,QAAQ;YACzBD,MAAME,IAAI,CAACH,OAAO,CAAC,CAACI;gBAClB,MAAMC,UAAUjB,WAAWgB,OAAO,CAAC,EAAEP,KAAK,EAAEO,IAAIE,IAAI,CAAC,CAAC,CAAC,GAAGT;gBAE1DP,eAAe;oBACbC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC,QAAQQ,IAAIR,MAAM;oBAClBC,MAAMQ;oBACNP;oBACAC;gBACF;YACF;YAEA;QACF;QAEA,IAAIZ,iBAAiBc,QAAQ;YAC3B,OAAQA,MAAMC,IAAI;gBAChB,KAAK;oBAAS;wBACZ,MAAMK,YAAoB;4BACxBC,SAAS;gCACPC,WAAW;4BACb;4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CAACA,IAAID;qCAAQ;gCAC/CE,MAAM,CAAC;4BACT;4BAEA,MAAMa,YAAY,CAAC,EAAE3B,kBAAkB,QAAQ,EAAEV,YAAYiC,MAAME,IAAI,EAAE,CAAC;4BAE1E,IAAIhC,QAAQuB,MAAM,CAAC,CAAC,EAAEW,UAAU,QAAQ,CAAC,CAAC,EAAED,UAAUZ,IAAI,CAACtB,QAAQ,GAAGA;4BACtEO,aAAae,IAAI,CAACU,SAAS,GAAGE;4BAE9BnC,eAAe;gCACbC;gCACAC;gCACAC,aAAagC;gCACb/B,kBAAkBgC;gCAClB/B;gCACAC,QAAQ0B,MAAM1B,MAAM;gCACpBC,MAAM;gCACNC;gCACAC;4BACF;wBACF;oBACF;oBAEA;gBAEF,KAAK;oBACHT,eAAe;wBACbC;wBACAC;wBACAC;wBACAC;wBACAC;wBACAC,QAAQK,MAAML,MAAM;wBACpBC,MAAM,CAAC,EAAEA,KAAK,EAAEI,MAAMK,IAAI,CAAC,CAAC,CAAC;wBAC7BR;wBACAC;oBACF;oBAEA;gBAEF;oBAAS;wBACP;oBACF;YACF;QACF;IACF;IAEA,OAAOD;AACT,EAAC"}
|
package/dist/find.js
CHANGED
@@ -17,4 +17,4 @@ export const find = async function find({ collection, limit: limitArg, locale, p
|
|
17
17
|
});
|
18
18
|
};
|
19
19
|
|
20
|
-
//# sourceMappingURL=
|
20
|
+
//# sourceMappingURL=find.js.map
|
package/dist/find.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { Find } from 'payload/database'\nimport type { PayloadRequest, SanitizedCollectionConfig } from 'payload/types'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const find: Find = async function find(\n this: PostgresAdapter,\n {\n collection,\n limit: limitArg,\n locale,\n page = 1,\n pagination,\n req = {} as PayloadRequest,\n sort: sortArg,\n where: whereArg,\n },\n) {\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n const sort = typeof sortArg === 'string' ? sortArg : collectionConfig.defaultSort\n\n return findMany({\n adapter: this,\n fields: collectionConfig.fields,\n limit: limitArg,\n locale,\n page,\n pagination,\n req,\n sort,\n tableName: toSnakeCase(collection),\n where: whereArg,\n })\n}\n"],"names":["toSnakeCase","findMany","find","collection","limit","limitArg","locale","page","pagination","req","sort","sortArg","where","whereArg","collectionConfig","payload","collections","config","defaultSort","adapter","fields","tableName"],"mappings":"AAGA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,MAAMC,OAAa,eAAeA,KAEvC,EACEC,UAAU,EACVC,OAAOC,QAAQ,EACfC,MAAM,EACNC,OAAO,CAAC,EACRC,UAAU,EACVC,MAAM,CAAC,CAAmB,EAC1BC,MAAMC,OAAO,EACbC,OAAOC,QAAQ,EAChB;IAED,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACb,WAAW,CAACc,MAAM;IAC/F,MAAMP,OAAO,OAAOC,YAAY,WAAWA,UAAUG,iBAAiBI,WAAW;IAEjF,OAAOjB,SAAS;QACdkB,SAAS,IAAI;QACbC,QAAQN,iBAAiBM,MAAM;QAC/BhB,OAAOC;QACPC;QACAC;QACAC;QACAC;QACAC;QACAW,WAAWrB,YAAYG;QACvBS,OAAOC;IACT;AACF,EAAC"}
|
package/dist/findGlobal.js
CHANGED
@@ -20,4 +20,4 @@ export const findGlobal = async function findGlobal({ locale, req, slug, where }
|
|
20
20
|
return {};
|
21
21
|
};
|
22
22
|
|
23
|
-
//# sourceMappingURL=
|
23
|
+
//# sourceMappingURL=findGlobal.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { FindGlobal } from 'payload/database'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const findGlobal: FindGlobal = async function findGlobal(\n this: PostgresAdapter,\n { locale, req, slug, where },\n) {\n const globalConfig = this.payload.globals.config.find((config) => config.slug === slug)\n const tableName = toSnakeCase(slug)\n\n const {\n docs: [doc],\n } = await findMany({\n adapter: this,\n fields: globalConfig.fields,\n limit: 1,\n locale,\n pagination: false,\n req,\n tableName,\n where,\n })\n\n if (doc) {\n doc.globalType = slug\n return doc\n }\n\n return {}\n}\n"],"names":["toSnakeCase","findMany","findGlobal","locale","req","slug","where","globalConfig","payload","globals","config","find","tableName","docs","doc","adapter","fields","limit","pagination","globalType"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,MAAM,EAAEC,GAAG,EAAEC,IAAI,EAAEC,KAAK,EAAE;IAE5B,MAAMC,eAAe,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAACD,SAAWA,OAAOL,IAAI,KAAKA;IAClF,MAAMO,YAAYZ,YAAYK;IAE9B,MAAM,EACJQ,MAAM,CAACC,IAAI,EACZ,GAAG,MAAMb,SAAS;QACjBc,SAAS,IAAI;QACbC,QAAQT,aAAaS,MAAM;QAC3BC,OAAO;QACPd;QACAe,YAAY;QACZd;QACAQ;QACAN;IACF;IAEA,IAAIQ,KAAK;QACPA,IAAIK,UAAU,GAAGd;QACjB,OAAOS;IACT;IAEA,OAAO,CAAC;AACV,EAAC"}
|
@@ -21,4 +21,4 @@ export const findGlobalVersions = async function findGlobalVersions({ global, li
|
|
21
21
|
});
|
22
22
|
};
|
23
23
|
|
24
|
-
//# sourceMappingURL=
|
24
|
+
//# sourceMappingURL=findGlobalVersions.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { FindGlobalVersions } from 'payload/database'\nimport type { PayloadRequest, SanitizedGlobalConfig } from 'payload/types'\n\nimport { buildVersionGlobalFields } from 'payload/versions'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: PostgresAdapter,\n {\n global,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const globalConfig: SanitizedGlobalConfig = this.payload.globals.config.find(\n ({ slug }) => slug === global,\n )\n const sort = typeof sortArg === 'string' ? sortArg : '-createdAt'\n\n const tableName = `_${toSnakeCase(global)}_v`\n const fields = buildVersionGlobalFields(globalConfig)\n\n return findMany({\n adapter: this,\n fields,\n limit,\n locale,\n page,\n pagination,\n req,\n skip,\n sort,\n tableName,\n where,\n })\n}\n"],"names":["buildVersionGlobalFields","toSnakeCase","findMany","findGlobalVersions","global","limit","locale","page","pagination","req","skip","sort","sortArg","where","globalConfig","payload","globals","config","find","slug","tableName","fields","adapter"],"mappings":"AAGA,SAASA,wBAAwB,QAAQ,mBAAkB;AAC3D,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,MAAMC,qBAAyC,eAAeA,mBAEnE,EACEC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAAmB,EAC1BC,IAAI,EACJC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,eAAsC,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAC1E,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASf;IAEzB,MAAMO,OAAO,OAAOC,YAAY,WAAWA,UAAU;IAErD,MAAMQ,YAAY,CAAC,CAAC,EAAEnB,YAAYG,QAAQ,EAAE,CAAC;IAC7C,MAAMiB,SAASrB,yBAAyBc;IAExC,OAAOZ,SAAS;QACdoB,SAAS,IAAI;QACbD;QACAhB;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAS;QACAP;IACF;AACF,EAAC"}
|
package/dist/findOne.js
CHANGED
@@ -17,4 +17,4 @@ export async function findOne({ collection, locale, req = {}, where: incomingWhe
|
|
17
17
|
return docs?.[0] || null;
|
18
18
|
}
|
19
19
|
|
20
|
-
//# sourceMappingURL=
|
20
|
+
//# sourceMappingURL=findOne.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type { FindOneArgs } from 'payload/database'\nimport type { PayloadRequest, SanitizedCollectionConfig, TypeWithID } from 'payload/types'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport async function findOne<T extends TypeWithID>(\n this: PostgresAdapter,\n { collection, locale, req = {} as PayloadRequest, where: incomingWhere }: FindOneArgs,\n): Promise<T> {\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n\n const { docs } = await findMany({\n adapter: this,\n fields: collectionConfig.fields,\n limit: 1,\n locale,\n page: 1,\n pagination: false,\n req,\n sort: undefined,\n tableName: toSnakeCase(collection),\n where: incomingWhere,\n })\n\n return docs?.[0] || null\n}\n"],"names":["toSnakeCase","findMany","findOne","collection","locale","req","where","incomingWhere","collectionConfig","payload","collections","config","docs","adapter","fields","limit","page","pagination","sort","undefined","tableName"],"mappings":"AAGA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,eAAeC,QAEpB,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,OAAOC,aAAa,EAAe;IAErF,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACP,WAAW,CAACQ,MAAM;IAE/F,MAAM,EAAEC,IAAI,EAAE,GAAG,MAAMX,SAAS;QAC9BY,SAAS,IAAI;QACbC,QAAQN,iBAAiBM,MAAM;QAC/BC,OAAO;QACPX;QACAY,MAAM;QACNC,YAAY;QACZZ;QACAa,MAAMC;QACNC,WAAWpB,YAAYG;QACvBG,OAAOC;IACT;IAEA,OAAOK,MAAM,CAAC,EAAE,IAAI;AACtB"}
|
package/dist/findVersions.js
CHANGED
@@ -21,4 +21,4 @@ export const findVersions = async function findVersions({ collection, limit, loc
|
|
21
21
|
});
|
22
22
|
};
|
23
23
|
|
24
|
-
//# sourceMappingURL=
|
24
|
+
//# sourceMappingURL=findVersions.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { FindVersions } from 'payload/database'\nimport type { PayloadRequest, SanitizedCollectionConfig } from 'payload/types'\n\nimport { buildVersionCollectionFields } from 'payload/versions'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const findVersions: FindVersions = async function findVersions(\n this: PostgresAdapter,\n {\n collection,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n const sort = typeof sortArg === 'string' ? sortArg : collectionConfig.defaultSort\n\n const tableName = `_${toSnakeCase(collection)}_v`\n const fields = buildVersionCollectionFields(collectionConfig)\n\n return findMany({\n adapter: this,\n fields,\n limit,\n locale,\n page,\n pagination,\n req,\n skip,\n sort,\n tableName,\n where,\n })\n}\n"],"names":["buildVersionCollectionFields","toSnakeCase","findMany","findVersions","collection","limit","locale","page","pagination","req","skip","sort","sortArg","where","collectionConfig","payload","collections","config","defaultSort","tableName","fields","adapter"],"mappings":"AAGA,SAASA,4BAA4B,QAAQ,mBAAkB;AAC/D,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EACEC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAAmB,EAC1BC,IAAI,EACJC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACZ,WAAW,CAACa,MAAM;IAC/F,MAAMN,OAAO,OAAOC,YAAY,WAAWA,UAAUE,iBAAiBI,WAAW;IAEjF,MAAMC,YAAY,CAAC,CAAC,EAAElB,YAAYG,YAAY,EAAE,CAAC;IACjD,MAAMgB,SAASpB,6BAA6Bc;IAE5C,OAAOZ,SAAS;QACdmB,SAAS,IAAI;QACbD;QACAf;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAQ;QACAN;IACF;AACF,EAAC"}
|
package/dist/index.js
CHANGED
@@ -128,4 +128,4 @@ export function postgresAdapter(args) {
|
|
128
128
|
return srcDir;
|
129
129
|
}
|
130
130
|
|
131
|
-
//# sourceMappingURL=
|
131
|
+
//# sourceMappingURL=index.js.map
|