@hanzo/cms-drizzle 3.85.2
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/LICENSE.md +22 -0
- package/README.md +3 -0
- package/dist/count.d.ts +3 -0
- package/dist/count.d.ts.map +1 -0
- package/dist/count.js +26 -0
- package/dist/count.js.map +1 -0
- package/dist/countGlobalVersions.d.ts +3 -0
- package/dist/countGlobalVersions.d.ts.map +1 -0
- package/dist/countGlobalVersions.js +28 -0
- package/dist/countGlobalVersions.js.map +1 -0
- package/dist/countVersions.d.ts +3 -0
- package/dist/countVersions.d.ts.map +1 -0
- package/dist/countVersions.js +28 -0
- package/dist/countVersions.js.map +1 -0
- package/dist/create.d.ts +3 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/create.js +28 -0
- package/dist/create.js.map +1 -0
- package/dist/createGlobal.d.ts +4 -0
- package/dist/createGlobal.d.ts.map +1 -0
- package/dist/createGlobal.js +28 -0
- package/dist/createGlobal.js.map +1 -0
- package/dist/createGlobalVersion.d.ts +4 -0
- package/dist/createGlobalVersion.d.ts.map +1 -0
- package/dist/createGlobalVersion.js +49 -0
- package/dist/createGlobalVersion.js.map +1 -0
- package/dist/createTableName.d.ts +31 -0
- package/dist/createTableName.d.ts.map +1 -0
- package/dist/createTableName.js +37 -0
- package/dist/createTableName.js.map +1 -0
- package/dist/createVersion.d.ts +4 -0
- package/dist/createVersion.d.ts.map +1 -0
- package/dist/createVersion.js +65 -0
- package/dist/createVersion.js.map +1 -0
- package/dist/deleteMany.d.ts +3 -0
- package/dist/deleteMany.d.ts.map +1 -0
- package/dist/deleteMany.js +51 -0
- package/dist/deleteMany.js.map +1 -0
- package/dist/deleteOne.d.ts +3 -0
- package/dist/deleteOne.d.ts.map +1 -0
- package/dist/deleteOne.js +67 -0
- package/dist/deleteOne.js.map +1 -0
- package/dist/deleteVersions.d.ts +3 -0
- package/dist/deleteVersions.d.ts.map +1 -0
- package/dist/deleteVersions.js +52 -0
- package/dist/deleteVersions.js.map +1 -0
- package/dist/destroy.d.ts +3 -0
- package/dist/destroy.d.ts.map +1 -0
- package/dist/destroy.js +17 -0
- package/dist/destroy.js.map +1 -0
- package/dist/exports/postgres.d.ts +16 -0
- package/dist/exports/postgres.d.ts.map +1 -0
- package/dist/exports/postgres.js +17 -0
- package/dist/exports/postgres.js.map +1 -0
- package/dist/exports/sqlite.d.ts +13 -0
- package/dist/exports/sqlite.d.ts.map +1 -0
- package/dist/exports/sqlite.js +14 -0
- package/dist/exports/sqlite.js.map +1 -0
- package/dist/exports/types-deprecated.d.ts +150 -0
- package/dist/exports/types-deprecated.d.ts.map +1 -0
- package/dist/exports/types-deprecated.js +5 -0
- package/dist/exports/types-deprecated.js.map +1 -0
- package/dist/find/buildFindManyArgs.d.ts +27 -0
- package/dist/find/buildFindManyArgs.d.ts.map +1 -0
- package/dist/find/buildFindManyArgs.js +96 -0
- package/dist/find/buildFindManyArgs.js.map +1 -0
- package/dist/find/chainMethods.d.ts +20 -0
- package/dist/find/chainMethods.d.ts.map +1 -0
- package/dist/find/chainMethods.js +16 -0
- package/dist/find/chainMethods.js.map +1 -0
- package/dist/find/findMany.d.ts +23 -0
- package/dist/find/findMany.d.ts.map +1 -0
- package/dist/find/findMany.js +173 -0
- package/dist/find/findMany.js.map +1 -0
- package/dist/find/traverseFields.d.ts +34 -0
- package/dist/find/traverseFields.d.ts.map +1 -0
- package/dist/find/traverseFields.js +653 -0
- package/dist/find/traverseFields.js.map +1 -0
- package/dist/find.d.ts +3 -0
- package/dist/find.d.ts.map +1 -0
- package/dist/find.js +25 -0
- package/dist/find.js.map +1 -0
- package/dist/findDistinct.d.ts +3 -0
- package/dist/findDistinct.d.ts.map +1 -0
- package/dist/findDistinct.js +135 -0
- package/dist/findDistinct.js.map +1 -0
- package/dist/findGlobal.d.ts +3 -0
- package/dist/findGlobal.d.ts.map +1 -0
- package/dist/findGlobal.js +24 -0
- package/dist/findGlobal.js.map +1 -0
- package/dist/findGlobalVersions.d.ts +3 -0
- package/dist/findGlobalVersions.d.ts.map +1 -0
- package/dist/findGlobalVersions.js +24 -0
- package/dist/findGlobalVersions.js.map +1 -0
- package/dist/findOne.d.ts +4 -0
- package/dist/findOne.d.ts.map +1 -0
- package/dist/findOne.js +25 -0
- package/dist/findOne.js.map +1 -0
- package/dist/findVersions.d.ts +3 -0
- package/dist/findVersions.d.ts.map +1 -0
- package/dist/findVersions.js +25 -0
- package/dist/findVersions.js.map +1 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +1 -0
- package/dist/migrate.d.ts +3 -0
- package/dist/migrate.d.ts.map +1 -0
- package/dist/migrate.js +98 -0
- package/dist/migrate.js.map +1 -0
- package/dist/migrateDown.d.ts +3 -0
- package/dist/migrateDown.d.ts.map +1 -0
- package/dist/migrateDown.js +64 -0
- package/dist/migrateDown.js.map +1 -0
- package/dist/migrateFresh.d.ts +8 -0
- package/dist/migrateFresh.d.ts.map +1 -0
- package/dist/migrateFresh.js +77 -0
- package/dist/migrateFresh.js.map +1 -0
- package/dist/migrateRefresh.d.ts +6 -0
- package/dist/migrateRefresh.d.ts.map +1 -0
- package/dist/migrateRefresh.js +104 -0
- package/dist/migrateRefresh.js.map +1 -0
- package/dist/migrateReset.d.ts +6 -0
- package/dist/migrateReset.d.ts.map +1 -0
- package/dist/migrateReset.js +86 -0
- package/dist/migrateReset.js.map +1 -0
- package/dist/migrateStatus.d.ts +3 -0
- package/dist/migrateStatus.d.ts.map +1 -0
- package/dist/migrateStatus.js +44 -0
- package/dist/migrateStatus.js.map +1 -0
- package/dist/postgres/columnToCodeConverter.d.ts +3 -0
- package/dist/postgres/columnToCodeConverter.d.ts.map +1 -0
- package/dist/postgres/columnToCodeConverter.js +93 -0
- package/dist/postgres/columnToCodeConverter.js.map +1 -0
- 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 +76 -0
- package/dist/postgres/createDatabase.js.map +1 -0
- package/dist/postgres/createExtensions.d.ts +3 -0
- package/dist/postgres/createExtensions.d.ts.map +1 -0
- package/dist/postgres/createExtensions.js +16 -0
- package/dist/postgres/createExtensions.js.map +1 -0
- package/dist/postgres/createJSONQuery/index.d.ts +3 -0
- package/dist/postgres/createJSONQuery/index.d.ts.map +1 -0
- package/dist/postgres/createJSONQuery/index.js +67 -0
- package/dist/postgres/createJSONQuery/index.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 +20 -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/init.d.ts +3 -0
- package/dist/postgres/init.d.ts.map +1 -0
- package/dist/postgres/init.js +41 -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/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +19 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.js +173 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts +11 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +151 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts +3 -0
- package/dist/postgres/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/groupUpSQLStatements.js +114 -0
- package/dist/postgres/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/index.d.ts +23 -0
- package/dist/postgres/predefinedMigrations/v2-v3/index.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/index.js +275 -0
- package/dist/postgres/predefinedMigrations/v2-v3/index.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/migrateRelationships.d.ts +19 -0
- package/dist/postgres/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/migrateRelationships.js +64 -0
- package/dist/postgres/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/traverseFields.d.ts +22 -0
- package/dist/postgres/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/traverseFields.js +64 -0
- package/dist/postgres/predefinedMigrations/v2-v3/traverseFields.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/types.d.ts +9 -0
- package/dist/postgres/predefinedMigrations/v2-v3/types.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/types.js +6 -0
- package/dist/postgres/predefinedMigrations/v2-v3/types.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 +13 -0
- package/dist/postgres/requireDrizzleKit.js.map +1 -0
- package/dist/postgres/schema/buildDrizzleTable.d.ts +7 -0
- package/dist/postgres/schema/buildDrizzleTable.d.ts.map +1 -0
- package/dist/postgres/schema/buildDrizzleTable.js +157 -0
- package/dist/postgres/schema/buildDrizzleTable.js.map +1 -0
- package/dist/postgres/schema/geometryColumn.d.ts +11 -0
- package/dist/postgres/schema/geometryColumn.d.ts.map +1 -0
- package/dist/postgres/schema/geometryColumn.js +18 -0
- package/dist/postgres/schema/geometryColumn.js.map +1 -0
- package/dist/postgres/schema/setColumnID.d.ts +3 -0
- package/dist/postgres/schema/setColumnID.d.ts.map +1 -0
- package/dist/postgres/schema/setColumnID.js +47 -0
- package/dist/postgres/schema/setColumnID.js.map +1 -0
- package/dist/postgres/types.d.ts +199 -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/addJoinTable.d.ts +13 -0
- package/dist/queries/addJoinTable.d.ts.map +1 -0
- package/dist/queries/addJoinTable.js +15 -0
- package/dist/queries/addJoinTable.js.map +1 -0
- package/dist/queries/buildAndOrConditions.d.ts +21 -0
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -0
- package/dist/queries/buildAndOrConditions.js +30 -0
- package/dist/queries/buildAndOrConditions.js.map +1 -0
- package/dist/queries/buildOrderBy.d.ts +22 -0
- package/dist/queries/buildOrderBy.d.ts.map +1 -0
- package/dist/queries/buildOrderBy.js +71 -0
- package/dist/queries/buildOrderBy.js.map +1 -0
- package/dist/queries/buildQuery.d.ts +35 -0
- package/dist/queries/buildQuery.d.ts.map +1 -0
- package/dist/queries/buildQuery.js +46 -0
- package/dist/queries/buildQuery.js.map +1 -0
- package/dist/queries/getTableAlias.d.ts +13 -0
- package/dist/queries/getTableAlias.d.ts.map +1 -0
- package/dist/queries/getTableAlias.js +20 -0
- package/dist/queries/getTableAlias.js.map +1 -0
- package/dist/queries/getTableColumnFromPath.d.ts +58 -0
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -0
- package/dist/queries/getTableColumnFromPath.js +793 -0
- package/dist/queries/getTableColumnFromPath.js.map +1 -0
- package/dist/queries/operatorMap.d.ts +6 -0
- package/dist/queries/operatorMap.d.ts.map +1 -0
- package/dist/queries/operatorMap.js +22 -0
- package/dist/queries/operatorMap.js.map +1 -0
- package/dist/queries/parseParams.d.ts +24 -0
- package/dist/queries/parseParams.d.ts.map +1 -0
- package/dist/queries/parseParams.js +356 -0
- package/dist/queries/parseParams.js.map +1 -0
- package/dist/queries/sanitizeQueryValue.d.ts +26 -0
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -0
- package/dist/queries/sanitizeQueryValue.js +246 -0
- package/dist/queries/sanitizeQueryValue.js.map +1 -0
- package/dist/queries/selectDistinct.d.ts +25 -0
- package/dist/queries/selectDistinct.d.ts.map +1 -0
- package/dist/queries/selectDistinct.js +29 -0
- package/dist/queries/selectDistinct.js.map +1 -0
- package/dist/queryDrafts.d.ts +3 -0
- package/dist/queryDrafts.d.ts.map +1 -0
- package/dist/queryDrafts.js +41 -0
- package/dist/queryDrafts.js.map +1 -0
- package/dist/schema/build.d.ts +50 -0
- package/dist/schema/build.d.ts.map +1 -0
- package/dist/schema/build.js +705 -0
- package/dist/schema/build.js.map +1 -0
- package/dist/schema/buildDrizzleRelations.d.ts +5 -0
- package/dist/schema/buildDrizzleRelations.d.ts.map +1 -0
- package/dist/schema/buildDrizzleRelations.js +28 -0
- package/dist/schema/buildDrizzleRelations.js.map +1 -0
- package/dist/schema/buildRawSchema.d.ts +9 -0
- package/dist/schema/buildRawSchema.d.ts.map +1 -0
- package/dist/schema/buildRawSchema.js +117 -0
- package/dist/schema/buildRawSchema.js.map +1 -0
- package/dist/schema/idToUUID.d.ts +3 -0
- package/dist/schema/idToUUID.d.ts.map +1 -0
- package/dist/schema/idToUUID.js +11 -0
- package/dist/schema/idToUUID.js.map +1 -0
- package/dist/schema/traverseFields.d.ts +44 -0
- package/dist/schema/traverseFields.d.ts.map +1 -0
- package/dist/schema/traverseFields.js +810 -0
- package/dist/schema/traverseFields.js.map +1 -0
- package/dist/schema/withDefault.d.ts +4 -0
- package/dist/schema/withDefault.d.ts.map +1 -0
- package/dist/schema/withDefault.js +11 -0
- package/dist/schema/withDefault.js.map +1 -0
- package/dist/sqlite/columnToCodeConverter.d.ts +3 -0
- package/dist/sqlite/columnToCodeConverter.d.ts.map +1 -0
- package/dist/sqlite/columnToCodeConverter.js +116 -0
- package/dist/sqlite/columnToCodeConverter.js.map +1 -0
- package/dist/sqlite/countDistinct.d.ts +3 -0
- package/dist/sqlite/countDistinct.d.ts.map +1 -0
- package/dist/sqlite/countDistinct.js +24 -0
- package/dist/sqlite/countDistinct.js.map +1 -0
- package/dist/sqlite/createJSONQuery/convertPathToJSONTraversal.d.ts +2 -0
- package/dist/sqlite/createJSONQuery/convertPathToJSONTraversal.d.ts.map +1 -0
- package/dist/sqlite/createJSONQuery/convertPathToJSONTraversal.js +14 -0
- package/dist/sqlite/createJSONQuery/convertPathToJSONTraversal.js.map +1 -0
- package/dist/sqlite/createJSONQuery/index.d.ts +3 -0
- package/dist/sqlite/createJSONQuery/index.d.ts.map +1 -0
- package/dist/sqlite/createJSONQuery/index.js +109 -0
- package/dist/sqlite/createJSONQuery/index.js.map +1 -0
- package/dist/sqlite/defaultSnapshot.d.ts +3 -0
- package/dist/sqlite/defaultSnapshot.d.ts.map +1 -0
- package/dist/sqlite/defaultSnapshot.js +15 -0
- package/dist/sqlite/defaultSnapshot.js.map +1 -0
- package/dist/sqlite/deleteWhere.d.ts +3 -0
- package/dist/sqlite/deleteWhere.d.ts.map +1 -0
- package/dist/sqlite/deleteWhere.js +6 -0
- package/dist/sqlite/deleteWhere.js.map +1 -0
- package/dist/sqlite/dropDatabase.d.ts +3 -0
- package/dist/sqlite/dropDatabase.d.ts.map +1 -0
- package/dist/sqlite/dropDatabase.js +19 -0
- package/dist/sqlite/dropDatabase.js.map +1 -0
- package/dist/sqlite/execute.d.ts +3 -0
- package/dist/sqlite/execute.d.ts.map +1 -0
- package/dist/sqlite/execute.js +13 -0
- package/dist/sqlite/execute.js.map +1 -0
- package/dist/sqlite/init.d.ts +3 -0
- package/dist/sqlite/init.d.ts.map +1 -0
- package/dist/sqlite/init.js +42 -0
- package/dist/sqlite/init.js.map +1 -0
- package/dist/sqlite/insert.d.ts +3 -0
- package/dist/sqlite/insert.d.ts.map +1 -0
- package/dist/sqlite/insert.js +21 -0
- package/dist/sqlite/insert.js.map +1 -0
- package/dist/sqlite/requireDrizzleKit.d.ts +3 -0
- package/dist/sqlite/requireDrizzleKit.d.ts.map +1 -0
- package/dist/sqlite/requireDrizzleKit.js +12 -0
- package/dist/sqlite/requireDrizzleKit.js.map +1 -0
- package/dist/sqlite/schema/buildDrizzleTable.d.ts +3 -0
- package/dist/sqlite/schema/buildDrizzleTable.d.ts.map +1 -0
- package/dist/sqlite/schema/buildDrizzleTable.js +153 -0
- package/dist/sqlite/schema/buildDrizzleTable.js.map +1 -0
- package/dist/sqlite/schema/setColumnID.d.ts +3 -0
- package/dist/sqlite/schema/setColumnID.d.ts.map +1 -0
- package/dist/sqlite/schema/setColumnID.js +48 -0
- package/dist/sqlite/schema/setColumnID.js.map +1 -0
- package/dist/sqlite/types.d.ts +214 -0
- package/dist/sqlite/types.d.ts.map +1 -0
- package/dist/sqlite/types.js +3 -0
- package/dist/sqlite/types.js.map +1 -0
- package/dist/transactions/beginTransaction.d.ts +3 -0
- package/dist/transactions/beginTransaction.d.ts.map +1 -0
- package/dist/transactions/beginTransaction.js +59 -0
- package/dist/transactions/beginTransaction.js.map +1 -0
- package/dist/transactions/commitTransaction.d.ts +3 -0
- package/dist/transactions/commitTransaction.d.ts.map +1 -0
- package/dist/transactions/commitTransaction.js +18 -0
- package/dist/transactions/commitTransaction.js.map +1 -0
- package/dist/transactions/rollbackTransaction.d.ts +3 -0
- package/dist/transactions/rollbackTransaction.d.ts.map +1 -0
- package/dist/transactions/rollbackTransaction.js +16 -0
- package/dist/transactions/rollbackTransaction.js.map +1 -0
- package/dist/transform/read/hasManyNumber.d.ts +11 -0
- package/dist/transform/read/hasManyNumber.d.ts.map +1 -0
- package/dist/transform/read/hasManyNumber.js +28 -0
- package/dist/transform/read/hasManyNumber.js.map +1 -0
- package/dist/transform/read/hasManyText.d.ts +11 -0
- package/dist/transform/read/hasManyText.d.ts.map +1 -0
- package/dist/transform/read/hasManyText.js +20 -0
- package/dist/transform/read/hasManyText.js.map +1 -0
- package/dist/transform/read/index.d.ts +16 -0
- package/dist/transform/read/index.d.ts.map +1 -0
- package/dist/transform/read/index.js +49 -0
- package/dist/transform/read/index.js.map +1 -0
- package/dist/transform/read/relationship.d.ts +11 -0
- package/dist/transform/read/relationship.d.ts.map +1 -0
- package/dist/transform/read/relationship.js +69 -0
- package/dist/transform/read/relationship.js.map +1 -0
- package/dist/transform/read/traverseFields.d.ts +68 -0
- package/dist/transform/read/traverseFields.d.ts.map +1 -0
- package/dist/transform/read/traverseFields.js +542 -0
- package/dist/transform/read/traverseFields.js.map +1 -0
- package/dist/transform/write/array.d.ts +34 -0
- package/dist/transform/write/array.d.ts.map +1 -0
- package/dist/transform/write/array.js +73 -0
- package/dist/transform/write/array.js.map +1 -0
- package/dist/transform/write/blocks.d.ts +33 -0
- package/dist/transform/write/blocks.d.ts.map +1 -0
- package/dist/transform/write/blocks.js +78 -0
- package/dist/transform/write/blocks.js.map +1 -0
- package/dist/transform/write/index.d.ts +15 -0
- package/dist/transform/write/index.d.ts.map +1 -0
- package/dist/transform/write/index.js +51 -0
- package/dist/transform/write/index.js.map +1 -0
- package/dist/transform/write/numbers.d.ts +8 -0
- package/dist/transform/write/numbers.d.ts.map +1 -0
- package/dist/transform/write/numbers.js +11 -0
- package/dist/transform/write/numbers.js.map +1 -0
- package/dist/transform/write/relationships.d.ts +10 -0
- package/dist/transform/write/relationships.d.ts.map +1 -0
- package/dist/transform/write/relationships.js +27 -0
- package/dist/transform/write/relationships.js.map +1 -0
- package/dist/transform/write/selects.d.ts +8 -0
- package/dist/transform/write/selects.d.ts.map +1 -0
- package/dist/transform/write/selects.js +20 -0
- package/dist/transform/write/selects.js.map +1 -0
- package/dist/transform/write/texts.d.ts +8 -0
- package/dist/transform/write/texts.d.ts.map +1 -0
- package/dist/transform/write/texts.js +11 -0
- package/dist/transform/write/texts.js.map +1 -0
- package/dist/transform/write/traverseFields.d.ts +68 -0
- package/dist/transform/write/traverseFields.d.ts.map +1 -0
- package/dist/transform/write/traverseFields.js +661 -0
- package/dist/transform/write/traverseFields.js.map +1 -0
- package/dist/transform/write/types.d.ts +71 -0
- package/dist/transform/write/types.d.ts.map +1 -0
- package/dist/transform/write/types.js +3 -0
- package/dist/transform/write/types.js.map +1 -0
- package/dist/types.d.ts +355 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/updateGlobal.d.ts +4 -0
- package/dist/updateGlobal.d.ts.map +1 -0
- package/dist/updateGlobal.js +34 -0
- package/dist/updateGlobal.js.map +1 -0
- package/dist/updateGlobalVersion.d.ts +4 -0
- package/dist/updateGlobalVersion.d.ts.map +1 -0
- package/dist/updateGlobalVersion.js +44 -0
- package/dist/updateGlobalVersion.js.map +1 -0
- package/dist/updateJobs.d.ts +3 -0
- package/dist/updateJobs.d.ts.map +1 -0
- package/dist/updateJobs.js +84 -0
- package/dist/updateJobs.js.map +1 -0
- package/dist/updateMany.d.ts +3 -0
- package/dist/updateMany.d.ts.map +1 -0
- package/dist/updateMany.js +76 -0
- package/dist/updateMany.js.map +1 -0
- package/dist/updateOne.d.ts +3 -0
- package/dist/updateOne.d.ts.map +1 -0
- package/dist/updateOne.js +69 -0
- package/dist/updateOne.js.map +1 -0
- package/dist/updateVersion.d.ts +4 -0
- package/dist/updateVersion.d.ts.map +1 -0
- package/dist/updateVersion.js +45 -0
- package/dist/updateVersion.js.map +1 -0
- package/dist/upsert.d.ts +3 -0
- package/dist/upsert.d.ts.map +1 -0
- package/dist/upsert.js +17 -0
- package/dist/upsert.js.map +1 -0
- package/dist/upsertRow/deleteExistingArrayRows.d.ts +10 -0
- package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +1 -0
- package/dist/upsertRow/deleteExistingArrayRows.js +14 -0
- package/dist/upsertRow/deleteExistingArrayRows.js.map +1 -0
- package/dist/upsertRow/deleteExistingRowsByPath.d.ts +14 -0
- package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +1 -0
- package/dist/upsertRow/deleteExistingRowsByPath.js +45 -0
- package/dist/upsertRow/deleteExistingRowsByPath.js.map +1 -0
- package/dist/upsertRow/handleUpsertError.d.ts +19 -0
- package/dist/upsertRow/handleUpsertError.d.ts.map +1 -0
- package/dist/upsertRow/handleUpsertError.js +66 -0
- package/dist/upsertRow/handleUpsertError.js.map +1 -0
- package/dist/upsertRow/handleUpsertError.spec.js +42 -0
- package/dist/upsertRow/handleUpsertError.spec.js.map +1 -0
- package/dist/upsertRow/index.d.ts +11 -0
- package/dist/upsertRow/index.d.ts.map +1 -0
- package/dist/upsertRow/index.js +668 -0
- package/dist/upsertRow/index.js.map +1 -0
- package/dist/upsertRow/insertArrays.d.ts +14 -0
- package/dist/upsertRow/insertArrays.d.ts.map +1 -0
- package/dist/upsertRow/insertArrays.js +87 -0
- package/dist/upsertRow/insertArrays.js.map +1 -0
- package/dist/upsertRow/shouldUseOptimizedUpsertRow.d.ts +10 -0
- package/dist/upsertRow/shouldUseOptimizedUpsertRow.d.ts.map +1 -0
- package/dist/upsertRow/shouldUseOptimizedUpsertRow.js +63 -0
- package/dist/upsertRow/shouldUseOptimizedUpsertRow.js.map +1 -0
- package/dist/upsertRow/types.d.ts +47 -0
- package/dist/upsertRow/types.d.ts.map +1 -0
- package/dist/upsertRow/types.js +3 -0
- package/dist/upsertRow/types.js.map +1 -0
- package/dist/utilities/appendPrefixToKeys.d.ts +2 -0
- package/dist/utilities/appendPrefixToKeys.d.ts.map +1 -0
- package/dist/utilities/appendPrefixToKeys.js +6 -0
- package/dist/utilities/appendPrefixToKeys.js.map +1 -0
- package/dist/utilities/blocksToJsonMigrator.d.ts +15 -0
- package/dist/utilities/blocksToJsonMigrator.d.ts.map +1 -0
- package/dist/utilities/blocksToJsonMigrator.js +587 -0
- package/dist/utilities/blocksToJsonMigrator.js.map +1 -0
- package/dist/utilities/buildCreateMigration.d.ts +10 -0
- package/dist/utilities/buildCreateMigration.d.ts.map +1 -0
- package/dist/utilities/buildCreateMigration.js +121 -0
- package/dist/utilities/buildCreateMigration.js.map +1 -0
- package/dist/utilities/buildForeignKeyName.d.ts +7 -0
- package/dist/utilities/buildForeignKeyName.d.ts.map +1 -0
- package/dist/utilities/buildForeignKeyName.js +18 -0
- package/dist/utilities/buildForeignKeyName.js.map +1 -0
- package/dist/utilities/buildIndexName.d.ts +8 -0
- package/dist/utilities/buildIndexName.d.ts.map +1 -0
- package/dist/utilities/buildIndexName.js +19 -0
- package/dist/utilities/buildIndexName.js.map +1 -0
- package/dist/utilities/createBlocksMap.d.ts +5 -0
- package/dist/utilities/createBlocksMap.d.ts.map +1 -0
- package/dist/utilities/createBlocksMap.js +35 -0
- package/dist/utilities/createBlocksMap.js.map +1 -0
- package/dist/utilities/createRelationshipMap.d.ts +2 -0
- package/dist/utilities/createRelationshipMap.d.ts.map +1 -0
- package/dist/utilities/createRelationshipMap.js +21 -0
- package/dist/utilities/createRelationshipMap.js.map +1 -0
- package/dist/utilities/createSchemaGenerator.d.ts +11 -0
- package/dist/utilities/createSchemaGenerator.d.ts.map +1 -0
- package/dist/utilities/createSchemaGenerator.js +257 -0
- package/dist/utilities/createSchemaGenerator.js.map +1 -0
- package/dist/utilities/escapeSQLValue.d.ts +3 -0
- package/dist/utilities/escapeSQLValue.d.ts.map +1 -0
- package/dist/utilities/escapeSQLValue.js +20 -0
- package/dist/utilities/escapeSQLValue.js.map +1 -0
- 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/getArrayRelationName.d.ts +7 -0
- package/dist/utilities/getArrayRelationName.d.ts.map +1 -0
- package/dist/utilities/getArrayRelationName.js +8 -0
- package/dist/utilities/getArrayRelationName.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 +12 -0
- package/dist/utilities/getCollectionIdType.js.map +1 -0
- package/dist/utilities/getMigrationTemplate.d.ts +4 -0
- package/dist/utilities/getMigrationTemplate.d.ts.map +1 -0
- package/dist/utilities/getMigrationTemplate.js +13 -0
- package/dist/utilities/getMigrationTemplate.js.map +1 -0
- package/dist/utilities/getNameFromDrizzleTable.d.ts +3 -0
- package/dist/utilities/getNameFromDrizzleTable.d.ts.map +1 -0
- package/dist/utilities/getNameFromDrizzleTable.js +6 -0
- package/dist/utilities/getNameFromDrizzleTable.js.map +1 -0
- package/dist/utilities/getPrimaryDb.d.ts +6 -0
- package/dist/utilities/getPrimaryDb.d.ts.map +1 -0
- package/dist/utilities/getPrimaryDb.js +10 -0
- package/dist/utilities/getPrimaryDb.js.map +1 -0
- package/dist/utilities/getTransaction.d.ts +13 -0
- package/dist/utilities/getTransaction.d.ts.map +1 -0
- package/dist/utilities/getTransaction.js +20 -0
- package/dist/utilities/getTransaction.js.map +1 -0
- package/dist/utilities/hasLocalesTable.d.ts +9 -0
- package/dist/utilities/hasLocalesTable.d.ts.map +1 -0
- package/dist/utilities/hasLocalesTable.js +30 -0
- package/dist/utilities/hasLocalesTable.js.map +1 -0
- package/dist/utilities/isArrayOfRows.d.ts +2 -0
- package/dist/utilities/isArrayOfRows.d.ts.map +1 -0
- package/dist/utilities/isArrayOfRows.js +5 -0
- package/dist/utilities/isArrayOfRows.js.map +1 -0
- 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/isUUIDType.d.ts +2 -0
- package/dist/utilities/isUUIDType.d.ts.map +1 -0
- package/dist/utilities/isUUIDType.js +3 -0
- package/dist/utilities/isUUIDType.js.map +1 -0
- package/dist/utilities/isValidStringID.d.ts +2 -0
- package/dist/utilities/isValidStringID.d.ts.map +1 -0
- package/dist/utilities/isValidStringID.js +5 -0
- package/dist/utilities/isValidStringID.js.map +1 -0
- package/dist/utilities/isValidStringID.spec.js +15 -0
- package/dist/utilities/isValidStringID.spec.js.map +1 -0
- package/dist/utilities/json.d.ts +9 -0
- package/dist/utilities/json.d.ts.map +1 -0
- package/dist/utilities/json.js +33 -0
- package/dist/utilities/json.js.map +1 -0
- package/dist/utilities/migrationTableExists.d.ts +4 -0
- package/dist/utilities/migrationTableExists.d.ts.map +1 -0
- package/dist/utilities/migrationTableExists.js +25 -0
- package/dist/utilities/migrationTableExists.js.map +1 -0
- package/dist/utilities/parseError.d.ts +5 -0
- package/dist/utilities/parseError.d.ts.map +1 -0
- package/dist/utilities/parseError.js +15 -0
- package/dist/utilities/parseError.js.map +1 -0
- package/dist/utilities/pushDevSchema.d.ts +9 -0
- package/dist/utilities/pushDevSchema.d.ts.map +1 -0
- package/dist/utilities/pushDevSchema.js +83 -0
- package/dist/utilities/pushDevSchema.js.map +1 -0
- package/dist/utilities/rawConstraint.d.ts +10 -0
- package/dist/utilities/rawConstraint.d.ts.map +1 -0
- package/dist/utilities/rawConstraint.js +13 -0
- package/dist/utilities/rawConstraint.js.map +1 -0
- package/dist/utilities/readAfterWrite.d.ts +17 -0
- package/dist/utilities/readAfterWrite.d.ts.map +1 -0
- package/dist/utilities/readAfterWrite.js +21 -0
- package/dist/utilities/readAfterWrite.js.map +1 -0
- package/dist/utilities/sanitizePathSegment.d.ts +2 -0
- package/dist/utilities/sanitizePathSegment.d.ts.map +1 -0
- package/dist/utilities/sanitizePathSegment.js +14 -0
- package/dist/utilities/sanitizePathSegment.js.map +1 -0
- package/dist/utilities/validateExistingBlockIsIdentical.d.ts +22 -0
- package/dist/utilities/validateExistingBlockIsIdentical.d.ts.map +1 -0
- package/dist/utilities/validateExistingBlockIsIdentical.js +100 -0
- package/dist/utilities/validateExistingBlockIsIdentical.js.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,793 @@
|
|
|
1
|
+
import { and, eq, getTableName, like, sql } from 'drizzle-orm';
|
|
2
|
+
import { APIError, getFieldByPath } from '@hanzo/cms';
|
|
3
|
+
import { fieldShouldBeLocalized, tabHasName } from '@hanzo/cms/shared';
|
|
4
|
+
import toSnakeCase from 'to-snake-case';
|
|
5
|
+
import { validate as uuidValidate } from 'uuid';
|
|
6
|
+
import { isPolymorphicRelationship } from '../utilities/isPolymorphicRelationship.js';
|
|
7
|
+
import { isUUIDType } from '../utilities/isUUIDType.js';
|
|
8
|
+
import { jsonBuildObject } from '../utilities/json.js';
|
|
9
|
+
import { DistinctSymbol } from '../utilities/rawConstraint.js';
|
|
10
|
+
import { resolveBlockTableName } from '../utilities/validateExistingBlockIsIdentical.js';
|
|
11
|
+
import { addJoinTable } from './addJoinTable.js';
|
|
12
|
+
import { getTableAlias } from './getTableAlias.js';
|
|
13
|
+
/**
|
|
14
|
+
* Transforms path to table and column name or to a list of OR columns
|
|
15
|
+
* Adds tables to `join`
|
|
16
|
+
* @returns TableColumn
|
|
17
|
+
*/ export const getTableColumnFromPath = ({ adapter, aliasTable, collectionPath, columnPrefix = '', constraintPath: incomingConstraintPath, constraints = [], fields, joins, locale: incomingLocale, parentAliasTable, parentIsLocalized, pathSegments: incomingSegments, rootTableName: incomingRootTableName, selectFields, selectLocale, tableName, tableNameSuffix = '', value })=>{
|
|
18
|
+
const fieldPath = incomingSegments[0];
|
|
19
|
+
let locale = incomingLocale;
|
|
20
|
+
const rootTableName = incomingRootTableName || tableName;
|
|
21
|
+
let constraintPath = incomingConstraintPath || '';
|
|
22
|
+
const field = fields.find((fieldToFind)=>fieldToFind.name === fieldPath);
|
|
23
|
+
let newTableName = tableName;
|
|
24
|
+
if (!field && fieldPath === 'id') {
|
|
25
|
+
selectFields.id = adapter.tables[newTableName].id;
|
|
26
|
+
return {
|
|
27
|
+
columnName: 'id',
|
|
28
|
+
constraints,
|
|
29
|
+
field: {
|
|
30
|
+
name: 'id',
|
|
31
|
+
type: isUUIDType(adapter.idType) ? 'text' : 'number'
|
|
32
|
+
},
|
|
33
|
+
table: adapter.tables[newTableName]
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
let localizedPathQuery = false;
|
|
37
|
+
if (field) {
|
|
38
|
+
const pathSegments = [
|
|
39
|
+
...incomingSegments
|
|
40
|
+
];
|
|
41
|
+
const isFieldLocalized = fieldShouldBeLocalized({
|
|
42
|
+
field,
|
|
43
|
+
parentIsLocalized
|
|
44
|
+
});
|
|
45
|
+
// If next segment is a locale,
|
|
46
|
+
// we need to take it out and use it as the locale from this point on
|
|
47
|
+
if (isFieldLocalized && adapter.cms.config.localization) {
|
|
48
|
+
const matchedLocale = adapter.cms.config.localization.localeCodes.find((locale)=>locale === pathSegments[1]);
|
|
49
|
+
if (matchedLocale) {
|
|
50
|
+
locale = matchedLocale;
|
|
51
|
+
localizedPathQuery = true;
|
|
52
|
+
pathSegments.splice(1, 1);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
switch(field.type){
|
|
56
|
+
case 'array':
|
|
57
|
+
{
|
|
58
|
+
newTableName = adapter.tableNameMap.get(`${tableName}_${tableNameSuffix}${toSnakeCase(field.name)}`);
|
|
59
|
+
const arrayParentTable = aliasTable || adapter.tables[tableName];
|
|
60
|
+
constraintPath = `${constraintPath}${field.name}.%.`;
|
|
61
|
+
if (locale && isFieldLocalized && adapter.cms.config.localization) {
|
|
62
|
+
const conditions = [
|
|
63
|
+
eq(arrayParentTable.id, adapter.tables[newTableName]._parentID)
|
|
64
|
+
];
|
|
65
|
+
if (selectLocale) {
|
|
66
|
+
selectFields._locale = adapter.tables[newTableName]._locale;
|
|
67
|
+
}
|
|
68
|
+
if (locale !== 'all') {
|
|
69
|
+
conditions.push(eq(adapter.tables[newTableName]._locale, locale));
|
|
70
|
+
}
|
|
71
|
+
addJoinTable({
|
|
72
|
+
condition: and(...conditions),
|
|
73
|
+
isOneToMany: true,
|
|
74
|
+
joins,
|
|
75
|
+
table: adapter.tables[newTableName]
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
addJoinTable({
|
|
79
|
+
condition: eq(arrayParentTable.id, adapter.tables[newTableName]._parentID),
|
|
80
|
+
isOneToMany: true,
|
|
81
|
+
joins,
|
|
82
|
+
table: adapter.tables[newTableName]
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return getTableColumnFromPath({
|
|
86
|
+
adapter,
|
|
87
|
+
collectionPath,
|
|
88
|
+
constraintPath,
|
|
89
|
+
constraints,
|
|
90
|
+
fields: field.flattenedFields,
|
|
91
|
+
joins,
|
|
92
|
+
locale,
|
|
93
|
+
parentAliasTable: aliasTable,
|
|
94
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
95
|
+
pathSegments: pathSegments.slice(1),
|
|
96
|
+
rootTableName,
|
|
97
|
+
selectFields,
|
|
98
|
+
selectLocale,
|
|
99
|
+
tableName: newTableName,
|
|
100
|
+
value
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
case 'blocks':
|
|
104
|
+
{
|
|
105
|
+
if (adapter.blocksAsJSON) {
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
let blockTableColumn;
|
|
109
|
+
let newTableName;
|
|
110
|
+
// handle blockType queries
|
|
111
|
+
if (pathSegments[1] === 'blockType') {
|
|
112
|
+
// find the block config using the value
|
|
113
|
+
const blockTypes = Array.isArray(value) ? value : [
|
|
114
|
+
value
|
|
115
|
+
];
|
|
116
|
+
blockTypes.forEach((blockType)=>{
|
|
117
|
+
const block = adapter.cms.blocks[blockType] ?? (field.blockReferences ?? field.blocks).find((block)=>typeof block !== 'string' && block.slug === blockType);
|
|
118
|
+
newTableName = resolveBlockTableName(block, adapter.tableNameMap.get(`${tableName}_blocks_${toSnakeCase(block.slug)}`));
|
|
119
|
+
const { newAliasTable } = getTableAlias({
|
|
120
|
+
adapter,
|
|
121
|
+
tableName: newTableName
|
|
122
|
+
});
|
|
123
|
+
joins.push({
|
|
124
|
+
condition: eq(adapter.tables[tableName].id, newAliasTable._parentID),
|
|
125
|
+
table: newAliasTable
|
|
126
|
+
});
|
|
127
|
+
constraints.push({
|
|
128
|
+
columnName: '_path',
|
|
129
|
+
table: newAliasTable,
|
|
130
|
+
value: `${constraintPath}${pathSegments[0]}`
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
return {
|
|
134
|
+
constraints,
|
|
135
|
+
field,
|
|
136
|
+
getNotNullColumnByValue: ()=>'id',
|
|
137
|
+
table: adapter.tables[tableName]
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const hasBlockField = (field.blockReferences ?? field.blocks).some((_block)=>{
|
|
141
|
+
const block = typeof _block === 'string' ? adapter.cms.blocks[_block] : _block;
|
|
142
|
+
newTableName = resolveBlockTableName(block, adapter.tableNameMap.get(`${tableName}_blocks_${toSnakeCase(block.slug)}`));
|
|
143
|
+
constraintPath = `${constraintPath}${field.name}.%.`;
|
|
144
|
+
let result;
|
|
145
|
+
const blockConstraints = [];
|
|
146
|
+
const blockSelectFields = {};
|
|
147
|
+
let blockJoin;
|
|
148
|
+
if (isFieldLocalized && adapter.cms.config.localization) {
|
|
149
|
+
const conditions = [
|
|
150
|
+
eq((aliasTable || adapter.tables[tableName]).id, adapter.tables[newTableName]._parentID)
|
|
151
|
+
];
|
|
152
|
+
if (locale !== 'all') {
|
|
153
|
+
conditions.push(eq(adapter.tables[newTableName]._locale, locale));
|
|
154
|
+
}
|
|
155
|
+
blockJoin = {
|
|
156
|
+
condition: and(...conditions),
|
|
157
|
+
table: adapter.tables[newTableName]
|
|
158
|
+
};
|
|
159
|
+
} else {
|
|
160
|
+
blockJoin = {
|
|
161
|
+
condition: eq((aliasTable || adapter.tables[tableName]).id, adapter.tables[newTableName]._parentID),
|
|
162
|
+
table: adapter.tables[newTableName]
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
// Create a new reference for nested joins
|
|
166
|
+
const newJoins = [
|
|
167
|
+
...joins
|
|
168
|
+
];
|
|
169
|
+
try {
|
|
170
|
+
result = getTableColumnFromPath({
|
|
171
|
+
adapter,
|
|
172
|
+
collectionPath,
|
|
173
|
+
constraintPath,
|
|
174
|
+
constraints: blockConstraints,
|
|
175
|
+
fields: block.flattenedFields,
|
|
176
|
+
joins: newJoins,
|
|
177
|
+
locale,
|
|
178
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
179
|
+
pathSegments: pathSegments.slice(1),
|
|
180
|
+
rootTableName,
|
|
181
|
+
selectFields: blockSelectFields,
|
|
182
|
+
selectLocale,
|
|
183
|
+
tableName: newTableName,
|
|
184
|
+
value
|
|
185
|
+
});
|
|
186
|
+
} catch (_) {
|
|
187
|
+
// this is fine, not every block will have the field
|
|
188
|
+
}
|
|
189
|
+
if (!result) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
blockTableColumn = result;
|
|
193
|
+
constraints = constraints.concat(blockConstraints);
|
|
194
|
+
selectFields = {
|
|
195
|
+
...selectFields,
|
|
196
|
+
...blockSelectFields
|
|
197
|
+
};
|
|
198
|
+
const previousLength = joins.length;
|
|
199
|
+
joins.push(blockJoin);
|
|
200
|
+
// Append new joins AFTER the block join to prevent errors with missing FROM clause.
|
|
201
|
+
if (newJoins.length > previousLength) {
|
|
202
|
+
for(let i = previousLength; i < newJoins.length; i++){
|
|
203
|
+
joins.push(newJoins[i]);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return true;
|
|
207
|
+
});
|
|
208
|
+
if (hasBlockField) {
|
|
209
|
+
return {
|
|
210
|
+
columnName: blockTableColumn.columnName,
|
|
211
|
+
constraints,
|
|
212
|
+
field: blockTableColumn.field,
|
|
213
|
+
pathSegments: pathSegments.slice(1),
|
|
214
|
+
rawColumn: blockTableColumn.rawColumn,
|
|
215
|
+
table: blockTableColumn.table
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
case 'group':
|
|
221
|
+
{
|
|
222
|
+
if (locale && isFieldLocalized && adapter.cms.config.localization) {
|
|
223
|
+
newTableName = `${tableName}${adapter.localesSuffix}`;
|
|
224
|
+
let condition = eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID);
|
|
225
|
+
if (locale !== 'all') {
|
|
226
|
+
condition = and(condition, eq(adapter.tables[newTableName]._locale, locale));
|
|
227
|
+
}
|
|
228
|
+
addJoinTable({
|
|
229
|
+
condition,
|
|
230
|
+
joins,
|
|
231
|
+
table: adapter.tables[newTableName]
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
return getTableColumnFromPath({
|
|
235
|
+
adapter,
|
|
236
|
+
aliasTable,
|
|
237
|
+
collectionPath,
|
|
238
|
+
columnPrefix: `${columnPrefix}${field.name}_`,
|
|
239
|
+
constraintPath: `${constraintPath}${field.name}.`,
|
|
240
|
+
constraints,
|
|
241
|
+
fields: field.flattenedFields,
|
|
242
|
+
joins,
|
|
243
|
+
locale,
|
|
244
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
245
|
+
pathSegments: pathSegments.slice(1),
|
|
246
|
+
rootTableName,
|
|
247
|
+
selectFields,
|
|
248
|
+
selectLocale,
|
|
249
|
+
tableName: newTableName,
|
|
250
|
+
tableNameSuffix: `${tableNameSuffix}${toSnakeCase(field.name)}_`,
|
|
251
|
+
value
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
case 'join':
|
|
255
|
+
{
|
|
256
|
+
if (Array.isArray(field.collection)) {
|
|
257
|
+
throw new APIError('Not supported');
|
|
258
|
+
}
|
|
259
|
+
const newCollectionPath = pathSegments.slice(1).join('.');
|
|
260
|
+
if (field.hasMany) {
|
|
261
|
+
const relationTableName = `${adapter.tableNameMap.get(toSnakeCase(field.collection))}${adapter.relationshipsSuffix}`;
|
|
262
|
+
const existingTable = joins.find((e)=>e.queryPath === `${constraintPath}${field.name}._rels`);
|
|
263
|
+
const aliasRelationshipTable = existingTable?.table ?? getTableAlias({
|
|
264
|
+
adapter,
|
|
265
|
+
tableName: relationTableName
|
|
266
|
+
}).newAliasTable;
|
|
267
|
+
const relationshipField = getFieldByPath({
|
|
268
|
+
fields: adapter.cms.collections[field.collection].config.flattenedFields,
|
|
269
|
+
path: field.on
|
|
270
|
+
});
|
|
271
|
+
if (!relationshipField) {
|
|
272
|
+
throw new APIError('Relationship was not found');
|
|
273
|
+
}
|
|
274
|
+
if (!existingTable) {
|
|
275
|
+
addJoinTable({
|
|
276
|
+
condition: and(eq(adapter.tables[rootTableName].id, aliasRelationshipTable[`${relationshipField.field.relationTo}ID`]), like(aliasRelationshipTable.path, field.on)),
|
|
277
|
+
joins,
|
|
278
|
+
queryPath: `${constraintPath}${field.name}._rels`,
|
|
279
|
+
table: aliasRelationshipTable
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
if (newCollectionPath === 'id') {
|
|
283
|
+
return {
|
|
284
|
+
columnName: 'parent',
|
|
285
|
+
constraints,
|
|
286
|
+
field: {
|
|
287
|
+
name: 'id',
|
|
288
|
+
type: isUUIDType(adapter.idType) ? 'text' : 'number'
|
|
289
|
+
},
|
|
290
|
+
table: aliasRelationshipTable
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
const relationshipConfig = adapter.cms.collections[field.collection].config;
|
|
294
|
+
const relationshipTableName = adapter.tableNameMap.get(toSnakeCase(relationshipConfig.slug));
|
|
295
|
+
// parent to relationship join table
|
|
296
|
+
const relationshipFields = relationshipConfig.flattenedFields;
|
|
297
|
+
const existingMainTable = joins.find((e)=>e.queryPath === `${constraintPath}${field.name}`);
|
|
298
|
+
const relationshipTable = existingMainTable?.table ?? getTableAlias({
|
|
299
|
+
adapter,
|
|
300
|
+
tableName: relationshipTableName
|
|
301
|
+
}).newAliasTable;
|
|
302
|
+
if (!existingMainTable) {
|
|
303
|
+
joins.push({
|
|
304
|
+
condition: eq(aliasRelationshipTable.parent, relationshipTable.id),
|
|
305
|
+
queryPath: `${constraintPath}${field.name}`,
|
|
306
|
+
table: relationshipTable
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
return getTableColumnFromPath({
|
|
310
|
+
adapter,
|
|
311
|
+
aliasTable: relationshipTable,
|
|
312
|
+
collectionPath: newCollectionPath,
|
|
313
|
+
constraints,
|
|
314
|
+
// relationshipFields are fields from a different collection => no parentIsLocalized
|
|
315
|
+
fields: relationshipFields,
|
|
316
|
+
joins,
|
|
317
|
+
locale,
|
|
318
|
+
parentIsLocalized: false,
|
|
319
|
+
pathSegments: pathSegments.slice(1),
|
|
320
|
+
rootTableName: relationshipTableName,
|
|
321
|
+
selectFields,
|
|
322
|
+
selectLocale,
|
|
323
|
+
tableName: relationshipTableName,
|
|
324
|
+
value
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
const newTableName = adapter.tableNameMap.get(toSnakeCase(adapter.cms.collections[field.collection].config.slug));
|
|
328
|
+
const existingTable = joins.find((e)=>e.queryPath === `${constraintPath}${field.name}`)?.table;
|
|
329
|
+
const newAliasTable = existingTable || getTableAlias({
|
|
330
|
+
adapter,
|
|
331
|
+
tableName: newTableName
|
|
332
|
+
}).newAliasTable;
|
|
333
|
+
if (!existingTable) {
|
|
334
|
+
const onSegments = field.on.split('.');
|
|
335
|
+
const collectionFlattenedFields = adapter.cms.collections[field.collection].config.flattenedFields;
|
|
336
|
+
const firstSegField = onSegments.length > 1 ? collectionFlattenedFields.find((f)=>f.name === onSegments[0]) : null;
|
|
337
|
+
const arrayTableName = firstSegField?.type === 'array' ? adapter.tableNameMap.get(`${newTableName}_${toSnakeCase(onSegments[0])}`) : undefined;
|
|
338
|
+
if (arrayTableName) {
|
|
339
|
+
// join from main table to array table
|
|
340
|
+
const { newAliasTable: arrayAliasTable } = getTableAlias({
|
|
341
|
+
adapter,
|
|
342
|
+
tableName: arrayTableName
|
|
343
|
+
});
|
|
344
|
+
joins.push({
|
|
345
|
+
condition: eq(arrayAliasTable[onSegments.slice(1).join('_')], aliasTable ? aliasTable.id : adapter.tables[tableName].id),
|
|
346
|
+
queryPath: `${constraintPath}${field.name}._array`,
|
|
347
|
+
table: arrayAliasTable
|
|
348
|
+
});
|
|
349
|
+
joins.push({
|
|
350
|
+
condition: eq(newAliasTable.id, arrayAliasTable._parentID),
|
|
351
|
+
queryPath: `${constraintPath}${field.name}`,
|
|
352
|
+
table: newAliasTable
|
|
353
|
+
});
|
|
354
|
+
} else {
|
|
355
|
+
joins.push({
|
|
356
|
+
condition: eq(newAliasTable[field.on.replaceAll('.', '_')], aliasTable ? aliasTable.id : adapter.tables[tableName].id),
|
|
357
|
+
queryPath: `${constraintPath}${field.name}`,
|
|
358
|
+
table: newAliasTable
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (newCollectionPath === 'id') {
|
|
363
|
+
return {
|
|
364
|
+
columnName: 'id',
|
|
365
|
+
constraints,
|
|
366
|
+
field: {
|
|
367
|
+
name: 'id',
|
|
368
|
+
type: isUUIDType(adapter.idType) ? 'text' : 'number'
|
|
369
|
+
},
|
|
370
|
+
table: newAliasTable
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
return getTableColumnFromPath({
|
|
374
|
+
adapter,
|
|
375
|
+
aliasTable: newAliasTable,
|
|
376
|
+
collectionPath: newCollectionPath,
|
|
377
|
+
constraintPath: '',
|
|
378
|
+
constraints,
|
|
379
|
+
fields: adapter.cms.collections[field.collection].config.flattenedFields,
|
|
380
|
+
joins,
|
|
381
|
+
locale,
|
|
382
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
383
|
+
pathSegments: pathSegments.slice(1),
|
|
384
|
+
selectFields,
|
|
385
|
+
tableName: newTableName,
|
|
386
|
+
value
|
|
387
|
+
});
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
390
|
+
case 'number':
|
|
391
|
+
case 'text':
|
|
392
|
+
{
|
|
393
|
+
if (field.hasMany) {
|
|
394
|
+
let tableType = 'texts';
|
|
395
|
+
let columnName = 'text';
|
|
396
|
+
if (field.type === 'number') {
|
|
397
|
+
tableType = 'numbers';
|
|
398
|
+
columnName = 'number';
|
|
399
|
+
}
|
|
400
|
+
newTableName = `${rootTableName}_${tableType}`;
|
|
401
|
+
const existingTable = joins.find((e)=>e.queryPath === `${constraintPath}${field.name}`);
|
|
402
|
+
const table = existingTable?.table ?? getTableAlias({
|
|
403
|
+
adapter,
|
|
404
|
+
tableName: newTableName
|
|
405
|
+
}).newAliasTable;
|
|
406
|
+
const joinConstraints = [
|
|
407
|
+
eq(adapter.tables[rootTableName].id, table.parent),
|
|
408
|
+
like(table.path, `${constraintPath}${field.name}`)
|
|
409
|
+
];
|
|
410
|
+
if (locale && isFieldLocalized && adapter.cms.config.localization) {
|
|
411
|
+
const conditions = [
|
|
412
|
+
...joinConstraints
|
|
413
|
+
];
|
|
414
|
+
if (locale !== 'all') {
|
|
415
|
+
conditions.push(eq(table._locale, locale));
|
|
416
|
+
}
|
|
417
|
+
addJoinTable({
|
|
418
|
+
condition: and(...conditions),
|
|
419
|
+
joins,
|
|
420
|
+
queryPath: `${constraintPath}${field.name}`,
|
|
421
|
+
table
|
|
422
|
+
});
|
|
423
|
+
} else {
|
|
424
|
+
addJoinTable({
|
|
425
|
+
condition: and(...joinConstraints),
|
|
426
|
+
joins,
|
|
427
|
+
queryPath: `${constraintPath}${field.name}`,
|
|
428
|
+
table
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
return {
|
|
432
|
+
columnName,
|
|
433
|
+
constraints,
|
|
434
|
+
field,
|
|
435
|
+
table
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
break;
|
|
439
|
+
}
|
|
440
|
+
case 'relationship':
|
|
441
|
+
case 'upload':
|
|
442
|
+
{
|
|
443
|
+
const newCollectionPath = pathSegments.slice(1).join('.');
|
|
444
|
+
if (Array.isArray(field.relationTo) || field.hasMany) {
|
|
445
|
+
let relationshipFields;
|
|
446
|
+
const relationTableName = `${rootTableName}${adapter.relationshipsSuffix}`;
|
|
447
|
+
const existingJoin = joins.find((e)=>e.queryPath === `${constraintPath}.${field.name}`);
|
|
448
|
+
let aliasRelationshipTable;
|
|
449
|
+
let aliasRelationshipTableName;
|
|
450
|
+
if (existingJoin) {
|
|
451
|
+
aliasRelationshipTable = existingJoin.table;
|
|
452
|
+
aliasRelationshipTableName = getTableName(existingJoin.table);
|
|
453
|
+
} else {
|
|
454
|
+
const res = getTableAlias({
|
|
455
|
+
adapter,
|
|
456
|
+
tableName: relationTableName
|
|
457
|
+
});
|
|
458
|
+
aliasRelationshipTable = res.newAliasTable;
|
|
459
|
+
aliasRelationshipTableName = res.newAliasTableName;
|
|
460
|
+
}
|
|
461
|
+
if (selectLocale && isFieldLocalized && adapter.cms.config.localization) {
|
|
462
|
+
selectFields._locale = aliasRelationshipTable.locale;
|
|
463
|
+
}
|
|
464
|
+
// Join in the relationships table
|
|
465
|
+
if (locale && isFieldLocalized && adapter.cms.config.localization) {
|
|
466
|
+
const conditions = [
|
|
467
|
+
eq((parentAliasTable || aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent),
|
|
468
|
+
like(aliasRelationshipTable.path, `${constraintPath}${field.name}`)
|
|
469
|
+
];
|
|
470
|
+
if (locale !== 'all') {
|
|
471
|
+
conditions.push(eq(aliasRelationshipTable.locale, locale));
|
|
472
|
+
}
|
|
473
|
+
addJoinTable({
|
|
474
|
+
condition: and(...conditions),
|
|
475
|
+
joins,
|
|
476
|
+
queryPath: `${constraintPath}.${field.name}`,
|
|
477
|
+
table: aliasRelationshipTable
|
|
478
|
+
});
|
|
479
|
+
} else {
|
|
480
|
+
// Join in the relationships table
|
|
481
|
+
addJoinTable({
|
|
482
|
+
condition: and(eq((parentAliasTable || aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent), like(aliasRelationshipTable.path, `${constraintPath}${field.name}`)),
|
|
483
|
+
joins,
|
|
484
|
+
queryPath: `${constraintPath}.${field.name}`,
|
|
485
|
+
table: aliasRelationshipTable
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
selectFields[`${relationTableName}.path`] = aliasRelationshipTable.path;
|
|
489
|
+
let newAliasTable;
|
|
490
|
+
if (typeof field.relationTo === 'string') {
|
|
491
|
+
const relationshipConfig = adapter.cms.collections[field.relationTo].config;
|
|
492
|
+
newTableName = adapter.tableNameMap.get(toSnakeCase(relationshipConfig.slug));
|
|
493
|
+
// parent to relationship join table
|
|
494
|
+
relationshipFields = relationshipConfig.flattenedFields;
|
|
495
|
+
({ newAliasTable } = getTableAlias({
|
|
496
|
+
adapter,
|
|
497
|
+
tableName: newTableName
|
|
498
|
+
}));
|
|
499
|
+
joins.push({
|
|
500
|
+
condition: eq(newAliasTable.id, aliasRelationshipTable[`${field.relationTo}ID`]),
|
|
501
|
+
table: newAliasTable
|
|
502
|
+
});
|
|
503
|
+
if (newCollectionPath === '' || newCollectionPath === 'id') {
|
|
504
|
+
return {
|
|
505
|
+
columnName: `${field.relationTo}ID`,
|
|
506
|
+
constraints,
|
|
507
|
+
field,
|
|
508
|
+
table: aliasRelationshipTable
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
} else if (newCollectionPath === 'value') {
|
|
512
|
+
const hasCustomCollectionWithCustomID = field.relationTo.some((relationTo)=>!!adapter.cms.collections[relationTo].customIDType);
|
|
513
|
+
const columns = field.relationTo.map((relationTo)=>{
|
|
514
|
+
let idType = isUUIDType(adapter.idType) ? 'uuid' : 'number';
|
|
515
|
+
const { customIDType } = adapter.cms.collections[relationTo];
|
|
516
|
+
if (customIDType) {
|
|
517
|
+
idType = customIDType;
|
|
518
|
+
}
|
|
519
|
+
const idTypeTextOrUuid = idType === 'text' || idType === 'uuid';
|
|
520
|
+
// Do not add the column to OR if we know that it can't match by the type
|
|
521
|
+
// We can't do the same with idType: 'number' because `value` can be from the REST search query params
|
|
522
|
+
if (typeof value === 'number' && idTypeTextOrUuid) {
|
|
523
|
+
return null;
|
|
524
|
+
}
|
|
525
|
+
if (Array.isArray(value) && value.every((val)=>typeof val === 'number') && idTypeTextOrUuid) {
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
528
|
+
// Do not add the UUID type column if incoming query value doesn't match UUID. If there aren't any collections with
|
|
529
|
+
// a custom ID type, we skip this check
|
|
530
|
+
// We need this because Postgres throws an error if querying by UUID column with a value that isn't a valid UUID.
|
|
531
|
+
if (value && !Array.isArray(value) && idType === 'uuid' && hasCustomCollectionWithCustomID) {
|
|
532
|
+
if (!uuidValidate(value)) {
|
|
533
|
+
return null;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
if (Array.isArray(value) && idType === 'uuid' && hasCustomCollectionWithCustomID && !value.some((val)=>uuidValidate(val))) {
|
|
537
|
+
return null;
|
|
538
|
+
}
|
|
539
|
+
const relationTableName = adapter.tableNameMap.get(toSnakeCase(adapter.cms.collections[relationTo].config.slug));
|
|
540
|
+
return {
|
|
541
|
+
idType,
|
|
542
|
+
rawColumn: sql.raw(`"${aliasRelationshipTableName}"."${relationTableName}_id"`)
|
|
543
|
+
};
|
|
544
|
+
}).filter(Boolean);
|
|
545
|
+
return {
|
|
546
|
+
columns,
|
|
547
|
+
constraints,
|
|
548
|
+
field,
|
|
549
|
+
table: aliasRelationshipTable
|
|
550
|
+
};
|
|
551
|
+
} else if (newCollectionPath === 'relationTo') {
|
|
552
|
+
const relationTo = Array.isArray(field.relationTo) ? field.relationTo : [
|
|
553
|
+
field.relationTo
|
|
554
|
+
];
|
|
555
|
+
return {
|
|
556
|
+
constraints,
|
|
557
|
+
field,
|
|
558
|
+
getNotNullColumnByValue: (val)=>{
|
|
559
|
+
const matchedRelation = relationTo.find((relation)=>relation === val);
|
|
560
|
+
if (matchedRelation) {
|
|
561
|
+
return `${matchedRelation}ID`;
|
|
562
|
+
}
|
|
563
|
+
return undefined;
|
|
564
|
+
},
|
|
565
|
+
table: aliasRelationshipTable
|
|
566
|
+
};
|
|
567
|
+
} else if (isPolymorphicRelationship(value)) {
|
|
568
|
+
const { relationTo } = value;
|
|
569
|
+
const relationTableName = adapter.tableNameMap.get(toSnakeCase(adapter.cms.collections[relationTo].config.slug));
|
|
570
|
+
return {
|
|
571
|
+
constraints,
|
|
572
|
+
field,
|
|
573
|
+
rawColumn: sql.raw(`"${aliasRelationshipTableName}"."${relationTableName}_id"`),
|
|
574
|
+
table: aliasRelationshipTable
|
|
575
|
+
};
|
|
576
|
+
} else if (value === DistinctSymbol) {
|
|
577
|
+
const obj = {};
|
|
578
|
+
field.relationTo.forEach((relationTo)=>{
|
|
579
|
+
const relationTableName = adapter.tableNameMap.get(toSnakeCase(adapter.cms.collections[relationTo].config.slug));
|
|
580
|
+
obj[relationTo] = sql.raw(`"${aliasRelationshipTableName}"."${relationTableName}_id"`);
|
|
581
|
+
});
|
|
582
|
+
let rawColumn = jsonBuildObject(adapter, obj);
|
|
583
|
+
if (adapter.name === 'postgres') {
|
|
584
|
+
rawColumn = sql`${rawColumn}::text`;
|
|
585
|
+
}
|
|
586
|
+
return {
|
|
587
|
+
constraints,
|
|
588
|
+
field,
|
|
589
|
+
rawColumn,
|
|
590
|
+
table: aliasRelationshipTable
|
|
591
|
+
};
|
|
592
|
+
} else {
|
|
593
|
+
throw new APIError('Not supported');
|
|
594
|
+
}
|
|
595
|
+
return getTableColumnFromPath({
|
|
596
|
+
adapter,
|
|
597
|
+
aliasTable: newAliasTable,
|
|
598
|
+
collectionPath: newCollectionPath,
|
|
599
|
+
constraints,
|
|
600
|
+
// relationshipFields are fields from a different collection => no parentIsLocalized
|
|
601
|
+
fields: relationshipFields,
|
|
602
|
+
joins,
|
|
603
|
+
locale,
|
|
604
|
+
parentIsLocalized: false,
|
|
605
|
+
pathSegments: pathSegments.slice(1),
|
|
606
|
+
rootTableName: newTableName,
|
|
607
|
+
selectFields,
|
|
608
|
+
selectLocale,
|
|
609
|
+
tableName: newTableName,
|
|
610
|
+
value
|
|
611
|
+
});
|
|
612
|
+
} else if (pathSegments.length > 1 && !(pathSegments.length === 2 && pathSegments[1] === 'id')) {
|
|
613
|
+
// simple relationships
|
|
614
|
+
const columnName = `${columnPrefix}${field.name}`;
|
|
615
|
+
const newTableName = adapter.tableNameMap.get(toSnakeCase(adapter.cms.collections[field.relationTo].config.slug));
|
|
616
|
+
const { newAliasTable } = getTableAlias({
|
|
617
|
+
adapter,
|
|
618
|
+
tableName: newTableName
|
|
619
|
+
});
|
|
620
|
+
if (isFieldLocalized && adapter.cms.config.localization) {
|
|
621
|
+
const { newAliasTable: aliasLocaleTable } = getTableAlias({
|
|
622
|
+
adapter,
|
|
623
|
+
tableName: `${rootTableName}${adapter.localesSuffix}`
|
|
624
|
+
});
|
|
625
|
+
const condtions = [
|
|
626
|
+
eq(aliasLocaleTable._parentID, adapter.tables[rootTableName].id)
|
|
627
|
+
];
|
|
628
|
+
if (selectLocale) {
|
|
629
|
+
selectFields._locale = aliasLocaleTable._locale;
|
|
630
|
+
}
|
|
631
|
+
if (locale !== 'all') {
|
|
632
|
+
condtions.push(eq(aliasLocaleTable._locale, locale));
|
|
633
|
+
}
|
|
634
|
+
const localesTable = adapter.tables[`${rootTableName}${adapter.localesSuffix}`];
|
|
635
|
+
addJoinTable({
|
|
636
|
+
condition: and(...condtions),
|
|
637
|
+
joins,
|
|
638
|
+
table: localesTable
|
|
639
|
+
});
|
|
640
|
+
joins.push({
|
|
641
|
+
condition: eq(localesTable[columnName], newAliasTable.id),
|
|
642
|
+
table: newAliasTable
|
|
643
|
+
});
|
|
644
|
+
} else {
|
|
645
|
+
joins.push({
|
|
646
|
+
condition: eq(newAliasTable.id, aliasTable ? aliasTable[columnName] : adapter.tables[tableName][columnName]),
|
|
647
|
+
table: newAliasTable
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
return getTableColumnFromPath({
|
|
651
|
+
adapter,
|
|
652
|
+
aliasTable: newAliasTable,
|
|
653
|
+
collectionPath: newCollectionPath,
|
|
654
|
+
constraintPath: '',
|
|
655
|
+
constraints,
|
|
656
|
+
fields: adapter.cms.collections[field.relationTo].config.flattenedFields,
|
|
657
|
+
joins,
|
|
658
|
+
locale,
|
|
659
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
660
|
+
pathSegments: pathSegments.slice(1),
|
|
661
|
+
selectFields,
|
|
662
|
+
tableName: newTableName,
|
|
663
|
+
value
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
break;
|
|
667
|
+
}
|
|
668
|
+
case 'select':
|
|
669
|
+
{
|
|
670
|
+
if (field.hasMany) {
|
|
671
|
+
const newTableName = adapter.tableNameMap.get(`${tableName}_${tableNameSuffix}${toSnakeCase(field.name)}`);
|
|
672
|
+
const idColumn = (aliasTable ?? adapter.tables[tableName]).id;
|
|
673
|
+
if (locale && isFieldLocalized && adapter.cms.config.localization) {
|
|
674
|
+
const conditions = [
|
|
675
|
+
eq(idColumn, adapter.tables[newTableName].parent),
|
|
676
|
+
eq(adapter.tables[newTableName]._locale, locale)
|
|
677
|
+
];
|
|
678
|
+
if (locale !== 'all') {
|
|
679
|
+
conditions.push(eq(adapter.tables[newTableName]._locale, locale));
|
|
680
|
+
}
|
|
681
|
+
addJoinTable({
|
|
682
|
+
condition: and(...conditions),
|
|
683
|
+
joins,
|
|
684
|
+
table: adapter.tables[newTableName]
|
|
685
|
+
});
|
|
686
|
+
} else {
|
|
687
|
+
addJoinTable({
|
|
688
|
+
condition: eq(idColumn, adapter.tables[newTableName].parent),
|
|
689
|
+
joins,
|
|
690
|
+
table: adapter.tables[newTableName]
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
return {
|
|
694
|
+
columnName: 'value',
|
|
695
|
+
constraints,
|
|
696
|
+
field,
|
|
697
|
+
table: adapter.tables[newTableName]
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
break;
|
|
701
|
+
}
|
|
702
|
+
case 'tab':
|
|
703
|
+
{
|
|
704
|
+
if (tabHasName(field)) {
|
|
705
|
+
return getTableColumnFromPath({
|
|
706
|
+
adapter,
|
|
707
|
+
aliasTable,
|
|
708
|
+
collectionPath,
|
|
709
|
+
columnPrefix: `${columnPrefix}${field.name}_`,
|
|
710
|
+
constraintPath: `${constraintPath}${field.name}.`,
|
|
711
|
+
constraints,
|
|
712
|
+
fields: field.flattenedFields,
|
|
713
|
+
joins,
|
|
714
|
+
locale,
|
|
715
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
716
|
+
pathSegments: pathSegments.slice(1),
|
|
717
|
+
rootTableName,
|
|
718
|
+
selectFields,
|
|
719
|
+
selectLocale,
|
|
720
|
+
tableName: newTableName,
|
|
721
|
+
tableNameSuffix: `${tableNameSuffix}${toSnakeCase(field.name)}_`,
|
|
722
|
+
value
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
return getTableColumnFromPath({
|
|
726
|
+
adapter,
|
|
727
|
+
aliasTable,
|
|
728
|
+
collectionPath,
|
|
729
|
+
columnPrefix,
|
|
730
|
+
constraintPath,
|
|
731
|
+
constraints,
|
|
732
|
+
fields: field.flattenedFields,
|
|
733
|
+
joins,
|
|
734
|
+
locale,
|
|
735
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
736
|
+
pathSegments: pathSegments.slice(1),
|
|
737
|
+
rootTableName,
|
|
738
|
+
selectFields,
|
|
739
|
+
selectLocale,
|
|
740
|
+
tableName: newTableName,
|
|
741
|
+
tableNameSuffix,
|
|
742
|
+
value
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
default:
|
|
746
|
+
{
|
|
747
|
+
break;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
let newTable = adapter.tables[newTableName];
|
|
751
|
+
if (isFieldLocalized && adapter.cms.config.localization) {
|
|
752
|
+
// If localized, we go to localized table and set aliasTable to undefined
|
|
753
|
+
// so it is not picked up below to be used as targetTable
|
|
754
|
+
const parentTable = aliasTable || adapter.tables[tableName];
|
|
755
|
+
newTableName = `${tableName}${adapter.localesSuffix}`;
|
|
756
|
+
// use an alias because the same query may contain constraints with different locale value
|
|
757
|
+
if (localizedPathQuery) {
|
|
758
|
+
const { newAliasTable } = getTableAlias({
|
|
759
|
+
adapter,
|
|
760
|
+
tableName: newTableName
|
|
761
|
+
});
|
|
762
|
+
newTable = newAliasTable;
|
|
763
|
+
} else {
|
|
764
|
+
newTable = adapter.tables[newTableName];
|
|
765
|
+
}
|
|
766
|
+
let condition = eq(parentTable.id, newTable._parentID);
|
|
767
|
+
if (locale !== 'all') {
|
|
768
|
+
condition = and(condition, eq(newTable._locale, locale));
|
|
769
|
+
}
|
|
770
|
+
if (selectLocale) {
|
|
771
|
+
selectFields._locale = newTable._locale;
|
|
772
|
+
}
|
|
773
|
+
addJoinTable({
|
|
774
|
+
condition,
|
|
775
|
+
joins,
|
|
776
|
+
table: newTable
|
|
777
|
+
});
|
|
778
|
+
aliasTable = undefined;
|
|
779
|
+
}
|
|
780
|
+
const targetTable = aliasTable || newTable;
|
|
781
|
+
selectFields[`${newTableName}.${columnPrefix}${field.name}`] = targetTable[`${columnPrefix}${field.name}`];
|
|
782
|
+
return {
|
|
783
|
+
columnName: `${columnPrefix}${field.name}`,
|
|
784
|
+
constraints,
|
|
785
|
+
field,
|
|
786
|
+
pathSegments,
|
|
787
|
+
table: targetTable
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
throw new APIError(`Cannot find field for path at ${fieldPath}`);
|
|
791
|
+
};
|
|
792
|
+
|
|
793
|
+
//# sourceMappingURL=getTableColumnFromPath.js.map
|