@payloadcms/db-postgres 3.0.0-beta.11 → 3.0.0-beta.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ import type { Count } from 'payload/database';
2
+ export declare const count: Count;
3
+ //# sourceMappingURL=count.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../src/count.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAY7C,eAAO,MAAM,KAAK,EAAE,KAoDnB,CAAA"}
package/dist/count.js ADDED
@@ -0,0 +1,53 @@
1
+ import { sql } from 'drizzle-orm';
2
+ import { chainMethods } from './find/chainMethods.js';
3
+ import buildQuery from './queries/buildQuery.js';
4
+ import { getTableName } from './schema/getTableName.js';
5
+ export const count = async function count({ collection, locale, req, where: whereArg }) {
6
+ const collectionConfig = this.payload.collections[collection].config;
7
+ const tableName = getTableName({
8
+ adapter: this,
9
+ config: collectionConfig
10
+ });
11
+ const db = this.sessions[req.transactionID]?.db || this.drizzle;
12
+ const table = this.tables[tableName];
13
+ const { joinAliases, joins, where } = await buildQuery({
14
+ adapter: this,
15
+ fields: collectionConfig.fields,
16
+ locale,
17
+ tableName,
18
+ where: whereArg
19
+ });
20
+ const selectCountMethods = [];
21
+ joinAliases.forEach(({ condition, table })=>{
22
+ selectCountMethods.push({
23
+ args: [
24
+ table,
25
+ condition
26
+ ],
27
+ method: 'leftJoin'
28
+ });
29
+ });
30
+ Object.entries(joins).forEach(([joinTable, condition])=>{
31
+ if (joinTable) {
32
+ selectCountMethods.push({
33
+ args: [
34
+ this.tables[joinTable],
35
+ condition
36
+ ],
37
+ method: 'leftJoin'
38
+ });
39
+ }
40
+ });
41
+ const countResult = await chainMethods({
42
+ methods: selectCountMethods,
43
+ query: db.select({
44
+ count: sql`count
45
+ (DISTINCT ${this.tables[tableName].id})`
46
+ }).from(table).where(where)
47
+ });
48
+ return {
49
+ totalDocs: Number(countResult[0].count)
50
+ };
51
+ };
52
+
53
+ //# sourceMappingURL=count.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/count.ts"],"sourcesContent":["import type { Count } from 'payload/database'\nimport type { SanitizedCollectionConfig } from 'payload/types'\n\nimport { sql } from 'drizzle-orm'\n\nimport type { ChainedMethods } from './find/chainMethods.js'\nimport type { PostgresAdapter } from './types.js'\n\nimport { chainMethods } from './find/chainMethods.js'\nimport buildQuery from './queries/buildQuery.js'\nimport { getTableName } from './schema/getTableName.js'\n\nexport const count: Count = async function count(\n this: PostgresAdapter,\n { collection, locale, req, where: whereArg },\n) {\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n\n const tableName = getTableName({\n adapter: this,\n config: collectionConfig,\n })\n\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const table = this.tables[tableName]\n\n const { joinAliases, joins, where } = await buildQuery({\n adapter: this,\n fields: collectionConfig.fields,\n locale,\n tableName,\n where: whereArg,\n })\n\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: [this.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 ${this.tables[tableName].id})`,\n })\n .from(table)\n .where(where),\n })\n\n return { totalDocs: Number(countResult[0].count) }\n}\n"],"names":["sql","chainMethods","buildQuery","getTableName","count","collection","locale","req","where","whereArg","collectionConfig","payload","collections","config","tableName","adapter","db","sessions","transactionID","drizzle","table","tables","joinAliases","joins","fields","selectCountMethods","forEach","condition","push","args","method","Object","entries","joinTable","countResult","methods","query","select","id","from","totalDocs","Number"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,S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AU,CAACwB,EAAE,CAAC,CAAC,CAAC;QAC9C,GACCC,IAAI,CAACnB,OACLZ,KAAK,CAACA;IACX;IAEA,OAAO;QAAEgC,WAAWC,OAAOP,WAAW,CAAC,EAAE,CAAC9B,KAAK;IAAE;AACnD,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAM1D,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAiCvD,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,CAuE/E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAM1D,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAkCvD,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,CAwE/E"}
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { createDatabaseAdapter } from 'payload/database';
4
4
  import { connect } from './connect.js';
5
+ import { count } from './count.js';
5
6
  import { create } from './create.js';
6
7
  import { createGlobal } from './createGlobal.js';
7
8
  import { createGlobalVersion } from './createGlobalVersion.js';
@@ -62,6 +63,7 @@ export function postgresAdapter(args) {
62
63
  beginTransaction,
63
64
  commitTransaction,
64
65
  connect,
66
+ count,
65
67
  create,
66
68
  createGlobal,
67
69
  createGlobalVersion,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport type { DatabaseAdapterObj } from 'payload/database'\n\nimport fs from 'fs'\nimport path from 'path'\nimport { createDatabaseAdapter } from 'payload/database'\n\nimport type { Args, PostgresAdapter } from './types.js'\n\nimport { connect } from './connect.js'\nimport { create } from './create.js'\nimport { createGlobal } from './createGlobal.js'\nimport { createGlobalVersion } from './createGlobalVersion.js'\nimport { createMigration } from './createMigration.js'\nimport { createVersion } from './createVersion.js'\nimport { deleteMany } from './deleteMany.js'\nimport { deleteOne } from './deleteOne.js'\nimport { deleteVersions } from './deleteVersions.js'\nimport { destroy } from './destroy.js'\nimport { find } from './find.js'\nimport { findGlobal } from './findGlobal.js'\nimport { findGlobalVersions } from './findGlobalVersions.js'\nimport { findOne } from './findOne.js'\nimport { findVersions } from './findVersions.js'\nimport { init } from './init.js'\nimport { migrate } from './migrate.js'\nimport { migrateDown } from './migrateDown.js'\nimport { migrateFresh } from './migrateFresh.js'\nimport { migrateRefresh } from './migrateRefresh.js'\nimport { migrateReset } from './migrateReset.js'\nimport { migrateStatus } from './migrateStatus.js'\nimport { queryDrafts } from './queryDrafts.js'\nimport { beginTransaction } from './transactions/beginTransaction.js'\nimport { commitTransaction } from './transactions/commitTransaction.js'\nimport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nimport { updateOne } from './update.js'\nimport { updateGlobal } from './updateGlobal.js'\nimport { updateGlobalVersion } from './updateGlobalVersion.js'\nimport { updateVersion } from './updateVersion.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 ? 'number' : 'text'\n\n function adapter({ payload }: { payload: Payload }) {\n const migrationDir = findMigrationDir(args.migrationDir)\n\n return createDatabaseAdapter<PostgresAdapter>({\n name: 'postgres',\n\n // Postgres-specific\n blockTableNames: {},\n drizzle: undefined,\n enums: {},\n fieldConstraints: {},\n idType: postgresIDType,\n localesSuffix: args.localesSuffix || '_locales',\n logger: args.logger,\n pgSchema: undefined,\n pool: undefined,\n poolOptions: args.pool,\n push: args.push,\n relations: {},\n relationshipsSuffix: args.relationshipsSuffix || '_rels',\n schema: {},\n schemaName: args.schemaName,\n sessions: {},\n tables: {},\n versionsSuffix: args.versionsSuffix || '_v',\n\n // DatabaseAdapter\n beginTransaction,\n commitTransaction,\n connect,\n create,\n createGlobal,\n createGlobalVersion,\n createMigration,\n createVersion,\n defaultIDType: payloadIDType,\n deleteMany,\n deleteOne,\n deleteVersions,\n destroy,\n find,\n findGlobal,\n findGlobalVersions,\n findOne,\n findVersions,\n init,\n migrate,\n migrateDown,\n migrateFresh,\n migrateRefresh,\n migrateReset,\n migrateStatus,\n migrationDir,\n payload,\n queryDrafts,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n })\n }\n\n return {\n defaultIDType: payloadIDType,\n init: adapter,\n }\n}\n\n/**\n * Attempt to find migrations directory.\n *\n * Checks for the following directories in order:\n * - `migrationDir` argument from Payload config\n * - `src/migrations`\n * - `dist/migrations`\n * - `migrations`\n *\n * Defaults to `src/migrations`\n *\n * @param migrationDir\n * @returns\n */\nfunction findMigrationDir(migrationDir?: string): string {\n const cwd = process.cwd()\n const srcDir = path.resolve(cwd, 'src/migrations')\n const distDir = path.resolve(cwd, 'dist/migrations')\n const relativeMigrations = path.resolve(cwd, 'migrations')\n\n // Use arg if provided\n if (migrationDir) return migrationDir\n\n // Check other common locations\n if (fs.existsSync(srcDir)) {\n return srcDir\n }\n\n if (fs.existsSync(distDir)) {\n return distDir\n }\n\n if (fs.existsSync(relativeMigrations)) {\n return relativeMigrations\n }\n\n return srcDir\n}\n"],"names":["fs","path","createDatabaseAdapter","connect","create","createGlobal","createGlobalVersion","createMigration","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findGlobal","findGlobalVersions","findOne","findVersions","init","migrate","migrateDown","migrateFresh","migrateRefresh","migrateReset","migrateStatus","queryDrafts","beginTransaction","commitTransaction","rollbackTransaction","updateOne","updateGlobal","updateGlobalVersion","updateVersion","sql","postgresAdapter","args","postgresIDType","idType","payloadIDType","adapter","payload","migrationDir","findMigrationDir","name","blockTableNames","drizzle","undefined","enums","fieldConstraints","localesSuffix","logger","pgSchema","pool","poolOptions","push","relations","relationshipsSuffix","schema","schemaName","sessions","tables","versionsSuffix","defaultIDType","cwd","process","srcDir","resolve","distDir","relativeMigrations","existsSync"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,UAAU,OAAM;AACvB,SAASC,qBAAqB,QAAQ,mBAAkB;AAIxD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,MAAM,QAAQ,cAAa;AACpC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,YAAY,QAAQ,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AkB;YAClBnC;YACAC;YACAxB;YACAC;YACAC;YACAC;YACAC;YACAC;YACAsD,eAAexB;YACf7B;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAiB;YACAD;YACAf;YACAG;YACAE;YACAC;YACAF;YACAG;QACF;IACF;IAEA,OAAO;QACL8B,eAAexB;QACfpB,MAAMqB;IACR;AACF;AAEA;;;;;;;;;;;;;CAaC,GACD,SAASG,iBAAiBD,YAAqB;IAC7C,MAAMsB,MAAMC,QAAQD,GAAG;IACvB,MAAME,SAAShE,KAAKiE,OAAO,CAACH,KAAK;IACjC,MAAMI,UAAUlE,KAAKiE,OAAO,CAACH,KAAK;IAClC,MAAMK,qBAAqBnE,KAAKiE,OAAO,CAACH,KAAK;IAE7C,sBAAsB;IACtB,IAAItB,cAAc,OAAOA;IAEzB,+BAA+B;IAC/B,IAAIzC,GAAGqE,UAAU,CAACJ,SAAS;QACzB,OAAOA;IACT;IAEA,IAAIjE,GAAGqE,UAAU,CAACF,UAAU;QAC1B,OAAOA;IACT;IAEA,IAAInE,GAAGqE,UAAU,CAACD,qBAAqB;QACrC,OAAOA;IACT;IAEA,OAAOH;AACT"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport type { DatabaseAdapterObj } from 'payload/database'\n\nimport fs from 'fs'\nimport path from 'path'\nimport { createDatabaseAdapter } from 'payload/database'\n\nimport type { Args, PostgresAdapter } from './types.js'\n\nimport { connect } from './connect.js'\nimport { count } from './count.js'\nimport { create } from './create.js'\nimport { createGlobal } from './createGlobal.js'\nimport { createGlobalVersion } from './createGlobalVersion.js'\nimport { createMigration } from './createMigration.js'\nimport { createVersion } from './createVersion.js'\nimport { deleteMany } from './deleteMany.js'\nimport { deleteOne } from './deleteOne.js'\nimport { deleteVersions } from './deleteVersions.js'\nimport { destroy } from './destroy.js'\nimport { find } from './find.js'\nimport { findGlobal } from './findGlobal.js'\nimport { findGlobalVersions } from './findGlobalVersions.js'\nimport { findOne } from './findOne.js'\nimport { findVersions } from './findVersions.js'\nimport { init } from './init.js'\nimport { migrate } from './migrate.js'\nimport { migrateDown } from './migrateDown.js'\nimport { migrateFresh } from './migrateFresh.js'\nimport { migrateRefresh } from './migrateRefresh.js'\nimport { migrateReset } from './migrateReset.js'\nimport { migrateStatus } from './migrateStatus.js'\nimport { queryDrafts } from './queryDrafts.js'\nimport { beginTransaction } from './transactions/beginTransaction.js'\nimport { commitTransaction } from './transactions/commitTransaction.js'\nimport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nimport { updateOne } from './update.js'\nimport { updateGlobal } from './updateGlobal.js'\nimport { updateGlobalVersion } from './updateGlobalVersion.js'\nimport { updateVersion } from './updateVersion.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 ? 'number' : 'text'\n\n function adapter({ payload }: { payload: Payload }) {\n const migrationDir = findMigrationDir(args.migrationDir)\n\n return createDatabaseAdapter<PostgresAdapter>({\n name: 'postgres',\n\n // Postgres-specific\n blockTableNames: {},\n drizzle: undefined,\n enums: {},\n fieldConstraints: {},\n idType: postgresIDType,\n localesSuffix: args.localesSuffix || '_locales',\n logger: args.logger,\n pgSchema: undefined,\n pool: undefined,\n poolOptions: args.pool,\n push: args.push,\n relations: {},\n relationshipsSuffix: args.relationshipsSuffix || '_rels',\n schema: {},\n schemaName: args.schemaName,\n sessions: {},\n tables: {},\n versionsSuffix: args.versionsSuffix || '_v',\n\n // DatabaseAdapter\n beginTransaction,\n commitTransaction,\n connect,\n count,\n create,\n createGlobal,\n createGlobalVersion,\n createMigration,\n createVersion,\n defaultIDType: payloadIDType,\n deleteMany,\n deleteOne,\n deleteVersions,\n destroy,\n find,\n findGlobal,\n findGlobalVersions,\n findOne,\n findVersions,\n init,\n migrate,\n migrateDown,\n migrateFresh,\n migrateRefresh,\n migrateReset,\n migrateStatus,\n migrationDir,\n payload,\n queryDrafts,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n })\n }\n\n return {\n defaultIDType: payloadIDType,\n init: adapter,\n }\n}\n\n/**\n * Attempt to find migrations directory.\n *\n * Checks for the following directories in order:\n * - `migrationDir` argument from Payload config\n * - `src/migrations`\n * - `dist/migrations`\n * - `migrations`\n *\n * Defaults to `src/migrations`\n *\n * @param migrationDir\n * @returns\n */\nfunction findMigrationDir(migrationDir?: string): string {\n const cwd = process.cwd()\n const srcDir = path.resolve(cwd, 'src/migrations')\n const distDir = path.resolve(cwd, 'dist/migrations')\n const relativeMigrations = path.resolve(cwd, 'migrations')\n\n // Use arg if provided\n if (migrationDir) return migrationDir\n\n // Check other common locations\n if (fs.existsSync(srcDir)) {\n return srcDir\n }\n\n if (fs.existsSync(distDir)) {\n return distDir\n }\n\n if (fs.existsSync(relativeMigrations)) {\n return relativeMigrations\n }\n\n return srcDir\n}\n"],"names":["fs","path","createDatabaseAdapter","connect","count","create","createGlobal","createGlobalVersion","createMigration","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findGlobal","findGlobalVersions","findOne","findVersions","init","migrate","migrateDown","migrateFresh","migrateRefresh","migrateReset","migrateStatus","queryDrafts","beginTransaction","commitTransaction","rollbackTransaction","updateOne","updateGlobal","updateGlobalVersion","updateVersion","sql","postgresAdapter","args","postgresIDType","idType","payloadIDType","adapter","payload","migrationDir","findMigrationDir","name","blockTableNames","drizzle","undefined","enums","fieldConstraints","localesSuffix","logger","pgSchema","pool","poolOptions","push","relations","relationshipsSuffix","schema","schemaName","sessions","tables","versionsSuffix","defaultIDType","cwd","process","srcDir","resolve","distDir","relativeMigrations","existsSync"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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"}
@@ -146,6 +146,72 @@ import { getTableName } from '../schema/getTableName.js';
146
146
  value
147
147
  });
148
148
  }
149
+ case 'select':
150
+ {
151
+ if (field.hasMany) {
152
+ newTableName = getTableName({
153
+ adapter,
154
+ config: field,
155
+ parentTableName: `${tableName}_${tableNameSuffix}`,
156
+ prefix: `${tableName}_${tableNameSuffix}`
157
+ });
158
+ if (locale && field.localized && adapter.payload.config.localization) {
159
+ joins[newTableName] = and(eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent), eq(adapter.tables[newTableName]._locale, locale));
160
+ if (locale !== 'all') {
161
+ constraints.push({
162
+ columnName: '_locale',
163
+ table: adapter.tables[newTableName],
164
+ value: locale
165
+ });
166
+ }
167
+ } else {
168
+ joins[newTableName] = eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent);
169
+ }
170
+ return {
171
+ columnName: 'value',
172
+ constraints,
173
+ field,
174
+ table: adapter.tables[newTableName]
175
+ };
176
+ }
177
+ break;
178
+ }
179
+ case 'text':
180
+ case 'number':
181
+ {
182
+ if (field.hasMany) {
183
+ let tableType = 'texts';
184
+ let columnName = 'text';
185
+ if (field.type === 'number') {
186
+ tableType = 'numbers';
187
+ columnName = 'number';
188
+ }
189
+ newTableName = `${tableName}_${tableType}`;
190
+ const joinConstraints = [
191
+ eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent),
192
+ eq(adapter.tables[newTableName].path, `${constraintPath}${field.name}`)
193
+ ];
194
+ if (locale && field.localized && adapter.payload.config.localization) {
195
+ joins[newTableName] = and(...joinConstraints, eq(adapter.tables[newTableName]._locale, locale));
196
+ if (locale !== 'all') {
197
+ constraints.push({
198
+ columnName: 'locale',
199
+ table: adapter.tables[newTableName],
200
+ value: locale
201
+ });
202
+ }
203
+ } else {
204
+ joins[newTableName] = and(...joinConstraints);
205
+ }
206
+ return {
207
+ columnName,
208
+ constraints,
209
+ field,
210
+ table: adapter.tables[newTableName]
211
+ };
212
+ }
213
+ break;
214
+ }
149
215
  case 'array':
