@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
package/src/adapters/kysely.ts
CHANGED
|
@@ -1,24 +1,359 @@
|
|
|
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 type { Kysely, Transaction } from "kysely";
|
|
2
14
|
|
|
3
|
-
import
|
|
15
|
+
import {
|
|
16
|
+
bundleToPatchRows,
|
|
17
|
+
bundleToRow,
|
|
18
|
+
type BundlePatchRow,
|
|
19
|
+
type BundleRow,
|
|
20
|
+
rowToBundle,
|
|
21
|
+
} from "../db/bundleRows";
|
|
22
|
+
import { createKyselyMigrator } from "../db/fixedMigrator";
|
|
23
|
+
import type {
|
|
24
|
+
DatabasePluginFactory,
|
|
25
|
+
ORMSQLProvider,
|
|
26
|
+
RelationMode,
|
|
27
|
+
} from "../db/types";
|
|
4
28
|
|
|
5
|
-
|
|
6
|
-
export type SQLProvider = import("fumadb").SQLProvider;
|
|
29
|
+
type KyselySQLProvider = Exclude<ORMSQLProvider, "mssql">;
|
|
7
30
|
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
31
|
+
export type { RelationMode, KyselySQLProvider as SQLProvider };
|
|
32
|
+
|
|
33
|
+
interface Database {
|
|
34
|
+
readonly bundles: BundleRow;
|
|
35
|
+
readonly bundle_patches: BundlePatchRow;
|
|
36
|
+
readonly private_hot_updater_settings: {
|
|
37
|
+
readonly key: string;
|
|
38
|
+
readonly value: string;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface KyselyAdapterConfig<TDatabase extends object = Database> {
|
|
43
|
+
readonly db: Kysely<TDatabase>;
|
|
44
|
+
readonly provider: KyselySQLProvider;
|
|
45
|
+
readonly relationMode?: RelationMode;
|
|
12
46
|
}
|
|
13
47
|
|
|
48
|
+
const assertKyselySQLProvider: (
|
|
49
|
+
provider: ORMSQLProvider,
|
|
50
|
+
) => asserts provider is KyselySQLProvider = (provider) => {
|
|
51
|
+
if (provider === "mssql") {
|
|
52
|
+
throw new Error("Kysely adapter does not support provider: mssql.");
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const applyWhere = <T extends object>(
|
|
57
|
+
query: T,
|
|
58
|
+
where: DatabaseBundleQueryWhere | undefined,
|
|
59
|
+
): T => {
|
|
60
|
+
let next = query as {
|
|
61
|
+
where: (column: string, op: string, value?: unknown) => unknown;
|
|
62
|
+
};
|
|
63
|
+
if (where?.channel !== undefined)
|
|
64
|
+
next = next.where("channel", "=", where.channel) as typeof next;
|
|
65
|
+
if (where?.platform !== undefined)
|
|
66
|
+
next = next.where("platform", "=", where.platform) as typeof next;
|
|
67
|
+
if (where?.enabled !== undefined)
|
|
68
|
+
next = next.where("enabled", "=", where.enabled) as typeof next;
|
|
69
|
+
if (where?.fingerprintHash !== undefined) {
|
|
70
|
+
next =
|
|
71
|
+
where.fingerprintHash === null
|
|
72
|
+
? (next.where("fingerprint_hash", "is", null) as typeof next)
|
|
73
|
+
: (next.where(
|
|
74
|
+
"fingerprint_hash",
|
|
75
|
+
"=",
|
|
76
|
+
where.fingerprintHash,
|
|
77
|
+
) as typeof next);
|
|
78
|
+
}
|
|
79
|
+
if (where?.targetAppVersion !== undefined) {
|
|
80
|
+
next =
|
|
81
|
+
where.targetAppVersion === null
|
|
82
|
+
? (next.where("target_app_version", "is", null) as typeof next)
|
|
83
|
+
: (next.where(
|
|
84
|
+
"target_app_version",
|
|
85
|
+
"=",
|
|
86
|
+
where.targetAppVersion,
|
|
87
|
+
) as typeof next);
|
|
88
|
+
}
|
|
89
|
+
if (where?.targetAppVersionIn) {
|
|
90
|
+
next = next.where(
|
|
91
|
+
"target_app_version",
|
|
92
|
+
"in",
|
|
93
|
+
where.targetAppVersionIn,
|
|
94
|
+
) as typeof next;
|
|
95
|
+
}
|
|
96
|
+
if (where?.targetAppVersionNotNull) {
|
|
97
|
+
next = next.where("target_app_version", "is not", null) as typeof next;
|
|
98
|
+
}
|
|
99
|
+
if (where?.id?.eq) next = next.where("id", "=", where.id.eq) as typeof next;
|
|
100
|
+
if (where?.id?.gt) next = next.where("id", ">", where.id.gt) as typeof next;
|
|
101
|
+
if (where?.id?.gte)
|
|
102
|
+
next = next.where("id", ">=", where.id.gte) as typeof next;
|
|
103
|
+
if (where?.id?.lt) next = next.where("id", "<", where.id.lt) as typeof next;
|
|
104
|
+
if (where?.id?.lte)
|
|
105
|
+
next = next.where("id", "<=", where.id.lte) as typeof next;
|
|
106
|
+
if (where?.id?.in) next = next.where("id", "in", where.id.in) as typeof next;
|
|
107
|
+
return next as T;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const hasEmptySetFilter = (
|
|
111
|
+
where: DatabaseBundleQueryWhere | undefined,
|
|
112
|
+
): boolean =>
|
|
113
|
+
where?.targetAppVersionIn?.length === 0 || where?.id?.in?.length === 0;
|
|
114
|
+
|
|
115
|
+
const toProviderBundleRow = (
|
|
116
|
+
row: BundleRow,
|
|
117
|
+
provider: KyselySQLProvider,
|
|
118
|
+
): BundleRow => {
|
|
119
|
+
if (provider !== "mysql" && provider !== "sqlite") return row;
|
|
120
|
+
return {
|
|
121
|
+
...row,
|
|
122
|
+
metadata: JSON.stringify(row.metadata ?? {}),
|
|
123
|
+
target_cohorts:
|
|
124
|
+
row.target_cohorts === null || row.target_cohorts === undefined
|
|
125
|
+
? null
|
|
126
|
+
: JSON.stringify(row.target_cohorts),
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const createKyselyPlugin = createDatabasePlugin<KyselyAdapterConfig<Database>>({
|
|
131
|
+
name: "kysely",
|
|
132
|
+
factory: ({ db, provider }) => {
|
|
133
|
+
const fetchPatchMap = async (bundleIds: readonly string[]) => {
|
|
134
|
+
const patchMap = new Map<string, BundlePatchRow[]>();
|
|
135
|
+
if (bundleIds.length === 0) return patchMap;
|
|
136
|
+
const rows = await db
|
|
137
|
+
.selectFrom("bundle_patches")
|
|
138
|
+
.selectAll()
|
|
139
|
+
.where("bundle_id", "in", [...bundleIds])
|
|
140
|
+
.orderBy("order_index", "asc")
|
|
141
|
+
.execute();
|
|
142
|
+
for (const row of rows) {
|
|
143
|
+
const current = patchMap.get(row.bundle_id) ?? [];
|
|
144
|
+
current.push(row);
|
|
145
|
+
patchMap.set(row.bundle_id, current);
|
|
146
|
+
}
|
|
147
|
+
return patchMap;
|
|
148
|
+
};
|
|
149
|
+
const mapRowsToBundles = async (
|
|
150
|
+
rows: readonly BundleRow[],
|
|
151
|
+
): Promise<Bundle[]> => {
|
|
152
|
+
const patchMap = await fetchPatchMap(rows.map((row) => row.id));
|
|
153
|
+
return rows.map((row) => rowToBundle(row, patchMap.get(row.id) ?? []));
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const upsertBundle = async (
|
|
157
|
+
executor: Kysely<Database> | Transaction<Database>,
|
|
158
|
+
bundle: Bundle,
|
|
159
|
+
) => {
|
|
160
|
+
const row = toProviderBundleRow(bundleToRow(bundle), provider);
|
|
161
|
+
const { id: _id, ...updateRow } = row;
|
|
162
|
+
if (provider === "mysql") {
|
|
163
|
+
await executor
|
|
164
|
+
.insertInto("bundles")
|
|
165
|
+
.values(row)
|
|
166
|
+
.onDuplicateKeyUpdate(updateRow)
|
|
167
|
+
.execute();
|
|
168
|
+
} else {
|
|
169
|
+
await executor
|
|
170
|
+
.insertInto("bundles")
|
|
171
|
+
.values(row)
|
|
172
|
+
.onConflict((oc) => oc.column("id").doUpdateSet(updateRow))
|
|
173
|
+
.execute();
|
|
174
|
+
}
|
|
175
|
+
await executor
|
|
176
|
+
.deleteFrom("bundle_patches")
|
|
177
|
+
.where("bundle_id", "=", bundle.id)
|
|
178
|
+
.execute();
|
|
179
|
+
const patches = bundleToPatchRows(bundle);
|
|
180
|
+
if (patches.length > 0) {
|
|
181
|
+
await executor.insertInto("bundle_patches").values(patches).execute();
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
return {
|
|
186
|
+
async getBundleById(bundleId) {
|
|
187
|
+
const row = await db
|
|
188
|
+
.selectFrom("bundles")
|
|
189
|
+
.selectAll()
|
|
190
|
+
.where("id", "=", bundleId)
|
|
191
|
+
.executeTakeFirst();
|
|
192
|
+
if (!row) return null;
|
|
193
|
+
const patchMap = await fetchPatchMap([bundleId]);
|
|
194
|
+
return rowToBundle(row, patchMap.get(bundleId) ?? []);
|
|
195
|
+
},
|
|
196
|
+
async getBundles(
|
|
197
|
+
options: DatabaseBundleQueryOptions & { offset?: number },
|
|
198
|
+
) {
|
|
199
|
+
const offset = options.offset ?? 0;
|
|
200
|
+
if (hasEmptySetFilter(options.where)) {
|
|
201
|
+
return {
|
|
202
|
+
data: [],
|
|
203
|
+
pagination: calculatePagination(0, {
|
|
204
|
+
limit: options.limit,
|
|
205
|
+
offset,
|
|
206
|
+
}),
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
const orderBy = options.orderBy ?? { field: "id", direction: "desc" };
|
|
210
|
+
const countRow = await applyWhere(
|
|
211
|
+
db.selectFrom("bundles"),
|
|
212
|
+
options.where,
|
|
213
|
+
)
|
|
214
|
+
.select(db.fn.count<number>("id").as("total"))
|
|
215
|
+
.executeTakeFirst();
|
|
216
|
+
const total = Number(countRow?.total ?? 0);
|
|
217
|
+
const rows = await applyWhere(
|
|
218
|
+
db.selectFrom("bundles").selectAll(),
|
|
219
|
+
options.where,
|
|
220
|
+
)
|
|
221
|
+
.orderBy("id", orderBy.direction)
|
|
222
|
+
.limit(options.limit)
|
|
223
|
+
.offset(offset)
|
|
224
|
+
.execute();
|
|
225
|
+
const patchMap = await fetchPatchMap(rows.map((row) => row.id));
|
|
226
|
+
return {
|
|
227
|
+
data: rows.map((row) => rowToBundle(row, patchMap.get(row.id) ?? [])),
|
|
228
|
+
pagination: calculatePagination(total, {
|
|
229
|
+
limit: options.limit,
|
|
230
|
+
offset,
|
|
231
|
+
}),
|
|
232
|
+
};
|
|
233
|
+
},
|
|
234
|
+
async getUpdateInfo(args, context) {
|
|
235
|
+
if (args._updateStrategy === "appVersion") {
|
|
236
|
+
const channel = args.channel ?? "production";
|
|
237
|
+
const minBundleId = args.minBundleId ?? NIL_UUID;
|
|
238
|
+
const rows = await db
|
|
239
|
+
.selectFrom("bundles")
|
|
240
|
+
.select("target_app_version")
|
|
241
|
+
.where("enabled", "=", true)
|
|
242
|
+
.where("platform", "=", args.platform)
|
|
243
|
+
.where("channel", "=", channel)
|
|
244
|
+
.where("id", ">=", minBundleId)
|
|
245
|
+
.where("target_app_version", "is not", null)
|
|
246
|
+
.execute();
|
|
247
|
+
|
|
248
|
+
const targetAppVersions = Array.from(
|
|
249
|
+
new Set(
|
|
250
|
+
rows
|
|
251
|
+
.map((row) => row.target_app_version)
|
|
252
|
+
.filter(
|
|
253
|
+
(value): value is string =>
|
|
254
|
+
typeof value === "string" && value.length > 0,
|
|
255
|
+
),
|
|
256
|
+
),
|
|
257
|
+
);
|
|
258
|
+
const compatibleAppVersions = filterCompatibleAppVersions(
|
|
259
|
+
targetAppVersions,
|
|
260
|
+
args.appVersion,
|
|
261
|
+
);
|
|
262
|
+
const bundles =
|
|
263
|
+
compatibleAppVersions.length > 0
|
|
264
|
+
? await db
|
|
265
|
+
.selectFrom("bundles")
|
|
266
|
+
.selectAll()
|
|
267
|
+
.where("enabled", "=", true)
|
|
268
|
+
.where("platform", "=", args.platform)
|
|
269
|
+
.where("channel", "=", channel)
|
|
270
|
+
.where("id", ">=", minBundleId)
|
|
271
|
+
.where("target_app_version", "in", compatibleAppVersions)
|
|
272
|
+
.orderBy("id", "desc")
|
|
273
|
+
.execute()
|
|
274
|
+
.then(mapRowsToBundles)
|
|
275
|
+
: [];
|
|
276
|
+
|
|
277
|
+
return resolveUpdateInfoFromBundles({
|
|
278
|
+
args: { ...args, channel, minBundleId },
|
|
279
|
+
bundles,
|
|
280
|
+
context,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const channel = args.channel ?? "production";
|
|
285
|
+
const minBundleId = args.minBundleId ?? NIL_UUID;
|
|
286
|
+
const rows = await db
|
|
287
|
+
.selectFrom("bundles")
|
|
288
|
+
.selectAll()
|
|
289
|
+
.where("enabled", "=", true)
|
|
290
|
+
.where("platform", "=", args.platform)
|
|
291
|
+
.where("channel", "=", channel)
|
|
292
|
+
.where("id", ">=", minBundleId)
|
|
293
|
+
.where("fingerprint_hash", "=", args.fingerprintHash)
|
|
294
|
+
.orderBy("id", "desc")
|
|
295
|
+
.execute();
|
|
296
|
+
|
|
297
|
+
return resolveUpdateInfoFromBundles({
|
|
298
|
+
args: { ...args, channel, minBundleId },
|
|
299
|
+
bundles: await mapRowsToBundles(rows),
|
|
300
|
+
context,
|
|
301
|
+
});
|
|
302
|
+
},
|
|
303
|
+
async getChannels() {
|
|
304
|
+
const rows = await db
|
|
305
|
+
.selectFrom("bundles")
|
|
306
|
+
.select("channel")
|
|
307
|
+
.orderBy("channel", "asc")
|
|
308
|
+
.execute();
|
|
309
|
+
return Array.from(new Set(rows.map((row) => row.channel)));
|
|
310
|
+
},
|
|
311
|
+
async commitBundle({ changedSets }) {
|
|
312
|
+
await db.transaction().execute(async (tx) => {
|
|
313
|
+
for (const change of changedSets) {
|
|
314
|
+
if (change.operation === "delete") {
|
|
315
|
+
await tx
|
|
316
|
+
.deleteFrom("bundle_patches")
|
|
317
|
+
.where("bundle_id", "=", change.data.id)
|
|
318
|
+
.execute();
|
|
319
|
+
await tx
|
|
320
|
+
.deleteFrom("bundle_patches")
|
|
321
|
+
.where("base_bundle_id", "=", change.data.id)
|
|
322
|
+
.execute();
|
|
323
|
+
await tx
|
|
324
|
+
.deleteFrom("bundles")
|
|
325
|
+
.where("id", "=", change.data.id)
|
|
326
|
+
.execute();
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
await upsertBundle(tx, change.data);
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
},
|
|
333
|
+
};
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
|
|
14
337
|
export const kyselyAdapter = <TDatabase extends object>(
|
|
15
|
-
config:
|
|
16
|
-
):
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
) as unknown as ORMDatabaseAdapter,
|
|
338
|
+
config: KyselyAdapterConfig<TDatabase>,
|
|
339
|
+
): DatabasePluginFactory => {
|
|
340
|
+
assertKyselySQLProvider(config.provider);
|
|
341
|
+
return Object.assign(
|
|
342
|
+
createKyselyPlugin(config as unknown as KyselyAdapterConfig<Database>),
|
|
21
343
|
{
|
|
344
|
+
adapterName: "kysely",
|
|
22
345
|
provider: config.provider,
|
|
346
|
+
createMigrator: () =>
|
|
347
|
+
createKyselyMigrator({
|
|
348
|
+
db: config.db as unknown as Kysely<{
|
|
349
|
+
private_hot_updater_settings: {
|
|
350
|
+
key: string;
|
|
351
|
+
value: string;
|
|
352
|
+
};
|
|
353
|
+
}>,
|
|
354
|
+
provider: config.provider,
|
|
355
|
+
relationMode: config.relationMode,
|
|
356
|
+
}),
|
|
23
357
|
},
|
|
24
358
|
);
|
|
359
|
+
};
|
package/src/adapters/mongodb.ts
CHANGED
|
@@ -1,19 +1,302 @@
|
|
|
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 type { ClientSession, Collection, Filter, MongoClient } from "mongodb";
|
|
2
14
|
|
|
3
|
-
import
|
|
15
|
+
import {
|
|
16
|
+
bundleToPatchRows,
|
|
17
|
+
bundleToRow,
|
|
18
|
+
type BundlePatchRow,
|
|
19
|
+
type BundleRow,
|
|
20
|
+
rowToBundle,
|
|
21
|
+
} from "../db/bundleRows";
|
|
22
|
+
import { createMongoMigrator } from "../db/fixedMigrator";
|
|
23
|
+
import type { DatabasePluginFactory } from "../db/types";
|
|
4
24
|
|
|
5
|
-
export interface MongoDBConfig
|
|
6
|
-
client:
|
|
25
|
+
export interface MongoDBConfig {
|
|
26
|
+
readonly client: MongoClient;
|
|
7
27
|
}
|
|
8
28
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
):
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
29
|
+
const mongoWhere = (
|
|
30
|
+
where: DatabaseBundleQueryWhere | undefined,
|
|
31
|
+
): Filter<BundleRow> => {
|
|
32
|
+
const baseFilter: Filter<BundleRow> = {
|
|
33
|
+
...(where?.channel !== undefined ? { channel: where.channel } : {}),
|
|
34
|
+
...(where?.platform !== undefined ? { platform: where.platform } : {}),
|
|
35
|
+
...(where?.enabled !== undefined ? { enabled: where.enabled } : {}),
|
|
36
|
+
...(where?.fingerprintHash !== undefined
|
|
37
|
+
? where.fingerprintHash === null
|
|
38
|
+
? { fingerprint_hash: { $in: [null, ""] } }
|
|
39
|
+
: { fingerprint_hash: where.fingerprintHash }
|
|
40
|
+
: {}),
|
|
41
|
+
...(where?.id
|
|
42
|
+
? {
|
|
43
|
+
id: {
|
|
44
|
+
...(where.id.eq !== undefined ? { $eq: where.id.eq } : {}),
|
|
45
|
+
...(where.id.gt !== undefined ? { $gt: where.id.gt } : {}),
|
|
46
|
+
...(where.id.gte !== undefined ? { $gte: where.id.gte } : {}),
|
|
47
|
+
...(where.id.lt !== undefined ? { $lt: where.id.lt } : {}),
|
|
48
|
+
...(where.id.lte !== undefined ? { $lte: where.id.lte } : {}),
|
|
49
|
+
...(where.id.in !== undefined ? { $in: where.id.in } : {}),
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
: {}),
|
|
53
|
+
};
|
|
54
|
+
const targetAppVersionFilters: Filter<BundleRow>[] = [];
|
|
55
|
+
if (where?.targetAppVersion !== undefined) {
|
|
56
|
+
targetAppVersionFilters.push(
|
|
57
|
+
where.targetAppVersion === null
|
|
58
|
+
? { target_app_version: { $in: [null, ""] } }
|
|
59
|
+
: { target_app_version: where.targetAppVersion },
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
if (where?.targetAppVersionIn) {
|
|
63
|
+
targetAppVersionFilters.push({
|
|
64
|
+
target_app_version: { $in: where.targetAppVersionIn },
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (where?.targetAppVersionNotNull) {
|
|
68
|
+
targetAppVersionFilters.push({
|
|
69
|
+
target_app_version: { $exists: true, $nin: [null, ""] },
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const filters = [
|
|
74
|
+
...(Object.keys(baseFilter).length > 0 ? [baseFilter] : []),
|
|
75
|
+
...targetAppVersionFilters,
|
|
76
|
+
];
|
|
77
|
+
if (filters.length === 0) return {};
|
|
78
|
+
if (filters.length === 1) return filters[0] ?? {};
|
|
79
|
+
return { $and: filters };
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const createMongoPlugin = createDatabasePlugin<MongoDBConfig>({
|
|
83
|
+
name: "mongodb",
|
|
84
|
+
factory: ({ client }) => {
|
|
85
|
+
const db = client.db();
|
|
86
|
+
const bundles = db.collection<BundleRow>("bundles");
|
|
87
|
+
const patches = db.collection<BundlePatchRow>("bundle_patches");
|
|
88
|
+
const fetchPatchMap = async (bundleIds: readonly string[]) => {
|
|
89
|
+
const patchMap = new Map<string, BundlePatchRow[]>();
|
|
90
|
+
if (bundleIds.length === 0) return patchMap;
|
|
91
|
+
const rows = await patches
|
|
92
|
+
.find({ bundle_id: { $in: [...bundleIds] } })
|
|
93
|
+
.sort({ order_index: 1 })
|
|
94
|
+
.toArray();
|
|
95
|
+
for (const row of rows) {
|
|
96
|
+
const current = patchMap.get(row.bundle_id) ?? [];
|
|
97
|
+
current.push(row);
|
|
98
|
+
patchMap.set(row.bundle_id, current);
|
|
99
|
+
}
|
|
100
|
+
return patchMap;
|
|
101
|
+
};
|
|
102
|
+
const mapRowsToBundles = async (
|
|
103
|
+
rows: readonly BundleRow[],
|
|
104
|
+
): Promise<Bundle[]> => {
|
|
105
|
+
const patchMap = await fetchPatchMap(rows.map((row) => row.id));
|
|
106
|
+
return rows.map((row) => rowToBundle(row, patchMap.get(row.id) ?? []));
|
|
107
|
+
};
|
|
108
|
+
const isTransactionUnsupported = (error: unknown): boolean =>
|
|
109
|
+
error instanceof Error &&
|
|
110
|
+
/Transaction numbers are only allowed|replica set member or mongos|Transaction API error/i.test(
|
|
111
|
+
error.message,
|
|
112
|
+
);
|
|
113
|
+
const runInTransaction = async <T>(
|
|
114
|
+
operation: (session: ClientSession | undefined) => Promise<T>,
|
|
115
|
+
) => {
|
|
116
|
+
if (typeof client.startSession !== "function") {
|
|
117
|
+
return operation(undefined);
|
|
118
|
+
}
|
|
119
|
+
const session = client.startSession();
|
|
120
|
+
try {
|
|
121
|
+
if (typeof session.withTransaction !== "function") {
|
|
122
|
+
return await operation(session);
|
|
123
|
+
}
|
|
124
|
+
let result: T | undefined;
|
|
125
|
+
await session.withTransaction(async () => {
|
|
126
|
+
result = await operation(session);
|
|
127
|
+
});
|
|
128
|
+
return result as T;
|
|
129
|
+
} catch (error) {
|
|
130
|
+
if (isTransactionUnsupported(error)) {
|
|
131
|
+
return operation(undefined);
|
|
132
|
+
}
|
|
133
|
+
throw error;
|
|
134
|
+
} finally {
|
|
135
|
+
await session.endSession();
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const replaceBundle = async (
|
|
139
|
+
bundle: Bundle,
|
|
140
|
+
session: ClientSession | undefined,
|
|
141
|
+
) => {
|
|
142
|
+
const row = bundleToRow(bundle);
|
|
143
|
+
await bundles.updateOne(
|
|
144
|
+
{ id: bundle.id },
|
|
145
|
+
{ $set: row },
|
|
146
|
+
{ session, upsert: true },
|
|
147
|
+
);
|
|
148
|
+
await patches.deleteMany({ bundle_id: bundle.id }, { session });
|
|
149
|
+
const patchRows = bundleToPatchRows(bundle);
|
|
150
|
+
if (patchRows.length > 0)
|
|
151
|
+
await patches.insertMany(patchRows, { session });
|
|
152
|
+
};
|
|
153
|
+
const deleteByBundleId = async (
|
|
154
|
+
collection: Collection<BundlePatchRow>,
|
|
155
|
+
field: "bundle_id" | "base_bundle_id",
|
|
156
|
+
bundleId: string,
|
|
157
|
+
session: ClientSession | undefined,
|
|
158
|
+
) => {
|
|
159
|
+
await collection.deleteMany({ [field]: bundleId }, { session });
|
|
160
|
+
};
|
|
161
|
+
return {
|
|
162
|
+
async getBundleById(bundleId) {
|
|
163
|
+
const row = await bundles.findOne({ id: bundleId });
|
|
164
|
+
if (!row) return null;
|
|
165
|
+
const patchMap = await fetchPatchMap([bundleId]);
|
|
166
|
+
return rowToBundle(row, patchMap.get(bundleId) ?? []);
|
|
167
|
+
},
|
|
168
|
+
async getBundles(
|
|
169
|
+
options: DatabaseBundleQueryOptions & { offset?: number },
|
|
170
|
+
) {
|
|
171
|
+
const offset = options.offset ?? 0;
|
|
172
|
+
const orderBy = options.orderBy ?? { field: "id", direction: "desc" };
|
|
173
|
+
const where = mongoWhere(options.where);
|
|
174
|
+
const [total, rows] = await Promise.all([
|
|
175
|
+
bundles.countDocuments(where),
|
|
176
|
+
bundles
|
|
177
|
+
.find(where)
|
|
178
|
+
.sort({ id: orderBy.direction === "asc" ? 1 : -1 })
|
|
179
|
+
.skip(offset)
|
|
180
|
+
.limit(options.limit)
|
|
181
|
+
.toArray(),
|
|
182
|
+
]);
|
|
183
|
+
const patchMap = await fetchPatchMap(rows.map((row) => row.id));
|
|
184
|
+
return {
|
|
185
|
+
data: rows.map((row) => rowToBundle(row, patchMap.get(row.id) ?? [])),
|
|
186
|
+
pagination: calculatePagination(total, {
|
|
187
|
+
limit: options.limit,
|
|
188
|
+
offset,
|
|
189
|
+
}),
|
|
190
|
+
};
|
|
191
|
+
},
|
|
192
|
+
async getUpdateInfo(args, context) {
|
|
193
|
+
if (args._updateStrategy === "appVersion") {
|
|
194
|
+
const channel = args.channel ?? "production";
|
|
195
|
+
const minBundleId = args.minBundleId ?? NIL_UUID;
|
|
196
|
+
const rows = await bundles
|
|
197
|
+
.find({
|
|
198
|
+
enabled: true,
|
|
199
|
+
platform: args.platform,
|
|
200
|
+
channel,
|
|
201
|
+
id: { $gte: minBundleId },
|
|
202
|
+
target_app_version: { $exists: true, $nin: [null, ""] },
|
|
203
|
+
})
|
|
204
|
+
.project<{ target_app_version?: string | null }>({
|
|
205
|
+
target_app_version: 1,
|
|
206
|
+
})
|
|
207
|
+
.toArray();
|
|
208
|
+
|
|
209
|
+
const targetAppVersions = Array.from(
|
|
210
|
+
new Set(
|
|
211
|
+
rows
|
|
212
|
+
.map((row) => row.target_app_version)
|
|
213
|
+
.filter(
|
|
214
|
+
(value): value is string =>
|
|
215
|
+
typeof value === "string" && value.length > 0,
|
|
216
|
+
),
|
|
217
|
+
),
|
|
218
|
+
);
|
|
219
|
+
const compatibleAppVersions = filterCompatibleAppVersions(
|
|
220
|
+
targetAppVersions,
|
|
221
|
+
args.appVersion,
|
|
222
|
+
);
|
|
223
|
+
const updateRows =
|
|
224
|
+
compatibleAppVersions.length > 0
|
|
225
|
+
? await bundles
|
|
226
|
+
.find({
|
|
227
|
+
enabled: true,
|
|
228
|
+
platform: args.platform,
|
|
229
|
+
channel,
|
|
230
|
+
id: { $gte: minBundleId },
|
|
231
|
+
target_app_version: { $in: compatibleAppVersions },
|
|
232
|
+
})
|
|
233
|
+
.sort({ id: -1 })
|
|
234
|
+
.toArray()
|
|
235
|
+
: [];
|
|
236
|
+
|
|
237
|
+
return resolveUpdateInfoFromBundles({
|
|
238
|
+
args: { ...args, channel, minBundleId },
|
|
239
|
+
bundles: await mapRowsToBundles(updateRows),
|
|
240
|
+
context,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const channel = args.channel ?? "production";
|
|
245
|
+
const minBundleId = args.minBundleId ?? NIL_UUID;
|
|
246
|
+
const rows = await bundles
|
|
247
|
+
.find({
|
|
248
|
+
enabled: true,
|
|
249
|
+
platform: args.platform,
|
|
250
|
+
channel,
|
|
251
|
+
id: { $gte: minBundleId },
|
|
252
|
+
fingerprint_hash: args.fingerprintHash,
|
|
253
|
+
})
|
|
254
|
+
.sort({ id: -1 })
|
|
255
|
+
.toArray();
|
|
256
|
+
|
|
257
|
+
return resolveUpdateInfoFromBundles({
|
|
258
|
+
args: { ...args, channel, minBundleId },
|
|
259
|
+
bundles: await mapRowsToBundles(rows),
|
|
260
|
+
context,
|
|
261
|
+
});
|
|
262
|
+
},
|
|
263
|
+
async getChannels() {
|
|
264
|
+
const channels = await bundles.distinct("channel");
|
|
265
|
+
return channels
|
|
266
|
+
.filter((channel): channel is string => typeof channel === "string")
|
|
267
|
+
.sort((left, right) => left.localeCompare(right));
|
|
268
|
+
},
|
|
269
|
+
async commitBundle({ changedSets }) {
|
|
270
|
+
await runInTransaction(async (session) => {
|
|
271
|
+
for (const change of changedSets) {
|
|
272
|
+
if (change.operation === "delete") {
|
|
273
|
+
await deleteByBundleId(
|
|
274
|
+
patches,
|
|
275
|
+
"bundle_id",
|
|
276
|
+
change.data.id,
|
|
277
|
+
session,
|
|
278
|
+
);
|
|
279
|
+
await deleteByBundleId(
|
|
280
|
+
patches,
|
|
281
|
+
"base_bundle_id",
|
|
282
|
+
change.data.id,
|
|
283
|
+
session,
|
|
284
|
+
);
|
|
285
|
+
await bundles.deleteMany({ id: change.data.id }, { session });
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
await replaceBundle(change.data, session);
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
export const mongoAdapter = (config: MongoDBConfig): DatabasePluginFactory => {
|
|
297
|
+
return Object.assign(createMongoPlugin(config), {
|
|
298
|
+
adapterName: "mongodb",
|
|
299
|
+
provider: "mongodb" as const,
|
|
300
|
+
createMigrator: () => createMongoMigrator(config.client),
|
|
301
|
+
});
|
|
302
|
+
};
|