@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
package/LICENSE.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018-2025 Payload CMS, Inc. <info@payloadcms.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
package/dist/count.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../src/count.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAA6B,MAAM,YAAY,CAAA;AASlE,eAAO,MAAM,KAAK,EAAE,KA0BnB,CAAA"}
|
package/dist/count.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import toSnakeCase from 'to-snake-case';
|
|
2
|
+
import { buildQuery } from './queries/buildQuery.js';
|
|
3
|
+
import { getTransaction } from './utilities/getTransaction.js';
|
|
4
|
+
export const count = async function count({ collection, locale, req, where: whereArg }) {
|
|
5
|
+
const collectionConfig = this.cms.collections[collection].config;
|
|
6
|
+
const tableName = this.tableNameMap.get(toSnakeCase(collectionConfig.slug));
|
|
7
|
+
const { joins, where } = buildQuery({
|
|
8
|
+
adapter: this,
|
|
9
|
+
fields: collectionConfig.flattenedFields,
|
|
10
|
+
locale,
|
|
11
|
+
tableName,
|
|
12
|
+
where: whereArg
|
|
13
|
+
});
|
|
14
|
+
const db = await getTransaction(this, req);
|
|
15
|
+
const countResult = await this.countDistinct({
|
|
16
|
+
db,
|
|
17
|
+
joins,
|
|
18
|
+
tableName,
|
|
19
|
+
where
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
totalDocs: countResult
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=count.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/count.ts"],"sourcesContent":["import type { Count, SanitizedCollectionConfig } from '@hanzo/cms'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const count: Count = async function count(\n this: DrizzleAdapter,\n { collection, locale, req, where: whereArg },\n) {\n const collectionConfig: SanitizedCollectionConfig = this.cms.collections[collection].config\n\n const tableName = this.tableNameMap.get(toSnakeCase(collectionConfig.slug))\n\n const { joins, where } = buildQuery({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n locale,\n tableName,\n where: whereArg,\n })\n\n const db = await getTransaction(this, req)\n\n const countResult = await this.countDistinct({\n db,\n joins,\n tableName,\n where,\n })\n\n return { totalDocs: countResult }\n}\n"],"names":["toSnakeCase","buildQuery","getTransaction","count","collection","locale","req","where","whereArg","collectionConfig","cms","collections","config","tableName","tableNameMap","get","slug","joins","adapter","fields","flattenedFields","db","countResult","countDistinct","totalDocs"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,MAAMC,QAAe,eAAeA,MAEzC,EAAEC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,OAAOC,QAAQ,EAAE;IAE5C,MAAMC,mBAA8C,IAAI,CAACC,GAAG,CAACC,WAAW,CAACP,WAAW,CAACQ,MAAM;IAE3F,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACf,YAAYS,iBAAiBO,IAAI;IAEzE,MAAM,EAAEC,KAAK,EAAEV,KAAK,EAAE,GAAGN,WAAW;QAClCiB,SAAS,IAAI;QACbC,QAAQV,iBAAiBW,eAAe;QACxCf;QACAQ;QACAN,OAAOC;IACT;IAEA,MAAMa,KAAK,MAAMnB,eAAe,IAAI,EAAEI;IAEtC,MAAMgB,cAAc,MAAM,IAAI,CAACC,aAAa,CAAC;QAC3CF;QACAJ;QACAJ;QACAN;IACF;IAEA,OAAO;QAAEiB,WAAWF;IAAY;AAClC,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"countGlobalVersions.d.ts","sourceRoot":"","sources":["../src/countGlobalVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAyB,MAAM,YAAY,CAAA;AAU5E,eAAO,MAAM,mBAAmB,EAAE,mBAgCjC,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { buildVersionGlobalFields } from '@hanzo/cms';
|
|
2
|
+
import toSnakeCase from 'to-snake-case';
|
|
3
|
+
import { buildQuery } from './queries/buildQuery.js';
|
|
4
|
+
import { getTransaction } from './utilities/getTransaction.js';
|
|
5
|
+
export const countGlobalVersions = async function countGlobalVersions({ global, locale, req, where: whereArg }) {
|
|
6
|
+
const globalConfig = this.cms.globals.config.find(({ slug })=>slug === global);
|
|
7
|
+
const tableName = this.tableNameMap.get(`_${toSnakeCase(globalConfig.slug)}${this.versionsSuffix}`);
|
|
8
|
+
const fields = buildVersionGlobalFields(this.cms.config, globalConfig, true);
|
|
9
|
+
const { joins, where } = buildQuery({
|
|
10
|
+
adapter: this,
|
|
11
|
+
fields,
|
|
12
|
+
locale,
|
|
13
|
+
tableName,
|
|
14
|
+
where: whereArg
|
|
15
|
+
});
|
|
16
|
+
const db = await getTransaction(this, req);
|
|
17
|
+
const countResult = await this.countDistinct({
|
|
18
|
+
db,
|
|
19
|
+
joins,
|
|
20
|
+
tableName,
|
|
21
|
+
where
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
totalDocs: countResult
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=countGlobalVersions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/countGlobalVersions.ts"],"sourcesContent":["import type { CountGlobalVersions, SanitizedGlobalConfig } from '@hanzo/cms'\n\nimport { buildVersionGlobalFields } from '@hanzo/cms'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const countGlobalVersions: CountGlobalVersions = async function countGlobalVersions(\n this: DrizzleAdapter,\n { global, locale, req, where: whereArg },\n) {\n const globalConfig: SanitizedGlobalConfig = this.cms.globals.config.find(\n ({ slug }) => slug === global,\n )\n\n const tableName = this.tableNameMap.get(\n `_${toSnakeCase(globalConfig.slug)}${this.versionsSuffix}`,\n )\n\n const fields = buildVersionGlobalFields(this.cms.config, globalConfig, true)\n\n const { joins, where } = buildQuery({\n adapter: this,\n fields,\n locale,\n tableName,\n where: whereArg,\n })\n\n const db = await getTransaction(this, req)\n\n const countResult = await this.countDistinct({\n db,\n joins,\n tableName,\n where,\n })\n\n return { totalDocs: countResult }\n}\n"],"names":["buildVersionGlobalFields","toSnakeCase","buildQuery","getTransaction","countGlobalVersions","global","locale","req","where","whereArg","globalConfig","cms","globals","config","find","slug","tableName","tableNameMap","get","versionsSuffix","fields","joins","adapter","db","countResult","countDistinct","totalDocs"],"mappings":"AAEA,SAASA,wBAAwB,QAAQ,aAAY;AACrD,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,MAAMC,sBAA2C,eAAeA,oBAErE,EAAEC,MAAM,EAAEC,MAAM,EAAEC,GAAG,EAAEC,OAAOC,QAAQ,EAAE;IAExC,MAAMC,eAAsC,IAAI,CAACC,GAAG,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CACtE,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASV;IAGzB,MAAMW,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CACrC,CAAC,CAAC,EAAEjB,YAAYS,aAAaK,IAAI,IAAI,IAAI,CAACI,cAAc,EAAE;IAG5D,MAAMC,SAASpB,yBAAyB,IAAI,CAACW,GAAG,CAACE,MAAM,EAAEH,cAAc;IAEvE,MAAM,EAAEW,KAAK,EAAEb,KAAK,EAAE,GAAGN,WAAW;QAClCoB,SAAS,IAAI;QACbF;QACAd;QACAU;QACAR,OAAOC;IACT;IAEA,MAAMc,KAAK,MAAMpB,eAAe,IAAI,EAAEI;IAEtC,MAAMiB,cAAc,MAAM,IAAI,CAACC,aAAa,CAAC;QAC3CF;QACAF;QACAL;QACAR;IACF;IAEA,OAAO;QAAEkB,WAAWF;IAAY;AAClC,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"countVersions.d.ts","sourceRoot":"","sources":["../src/countVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAA6B,MAAM,YAAY,CAAA;AAU1E,eAAO,MAAM,aAAa,EAAE,aA8B3B,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { buildVersionCollectionFields } from '@hanzo/cms';
|
|
2
|
+
import toSnakeCase from 'to-snake-case';
|
|
3
|
+
import { buildQuery } from './queries/buildQuery.js';
|
|
4
|
+
import { getTransaction } from './utilities/getTransaction.js';
|
|
5
|
+
export const countVersions = async function countVersions({ collection, locale, req, where: whereArg }) {
|
|
6
|
+
const collectionConfig = this.cms.collections[collection].config;
|
|
7
|
+
const tableName = this.tableNameMap.get(`_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`);
|
|
8
|
+
const fields = buildVersionCollectionFields(this.cms.config, collectionConfig, true);
|
|
9
|
+
const { joins, where } = buildQuery({
|
|
10
|
+
adapter: this,
|
|
11
|
+
fields,
|
|
12
|
+
locale,
|
|
13
|
+
tableName,
|
|
14
|
+
where: whereArg
|
|
15
|
+
});
|
|
16
|
+
const db = await getTransaction(this, req);
|
|
17
|
+
const countResult = await this.countDistinct({
|
|
18
|
+
db,
|
|
19
|
+
joins,
|
|
20
|
+
tableName,
|
|
21
|
+
where
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
totalDocs: countResult
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=countVersions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/countVersions.ts"],"sourcesContent":["import type { CountVersions, SanitizedCollectionConfig } from '@hanzo/cms'\n\nimport { buildVersionCollectionFields } from '@hanzo/cms'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const countVersions: CountVersions = async function countVersions(\n this: DrizzleAdapter,\n { collection, locale, req, where: whereArg },\n) {\n const collectionConfig: SanitizedCollectionConfig = this.cms.collections[collection].config\n\n const tableName = this.tableNameMap.get(\n `_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`,\n )\n\n const fields = buildVersionCollectionFields(this.cms.config, collectionConfig, true)\n\n const { joins, where } = buildQuery({\n adapter: this,\n fields,\n locale,\n tableName,\n where: whereArg,\n })\n\n const db = await getTransaction(this, req)\n\n const countResult = await this.countDistinct({\n db,\n joins,\n tableName,\n where,\n })\n\n return { totalDocs: countResult }\n}\n"],"names":["buildVersionCollectionFields","toSnakeCase","buildQuery","getTransaction","countVersions","collection","locale","req","where","whereArg","collectionConfig","cms","collections","config","tableName","tableNameMap","get","slug","versionsSuffix","fields","joins","adapter","db","countResult","countDistinct","totalDocs"],"mappings":"AAEA,SAASA,4BAA4B,QAAQ,aAAY;AACzD,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,OAAOC,QAAQ,EAAE;IAE5C,MAAMC,mBAA8C,IAAI,CAACC,GAAG,CAACC,WAAW,CAACP,WAAW,CAACQ,MAAM;IAE3F,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CACrC,CAAC,CAAC,EAAEf,YAAYS,iBAAiBO,IAAI,IAAI,IAAI,CAACC,cAAc,EAAE;IAGhE,MAAMC,SAASnB,6BAA6B,IAAI,CAACW,GAAG,CAACE,MAAM,EAAEH,kBAAkB;IAE/E,MAAM,EAAEU,KAAK,EAAEZ,KAAK,EAAE,GAAGN,WAAW;QAClCmB,SAAS,IAAI;QACbF;QACAb;QACAQ;QACAN,OAAOC;IACT;IAEA,MAAMa,KAAK,MAAMnB,eAAe,IAAI,EAAEI;IAEtC,MAAMgB,cAAc,MAAM,IAAI,CAACC,aAAa,CAAC;QAC3CF;QACAF;QACAN;QACAN;IACF;IAEA,OAAO;QAAEiB,WAAWF;IAAY;AAClC,EAAC"}
|
package/dist/create.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAUxC,eAAO,MAAM,MAAM,EAAE,MA6BpB,CAAA"}
|
package/dist/create.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import toSnakeCase from 'to-snake-case';
|
|
2
|
+
import { upsertRow } from './upsertRow/index.js';
|
|
3
|
+
import { getPrimaryDb } from './utilities/getPrimaryDb.js';
|
|
4
|
+
import { getTransaction } from './utilities/getTransaction.js';
|
|
5
|
+
export const create = async function create({ collection: collectionSlug, customID, data, req, returning, select }) {
|
|
6
|
+
const collection = this.cms.collections[collectionSlug].config;
|
|
7
|
+
const tableName = this.tableNameMap.get(toSnakeCase(collection.slug));
|
|
8
|
+
const db = getPrimaryDb(this, await getTransaction(this, req));
|
|
9
|
+
const result = await upsertRow({
|
|
10
|
+
adapter: this,
|
|
11
|
+
collectionSlug,
|
|
12
|
+
customID,
|
|
13
|
+
data,
|
|
14
|
+
db,
|
|
15
|
+
fields: collection.flattenedFields,
|
|
16
|
+
ignoreResult: returning === false,
|
|
17
|
+
operation: 'create',
|
|
18
|
+
req,
|
|
19
|
+
select,
|
|
20
|
+
tableName
|
|
21
|
+
});
|
|
22
|
+
if (returning === false) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { Create } from '@hanzo/cms'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\nimport { getPrimaryDb } from './utilities/getPrimaryDb.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const create: Create = async function create(\n this: DrizzleAdapter,\n { collection: collectionSlug, customID, data, req, returning, select },\n) {\n const collection = this.cms.collections[collectionSlug].config\n\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n\n const db = getPrimaryDb(this, await getTransaction(this, req))\n\n const result = await upsertRow({\n adapter: this,\n collectionSlug,\n customID,\n data,\n db,\n fields: collection.flattenedFields,\n ignoreResult: returning === false,\n operation: 'create',\n req,\n select,\n tableName,\n })\n\n if (returning === false) {\n return null\n }\n\n return result\n}\n"],"names":["toSnakeCase","upsertRow","getPrimaryDb","getTransaction","create","collection","collectionSlug","customID","data","req","returning","select","cms","collections","config","tableName","tableNameMap","get","slug","db","result","adapter","fields","flattenedFields","ignoreResult","operation"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,MAAMC,SAAiB,eAAeA,OAE3C,EAAEC,YAAYC,cAAc,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,EAAE;IAEtE,MAAMN,aAAa,IAAI,CAACO,GAAG,CAACC,WAAW,CAACP,eAAe,CAACQ,MAAM;IAE9D,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACjB,YAAYK,WAAWa,IAAI;IAEnE,MAAMC,KAAKjB,aAAa,IAAI,EAAE,MAAMC,eAAe,IAAI,EAAEM;IAEzD,MAAMW,SAAS,MAAMnB,UAAU;QAC7BoB,SAAS,IAAI;QACbf;QACAC;QACAC;QACAW;QACAG,QAAQjB,WAAWkB,eAAe;QAClCC,cAAcd,cAAc;QAC5Be,WAAW;QACXhB;QACAE;QACAI;IACF;IAEA,IAAIL,cAAc,OAAO;QACvB,OAAO;IACT;IAEA,OAAOU;AACT,EAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CreateGlobalArgs } from '@hanzo/cms';
|
|
2
|
+
import type { DrizzleAdapter } from './types.js';
|
|
3
|
+
export declare function createGlobal<T extends Record<string, unknown>>(this: DrizzleAdapter, { slug, data, req, returning }: CreateGlobalArgs): Promise<T>;
|
|
4
|
+
//# sourceMappingURL=createGlobal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createGlobal.d.ts","sourceRoot":"","sources":["../src/createGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAIlD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAMhD,wBAAsB,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClE,IAAI,EAAE,cAAc,EACpB,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,gBAAgB,GAC/C,OAAO,CAAC,CAAC,CAAC,CA4BZ"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import toSnakeCase from 'to-snake-case';
|
|
2
|
+
import { upsertRow } from './upsertRow/index.js';
|
|
3
|
+
import { getPrimaryDb } from './utilities/getPrimaryDb.js';
|
|
4
|
+
import { getTransaction } from './utilities/getTransaction.js';
|
|
5
|
+
export async function createGlobal({ slug, data, req, returning }) {
|
|
6
|
+
const globalConfig = this.cms.globals.config.find((config)=>config.slug === slug);
|
|
7
|
+
const tableName = this.tableNameMap.get(toSnakeCase(globalConfig.slug));
|
|
8
|
+
data.createdAt = new Date().toISOString();
|
|
9
|
+
const db = getPrimaryDb(this, await getTransaction(this, req));
|
|
10
|
+
const result = await upsertRow({
|
|
11
|
+
adapter: this,
|
|
12
|
+
data,
|
|
13
|
+
db,
|
|
14
|
+
fields: globalConfig.flattenedFields,
|
|
15
|
+
globalSlug: slug,
|
|
16
|
+
ignoreResult: returning === false,
|
|
17
|
+
operation: 'create',
|
|
18
|
+
req,
|
|
19
|
+
tableName
|
|
20
|
+
});
|
|
21
|
+
if (returning === false) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
result.globalType = slug;
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=createGlobal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/createGlobal.ts"],"sourcesContent":["import type { CreateGlobalArgs } from '@hanzo/cms'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\nimport { getPrimaryDb } from './utilities/getPrimaryDb.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport async function createGlobal<T extends Record<string, unknown>>(\n this: DrizzleAdapter,\n { slug, data, req, returning }: CreateGlobalArgs,\n): Promise<T> {\n const globalConfig = this.cms.globals.config.find((config) => config.slug === slug)\n\n const tableName = this.tableNameMap.get(toSnakeCase(globalConfig.slug))\n\n data.createdAt = new Date().toISOString()\n\n const db = getPrimaryDb(this, await getTransaction(this, req))\n\n const result = await upsertRow<{ globalType: string } & T>({\n adapter: this,\n data,\n db,\n fields: globalConfig.flattenedFields,\n globalSlug: slug,\n ignoreResult: returning === false,\n operation: 'create',\n req,\n tableName,\n })\n\n if (returning === false) {\n return null\n }\n\n result.globalType = slug\n\n return result\n}\n"],"names":["toSnakeCase","upsertRow","getPrimaryDb","getTransaction","createGlobal","slug","data","req","returning","globalConfig","cms","globals","config","find","tableName","tableNameMap","get","createdAt","Date","toISOString","db","result","adapter","fields","flattenedFields","globalSlug","ignoreResult","operation","globalType"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,eAAeC,aAEpB,EAAEC,IAAI,EAAEC,IAAI,EAAEC,GAAG,EAAEC,SAAS,EAAoB;IAEhD,MAAMC,eAAe,IAAI,CAACC,GAAG,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAACD,SAAWA,OAAOP,IAAI,KAAKA;IAE9E,MAAMS,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAAChB,YAAYS,aAAaJ,IAAI;IAErEC,KAAKW,SAAS,GAAG,IAAIC,OAAOC,WAAW;IAEvC,MAAMC,KAAKlB,aAAa,IAAI,EAAE,MAAMC,eAAe,IAAI,EAAEI;IAEzD,MAAMc,SAAS,MAAMpB,UAAsC;QACzDqB,SAAS,IAAI;QACbhB;QACAc;QACAG,QAAQd,aAAae,eAAe;QACpCC,YAAYpB;QACZqB,cAAclB,cAAc;QAC5BmB,WAAW;QACXpB;QACAO;IACF;IAEA,IAAIN,cAAc,OAAO;QACvB,OAAO;IACT;IAEAa,OAAOO,UAAU,GAAGvB;IAEpB,OAAOgB;AACT"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CreateGlobalVersionArgs, JsonObject, TypeWithVersion } from '@hanzo/cms';
|
|
2
|
+
import type { DrizzleAdapter } from './types.js';
|
|
3
|
+
export declare function createGlobalVersion<T extends JsonObject = JsonObject>(this: DrizzleAdapter, { autosave, createdAt, globalSlug, publishedLocale, req, returning, select, snapshot, updatedAt, versionData, }: CreateGlobalVersionArgs): Promise<TypeWithVersion<T>>;
|
|
4
|
+
//# sourceMappingURL=createGlobalVersion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createGlobalVersion.d.ts","sourceRoot":"","sources":["../src/createGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAOtF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAMhD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EACzE,IAAI,EAAE,cAAc,EACpB,EACE,QAAQ,EACR,SAAS,EACT,UAAU,EACV,eAAe,EACf,GAAG,EACH,SAAS,EACT,MAAM,EACN,QAAQ,EACR,SAAS,EACT,WAAW,GACZ,EAAE,uBAAuB,GACzB,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CA6C7B"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { buildVersionGlobalFields } from '@hanzo/cms';
|
|
3
|
+
import { hasDraftsEnabled } from '@hanzo/cms/shared';
|
|
4
|
+
import toSnakeCase from 'to-snake-case';
|
|
5
|
+
import { upsertRow } from './upsertRow/index.js';
|
|
6
|
+
import { getPrimaryDb } from './utilities/getPrimaryDb.js';
|
|
7
|
+
import { getTransaction } from './utilities/getTransaction.js';
|
|
8
|
+
export async function createGlobalVersion({ autosave, createdAt, globalSlug, publishedLocale, req, returning, select, snapshot, updatedAt, versionData }) {
|
|
9
|
+
const global = this.cms.globals.config.find(({ slug })=>slug === globalSlug);
|
|
10
|
+
const tableName = this.tableNameMap.get(`_${toSnakeCase(global.slug)}${this.versionsSuffix}`);
|
|
11
|
+
const db = getPrimaryDb(this, await getTransaction(this, req));
|
|
12
|
+
const result = await upsertRow({
|
|
13
|
+
adapter: this,
|
|
14
|
+
data: {
|
|
15
|
+
autosave,
|
|
16
|
+
createdAt,
|
|
17
|
+
latest: true,
|
|
18
|
+
publishedLocale,
|
|
19
|
+
snapshot,
|
|
20
|
+
updatedAt,
|
|
21
|
+
version: versionData
|
|
22
|
+
},
|
|
23
|
+
db,
|
|
24
|
+
fields: buildVersionGlobalFields(this.cms.config, global, true),
|
|
25
|
+
globalSlug,
|
|
26
|
+
ignoreResult: returning === false ? 'idOnly' : false,
|
|
27
|
+
operation: 'create',
|
|
28
|
+
req,
|
|
29
|
+
select,
|
|
30
|
+
tableName
|
|
31
|
+
});
|
|
32
|
+
const table = this.tables[tableName];
|
|
33
|
+
if (hasDraftsEnabled(global)) {
|
|
34
|
+
await this.execute({
|
|
35
|
+
db,
|
|
36
|
+
sql: sql`
|
|
37
|
+
UPDATE ${table}
|
|
38
|
+
SET latest = false
|
|
39
|
+
WHERE ${table.id} != ${result.id};
|
|
40
|
+
`
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (returning === false) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=createGlobalVersion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import type { CreateGlobalVersionArgs, JsonObject, TypeWithVersion } from '@hanzo/cms'\n\nimport { sql } from 'drizzle-orm'\nimport { buildVersionGlobalFields } from '@hanzo/cms'\nimport { hasDraftsEnabled } from '@hanzo/cms/shared'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\nimport { getPrimaryDb } from './utilities/getPrimaryDb.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport async function createGlobalVersion<T extends JsonObject = JsonObject>(\n this: DrizzleAdapter,\n {\n autosave,\n createdAt,\n globalSlug,\n publishedLocale,\n req,\n returning,\n select,\n snapshot,\n updatedAt,\n versionData,\n }: CreateGlobalVersionArgs,\n): Promise<TypeWithVersion<T>> {\n const global = this.cms.globals.config.find(({ slug }) => slug === globalSlug)\n\n const tableName = this.tableNameMap.get(`_${toSnakeCase(global.slug)}${this.versionsSuffix}`)\n\n const db = getPrimaryDb(this, await getTransaction(this, req))\n\n const result = await upsertRow<TypeWithVersion<T>>({\n adapter: this,\n data: {\n autosave,\n createdAt,\n latest: true,\n publishedLocale,\n snapshot,\n updatedAt,\n version: versionData,\n },\n db,\n fields: buildVersionGlobalFields(this.cms.config, global, true),\n globalSlug,\n ignoreResult: returning === false ? 'idOnly' : false,\n operation: 'create',\n req,\n select,\n tableName,\n })\n\n const table = this.tables[tableName]\n if (hasDraftsEnabled(global)) {\n await this.execute({\n db,\n sql: sql`\n UPDATE ${table}\n SET latest = false\n WHERE ${table.id} != ${result.id};\n `,\n })\n }\n\n if (returning === false) {\n return null\n }\n\n return result\n}\n"],"names":["sql","buildVersionGlobalFields","hasDraftsEnabled","toSnakeCase","upsertRow","getPrimaryDb","getTransaction","createGlobalVersion","autosave","createdAt","globalSlug","publishedLocale","req","returning","select","snapshot","updatedAt","versionData","global","cms","globals","config","find","slug","tableName","tableNameMap","get","versionsSuffix","db","result","adapter","data","latest","version","fields","ignoreResult","operation","table","tables","execute","id"],"mappings":"AAEA,SAASA,GAAG,QAAQ,cAAa;AACjC,SAASC,wBAAwB,QAAQ,aAAY;AACrD,SAASC,gBAAgB,QAAQ,oBAAmB;AACpD,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,eAAeC,oBAEpB,EACEC,QAAQ,EACRC,SAAS,EACTC,UAAU,EACVC,eAAe,EACfC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACa;IAE1B,MAAMC,SAAS,IAAI,CAACC,GAAG,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASb;IAEnE,MAAMc,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAAC,CAAC,CAAC,EAAEvB,YAAYe,OAAOK,IAAI,IAAI,IAAI,CAACI,cAAc,EAAE;IAE5F,MAAMC,KAAKvB,aAAa,IAAI,EAAE,MAAMC,eAAe,IAAI,EAAEM;IAEzD,MAAMiB,SAAS,MAAMzB,UAA8B;QACjD0B,SAAS,IAAI;QACbC,MAAM;YACJvB;YACAC;YACAuB,QAAQ;YACRrB;YACAI;YACAC;YACAiB,SAAShB;QACX;QACAW;QACAM,QAAQjC,yBAAyB,IAAI,CAACkB,GAAG,CAACE,MAAM,EAAEH,QAAQ;QAC1DR;QACAyB,cAActB,cAAc,QAAQ,WAAW;QAC/CuB,WAAW;QACXxB;QACAE;QACAU;IACF;IAEA,MAAMa,QAAQ,IAAI,CAACC,MAAM,CAACd,UAAU;IACpC,IAAItB,iBAAiBgB,SAAS;QAC5B,MAAM,IAAI,CAACqB,OAAO,CAAC;YACjBX;YACA5B,KAAKA,GAAG,CAAC;iBACE,EAAEqC,MAAM;;gBAET,EAAEA,MAAMG,EAAE,CAAC,IAAI,EAAEX,OAAOW,EAAE,CAAC;QACnC,CAAC;QACL;IACF;IAEA,IAAI3B,cAAc,OAAO;QACvB,OAAO;IACT;IAEA,OAAOgB;AACT"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { DBIdentifierName } from '@hanzo/cms';
|
|
2
|
+
import type { DrizzleAdapter } from './types.js';
|
|
3
|
+
type Args = {
|
|
4
|
+
adapter: Pick<DrizzleAdapter, 'tableNameMap' | 'versionsSuffix'>;
|
|
5
|
+
/** The collection, global or field config **/
|
|
6
|
+
config: {
|
|
7
|
+
dbName?: DBIdentifierName;
|
|
8
|
+
enumName?: DBIdentifierName;
|
|
9
|
+
name?: string;
|
|
10
|
+
slug?: string;
|
|
11
|
+
};
|
|
12
|
+
/** For nested tables passed for the user custom dbName functions to handle their own iterations */
|
|
13
|
+
parentTableName?: string;
|
|
14
|
+
/** For sub tables (array for example) this needs to include the parentTableName */
|
|
15
|
+
prefix?: string;
|
|
16
|
+
/** For tables based on fields that could have both enumName and dbName (ie: select with hasMany), default: 'dbName' */
|
|
17
|
+
target?: 'dbName' | 'enumName';
|
|
18
|
+
/** Throws error if true for postgres when table and enum names exceed 63 characters */
|
|
19
|
+
throwValidationError?: boolean;
|
|
20
|
+
/** Adds the versions suffix to the default table name - should only be used on the base collection to avoid duplicate suffixing */
|
|
21
|
+
versions?: boolean;
|
|
22
|
+
/** Adds the versions suffix to custom dbName only - this is used while creating blocks / selects / arrays / etc */
|
|
23
|
+
versionsCustomName?: boolean;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Used to name database enums and tables
|
|
27
|
+
* Returns the table or enum name for a given entity
|
|
28
|
+
*/
|
|
29
|
+
export declare const createTableName: ({ adapter, config: { name, slug }, config, parentTableName, prefix, target, throwValidationError, versions, versionsCustomName, }: Args) => string;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=createTableName.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTableName.d.ts","sourceRoot":"","sources":["../src/createTableName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAKlD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,cAAc,GAAG,gBAAgB,CAAC,CAAA;IAChE,8CAA8C;IAC9C,MAAM,EAAE;QACN,MAAM,CAAC,EAAE,gBAAgB,CAAA;QACzB,QAAQ,CAAC,EAAE,gBAAgB,CAAA;QAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,CAAA;IACD,mGAAmG;IACnG,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,mFAAmF;IACnF,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,uHAAuH;IACvH,MAAM,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAA;IAC9B,uFAAuF;IACvF,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,mIAAmI;IACnI,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,mHAAmH;IACnH,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,sIAUzB,IAAI,KAAG,MA2CT,CAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { APIError } from '@hanzo/cms';
|
|
2
|
+
import toSnakeCase from 'to-snake-case';
|
|
3
|
+
/**
|
|
4
|
+
* Used to name database enums and tables
|
|
5
|
+
* Returns the table or enum name for a given entity
|
|
6
|
+
*/ export const createTableName = ({ adapter, config: { name, slug }, config, parentTableName, prefix = '', target = 'dbName', throwValidationError = false, versions = false, versionsCustomName = false })=>{
|
|
7
|
+
let customNameDefinition = config[target];
|
|
8
|
+
let defaultTableName = `${prefix}${toSnakeCase(name ?? slug)}`;
|
|
9
|
+
if (versions) {
|
|
10
|
+
defaultTableName = `_${defaultTableName}${adapter.versionsSuffix}`;
|
|
11
|
+
}
|
|
12
|
+
let customTableNameResult;
|
|
13
|
+
if (!customNameDefinition && target === 'enumName') {
|
|
14
|
+
customNameDefinition = config['dbName'];
|
|
15
|
+
}
|
|
16
|
+
if (customNameDefinition) {
|
|
17
|
+
customTableNameResult = typeof customNameDefinition === 'function' ? customNameDefinition({
|
|
18
|
+
tableName: parentTableName
|
|
19
|
+
}) : customNameDefinition;
|
|
20
|
+
if (versionsCustomName) {
|
|
21
|
+
customTableNameResult = `_${customTableNameResult}${adapter.versionsSuffix}`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const result = customTableNameResult || defaultTableName;
|
|
25
|
+
adapter.tableNameMap.set(defaultTableName, result);
|
|
26
|
+
if (!throwValidationError) {
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
if (result.length > 63) {
|
|
30
|
+
throw new APIError(`Exceeded max identifier length for table or enum name of 63 characters. Invalid name: ${result}.
|
|
31
|
+
Tip: You can use the dbName property to reduce the table name length.
|
|
32
|
+
`);
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=createTableName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/createTableName.ts"],"sourcesContent":["import type { DBIdentifierName } from '@hanzo/cms'\n\nimport { APIError } from '@hanzo/cms'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\ntype Args = {\n adapter: Pick<DrizzleAdapter, 'tableNameMap' | 'versionsSuffix'>\n /** The collection, global or field config **/\n config: {\n dbName?: DBIdentifierName\n enumName?: DBIdentifierName\n name?: string\n slug?: string\n }\n /** For nested tables passed for the user custom dbName functions to handle their own iterations */\n parentTableName?: string\n /** For sub tables (array for example) this needs to include the parentTableName */\n prefix?: string\n /** For tables based on fields that could have both enumName and dbName (ie: select with hasMany), default: 'dbName' */\n target?: 'dbName' | 'enumName'\n /** Throws error if true for postgres when table and enum names exceed 63 characters */\n throwValidationError?: boolean\n /** Adds the versions suffix to the default table name - should only be used on the base collection to avoid duplicate suffixing */\n versions?: boolean\n /** Adds the versions suffix to custom dbName only - this is used while creating blocks / selects / arrays / etc */\n versionsCustomName?: boolean\n}\n\n/**\n * Used to name database enums and tables\n * Returns the table or enum name for a given entity\n */\nexport const createTableName = ({\n adapter,\n config: { name, slug },\n config,\n parentTableName,\n prefix = '',\n target = 'dbName',\n throwValidationError = false,\n versions = false,\n versionsCustomName = false,\n}: Args): string => {\n let customNameDefinition = config[target]\n\n let defaultTableName = `${prefix}${toSnakeCase(name ?? slug)}`\n\n if (versions) {\n defaultTableName = `_${defaultTableName}${adapter.versionsSuffix}`\n }\n\n let customTableNameResult: string\n\n if (!customNameDefinition && target === 'enumName') {\n customNameDefinition = config['dbName']\n }\n\n if (customNameDefinition) {\n customTableNameResult =\n typeof customNameDefinition === 'function'\n ? customNameDefinition({ tableName: parentTableName })\n : customNameDefinition\n\n if (versionsCustomName) {\n customTableNameResult = `_${customTableNameResult}${adapter.versionsSuffix}`\n }\n }\n\n const result = customTableNameResult || defaultTableName\n\n adapter.tableNameMap.set(defaultTableName, result)\n\n if (!throwValidationError) {\n return result\n }\n\n if (result.length > 63) {\n throw new APIError(\n `Exceeded max identifier length for table or enum name of 63 characters. Invalid name: ${result}.\nTip: You can use the dbName property to reduce the table name length.\n `,\n )\n }\n\n return result\n}\n"],"names":["APIError","toSnakeCase","createTableName","adapter","config","name","slug","parentTableName","prefix","target","throwValidationError","versions","versionsCustomName","customNameDefinition","defaultTableName","versionsSuffix","customTableNameResult","tableName","result","tableNameMap","set","length"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,aAAY;AACrC,OAAOC,iBAAiB,gBAAe;AA2BvC;;;CAGC,GACD,OAAO,MAAMC,kBAAkB,CAAC,EAC9BC,OAAO,EACPC,QAAQ,EAAEC,IAAI,EAAEC,IAAI,EAAE,EACtBF,MAAM,EACNG,eAAe,EACfC,SAAS,EAAE,EACXC,SAAS,QAAQ,EACjBC,uBAAuB,KAAK,EAC5BC,WAAW,KAAK,EAChBC,qBAAqB,KAAK,EACrB;IACL,IAAIC,uBAAuBT,MAAM,CAACK,OAAO;IAEzC,IAAIK,mBAAmB,GAAGN,SAASP,YAAYI,QAAQC,OAAO;IAE9D,IAAIK,UAAU;QACZG,mBAAmB,CAAC,CAAC,EAAEA,mBAAmBX,QAAQY,cAAc,EAAE;IACpE;IAEA,IAAIC;IAEJ,IAAI,CAACH,wBAAwBJ,WAAW,YAAY;QAClDI,uBAAuBT,MAAM,CAAC,SAAS;IACzC;IAEA,IAAIS,sBAAsB;QACxBG,wBACE,OAAOH,yBAAyB,aAC5BA,qBAAqB;YAAEI,WAAWV;QAAgB,KAClDM;QAEN,IAAID,oBAAoB;YACtBI,wBAAwB,CAAC,CAAC,EAAEA,wBAAwBb,QAAQY,cAAc,EAAE;QAC9E;IACF;IAEA,MAAMG,SAASF,yBAAyBF;IAExCX,QAAQgB,YAAY,CAACC,GAAG,CAACN,kBAAkBI;IAE3C,IAAI,CAACR,sBAAsB;QACzB,OAAOQ;IACT;IAEA,IAAIA,OAAOG,MAAM,GAAG,IAAI;QACtB,MAAM,IAAIrB,SACR,CAAC,sFAAsF,EAAEkB,OAAO;;MAEhG,CAAC;IAEL;IAEA,OAAOA;AACT,EAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CreateVersionArgs, JsonObject, TypeWithVersion } from '@hanzo/cms';
|
|
2
|
+
import type { DrizzleAdapter } from './types.js';
|
|
3
|
+
export declare function createVersion<T extends JsonObject = JsonObject>(this: DrizzleAdapter, { autosave, collectionSlug, createdAt, parent, publishedLocale, req, returning, select, snapshot, updatedAt, versionData, }: CreateVersionArgs<T>): Promise<TypeWithVersion<T>>;
|
|
4
|
+
//# sourceMappingURL=createVersion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createVersion.d.ts","sourceRoot":"","sources":["../src/createVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAOhF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAMhD,wBAAsB,aAAa,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EACnE,IAAI,EAAE,cAAc,EACpB,EACE,QAAQ,EACR,cAAc,EACd,SAAS,EACT,MAAM,EACN,eAAe,EACf,GAAG,EACH,SAAS,EACT,MAAM,EACN,QAAQ,EACR,SAAS,EACT,WAAW,GACZ,EAAE,iBAAiB,CAAC,CAAC,CAAC,GACtB,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CA8D7B"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { buildVersionCollectionFields } from '@hanzo/cms';
|
|
3
|
+
import { hasDraftsEnabled } from '@hanzo/cms/shared';
|
|
4
|
+
import toSnakeCase from 'to-snake-case';
|
|
5
|
+
import { upsertRow } from './upsertRow/index.js';
|
|
6
|
+
import { getPrimaryDb } from './utilities/getPrimaryDb.js';
|
|
7
|
+
import { getTransaction } from './utilities/getTransaction.js';
|
|
8
|
+
export async function createVersion({ autosave, collectionSlug, createdAt, parent, publishedLocale, req, returning, select, snapshot, updatedAt, versionData }) {
|
|
9
|
+
const collection = this.cms.collections[collectionSlug].config;
|
|
10
|
+
if (collection.versions.drafts) {
|
|
11
|
+
if (typeof select === 'object') {
|
|
12
|
+
select.updatedAt = true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const defaultTableName = toSnakeCase(collection.slug);
|
|
16
|
+
const tableName = this.tableNameMap.get(`_${defaultTableName}${this.versionsSuffix}`);
|
|
17
|
+
const version = {
|
|
18
|
+
...versionData
|
|
19
|
+
};
|
|
20
|
+
if (version.id) {
|
|
21
|
+
delete version.id;
|
|
22
|
+
}
|
|
23
|
+
const data = {
|
|
24
|
+
autosave,
|
|
25
|
+
createdAt,
|
|
26
|
+
latest: true,
|
|
27
|
+
parent,
|
|
28
|
+
publishedLocale,
|
|
29
|
+
snapshot,
|
|
30
|
+
updatedAt,
|
|
31
|
+
version
|
|
32
|
+
};
|
|
33
|
+
const db = getPrimaryDb(this, await getTransaction(this, req));
|
|
34
|
+
const result = await upsertRow({
|
|
35
|
+
adapter: this,
|
|
36
|
+
collectionSlug,
|
|
37
|
+
data,
|
|
38
|
+
db,
|
|
39
|
+
fields: buildVersionCollectionFields(this.cms.config, collection, true),
|
|
40
|
+
ignoreResult: returning === false ? 'idOnly' : undefined,
|
|
41
|
+
operation: 'create',
|
|
42
|
+
req,
|
|
43
|
+
select,
|
|
44
|
+
tableName
|
|
45
|
+
});
|
|
46
|
+
const table = this.tables[tableName];
|
|
47
|
+
if (hasDraftsEnabled(collection)) {
|
|
48
|
+
await this.execute({
|
|
49
|
+
db,
|
|
50
|
+
sql: sql`
|
|
51
|
+
UPDATE ${table}
|
|
52
|
+
SET latest = false
|
|
53
|
+
WHERE ${table.id} != ${result.id}
|
|
54
|
+
AND ${table.parent} = ${parent}
|
|
55
|
+
AND ${table.updatedAt} < ${result.updatedAt || updatedAt}
|
|
56
|
+
`
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (returning === false) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=createVersion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import type { CreateVersionArgs, JsonObject, TypeWithVersion } from '@hanzo/cms'\n\nimport { sql } from 'drizzle-orm'\nimport { buildVersionCollectionFields } from '@hanzo/cms'\nimport { hasDraftsEnabled } from '@hanzo/cms/shared'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\nimport { getPrimaryDb } from './utilities/getPrimaryDb.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport async function createVersion<T extends JsonObject = JsonObject>(\n this: DrizzleAdapter,\n {\n autosave,\n collectionSlug,\n createdAt,\n parent,\n publishedLocale,\n req,\n returning,\n select,\n snapshot,\n updatedAt,\n versionData,\n }: CreateVersionArgs<T>,\n): Promise<TypeWithVersion<T>> {\n const collection = this.cms.collections[collectionSlug].config\n if (collection.versions.drafts) {\n if (typeof select === 'object') {\n select.updatedAt = true\n }\n }\n\n const defaultTableName = toSnakeCase(collection.slug)\n const tableName = this.tableNameMap.get(`_${defaultTableName}${this.versionsSuffix}`)\n\n const version = { ...versionData }\n if (version.id) {\n delete version.id\n }\n\n const data: Record<string, unknown> = {\n autosave,\n createdAt,\n latest: true,\n parent,\n publishedLocale,\n snapshot,\n updatedAt,\n version,\n }\n\n const db = getPrimaryDb(this, await getTransaction(this, req))\n\n const result = await upsertRow<TypeWithVersion<T>>({\n adapter: this,\n collectionSlug,\n data,\n db,\n fields: buildVersionCollectionFields(this.cms.config, collection, true),\n ignoreResult: returning === false ? 'idOnly' : undefined,\n operation: 'create',\n req,\n select,\n tableName,\n })\n\n const table = this.tables[tableName]\n\n if (hasDraftsEnabled(collection)) {\n await this.execute({\n db,\n sql: sql`\n UPDATE ${table}\n SET latest = false\n WHERE ${table.id} != ${result.id}\n AND ${table.parent} = ${parent}\n AND ${table.updatedAt} < ${result.updatedAt || updatedAt}\n `,\n })\n }\n\n if (returning === false) {\n return null\n }\n\n return result\n}\n"],"names":["sql","buildVersionCollectionFields","hasDraftsEnabled","toSnakeCase","upsertRow","getPrimaryDb","getTransaction","createVersion","autosave","collectionSlug","createdAt","parent","publishedLocale","req","returning","select","snapshot","updatedAt","versionData","collection","cms","collections","config","versions","drafts","defaultTableName","slug","tableName","tableNameMap","get","versionsSuffix","version","id","data","latest","db","result","adapter","fields","ignoreResult","undefined","operation","table","tables","execute"],"mappings":"AAEA,SAASA,GAAG,QAAQ,cAAa;AACjC,SAASC,4BAA4B,QAAQ,aAAY;AACzD,SAASC,gBAAgB,QAAQ,oBAAmB;AACpD,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,eAAeC,cAEpB,EACEC,QAAQ,EACRC,cAAc,EACdC,SAAS,EACTC,MAAM,EACNC,eAAe,EACfC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACU;IAEvB,MAAMC,aAAa,IAAI,CAACC,GAAG,CAACC,WAAW,CAACZ,eAAe,CAACa,MAAM;IAC9D,IAAIH,WAAWI,QAAQ,CAACC,MAAM,EAAE;QAC9B,IAAI,OAAOT,WAAW,UAAU;YAC9BA,OAAOE,SAAS,GAAG;QACrB;IACF;IAEA,MAAMQ,mBAAmBtB,YAAYgB,WAAWO,IAAI;IACpD,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAAC,CAAC,CAAC,EAAEJ,mBAAmB,IAAI,CAACK,cAAc,EAAE;IAEpF,MAAMC,UAAU;QAAE,GAAGb,WAAW;IAAC;IACjC,IAAIa,QAAQC,EAAE,EAAE;QACd,OAAOD,QAAQC,EAAE;IACnB;IAEA,MAAMC,OAAgC;QACpCzB;QACAE;QACAwB,QAAQ;QACRvB;QACAC;QACAI;QACAC;QACAc;IACF;IAEA,MAAMI,KAAK9B,aAAa,IAAI,EAAE,MAAMC,eAAe,IAAI,EAAEO;IAEzD,MAAMuB,SAAS,MAAMhC,UAA8B;QACjDiC,SAAS,IAAI;QACb5B;QACAwB;QACAE;QACAG,QAAQrC,6BAA6B,IAAI,CAACmB,GAAG,CAACE,MAAM,EAAEH,YAAY;QAClEoB,cAAczB,cAAc,QAAQ,WAAW0B;QAC/CC,WAAW;QACX5B;QACAE;QACAY;IACF;IAEA,MAAMe,QAAQ,IAAI,CAACC,MAAM,CAAChB,UAAU;IAEpC,IAAIzB,iBAAiBiB,aAAa;QAChC,MAAM,IAAI,CAACyB,OAAO,CAAC;YACjBT;YACAnC,KAAKA,GAAG,CAAC;eACA,EAAE0C,MAAM;;cAET,EAAEA,MAAMV,EAAE,CAAC,IAAI,EAAEI,OAAOJ,EAAE,CAAC;cAC3B,EAAEU,MAAM/B,MAAM,CAAC,GAAG,EAAEA,OAAO;cAC3B,EAAE+B,MAAMzB,SAAS,CAAC,GAAG,EAAEmB,OAAOnB,SAAS,IAAIA,UAAU;MAC7D,CAAC;QACH;IACF;IAEA,IAAIH,cAAc,OAAO;QACvB,OAAO;IACT;IAEA,OAAOsB;AACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleteMany.d.ts","sourceRoot":"","sources":["../src/deleteMany.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAY5C,eAAO,MAAM,UAAU,EAAE,UAyDxB,CAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { inArray } from 'drizzle-orm';
|
|
2
|
+
import toSnakeCase from 'to-snake-case';
|
|
3
|
+
import { findMany } from './find/findMany.js';
|
|
4
|
+
import { buildQuery } from './queries/buildQuery.js';
|
|
5
|
+
import { getTransaction } from './utilities/getTransaction.js';
|
|
6
|
+
import { markWrite } from './utilities/readAfterWrite.js';
|
|
7
|
+
export const deleteMany = async function deleteMany({ collection, req, where: whereArg }) {
|
|
8
|
+
const collectionConfig = this.cms.collections[collection].config;
|
|
9
|
+
const tableName = this.tableNameMap.get(toSnakeCase(collectionConfig.slug));
|
|
10
|
+
const table = this.tables[tableName];
|
|
11
|
+
const { joins, where } = buildQuery({
|
|
12
|
+
adapter: this,
|
|
13
|
+
fields: collectionConfig.flattenedFields,
|
|
14
|
+
locale: req?.locale,
|
|
15
|
+
tableName,
|
|
16
|
+
where: whereArg
|
|
17
|
+
});
|
|
18
|
+
let whereToUse = where;
|
|
19
|
+
if (joins?.length) {
|
|
20
|
+
// Difficult to support joins (through where referencing other tables) in deleteMany. => 2 separate queries.
|
|
21
|
+
// We can look into supporting this using one single query (through a subquery) in the future, though that's difficult to do in a generic way.
|
|
22
|
+
const result = await findMany({
|
|
23
|
+
adapter: this,
|
|
24
|
+
fields: collectionConfig.flattenedFields,
|
|
25
|
+
joins: false,
|
|
26
|
+
limit: 0,
|
|
27
|
+
locale: req?.locale,
|
|
28
|
+
page: 1,
|
|
29
|
+
pagination: false,
|
|
30
|
+
req,
|
|
31
|
+
select: {
|
|
32
|
+
id: true
|
|
33
|
+
},
|
|
34
|
+
tableName,
|
|
35
|
+
where: whereArg
|
|
36
|
+
});
|
|
37
|
+
whereToUse = inArray(table.id, result.docs.map((doc)=>doc.id));
|
|
38
|
+
}
|
|
39
|
+
// No getPrimaryDb needed: db is only used for deleteWhere (a write, always routed to primary
|
|
40
|
+
// by drizzle's withReplicas). findMany resolves its own db via getTransaction, which returns
|
|
41
|
+
// the transaction db (always primary) or falls back to shouldReadFromPrimary.
|
|
42
|
+
const db = await getTransaction(this, req);
|
|
43
|
+
await this.deleteWhere({
|
|
44
|
+
db,
|
|
45
|
+
tableName,
|
|
46
|
+
where: whereToUse
|
|
47
|
+
});
|
|
48
|
+
markWrite(this);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=deleteMany.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteMany } from '@hanzo/cms'\n\nimport { inArray } from 'drizzle-orm'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getTransaction } from './utilities/getTransaction.js'\nimport { markWrite } from './utilities/readAfterWrite.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: DrizzleAdapter,\n { collection, req, where: whereArg },\n) {\n const collectionConfig = this.cms.collections[collection].config\n\n const tableName = this.tableNameMap.get(toSnakeCase(collectionConfig.slug))\n\n const table = this.tables[tableName]\n\n const { joins, where } = buildQuery({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n locale: req?.locale,\n tableName,\n where: whereArg,\n })\n\n let whereToUse = where\n\n if (joins?.length) {\n // Difficult to support joins (through where referencing other tables) in deleteMany. => 2 separate queries.\n // We can look into supporting this using one single query (through a subquery) in the future, though that's difficult to do in a generic way.\n const result = await findMany({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n joins: false,\n limit: 0,\n locale: req?.locale,\n page: 1,\n pagination: false,\n req,\n select: {\n id: true,\n },\n tableName,\n where: whereArg,\n })\n\n whereToUse = inArray(\n table.id,\n result.docs.map((doc) => doc.id),\n )\n }\n\n // No getPrimaryDb needed: db is only used for deleteWhere (a write, always routed to primary\n // by drizzle's withReplicas). findMany resolves its own db via getTransaction, which returns\n // the transaction db (always primary) or falls back to shouldReadFromPrimary.\n const db = await getTransaction(this, req)\n\n await this.deleteWhere({\n db,\n tableName,\n where: whereToUse,\n })\n\n markWrite(this)\n}\n"],"names":["inArray","toSnakeCase","findMany","buildQuery","getTransaction","markWrite","deleteMany","collection","req","where","whereArg","collectionConfig","cms","collections","config","tableName","tableNameMap","get","slug","table","tables","joins","adapter","fields","flattenedFields","locale","whereToUse","length","result","limit","page","pagination","select","id","docs","map","doc","db","deleteWhere"],"mappings":"AAEA,SAASA,OAAO,QAAQ,cAAa;AACrC,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAC7C,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,gCAA+B;AAC9D,SAASC,SAAS,QAAQ,gCAA+B;AAEzD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,UAAU,EAAEC,GAAG,EAAEC,OAAOC,QAAQ,EAAE;IAEpC,MAAMC,mBAAmB,IAAI,CAACC,GAAG,CAACC,WAAW,CAACN,WAAW,CAACO,MAAM;IAEhE,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAAChB,YAAYU,iBAAiBO,IAAI;IAEzE,MAAMC,QAAQ,IAAI,CAACC,MAAM,CAACL,UAAU;IAEpC,MAAM,EAAEM,KAAK,EAAEZ,KAAK,EAAE,GAAGN,WAAW;QAClCmB,SAAS,IAAI;QACbC,QAAQZ,iBAAiBa,eAAe;QACxCC,QAAQjB,KAAKiB;QACbV;QACAN,OAAOC;IACT;IAEA,IAAIgB,aAAajB;IAEjB,IAAIY,OAAOM,QAAQ;QACjB,4GAA4G;QAC5G,8IAA8I;QAC9I,MAAMC,SAAS,MAAM1B,SAAS;YAC5BoB,SAAS,IAAI;YACbC,QAAQZ,iBAAiBa,eAAe;YACxCH,OAAO;YACPQ,OAAO;YACPJ,QAAQjB,KAAKiB;YACbK,MAAM;YACNC,YAAY;YACZvB;YACAwB,QAAQ;gBACNC,IAAI;YACN;YACAlB;YACAN,OAAOC;QACT;QAEAgB,aAAa1B,QACXmB,MAAMc,EAAE,EACRL,OAAOM,IAAI,CAACC,GAAG,CAAC,CAACC,MAAQA,IAAIH,EAAE;IAEnC;IAEA,6FAA6F;IAC7F,6FAA6F;IAC7F,8EAA8E;IAC9E,MAAMI,KAAK,MAAMjC,eAAe,IAAI,EAAEI;IAEtC,MAAM,IAAI,CAAC8B,WAAW,CAAC;QACrBD;QACAtB;QACAN,OAAOiB;IACT;IAEArB,UAAU,IAAI;AAChB,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAe3C,eAAO,MAAM,SAAS,EAAE,SA0EvB,CAAA"}
|