150
216
  {
151
217
  newTableName = getTableName({
@@ -375,35 +441,32 @@ import { getTableName } from '../schema/getTableName.js';
375
441
  value
376
442
  });
377
443
  }
378
- default:
379
- {
380
- if (fieldAffectsData(field)) {
381
- if (field.localized && adapter.payload.config.localization) {
382
- // If localized, we go to localized table and set aliasTable to undefined
383
- // so it is not picked up below to be used as targetTable
384
- newTableName = `${tableName}${adapter.localesSuffix}`;
385
- const parentTable = aliasTable || adapter.tables[tableName];
386
- joins[newTableName] = eq(parentTable.id, adapter.tables[newTableName]._parentID);
387
- aliasTable = undefined;
388
- if (locale !== 'all') {
389
- constraints.push({
390
- columnName: '_locale',
391
- table: adapter.tables[newTableName],
392
- value: locale
393
- });
394
- }
395
- }
396
- const targetTable = aliasTable || adapter.tables[newTableName];
397
- selectFields[`${newTableName}.${columnPrefix}${field.name}`] = targetTable[`${columnPrefix}${field.name}`];
398
- return {
399
- columnName: `${columnPrefix}${field.name}`,
400
- constraints,
401
- field,
402
- pathSegments,
403
- table: targetTable
404
- };
405
- }
444
+ }
445
+ if (fieldAffectsData(field)) {
446
+ if (field.localized && adapter.payload.config.localization) {
447
+ // If localized, we go to localized table and set aliasTable to undefined
448
+ // so it is not picked up below to be used as targetTable
449
+ newTableName = `${tableName}${adapter.localesSuffix}`;
450
+ const parentTable = aliasTable || adapter.tables[tableName];
451
+ joins[newTableName] = eq(parentTable.id, adapter.tables[newTableName]._parentID);
452
+ aliasTable = undefined;
453
+ if (locale !== 'all') {
454
+ constraints.push({
455
+ columnName: '_locale',
456
+ table: adapter.tables[newTableName],
457
+ value: locale
458
+ });
406
459
  }
460
+ }
461
+ const targetTable = aliasTable || adapter.tables[newTableName];
462
+ selectFields[`${newTableName}.${columnPrefix}${field.name}`] = targetTable[`${columnPrefix}${field.name}`];
463
+ return {
464
+ columnName: `${columnPrefix}${field.name}`,
465
+ constraints,
466
+ field,
467
+ pathSegments,
468
+ table: targetTable
469
+ };
407
470
  }
408
471
  }
