@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,668 @@
|
|
|
1
|
+
import { and, desc, eq, isNull, or } from 'drizzle-orm';
|
|
2
|
+
import { buildFindManyArgs } from '../find/buildFindManyArgs.js';
|
|
3
|
+
import { transform } from '../transform/read/index.js';
|
|
4
|
+
import { transformForWrite } from '../transform/write/index.js';
|
|
5
|
+
import { markWrite } from '../utilities/readAfterWrite.js';
|
|
6
|
+
import { deleteExistingArrayRows } from './deleteExistingArrayRows.js';
|
|
7
|
+
import { deleteExistingRowsByPath } from './deleteExistingRowsByPath.js';
|
|
8
|
+
import { handleUpsertError } from './handleUpsertError.js';
|
|
9
|
+
import { insertArrays } from './insertArrays.js';
|
|
10
|
+
import { shouldUseOptimizedUpsertRow } from './shouldUseOptimizedUpsertRow.js';
|
|
11
|
+
/**
|
|
12
|
+
* If `id` is provided, it will update the row with that ID.
|
|
13
|
+
* If `where` is provided, it will update the row that matches the `where`
|
|
14
|
+
* If neither `id` nor `where` is provided, it will create a new row.
|
|
15
|
+
*
|
|
16
|
+
* adapter function replaces the entire row and does not support partial updates.
|
|
17
|
+
*/ export const upsertRow = async ({ id, adapter, collectionSlug, data, db, fields, globalSlug, ignoreResult, // TODO:
|
|
18
|
+
// When we support joins for write operations (create/update) - pass collectionSlug to the buildFindManyArgs
|
|
19
|
+
// Make a new argument in upsertRow.ts and pass the slug from every operation.
|
|
20
|
+
customID, joinQuery: _joinQuery, operation, path = '', req, select, tableName, upsertTarget, where })=>{
|
|
21
|
+
if (operation === 'create' && !data.createdAt) {
|
|
22
|
+
data.createdAt = new Date().toISOString();
|
|
23
|
+
}
|
|
24
|
+
markWrite(adapter);
|
|
25
|
+
let insertedRow = {
|
|
26
|
+
id
|
|
27
|
+
};
|
|
28
|
+
if (id && shouldUseOptimizedUpsertRow({
|
|
29
|
+
data,
|
|
30
|
+
fields
|
|
31
|
+
})) {
|
|
32
|
+
try {
|
|
33
|
+
const transformedForWrite = transformForWrite({
|
|
34
|
+
adapter,
|
|
35
|
+
data,
|
|
36
|
+
enableAtomicWrites: true,
|
|
37
|
+
fields,
|
|
38
|
+
tableName
|
|
39
|
+
});
|
|
40
|
+
const { row } = transformedForWrite;
|
|
41
|
+
const { arraysToPush } = transformedForWrite;
|
|
42
|
+
const drizzle = db;
|
|
43
|
+
// First, handle $push arrays
|
|
44
|
+
if (arraysToPush && Object.keys(arraysToPush)?.length) {
|
|
45
|
+
await insertArrays({
|
|
46
|
+
adapter,
|
|
47
|
+
arrays: [
|
|
48
|
+
arraysToPush
|
|
49
|
+
],
|
|
50
|
+
db,
|
|
51
|
+
parentRows: [
|
|
52
|
+
insertedRow
|
|
53
|
+
],
|
|
54
|
+
uuidMap: {}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
// If row.updatedAt is not set, delete it to avoid triggering hasDataToUpdate. `updatedAt` may be explicitly set to null to
|
|
58
|
+
// disable triggering hasDataToUpdate.
|
|
59
|
+
if (typeof row.updatedAt === 'undefined' || row.updatedAt === null) {
|
|
60
|
+
delete row.updatedAt;
|
|
61
|
+
}
|
|
62
|
+
const hasDataToUpdate = row && Object.keys(row)?.length;
|
|
63
|
+
// Then, handle regular row update
|
|
64
|
+
if (ignoreResult) {
|
|
65
|
+
if (hasDataToUpdate) {
|
|
66
|
+
// Only update row if there is something to update.
|
|
67
|
+
// Example: if the data only consists of a single $push, calling insertArrays is enough - we don't need to update the row.
|
|
68
|
+
await drizzle.update(adapter.tables[tableName]).set(row).where(eq(adapter.tables[tableName].id, id));
|
|
69
|
+
}
|
|
70
|
+
return ignoreResult === 'idOnly' ? {
|
|
71
|
+
id
|
|
72
|
+
} : null;
|
|
73
|
+
}
|
|
74
|
+
const findManyArgs = buildFindManyArgs({
|
|
75
|
+
adapter,
|
|
76
|
+
depth: 0,
|
|
77
|
+
fields,
|
|
78
|
+
joinQuery: false,
|
|
79
|
+
select,
|
|
80
|
+
tableName
|
|
81
|
+
});
|
|
82
|
+
const findManyKeysLength = Object.keys(findManyArgs).length;
|
|
83
|
+
const hasOnlyColumns = Object.keys(findManyArgs.columns || {}).length > 0;
|
|
84
|
+
if (!hasDataToUpdate) {
|
|
85
|
+
// Nothing to update => just fetch current row and return
|
|
86
|
+
findManyArgs.where = eq(adapter.tables[tableName].id, insertedRow.id);
|
|
87
|
+
const doc = await db.query[tableName].findFirst(findManyArgs);
|
|
88
|
+
return transform({
|
|
89
|
+
adapter,
|
|
90
|
+
config: adapter.cms.config,
|
|
91
|
+
data: doc,
|
|
92
|
+
fields,
|
|
93
|
+
joinQuery: false,
|
|
94
|
+
tableName
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (findManyKeysLength === 0 || hasOnlyColumns) {
|
|
98
|
+
// Optimization - No need for joins => can simply use returning(). This is optimal for very simple collections
|
|
99
|
+
// without complex fields that live in separate tables like blocks, arrays, relationships, etc.
|
|
100
|
+
const selectedFields = {};
|
|
101
|
+
if (hasOnlyColumns) {
|
|
102
|
+
for (const [column, enabled] of Object.entries(findManyArgs.columns)){
|
|
103
|
+
if (enabled) {
|
|
104
|
+
selectedFields[column] = adapter.tables[tableName][column];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const docs = await drizzle.update(adapter.tables[tableName]).set(row).where(eq(adapter.tables[tableName].id, id)).returning(Object.keys(selectedFields).length ? selectedFields : undefined);
|
|
109
|
+
return transform({
|
|
110
|
+
adapter,
|
|
111
|
+
config: adapter.cms.config,
|
|
112
|
+
data: docs[0],
|
|
113
|
+
fields,
|
|
114
|
+
joinQuery: false,
|
|
115
|
+
tableName
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
// DB Update that needs the result, potentially with joins => need to update first, then find. returning() does not work with joins.
|
|
119
|
+
await drizzle.update(adapter.tables[tableName]).set(row).where(eq(adapter.tables[tableName].id, id));
|
|
120
|
+
findManyArgs.where = eq(adapter.tables[tableName].id, insertedRow.id);
|
|
121
|
+
const doc = await db.query[tableName].findFirst(findManyArgs);
|
|
122
|
+
return transform({
|
|
123
|
+
adapter,
|
|
124
|
+
config: adapter.cms.config,
|
|
125
|
+
data: doc,
|
|
126
|
+
fields,
|
|
127
|
+
joinQuery: false,
|
|
128
|
+
tableName
|
|
129
|
+
});
|
|
130
|
+
} catch (error) {
|
|
131
|
+
handleUpsertError({
|
|
132
|
+
id,
|
|
133
|
+
adapter,
|
|
134
|
+
collectionSlug,
|
|
135
|
+
error,
|
|
136
|
+
globalSlug,
|
|
137
|
+
req,
|
|
138
|
+
tableName
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Split out the incoming data into the corresponding:
|
|
143
|
+
// base row, locales, relationships, blocks, and arrays
|
|
144
|
+
const rowToInsert = transformForWrite({
|
|
145
|
+
adapter,
|
|
146
|
+
data,
|
|
147
|
+
enableAtomicWrites: false,
|
|
148
|
+
fields,
|
|
149
|
+
path,
|
|
150
|
+
tableName
|
|
151
|
+
});
|
|
152
|
+
if (customID) {
|
|
153
|
+
rowToInsert.row.id = customID;
|
|
154
|
+
}
|
|
155
|
+
// First, we insert the main row
|
|
156
|
+
try {
|
|
157
|
+
if (operation === 'update') {
|
|
158
|
+
const target = upsertTarget || adapter.tables[tableName].id;
|
|
159
|
+
// Check if we only have relationship operations and no main row data to update
|
|
160
|
+
// Exclude timestamp-only updates when we only have relationship operations
|
|
161
|
+
const rowKeys = Object.keys(rowToInsert.row);
|
|
162
|
+
const hasMainRowData = rowKeys.length > 0 && !rowKeys.every((key)=>key === 'updatedAt' || key === 'createdAt');
|
|
163
|
+
if (hasMainRowData) {
|
|
164
|
+
if (id) {
|
|
165
|
+
rowToInsert.row.id = id;
|
|
166
|
+
[insertedRow] = await adapter.insert({
|
|
167
|
+
db,
|
|
168
|
+
onConflictDoUpdate: {
|
|
169
|
+
set: rowToInsert.row,
|
|
170
|
+
target
|
|
171
|
+
},
|
|
172
|
+
tableName,
|
|
173
|
+
values: rowToInsert.row
|
|
174
|
+
});
|
|
175
|
+
} else {
|
|
176
|
+
;
|
|
177
|
+
[insertedRow] = await adapter.insert({
|
|
178
|
+
db,
|
|
179
|
+
onConflictDoUpdate: {
|
|
180
|
+
set: rowToInsert.row,
|
|
181
|
+
target,
|
|
182
|
+
where
|
|
183
|
+
},
|
|
184
|
+
tableName,
|
|
185
|
+
values: rowToInsert.row
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
// No main row data to update, just use the existing ID
|
|
190
|
+
insertedRow = {
|
|
191
|
+
id
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
} else {
|
|
195
|
+
if (adapter.allowIDOnCreate && data.id) {
|
|
196
|
+
rowToInsert.row.id = data.id;
|
|
197
|
+
}
|
|
198
|
+
;
|
|
199
|
+
[insertedRow] = await adapter.insert({
|
|
200
|
+
db,
|
|
201
|
+
tableName,
|
|
202
|
+
values: rowToInsert.row
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
const localesToInsert = [];
|
|
206
|
+
const relationsToInsert = [];
|
|
207
|
+
const textsToInsert = [];
|
|
208
|
+
const numbersToInsert = [];
|
|
209
|
+
const blocksToInsert = {};
|
|
210
|
+
const selectsToInsert = {};
|
|
211
|
+
// If there are locale rows with data, add the parent and locale to each
|
|
212
|
+
if (Object.keys(rowToInsert.locales).length > 0) {
|
|
213
|
+
Object.entries(rowToInsert.locales).forEach(([locale, localeRow])=>{
|
|
214
|
+
localeRow._parentID = insertedRow.id;
|
|
215
|
+
localeRow._locale = locale;
|
|
216
|
+
localesToInsert.push(localeRow);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
// If there are relationships, add parent to each
|
|
220
|
+
if (rowToInsert.relationships.length > 0) {
|
|
221
|
+
rowToInsert.relationships.forEach((relation)=>{
|
|
222
|
+
relation.parent = insertedRow.id;
|
|
223
|
+
relationsToInsert.push(relation);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
// If there are texts, add parent to each
|
|
227
|
+
if (rowToInsert.texts.length > 0) {
|
|
228
|
+
rowToInsert.texts.forEach((textRow)=>{
|
|
229
|
+
textRow.parent = insertedRow.id;
|
|
230
|
+
textsToInsert.push(textRow);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
// If there are numbers, add parent to each
|
|
234
|
+
if (rowToInsert.numbers.length > 0) {
|
|
235
|
+
rowToInsert.numbers.forEach((numberRow)=>{
|
|
236
|
+
numberRow.parent = insertedRow.id;
|
|
237
|
+
numbersToInsert.push(numberRow);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
// If there are selects, add parent to each, and then
|
|
241
|
+
// store by table name and rows
|
|
242
|
+
if (Object.keys(rowToInsert.selects).length > 0) {
|
|
243
|
+
Object.entries(rowToInsert.selects).forEach(([selectTableName, selectRows])=>{
|
|
244
|
+
selectsToInsert[selectTableName] = [];
|
|
245
|
+
selectRows.forEach((row)=>{
|
|
246
|
+
if (typeof row.parent === 'undefined') {
|
|
247
|
+
row.parent = insertedRow.id;
|
|
248
|
+
}
|
|
249
|
+
selectsToInsert[selectTableName].push(row);
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
// If there are blocks, add parent to each, and then
|
|
254
|
+
// store by table name and rows
|
|
255
|
+
Object.keys(rowToInsert.blocks).forEach((tableName)=>{
|
|
256
|
+
rowToInsert.blocks[tableName].forEach((blockRow)=>{
|
|
257
|
+
blockRow.row._parentID = insertedRow.id;
|
|
258
|
+
if (!blocksToInsert[tableName]) {
|
|
259
|
+
blocksToInsert[tableName] = [];
|
|
260
|
+
}
|
|
261
|
+
if (blockRow.row.uuid) {
|
|
262
|
+
delete blockRow.row.uuid;
|
|
263
|
+
}
|
|
264
|
+
blocksToInsert[tableName].push(blockRow);
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
// //////////////////////////////////
|
|
268
|
+
// INSERT LOCALES
|
|
269
|
+
// //////////////////////////////////
|
|
270
|
+
if (localesToInsert.length > 0) {
|
|
271
|
+
const localeTableName = `${tableName}${adapter.localesSuffix}`;
|
|
272
|
+
const localeTable = adapter.tables[`${tableName}${adapter.localesSuffix}`];
|
|
273
|
+
if (operation === 'update') {
|
|
274
|
+
await adapter.deleteWhere({
|
|
275
|
+
db,
|
|
276
|
+
tableName: localeTableName,
|
|
277
|
+
where: eq(localeTable._parentID, insertedRow.id)
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
await adapter.insert({
|
|
281
|
+
db,
|
|
282
|
+
tableName: localeTableName,
|
|
283
|
+
values: localesToInsert
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
// //////////////////////////////////
|
|
287
|
+
// INSERT RELATIONSHIPS
|
|
288
|
+
// //////////////////////////////////
|
|
289
|
+
const relationshipsTableName = `${tableName}${adapter.relationshipsSuffix}`;
|
|
290
|
+
if (operation === 'update') {
|
|
291
|
+
// Filter out specific item deletions (those with itemToRemove) from general path deletions
|
|
292
|
+
const generalRelationshipDeletes = rowToInsert.relationshipsToDelete.filter((rel)=>!('itemToRemove' in rel));
|
|
293
|
+
await deleteExistingRowsByPath({
|
|
294
|
+
adapter,
|
|
295
|
+
db,
|
|
296
|
+
localeColumnName: 'locale',
|
|
297
|
+
parentColumnName: 'parent',
|
|
298
|
+
parentID: insertedRow.id,
|
|
299
|
+
pathColumnName: 'path',
|
|
300
|
+
rows: [
|
|
301
|
+
...relationsToInsert,
|
|
302
|
+
...generalRelationshipDeletes
|
|
303
|
+
],
|
|
304
|
+
tableName: relationshipsTableName
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
if (relationsToInsert.length > 0) {
|
|
308
|
+
await adapter.insert({
|
|
309
|
+
db,
|
|
310
|
+
tableName: relationshipsTableName,
|
|
311
|
+
values: relationsToInsert
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
// //////////////////////////////////
|
|
315
|
+
// HANDLE RELATIONSHIP $push OPERATIONS
|
|
316
|
+
// //////////////////////////////////
|
|
317
|
+
if (rowToInsert.relationshipsToAppend.length > 0) {
|
|
318
|
+
// Prepare all relationships for batch insert (order will be set after max query)
|
|
319
|
+
const relationshipsToInsert = rowToInsert.relationshipsToAppend.map((rel)=>{
|
|
320
|
+
const parentId = id || insertedRow.id;
|
|
321
|
+
const row = {
|
|
322
|
+
parent: parentId,
|
|
323
|
+
path: rel.path
|
|
324
|
+
};
|
|
325
|
+
// Only add locale if this relationship table has a locale column
|
|
326
|
+
const relationshipTable = adapter.rawTables[relationshipsTableName];
|
|
327
|
+
if (rel.locale && relationshipTable && relationshipTable.columns.locale) {
|
|
328
|
+
row.locale = rel.locale;
|
|
329
|
+
}
|
|
330
|
+
if (rel.relationTo) {
|
|
331
|
+
// Use camelCase key for Drizzle table (e.g., categoriesID not categories_id)
|
|
332
|
+
row[`${rel.relationTo}ID`] = rel.value;
|
|
333
|
+
}
|
|
334
|
+
return row;
|
|
335
|
+
});
|
|
336
|
+
if (relationshipsToInsert.length > 0) {
|
|
337
|
+
// Check for potential duplicates
|
|
338
|
+
const relationshipTable = adapter.tables[relationshipsTableName];
|
|
339
|
+
if (relationshipTable) {
|
|
340
|
+
// Build conditions only if we have relationships to check
|
|
341
|
+
if (relationshipsToInsert.length === 0) {
|
|
342
|
+
return; // No relationships to insert
|
|
343
|
+
}
|
|
344
|
+
const conditions = relationshipsToInsert.map((row)=>{
|
|
345
|
+
const parts = [
|
|
346
|
+
eq(relationshipTable.parent, row.parent),
|
|
347
|
+
eq(relationshipTable.path, row.path)
|
|
348
|
+
];
|
|
349
|
+
// Add locale condition
|
|
350
|
+
if (row.locale !== undefined && relationshipTable.locale) {
|
|
351
|
+
parts.push(eq(relationshipTable.locale, row.locale));
|
|
352
|
+
} else if (relationshipTable.locale) {
|
|
353
|
+
parts.push(isNull(relationshipTable.locale));
|
|
354
|
+
}
|
|
355
|
+
// Add all relationship ID matches using schema fields
|
|
356
|
+
for (const [key, value] of Object.entries(row)){
|
|
357
|
+
if (key.endsWith('ID') && value != null) {
|
|
358
|
+
const column = relationshipTable[key];
|
|
359
|
+
if (column && typeof column === 'object') {
|
|
360
|
+
parts.push(eq(column, value));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return and(...parts);
|
|
365
|
+
});
|
|
366
|
+
// Get both existing relationships AND max order in a single query
|
|
367
|
+
let existingRels = [];
|
|
368
|
+
let maxOrder = 0;
|
|
369
|
+
if (conditions.length > 0) {
|
|
370
|
+
// Query for existing relationships
|
|
371
|
+
existingRels = await db.select().from(relationshipTable).where(or(...conditions));
|
|
372
|
+
}
|
|
373
|
+
// Get max order for this parent across all paths in a single query
|
|
374
|
+
const parentId = id || insertedRow.id;
|
|
375
|
+
const maxOrderResult = await db.select({
|
|
376
|
+
maxOrder: relationshipTable.order
|
|
377
|
+
}).from(relationshipTable).where(eq(relationshipTable.parent, parentId)).orderBy(desc(relationshipTable.order)).limit(1);
|
|
378
|
+
if (maxOrderResult.length > 0 && maxOrderResult[0].maxOrder) {
|
|
379
|
+
maxOrder = maxOrderResult[0].maxOrder;
|
|
380
|
+
}
|
|
381
|
+
// Set order values for all relationships based on max order
|
|
382
|
+
relationshipsToInsert.forEach((row, index)=>{
|
|
383
|
+
row.order = maxOrder + index + 1;
|
|
384
|
+
});
|
|
385
|
+
// Filter out relationships that already exist
|
|
386
|
+
const relationshipsToActuallyInsert = relationshipsToInsert.filter((newRow)=>{
|
|
387
|
+
return !existingRels.some((existingRow)=>{
|
|
388
|
+
// Check if this relationship already exists
|
|
389
|
+
let matches = existingRow.parent === newRow.parent && existingRow.path === newRow.path;
|
|
390
|
+
if (newRow.locale !== undefined) {
|
|
391
|
+
matches = matches && existingRow.locale === newRow.locale;
|
|
392
|
+
}
|
|
393
|
+
// Check relationship value matches - convert to camelCase for comparison
|
|
394
|
+
for (const key of Object.keys(newRow)){
|
|
395
|
+
if (key.endsWith('ID')) {
|
|
396
|
+
// Now using camelCase keys
|
|
397
|
+
matches = matches && existingRow[key] === newRow[key];
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return matches;
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
// Insert only non-duplicate relationships
|
|
404
|
+
if (relationshipsToActuallyInsert.length > 0) {
|
|
405
|
+
await adapter.insert({
|
|
406
|
+
db,
|
|
407
|
+
tableName: relationshipsTableName,
|
|
408
|
+
values: relationshipsToActuallyInsert
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
// //////////////////////////////////
|
|
415
|
+
// HANDLE RELATIONSHIP $remove OPERATIONS
|
|
416
|
+
// //////////////////////////////////
|
|
417
|
+
if (rowToInsert.relationshipsToDelete.some((rel)=>'itemToRemove' in rel)) {
|
|
418
|
+
const relationshipTable = adapter.tables[relationshipsTableName];
|
|
419
|
+
if (relationshipTable) {
|
|
420
|
+
for (const relToDelete of rowToInsert.relationshipsToDelete){
|
|
421
|
+
if ('itemToRemove' in relToDelete && relToDelete.itemToRemove) {
|
|
422
|
+
const item = relToDelete.itemToRemove;
|
|
423
|
+
const parentId = id || insertedRow.id;
|
|
424
|
+
const conditions = [
|
|
425
|
+
eq(relationshipTable.parent, parentId),
|
|
426
|
+
eq(relationshipTable.path, relToDelete.path)
|
|
427
|
+
];
|
|
428
|
+
// Add locale condition if this relationship table has a locale column
|
|
429
|
+
if (adapter.rawTables[relationshipsTableName]?.columns.locale) {
|
|
430
|
+
if (relToDelete.locale) {
|
|
431
|
+
conditions.push(eq(relationshipTable.locale, relToDelete.locale));
|
|
432
|
+
} else {
|
|
433
|
+
conditions.push(isNull(relationshipTable.locale));
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
// Handle polymorphic vs simple relationships
|
|
437
|
+
if (typeof item === 'object' && 'relationTo' in item) {
|
|
438
|
+
// Polymorphic relationship - convert to camelCase key
|
|
439
|
+
const camelKey = `${item.relationTo}ID`;
|
|
440
|
+
if (relationshipTable[camelKey]) {
|
|
441
|
+
conditions.push(eq(relationshipTable[camelKey], item.value));
|
|
442
|
+
}
|
|
443
|
+
} else if (relToDelete.relationTo) {
|
|
444
|
+
// Simple relationship - convert to camelCase key
|
|
445
|
+
const camelKey = `${relToDelete.relationTo}ID`;
|
|
446
|
+
if (relationshipTable[camelKey]) {
|
|
447
|
+
conditions.push(eq(relationshipTable[camelKey], item));
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
// Execute DELETE using Drizzle query builder
|
|
451
|
+
await adapter.deleteWhere({
|
|
452
|
+
db,
|
|
453
|
+
tableName: relationshipsTableName,
|
|
454
|
+
where: and(...conditions)
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
// //////////////////////////////////
|
|
461
|
+
// INSERT hasMany TEXTS
|
|
462
|
+
// //////////////////////////////////
|
|
463
|
+
const textsTableName = `${tableName}_texts`;
|
|
464
|
+
if (operation === 'update') {
|
|
465
|
+
await deleteExistingRowsByPath({
|
|
466
|
+
adapter,
|
|
467
|
+
db,
|
|
468
|
+
localeColumnName: 'locale',
|
|
469
|
+
parentColumnName: 'parent',
|
|
470
|
+
parentID: insertedRow.id,
|
|
471
|
+
pathColumnName: 'path',
|
|
472
|
+
rows: [
|
|
473
|
+
...textsToInsert,
|
|
474
|
+
...rowToInsert.textsToDelete
|
|
475
|
+
],
|
|
476
|
+
tableName: textsTableName
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
if (textsToInsert.length > 0) {
|
|
480
|
+
await adapter.insert({
|
|
481
|
+
db,
|
|
482
|
+
tableName: textsTableName,
|
|
483
|
+
values: textsToInsert
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
// //////////////////////////////////
|
|
487
|
+
// INSERT hasMany NUMBERS
|
|
488
|
+
// //////////////////////////////////
|
|
489
|
+
const numbersTableName = `${tableName}_numbers`;
|
|
490
|
+
if (operation === 'update') {
|
|
491
|
+
await deleteExistingRowsByPath({
|
|
492
|
+
adapter,
|
|
493
|
+
db,
|
|
494
|
+
localeColumnName: 'locale',
|
|
495
|
+
parentColumnName: 'parent',
|
|
496
|
+
parentID: insertedRow.id,
|
|
497
|
+
pathColumnName: 'path',
|
|
498
|
+
rows: [
|
|
499
|
+
...numbersToInsert,
|
|
500
|
+
...rowToInsert.numbersToDelete
|
|
501
|
+
],
|
|
502
|
+
tableName: numbersTableName
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
if (numbersToInsert.length > 0) {
|
|
506
|
+
await adapter.insert({
|
|
507
|
+
db,
|
|
508
|
+
tableName: numbersTableName,
|
|
509
|
+
values: numbersToInsert
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
// //////////////////////////////////
|
|
513
|
+
// INSERT BLOCKS
|
|
514
|
+
// //////////////////////////////////
|
|
515
|
+
const insertedBlockRows = {};
|
|
516
|
+
if (operation === 'update') {
|
|
517
|
+
for (const tableName of rowToInsert.blocksToDelete){
|
|
518
|
+
const blockTable = adapter.tables[tableName];
|
|
519
|
+
await adapter.deleteWhere({
|
|
520
|
+
db,
|
|
521
|
+
tableName,
|
|
522
|
+
where: eq(blockTable._parentID, insertedRow.id)
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
// When versions are enabled, adapter is used to track mapping between blocks/arrays ObjectID to their numeric generated representation, then we use it for nested to arrays/blocks select hasMany in versions.
|
|
527
|
+
const arraysBlocksUUIDMap = {};
|
|
528
|
+
for (const [tableName, blockRows] of Object.entries(blocksToInsert)){
|
|
529
|
+
insertedBlockRows[tableName] = await adapter.insert({
|
|
530
|
+
db,
|
|
531
|
+
tableName,
|
|
532
|
+
values: blockRows.map(({ row })=>row)
|
|
533
|
+
});
|
|
534
|
+
insertedBlockRows[tableName].forEach((row, i)=>{
|
|
535
|
+
blockRows[i].row = row;
|
|
536
|
+
if (typeof row._uuid === 'string' && (typeof row.id === 'string' || typeof row.id === 'number')) {
|
|
537
|
+
arraysBlocksUUIDMap[row._uuid] = row.id;
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
const blockLocaleIndexMap = [];
|
|
541
|
+
const blockLocaleRowsToInsert = blockRows.reduce((acc, blockRow, i)=>{
|
|
542
|
+
if (Object.entries(blockRow.locales).length > 0) {
|
|
543
|
+
Object.entries(blockRow.locales).forEach(([blockLocale, blockLocaleData])=>{
|
|
544
|
+
if (Object.keys(blockLocaleData).length > 0) {
|
|
545
|
+
blockLocaleData._parentID = blockRow.row.id;
|
|
546
|
+
blockLocaleData._locale = blockLocale;
|
|
547
|
+
acc.push(blockLocaleData);
|
|
548
|
+
blockLocaleIndexMap.push(i);
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
return acc;
|
|
553
|
+
}, []);
|
|
554
|
+
if (blockLocaleRowsToInsert.length > 0) {
|
|
555
|
+
await adapter.insert({
|
|
556
|
+
db,
|
|
557
|
+
tableName: `${tableName}${adapter.localesSuffix}`,
|
|
558
|
+
values: blockLocaleRowsToInsert
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
await insertArrays({
|
|
562
|
+
adapter,
|
|
563
|
+
arrays: blockRows.map(({ arrays })=>arrays),
|
|
564
|
+
db,
|
|
565
|
+
parentRows: insertedBlockRows[tableName],
|
|
566
|
+
uuidMap: arraysBlocksUUIDMap
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
// //////////////////////////////////
|
|
570
|
+
// INSERT ARRAYS RECURSIVELY
|
|
571
|
+
// //////////////////////////////////
|
|
572
|
+
if (operation === 'update') {
|
|
573
|
+
for (const arrayTableName of Object.keys(rowToInsert.arrays)){
|
|
574
|
+
await deleteExistingArrayRows({
|
|
575
|
+
adapter,
|
|
576
|
+
db,
|
|
577
|
+
parentID: insertedRow.id,
|
|
578
|
+
tableName: arrayTableName
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
await insertArrays({
|
|
583
|
+
adapter,
|
|
584
|
+
arrays: [
|
|
585
|
+
rowToInsert.arrays,
|
|
586
|
+
rowToInsert.arraysToPush
|
|
587
|
+
],
|
|
588
|
+
db,
|
|
589
|
+
parentRows: [
|
|
590
|
+
insertedRow,
|
|
591
|
+
insertedRow
|
|
592
|
+
],
|
|
593
|
+
uuidMap: arraysBlocksUUIDMap
|
|
594
|
+
});
|
|
595
|
+
// //////////////////////////////////
|
|
596
|
+
// INSERT hasMany SELECTS
|
|
597
|
+
// //////////////////////////////////
|
|
598
|
+
for (const [selectTableName, tableRows] of Object.entries(selectsToInsert)){
|
|
599
|
+
const selectTable = adapter.tables[selectTableName];
|
|
600
|
+
if (operation === 'update') {
|
|
601
|
+
await adapter.deleteWhere({
|
|
602
|
+
db,
|
|
603
|
+
tableName: selectTableName,
|
|
604
|
+
where: eq(selectTable.parent, insertedRow.id)
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
if (Object.keys(arraysBlocksUUIDMap).length > 0) {
|
|
608
|
+
tableRows.forEach((row)=>{
|
|
609
|
+
if (row.parent in arraysBlocksUUIDMap) {
|
|
610
|
+
row.parent = arraysBlocksUUIDMap[row.parent];
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
if (tableRows.length) {
|
|
615
|
+
await adapter.insert({
|
|
616
|
+
db,
|
|
617
|
+
tableName: selectTableName,
|
|
618
|
+
values: tableRows
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
} catch (error) {
|
|
623
|
+
handleUpsertError({
|
|
624
|
+
id,
|
|
625
|
+
adapter,
|
|
626
|
+
collectionSlug,
|
|
627
|
+
error,
|
|
628
|
+
globalSlug,
|
|
629
|
+
req,
|
|
630
|
+
tableName
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
if (ignoreResult === 'idOnly') {
|
|
634
|
+
return {
|
|
635
|
+
id: insertedRow.id
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
if (ignoreResult) {
|
|
639
|
+
return data;
|
|
640
|
+
}
|
|
641
|
+
// //////////////////////////////////
|
|
642
|
+
// RETRIEVE NEWLY UPDATED ROW
|
|
643
|
+
// //////////////////////////////////
|
|
644
|
+
const findManyArgs = buildFindManyArgs({
|
|
645
|
+
adapter,
|
|
646
|
+
depth: 0,
|
|
647
|
+
fields,
|
|
648
|
+
joinQuery: false,
|
|
649
|
+
select,
|
|
650
|
+
tableName
|
|
651
|
+
});
|
|
652
|
+
findManyArgs.where = eq(adapter.tables[tableName].id, insertedRow.id);
|
|
653
|
+
const doc = await db.query[tableName].findFirst(findManyArgs);
|
|
654
|
+
// //////////////////////////////////
|
|
655
|
+
// TRANSFORM DATA
|
|
656
|
+
// //////////////////////////////////
|
|
657
|
+
const result = transform({
|
|
658
|
+
adapter,
|
|
659
|
+
config: adapter.cms.config,
|
|
660
|
+
data: doc,
|
|
661
|
+
fields,
|
|
662
|
+
joinQuery: false,
|
|
663
|
+
tableName
|
|
664
|
+
});
|
|
665
|
+
return result;
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
//# sourceMappingURL=index.js.map
|