@hot-updater/server 0.33.2 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.cjs +0 -2
- package/dist/adapters/drizzle.cjs +195 -2
- package/dist/adapters/drizzle.d.cts +7 -4
- package/dist/adapters/drizzle.d.mts +7 -4
- package/dist/adapters/drizzle.mjs +194 -2
- package/dist/adapters/drizzleLazyDB.cjs +53 -0
- package/dist/adapters/drizzleLazyDB.mjs +53 -0
- package/dist/adapters/kysely.cjs +154 -3
- package/dist/adapters/kysely.d.cts +18 -10
- package/dist/adapters/kysely.d.mts +18 -10
- package/dist/adapters/kysely.mjs +153 -3
- package/dist/adapters/mongodb.cjs +183 -2
- package/dist/adapters/mongodb.d.cts +5 -4
- package/dist/adapters/mongodb.d.mts +5 -4
- package/dist/adapters/mongodb.mjs +183 -2
- package/dist/adapters/prisma.cjs +200 -2
- package/dist/adapters/prisma.d.cts +9 -4
- package/dist/adapters/prisma.d.mts +9 -4
- package/dist/adapters/prisma.mjs +199 -2
- package/dist/db/bundleRows.cjs +82 -0
- package/dist/db/bundleRows.d.cts +33 -0
- package/dist/db/bundleRows.d.mts +33 -0
- package/dist/db/bundleRows.mjs +79 -0
- package/dist/db/fixedMigrator.cjs +136 -0
- package/dist/db/fixedMigrator.mjs +135 -0
- package/dist/db/index.cjs +17 -15
- package/dist/db/index.d.cts +3 -3
- package/dist/db/index.d.mts +3 -3
- package/dist/db/index.mjs +17 -15
- package/dist/db/pluginCore.cjs +13 -5
- package/dist/db/pluginCore.mjs +13 -5
- package/dist/db/schema/mongodb.cjs +17 -0
- package/dist/db/schema/mongodb.mjs +17 -0
- package/dist/db/schema/registry.cjs +23 -0
- package/dist/db/schema/registry.mjs +18 -0
- package/dist/db/schema/sql.cjs +84 -0
- package/dist/db/schema/sql.mjs +78 -0
- package/dist/db/schema/sqlMigrations.cjs +74 -0
- package/dist/db/schema/sqlMigrations.mjs +73 -0
- package/dist/db/schema/sqlOperations.cjs +27 -0
- package/dist/db/schema/sqlOperations.mjs +26 -0
- package/dist/db/schemaEnhancements.cjs +1 -152
- package/dist/db/schemaEnhancements.mjs +1 -149
- package/dist/db/schemaGenerators.cjs +222 -0
- package/dist/db/schemaGenerators.mjs +220 -0
- package/dist/db/schemaReadiness.cjs +23 -0
- package/dist/db/schemaReadiness.d.cts +8 -0
- package/dist/db/schemaReadiness.d.mts +8 -0
- package/dist/db/schemaReadiness.mjs +22 -0
- package/dist/db/types.cjs +10 -2
- package/dist/db/types.d.cts +58 -14
- package/dist/db/types.d.mts +58 -14
- package/dist/db/types.mjs +9 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +2 -2
- package/dist/{packages/server/package.cjs → package.cjs} +1 -1
- package/dist/{packages/server/package.mjs → package.mjs} +1 -1
- package/dist/runtime.cjs +9 -2
- package/dist/runtime.mjs +9 -2
- package/dist/schema/dsl.cjs +86 -0
- package/dist/schema/dsl.mjs +73 -0
- package/dist/schema/index.cjs +13 -0
- package/dist/schema/index.mjs +13 -0
- package/dist/schema/settings.cjs +9 -0
- package/dist/schema/settings.mjs +9 -0
- package/dist/schema/types.cjs +6 -0
- package/dist/schema/types.mjs +5 -0
- package/dist/schema/v0_21_0.cjs +33 -18
- package/dist/schema/v0_21_0.mjs +32 -18
- package/dist/schema/v0_29_0.cjs +40 -20
- package/dist/schema/v0_29_0.mjs +39 -20
- package/dist/schema/v0_31_0.cjs +77 -43
- package/dist/schema/v0_31_0.mjs +75 -43
- package/dist/version.cjs +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +30 -16
- package/src/adapters/drizzle.spec.ts +75 -0
- package/src/adapters/drizzle.ts +328 -12
- package/src/adapters/drizzleLazyDB.ts +151 -0
- package/src/adapters/kysely.spec.ts +107 -0
- package/src/adapters/kysely.ts +349 -14
- package/src/adapters/mongodb.ts +298 -15
- package/src/adapters/prisma.ts +337 -12
- package/src/db/bundleRows.ts +140 -0
- package/src/db/fixedMigrator.spec.ts +89 -0
- package/src/db/fixedMigrator.ts +288 -0
- package/src/db/hotUpdaterSchema.ts +6 -0
- package/src/db/index.spec.ts +976 -13
- package/src/db/index.ts +37 -36
- package/src/db/pluginCore.spec.ts +17 -11
- package/src/db/pluginCore.ts +15 -6
- package/src/db/schema/definitions.ts +1 -0
- package/src/db/schema/mongodb.ts +26 -0
- package/src/db/schema/registry.ts +55 -0
- package/src/db/schema/sql.ts +200 -0
- package/src/db/schema/sqlMigrations.ts +219 -0
- package/src/db/schema/sqlOperations.ts +62 -0
- package/src/db/schema/types.ts +1 -0
- package/src/db/schemaEnhancements.ts +0 -405
- package/src/db/schemaGenerators.ts +382 -0
- package/src/db/schemaReadiness.ts +33 -0
- package/src/db/types.ts +69 -25
- package/src/runtime.spec.ts +70 -0
- package/src/runtime.ts +14 -2
- package/src/schema/dsl-all-versions.spec.ts +26 -0
- package/src/schema/dsl.ts +148 -0
- package/src/schema/index.ts +16 -0
- package/src/schema/settings.ts +15 -0
- package/src/schema/types.ts +73 -0
- package/src/schema/v0_21_0.ts +48 -18
- package/src/schema/v0_29_0.ts +58 -22
- package/src/schema/v0_31_0.spec.ts +73 -0
- package/src/schema/v0_31_0.ts +116 -54
- package/dist/_virtual/_rolldown/runtime.mjs +0 -6
- package/dist/calculatePagination.cjs +0 -25
- package/dist/calculatePagination.mjs +0 -25
- package/dist/db/ormCore.cjs +0 -577
- package/dist/db/ormCore.d.cts +0 -110
- package/dist/db/ormCore.d.mts +0 -110
- package/dist/db/ormCore.mjs +0 -575
- package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/_u64.cjs +0 -112
- package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/_u64.mjs +0 -108
- package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/cryptoNode.cjs +0 -22
- package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/cryptoNode.mjs +0 -18
- package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/sha3.cjs +0 -219
- package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/sha3.mjs +0 -214
- package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/utils.cjs +0 -275
- package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/utils.mjs +0 -270
- package/dist/node_modules/.pnpm/@paralleldrive_cuid2@2.3.1/node_modules/@paralleldrive/cuid2/index.cjs +0 -17
- package/dist/node_modules/.pnpm/@paralleldrive_cuid2@2.3.1/node_modules/@paralleldrive/cuid2/index.mjs +0 -13
- package/dist/node_modules/.pnpm/@paralleldrive_cuid2@2.3.1/node_modules/@paralleldrive/cuid2/src/index.cjs +0 -69
- package/dist/node_modules/.pnpm/@paralleldrive_cuid2@2.3.1/node_modules/@paralleldrive/cuid2/src/index.mjs +0 -65
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/column.cjs +0 -52
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/column.mjs +0 -52
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/entity.cjs +0 -16
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/entity.mjs +0 -15
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/pg-core/columns/enum.cjs +0 -7
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/pg-core/columns/enum.mjs +0 -7
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/sql/expressions/conditions.cjs +0 -92
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/sql/expressions/conditions.mjs +0 -78
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/sql/expressions/select.cjs +0 -11
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/sql/expressions/select.mjs +0 -10
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/sql/sql.cjs +0 -383
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/sql/sql.mjs +0 -366
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/subquery.cjs +0 -17
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/subquery.mjs +0 -17
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/table.cjs +0 -60
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/table.mjs +0 -59
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/table.utils.cjs +0 -4
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/table.utils.mjs +0 -4
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/tracing.cjs +0 -6
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/tracing.mjs +0 -6
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/view-common.cjs +0 -4
- package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/view-common.mjs +0 -4
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/adapters/drizzle/index.cjs +0 -383
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/adapters/drizzle/index.d.cts +0 -12
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/adapters/drizzle/index.d.mts +0 -12
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/adapters/drizzle/index.mjs +0 -383
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/adapters/kysely/index.cjs +0 -4
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/adapters/kysely/index.mjs +0 -5
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/adapters/prisma/index.cjs +0 -339
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/adapters/prisma/index.d.cts +0 -70
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/adapters/prisma/index.d.mts +0 -70
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/adapters/prisma/index.mjs +0 -339
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-7PZK4ONR.cjs +0 -57
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-7PZK4ONR.mjs +0 -56
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-C6OTUURW.cjs +0 -330
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-C6OTUURW.mjs +0 -326
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-CHTIKPQU.cjs +0 -166
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-CHTIKPQU.mjs +0 -163
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-GUE4GMNC.cjs +0 -14
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-GUE4GMNC.mjs +0 -13
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-LHHP6UVP.cjs +0 -24
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-LHHP6UVP.mjs +0 -24
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-LVCPMTAT.cjs +0 -1190
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-LVCPMTAT.mjs +0 -1189
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-PK2W2SQ7.cjs +0 -197
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-PK2W2SQ7.mjs +0 -197
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-ZEQMAIFI.cjs +0 -410
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-ZEQMAIFI.mjs +0 -400
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-ZOCGSAWS.cjs +0 -213
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-ZOCGSAWS.mjs +0 -212
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/create-tg0451Y_.d.cts +0 -285
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/create-tg0451Y_.d.mts +0 -285
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/index-CMqePMTF.d.cts +0 -45
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/index-CMqePMTF.d.mts +0 -45
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/index.cjs +0 -69
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/index.d.cts +0 -49
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/index.d.mts +0 -49
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/index.mjs +0 -67
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/query/index.d.cts +0 -156
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/query/index.d.mts +0 -156
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/schema/index.cjs +0 -1
- package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/schema/index.mjs +0 -2
- package/src/db/ormCore.ts +0 -1059
- package/src/db/ormUpdateCheck.bench.ts +0 -262
|
@@ -1,105 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
let _hot_updater_core = require("@hot-updater/core");
|
|
3
|
-
let semver = require("semver");
|
|
4
|
-
semver = require_runtime.__toESM(semver);
|
|
5
3
|
//#region src/db/schemaEnhancements.ts
|
|
6
4
|
const normalizeNullableString = (value) => {
|
|
7
5
|
if (value === null || value === void 0) return null;
|
|
8
6
|
const normalized = value.trim();
|
|
9
7
|
return normalized.length > 0 ? normalized : null;
|
|
10
8
|
};
|
|
11
|
-
const appendPrismaModelLines = (code, modelName, lines, options) => {
|
|
12
|
-
const pattern = new RegExp(`model ${modelName} \\{\\n([\\s\\S]*?)\\n\\}`, "m");
|
|
13
|
-
return code.replace(pattern, (full, body) => {
|
|
14
|
-
const bodyLines = body.split("\n");
|
|
15
|
-
const existingLines = new Set(bodyLines.map((line) => line.trim()).filter(Boolean));
|
|
16
|
-
const additions = lines.filter((line) => !existingLines.has(line)).map((line) => ` ${line}`);
|
|
17
|
-
if (additions.length === 0) return full;
|
|
18
|
-
if (options?.position === "beforeAttributes") {
|
|
19
|
-
const insertIndex = bodyLines.findIndex((line) => line.trim().startsWith("@@"));
|
|
20
|
-
if (insertIndex === -1) bodyLines.push(...additions);
|
|
21
|
-
else bodyLines.splice(insertIndex, 0, ...additions);
|
|
22
|
-
return `model ${modelName} {\n${bodyLines.join("\n")}\n}`;
|
|
23
|
-
}
|
|
24
|
-
return `model ${modelName} {\n${body}\n${additions.join("\n")}\n}`;
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
const getPrismaDatasourceProvider = (code) => {
|
|
28
|
-
return code.match(/datasource\s+\w+\s+\{[\s\S]*?provider\s*=\s*"([^"]+)"[\s\S]*?\}/m)?.[1] ?? null;
|
|
29
|
-
};
|
|
30
|
-
const ensureDrizzleIndexImport = (code) => code.replace(/import \{ ([^}]+) \} from "(drizzle-orm\/[^"]+-core)"/, (_full, imports, modulePath) => {
|
|
31
|
-
const values = imports.split(",").map((value) => value.trim()).filter(Boolean);
|
|
32
|
-
if (!values.includes("index")) values.push("index");
|
|
33
|
-
return `import { ${values.join(", ")} } from "${modulePath}"`;
|
|
34
|
-
});
|
|
35
|
-
const ensureDrizzleMetadataDefault = (code) => code.replace(/metadata: json\("metadata"\)\.notNull\(\)(?!\.default\(\{\}\))/, "metadata: json(\"metadata\").notNull().default({})").replace(/metadata: blob\("metadata", \{ mode: "json" \}\)\.notNull\(\)(?!\.default\(\{\}\))/, "metadata: blob(\"metadata\", { mode: \"json\" }).notNull().default({})");
|
|
36
|
-
const removeUnusedDrizzleRelationMany = (code) => code.replace(/export const bundle_patchesRelations = relations\(bundle_patches, \(\{ one, many \}\) => \(\{/, "export const bundle_patchesRelations = relations(bundle_patches, ({ one }) => ({");
|
|
37
|
-
const ensureTrailingComma = (line) => {
|
|
38
|
-
const trimmed = line.trim();
|
|
39
|
-
if (!trimmed || trimmed.endsWith(",") || trimmed.endsWith("[")) return line;
|
|
40
|
-
return `${line},`;
|
|
41
|
-
};
|
|
42
|
-
const updateDrizzleTableBlock = (code, tableName, callbackLines) => {
|
|
43
|
-
const blockStart = code.indexOf(`export const ${tableName} = `);
|
|
44
|
-
if (blockStart === -1) return code;
|
|
45
|
-
const nextBlockStart = code.indexOf("\n\nexport const ", blockStart + 1);
|
|
46
|
-
const blockEnd = nextBlockStart === -1 ? code.length : nextBlockStart;
|
|
47
|
-
const block = code.slice(blockStart, blockEnd);
|
|
48
|
-
if (block.includes(", (table) => [")) {
|
|
49
|
-
const callbackPattern = /, \(table\) => \[\n([\s\S]*?)\n\]\)\s*$/;
|
|
50
|
-
const match = block.match(callbackPattern);
|
|
51
|
-
if (!match) return code;
|
|
52
|
-
const callbackBody = match[1] ?? "";
|
|
53
|
-
const existingLines = callbackBody.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
54
|
-
const additions = callbackLines.filter((line) => !existingLines.includes(line));
|
|
55
|
-
if (additions.length === 0) return code;
|
|
56
|
-
const callbackBodyLines = callbackBody.split("\n");
|
|
57
|
-
for (let index = callbackBodyLines.length - 1; index >= 0; index -= 1) if (callbackBodyLines[index]?.trim()) {
|
|
58
|
-
callbackBodyLines[index] = ensureTrailingComma(callbackBodyLines[index]);
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
const nextCallbackBody = [...callbackBodyLines, ...additions.map((line) => ` ${line}`)].join("\n");
|
|
62
|
-
const nextBlock = block.replace(callbackPattern, `, (table) => [\n${nextCallbackBody}\n])`);
|
|
63
|
-
return `${code.slice(0, blockStart)}${nextBlock}${code.slice(blockEnd)}`;
|
|
64
|
-
}
|
|
65
|
-
const callbackBody = callbackLines.map((line) => ` ${line}`).join("\n");
|
|
66
|
-
const nextBlock = block.replace(/\n\}\)\s*$/, `\n}, (table) => [\n${callbackBody}\n])`);
|
|
67
|
-
return `${code.slice(0, blockStart)}${nextBlock}${code.slice(blockEnd)}`;
|
|
68
|
-
};
|
|
69
|
-
const addCustomSqlOperation = (result, sql) => {
|
|
70
|
-
const normalizedSql = sql.trim();
|
|
71
|
-
if (!result.operations.some((operation) => {
|
|
72
|
-
return operation["type"] === "custom" && typeof operation["sql"] === "string" && operation["sql"].trim() === normalizedSql;
|
|
73
|
-
})) result.operations.push({
|
|
74
|
-
type: "custom",
|
|
75
|
-
sql: normalizedSql
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
const getMigrationCustomSql = (provider, targetVersion) => {
|
|
79
|
-
const statements = [];
|
|
80
|
-
const hasRolloutColumns = semver.default.gte(targetVersion, "0.29.0");
|
|
81
|
-
const hasPatchTable = semver.default.gte(targetVersion, "0.31.0");
|
|
82
|
-
if (provider === "postgresql") {
|
|
83
|
-
statements.push("create index bundles_target_app_version_idx on bundles(target_app_version)", "create index bundles_fingerprint_hash_idx on bundles(fingerprint_hash)", "create index bundles_channel_idx on bundles(channel)", "alter table bundles add constraint check_version_or_fingerprint check ((target_app_version is not null) or (fingerprint_hash is not null))");
|
|
84
|
-
if (hasRolloutColumns) statements.push("create index bundles_rollout_idx on bundles(rollout_cohort_count)", "alter table bundles add constraint bundles_rollout_cohort_count_check check (rollout_cohort_count >= 0 and rollout_cohort_count <= 1000)");
|
|
85
|
-
if (hasPatchTable) statements.push("create index bundle_patches_bundle_id_idx on bundle_patches(bundle_id)", "create index bundle_patches_base_bundle_id_idx on bundle_patches(base_bundle_id)");
|
|
86
|
-
return statements;
|
|
87
|
-
}
|
|
88
|
-
if (provider === "mysql") {
|
|
89
|
-
statements.push("create index bundles_target_app_version_idx on bundles(target_app_version(255))", "create index bundles_fingerprint_hash_idx on bundles(fingerprint_hash(255))", "create index bundles_channel_idx on bundles(channel(255))", "alter table bundles add constraint check_version_or_fingerprint check ((target_app_version is not null) or (fingerprint_hash is not null))");
|
|
90
|
-
if (hasRolloutColumns) statements.push("create index bundles_rollout_idx on bundles(rollout_cohort_count)", "alter table bundles add constraint bundles_rollout_cohort_count_check check (rollout_cohort_count >= 0 and rollout_cohort_count <= 1000)");
|
|
91
|
-
if (hasPatchTable) statements.push("create index bundle_patches_bundle_id_idx on bundle_patches(bundle_id)", "create index bundle_patches_base_bundle_id_idx on bundle_patches(base_bundle_id)");
|
|
92
|
-
return statements;
|
|
93
|
-
}
|
|
94
|
-
statements.push("create index bundles_target_app_version_idx on bundles(target_app_version)", "create index bundles_fingerprint_hash_idx on bundles(fingerprint_hash)", "create index bundles_channel_idx on bundles(channel)");
|
|
95
|
-
if (hasRolloutColumns) statements.push("create index bundles_rollout_idx on bundles(rollout_cohort_count)");
|
|
96
|
-
if (hasPatchTable) statements.push("create index bundle_patches_bundle_id_idx on bundle_patches(bundle_id)", "create index bundle_patches_base_bundle_id_idx on bundle_patches(base_bundle_id)");
|
|
97
|
-
return statements;
|
|
98
|
-
};
|
|
99
|
-
const enhanceUpwardMigrationResult = (result, provider, targetVersion) => {
|
|
100
|
-
for (const sql of getMigrationCustomSql(provider, targetVersion)) addCustomSqlOperation(result, sql);
|
|
101
|
-
return result;
|
|
102
|
-
};
|
|
103
9
|
const assertBundlePersistenceConstraints = (bundle) => {
|
|
104
10
|
const targetAppVersion = normalizeNullableString(bundle.targetAppVersion);
|
|
105
11
|
const fingerprintHash = normalizeNullableString(bundle.fingerprintHash);
|
|
@@ -110,62 +16,5 @@ const assertBundlePersistenceConstraints = (bundle) => {
|
|
|
110
16
|
}
|
|
111
17
|
for (const cohort of bundle.targetCohorts ?? []) if (!(0, _hot_updater_core.isValidCohort)(cohort)) throw new Error(`Invalid target cohort "${cohort}". ${_hot_updater_core.INVALID_COHORT_ERROR_MESSAGE}`);
|
|
112
18
|
};
|
|
113
|
-
const enhanceGeneratedSchema = (adapterName, code, provider) => {
|
|
114
|
-
if (adapterName === "prisma") {
|
|
115
|
-
const datasourceProvider = provider ?? getPrismaDatasourceProvider(code);
|
|
116
|
-
let nextCode = code;
|
|
117
|
-
if (datasourceProvider !== "sqlite") nextCode = nextCode.replace(/^(\s*metadata\s+Json)(?!\s+@default\("?\{\}"?\))(.*)$/m, "$1 @default(\"{}\")$2");
|
|
118
|
-
nextCode = appendPrismaModelLines(nextCode, "bundles", ["patches bundle_patches[] @relation(\"bundle_patches_bundles_patches\")", "baseForPatches bundle_patches[] @relation(\"bundle_patches_bundles_baseForPatches\")"], { position: "beforeAttributes" });
|
|
119
|
-
nextCode = appendPrismaModelLines(nextCode, "bundles", [
|
|
120
|
-
"@@index([target_app_version], map: \"bundles_target_app_version_idx\")",
|
|
121
|
-
"@@index([fingerprint_hash], map: \"bundles_fingerprint_hash_idx\")",
|
|
122
|
-
"@@index([channel], map: \"bundles_channel_idx\")",
|
|
123
|
-
"@@index([rollout_cohort_count], map: \"bundles_rollout_idx\")"
|
|
124
|
-
]);
|
|
125
|
-
return appendPrismaModelLines(nextCode, "bundle_patches", ["@@index([bundle_id], map: \"bundle_patches_bundle_id_idx\")", "@@index([base_bundle_id], map: \"bundle_patches_base_bundle_id_idx\")"]);
|
|
126
|
-
}
|
|
127
|
-
if (adapterName === "drizzle") {
|
|
128
|
-
let nextCode = ensureDrizzleMetadataDefault(code);
|
|
129
|
-
nextCode = removeUnusedDrizzleRelationMany(nextCode);
|
|
130
|
-
nextCode = ensureDrizzleIndexImport(nextCode);
|
|
131
|
-
nextCode = updateDrizzleTableBlock(nextCode, "bundles", [
|
|
132
|
-
"index(\"bundles_target_app_version_idx\").on(table.target_app_version),",
|
|
133
|
-
"index(\"bundles_fingerprint_hash_idx\").on(table.fingerprint_hash),",
|
|
134
|
-
"index(\"bundles_channel_idx\").on(table.channel),",
|
|
135
|
-
"index(\"bundles_rollout_idx\").on(table.rollout_cohort_count),"
|
|
136
|
-
]);
|
|
137
|
-
nextCode = updateDrizzleTableBlock(nextCode, "bundle_patches", ["index(\"bundle_patches_bundle_id_idx\").on(table.bundle_id),", "index(\"bundle_patches_base_bundle_id_idx\").on(table.base_bundle_id),"]);
|
|
138
|
-
return nextCode;
|
|
139
|
-
}
|
|
140
|
-
return code;
|
|
141
|
-
};
|
|
142
|
-
const wrapKyselyMigrator = (migrator, provider, latestVersion) => {
|
|
143
|
-
if (!provider) return migrator;
|
|
144
|
-
return {
|
|
145
|
-
...migrator,
|
|
146
|
-
async up(...args) {
|
|
147
|
-
const next = await migrator.next();
|
|
148
|
-
const result = await migrator.up(...args);
|
|
149
|
-
if (next) enhanceUpwardMigrationResult(result, provider, next.version);
|
|
150
|
-
return result;
|
|
151
|
-
},
|
|
152
|
-
async migrateTo(...args) {
|
|
153
|
-
const version = args[0];
|
|
154
|
-
const options = args[1];
|
|
155
|
-
const currentVersion = await migrator.getVersion();
|
|
156
|
-
const result = await migrator.migrateTo(version, options);
|
|
157
|
-
if (!currentVersion || semver.default.gt(version, currentVersion)) enhanceUpwardMigrationResult(result, provider, version);
|
|
158
|
-
return result;
|
|
159
|
-
},
|
|
160
|
-
async migrateToLatest(...args) {
|
|
161
|
-
const currentVersion = await migrator.getVersion();
|
|
162
|
-
const result = await migrator.migrateToLatest(...args);
|
|
163
|
-
if (!currentVersion || semver.default.gt(latestVersion, currentVersion)) enhanceUpwardMigrationResult(result, provider, latestVersion);
|
|
164
|
-
return result;
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
};
|
|
168
19
|
//#endregion
|
|
169
20
|
exports.assertBundlePersistenceConstraints = assertBundlePersistenceConstraints;
|
|
170
|
-
exports.enhanceGeneratedSchema = enhanceGeneratedSchema;
|
|
171
|
-
exports.wrapKyselyMigrator = wrapKyselyMigrator;
|
|
@@ -1,103 +1,10 @@
|
|
|
1
1
|
import { DEFAULT_ROLLOUT_COHORT_COUNT, INVALID_COHORT_ERROR_MESSAGE, isValidCohort } from "@hot-updater/core";
|
|
2
|
-
import semver from "semver";
|
|
3
2
|
//#region src/db/schemaEnhancements.ts
|
|
4
3
|
const normalizeNullableString = (value) => {
|
|
5
4
|
if (value === null || value === void 0) return null;
|
|
6
5
|
const normalized = value.trim();
|
|
7
6
|
return normalized.length > 0 ? normalized : null;
|
|
8
7
|
};
|
|
9
|
-
const appendPrismaModelLines = (code, modelName, lines, options) => {
|
|
10
|
-
const pattern = new RegExp(`model ${modelName} \\{\\n([\\s\\S]*?)\\n\\}`, "m");
|
|
11
|
-
return code.replace(pattern, (full, body) => {
|
|
12
|
-
const bodyLines = body.split("\n");
|
|
13
|
-
const existingLines = new Set(bodyLines.map((line) => line.trim()).filter(Boolean));
|
|
14
|
-
const additions = lines.filter((line) => !existingLines.has(line)).map((line) => ` ${line}`);
|
|
15
|
-
if (additions.length === 0) return full;
|
|
16
|
-
if (options?.position === "beforeAttributes") {
|
|
17
|
-
const insertIndex = bodyLines.findIndex((line) => line.trim().startsWith("@@"));
|
|
18
|
-
if (insertIndex === -1) bodyLines.push(...additions);
|
|
19
|
-
else bodyLines.splice(insertIndex, 0, ...additions);
|
|
20
|
-
return `model ${modelName} {\n${bodyLines.join("\n")}\n}`;
|
|
21
|
-
}
|
|
22
|
-
return `model ${modelName} {\n${body}\n${additions.join("\n")}\n}`;
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
const getPrismaDatasourceProvider = (code) => {
|
|
26
|
-
return code.match(/datasource\s+\w+\s+\{[\s\S]*?provider\s*=\s*"([^"]+)"[\s\S]*?\}/m)?.[1] ?? null;
|
|
27
|
-
};
|
|
28
|
-
const ensureDrizzleIndexImport = (code) => code.replace(/import \{ ([^}]+) \} from "(drizzle-orm\/[^"]+-core)"/, (_full, imports, modulePath) => {
|
|
29
|
-
const values = imports.split(",").map((value) => value.trim()).filter(Boolean);
|
|
30
|
-
if (!values.includes("index")) values.push("index");
|
|
31
|
-
return `import { ${values.join(", ")} } from "${modulePath}"`;
|
|
32
|
-
});
|
|
33
|
-
const ensureDrizzleMetadataDefault = (code) => code.replace(/metadata: json\("metadata"\)\.notNull\(\)(?!\.default\(\{\}\))/, "metadata: json(\"metadata\").notNull().default({})").replace(/metadata: blob\("metadata", \{ mode: "json" \}\)\.notNull\(\)(?!\.default\(\{\}\))/, "metadata: blob(\"metadata\", { mode: \"json\" }).notNull().default({})");
|
|
34
|
-
const removeUnusedDrizzleRelationMany = (code) => code.replace(/export const bundle_patchesRelations = relations\(bundle_patches, \(\{ one, many \}\) => \(\{/, "export const bundle_patchesRelations = relations(bundle_patches, ({ one }) => ({");
|
|
35
|
-
const ensureTrailingComma = (line) => {
|
|
36
|
-
const trimmed = line.trim();
|
|
37
|
-
if (!trimmed || trimmed.endsWith(",") || trimmed.endsWith("[")) return line;
|
|
38
|
-
return `${line},`;
|
|
39
|
-
};
|
|
40
|
-
const updateDrizzleTableBlock = (code, tableName, callbackLines) => {
|
|
41
|
-
const blockStart = code.indexOf(`export const ${tableName} = `);
|
|
42
|
-
if (blockStart === -1) return code;
|
|
43
|
-
const nextBlockStart = code.indexOf("\n\nexport const ", blockStart + 1);
|
|
44
|
-
const blockEnd = nextBlockStart === -1 ? code.length : nextBlockStart;
|
|
45
|
-
const block = code.slice(blockStart, blockEnd);
|
|
46
|
-
if (block.includes(", (table) => [")) {
|
|
47
|
-
const callbackPattern = /, \(table\) => \[\n([\s\S]*?)\n\]\)\s*$/;
|
|
48
|
-
const match = block.match(callbackPattern);
|
|
49
|
-
if (!match) return code;
|
|
50
|
-
const callbackBody = match[1] ?? "";
|
|
51
|
-
const existingLines = callbackBody.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
52
|
-
const additions = callbackLines.filter((line) => !existingLines.includes(line));
|
|
53
|
-
if (additions.length === 0) return code;
|
|
54
|
-
const callbackBodyLines = callbackBody.split("\n");
|
|
55
|
-
for (let index = callbackBodyLines.length - 1; index >= 0; index -= 1) if (callbackBodyLines[index]?.trim()) {
|
|
56
|
-
callbackBodyLines[index] = ensureTrailingComma(callbackBodyLines[index]);
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
const nextCallbackBody = [...callbackBodyLines, ...additions.map((line) => ` ${line}`)].join("\n");
|
|
60
|
-
const nextBlock = block.replace(callbackPattern, `, (table) => [\n${nextCallbackBody}\n])`);
|
|
61
|
-
return `${code.slice(0, blockStart)}${nextBlock}${code.slice(blockEnd)}`;
|
|
62
|
-
}
|
|
63
|
-
const callbackBody = callbackLines.map((line) => ` ${line}`).join("\n");
|
|
64
|
-
const nextBlock = block.replace(/\n\}\)\s*$/, `\n}, (table) => [\n${callbackBody}\n])`);
|
|
65
|
-
return `${code.slice(0, blockStart)}${nextBlock}${code.slice(blockEnd)}`;
|
|
66
|
-
};
|
|
67
|
-
const addCustomSqlOperation = (result, sql) => {
|
|
68
|
-
const normalizedSql = sql.trim();
|
|
69
|
-
if (!result.operations.some((operation) => {
|
|
70
|
-
return operation["type"] === "custom" && typeof operation["sql"] === "string" && operation["sql"].trim() === normalizedSql;
|
|
71
|
-
})) result.operations.push({
|
|
72
|
-
type: "custom",
|
|
73
|
-
sql: normalizedSql
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
const getMigrationCustomSql = (provider, targetVersion) => {
|
|
77
|
-
const statements = [];
|
|
78
|
-
const hasRolloutColumns = semver.gte(targetVersion, "0.29.0");
|
|
79
|
-
const hasPatchTable = semver.gte(targetVersion, "0.31.0");
|
|
80
|
-
if (provider === "postgresql") {
|
|
81
|
-
statements.push("create index bundles_target_app_version_idx on bundles(target_app_version)", "create index bundles_fingerprint_hash_idx on bundles(fingerprint_hash)", "create index bundles_channel_idx on bundles(channel)", "alter table bundles add constraint check_version_or_fingerprint check ((target_app_version is not null) or (fingerprint_hash is not null))");
|
|
82
|
-
if (hasRolloutColumns) statements.push("create index bundles_rollout_idx on bundles(rollout_cohort_count)", "alter table bundles add constraint bundles_rollout_cohort_count_check check (rollout_cohort_count >= 0 and rollout_cohort_count <= 1000)");
|
|
83
|
-
if (hasPatchTable) statements.push("create index bundle_patches_bundle_id_idx on bundle_patches(bundle_id)", "create index bundle_patches_base_bundle_id_idx on bundle_patches(base_bundle_id)");
|
|
84
|
-
return statements;
|
|
85
|
-
}
|
|
86
|
-
if (provider === "mysql") {
|
|
87
|
-
statements.push("create index bundles_target_app_version_idx on bundles(target_app_version(255))", "create index bundles_fingerprint_hash_idx on bundles(fingerprint_hash(255))", "create index bundles_channel_idx on bundles(channel(255))", "alter table bundles add constraint check_version_or_fingerprint check ((target_app_version is not null) or (fingerprint_hash is not null))");
|
|
88
|
-
if (hasRolloutColumns) statements.push("create index bundles_rollout_idx on bundles(rollout_cohort_count)", "alter table bundles add constraint bundles_rollout_cohort_count_check check (rollout_cohort_count >= 0 and rollout_cohort_count <= 1000)");
|
|
89
|
-
if (hasPatchTable) statements.push("create index bundle_patches_bundle_id_idx on bundle_patches(bundle_id)", "create index bundle_patches_base_bundle_id_idx on bundle_patches(base_bundle_id)");
|
|
90
|
-
return statements;
|
|
91
|
-
}
|
|
92
|
-
statements.push("create index bundles_target_app_version_idx on bundles(target_app_version)", "create index bundles_fingerprint_hash_idx on bundles(fingerprint_hash)", "create index bundles_channel_idx on bundles(channel)");
|
|
93
|
-
if (hasRolloutColumns) statements.push("create index bundles_rollout_idx on bundles(rollout_cohort_count)");
|
|
94
|
-
if (hasPatchTable) statements.push("create index bundle_patches_bundle_id_idx on bundle_patches(bundle_id)", "create index bundle_patches_base_bundle_id_idx on bundle_patches(base_bundle_id)");
|
|
95
|
-
return statements;
|
|
96
|
-
};
|
|
97
|
-
const enhanceUpwardMigrationResult = (result, provider, targetVersion) => {
|
|
98
|
-
for (const sql of getMigrationCustomSql(provider, targetVersion)) addCustomSqlOperation(result, sql);
|
|
99
|
-
return result;
|
|
100
|
-
};
|
|
101
8
|
const assertBundlePersistenceConstraints = (bundle) => {
|
|
102
9
|
const targetAppVersion = normalizeNullableString(bundle.targetAppVersion);
|
|
103
10
|
const fingerprintHash = normalizeNullableString(bundle.fingerprintHash);
|
|
@@ -108,60 +15,5 @@ const assertBundlePersistenceConstraints = (bundle) => {
|
|
|
108
15
|
}
|
|
109
16
|
for (const cohort of bundle.targetCohorts ?? []) if (!isValidCohort(cohort)) throw new Error(`Invalid target cohort "${cohort}". ${INVALID_COHORT_ERROR_MESSAGE}`);
|
|
110
17
|
};
|
|
111
|
-
const enhanceGeneratedSchema = (adapterName, code, provider) => {
|
|
112
|
-
if (adapterName === "prisma") {
|
|
113
|
-
const datasourceProvider = provider ?? getPrismaDatasourceProvider(code);
|
|
114
|
-
let nextCode = code;
|
|
115
|
-
if (datasourceProvider !== "sqlite") nextCode = nextCode.replace(/^(\s*metadata\s+Json)(?!\s+@default\("?\{\}"?\))(.*)$/m, "$1 @default(\"{}\")$2");
|
|
116
|
-
nextCode = appendPrismaModelLines(nextCode, "bundles", ["patches bundle_patches[] @relation(\"bundle_patches_bundles_patches\")", "baseForPatches bundle_patches[] @relation(\"bundle_patches_bundles_baseForPatches\")"], { position: "beforeAttributes" });
|
|
117
|
-
nextCode = appendPrismaModelLines(nextCode, "bundles", [
|
|
118
|
-
"@@index([target_app_version], map: \"bundles_target_app_version_idx\")",
|
|
119
|
-
"@@index([fingerprint_hash], map: \"bundles_fingerprint_hash_idx\")",
|
|
120
|
-
"@@index([channel], map: \"bundles_channel_idx\")",
|
|
121
|
-
"@@index([rollout_cohort_count], map: \"bundles_rollout_idx\")"
|
|
122
|
-
]);
|
|
123
|
-
return appendPrismaModelLines(nextCode, "bundle_patches", ["@@index([bundle_id], map: \"bundle_patches_bundle_id_idx\")", "@@index([base_bundle_id], map: \"bundle_patches_base_bundle_id_idx\")"]);
|
|
124
|
-
}
|
|
125
|
-
if (adapterName === "drizzle") {
|
|
126
|
-
let nextCode = ensureDrizzleMetadataDefault(code);
|
|
127
|
-
nextCode = removeUnusedDrizzleRelationMany(nextCode);
|
|
128
|
-
nextCode = ensureDrizzleIndexImport(nextCode);
|
|
129
|
-
nextCode = updateDrizzleTableBlock(nextCode, "bundles", [
|
|
130
|
-
"index(\"bundles_target_app_version_idx\").on(table.target_app_version),",
|
|
131
|
-
"index(\"bundles_fingerprint_hash_idx\").on(table.fingerprint_hash),",
|
|
132
|
-
"index(\"bundles_channel_idx\").on(table.channel),",
|
|
133
|
-
"index(\"bundles_rollout_idx\").on(table.rollout_cohort_count),"
|
|
134
|
-
]);
|
|
135
|
-
nextCode = updateDrizzleTableBlock(nextCode, "bundle_patches", ["index(\"bundle_patches_bundle_id_idx\").on(table.bundle_id),", "index(\"bundle_patches_base_bundle_id_idx\").on(table.base_bundle_id),"]);
|
|
136
|
-
return nextCode;
|
|
137
|
-
}
|
|
138
|
-
return code;
|
|
139
|
-
};
|
|
140
|
-
const wrapKyselyMigrator = (migrator, provider, latestVersion) => {
|
|
141
|
-
if (!provider) return migrator;
|
|
142
|
-
return {
|
|
143
|
-
...migrator,
|
|
144
|
-
async up(...args) {
|
|
145
|
-
const next = await migrator.next();
|
|
146
|
-
const result = await migrator.up(...args);
|
|
147
|
-
if (next) enhanceUpwardMigrationResult(result, provider, next.version);
|
|
148
|
-
return result;
|
|
149
|
-
},
|
|
150
|
-
async migrateTo(...args) {
|
|
151
|
-
const version = args[0];
|
|
152
|
-
const options = args[1];
|
|
153
|
-
const currentVersion = await migrator.getVersion();
|
|
154
|
-
const result = await migrator.migrateTo(version, options);
|
|
155
|
-
if (!currentVersion || semver.gt(version, currentVersion)) enhanceUpwardMigrationResult(result, provider, version);
|
|
156
|
-
return result;
|
|
157
|
-
},
|
|
158
|
-
async migrateToLatest(...args) {
|
|
159
|
-
const currentVersion = await migrator.getVersion();
|
|
160
|
-
const result = await migrator.migrateToLatest(...args);
|
|
161
|
-
if (!currentVersion || semver.gt(latestVersion, currentVersion)) enhanceUpwardMigrationResult(result, provider, latestVersion);
|
|
162
|
-
return result;
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
};
|
|
166
18
|
//#endregion
|
|
167
|
-
export { assertBundlePersistenceConstraints
|
|
19
|
+
export { assertBundlePersistenceConstraints };
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
require("../schema/types.cjs");
|
|
2
|
+
const require_registry = require("./schema/registry.cjs");
|
|
3
|
+
const require_types$1 = require("./types.cjs");
|
|
4
|
+
//#region src/db/schemaGenerators.ts
|
|
5
|
+
const literal = (value) => JSON.stringify(value);
|
|
6
|
+
const toPascalCase = (value) => value.split("_").filter(Boolean).map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`).join("");
|
|
7
|
+
const prismaDb = (type, provider) => {
|
|
8
|
+
if (provider === "postgresql") {
|
|
9
|
+
if (type === "uuid") return " @db.Uuid";
|
|
10
|
+
if (type.startsWith("varchar")) return " @db.VarChar(255)";
|
|
11
|
+
}
|
|
12
|
+
if (provider === "mysql") {
|
|
13
|
+
if (type === "uuid") return " @db.Char(36)";
|
|
14
|
+
if (type.startsWith("varchar")) return " @db.VarChar(255)";
|
|
15
|
+
}
|
|
16
|
+
return "";
|
|
17
|
+
};
|
|
18
|
+
const prismaType = (column, provider) => {
|
|
19
|
+
return `${(() => {
|
|
20
|
+
if (column.type === "bool") return "Boolean";
|
|
21
|
+
if (column.type === "integer") return "Int";
|
|
22
|
+
if (column.type === "json") return "Json";
|
|
23
|
+
return "String";
|
|
24
|
+
})()}${column.nullable ? "?" : ""}${prismaDb(column.type, provider)}`;
|
|
25
|
+
};
|
|
26
|
+
const prismaDefault = (column, provider) => {
|
|
27
|
+
if (!column.default) return "";
|
|
28
|
+
if (provider === "sqlite" && column.type === "json") return "";
|
|
29
|
+
if (column.default.type === "json") return ` @default(${literal(JSON.stringify(column.default.value))})`;
|
|
30
|
+
return ` @default(${JSON.stringify(column.default.value)})`;
|
|
31
|
+
};
|
|
32
|
+
const prismaField = (column, provider) => [
|
|
33
|
+
column.ormName,
|
|
34
|
+
prismaType(column, provider),
|
|
35
|
+
column.primaryKey ? "@id" : void 0,
|
|
36
|
+
prismaDefault(column, provider).trim() || void 0
|
|
37
|
+
].filter(Boolean).join(" ");
|
|
38
|
+
const relationTargetFields = (table, schema) => schema.tables.flatMap((sourceTable) => (sourceTable.relations ?? []).filter((relation) => relation.referencedTable === table.ormName));
|
|
39
|
+
const prismaRelationFields = (table, schema) => {
|
|
40
|
+
const lines = relationTargetFields(table, schema).map((relation) => `${relation.fieldName} ${relation.referencedTable === table.ormName ? "bundle_patches" : relation.referencedTable}[] @relation(${literal(relation.relationName)})`);
|
|
41
|
+
for (const relation of table.relations ?? []) {
|
|
42
|
+
const targetType = toPascalCase(relation.referencedTable);
|
|
43
|
+
lines.push(`${relation.targetFieldName} ${targetType === "Bundles" ? "bundles" : relation.referencedTable} @relation(${literal(relation.relationName)}, fields: [${relation.columns.join(", ")}], references: [${relation.referencedColumns.join(", ")}], onUpdate: Restrict, onDelete: Cascade)`);
|
|
44
|
+
}
|
|
45
|
+
return lines;
|
|
46
|
+
};
|
|
47
|
+
const prismaIndexes = (table, provider) => (table.indexes ?? []).filter((index) => require_registry.schemaIndexAppliesToProvider(index, provider)).map((index) => `@@index([${index.columns.join(", ")}], map: ${literal(index.name)})`);
|
|
48
|
+
const generatePrismaSchema = (provider, schema = require_registry.hotUpdaterSchema) => schema.tables.map((table) => {
|
|
49
|
+
const lines = [
|
|
50
|
+
...table.columns.map((column) => prismaField(column, provider)),
|
|
51
|
+
...prismaRelationFields(table, schema),
|
|
52
|
+
...prismaIndexes(table, provider)
|
|
53
|
+
];
|
|
54
|
+
return `model ${table.ormName} {\n${lines.map((line) => ` ${line}`).join("\n")}\n}`;
|
|
55
|
+
}).join("\n\n");
|
|
56
|
+
const drizzleImportSource = (provider) => provider === "sqlite" ? "drizzle-orm/sqlite-core" : provider === "mysql" ? "drizzle-orm/mysql-core" : "drizzle-orm/pg-core";
|
|
57
|
+
const drizzleTableFn = (provider) => provider === "sqlite" ? "sqliteTable" : provider === "mysql" ? "mysqlTable" : "pgTable";
|
|
58
|
+
const drizzleColumnFn = (column, provider) => {
|
|
59
|
+
if (provider === "sqlite") {
|
|
60
|
+
if (column.type === "bool") return {
|
|
61
|
+
code: `integer(${literal(column.ormName)}, { mode: "boolean" })`,
|
|
62
|
+
imports: ["integer"]
|
|
63
|
+
};
|
|
64
|
+
if (column.type === "integer") return {
|
|
65
|
+
code: `integer(${literal(column.ormName)})`,
|
|
66
|
+
imports: ["integer"]
|
|
67
|
+
};
|
|
68
|
+
if (column.type === "json") return {
|
|
69
|
+
code: `blob(${literal(column.ormName)}, { mode: "json" })`,
|
|
70
|
+
imports: ["blob"]
|
|
71
|
+
};
|
|
72
|
+
if (column.type.startsWith("varchar")) return {
|
|
73
|
+
code: `text(${literal(column.ormName)}, { length: 255 })`,
|
|
74
|
+
imports: ["text"]
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
code: `text(${literal(column.ormName)})`,
|
|
78
|
+
imports: ["text"]
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (provider === "mysql") {
|
|
82
|
+
if (column.type === "uuid") return {
|
|
83
|
+
code: `char(${literal(column.ormName)}, { length: 36 })`,
|
|
84
|
+
imports: ["char"]
|
|
85
|
+
};
|
|
86
|
+
if (column.type === "bool") return {
|
|
87
|
+
code: `boolean(${literal(column.ormName)})`,
|
|
88
|
+
imports: ["boolean"]
|
|
89
|
+
};
|
|
90
|
+
if (column.type === "integer") return {
|
|
91
|
+
code: `int(${literal(column.ormName)})`,
|
|
92
|
+
imports: ["int"]
|
|
93
|
+
};
|
|
94
|
+
if (column.type === "json") return {
|
|
95
|
+
code: `json(${literal(column.ormName)})`,
|
|
96
|
+
imports: ["json"]
|
|
97
|
+
};
|
|
98
|
+
if (column.type.startsWith("varchar")) return {
|
|
99
|
+
code: `varchar(${literal(column.ormName)}, { length: 255 })`,
|
|
100
|
+
imports: ["varchar"]
|
|
101
|
+
};
|
|
102
|
+
return {
|
|
103
|
+
code: `text(${literal(column.ormName)})`,
|
|
104
|
+
imports: ["text"]
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (column.type === "uuid") return {
|
|
108
|
+
code: `uuid(${literal(column.ormName)})`,
|
|
109
|
+
imports: ["uuid"]
|
|
110
|
+
};
|
|
111
|
+
if (column.type === "bool") return {
|
|
112
|
+
code: `boolean(${literal(column.ormName)})`,
|
|
113
|
+
imports: ["boolean"]
|
|
114
|
+
};
|
|
115
|
+
if (column.type === "integer") return {
|
|
116
|
+
code: `integer(${literal(column.ormName)})`,
|
|
117
|
+
imports: ["integer"]
|
|
118
|
+
};
|
|
119
|
+
if (column.type === "json") return {
|
|
120
|
+
code: `json(${literal(column.ormName)})`,
|
|
121
|
+
imports: ["json"]
|
|
122
|
+
};
|
|
123
|
+
if (column.type.startsWith("varchar")) return {
|
|
124
|
+
code: `varchar(${literal(column.ormName)}, { length: 255 })`,
|
|
125
|
+
imports: ["varchar"]
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
code: `text(${literal(column.ormName)})`,
|
|
129
|
+
imports: ["text"]
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
const drizzleDefault = (value) => {
|
|
133
|
+
if (!value) return "";
|
|
134
|
+
if (value.type === "json") return ".default({})";
|
|
135
|
+
return `.default(${JSON.stringify(value.value)})`;
|
|
136
|
+
};
|
|
137
|
+
const drizzleColumn = (table, column) => {
|
|
138
|
+
if (table.ormName !== "private_hot_updater_settings") return column;
|
|
139
|
+
if (column.ormName === "key") return {
|
|
140
|
+
...column,
|
|
141
|
+
ormName: "id",
|
|
142
|
+
type: "varchar(255)"
|
|
143
|
+
};
|
|
144
|
+
if (column.ormName === "value") return {
|
|
145
|
+
...column,
|
|
146
|
+
ormName: "version",
|
|
147
|
+
type: "varchar(255)"
|
|
148
|
+
};
|
|
149
|
+
return column;
|
|
150
|
+
};
|
|
151
|
+
const drizzleTable = (table, provider, imports) => {
|
|
152
|
+
const columns = table.columns.map((sourceColumn) => {
|
|
153
|
+
const column = drizzleColumn(table, sourceColumn);
|
|
154
|
+
const type = drizzleColumnFn(column, provider);
|
|
155
|
+
for (const item of type.imports) imports.add(item);
|
|
156
|
+
const chain = [
|
|
157
|
+
type.code,
|
|
158
|
+
column.primaryKey ? "primaryKey()" : void 0,
|
|
159
|
+
column.nullable ? void 0 : "notNull()",
|
|
160
|
+
drizzleDefault(column.default).slice(1) || void 0
|
|
161
|
+
].filter(Boolean);
|
|
162
|
+
return ` ${column.ormName}: ${chain.join(".")}`;
|
|
163
|
+
});
|
|
164
|
+
const callbacks = [];
|
|
165
|
+
for (const foreignKey of table.foreignKeys ?? []) {
|
|
166
|
+
imports.add("foreignKey");
|
|
167
|
+
callbacks.push(`foreignKey({
|
|
168
|
+
columns: [table.${foreignKey.columns.join(", table.")}],
|
|
169
|
+
foreignColumns: [${foreignKey.referencedTable}.${foreignKey.referencedColumns.join(`, ${foreignKey.referencedTable}.`)}],
|
|
170
|
+
name: ${literal(foreignKey.name)}
|
|
171
|
+
}).onUpdate(${literal(foreignKey.onUpdate)}).onDelete(${literal(foreignKey.onDelete)})`);
|
|
172
|
+
}
|
|
173
|
+
for (const index of (table.indexes ?? []).filter((item) => require_registry.schemaIndexAppliesToProvider(item, provider))) {
|
|
174
|
+
imports.add("index");
|
|
175
|
+
callbacks.push(`index(${literal(index.name)}).on(${index.columns.map((column) => `table.${column}`).join(", ")})`);
|
|
176
|
+
}
|
|
177
|
+
const args = [
|
|
178
|
+
literal(table.ormName),
|
|
179
|
+
`{\n${columns.join(",\n")}\n}`,
|
|
180
|
+
callbacks.length > 0 ? `(table) => [\n${callbacks.map((line) => ` ${line}`).join(",\n")}\n]` : void 0
|
|
181
|
+
].filter(Boolean);
|
|
182
|
+
return `export const ${table.ormName} = ${drizzleTableFn(provider)}(${args.join(", ")})`;
|
|
183
|
+
};
|
|
184
|
+
const drizzleRelations = (table) => {
|
|
185
|
+
if (!table.relations || table.relations.length === 0) return void 0;
|
|
186
|
+
const lines = table.relations.map((relation) => ` ${relation.targetFieldName}: one(${relation.referencedTable}, {
|
|
187
|
+
relationName: ${literal(relation.relationName)},
|
|
188
|
+
fields: [${relation.columns.map((column) => `${table.ormName}.${column}`).join(", ")}],
|
|
189
|
+
references: [${relation.referencedColumns.map((column) => `${relation.referencedTable}.${column}`).join(", ")}]
|
|
190
|
+
})`);
|
|
191
|
+
return `export const ${table.ormName}Relations = relations(${table.ormName}, ({ one }) => ({
|
|
192
|
+
${lines.join(",\n")}
|
|
193
|
+
}))`;
|
|
194
|
+
};
|
|
195
|
+
const generateDrizzleSchema = (provider, schema = require_registry.hotUpdaterSchema) => {
|
|
196
|
+
const imports = new Set([drizzleTableFn(provider)]);
|
|
197
|
+
const body = [];
|
|
198
|
+
for (const table of schema.tables) {
|
|
199
|
+
body.push(drizzleTable(table, provider, imports));
|
|
200
|
+
const relations = drizzleRelations(table);
|
|
201
|
+
if (relations) body.push(relations);
|
|
202
|
+
}
|
|
203
|
+
if (body.some((block) => block.includes("relations("))) body.unshift("import { relations } from \"drizzle-orm\"");
|
|
204
|
+
return [`import { ${Array.from(imports).sort().join(", ")} } from "${drizzleImportSource(provider)}"`, ...body].join("\n\n");
|
|
205
|
+
};
|
|
206
|
+
const generateSchemaFromHotUpdaterSchema = (adapterName, provider, version, fallback) => {
|
|
207
|
+
const schema = version === "latest" ? require_registry.hotUpdaterSchema : require_registry.getHotUpdaterSchemaVersion(version);
|
|
208
|
+
if (adapterName === "prisma" && provider) return {
|
|
209
|
+
...fallback,
|
|
210
|
+
code: generatePrismaSchema(provider, schema)
|
|
211
|
+
};
|
|
212
|
+
const sqlProvider = require_types$1.getSQLProvider(provider);
|
|
213
|
+
if (adapterName === "drizzle" && sqlProvider) return {
|
|
214
|
+
...fallback,
|
|
215
|
+
code: generateDrizzleSchema(sqlProvider, schema)
|
|
216
|
+
};
|
|
217
|
+
return fallback;
|
|
218
|
+
};
|
|
219
|
+
//#endregion
|
|
220
|
+
exports.generateDrizzleSchema = generateDrizzleSchema;
|
|
221
|
+
exports.generatePrismaSchema = generatePrismaSchema;
|
|
222
|
+
exports.generateSchemaFromHotUpdaterSchema = generateSchemaFromHotUpdaterSchema;
|