@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
package/src/db/index.ts
CHANGED
|
@@ -9,22 +9,21 @@ export * from "./createBundleDiff";
|
|
|
9
9
|
import { createHandler, type HandlerRoutes } from "../handler";
|
|
10
10
|
import { normalizeBasePath } from "../route";
|
|
11
11
|
import { createStorageAccess } from "../storageAccess";
|
|
12
|
-
import {
|
|
13
|
-
createOrmDatabaseCore,
|
|
14
|
-
type HotUpdaterClient,
|
|
15
|
-
type Migrator,
|
|
16
|
-
} from "./ormCore";
|
|
17
12
|
import { createPluginDatabaseCore } from "./pluginCore";
|
|
13
|
+
import { generateSchemaFromHotUpdaterSchema } from "./schemaGenerators";
|
|
14
|
+
import { createSchemaReadinessChecker } from "./schemaReadiness";
|
|
18
15
|
import {
|
|
16
|
+
type DatabaseAdapterCapabilities,
|
|
19
17
|
type DatabaseAdapter,
|
|
20
18
|
type DatabaseAPI,
|
|
21
|
-
|
|
19
|
+
type Migrator,
|
|
20
|
+
type SchemaGenerator,
|
|
22
21
|
isDatabasePluginFactory,
|
|
23
22
|
type StoragePluginFactory,
|
|
24
23
|
} from "./types";
|
|
25
24
|
|
|
26
|
-
export type {
|
|
27
|
-
export {
|
|
25
|
+
export type { Migrator, SchemaGenerator } from "./types";
|
|
26
|
+
export { HotUpdaterSchemaMigrationRequiredError } from "./schemaReadiness";
|
|
28
27
|
export { HOT_UPDATER_SERVER_VERSION } from "../version";
|
|
29
28
|
|
|
30
29
|
export type HotUpdaterAPI<TContext = unknown> = DatabaseAPI<TContext> & {
|
|
@@ -35,7 +34,7 @@ export type HotUpdaterAPI<TContext = unknown> = DatabaseAPI<TContext> & {
|
|
|
35
34
|
) => Promise<Response>;
|
|
36
35
|
adapterName: string;
|
|
37
36
|
createMigrator: () => Migrator;
|
|
38
|
-
generateSchema:
|
|
37
|
+
generateSchema: SchemaGenerator;
|
|
39
38
|
};
|
|
40
39
|
|
|
41
40
|
export interface CreateHotUpdaterOptions<TContext = unknown> {
|
|
@@ -77,37 +76,39 @@ export function createHotUpdater<TContext = unknown>(
|
|
|
77
76
|
|
|
78
77
|
const database = options.database;
|
|
79
78
|
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
: { readStorageText },
|
|
98
|
-
);
|
|
99
|
-
})()
|
|
100
|
-
: createOrmDatabaseCore<TContext>({
|
|
101
|
-
database,
|
|
79
|
+
const capabilities = database as DatabaseAdapterCapabilities;
|
|
80
|
+
const plugin: DatabasePlugin<TContext> = isDatabasePluginFactory(database)
|
|
81
|
+
? database()
|
|
82
|
+
: database;
|
|
83
|
+
const adapterName = capabilities.adapterName ?? plugin.name;
|
|
84
|
+
const assertSchemaReady = createSchemaReadinessChecker(
|
|
85
|
+
adapterName,
|
|
86
|
+
capabilities.createMigrator,
|
|
87
|
+
);
|
|
88
|
+
const core = createPluginDatabaseCore<TContext>(
|
|
89
|
+
() => plugin,
|
|
90
|
+
resolveFileUrl,
|
|
91
|
+
isDatabasePluginFactory(database)
|
|
92
|
+
? {
|
|
93
|
+
createMutationPlugin: () => database(),
|
|
94
|
+
beforeOperation: assertSchemaReady,
|
|
102
95
|
readStorageText,
|
|
103
|
-
|
|
104
|
-
|
|
96
|
+
}
|
|
97
|
+
: { beforeOperation: assertSchemaReady, readStorageText },
|
|
98
|
+
);
|
|
105
99
|
|
|
100
|
+
const generateSchema = capabilities.generateSchema ?? core.generateSchema;
|
|
106
101
|
const api = {
|
|
107
102
|
basePath,
|
|
108
|
-
adapterName: core.adapterName,
|
|
109
|
-
createMigrator: core.createMigrator,
|
|
110
|
-
generateSchema:
|
|
103
|
+
adapterName: capabilities.adapterName ?? core.adapterName,
|
|
104
|
+
createMigrator: capabilities.createMigrator ?? core.createMigrator,
|
|
105
|
+
generateSchema: (...args: Parameters<SchemaGenerator>) =>
|
|
106
|
+
generateSchemaFromHotUpdaterSchema(
|
|
107
|
+
api.adapterName,
|
|
108
|
+
capabilities.provider,
|
|
109
|
+
args[0],
|
|
110
|
+
generateSchema(...args),
|
|
111
|
+
),
|
|
111
112
|
handler: createHandler(core.api, {
|
|
112
113
|
basePath,
|
|
113
114
|
routes: options.routes,
|
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
DatabasePlugin,
|
|
5
5
|
RequestEnvContext,
|
|
6
6
|
} from "@hot-updater/plugin-core";
|
|
7
|
-
import {
|
|
7
|
+
import { resolveUpdateInfoFromBundles } from "@hot-updater/plugin-core";
|
|
8
8
|
import { describe, expect, it, vi } from "vitest";
|
|
9
9
|
|
|
10
10
|
import { createPluginDatabaseCore } from "./pluginCore";
|
|
@@ -449,11 +449,14 @@ describe("createPluginDatabaseCore", () => {
|
|
|
449
449
|
throw new Error("unexpected provider bundle reread");
|
|
450
450
|
},
|
|
451
451
|
);
|
|
452
|
-
const getUpdateInfo
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
452
|
+
const getUpdateInfo: NonNullable<
|
|
453
|
+
DatabasePlugin<TestContext>["getUpdateInfo"]
|
|
454
|
+
> = async (args, context) =>
|
|
455
|
+
resolveUpdateInfoFromBundles({
|
|
456
|
+
args,
|
|
457
|
+
bundles: [targetBundle],
|
|
458
|
+
context,
|
|
459
|
+
});
|
|
457
460
|
const plugin: DatabasePlugin<TestContext> = {
|
|
458
461
|
name: "seeded-fast-path-plugin",
|
|
459
462
|
async appendBundle() {},
|
|
@@ -547,11 +550,14 @@ describe("createPluginDatabaseCore", () => {
|
|
|
547
550
|
throw new Error("unexpected provider current bundle reread");
|
|
548
551
|
},
|
|
549
552
|
);
|
|
550
|
-
const getUpdateInfo
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
553
|
+
const getUpdateInfo: NonNullable<
|
|
554
|
+
DatabasePlugin<TestContext>["getUpdateInfo"]
|
|
555
|
+
> = async (args, context) =>
|
|
556
|
+
resolveUpdateInfoFromBundles({
|
|
557
|
+
args,
|
|
558
|
+
bundles: [targetBundle],
|
|
559
|
+
context,
|
|
560
|
+
});
|
|
555
561
|
const plugin: DatabasePlugin<TestContext> = {
|
|
556
562
|
name: "seeded-current-miss-plugin",
|
|
557
563
|
async appendBundle() {},
|
package/src/db/pluginCore.ts
CHANGED
|
@@ -113,6 +113,7 @@ export function createPluginDatabaseCore<TContext = unknown>(
|
|
|
113
113
|
cleanupMutationPlugin?: (
|
|
114
114
|
plugin: DatabasePlugin<TContext>,
|
|
115
115
|
) => Promise<void> | void;
|
|
116
|
+
beforeOperation?: () => Promise<void>;
|
|
116
117
|
readStorageText?: (
|
|
117
118
|
storageUri: string,
|
|
118
119
|
context?: HotUpdaterContext<TContext>,
|
|
@@ -124,16 +125,17 @@ export function createPluginDatabaseCore<TContext = unknown>(
|
|
|
124
125
|
createMigrator: () => never;
|
|
125
126
|
generateSchema: () => never;
|
|
126
127
|
} {
|
|
128
|
+
const coreOptions = options;
|
|
127
129
|
const runWithMutationPlugin = async <T>(
|
|
128
130
|
operation: (plugin: DatabasePlugin<TContext>) => Promise<T>,
|
|
129
131
|
): Promise<T> => {
|
|
130
|
-
const plugin =
|
|
132
|
+
const plugin = coreOptions?.createMutationPlugin?.() ?? getPlugin();
|
|
131
133
|
|
|
132
134
|
try {
|
|
133
135
|
return await operation(plugin);
|
|
134
136
|
} finally {
|
|
135
|
-
if (
|
|
136
|
-
await
|
|
137
|
+
if (coreOptions?.createMutationPlugin) {
|
|
138
|
+
await coreOptions.cleanupMutationPlugin?.(plugin);
|
|
137
139
|
}
|
|
138
140
|
}
|
|
139
141
|
};
|
|
@@ -278,6 +280,7 @@ export function createPluginDatabaseCore<TContext = unknown>(
|
|
|
278
280
|
id: string,
|
|
279
281
|
context?: HotUpdaterContext<TContext>,
|
|
280
282
|
): Promise<Bundle | null> {
|
|
283
|
+
await coreOptions?.beforeOperation?.();
|
|
281
284
|
return getPlugin().getBundleById(id, context);
|
|
282
285
|
},
|
|
283
286
|
|
|
@@ -285,6 +288,7 @@ export function createPluginDatabaseCore<TContext = unknown>(
|
|
|
285
288
|
args: GetBundlesArgs,
|
|
286
289
|
context?: HotUpdaterContext<TContext>,
|
|
287
290
|
): Promise<UpdateInfo | null> {
|
|
291
|
+
await coreOptions?.beforeOperation?.();
|
|
288
292
|
const plugin = getPlugin();
|
|
289
293
|
const directGetUpdateInfo = plugin.getUpdateInfo;
|
|
290
294
|
if (directGetUpdateInfo) {
|
|
@@ -350,7 +354,7 @@ export function createPluginDatabaseCore<TContext = unknown>(
|
|
|
350
354
|
}
|
|
351
355
|
const { storageUri, ...rest } = info;
|
|
352
356
|
|
|
353
|
-
const readStorageText =
|
|
357
|
+
const readStorageText = coreOptions?.readStorageText;
|
|
354
358
|
if (info.id === NIL_UUID || !readStorageText) {
|
|
355
359
|
const fileUrl = await resolveFileUrl(storageUri ?? null, context);
|
|
356
360
|
const baseResponse: AppUpdateAvailableInfo = { ...rest, fileUrl };
|
|
@@ -400,10 +404,12 @@ export function createPluginDatabaseCore<TContext = unknown>(
|
|
|
400
404
|
async getChannels(
|
|
401
405
|
context?: HotUpdaterContext<TContext>,
|
|
402
406
|
): Promise<string[]> {
|
|
407
|
+
await coreOptions?.beforeOperation?.();
|
|
403
408
|
return getPlugin().getChannels(context);
|
|
404
409
|
},
|
|
405
410
|
|
|
406
411
|
async getBundles(options, context?: HotUpdaterContext<TContext>) {
|
|
412
|
+
await coreOptions?.beforeOperation?.();
|
|
407
413
|
return getPlugin().getBundles(options, context);
|
|
408
414
|
},
|
|
409
415
|
|
|
@@ -411,6 +417,7 @@ export function createPluginDatabaseCore<TContext = unknown>(
|
|
|
411
417
|
bundle: Bundle,
|
|
412
418
|
context?: HotUpdaterContext<TContext>,
|
|
413
419
|
): Promise<void> {
|
|
420
|
+
await coreOptions?.beforeOperation?.();
|
|
414
421
|
assertBundlePersistenceConstraints(bundle);
|
|
415
422
|
await runWithMutationPlugin(async (plugin) => {
|
|
416
423
|
await plugin.appendBundle(bundle, context);
|
|
@@ -423,6 +430,7 @@ export function createPluginDatabaseCore<TContext = unknown>(
|
|
|
423
430
|
newBundle: Partial<Bundle>,
|
|
424
431
|
context?: HotUpdaterContext<TContext>,
|
|
425
432
|
): Promise<void> {
|
|
433
|
+
await coreOptions?.beforeOperation?.();
|
|
426
434
|
await runWithMutationPlugin(async (plugin) => {
|
|
427
435
|
const current = await plugin.getBundleById(bundleId, context);
|
|
428
436
|
if (!current) {
|
|
@@ -438,6 +446,7 @@ export function createPluginDatabaseCore<TContext = unknown>(
|
|
|
438
446
|
bundleId: string,
|
|
439
447
|
context?: HotUpdaterContext<TContext>,
|
|
440
448
|
): Promise<void> {
|
|
449
|
+
await coreOptions?.beforeOperation?.();
|
|
441
450
|
await runWithMutationPlugin(async (plugin) => {
|
|
442
451
|
const bundle = await plugin.getBundleById(bundleId, context);
|
|
443
452
|
if (!bundle) {
|
|
@@ -454,12 +463,12 @@ export function createPluginDatabaseCore<TContext = unknown>(
|
|
|
454
463
|
adapterName: getPlugin().name,
|
|
455
464
|
createMigrator: () => {
|
|
456
465
|
throw new Error(
|
|
457
|
-
"createMigrator is only available for Kysely/
|
|
466
|
+
"createMigrator is only available for Kysely/MongoDB database adapters.",
|
|
458
467
|
);
|
|
459
468
|
},
|
|
460
469
|
generateSchema: () => {
|
|
461
470
|
throw new Error(
|
|
462
|
-
"generateSchema is only available for
|
|
471
|
+
"generateSchema is only available for Drizzle/Prisma database adapters.",
|
|
463
472
|
);
|
|
464
473
|
},
|
|
465
474
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../schema";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { MigrationOperation } from "../types";
|
|
2
|
+
import { hotUpdaterSchema, schemaIndexAppliesToProvider } from "./registry";
|
|
3
|
+
import { hotUpdaterCreateTableOperations } from "./sql";
|
|
4
|
+
|
|
5
|
+
export const createMongoMigrationOperations = (
|
|
6
|
+
settingsOperation?: MigrationOperation,
|
|
7
|
+
): MigrationOperation[] => [
|
|
8
|
+
...hotUpdaterCreateTableOperations,
|
|
9
|
+
{
|
|
10
|
+
type: "custom",
|
|
11
|
+
sql: "create index bundles_id_idx on bundles(id)",
|
|
12
|
+
},
|
|
13
|
+
...hotUpdaterSchema.tables.flatMap((table) =>
|
|
14
|
+
(table.indexes ?? [])
|
|
15
|
+
.filter((index) => schemaIndexAppliesToProvider(index, "mongodb"))
|
|
16
|
+
.map(
|
|
17
|
+
(index): MigrationOperation => ({
|
|
18
|
+
type: "custom",
|
|
19
|
+
sql: `create index ${index.name} on ${table.ormName}(${index.columns.join(
|
|
20
|
+
", ",
|
|
21
|
+
)})`,
|
|
22
|
+
}),
|
|
23
|
+
),
|
|
24
|
+
),
|
|
25
|
+
...(settingsOperation ? [settingsOperation] : []),
|
|
26
|
+
];
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { hotUpdaterSchemaVersions } from "../../schema";
|
|
2
|
+
import type {
|
|
3
|
+
HotUpdaterColumnSchema,
|
|
4
|
+
HotUpdaterIndexSchema,
|
|
5
|
+
HotUpdaterTableSchema,
|
|
6
|
+
HotUpdaterVersionedSchema,
|
|
7
|
+
} from "../../schema/types";
|
|
8
|
+
import type { ORMProvider } from "../types";
|
|
9
|
+
|
|
10
|
+
export { hotUpdaterSchemaVersions } from "../../schema";
|
|
11
|
+
|
|
12
|
+
export const hotUpdaterSchema =
|
|
13
|
+
hotUpdaterSchemaVersions[hotUpdaterSchemaVersions.length - 1]!;
|
|
14
|
+
|
|
15
|
+
export const getSchemaVersionIndex = (version: string): number =>
|
|
16
|
+
hotUpdaterSchemaVersions.findIndex((schema) => schema.version === version);
|
|
17
|
+
|
|
18
|
+
export const getHotUpdaterSchemaVersion = (
|
|
19
|
+
version: string,
|
|
20
|
+
): HotUpdaterVersionedSchema => {
|
|
21
|
+
const schema = hotUpdaterSchemaVersions.find(
|
|
22
|
+
(item) => item.version === version,
|
|
23
|
+
);
|
|
24
|
+
if (!schema)
|
|
25
|
+
throw new Error(`Unsupported Hot Updater schema version: ${version}`);
|
|
26
|
+
return schema;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const getSchemaTable = (name: string): HotUpdaterTableSchema => {
|
|
30
|
+
const table = hotUpdaterSchema.tables.find((item) => item.ormName === name);
|
|
31
|
+
if (!table) throw new Error(`Unknown Hot Updater schema table: ${name}`);
|
|
32
|
+
return table;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const getSchemaColumn = (
|
|
36
|
+
table: HotUpdaterTableSchema,
|
|
37
|
+
name: string,
|
|
38
|
+
): HotUpdaterColumnSchema => {
|
|
39
|
+
const column = table.columns.find((item) => item.ormName === name);
|
|
40
|
+
if (!column) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`Unknown Hot Updater schema column: ${table.ormName}.${name}`,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
return column;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const hotUpdaterDataTables = hotUpdaterSchema.tables.filter(
|
|
49
|
+
(table) => !table.internal,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
export const schemaIndexAppliesToProvider = (
|
|
53
|
+
index: HotUpdaterIndexSchema,
|
|
54
|
+
provider: ORMProvider,
|
|
55
|
+
): boolean => !index.providers || index.providers.includes(provider);
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HOT_UPDATER_SETTINGS_TABLE,
|
|
3
|
+
type HotUpdaterCheckSchema,
|
|
4
|
+
type HotUpdaterColumnSchema,
|
|
5
|
+
type HotUpdaterColumnType,
|
|
6
|
+
type HotUpdaterForeignKeySchema,
|
|
7
|
+
type HotUpdaterTableSchema,
|
|
8
|
+
} from "../../schema/types";
|
|
9
|
+
import type {
|
|
10
|
+
MigrationOperation,
|
|
11
|
+
ORMSQLProvider,
|
|
12
|
+
RelationMode,
|
|
13
|
+
} from "../types";
|
|
14
|
+
import {
|
|
15
|
+
getSchemaColumn,
|
|
16
|
+
hotUpdaterDataTables,
|
|
17
|
+
hotUpdaterSchema,
|
|
18
|
+
schemaIndexAppliesToProvider,
|
|
19
|
+
} from "./registry";
|
|
20
|
+
|
|
21
|
+
export const hotUpdaterCreateTableOperations: MigrationOperation[] =
|
|
22
|
+
hotUpdaterDataTables.map((table) => ({
|
|
23
|
+
type: "create-table",
|
|
24
|
+
value: {
|
|
25
|
+
ormName: table.ormName,
|
|
26
|
+
columns: Object.fromEntries(
|
|
27
|
+
table.columns.map((column) => [
|
|
28
|
+
column.ormName,
|
|
29
|
+
{ ormName: column.ormName, type: column.type },
|
|
30
|
+
]),
|
|
31
|
+
),
|
|
32
|
+
},
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
export const getSqlType = (
|
|
36
|
+
type: HotUpdaterColumnType,
|
|
37
|
+
provider: ORMSQLProvider,
|
|
38
|
+
): string => {
|
|
39
|
+
if (provider === "sqlite") {
|
|
40
|
+
if (type === "bool" || type === "integer") return "integer";
|
|
41
|
+
return "text";
|
|
42
|
+
}
|
|
43
|
+
if (provider === "mysql") {
|
|
44
|
+
if (type === "uuid") return "char(36)";
|
|
45
|
+
if (type === "bool") return "boolean";
|
|
46
|
+
if (type === "integer") return "integer";
|
|
47
|
+
if (type === "json") return "json";
|
|
48
|
+
if (type.startsWith("varchar")) return type;
|
|
49
|
+
return "text";
|
|
50
|
+
}
|
|
51
|
+
if (type === "uuid") return "uuid";
|
|
52
|
+
if (type === "bool") return "boolean";
|
|
53
|
+
if (type === "integer") return "integer";
|
|
54
|
+
if (type === "json") return "json";
|
|
55
|
+
if (type.startsWith("varchar")) return type;
|
|
56
|
+
return "text";
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const sqlStringLiteral = (value: string): string =>
|
|
60
|
+
`'${value.replaceAll("'", "''")}'`;
|
|
61
|
+
|
|
62
|
+
const sqlDefaultClause = (
|
|
63
|
+
column: HotUpdaterColumnSchema,
|
|
64
|
+
provider: ORMSQLProvider,
|
|
65
|
+
): string => {
|
|
66
|
+
const value = column.default;
|
|
67
|
+
if (!value) return "";
|
|
68
|
+
if (
|
|
69
|
+
provider === "mysql" &&
|
|
70
|
+
(column.type === "json" || column.type === "string")
|
|
71
|
+
) {
|
|
72
|
+
return "";
|
|
73
|
+
}
|
|
74
|
+
if (value.type === "json") {
|
|
75
|
+
const json = sqlStringLiteral(JSON.stringify(value.value));
|
|
76
|
+
return provider === "postgresql" || provider === "cockroachdb"
|
|
77
|
+
? ` default ${json}::json`
|
|
78
|
+
: ` default ${json}`;
|
|
79
|
+
}
|
|
80
|
+
if (typeof value.value === "string") {
|
|
81
|
+
return ` default ${sqlStringLiteral(value.value)}`;
|
|
82
|
+
}
|
|
83
|
+
return ` default ${String(value.value)}`;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const sqlColumnName = (
|
|
87
|
+
table: HotUpdaterTableSchema,
|
|
88
|
+
column: HotUpdaterColumnSchema,
|
|
89
|
+
provider: ORMSQLProvider,
|
|
90
|
+
): string =>
|
|
91
|
+
table.ormName === HOT_UPDATER_SETTINGS_TABLE &&
|
|
92
|
+
column.ormName === "key" &&
|
|
93
|
+
provider === "mysql"
|
|
94
|
+
? "`key`"
|
|
95
|
+
: column.ormName;
|
|
96
|
+
|
|
97
|
+
export const sqlColumnDefinition = (
|
|
98
|
+
table: HotUpdaterTableSchema,
|
|
99
|
+
column: HotUpdaterColumnSchema,
|
|
100
|
+
provider: ORMSQLProvider,
|
|
101
|
+
): string => {
|
|
102
|
+
const constraints = [
|
|
103
|
+
column.primaryKey ? "primary key" : undefined,
|
|
104
|
+
column.nullable ? undefined : "not null",
|
|
105
|
+
].filter(Boolean);
|
|
106
|
+
return (
|
|
107
|
+
[
|
|
108
|
+
sqlColumnName(table, column, provider),
|
|
109
|
+
getSqlType(column.type, provider),
|
|
110
|
+
...constraints,
|
|
111
|
+
].join(" ") + sqlDefaultClause(column, provider)
|
|
112
|
+
);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const sqlIndexColumn = (
|
|
116
|
+
table: HotUpdaterTableSchema,
|
|
117
|
+
columnName: string,
|
|
118
|
+
provider: ORMSQLProvider,
|
|
119
|
+
): string => {
|
|
120
|
+
const column = getSchemaColumn(table, columnName);
|
|
121
|
+
return provider === "mysql" && column.type === "string"
|
|
122
|
+
? `${columnName}(255)`
|
|
123
|
+
: columnName;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export const createIndexSql = (
|
|
127
|
+
table: HotUpdaterTableSchema,
|
|
128
|
+
index: { readonly name: string; readonly columns: readonly string[] },
|
|
129
|
+
provider: ORMSQLProvider,
|
|
130
|
+
): string =>
|
|
131
|
+
`create index ${index.name} on ${table.ormName}(${index.columns
|
|
132
|
+
.map((column) => sqlIndexColumn(table, column, provider))
|
|
133
|
+
.join(", ")})`;
|
|
134
|
+
|
|
135
|
+
export const createForeignKeySql = (
|
|
136
|
+
table: HotUpdaterTableSchema,
|
|
137
|
+
foreignKey: HotUpdaterForeignKeySchema,
|
|
138
|
+
): string =>
|
|
139
|
+
`alter table ${table.ormName} add constraint ${foreignKey.name} foreign key (${foreignKey.columns.join(", ")}) references ${foreignKey.referencedTable}(${foreignKey.referencedColumns.join(", ")}) on update ${foreignKey.onUpdate} on delete ${foreignKey.onDelete}`;
|
|
140
|
+
|
|
141
|
+
export const createCheckSql = (
|
|
142
|
+
table: HotUpdaterTableSchema,
|
|
143
|
+
check: HotUpdaterCheckSchema,
|
|
144
|
+
): string =>
|
|
145
|
+
`alter table ${table.ormName} add constraint ${check.name} check (${check.expression})`;
|
|
146
|
+
|
|
147
|
+
const inlineSqlChecks = (
|
|
148
|
+
table: HotUpdaterTableSchema,
|
|
149
|
+
provider: ORMSQLProvider,
|
|
150
|
+
): string[] =>
|
|
151
|
+
provider === "sqlite"
|
|
152
|
+
? (table.checks ?? [])
|
|
153
|
+
.filter((check) => check.sqliteInline)
|
|
154
|
+
.map((check) => `constraint ${check.name} check (${check.expression})`)
|
|
155
|
+
: [];
|
|
156
|
+
|
|
157
|
+
export const createTableStatement = (
|
|
158
|
+
table: HotUpdaterTableSchema,
|
|
159
|
+
provider: ORMSQLProvider,
|
|
160
|
+
): string => {
|
|
161
|
+
const lines = [
|
|
162
|
+
...table.columns.map((column) =>
|
|
163
|
+
sqlColumnDefinition(table, column, provider),
|
|
164
|
+
),
|
|
165
|
+
...inlineSqlChecks(table, provider),
|
|
166
|
+
];
|
|
167
|
+
return `create table if not exists ${table.ormName} (\n${lines.join(",\n")}\n)`;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export const createForeignKeySqlStatements = (
|
|
171
|
+
provider: ORMSQLProvider,
|
|
172
|
+
relationMode: RelationMode = "foreign-keys",
|
|
173
|
+
): readonly string[] => {
|
|
174
|
+
if (relationMode !== "foreign-keys" || provider === "sqlite") return [];
|
|
175
|
+
return hotUpdaterSchema.tables.flatMap((table) =>
|
|
176
|
+
(table.foreignKeys ?? []).map((foreignKey) =>
|
|
177
|
+
createForeignKeySql(table, foreignKey),
|
|
178
|
+
),
|
|
179
|
+
);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export const createTableSql = (
|
|
183
|
+
provider: ORMSQLProvider,
|
|
184
|
+
relationMode: RelationMode = "foreign-keys",
|
|
185
|
+
): readonly string[] => [
|
|
186
|
+
...hotUpdaterSchema.tables.map((table) =>
|
|
187
|
+
createTableStatement(table, provider),
|
|
188
|
+
),
|
|
189
|
+
...hotUpdaterSchema.tables.flatMap((table) =>
|
|
190
|
+
(table.indexes ?? [])
|
|
191
|
+
.filter((index) => schemaIndexAppliesToProvider(index, provider))
|
|
192
|
+
.map((index) => createIndexSql(table, index, provider)),
|
|
193
|
+
),
|
|
194
|
+
...(provider === "sqlite"
|
|
195
|
+
? []
|
|
196
|
+
: hotUpdaterSchema.tables.flatMap((table) =>
|
|
197
|
+
(table.checks ?? []).map((check) => createCheckSql(table, check)),
|
|
198
|
+
)),
|
|
199
|
+
...createForeignKeySqlStatements(provider, relationMode),
|
|
200
|
+
];
|