@payloadcms/db-postgres 3.0.0-canary.fb81f02 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. package/dist/connect.d.ts.map +1 -1
  2. package/dist/connect.js +67 -5
  3. package/dist/connect.js.map +1 -1
  4. package/dist/index.d.ts +2 -3
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +33 -21
  7. package/dist/index.js.map +1 -1
  8. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -1
  9. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +72 -67
  10. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -1
  11. package/dist/predefinedMigrations/v2-v3/index.js +2 -2
  12. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -1
  13. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -1
  14. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js +9 -3
  15. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -1
  16. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -1
  17. package/dist/predefinedMigrations/v2-v3/traverseFields.js +32 -32
  18. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -1
  19. package/dist/types.d.ts +31 -115
  20. package/dist/types.d.ts.map +1 -1
  21. package/dist/types.js.map +1 -1
  22. package/license.md +22 -0
  23. package/package.json +20 -12
  24. package/dist/connectionHelpers/nodePostgres.d.ts +0 -11
  25. package/dist/connectionHelpers/nodePostgres.d.ts.map +0 -1
  26. package/dist/connectionHelpers/nodePostgres.js +0 -6
  27. package/dist/connectionHelpers/nodePostgres.js.map +0 -1
  28. package/dist/countDistinct.d.ts +0 -3
  29. package/dist/countDistinct.d.ts.map +0 -1
  30. package/dist/countDistinct.js +0 -24
  31. package/dist/countDistinct.js.map +0 -1
  32. package/dist/createJSONQuery/convertPathToJSONTraversal.d.ts +0 -2
  33. package/dist/createJSONQuery/convertPathToJSONTraversal.d.ts.map +0 -1
  34. package/dist/createJSONQuery/convertPathToJSONTraversal.js +0 -14
  35. package/dist/createJSONQuery/convertPathToJSONTraversal.js.map +0 -1
  36. package/dist/createJSONQuery/formatJSONPathSegment.d.ts +0 -2
  37. package/dist/createJSONQuery/formatJSONPathSegment.d.ts.map +0 -1
  38. package/dist/createJSONQuery/formatJSONPathSegment.js +0 -5
  39. package/dist/createJSONQuery/formatJSONPathSegment.js.map +0 -1
  40. package/dist/createJSONQuery/index.d.ts +0 -10
  41. package/dist/createJSONQuery/index.d.ts.map +0 -1
  42. package/dist/createJSONQuery/index.js +0 -54
  43. package/dist/createJSONQuery/index.js.map +0 -1
  44. package/dist/createMigration.d.ts +0 -3
  45. package/dist/createMigration.d.ts.map +0 -1
  46. package/dist/createMigration.js +0 -91
  47. package/dist/createMigration.js.map +0 -1
  48. package/dist/defaultSnapshot.d.ts +0 -3
  49. package/dist/defaultSnapshot.d.ts.map +0 -1
  50. package/dist/defaultSnapshot.js +0 -17
  51. package/dist/defaultSnapshot.js.map +0 -1
  52. package/dist/deleteWhere.d.ts +0 -3
  53. package/dist/deleteWhere.d.ts.map +0 -1
  54. package/dist/deleteWhere.js +0 -6
  55. package/dist/deleteWhere.js.map +0 -1
  56. package/dist/dropDatabase.d.ts +0 -3
  57. package/dist/dropDatabase.d.ts.map +0 -1
  58. package/dist/dropDatabase.js +0 -9
  59. package/dist/dropDatabase.js.map +0 -1
  60. package/dist/execute.d.ts +0 -3
  61. package/dist/execute.d.ts.map +0 -1
  62. package/dist/execute.js +0 -11
  63. package/dist/execute.js.map +0 -1
  64. package/dist/getMigrationTemplate.d.ts +0 -4
  65. package/dist/getMigrationTemplate.d.ts.map +0 -1
  66. package/dist/getMigrationTemplate.js +0 -13
  67. package/dist/getMigrationTemplate.js.map +0 -1
  68. package/dist/init.d.ts +0 -3
  69. package/dist/init.d.ts.map +0 -1
  70. package/dist/init.js +0 -83
  71. package/dist/init.js.map +0 -1
  72. package/dist/insert.d.ts +0 -3
  73. package/dist/insert.d.ts.map +0 -1
  74. package/dist/insert.js +0 -12
  75. package/dist/insert.js.map +0 -1
  76. package/dist/requireDrizzleKit.d.ts +0 -3
  77. package/dist/requireDrizzleKit.d.ts.map +0 -1
  78. package/dist/requireDrizzleKit.js +0 -5
  79. package/dist/requireDrizzleKit.js.map +0 -1
  80. package/dist/schema/build.d.ts +0 -34
  81. package/dist/schema/build.d.ts.map +0 -1
  82. package/dist/schema/build.js +0 -369
  83. package/dist/schema/build.js.map +0 -1
  84. package/dist/schema/createIndex.d.ts +0 -12
  85. package/dist/schema/createIndex.d.ts.map +0 -1
  86. package/dist/schema/createIndex.js +0 -18
  87. package/dist/schema/createIndex.js.map +0 -1
  88. package/dist/schema/idToUUID.d.ts +0 -3
  89. package/dist/schema/idToUUID.d.ts.map +0 -1
  90. package/dist/schema/idToUUID.js +0 -11
  91. package/dist/schema/idToUUID.js.map +0 -1
  92. package/dist/schema/parentIDColumnMap.d.ts +0 -4
  93. package/dist/schema/parentIDColumnMap.d.ts.map +0 -1
  94. package/dist/schema/parentIDColumnMap.js +0 -9
  95. package/dist/schema/parentIDColumnMap.js.map +0 -1
  96. package/dist/schema/setColumnID.d.ts +0 -11
  97. package/dist/schema/setColumnID.d.ts.map +0 -1
  98. package/dist/schema/setColumnID.js +0 -24
  99. package/dist/schema/setColumnID.js.map +0 -1
  100. package/dist/schema/traverseFields.d.ts +0 -36
  101. package/dist/schema/traverseFields.d.ts.map +0 -1
  102. package/dist/schema/traverseFields.js +0 -613
  103. package/dist/schema/traverseFields.js.map +0 -1
  104. package/dist/schema/withDefault.d.ts +0 -4
  105. package/dist/schema/withDefault.d.ts.map +0 -1
  106. package/dist/schema/withDefault.js +0 -10
  107. package/dist/schema/withDefault.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAMtC,eAAO,MAAM,OAAO,EAAE,OAgDrB,CAAA"}
