@payloadcms/drizzle 4.0.0-internal.0b9bec1 → 4.0.0-internal.1235217
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/createTableName.d.ts.map +1 -1
- package/dist/createTableName.js +2 -7
- package/dist/createTableName.js.map +1 -1
- package/dist/exports/postgres.d.ts +6 -2
- package/dist/exports/postgres.d.ts.map +1 -1
- package/dist/exports/postgres.js +6 -2
- package/dist/exports/postgres.js.map +1 -1
- package/dist/exports/sqlite.d.ts +2 -2
- package/dist/exports/sqlite.d.ts.map +1 -1
- package/dist/exports/sqlite.js +2 -2
- package/dist/exports/sqlite.js.map +1 -1
- package/dist/find/buildPolymorphicJoinQuery.d.ts +39 -0
- package/dist/find/buildPolymorphicJoinQuery.d.ts.map +1 -0
- package/dist/find/buildPolymorphicJoinQuery.js +146 -0
- package/dist/find/buildPolymorphicJoinQuery.js.map +1 -0
- package/dist/find/buildPolymorphicJoinWhere.d.ts +20 -0
- package/dist/find/buildPolymorphicJoinWhere.d.ts.map +1 -0
- package/dist/find/buildPolymorphicJoinWhere.js +301 -0
- package/dist/find/buildPolymorphicJoinWhere.js.map +1 -0
- package/dist/find/createPolymorphicJoinWherePlan.d.ts +38 -0
- package/dist/find/createPolymorphicJoinWherePlan.d.ts.map +1 -0
- package/dist/find/createPolymorphicJoinWherePlan.js +200 -0
- package/dist/find/createPolymorphicJoinWherePlan.js.map +1 -0
- package/dist/find/traverseFields.d.ts.map +1 -1
- package/dist/find/traverseFields.js +20 -191
- package/dist/find/traverseFields.js.map +1 -1
- package/dist/index.d.ts +4 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -9
- package/dist/index.js.map +1 -1
- package/dist/migrate.d.ts.map +1 -1
- package/dist/migrate.js +41 -15
- package/dist/migrate.js.map +1 -1
- package/dist/migrateDown.d.ts +2 -1
- package/dist/migrateDown.d.ts.map +1 -1
- package/dist/migrateDown.js +17 -4
- package/dist/migrateDown.js.map +1 -1
- package/dist/migrateFresh.d.ts +4 -2
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +26 -9
- package/dist/migrateFresh.js.map +1 -1
- package/dist/migrateRefresh.d.ts +2 -1
- package/dist/migrateRefresh.d.ts.map +1 -1
- package/dist/migrateRefresh.js +20 -5
- package/dist/migrateRefresh.js.map +1 -1
- package/dist/migrateReset.d.ts +2 -1
- package/dist/migrateReset.d.ts.map +1 -1
- package/dist/migrateReset.js +18 -4
- package/dist/migrateReset.js.map +1 -1
- package/dist/migrateStatus.d.ts +2 -1
- package/dist/migrateStatus.d.ts.map +1 -1
- package/dist/migrateStatus.js +11 -6
- package/dist/migrateStatus.js.map +1 -1
- package/dist/postgres/createJSONQuery/index.js +3 -3
- package/dist/postgres/createJSONQuery/index.js.map +1 -1
- package/dist/postgres/findDocumentLocks.d.ts +4 -0
- package/dist/postgres/findDocumentLocks.d.ts.map +1 -0
- package/dist/postgres/findDocumentLocks.js +22 -0
- package/dist/postgres/findDocumentLocks.js.map +1 -0
- package/dist/postgres/init.d.ts.map +1 -1
- package/dist/postgres/init.js +6 -0
- package/dist/postgres/init.js.map +1 -1
- package/dist/postgres/predefinedMigrations/localize-status/getGeneratedColumnType.d.ts +26 -0
- package/dist/postgres/predefinedMigrations/localize-status/getGeneratedColumnType.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/localize-status/getGeneratedColumnType.js +61 -0
- package/dist/postgres/predefinedMigrations/localize-status/getGeneratedColumnType.js.map +1 -0
- package/dist/postgres/predefinedMigrations/localize-status/getMigrationDB.d.ts +13 -0
- package/dist/postgres/predefinedMigrations/localize-status/getMigrationDB.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/localize-status/getMigrationDB.js +17 -0
- package/dist/postgres/predefinedMigrations/localize-status/getMigrationDB.js.map +1 -0
- package/dist/postgres/predefinedMigrations/localize-status/index.d.ts.map +1 -1
- package/dist/postgres/predefinedMigrations/localize-status/index.js +73 -10
- package/dist/postgres/predefinedMigrations/localize-status/index.js.map +1 -1
- package/dist/postgres/predefinedMigrations/sizes-to-variants/index.d.ts +35 -0
- package/dist/postgres/predefinedMigrations/sizes-to-variants/index.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/sizes-to-variants/index.js +185 -0
- package/dist/postgres/predefinedMigrations/sizes-to-variants/index.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.js +8 -4
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/index.js +2 -2
- package/dist/postgres/predefinedMigrations/v2-v3/index.js.map +1 -1
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.d.ts +15 -0
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.d.ts.map +1 -0
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.js +25 -0
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.js.map +1 -0
- package/dist/postgres/query/postgresUnaccent.d.ts +13 -0
- package/dist/postgres/query/postgresUnaccent.d.ts.map +1 -0
- package/dist/postgres/query/postgresUnaccent.js +40 -0
- package/dist/postgres/query/postgresUnaccent.js.map +1 -0
- package/dist/postgres/requireDrizzleKit.d.ts +4 -0
- package/dist/postgres/requireDrizzleKit.d.ts.map +1 -1
- package/dist/postgres/requireDrizzleKit.js +16 -10
- package/dist/postgres/requireDrizzleKit.js.map +1 -1
- package/dist/postgres/types.d.ts +13 -2
- package/dist/postgres/types.d.ts.map +1 -1
- package/dist/postgres/types.js.map +1 -1
- package/dist/queries/buildOperatorConstraint.d.ts +22 -0
- package/dist/queries/buildOperatorConstraint.d.ts.map +1 -0
- package/dist/queries/buildOperatorConstraint.js +79 -0
- package/dist/queries/buildOperatorConstraint.js.map +1 -0
- package/dist/queries/getTableColumnFromPath.d.ts +12 -3
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
- package/dist/queries/getTableColumnFromPath.js +65 -28
- package/dist/queries/getTableColumnFromPath.js.map +1 -1
- package/dist/queries/operatorMap.d.ts +7 -3
- package/dist/queries/operatorMap.d.ts.map +1 -1
- package/dist/queries/operatorMap.js.map +1 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +262 -10
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/resolveRelationshipPath.d.ts +36 -0
- package/dist/queries/resolveRelationshipPath.d.ts.map +1 -0
- package/dist/queries/resolveRelationshipPath.js +66 -0
- package/dist/queries/resolveRelationshipPath.js.map +1 -0
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +6 -2
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queries/validateOperatorHandlers.d.ts +8 -0
- package/dist/queries/validateOperatorHandlers.d.ts.map +1 -0
- package/dist/queries/validateOperatorHandlers.js +30 -0
- package/dist/queries/validateOperatorHandlers.js.map +1 -0
- package/dist/schema/build.d.ts.map +1 -1
- package/dist/schema/build.js +54 -5
- package/dist/schema/build.js.map +1 -1
- package/dist/schema/traverseFields.d.ts.map +1 -1
- package/dist/schema/traverseFields.js +76 -19
- package/dist/schema/traverseFields.js.map +1 -1
- package/dist/sqlite/createJSONQuery/convertPathToJSONTraversal.js +3 -2
- package/dist/sqlite/createJSONQuery/convertPathToJSONTraversal.js.map +1 -1
- package/dist/sqlite/createJSONQuery/index.d.ts.map +1 -1
- package/dist/sqlite/createJSONQuery/index.js +6 -5
- package/dist/sqlite/createJSONQuery/index.js.map +1 -1
- package/dist/sqlite/createRequireDrizzleKit.d.ts +6 -0
- package/dist/sqlite/createRequireDrizzleKit.d.ts.map +1 -0
- package/dist/sqlite/createRequireDrizzleKit.js +15 -0
- package/dist/sqlite/createRequireDrizzleKit.js.map +1 -0
- package/dist/sqlite/execute.js.map +1 -1
- package/dist/sqlite/insert.d.ts.map +1 -1
- package/dist/sqlite/insert.js +4 -1
- package/dist/sqlite/insert.js.map +1 -1
- package/dist/sqlite/predefinedMigrations/sizes-to-variants/index.d.ts +15 -0
- package/dist/sqlite/predefinedMigrations/sizes-to-variants/index.d.ts.map +1 -0
- package/dist/sqlite/predefinedMigrations/sizes-to-variants/index.js +114 -0
- package/dist/sqlite/predefinedMigrations/sizes-to-variants/index.js.map +1 -0
- package/dist/transactions/beginTransaction.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.js +13 -5
- package/dist/transactions/beginTransaction.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +2 -5
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/transform/read/traverseFields.d.ts.map +1 -1
- package/dist/transform/read/traverseFields.js +11 -3
- package/dist/transform/read/traverseFields.js.map +1 -1
- package/dist/transform/write/addBlockTablesToDelete.d.ts +20 -0
- package/dist/transform/write/addBlockTablesToDelete.d.ts.map +1 -0
- package/dist/transform/write/addBlockTablesToDelete.js +54 -0
- package/dist/transform/write/addBlockTablesToDelete.js.map +1 -0
- package/dist/transform/write/array.d.ts +3 -2
- package/dist/transform/write/array.d.ts.map +1 -1
- package/dist/transform/write/array.js +2 -1
- package/dist/transform/write/array.js.map +1 -1
- package/dist/transform/write/blocks.d.ts +3 -2
- package/dist/transform/write/blocks.d.ts.map +1 -1
- package/dist/transform/write/blocks.js +5 -2
- package/dist/transform/write/blocks.js.map +1 -1
- package/dist/transform/write/index.d.ts.map +1 -1
- package/dist/transform/write/index.js +5 -1
- package/dist/transform/write/index.js.map +1 -1
- package/dist/transform/write/traverseFields.d.ts +2 -1
- package/dist/transform/write/traverseFields.d.ts.map +1 -1
- package/dist/transform/write/traverseFields.js +45 -20
- package/dist/transform/write/traverseFields.js.map +1 -1
- package/dist/transform/write/types.d.ts +10 -0
- package/dist/transform/write/types.d.ts.map +1 -1
- package/dist/transform/write/types.js.map +1 -1
- package/dist/types.d.ts +52 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +54 -1
- package/dist/updateOne.js.map +1 -1
- package/dist/upsertRow/deleteExistingRowsByPath.d.ts +6 -1
- package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +1 -1
- package/dist/upsertRow/deleteExistingRowsByPath.js +21 -3
- package/dist/upsertRow/deleteExistingRowsByPath.js.map +1 -1
- package/dist/upsertRow/index.d.ts +1 -1
- package/dist/upsertRow/index.d.ts.map +1 -1
- package/dist/upsertRow/index.js +57 -13
- package/dist/upsertRow/index.js.map +1 -1
- package/dist/upsertRow/insertArrays.d.ts.map +1 -1
- package/dist/upsertRow/insertArrays.js +2 -3
- package/dist/upsertRow/insertArrays.js.map +1 -1
- package/dist/utilities/blocksToJsonMigrator.d.ts.map +1 -1
- package/dist/utilities/blocksToJsonMigrator.js +7 -18
- package/dist/utilities/blocksToJsonMigrator.js.map +1 -1
- package/dist/utilities/buildCreateMigration.d.ts.map +1 -1
- package/dist/utilities/buildCreateMigration.js +13 -9
- package/dist/utilities/buildCreateMigration.js.map +1 -1
- package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.d.ts +15 -0
- package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.d.ts.map +1 -0
- package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.js +110 -0
- package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.js.map +1 -0
- package/dist/utilities/buildForeignKeyName.d.ts.map +1 -1
- package/dist/utilities/buildForeignKeyName.js +3 -2
- package/dist/utilities/buildForeignKeyName.js.map +1 -1
- package/dist/utilities/buildIndexName.d.ts.map +1 -1
- package/dist/utilities/buildIndexName.js +3 -2
- package/dist/utilities/buildIndexName.js.map +1 -1
- package/dist/utilities/checkTruncatedIdentifiers.d.ts +13 -0
- package/dist/utilities/checkTruncatedIdentifiers.d.ts.map +1 -0
- package/dist/utilities/checkTruncatedIdentifiers.js +56 -0
- package/dist/utilities/checkTruncatedIdentifiers.js.map +1 -0
- package/dist/utilities/createSchemaGenerator.d.ts.map +1 -1
- package/dist/utilities/createSchemaGenerator.js +27 -13
- package/dist/utilities/createSchemaGenerator.js.map +1 -1
- package/dist/utilities/executeSchemaHooks.js +1 -1
- package/dist/utilities/executeSchemaHooks.js.map +1 -1
- package/dist/utilities/fitIdentifierLength.d.ts +25 -0
- package/dist/utilities/fitIdentifierLength.d.ts.map +1 -0
- package/dist/utilities/fitIdentifierLength.js +35 -0
- package/dist/utilities/fitIdentifierLength.js.map +1 -0
- package/dist/utilities/formatGeneratedFile.d.ts +10 -0
- package/dist/utilities/formatGeneratedFile.d.ts.map +1 -0
- package/dist/utilities/formatGeneratedFile.js +58 -0
- package/dist/utilities/formatGeneratedFile.js.map +1 -0
- package/dist/utilities/getSizesToVariantsRenames.d.ts +54 -0
- package/dist/utilities/getSizesToVariantsRenames.d.ts.map +1 -0
- package/dist/utilities/getSizesToVariantsRenames.js +252 -0
- package/dist/utilities/getSizesToVariantsRenames.js.map +1 -0
- package/dist/utilities/getTransaction.js.map +1 -1
- package/dist/utilities/parseJSONPathSegment.d.ts +9 -0
- package/dist/utilities/parseJSONPathSegment.d.ts.map +1 -0
- package/dist/utilities/parseJSONPathSegment.js +17 -0
- package/dist/utilities/parseJSONPathSegment.js.map +1 -0
- package/dist/utilities/pushDevSchema.js +1 -1
- package/dist/utilities/pushDevSchema.js.map +1 -1
- package/dist/utilities/validateExistingBlockIsIdentical.d.ts +1 -5
- package/dist/utilities/validateExistingBlockIsIdentical.d.ts.map +1 -1
- package/dist/utilities/validateExistingBlockIsIdentical.js.map +1 -1
- package/dist/utilities/validateIdentifierLength.d.ts +12 -0
- package/dist/utilities/validateIdentifierLength.d.ts.map +1 -0
- package/dist/utilities/validateIdentifierLength.js +18 -0
- package/dist/utilities/validateIdentifierLength.js.map +1 -0
- package/package.json +17 -19
- package/dist/postgres/predefinedMigrations/jobs-processing-lease/index.d.ts +0 -12
- package/dist/postgres/predefinedMigrations/jobs-processing-lease/index.d.ts.map +0 -1
- package/dist/postgres/predefinedMigrations/jobs-processing-lease/index.js +0 -22
- package/dist/postgres/predefinedMigrations/jobs-processing-lease/index.js.map +0 -1
- package/dist/sqlite/predefinedMigrations/jobs-processing-lease/index.d.ts +0 -12
- package/dist/sqlite/predefinedMigrations/jobs-processing-lease/index.d.ts.map +0 -1
- package/dist/sqlite/predefinedMigrations/jobs-processing-lease/index.js +0 -22
- package/dist/sqlite/predefinedMigrations/jobs-processing-lease/index.js.map +0 -1
- package/dist/sqlite/requireDrizzleKit.d.ts +0 -3
- package/dist/sqlite/requireDrizzleKit.d.ts.map +0 -1
- package/dist/sqlite/requireDrizzleKit.js +0 -12
- package/dist/sqlite/requireDrizzleKit.js.map +0 -1
- package/dist/upsertRow/handleUpsertError.spec.js +0 -42
- package/dist/upsertRow/handleUpsertError.spec.js.map +0 -1
- package/dist/utilities/isValidStringID.spec.js +0 -15
- package/dist/utilities/isValidStringID.spec.js.map +0 -1
- package/dist/utilities/jobsProcessingLeaseMigration.d.ts +0 -6
- package/dist/utilities/jobsProcessingLeaseMigration.d.ts.map +0 -1
- package/dist/utilities/jobsProcessingLeaseMigration.js +0 -64
- package/dist/utilities/jobsProcessingLeaseMigration.js.map +0 -1
- package/dist/utilities/jobsProcessingLeaseMigration.spec.js +0 -186
- package/dist/utilities/jobsProcessingLeaseMigration.spec.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/queries/resolveRelationshipPath.ts"],"sourcesContent":["import type { FlattenedField, RelationshipField, UploadField } from 'payload'\n\nimport type { DrizzleAdapter } from '../types.js'\n\ntype ResolvedRelationshipPath = {\n field: RelationshipField | UploadField\n isLocalized: boolean\n locale?: string\n path: string\n}\n\n/**\n * Adds a field to the path used by Drizzle's shared relationship, text, and number tables.\n * Array and block entries are stored with a numeric position, represented by `%` while querying.\n *\n * @example `blocks` becomes `blocks.%` and then `directors` becomes\n * `blocks.%.directors`.\n */\nexport function appendFieldToStoragePath({\n field,\n path = '',\n}: {\n field: FlattenedField\n path?: string\n}): string {\n const pathSegments = path ? [path.replace(/\\.$/, ''), field.name] : [field.name]\n\n if (field.type === 'array' || field.type === 'blocks') {\n pathSegments.push('%')\n }\n\n return pathSegments.join('.')\n}\n\n/**\n * Resolves a schema path to the relationship field and the path stored in the collection's shared\n * relationships table. This understands groups, tabs, arrays, blocks, and explicit locale\n * segments.\n *\n * @example `blocks.directors` resolves to the stored path `blocks.%.directors`.\n */\nexport function resolveRelationshipPath({\n adapter,\n fields,\n locale,\n parentIsLocalized,\n path,\n pathPrefix = '',\n}: {\n adapter: DrizzleAdapter\n fields: FlattenedField[]\n locale?: string\n parentIsLocalized: boolean\n path: string\n pathPrefix?: string\n}): null | ResolvedRelationshipPath {\n const localeCodes = adapter.payload.config.localization\n ? adapter.payload.config.localization.localeCodes\n : []\n const pathSegments = path.split('.')\n let currentField: FlattenedField | undefined\n let currentFields = fields\n let isLocalized = parentIsLocalized\n let resolvedPath = pathPrefix\n\n for (const segment of pathSegments) {\n const field = currentFields.find(({ name }) => name === segment)\n\n if (!field && isLocalized && localeCodes.includes(segment)) {\n locale = segment\n continue\n }\n\n if (!field) {\n return null\n }\n\n currentField = field\n resolvedPath = appendFieldToStoragePath({ field, path: resolvedPath })\n isLocalized = isLocalized || Boolean(field.localized)\n\n if ('flattenedFields' in field) {\n currentFields = field.flattenedFields\n } else if (field.type === 'blocks') {\n currentFields = field.blocks.flatMap((block) =>\n typeof block === 'string'\n ? adapter.payload.blocks[block].flattenedFields\n : block.flattenedFields,\n )\n } else {\n currentFields = []\n }\n }\n\n if (!currentField || (currentField.type !== 'relationship' && currentField.type !== 'upload')) {\n return null\n }\n\n return {\n field: currentField,\n isLocalized,\n locale,\n path: resolvedPath,\n }\n}\n"],"names":["appendFieldToStoragePath","field","path","pathSegments","replace","name","type","push","join","resolveRelationshipPath","adapter","fields","locale","parentIsLocalized","pathPrefix","localeCodes","payload","config","localization","split","currentField","currentFields","isLocalized","resolvedPath","segment","find","includes","Boolean","localized","flattenedFields","blocks","flatMap","block"],"mappings":"AAWA;;;;;;CAMC,GACD,OAAO,SAASA,yBAAyB,EACvCC,KAAK,EACLC,OAAO,EAAE,EAIV;IACC,MAAMC,eAAeD,OAAO;QAACA,KAAKE,OAAO,CAAC,OAAO;QAAKH,MAAMI,IAAI;KAAC,GAAG;QAACJ,MAAMI,IAAI;KAAC;IAEhF,IAAIJ,MAAMK,IAAI,KAAK,WAAWL,MAAMK,IAAI,KAAK,UAAU;QACrDH,aAAaI,IAAI,CAAC;IACpB;IAEA,OAAOJ,aAAaK,IAAI,CAAC;AAC3B;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,wBAAwB,EACtCC,OAAO,EACPC,MAAM,EACNC,MAAM,EACNC,iBAAiB,EACjBX,IAAI,EACJY,aAAa,EAAE,EAQhB;IACC,MAAMC,cAAcL,QAAQM,OAAO,CAACC,MAAM,CAACC,YAAY,GACnDR,QAAQM,OAAO,CAACC,MAAM,CAACC,YAAY,CAACH,WAAW,GAC/C,EAAE;IACN,MAAMZ,eAAeD,KAAKiB,KAAK,CAAC;IAChC,IAAIC;IACJ,IAAIC,gBAAgBV;IACpB,IAAIW,cAAcT;IAClB,IAAIU,eAAeT;IAEnB,KAAK,MAAMU,WAAWrB,aAAc;QAClC,MAAMF,QAAQoB,cAAcI,IAAI,CAAC,CAAC,EAAEpB,IAAI,EAAE,GAAKA,SAASmB;QAExD,IAAI,CAACvB,SAASqB,eAAeP,YAAYW,QAAQ,CAACF,UAAU;YAC1DZ,SAASY;YACT;QACF;QAEA,IAAI,CAACvB,OAAO;YACV,OAAO;QACT;QAEAmB,eAAenB;QACfsB,eAAevB,yBAAyB;YAAEC;YAAOC,MAAMqB;QAAa;QACpED,cAAcA,eAAeK,QAAQ1B,MAAM2B,SAAS;QAEpD,IAAI,qBAAqB3B,OAAO;YAC9BoB,gBAAgBpB,MAAM4B,eAAe;QACvC,OAAO,IAAI5B,MAAMK,IAAI,KAAK,UAAU;YAClCe,gBAAgBpB,MAAM6B,MAAM,CAACC,OAAO,CAAC,CAACC,QACpC,OAAOA,UAAU,WACbtB,QAAQM,OAAO,CAACc,MAAM,CAACE,MAAM,CAACH,eAAe,GAC7CG,MAAMH,eAAe;QAE7B,OAAO;YACLR,gBAAgB,EAAE;QACpB;IACF;IAEA,IAAI,CAACD,gBAAiBA,aAAad,IAAI,KAAK,kBAAkBc,aAAad,IAAI,KAAK,UAAW;QAC7F,OAAO;IACT;IAEA,OAAO;QACLL,OAAOmB;QACPE;QACAV;QACAV,MAAMqB;IACR;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitizeQueryValue.d.ts","sourceRoot":"","sources":["../../src/queries/sanitizeQueryValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAEtC,OAAO,
|
|
1
|
+
{"version":3,"file":"sanitizeQueryValue.d.ts","sourceRoot":"","sources":["../../src/queries/sanitizeQueryValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAEtC,OAAO,EAGL,KAAK,KAAK,EAEV,KAAK,UAAU,EAChB,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAOjD,KAAK,sBAAsB,GAAG;IAC5B,OAAO,EAAE,cAAc,CAAA;IACvB,OAAO,CAAC,EAAE;QACR,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAA;QAClC,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;KACxB,EAAE,CAAA;IACH,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB,MAAM,EAAE,OAAO,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,cAAc,EAAE,MAAM,CAAA;IACtB,GAAG,EAAE,GAAG,CAAA;CACT,CAAA;AAED,KAAK,eAAe,GAAG;IACrB,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;IACvB,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAED,eAAO,MAAM,kBAAkB,qFAQ5B,sBAAsB,KAAG;IAC1B,OAAO,CAAC,EAAE,eAAe,EAAE,CAAA;IAC3B,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,OAAO,CAAA;CA4Qf,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { APIError, createArrayFromCommaDelineated } from 'payload';
|
|
2
|
-
import { fieldAffectsData } from 'payload/shared';
|
|
2
|
+
import { fieldAffectsData, isDateOnlyFilter, isDateOnlyFilterValue } from 'payload/shared';
|
|
3
3
|
import { validate as uuidValidate } from 'uuid';
|
|
4
4
|
import { getCollectionIdType } from '../utilities/getCollectionIdType.js';
|
|
5
5
|
import { isPolymorphicRelationship } from '../utilities/isPolymorphicRelationship.js';
|
|
@@ -88,7 +88,11 @@ export const sanitizeQueryValue = ({ adapter, columns, field, isUUID, operator:
|
|
|
88
88
|
}
|
|
89
89
|
return item;
|
|
90
90
|
};
|
|
91
|
-
|
|
91
|
+
const isDateOnlyComparison = field.type === 'date' && isDateOnlyFilter({
|
|
92
|
+
field,
|
|
93
|
+
operator: operator
|
|
94
|
+
}) && isDateOnlyFilterValue(val);
|
|
95
|
+
if (field.type === 'date' && operator !== 'exists' && !isDateOnlyComparison) {
|
|
92
96
|
if (Array.isArray(formattedValue)) {
|
|
93
97
|
// Handle arrays of dates for 'in' and 'not_in' operators
|
|
94
98
|
formattedValue = formattedValue.map(convertDateToISO).filter((item)=>item !== undefined);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\n\nimport { APIError, createArrayFromCommaDelineated, type Field, type TabAsField } from 'payload'\nimport { fieldAffectsData } from 'payload/shared'\nimport { validate as uuidValidate } from 'uuid'\n\nimport type { DrizzleAdapter } from '../types.js'\n\nimport { getCollectionIdType } from '../utilities/getCollectionIdType.js'\nimport { isPolymorphicRelationship } from '../utilities/isPolymorphicRelationship.js'\nimport { isUUIDType } from '../utilities/isUUIDType.js'\nimport { isRawConstraint } from '../utilities/rawConstraint.js'\n\ntype SanitizeQueryValueArgs = {\n adapter: DrizzleAdapter\n columns?: {\n idType: 'number' | 'text' | 'uuid'\n rawColumn: SQL<unknown>\n }[]\n field: Field | TabAsField\n isUUID: boolean\n operator: string\n relationOrPath: string\n val: any\n}\n\ntype SanitizedColumn = {\n rawColumn: SQL<unknown>\n value: unknown\n}\n\nexport const sanitizeQueryValue = ({\n adapter,\n columns,\n field,\n isUUID,\n operator: operatorArg,\n relationOrPath,\n val,\n}: SanitizeQueryValueArgs): {\n columns?: SanitizedColumn[]\n operator: string\n value: unknown\n} => {\n let operator = operatorArg\n let formattedValue = val\n let formattedColumns: SanitizedColumn[]\n\n if (!fieldAffectsData(field)) {\n return { operator, value: formattedValue }\n }\n\n if (isRawConstraint(val)) {\n return { operator, value: val.value }\n }\n if (\n (field.type === 'relationship' || field.type === 'upload') &&\n !relationOrPath.endsWith('relationTo') &&\n Array.isArray(formattedValue)\n ) {\n const allPossibleIDTypes: (number | string)[] = []\n formattedValue.forEach((val) => {\n if (!isUUIDType(adapter.idType) && typeof val === 'string') {\n allPossibleIDTypes.push(val, parseInt(val))\n } else if (typeof val === 'string') {\n allPossibleIDTypes.push(val)\n } else {\n allPossibleIDTypes.push(val, String(val))\n }\n })\n formattedValue = allPossibleIDTypes\n }\n\n // Cast incoming values as proper searchable types\n if (field.type === 'checkbox' && typeof val === 'string') {\n if (val.toLowerCase() === 'true') {\n formattedValue = true\n }\n if (val.toLowerCase() === 'false') {\n formattedValue = false\n }\n }\n\n if (['all', 'in', 'not_in'].includes(operator)) {\n if (typeof formattedValue === 'string') {\n formattedValue = createArrayFromCommaDelineated(formattedValue)\n\n if (field.type === 'number') {\n formattedValue = formattedValue.map((arrayVal) => parseFloat(arrayVal))\n }\n } else if (typeof formattedValue === 'number') {\n formattedValue = [formattedValue]\n }\n\n if (!Array.isArray(formattedValue)) {\n return null\n }\n }\n\n if (field.type === 'number' && typeof formattedValue === 'string') {\n formattedValue = Number(val)\n\n if (Number.isNaN(formattedValue)) {\n formattedValue = null\n }\n }\n\n if (isUUID && typeof formattedValue === 'string') {\n if (!uuidValidate(val)) {\n formattedValue = null\n }\n }\n\n // Helper function to convert a single date value to ISO string\n const convertDateToISO = (item: unknown): unknown => {\n if (typeof item === 'string') {\n if (item === 'null' || item === '') {\n return null\n }\n const date = new Date(item)\n return Number.isNaN(date.getTime()) ? undefined : date.toISOString()\n } else if (typeof item === 'number') {\n return new Date(item).toISOString()\n } else if (item instanceof Date) {\n return item.toISOString()\n }\n return item\n }\n\n if (field.type === 'date' && operator !== 'exists') {\n if (Array.isArray(formattedValue)) {\n // Handle arrays of dates for 'in' and 'not_in' operators\n formattedValue = formattedValue.map(convertDateToISO).filter((item) => item !== undefined)\n } else {\n const converted = convertDateToISO(val)\n if (converted === undefined) {\n return { operator, value: undefined }\n }\n formattedValue = converted\n }\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n if (val === 'null') {\n formattedValue = null\n } else if (!(formattedValue === null || typeof formattedValue === 'boolean')) {\n // convert the value to the idType of the relationship\n let idType: 'number' | 'text'\n if (typeof field.relationTo === 'string') {\n idType = getCollectionIdType({\n adapter,\n collection: adapter.payload.collections[field.relationTo],\n })\n } else {\n if (isPolymorphicRelationship(val)) {\n if (operator !== 'equals') {\n throw new APIError(\n `Only 'equals' operator is supported for polymorphic relationship object notation. Given - ${operator}`,\n )\n }\n idType = getCollectionIdType({\n adapter,\n collection: adapter.payload.collections[val.relationTo],\n })\n\n if (isRawConstraint(val.value)) {\n return {\n operator,\n value: val.value.value,\n }\n }\n return {\n operator,\n value: idType === 'number' ? Number(val.value) : String(val.value),\n }\n }\n\n formattedColumns = columns\n .map(({ idType, rawColumn }) => {\n let formattedValue: number | number[] | string | string[]\n\n if (Array.isArray(val)) {\n formattedValue = val\n .map((eachVal) => {\n let formattedValue: number | string\n\n if (idType === 'number') {\n formattedValue = Number(eachVal)\n\n if (Number.isNaN(formattedValue)) {\n return null\n }\n } else {\n if (idType === 'uuid' && !uuidValidate(eachVal)) {\n return null\n }\n\n formattedValue = String(eachVal)\n }\n\n return formattedValue\n })\n .filter(Boolean) as number[] | string[]\n } else if (idType === 'number') {\n formattedValue = Number(val)\n\n if (Number.isNaN(formattedValue)) {\n return null\n }\n } else {\n formattedValue = String(val)\n }\n\n return {\n rawColumn,\n value: formattedValue,\n }\n })\n .filter(Boolean)\n }\n if (Array.isArray(formattedValue)) {\n formattedValue = formattedValue.map((value) => {\n if (idType === 'number') {\n return Number(value)\n }\n if (idType === 'text') {\n return String(value)\n }\n return value\n })\n } else {\n if (idType === 'number') {\n formattedValue = Number(val)\n }\n if (idType === 'text') {\n formattedValue = String(val)\n }\n }\n }\n }\n\n // hasMany relationship/upload/select fields are stored as separate rows in a join table.\n // The JOIN already gives us individual rows, so \"contains\" becomes an equality check on each row's value.\n if (\n 'hasMany' in field &&\n field.hasMany &&\n operator === 'contains' &&\n (field.type === 'relationship' || field.type === 'upload' || field.type === 'select')\n ) {\n operator = 'equals'\n }\n\n if (operator === 'near' && field.type === 'point' && typeof formattedValue === 'string') {\n const [lng, lat, maxDistance, minDistance] = formattedValue.split(',')\n\n formattedValue = [Number(lng), Number(lat), Number(maxDistance), Number(minDistance)]\n }\n\n if (operator === 'contains') {\n // Handle array values for hasMany text/number/select fields\n if (\n Array.isArray(formattedValue) &&\n 'hasMany' in field &&\n field.hasMany &&\n ['number', 'text'].includes(field.type)\n ) {\n // For hasMany text/number/select fields with array values, wrap each element with % for LIKE matching\n formattedValue = formattedValue.map((val) => `%${val}%`)\n } else if (!Array.isArray(formattedValue)) {\n // For non-array values, wrap with % for LIKE matching\n formattedValue = `%${formattedValue}%`\n }\n }\n\n if (operator === 'exists') {\n formattedValue = val === 'true' || val === true\n\n if (formattedValue) {\n operator = 'exists'\n } else {\n operator = 'isNull'\n }\n }\n\n if ((field.type === 'relationship' || field.type === 'upload') && Array.isArray(formattedValue)) {\n if (operator === 'equals') {\n return {\n columns: formattedColumns,\n operator: 'in',\n value: formattedValue,\n }\n } else if (operator === 'not_equals') {\n return {\n columns: formattedColumns,\n operator: 'not_in',\n value: formattedValue,\n }\n }\n }\n\n return {\n columns: formattedColumns,\n operator,\n value: formattedValue,\n }\n}\n"],"names":["APIError","createArrayFromCommaDelineated","fieldAffectsData","validate","uuidValidate","getCollectionIdType","isPolymorphicRelationship","isUUIDType","isRawConstraint","sanitizeQueryValue","adapter","columns","field","isUUID","operator","operatorArg","relationOrPath","val","formattedValue","formattedColumns","value","type","endsWith","Array","isArray","allPossibleIDTypes","forEach","idType","push","parseInt","String","toLowerCase","includes","map","arrayVal","parseFloat","Number","isNaN","convertDateToISO","item","date","Date","getTime","undefined","toISOString","filter","converted","relationTo","collection","payload","collections","rawColumn","eachVal","Boolean","hasMany","lng","lat","maxDistance","minDistance","split"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,8BAA8B,QAAqC,UAAS;AAC/F,SAASC,gBAAgB,QAAQ,iBAAgB;AACjD,SAASC,YAAYC,YAAY,QAAQ,OAAM;AAI/C,SAASC,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,yBAAyB,QAAQ,4CAA2C;AACrF,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,eAAe,QAAQ,gCAA+B;AAoB/D,OAAO,MAAMC,qBAAqB,CAAC,EACjCC,OAAO,EACPC,OAAO,EACPC,KAAK,EACLC,MAAM,EACNC,UAAUC,WAAW,EACrBC,cAAc,EACdC,GAAG,EACoB;IAKvB,IAAIH,WAAWC;IACf,IAAIG,iBAAiBD;IACrB,IAAIE;IAEJ,IAAI,CAACjB,iBAAiBU,QAAQ;QAC5B,OAAO;YAAEE;YAAUM,OAAOF;QAAe;IAC3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BI,iBAAiBD,QAAQ,UAAUA,QAAQ;QAE3C,IAAIC,gBAAgB;YAClBJ,WAAW;QACb,OAAO;YACLA,WAAW;QACb;IACF;IAEA,IAAI,AAACF,CAAAA,MAAMS,IAAI,KAAK,kBAAkBT,MAAMS,IAAI,KAAK,QAAO,KAAME,MAAMC,OAAO,CAACN,iBAAiB;QAC/F,IAAIJ,aAAa,UAAU;YACzB,OAAO;gBACLH,SAASQ;gBACTL,UAAU;gBACVM,OAAOF;YACT;QACF,OAAO,IAAIJ,aAAa,cAAc;YACpC,OAAO;gBACLH,SAASQ;gBACTL,UAAU;gBACVM,OAAOF;YACT;QACF;IACF;IAEA,OAAO;QACLP,SAASQ;QACTL;QACAM,OAAOF;IACT;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\n\nimport {\n APIError,\n createArrayFromCommaDelineated,\n type Field,\n type Operator,\n type TabAsField,\n} from 'payload'\nimport { fieldAffectsData, isDateOnlyFilter, isDateOnlyFilterValue } from 'payload/shared'\nimport { validate as uuidValidate } from 'uuid'\n\nimport type { DrizzleAdapter } from '../types.js'\n\nimport { getCollectionIdType } from '../utilities/getCollectionIdType.js'\nimport { isPolymorphicRelationship } from '../utilities/isPolymorphicRelationship.js'\nimport { isUUIDType } from '../utilities/isUUIDType.js'\nimport { isRawConstraint } from '../utilities/rawConstraint.js'\n\ntype SanitizeQueryValueArgs = {\n adapter: DrizzleAdapter\n columns?: {\n idType: 'number' | 'text' | 'uuid'\n rawColumn: SQL<unknown>\n }[]\n field: Field | TabAsField\n isUUID: boolean\n operator: string\n relationOrPath: string\n val: any\n}\n\ntype SanitizedColumn = {\n rawColumn: SQL<unknown>\n value: unknown\n}\n\nexport const sanitizeQueryValue = ({\n adapter,\n columns,\n field,\n isUUID,\n operator: operatorArg,\n relationOrPath,\n val,\n}: SanitizeQueryValueArgs): {\n columns?: SanitizedColumn[]\n operator: string\n value: unknown\n} => {\n let operator = operatorArg\n let formattedValue = val\n let formattedColumns: SanitizedColumn[]\n\n if (!fieldAffectsData(field)) {\n return { operator, value: formattedValue }\n }\n\n if (isRawConstraint(val)) {\n return { operator, value: val.value }\n }\n if (\n (field.type === 'relationship' || field.type === 'upload') &&\n !relationOrPath.endsWith('relationTo') &&\n Array.isArray(formattedValue)\n ) {\n const allPossibleIDTypes: (number | string)[] = []\n formattedValue.forEach((val) => {\n if (!isUUIDType(adapter.idType) && typeof val === 'string') {\n allPossibleIDTypes.push(val, parseInt(val))\n } else if (typeof val === 'string') {\n allPossibleIDTypes.push(val)\n } else {\n allPossibleIDTypes.push(val, String(val))\n }\n })\n formattedValue = allPossibleIDTypes\n }\n\n // Cast incoming values as proper searchable types\n if (field.type === 'checkbox' && typeof val === 'string') {\n if (val.toLowerCase() === 'true') {\n formattedValue = true\n }\n if (val.toLowerCase() === 'false') {\n formattedValue = false\n }\n }\n\n if (['all', 'in', 'not_in'].includes(operator)) {\n if (typeof formattedValue === 'string') {\n formattedValue = createArrayFromCommaDelineated(formattedValue)\n\n if (field.type === 'number') {\n formattedValue = formattedValue.map((arrayVal) => parseFloat(arrayVal))\n }\n } else if (typeof formattedValue === 'number') {\n formattedValue = [formattedValue]\n }\n\n if (!Array.isArray(formattedValue)) {\n return null\n }\n }\n\n if (field.type === 'number' && typeof formattedValue === 'string') {\n formattedValue = Number(val)\n\n if (Number.isNaN(formattedValue)) {\n formattedValue = null\n }\n }\n\n if (isUUID && typeof formattedValue === 'string') {\n if (!uuidValidate(val)) {\n formattedValue = null\n }\n }\n\n // Helper function to convert a single date value to ISO string\n const convertDateToISO = (item: unknown): unknown => {\n if (typeof item === 'string') {\n if (item === 'null' || item === '') {\n return null\n }\n const date = new Date(item)\n return Number.isNaN(date.getTime()) ? undefined : date.toISOString()\n } else if (typeof item === 'number') {\n return new Date(item).toISOString()\n } else if (item instanceof Date) {\n return item.toISOString()\n }\n return item\n }\n\n const isDateOnlyComparison =\n field.type === 'date' &&\n isDateOnlyFilter({ field, operator: operator as Operator }) &&\n isDateOnlyFilterValue(val)\n\n if (field.type === 'date' && operator !== 'exists' && !isDateOnlyComparison) {\n if (Array.isArray(formattedValue)) {\n // Handle arrays of dates for 'in' and 'not_in' operators\n formattedValue = formattedValue.map(convertDateToISO).filter((item) => item !== undefined)\n } else {\n const converted = convertDateToISO(val)\n if (converted === undefined) {\n return { operator, value: undefined }\n }\n formattedValue = converted\n }\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n if (val === 'null') {\n formattedValue = null\n } else if (!(formattedValue === null || typeof formattedValue === 'boolean')) {\n // convert the value to the idType of the relationship\n let idType: 'number' | 'text'\n if (typeof field.relationTo === 'string') {\n idType = getCollectionIdType({\n adapter,\n collection: adapter.payload.collections[field.relationTo],\n })\n } else {\n if (isPolymorphicRelationship(val)) {\n if (operator !== 'equals') {\n throw new APIError(\n `Only 'equals' operator is supported for polymorphic relationship object notation. Given - ${operator}`,\n )\n }\n idType = getCollectionIdType({\n adapter,\n collection: adapter.payload.collections[val.relationTo],\n })\n\n if (isRawConstraint(val.value)) {\n return {\n operator,\n value: val.value.value,\n }\n }\n return {\n operator,\n value: idType === 'number' ? Number(val.value) : String(val.value),\n }\n }\n\n formattedColumns = columns\n .map(({ idType, rawColumn }) => {\n let formattedValue: number | number[] | string | string[]\n\n if (Array.isArray(val)) {\n formattedValue = val\n .map((eachVal) => {\n let formattedValue: number | string\n\n if (idType === 'number') {\n formattedValue = Number(eachVal)\n\n if (Number.isNaN(formattedValue)) {\n return null\n }\n } else {\n if (idType === 'uuid' && !uuidValidate(eachVal)) {\n return null\n }\n\n formattedValue = String(eachVal)\n }\n\n return formattedValue\n })\n .filter(Boolean) as number[] | string[]\n } else if (idType === 'number') {\n formattedValue = Number(val)\n\n if (Number.isNaN(formattedValue)) {\n return null\n }\n } else {\n formattedValue = String(val)\n }\n\n return {\n rawColumn,\n value: formattedValue,\n }\n })\n .filter(Boolean)\n }\n if (Array.isArray(formattedValue)) {\n formattedValue = formattedValue.map((value) => {\n if (idType === 'number') {\n return Number(value)\n }\n if (idType === 'text') {\n return String(value)\n }\n return value\n })\n } else {\n if (idType === 'number') {\n formattedValue = Number(val)\n }\n if (idType === 'text') {\n formattedValue = String(val)\n }\n }\n }\n }\n\n // hasMany relationship/upload/select fields are stored as separate rows in a join table.\n // The JOIN already gives us individual rows, so \"contains\" becomes an equality check on each row's value.\n if (\n 'hasMany' in field &&\n field.hasMany &&\n operator === 'contains' &&\n (field.type === 'relationship' || field.type === 'upload' || field.type === 'select')\n ) {\n operator = 'equals'\n }\n\n if (operator === 'near' && field.type === 'point' && typeof formattedValue === 'string') {\n const [lng, lat, maxDistance, minDistance] = formattedValue.split(',')\n\n formattedValue = [Number(lng), Number(lat), Number(maxDistance), Number(minDistance)]\n }\n\n if (operator === 'contains') {\n // Handle array values for hasMany text/number/select fields\n if (\n Array.isArray(formattedValue) &&\n 'hasMany' in field &&\n field.hasMany &&\n ['number', 'text'].includes(field.type)\n ) {\n // For hasMany text/number/select fields with array values, wrap each element with % for LIKE matching\n formattedValue = formattedValue.map((val) => `%${val}%`)\n } else if (!Array.isArray(formattedValue)) {\n // For non-array values, wrap with % for LIKE matching\n formattedValue = `%${formattedValue}%`\n }\n }\n\n if (operator === 'exists') {\n formattedValue = val === 'true' || val === true\n\n if (formattedValue) {\n operator = 'exists'\n } else {\n operator = 'isNull'\n }\n }\n\n if ((field.type === 'relationship' || field.type === 'upload') && Array.isArray(formattedValue)) {\n if (operator === 'equals') {\n return {\n columns: formattedColumns,\n operator: 'in',\n value: formattedValue,\n }\n } else if (operator === 'not_equals') {\n return {\n columns: formattedColumns,\n operator: 'not_in',\n value: formattedValue,\n }\n }\n }\n\n return {\n columns: formattedColumns,\n operator,\n value: formattedValue,\n }\n}\n"],"names":["APIError","createArrayFromCommaDelineated","fieldAffectsData","isDateOnlyFilter","isDateOnlyFilterValue","validate","uuidValidate","getCollectionIdType","isPolymorphicRelationship","isUUIDType","isRawConstraint","sanitizeQueryValue","adapter","columns","field","isUUID","operator","operatorArg","relationOrPath","val","formattedValue","formattedColumns","value","type","endsWith","Array","isArray","allPossibleIDTypes","forEach","idType","push","parseInt","String","toLowerCase","includes","map","arrayVal","parseFloat","Number","isNaN","convertDateToISO","item","date","Date","getTime","undefined","toISOString","isDateOnlyComparison","filter","converted","relationTo","collection","payload","collections","rawColumn","eachVal","Boolean","hasMany","lng","lat","maxDistance","minDistance","split"],"mappings":"AAEA,SACEA,QAAQ,EACRC,8BAA8B,QAIzB,UAAS;AAChB,SAASC,gBAAgB,EAAEC,gBAAgB,EAAEC,qBAAqB,QAAQ,iBAAgB;AAC1F,SAASC,YAAYC,YAAY,QAAQ,OAAM;AAI/C,SAASC,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,yBAAyB,QAAQ,4CAA2C;AACrF,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,eAAe,QAAQ,gCAA+B;AAoB/D,OAAO,MAAMC,qBAAqB,CAAC,EACjCC,OAAO,EACPC,OAAO,EACPC,KAAK,EACLC,MAAM,EACNC,UAAUC,WAAW,EACrBC,cAAc,EACdC,GAAG,EACoB;IAKvB,IAAIH,WAAWC;IACf,IAAIG,iBAAiBD;IACrB,IAAIE;IAEJ,IAAI,CAACnB,iBAAiBY,QAAQ;QAC5B,OAAO;YAAEE;YAAUM,OAAOF;QAAe;IAC3C;IAEA,IAAIV,gBAAgBS,MAAM;QACxB,OAAO;YAAEH;YAAUM,OAAOH,IAAIG,KAAK;QAAC;IACtC;IACA,IACE,AAACR,CAAAA,MAAMS,IAAI,KAAK,kBAAkBT,MAAMS,IAAI,KAAK,QAAO,KACxD,CAACL,eAAeM,QAAQ,CAAC,iBACzBC,MAAMC,OAAO,CAACN,iBACd;QACA,MAAMO,qBAA0C,EAAE;QAClDP,eAAeQ,OAAO,CAAC,CAACT;YACtB,IAAI,CAACV,WAAWG,QAAQiB,MAAM,KAAK,OAAOV,QAAQ,UAAU;gBAC1DQ,mBA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OAAO;gBACLH,SAASQ;gBACTL,UAAU;gBACVM,OAAOF;YACT;QACF,OAAO,IAAIJ,aAAa,cAAc;YACpC,OAAO;gBACLH,SAASQ;gBACTL,UAAU;gBACVM,OAAOF;YACT;QACF;IACF;IAEA,OAAO;QACLP,SAASQ;QACTL;QACAM,OAAOF;IACT;AACF,EAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DrizzleOperatorHandler } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validates operator-handler configuration before any request runs: rejects a handler that
|
|
4
|
+
* defines both `build` and `transformOperands`, and rejects two replacement handlers whose
|
|
5
|
+
* `operators` and `fieldTypes` both overlap for the same resolved operator.
|
|
6
|
+
*/
|
|
7
|
+
export declare const validateOperatorHandlers: (operatorHandlers: DrizzleOperatorHandler[]) => void;
|
|
8
|
+
//# sourceMappingURL=validateOperatorHandlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateOperatorHandlers.d.ts","sourceRoot":"","sources":["../../src/queries/validateOperatorHandlers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAqC,MAAM,aAAa,CAAA;AAc5F;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,qBAAsB,sBAAsB,EAAE,KAAG,IA+BrF,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { APIError } from 'payload';
|
|
2
|
+
const isReplacementHandler = (handler)=>typeof handler.build === 'function';
|
|
3
|
+
const fieldTypesOverlap = (a, b)=>!a.fieldTypes || !b.fieldTypes || a.fieldTypes.some((fieldType)=>b.fieldTypes.includes(fieldType));
|
|
4
|
+
/**
|
|
5
|
+
* Validates operator-handler configuration before any request runs: rejects a handler that
|
|
6
|
+
* defines both `build` and `transformOperands`, and rejects two replacement handlers whose
|
|
7
|
+
* `operators` and `fieldTypes` both overlap for the same resolved operator.
|
|
8
|
+
*/ export const validateOperatorHandlers = (operatorHandlers)=>{
|
|
9
|
+
for (const handler of operatorHandlers){
|
|
10
|
+
if (typeof handler.build === 'function' && typeof handler.transformOperands === 'function') {
|
|
11
|
+
throw new APIError(`Operator handler "${handler.name}" cannot define both "build" and "transformOperands". Use "transformOperands" to adjust operands, or "build" to replace the comparison entirely.`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const replacementHandlers = operatorHandlers.filter(isReplacementHandler);
|
|
15
|
+
for(let i = 0; i < replacementHandlers.length; i++){
|
|
16
|
+
for(let j = i + 1; j < replacementHandlers.length; j++){
|
|
17
|
+
const handlerA = replacementHandlers[i];
|
|
18
|
+
const handlerB = replacementHandlers[j];
|
|
19
|
+
const sharedOperators = handlerA.operators.filter((operator)=>handlerB.operators.includes(operator));
|
|
20
|
+
if (!sharedOperators.length) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (fieldTypesOverlap(handlerA, handlerB)) {
|
|
24
|
+
throw new APIError(`Operator handlers "${handlerA.name}" and "${handlerB.name}" both replace the "${sharedOperators.join('", "')}" operator for overlapping field types. Only one replacement handler may match a given resolved operator and field type.`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=validateOperatorHandlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/queries/validateOperatorHandlers.ts"],"sourcesContent":["import { APIError } from 'payload'\n\nimport type { DrizzleOperatorHandler, DrizzleOperatorReplacementHandler } from '../types.js'\n\nconst isReplacementHandler = (\n handler: DrizzleOperatorHandler,\n): handler is DrizzleOperatorReplacementHandler => typeof handler.build === 'function'\n\nconst fieldTypesOverlap = (\n a: DrizzleOperatorReplacementHandler,\n b: DrizzleOperatorReplacementHandler,\n): boolean =>\n !a.fieldTypes ||\n !b.fieldTypes ||\n a.fieldTypes.some((fieldType) => b.fieldTypes.includes(fieldType))\n\n/**\n * Validates operator-handler configuration before any request runs: rejects a handler that\n * defines both `build` and `transformOperands`, and rejects two replacement handlers whose\n * `operators` and `fieldTypes` both overlap for the same resolved operator.\n */\nexport const validateOperatorHandlers = (operatorHandlers: DrizzleOperatorHandler[]): void => {\n for (const handler of operatorHandlers) {\n if (typeof handler.build === 'function' && typeof handler.transformOperands === 'function') {\n throw new APIError(\n `Operator handler \"${handler.name}\" cannot define both \"build\" and \"transformOperands\". Use \"transformOperands\" to adjust operands, or \"build\" to replace the comparison entirely.`,\n )\n }\n }\n\n const replacementHandlers = operatorHandlers.filter(isReplacementHandler)\n\n for (let i = 0; i < replacementHandlers.length; i++) {\n for (let j = i + 1; j < replacementHandlers.length; j++) {\n const handlerA = replacementHandlers[i]\n const handlerB = replacementHandlers[j]\n\n const sharedOperators = handlerA.operators.filter((operator) =>\n handlerB.operators.includes(operator),\n )\n\n if (!sharedOperators.length) {\n continue\n }\n\n if (fieldTypesOverlap(handlerA, handlerB)) {\n throw new APIError(\n `Operator handlers \"${handlerA.name}\" and \"${handlerB.name}\" both replace the \"${sharedOperators.join('\", \"')}\" operator for overlapping field types. Only one replacement handler may match a given resolved operator and field type.`,\n )\n }\n }\n }\n}\n"],"names":["APIError","isReplacementHandler","handler","build","fieldTypesOverlap","a","b","fieldTypes","some","fieldType","includes","validateOperatorHandlers","operatorHandlers","transformOperands","name","replacementHandlers","filter","i","length","j","handlerA","handlerB","sharedOperators","operators","operator","join"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,UAAS;AAIlC,MAAMC,uBAAuB,CAC3BC,UACiD,OAAOA,QAAQC,KAAK,KAAK;AAE5E,MAAMC,oBAAoB,CACxBC,GACAC,IAEA,CAACD,EAAEE,UAAU,IACb,CAACD,EAAEC,UAAU,IACbF,EAAEE,UAAU,CAACC,IAAI,CAAC,CAACC,YAAcH,EAAEC,UAAU,CAACG,QAAQ,CAACD;AAEzD;;;;CAIC,GACD,OAAO,MAAME,2BAA2B,CAACC;IACvC,KAAK,MAAMV,WAAWU,iBAAkB;QACtC,IAAI,OAAOV,QAAQC,KAAK,KAAK,cAAc,OAAOD,QAAQW,iBAAiB,KAAK,YAAY;YAC1F,MAAM,IAAIb,SACR,CAAC,kBAAkB,EAAEE,QAAQY,IAAI,CAAC,gJAAgJ,CAAC;QAEvL;IACF;IAEA,MAAMC,sBAAsBH,iBAAiBI,MAAM,CAACf;IAEpD,IAAK,IAAIgB,IAAI,GAAGA,IAAIF,oBAAoBG,MAAM,EAAED,IAAK;QACnD,IAAK,IAAIE,IAAIF,IAAI,GAAGE,IAAIJ,oBAAoBG,MAAM,EAAEC,IAAK;YACvD,MAAMC,WAAWL,mBAAmB,CAACE,EAAE;YACvC,MAAMI,WAAWN,mBAAmB,CAACI,EAAE;YAEvC,MAAMG,kBAAkBF,SAASG,SAAS,CAACP,MAAM,CAAC,CAACQ,WACjDH,SAASE,SAAS,CAACb,QAAQ,CAACc;YAG9B,IAAI,CAACF,gBAAgBJ,MAAM,EAAE;gBAC3B;YACF;YAEA,IAAId,kBAAkBgB,UAAUC,WAAW;gBACzC,MAAM,IAAIrB,SACR,CAAC,mBAAmB,EAAEoB,SAASN,IAAI,CAAC,OAAO,EAAEO,SAASP,IAAI,CAAC,oBAAoB,EAAEQ,gBAAgBG,IAAI,CAAC,QAAQ,wHAAwH,CAAC;YAE3O;QACF;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/schema/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAKrE,OAAO,KAAK,EACV,cAAc,EACd,MAAM,EACN,SAAS,EACT,aAAa,EACb,QAAQ,EAGR,WAAW,EACX,WAAW,EACZ,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/schema/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAA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,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;IACnC,gBAAgB,EAAE,WAAW,CAAA;CAC9B,CAAA;AAED,eAAO,MAAM,UAAU,0XAsBpB,IAAI,KAAG,MAosBT,CAAA"}
|
package/dist/schema/build.js
CHANGED
|
@@ -3,6 +3,7 @@ import toSnakeCase from 'to-snake-case';
|
|
|
3
3
|
import { createTableName } from '../createTableName.js';
|
|
4
4
|
import { buildForeignKeyName } from '../utilities/buildForeignKeyName.js';
|
|
5
5
|
import { buildIndexName } from '../utilities/buildIndexName.js';
|
|
6
|
+
import { exceedsIdentifierLength, fitIdentifierLength } from '../utilities/fitIdentifierLength.js';
|
|
6
7
|
import { isUUIDType } from '../utilities/isUUIDType.js';
|
|
7
8
|
import { traverseFields } from './traverseFields.js';
|
|
8
9
|
export const buildTable = ({ adapter, baseColumns = {}, baseForeignKeys = {}, baseIndexes = {}, blocksTableNameMap, compoundIndexes, disableNotNull, disableRelsTableUnique = false, disableUnique = false, fields, parentIsLocalized, rootRelationships, rootRelationsToBuild, rootTableIDColType, rootTableName: incomingRootTableName, rootUniqueRelationships, setColumnID, tableName, timestamps, versions, withinLocalizedArrayOrBlock })=>{
|
|
@@ -88,7 +89,10 @@ export const buildTable = ({ adapter, baseColumns = {}, baseForeignKeys = {}, ba
|
|
|
88
89
|
foreignKeys: baseForeignKeys,
|
|
89
90
|
indexes
|
|
90
91
|
};
|
|
91
|
-
adapter.rawTables[tableName] =
|
|
92
|
+
adapter.rawTables[tableName] = promoteLongInlineForeignKeys({
|
|
93
|
+
adapter,
|
|
94
|
+
table
|
|
95
|
+
});
|
|
92
96
|
if (hasLocalizedField || localizedRelations.size) {
|
|
93
97
|
const localeTableName = `${tableName}${adapter.localesSuffix}`;
|
|
94
98
|
adapter.rawTables[localeTableName] = localesTable;
|
|
@@ -110,13 +114,13 @@ export const buildTable = ({ adapter, baseColumns = {}, baseForeignKeys = {}, ba
|
|
|
110
114
|
};
|
|
111
115
|
localesIndexes._localeParent = {
|
|
112
116
|
name: buildIndexName({
|
|
113
|
-
name: `${localeTableName}
|
|
117
|
+
name: `${localeTableName}_parent_id_locale_unique`,
|
|
114
118
|
adapter,
|
|
115
119
|
appendSuffix: false
|
|
116
120
|
}),
|
|
117
121
|
on: [
|
|
118
|
-
'
|
|
119
|
-
'
|
|
122
|
+
'_parentID',
|
|
123
|
+
'_locale'
|
|
120
124
|
],
|
|
121
125
|
unique: true
|
|
122
126
|
};
|
|
@@ -143,7 +147,10 @@ export const buildTable = ({ adapter, baseColumns = {}, baseForeignKeys = {}, ba
|
|
|
143
147
|
},
|
|
144
148
|
indexes: localesIndexes
|
|
145
149
|
};
|
|
146
|
-
adapter.rawTables[localeTableName] =
|
|
150
|
+
adapter.rawTables[localeTableName] = promoteLongInlineForeignKeys({
|
|
151
|
+
adapter,
|
|
152
|
+
table: localesTable
|
|
153
|
+
});
|
|
147
154
|
const localeRelations = {
|
|
148
155
|
_parentID: {
|
|
149
156
|
type: 'one',
|
|
@@ -701,5 +708,47 @@ export const buildTable = ({ adapter, baseColumns = {}, baseForeignKeys = {}, ba
|
|
|
701
708
|
relationsToBuild
|
|
702
709
|
};
|
|
703
710
|
};
|
|
711
|
+
/**
|
|
712
|
+
* Single-relation relationship/upload columns use Drizzle's inline `.references()`, which names
|
|
713
|
+
* the foreign key `<table>_<column>_<target>_<targetColumn>_fk` with no way to override it.
|
|
714
|
+
* When that name exceeds the Postgres identifier limit, Postgres stores a truncated name, so push
|
|
715
|
+
* never matches it and drops and re-adds the foreign key on every run, which can fail with
|
|
716
|
+
* "already exists". Those foreign keys are moved to explicitly named table-level foreign keys
|
|
717
|
+
* instead. Names that fit, and every foreign key on non-Postgres adapters, keep `.references()`.
|
|
718
|
+
*/ const promoteLongInlineForeignKeys = ({ adapter, table })=>{
|
|
719
|
+
for (const [columnKey, column] of Object.entries(table.columns)){
|
|
720
|
+
if (!column.reference) {
|
|
721
|
+
continue;
|
|
722
|
+
}
|
|
723
|
+
const { name: targetColumnName, onDelete, table: targetTableName } = column.reference;
|
|
724
|
+
const drizzleForeignKeyName = `${table.name}_${column.name}_${targetTableName}_${targetColumnName}`;
|
|
725
|
+
if (!exceedsIdentifierLength({
|
|
726
|
+
adapter,
|
|
727
|
+
identifier: `${drizzleForeignKeyName}_fk`
|
|
728
|
+
})) {
|
|
729
|
+
continue;
|
|
730
|
+
}
|
|
731
|
+
table.foreignKeys ??= {};
|
|
732
|
+
table.foreignKeys[`${columnKey}Fk`] = {
|
|
733
|
+
name: fitIdentifierLength({
|
|
734
|
+
name: drizzleForeignKeyName,
|
|
735
|
+
adapter,
|
|
736
|
+
suffix: '_fk'
|
|
737
|
+
}),
|
|
738
|
+
columns: [
|
|
739
|
+
columnKey
|
|
740
|
+
],
|
|
741
|
+
foreignColumns: [
|
|
742
|
+
{
|
|
743
|
+
name: targetColumnName,
|
|
744
|
+
table: targetTableName
|
|
745
|
+
}
|
|
746
|
+
],
|
|
747
|
+
onDelete
|
|
748
|
+
};
|
|
749
|
+
delete column.reference;
|
|
750
|
+
}
|
|
751
|
+
return table;
|
|
752
|
+
};
|
|
704
753
|
|
|
705
754
|
//# sourceMappingURL=build.js.map
|
package/dist/schema/build.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema/build.ts"],"sourcesContent":["import type { FlattenedField, SanitizedCompoundIndex } from 'payload'\n\nimport { InvalidConfiguration } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type {\n DrizzleAdapter,\n IDType,\n RawColumn,\n RawForeignKey,\n RawIndex,\n RawRelation,\n RawTable,\n RelationMap,\n SetColumnID,\n} from '../types.js'\n\nimport { createTableName } from '../createTableName.js'\nimport { buildForeignKeyName } from '../utilities/buildForeignKeyName.js'\nimport { buildIndexName } from '../utilities/buildIndexName.js'\nimport { isUUIDType } from '../utilities/isUUIDType.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n baseColumns?: Record<string, RawColumn>\n /**\n * After table is created, run these functions to add extra config to the table\n * ie. indexes, multiple columns, etc\n */\n baseForeignKeys?: Record<string, RawForeignKey>\n /**\n * After table is created, run these functions to add extra config to the table\n * ie. indexes, multiple columns, etc\n */\n baseIndexes?: Record<string, RawIndex>\n blocksTableNameMap: Record<string, number>\n buildNumbers?: boolean\n buildRelationships?: boolean\n compoundIndexes?: SanitizedCompoundIndex[]\n disableNotNull: boolean\n disableRelsTableUnique?: boolean\n disableUnique: boolean\n fields: FlattenedField[]\n parentIsLocalized: boolean\n rootRelationships?: Set<string>\n rootRelationsToBuild?: RelationMap\n rootTableIDColType?: IDType\n rootTableName?: string\n rootUniqueRelationships?: Set<string>\n setColumnID: SetColumnID\n tableName: string\n timestamps?: boolean\n versions: boolean\n /**\n * Tracks whether or not this table is built\n * from the result of a localized array or block field at some point\n */\n withinLocalizedArrayOrBlock?: boolean\n}\n\ntype Result = {\n hasLocalizedManyNumberField: boolean\n hasLocalizedManyTextField: boolean\n hasLocalizedRelationshipField: boolean\n hasManyNumberField: 'index' | boolean\n hasManyTextField: 'index' | boolean\n relationsToBuild: RelationMap\n}\n\nexport const buildTable = ({\n adapter,\n baseColumns = {},\n baseForeignKeys = {},\n baseIndexes = {},\n blocksTableNameMap,\n compoundIndexes,\n disableNotNull,\n disableRelsTableUnique = false,\n disableUnique = false,\n fields,\n parentIsLocalized,\n rootRelationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName: incomingRootTableName,\n rootUniqueRelationships,\n setColumnID,\n tableName,\n timestamps,\n versions,\n withinLocalizedArrayOrBlock,\n}: Args): Result => {\n const isRoot = !incomingRootTableName\n const rootTableName = incomingRootTableName || tableName\n const columns: Record<string, RawColumn> = baseColumns\n const indexes: Record<string, RawIndex> = baseIndexes\n\n const localesColumns: Record<string, RawColumn> = {}\n const localesIndexes: Record<string, RawIndex> = {}\n let localesTable: RawTable\n let textsTable: RawTable\n let numbersTable: RawTable\n\n // Relationships to the base collection\n const relationships: Set<string> = rootRelationships || new Set()\n\n // Unique relationships to the base collection\n const uniqueRelationships: Set<string> = rootUniqueRelationships || new Set()\n\n let relationshipsTable: RawTable\n\n // Drizzle relations\n const relationsToBuild: RelationMap = new Map()\n\n const idColType: IDType = setColumnID({ adapter, columns, fields })\n\n const {\n hasLocalizedField,\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n } = traverseFields({\n adapter,\n blocksTableNameMap,\n columns,\n disableNotNull,\n disableRelsTableUnique,\n disableUnique,\n fields,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName: tableName,\n parentIsLocalized,\n parentTableName: tableName,\n relationships,\n relationsToBuild,\n rootRelationsToBuild: rootRelationsToBuild || relationsToBuild,\n rootTableIDColType: rootTableIDColType || idColType,\n rootTableName,\n setColumnID,\n uniqueRelationships,\n versions,\n withinLocalizedArrayOrBlock,\n })\n\n // split the relationsToBuild by localized and non-localized\n const localizedRelations = new Map()\n const nonLocalizedRelations = new Map()\n\n relationsToBuild.forEach(({ type, localized, relationName, target }, key) => {\n const map = localized ? localizedRelations : nonLocalizedRelations\n map.set(key, { type, relationName, target })\n })\n\n if (timestamps) {\n columns.createdAt = {\n name: 'created_at',\n type: 'timestamp',\n defaultNow: true,\n mode: 'string',\n notNull: true,\n precision: 3,\n withTimezone: true,\n }\n\n columns.updatedAt = {\n name: 'updated_at',\n type: 'timestamp',\n defaultNow: true,\n mode: 'string',\n notNull: true,\n precision: 3,\n withTimezone: true,\n }\n }\n\n const table: RawTable = {\n name: tableName,\n columns,\n foreignKeys: baseForeignKeys,\n indexes,\n }\n\n adapter.rawTables[tableName] = table\n\n if (hasLocalizedField || localizedRelations.size) {\n const localeTableName = `${tableName}${adapter.localesSuffix}`\n adapter.rawTables[localeTableName] = localesTable\n\n localesColumns.id = {\n name: 'id',\n type: 'serial',\n primaryKey: true,\n }\n\n localesColumns._locale = {\n name: '_locale',\n type: 'enum',\n locale: true,\n notNull: true,\n }\n\n localesColumns._parentID = {\n name: '_parent_id',\n type: idColType,\n notNull: true,\n }\n\n localesIndexes._localeParent = {\n name: buildIndexName({\n name: `${localeTableName}_locale_parent_id_unique`,\n adapter,\n appendSuffix: false,\n }),\n on: ['_locale', '_parentID'],\n unique: true,\n }\n\n localesTable = {\n name: localeTableName,\n columns: localesColumns,\n foreignKeys: {\n _parentIdFk: {\n name: buildForeignKeyName({ name: `${localeTableName}_parent_id`, adapter }),\n columns: ['_parentID'],\n foreignColumns: [\n {\n name: 'id',\n table: tableName,\n },\n ],\n onDelete: 'cascade',\n },\n },\n indexes: localesIndexes,\n }\n\n adapter.rawTables[localeTableName] = localesTable\n\n const localeRelations: Record<string, RawRelation> = {\n _parentID: {\n type: 'one',\n fields: [\n {\n name: '_parentID',\n table: localeTableName,\n },\n ],\n references: ['id'],\n relationName: '_locales',\n to: tableName,\n },\n }\n\n localizedRelations.forEach(({ type, target }, key) => {\n if (type === 'one') {\n localeRelations[key] = {\n type: 'one',\n fields: [\n {\n name: key,\n table: localeTableName,\n },\n ],\n references: ['id'],\n relationName: key,\n to: target,\n }\n }\n if (type === 'many') {\n localeRelations[key] = {\n type: 'many',\n relationName: key,\n to: target,\n }\n }\n })\n adapter.rawRelations[localeTableName] = localeRelations\n }\n\n if (compoundIndexes) {\n for (const index of compoundIndexes) {\n let someLocalized: boolean | null = null\n const columns: string[] = []\n\n const getTableToUse = () => {\n if (someLocalized) {\n return localesTable\n }\n\n return table\n }\n\n for (const { path, pathHasLocalized } of index.fields) {\n if (someLocalized === null) {\n someLocalized = pathHasLocalized\n }\n\n if (someLocalized !== pathHasLocalized) {\n throw new InvalidConfiguration(\n `Compound indexes within localized and non localized fields are not supported in SQL. Expected ${path} to be ${someLocalized ? 'non' : ''} localized.`,\n )\n }\n\n const columnPath = path.replaceAll('.', '_')\n\n if (!getTableToUse().columns[columnPath]) {\n throw new InvalidConfiguration(\n `Column ${columnPath} for compound index on ${path} was not found in the ${getTableToUse().name} table.`,\n )\n }\n\n columns.push(columnPath)\n }\n\n if (someLocalized) {\n columns.push('_locale')\n }\n\n let name = columns.join('_')\n // truncate against the limit, buildIndexName will handle collisions\n if (name.length > 63) {\n name = 'compound_index'\n }\n\n const indexName = buildIndexName({ name, adapter })\n\n getTableToUse().indexes[indexName] = {\n name: indexName,\n on: columns,\n unique: disableUnique ? false : index.unique,\n }\n }\n }\n\n if (isRoot) {\n if (hasManyTextField) {\n const textsTableName = `${rootTableName}_texts`\n adapter.rawTables[textsTableName] = textsTable\n\n const columns: Record<string, RawColumn> = {\n id: {\n name: 'id',\n type: 'serial',\n primaryKey: true,\n },\n order: {\n name: 'order',\n type: 'integer',\n notNull: true,\n },\n parent: {\n name: 'parent_id',\n type: idColType,\n notNull: true,\n },\n path: {\n name: 'path',\n type: 'varchar',\n\n notNull: true,\n },\n text: {\n name: 'text',\n type: 'varchar',\n },\n }\n\n if (hasLocalizedManyTextField) {\n columns.locale = {\n name: 'locale',\n type: 'enum',\n locale: true,\n }\n }\n\n const textsTableIndexes: Record<string, RawIndex> = {\n orderParentIdx: {\n name: buildIndexName({\n name: `${textsTableName}_order_parent`,\n adapter,\n appendSuffix: false,\n }),\n on: ['order', 'parent'],\n },\n }\n\n if (hasManyTextField === 'index') {\n textsTableIndexes.text_idx = {\n name: buildIndexName({ name: `${textsTableName}_text`, adapter }),\n on: 'text',\n }\n }\n\n if (hasLocalizedManyTextField) {\n textsTableIndexes.localeParent = {\n name: buildIndexName({\n name: `${textsTableName}_locale_parent`,\n adapter,\n appendSuffix: false,\n }),\n on: ['locale', 'parent'],\n }\n }\n\n textsTable = {\n name: textsTableName,\n columns,\n foreignKeys: {\n parentFk: {\n name: buildForeignKeyName({ name: `${textsTableName}_parent`, adapter }),\n columns: ['parent'],\n foreignColumns: [\n {\n name: 'id',\n table: tableName,\n },\n ],\n onDelete: 'cascade',\n },\n },\n indexes: textsTableIndexes,\n }\n\n adapter.rawTables[textsTableName] = textsTable\n\n adapter.rawRelations[textsTableName] = {\n parent: {\n type: 'one',\n fields: [\n {\n name: 'parent',\n table: textsTableName,\n },\n ],\n references: ['id'],\n relationName: '_texts',\n to: tableName,\n },\n }\n }\n\n if (hasManyNumberField) {\n const numbersTableName = `${rootTableName}_numbers`\n adapter.rawTables[numbersTableName] = numbersTable\n const columns: Record<string, RawColumn> = {\n id: {\n name: 'id',\n type: 'serial',\n primaryKey: true,\n },\n number: {\n name: 'number',\n type: 'numeric',\n },\n order: {\n name: 'order',\n type: 'integer',\n notNull: true,\n },\n parent: {\n name: 'parent_id',\n type: idColType,\n notNull: true,\n },\n path: {\n name: 'path',\n type: 'varchar',\n notNull: true,\n },\n }\n\n if (hasLocalizedManyNumberField) {\n columns.locale = {\n name: 'locale',\n type: 'enum',\n locale: true,\n }\n }\n\n const numbersTableIndexes: Record<string, RawIndex> = {\n orderParentIdx: {\n name: buildIndexName({ name: `${numbersTableName}_order_parent`, adapter }),\n on: ['order', 'parent'],\n },\n }\n\n if (hasManyNumberField === 'index') {\n numbersTableIndexes.numberIdx = {\n name: buildIndexName({ name: `${numbersTableName}_number`, adapter }),\n on: 'number',\n }\n }\n\n if (hasLocalizedManyNumberField) {\n numbersTableIndexes.localeParent = {\n name: buildIndexName({\n name: `${numbersTableName}_locale_parent`,\n adapter,\n appendSuffix: false,\n }),\n on: ['locale', 'parent'],\n }\n }\n\n numbersTable = {\n name: numbersTableName,\n columns,\n foreignKeys: {\n parentFk: {\n name: buildForeignKeyName({ name: `${numbersTableName}_parent`, adapter }),\n columns: ['parent'],\n foreignColumns: [\n {\n name: 'id',\n table: tableName,\n },\n ],\n onDelete: 'cascade',\n },\n },\n indexes: numbersTableIndexes,\n }\n\n adapter.rawTables[numbersTableName] = numbersTable\n\n adapter.rawRelations[numbersTableName] = {\n parent: {\n type: 'one',\n fields: [\n {\n name: 'parent',\n table: numbersTableName,\n },\n ],\n references: ['id'],\n relationName: '_numbers',\n to: tableName,\n },\n }\n }\n\n if (relationships.size) {\n const relationshipColumns: Record<string, RawColumn> = {\n id: {\n name: 'id',\n type: 'serial',\n primaryKey: true,\n },\n order: {\n name: 'order',\n type: 'integer',\n },\n parent: {\n name: 'parent_id',\n type: idColType,\n notNull: true,\n },\n path: {\n name: 'path',\n type: 'varchar',\n notNull: true,\n },\n }\n\n if (hasLocalizedRelationshipField) {\n relationshipColumns.locale = {\n name: 'locale',\n type: 'enum',\n locale: true,\n }\n }\n\n const relationshipsTableName = `${tableName}${adapter.relationshipsSuffix}`\n\n const relationshipIndexes: Record<string, RawIndex> = {\n order: {\n name: buildIndexName({ name: `${relationshipsTableName}_order`, adapter }),\n on: 'order',\n },\n parentIdx: {\n name: buildIndexName({ name: `${relationshipsTableName}_parent`, adapter }),\n on: 'parent',\n },\n pathIdx: {\n name: buildIndexName({ name: `${relationshipsTableName}_path`, adapter }),\n on: 'path',\n },\n }\n\n if (hasLocalizedRelationshipField) {\n relationshipIndexes.localeIdx = {\n name: buildIndexName({ name: `${relationshipsTableName}_locale`, adapter }),\n on: 'locale',\n }\n }\n\n const relationshipForeignKeys: Record<string, RawForeignKey> = {\n parentFk: {\n name: buildForeignKeyName({ name: `${relationshipsTableName}_parent`, adapter }),\n columns: ['parent'],\n foreignColumns: [\n {\n name: 'id',\n table: tableName,\n },\n ],\n onDelete: 'cascade',\n },\n }\n\n relationships.forEach((relationTo) => {\n const relationshipConfig = adapter.payload.collections[relationTo].config\n const formattedRelationTo = createTableName({\n adapter,\n config: relationshipConfig,\n throwValidationError: true,\n })\n let colType: 'integer' | 'numeric' | 'uuid' | 'varchar' = isUUIDType(adapter.idType)\n ? 'uuid'\n : 'integer'\n const relatedCollectionCustomIDType =\n adapter.payload.collections[relationshipConfig.slug]?.customIDType\n\n if (relatedCollectionCustomIDType === 'number') {\n colType = 'numeric'\n }\n if (relatedCollectionCustomIDType === 'text') {\n colType = 'varchar'\n }\n\n const colName = `${relationTo}ID`\n\n relationshipColumns[colName] = {\n name: `${formattedRelationTo}_id`,\n type: colType,\n }\n\n relationshipForeignKeys[`${relationTo}IdFk`] = {\n name: buildForeignKeyName({\n name: `${relationshipsTableName}_${toSnakeCase(relationTo)}`,\n adapter,\n }),\n columns: [colName],\n foreignColumns: [\n {\n name: 'id',\n table: formattedRelationTo,\n },\n ],\n onDelete: 'cascade',\n }\n\n const indexColumns = [colName]\n\n const unique = !disableUnique && uniqueRelationships.has(relationTo)\n\n if (unique) {\n indexColumns.push('path')\n }\n if (hasLocalizedRelationshipField) {\n indexColumns.push('locale')\n }\n\n const indexName = buildIndexName({\n name: `${relationshipsTableName}_${formattedRelationTo}_id`,\n adapter,\n })\n\n relationshipIndexes[indexName] = {\n name: indexName,\n on: indexColumns,\n unique,\n }\n })\n\n relationshipsTable = {\n name: relationshipsTableName,\n columns: relationshipColumns,\n foreignKeys: relationshipForeignKeys,\n indexes: relationshipIndexes,\n }\n\n adapter.rawTables[relationshipsTableName] = relationshipsTable\n\n const relationshipsTableRelations: Record<string, RawRelation> = {\n parent: {\n type: 'one',\n fields: [\n {\n name: 'parent',\n table: relationshipsTableName,\n },\n ],\n references: ['id'],\n relationName: '_rels',\n to: tableName,\n },\n }\n\n relationships.forEach((relationTo) => {\n const relatedTableName = createTableName({\n adapter,\n config: adapter.payload.collections[relationTo].config,\n throwValidationError: true,\n })\n const idColumnName = `${relationTo}ID`\n\n relationshipsTableRelations[idColumnName] = {\n type: 'one',\n fields: [\n {\n name: idColumnName,\n table: relationshipsTableName,\n },\n ],\n references: ['id'],\n relationName: relationTo,\n to: relatedTableName,\n }\n })\n adapter.rawRelations[relationshipsTableName] = relationshipsTableRelations\n }\n }\n\n const tableRelations: Record<string, RawRelation> = {}\n\n nonLocalizedRelations.forEach(({ type, relationName, target }, key) => {\n if (type === 'one') {\n tableRelations[key] = {\n type: 'one',\n fields: [\n {\n name: key,\n table: tableName,\n },\n ],\n references: ['id'],\n relationName: key,\n to: target,\n }\n }\n if (type === 'many') {\n tableRelations[key] = {\n type: 'many',\n relationName: relationName || key,\n to: target,\n }\n }\n })\n\n if (hasLocalizedField) {\n tableRelations._locales = {\n type: 'many',\n relationName: '_locales',\n to: localesTable.name,\n }\n }\n\n if (isRoot && textsTable) {\n tableRelations._texts = {\n type: 'many',\n relationName: '_texts',\n to: textsTable.name,\n }\n }\n\n if (isRoot && numbersTable) {\n tableRelations._numbers = {\n type: 'many',\n relationName: '_numbers',\n to: numbersTable.name,\n }\n }\n\n if (relationships.size && relationshipsTable) {\n tableRelations._rels = {\n type: 'many',\n relationName: '_rels',\n to: relationshipsTable.name,\n }\n }\n\n adapter.rawRelations[tableName] = tableRelations\n\n return {\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n relationsToBuild,\n }\n}\n"],"names":["InvalidConfiguration","toSnakeCase","createTableName","buildForeignKeyName","buildIndexName","isUUIDType","traverseFields","buildTable","adapter","baseColumns","baseForeignKeys","baseIndexes","blocksTableNameMap","compoundIndexes","disableNotNull","disableRelsTableUnique","disableUnique","fields","parentIsLocalized","rootRelationships","rootRelationsToBuild","rootTableIDColType","rootTableName","incomingRootTableName","rootUniqueRelationships","setColumnID","tableName","timestamps","versions","withinLocalizedArrayOrBlock","isRoot","columns","indexes","localesColumns","localesIndexes","localesTable","textsTable","numbersTable","relationships","Set","uniqueRelationships","relationshipsTable","relationsToBuild","Map","idColType","hasLocalizedField","hasLocalizedManyNumberField","hasLocalizedManyTextField","hasLocalizedRelationshipField","hasManyNumberField","hasManyTextField","newTableName","parentTableName","localizedRelations","nonLocalizedRelations","forEach","type","localized","relationName","target","key","map","set","createdAt","name","defaultNow","mode","notNull","precision","withTimezone","updatedAt","table","foreignKeys","rawTables","size","localeTableName","localesSuffix","id","primaryKey","_locale","locale","_parentID","_localeParent","appendSuffix","on","unique","_parentIdFk","foreignColumns","onDelete","localeRelations","references","to","rawRelations","index","someLocalized","getTableToUse","path","pathHasLocalized","columnPath","replaceAll","push","join","length","indexName","textsTableName","order","parent","text","textsTableIndexes","orderParentIdx","text_idx","localeParent","parentFk","numbersTableName","number","numbersTableIndexes","numberIdx","relationshipColumns","relationshipsTableName","relationshipsSuffix","relationshipIndexes","parentIdx","pathIdx","localeIdx","relationshipForeignKeys","relationTo","relationshipConfig","payload","collections","config","formattedRelationTo","throwValidationError","colType","idType","relatedCollectionCustomIDType","slug","customIDType","colName","indexColumns","has","relationshipsTableRelations","relatedTableName","idColumnName","tableRelations","_locales","_texts","_numbers","_rels"],"mappings":"AAEA,SAASA,oBAAoB,QAAQ,UAAS;AAC9C,OAAOC,iBAAiB,gBAAe;AAcvC,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,cAAc,QAAQ,iCAAgC;AAC/D,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,cAAc,QAAQ,sBAAqB;AAiDpD,OAAO,MAAMC,aAAa,CAAC,EACzBC,OAAO,EACPC,cAAc,CAAC,CAAC,EAChBC,kBAAkB,CAAC,CAAC,EACpBC,cAAc,CAAC,CAAC,EAChBC,kBAAkB,EAClBC,eAAe,EACfC,cAAc,EACdC,yBAAyB,KAAK,EAC9BC,gBAAgB,KAAK,EACrBC,MAAM,EACNC,iBAAiB,EACjBC,iBAAiB,EACjBC,oBAAoB,EACpBC,kBAAkB,EAClBC,eAAeC,qBAAqB,EACpCC,uBAAuB,EACvBC,WAAW,EACXC,SAAS,EACTC,UAAU,EACVC,QAAQ,EACRC,2BAA2B,EACtB;IACL,MAAMC,SAAS,CAACP;IAChB,MAAMD,gBAAgBC,yBAAyBG;IAC/C,MAAMK,UAAqCtB;IAC3C,MAAMuB,UAAoCrB;IAE1C,MAAMsB,iBAA4C,CAAC;IACnD,MAAMC,iBAA2C,CAAC;IAClD,IAAIC;IACJ,IAAIC;IACJ,IAAIC;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E;gBAC9B+B,IAAIhC;YACN;QACF;IACF;IAEA,IAAId,mBAAmB;QACrBkG,eAAeC,QAAQ,GAAG;YACxBxF,MAAM;YACNE,cAAc;YACdiC,IAAIxD,aAAa6B,IAAI;QACvB;IACF;IAEA,IAAIlC,UAAUM,YAAY;QACxB2G,eAAeE,MAAM,GAAG;YACtBzF,MAAM;YACNE,cAAc;YACdiC,IAAIvD,WAAW4B,IAAI;QACrB;IACF;IAEA,IAAIlC,UAAUO,cAAc;QAC1B0G,eAAeG,QAAQ,GAAG;YACxB1F,MAAM;YACNE,cAAc;YACdiC,IAAItD,aAAa2B,IAAI;QACvB;IACF;IAEA,IAAI1B,cAAcoC,IAAI,IAAIjC,oBAAoB;QAC5CsG,eAAeI,KAAK,GAAG;YACrB3F,MAAM;YACNE,cAAc;YACdiC,IAAIlD,mBAAmBuB,IAAI;QAC7B;IACF;IAEAxD,QAAQoF,YAAY,CAAClE,UAAU,GAAGqH;IAElC,OAAO;QACLjG;QACAC;QACAC;QACAC;QACAC;QACAR;IACF;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/schema/build.ts"],"sourcesContent":["import type { FlattenedField, SanitizedCompoundIndex } from 'payload'\n\nimport { InvalidConfiguration } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type {\n DrizzleAdapter,\n IDType,\n RawColumn,\n RawForeignKey,\n RawIndex,\n RawRelation,\n RawTable,\n RelationMap,\n SetColumnID,\n} from '../types.js'\n\nimport { createTableName } from '../createTableName.js'\nimport { buildForeignKeyName } from '../utilities/buildForeignKeyName.js'\nimport { buildIndexName } from '../utilities/buildIndexName.js'\nimport { exceedsIdentifierLength, fitIdentifierLength } from '../utilities/fitIdentifierLength.js'\nimport { isUUIDType } from '../utilities/isUUIDType.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n baseColumns?: Record<string, RawColumn>\n /**\n * After table is created, run these functions to add extra config to the table\n * ie. indexes, multiple columns, etc\n */\n baseForeignKeys?: Record<string, RawForeignKey>\n /**\n * After table is created, run these functions to add extra config to the table\n * ie. indexes, multiple columns, etc\n */\n baseIndexes?: Record<string, RawIndex>\n blocksTableNameMap: Record<string, number>\n buildNumbers?: boolean\n buildRelationships?: boolean\n compoundIndexes?: SanitizedCompoundIndex[]\n disableNotNull: boolean\n disableRelsTableUnique?: boolean\n disableUnique: boolean\n fields: FlattenedField[]\n parentIsLocalized: boolean\n rootRelationships?: Set<string>\n rootRelationsToBuild?: RelationMap\n rootTableIDColType?: IDType\n rootTableName?: string\n rootUniqueRelationships?: Set<string>\n setColumnID: SetColumnID\n tableName: string\n timestamps?: boolean\n versions: boolean\n /**\n * Tracks whether or not this table is built\n * from the result of a localized array or block field at some point\n */\n withinLocalizedArrayOrBlock?: boolean\n}\n\ntype Result = {\n hasLocalizedManyNumberField: boolean\n hasLocalizedManyTextField: boolean\n hasLocalizedRelationshipField: boolean\n hasManyNumberField: 'index' | boolean\n hasManyTextField: 'index' | boolean\n relationsToBuild: RelationMap\n}\n\nexport const buildTable = ({\n adapter,\n baseColumns = {},\n baseForeignKeys = {},\n baseIndexes = {},\n blocksTableNameMap,\n compoundIndexes,\n disableNotNull,\n disableRelsTableUnique = false,\n disableUnique = false,\n fields,\n parentIsLocalized,\n rootRelationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName: incomingRootTableName,\n rootUniqueRelationships,\n setColumnID,\n tableName,\n timestamps,\n versions,\n withinLocalizedArrayOrBlock,\n}: Args): Result => {\n const isRoot = !incomingRootTableName\n const rootTableName = incomingRootTableName || tableName\n const columns: Record<string, RawColumn> = baseColumns\n const indexes: Record<string, RawIndex> = baseIndexes\n\n const localesColumns: Record<string, RawColumn> = {}\n const localesIndexes: Record<string, RawIndex> = {}\n let localesTable: RawTable\n let textsTable: RawTable\n let numbersTable: RawTable\n\n // Relationships to the base collection\n const relationships: Set<string> = rootRelationships || new Set()\n\n // Unique relationships to the base collection\n const uniqueRelationships: Set<string> = rootUniqueRelationships || new Set()\n\n let relationshipsTable: RawTable\n\n // Drizzle relations\n const relationsToBuild: RelationMap = new Map()\n\n const idColType: IDType = setColumnID({ adapter, columns, fields })\n\n const {\n hasLocalizedField,\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n } = traverseFields({\n adapter,\n blocksTableNameMap,\n columns,\n disableNotNull,\n disableRelsTableUnique,\n disableUnique,\n fields,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName: tableName,\n parentIsLocalized,\n parentTableName: tableName,\n relationships,\n relationsToBuild,\n rootRelationsToBuild: rootRelationsToBuild || relationsToBuild,\n rootTableIDColType: rootTableIDColType || idColType,\n rootTableName,\n setColumnID,\n uniqueRelationships,\n versions,\n withinLocalizedArrayOrBlock,\n })\n\n // split the relationsToBuild by localized and non-localized\n const localizedRelations = new Map()\n const nonLocalizedRelations = new Map()\n\n relationsToBuild.forEach(({ type, localized, relationName, target }, key) => {\n const map = localized ? localizedRelations : nonLocalizedRelations\n map.set(key, { type, relationName, target })\n })\n\n if (timestamps) {\n columns.createdAt = {\n name: 'created_at',\n type: 'timestamp',\n defaultNow: true,\n mode: 'string',\n notNull: true,\n precision: 3,\n withTimezone: true,\n }\n\n columns.updatedAt = {\n name: 'updated_at',\n type: 'timestamp',\n defaultNow: true,\n mode: 'string',\n notNull: true,\n precision: 3,\n withTimezone: true,\n }\n }\n\n const table: RawTable = {\n name: tableName,\n columns,\n foreignKeys: baseForeignKeys,\n indexes,\n }\n\n adapter.rawTables[tableName] = promoteLongInlineForeignKeys({ adapter, table })\n\n if (hasLocalizedField || localizedRelations.size) {\n const localeTableName = `${tableName}${adapter.localesSuffix}`\n adapter.rawTables[localeTableName] = localesTable\n\n localesColumns.id = {\n name: 'id',\n type: 'serial',\n primaryKey: true,\n }\n\n localesColumns._locale = {\n name: '_locale',\n type: 'enum',\n locale: true,\n notNull: true,\n }\n\n localesColumns._parentID = {\n name: '_parent_id',\n type: idColType,\n notNull: true,\n }\n\n localesIndexes._localeParent = {\n name: buildIndexName({\n name: `${localeTableName}_parent_id_locale_unique`,\n adapter,\n appendSuffix: false,\n }),\n on: ['_parentID', '_locale'],\n unique: true,\n }\n\n localesTable = {\n name: localeTableName,\n columns: localesColumns,\n foreignKeys: {\n _parentIdFk: {\n name: buildForeignKeyName({ name: `${localeTableName}_parent_id`, adapter }),\n columns: ['_parentID'],\n foreignColumns: [\n {\n name: 'id',\n table: tableName,\n },\n ],\n onDelete: 'cascade',\n },\n },\n indexes: localesIndexes,\n }\n\n adapter.rawTables[localeTableName] = promoteLongInlineForeignKeys({\n adapter,\n table: localesTable,\n })\n\n const localeRelations: Record<string, RawRelation> = {\n _parentID: {\n type: 'one',\n fields: [\n {\n name: '_parentID',\n table: localeTableName,\n },\n ],\n references: ['id'],\n relationName: '_locales',\n to: tableName,\n },\n }\n\n localizedRelations.forEach(({ type, target }, key) => {\n if (type === 'one') {\n localeRelations[key] = {\n type: 'one',\n fields: [\n {\n name: key,\n table: localeTableName,\n },\n ],\n references: ['id'],\n relationName: key,\n to: target,\n }\n }\n if (type === 'many') {\n localeRelations[key] = {\n type: 'many',\n relationName: key,\n to: target,\n }\n }\n })\n adapter.rawRelations[localeTableName] = localeRelations\n }\n\n if (compoundIndexes) {\n for (const index of compoundIndexes) {\n let someLocalized: boolean | null = null\n const columns: string[] = []\n\n const getTableToUse = () => {\n if (someLocalized) {\n return localesTable\n }\n\n return table\n }\n\n for (const { path, pathHasLocalized } of index.fields) {\n if (someLocalized === null) {\n someLocalized = pathHasLocalized\n }\n\n if (someLocalized !== pathHasLocalized) {\n throw new InvalidConfiguration(\n `Compound indexes within localized and non localized fields are not supported in SQL. Expected ${path} to be ${someLocalized ? 'non' : ''} localized.`,\n )\n }\n\n const columnPath = path.replaceAll('.', '_')\n\n if (!getTableToUse().columns[columnPath]) {\n throw new InvalidConfiguration(\n `Column ${columnPath} for compound index on ${path} was not found in the ${getTableToUse().name} table.`,\n )\n }\n\n columns.push(columnPath)\n }\n\n if (someLocalized) {\n columns.push('_locale')\n }\n\n let name = columns.join('_')\n // truncate against the limit, buildIndexName will handle collisions\n if (name.length > 63) {\n name = 'compound_index'\n }\n\n const indexName = buildIndexName({ name, adapter })\n\n getTableToUse().indexes[indexName] = {\n name: indexName,\n on: columns,\n unique: disableUnique ? false : index.unique,\n }\n }\n }\n\n if (isRoot) {\n if (hasManyTextField) {\n const textsTableName = `${rootTableName}_texts`\n adapter.rawTables[textsTableName] = textsTable\n\n const columns: Record<string, RawColumn> = {\n id: {\n name: 'id',\n type: 'serial',\n primaryKey: true,\n },\n order: {\n name: 'order',\n type: 'integer',\n notNull: true,\n },\n parent: {\n name: 'parent_id',\n type: idColType,\n notNull: true,\n },\n path: {\n name: 'path',\n type: 'varchar',\n\n notNull: true,\n },\n text: {\n name: 'text',\n type: 'varchar',\n },\n }\n\n if (hasLocalizedManyTextField) {\n columns.locale = {\n name: 'locale',\n type: 'enum',\n locale: true,\n }\n }\n\n const textsTableIndexes: Record<string, RawIndex> = {\n orderParentIdx: {\n name: buildIndexName({\n name: `${textsTableName}_order_parent`,\n adapter,\n appendSuffix: false,\n }),\n on: ['order', 'parent'],\n },\n }\n\n if (hasManyTextField === 'index') {\n textsTableIndexes.text_idx = {\n name: buildIndexName({ name: `${textsTableName}_text`, adapter }),\n on: 'text',\n }\n }\n\n if (hasLocalizedManyTextField) {\n textsTableIndexes.localeParent = {\n name: buildIndexName({\n name: `${textsTableName}_locale_parent`,\n adapter,\n appendSuffix: false,\n }),\n on: ['locale', 'parent'],\n }\n }\n\n textsTable = {\n name: textsTableName,\n columns,\n foreignKeys: {\n parentFk: {\n name: buildForeignKeyName({ name: `${textsTableName}_parent`, adapter }),\n columns: ['parent'],\n foreignColumns: [\n {\n name: 'id',\n table: tableName,\n },\n ],\n onDelete: 'cascade',\n },\n },\n indexes: textsTableIndexes,\n }\n\n adapter.rawTables[textsTableName] = textsTable\n\n adapter.rawRelations[textsTableName] = {\n parent: {\n type: 'one',\n fields: [\n {\n name: 'parent',\n table: textsTableName,\n },\n ],\n references: ['id'],\n relationName: '_texts',\n to: tableName,\n },\n }\n }\n\n if (hasManyNumberField) {\n const numbersTableName = `${rootTableName}_numbers`\n adapter.rawTables[numbersTableName] = numbersTable\n const columns: Record<string, RawColumn> = {\n id: {\n name: 'id',\n type: 'serial',\n primaryKey: true,\n },\n number: {\n name: 'number',\n type: 'numeric',\n },\n order: {\n name: 'order',\n type: 'integer',\n notNull: true,\n },\n parent: {\n name: 'parent_id',\n type: idColType,\n notNull: true,\n },\n path: {\n name: 'path',\n type: 'varchar',\n notNull: true,\n },\n }\n\n if (hasLocalizedManyNumberField) {\n columns.locale = {\n name: 'locale',\n type: 'enum',\n locale: true,\n }\n }\n\n const numbersTableIndexes: Record<string, RawIndex> = {\n orderParentIdx: {\n name: buildIndexName({ name: `${numbersTableName}_order_parent`, adapter }),\n on: ['order', 'parent'],\n },\n }\n\n if (hasManyNumberField === 'index') {\n numbersTableIndexes.numberIdx = {\n name: buildIndexName({ name: `${numbersTableName}_number`, adapter }),\n on: 'number',\n }\n }\n\n if (hasLocalizedManyNumberField) {\n numbersTableIndexes.localeParent = {\n name: buildIndexName({\n name: `${numbersTableName}_locale_parent`,\n adapter,\n appendSuffix: false,\n }),\n on: ['locale', 'parent'],\n }\n }\n\n numbersTable = {\n name: numbersTableName,\n columns,\n foreignKeys: {\n parentFk: {\n name: buildForeignKeyName({ name: `${numbersTableName}_parent`, adapter }),\n columns: ['parent'],\n foreignColumns: [\n {\n name: 'id',\n table: tableName,\n },\n ],\n onDelete: 'cascade',\n },\n },\n indexes: numbersTableIndexes,\n }\n\n adapter.rawTables[numbersTableName] = numbersTable\n\n adapter.rawRelations[numbersTableName] = {\n parent: {\n type: 'one',\n fields: [\n {\n name: 'parent',\n table: numbersTableName,\n },\n ],\n references: ['id'],\n relationName: '_numbers',\n to: tableName,\n },\n }\n }\n\n if (relationships.size) {\n const relationshipColumns: Record<string, RawColumn> = {\n id: {\n name: 'id',\n type: 'serial',\n primaryKey: true,\n },\n order: {\n name: 'order',\n type: 'integer',\n },\n parent: {\n name: 'parent_id',\n type: idColType,\n notNull: true,\n },\n path: {\n name: 'path',\n type: 'varchar',\n notNull: true,\n },\n }\n\n if (hasLocalizedRelationshipField) {\n relationshipColumns.locale = {\n name: 'locale',\n type: 'enum',\n locale: true,\n }\n }\n\n const relationshipsTableName = `${tableName}${adapter.relationshipsSuffix}`\n\n const relationshipIndexes: Record<string, RawIndex> = {\n order: {\n name: buildIndexName({ name: `${relationshipsTableName}_order`, adapter }),\n on: 'order',\n },\n parentIdx: {\n name: buildIndexName({ name: `${relationshipsTableName}_parent`, adapter }),\n on: 'parent',\n },\n pathIdx: {\n name: buildIndexName({ name: `${relationshipsTableName}_path`, adapter }),\n on: 'path',\n },\n }\n\n if (hasLocalizedRelationshipField) {\n relationshipIndexes.localeIdx = {\n name: buildIndexName({ name: `${relationshipsTableName}_locale`, adapter }),\n on: 'locale',\n }\n }\n\n const relationshipForeignKeys: Record<string, RawForeignKey> = {\n parentFk: {\n name: buildForeignKeyName({ name: `${relationshipsTableName}_parent`, adapter }),\n columns: ['parent'],\n foreignColumns: [\n {\n name: 'id',\n table: tableName,\n },\n ],\n onDelete: 'cascade',\n },\n }\n\n relationships.forEach((relationTo) => {\n const relationshipConfig = adapter.payload.collections[relationTo].config\n const formattedRelationTo = createTableName({\n adapter,\n config: relationshipConfig,\n throwValidationError: true,\n })\n let colType: 'integer' | 'numeric' | 'uuid' | 'varchar' = isUUIDType(adapter.idType)\n ? 'uuid'\n : 'integer'\n const relatedCollectionCustomIDType =\n adapter.payload.collections[relationshipConfig.slug]?.customIDType\n\n if (relatedCollectionCustomIDType === 'number') {\n colType = 'numeric'\n }\n if (relatedCollectionCustomIDType === 'text') {\n colType = 'varchar'\n }\n\n const colName = `${relationTo}ID`\n\n relationshipColumns[colName] = {\n name: `${formattedRelationTo}_id`,\n type: colType,\n }\n\n relationshipForeignKeys[`${relationTo}IdFk`] = {\n name: buildForeignKeyName({\n name: `${relationshipsTableName}_${toSnakeCase(relationTo)}`,\n adapter,\n }),\n columns: [colName],\n foreignColumns: [\n {\n name: 'id',\n table: formattedRelationTo,\n },\n ],\n onDelete: 'cascade',\n }\n\n const indexColumns = [colName]\n\n const unique = !disableUnique && uniqueRelationships.has(relationTo)\n\n if (unique) {\n indexColumns.push('path')\n }\n if (hasLocalizedRelationshipField) {\n indexColumns.push('locale')\n }\n\n const indexName = buildIndexName({\n name: `${relationshipsTableName}_${formattedRelationTo}_id`,\n adapter,\n })\n\n relationshipIndexes[indexName] = {\n name: indexName,\n on: indexColumns,\n unique,\n }\n })\n\n relationshipsTable = {\n name: relationshipsTableName,\n columns: relationshipColumns,\n foreignKeys: relationshipForeignKeys,\n indexes: relationshipIndexes,\n }\n\n adapter.rawTables[relationshipsTableName] = relationshipsTable\n\n const relationshipsTableRelations: Record<string, RawRelation> = {\n parent: {\n type: 'one',\n fields: [\n {\n name: 'parent',\n table: relationshipsTableName,\n },\n ],\n references: ['id'],\n relationName: '_rels',\n to: tableName,\n },\n }\n\n relationships.forEach((relationTo) => {\n const relatedTableName = createTableName({\n adapter,\n config: adapter.payload.collections[relationTo].config,\n throwValidationError: true,\n })\n const idColumnName = `${relationTo}ID`\n\n relationshipsTableRelations[idColumnName] = {\n type: 'one',\n fields: [\n {\n name: idColumnName,\n table: relationshipsTableName,\n },\n ],\n references: ['id'],\n relationName: relationTo,\n to: relatedTableName,\n }\n })\n adapter.rawRelations[relationshipsTableName] = relationshipsTableRelations\n }\n }\n\n const tableRelations: Record<string, RawRelation> = {}\n\n nonLocalizedRelations.forEach(({ type, relationName, target }, key) => {\n if (type === 'one') {\n tableRelations[key] = {\n type: 'one',\n fields: [\n {\n name: key,\n table: tableName,\n },\n ],\n references: ['id'],\n relationName: key,\n to: target,\n }\n }\n if (type === 'many') {\n tableRelations[key] = {\n type: 'many',\n relationName: relationName || key,\n to: target,\n }\n }\n })\n\n if (hasLocalizedField) {\n tableRelations._locales = {\n type: 'many',\n relationName: '_locales',\n to: localesTable.name,\n }\n }\n\n if (isRoot && textsTable) {\n tableRelations._texts = {\n type: 'many',\n relationName: '_texts',\n to: textsTable.name,\n }\n }\n\n if (isRoot && numbersTable) {\n tableRelations._numbers = {\n type: 'many',\n relationName: '_numbers',\n to: numbersTable.name,\n }\n }\n\n if (relationships.size && relationshipsTable) {\n tableRelations._rels = {\n type: 'many',\n relationName: '_rels',\n to: relationshipsTable.name,\n }\n }\n\n adapter.rawRelations[tableName] = tableRelations\n\n return {\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n relationsToBuild,\n }\n}\n\n/**\n * Single-relation relationship/upload columns use Drizzle's inline `.references()`, which names\n * the foreign key `<table>_<column>_<target>_<targetColumn>_fk` with no way to override it.\n * When that name exceeds the Postgres identifier limit, Postgres stores a truncated name, so push\n * never matches it and drops and re-adds the foreign key on every run, which can fail with\n * \"already exists\". Those foreign keys are moved to explicitly named table-level foreign keys\n * instead. Names that fit, and every foreign key on non-Postgres adapters, keep `.references()`.\n */\nconst promoteLongInlineForeignKeys = ({\n adapter,\n table,\n}: {\n adapter: DrizzleAdapter\n table: RawTable\n}): RawTable => {\n for (const [columnKey, column] of Object.entries(table.columns)) {\n if (!column.reference) {\n continue\n }\n\n const { name: targetColumnName, onDelete, table: targetTableName } = column.reference\n const drizzleForeignKeyName = `${table.name}_${column.name}_${targetTableName}_${targetColumnName}`\n\n if (!exceedsIdentifierLength({ adapter, identifier: `${drizzleForeignKeyName}_fk` })) {\n continue\n }\n\n table.foreignKeys ??= {}\n table.foreignKeys[`${columnKey}Fk`] = {\n name: fitIdentifierLength({ name: drizzleForeignKeyName, adapter, suffix: '_fk' }),\n columns: [columnKey],\n foreignColumns: [{ name: targetColumnName, table: targetTableName }],\n onDelete,\n }\n\n delete column.reference\n }\n\n return table\n}\n"],"names":["InvalidConfiguration","toSnakeCase","createTableName","buildForeignKeyName","buildIndexName","exceedsIdentifierLength","fitIdentifierLength","isUUIDType","traverseFields","buildTable","adapter","baseColumns","baseForeignKeys","baseIndexes","blocksTableNameMap","compoundIndexes","disableNotNull","disableRelsTableUnique","disableUnique","fields","parentIsLocalized","rootRelationships","rootRelationsToBuild","rootTableIDColType","rootTableName","incomingRootTableName","rootUniqueRelationships","setColumnID","tableName","timestamps","versions","withinLocalizedArrayOrBlock","isRoot","columns","indexes","localesColumns","localesIndexes","localesTable","textsTable","numbersTable","relationships","Set","uniqueRelationships","relationshipsTable","relationsToBuild","Map","idColType","hasLocalizedField","hasLocalizedManyNumberField","hasLocalizedManyTextField","hasLocalizedRelationshipField","hasManyNumberField","hasManyTextField","newTableName","parentTableName","localizedRelations","nonLocalizedRelations","forEach","type","localized","relationName","target","key","map","set","createdAt","name","defaultNow","mode","notNull","precision","withTimezone","updatedAt","table","foreignKeys","rawTables","promoteLongInlineForeignKeys","size","localeTableName","localesSuffix","id","primaryKey","_locale","locale","_parentID","_localeParent","appendSuffix","on","unique","_parentIdFk","foreignColumns","onDelete","localeRelations","references","to","rawRelations","index","someLocalized","getTableToUse","path","pathHasLocalized","columnPath","replaceAll","push","join","length","indexName","textsTableName","order","parent","text","textsTableIndexes","orderParentIdx","text_idx","localeParent","parentFk","numbersTableName","number","numbersTableIndexes","numberIdx","relationshipColumns","relationshipsTableName","relationshipsSuffix","relationshipIndexes","parentIdx","pathIdx","localeIdx","relationshipForeignKeys","relationTo","relationshipConfig","payload","collections","config","formattedRelationTo","throwValidationError","colType","idType","relatedCollectionCustomIDType","slug","customIDType","colName","indexColumns","has","relationshipsTableRelations","relatedTableName","idColumnName","tableRelations","_locales","_texts","_numbers","_rels","columnKey","column","Object","entries","reference","targetColumnName","targetTableName","drizzleForeignKeyName","identifier","suffix"],"mappings":"AAEA,SAASA,oBAAoB,QAAQ,UAAS;AAC9C,OAAOC,iBAAiB,gBAAe;AAcvC,SAASC,eAAe,QAAQ,wBAAuB;AACv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src/schema/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAW7C,OAAO,KAAK,EACV,cAAc,EACd,MAAM,EACN,SAAS,EAET,QAAQ,EAER,WAAW,EACX,WAAW,EACZ,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../src/schema/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAW7C,OAAO,KAAK,EACV,cAAc,EACd,MAAM,EACN,SAAS,EAET,QAAQ,EAER,WAAW,EACX,WAAW,EACZ,MAAM,aAAa,CAAA;AAiBpB,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC1C,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IAClC,cAAc,EAAE,OAAO,CAAA;IACvB,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IACjC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IACzC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IACxC,YAAY,EAAE,MAAM,CAAA;IACpB,iBAAiB,EAAE,OAAO,CAAA;IAC1B,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC1B,gBAAgB,EAAE,WAAW,CAAA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