@hot-updater/server 0.33.2 → 0.35.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/{runtime.cjs → createHotUpdaterCore.cjs} +34 -12
- package/dist/createHotUpdaterCore.d.cts +25 -0
- package/dist/createHotUpdaterCore.d.mts +25 -0
- package/dist/{runtime.mjs → createHotUpdaterCore.mjs} +34 -10
- 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/createBundleDiff.cjs +1 -1
- package/dist/db/createBundleDiff.mjs +1 -1
- package/dist/db/fixedMigrator.cjs +136 -0
- package/dist/db/fixedMigrator.mjs +135 -0
- package/dist/db/index.cjs +24 -42
- package/dist/db/index.d.cts +7 -26
- package/dist/db/index.d.mts +7 -26
- package/dist/db/index.mjs +19 -41
- 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 -6
- package/dist/index.d.cts +3 -5
- package/dist/index.d.mts +3 -5
- package/dist/index.mjs +2 -4
- package/dist/node.cjs +2 -0
- package/dist/node.d.cts +7 -3
- package/dist/node.d.mts +7 -3
- package/dist/node.mjs +2 -1
- package/dist/{packages/server/package.cjs → package.cjs} +1 -1
- package/dist/{packages/server/package.mjs → package.mjs} +1 -1
- 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/types/index.d.cts +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +34 -20
- package/src/adapters/drizzle.spec.ts +76 -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/createHotUpdaterCore.ts +168 -0
- 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 +983 -19
- package/src/db/index.ts +37 -108
- 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/handler-standalone.integration.spec.ts +3 -2
- package/src/index.ts +9 -3
- package/src/node.spec.ts +50 -0
- package/src/node.ts +7 -3
- package/src/runtime.spec.ts +132 -1
- 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/src/types/index.ts +1 -1
- 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/dist/runtime.d.cts +0 -22
- package/dist/runtime.d.mts +0 -22
- package/src/db/ormCore.ts +0 -1059
- package/src/db/ormUpdateCheck.bench.ts +0 -262
- package/src/runtime.ts +0 -106
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { generateSchema } from "../db";
|
|
4
|
+
import { createHotUpdater } from "../index";
|
|
5
|
+
import { drizzleAdapter } from "./drizzle";
|
|
6
|
+
|
|
7
|
+
describe("drizzleAdapter", () => {
|
|
8
|
+
it("generates schema without resolving a lazy runtime database", () => {
|
|
9
|
+
const getDB = vi.fn(() => {
|
|
10
|
+
throw new Error("runtime database should not be opened");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const hotUpdater = createHotUpdater({
|
|
14
|
+
database: drizzleAdapter({
|
|
15
|
+
db: getDB,
|
|
16
|
+
provider: "postgresql",
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const schema = generateSchema(hotUpdater, "latest");
|
|
21
|
+
|
|
22
|
+
expect(schema.path).toBe("hot-updater-schema.ts");
|
|
23
|
+
expect(schema.code).toContain("pgTable");
|
|
24
|
+
expect(getDB).not.toHaveBeenCalled();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("resolves a lazy runtime database only when a database operation runs", async () => {
|
|
28
|
+
const bundles = { channel: "channel" };
|
|
29
|
+
const bundlePatches = { bundle_id: "bundle_id" };
|
|
30
|
+
const db = {
|
|
31
|
+
_: { fullSchema: { bundle_patches: bundlePatches, bundles } },
|
|
32
|
+
$count: vi.fn(),
|
|
33
|
+
delete: vi.fn(),
|
|
34
|
+
insert: vi.fn(),
|
|
35
|
+
query: {
|
|
36
|
+
bundle_patches: {
|
|
37
|
+
findMany: vi.fn(),
|
|
38
|
+
},
|
|
39
|
+
bundles: {
|
|
40
|
+
findFirst: vi.fn(),
|
|
41
|
+
findMany: vi.fn(async () => [{ channel: "production" }]),
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
select: vi.fn(),
|
|
45
|
+
update: vi.fn(),
|
|
46
|
+
};
|
|
47
|
+
const getDB = vi.fn(async () => db);
|
|
48
|
+
|
|
49
|
+
const plugin = drizzleAdapter({
|
|
50
|
+
db: getDB,
|
|
51
|
+
provider: "postgresql",
|
|
52
|
+
schema: { bundle_patches: bundlePatches, bundles },
|
|
53
|
+
})();
|
|
54
|
+
|
|
55
|
+
expect(getDB).not.toHaveBeenCalled();
|
|
56
|
+
|
|
57
|
+
await expect(plugin.getChannels()).resolves.toEqual(["production"]);
|
|
58
|
+
expect(getDB).toHaveBeenCalledOnce();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("requires schema for lazy runtime database configs", async () => {
|
|
62
|
+
const getDB = vi.fn(() => {
|
|
63
|
+
throw new Error("runtime database should not be opened");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const plugin = drizzleAdapter({
|
|
67
|
+
db: getDB,
|
|
68
|
+
provider: "postgresql",
|
|
69
|
+
})();
|
|
70
|
+
|
|
71
|
+
await expect(plugin.getChannels()).rejects.toThrow(
|
|
72
|
+
"[hot-updater] Drizzle adapter requires schema when db is lazy.",
|
|
73
|
+
);
|
|
74
|
+
expect(getDB).not.toHaveBeenCalled();
|
|
75
|
+
});
|
|
76
|
+
});
|
package/src/adapters/drizzle.ts
CHANGED
|
@@ -1,15 +1,331 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NIL_UUID } from "@hot-updater/core";
|
|
2
|
+
import type {
|
|
3
|
+
Bundle,
|
|
4
|
+
DatabaseBundleQueryOptions,
|
|
5
|
+
DatabaseBundleQueryWhere,
|
|
6
|
+
} from "@hot-updater/plugin-core";
|
|
7
|
+
import {
|
|
8
|
+
calculatePagination,
|
|
9
|
+
createDatabasePlugin,
|
|
10
|
+
filterCompatibleAppVersions,
|
|
11
|
+
resolveUpdateInfoFromBundles,
|
|
12
|
+
} from "@hot-updater/plugin-core";
|
|
13
|
+
import {
|
|
14
|
+
and,
|
|
15
|
+
asc,
|
|
16
|
+
desc,
|
|
17
|
+
eq,
|
|
18
|
+
gt,
|
|
19
|
+
gte,
|
|
20
|
+
inArray,
|
|
21
|
+
isNotNull,
|
|
22
|
+
isNull,
|
|
23
|
+
lt,
|
|
24
|
+
lte,
|
|
25
|
+
} from "drizzle-orm";
|
|
26
|
+
import type { SQLWrapper } from "drizzle-orm";
|
|
2
27
|
|
|
3
|
-
import
|
|
28
|
+
import {
|
|
29
|
+
bundleToPatchRows,
|
|
30
|
+
bundleToRow,
|
|
31
|
+
type BundlePatchRow,
|
|
32
|
+
type BundleRow,
|
|
33
|
+
rowToBundle,
|
|
34
|
+
} from "../db/bundleRows";
|
|
35
|
+
import {
|
|
36
|
+
getHotUpdaterSchemaVersion,
|
|
37
|
+
hotUpdaterSchema,
|
|
38
|
+
} from "../db/schema/registry";
|
|
39
|
+
import { generateDrizzleSchema } from "../db/schemaGenerators";
|
|
40
|
+
import type {
|
|
41
|
+
DatabasePluginFactory,
|
|
42
|
+
ORMProvider,
|
|
43
|
+
ORMSQLProvider,
|
|
44
|
+
SchemaGenerator,
|
|
45
|
+
} from "../db/types";
|
|
46
|
+
import {
|
|
47
|
+
createLazyDB,
|
|
48
|
+
type DrizzleDB,
|
|
49
|
+
type DrizzleTable,
|
|
50
|
+
} from "./drizzleLazyDB";
|
|
4
51
|
|
|
5
|
-
export
|
|
52
|
+
export interface DrizzleConfig {
|
|
53
|
+
readonly db: unknown | (() => unknown | Promise<unknown>);
|
|
54
|
+
readonly provider: Exclude<ORMProvider, "cockroachdb" | "mongodb" | "mssql">;
|
|
55
|
+
readonly schema?: Record<string, unknown>;
|
|
56
|
+
}
|
|
6
57
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
58
|
+
const getTable = (db: DrizzleDB, name: string) => {
|
|
59
|
+
const table = db._.fullSchema[name];
|
|
60
|
+
if (!table) throw new Error(`Drizzle schema is missing table "${name}".`);
|
|
61
|
+
return table;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const column = (table: DrizzleTable, name: string): SQLWrapper =>
|
|
65
|
+
table[name] as SQLWrapper;
|
|
66
|
+
|
|
67
|
+
const buildWhere = (
|
|
68
|
+
table: DrizzleTable,
|
|
69
|
+
where: DatabaseBundleQueryWhere | undefined,
|
|
70
|
+
) => {
|
|
71
|
+
const conditions = [];
|
|
72
|
+
if (where?.channel !== undefined)
|
|
73
|
+
conditions.push(eq(column(table, "channel"), where.channel));
|
|
74
|
+
if (where?.platform !== undefined)
|
|
75
|
+
conditions.push(eq(column(table, "platform"), where.platform));
|
|
76
|
+
if (where?.enabled !== undefined)
|
|
77
|
+
conditions.push(eq(column(table, "enabled"), where.enabled));
|
|
78
|
+
if (where?.fingerprintHash !== undefined) {
|
|
79
|
+
conditions.push(
|
|
80
|
+
where.fingerprintHash === null
|
|
81
|
+
? isNull(column(table, "fingerprint_hash"))
|
|
82
|
+
: eq(column(table, "fingerprint_hash"), where.fingerprintHash),
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
if (where?.targetAppVersion !== undefined) {
|
|
86
|
+
conditions.push(
|
|
87
|
+
where.targetAppVersion === null
|
|
88
|
+
? isNull(column(table, "target_app_version"))
|
|
89
|
+
: eq(column(table, "target_app_version"), where.targetAppVersion),
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
if (where?.targetAppVersionIn) {
|
|
93
|
+
conditions.push(
|
|
94
|
+
inArray(column(table, "target_app_version"), where.targetAppVersionIn),
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
if (where?.targetAppVersionNotNull) {
|
|
98
|
+
conditions.push(isNotNull(column(table, "target_app_version")));
|
|
99
|
+
}
|
|
100
|
+
if (where?.id?.eq) conditions.push(eq(column(table, "id"), where.id.eq));
|
|
101
|
+
if (where?.id?.gt) conditions.push(gt(column(table, "id"), where.id.gt));
|
|
102
|
+
if (where?.id?.gte) conditions.push(gte(column(table, "id"), where.id.gte));
|
|
103
|
+
if (where?.id?.lt) conditions.push(lt(column(table, "id"), where.id.lt));
|
|
104
|
+
if (where?.id?.lte) conditions.push(lte(column(table, "id"), where.id.lte));
|
|
105
|
+
if (where?.id?.in) conditions.push(inArray(column(table, "id"), where.id.in));
|
|
106
|
+
return conditions.length > 0 ? and(...conditions) : undefined;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const createDrizzlePlugin = createDatabasePlugin<DrizzleConfig>({
|
|
110
|
+
name: "drizzle",
|
|
111
|
+
factory: (config) => {
|
|
112
|
+
const db = createLazyDB(config);
|
|
113
|
+
const bundles = getTable(db, "bundles");
|
|
114
|
+
const patches = getTable(db, "bundle_patches");
|
|
115
|
+
const runInTransaction = async <T>(
|
|
116
|
+
operation: (activeDB: DrizzleDB) => Promise<T>,
|
|
117
|
+
) => {
|
|
118
|
+
if (typeof db.transaction !== "function") return operation(db);
|
|
119
|
+
return db.transaction(operation);
|
|
120
|
+
};
|
|
121
|
+
const fetchPatchMap = async (bundleIds: readonly string[]) => {
|
|
122
|
+
const patchMap = new Map<string, BundlePatchRow[]>();
|
|
123
|
+
if (bundleIds.length === 0) return patchMap;
|
|
124
|
+
const rows = await db.query["bundle_patches"]?.findMany({
|
|
125
|
+
where: inArray(column(patches, "bundle_id"), [...bundleIds]),
|
|
126
|
+
orderBy: [asc(column(patches, "order_index"))],
|
|
127
|
+
});
|
|
128
|
+
for (const row of rows ?? []) {
|
|
129
|
+
const patch = row as BundlePatchRow;
|
|
130
|
+
const current = patchMap.get(patch.bundle_id) ?? [];
|
|
131
|
+
current.push(patch);
|
|
132
|
+
patchMap.set(patch.bundle_id, current);
|
|
133
|
+
}
|
|
134
|
+
return patchMap;
|
|
135
|
+
};
|
|
136
|
+
const mapRowsToBundles = async (
|
|
137
|
+
rows: readonly Record<string, unknown>[],
|
|
138
|
+
): Promise<Bundle[]> => {
|
|
139
|
+
const patchMap = await fetchPatchMap(
|
|
140
|
+
rows.map((row) => String(row["id"])),
|
|
141
|
+
);
|
|
142
|
+
return rows.map((row) =>
|
|
143
|
+
rowToBundle(row as BundleRow, patchMap.get(String(row["id"])) ?? []),
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
const upsertBundle = async (activeDB: DrizzleDB, bundle: Bundle) => {
|
|
147
|
+
const row = bundleToRow(bundle);
|
|
148
|
+
const current = await activeDB.query["bundles"]?.findFirst({
|
|
149
|
+
where: eq(column(bundles, "id"), bundle.id),
|
|
150
|
+
});
|
|
151
|
+
if (current) {
|
|
152
|
+
await activeDB
|
|
153
|
+
.update(bundles)
|
|
154
|
+
.set(row)
|
|
155
|
+
.where(eq(column(bundles, "id"), bundle.id));
|
|
156
|
+
} else {
|
|
157
|
+
const inserted = activeDB.insert(bundles).values(row);
|
|
158
|
+
if (inserted.execute) await inserted.execute();
|
|
159
|
+
else await inserted;
|
|
160
|
+
}
|
|
161
|
+
await activeDB
|
|
162
|
+
.delete(patches)
|
|
163
|
+
.where(eq(column(patches, "bundle_id"), bundle.id));
|
|
164
|
+
const patchRows = bundleToPatchRows(bundle);
|
|
165
|
+
if (patchRows.length > 0) {
|
|
166
|
+
const inserted = activeDB.insert(patches).values(patchRows);
|
|
167
|
+
if (inserted.execute) await inserted.execute();
|
|
168
|
+
else await inserted;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
return {
|
|
172
|
+
async getBundleById(bundleId) {
|
|
173
|
+
const row = await db.query["bundles"]?.findFirst({
|
|
174
|
+
where: eq(column(bundles, "id"), bundleId),
|
|
175
|
+
});
|
|
176
|
+
if (!row) return null;
|
|
177
|
+
const patchMap = await fetchPatchMap([bundleId]);
|
|
178
|
+
return rowToBundle(row as BundleRow, patchMap.get(bundleId) ?? []);
|
|
179
|
+
},
|
|
180
|
+
async getBundles(
|
|
181
|
+
options: DatabaseBundleQueryOptions & { offset?: number },
|
|
182
|
+
) {
|
|
183
|
+
const offset = options.offset ?? 0;
|
|
184
|
+
const orderBy = options.orderBy ?? { field: "id", direction: "desc" };
|
|
185
|
+
const where = buildWhere(bundles, options.where);
|
|
186
|
+
const total = await db.$count(bundles, where);
|
|
187
|
+
const rows = await db.query["bundles"]?.findMany({
|
|
188
|
+
where,
|
|
189
|
+
orderBy: [
|
|
190
|
+
orderBy.direction === "asc"
|
|
191
|
+
? asc(column(bundles, "id"))
|
|
192
|
+
: desc(column(bundles, "id")),
|
|
193
|
+
],
|
|
194
|
+
limit: options.limit,
|
|
195
|
+
offset,
|
|
196
|
+
});
|
|
197
|
+
const dataRows = rows ?? [];
|
|
198
|
+
const patchMap = await fetchPatchMap(
|
|
199
|
+
dataRows.map((row) => String(row["id"])),
|
|
200
|
+
);
|
|
201
|
+
return {
|
|
202
|
+
data: dataRows.map((row) =>
|
|
203
|
+
rowToBundle(
|
|
204
|
+
row as BundleRow,
|
|
205
|
+
patchMap.get(String(row["id"])) ?? [],
|
|
206
|
+
),
|
|
207
|
+
),
|
|
208
|
+
pagination: calculatePagination(total, {
|
|
209
|
+
limit: options.limit,
|
|
210
|
+
offset,
|
|
211
|
+
}),
|
|
212
|
+
};
|
|
213
|
+
},
|
|
214
|
+
async getUpdateInfo(args, context) {
|
|
215
|
+
if (args._updateStrategy === "appVersion") {
|
|
216
|
+
const channel = args.channel ?? "production";
|
|
217
|
+
const minBundleId = args.minBundleId ?? NIL_UUID;
|
|
218
|
+
const rows = await db.query["bundles"]?.findMany({
|
|
219
|
+
columns: { target_app_version: true },
|
|
220
|
+
where: buildWhere(bundles, {
|
|
221
|
+
enabled: true,
|
|
222
|
+
platform: args.platform,
|
|
223
|
+
channel,
|
|
224
|
+
id: { gte: minBundleId },
|
|
225
|
+
targetAppVersionNotNull: true,
|
|
226
|
+
}),
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
const targetAppVersions = Array.from(
|
|
230
|
+
new Set(
|
|
231
|
+
(rows ?? [])
|
|
232
|
+
.map((row) => row["target_app_version"])
|
|
233
|
+
.filter(
|
|
234
|
+
(value): value is string =>
|
|
235
|
+
typeof value === "string" && value.length > 0,
|
|
236
|
+
),
|
|
237
|
+
),
|
|
238
|
+
);
|
|
239
|
+
const compatibleAppVersions = filterCompatibleAppVersions(
|
|
240
|
+
targetAppVersions,
|
|
241
|
+
args.appVersion,
|
|
242
|
+
);
|
|
243
|
+
const updateRows =
|
|
244
|
+
compatibleAppVersions.length > 0
|
|
245
|
+
? await db.query["bundles"]?.findMany({
|
|
246
|
+
where: buildWhere(bundles, {
|
|
247
|
+
enabled: true,
|
|
248
|
+
platform: args.platform,
|
|
249
|
+
channel,
|
|
250
|
+
id: { gte: minBundleId },
|
|
251
|
+
targetAppVersionIn: compatibleAppVersions,
|
|
252
|
+
}),
|
|
253
|
+
orderBy: [desc(column(bundles, "id"))],
|
|
254
|
+
})
|
|
255
|
+
: [];
|
|
256
|
+
|
|
257
|
+
return resolveUpdateInfoFromBundles({
|
|
258
|
+
args: { ...args, channel, minBundleId },
|
|
259
|
+
bundles: await mapRowsToBundles(updateRows ?? []),
|
|
260
|
+
context,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const channel = args.channel ?? "production";
|
|
265
|
+
const minBundleId = args.minBundleId ?? NIL_UUID;
|
|
266
|
+
const rows = await db.query["bundles"]?.findMany({
|
|
267
|
+
where: buildWhere(bundles, {
|
|
268
|
+
enabled: true,
|
|
269
|
+
platform: args.platform,
|
|
270
|
+
channel,
|
|
271
|
+
id: { gte: minBundleId },
|
|
272
|
+
fingerprintHash: args.fingerprintHash,
|
|
273
|
+
}),
|
|
274
|
+
orderBy: [desc(column(bundles, "id"))],
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
return resolveUpdateInfoFromBundles({
|
|
278
|
+
args: { ...args, channel, minBundleId },
|
|
279
|
+
bundles: await mapRowsToBundles(rows ?? []),
|
|
280
|
+
context,
|
|
281
|
+
});
|
|
282
|
+
},
|
|
283
|
+
async getChannels() {
|
|
284
|
+
const rows = await db.query["bundles"]?.findMany({
|
|
285
|
+
columns: { channel: true },
|
|
286
|
+
orderBy: [asc(column(bundles, "channel"))],
|
|
287
|
+
});
|
|
288
|
+
return Array.from(
|
|
289
|
+
new Set((rows ?? []).map((row) => String(row["channel"]))),
|
|
290
|
+
);
|
|
291
|
+
},
|
|
292
|
+
async commitBundle({ changedSets }) {
|
|
293
|
+
await runInTransaction(async (activeDB) => {
|
|
294
|
+
for (const change of changedSets) {
|
|
295
|
+
if (change.operation === "delete") {
|
|
296
|
+
await activeDB
|
|
297
|
+
.delete(patches)
|
|
298
|
+
.where(eq(column(patches, "bundle_id"), change.data.id));
|
|
299
|
+
await activeDB
|
|
300
|
+
.delete(patches)
|
|
301
|
+
.where(eq(column(patches, "base_bundle_id"), change.data.id));
|
|
302
|
+
await activeDB
|
|
303
|
+
.delete(bundles)
|
|
304
|
+
.where(eq(column(bundles, "id"), change.data.id));
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
await upsertBundle(activeDB, change.data);
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
export const drizzleAdapter = (
|
|
316
|
+
config: DrizzleConfig,
|
|
317
|
+
): DatabasePluginFactory => {
|
|
318
|
+
return Object.assign(createDrizzlePlugin(config), {
|
|
319
|
+
adapterName: "drizzle",
|
|
320
|
+
provider: config.provider,
|
|
321
|
+
generateSchema: (version: Parameters<SchemaGenerator>[0]) => ({
|
|
322
|
+
code: generateDrizzleSchema(
|
|
323
|
+
config.provider as ORMSQLProvider,
|
|
324
|
+
version === "latest"
|
|
325
|
+
? hotUpdaterSchema
|
|
326
|
+
: getHotUpdaterSchemaVersion(version),
|
|
327
|
+
),
|
|
328
|
+
path: "hot-updater-schema.ts",
|
|
329
|
+
}),
|
|
330
|
+
});
|
|
331
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { DrizzleConfig } from "./drizzle";
|
|
2
|
+
|
|
3
|
+
export type DrizzleTable = Record<string, unknown>;
|
|
4
|
+
|
|
5
|
+
export type DrizzleDB = {
|
|
6
|
+
readonly _: { readonly fullSchema: Record<string, DrizzleTable> };
|
|
7
|
+
readonly $count: (table: DrizzleTable, where?: unknown) => Promise<number>;
|
|
8
|
+
readonly delete: (table: DrizzleTable) => {
|
|
9
|
+
where: (condition: unknown) => Promise<unknown>;
|
|
10
|
+
};
|
|
11
|
+
readonly insert: (table: DrizzleTable) => {
|
|
12
|
+
values: (value: unknown) => {
|
|
13
|
+
onConflictDoUpdate?: (args: unknown) => Promise<unknown>;
|
|
14
|
+
onDuplicateKeyUpdate?: (args: unknown) => Promise<unknown>;
|
|
15
|
+
execute?: () => Promise<unknown>;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
readonly query: Record<
|
|
19
|
+
string,
|
|
20
|
+
{
|
|
21
|
+
findFirst: (
|
|
22
|
+
args?: unknown,
|
|
23
|
+
) => Promise<Record<string, unknown> | undefined>;
|
|
24
|
+
findMany: (args?: unknown) => Promise<Record<string, unknown>[]>;
|
|
25
|
+
}
|
|
26
|
+
>;
|
|
27
|
+
readonly select: (fields?: unknown) => {
|
|
28
|
+
from: (table: DrizzleTable) => {
|
|
29
|
+
where?: (condition: unknown) => unknown;
|
|
30
|
+
orderBy?: (order: unknown) => unknown;
|
|
31
|
+
limit?: (limit: number) => unknown;
|
|
32
|
+
offset?: (offset: number) => Promise<Record<string, unknown>[]>;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
readonly update: (table: DrizzleTable) => {
|
|
36
|
+
set: (values: unknown) => {
|
|
37
|
+
where: (condition: unknown) => Promise<unknown>;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
readonly transaction?: <T>(
|
|
41
|
+
operation: (tx: DrizzleDB) => Promise<T>,
|
|
42
|
+
) => Promise<T>;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const asDB = (db: unknown): DrizzleDB => {
|
|
46
|
+
const typed = db as DrizzleDB;
|
|
47
|
+
if (!typed._?.fullSchema) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
"[hot-updater] Drizzle adapter requires query mode with schema.",
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
return typed;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const isDBFactory = (
|
|
56
|
+
db: DrizzleConfig["db"],
|
|
57
|
+
): db is () => unknown | Promise<unknown> => typeof db === "function";
|
|
58
|
+
|
|
59
|
+
export const createLazyDB = (config: DrizzleConfig): DrizzleDB => {
|
|
60
|
+
const dbSource = config.db;
|
|
61
|
+
if (!isDBFactory(dbSource)) return asDB(dbSource);
|
|
62
|
+
|
|
63
|
+
if (!config.schema) {
|
|
64
|
+
throw new Error(
|
|
65
|
+
"[hot-updater] Drizzle adapter requires schema when db is lazy.",
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let resolvedDB: Promise<DrizzleDB> | undefined;
|
|
70
|
+
const getDB = async () => {
|
|
71
|
+
resolvedDB ??= Promise.resolve(dbSource()).then(asDB);
|
|
72
|
+
return resolvedDB;
|
|
73
|
+
};
|
|
74
|
+
const fullSchema = config.schema as Record<string, DrizzleTable>;
|
|
75
|
+
const runInserted = async (
|
|
76
|
+
table: DrizzleTable,
|
|
77
|
+
value: unknown,
|
|
78
|
+
operation: (
|
|
79
|
+
inserted: ReturnType<ReturnType<DrizzleDB["insert"]>["values"]>,
|
|
80
|
+
) => Promise<unknown> | unknown,
|
|
81
|
+
) => {
|
|
82
|
+
const db = await getDB();
|
|
83
|
+
return operation(db.insert(table).values(value));
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
_: { fullSchema },
|
|
88
|
+
$count: async (table, where) => (await getDB()).$count(table, where),
|
|
89
|
+
delete: (table) => ({
|
|
90
|
+
where: async (condition) =>
|
|
91
|
+
(await getDB()).delete(table).where(condition),
|
|
92
|
+
}),
|
|
93
|
+
insert: (table) => ({
|
|
94
|
+
values: (value) => ({
|
|
95
|
+
execute: async () =>
|
|
96
|
+
runInserted(table, value, async (inserted) => {
|
|
97
|
+
if (typeof inserted.execute === "function") {
|
|
98
|
+
return inserted.execute();
|
|
99
|
+
}
|
|
100
|
+
return inserted;
|
|
101
|
+
}),
|
|
102
|
+
onConflictDoUpdate: async (args) =>
|
|
103
|
+
runInserted(table, value, async (inserted) => {
|
|
104
|
+
if (typeof inserted.onConflictDoUpdate !== "function") {
|
|
105
|
+
throw new Error(
|
|
106
|
+
"[hot-updater] Drizzle insert does not support onConflictDoUpdate.",
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
return inserted.onConflictDoUpdate(args);
|
|
110
|
+
}),
|
|
111
|
+
onDuplicateKeyUpdate: async (args) =>
|
|
112
|
+
runInserted(table, value, async (inserted) => {
|
|
113
|
+
if (typeof inserted.onDuplicateKeyUpdate !== "function") {
|
|
114
|
+
throw new Error(
|
|
115
|
+
"[hot-updater] Drizzle insert does not support onDuplicateKeyUpdate.",
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
return inserted.onDuplicateKeyUpdate(args);
|
|
119
|
+
}),
|
|
120
|
+
}),
|
|
121
|
+
}),
|
|
122
|
+
query: new Proxy(
|
|
123
|
+
{},
|
|
124
|
+
{
|
|
125
|
+
get: (_target, tableName) => ({
|
|
126
|
+
findFirst: async (args?: unknown) =>
|
|
127
|
+
(await getDB()).query[String(tableName)]?.findFirst(args),
|
|
128
|
+
findMany: async (args?: unknown) =>
|
|
129
|
+
(await getDB()).query[String(tableName)]?.findMany(args) ?? [],
|
|
130
|
+
}),
|
|
131
|
+
},
|
|
132
|
+
) as DrizzleDB["query"],
|
|
133
|
+
select: (fields) => ({
|
|
134
|
+
from: (table) => ({
|
|
135
|
+
offset: async (offset) =>
|
|
136
|
+
(await getDB()).select(fields).from(table).offset?.(offset) ?? [],
|
|
137
|
+
}),
|
|
138
|
+
}),
|
|
139
|
+
update: (table) => ({
|
|
140
|
+
set: (values) => ({
|
|
141
|
+
where: async (condition) =>
|
|
142
|
+
(await getDB()).update(table).set(values).where(condition),
|
|
143
|
+
}),
|
|
144
|
+
}),
|
|
145
|
+
transaction: async (operation) => {
|
|
146
|
+
const db = await getDB();
|
|
147
|
+
if (typeof db.transaction !== "function") return operation(db);
|
|
148
|
+
return db.transaction(operation);
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { PGlite } from "@electric-sql/pglite";
|
|
2
|
+
import type { Bundle } from "@hot-updater/core";
|
|
3
|
+
import { Kysely } from "kysely";
|
|
4
|
+
import { PGliteDialect } from "kysely-pglite-dialect";
|
|
5
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
6
|
+
|
|
7
|
+
import { createHotUpdater } from "../index";
|
|
8
|
+
import {
|
|
9
|
+
HOT_UPDATER_SCHEMA_VERSION,
|
|
10
|
+
HOT_UPDATER_SETTINGS_TABLE,
|
|
11
|
+
} from "../schema/types";
|
|
12
|
+
import { kyselyAdapter } from "./kysely";
|
|
13
|
+
|
|
14
|
+
const sqliteJsonBundle: Bundle = {
|
|
15
|
+
id: "00000000-0000-0000-0000-000000000901",
|
|
16
|
+
platform: "ios",
|
|
17
|
+
shouldForceUpdate: false,
|
|
18
|
+
enabled: true,
|
|
19
|
+
fileHash: "sqlite-json-hash",
|
|
20
|
+
gitCommitHash: null,
|
|
21
|
+
message: "sqlite json bundle",
|
|
22
|
+
channel: "production",
|
|
23
|
+
storageUri: "s3://bucket/sqlite-json.zip",
|
|
24
|
+
targetAppVersion: "1.0.0",
|
|
25
|
+
fingerprintHash: null,
|
|
26
|
+
metadata: { app_version: "1.0.0" },
|
|
27
|
+
targetCohorts: ["17", "qa-group"],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
describe("kyselyAdapter sqlite provider", () => {
|
|
31
|
+
const databases: PGlite[] = [];
|
|
32
|
+
const kyselyInstances: Kysely<object>[] = [];
|
|
33
|
+
|
|
34
|
+
afterEach(async () => {
|
|
35
|
+
for (const kysely of kyselyInstances.splice(0)) {
|
|
36
|
+
await kysely.destroy();
|
|
37
|
+
}
|
|
38
|
+
for (const db of databases.splice(0)) {
|
|
39
|
+
await db.close();
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("stores bundle JSON columns as text and round-trips them", async () => {
|
|
44
|
+
const db = new PGlite();
|
|
45
|
+
databases.push(db);
|
|
46
|
+
const kysely = new Kysely({ dialect: new PGliteDialect(db) });
|
|
47
|
+
kyselyInstances.push(kysely);
|
|
48
|
+
await db.exec(`
|
|
49
|
+
create table bundles (
|
|
50
|
+
id text primary key,
|
|
51
|
+
platform text not null,
|
|
52
|
+
should_force_update boolean not null,
|
|
53
|
+
enabled boolean not null,
|
|
54
|
+
file_hash text not null,
|
|
55
|
+
git_commit_hash text,
|
|
56
|
+
message text,
|
|
57
|
+
channel text not null,
|
|
58
|
+
storage_uri text not null,
|
|
59
|
+
target_app_version text,
|
|
60
|
+
fingerprint_hash text,
|
|
61
|
+
metadata text not null,
|
|
62
|
+
manifest_storage_uri text,
|
|
63
|
+
manifest_file_hash text,
|
|
64
|
+
asset_base_storage_uri text,
|
|
65
|
+
rollout_cohort_count integer not null,
|
|
66
|
+
target_cohorts text
|
|
67
|
+
);
|
|
68
|
+
create table bundle_patches (
|
|
69
|
+
id text primary key,
|
|
70
|
+
bundle_id text not null,
|
|
71
|
+
base_bundle_id text not null,
|
|
72
|
+
base_file_hash text not null,
|
|
73
|
+
patch_file_hash text not null,
|
|
74
|
+
patch_storage_uri text not null,
|
|
75
|
+
order_index integer not null
|
|
76
|
+
);
|
|
77
|
+
create table ${HOT_UPDATER_SETTINGS_TABLE} (
|
|
78
|
+
key text primary key,
|
|
79
|
+
value text not null
|
|
80
|
+
);
|
|
81
|
+
insert into ${HOT_UPDATER_SETTINGS_TABLE} (key, value)
|
|
82
|
+
values ('version', '${HOT_UPDATER_SCHEMA_VERSION}');
|
|
83
|
+
`);
|
|
84
|
+
const hotUpdater = createHotUpdater({
|
|
85
|
+
database: kyselyAdapter({
|
|
86
|
+
db: kysely,
|
|
87
|
+
provider: "sqlite",
|
|
88
|
+
}),
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
await hotUpdater.insertBundle(sqliteJsonBundle);
|
|
92
|
+
const stored = await db.query<{
|
|
93
|
+
metadata: string;
|
|
94
|
+
target_cohorts: string;
|
|
95
|
+
}>("select metadata, target_cohorts from bundles where id = $1", [
|
|
96
|
+
sqliteJsonBundle.id,
|
|
97
|
+
]);
|
|
98
|
+
const restored = await hotUpdater.getBundleById(sqliteJsonBundle.id);
|
|
99
|
+
|
|
100
|
+
expect(stored.rows[0]).toEqual({
|
|
101
|
+
metadata: JSON.stringify({ app_version: "1.0.0" }),
|
|
102
|
+
target_cohorts: JSON.stringify(["17", "qa-group"]),
|
|
103
|
+
});
|
|
104
|
+
expect(restored?.metadata).toEqual({ app_version: "1.0.0" });
|
|
105
|
+
expect(restored?.targetCohorts).toEqual(["17", "qa-group"]);
|
|
106
|
+
});
|
|
107
|
+
});
|