1
+ {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAW,MAAM,SAAS,CAAA;AA6C/C,eAAO,MAAM,OAAO,EAAE,OA0ErB,CAAA"}
package/dist/connect.js CHANGED
@@ -1,4 +1,41 @@
1
1
  import { pushDevSchema } from '@payloadcms/drizzle';
2
+ import { drizzle } from 'drizzle-orm/node-postgres';
3
+ import pg from 'pg';
4
+ const connectWithReconnect = async function({ adapter, payload, reconnect = false }) {
5
+ let result;
6
+ if (!reconnect) {
7
+ result = await adapter.pool.connect();
8
+ } else {
9
+ try {
10
+ result = await adapter.pool.connect();
11
+ } catch (ignore) {
12
+ setTimeout(()=>{
13
+ payload.logger.info('Reconnecting to postgres');
14
+ void connectWithReconnect({
15
+ adapter,
16
+ payload,
17
+ reconnect: true
18
+ });
19
+ }, 1000);
20
+ }
21
+ }
22
+ if (!result) {
23
+ return;
24
+ }
25
+ result.prependListener('error', (err)=>{
26
+ try {
27
+ if (err.code === 'ECONNRESET') {
28
+ void connectWithReconnect({
29
+ adapter,
30
+ payload,
31
+ reconnect: true
32
+ });
33
+ }
34
+ } catch (ignore) {
35
+ // swallow error
36
+ }
37
+ });
38
+ };
2
39
  export const connect = async function connect(options = {
3
40
  hotReload: false
4
41
  }) {
@@ -10,12 +47,19 @@ export const connect = async function connect(options = {
10
47
  ...this.enums
11
48
  };
12
49
  try {
50
+ if (!this.pool) {
51
+ this.pool = new pg.Pool(this.poolOptions);
52
+ await connectWithReconnect({
53
+ adapter: this,
54
+ payload: this.payload
55
+ });
56
+ }
13
57
  const logger = this.logger || false;
14
- const { drizzle } = await this.getDrizzle({
58
+ this.drizzle = drizzle({
59
+ client: this.pool,
15
60
  logger,
16
61
  schema: this.schema
17
62
  });
18
- this.drizzle = drizzle;
19
63
  if (!hotReload) {
20
64
  if (process.env.PAYLOAD_DROP_DATABASE === 'true') {
21
65
  this.payload.logger.info(`---- DROPPING TABLES SCHEMA(${this.schemaName || 'public'}) ----`);
@@ -26,15 +70,33 @@ export const connect = async function connect(options = {
26
70
  }
27
71
  }
28
72
  } catch (err) {
29
- this.payload.logger.error(`Error: cannot connect to Postgres. Details: ${err.message}`, err);
30
- if (typeof this.rejectInitializing === 'function') this.rejectInitializing();
73
+ if (err.message?.match(/database .* does not exist/i) && !this.disableCreateDatabase) {
74
+ // capitalize first char of the err msg
75
+ this.payload.logger.info(`${err.message.charAt(0).toUpperCase() + err.message.slice(1)}, creating...`);
76
+ const isCreated = await this.createDatabase();
77
+ if (isCreated) {
78
+ await this.connect(options);
79
+ return;
80
+ }
81
+ } else {
82
+ this.payload.logger.error({
83
+ err,
84
+ msg: `Error: cannot connect to Postgres. Details: ${err.message}`
85
+ });
86
+ }
87
+ if (typeof this.rejectInitializing === 'function') {
88
+ this.rejectInitializing();
89
+ }
31
90
  process.exit(1);
32
91
  }
92
+ await this.createExtensions();
33
93
  // Only push schema if not in production
34
94
  if (process.env.NODE_ENV !== 'production' && process.env.PAYLOAD_MIGRATING !== 'true' && this.push !== false) {
35
95
  await pushDevSchema(this);
36
96
  }
37
- if (typeof this.resolveInitializing === 'function') this.resolveInitializing();
97
+ if (typeof this.resolveInitializing === 'function') {
98
+ this.resolveInitializing();
99
+ }
38
100
  if (process.env.NODE_ENV === 'production' && this.prodMigrations) {
39
101
  await this.migrate({
40
102
  migrations: this.prodMigrations
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { DrizzleAdapter } from '@payloadcms/drizzle/types'\nimport type { Connect } from 'payload'\n\nimport { pushDevSchema } from '@payloadcms/drizzle'\n\nimport type { PostgresAdapter } from './types.js'\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 pgSchema: this.pgSchema,\n ...this.tables,\n ...this.relations,\n ...this.enums,\n }\n\n try {\n const logger = this.logger || false\n\n const { drizzle } = await this.getDrizzle({ logger, schema: this.schema })\n this.drizzle = drizzle\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 (err) {\n this.payload.logger.error(`Error: cannot connect to Postgres. Details: ${err.message}`, err)\n if (typeof this.rejectInitializing === 'function') this.rejectInitializing()\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 await pushDevSchema(this as unknown as DrizzleAdapter)\n }\n\n if (typeof this.resolveInitializing === 'function') this.resolveInitializing()\n\n if (process.env.NODE_ENV === 'production' && this.prodMigrations) {\n await this.migrate({ migrations: this.prodMigrations })\n }\n}\n"],"names":["pushDevSchema","connect","options","hotReload","schema","pgSchema","tables","relations","enums","logger","drizzle","getDrizzle","process","env","PAYLOAD_DROP_DATABASE","payload","info","schemaName","dropDatabase","adapter","err","error","message","rejectInitializing","exit","NODE_ENV","PAYLOAD_MIGRATING","push","resolveInitializing","prodMigrations","migrate","migrations"],"mappings":"AAGA,SAASA,aAAa,QAAQ,sBAAqB;AAInD,OAAO,MAAMC,UAAmB,eAAeA,QAE7CC,UAAU;IACRC,WAAW;AACb,CAAC;IAED,MAAM,EAAEA,SAAS,EAAE,GAAGD;IAEtB,IAAI,CAACE,MAAM,GAAG;QACZC,UAAU,IAAI,CAACA,QAAQ;QACvB,GAAG,IAAI,CAACC,MAAM;QACd,GAAG,IAAI,CAACC,SAAS;QACjB,GAAG,IAAI,CAACC,KAAK;IACf;IAEA,IAAI;QACF,MAAMC,SAAS,IAAI,CAACA,MAAM,IAAI;QAE9B,MAAM,EAAEC,OAAO,EAAE,GAAG,MAAM,IAAI,CAACC,UAAU,CAAC;YAAEF;YAAQL,QAAQ,IAAI,CAACA,MAAM;QAAC;QACxE,IAAI,CAACM,OAAO,GAAGA;QAEf,IAAI,CAACP,WAAW;YACd,IAAIS,QAAQC,GAAG,CAACC,qBAAqB,KAAK,QAAQ;gBAChD,IAAI,CAACC,OAAO,CAACN,MAAM,CAACO,IAAI,CAAC,CAAC,4BAA4B,EAAE,IAAI,CAACC,UAAU,IAAI,SAAS,MAAM,CAAC;gBAC3F,MAAM,IAAI,CAACC,YAAY,CAAC;oBAAEC,SAAS,IAAI;gBAAC;gBACxC,IAAI,CAACJ,OAAO,CAACN,MAAM,CAACO,IAAI,CAAC;YAC3B;QACF;IACF,EAAE,OAAOI,KAAK;QACZ,IAAI,CAACL,OAAO,CAACN,MAAM,CAACY,KAAK,CAAC,CAAC,4CAA4C,EAAED,IAAIE,OAAO,CAAC,CAAC,EAAEF;QACxF,IAAI,OAAO,IAAI,CAACG,kBAAkB,KAAK,YAAY,IAAI,CAACA,kBAAkB;QAC1EX,QAAQY,IAAI,CAAC;IACf;IAEA,wCAAwC;IACxC,IACEZ,QAAQC,GAAG,CAACY,QAAQ,KAAK,gBACzBb,QAAQC,GAAG,CAACa,iBAAiB,KAAK,UAClC,IAAI,CAACC,IAAI,KAAK,OACd;QACA,MAAM3B,cAAc,IAAI;IAC1B;IAEA,IAAI,OAAO,IAAI,CAAC4B,mBAAmB,KAAK,YAAY,IAAI,CAACA,mBAAmB;IAE5E,IAAIhB,QAAQC,GAAG,CAACY,QAAQ,KAAK,gBAAgB,IAAI,CAACI,cAAc,EAAE;QAChE,MAAM,IAAI,CAACC,OAAO,CAAC;YAAEC,YAAY,IAAI,CAACF,cAAc;QAAC;IACvD;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { DrizzleAdapter } from '@payloadcms/drizzle/types'\nimport type { Connect, Payload } from 'payload'\n\nimport { pushDevSchema } from '@payloadcms/drizzle'\nimport { drizzle } from 'drizzle-orm/node-postgres'\nimport pg from 'pg'\n\nimport type { PostgresAdapter } from './types.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 (ignore) {\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 (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 this.schema = {\n pgSchema: this.pgSchema,\n ...this.tables,\n ...this.relations,\n ...this.enums,\n }\n\n try {\n if (!this.pool) {\n this.pool = new pg.Pool(this.poolOptions)\n await connectWithReconnect({ adapter: this, payload: this.payload })\n }\n\n const logger = this.logger || false\n this.drizzle = drizzle({ client: 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.dropDatabase({ adapter: this })\n this.payload.logger.info('---- DROPPED TABLES ----')\n }\n }\n } catch (err) {\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) {\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 })\n }\n}\n"],"names":["pushDevSchema","drizzle","pg","connectWithReconnect","adapter","payload","reconnect","result","pool","connect","ignore","setTimeout","logger","info","prependListener","err","code","options","hotReload","schema","pgSchema","tables","relations","enums","Pool","poolOptions","client","process","env","PAYLOAD_DROP_DATABASE","schemaName","dropDatabase","message","match","disableCreateDatabase","charAt","toUpperCase","slice","isCreated","createDatabase","error","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,OAAOC,QAAQ,KAAI;AAInB,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,QAAQ;YACfC,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,CAACC;QAC/B,IAAI;YACF,IAAIA,IAAIC,IAAI,KAAK,cAAc;gBAC7B,KAAKb,qBAAqB;oBAAEC;oBAASC;oBAASC,WA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AAEE,IAAIiB,OAAO,CAACG,MAAM,CAAC,GAAGC,WAAW,KAAKrB,IAAIiB,OAAO,CAACK,KAAK,CAAC,GAAG,aAAa,CAAC;YAE9E,MAAMC,YAAY,MAAM,IAAI,CAACC,cAAc;YAE3C,IAAID,WAAW;gBACb,MAAM,IAAI,CAAC7B,OAAO,CAACQ;gBACnB;YACF;QACF,OAAO;YACL,IAAI,CAACZ,OAAO,CAACO,MAAM,CAAC4B,KAAK,CAAC;gBACxBzB;gBACA0B,KAAK,CAAC,4CAA4C,EAAE1B,IAAIiB,OAAO,CAAC,CAAC;YACnE;QACF;QAEA,IAAI,OAAO,IAAI,CAACU,kBAAkB,KAAK,YAAY;YACjD,IAAI,CAACA,kBAAkB;QACzB;QACAf,QAAQgB,IAAI,CAAC;IACf;IAEA,MAAM,IAAI,CAACC,gBAAgB;IAE3B,wCAAwC;IACxC,IACEjB,QAAQC,GAAG,CAACiB,QAAQ,KAAK,gBACzBlB,QAAQC,GAAG,CAACkB,iBAAiB,KAAK,UAClC,IAAI,CAACC,IAAI,KAAK,OACd;QACA,MAAM/C,cAAc,IAAI;IAC1B;IAEA,IAAI,OAAO,IAAI,CAACgD,mBAAmB,KAAK,YAAY;QAClD,IAAI,CAACA,mBAAmB;IAC1B;IAEA,IAAIrB,QAAQC,GAAG,CAACiB,QAAQ,KAAK,gBAAgB,IAAI,CAACI,cAAc,EAAE;QAChE,MAAM,IAAI,CAACC,OAAO,CAAC;YAAEC,YAAY,IAAI,CAACF,cAAc;QAAC;IACvD;AACF,EAAC"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import type { DatabaseAdapterObj } from 'payload';
2
- export { nodePostgres } from './connectionHelpers/nodePostgres.js';
3
2
  import type { Args, PostgresAdapter } from './types.js';
4
- export type { MigrateDownArgs, MigrateUpArgs } from './types.js';
5
- export { sql } from 'drizzle-orm';
6
3
  export declare function postgresAdapter(args: Args): DatabaseAdapterObj<PostgresAdapter>;
4
+ export type { MigrateDownArgs, MigrateUpArgs } from '@payloadcms/drizzle/postgres';
5
+ export { sql } from 'drizzle-orm';
7
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAW,MAAM,SAAS,CAAA;AAE1D,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAA;AAqClE,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAgBvD,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAEhE,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAEjC,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,kBAAkB,CAAC,eAAe,CAAC,CAuG/E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAW,MAAM,SAAS,CAAA;AAwD1D,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAOvD,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,kBAAkB,CAAC,eAAe,CAAC,CA0H/E;AAED,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAClF,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA"}
package/dist/index.js CHANGED
@@ -1,21 +1,12 @@
1
- export { nodePostgres } from './connectionHelpers/nodePostgres.js';
2
- import { beginTransaction, commitTransaction, count, create, createGlobal, createGlobalVersion, createVersion, deleteMany, deleteOne, deleteVersions, destroy, find, findGlobal, findGlobalVersions, findMigrationDir, findOne, findVersions, migrate, migrateDown, migrateFresh, migrateRefresh, migrateReset, migrateStatus, operatorMap, queryDrafts, rollbackTransaction, updateGlobal, updateGlobalVersion, updateOne, updateVersion } from '@payloadcms/drizzle';
1
+ import { beginTransaction, commitTransaction, count, countGlobalVersions, countVersions, create, createGlobal, createGlobalVersion, createVersion, deleteMany, deleteOne, deleteVersions, destroy, find, findGlobal, findGlobalVersions, findMigrationDir, findOne, findVersions, migrate, migrateDown, migrateFresh, migrateRefresh, migrateReset, migrateStatus, operatorMap, queryDrafts, rollbackTransaction, updateGlobal, updateGlobalVersion, updateOne, updateVersion } from '@payloadcms/drizzle';
2
+ import { countDistinct, createDatabase, createExtensions, createJSONQuery, createMigration, defaultDrizzleSnapshot, deleteWhere, dropDatabase, execute, getMigrationTemplate, init, insert, requireDrizzleKit } from '@payloadcms/drizzle/postgres';
3
3
  import { pgEnum, pgSchema, pgTable } from 'drizzle-orm/pg-core';
4
- import { createDatabaseAdapter } from 'payload';
4
+ import path from 'path';
5
+ import { createDatabaseAdapter, defaultBeginTransaction } from 'payload';
6
+ import { fileURLToPath } from 'url';
5
7
  import { connect } from './connect.js';
6
- import { countDistinct } from './countDistinct.js';
7
- import { convertPathToJSONTraversal } from './createJSONQuery/convertPathToJSONTraversal.js';
8
- import { createJSONQuery } from './createJSONQuery/index.js';
9
- import { createMigration } from './createMigration.js';
10
- import { defaultDrizzleSnapshot } from './defaultSnapshot.js';
11
- import { deleteWhere } from './deleteWhere.js';
12
- import { dropDatabase } from './dropDatabase.js';
13
- import { execute } from './execute.js';
14
- import { getMigrationTemplate } from './getMigrationTemplate.js';
15
- import { init } from './init.js';
16
- import { insert } from './insert.js';
17
- import { requireDrizzleKit } from './requireDrizzleKit.js';
18
- export { sql } from 'drizzle-orm';
8
+ const filename = fileURLToPath(import.meta.url);
9
+ const dirname = path.dirname(filename);
19
10
  export function postgresAdapter(args) {
20
11
  const postgresIDType = args.idType || 'serial';
21
12
  const payloadIDType = postgresIDType === 'serial' ? 'number' : 'text';
@@ -36,16 +27,31 @@ export function postgresAdapter(args) {
36
27
  table: pgTable
37
28
  };
38
29
  }
30
+ const extensions = (args.extensions ?? []).reduce((acc, name)=>{
31
+ acc[name] = true;
32
+ return acc;
33
+ }, {});
39
34
  return createDatabaseAdapter({
40
35
  name: 'postgres',
36
+ afterSchemaInit: args.afterSchemaInit ?? [],
37
+ beforeSchemaInit: args.beforeSchemaInit ?? [],
38
+ createDatabase,
39
+ createExtensions,
40
+ createMigration (args) {
41
+ return createMigration.bind(this)({
42
+ ...args,
43
+ dirname
44
+ });
45
+ },
41
46
  defaultDrizzleSnapshot,
47
+ disableCreateDatabase: args.disableCreateDatabase ?? false,
42
48
  drizzle: undefined,
43
49
  enums: {},
50
+ extensions,
44
51
  features: {
45
52
  json: true
46
53
  },
47
54
  fieldConstraints: {},
48
- getDrizzle: args.getDrizzle,
49
55
  getMigrationTemplate,
50
56
  idType: postgresIDType,
51
57
  initializing,
@@ -54,6 +60,7 @@ export function postgresAdapter(args) {
54
60
  operators: operatorMap,
55
61
  pgSchema: adapterSchema,
56
62
  pool: undefined,
63
+ poolOptions: args.pool,
57
64
  prodMigrations: args.prodMigrations,
58
65
  push: args.push,
59
66
  relations: {},
@@ -63,20 +70,21 @@ export function postgresAdapter(args) {
63
70
  sessions: {},
64
71
  tableNameMap: new Map(),
65
72
  tables: {},
73
+ tablesFilter: args.tablesFilter,
66
74
  transactionOptions: args.transactionOptions || undefined,
67
75
  versionsSuffix: args.versionsSuffix || '_v',
68
76
  // DatabaseAdapter
69
- beginTransaction: args.transactionOptions === false ? undefined : beginTransaction,
77
+ beginTransaction: args.transactionOptions === false ? defaultBeginTransaction() : beginTransaction,
70
78
  commitTransaction,
71
79
  connect,
72
- convertPathToJSONTraversal,
73
80
  count,
74
81
  countDistinct,
82
+ countGlobalVersions,
83
+ countVersions,
75
84
  create,
76
85
  createGlobal,
77
86
  createGlobalVersion,
78
87
  createJSONQuery,
79
- createMigration,
80
88
  createVersion,
81
89
  defaultIDType: payloadIDType,
82
90
  deleteMany,
@@ -91,6 +99,7 @@ export function postgresAdapter(args) {
91
99
  findGlobalVersions,
92
100
  findOne,
93
101
  findVersions,
102
+ indexes: new Set(),
94
103
  init,
95
104
  insert,
96
105
  migrate,
@@ -100,6 +109,7 @@ export function postgresAdapter(args) {
100
109
  migrateReset,
101
110
  migrateStatus,
102
111
  migrationDir,
112
+ packageName: '@payloadcms/db-postgres',
103
113
  payload,
104
114
  queryDrafts,
105
115
  rejectInitializing,
@@ -109,7 +119,8 @@ export function postgresAdapter(args) {
109
119
  updateGlobal,
110
120
  updateGlobalVersion,
111
121
  updateOne,
112
- updateVersion
122
+ updateVersion,
123
+ upsert: updateOne
113
124
  });
114
125
  }
115
126
  return {
@@ -117,5 +128,6 @@ export function postgresAdapter(args) {
117
128
  init: adapter
118
129
  };
119
130
  }
131
+ export { sql } from 'drizzle-orm';
120
132
 
121
133
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { DatabaseAdapterObj, Payload } from 'payload'\n\nexport { nodePostgres } from './connectionHelpers/nodePostgres.js'\n\nimport {\n beginTransaction,\n commitTransaction,\n count,\n create,\n createGlobal,\n createGlobalVersion,\n createVersion,\n deleteMany,\n deleteOne,\n deleteVersions,\n destroy,\n find,\n findGlobal,\n findGlobalVersions,\n findMigrationDir,\n findOne,\n findVersions,\n migrate,\n migrateDown,\n migrateFresh,\n migrateRefresh,\n migrateReset,\n migrateStatus,\n operatorMap,\n queryDrafts,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n} from '@payloadcms/drizzle'\nimport { pgEnum, pgSchema, pgTable } from 'drizzle-orm/pg-core'\nimport { createDatabaseAdapter } from 'payload'\n\nimport type { Args, PostgresAdapter } from './types.js'\n\nimport { connect } from './connect.js'\nimport { countDistinct } from './countDistinct.js'\nimport { convertPathToJSONTraversal } from './createJSONQuery/convertPathToJSONTraversal.js'\nimport { createJSONQuery } from './createJSONQuery/index.js'\nimport { createMigration } from './createMigration.js'\nimport { defaultDrizzleSnapshot } from './defaultSnapshot.js'\nimport { deleteWhere } from './deleteWhere.js'\nimport { dropDatabase } from './dropDatabase.js'\nimport { execute } from './execute.js'\nimport { getMigrationTemplate } from './getMigrationTemplate.js'\nimport { init } from './init.js'\nimport { insert } from './insert.js'\nimport { requireDrizzleKit } from './requireDrizzleKit.js'\n\nexport type { MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nexport { sql } from 'drizzle-orm'\n\nexport function postgresAdapter(args: Args): DatabaseAdapterObj<PostgresAdapter> {\n const postgresIDType = args.idType || 'serial'\n const payloadIDType = postgresIDType === 'serial' ? 'number' : 'text'\n\n function adapter({ payload }: { payload: Payload }) {\n const migrationDir = findMigrationDir(args.migrationDir)\n let resolveInitializing\n let rejectInitializing\n let adapterSchema: PostgresAdapter['pgSchema']\n\n const initializing = new Promise<void>((res, rej) => {\n resolveInitializing = res\n rejectInitializing = rej\n })\n\n if (args.schemaName) {\n adapterSchema = pgSchema(args.schemaName)\n } else {\n adapterSchema = { enum: pgEnum, table: pgTable }\n }\n\n return createDatabaseAdapter<PostgresAdapter>({\n name: 'postgres',\n defaultDrizzleSnapshot,\n drizzle: undefined,\n enums: {},\n features: {\n json: true,\n },\n fieldConstraints: {},\n getDrizzle: args.getDrizzle,\n getMigrationTemplate,\n idType: postgresIDType,\n initializing,\n localesSuffix: args.localesSuffix || '_locales',\n logger: args.logger,\n operators: operatorMap,\n pgSchema: adapterSchema,\n pool: undefined,\n prodMigrations: args.prodMigrations,\n push: args.push,\n relations: {},\n relationshipsSuffix: args.relationshipsSuffix || '_rels',\n schema: {},\n schemaName: args.schemaName,\n sessions: {},\n tableNameMap: new Map<string, string>(),\n tables: {},\n transactionOptions: args.transactionOptions || undefined,\n versionsSuffix: args.versionsSuffix || '_v',\n\n // DatabaseAdapter\n beginTransaction: args.transactionOptions === false ? undefined : beginTransaction,\n commitTransaction,\n connect,\n convertPathToJSONTraversal,\n count,\n countDistinct,\n create,\n createGlobal,\n createGlobalVersion,\n createJSONQuery,\n createMigration,\n createVersion,\n defaultIDType: payloadIDType,\n deleteMany,\n deleteOne,\n deleteVersions,\n deleteWhere,\n destroy,\n dropDatabase,\n execute,\n find,\n findGlobal,\n findGlobalVersions,\n findOne,\n findVersions,\n init,\n insert,\n migrate,\n migrateDown,\n migrateFresh,\n migrateRefresh,\n migrateReset,\n migrateStatus,\n migrationDir,\n payload,\n queryDrafts,\n rejectInitializing,\n requireDrizzleKit,\n resolveInitializing,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n })\n }\n\n return {\n defaultIDType: payloadIDType,\n init: adapter,\n }\n}\n"],"names":["nodePostgres","beginTransaction","commitTransaction","count","create","createGlobal","createGlobalVersion","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findGlobal","findGlobalVersions","findMigrationDir","findOne","findVersions","migrate","migrateDown","migrateFresh","migrateRefresh","migrateReset","migrateStatus","operatorMap","queryDrafts","rollbackTransaction","updateGlobal","updateGlobalVersion","updateOne","updateVersion","pgEnum","pgSchema","pgTable","createDatabaseAdapter","connect","countDistinct","convertPathToJSONTraversal","createJSONQuery","createMigration","defaultDrizzleSnapshot","deleteWhere","dropDatabase","execute","getMigrationTemplate","init","insert","requireDrizzleKit","sql","postgresAdapter","args","postgresIDType","idType","payloadIDType","adapter","payload","migrationDir","resolveInitializing","rejectInitializing","adapterSchema","initializing","Promise","res","rej","schemaName","enum","table","name","drizzle","undefined","enums","features","json","fieldConstraints","getDrizzle","localesSuffix","logger","operators","pool","prodMigrations","push","relations","relationshipsSuffix","schema","sessions","tableNameMap","Map","tables","transactionOptions","versionsSuffix","defaultIDType"],"mappings":"AAEA,SAASA,YAAY,QAAQ,sCAAqC;AAElE,SACEC,gBAAgB,EAChBC,iBAAiB,EACjBC,KAAK,EACLC,MAAM,EACNC,YAAY,EACZC,mBAAmB,EACnBC,aAAa,EACbC,UAAU,EACVC,SAAS,EACTC,cAAc,EACdC,OAAO,EACPC,IAAI,EACJC,UAAU,EACVC,kBAAkB,E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MAAMlC;gBAAQmC,OAAOjC;YAAQ;QACjD;QAEA,OAAOC,sBAAuC;YAC5CiC,MAAM;YACN3B;YACA4B,SAASC;YACTC,OAAO,CAAC;YACRC,UAAU;gBACRC,MAAM;YACR;YACAC,kBAAkB,CAAC;YACnBC,YAAYxB,KAAKwB,UAAU;YAC3B9B;YACAQ,QAAQD;YACRS;YACAe,eAAezB,KAAKyB,aAAa,IAAI;YACrCC,QAAQ1B,KAAK0B,MAAM;YACnBC,WAAWrD;YACXQ,UAAU2B;YACVmB,MAAMT;YACNU,gBAAgB7B,KAAK6B,cAAc;YACnCC,MAAM9B,KAAK8B,IAAI;YACfC,WAAW,CAAC;YACZC,qBAAqBhC,KAAKgC,mBAAmB,IAAI;YACjDC,QAAQ,CAAC;YACTnB,YAAYd,KAAKc,UAAU;YAC3BoB,UAAU,CAAC;YACXC,cAAc,IAAIC;YAClBC,QAAQ,CAAC;YACTC,oBAAoBtC,KAAKsC,kBAAkB,IAAInB;YAC/CoB,gBAAgBvC,KAAKuC,cAAc,IAAI;YAEvC,kBAAkB;YAClBxF,kBAAkBiD,KAAKsC,kBAAkB,KAAK,QAAQnB,YAAYpE;YAClEC;YACAiC;YACAE;YACAlC;YACAiC;YACAhC;YACAC;YACAC;YACAgC;YACAC;YACAhC;YACAmF,eAAerC;YACf7C;YACAC;YACAC;YACA+B;YACA9B;YACA+B;YACAC;YACA/B;YACAC;YACAC;YACAE;YACAC;YACA4B;YACAC;YACA5B;YACAC;YACAC;YACAC;YACAC;YACAC;YACAiC;YACAD;YACA9B;YACAiC;YACAX;YACAU;YACA/B;YACAC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAO;QACL4D,eAAerC;QACfR,MAAMS;IACR;AACF"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { DatabaseAdapterObj, Payload } from 'payload'\n\nimport {\n beginTransaction,\n commitTransaction,\n count,\n countGlobalVersions,\n countVersions,\n create,\n createGlobal,\n createGlobalVersion,\n createVersion,\n deleteMany,\n deleteOne,\n deleteVersions,\n destroy,\n find,\n findGlobal,\n findGlobalVersions,\n findMigrationDir,\n findOne,\n findVersions,\n migrate,\n migrateDown,\n migrateFresh,\n migrateRefresh,\n migrateReset,\n migrateStatus,\n operatorMap,\n queryDrafts,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n} from '@payloadcms/drizzle'\nimport {\n countDistinct,\n createDatabase,\n createExtensions,\n createJSONQuery,\n createMigration,\n defaultDrizzleSnapshot,\n deleteWhere,\n dropDatabase,\n execute,\n getMigrationTemplate,\n init,\n insert,\n requireDrizzleKit,\n} from '@payloadcms/drizzle/postgres'\nimport { pgEnum, pgSchema, pgTable } from 'drizzle-orm/pg-core'\nimport path from 'path'\nimport { createDatabaseAdapter, defaultBeginTransaction } from 'payload'\nimport { fileURLToPath } from 'url'\n\nimport type { Args, PostgresAdapter } from './types.js'\n\nimport { connect } from './connect.js'\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nexport function postgresAdapter(args: Args): DatabaseAdapterObj<PostgresAdapter> {\n const postgresIDType = args.idType || 'serial'\n const payloadIDType = postgresIDType === 'serial' ? 'number' : 'text'\n\n function adapter({ payload }: { payload: Payload }) {\n const migrationDir = findMigrationDir(args.migrationDir)\n let resolveInitializing\n let rejectInitializing\n let adapterSchema: PostgresAdapter['pgSchema']\n\n const initializing = new Promise<void>((res, rej) => {\n resolveInitializing = res\n rejectInitializing = rej\n })\n\n if (args.schemaName) {\n adapterSchema = pgSchema(args.schemaName)\n } else {\n adapterSchema = { enum: pgEnum, table: pgTable }\n }\n\n const extensions = (args.extensions ?? []).reduce((acc, name) => {\n acc[name] = true\n return acc\n }, {})\n\n return createDatabaseAdapter<PostgresAdapter>({\n name: 'postgres',\n afterSchemaInit: args.afterSchemaInit ?? [],\n beforeSchemaInit: args.beforeSchemaInit ?? [],\n createDatabase,\n createExtensions,\n createMigration(args) {\n return createMigration.bind(this)({ ...args, dirname })\n },\n defaultDrizzleSnapshot,\n disableCreateDatabase: args.disableCreateDatabase ?? false,\n drizzle: undefined,\n enums: {},\n extensions,\n features: {\n json: true,\n },\n fieldConstraints: {},\n getMigrationTemplate,\n idType: postgresIDType,\n initializing,\n localesSuffix: args.localesSuffix || '_locales',\n logger: args.logger,\n operators: operatorMap,\n pgSchema: adapterSchema,\n pool: undefined,\n poolOptions: args.pool,\n prodMigrations: args.prodMigrations,\n push: args.push,\n relations: {},\n relationshipsSuffix: args.relationshipsSuffix || '_rels',\n schema: {},\n schemaName: args.schemaName,\n sessions: {},\n tableNameMap: new Map<string, string>(),\n tables: {},\n tablesFilter: args.tablesFilter,\n transactionOptions: args.transactionOptions || undefined,\n versionsSuffix: args.versionsSuffix || '_v',\n\n // DatabaseAdapter\n beginTransaction:\n args.transactionOptions === false ? defaultBeginTransaction() : beginTransaction,\n commitTransaction,\n connect,\n count,\n countDistinct,\n countGlobalVersions,\n countVersions,\n create,\n createGlobal,\n createGlobalVersion,\n createJSONQuery,\n createVersion,\n defaultIDType: payloadIDType,\n deleteMany,\n deleteOne,\n deleteVersions,\n deleteWhere,\n destroy,\n dropDatabase,\n execute,\n find,\n findGlobal,\n findGlobalVersions,\n findOne,\n findVersions,\n indexes: new Set<string>(),\n init,\n insert,\n migrate,\n migrateDown,\n migrateFresh,\n migrateRefresh,\n migrateReset,\n migrateStatus,\n migrationDir,\n packageName: '@payloadcms/db-postgres',\n payload,\n queryDrafts,\n rejectInitializing,\n requireDrizzleKit,\n resolveInitializing,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n upsert: updateOne,\n })\n }\n\n return {\n defaultIDType: payloadIDType,\n init: adapter,\n }\n}\n\nexport type { MigrateDownArgs, MigrateUpArgs } from '@payloadcms/drizzle/postgres'\nexport { sql } from 'drizzle-orm'\n"],"names":["beginTransaction","commitTransaction","count","countGlobalVersions","countVersions","create","createGlobal","createGlobalVersion","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findGlobal","findGlobalVersions","findMigrationDir","findOne","findVersions","migrate","migrateDown","migrateFresh","migrateRefresh","migrateReset","migrateStatus","operatorMap","queryDrafts","rollbackTransaction","updateGlobal","updateGlobalVersion","updateOne","updateVersion","countDistinct","createDatabase","createExtensions","createJSONQuery","createMigration","defaultDrizzleSnapshot","deleteWhere","dropDatabase","execute","getMigrationTemplate","init","insert","requireDrizzleKit","pgEnum","pgSchema","pgTable","path","createDatabaseAdapter","defaultBeginTransaction","fileURLToPath","connect","filename","url","dirname","postgresAdapter","args","postgresIDType","idType","payloadIDType","adapter","payload","migrationDir","resolveInitializing","rejectInitializing","adapterSchema","initializing","Promise","res","rej","schemaName","enum","table","extensions","reduce","acc","name","afterSchemaInit","beforeSchemaInit","bind","disableCreateDatabase","drizzle","undefined","enums","features","json","fieldConstraints","localesSuffix","logger","operators","pool","poolOptions","prodMigrations","push","relations","relationshipsSuffix","schema","sessions","tableNameMap","Map","tables","tablesFilter","transactionOptions","versionsSuffix","defaultIDType","indexes","Set","packageName","upsert","sql"],"mappings":"AAEA,SACEA,gBAAgB,EAChBC,iBAAiB,EACjBC,KAAK,EACLC,mBAAmB,EACnBC,aAAa,EACbC,MAAM,EACNC,YAAY,EACZC,mBAAmB,EACnBC,aAAa,EACbC,UAAU,EACVC,SAAS,EACTC,cAAc,EACdC,OAAO,EACPC,IAAI,EACJC,UAAU,EACVC,kBAAkB,EAClBC,gBAAgB,EAChBC,OAAO,EACPC,YAAY,EACZC,OAAO,EACPC,WAAW,EACXC,YAAY,EACZC,cAAc,EACdC,YAAY,EACZC,aAAa,EACbC,WAAW,EACXC,WAAW,EACXC,mBAAmB,EACnBC,YAAY,EACZC,mBAAmB,EACnBC,SAAS,EACTC,aAAa,QACR,sBAAqB;AAC5B,SACEC,aAAa,EACbC,cAAc,EACdC,gBAAgB,EAChBC,eAAe,EACfC,eAAe,EACfC,sBAAsB,EACtBC,WAAW,EACXC,YAAY,EACZC,OAAO,EACPC,o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EF;gBAAQ;YACvD;YACAlB;YACA4C,uBAAuBxB,KAAKwB,qBAAqB,IAAI;YACrDC,SAASC;YACTC,OAAO,CAAC;YACRV;YACAW,UAAU;gBACRC,MAAM;YACR;YACAC,kBAAkB,CAAC;YACnB9C;YACAkB,QAAQD;YACRS;YACAqB,eAAe/B,KAAK+B,aAAa,IAAI;YACrCC,QAAQhC,KAAKgC,MAAM;YACnBC,WAAWjE;YACXqB,UAAUoB;YACVyB,MAAMR;YACNS,aAAanC,KAAKkC,IAAI;YACtBE,gBAAgBpC,KAAKoC,cAAc;YACnCC,MAAMrC,KAAKqC,IAAI;YACfC,WAAW,CAAC;YACZC,qBAAqBvC,KAAKuC,mBAAmB,IAAI;YACjDC,QAAQ,CAAC;YACT1B,YAAYd,KAAKc,UAAU;YAC3B2B,UAAU,CAAC;YACXC,cAAc,IAAIC;YAClBC,QAAQ,CAAC;YACTC,cAAc7C,KAAK6C,YAAY;YAC/BC,oBAAoB9C,KAAK8C,kBAAkB,IAAIpB;YAC/CqB,gBAAgB/C,KAAK+C,cAAc,IAAI;YAEvC,kBAAkB;YAClBxG,kBACEyD,KAAK8C,kBAAkB,KAAK,QAAQrD,4BAA4BlD;YAClEC;YACAmD;YACAlD;YACA8B;YACA7B;YACAC;YACAC;YACAC;YACAC;YACA4B;YACA3B;YACAiG,eAAe7C;YACfnD;YACAC;YACAC;YACA2B;YACA1B;YACA2B;YACAC;YACA3B;YACAC;YACAC;YACAE;YACAC;YACAwF,SAAS,IAAIC;YACbjE;YACAC;YACAxB;YACAC;YACAC;YACAC;YACAC;YACAC;YACAuC;YACA6C,aAAa;YACb9C;YACApC;YACAuC;YACArB;YACAoB;YACArC;YACAC;YACAC;YACAC;YACAC;YACA8E,QAAQ/E;QACV;IACF;IAEA,OAAO;QACL2E,eAAe7C;QACflB,MAAMmB;IACR;AACF;AAGA,SAASiD,GAAG,QAAQ,cAAa"}
@@ -1 +1 @@
1
- {"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../../src/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIpC,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5B,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;CAChC,CAAA;AAED,eAAO,MAAM,cAAc,wCAAyC,IAAI,SA0MvE,CAAA"}
1
+ {"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../../src/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIpC,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5B,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;CAChC,CAAA;AAED,eAAO,MAAM,cAAc,wCAAyC,IAAI,SA6MvE,CAAA"}
@@ -2,42 +2,6 @@ import { tabHasName } from 'payload/shared';
2
2
  export const traverseFields = ({ doc, fields, locale, path, rows })=>{
3
3
  fields.forEach((field)=>{
4
4
  switch(field.type){
5
- case 'group':
6
- {
7
- const newPath = `${path ? `${path}.` : ''}${field.name}`;
8
- const newDoc = doc?.[field.name];
9
- if (typeof newDoc === 'object' && newDoc !== null) {
10
- if (field.localized) {
11
- Object.entries(newDoc).forEach(([locale, localeDoc])=>{
12
- return traverseFields({
13
- doc: localeDoc,
14
- fields: field.fields,
15
- locale,
16
- path: newPath,
17
- rows
18
- });
19
- });
20
- } else {
21
- return traverseFields({
22
- doc: newDoc,
23
- fields: field.fields,
24
- path: newPath,
25
- rows
26
- });
27
- }
28
- }
29
- break;
30
- }
31
- case 'row':
32
- case 'collapsible':
33
- {
34
- return traverseFields({
35
- doc,
36
- fields: field.fields,
37
- path,
38
- rows
39
- });
40
- }
41
5
  case 'array':
42
6
  {
43
7
  const rowData = doc?.[field.name];
@@ -104,43 +68,45 @@ export const traverseFields = ({ doc, fields, locale, path, rows })=>{
104
68
  }
105
69
  break;
106
70
  }
107
- case 'tabs':
71
+ case 'collapsible':
72
+ // falls through
73
+ case 'row':
108
74
  {
109
- return field.tabs.forEach((tab)=>{
110
- if (tabHasName(tab)) {
111
- const newDoc = doc?.[tab.name];
112
- const newPath = `${path ? `${path}.` : ''}${tab.name}`;
113
- if (typeof newDoc === 'object' && newDoc !== null) {
114
- if (tab.localized) {
115
- Object.entries(newDoc).forEach(([locale, localeDoc])=>{
116
- return traverseFields({
117
- doc: localeDoc,
118
- fields: tab.fields,
119
- locale,
120
- path: newPath,
121
- rows
122
- });
123
- });
124
- } else {
125
- return traverseFields({
126
- doc: newDoc,
127
- fields: tab.fields,
128
- path: newPath,
129
- rows
130
- });
131
- }
132
- }
75
+ return traverseFields({
76
+ doc,
77
+ fields: field.fields,
78
+ path,
79
+ rows
80
+ });
81
+ }
82
+ case 'group':
83
+ {
84
+ const newPath = `${path ? `${path}.` : ''}${field.name}`;
85
+ const newDoc = doc?.[field.name];
86
+ if (typeof newDoc === 'object' && newDoc !== null) {
87
+ if (field.localized) {
88
+ Object.entries(newDoc).forEach(([locale, localeDoc])=>{
89
+ return traverseFields({
90
+ doc: localeDoc,
91
+ fields: field.fields,
92
+ locale,
93
+ path: newPath,
94
+ rows
95
+ });
96
+ });
133
97
  } else {
134
- traverseFields({
135
- doc,
136
- fields: tab.fields,
137
- path,
98
+ return traverseFields({
99
+ doc: newDoc,
100
+ fields: field.fields,
101
+ path: newPath,
138
102
  rows
139
103
  });
140
104
  }
141
- });
105
+ }
106
+ break;
142
107
  }
143
108
  case 'relationship':
109
+ // falls through
144
110
  case 'upload':
145
111
  {
146
112
  if (typeof field.relationTo === 'string') {
@@ -167,7 +133,9 @@ export const traverseFields = ({ doc, fields, locale, path, rows })=>{
167
133
  } else {
168
134
  const matchedRelationship = rows.find((row)=>{
169
135
  const matchesPath = row.path === relationshipPath;
170
- if (locale) return matchesPath && locale === row.locale;
136
+ if (locale) {
137
+ return matchesPath && locale === row.locale;
138
+ }
171
139
  return row.path === relationshipPath;
172
140
  });
173
141
  if (matchedRelationship) {
@@ -183,6 +151,43 @@ export const traverseFields = ({ doc, fields, locale, path, rows })=>{
183
151
  }
184
152
  }
185
153
  }
154
+ break;
155
+ }
156
+ case 'tabs':
157
+ {
158
+ return field.tabs.forEach((tab)=>{
159
+ if (tabHasName(tab)) {
160
+ const newDoc = doc?.[tab.name];
161
+ const newPath = `${path ? `${path}.` : ''}${tab.name}`;
162
+ if (typeof newDoc === 'object' && newDoc !== null) {
163
+ if (tab.localized) {
164
+ Object.entries(newDoc).forEach(([locale, localeDoc])=>{
165
+ return traverseFields({
166
+ doc: localeDoc,
167
+ fields: tab.fields,
168
+ locale,
169
+ path: newPath,
170
+ rows
171
+ });
172
+ });
173
+ } else {
174
+ return traverseFields({
175
+ doc: newDoc,
176
+ fields: tab.fields,
177
+ path: newPath,
178
+ rows
179
+ });
180
+ }
181
+ }
182
+ } else {
183
+ traverseFields({
184
+ doc,
185
+ fields: tab.fields,
186
+ path,
187
+ rows
188
+ });
189
+ }
190
+ });
186
191
  }
187
192
  }
188
193
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.ts"],"sourcesContent":["import type { Field } from 'payload'\n\nimport { tabHasName } from 'payload/shared'\n\ntype Args = {\n doc: Record<string, unknown>\n fields: Field[]\n locale?: string\n path: string\n rows: Record<string, unknown>[]\n}\n\nexport const traverseFields = ({ doc, fields, locale, path, rows }: Args) => {\n fields.forEach((field) => {\n switch (field.type) {\n case 'group': {\n const newPath = `${path ? `${path}.` : ''}${field.name}`\n const newDoc = doc?.[field.name]\n\n if (typeof newDoc === 'object' && newDoc !== null) {\n if (field.localized) {\n Object.entries(newDoc).forEach(([locale, localeDoc]) => {\n return traverseFields({\n doc: localeDoc,\n fields: field.fields,\n locale,\n path: newPath,\n rows,\n })\n })\n } else {\n return traverseFields({\n doc: newDoc as Record<string, unknown>,\n fields: field.fields,\n path: newPath,\n rows,\n })\n }\n }\n\n break\n }\n\n case 'row':\n case 'collapsible': {\n return traverseFields({\n doc,\n fields: field.fields,\n path,\n rows,\n })\n }\n\n case 'array': {\n const rowData = doc?.[field.name]\n\n if (field.localized && typeof rowData === 'object' && rowData !== null) {\n Object.entries(rowData).forEach(([locale, localeRows]) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row, i) => {\n return traverseFields({\n doc: row as Record<string, unknown>,\n fields: field.fields,\n locale,\n path: `${path ? `${path}.` : ''}${field.name}.${i}`,\n rows,\n })\n })\n }\n })\n }\n\n if (Array.isArray(rowData)) {\n rowData.forEach((row, i) => {\n return traverseFields({\n doc: row as Record<string, unknown>,\n fields: field.fields,\n path: `${path ? `${path}.` : ''}${field.name}.${i}`,\n rows,\n })\n })\n }\n\n break\n }\n\n case 'blocks': {\n const rowData = doc?.[field.name]\n\n if (field.localized && typeof rowData === 'object' && rowData !== null) {\n Object.entries(rowData).forEach(([locale, localeRows]) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row, i) => {\n const matchedBlock = field.blocks.find((block) => block.slug === row.blockType)\n\n if (matchedBlock) {\n return traverseFields({\n doc: row as Record<string, unknown>,\n fields: matchedBlock.fields,\n locale,\n path: `${path ? `${path}.` : ''}${field.name}.${i}`,\n rows,\n })\n }\n })\n }\n })\n }\n\n if (Array.isArray(rowData)) {\n rowData.forEach((row, i) => {\n const matchedBlock = field.blocks.find((block) => block.slug === row.blockType)\n\n if (matchedBlock) {\n return traverseFields({\n doc: row as Record<string, unknown>,\n fields: matchedBlock.fields,\n path: `${path ? `${path}.` : ''}${field.name}.${i}`,\n rows,\n })\n }\n })\n }\n\n break\n }\n\n case 'tabs': {\n return field.tabs.forEach((tab) => {\n if (tabHasName(tab)) {\n const newDoc = doc?.[tab.name]\n const newPath = `${path ? `${path}.` : ''}${tab.name}`\n\n if (typeof newDoc === 'object' && newDoc !== null) {\n if (tab.localized) {\n Object.entries(newDoc).forEach(([locale, localeDoc]) => {\n return traverseFields({\n doc: localeDoc,\n fields: tab.fields,\n locale,\n path: newPath,\n rows,\n })\n })\n } else {\n return traverseFields({\n doc: newDoc as Record<string, unknown>,\n fields: tab.fields,\n path: newPath,\n rows,\n })\n }\n }\n } else {\n traverseFields({\n doc,\n fields: tab.fields,\n path,\n rows,\n })\n }\n })\n }\n\n case 'relationship':\n case 'upload': {\n if (typeof field.relationTo === 'string') {\n if (field.type === 'upload' || !field.hasMany) {\n const relationshipPath = `${path ? `${path}.` : ''}${field.name}`\n\n if (field.localized) {\n const matchedRelationshipsWithLocales = rows.filter(\n (row) => row.path === relationshipPath,\n )\n\n if (matchedRelationshipsWithLocales.length && !doc[field.name]) {\n doc[field.name] = {}\n }\n\n const newDoc = doc[field.name] as Record<string, unknown>\n\n matchedRelationshipsWithLocales.forEach((localeRow) => {\n if (typeof localeRow.locale === 'string') {\n const [, id] = Object.entries(localeRow).find(\n ([key, val]) =>\n val !== null && !['id', 'locale', 'order', 'parent_id', 'path'].includes(key),\n )\n\n newDoc[localeRow.locale] = id\n }\n })\n } else {\n const matchedRelationship = rows.find((row) => {\n const matchesPath = row.path === relationshipPath\n\n if (locale) return matchesPath && locale === row.locale\n\n return row.path === relationshipPath\n })\n\n if (matchedRelationship) {\n const [, id] = Object.entries(matchedRelationship).find(\n ([key, val]) =>\n val !== null && !['id', 'locale', 'order', 'parent_id', 'path'].includes(key),\n )\n\n doc[field.name] = id\n }\n }\n }\n }\n }\n }\n })\n}\n"],"names":["tabHasName","traverseFields","doc","fields","locale","path","rows","forEach","field","type","newPath","name","newDoc","localized","Object","entries","localeDoc","rowData","localeRows","Array","isArray","row","i","matchedBlock","blocks","find","block","slug","blockType","tabs","tab","relationTo","hasMany","relationshipPath","matchedRelationshipsWithLocales","filter","length","localeRow","id","key","val","includes","matchedRelationship","matchesPath"],"mappings":"AAEA,SAASA,UAAU,QAAQ,iBAAgB;AAU3C,OAAO,MAAMC,iBAAiB,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAQ;IACtEH,OAAOI,OAAO,CAAC,CAACC;QACd,OAAQA,MAAMC,IAAI;YAChB,KAAK;gBAAS;oBACZ,MAAMC,UAAU,CAAC,EAAEL,OAAO,CAAC,EAAEA,KAAK,CAAC,CAAC,GAAG,GAAG,EAAEG,MAAMG,IAAI,CAAC,CAAC;oBACxD,MAAMC,SAASV,KAAK,CAACM,MAAMG,IAAI,CAAC;oBAEhC,IAAI,OAAOC,WAAW,YAAYA,WAAW,MAAM;wBACjD,IAAIJ,MAAMK,SAAS,EAAE;4BACnBC,OAAOC,OAAO,CAACH,QAAQL,OAAO,CAAC,CAAC,CAACH,QAAQY,UAAU;gCACjD,OAAOf,eAAe;oCACpBC,KAAKc;oCACLb,QAAQK,MAAML,MAAM;oCACpBC;oCACAC,MAAMK;oCACNJ;gCACF;4BACF;wBACF,OAAO;4BACL,OAAOL,eAAe;gCACpBC,KAAKU;gCACLT,QAAQK,MAAML,MAAM;gCACpBE,MAAMK;gCACNJ;4BACF;wBACF;oBACF;oBAEA;gBACF;YAEA,KAAK;YACL,KAAK;gBAAe;oBAClB,OAAOL,eAAe;wBACpBC;wBACAC,QAAQK,MAAML,MAAM;wBACpBE;wBACAC;oBACF;gBACF;YAEA,KAAK;gBAAS;oBACZ,MAAMW,UAAUf,KAAK,CAACM,MAAMG,IAAI,CAAC;oBAEjC,IAAIH,MAAMK,SAAS,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eAAevC,WAAWiB,IAAIjB,MAAM;oCAEvD,OAAOiB,IAAIhB,IAAI,KAAK4B;gCACtB;gCAEA,IAAIS,qBAAqB;oCACvB,MAAM,GAAGJ,GAAG,GAAGxB,OAAOC,OAAO,CAAC2B,qBAAqBjB,IAAI,CACrD,CAAC,CAACc,KAAKC,IAAI,GACTA,QAAQ,QAAQ,CAAC;4CAAC;4CAAM;4CAAU;4CAAS;4CAAa;yCAAO,CAACC,QAAQ,CAACF;oCAG7ErC,GAAG,CAACM,MAAMG,IAAI,CAAC,GAAG2B;gCACpB;4BACF;wBACF;oBACF;gBACF;QACF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../src/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.ts"],"sourcesContent":["import type { Field } from 'payload'\n\nimport { tabHasName } from 'payload/shared'\n\ntype Args = {\n doc: Record<string, unknown>\n fields: Field[]\n locale?: string\n path: string\n rows: Record<string, unknown>[]\n}\n\nexport const traverseFields = ({ doc, fields, locale, path, rows }: Args) => {\n fields.forEach((field) => {\n switch (field.type) {\n case 'array': {\n const rowData = doc?.[field.name]\n\n if (field.localized && typeof rowData === 'object' && rowData !== null) {\n Object.entries(rowData).forEach(([locale, localeRows]) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row, i) => {\n return traverseFields({\n doc: row as Record<string, unknown>,\n fields: field.fields,\n locale,\n path: `${path ? `${path}.` : ''}${field.name}.${i}`,\n rows,\n })\n })\n }\n })\n }\n\n if (Array.isArray(rowData)) {\n rowData.forEach((row, i) => {\n return traverseFields({\n doc: row as Record<string, unknown>,\n fields: field.fields,\n path: `${path ? `${path}.` : ''}${field.name}.${i}`,\n rows,\n })\n })\n }\n\n break\n }\n\n case 'blocks': {\n const rowData = doc?.[field.name]\n\n if (field.localized && typeof rowData === 'object' && rowData !== null) {\n Object.entries(rowData).forEach(([locale, localeRows]) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row, i) => {\n const matchedBlock = field.blocks.find((block) => block.slug === row.blockType)\n\n if (matchedBlock) {\n return traverseFields({\n doc: row as Record<string, unknown>,\n fields: matchedBlock.fields,\n locale,\n path: `${path ? `${path}.` : ''}${field.name}.${i}`,\n rows,\n })\n }\n })\n }\n })\n }\n\n if (Array.isArray(rowData)) {\n rowData.forEach((row, i) => {\n const matchedBlock = field.blocks.find((block) => block.slug === row.blockType)\n\n if (matchedBlock) {\n return traverseFields({\n doc: row as Record<string, unknown>,\n fields: matchedBlock.fields,\n path: `${path ? `${path}.` : ''}${field.name}.${i}`,\n rows,\n })\n }\n })\n }\n\n break\n }\n case 'collapsible':\n // falls through\n case 'row': {\n return traverseFields({\n doc,\n fields: field.fields,\n path,\n rows,\n })\n }\n\n case 'group': {\n const newPath = `${path ? `${path}.` : ''}${field.name}`\n const newDoc = doc?.[field.name]\n\n if (typeof newDoc === 'object' && newDoc !== null) {\n if (field.localized) {\n Object.entries(newDoc).forEach(([locale, localeDoc]) => {\n return traverseFields({\n doc: localeDoc,\n fields: field.fields,\n locale,\n path: newPath,\n rows,\n })\n })\n } else {\n return traverseFields({\n doc: newDoc as Record<string, unknown>,\n fields: field.fields,\n path: newPath,\n rows,\n })\n }\n }\n\n break\n }\n\n case 'relationship':\n // falls through\n case 'upload': {\n if (typeof field.relationTo === 'string') {\n if (field.type === 'upload' || !field.hasMany) {\n const relationshipPath = `${path ? `${path}.` : ''}${field.name}`\n\n if (field.localized) {\n const matchedRelationshipsWithLocales = rows.filter(\n (row) => row.path === relationshipPath,\n )\n\n if (matchedRelationshipsWithLocales.length && !doc[field.name]) {\n doc[field.name] = {}\n }\n\n const newDoc = doc[field.name] as Record<string, unknown>\n\n matchedRelationshipsWithLocales.forEach((localeRow) => {\n if (typeof localeRow.locale === 'string') {\n const [, id] = Object.entries(localeRow).find(\n ([key, val]) =>\n val !== null && !['id', 'locale', 'order', 'parent_id', 'path'].includes(key),\n )\n\n newDoc[localeRow.locale] = id\n }\n })\n } else {\n const matchedRelationship = rows.find((row) => {\n const matchesPath = row.path === relationshipPath\n\n if (locale) {\n return matchesPath && locale === row.locale\n }\n\n return row.path === relationshipPath\n })\n\n if (matchedRelationship) {\n const [, id] = Object.entries(matchedRelationship).find(\n ([key, val]) =>\n val !== null && !['id', 'locale', 'order', 'parent_id', 'path'].includes(key),\n )\n\n doc[field.name] = id\n }\n }\n }\n }\n break\n }\n case 'tabs': {\n return field.tabs.forEach((tab) => {\n if (tabHasName(tab)) {\n const newDoc = doc?.[tab.name]\n const newPath = `${path ? `${path}.` : ''}${tab.name}`\n\n if (typeof newDoc === 'object' && newDoc !== null) {\n if (tab.localized) {\n Object.entries(newDoc).forEach(([locale, localeDoc]) => {\n return traverseFields({\n doc: localeDoc,\n fields: tab.fields,\n locale,\n path: newPath,\n rows,\n })\n })\n } else {\n return traverseFields({\n doc: newDoc as Record<string, unknown>,\n fields: tab.fields,\n path: newPath,\n rows,\n })\n }\n }\n } else {\n traverseFields({\n doc,\n fields: tab.fields,\n path,\n rows,\n })\n }\n })\n }\n }\n })\n}\n"],"names":["tabHasName","traverseFields","doc","fields","locale","path","rows","forEach","field","type","rowData","name","localized","Object","entries","localeRows","Array","isArray","row","i","matchedBlock","blocks","find","block","slug","blockType","newPath","newDoc","localeDoc","relationTo","hasMany","relationshipPath","matchedRelationshipsWithLocales","filter","length","localeRow","id","key","val","includes","matchedRelationship","matchesPath","tabs","tab"],"mappings":"AAEA,SAASA,UAAU,QAAQ,iBAAgB;AAU3C,OAAO,MAAMC,iBAAiB,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAQ;IACtEH,OAAOI,OAAO,CAAC,CAACC;QACd,OAAQA,MAAMC,IAAI;YAChB,KAAK;gBAAS;oBACZ,MAAMC,UAAUR,KAAK,CAACM,MAAMG,IAAI,CAAC;oBAEjC,IAAIH,MAAMI,SAAS,IAAI,OAAOF,YAAY,YAAYA,YAAY,MAAM;wBACtEG,OAAOC,OAAO,CAACJ,SAASH,O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,MAAM,GAAGJ,GAAG,GAAGvB,OAAOC,OAAO,CAAC0B,qBAAqBlB,IAAI,CACrD,CAAC,CAACe,KAAKC,IAAI,GACTA,QAAQ,QAAQ,CAAC;4CAAC;4CAAM;4CAAU;4CAAS;4CAAa;yCAAO,CAACC,QAAQ,CAACF;oCAG7EnC,GAAG,CAACM,MAAMG,IAAI,CAAC,GAAGyB;gCACpB;4BACF;wBACF;oBACF;oBACA;gBACF;YACA,KAAK;gBAAQ;oBACX,OAAO5B,MAAMkC,IAAI,CAACnC,OAAO,CAAC,CAACoC;wBACzB,IAAI3C,WAAW2C,MAAM;4BACnB,MAAMhB,SAASzB,KAAK,CAACyC,IAAIhC,IAAI,CAAC;4BAC9B,MAAMe,UAAU,CAAC,EAAErB,OAAO,CAAC,EAAEA,KAAK,CAAC,CAAC,GAAG,GAAG,EAAEsC,IAAIhC,IAAI,CAAC,CAAC;4BAEtD,IAAI,OAAOgB,WAAW,YAAYA,WAAW,MAAM;gCACjD,IAAIgB,IAAI/B,SAAS,EAAE;oCACjBC,OAAOC,OAAO,CAACa,QAAQpB,OAAO,CAAC,CAAC,CAACH,QAAQwB,UAAU;wCACjD,OAAO3B,eAAe;4CACpBC,KAAK0B;4CACLzB,QAAQwC,IAAIxC,MAAM;4CAClBC;4CACAC,MAAMqB;4CACNpB;wCACF;oCACF;gCACF,OAAO;oCACL,OAAOL,eAAe;wCACpBC,KAAKyB;wCACLxB,QAAQwC,IAAIxC,MAAM;wCAClBE,MAAMqB;wCACNpB;oCACF;gCACF;4BACF;wBACF,OAAO;4BACLL,eAAe;gCACbC;gCACAC,QAAQwC,IAAIxC,MAAM;gCAClBE;gCACAC;4BACF;wBACF;oBACF;gBACF;QACF;IACF;AACF,EAAC"}
@@ -77,7 +77,7 @@ const require = createRequire(import.meta.url);
77
77
  });
78
78
  if (collection.versions) {
79
79
  const versionsTableName = adapter.tableNameMap.get(`_${toSnakeCase(collection.slug)}${adapter.versionsSuffix}`);
80
- const versionFields = buildVersionCollectionFields(collection);
80
+ const versionFields = buildVersionCollectionFields(payload.config, collection);
81
81
  const versionPathsToQuery = new Set();
82
82
  traverseFields({
83
83
  adapter,
@@ -140,7 +140,7 @@ const require = createRequire(import.meta.url);
140
140
  });
141
141
  if (global.versions) {
142
142
  const versionsTableName = adapter.tableNameMap.get(`_${toSnakeCase(global.slug)}${adapter.versionsSuffix}`);
143
- const versionFields = buildVersionGlobalFields(global);
143
+ const versionFields = buildVersionGlobalFields(payload.config, global);
144
144
  const versionPathsToQuery = new Set();
145
145
  traverseFields({
146
146
  adapter,