409
472
  throw new APIError(`Cannot find field for path at ${fieldPath}`);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/getTableColumnFromPath.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { SQL } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { Field, FieldAffectingData, NumberField, TabAsField, TextField } from 'payload/types'\n\nimport { and, eq, like, sql } from 'drizzle-orm'\nimport { alias } from 'drizzle-orm/pg-core'\nimport { APIError } from 'payload/errors'\nimport { fieldAffectsData, tabHasName } from 'payload/types'\nimport { flattenTopLevelFields } from 'payload/utilities'\nimport toSnakeCase from 'to-snake-case'\nimport { v4 as uuid } from 'uuid'\n\nimport type { GenericColumn, GenericTable, PostgresAdapter } from '../types.js'\nimport type { BuildQueryJoinAliases, BuildQueryJoins } from './buildQuery.js'\n\nimport { getTableName } from '../schema/getTableName.js'\n\ntype Constraint = {\n columnName: string\n table: GenericTable | PgTableWithColumns<any>\n value: unknown\n}\n\ntype TableColumn = {\n columnName?: string\n constraints: Constraint[]\n field: FieldAffectingData\n getNotNullColumnByValue?: (val: unknown) => string\n pathSegments?: string[]\n rawColumn?: SQL\n table: GenericTable | PgTableWithColumns<any>\n}\n\ntype Args = {\n adapter: PostgresAdapter\n aliasTable?: GenericTable | PgTableWithColumns<any>\n collectionPath: string\n columnPrefix?: string\n constraintPath?: string\n constraints?: Constraint[]\n fields: (Field | TabAsField)[]\n joinAliases: BuildQueryJoinAliases\n joins: BuildQueryJoins\n locale?: string\n pathSegments: string[]\n rootTableName?: string\n selectFields: Record<string, GenericColumn>\n tableName: string\n /**\n * If creating a new table name for arrays and blocks, this suffix should be appended to the table name\n */\n tableNameSuffix?: string\n /**\n * The raw value of the query before sanitization\n */\n value: unknown\n}\n/**\n * Transforms path to table and column name\n * Adds tables to `join`\n * @returns TableColumn\n */\nexport const getTableColumnFromPath = ({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix = '',\n constraintPath: incomingConstraintPath,\n constraints = [],\n fields,\n joinAliases,\n joins,\n locale: incomingLocale,\n pathSegments: incomingSegments,\n rootTableName: incomingRootTableName,\n selectFields,\n tableName,\n tableNameSuffix = '',\n value,\n}: Args): TableColumn => {\n const fieldPath = incomingSegments[0]\n let locale = incomingLocale\n const rootTableName = incomingRootTableName || tableName\n let constraintPath = incomingConstraintPath || ''\n\n const field = flattenTopLevelFields(fields as Field[]).find(\n (fieldToFind) => fieldAffectsData(fieldToFind) && fieldToFind.name === fieldPath,\n ) as Field | TabAsField\n let newTableName = tableName\n\n if (!field && fieldPath === 'id') {\n selectFields.id = adapter.tables[newTableName].id\n return {\n columnName: 'id',\n constraints,\n field: {\n name: 'id',\n type: adapter.idType === 'uuid' ? 'text' : 'number',\n } as NumberField | TextField,\n table: adapter.tables[newTableName],\n }\n }\n\n if (field) {\n const pathSegments = [...incomingSegments]\n\n // If next segment is a locale,\n // we need to take it out and use it as the locale from this point on\n if ('localized' in field && field.localized && adapter.payload.config.localization) {\n const matchedLocale = adapter.payload.config.localization.localeCodes.find(\n (locale) => locale === pathSegments[1],\n )\n\n if (matchedLocale) {\n locale = matchedLocale\n pathSegments.splice(1, 1)\n }\n }\n\n switch (field.type) {\n case 'tabs': {\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix,\n constraintPath,\n constraints,\n fields: field.tabs.map((tab) => ({\n ...tab,\n type: 'tab',\n })),\n joinAliases,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix,\n value,\n })\n }\n case 'tab': {\n if (tabHasName(field)) {\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix: `${columnPrefix}${field.name}_`,\n constraintPath: `${constraintPath}${field.name}.`,\n constraints,\n fields: field.fields,\n joinAliases,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix: `${tableNameSuffix}${toSnakeCase(field.name)}_`,\n value,\n })\n }\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix,\n constraintPath,\n constraints,\n fields: field.fields,\n joinAliases,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix,\n value,\n })\n }\n\n case 'group': {\n if (locale && field.localized && adapter.payload.config.localization) {\n newTableName = getTableName({\n adapter,\n config: field,\n locales: true,\n parentTableName: tableName,\n prefix: `${tableName}_`,\n })\n\n joins[tableName] = eq(\n adapter.tables[tableName].id,\n adapter.tables[newTableName]._parentID,\n )\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n }\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix: `${columnPrefix}${field.name}_`,\n constraintPath: `${constraintPath}${field.name}.`,\n constraints,\n fields: field.fields,\n joinAliases,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix: `${tableNameSuffix}${toSnakeCase(field.name)}_`,\n value,\n })\n }\n\n case 'array': {\n newTableName = getTableName({\n adapter,\n config: field,\n parentTableName: `${tableName}_${tableNameSuffix}`,\n prefix: `${tableName}_${tableNameSuffix}`,\n })\n constraintPath = `${constraintPath}${field.name}.%.`\n if (locale && field.localized && adapter.payload.config.localization) {\n joins[newTableName] = and(\n eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),\n eq(adapter.tables[newTableName]._locale, locale),\n )\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins[newTableName] = eq(\n adapter.tables[tableName].id,\n adapter.tables[newTableName]._parentID,\n )\n }\n return getTableColumnFromPath({\n adapter,\n collectionPath,\n constraintPath,\n constraints,\n fields: field.fields,\n joinAliases,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n value,\n })\n }\n\n case 'blocks': {\n let blockTableColumn: TableColumn\n let newTableName: string\n\n // handle blockType queries\n if (pathSegments[1] === 'blockType') {\n // find the block config using the value\n const blockTypes = Array.isArray(value) ? value : [value]\n blockTypes.forEach((blockType) => {\n const block = field.blocks.find((block) => block.slug === blockType)\n newTableName = getTableName({\n adapter,\n config: block,\n parentTableName: tableName,\n prefix: `${tableName}_blocks_`,\n })\n joins[newTableName] = eq(\n adapter.tables[tableName].id,\n adapter.tables[newTableName]._parentID,\n )\n constraints.push({\n columnName: '_path',\n table: adapter.tables[newTableName],\n value: pathSegments[0],\n })\n })\n return {\n constraints,\n field,\n getNotNullColumnByValue: () => 'id',\n table: adapter.tables[tableName],\n }\n }\n\n const hasBlockField = field.blocks.some((block) => {\n newTableName = getTableName({\n adapter,\n config: block,\n parentTableName: tableName,\n prefix: `${tableName}_blocks_`,\n })\n constraintPath = `${constraintPath}${field.name}.%.`\n let result\n const blockConstraints = []\n const blockSelectFields = {}\n try {\n result = getTableColumnFromPath({\n adapter,\n collectionPath,\n constraintPath,\n constraints: blockConstraints,\n fields: block.fields,\n joinAliases,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields: blockSelectFields,\n tableName: newTableName,\n value,\n })\n } catch (error) {\n // this is fine, not every block will have the field\n }\n if (!result) {\n return\n }\n blockTableColumn = result\n constraints = constraints.concat(blockConstraints)\n selectFields = { ...selectFields, ...blockSelectFields }\n if (field.localized && adapter.payload.config.localization) {\n joins[newTableName] = and(\n eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),\n eq(adapter.tables[newTableName]._locale, locale),\n )\n if (locale) {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins[newTableName] = eq(\n adapter.tables[tableName].id,\n adapter.tables[newTableName]._parentID,\n )\n }\n return true\n })\n if (hasBlockField) {\n return {\n columnName: blockTableColumn.columnName,\n constraints,\n field: blockTableColumn.field,\n pathSegments: pathSegments.slice(1),\n rawColumn: blockTableColumn.rawColumn,\n table: blockTableColumn.table,\n }\n }\n break\n }\n\n case 'relationship':\n case 'upload': {\n let relationshipFields\n const relationTableName = `${rootTableName}${adapter.relationshipsSuffix}`\n const newCollectionPath = pathSegments.slice(1).join('.')\n const aliasRelationshipTableName = uuid()\n const aliasRelationshipTable = alias(\n adapter.tables[relationTableName],\n aliasRelationshipTableName,\n )\n\n // Join in the relationships table\n if (locale && field.localized && adapter.payload.config.localization) {\n joinAliases.push({\n condition: and(\n eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent),\n eq(aliasRelationshipTable.locale, locale),\n like(aliasRelationshipTable.path, `${constraintPath}${field.name}`),\n ),\n table: aliasRelationshipTable,\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: 'locale',\n table: aliasRelationshipTable,\n value: locale,\n })\n }\n } else {\n // Join in the relationships table\n joinAliases.push({\n condition: and(\n eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent),\n like(aliasRelationshipTable.path, `${constraintPath}${field.name}`),\n ),\n table: aliasRelationshipTable,\n })\n }\n\n selectFields[`${relationTableName}.path`] = aliasRelationshipTable.path\n\n let newAliasTable\n\n if (typeof field.relationTo === 'string') {\n const relationshipConfig = adapter.payload.collections[field.relationTo].config\n newTableName = getTableName({\n adapter,\n config: relationshipConfig,\n })\n // parent to relationship join table\n relationshipFields = relationshipConfig.fields\n\n newAliasTable = alias(adapter.tables[newTableName], toSnakeCase(uuid()))\n\n joinAliases.push({\n condition: eq(newAliasTable.id, aliasRelationshipTable[`${field.relationTo}ID`]),\n table: newAliasTable,\n })\n\n if (newCollectionPath === '' || newCollectionPath === 'id') {\n return {\n columnName: `${field.relationTo}ID`,\n constraints,\n field,\n table: aliasRelationshipTable,\n }\n }\n } else if (newCollectionPath === 'value') {\n const tableColumnsNames = field.relationTo.map(\n (relationTo) =>\n `\"${aliasRelationshipTableName}\".\"${getTableName({\n adapter,\n config: adapter.payload.collections[relationTo].config,\n })}_id\"`,\n )\n return {\n constraints,\n field,\n rawColumn: sql.raw(`COALESCE(${tableColumnsNames.join(', ')})`),\n table: aliasRelationshipTable,\n }\n } else if (newCollectionPath === 'relationTo') {\n const relationTo = Array.isArray(field.relationTo) ? field.relationTo : [field.relationTo]\n\n return {\n constraints,\n field,\n getNotNullColumnByValue: (val) => {\n const matchedRelation = relationTo.find((relation) => relation === val)\n if (matchedRelation) return `${matchedRelation}ID`\n return undefined\n },\n table: aliasRelationshipTable,\n }\n } else {\n throw new APIError('Not supported')\n }\n\n return getTableColumnFromPath({\n adapter,\n aliasTable: newAliasTable,\n collectionPath: newCollectionPath,\n constraints,\n fields: relationshipFields,\n joinAliases,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName: newTableName,\n selectFields,\n tableName: newTableName,\n value,\n })\n }\n\n default: {\n if (fieldAffectsData(field)) {\n if (field.localized && adapter.payload.config.localization) {\n // If localized, we go to localized table and set aliasTable to undefined\n // so it is not picked up below to be used as targetTable\n newTableName = `${tableName}${adapter.localesSuffix}`\n\n const parentTable = aliasTable || adapter.tables[tableName]\n\n joins[newTableName] = eq(parentTable.id, adapter.tables[newTableName]._parentID)\n\n aliasTable = undefined\n\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n }\n\n const targetTable = aliasTable || adapter.tables[newTableName]\n\n selectFields[`${newTableName}.${columnPrefix}${field.name}`] =\n targetTable[`${columnPrefix}${field.name}`]\n\n return {\n columnName: `${columnPrefix}${field.name}`,\n constraints,\n field,\n pathSegments,\n table: targetTable,\n }\n }\n }\n }\n }\n\n throw new APIError(`Cannot find field for path at ${fieldPath}`)\n}\n"],"names":["and","eq","like","sql","alias","APIError","fieldAffectsData","tabHasName","flattenTopLevelFields","toSnakeCase","v4","uuid","getTableName","getTableColumnFromPath","adapter","aliasTable","collectionPath","columnPrefix","constraintPath","incomingConstraintPath","constraints","fields","joinAliases","joins","locale","incomingLocale","pathSegments","incomingSegments","rootTableName","incomingRootTableName","selectFields","tableName","tableNameSuffix","value","fieldPath","field","find","fieldToFind","name","newTableName","id","tables","columnName","type","idType","table","localized","payload","config","localization","matchedLocale","localeCodes","splice","tabs","map","tab","slice","locales","parentTableName","prefix","_parentID","push","_locale","blockTableColumn","blockTypes","Array","isArray","forEach","blockType","block","blocks","slug","getNotNullColumnByValue","hasBlockField","some","result","blockConstraints","blockSelectFields","error","concat","rawColumn","relationshipFields","relationTableName","relationshipsSuffix","newCollectionPath","join","aliasRelationshipTableName","aliasRelationshipTable","condition","parent","path","newAliasTable","relationTo","relationshipConfig","collections","tableColumnsNames","raw","val","matchedRelation","relation","undefined","localesSuffix","parentTable","targetTable"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAKpC,SAASA,GAAG,EAAEC,EAAE,EAAEC,IAAI,EAAEC,GAAG,QAAQ,cAAa;AAChD,SAASC,KAAK,QAAQ,sBAAqB;AAC3C,SAASC,QAAQ,QAAQ,iBAAgB;AACzC,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,gBAAe;AAC5D,SAASC,qBAAqB,QAAQ,oBAAmB;AACzD,O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ACC,MAAM,CAACC,YAAY,EAAE;4BAC1D,yEAAyE;4BACzE,yDAAyD;4BACzDV,eAAe,CAAC,EAAER,UAAU,EAAEjB,QAAQuF,aAAa,CAAC,CAAC;4BAErD,MAAMC,cAAcvF,cAAcD,QAAQ2B,MAAM,CAACV,UAAU;4BAE3DR,KAAK,CAACgB,aAAa,GAAGtC,GAAGqG,YAAY9D,EAAE,EAAE1B,QAAQ2B,MAAM,CAACF,aAAa,CAACqB,SAAS;4BAE/E7C,aAAaqF;4BAEb,IAAI5E,WAAW,OAAO;gCACpBJ,YAAYyC,IAAI,CAAC;oCACfnB,YAAY;oCACZG,OAAO/B,QAAQ2B,MAAM,CAACF,aAAa;oCACnCN,OAAOT;gCACT;4BACF;wBACF;wBAEA,MAAM+E,cAAcxF,cAAcD,QAAQ2B,MAAM,CAACF,aAAa;wBAE9DT,YAAY,CAAC,CAAC,EAAES,aAAa,CAAC,EAAEtB,aAAa,EAAEkB,MAAMG,IAAI,CAAC,CAAC,CAAC,GAC1DiE,WAAW,CAAC,CAAC,EAAEtF,aAAa,EAAEkB,MAAMG,IAAI,CAAC,CAAC,CAAC;wBAE7C,OAAO;4BACLI,YAAY,CAAC,EAAEzB,aAAa,EAAEkB,MAAMG,IAAI,CAAC,CAAC;4BAC1ClB;4BACAe;4BACAT;4BACAmB,OAAO0D;wBACT;oBACF;gBACF;QACF;IACF;IAEA,MAAM,IAAIlG,SAAS,CAAC,8BAA8B,EAAE6B,UAAU,CAAC;AACjE,EAAC"}
1
+ {"version":3,"sources":["../../src/queries/getTableColumnFromPath.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { SQL } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { Field, FieldAffectingData, NumberField, TabAsField, TextField } from 'payload/types'\n\nimport { and, eq, like, sql } from 'drizzle-orm'\nimport { alias } from 'drizzle-orm/pg-core'\nimport { APIError } from 'payload/errors'\nimport { fieldAffectsData, tabHasName } from 'payload/types'\nimport { flattenTopLevelFields } from 'payload/utilities'\nimport toSnakeCase from 'to-snake-case'\nimport { v4 as uuid } from 'uuid'\n\nimport type { GenericColumn, GenericTable, PostgresAdapter } from '../types.js'\nimport type { BuildQueryJoinAliases, BuildQueryJoins } from './buildQuery.js'\n\nimport { getTableName } from '../schema/getTableName.js'\n\ntype Constraint = {\n columnName: string\n table: GenericTable | PgTableWithColumns<any>\n value: unknown\n}\n\ntype TableColumn = {\n columnName?: string\n constraints: Constraint[]\n field: FieldAffectingData\n getNotNullColumnByValue?: (val: unknown) => string\n pathSegments?: string[]\n rawColumn?: SQL\n table: GenericTable | PgTableWithColumns<any>\n}\n\ntype Args = {\n adapter: PostgresAdapter\n aliasTable?: GenericTable | PgTableWithColumns<any>\n collectionPath: string\n columnPrefix?: string\n constraintPath?: string\n constraints?: Constraint[]\n fields: (Field | TabAsField)[]\n joinAliases: BuildQueryJoinAliases\n joins: BuildQueryJoins\n locale?: string\n pathSegments: string[]\n rootTableName?: string\n selectFields: Record<string, GenericColumn>\n tableName: string\n /**\n * If creating a new table name for arrays and blocks, this suffix should be appended to the table name\n */\n tableNameSuffix?: string\n /**\n * The raw value of the query before sanitization\n */\n value: unknown\n}\n/**\n * Transforms path to table and column name\n * Adds tables to `join`\n * @returns TableColumn\n */\nexport const getTableColumnFromPath = ({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix = '',\n constraintPath: incomingConstraintPath,\n constraints = [],\n fields,\n joinAliases,\n joins,\n locale: incomingLocale,\n pathSegments: incomingSegments,\n rootTableName: incomingRootTableName,\n selectFields,\n tableName,\n tableNameSuffix = '',\n value,\n}: Args): TableColumn => {\n const fieldPath = incomingSegments[0]\n let locale = incomingLocale\n const rootTableName = incomingRootTableName || tableName\n let constraintPath = incomingConstraintPath || ''\n\n const field = flattenTopLevelFields(fields as Field[]).find(\n (fieldToFind) => fieldAffectsData(fieldToFind) && fieldToFind.name === fieldPath,\n ) as Field | TabAsField\n let newTableName = tableName\n\n if (!field && fieldPath === 'id') {\n selectFields.id = adapter.tables[newTableName].id\n return {\n columnName: 'id',\n constraints,\n field: {\n name: 'id',\n type: adapter.idType === 'uuid' ? 'text' : 'number',\n } as NumberField | TextField,\n table: adapter.tables[newTableName],\n }\n }\n\n if (field) {\n const pathSegments = [...incomingSegments]\n\n // If next segment is a locale,\n // we need to take it out and use it as the locale from this point on\n if ('localized' in field && field.localized && adapter.payload.config.localization) {\n const matchedLocale = adapter.payload.config.localization.localeCodes.find(\n (locale) => locale === pathSegments[1],\n )\n\n if (matchedLocale) {\n locale = matchedLocale\n pathSegments.splice(1, 1)\n }\n }\n\n switch (field.type) {\n case 'tabs': {\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix,\n constraintPath,\n constraints,\n fields: field.tabs.map((tab) => ({\n ...tab,\n type: 'tab',\n })),\n joinAliases,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix,\n value,\n })\n }\n case 'tab': {\n if (tabHasName(field)) {\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix: `${columnPrefix}${field.name}_`,\n constraintPath: `${constraintPath}${field.name}.`,\n constraints,\n fields: field.fields,\n joinAliases,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix: `${tableNameSuffix}${toSnakeCase(field.name)}_`,\n value,\n })\n }\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix,\n constraintPath,\n constraints,\n fields: field.fields,\n joinAliases,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix,\n value,\n })\n }\n\n case 'group': {\n if (locale && field.localized && adapter.payload.config.localization) {\n newTableName = getTableName({\n adapter,\n config: field,\n locales: true,\n parentTableName: tableName,\n prefix: `${tableName}_`,\n })\n\n joins[tableName] = eq(\n adapter.tables[tableName].id,\n adapter.tables[newTableName]._parentID,\n )\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n }\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix: `${columnPrefix}${field.name}_`,\n constraintPath: `${constraintPath}${field.name}.`,\n constraints,\n fields: field.fields,\n joinAliases,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix: `${tableNameSuffix}${toSnakeCase(field.name)}_`,\n value,\n })\n }\n\n case 'select': {\n if (field.hasMany) {\n newTableName = getTableName({\n adapter,\n config: field,\n parentTableName: `${tableName}_${tableNameSuffix}`,\n prefix: `${tableName}_${tableNameSuffix}`,\n })\n\n if (locale && field.localized && adapter.payload.config.localization) {\n joins[newTableName] = and(\n eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent),\n eq(adapter.tables[newTableName]._locale, locale),\n )\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins[newTableName] = eq(\n adapter.tables[tableName].id,\n adapter.tables[newTableName].parent,\n )\n }\n\n return {\n columnName: 'value',\n constraints,\n field,\n table: adapter.tables[newTableName],\n }\n }\n break\n }\n\n case 'text':\n case 'number': {\n if (field.hasMany) {\n let tableType = 'texts'\n let columnName = 'text'\n if (field.type === 'number') {\n tableType = 'numbers'\n columnName = 'number'\n }\n newTableName = `${tableName}_${tableType}`\n const joinConstraints = [\n eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent),\n eq(adapter.tables[newTableName].path, `${constraintPath}${field.name}`),\n ]\n\n if (locale && field.localized && adapter.payload.config.localization) {\n joins[newTableName] = and(\n ...joinConstraints,\n eq(adapter.tables[newTableName]._locale, locale),\n )\n if (locale !== 'all') {\n constraints.push({\n columnName: 'locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins[newTableName] = and(...joinConstraints)\n }\n\n return {\n columnName,\n constraints,\n field,\n table: adapter.tables[newTableName],\n }\n }\n break\n }\n\n case 'array': {\n newTableName = getTableName({\n adapter,\n config: field,\n parentTableName: `${tableName}_${tableNameSuffix}`,\n prefix: `${tableName}_${tableNameSuffix}`,\n })\n constraintPath = `${constraintPath}${field.name}.%.`\n if (locale && field.localized && adapter.payload.config.localization) {\n joins[newTableName] = and(\n eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),\n eq(adapter.tables[newTableName]._locale, locale),\n )\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins[newTableName] = eq(\n adapter.tables[tableName].id,\n adapter.tables[newTableName]._parentID,\n )\n }\n return getTableColumnFromPath({\n adapter,\n collectionPath,\n constraintPath,\n constraints,\n fields: field.fields,\n joinAliases,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n value,\n })\n }\n\n case 'blocks': {\n let blockTableColumn: TableColumn\n let newTableName: string\n\n // handle blockType queries\n if (pathSegments[1] === 'blockType') {\n // find the block config using the value\n const blockTypes = Array.isArray(value) ? value : [value]\n blockTypes.forEach((blockType) => {\n const block = field.blocks.find((block) => block.slug === blockType)\n newTableName = getTableName({\n adapter,\n config: block,\n parentTableName: tableName,\n prefix: `${tableName}_blocks_`,\n })\n joins[newTableName] = eq(\n adapter.tables[tableName].id,\n adapter.tables[newTableName]._parentID,\n )\n constraints.push({\n columnName: '_path',\n table: adapter.tables[newTableName],\n value: pathSegments[0],\n })\n })\n return {\n constraints,\n field,\n getNotNullColumnByValue: () => 'id',\n table: adapter.tables[tableName],\n }\n }\n\n const hasBlockField = field.blocks.some((block) => {\n newTableName = getTableName({\n adapter,\n config: block,\n parentTableName: tableName,\n prefix: `${tableName}_blocks_`,\n })\n constraintPath = `${constraintPath}${field.name}.%.`\n let result\n const blockConstraints = []\n const blockSelectFields = {}\n try {\n result = getTableColumnFromPath({\n adapter,\n collectionPath,\n constraintPath,\n constraints: blockConstraints,\n fields: block.fields,\n joinAliases,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields: blockSelectFields,\n tableName: newTableName,\n value,\n })\n } catch (error) {\n // this is fine, not every block will have the field\n }\n if (!result) {\n return\n }\n blockTableColumn = result\n constraints = constraints.concat(blockConstraints)\n selectFields = { ...selectFields, ...blockSelectFields }\n if (field.localized && adapter.payload.config.localization) {\n joins[newTableName] = and(\n eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),\n eq(adapter.tables[newTableName]._locale, locale),\n )\n if (locale) {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins[newTableName] = eq(\n adapter.tables[tableName].id,\n adapter.tables[newTableName]._parentID,\n )\n }\n return true\n })\n if (hasBlockField) {\n return {\n columnName: blockTableColumn.columnName,\n constraints,\n field: blockTableColumn.field,\n pathSegments: pathSegments.slice(1),\n rawColumn: blockTableColumn.rawColumn,\n table: blockTableColumn.table,\n }\n }\n break\n }\n\n case 'relationship':\n case 'upload': {\n let relationshipFields\n const relationTableName = `${rootTableName}${adapter.relationshipsSuffix}`\n const newCollectionPath = pathSegments.slice(1).join('.')\n const aliasRelationshipTableName = uuid()\n const aliasRelationshipTable = alias(\n adapter.tables[relationTableName],\n aliasRelationshipTableName,\n )\n\n // Join in the relationships table\n if (locale && field.localized && adapter.payload.config.localization) {\n joinAliases.push({\n condition: and(\n eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent),\n eq(aliasRelationshipTable.locale, locale),\n like(aliasRelationshipTable.path, `${constraintPath}${field.name}`),\n ),\n table: aliasRelationshipTable,\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: 'locale',\n table: aliasRelationshipTable,\n value: locale,\n })\n }\n } else {\n // Join in the relationships table\n joinAliases.push({\n condition: and(\n eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent),\n like(aliasRelationshipTable.path, `${constraintPath}${field.name}`),\n ),\n table: aliasRelationshipTable,\n })\n }\n\n selectFields[`${relationTableName}.path`] = aliasRelationshipTable.path\n\n let newAliasTable\n\n if (typeof field.relationTo === 'string') {\n const relationshipConfig = adapter.payload.collections[field.relationTo].config\n newTableName = getTableName({\n adapter,\n config: relationshipConfig,\n })\n // parent to relationship join table\n relationshipFields = relationshipConfig.fields\n\n newAliasTable = alias(adapter.tables[newTableName], toSnakeCase(uuid()))\n\n joinAliases.push({\n condition: eq(newAliasTable.id, aliasRelationshipTable[`${field.relationTo}ID`]),\n table: newAliasTable,\n })\n\n if (newCollectionPath === '' || newCollectionPath === 'id') {\n return {\n columnName: `${field.relationTo}ID`,\n constraints,\n field,\n table: aliasRelationshipTable,\n }\n }\n } else if (newCollectionPath === 'value') {\n const tableColumnsNames = field.relationTo.map(\n (relationTo) =>\n `\"${aliasRelationshipTableName}\".\"${getTableName({\n adapter,\n config: adapter.payload.collections[relationTo].config,\n })}_id\"`,\n )\n return {\n constraints,\n field,\n rawColumn: sql.raw(`COALESCE(${tableColumnsNames.join(', ')})`),\n table: aliasRelationshipTable,\n }\n } else if (newCollectionPath === 'relationTo') {\n const relationTo = Array.isArray(field.relationTo) ? field.relationTo : [field.relationTo]\n\n return {\n constraints,\n field,\n getNotNullColumnByValue: (val) => {\n const matchedRelation = relationTo.find((relation) => relation === val)\n if (matchedRelation) return `${matchedRelation}ID`\n return undefined\n },\n table: aliasRelationshipTable,\n }\n } else {\n throw new APIError('Not supported')\n }\n\n return getTableColumnFromPath({\n adapter,\n aliasTable: newAliasTable,\n collectionPath: newCollectionPath,\n constraints,\n fields: relationshipFields,\n joinAliases,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName: newTableName,\n selectFields,\n tableName: newTableName,\n value,\n })\n }\n }\n\n if (fieldAffectsData(field)) {\n if (field.localized && adapter.payload.config.localization) {\n // If localized, we go to localized table and set aliasTable to undefined\n // so it is not picked up below to be used as targetTable\n newTableName = `${tableName}${adapter.localesSuffix}`\n\n const parentTable = aliasTable || adapter.tables[tableName]\n\n joins[newTableName] = eq(parentTable.id, adapter.tables[newTableName]._parentID)\n\n aliasTable = undefined\n\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n }\n\n const targetTable = aliasTable || adapter.tables[newTableName]\n\n selectFields[`${newTableName}.${columnPrefix}${field.name}`] =\n targetTable[`${columnPrefix}${field.name}`]\n\n return {\n columnName: `${columnPrefix}${field.name}`,\n constraints,\n field,\n pathSegments,\n table: targetTable,\n }\n }\n }\n\n throw new APIError(`Cannot find field for path at ${fieldPath}`)\n}\n"],"names":["and","eq","like","sql","alias","APIError","fieldAffectsData","tabHasName","flattenTopLevelFields","toSnakeCase","v4","uuid","getTableName","getTableColumnFromPath","adapter","aliasTable","collectionPath","columnPrefix","constraintPath","incomingConstraintPath","constraints","fields","joinAliases","joins","locale","incomingLocale","pathSegments","incomingSegments","rootTableName","incomingRootTableName","selectFields","tableName","tableNameSuffix","value","fieldPath","field","find","fieldToFind","name","newTableName","id","tables","columnName","type","idType","table","localized","payload","config","localization","matchedLocale","localeCodes","splice","tabs","map","tab","slice","locales","parentTableName","prefix","_parentID","push","hasMany","parent","_locale","tableType","joinConstraints","path","blockTableColumn","blockTypes","Array","isArray","forEach","blockType","block","blocks","slug","getNotNullColumnByValue","hasBlockField","some","result","blockConstraints","blockSelectFields","error","concat","rawColumn","relationshipFields","relationTableName","relationshipsSuffix","newCollectionPath","join","aliasRelationshipTableName","aliasRelationshipTable","condition","newAliasTable","relationTo","relationshipConfig","collections","tableColumnsNames","raw","val","matchedRelation","relation","undefined","localesSuffix","parentTable","targetTable"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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CAAC,CAAA;IACtE,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;IACvB,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACrC,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC1B,oBAAoB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC1C,kBAAkB,EAAE,MAAM,CAAA;IAC1B,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,KAAK,MAAM,GAAG;IACZ,iBAAiB,EAAE,OAAO,CAAA;IAC1B,2BAA2B,EAAE,OAAO,CAAA;IACpC,yBAAyB,EAAE,OAAO,CAAA;IAClC,6BAA6B,EAAE,OAAO,CAAA;IACtC,kBAAkB,EAAE,OAAO,GAAG,OAAO,CAAA;IACrC,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAA;CACpC,CAAA;AAED,eAAO,MAAM,cAAc,sUAuBxB,IAAI,KAAG,MAinBT,CAAA"}
@@ -136,8 +136,7 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
136
136
  parentTableName: newTableName,
137
137
  prefix: `enum_${newTableName}_`,
138
138
  target: 'enumName',
139
- throwValidationError,
140
- versions
139
+ throwValidationError
141
140
  });
142
141
  adapter.enums[enumName] = pgEnum(enumName, field.options.map((option)=>{
143
142
  if (optionIsObject(option)) {
@@ -151,8 +150,7 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
151
150
  config: field,
152
151
  parentTableName: newTableName,
153
152
  prefix: `${newTableName}_`,
154
- throwValidationError,
155
- versions
153
+ throwValidationError
156
154
  });
157
155
  const baseColumns = {
158
156
  order: integer('order').notNull(),
@@ -347,7 +345,8 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
347
345
  block,
348
346
  localized: field.localized,
349
347
  rootTableName,
350
- table: adapter.tables[blockTableName]
348
+ table: adapter.tables[blockTableName],
349
+ tableLocales: adapter.tables[`${blockTableName}${adapter.localesSuffix}`]
351
350
  });
352
351
  }
353
352
  adapter.blockTableNames[`${rootTableName}.${toSnakeCase(block.slug)}`] = blockTableName;
@@ -481,7 +480,7 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
481
480
  indexes,
482
481
  localesColumns,
483
482
  localesIndexes,
484
- newTableName: parentTableName,
483
+ newTableName,
485
484
  parentTableName,
486
485
  relationsToBuild,
487
486
  relationships,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema/traverseFields.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Relation } from 'drizzle-orm'\nimport type { IndexBuilder, PgColumnBuilder, UniqueConstraintBuilder } from 'drizzle-orm/pg-core'\nimport type { Field, TabAsField } from 'payload/types'\n\nimport { relations } from 'drizzle-orm'\nimport {\n PgNumericBuilder,\n PgUUIDBuilder,\n PgVarcharBuilder,\n boolean,\n index,\n integer,\n jsonb,\n numeric,\n pgEnum,\n text,\n timestamp,\n varchar,\n} from 'drizzle-orm/pg-core'\nimport { InvalidConfiguration } from 'payload/errors'\nimport { fieldAffectsData, optionIsObject } from 'payload/types'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { GenericColumns, IDType, PostgresAdapter } from '../types.js'\n\nimport { hasLocalesTable } from '../utilities/hasLocalesTable.js'\nimport { buildTable } from './build.js'\nimport { createIndex } from './createIndex.js'\nimport { getTableName } from './getTableName.js'\nimport { idToUUID } from './idToUUID.js'\nimport { parentIDColumnMap } from './parentIDColumnMap.js'\nimport { validateExistingBlockIsIdentical } from './validateExistingBlockIsIdentical.js'\n\ntype Args = {\n adapter: PostgresAdapter\n buildNumbers: boolean\n buildRelationships: boolean\n buildTexts: boolean\n columnPrefix?: string\n columns: Record<string, PgColumnBuilder>\n disableNotNull: boolean\n disableUnique?: boolean\n fieldPrefix?: string\n fields: (Field | TabAsField)[]\n forceLocalized?: boolean\n indexes: Record<string, (cols: GenericColumns) => IndexBuilder>\n localesColumns: Record<string, PgColumnBuilder>\n localesIndexes: Record<string, (cols: GenericColumns) => IndexBuilder>\n newTableName: string\n parentTableName: string\n relationsToBuild: Map<string, string>\n relationships: Set<string>\n rootRelationsToBuild?: Map<string, string>\n rootTableIDColType: string\n rootTableName: string\n versions: boolean\n}\n\ntype Result = {\n hasLocalizedField: boolean\n hasLocalizedManyNumberField: boolean\n hasLocalizedManyTextField: boolean\n hasLocalizedRelationshipField: boolean\n hasManyNumberField: 'index' | boolean\n hasManyTextField: 'index' | boolean\n}\n\nexport const traverseFields = ({\n adapter,\n buildNumbers,\n buildRelationships,\n buildTexts,\n columnPrefix,\n columns,\n disableNotNull,\n disableUnique = false,\n fieldPrefix,\n fields,\n forceLocalized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName,\n parentTableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n versions,\n}: Args): Result => {\n const throwValidationError = true\n let hasLocalizedField = false\n let hasLocalizedRelationshipField = false\n let hasManyTextField: 'index' | boolean = false\n let hasLocalizedManyTextField = false\n let hasManyNumberField: 'index' | boolean = false\n let hasLocalizedManyNumberField = false\n\n let parentIDColType: IDType = 'integer'\n if (columns.id instanceof PgUUIDBuilder) parentIDColType = 'uuid'\n if (columns.id instanceof PgNumericBuilder) parentIDColType = 'numeric'\n if (columns.id instanceof PgVarcharBuilder) parentIDColType = 'varchar'\n\n fields.forEach((field) => {\n if ('name' in field && field.name === 'id') return\n let columnName: string\n let fieldName: string\n\n let targetTable = columns\n let targetIndexes = indexes\n\n if (fieldAffectsData(field)) {\n columnName = `${columnPrefix || ''}${field.name[0] === '_' ? '_' : ''}${toSnakeCase(\n field.name,\n )}`\n fieldName = `${fieldPrefix?.replace('.', '_') || ''}${field.name}`\n\n // If field is localized,\n // add the column to the locale table instead of main table\n if (adapter.payload.config.localization && (field.localized || forceLocalized)) {\n hasLocalizedField = true\n targetTable = localesColumns\n targetIndexes = localesIndexes\n }\n\n if (\n (field.unique || field.index) &&\n !['array', 'blocks', 'group', 'point', 'relationship', 'upload'].includes(field.type) &&\n !('hasMany' in field && field.hasMany === true)\n ) {\n const unique = disableUnique !== true && field.unique\n if (unique) {\n const constraintValue = `${fieldPrefix || ''}${field.name}`\n if (!adapter.fieldConstraints?.[rootTableName]) {\n adapter.fieldConstraints[rootTableName] = {}\n }\n adapter.fieldConstraints[rootTableName][`${columnName}_idx`] = constraintValue\n }\n targetIndexes[`${newTableName}_${field.name}Idx`] = createIndex({\n name: fieldName,\n columnName,\n tableName: newTableName,\n unique,\n })\n }\n }\n\n switch (field.type) {\n case 'text': {\n if (field.hasMany) {\n if (field.localized) {\n hasLocalizedManyTextField = true\n }\n\n if (field.index) {\n hasManyTextField = 'index'\n } else if (!hasManyTextField) {\n hasManyTextField = true\n }\n\n if (field.unique) {\n throw new InvalidConfiguration(\n 'Unique is not supported in Postgres for hasMany text fields.',\n )\n }\n } else {\n targetTable[fieldName] = varchar(columnName)\n }\n break\n }\n case 'email':\n case 'code':\n case 'textarea': {\n targetTable[fieldName] = varchar(columnName)\n break\n }\n\n case 'number': {\n if (field.hasMany) {\n if (field.localized) {\n hasLocalizedManyNumberField = true\n }\n\n if (field.index) {\n hasManyNumberField = 'index'\n } else if (!hasManyNumberField) {\n hasManyNumberField = true\n }\n\n if (field.unique) {\n throw new InvalidConfiguration(\n 'Unique is not supported in Postgres for hasMany number fields.',\n )\n }\n } else {\n targetTable[fieldName] = numeric(columnName)\n }\n break\n }\n\n case 'richText':\n case 'json': {\n targetTable[fieldName] = jsonb(columnName)\n break\n }\n\n case 'date': {\n targetTable[fieldName] = timestamp(columnName, {\n mode: 'string',\n precision: 3,\n withTimezone: true,\n })\n break\n }\n\n case 'point': {\n break\n }\n\n case 'radio':\n case 'select': {\n const enumName = getTableName({\n adapter,\n config: field,\n parentTableName: newTableName,\n prefix: `enum_${newTableName}_`,\n target: 'enumName',\n throwValidationError,\n versions,\n })\n\n adapter.enums[enumName] = pgEnum(\n enumName,\n field.options.map((option) => {\n if (optionIsObject(option)) {\n return option.value\n }\n\n return option\n }) as [string, ...string[]],\n )\n\n if (field.type === 'select' && field.hasMany) {\n const selectTableName = getTableName({\n adapter,\n config: field,\n parentTableName: newTableName,\n prefix: `${newTableName}_`,\n throwValidationError,\n versions,\n })\n const baseColumns: Record<string, PgColumnBuilder> = {\n order: integer('order').notNull(),\n parent: parentIDColumnMap[parentIDColType]('parent_id')\n .references(() => adapter.tables[parentTableName].id, { onDelete: 'cascade' })\n .notNull(),\n value: adapter.enums[enumName]('value'),\n }\n\n const baseExtraConfig: Record<\n string,\n (cols: GenericColumns) => IndexBuilder | UniqueConstraintBuilder\n > = {\n orderIdx: (cols) => index(`${selectTableName}_order_idx`).on(cols.order),\n parentIdx: (cols) => index(`${selectTableName}_parent_idx`).on(cols.parent),\n }\n\n if (field.localized) {\n baseColumns.locale = adapter.enums.enum__locales('locale').notNull()\n baseExtraConfig.localeIdx = (cols) =>\n index(`${selectTableName}_locale_idx`).on(cols.locale)\n }\n\n if (field.index) {\n baseExtraConfig.value = (cols) => index(`${selectTableName}_value_idx`).on(cols.value)\n }\n\n buildTable({\n adapter,\n baseColumns,\n baseExtraConfig,\n disableNotNull,\n disableUnique,\n fields: [],\n tableName: selectTableName,\n versions,\n })\n\n relationsToBuild.set(fieldName, selectTableName)\n\n const selectTableRelations = relations(adapter.tables[selectTableName], ({ one }) => {\n const result: Record<string, Relation<string>> = {\n parent: one(adapter.tables[parentTableName], {\n fields: [adapter.tables[selectTableName].parent],\n references: [adapter.tables[parentTableName].id],\n }),\n }\n\n return result\n })\n\n adapter.relations[`relation_${selectTableName}`] = selectTableRelations\n } else {\n targetTable[fieldName] = adapter.enums[enumName](fieldName)\n }\n break\n }\n\n case 'checkbox': {\n targetTable[fieldName] = boolean(columnName)\n break\n }\n\n case 'array': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n const arrayTableName = getTableName({\n adapter,\n config: field,\n parentTableName: newTableName,\n prefix: `${newTableName}_`,\n throwValidationError,\n })\n const baseColumns: Record<string, PgColumnBuilder> = {\n _order: integer('_order').notNull(),\n _parentID: parentIDColumnMap[parentIDColType]('_parent_id')\n .references(() => adapter.tables[parentTableName].id, { onDelete: 'cascade' })\n .notNull(),\n }\n\n const baseExtraConfig: Record<\n string,\n (cols: GenericColumns) => IndexBuilder | UniqueConstraintBuilder\n > = {\n _orderIdx: (cols) => index(`${arrayTableName}_order_idx`).on(cols._order),\n _parentIDIdx: (cols) => index(`${arrayTableName}_parent_id_idx`).on(cols._parentID),\n }\n\n if (field.localized && adapter.payload.config.localization) {\n baseColumns._locale = adapter.enums.enum__locales('_locale').notNull()\n baseExtraConfig._localeIdx = (cols) =>\n index(`${arrayTableName}_locale_idx`).on(cols._locale)\n }\n\n const {\n hasManyNumberField: subHasManyNumberField,\n hasManyTextField: subHasManyTextField,\n relationsToBuild: subRelationsToBuild,\n } = buildTable({\n adapter,\n baseColumns,\n baseExtraConfig,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fields: disableUnique ? idToUUID(field.fields) : field.fields,\n rootRelationsToBuild,\n rootRelationships: relationships,\n rootTableIDColType,\n rootTableName,\n tableName: arrayTableName,\n versions,\n })\n\n if (subHasManyTextField) {\n if (!hasManyTextField || subHasManyTextField === 'index')\n hasManyTextField = subHasManyTextField\n }\n if (subHasManyNumberField) {\n if (!hasManyNumberField || subHasManyNumberField === 'index')\n hasManyNumberField = subHasManyNumberField\n }\n\n relationsToBuild.set(fieldName, arrayTableName)\n\n const arrayTableRelations = relations(adapter.tables[arrayTableName], ({ many, one }) => {\n const result: Record<string, Relation<string>> = {\n _parentID: one(adapter.tables[parentTableName], {\n fields: [adapter.tables[arrayTableName]._parentID],\n references: [adapter.tables[parentTableName].id],\n }),\n }\n\n if (hasLocalesTable(field.fields)) {\n result._locales = many(adapter.tables[`${arrayTableName}${adapter.localesSuffix}`])\n }\n\n subRelationsToBuild.forEach((val, key) => {\n result[key] = many(adapter.tables[val])\n })\n\n return result\n })\n\n adapter.relations[`relations_${arrayTableName}`] = arrayTableRelations\n\n break\n }\n\n case 'blocks': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n field.blocks.forEach((block) => {\n const blockTableName = getTableName({\n adapter,\n config: block,\n parentTableName: rootTableName,\n prefix: `${rootTableName}_blocks_`,\n throwValidationError,\n })\n if (!adapter.tables[blockTableName]) {\n const baseColumns: Record<string, PgColumnBuilder> = {\n _order: integer('_order').notNull(),\n _parentID: parentIDColumnMap[rootTableIDColType]('_parent_id')\n .references(() => adapter.tables[rootTableName].id, { onDelete: 'cascade' })\n .notNull(),\n _path: text('_path').notNull(),\n }\n\n const baseExtraConfig: Record<\n string,\n (cols: GenericColumns) => IndexBuilder | UniqueConstraintBuilder\n > = {\n _orderIdx: (cols) => index(`${blockTableName}_order_idx`).on(cols._order),\n _parentIDIdx: (cols) => index(`${blockTableName}_parent_id_idx`).on(cols._parentID),\n _pathIdx: (cols) => index(`${blockTableName}_path_idx`).on(cols._path),\n }\n\n if (field.localized && adapter.payload.config.localization) {\n baseColumns._locale = adapter.enums.enum__locales('_locale').notNull()\n baseExtraConfig._localeIdx = (cols) =>\n index(`${blockTableName}_locale_idx`).on(cols._locale)\n }\n\n const {\n hasManyNumberField: subHasManyNumberField,\n hasManyTextField: subHasManyTextField,\n relationsToBuild: subRelationsToBuild,\n } = buildTable({\n adapter,\n baseColumns,\n baseExtraConfig,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fields: disableUnique ? idToUUID(block.fields) : block.fields,\n rootRelationsToBuild,\n rootRelationships: relationships,\n rootTableIDColType,\n rootTableName,\n tableName: blockTableName,\n versions,\n })\n\n if (subHasManyTextField) {\n if (!hasManyTextField || subHasManyTextField === 'index')\n hasManyTextField = subHasManyTextField\n }\n\n if (subHasManyNumberField) {\n if (!hasManyNumberField || subHasManyNumberField === 'index')\n hasManyNumberField = subHasManyNumberField\n }\n\n const blockTableRelations = relations(\n adapter.tables[blockTableName],\n ({ many, one }) => {\n const result: Record<string, Relation<string>> = {\n _parentID: one(adapter.tables[rootTableName], {\n fields: [adapter.tables[blockTableName]._parentID],\n references: [adapter.tables[rootTableName].id],\n }),\n }\n\n if (hasLocalesTable(block.fields)) {\n result._locales = many(\n adapter.tables[`${blockTableName}${adapter.localesSuffix}`],\n )\n }\n\n subRelationsToBuild.forEach((val, key) => {\n result[key] = many(adapter.tables[val])\n })\n\n return result\n },\n )\n\n adapter.relations[`relations_${blockTableName}`] = blockTableRelations\n } else if (process.env.NODE_ENV !== 'production' && !versions) {\n validateExistingBlockIsIdentical({\n block,\n localized: field.localized,\n rootTableName,\n table: adapter.tables[blockTableName],\n })\n }\n adapter.blockTableNames[`${rootTableName}.${toSnakeCase(block.slug)}`] = blockTableName\n rootRelationsToBuild.set(`_blocks_${block.slug}`, blockTableName)\n })\n\n break\n }\n\n case 'tab':\n case 'group': {\n if (!('name' in field)) {\n const {\n hasLocalizedField: groupHasLocalizedField,\n hasLocalizedManyNumberField: groupHasLocalizedManyNumberField,\n hasLocalizedManyTextField: groupHasLocalizedManyTextField,\n hasLocalizedRelationshipField: groupHasLocalizedRelationshipField,\n hasManyNumberField: groupHasManyNumberField,\n hasManyTextField: groupHasManyTextField,\n } = traverseFields({\n adapter,\n buildNumbers,\n buildRelationships,\n buildTexts,\n columnPrefix,\n columns,\n disableNotNull,\n disableUnique,\n fieldPrefix,\n fields: field.fields,\n forceLocalized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName,\n parentTableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n versions,\n })\n\n if (groupHasLocalizedField) hasLocalizedField = true\n if (groupHasLocalizedRelationshipField) hasLocalizedRelationshipField = true\n if (groupHasManyTextField) hasManyTextField = true\n if (groupHasLocalizedManyTextField) hasLocalizedManyTextField = true\n if (groupHasManyNumberField) hasManyNumberField = true\n if (groupHasLocalizedManyNumberField) hasLocalizedManyNumberField = true\n break\n }\n\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n const {\n hasLocalizedField: groupHasLocalizedField,\n hasLocalizedManyNumberField: groupHasLocalizedManyNumberField,\n hasLocalizedManyTextField: groupHasLocalizedManyTextField,\n hasLocalizedRelationshipField: groupHasLocalizedRelationshipField,\n hasManyNumberField: groupHasManyNumberField,\n hasManyTextField: groupHasManyTextField,\n } = traverseFields({\n adapter,\n buildNumbers,\n buildRelationships,\n buildTexts,\n columnPrefix: `${columnName}_`,\n columns,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fieldPrefix: `${fieldName}.`,\n fields: field.fields,\n forceLocalized: field.localized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName: `${parentTableName}_${columnName}`,\n parentTableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n versions,\n })\n\n if (groupHasLocalizedField) hasLocalizedField = true\n if (groupHasLocalizedRelationshipField) hasLocalizedRelationshipField = true\n if (groupHasManyTextField) hasManyTextField = true\n if (groupHasLocalizedManyTextField) hasLocalizedManyTextField = true\n if (groupHasManyNumberField) hasManyNumberField = true\n if (groupHasLocalizedManyNumberField) hasLocalizedManyNumberField = true\n break\n }\n\n case 'tabs': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n const {\n hasLocalizedField: tabHasLocalizedField,\n hasLocalizedManyNumberField: tabHasLocalizedManyNumberField,\n hasLocalizedManyTextField: tabHasLocalizedManyTextField,\n hasLocalizedRelationshipField: tabHasLocalizedRelationshipField,\n hasManyNumberField: tabHasManyNumberField,\n hasManyTextField: tabHasManyTextField,\n } = traverseFields({\n adapter,\n buildNumbers,\n buildRelationships,\n buildTexts,\n columnPrefix,\n columns,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fieldPrefix,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n forceLocalized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName,\n parentTableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n versions,\n })\n\n if (tabHasLocalizedField) hasLocalizedField = true\n if (tabHasLocalizedRelationshipField) hasLocalizedRelationshipField = true\n if (tabHasManyTextField) hasManyTextField = true\n if (tabHasLocalizedManyTextField) hasLocalizedManyTextField = true\n if (tabHasManyNumberField) hasManyNumberField = true\n if (tabHasLocalizedManyNumberField) hasLocalizedManyNumberField = true\n break\n }\n\n case 'row':\n case 'collapsible': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n const {\n hasLocalizedField: rowHasLocalizedField,\n hasLocalizedManyNumberField: rowHasLocalizedManyNumberField,\n hasLocalizedManyTextField: rowHasLocalizedManyTextField,\n hasLocalizedRelationshipField: rowHasLocalizedRelationshipField,\n hasManyNumberField: rowHasManyNumberField,\n hasManyTextField: rowHasManyTextField,\n } = traverseFields({\n adapter,\n buildNumbers,\n buildRelationships,\n buildTexts,\n columnPrefix,\n columns,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fieldPrefix,\n fields: field.fields,\n forceLocalized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName: parentTableName,\n parentTableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n versions,\n })\n\n if (rowHasLocalizedField) hasLocalizedField = true\n if (rowHasLocalizedRelationshipField) hasLocalizedRelationshipField = true\n if (rowHasManyTextField) hasManyTextField = true\n if (rowHasLocalizedManyTextField) hasLocalizedManyTextField = true\n if (rowHasManyNumberField) hasManyNumberField = true\n if (rowHasLocalizedManyNumberField) hasLocalizedManyNumberField = true\n break\n }\n\n case 'relationship':\n case 'upload':\n if (Array.isArray(field.relationTo)) {\n field.relationTo.forEach((relation) => relationships.add(relation))\n } else {\n relationships.add(field.relationTo)\n }\n\n if (field.localized && adapter.payload.config.localization) {\n hasLocalizedRelationshipField = true\n }\n break\n\n default:\n break\n }\n\n const condition = field.admin && field.admin.condition\n\n if (\n !disableNotNull &&\n targetTable[fieldName] &&\n 'required' in field &&\n field.required &&\n !condition\n ) {\n targetTable[fieldName].notNull()\n }\n })\n\n return {\n hasLocalizedField,\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n }\n}\n"],"names":["relations","PgNumericBuilder","PgUUIDBuilder","PgVarcharBuilder","boolean","index","integer","jsonb","numeric","pgEnum","text","timestamp","varchar","InvalidConfiguration","fieldAffectsData","optionIsObject","toSnakeCase","hasLocalesTable","buildTable","createIndex","getTableName","idToUUID","parentIDColumnMap","validateExistingBlockIsIdentical","traverseFields","adapter","buildNumbers","buildRelationships","buildTexts","columnPrefix","columns","disableNotNull","disableUnique","fieldPrefix","fields","forceLocalized","indexes","localesColumns","localesIndexes","newTableName","parentTableName","relationsToBuild","relationships","rootRelationsToBuild","rootTableIDColType","rootTableName","versions","throwValidationError","hasLocalizedField","hasLocalizedRelationshipField","hasManyTextField","hasLocalizedManyTextField","hasManyNumberField","hasLocalizedManyNumberField","parentIDColType","id","forEach","field","name","columnName","fieldName","targetTable","targetIndexes","replace","payload","config","localization","localized","unique","includes","type","hasMany","constraintValue","fieldConstraints","tableName","mode","precision","withTimezone","enumName","prefix","target","enums","options","map","option","value","selectTableName","baseColumns","order","notNull","parent","references","tables","onDelete","baseExtraConfig","orderIdx","cols","on","parentIdx","locale","enum__locales","localeIdx","set","selectTableRelations","one","result","disableNotNullFromHere","Boolean","admin","condition","arrayTableName","_order","_parentID","_orderIdx","_parentIDIdx","_locale","_localeIdx","subHasManyNumberField","subHasManyTextField","subRelationsToBuild","rootRelationships","arrayTableRelations","many","_locales","localesSuffix","val","key","blocks","block","blockTableName","_path","_pathIdx","blockTableRelations","process","env","NODE_ENV","table","blockTableNames","slug","groupHasLocalizedField","groupHasLocalizedManyNumberField","groupHasLocalizedManyTextField","groupHasLocalizedRelationshipField","groupHasManyNumberField","groupHasManyTextField","tabHasLocalizedField","tabHasLocalizedManyNumberField","tabHasLocalizedManyTextField","tabHasLocalizedRelationshipField","tabHasManyNumberField","tabHasManyTextField","tabs","tab","rowHasLocalizedField","rowHasLocalizedManyNumberField","rowHasLocalizedManyTextField","rowHasLocalizedRelationshipField","rowHasManyNumberField","rowHasManyTextField","Array","isArray","relationTo","relation","add","required"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAKpC,SAASA,SAAS,QAAQ,cAAa;AACvC,SACEC,gBAAgB,EAChBC,aAAa,EACbC,gBAAgB,EAChBC,OAAO,EACPC,KAAK,EACLC,OAAO,EACPC,KAAK,EACLC,OAAO,EACPC,MAAM,EACNC,IAAI,EACJC,SAAS,EACTC,OAAO,QACF,sBAAqB;AAC5B,SAASC,oBAAoB,QAAQ,iBAAgB;AACrD,SAASC,gBAAgB,EAAEC,cAAc,QAAQ,gBAAe;AAChE,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,eAAe,QAAQ,kCAAiC;AACjE,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;wBACpBC;wBACAC;wBACAC;wBACAC;wBACAC,cAAcC;wBACdA;wBACAC;wBACAC;wBACAC;wBACAC;wBACAC;wBACAC;oBACF;oBAEA,IAAI2G,sBAAsBzG,oBAAoB;oBAC9C,IAAI4G,kCAAkC3G,gCAAgC;oBACtE,IAAI6G,qBAAqB5G,mBAAmB;oBAC5C,IAAIyG,8BAA8BxG,4BAA4B;oBAC9D,IAAI0G,uBAAuBzG,qBAAqB;oBAChD,IAAIsG,gCAAgCrG,8BAA8B;oBAClE;gBACF;YAEA,KAAK;YACL,KAAK;gBACH,IAAI0G,MAAMC,OAAO,CAACvG,MAAMwG,UAAU,GAAG;oBACnCxG,MAAMwG,UAAU,CAACzG,OAAO,CAAC,CAAC0G,WAAaxH,cAAcyH,GAAG,CAACD;gBAC3D,OAAO;oBACLxH,cAAcyH,GAAG,CAAC1G,MAAMwG,UAAU;gBACpC;gBAEA,IAAIxG,MAAMU,SAAS,IAAI1C,QAAQuC,OAAO,CAACC,MAAM,CAACC,YAAY,EAAE;oBAC1DjB,gCAAgC;gBAClC;gBACA;YAEF;gBACE;QACJ;QAEA,MAAM4D,YAAYpD,MAAMmD,KAAK,IAAInD,MAAMmD,KAAK,CAACC,SAAS;QAEtD,IACE,CAAC9E,kBACD8B,WAAW,CAACD,UAAU,IACtB,cAAcH,SACdA,MAAM2G,QAAQ,IACd,CAACvD,WACD;YACAhD,WAAW,CAACD,UAAU,CAAC6B,OAAO;QAChC;IACF;IAEA,OAAO;QACLzC;QACAK;QACAF;QACAF;QACAG;QACAF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/schema/traverseFields.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Relation } from 'drizzle-orm'\nimport type { IndexBuilder, PgColumnBuilder, UniqueConstraintBuilder } from 'drizzle-orm/pg-core'\nimport type { Field, TabAsField } from 'payload/types'\n\nimport { relations } from 'drizzle-orm'\nimport {\n PgNumericBuilder,\n PgUUIDBuilder,\n PgVarcharBuilder,\n boolean,\n index,\n integer,\n jsonb,\n numeric,\n pgEnum,\n text,\n timestamp,\n varchar,\n} from 'drizzle-orm/pg-core'\nimport { InvalidConfiguration } from 'payload/errors'\nimport { fieldAffectsData, optionIsObject } from 'payload/types'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { GenericColumns, IDType, PostgresAdapter } from '../types.js'\n\nimport { hasLocalesTable } from '../utilities/hasLocalesTable.js'\nimport { buildTable } from './build.js'\nimport { createIndex } from './createIndex.js'\nimport { getTableName } from './getTableName.js'\nimport { idToUUID } from './idToUUID.js'\nimport { parentIDColumnMap } from './parentIDColumnMap.js'\nimport { validateExistingBlockIsIdentical } from './validateExistingBlockIsIdentical.js'\n\ntype Args = {\n adapter: PostgresAdapter\n buildNumbers: boolean\n buildRelationships: boolean\n buildTexts: boolean\n columnPrefix?: string\n columns: Record<string, PgColumnBuilder>\n disableNotNull: boolean\n disableUnique?: boolean\n fieldPrefix?: string\n fields: (Field | TabAsField)[]\n forceLocalized?: boolean\n indexes: Record<string, (cols: GenericColumns) => IndexBuilder>\n localesColumns: Record<string, PgColumnBuilder>\n localesIndexes: Record<string, (cols: GenericColumns) => IndexBuilder>\n newTableName: string\n parentTableName: string\n relationsToBuild: Map<string, string>\n relationships: Set<string>\n rootRelationsToBuild?: Map<string, string>\n rootTableIDColType: string\n rootTableName: string\n versions: boolean\n}\n\ntype Result = {\n hasLocalizedField: boolean\n hasLocalizedManyNumberField: boolean\n hasLocalizedManyTextField: boolean\n hasLocalizedRelationshipField: boolean\n hasManyNumberField: 'index' | boolean\n hasManyTextField: 'index' | boolean\n}\n\nexport const traverseFields = ({\n adapter,\n buildNumbers,\n buildRelationships,\n buildTexts,\n columnPrefix,\n columns,\n disableNotNull,\n disableUnique = false,\n fieldPrefix,\n fields,\n forceLocalized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName,\n parentTableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n versions,\n}: Args): Result => {\n const throwValidationError = true\n let hasLocalizedField = false\n let hasLocalizedRelationshipField = false\n let hasManyTextField: 'index' | boolean = false\n let hasLocalizedManyTextField = false\n let hasManyNumberField: 'index' | boolean = false\n let hasLocalizedManyNumberField = false\n\n let parentIDColType: IDType = 'integer'\n if (columns.id instanceof PgUUIDBuilder) parentIDColType = 'uuid'\n if (columns.id instanceof PgNumericBuilder) parentIDColType = 'numeric'\n if (columns.id instanceof PgVarcharBuilder) parentIDColType = 'varchar'\n\n fields.forEach((field) => {\n if ('name' in field && field.name === 'id') return\n let columnName: string\n let fieldName: string\n\n let targetTable = columns\n let targetIndexes = indexes\n\n if (fieldAffectsData(field)) {\n columnName = `${columnPrefix || ''}${field.name[0] === '_' ? '_' : ''}${toSnakeCase(\n field.name,\n )}`\n fieldName = `${fieldPrefix?.replace('.', '_') || ''}${field.name}`\n\n // If field is localized,\n // add the column to the locale table instead of main table\n if (adapter.payload.config.localization && (field.localized || forceLocalized)) {\n hasLocalizedField = true\n targetTable = localesColumns\n targetIndexes = localesIndexes\n }\n\n if (\n (field.unique || field.index) &&\n !['array', 'blocks', 'group', 'point', 'relationship', 'upload'].includes(field.type) &&\n !('hasMany' in field && field.hasMany === true)\n ) {\n const unique = disableUnique !== true && field.unique\n if (unique) {\n const constraintValue = `${fieldPrefix || ''}${field.name}`\n if (!adapter.fieldConstraints?.[rootTableName]) {\n adapter.fieldConstraints[rootTableName] = {}\n }\n adapter.fieldConstraints[rootTableName][`${columnName}_idx`] = constraintValue\n }\n targetIndexes[`${newTableName}_${field.name}Idx`] = createIndex({\n name: fieldName,\n columnName,\n tableName: newTableName,\n unique,\n })\n }\n }\n\n switch (field.type) {\n case 'text': {\n if (field.hasMany) {\n if (field.localized) {\n hasLocalizedManyTextField = true\n }\n\n if (field.index) {\n hasManyTextField = 'index'\n } else if (!hasManyTextField) {\n hasManyTextField = true\n }\n\n if (field.unique) {\n throw new InvalidConfiguration(\n 'Unique is not supported in Postgres for hasMany text fields.',\n )\n }\n } else {\n targetTable[fieldName] = varchar(columnName)\n }\n break\n }\n case 'email':\n case 'code':\n case 'textarea': {\n targetTable[fieldName] = varchar(columnName)\n break\n }\n\n case 'number': {\n if (field.hasMany) {\n if (field.localized) {\n hasLocalizedManyNumberField = true\n }\n\n if (field.index) {\n hasManyNumberField = 'index'\n } else if (!hasManyNumberField) {\n hasManyNumberField = true\n }\n\n if (field.unique) {\n throw new InvalidConfiguration(\n 'Unique is not supported in Postgres for hasMany number fields.',\n )\n }\n } else {\n targetTable[fieldName] = numeric(columnName)\n }\n break\n }\n\n case 'richText':\n case 'json': {\n targetTable[fieldName] = jsonb(columnName)\n break\n }\n\n case 'date': {\n targetTable[fieldName] = timestamp(columnName, {\n mode: 'string',\n precision: 3,\n withTimezone: true,\n })\n break\n }\n\n case 'point': {\n break\n }\n\n case 'radio':\n case 'select': {\n const enumName = getTableName({\n adapter,\n config: field,\n parentTableName: newTableName,\n prefix: `enum_${newTableName}_`,\n target: 'enumName',\n throwValidationError,\n })\n\n adapter.enums[enumName] = pgEnum(\n enumName,\n field.options.map((option) => {\n if (optionIsObject(option)) {\n return option.value\n }\n\n return option\n }) as [string, ...string[]],\n )\n\n if (field.type === 'select' && field.hasMany) {\n const selectTableName = getTableName({\n adapter,\n config: field,\n parentTableName: newTableName,\n prefix: `${newTableName}_`,\n throwValidationError,\n })\n const baseColumns: Record<string, PgColumnBuilder> = {\n order: integer('order').notNull(),\n parent: parentIDColumnMap[parentIDColType]('parent_id')\n .references(() => adapter.tables[parentTableName].id, { onDelete: 'cascade' })\n .notNull(),\n value: adapter.enums[enumName]('value'),\n }\n\n const baseExtraConfig: Record<\n string,\n (cols: GenericColumns) => IndexBuilder | UniqueConstraintBuilder\n > = {\n orderIdx: (cols) => index(`${selectTableName}_order_idx`).on(cols.order),\n parentIdx: (cols) => index(`${selectTableName}_parent_idx`).on(cols.parent),\n }\n\n if (field.localized) {\n baseColumns.locale = adapter.enums.enum__locales('locale').notNull()\n baseExtraConfig.localeIdx = (cols) =>\n index(`${selectTableName}_locale_idx`).on(cols.locale)\n }\n\n if (field.index) {\n baseExtraConfig.value = (cols) => index(`${selectTableName}_value_idx`).on(cols.value)\n }\n\n buildTable({\n adapter,\n baseColumns,\n baseExtraConfig,\n disableNotNull,\n disableUnique,\n fields: [],\n tableName: selectTableName,\n versions,\n })\n\n relationsToBuild.set(fieldName, selectTableName)\n\n const selectTableRelations = relations(adapter.tables[selectTableName], ({ one }) => {\n const result: Record<string, Relation<string>> = {\n parent: one(adapter.tables[parentTableName], {\n fields: [adapter.tables[selectTableName].parent],\n references: [adapter.tables[parentTableName].id],\n }),\n }\n\n return result\n })\n\n adapter.relations[`relation_${selectTableName}`] = selectTableRelations\n } else {\n targetTable[fieldName] = adapter.enums[enumName](fieldName)\n }\n break\n }\n\n case 'checkbox': {\n targetTable[fieldName] = boolean(columnName)\n break\n }\n\n case 'array': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n const arrayTableName = getTableName({\n adapter,\n config: field,\n parentTableName: newTableName,\n prefix: `${newTableName}_`,\n throwValidationError,\n })\n const baseColumns: Record<string, PgColumnBuilder> = {\n _order: integer('_order').notNull(),\n _parentID: parentIDColumnMap[parentIDColType]('_parent_id')\n .references(() => adapter.tables[parentTableName].id, { onDelete: 'cascade' })\n .notNull(),\n }\n\n const baseExtraConfig: Record<\n string,\n (cols: GenericColumns) => IndexBuilder | UniqueConstraintBuilder\n > = {\n _orderIdx: (cols) => index(`${arrayTableName}_order_idx`).on(cols._order),\n _parentIDIdx: (cols) => index(`${arrayTableName}_parent_id_idx`).on(cols._parentID),\n }\n\n if (field.localized && adapter.payload.config.localization) {\n baseColumns._locale = adapter.enums.enum__locales('_locale').notNull()\n baseExtraConfig._localeIdx = (cols) =>\n index(`${arrayTableName}_locale_idx`).on(cols._locale)\n }\n\n const {\n hasManyNumberField: subHasManyNumberField,\n hasManyTextField: subHasManyTextField,\n relationsToBuild: subRelationsToBuild,\n } = buildTable({\n adapter,\n baseColumns,\n baseExtraConfig,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fields: disableUnique ? idToUUID(field.fields) : field.fields,\n rootRelationsToBuild,\n rootRelationships: relationships,\n rootTableIDColType,\n rootTableName,\n tableName: arrayTableName,\n versions,\n })\n\n if (subHasManyTextField) {\n if (!hasManyTextField || subHasManyTextField === 'index')\n hasManyTextField = subHasManyTextField\n }\n if (subHasManyNumberField) {\n if (!hasManyNumberField || subHasManyNumberField === 'index')\n hasManyNumberField = subHasManyNumberField\n }\n\n relationsToBuild.set(fieldName, arrayTableName)\n\n const arrayTableRelations = relations(adapter.tables[arrayTableName], ({ many, one }) => {\n const result: Record<string, Relation<string>> = {\n _parentID: one(adapter.tables[parentTableName], {\n fields: [adapter.tables[arrayTableName]._parentID],\n references: [adapter.tables[parentTableName].id],\n }),\n }\n\n if (hasLocalesTable(field.fields)) {\n result._locales = many(adapter.tables[`${arrayTableName}${adapter.localesSuffix}`])\n }\n\n subRelationsToBuild.forEach((val, key) => {\n result[key] = many(adapter.tables[val])\n })\n\n return result\n })\n\n adapter.relations[`relations_${arrayTableName}`] = arrayTableRelations\n\n break\n }\n\n case 'blocks': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n field.blocks.forEach((block) => {\n const blockTableName = getTableName({\n adapter,\n config: block,\n parentTableName: rootTableName,\n prefix: `${rootTableName}_blocks_`,\n throwValidationError,\n })\n if (!adapter.tables[blockTableName]) {\n const baseColumns: Record<string, PgColumnBuilder> = {\n _order: integer('_order').notNull(),\n _parentID: parentIDColumnMap[rootTableIDColType]('_parent_id')\n .references(() => adapter.tables[rootTableName].id, { onDelete: 'cascade' })\n .notNull(),\n _path: text('_path').notNull(),\n }\n\n const baseExtraConfig: Record<\n string,\n (cols: GenericColumns) => IndexBuilder | UniqueConstraintBuilder\n > = {\n _orderIdx: (cols) => index(`${blockTableName}_order_idx`).on(cols._order),\n _parentIDIdx: (cols) => index(`${blockTableName}_parent_id_idx`).on(cols._parentID),\n _pathIdx: (cols) => index(`${blockTableName}_path_idx`).on(cols._path),\n }\n\n if (field.localized && adapter.payload.config.localization) {\n baseColumns._locale = adapter.enums.enum__locales('_locale').notNull()\n baseExtraConfig._localeIdx = (cols) =>\n index(`${blockTableName}_locale_idx`).on(cols._locale)\n }\n\n const {\n hasManyNumberField: subHasManyNumberField,\n hasManyTextField: subHasManyTextField,\n relationsToBuild: subRelationsToBuild,\n } = buildTable({\n adapter,\n baseColumns,\n baseExtraConfig,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fields: disableUnique ? idToUUID(block.fields) : block.fields,\n rootRelationsToBuild,\n rootRelationships: relationships,\n rootTableIDColType,\n rootTableName,\n tableName: blockTableName,\n versions,\n })\n\n if (subHasManyTextField) {\n if (!hasManyTextField || subHasManyTextField === 'index')\n hasManyTextField = subHasManyTextField\n }\n\n if (subHasManyNumberField) {\n if (!hasManyNumberField || subHasManyNumberField === 'index')\n hasManyNumberField = subHasManyNumberField\n }\n\n const blockTableRelations = relations(\n adapter.tables[blockTableName],\n ({ many, one }) => {\n const result: Record<string, Relation<string>> = {\n _parentID: one(adapter.tables[rootTableName], {\n fields: [adapter.tables[blockTableName]._parentID],\n references: [adapter.tables[rootTableName].id],\n }),\n }\n\n if (hasLocalesTable(block.fields)) {\n result._locales = many(\n adapter.tables[`${blockTableName}${adapter.localesSuffix}`],\n )\n }\n\n subRelationsToBuild.forEach((val, key) => {\n result[key] = many(adapter.tables[val])\n })\n\n return result\n },\n )\n\n adapter.relations[`relations_${blockTableName}`] = blockTableRelations\n } else if (process.env.NODE_ENV !== 'production' && !versions) {\n validateExistingBlockIsIdentical({\n block,\n localized: field.localized,\n rootTableName,\n table: adapter.tables[blockTableName],\n tableLocales: adapter.tables[`${blockTableName}${adapter.localesSuffix}`],\n })\n }\n adapter.blockTableNames[`${rootTableName}.${toSnakeCase(block.slug)}`] = blockTableName\n rootRelationsToBuild.set(`_blocks_${block.slug}`, blockTableName)\n })\n\n break\n }\n\n case 'tab':\n case 'group': {\n if (!('name' in field)) {\n const {\n hasLocalizedField: groupHasLocalizedField,\n hasLocalizedManyNumberField: groupHasLocalizedManyNumberField,\n hasLocalizedManyTextField: groupHasLocalizedManyTextField,\n hasLocalizedRelationshipField: groupHasLocalizedRelationshipField,\n hasManyNumberField: groupHasManyNumberField,\n hasManyTextField: groupHasManyTextField,\n } = traverseFields({\n adapter,\n buildNumbers,\n buildRelationships,\n buildTexts,\n columnPrefix,\n columns,\n disableNotNull,\n disableUnique,\n fieldPrefix,\n fields: field.fields,\n forceLocalized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName,\n parentTableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n versions,\n })\n\n if (groupHasLocalizedField) hasLocalizedField = true\n if (groupHasLocalizedRelationshipField) hasLocalizedRelationshipField = true\n if (groupHasManyTextField) hasManyTextField = true\n if (groupHasLocalizedManyTextField) hasLocalizedManyTextField = true\n if (groupHasManyNumberField) hasManyNumberField = true\n if (groupHasLocalizedManyNumberField) hasLocalizedManyNumberField = true\n break\n }\n\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n const {\n hasLocalizedField: groupHasLocalizedField,\n hasLocalizedManyNumberField: groupHasLocalizedManyNumberField,\n hasLocalizedManyTextField: groupHasLocalizedManyTextField,\n hasLocalizedRelationshipField: groupHasLocalizedRelationshipField,\n hasManyNumberField: groupHasManyNumberField,\n hasManyTextField: groupHasManyTextField,\n } = traverseFields({\n adapter,\n buildNumbers,\n buildRelationships,\n buildTexts,\n columnPrefix: `${columnName}_`,\n columns,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fieldPrefix: `${fieldName}.`,\n fields: field.fields,\n forceLocalized: field.localized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName: `${parentTableName}_${columnName}`,\n parentTableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n versions,\n })\n\n if (groupHasLocalizedField) hasLocalizedField = true\n if (groupHasLocalizedRelationshipField) hasLocalizedRelationshipField = true\n if (groupHasManyTextField) hasManyTextField = true\n if (groupHasLocalizedManyTextField) hasLocalizedManyTextField = true\n if (groupHasManyNumberField) hasManyNumberField = true\n if (groupHasLocalizedManyNumberField) hasLocalizedManyNumberField = true\n break\n }\n\n case 'tabs': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n const {\n hasLocalizedField: tabHasLocalizedField,\n hasLocalizedManyNumberField: tabHasLocalizedManyNumberField,\n hasLocalizedManyTextField: tabHasLocalizedManyTextField,\n hasLocalizedRelationshipField: tabHasLocalizedRelationshipField,\n hasManyNumberField: tabHasManyNumberField,\n hasManyTextField: tabHasManyTextField,\n } = traverseFields({\n adapter,\n buildNumbers,\n buildRelationships,\n buildTexts,\n columnPrefix,\n columns,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fieldPrefix,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n forceLocalized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName,\n parentTableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n versions,\n })\n\n if (tabHasLocalizedField) hasLocalizedField = true\n if (tabHasLocalizedRelationshipField) hasLocalizedRelationshipField = true\n if (tabHasManyTextField) hasManyTextField = true\n if (tabHasLocalizedManyTextField) hasLocalizedManyTextField = true\n if (tabHasManyNumberField) hasManyNumberField = true\n if (tabHasLocalizedManyNumberField) hasLocalizedManyNumberField = true\n break\n }\n\n case 'row':\n case 'collapsible': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n const {\n hasLocalizedField: rowHasLocalizedField,\n hasLocalizedManyNumberField: rowHasLocalizedManyNumberField,\n hasLocalizedManyTextField: rowHasLocalizedManyTextField,\n hasLocalizedRelationshipField: rowHasLocalizedRelationshipField,\n hasManyNumberField: rowHasManyNumberField,\n hasManyTextField: rowHasManyTextField,\n } = traverseFields({\n adapter,\n buildNumbers,\n buildRelationships,\n buildTexts,\n columnPrefix,\n columns,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fieldPrefix,\n fields: field.fields,\n forceLocalized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName,\n parentTableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n versions,\n })\n\n if (rowHasLocalizedField) hasLocalizedField = true\n if (rowHasLocalizedRelationshipField) hasLocalizedRelationshipField = true\n if (rowHasManyTextField) hasManyTextField = true\n if (rowHasLocalizedManyTextField) hasLocalizedManyTextField = true\n if (rowHasManyNumberField) hasManyNumberField = true\n if (rowHasLocalizedManyNumberField) hasLocalizedManyNumberField = true\n break\n }\n\n case 'relationship':\n case 'upload':\n if (Array.isArray(field.relationTo)) {\n field.relationTo.forEach((relation) => relationships.add(relation))\n } else {\n relationships.add(field.relationTo)\n }\n\n if (field.localized && adapter.payload.config.localization) {\n hasLocalizedRelationshipField = true\n }\n break\n\n default:\n break\n }\n\n const condition = field.admin && field.admin.condition\n\n if (\n !disableNotNull &&\n targetTable[fieldName] &&\n 'required' in field &&\n field.required &&\n !condition\n ) {\n targetTable[fieldName].notNull()\n }\n })\n\n return {\n hasLocalizedField,\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n }\n}\n"],"names":["relations","PgNumericBuilder","PgUUIDBuilder","PgVarcharBuilder","boolean","index","integer","jsonb","numeric","pgEnum","text","timestamp","varchar","InvalidConfiguration","fieldAffectsData","optionIsObject","toSnakeCase","hasLocalesTable","buildTable","createIndex","getTableName","idToUUID","parentIDColumnMap","validateExistingBlockIsIdentical","traverseFields","adapter","buildNumbers","buildRelationships","buildTexts","columnPrefix","columns","disableNotNull","disableUnique","fieldPrefix","fields","forceLocalized","indexes","localesColumns","localesIndexes","newTableName","parentTableName","relationsToBuild","relationships","rootRelationsToBuild","rootTableIDColType","rootTableName","versions","throwValidationError","hasLocalizedField","hasLocalizedRelationshipField","hasManyTextField","hasLocalizedManyTextField","hasManyNumberField","hasLocalizedManyNumberField","parentIDColType","id","forEach","field","name","columnName","fieldName","targetTable","targetIndexes","replace","payload","config","localization","localized","unique","includes","type","hasMany","constraintValue","fieldConstraints","tableName","mode","precision","withTimezone","enumName","prefix","target","enums","options","map","option","value","selectTableName","baseColumns","order","notNull","parent","references","tables","onDelete","baseExtraConfig","orderIdx","cols","on","parentIdx","locale","enum__locales","localeIdx","set","selectTableRelations","one","result","disableNotNullFromHere","Boolean","admin","condition","arrayTableName","_order","_parentID","_orderIdx","_parentIDIdx","_locale","_localeIdx","subHasManyNumberField","subHasManyTextField","subRelationsToBuild","rootRelationships","arrayTableRelations","many","_locales","localesSuffix","val","key","blocks","block","blockTableName","_path","_pathIdx","blockTableRelations","process","env","NODE_ENV","table","tableLocales","blockTableNames","slug","groupHasLocalizedField","groupHasLocalizedManyNumberField","groupHasLocalizedManyTextField","groupHasLocalizedRelationshipField","groupHasManyNumberField","groupHasManyTextField","tabHasLocalizedField","tabHasLocalizedManyNumberField","tabHasLocalizedManyTextField","tabHasLocalizedRelationshipField","tabHasManyNumberField","tabHasManyTextField","tabs","tab","rowHasLocalizedField","rowHasLocalizedManyNumberField","rowHasLocalizedManyTextField","rowHasLocalizedRelationshipField","rowHasManyNumberField","rowHasManyTextField","Array","isArray","relationTo","relation","add","required"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,GAAG,CAACD;gBAC3D,OAAO;oBACLzH,cAAc0H,GAAG,CAAC3G,MAAMyG,UAAU;gBACpC;gBAEA,IAAIzG,MAAMU,SAAS,IAAI1C,QAAQuC,OAAO,CAACC,MAAM,CAACC,YAAY,EAAE;oBAC1DjB,gCAAgC;gBAClC;gBACA;YAEF;gBACE;QACJ;QAEA,MAAM4D,YAAYpD,MAAMmD,KAAK,IAAInD,MAAMmD,KAAK,CAACC,SAAS;QAEtD,IACE,CAAC9E,kBACD8B,WAAW,CAACD,UAAU,IACtB,cAAcH,SACdA,MAAM4G,QAAQ,IACd,CAACxD,WACD;YACAhD,WAAW,CAACD,UAAU,CAAC6B,OAAO;QAChC;IACF;IAEA,OAAO;QACLzC;QACAK;QACAF;QACAF;QACAG;QACAF;IACF;AACF,EAAC"}
@@ -5,7 +5,8 @@ type Args = {
5
5
  localized: boolean;
6
6
  rootTableName: string;
7
7
  table: GenericTable;
8
+ tableLocales?: GenericTable;
8
9
  };
9
- export declare const validateExistingBlockIsIdentical: ({ block, localized, rootTableName, table, }: Args) => void;
10
+ export declare const validateExistingBlockIsIdentical: ({ block, localized, rootTableName, table, tableLocales, }: Args) => void;
10
11
  export {};
11
12
  //# sourceMappingURL=validateExistingBlockIsIdentical.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validateExistingBlockIsIdentical.d.ts","sourceRoot":"","sources":["../../src/schema/validateExistingBlockIsIdentical.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAS,MAAM,eAAe,CAAA;AAKjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,KAAK,IAAI,GAAG;IACV,KAAK,EAAE,KAAK,CAAA;IACZ,SAAS,EAAE,OAAO,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;IACrB,KAAK,EAAE,YAAY,CAAA;CACpB,CAAA;AAyCD,eAAO,MAAM,gCAAgC,gDAK1C,IAAI,KAAG,IAwBT,CAAA"}
1
+ {"version":3,"file":"validateExistingBlockIsIdentical.d.ts","sourceRoot":"","sources":["../../src/schema/validateExistingBlockIsIdentical.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAS,MAAM,eAAe,CAAA;AAKjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,KAAK,IAAI,GAAG;IACV,KAAK,EAAE,KAAK,CAAA;IACZ,SAAS,EAAE,OAAO,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;IACrB,KAAK,EAAE,YAAY,CAAA;IACnB,YAAY,CAAC,EAAE,YAAY,CAAA;CAC5B,CAAA;AAkDD,eAAO,MAAM,gCAAgC,8DAM1C,IAAI,KAAG,IA+BT,CAAA"}
@@ -12,7 +12,7 @@ const getFlattenedFieldNames = (fields, prefix = '')=>{
12
12
  return fieldsToUse;
13
13
  }
14
14
  if (fieldHasSubFields(field)) {
15
- fieldPrefix = 'name' in field ? `${prefix}${field.name}.` : prefix;
15
+ fieldPrefix = 'name' in field ? `${prefix}${field.name}_` : prefix;
16
16
  return [
17
17
  ...fieldsToUse,
18
18
  ...getFlattenedFieldNames(field.fields, fieldPrefix)
@@ -22,7 +22,7 @@ const getFlattenedFieldNames = (fields, prefix = '')=>{
22
22
  return [
23
23
  ...fieldsToUse,
24
24
  ...field.tabs.reduce((tabFields, tab)=>{
25
- fieldPrefix = 'name' in tab ? `${prefix}.${tab.name}` : prefix;
25
+ fieldPrefix = 'name' in tab ? `${prefix}_${tab.name}` : prefix;
26
26
  return [
27
27
  ...tabFields,
28
28
  ...tabHasName(tab) ? [
@@ -38,16 +38,22 @@ const getFlattenedFieldNames = (fields, prefix = '')=>{
38
38
  if (fieldAffectsData(field)) {
39
39
  return [
40
40
  ...fieldsToUse,
41
- `${fieldPrefix?.replace('.', '_') || ''}${field.name}`
41
+ {
42
+ name: `${fieldPrefix}${field.name}`,
43
+ localized: field.localized
44
+ }
42
45
  ];
43
46
  }
44
47
  return fieldsToUse;
45
48
  }, []);
46
49
  };
47
- export const validateExistingBlockIsIdentical = ({ block, localized, rootTableName, table })=>{
50
+ export const validateExistingBlockIsIdentical = ({ block, localized, rootTableName, table, tableLocales })=>{
48
51
  const fieldNames = getFlattenedFieldNames(block.fields);
49
52
  const missingField = // ensure every field from the config is in the matching table
50
- fieldNames.find((name)=>Object.keys(table).indexOf(name) === -1) || // ensure every table column is matched for every field from the config
53
+ fieldNames.find(({ name, localized })=>{
54
+ const fieldTable = localized && tableLocales ? tableLocales : table;
55
+ return Object.keys(fieldTable).indexOf(name) === -1;
56
+ }) || // ensure every table column is matched for every field from the config
51
57
  Object.keys(table).find((fieldName)=>{
52
58
  if (![
53
59
  '_locale',
@@ -56,11 +62,11 @@ export const validateExistingBlockIsIdentical = ({ block, localized, rootTableNa
56
62
  '_path',
57
63
  '_uuid'
58
64
  ].includes(fieldName)) {
59
- return fieldNames.indexOf(fieldName) === -1;
65
+ return fieldNames.findIndex((field)=>field.name) === -1;
60
66
  }
61
67
  });
62
68
  if (missingField) {
63
- throw new InvalidConfiguration(`The table ${rootTableName} has multiple blocks with slug ${block.slug}, but the schemas do not match. One block includes the field ${missingField}, while the other block does not.`);
69
+ throw new InvalidConfiguration(`The table ${rootTableName} has multiple blocks with slug ${block.slug}, but the schemas do not match. One block includes the field ${typeof missingField === 'string' ? missingField : missingField.name}, while the other block does not.`);
64
70
  }
65
71
  if (Boolean(localized) !== Boolean(table._locale)) {
66
72
  throw new InvalidConfiguration(`The table ${rootTableName} has multiple blocks with slug ${block.slug}, but the schemas do not match. One is localized, but another is not. Block schemas of the same name must match exactly.`);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema/validateExistingBlockIsIdentical.ts"],"sourcesContent":["import type { Block, Field } from 'payload/types'\n\nimport { InvalidConfiguration } from 'payload/errors'\nimport { fieldAffectsData, fieldHasSubFields, tabHasName } from 'payload/types'\n\nimport type { GenericTable } from '../types.js'\n\ntype Args = {\n block: Block\n localized: boolean\n rootTableName: string\n table: GenericTable\n}\n\nconst getFlattenedFieldNames = (fields: Field[], prefix: string = ''): string[] => {\n return fields.reduce((fieldsToUse, field) => {\n let fieldPrefix = prefix\n\n if (\n ['array', 'blocks', 'relationship', 'upload'].includes(field.type) ||\n ('hasMany' in field && field.hasMany === true)\n ) {\n return fieldsToUse\n }\n\n if (fieldHasSubFields(field)) {\n fieldPrefix = 'name' in field ? `${prefix}${field.name}.` : prefix\n return [...fieldsToUse, ...getFlattenedFieldNames(field.fields, fieldPrefix)]\n }\n\n if (field.type === 'tabs') {\n return [\n ...fieldsToUse,\n ...field.tabs.reduce((tabFields, tab) => {\n fieldPrefix = 'name' in tab ? `${prefix}.${tab.name}` : prefix\n return [\n ...tabFields,\n ...(tabHasName(tab)\n ? [{ ...tab, type: 'tab' }]\n : getFlattenedFieldNames(tab.fields, fieldPrefix)),\n ]\n }, []),\n ]\n }\n\n if (fieldAffectsData(field)) {\n return [...fieldsToUse, `${fieldPrefix?.replace('.', '_') || ''}${field.name}`]\n }\n\n return fieldsToUse\n }, [])\n}\n\nexport const validateExistingBlockIsIdentical = ({\n block,\n localized,\n rootTableName,\n table,\n}: Args): void => {\n const fieldNames = getFlattenedFieldNames(block.fields)\n\n const missingField =\n // ensure every field from the config is in the matching table\n fieldNames.find((name) => Object.keys(table).indexOf(name) === -1) ||\n // ensure every table column is matched for every field from the config\n Object.keys(table).find((fieldName) => {\n if (!['_locale', '_order', '_parentID', '_path', '_uuid'].includes(fieldName)) {\n return fieldNames.indexOf(fieldName) === -1\n }\n })\n\n if (missingField) {\n throw new InvalidConfiguration(\n `The table ${rootTableName} has multiple blocks with slug ${block.slug}, but the schemas do not match. One block includes the field ${missingField}, while the other block does not.`,\n )\n }\n\n if (Boolean(localized) !== Boolean(table._locale)) {\n throw new InvalidConfiguration(\n `The table ${rootTableName} has multiple blocks with slug ${block.slug}, but the schemas do not match. One is localized, but another is not. Block schemas of the same name must match exactly.`,\n )\n }\n}\n"],"names":["InvalidConfiguration","fieldAffectsData","fieldHasSubFields","tabHasName","getFlattenedFieldNames","fields","prefix","reduce","fieldsToUse","field","fieldPrefix","includes","type","hasMany","name","tabs","tabFields","tab","replace","validateExistingBlockIsIdentical","block","localized","rootTableName","table","fieldNames","missingField","find","Object","keys","indexOf","fieldName","slug","Boolean","_locale"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,oBAAoB,QAAQ,iBAAgB;AACrD,SAASC,gBAAgB,EAAEC,iBAAiB,EAAEC,UAAU,QAAQ,gBAAe;AAW/E,MAAMC,yBAAyB,CAACC,QAAiBC,SAAiB,EAAE;IAClE,OAAOD,OAAOE,MAAM,CAAC,CAACC,aAAaC;QACjC,IAAIC,cAAcJ;QAElB,IACE;YAAC;YAAS;YAAU;YAAgB;SAAS,CAACK,QAAQ,CAACF,MAAMG,IAAI,KAChE,aAAaH,SAASA,MAAMI,OAAO,KAAK,MACzC;YACA,OAAOL;QACT;QAEA,IAAIN,kBAAkBO,QAAQ;YAC5BC,cAAc,UAAUD,QAAQ,CAAC,EAAEH,OAAO,EAAEG,MAAMK,IAAI,CAAC,CAAC,CAAC,GAAGR;YAC5D,OAAO;mBAAIE;mBAAgBJ,uBAAuBK,MAAMJ,MAAM,EAAEK;aAAa;QAC/E;QAEA,IAAID,MAAMG,IAAI,KAAK,QAAQ;YACzB,OAAO;mBACFJ;mBACAC,MAAMM,IAAI,CAACR,MAAM,CAAC,CAACS,WAAWC;oBAC/BP,cAAc,UAAUO,MAAM,CAAC,EAAEX,OAAO,CAAC,EAAEW,IAAIH,IAAI,CAAC,CAAC,GAAGR;oBACxD,OAAO;2BACFU;2BACCb,WAAWc,OACX;4BAAC;gCAAE,GAAGA,GAAG;gCAAEL,MAAM;4BAAM;yBAAE,GACzBR,uBAAuBa,IAAIZ,MAAM,EAAEK;qBACxC;gBACH,GAAG,EAAE;aACN;QACH;QAEA,IAAIT,iBAAiBQ,QAAQ;YAC3B,OAAO;mBAAID;gBAAa,CAAC,EAAEE,aAAaQ,QAAQ,KAAK,QAAQ,GAAG,EAAET,MAAMK,IAAI,CAAC,CAAC;aAAC;QACjF;QAEA,OAAON;IACT,GAAG,EAAE;AACP;AAEA,OAAO,MAAMW,mCAAmC,CAAC,EAC/CC,KAAK,EACLC,SAAS,EACTC,aAAa,EACbC,KAAK,EACA;IACL,MAAMC,aAAapB,uBAAuBgB,MAAMf,MAAM;IAEtD,MAAMoB,eACJ,8DAA8D;IAC9DD,WAAWE,IAAI,CAAC,CAACZ,OAASa,OAAOC,IAAI,CAACL,OAAOM,OAAO,CAACf,UAAU,CAAC,MAChE,uEAAuE;IACvEa,OAAOC,IAAI,CAACL,OAAOG,IAAI,CAAC,CAACI;QACvB,IAAI,CAAC;YAAC;YAAW;YAAU;YAAa;YAAS;SAAQ,CAACnB,QAAQ,CAACmB,YAAY;YAC7E,OAAON,WAAWK,OAAO,CAACC,eAAe,CAAC;QAC5C;IACF;IAEF,IAAIL,cAAc;QAChB,MAAM,IAAIzB,qBACR,CAAC,UAAU,EAAEsB,cAAc,+BAA+B,EAAEF,MAAMW,IAAI,CAAC,6DAA6D,EAAEN,aAAa,iCAAiC,CAAC;IAEzL;IAEA,IAAIO,QAAQX,eAAeW,QAAQT,MAAMU,OAAO,GAAG;QACjD,MAAM,IAAIjC,qBACR,CAAC,UAAU,EAAEsB,cAAc,+BAA+B,EAAEF,MAAMW,IAAI,CAAC,wHAAwH,CAAC;IAEpM;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/schema/validateExistingBlockIsIdentical.ts"],"sourcesContent":["import type { Block, Field } from 'payload/types'\n\nimport { InvalidConfiguration } from 'payload/errors'\nimport { fieldAffectsData, fieldHasSubFields, tabHasName } from 'payload/types'\n\nimport type { GenericTable } from '../types.js'\n\ntype Args = {\n block: Block\n localized: boolean\n rootTableName: string\n table: GenericTable\n tableLocales?: GenericTable\n}\n\nconst getFlattenedFieldNames = (\n fields: Field[],\n prefix: string = '',\n): { localized?: boolean; name: string }[] => {\n return fields.reduce((fieldsToUse, field) => {\n let fieldPrefix = prefix\n\n if (\n ['array', 'blocks', 'relationship', 'upload'].includes(field.type) ||\n ('hasMany' in field && field.hasMany === true)\n ) {\n return fieldsToUse\n }\n\n if (fieldHasSubFields(field)) {\n fieldPrefix = 'name' in field ? `${prefix}${field.name}_` : prefix\n return [...fieldsToUse, ...getFlattenedFieldNames(field.fields, fieldPrefix)]\n }\n\n if (field.type === 'tabs') {\n return [\n ...fieldsToUse,\n ...field.tabs.reduce((tabFields, tab) => {\n fieldPrefix = 'name' in tab ? `${prefix}_${tab.name}` : prefix\n return [\n ...tabFields,\n ...(tabHasName(tab)\n ? [{ ...tab, type: 'tab' }]\n : getFlattenedFieldNames(tab.fields, fieldPrefix)),\n ]\n }, []),\n ]\n }\n\n if (fieldAffectsData(field)) {\n return [\n ...fieldsToUse,\n {\n name: `${fieldPrefix}${field.name}`,\n localized: field.localized,\n },\n ]\n }\n\n return fieldsToUse\n }, [])\n}\n\nexport const validateExistingBlockIsIdentical = ({\n block,\n localized,\n rootTableName,\n table,\n tableLocales,\n}: Args): void => {\n const fieldNames = getFlattenedFieldNames(block.fields)\n\n const missingField =\n // ensure every field from the config is in the matching table\n fieldNames.find(({ name, localized }) => {\n const fieldTable = localized && tableLocales ? tableLocales : table\n return Object.keys(fieldTable).indexOf(name) === -1\n }) ||\n // ensure every table column is matched for every field from the config\n Object.keys(table).find((fieldName) => {\n if (!['_locale', '_order', '_parentID', '_path', '_uuid'].includes(fieldName)) {\n return fieldNames.findIndex((field) => field.name) === -1\n }\n })\n\n if (missingField) {\n throw new InvalidConfiguration(\n `The table ${rootTableName} has multiple blocks with slug ${\n block.slug\n }, but the schemas do not match. One block includes the field ${\n typeof missingField === 'string' ? missingField : missingField.name\n }, while the other block does not.`,\n )\n }\n\n if (Boolean(localized) !== Boolean(table._locale)) {\n throw new InvalidConfiguration(\n `The table ${rootTableName} has multiple blocks with slug ${block.slug}, but the schemas do not match. One is localized, but another is not. Block schemas of the same name must match exactly.`,\n )\n }\n}\n"],"names":["InvalidConfiguration","fieldAffectsData","fieldHasSubFields","tabHasName","getFlattenedFieldNames","fields","prefix","reduce","fieldsToUse","field","fieldPrefix","includes","type","hasMany","name","tabs","tabFields","tab","localized","validateExistingBlockIsIdentical","block","rootTableName","table","tableLocales","fieldNames","missingField","find","fieldTable","Object","keys","indexOf","fieldName","findIndex","slug","Boolean","_locale"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,oBAAoB,QAAQ,iBAAgB;AACrD,SAASC,gBAAgB,EAAEC,iBAAiB,EAAEC,UAAU,QAAQ,gBAAe;AAY/E,MAAMC,yBAAyB,CAC7BC,QACAC,SAAiB,EAAE;IAEnB,OAAOD,OAAOE,MAAM,CAAC,CAACC,aAAaC;QACjC,IAAIC,cAAcJ;QAElB,IACE;YAAC;YAAS;YAAU;YAAgB;SAAS,CAACK,QAAQ,CAACF,MAAMG,IAAI,KAChE,aAAaH,SAASA,MAAMI,OAAO,KAAK,MACzC;YACA,OAAOL;QACT;QAEA,IAAIN,kBAAkBO,QAAQ;YAC5BC,cAAc,UAAUD,QAAQ,CAAC,EAAEH,OAAO,EAAEG,MAAMK,IAAI,CAAC,CAAC,CAAC,GAAGR;YAC5D,OAAO;mBAAIE;mBAAgBJ,uBAAuBK,MAAMJ,MAAM,EAAEK;aAAa;QAC/E;QAEA,IAAID,MAAMG,IAAI,KAAK,QAAQ;YACzB,OAAO;mBACFJ;mBACAC,MAAMM,IAAI,CAACR,MAAM,CAAC,CAACS,WAAWC;oBAC/BP,cAAc,UAAUO,MAAM,CAAC,EAAEX,OAAO,CAAC,EAAEW,IAAIH,IAAI,CAAC,CAAC,GAAGR;oBACxD,OAAO;2BACFU;2BACCb,WAAWc,OACX;4BAAC;gCAAE,GAAGA,GAAG;gC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HAAwH,CAAC;IAEpM;AACF,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/db-postgres",
3
- "version": "3.0.0-beta.11",
3
+ "version": "3.0.0-beta.12",
4
4
  "description": "The officially supported Postgres database adapter for Payload",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,10 +31,10 @@
31
31
  "@types/pg": "8.10.2",
32
32
  "@types/to-snake-case": "1.0.0",
33
33
  "@payloadcms/eslint-config": "1.1.1",
34
- "payload": "3.0.0-beta.11"
34
+ "payload": "3.0.0-beta.12"
35
35
  },
36
36
  "peerDependencies": {
37
- "payload": "3.0.0-beta.11"
37
+ "payload": "3.0.0-beta.12"
38
38
  },
39
39
  "exports": {
40
40
  ".": {
package/src/index.ts DELETED
@@ -1,155 +0,0 @@
1
- import type { Payload } from 'payload'
2
- import type { DatabaseAdapterObj } from 'payload/database'
3
-
4
- import fs from 'fs'
5
- import path from 'path'
6
- import { createDatabaseAdapter } from 'payload/database'
7
-
8
- import type { Args, PostgresAdapter } from './types.js'
9
-
10
- import { connect } from './connect.js'
11
- import { create } from './create.js'
12
- import { createGlobal } from './createGlobal.js'
13
- import { createGlobalVersion } from './createGlobalVersion.js'
14
- import { createMigration } from './createMigration.js'
15
- import { createVersion } from './createVersion.js'
16
- import { deleteMany } from './deleteMany.js'
17
- import { deleteOne } from './deleteOne.js'
18
- import { deleteVersions } from './deleteVersions.js'
19
- import { destroy } from './destroy.js'
20
- import { find } from './find.js'
21
- import { findGlobal } from './findGlobal.js'
22
- import { findGlobalVersions } from './findGlobalVersions.js'
23
- import { findOne } from './findOne.js'
24
- import { findVersions } from './findVersions.js'
25
- import { init } from './init.js'
26
- import { migrate } from './migrate.js'
27
- import { migrateDown } from './migrateDown.js'
28
- import { migrateFresh } from './migrateFresh.js'
29
- import { migrateRefresh } from './migrateRefresh.js'
30
- import { migrateReset } from './migrateReset.js'
31
- import { migrateStatus } from './migrateStatus.js'
32
- import { queryDrafts } from './queryDrafts.js'
33
- import { beginTransaction } from './transactions/beginTransaction.js'
34
- import { commitTransaction } from './transactions/commitTransaction.js'
35
- import { rollbackTransaction } from './transactions/rollbackTransaction.js'
36
- import { updateOne } from './update.js'
37
- import { updateGlobal } from './updateGlobal.js'
38
- import { updateGlobalVersion } from './updateGlobalVersion.js'
39
- import { updateVersion } from './updateVersion.js'
40
-
41
- export type { MigrateDownArgs, MigrateUpArgs } from './types.js'
42
-
43
- export { sql } from 'drizzle-orm'
44
-
45
- export function postgresAdapter(args: Args): DatabaseAdapterObj<PostgresAdapter> {
46
- const postgresIDType = args.idType || 'serial'
47
- const payloadIDType = postgresIDType ? 'number' : 'text'
48
-
49
- function adapter({ payload }: { payload: Payload }) {
50
- const migrationDir = findMigrationDir(args.migrationDir)
51
-
52
- return createDatabaseAdapter<PostgresAdapter>({
53
- name: 'postgres',
54
-
55
- // Postgres-specific
56
- blockTableNames: {},
57
- drizzle: undefined,
58
- enums: {},
59
- fieldConstraints: {},
60
- idType: postgresIDType,
61
- localesSuffix: args.localesSuffix || '_locales',
62
- logger: args.logger,
63
- pgSchema: undefined,
64
- pool: undefined,
65
- poolOptions: args.pool,
66
- push: args.push,
67
- relations: {},
68
- relationshipsSuffix: args.relationshipsSuffix || '_rels',
69
- schema: {},
70
- schemaName: args.schemaName,
71
- sessions: {},
72
- tables: {},
73
- versionsSuffix: args.versionsSuffix || '_v',
74
-
75
- // DatabaseAdapter
76
- beginTransaction,
77
- commitTransaction,
78
- connect,
79
- create,
80
- createGlobal,
81
- createGlobalVersion,
82
- createMigration,
83
- createVersion,
84
- defaultIDType: payloadIDType,
85
- deleteMany,
86
- deleteOne,
87
- deleteVersions,
88
- destroy,
89
- find,
90
- findGlobal,
91
- findGlobalVersions,
92
- findOne,
93
- findVersions,
94
- init,
95
- migrate,
96
- migrateDown,
97
- migrateFresh,
98
- migrateRefresh,
99
- migrateReset,
100
- migrateStatus,
101
- migrationDir,
102
- payload,
103
- queryDrafts,
104
- rollbackTransaction,
105
- updateGlobal,
106
- updateGlobalVersion,
107
- updateOne,
108
- updateVersion,
109
- })
110
- }
111
-
112
- return {
113
- defaultIDType: payloadIDType,
114
- init: adapter,
115
- }
116
- }
117
-
118
- /**
119
- * Attempt to find migrations directory.
120
- *
121
- * Checks for the following directories in order:
122
- * - `migrationDir` argument from Payload config
123
- * - `src/migrations`
124
- * - `dist/migrations`
125
- * - `migrations`
126
- *
127
- * Defaults to `src/migrations`
128
- *
129
- * @param migrationDir
130
- * @returns
131
- */
132
- function findMigrationDir(migrationDir?: string): string {
133
- const cwd = process.cwd()
134
- const srcDir = path.resolve(cwd, 'src/migrations')
135
- const distDir = path.resolve(cwd, 'dist/migrations')
136
- const relativeMigrations = path.resolve(cwd, 'migrations')
137
-
138
- // Use arg if provided
139
- if (migrationDir) return migrationDir
140
-
141
- // Check other common locations
142
- if (fs.existsSync(srcDir)) {
143
- return srcDir
144
- }
145
-
146
- if (fs.existsSync(distDir)) {
147
- return distDir
148
- }
149
-
150
- if (fs.existsSync(relativeMigrations)) {
151
- return relativeMigrations
152
- }
153
-
154
- return srcDir
155
- }