@payloadcms/drizzle 3.0.0-canary.6d066c2 → 3.0.0-canary.71da5b9
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/count.d.ts.map +1 -1
- package/dist/count.js +2 -2
- package/dist/count.js.map +1 -1
- package/dist/create.js +1 -1
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.js +1 -1
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +7 -3
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createTableName.d.ts.map +1 -1
- package/dist/createTableName.js +6 -2
- package/dist/createTableName.js.map +1 -1
- package/dist/createVersion.d.ts +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +22 -15
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.js +1 -1
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +6 -4
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.js +2 -2
- package/dist/deleteVersions.js.map +1 -1
- package/dist/destroy.d.ts.map +1 -1
- package/dist/destroy.js +3 -1
- package/dist/destroy.js.map +1 -1
- package/dist/exports/postgres.d.ts +15 -0
- package/dist/exports/postgres.d.ts.map +1 -0
- package/dist/exports/postgres.js +16 -0
- package/dist/exports/postgres.js.map +1 -0
- package/dist/find/buildFindManyArgs.d.ts +13 -7
- package/dist/find/buildFindManyArgs.d.ts.map +1 -1
- package/dist/find/buildFindManyArgs.js +7 -1
- package/dist/find/buildFindManyArgs.js.map +1 -1
- package/dist/find/findMany.d.ts +1 -1
- package/dist/find/findMany.d.ts.map +1 -1
- package/dist/find/findMany.js +6 -3
- package/dist/find/findMany.js.map +1 -1
- package/dist/find/traverseFields.d.ts +7 -3
- package/dist/find/traverseFields.d.ts.map +1 -1
- package/dist/find/traverseFields.js +147 -16
- package/dist/find/traverseFields.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +2 -1
- package/dist/find.js.map +1 -1
- package/dist/findGlobalVersions.js +1 -1
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findMigrationDir.d.ts.map +1 -1
- package/dist/findMigrationDir.js +3 -1
- package/dist/findMigrationDir.js.map +1 -1
- package/dist/findOne.d.ts +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +2 -1
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.js +1 -1
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/migrate.d.ts +1 -1
- package/dist/migrate.d.ts.map +1 -1
- package/dist/migrate.js +5 -10
- package/dist/migrate.js.map +1 -1
- package/dist/migrateDown.d.ts.map +1 -1
- package/dist/migrateDown.js +1 -1
- package/dist/migrateDown.js.map +1 -1
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +1 -0
- package/dist/migrateFresh.js.map +1 -1
- package/dist/migrateRefresh.d.ts.map +1 -1
- package/dist/migrateRefresh.js +2 -1
- package/dist/migrateRefresh.js.map +1 -1
- package/dist/migrateReset.d.ts.map +1 -1
- package/dist/migrateReset.js +4 -2
- package/dist/migrateReset.js.map +1 -1
- package/dist/migrateStatus.js +0 -1
- package/dist/migrateStatus.js.map +1 -1
- package/dist/postgres/countDistinct.d.ts +3 -0
- package/dist/postgres/countDistinct.d.ts.map +1 -0
- package/dist/postgres/countDistinct.js +24 -0
- package/dist/postgres/countDistinct.js.map +1 -0
- package/dist/postgres/createDatabase.d.ts +14 -0
- package/dist/postgres/createDatabase.d.ts.map +1 -0
- package/dist/postgres/createDatabase.js +73 -0
- package/dist/postgres/createDatabase.js.map +1 -0
- package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.d.ts +2 -0
- package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.d.ts.map +1 -0
- package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.js +16 -0
- package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.js.map +1 -0
- package/dist/postgres/createJSONQuery/formatJSONPathSegment.d.ts +2 -0
- package/dist/postgres/createJSONQuery/formatJSONPathSegment.d.ts.map +1 -0
- package/dist/postgres/createJSONQuery/formatJSONPathSegment.js +5 -0
- package/dist/postgres/createJSONQuery/formatJSONPathSegment.js.map +1 -0
- package/dist/postgres/createJSONQuery/index.d.ts +10 -0
- package/dist/postgres/createJSONQuery/index.d.ts.map +1 -0
- package/dist/postgres/createJSONQuery/index.js +54 -0
- package/dist/postgres/createJSONQuery/index.js.map +1 -0
- package/dist/postgres/createMigration.d.ts +3 -0
- package/dist/postgres/createMigration.d.ts.map +1 -0
- package/dist/postgres/createMigration.js +92 -0
- package/dist/postgres/createMigration.js.map +1 -0
- package/dist/postgres/defaultSnapshot.d.ts +3 -0
- package/dist/postgres/defaultSnapshot.d.ts.map +1 -0
- package/dist/postgres/defaultSnapshot.js +17 -0
- package/dist/postgres/defaultSnapshot.js.map +1 -0
- package/dist/postgres/deleteWhere.d.ts +3 -0
- package/dist/postgres/deleteWhere.d.ts.map +1 -0
- package/dist/postgres/deleteWhere.js +6 -0
- package/dist/postgres/deleteWhere.js.map +1 -0
- package/dist/postgres/dropDatabase.d.ts +3 -0
- package/dist/postgres/dropDatabase.d.ts.map +1 -0
- package/dist/postgres/dropDatabase.js +9 -0
- package/dist/postgres/dropDatabase.js.map +1 -0
- package/dist/postgres/execute.d.ts +3 -0
- package/dist/postgres/execute.d.ts.map +1 -0
- package/dist/postgres/execute.js +11 -0
- package/dist/postgres/execute.js.map +1 -0
- package/dist/postgres/getMigrationTemplate.d.ts +4 -0
- package/dist/postgres/getMigrationTemplate.d.ts.map +1 -0
- package/dist/postgres/getMigrationTemplate.js +13 -0
- package/dist/postgres/getMigrationTemplate.js.map +1 -0
- package/dist/postgres/init.d.ts +3 -0
- package/dist/postgres/init.d.ts.map +1 -0
- package/dist/postgres/init.js +105 -0
- package/dist/postgres/init.js.map +1 -0
- package/dist/postgres/insert.d.ts +3 -0
- package/dist/postgres/insert.d.ts.map +1 -0
- package/dist/postgres/insert.js +12 -0
- package/dist/postgres/insert.js.map +1 -0
- package/dist/postgres/requireDrizzleKit.d.ts +3 -0
- package/dist/postgres/requireDrizzleKit.d.ts.map +1 -0
- package/dist/postgres/requireDrizzleKit.js +5 -0
- package/dist/postgres/requireDrizzleKit.js.map +1 -0
- package/dist/postgres/schema/build.d.ts +43 -0
- package/dist/postgres/schema/build.d.ts.map +1 -0
- package/dist/postgres/schema/build.js +401 -0
- package/dist/postgres/schema/build.js.map +1 -0
- package/dist/postgres/schema/createIndex.d.ts +12 -0
- package/dist/postgres/schema/createIndex.d.ts.map +1 -0
- package/dist/postgres/schema/createIndex.js +20 -0
- package/dist/postgres/schema/createIndex.js.map +1 -0
- package/dist/postgres/schema/idToUUID.d.ts +3 -0
- package/dist/postgres/schema/idToUUID.d.ts.map +1 -0
- package/dist/postgres/schema/idToUUID.js +11 -0
- package/dist/postgres/schema/idToUUID.js.map +1 -0
- package/dist/postgres/schema/parentIDColumnMap.d.ts +4 -0
- package/dist/postgres/schema/parentIDColumnMap.d.ts.map +1 -0
- package/dist/postgres/schema/parentIDColumnMap.js +9 -0
- package/dist/postgres/schema/parentIDColumnMap.js.map +1 -0
- package/dist/postgres/schema/setColumnID.d.ts +11 -0
- package/dist/postgres/schema/setColumnID.d.ts.map +1 -0
- package/dist/postgres/schema/setColumnID.js +24 -0
- package/dist/postgres/schema/setColumnID.js.map +1 -0
- package/dist/postgres/schema/traverseFields.d.ts +43 -0
- package/dist/postgres/schema/traverseFields.d.ts.map +1 -0
- package/dist/postgres/schema/traverseFields.js +761 -0
- package/dist/postgres/schema/traverseFields.js.map +1 -0
- package/dist/postgres/schema/withDefault.d.ts +4 -0
- package/dist/postgres/schema/withDefault.d.ts.map +1 -0
- package/dist/postgres/schema/withDefault.js +12 -0
- package/dist/postgres/schema/withDefault.js.map +1 -0
- package/dist/postgres/types.d.ts +139 -0
- package/dist/postgres/types.d.ts.map +1 -0
- package/dist/postgres/types.js +3 -0
- package/dist/postgres/types.js.map +1 -0
- package/dist/queries/buildAndOrConditions.d.ts +1 -1
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +2 -4
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildOrderBy.d.ts +18 -0
- package/dist/queries/buildOrderBy.d.ts.map +1 -0
- package/dist/queries/buildOrderBy.js +52 -0
- package/dist/queries/buildOrderBy.js.map +1 -0
- package/dist/queries/buildQuery.d.ts +5 -4
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +12 -47
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/getTableColumnFromPath.d.ts +8 -3
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
- package/dist/queries/getTableColumnFromPath.js +73 -23
- package/dist/queries/getTableColumnFromPath.js.map +1 -1
- package/dist/queries/operatorMap.d.ts.map +1 -1
- package/dist/queries/operatorMap.js.map +1 -1
- package/dist/queries/parseParams.d.ts +1 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +52 -6
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts +12 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +77 -21
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queries/selectDistinct.d.ts +3 -4
- package/dist/queries/selectDistinct.d.ts.map +1 -1
- package/dist/queries/selectDistinct.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +2 -5
- package/dist/queryDrafts.js.map +1 -1
- package/dist/transactions/beginTransaction.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.js +7 -3
- package/dist/transactions/beginTransaction.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +3 -1
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/transform/read/hasManyNumber.d.ts +2 -1
- package/dist/transform/read/hasManyNumber.d.ts.map +1 -1
- package/dist/transform/read/hasManyNumber.js +12 -2
- package/dist/transform/read/hasManyNumber.js.map +1 -1
- package/dist/transform/read/hasManyText.d.ts +2 -1
- package/dist/transform/read/hasManyText.d.ts.map +1 -1
- package/dist/transform/read/hasManyText.js +12 -2
- package/dist/transform/read/hasManyText.js.map +1 -1
- package/dist/transform/read/index.d.ts +3 -2
- package/dist/transform/read/index.d.ts.map +1 -1
- package/dist/transform/read/index.js +3 -2
- package/dist/transform/read/index.js.map +1 -1
- package/dist/transform/read/relationship.d.ts +2 -1
- package/dist/transform/read/relationship.d.ts.map +1 -1
- package/dist/transform/read/relationship.js +15 -6
- package/dist/transform/read/relationship.js.map +1 -1
- package/dist/transform/read/traverseFields.d.ts +10 -2
- package/dist/transform/read/traverseFields.d.ts.map +1 -1
- package/dist/transform/read/traverseFields.js +170 -56
- package/dist/transform/read/traverseFields.js.map +1 -1
- package/dist/transform/write/array.d.ts +6 -1
- package/dist/transform/write/array.d.ts.map +1 -1
- package/dist/transform/write/array.js +7 -3
- package/dist/transform/write/array.js.map +1 -1
- package/dist/transform/write/blocks.d.ts +8 -3
- package/dist/transform/write/blocks.d.ts.map +1 -1
- package/dist/transform/write/blocks.js +19 -7
- 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 +1 -1
- package/dist/transform/write/index.js.map +1 -1
- package/dist/transform/write/relationships.d.ts.map +1 -1
- package/dist/transform/write/relationships.js +6 -2
- package/dist/transform/write/relationships.js.map +1 -1
- package/dist/transform/write/selects.d.ts.map +1 -1
- package/dist/transform/write/selects.js +1 -1
- package/dist/transform/write/selects.js.map +1 -1
- package/dist/transform/write/traverseFields.d.ts +6 -1
- package/dist/transform/write/traverseFields.d.ts.map +1 -1
- package/dist/transform/write/traverseFields.js +46 -17
- package/dist/transform/write/traverseFields.js.map +1 -1
- package/dist/types.d.ts +4 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/update.d.ts.map +1 -1
- package/dist/update.js +4 -3
- package/dist/update.js.map +1 -1
- package/dist/updateGlobal.js +1 -1
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.js +3 -3
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateVersion.js +3 -3
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +1 -1
- package/dist/upsertRow/deleteExistingRowsByPath.js +6 -2
- 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 +50 -12
- package/dist/upsertRow/index.js.map +1 -1
- package/dist/upsertRow/insertArrays.d.ts.map +1 -1
- package/dist/upsertRow/insertArrays.js +5 -2
- package/dist/upsertRow/insertArrays.js.map +1 -1
- package/dist/upsertRow/types.d.ts +8 -5
- package/dist/upsertRow/types.d.ts.map +1 -1
- package/dist/upsertRow/types.js.map +1 -1
- package/dist/utilities/createBlocksMap.d.ts.map +1 -1
- package/dist/utilities/createBlocksMap.js +4 -2
- package/dist/utilities/createBlocksMap.js.map +1 -1
- package/dist/utilities/createRelationshipMap.d.ts.map +1 -1
- package/dist/utilities/createRelationshipMap.js +3 -1
- package/dist/utilities/createRelationshipMap.js.map +1 -1
- package/dist/utilities/executeSchemaHooks.d.ts +24 -0
- package/dist/utilities/executeSchemaHooks.d.ts.map +1 -0
- package/dist/utilities/executeSchemaHooks.js +21 -0
- package/dist/utilities/executeSchemaHooks.js.map +1 -0
- package/dist/utilities/extendDrizzleTable.d.ts +19 -0
- package/dist/utilities/extendDrizzleTable.d.ts.map +1 -0
- package/dist/utilities/extendDrizzleTable.js +38 -0
- package/dist/utilities/extendDrizzleTable.js.map +1 -0
- package/dist/utilities/getCollectionIdType.d.ts +7 -0
- package/dist/utilities/getCollectionIdType.d.ts.map +1 -0
- package/dist/utilities/getCollectionIdType.js +11 -0
- package/dist/utilities/getCollectionIdType.js.map +1 -0
- package/dist/utilities/hasLocalesTable.d.ts.map +1 -1
- package/dist/utilities/hasLocalesTable.js +13 -3
- package/dist/utilities/hasLocalesTable.js.map +1 -1
- package/dist/utilities/isPolymorphicRelationship.d.ts +6 -0
- package/dist/utilities/isPolymorphicRelationship.d.ts.map +1 -0
- package/dist/utilities/isPolymorphicRelationship.js +5 -0
- package/dist/utilities/isPolymorphicRelationship.js.map +1 -0
- package/dist/utilities/migrationTableExists.js +1 -1
- package/dist/utilities/migrationTableExists.js.map +1 -1
- package/dist/utilities/pushDevSchema.d.ts.map +1 -1
- package/dist/utilities/pushDevSchema.js +3 -1
- package/dist/utilities/pushDevSchema.js.map +1 -1
- package/package.json +17 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/postgres/schema/traverseFields.ts"],"sourcesContent":["import type { Relation } from 'drizzle-orm'\nimport type { IndexBuilder, PgColumnBuilder } from 'drizzle-orm/pg-core'\nimport type { Field, SanitizedJoins, TabAsField } from 'payload'\n\nimport { relations } from 'drizzle-orm'\nimport {\n boolean,\n foreignKey,\n index,\n integer,\n jsonb,\n numeric,\n PgNumericBuilder,\n PgUUIDBuilder,\n PgVarcharBuilder,\n text,\n timestamp,\n varchar,\n} from 'drizzle-orm/pg-core'\nimport { InvalidConfiguration } from 'payload'\nimport { fieldAffectsData, fieldIsVirtual, optionIsObject } from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\n\nimport type {\n BaseExtraConfig,\n BasePostgresAdapter,\n GenericColumns,\n IDType,\n RelationMap,\n} from '../types.js'\n\nimport { createTableName } from '../../createTableName.js'\nimport { hasLocalesTable } from '../../utilities/hasLocalesTable.js'\nimport { validateExistingBlockIsIdentical } from '../../utilities/validateExistingBlockIsIdentical.js'\nimport { buildTable } from './build.js'\nimport { createIndex } from './createIndex.js'\nimport { idToUUID } from './idToUUID.js'\nimport { parentIDColumnMap } from './parentIDColumnMap.js'\nimport { withDefault } from './withDefault.js'\n\ntype Args = {\n adapter: BasePostgresAdapter\n columnPrefix?: string\n columns: Record<string, PgColumnBuilder>\n disableNotNull: boolean\n disableRelsTableUnique?: boolean\n disableUnique?: boolean\n fieldPrefix?: string\n fields: (Field | TabAsField)[]\n forceLocalized?: boolean\n indexes: Record<string, (cols: GenericColumns) => IndexBuilder>\n joins?: SanitizedJoins\n localesColumns: Record<string, PgColumnBuilder>\n localesIndexes: Record<string, (cols: GenericColumns) => IndexBuilder>\n newTableName: string\n parentTableName: string\n relationships: Set<string>\n relationsToBuild: RelationMap\n rootRelationsToBuild?: RelationMap\n rootTableIDColType: string\n rootTableName: string\n uniqueRelationships: Set<string>\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 hasLocalizedField: boolean\n hasLocalizedManyNumberField: boolean\n hasLocalizedManyTextField: boolean\n hasLocalizedRelationshipField: boolean\n hasManyNumberField: 'index' | boolean\n hasManyTextField: 'index' | boolean\n}\n\nexport const traverseFields = ({\n adapter,\n columnPrefix,\n columns,\n disableNotNull,\n disableRelsTableUnique,\n disableUnique = false,\n fieldPrefix,\n fields,\n forceLocalized,\n indexes,\n joins,\n localesColumns,\n localesIndexes,\n newTableName,\n parentTableName,\n relationships,\n relationsToBuild,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n uniqueRelationships,\n versions,\n withinLocalizedArrayOrBlock,\n}: Args): Result => {\n const throwValidationError = true\n let hasLocalizedField = false\n let hasLocalizedRelationshipField = false\n let hasManyTextField: 'index' | boolean = false\n let hasLocalizedManyTextField = false\n let hasManyNumberField: 'index' | boolean = false\n let hasLocalizedManyNumberField = false\n\n let parentIDColType: IDType = 'integer'\n if (columns.id instanceof PgUUIDBuilder) {\n parentIDColType = 'uuid'\n }\n if (columns.id instanceof PgNumericBuilder) {\n parentIDColType = 'numeric'\n }\n if (columns.id instanceof PgVarcharBuilder) {\n parentIDColType = 'varchar'\n }\n\n fields.forEach((field) => {\n if ('name' in field && field.name === 'id') {\n return\n }\n if (fieldIsVirtual(field)) {\n return\n }\n\n let columnName: string\n let fieldName: string\n\n let targetTable = columns\n let targetIndexes = indexes\n\n if (fieldAffectsData(field)) {\n columnName = `${columnPrefix || ''}${field.name[0] === '_' ? '_' : ''}${toSnakeCase(\n field.name,\n )}`\n fieldName = `${fieldPrefix?.replace('.', '_') || ''}${field.name}`\n\n // If field is localized,\n // add the column to the locale table instead of main table\n if (\n adapter.payload.config.localization &&\n (field.localized || forceLocalized) &&\n field.type !== 'array' &&\n field.type !== 'blocks' &&\n (('hasMany' in field && field.hasMany !== true) || !('hasMany' in field))\n ) {\n hasLocalizedField = true\n targetTable = localesColumns\n targetIndexes = localesIndexes\n }\n\n if (\n (field.unique || field.index || ['relationship', 'upload'].includes(field.type)) &&\n !['array', 'blocks', 'group', 'point'].includes(field.type) &&\n !('hasMany' in field && field.hasMany === true) &&\n !('relationTo' in field && Array.isArray(field.relationTo))\n ) {\n const unique = disableUnique !== true && field.unique\n if (unique) {\n const constraintValue = `${fieldPrefix || ''}${field.name}`\n if (!adapter.fieldConstraints?.[rootTableName]) {\n adapter.fieldConstraints[rootTableName] = {}\n }\n adapter.fieldConstraints[rootTableName][`${columnName}_idx`] = constraintValue\n }\n targetIndexes[`${newTableName}_${field.name}Idx`] = createIndex({\n name: field.localized ? [fieldName, '_locale'] : fieldName,\n columnName,\n tableName: newTableName,\n unique,\n })\n }\n }\n\n switch (field.type) {\n case 'text': {\n if (field.hasMany) {\n const isLocalized =\n Boolean(field.localized && adapter.payload.config.localization) ||\n withinLocalizedArrayOrBlock ||\n forceLocalized\n\n if (isLocalized) {\n hasLocalizedManyTextField = true\n }\n\n if (field.index) {\n hasManyTextField = 'index'\n } else if (!hasManyTextField) {\n hasManyTextField = true\n }\n\n if (field.unique) {\n throw new InvalidConfiguration(\n 'Unique is not supported in Postgres for hasMany text fields.',\n )\n }\n } else {\n targetTable[fieldName] = withDefault(varchar(columnName), field)\n }\n break\n }\n case 'email':\n case 'code':\n case 'textarea': {\n targetTable[fieldName] = withDefault(varchar(columnName), field)\n break\n }\n\n case 'number': {\n if (field.hasMany) {\n const isLocalized =\n Boolean(field.localized && adapter.payload.config.localization) ||\n withinLocalizedArrayOrBlock ||\n forceLocalized\n\n if (isLocalized) {\n hasLocalizedManyNumberField = true\n }\n\n if (field.index) {\n hasManyNumberField = 'index'\n } else if (!hasManyNumberField) {\n hasManyNumberField = true\n }\n\n if (field.unique) {\n throw new InvalidConfiguration(\n 'Unique is not supported in Postgres for hasMany number fields.',\n )\n }\n } else {\n targetTable[fieldName] = withDefault(numeric(columnName), field)\n }\n break\n }\n\n case 'richText':\n case 'json': {\n targetTable[fieldName] = withDefault(jsonb(columnName), field)\n break\n }\n\n case 'date': {\n targetTable[fieldName] = withDefault(\n timestamp(columnName, {\n mode: 'string',\n precision: 3,\n withTimezone: true,\n }),\n field,\n )\n break\n }\n\n case 'point': {\n break\n }\n\n case 'radio':\n case 'select': {\n const enumName = createTableName({\n adapter,\n config: field,\n parentTableName: newTableName,\n prefix: `enum_${newTableName}_`,\n target: 'enumName',\n throwValidationError,\n })\n\n adapter.enums[enumName] = adapter.pgSchema.enum(\n enumName,\n field.options.map((option) => {\n if (optionIsObject(option)) {\n return option.value\n }\n\n return option\n }) as [string, ...string[]],\n )\n\n if (field.type === 'select' && field.hasMany) {\n const selectTableName = createTableName({\n adapter,\n config: field,\n parentTableName: newTableName,\n prefix: `${newTableName}_`,\n throwValidationError,\n versionsCustomName: versions,\n })\n const baseColumns: Record<string, PgColumnBuilder> = {\n order: integer('order').notNull(),\n parent: parentIDColumnMap[parentIDColType]('parent_id').notNull(),\n value: adapter.enums[enumName]('value'),\n }\n\n const baseExtraConfig: BaseExtraConfig = {\n orderIdx: (cols) => index(`${selectTableName}_order_idx`).on(cols.order),\n parentFk: (cols) =>\n foreignKey({\n name: `${selectTableName}_parent_fk`,\n columns: [cols.parent],\n foreignColumns: [adapter.tables[parentTableName].id],\n }).onDelete('cascade'),\n parentIdx: (cols) => index(`${selectTableName}_parent_idx`).on(cols.parent),\n }\n\n const isLocalized =\n Boolean(field.localized && adapter.payload.config.localization) ||\n withinLocalizedArrayOrBlock ||\n forceLocalized\n\n if (isLocalized) {\n baseColumns.locale = adapter.enums.enum__locales('locale').notNull()\n baseExtraConfig.localeIdx = (cols) =>\n index(`${selectTableName}_locale_idx`).on(cols.locale)\n }\n\n if (field.index) {\n baseExtraConfig.value = (cols) => index(`${selectTableName}_value_idx`).on(cols.value)\n }\n\n buildTable({\n adapter,\n baseColumns,\n baseExtraConfig,\n disableNotNull,\n disableUnique,\n fields: [],\n rootTableName,\n tableName: selectTableName,\n versions,\n })\n\n relationsToBuild.set(fieldName, {\n type: 'many',\n // selects have their own localized table, independent of the base table.\n localized: false,\n target: selectTableName,\n })\n\n adapter.relations[`relations_${selectTableName}`] = relations(\n adapter.tables[selectTableName],\n ({ one }) => ({\n parent: one(adapter.tables[parentTableName], {\n fields: [adapter.tables[selectTableName].parent],\n references: [adapter.tables[parentTableName].id],\n relationName: fieldName,\n }),\n }),\n )\n } else {\n targetTable[fieldName] = withDefault(adapter.enums[enumName](columnName), field)\n }\n break\n }\n\n case 'checkbox': {\n targetTable[fieldName] = withDefault(boolean(columnName), field)\n break\n }\n\n case 'array': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n const arrayTableName = createTableName({\n adapter,\n config: field,\n parentTableName: newTableName,\n prefix: `${newTableName}_`,\n throwValidationError,\n versionsCustomName: versions,\n })\n\n const baseColumns: Record<string, PgColumnBuilder> = {\n _order: integer('_order').notNull(),\n _parentID: parentIDColumnMap[parentIDColType]('_parent_id').notNull(),\n }\n\n const baseExtraConfig: BaseExtraConfig = {\n _orderIdx: (cols) => index(`${arrayTableName}_order_idx`).on(cols._order),\n _parentIDFk: (cols) =>\n foreignKey({\n name: `${arrayTableName}_parent_id_fk`,\n columns: [cols['_parentID']],\n foreignColumns: [adapter.tables[parentTableName].id],\n }).onDelete('cascade'),\n _parentIDIdx: (cols) => index(`${arrayTableName}_parent_id_idx`).on(cols._parentID),\n }\n\n const isLocalized =\n Boolean(field.localized && adapter.payload.config.localization) ||\n withinLocalizedArrayOrBlock ||\n forceLocalized\n\n if (isLocalized) {\n baseColumns._locale = adapter.enums.enum__locales('_locale').notNull()\n baseExtraConfig._localeIdx = (cols) =>\n index(`${arrayTableName}_locale_idx`).on(cols._locale)\n }\n\n const {\n hasLocalizedManyNumberField: subHasLocalizedManyNumberField,\n hasLocalizedManyTextField: subHasLocalizedManyTextField,\n hasLocalizedRelationshipField: subHasLocalizedRelationshipField,\n hasManyNumberField: subHasManyNumberField,\n hasManyTextField: subHasManyTextField,\n relationsToBuild: subRelationsToBuild,\n } = buildTable({\n adapter,\n baseColumns,\n baseExtraConfig,\n disableNotNull: disableNotNullFromHere,\n disableRelsTableUnique: true,\n disableUnique,\n fields: disableUnique ? idToUUID(field.fields) : field.fields,\n rootRelationships: relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n rootUniqueRelationships: uniqueRelationships,\n tableName: arrayTableName,\n versions,\n withinLocalizedArrayOrBlock: isLocalized,\n })\n\n if (subHasLocalizedManyNumberField) {\n hasLocalizedManyNumberField = subHasLocalizedManyNumberField\n }\n\n if (subHasLocalizedRelationshipField) {\n hasLocalizedRelationshipField = subHasLocalizedRelationshipField\n }\n\n if (subHasLocalizedManyTextField) {\n hasLocalizedManyTextField = subHasLocalizedManyTextField\n }\n\n if (subHasManyTextField) {\n if (!hasManyTextField || subHasManyTextField === 'index') {\n hasManyTextField = subHasManyTextField\n }\n }\n if (subHasManyNumberField) {\n if (!hasManyNumberField || subHasManyNumberField === 'index') {\n hasManyNumberField = subHasManyNumberField\n }\n }\n\n relationsToBuild.set(fieldName, {\n type: 'many',\n // arrays have their own localized table, independent of the base table.\n localized: false,\n target: arrayTableName,\n })\n\n adapter.relations[`relations_${arrayTableName}`] = relations(\n adapter.tables[arrayTableName],\n ({ many, one }) => {\n const result: Record<string, Relation<string>> = {\n _parentID: one(adapter.tables[parentTableName], {\n fields: [adapter.tables[arrayTableName]._parentID],\n references: [adapter.tables[parentTableName].id],\n relationName: fieldName,\n }),\n }\n\n if (hasLocalesTable(field.fields)) {\n result._locales = many(adapter.tables[`${arrayTableName}${adapter.localesSuffix}`], {\n relationName: '_locales',\n })\n }\n\n subRelationsToBuild.forEach(({ type, localized, target }, key) => {\n if (type === 'one') {\n const arrayWithLocalized = localized\n ? `${arrayTableName}${adapter.localesSuffix}`\n : arrayTableName\n result[key] = one(adapter.tables[target], {\n fields: [adapter.tables[arrayWithLocalized][key]],\n references: [adapter.tables[target].id],\n relationName: key,\n })\n }\n if (type === 'many') {\n result[key] = many(adapter.tables[target], { relationName: key })\n }\n })\n\n return result\n },\n )\n\n break\n }\n\n case 'blocks': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n field.blocks.forEach((block) => {\n const blockTableName = createTableName({\n adapter,\n config: block,\n parentTableName: rootTableName,\n prefix: `${rootTableName}_blocks_`,\n throwValidationError,\n versionsCustomName: versions,\n })\n if (!adapter.tables[blockTableName]) {\n const baseColumns: Record<string, PgColumnBuilder> = {\n _order: integer('_order').notNull(),\n _parentID: parentIDColumnMap[rootTableIDColType]('_parent_id').notNull(),\n _path: text('_path').notNull(),\n }\n\n const baseExtraConfig: BaseExtraConfig = {\n _orderIdx: (cols) => index(`${blockTableName}_order_idx`).on(cols._order),\n _parentIdFk: (cols) =>\n foreignKey({\n name: `${blockTableName}_parent_id_fk`,\n columns: [cols._parentID],\n foreignColumns: [adapter.tables[rootTableName].id],\n }).onDelete('cascade'),\n _parentIDIdx: (cols) => index(`${blockTableName}_parent_id_idx`).on(cols._parentID),\n _pathIdx: (cols) => index(`${blockTableName}_path_idx`).on(cols._path),\n }\n\n const isLocalized =\n Boolean(field.localized && adapter.payload.config.localization) ||\n withinLocalizedArrayOrBlock ||\n forceLocalized\n\n if (isLocalized) {\n baseColumns._locale = adapter.enums.enum__locales('_locale').notNull()\n baseExtraConfig._localeIdx = (cols) =>\n index(`${blockTableName}_locale_idx`).on(cols._locale)\n }\n\n const {\n hasLocalizedManyNumberField: subHasLocalizedManyNumberField,\n hasLocalizedManyTextField: subHasLocalizedManyTextField,\n hasLocalizedRelationshipField: subHasLocalizedRelationshipField,\n hasManyNumberField: subHasManyNumberField,\n hasManyTextField: subHasManyTextField,\n relationsToBuild: subRelationsToBuild,\n } = buildTable({\n adapter,\n baseColumns,\n baseExtraConfig,\n disableNotNull: disableNotNullFromHere,\n disableRelsTableUnique: true,\n disableUnique,\n fields: disableUnique ? idToUUID(block.fields) : block.fields,\n rootRelationships: relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n rootUniqueRelationships: uniqueRelationships,\n tableName: blockTableName,\n versions,\n withinLocalizedArrayOrBlock: isLocalized,\n })\n\n if (subHasLocalizedManyNumberField) {\n hasLocalizedManyNumberField = subHasLocalizedManyNumberField\n }\n\n if (subHasLocalizedRelationshipField) {\n hasLocalizedRelationshipField = subHasLocalizedRelationshipField\n }\n\n if (subHasLocalizedManyTextField) {\n hasLocalizedManyTextField = subHasLocalizedManyTextField\n }\n\n if (subHasManyTextField) {\n if (!hasManyTextField || subHasManyTextField === 'index') {\n hasManyTextField = subHasManyTextField\n }\n }\n\n if (subHasManyNumberField) {\n if (!hasManyNumberField || subHasManyNumberField === 'index') {\n hasManyNumberField = subHasManyNumberField\n }\n }\n\n adapter.relations[`relations_${blockTableName}`] = relations(\n adapter.tables[blockTableName],\n ({ many, one }) => {\n const result: Record<string, Relation<string>> = {\n _parentID: one(adapter.tables[rootTableName], {\n fields: [adapter.tables[blockTableName]._parentID],\n references: [adapter.tables[rootTableName].id],\n relationName: `_blocks_${block.slug}`,\n }),\n }\n\n if (hasLocalesTable(block.fields)) {\n result._locales = many(\n adapter.tables[`${blockTableName}${adapter.localesSuffix}`],\n { relationName: '_locales' },\n )\n }\n\n subRelationsToBuild.forEach(({ type, localized, target }, key) => {\n if (type === 'one') {\n const blockWithLocalized = localized\n ? `${blockTableName}${adapter.localesSuffix}`\n : blockTableName\n result[key] = one(adapter.tables[target], {\n fields: [adapter.tables[blockWithLocalized][key]],\n references: [adapter.tables[target].id],\n relationName: key,\n })\n }\n if (type === 'many') {\n result[key] = many(adapter.tables[target], { relationName: key })\n }\n })\n\n return result\n },\n )\n } else if (process.env.NODE_ENV !== 'production' && !versions) {\n validateExistingBlockIsIdentical({\n block,\n localized: field.localized,\n rootTableName,\n table: adapter.tables[blockTableName],\n tableLocales: adapter.tables[`${blockTableName}${adapter.localesSuffix}`],\n })\n }\n // blocks relationships are defined from the collection or globals table down to the block, bypassing any subBlocks\n rootRelationsToBuild.set(`_blocks_${block.slug}`, {\n type: 'many',\n // blocks are not localized on the parent table\n localized: false,\n target: blockTableName,\n })\n })\n\n break\n }\n\n case 'tab':\n case 'group': {\n if (!('name' in field)) {\n const {\n hasLocalizedField: groupHasLocalizedField,\n hasLocalizedManyNumberField: groupHasLocalizedManyNumberField,\n hasLocalizedManyTextField: groupHasLocalizedManyTextField,\n hasLocalizedRelationshipField: groupHasLocalizedRelationshipField,\n hasManyNumberField: groupHasManyNumberField,\n hasManyTextField: groupHasManyTextField,\n } = traverseFields({\n adapter,\n columnPrefix,\n columns,\n disableNotNull,\n disableUnique,\n fieldPrefix,\n fields: field.fields,\n forceLocalized,\n indexes,\n joins,\n localesColumns,\n localesIndexes,\n newTableName,\n parentTableName,\n relationships,\n relationsToBuild,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n uniqueRelationships,\n versions,\n withinLocalizedArrayOrBlock,\n })\n\n if (groupHasLocalizedField) {\n hasLocalizedField = true\n }\n if (groupHasLocalizedRelationshipField) {\n hasLocalizedRelationshipField = true\n }\n if (groupHasManyTextField) {\n hasManyTextField = true\n }\n if (groupHasLocalizedManyTextField) {\n hasLocalizedManyTextField = true\n }\n if (groupHasManyNumberField) {\n hasManyNumberField = true\n }\n if (groupHasLocalizedManyNumberField) {\n hasLocalizedManyNumberField = true\n }\n break\n }\n\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n const {\n hasLocalizedField: groupHasLocalizedField,\n hasLocalizedManyNumberField: groupHasLocalizedManyNumberField,\n hasLocalizedManyTextField: groupHasLocalizedManyTextField,\n hasLocalizedRelationshipField: groupHasLocalizedRelationshipField,\n hasManyNumberField: groupHasManyNumberField,\n hasManyTextField: groupHasManyTextField,\n } = traverseFields({\n adapter,\n columnPrefix: `${columnName}_`,\n columns,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fieldPrefix: `${fieldName}.`,\n fields: field.fields,\n forceLocalized: field.localized,\n indexes,\n joins,\n localesColumns,\n localesIndexes,\n newTableName: `${parentTableName}_${columnName}`,\n parentTableName,\n relationships,\n relationsToBuild,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n uniqueRelationships,\n versions,\n withinLocalizedArrayOrBlock: withinLocalizedArrayOrBlock || field.localized,\n })\n\n if (groupHasLocalizedField) {\n hasLocalizedField = true\n }\n if (groupHasLocalizedRelationshipField) {\n hasLocalizedRelationshipField = true\n }\n if (groupHasManyTextField) {\n hasManyTextField = true\n }\n if (groupHasLocalizedManyTextField) {\n hasLocalizedManyTextField = true\n }\n if (groupHasManyNumberField) {\n hasManyNumberField = true\n }\n if (groupHasLocalizedManyNumberField) {\n hasLocalizedManyNumberField = true\n }\n break\n }\n\n case 'tabs': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n const {\n hasLocalizedField: tabHasLocalizedField,\n hasLocalizedManyNumberField: tabHasLocalizedManyNumberField,\n hasLocalizedManyTextField: tabHasLocalizedManyTextField,\n hasLocalizedRelationshipField: tabHasLocalizedRelationshipField,\n hasManyNumberField: tabHasManyNumberField,\n hasManyTextField: tabHasManyTextField,\n } = traverseFields({\n adapter,\n columnPrefix,\n columns,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fieldPrefix,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n forceLocalized,\n indexes,\n joins,\n localesColumns,\n localesIndexes,\n newTableName,\n parentTableName,\n relationships,\n relationsToBuild,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n uniqueRelationships,\n versions,\n withinLocalizedArrayOrBlock,\n })\n\n if (tabHasLocalizedField) {\n hasLocalizedField = true\n }\n if (tabHasLocalizedRelationshipField) {\n hasLocalizedRelationshipField = true\n }\n if (tabHasManyTextField) {\n hasManyTextField = true\n }\n if (tabHasLocalizedManyTextField) {\n hasLocalizedManyTextField = true\n }\n if (tabHasManyNumberField) {\n hasManyNumberField = true\n }\n if (tabHasLocalizedManyNumberField) {\n hasLocalizedManyNumberField = true\n }\n break\n }\n\n case 'row':\n case 'collapsible': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n const {\n hasLocalizedField: rowHasLocalizedField,\n hasLocalizedManyNumberField: rowHasLocalizedManyNumberField,\n hasLocalizedManyTextField: rowHasLocalizedManyTextField,\n hasLocalizedRelationshipField: rowHasLocalizedRelationshipField,\n hasManyNumberField: rowHasManyNumberField,\n hasManyTextField: rowHasManyTextField,\n } = traverseFields({\n adapter,\n columnPrefix,\n columns,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fieldPrefix,\n fields: field.fields,\n forceLocalized,\n indexes,\n joins,\n localesColumns,\n localesIndexes,\n newTableName,\n parentTableName,\n relationships,\n relationsToBuild,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n uniqueRelationships,\n versions,\n withinLocalizedArrayOrBlock,\n })\n\n if (rowHasLocalizedField) {\n hasLocalizedField = true\n }\n if (rowHasLocalizedRelationshipField) {\n hasLocalizedRelationshipField = true\n }\n if (rowHasManyTextField) {\n hasManyTextField = true\n }\n if (rowHasLocalizedManyTextField) {\n hasLocalizedManyTextField = true\n }\n if (rowHasManyNumberField) {\n hasManyNumberField = true\n }\n if (rowHasLocalizedManyNumberField) {\n hasLocalizedManyNumberField = true\n }\n break\n }\n\n case 'relationship':\n case 'upload':\n if (Array.isArray(field.relationTo)) {\n field.relationTo.forEach((relation) => {\n relationships.add(relation)\n if (field.unique && !disableUnique && !disableRelsTableUnique) {\n uniqueRelationships.add(relation)\n }\n })\n } else if (field.hasMany) {\n relationships.add(field.relationTo)\n if (field.unique && !disableUnique && !disableRelsTableUnique) {\n uniqueRelationships.add(field.relationTo)\n }\n } else {\n // simple relationships get a column on the targetTable with a foreign key to the relationTo table\n const relationshipConfig = adapter.payload.collections[field.relationTo].config\n\n const tableName = adapter.tableNameMap.get(toSnakeCase(field.relationTo))\n\n // get the id type of the related collection\n let colType = adapter.idType === 'uuid' ? 'uuid' : 'integer'\n const relatedCollectionCustomID = relationshipConfig.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n if (relatedCollectionCustomID?.type === 'number') {\n colType = 'numeric'\n }\n if (relatedCollectionCustomID?.type === 'text') {\n colType = 'varchar'\n }\n\n // make the foreign key column for relationship using the correct id column type\n targetTable[fieldName] = parentIDColumnMap[colType](`${columnName}_id`).references(\n () => adapter.tables[tableName].id,\n { onDelete: 'set null' },\n )\n\n // add relationship to table\n relationsToBuild.set(fieldName, {\n type: 'one',\n localized: adapter.payload.config.localization && (field.localized || forceLocalized),\n target: tableName,\n })\n\n // add notNull when not required\n if (!disableNotNull && field.required && !field.admin?.condition) {\n targetTable[fieldName].notNull()\n }\n break\n }\n\n if (\n Boolean(field.localized && adapter.payload.config.localization) ||\n withinLocalizedArrayOrBlock\n ) {\n hasLocalizedRelationshipField = true\n }\n\n break\n\n case 'join': {\n // fieldName could be 'posts' or 'group_posts'\n // using `on` as the key for the relation\n const localized = adapter.payload.config.localization && field.localized\n const fieldSchemaPath = `${fieldPrefix || ''}${field.name}`\n let target: string\n const joinConfig = joins[field.collection].find(\n ({ schemaPath }) => fieldSchemaPath === schemaPath,\n )\n if (joinConfig.targetField.hasMany) {\n target = `${adapter.tableNameMap.get(toSnakeCase(field.collection))}${adapter.relationshipsSuffix}`\n } else {\n target = `${adapter.tableNameMap.get(toSnakeCase(field.collection))}${localized ? adapter.localesSuffix : ''}`\n }\n relationsToBuild.set(fieldName, {\n type: 'many',\n // joins are not localized on the parent table\n localized: false,\n relationName: field.on.replaceAll('.', '_'),\n target,\n })\n break\n }\n\n default:\n break\n }\n\n const condition = field.admin && field.admin.condition\n\n if (\n !disableNotNull &&\n targetTable[fieldName] &&\n 'required' in field &&\n field.required &&\n !condition\n ) {\n targetTable[fieldName].notNull()\n }\n })\n\n return {\n hasLocalizedField,\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n }\n}\n"],"names":["relations","boolean","foreignKey","index","integer","jsonb","numeric","PgNumericBuilder","PgUUIDBuilder","PgVarcharBuilder","text","timestamp","varchar","InvalidConfiguration","fieldAffectsData","fieldIsVirtual","optionIsObject","toSnakeCase","createTableName","hasLocalesTable","validateExistingBlockIsIdentical","buildTable","createIndex","idToUUID","parentIDColumnMap","withDefault","traverseFields","adapter","columnPrefix","columns","disableNotNull","disableRelsTableUnique","disableUnique","fieldPrefix","fields","forceLocalized","indexes","joins","localesColumns","localesIndexes","newTableName","parentTableName","relationships","relationsToBuild","rootRelationsToBuild","rootTableIDColType","rootTableName","uniqueRelationships","versions","withinLocalizedArrayOrBlock","throwValidationError","hasLocalizedField","hasLocalizedRelationshipField","hasManyTextField","hasLocalizedManyTextField","hasManyNumberField","hasLocalizedManyNumberField","parentIDColType","id","forEach","field","name","columnName","fieldName","targetTable","targetIndexes","replace","payload","config","localization","localized","type","hasMany","unique","includes","Array","isArray","relationTo","constraintValue","fieldConstraints","tableName","isLocalized","Boolean","mode","precision","withTimezone","enumName","prefix","target","enums","pgSchema","enum","options","map","option","value","selectTableName","versionsCustomName","baseColumns","order","notNull","parent","baseExtraConfig","orderIdx","cols","on","parentFk","foreignColumns","tables","onDelete","parentIdx","locale","enum__locales","localeIdx","set","one","references","relationName","disableNotNullFromHere","admin","condition","arrayTableName","_order","_parentID","_orderIdx","_parentIDFk","_parentIDIdx","_locale","_localeIdx","subHasLocalizedManyNumberField","subHasLocalizedManyTextField","subHasLocalizedRelationshipField","subHasManyNumberField","subHasManyTextField","subRelationsToBuild","rootRelationships","rootUniqueRelationships","many","result","_locales","localesSuffix","key","arrayWithLocalized","blocks","block","blockTableName","_path","_parentIdFk","_pathIdx","slug","blockWithLocalized","process","env","NODE_ENV","table","tableLocales","groupHasLocalizedField","groupHasLocalizedManyNumberField","groupHasLocalizedManyTextField","groupHasLocalizedRelationshipField","groupHasManyNumberField","groupHasManyTextField","tabHasLocalizedField","tabHasLocalizedManyNumberField","tabHasLocalizedManyTextField","tabHasLocalizedRelationshipField","tabHasManyNumberField","tabHasManyTextField","tabs","tab","rowHasLocalizedField","rowHasLocalizedManyNumberField","rowHasLocalizedManyTextField","rowHasLocalizedRelationshipField","rowHasManyNumberField","rowHasManyTextField","relation","add","relationshipConfig","collections","tableNameMap","get","colType","idType","relatedCollectionCustomID","find","required","fieldSchemaPath","joinConfig","collection","schemaPath","targetField","relationshipsSuffix","replaceAll"],"mappings":"AAIA,SAASA,SAAS,QAAQ,cAAa;AACvC,SACEC,OAAO,EACPC,UAAU,EACVC,KAAK,EACLC,OAAO,EACPC,KAAK,EACLC,OAAO,EACPC,gBAAgB,EAChBC,aAAa,EACbC,gBAAgB,EAChBC,IAAI,EACJC,SAAS,EACTC,OAAO,QACF,sBAAqB;AAC5B,SAASC,oBAAoB,QAAQ,UAAS;AAC9C,SAASC,gBAAgB,EAAEC,cAAc,EAAEC,cAAc,QAAQ,iBAAgB;AACjF,OAAOC,i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AS,CAAC,EAAE7D,QAAQyJ,YAAY,CAACC,GAAG,CAACpK,YAAY2C,MAAMiI,UAAU,GAAG,EAAElK,QAAQqK,mBAAmB,CAAC,CAAC;oBACrG,OAAO;wBACLxG,SAAS,CAAC,EAAE7D,QAAQyJ,YAAY,CAACC,GAAG,CAACpK,YAAY2C,MAAMiI,UAAU,GAAG,EAAEvH,YAAY3C,QAAQiH,aAAa,GAAG,GAAG,CAAC;oBAChH;oBACAjG,iBAAiBuE,GAAG,CAACnD,WAAW;wBAC9BQ,MAAM;wBACN,8CAA8C;wBAC9CD,WAAW;wBACX+C,cAAczD,MAAM6C,EAAE,CAACwF,UAAU,CAAC,KAAK;wBACvCzG;oBACF;oBACA;gBACF;YAEA;gBACE;QACJ;QAEA,MAAMgC,YAAY5D,MAAM2D,KAAK,IAAI3D,MAAM2D,KAAK,CAACC,SAAS;QAEtD,IACE,CAAC1F,kBACDkC,WAAW,CAACD,UAAU,IACtB,cAAcH,SACdA,MAAM8H,QAAQ,IACd,CAAClE,WACD;YACAxD,WAAW,CAACD,UAAU,CAACqC,OAAO;QAChC;IACF;IAEA,OAAO;QACLjD;QACAK;QACAF;QACAF;QACAG;QACAF;IACF;AACF,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withDefault.d.ts","sourceRoot":"","sources":["../../../src/postgres/schema/withDefault.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAEjD,eAAO,MAAM,WAAW,WACd,eAAe,SAChB,kBAAkB,KACxB,eAWF,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const withDefault = (column, field)=>{
|
|
2
|
+
if (typeof field.defaultValue === 'undefined' || typeof field.defaultValue === 'function') {
|
|
3
|
+
return column;
|
|
4
|
+
}
|
|
5
|
+
if (typeof field.defaultValue === 'string' && field.defaultValue.includes("'")) {
|
|
6
|
+
const escapedString = field.defaultValue.replaceAll("'", "''");
|
|
7
|
+
return column.default(escapedString);
|
|
8
|
+
}
|
|
9
|
+
return column.default(field.defaultValue);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=withDefault.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/postgres/schema/withDefault.ts"],"sourcesContent":["import type { PgColumnBuilder } from 'drizzle-orm/pg-core'\nimport type { FieldAffectingData } from 'payload'\n\nexport const withDefault = (\n column: PgColumnBuilder,\n field: FieldAffectingData,\n): PgColumnBuilder => {\n if (typeof field.defaultValue === 'undefined' || typeof field.defaultValue === 'function') {\n return column\n }\n\n if (typeof field.defaultValue === 'string' && field.defaultValue.includes(\"'\")) {\n const escapedString = field.defaultValue.replaceAll(\"'\", \"''\")\n return column.default(escapedString)\n }\n\n return column.default(field.defaultValue)\n}\n"],"names":["withDefault","column","field","defaultValue","includes","escapedString","replaceAll","default"],"mappings":"AAGA,OAAO,MAAMA,cAAc,CACzBC,QACAC;IAEA,IAAI,OAAOA,MAAMC,YAAY,KAAK,eAAe,OAAOD,MAAMC,YAAY,KAAK,YAAY;QACzF,OAAOF;IACT;IAEA,IAAI,OAAOC,MAAMC,YAAY,KAAK,YAAYD,MAAMC,YAAY,CAACC,QAAQ,CAAC,MAAM;QAC9E,MAAMC,gBAAgBH,MAAMC,YAAY,CAACG,UAAU,CAAC,KAAK;QACzD,OAAOL,OAAOM,OAAO,CAACF;IACxB;IAEA,OAAOJ,OAAOM,OAAO,CAACL,MAAMC,YAAY;AAC1C,EAAC"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { DrizzleSnapshotJSON } from 'drizzle-kit/api';
|
|
2
|
+
import type { ColumnBaseConfig, ColumnDataType, DrizzleConfig, Relation, Relations, SQL } from 'drizzle-orm';
|
|
3
|
+
import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
4
|
+
import type { ForeignKeyBuilder, IndexBuilder, PgColumn, PgEnum, pgEnum, PgInsertOnConflictDoUpdateConfig, PgSchema, PgTableWithColumns, UniqueConstraintBuilder } from 'drizzle-orm/pg-core';
|
|
5
|
+
import type { PgTableFn } from 'drizzle-orm/pg-core/table';
|
|
6
|
+
import type { Payload, PayloadRequest } from 'payload';
|
|
7
|
+
import type { ClientConfig, QueryResult } from 'pg';
|
|
8
|
+
import type { extendDrizzleTable, Operators } from '../index.js';
|
|
9
|
+
import type { BuildQueryJoinAliases, DrizzleAdapter, TransactionPg } from '../types.js';
|
|
10
|
+
export type BaseExtraConfig = Record<string, (cols: GenericColumns) => ForeignKeyBuilder | IndexBuilder | UniqueConstraintBuilder>;
|
|
11
|
+
export type RelationMap = Map<string, {
|
|
12
|
+
localized: boolean;
|
|
13
|
+
relationName?: string;
|
|
14
|
+
target: string;
|
|
15
|
+
type: 'many' | 'one';
|
|
16
|
+
}>;
|
|
17
|
+
export type GenericColumn = PgColumn<ColumnBaseConfig<ColumnDataType, string>, Record<string, unknown>>;
|
|
18
|
+
export type GenericColumns = {
|
|
19
|
+
[x: string]: GenericColumn;
|
|
20
|
+
};
|
|
21
|
+
export type GenericTable = PgTableWithColumns<{
|
|
22
|
+
columns: GenericColumns;
|
|
23
|
+
dialect: string;
|
|
24
|
+
name: string;
|
|
25
|
+
schema: string;
|
|
26
|
+
}>;
|
|
27
|
+
export type GenericEnum = PgEnum<[string, ...string[]]>;
|
|
28
|
+
export type GenericRelation = Relations<string, Record<string, Relation<string>>>;
|
|
29
|
+
export type PostgresDB = NodePgDatabase<Record<string, unknown>>;
|
|
30
|
+
export type CountDistinct = (args: {
|
|
31
|
+
db: PostgresDB | TransactionPg;
|
|
32
|
+
joins: BuildQueryJoinAliases;
|
|
33
|
+
tableName: string;
|
|
34
|
+
where: SQL;
|
|
35
|
+
}) => Promise<number>;
|
|
36
|
+
export type DeleteWhere = (args: {
|
|
37
|
+
db: PostgresDB | TransactionPg;
|
|
38
|
+
tableName: string;
|
|
39
|
+
where: SQL;
|
|
40
|
+
}) => Promise<void>;
|
|
41
|
+
export type DropDatabase = (args: {
|
|
42
|
+
adapter: BasePostgresAdapter;
|
|
43
|
+
}) => Promise<void>;
|
|
44
|
+
export type Execute<T> = (args: {
|
|
45
|
+
db?: PostgresDB | TransactionPg;
|
|
46
|
+
drizzle?: PostgresDB;
|
|
47
|
+
raw?: string;
|
|
48
|
+
sql?: SQL<unknown>;
|
|
49
|
+
}) => Promise<QueryResult<Record<string, T>>>;
|
|
50
|
+
export type Insert = (args: {
|
|
51
|
+
db: PostgresDB | TransactionPg;
|
|
52
|
+
onConflictDoUpdate?: PgInsertOnConflictDoUpdateConfig<any>;
|
|
53
|
+
tableName: string;
|
|
54
|
+
values: Record<string, unknown> | Record<string, unknown>[];
|
|
55
|
+
}) => Promise<Record<string, unknown>[]>;
|
|
56
|
+
export type CreateDatabase = (args?: {
|
|
57
|
+
/**
|
|
58
|
+
* Name of a database, defaults to the current one
|
|
59
|
+
*/
|
|
60
|
+
name?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Schema to create in addition to 'public'. Defaults from adapter.schemaName if exists.
|
|
63
|
+
*/
|
|
64
|
+
schemaName?: string;
|
|
65
|
+
}) => Promise<boolean>;
|
|
66
|
+
type Schema = {
|
|
67
|
+
enum: typeof pgEnum;
|
|
68
|
+
table: PgTableFn;
|
|
69
|
+
} | PgSchema;
|
|
70
|
+
type PostgresSchema = {
|
|
71
|
+
enums: Record<string, GenericEnum>;
|
|
72
|
+
relations: Record<string, GenericRelation>;
|
|
73
|
+
tables: Record<string, PgTableWithColumns<any>>;
|
|
74
|
+
};
|
|
75
|
+
type PostgresSchemaHookArgs = {
|
|
76
|
+
adapter: PostgresDrizzleAdapter;
|
|
77
|
+
extendTable: typeof extendDrizzleTable;
|
|
78
|
+
schema: PostgresSchema;
|
|
79
|
+
};
|
|
80
|
+
export type PostgresSchemaHook = (args: PostgresSchemaHookArgs) => PostgresSchema | Promise<PostgresSchema>;
|
|
81
|
+
export type BasePostgresAdapter = {
|
|
82
|
+
afterSchemaInit: PostgresSchemaHook[];
|
|
83
|
+
beforeSchemaInit: PostgresSchemaHook[];
|
|
84
|
+
countDistinct: CountDistinct;
|
|
85
|
+
createDatabase: CreateDatabase;
|
|
86
|
+
defaultDrizzleSnapshot: DrizzleSnapshotJSON;
|
|
87
|
+
deleteWhere: DeleteWhere;
|
|
88
|
+
disableCreateDatabase: boolean;
|
|
89
|
+
drizzle: PostgresDB;
|
|
90
|
+
dropDatabase: DropDatabase;
|
|
91
|
+
enums: Record<string, GenericEnum>;
|
|
92
|
+
execute: Execute<unknown>;
|
|
93
|
+
/**
|
|
94
|
+
* An object keyed on each table, with a key value pair where the constraint name is the key, followed by the dot-notation field name
|
|
95
|
+
* Used for returning properly formed errors from unique fields
|
|
96
|
+
*/
|
|
97
|
+
fieldConstraints: Record<string, Record<string, string>>;
|
|
98
|
+
idType: 'serial' | 'uuid';
|
|
99
|
+
initializing: Promise<void>;
|
|
100
|
+
insert: Insert;
|
|
101
|
+
localesSuffix?: string;
|
|
102
|
+
logger: DrizzleConfig['logger'];
|
|
103
|
+
operators: Operators;
|
|
104
|
+
pgSchema?: Schema;
|
|
105
|
+
poolOptions?: ClientConfig;
|
|
106
|
+
prodMigrations?: {
|
|
107
|
+
down: (args: MigrateDownArgs) => Promise<void>;
|
|
108
|
+
name: string;
|
|
109
|
+
up: (args: MigrateUpArgs) => Promise<void>;
|
|
110
|
+
}[];
|
|
111
|
+
push: boolean;
|
|
112
|
+
rejectInitializing: () => void;
|
|
113
|
+
relations: Record<string, GenericRelation>;
|
|
114
|
+
relationshipsSuffix?: string;
|
|
115
|
+
resolveInitializing: () => void;
|
|
116
|
+
schemaName?: string;
|
|
117
|
+
sessions: {
|
|
118
|
+
[id: string]: {
|
|
119
|
+
db: PostgresDB | TransactionPg;
|
|
120
|
+
reject: () => Promise<void>;
|
|
121
|
+
resolve: () => Promise<void>;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
tableNameMap: Map<string, string>;
|
|
125
|
+
tables: Record<string, GenericTable>;
|
|
126
|
+
versionsSuffix?: string;
|
|
127
|
+
} & PostgresDrizzleAdapter;
|
|
128
|
+
export type PostgresDrizzleAdapter = Omit<DrizzleAdapter, 'countDistinct' | 'deleteWhere' | 'drizzle' | 'dropDatabase' | 'execute' | 'insert' | 'operators' | 'relations'>;
|
|
129
|
+
export type IDType = 'integer' | 'numeric' | 'uuid' | 'varchar';
|
|
130
|
+
export type MigrateUpArgs = {
|
|
131
|
+
payload: Payload;
|
|
132
|
+
req: PayloadRequest;
|
|
133
|
+
};
|
|
134
|
+
export type MigrateDownArgs = {
|
|
135
|
+
payload: Payload;
|
|
136
|
+
req: PayloadRequest;
|
|
137
|
+
};
|
|
138
|
+
export {};
|
|
139
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/postgres/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,QAAQ,EACR,SAAS,EACT,GAAG,EACJ,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,KAAK,EACV,iBAAiB,EACjB,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,MAAM,EACN,gCAAgC,EAChC,QAAQ,EACR,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,IAAI,CAAA;AAEnD,OA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Ac,CAAC,EAAE,MAAM,CAAA;CACxB,GAAG,sBAAsB,CAAA;AAE1B,MAAM,MAAM,sBAAsB,GAAG,IAAI,CACvC,cAAc,EACZ,eAAe,GACf,aAAa,GACb,SAAS,GACT,cAAc,GACd,SAAS,GACT,QAAQ,GACR,WAAW,GACX,WAAW,CACd,CAAA;AAED,MAAM,MAAM,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;AAE/D,MAAM,MAAM,aAAa,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,cAAc,CAAA;CAAE,CAAA;AACrE,MAAM,MAAM,eAAe,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,cAAc,CAAA;CAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/postgres/types.ts"],"sourcesContent":["import type { DrizzleSnapshotJSON } from 'drizzle-kit/api'\nimport type {\n ColumnBaseConfig,\n ColumnDataType,\n DrizzleConfig,\n Relation,\n Relations,\n SQL,\n} from 'drizzle-orm'\nimport type { NodePgDatabase } from 'drizzle-orm/node-postgres'\nimport type {\n ForeignKeyBuilder,\n IndexBuilder,\n PgColumn,\n PgEnum,\n pgEnum,\n PgInsertOnConflictDoUpdateConfig,\n PgSchema,\n PgTableWithColumns,\n UniqueConstraintBuilder,\n} from 'drizzle-orm/pg-core'\nimport type { PgTableFn } from 'drizzle-orm/pg-core/table'\nimport type { Payload, PayloadRequest } from 'payload'\nimport type { ClientConfig, QueryResult } from 'pg'\n\nimport type { extendDrizzleTable, Operators } from '../index.js'\nimport type { BuildQueryJoinAliases, DrizzleAdapter, TransactionPg } from '../types.js'\n\nexport type BaseExtraConfig = Record<\n string,\n (cols: GenericColumns) => ForeignKeyBuilder | IndexBuilder | UniqueConstraintBuilder\n>\n\nexport type RelationMap = Map<\n string,\n {\n localized: boolean\n relationName?: string\n target: string\n type: 'many' | 'one'\n }\n>\n\nexport type GenericColumn = PgColumn<\n ColumnBaseConfig<ColumnDataType, string>,\n Record<string, unknown>\n>\n\nexport type GenericColumns = {\n [x: string]: GenericColumn\n}\n\nexport type GenericTable = PgTableWithColumns<{\n columns: GenericColumns\n dialect: string\n name: string\n schema: string\n}>\n\nexport type GenericEnum = PgEnum<[string, ...string[]]>\n\nexport type GenericRelation = Relations<string, Record<string, Relation<string>>>\n\nexport type PostgresDB = NodePgDatabase<Record<string, unknown>>\n\nexport type CountDistinct = (args: {\n db: PostgresDB | TransactionPg\n joins: BuildQueryJoinAliases\n tableName: string\n where: SQL\n}) => Promise<number>\n\nexport type DeleteWhere = (args: {\n db: PostgresDB | TransactionPg\n tableName: string\n where: SQL\n}) => Promise<void>\n\nexport type DropDatabase = (args: { adapter: BasePostgresAdapter }) => Promise<void>\n\nexport type Execute<T> = (args: {\n db?: PostgresDB | TransactionPg\n drizzle?: PostgresDB\n raw?: string\n sql?: SQL<unknown>\n}) => Promise<QueryResult<Record<string, T>>>\n\nexport type Insert = (args: {\n db: PostgresDB | TransactionPg\n onConflictDoUpdate?: PgInsertOnConflictDoUpdateConfig<any>\n tableName: string\n values: Record<string, unknown> | Record<string, unknown>[]\n}) => Promise<Record<string, unknown>[]>\n\nexport type CreateDatabase = (args?: {\n /**\n * Name of a database, defaults to the current one\n */\n name?: string\n /**\n * Schema to create in addition to 'public'. Defaults from adapter.schemaName if exists.\n */\n schemaName?: string\n}) => Promise<boolean>\n\ntype Schema =\n | {\n enum: typeof pgEnum\n table: PgTableFn\n }\n | PgSchema\n\ntype PostgresSchema = {\n enums: Record<string, GenericEnum>\n relations: Record<string, GenericRelation>\n tables: Record<string, PgTableWithColumns<any>>\n}\n\ntype PostgresSchemaHookArgs = {\n adapter: PostgresDrizzleAdapter\n extendTable: typeof extendDrizzleTable\n schema: PostgresSchema\n}\n\nexport type PostgresSchemaHook = (\n args: PostgresSchemaHookArgs,\n) => PostgresSchema | Promise<PostgresSchema>\n\nexport type BasePostgresAdapter = {\n afterSchemaInit: PostgresSchemaHook[]\n beforeSchemaInit: PostgresSchemaHook[]\n countDistinct: CountDistinct\n createDatabase: CreateDatabase\n defaultDrizzleSnapshot: DrizzleSnapshotJSON\n deleteWhere: DeleteWhere\n disableCreateDatabase: boolean\n drizzle: PostgresDB\n dropDatabase: DropDatabase\n enums: Record<string, GenericEnum>\n execute: Execute<unknown>\n /**\n * An object keyed on each table, with a key value pair where the constraint name is the key, followed by the dot-notation field name\n * Used for returning properly formed errors from unique fields\n */\n fieldConstraints: Record<string, Record<string, string>>\n idType: 'serial' | 'uuid'\n initializing: Promise<void>\n insert: Insert\n localesSuffix?: string\n logger: DrizzleConfig['logger']\n operators: Operators\n pgSchema?: Schema\n poolOptions?: ClientConfig\n prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\n push: boolean\n rejectInitializing: () => void\n relations: Record<string, GenericRelation>\n relationshipsSuffix?: string\n resolveInitializing: () => void\n schemaName?: string\n sessions: {\n [id: string]: {\n db: PostgresDB | TransactionPg\n reject: () => Promise<void>\n resolve: () => Promise<void>\n }\n }\n tableNameMap: Map<string, string>\n tables: Record<string, GenericTable>\n versionsSuffix?: string\n} & PostgresDrizzleAdapter\n\nexport type PostgresDrizzleAdapter = Omit<\n DrizzleAdapter,\n | 'countDistinct'\n | 'deleteWhere'\n | 'drizzle'\n | 'dropDatabase'\n | 'execute'\n | 'insert'\n | 'operators'\n | 'relations'\n>\n\nexport type IDType = 'integer' | 'numeric' | 'uuid' | 'varchar'\n\nexport type MigrateUpArgs = { payload: Payload; req: PayloadRequest }\nexport type MigrateDownArgs = { payload: Payload; req: PayloadRequest }\n"],"names":[],"mappings":"AA+LA,WAAuE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildAndOrConditions.d.ts","sourceRoot":"","sources":["../../src/queries/buildAndOrConditions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE3C,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAI5D,
|
|
1
|
+
{"version":3,"file":"buildAndOrConditions.d.ts","sourceRoot":"","sources":["../../src/queries/buildAndOrConditions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE3C,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAI5D,wBAAgB,oBAAoB,CAAC,EACnC,OAAO,EACP,MAAM,EACN,KAAK,EACL,MAAM,EACN,YAAY,EACZ,SAAS,EACT,KAAK,GACN,EAAE;IACD,OAAO,EAAE,cAAc,CAAA;IACvB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,qBAAqB,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,KAAK,EAAE,CAAA;CACf,GAAG,GAAG,EAAE,CAuBR"}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { parseParams } from './parseParams.js';
|
|
2
|
-
export
|
|
2
|
+
export function buildAndOrConditions({ adapter, fields, joins, locale, selectFields, tableName, where }) {
|
|
3
3
|
const completedConditions = [];
|
|
4
4
|
// Loop over all AND / OR operations and add them to the AND / OR query param
|
|
5
5
|
// Operations should come through as an array
|
|
6
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
7
6
|
for (const condition of where){
|
|
8
7
|
// If the operation is properly formatted as an object
|
|
9
8
|
if (typeof condition === 'object') {
|
|
10
|
-
|
|
11
|
-
const result = await parseParams({
|
|
9
|
+
const result = parseParams({
|
|
12
10
|
adapter,
|
|
13
11
|
fields,
|
|
14
12
|
joins,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/buildAndOrConditions.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { Field, Where } from 'payload'\n\nimport type { DrizzleAdapter, GenericColumn } from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\n\nimport { parseParams } from './parseParams.js'\n\nexport
|
|
1
|
+
{"version":3,"sources":["../../src/queries/buildAndOrConditions.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { Field, Where } from 'payload'\n\nimport type { DrizzleAdapter, GenericColumn } from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\n\nimport { parseParams } from './parseParams.js'\n\nexport function buildAndOrConditions({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where,\n}: {\n adapter: DrizzleAdapter\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n joins: BuildQueryJoinAliases\n locale?: string\n selectFields: Record<string, GenericColumn>\n tableName: string\n where: Where[]\n}): SQL[] {\n const completedConditions = []\n // Loop over all AND / OR operations and add them to the AND / OR query param\n // Operations should come through as an array\n\n for (const condition of where) {\n // If the operation is properly formatted as an object\n if (typeof condition === 'object') {\n const result = parseParams({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where: condition,\n })\n if (result && Object.keys(result).length > 0) {\n completedConditions.push(result)\n }\n }\n }\n return completedConditions\n}\n"],"names":["parseParams","buildAndOrConditions","adapter","fields","joins","locale","selectFields","tableName","where","completedConditions","condition","result","Object","keys","length","push"],"mappings":"AAMA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,SAASC,qBAAqB,EACnCC,OAAO,EACPC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,YAAY,EACZC,SAAS,EACTC,KAAK,EAWN;IACC,MAAMC,sBAAsB,EAAE;IAC9B,6EAA6E;IAC7E,6CAA6C;IAE7C,KAAK,MAAMC,aAAaF,MAAO;QAC7B,sDAAsD;QACtD,IAAI,OAAOE,cAAc,UAAU;YACjC,MAAMC,SAASX,YAAY;gBACzBE;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC,OAAOE;YACT;YACA,IAAIC,UAAUC,OAAOC,IAAI,CAACF,QAAQG,MAAM,GAAG,GAAG;gBAC5CL,oBAAoBM,IAAI,CAACJ;YAC3B;QACF;IACF;IACA,OAAOF;AACT"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Field } from 'payload';
|
|
2
|
+
import type { DrizzleAdapter, GenericColumn } from '../types.js';
|
|
3
|
+
import type { BuildQueryJoinAliases, BuildQueryResult } from './buildQuery.js';
|
|
4
|
+
type Args = {
|
|
5
|
+
adapter: DrizzleAdapter;
|
|
6
|
+
fields: Field[];
|
|
7
|
+
joins: BuildQueryJoinAliases;
|
|
8
|
+
locale?: string;
|
|
9
|
+
selectFields: Record<string, GenericColumn>;
|
|
10
|
+
sort?: string;
|
|
11
|
+
tableName: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Gets the order by column and direction constructed from the sort argument adds the column to the select fields and joins if necessary
|
|
15
|
+
*/
|
|
16
|
+
export declare const buildOrderBy: ({ adapter, fields, joins, locale, selectFields, sort, tableName, }: Args) => BuildQueryResult["orderBy"];
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=buildOrderBy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildOrderBy.d.ts","sourceRoot":"","sources":["../../src/queries/buildOrderBy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIpC,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,KAAK,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAI9E,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,KAAK,EAAE,qBAAqB,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,uEAQtB,IAAI,KAAG,gBAAgB,CAAC,SAAS,CAoDnC,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { asc, desc } from 'drizzle-orm';
|
|
2
|
+
import { getTableColumnFromPath } from './getTableColumnFromPath.js';
|
|
3
|
+
/**
|
|
4
|
+
* Gets the order by column and direction constructed from the sort argument adds the column to the select fields and joins if necessary
|
|
5
|
+
*/ export const buildOrderBy = ({ adapter, fields, joins, locale, selectFields, sort, tableName })=>{
|
|
6
|
+
const orderBy = {
|
|
7
|
+
column: null,
|
|
8
|
+
order: null
|
|
9
|
+
};
|
|
10
|
+
if (sort) {
|
|
11
|
+
let sortPath;
|
|
12
|
+
if (sort[0] === '-') {
|
|
13
|
+
sortPath = sort.substring(1);
|
|
14
|
+
orderBy.order = desc;
|
|
15
|
+
} else {
|
|
16
|
+
sortPath = sort;
|
|
17
|
+
orderBy.order = asc;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const { columnName: sortTableColumnName, table: sortTable } = getTableColumnFromPath({
|
|
21
|
+
adapter,
|
|
22
|
+
collectionPath: sortPath,
|
|
23
|
+
fields,
|
|
24
|
+
joins,
|
|
25
|
+
locale,
|
|
26
|
+
pathSegments: sortPath.replace(/__/g, '.').split('.'),
|
|
27
|
+
selectFields,
|
|
28
|
+
tableName,
|
|
29
|
+
useAlias: true,
|
|
30
|
+
value: sortPath
|
|
31
|
+
});
|
|
32
|
+
orderBy.column = sortTable?.[sortTableColumnName];
|
|
33
|
+
} catch (err) {
|
|
34
|
+
// continue
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (!orderBy?.column) {
|
|
38
|
+
orderBy.order = desc;
|
|
39
|
+
const createdAt = adapter.tables[tableName]?.createdAt;
|
|
40
|
+
if (createdAt) {
|
|
41
|
+
orderBy.column = createdAt;
|
|
42
|
+
} else {
|
|
43
|
+
orderBy.column = adapter.tables[tableName].id;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (orderBy.column) {
|
|
47
|
+
selectFields.sort = orderBy.column;
|
|
48
|
+
}
|
|
49
|
+
return orderBy;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=buildOrderBy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/queries/buildOrderBy.ts"],"sourcesContent":["import type { Field } from 'payload'\n\nimport { asc, desc } from 'drizzle-orm'\n\nimport type { DrizzleAdapter, GenericColumn } from '../types.js'\nimport type { BuildQueryJoinAliases, BuildQueryResult } from './buildQuery.js'\n\nimport { getTableColumnFromPath } from './getTableColumnFromPath.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n fields: Field[]\n joins: BuildQueryJoinAliases\n locale?: string\n selectFields: Record<string, GenericColumn>\n sort?: string\n tableName: string\n}\n\n/**\n * Gets the order by column and direction constructed from the sort argument adds the column to the select fields and joins if necessary\n */\nexport const buildOrderBy = ({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n sort,\n tableName,\n}: Args): BuildQueryResult['orderBy'] => {\n const orderBy: BuildQueryResult['orderBy'] = {\n column: null,\n order: null,\n }\n\n if (sort) {\n let sortPath\n\n if (sort[0] === '-') {\n sortPath = sort.substring(1)\n orderBy.order = desc\n } else {\n sortPath = sort\n orderBy.order = asc\n }\n\n try {\n const { columnName: sortTableColumnName, table: sortTable } = getTableColumnFromPath({\n adapter,\n collectionPath: sortPath,\n fields,\n joins,\n locale,\n pathSegments: sortPath.replace(/__/g, '.').split('.'),\n selectFields,\n tableName,\n useAlias: true,\n value: sortPath,\n })\n orderBy.column = sortTable?.[sortTableColumnName]\n } catch (err) {\n // continue\n }\n }\n\n if (!orderBy?.column) {\n orderBy.order = desc\n const createdAt = adapter.tables[tableName]?.createdAt\n\n if (createdAt) {\n orderBy.column = createdAt\n } else {\n orderBy.column = adapter.tables[tableName].id\n }\n }\n\n if (orderBy.column) {\n selectFields.sort = orderBy.column\n }\n\n return orderBy\n}\n"],"names":["asc","desc","getTableColumnFromPath","buildOrderBy","adapter","fields","joins","locale","selectFields","sort","tableName","orderBy","column","order","sortPath","substring","columnName","sortTableColumnName","table","sortTable","collectionPath","pathSegments","replace","split","useAlias","value","err","createdAt","tables","id"],"mappings":"AAEA,SAASA,GAAG,EAAEC,IAAI,QAAQ,cAAa;AAKvC,SAASC,sBAAsB,QAAQ,8BAA6B;AAYpE;;CAEC,GACD,OAAO,MAAMC,eAAe,CAAC,EAC3BC,OAAO,EACPC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,YAAY,EACZC,IAAI,EACJC,SAAS,EACJ;IACL,MAAMC,UAAuC;QAC3CC,QAAQ;QACRC,OAAO;IACT;IAEA,IAAIJ,MAAM;QACR,IAAIK;QAEJ,IAAIL,IAAI,CAAC,EAAE,KAAK,KAAK;YACnBK,WAAWL,KAAKM,SAAS,CAAC;YAC1BJ,QAAQE,KAAK,GAAGZ;QAClB,OAAO;YACLa,WAAWL;YACXE,QAAQE,KAAK,GAAGb;QAClB;QAEA,IAAI;YACF,MAAM,EAAEgB,YAAYC,mBAAmB,EAAEC,OAAOC,SAAS,EAAE,GAAGjB,uBAAuB;gBACnFE;gBACAgB,gBAAgBN;gBAChBT;gBACAC;gBACAC;gBACAc,cAAcP,SAASQ,OAAO,CAAC,OAAO,KAAKC,KAAK,CAAC;gBACjDf;gBACAE;gBACAc,UAAU;gBACVC,OAAOX;YACT;YACAH,QAAQC,MAAM,GAAGO,WAAW,CAACF,oBAAoB;QACnD,EAAE,OAAOS,KAAK;QACZ,WAAW;QACb;IACF;IAEA,IAAI,CAACf,SAASC,QAAQ;QACpBD,QAAQE,KAAK,GAAGZ;QAChB,MAAM0B,YAAYvB,QAAQwB,MAAM,CAAClB,UAAU,EAAEiB;QAE7C,IAAIA,WAAW;YACbhB,QAAQC,MAAM,GAAGe;QACnB,OAAO;YACLhB,QAAQC,MAAM,GAAGR,QAAQwB,MAAM,CAAClB,UAAU,CAACmB,EAAE;QAC/C;IACF;IAEA,IAAIlB,QAAQC,MAAM,EAAE;QAClBJ,aAAaC,IAAI,GAAGE,QAAQC,MAAM;IACpC;IAEA,OAAOD;AACT,EAAC"}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import type { SQL } from 'drizzle-orm';
|
|
1
|
+
import type { asc, desc, SQL } from 'drizzle-orm';
|
|
2
2
|
import type { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
3
3
|
import type { Field, Where } from 'payload';
|
|
4
|
-
import { asc, desc } from 'drizzle-orm';
|
|
5
4
|
import type { DrizzleAdapter, GenericColumn, GenericTable } from '../types.js';
|
|
6
5
|
export type BuildQueryJoinAliases = {
|
|
7
6
|
condition: SQL;
|
|
8
7
|
table: GenericTable | PgTableWithColumns<any>;
|
|
8
|
+
type?: 'innerJoin' | 'leftJoin' | 'rightJoin';
|
|
9
9
|
}[];
|
|
10
10
|
type BuildQueryArgs = {
|
|
11
11
|
adapter: DrizzleAdapter;
|
|
12
12
|
fields: Field[];
|
|
13
|
+
joins?: BuildQueryJoinAliases;
|
|
13
14
|
locale?: string;
|
|
14
15
|
sort?: string;
|
|
15
16
|
tableName: string;
|
|
16
17
|
where: Where;
|
|
17
18
|
};
|
|
18
|
-
type
|
|
19
|
+
export type BuildQueryResult = {
|
|
19
20
|
joins: BuildQueryJoinAliases;
|
|
20
21
|
orderBy: {
|
|
21
22
|
column: GenericColumn;
|
|
@@ -24,6 +25,6 @@ type Result = {
|
|
|
24
25
|
selectFields: Record<string, GenericColumn>;
|
|
25
26
|
where: SQL;
|
|
26
27
|
};
|
|
27
|
-
declare const buildQuery: ({ adapter, fields, locale, sort, tableName, where: incomingWhere, }: BuildQueryArgs) =>
|
|
28
|
+
declare const buildQuery: ({ adapter, fields, joins, locale, sort, tableName, where: incomingWhere, }: BuildQueryArgs) => BuildQueryResult;
|
|
28
29
|
export default buildQuery;
|
|
29
30
|
//# sourceMappingURL=buildQuery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildQuery.d.ts","sourceRoot":"","sources":["../../src/queries/buildQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"buildQuery.d.ts","sourceRoot":"","sources":["../../src/queries/buildQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE3C,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAK9E,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,EAAE,GAAG,CAAA;IACd,KAAK,EAAE,YAAY,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAA;IAC7C,IAAI,CAAC,EAAE,WAAW,GAAG,UAAU,GAAG,WAAW,CAAA;CAC9C,EAAE,CAAA;AAEH,KAAK,cAAc,GAAG;IACpB,OAAO,EAAE,cAAc,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,KAAK,CAAC,EAAE,qBAAqB,CAAA;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,qBAAqB,CAAA;IAC5B,OAAO,EAAE;QACP,MAAM,EAAE,aAAa,CAAA;QACrB,KAAK,EAAE,OAAO,GAAG,GAAG,OAAO,IAAI,CAAA;KAChC,CAAA;IACD,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,KAAK,EAAE,GAAG,CAAA;CACX,CAAA;AACD,QAAA,MAAM,UAAU,+EAQb,cAAc,KAAG,gBAmCnB,CAAA;AAED,eAAe,UAAU,CAAA"}
|
|
@@ -1,56 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getTableColumnFromPath } from './getTableColumnFromPath.js';
|
|
1
|
+
import { buildOrderBy } from './buildOrderBy.js';
|
|
3
2
|
import { parseParams } from './parseParams.js';
|
|
4
|
-
const buildQuery =
|
|
3
|
+
const buildQuery = function buildQuery({ adapter, fields, joins = [], locale, sort, tableName, where: incomingWhere }) {
|
|
5
4
|
const selectFields = {
|
|
6
5
|
id: adapter.tables[tableName].id
|
|
7
6
|
};
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
orderBy.order = desc;
|
|
18
|
-
} else {
|
|
19
|
-
sortPath = sort;
|
|
20
|
-
orderBy.order = asc;
|
|
21
|
-
}
|
|
22
|
-
try {
|
|
23
|
-
const { columnName: sortTableColumnName, table: sortTable } = getTableColumnFromPath({
|
|
24
|
-
adapter,
|
|
25
|
-
collectionPath: sortPath,
|
|
26
|
-
fields,
|
|
27
|
-
joins,
|
|
28
|
-
locale,
|
|
29
|
-
pathSegments: sortPath.replace(/__/g, '.').split('.'),
|
|
30
|
-
selectFields,
|
|
31
|
-
tableName,
|
|
32
|
-
value: sortPath
|
|
33
|
-
});
|
|
34
|
-
orderBy.column = sortTable?.[sortTableColumnName];
|
|
35
|
-
} catch (err) {
|
|
36
|
-
// continue
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (!orderBy?.column) {
|
|
40
|
-
orderBy.order = desc;
|
|
41
|
-
const createdAt = adapter.tables[tableName]?.createdAt;
|
|
42
|
-
if (createdAt) {
|
|
43
|
-
orderBy.column = createdAt;
|
|
44
|
-
} else {
|
|
45
|
-
orderBy.column = adapter.tables[tableName].id;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (orderBy.column) {
|
|
49
|
-
selectFields.sort = orderBy.column;
|
|
50
|
-
}
|
|
7
|
+
const orderBy = buildOrderBy({
|
|
8
|
+
adapter,
|
|
9
|
+
fields,
|
|
10
|
+
joins,
|
|
11
|
+
locale,
|
|
12
|
+
selectFields,
|
|
13
|
+
sort,
|
|
14
|
+
tableName
|
|
15
|
+
});
|
|
51
16
|
let where;
|
|
52
17
|
if (incomingWhere && Object.keys(incomingWhere).length > 0) {
|
|
53
|
-
where =
|
|
18
|
+
where = parseParams({
|
|
54
19
|
adapter,
|
|
55
20
|
fields,
|
|
56
21
|
joins,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { Field, Where } from 'payload'\n\nimport
|
|
1
|
+
{"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { asc, desc, SQL } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { Field, Where } from 'payload'\n\nimport type { DrizzleAdapter, GenericColumn, GenericTable } from '../types.js'\n\nimport { buildOrderBy } from './buildOrderBy.js'\nimport { parseParams } from './parseParams.js'\n\nexport type BuildQueryJoinAliases = {\n condition: SQL\n table: GenericTable | PgTableWithColumns<any>\n type?: 'innerJoin' | 'leftJoin' | 'rightJoin'\n}[]\n\ntype BuildQueryArgs = {\n adapter: DrizzleAdapter\n fields: Field[]\n joins?: BuildQueryJoinAliases\n locale?: string\n sort?: string\n tableName: string\n where: Where\n}\n\nexport type BuildQueryResult = {\n joins: BuildQueryJoinAliases\n orderBy: {\n column: GenericColumn\n order: typeof asc | typeof desc\n }\n selectFields: Record<string, GenericColumn>\n where: SQL\n}\nconst buildQuery = function buildQuery({\n adapter,\n fields,\n joins = [],\n locale,\n sort,\n tableName,\n where: incomingWhere,\n}: BuildQueryArgs): BuildQueryResult {\n const selectFields: Record<string, GenericColumn> = {\n id: adapter.tables[tableName].id,\n }\n\n const orderBy = buildOrderBy({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n sort,\n tableName,\n })\n\n let where: SQL\n\n if (incomingWhere && Object.keys(incomingWhere).length > 0) {\n where = parseParams({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where: incomingWhere,\n })\n }\n\n return {\n joins,\n orderBy,\n selectFields,\n where,\n }\n}\n\nexport default buildQuery\n"],"names":["buildOrderBy","parseParams","buildQuery","adapter","fields","joins","locale","sort","tableName","where","incomingWhere","selectFields","id","tables","orderBy","Object","keys","length"],"mappings":"AAMA,SAASA,YAAY,QAAQ,oBAAmB;AAChD,SAASC,WAAW,QAAQ,mBAAkB;AA2B9C,MAAMC,aAAa,SAASA,WAAW,EACrCC,OAAO,EACPC,MAAM,EACNC,QAAQ,EAAE,EACVC,MAAM,EACNC,IAAI,EACJC,SAAS,EACTC,OAAOC,aAAa,EACL;IACf,MAAMC,eAA8C;QAClDC,IAAIT,QAAQU,MAAM,CAACL,UAAU,CAACI,EAAE;IAClC;IAEA,MAAME,UAAUd,aAAa;QAC3BG;QACAC;QACAC;QACAC;QACAK;QACAJ;QACAC;IACF;IAEA,IAAIC;IAEJ,IAAIC,iBAAiBK,OAAOC,IAAI,CAACN,eAAeO,MAAM,GAAG,GAAG;QAC1DR,QAAQR,YAAY;YAClBE;YACAC;YACAC;YACAC;YACAK;YACAH;YACAC,OAAOC;QACT;IACF;IAEA,OAAO;QACLL;QACAS;QACAH;QACAF;IACF;AACF;AAEA,eAAeP,WAAU"}
|