@hot-updater/server 1.0.0-rc.1 → 1.0.0-rc.16
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 +1 -1
- package/dist/adapters/drizzle.cjs +35 -69
- package/dist/adapters/drizzle.d.cts +13 -6
- package/dist/adapters/drizzle.d.mts +13 -6
- package/dist/adapters/drizzle.mjs +34 -69
- package/dist/adapters/drizzleExecutor.cjs +114 -0
- package/dist/adapters/drizzleExecutor.d.cts +9 -0
- package/dist/adapters/drizzleExecutor.d.mts +9 -0
- package/dist/adapters/drizzleExecutor.mjs +112 -0
- package/dist/adapters/kysely.cjs +25 -31
- package/dist/adapters/kysely.d.cts +10 -7
- package/dist/adapters/kysely.d.mts +10 -7
- package/dist/adapters/kysely.mjs +25 -31
- package/dist/adapters/kyselyExecutor.cjs +32 -0
- package/dist/adapters/kyselyExecutor.d.cts +12 -0
- package/dist/adapters/kyselyExecutor.d.mts +12 -0
- package/dist/adapters/kyselyExecutor.mjs +32 -0
- package/dist/adapters/mongodb.cjs +28 -27
- package/dist/adapters/mongodb.d.cts +10 -5
- package/dist/adapters/mongodb.d.mts +10 -5
- package/dist/adapters/mongodb.mjs +28 -27
- package/dist/adapters/mongodbAdapter.cjs +174 -0
- package/dist/adapters/mongodbAdapter.d.cts +9 -0
- package/dist/adapters/mongodbAdapter.d.mts +9 -0
- package/dist/adapters/mongodbAdapter.mjs +173 -0
- package/dist/adapters/prisma.cjs +38 -220
- package/dist/adapters/prisma.d.cts +12 -8
- package/dist/adapters/prisma.d.mts +12 -8
- package/dist/adapters/prisma.mjs +38 -219
- package/dist/adapters/prismaExecutor.cjs +64 -0
- package/dist/adapters/prismaExecutor.mjs +64 -0
- package/dist/adapters/sqlProviders.cjs +9 -0
- package/dist/adapters/sqlProviders.mjs +9 -0
- package/dist/apiKeys.cjs +8 -8
- package/dist/apiKeys.d.cts +1 -24
- package/dist/apiKeys.d.mts +1 -24
- package/dist/apiKeys.mjs +5 -9
- package/dist/assembly/assemblePlugins.cjs +147 -0
- package/dist/assembly/assemblePlugins.d.cts +12 -0
- package/dist/assembly/assemblePlugins.d.mts +12 -0
- package/dist/assembly/assemblePlugins.mjs +146 -0
- package/dist/assembly/databasePlugins.cjs +23 -0
- package/dist/assembly/databasePlugins.d.cts +43 -0
- package/dist/assembly/databasePlugins.d.mts +43 -0
- package/dist/assembly/databasePlugins.mjs +22 -0
- package/dist/core/api.cjs +91 -0
- package/dist/core/api.d.cts +65 -0
- package/dist/core/api.d.mts +65 -0
- package/dist/core/api.mjs +87 -0
- package/dist/core/baseCandidates.cjs +71 -0
- package/dist/core/baseCandidates.d.cts +17 -0
- package/dist/core/baseCandidates.d.mts +17 -0
- package/dist/core/baseCandidates.mjs +69 -0
- package/dist/core/operations.cjs +350 -0
- package/dist/core/operations.mjs +350 -0
- package/dist/core/reads.cjs +273 -0
- package/dist/core/reads.d.cts +48 -0
- package/dist/core/reads.d.mts +48 -0
- package/dist/core/reads.mjs +267 -0
- package/dist/core/releases.cjs +193 -0
- package/dist/core/releases.mjs +190 -0
- package/dist/core/schema.cjs +279 -0
- package/dist/core/schema.d.cts +307 -0
- package/dist/core/schema.d.mts +307 -0
- package/dist/core/schema.mjs +277 -0
- package/dist/core/writes.cjs +96 -0
- package/dist/core/writes.mjs +91 -0
- package/dist/createHotUpdaterCore.cjs +61 -63
- package/dist/createHotUpdaterCore.d.cts +53 -45
- package/dist/createHotUpdaterCore.d.mts +53 -45
- package/dist/createHotUpdaterCore.mjs +61 -63
- package/dist/database/cursor.cjs +44 -0
- package/dist/database/cursor.d.cts +7 -0
- package/dist/database/cursor.d.mts +7 -0
- package/dist/database/cursor.mjs +40 -0
- package/dist/database/database.cjs +44 -0
- package/dist/database/database.d.cts +123 -0
- package/dist/database/database.d.mts +123 -0
- package/dist/database/database.mjs +44 -0
- package/dist/database/definitions.d.cts +68 -0
- package/dist/database/definitions.d.mts +68 -0
- package/dist/database/engine.cjs +37 -0
- package/dist/database/engine.d.cts +40 -0
- package/dist/database/engine.d.mts +40 -0
- package/dist/database/engine.mjs +37 -0
- package/dist/database/engineAggregates.cjs +115 -0
- package/dist/database/engineAggregates.mjs +112 -0
- package/dist/database/engineReads.cjs +180 -0
- package/dist/database/engineReads.d.cts +35 -0
- package/dist/database/engineReads.d.mts +35 -0
- package/dist/database/engineReads.mjs +179 -0
- package/dist/database/engineTransaction.cjs +403 -0
- package/dist/database/engineTransaction.d.cts +26 -0
- package/dist/database/engineTransaction.d.mts +26 -0
- package/dist/database/engineTransaction.mjs +402 -0
- package/dist/database/errors.cjs +27 -0
- package/dist/database/errors.d.cts +21 -0
- package/dist/database/errors.d.mts +21 -0
- package/dist/database/errors.mjs +24 -0
- package/dist/database/fence.cjs +124 -0
- package/dist/database/fence.d.cts +42 -0
- package/dist/database/fence.d.mts +42 -0
- package/dist/database/fence.mjs +116 -0
- package/dist/database/index.cjs +127 -0
- package/dist/database/index.d.cts +17 -0
- package/dist/database/index.d.mts +17 -0
- package/dist/database/index.mjs +15 -0
- package/dist/database/kv/kvAdapter.cjs +273 -0
- package/dist/database/kv/kvAdapter.d.cts +101 -0
- package/dist/database/kv/kvAdapter.d.mts +101 -0
- package/dist/database/kv/kvAdapter.mjs +272 -0
- package/dist/database/resolveSchema.cjs +196 -0
- package/dist/database/resolveSchema.d.cts +42 -0
- package/dist/database/resolveSchema.d.mts +42 -0
- package/dist/database/resolveSchema.mjs +193 -0
- package/dist/database/schema.cjs +21 -0
- package/dist/database/schema.d.cts +61 -0
- package/dist/database/schema.d.mts +61 -0
- package/dist/database/schema.mjs +20 -0
- package/dist/database/sql/sqlAdapter.cjs +282 -0
- package/dist/database/sql/sqlAdapter.d.cts +46 -0
- package/dist/database/sql/sqlAdapter.d.mts +46 -0
- package/dist/database/sql/sqlAdapter.mjs +279 -0
- package/dist/database/sql/sqlSchema.cjs +115 -0
- package/dist/database/sql/sqlSchema.d.cts +8 -0
- package/dist/database/sql/sqlSchema.d.mts +8 -0
- package/dist/database/sql/sqlSchema.mjs +111 -0
- package/dist/db/builtInDatabase.cjs +104 -0
- package/dist/db/builtInDatabase.d.cts +38 -0
- package/dist/db/builtInDatabase.d.mts +38 -0
- package/dist/db/builtInDatabase.mjs +97 -0
- package/dist/db/createBundleDiff.cjs +6 -6
- package/dist/db/createBundleDiff.d.cts +4 -7
- package/dist/db/createBundleDiff.d.mts +4 -7
- package/dist/db/createBundleDiff.mjs +5 -5
- package/dist/db/engineDrizzleSchema.cjs +54 -0
- package/dist/db/engineDrizzleSchema.mjs +54 -0
- package/dist/db/engineMigrator.cjs +53 -0
- package/dist/db/engineMigrator.mjs +53 -0
- package/dist/db/enginePrismaSchema.cjs +85 -0
- package/dist/db/enginePrismaSchema.d.cts +5 -0
- package/dist/db/enginePrismaSchema.d.mts +5 -0
- package/dist/db/enginePrismaSchema.mjs +84 -0
- package/dist/db/engineSql.cjs +26 -0
- package/dist/db/engineSql.d.cts +17 -0
- package/dist/db/engineSql.d.mts +17 -0
- package/dist/db/engineSql.mjs +25 -0
- package/dist/db/engineSqlMigrator.cjs +66 -0
- package/dist/db/engineSqlMigrator.mjs +66 -0
- package/dist/db/fixedMigratorShared.cjs +0 -11
- package/dist/db/fixedMigratorShared.mjs +1 -8
- package/dist/db/index.cjs +23 -8
- package/dist/db/index.d.cts +10 -4
- package/dist/db/index.d.mts +10 -4
- package/dist/db/index.mjs +16 -8
- package/dist/db/releaseCatalog.cjs +20 -44
- package/dist/db/releaseCatalog.d.cts +2 -3
- package/dist/db/releaseCatalog.d.mts +2 -3
- package/dist/db/releaseCatalog.mjs +20 -44
- package/dist/db/schemaSettings.cjs +63 -0
- package/dist/db/schemaSettings.d.cts +12 -0
- package/dist/db/schemaSettings.d.mts +12 -0
- package/dist/db/schemaSettings.mjs +62 -0
- package/dist/db/settingsMigrator.cjs +92 -0
- package/dist/db/settingsMigrator.mjs +89 -0
- package/dist/db/types.cjs +3 -12
- package/dist/db/types.d.cts +26 -69
- package/dist/db/types.d.mts +26 -69
- package/dist/db/types.mjs +2 -11
- package/dist/db/updateArtifacts.cjs +38 -68
- package/dist/db/updateArtifacts.mjs +40 -69
- package/dist/handler.cjs +72 -43
- package/dist/handler.d.cts +3 -6
- package/dist/handler.d.mts +3 -6
- package/dist/handler.mjs +73 -43
- package/dist/handlerAdminRoutes.cjs +375 -0
- package/dist/handlerAdminRoutes.mjs +373 -0
- package/dist/handlerParameters.cjs +6 -11
- package/dist/handlerParameters.mjs +6 -10
- package/dist/handlerReleaseCatalogRoutes.cjs +11 -14
- package/dist/handlerReleaseCatalogRoutes.mjs +11 -13
- package/dist/handlerTypes.d.cts +2 -56
- package/dist/handlerTypes.d.mts +2 -56
- package/dist/handlerVersionRoutes.cjs +20 -4
- package/dist/handlerVersionRoutes.d.cts +1 -0
- package/dist/handlerVersionRoutes.d.mts +1 -0
- package/dist/handlerVersionRoutes.mjs +20 -4
- package/dist/index.cjs +4 -7
- package/dist/index.d.cts +10 -9
- package/dist/index.d.mts +10 -9
- package/dist/index.mjs +4 -4
- package/dist/insights/domain.d.cts +53 -70
- package/dist/insights/domain.d.mts +53 -70
- package/dist/insights/errors.cjs +35 -8
- package/dist/insights/errors.mjs +35 -8
- package/dist/insights/eventInput.cjs +64 -24
- package/dist/insights/eventInput.mjs +63 -25
- package/dist/insights/provider.cjs +356 -0
- package/dist/insights/provider.d.cts +6 -0
- package/dist/insights/provider.d.mts +6 -0
- package/dist/insights/provider.mjs +355 -0
- package/dist/insights/queryInput.cjs +78 -43
- package/dist/insights/queryInput.mjs +76 -40
- package/dist/insights/routes.cjs +94 -34
- package/dist/insights/routes.mjs +93 -35
- package/dist/insights/types.d.cts +27 -12
- package/dist/insights/types.d.mts +27 -12
- package/dist/node.d.cts +1 -2
- package/dist/node.d.mts +1 -2
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugins/api-keys/index.cjs +50 -0
- package/dist/plugins/api-keys/index.d.cts +85 -0
- package/dist/plugins/api-keys/index.d.mts +85 -0
- package/dist/plugins/api-keys/index.mjs +47 -0
- package/dist/plugins/api-keys/model.cjs +58 -0
- package/dist/plugins/api-keys/model.d.cts +8 -0
- package/dist/plugins/api-keys/model.d.mts +8 -0
- package/dist/plugins/api-keys/model.mjs +58 -0
- package/dist/plugins/api-keys/schema.cjs +38 -0
- package/dist/plugins/api-keys/schema.d.cts +44 -0
- package/dist/plugins/api-keys/schema.d.mts +44 -0
- package/dist/plugins/api-keys/schema.mjs +39 -0
- package/dist/plugins/builtIn.cjs +7 -0
- package/dist/plugins/builtIn.mjs +6 -0
- package/dist/plugins/definePlugin.cjs +5 -0
- package/dist/plugins/definePlugin.d.cts +73 -0
- package/dist/plugins/definePlugin.d.mts +73 -0
- package/dist/plugins/definePlugin.mjs +5 -0
- package/dist/plugins/index.cjs +17 -0
- package/dist/plugins/index.d.cts +9 -0
- package/dist/plugins/index.d.mts +9 -0
- package/dist/plugins/index.mjs +7 -0
- package/dist/plugins/insights/index.cjs +48 -0
- package/dist/plugins/insights/index.d.cts +295 -0
- package/dist/plugins/insights/index.d.mts +295 -0
- package/dist/plugins/insights/index.mjs +44 -0
- package/dist/plugins/insights/model.cjs +17 -0
- package/dist/plugins/insights/model.d.cts +10 -0
- package/dist/plugins/insights/model.d.mts +10 -0
- package/dist/plugins/insights/model.mjs +17 -0
- package/dist/plugins/insights/reads.cjs +471 -0
- package/dist/plugins/insights/reads.mjs +466 -0
- package/dist/plugins/insights/recordEvent.cjs +135 -0
- package/dist/plugins/insights/recordEvent.d.cts +13 -0
- package/dist/plugins/insights/recordEvent.d.mts +13 -0
- package/dist/plugins/insights/recordEvent.mjs +132 -0
- package/dist/plugins/insights/schema.cjs +347 -0
- package/dist/plugins/insights/schema.d.cts +258 -0
- package/dist/plugins/insights/schema.d.mts +258 -0
- package/dist/plugins/insights/schema.mjs +344 -0
- package/dist/storageAccess.cjs +0 -1
- package/dist/types/index.d.cts +2 -29
- package/dist/types/index.d.mts +2 -29
- package/package.json +30 -7
- package/src/adapters/drizzle.conformance.integration.spec.ts +34 -0
- package/src/adapters/drizzle.readBudgets.integration.spec.ts +41 -0
- package/src/adapters/drizzle.spec.ts +277 -208
- package/src/adapters/drizzle.ts +48 -128
- package/src/adapters/drizzleExecutor.ts +166 -0
- package/src/adapters/kysely.conformance.integration.spec.ts +36 -0
- package/src/adapters/kysely.readBudgets.integration.spec.ts +42 -0
- package/src/adapters/kysely.spec.ts +212 -117
- package/src/adapters/kysely.ts +32 -87
- package/src/adapters/kyselyExecutor.ts +53 -0
- package/src/adapters/mongodb.integration.spec.ts +180 -0
- package/src/adapters/mongodb.readBudgets.integration.spec.ts +61 -0
- package/src/adapters/mongodb.ts +36 -65
- package/src/adapters/mongodbAdapter.ts +293 -0
- package/src/adapters/prisma.conformance.integration.spec.ts +36 -0
- package/src/adapters/prisma.integration.spec.ts +138 -0
- package/src/adapters/prisma.readBudgets.integration.spec.ts +40 -0
- package/src/adapters/prisma.spec.ts +226 -173
- package/src/adapters/prisma.ts +60 -451
- package/src/adapters/prismaExecutor.ts +107 -0
- package/src/adapters/prismaTestClients.ts +175 -0
- package/src/adapters/sqlProviders.ts +14 -0
- package/src/apiKeys.integration.spec.ts +19 -119
- package/src/apiKeys.spec.ts +39 -35
- package/src/apiKeys.ts +2 -8
- package/src/assembly/assemblePlugins.ts +269 -0
- package/src/assembly/assembly.spec.ts +325 -0
- package/src/assembly/assembly.types.spec.ts +155 -0
- package/src/assembly/builtInRoutes.spec.ts +213 -0
- package/src/assembly/databasePlugins.spec.ts +71 -0
- package/src/assembly/databasePlugins.ts +96 -0
- package/src/core/api.ts +139 -0
- package/src/core/baseCandidates.spec.ts +378 -0
- package/src/core/baseCandidates.ts +136 -0
- package/src/core/index.ts +44 -0
- package/src/core/operations.spec.ts +415 -0
- package/src/core/operations.ts +551 -0
- package/src/core/reads.spec.ts +300 -0
- package/src/core/reads.ts +417 -0
- package/src/core/releases.spec.ts +308 -0
- package/src/core/releases.ts +345 -0
- package/src/core/schema.ts +173 -0
- package/src/core/writes.ts +160 -0
- package/src/createHotUpdaterCore.ts +191 -167
- package/src/database/cursor.ts +65 -0
- package/src/database/database.ts +335 -0
- package/src/database/database.types.spec.ts +135 -0
- package/src/database/definitions.ts +72 -0
- package/src/database/engine.ts +62 -0
- package/src/database/engineAggregates.spec.ts +539 -0
- package/src/database/engineAggregates.ts +193 -0
- package/src/database/engineReads.spec.ts +219 -0
- package/src/database/engineReads.ts +302 -0
- package/src/database/engineTransaction.spec.ts +710 -0
- package/src/database/engineTransaction.ts +588 -0
- package/src/database/errors.ts +30 -0
- package/src/database/fence.spec.ts +223 -0
- package/src/database/fence.ts +171 -0
- package/src/database/index.ts +154 -0
- package/src/database/kv/kvAdapter.conformance.integration.spec.ts +17 -0
- package/src/database/kv/kvAdapter.readBudgets.integration.spec.ts +17 -0
- package/src/database/kv/kvAdapter.spec.ts +468 -0
- package/src/database/kv/kvAdapter.ts +450 -0
- package/src/database/kv/kvTestStore.ts +91 -0
- package/src/database/memory.readBudgets.integration.spec.ts +13 -0
- package/src/database/resolveSchema.spec.ts +230 -0
- package/src/database/resolveSchema.ts +372 -0
- package/src/database/schema.ts +169 -0
- package/src/database/schema.types.spec.ts +94 -0
- package/src/database/sql/docker-compose.yml +36 -0
- package/src/database/sql/sqlAdapter.integration.spec.ts +148 -0
- package/src/database/sql/sqlAdapter.readBudgets.integration.spec.ts +109 -0
- package/src/database/sql/sqlAdapter.spec.ts +255 -0
- package/src/database/sql/sqlAdapter.ts +532 -0
- package/src/database/sql/sqlSchema.ts +205 -0
- package/src/database/sql/sqlTestExecutors.ts +183 -0
- package/src/databaseTestSuite.spec.ts +39 -0
- package/src/db/builtInDatabase.ts +149 -0
- package/src/db/bundleRows.spec.ts +3 -3
- package/src/db/createBundleDiff.spec.ts +43 -29
- package/src/db/createBundleDiff.ts +13 -7
- package/src/db/engineDrizzleSchema.ts +72 -0
- package/src/db/engineMigrator.ts +105 -0
- package/src/db/enginePrismaSchema.ts +147 -0
- package/src/db/engineSql.spec.ts +129 -0
- package/src/db/engineSql.ts +48 -0
- package/src/db/engineSqlMigrator.ts +116 -0
- package/src/db/fixedMigratorShared.ts +1 -20
- package/src/db/index.spec.ts +116 -824
- package/src/db/index.ts +43 -14
- package/src/db/pluginTables.spec.ts +218 -0
- package/src/db/releaseCatalog.ts +48 -90
- package/src/db/schemaSettings.ts +104 -0
- package/src/db/settingsMigrator.spec.ts +65 -0
- package/src/db/settingsMigrator.ts +152 -0
- package/src/db/types.ts +25 -165
- package/src/db/updateArtifacts.spec.ts +170 -294
- package/src/db/updateArtifacts.ts +74 -142
- package/src/db/updateCheck.bench.ts +47 -0
- package/src/handler-standalone.integration.spec.ts +204 -412
- package/src/handler.spec.ts +134 -51
- package/src/handler.testFixtures.ts +14 -19
- package/src/handler.ts +163 -75
- package/src/handlerAdminRoutes.spec.ts +183 -0
- package/src/handlerAdminRoutes.ts +536 -0
- package/src/handlerAuth.integration.spec.ts +3 -3
- package/src/handlerManagement.spec.ts +136 -196
- package/src/handlerReleaseCatalogRoutes.ts +15 -17
- package/src/handlerTypes.ts +3 -80
- package/src/handlerVersionRoutes.ts +20 -7
- package/src/index.ts +7 -14
- package/src/insights/domain.ts +56 -77
- package/src/insights/errors.spec.ts +48 -0
- package/src/insights/errors.ts +50 -6
- package/src/insights/eventInput.ts +80 -27
- package/src/insights/insights.integration.spec.ts +525 -44
- package/src/insights/provider.spec.ts +574 -0
- package/src/insights/provider.ts +667 -0
- package/src/insights/queryInput.ts +113 -73
- package/src/insights/routes.ts +125 -69
- package/src/insights/types.ts +47 -36
- package/src/lintRules.spec.ts +76 -0
- package/src/plugins/api-keys/apiKeysPlugin.spec.ts +172 -0
- package/src/plugins/api-keys/index.ts +66 -0
- package/src/plugins/api-keys/model.ts +69 -0
- package/src/plugins/api-keys/schema.ts +22 -0
- package/src/plugins/builtIn.ts +5 -0
- package/src/plugins/definePlugin.ts +100 -0
- package/src/plugins/index.ts +55 -0
- package/src/plugins/insights/index.ts +86 -0
- package/src/plugins/insights/insightsRollout.integration.spec.ts +187 -0
- package/src/plugins/insights/model.spec.ts +66 -0
- package/src/plugins/insights/model.ts +19 -0
- package/src/plugins/insights/reads.spec.ts +725 -0
- package/src/plugins/insights/reads.ts +707 -0
- package/src/plugins/insights/recordEvent.spec.ts +443 -0
- package/src/plugins/insights/recordEvent.ts +238 -0
- package/src/plugins/insights/schema.ts +229 -0
- package/src/plugins/pluginTestHarness.spec.ts +56 -0
- package/src/readBudgets.testFixtures.ts +15 -0
- package/src/releaseCatalogRoutes.integration.spec.ts +47 -92
- package/src/runtime.spec.ts +91 -77
- package/src/runtime.testFixtures.ts +28 -44
- package/src/runtimeBundles.integration.spec.ts +112 -0
- package/src/testUtilsMutation.integration.spec.ts +215 -0
- package/src/testUtilsPackage.integration.spec.ts +176 -0
- package/src/types/index.ts +0 -32
- package/dist/adapters/databaseConstraintErrors.cjs +0 -23
- package/dist/adapters/databaseConstraintErrors.mjs +0 -21
- package/dist/adapters/databasePluginUtils.cjs +0 -117
- package/dist/adapters/databasePluginUtils.mjs +0 -106
- package/dist/adapters/drizzleCrud.cjs +0 -250
- package/dist/adapters/drizzleCrud.mjs +0 -249
- package/dist/adapters/drizzleLazyDB.cjs +0 -101
- package/dist/adapters/drizzleLazyDB.mjs +0 -101
- package/dist/adapters/drizzleQuery.cjs +0 -68
- package/dist/adapters/drizzleQuery.mjs +0 -67
- package/dist/adapters/kyselyCrud.cjs +0 -254
- package/dist/adapters/kyselyCrud.mjs +0 -253
- package/dist/adapters/kyselyQuery.cjs +0 -56
- package/dist/adapters/kyselyQuery.mjs +0 -55
- package/dist/adapters/mongodbCollections.cjs +0 -36
- package/dist/adapters/mongodbCollections.mjs +0 -30
- package/dist/adapters/mongodbQuery.cjs +0 -77
- package/dist/adapters/mongodbQuery.mjs +0 -70
- package/dist/adapters/mongodbReads.cjs +0 -148
- package/dist/adapters/mongodbReads.mjs +0 -147
- package/dist/adapters/mongodbWrites.cjs +0 -134
- package/dist/adapters/mongodbWrites.mjs +0 -133
- package/dist/adapters/prismaQuery.cjs +0 -58
- package/dist/adapters/prismaQuery.mjs +0 -56
- package/dist/adapters/prismaRows.cjs +0 -198
- package/dist/adapters/prismaRows.mjs +0 -188
- package/dist/db/databasePluginCore.cjs +0 -138
- package/dist/db/databasePluginCore.mjs +0 -137
- package/dist/db/fixedMigrator.cjs +0 -79
- package/dist/db/fixedMigrator.mjs +0 -78
- package/dist/db/fixedMigratorMongo.cjs +0 -319
- package/dist/db/fixedMigratorMongo.mjs +0 -319
- package/dist/db/mongoMigrationExecution.cjs +0 -11
- package/dist/db/mongoMigrationExecution.mjs +0 -11
- package/dist/db/schema/mongodb.cjs +0 -25
- package/dist/db/schema/mongodb.mjs +0 -25
- package/dist/db/schema/registry.cjs +0 -21
- package/dist/db/schema/registry.mjs +0 -17
- package/dist/db/schema/sql.cjs +0 -101
- package/dist/db/schema/sql.mjs +0 -97
- package/dist/db/schema/sqlOperations.cjs +0 -27
- package/dist/db/schema/sqlOperations.mjs +0 -26
- package/dist/db/schemaGenerators.cjs +0 -256
- package/dist/db/schemaGenerators.mjs +0 -254
- package/dist/db/schemaReadiness.cjs +0 -24
- package/dist/db/schemaReadiness.d.cts +0 -8
- package/dist/db/schemaReadiness.d.mts +0 -8
- package/dist/db/schemaReadiness.mjs +0 -23
- package/dist/db/sqlMigrationExecution.cjs +0 -67
- package/dist/db/sqlMigrationExecution.mjs +0 -66
- package/dist/handlerBundleRoutes.cjs +0 -155
- package/dist/handlerBundleRoutes.mjs +0 -155
- package/dist/handlerReleaseManagementRoutes.cjs +0 -125
- package/dist/handlerReleaseManagementRoutes.mjs +0 -124
- package/dist/insights/bounded/activeOverview.cjs +0 -87
- package/dist/insights/bounded/activeOverview.mjs +0 -85
- package/dist/insights/bounded/installationSearch.cjs +0 -42
- package/dist/insights/bounded/installationSearch.mjs +0 -42
- package/dist/insights/bounded/persistence.cjs +0 -39
- package/dist/insights/bounded/persistence.mjs +0 -38
- package/dist/insights/bounded/provider.cjs +0 -170
- package/dist/insights/bounded/provider.d.cts +0 -7
- package/dist/insights/bounded/provider.d.mts +0 -7
- package/dist/insights/bounded/provider.mjs +0 -170
- package/dist/insights/bounded/scan.cjs +0 -144
- package/dist/insights/bounded/scan.mjs +0 -138
- package/dist/insights/persistence.d.cts +0 -6
- package/dist/insights/persistence.d.mts +0 -6
- package/dist/schema/dsl.cjs +0 -103
- package/dist/schema/dsl.mjs +0 -87
- package/dist/schema/index.cjs +0 -6
- package/dist/schema/index.mjs +0 -7
- package/dist/schema/settings.cjs +0 -9
- package/dist/schema/settings.mjs +0 -9
- package/dist/schema/types.cjs +0 -8
- package/dist/schema/types.mjs +0 -6
- package/dist/schema/v1_0_0.cjs +0 -364
- package/dist/schema/v1_0_0.mjs +0 -357
- package/src/adapters/databaseConstraintErrors.ts +0 -25
- package/src/adapters/databasePluginTestDatabase.ts +0 -106
- package/src/adapters/databasePluginUtils.spec.ts +0 -29
- package/src/adapters/databasePluginUtils.ts +0 -214
- package/src/adapters/drizzleCrud.ts +0 -419
- package/src/adapters/drizzleLazyDB.ts +0 -257
- package/src/adapters/drizzleQuery.ts +0 -164
- package/src/adapters/kyselyCrud.ts +0 -588
- package/src/adapters/kyselyQuery.ts +0 -128
- package/src/adapters/mongodb.spec.ts +0 -141
- package/src/adapters/mongodbCollections.ts +0 -62
- package/src/adapters/mongodbQuery.ts +0 -226
- package/src/adapters/mongodbReads.ts +0 -311
- package/src/adapters/mongodbRows.spec.ts +0 -64
- package/src/adapters/mongodbRows.ts +0 -118
- package/src/adapters/mongodbTestClient.ts +0 -342
- package/src/adapters/mongodbTestFilter.ts +0 -166
- package/src/adapters/mongodbWrites.ts +0 -260
- package/src/adapters/prismaQuery.ts +0 -129
- package/src/adapters/prismaRows.spec.ts +0 -98
- package/src/adapters/prismaRows.ts +0 -301
- package/src/adapters/prismaTestClient.ts +0 -396
- package/src/calculatePagination.ts +0 -34
- package/src/db/databasePluginCore.spec.ts +0 -62
- package/src/db/databasePluginCore.testFixtures.ts +0 -76
- package/src/db/databasePluginCore.ts +0 -185
- package/src/db/databasePluginUpdateCheck.bench.ts +0 -107
- package/src/db/fixedMigrator.spec.ts +0 -231
- package/src/db/fixedMigrator.ts +0 -147
- package/src/db/fixedMigratorMongo.spec.ts +0 -192
- package/src/db/fixedMigratorMongo.ts +0 -425
- package/src/db/hotUpdaterSchema.ts +0 -5
- package/src/db/mongoMigrationExecution.ts +0 -23
- package/src/db/schema/definitions.ts +0 -1
- package/src/db/schema/mongodb.ts +0 -40
- package/src/db/schema/registry.ts +0 -55
- package/src/db/schema/sql.ts +0 -241
- package/src/db/schema/sqlOperations.ts +0 -63
- package/src/db/schema/types.ts +0 -1
- package/src/db/schemaGenerators.ts +0 -466
- package/src/db/schemaReadiness.ts +0 -34
- package/src/db/sqlMigrationExecution.spec.ts +0 -65
- package/src/db/sqlMigrationExecution.ts +0 -108
- package/src/db/types.spec.ts +0 -55
- package/src/handlerBundleRoutes.ts +0 -259
- package/src/handlerReleaseManagementRoutes.ts +0 -213
- package/src/insights/bounded/activeOverview.spec.ts +0 -189
- package/src/insights/bounded/activeOverview.ts +0 -148
- package/src/insights/bounded/installationSearch.spec.ts +0 -130
- package/src/insights/bounded/installationSearch.ts +0 -69
- package/src/insights/bounded/persistence.ts +0 -43
- package/src/insights/bounded/provider.spec.ts +0 -219
- package/src/insights/bounded/provider.ts +0 -229
- package/src/insights/bounded/scan.ts +0 -235
- package/src/insights/persistence.ts +0 -10
- package/src/schema/dsl-all-versions.spec.ts +0 -35
- package/src/schema/dsl.ts +0 -187
- package/src/schema/index.ts +0 -10
- package/src/schema/settings.ts +0 -15
- package/src/schema/types.ts +0 -79
- package/src/schema/v1_0_0.spec.ts +0 -146
- package/src/schema/v1_0_0.ts +0 -465
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
let _hot_updater_plugin_core_internal = require("@hot-updater/plugin-core/internal");
|
|
2
|
+
//#region src/database/sql/sqlSchema.ts
|
|
3
|
+
/** Quotes an identifier: backticks on MySQL, double quotes elsewhere. */
|
|
4
|
+
const quoteSql = (dialect, name) => dialect === "mysql" ? `\`${name.replaceAll("`", "``")}\`` : `"${name.replaceAll("\"", "\"\"")}"`;
|
|
5
|
+
const isMultiIndex = (table, index) => index.eq.some((column) => (0, _hot_updater_plugin_core_internal.findPhysicalColumn)(table, column).multi);
|
|
6
|
+
/** Keeps an identifier within PostgreSQL's 63 and MySQL's 64 characters. */
|
|
7
|
+
const shortSqlName = (name) => {
|
|
8
|
+
if (name.length <= 60) return name;
|
|
9
|
+
let hash = 2166136261;
|
|
10
|
+
for (const char of name) hash = Math.imul(hash ^ char.charCodeAt(0), 16777619) >>> 0;
|
|
11
|
+
return `${name.slice(0, 51)}_${hash.toString(36)}`;
|
|
12
|
+
};
|
|
13
|
+
/** The column type; `entry` types one value of a multi-valued column in its index table. */
|
|
14
|
+
const columnType = (dialect, column, indexed, entry = false) => {
|
|
15
|
+
if (column.multi && !entry || column.type === "json") return {
|
|
16
|
+
postgresql: "jsonb",
|
|
17
|
+
mysql: "json",
|
|
18
|
+
sqlite: "TEXT"
|
|
19
|
+
}[dialect];
|
|
20
|
+
if (column.type === "string") {
|
|
21
|
+
const length = column.maxLength ?? (indexed ? 255 : void 0);
|
|
22
|
+
if (dialect === "sqlite") return "TEXT";
|
|
23
|
+
if (dialect === "postgresql") return `${column.maxLength ? `varchar(${column.maxLength})` : "text"} COLLATE "C"`;
|
|
24
|
+
const charset = column.ascii ? "ascii COLLATE ascii_bin" : "utf8mb4 COLLATE utf8mb4_0900_bin";
|
|
25
|
+
return `${length ? `varchar(${length})` : "longtext"} CHARACTER SET ${charset}`;
|
|
26
|
+
}
|
|
27
|
+
if (column.type === "integer") return dialect === "sqlite" ? "INTEGER" : "bigint";
|
|
28
|
+
if (column.type === "number") return {
|
|
29
|
+
postgresql: "double precision",
|
|
30
|
+
mysql: "double",
|
|
31
|
+
sqlite: "REAL"
|
|
32
|
+
}[dialect];
|
|
33
|
+
return dialect === "sqlite" ? "INTEGER" : "boolean";
|
|
34
|
+
};
|
|
35
|
+
/** InnoDB's limit on the bytes of one key or index. */
|
|
36
|
+
const MYSQL_KEY_BYTES = 3072;
|
|
37
|
+
/** Refuses a MySQL key or index over InnoDB's limit before any DDL runs. */
|
|
38
|
+
const checkMysqlKey = (table, name, columns) => {
|
|
39
|
+
const bytes = columns.reduce((sum, column) => {
|
|
40
|
+
const { type, maxLength, ascii } = (0, _hot_updater_plugin_core_internal.findPhysicalColumn)(table, column);
|
|
41
|
+
if (type === "string") return sum + (maxLength ?? 255) * (ascii ? 1 : 4);
|
|
42
|
+
return sum + (type === "boolean" ? 1 : 8);
|
|
43
|
+
}, 0);
|
|
44
|
+
if (bytes > MYSQL_KEY_BYTES) throw new _hot_updater_plugin_core_internal.DatabaseSchemaError(`${table.name} ${name} needs ${bytes} bytes on MySQL, over its ${MYSQL_KEY_BYTES}; shorten its strings or mark ASCII ones ascii.`);
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Each table as the DDL creates it, for the DDL below and for ORM schema
|
|
48
|
+
* generators: binary collation, one index per declared index, and an index
|
|
49
|
+
* table `<table>__<index>` for each index over a multi-valued field, keyed by
|
|
50
|
+
* every column it holds.
|
|
51
|
+
*/
|
|
52
|
+
const sqlTableShapes = (dialect, tables, tablePrefix = "") => tables.map((table) => {
|
|
53
|
+
const name = tablePrefix + table.name;
|
|
54
|
+
const indexed = /* @__PURE__ */ new Set([...table.key, ...table.indexes.flatMap(({ eq, sort }) => [...eq, ...sort])]);
|
|
55
|
+
if (dialect === "mysql") checkMysqlKey(table, "key", table.key);
|
|
56
|
+
const indexes = table.indexes.flatMap((index) => {
|
|
57
|
+
const columns = [...index.eq, ...(0, _hot_updater_plugin_core_internal.indexOrderColumns)(table, index)];
|
|
58
|
+
if (dialect === "mysql") checkMysqlKey(table, `index ${index.name}`, columns);
|
|
59
|
+
if (isMultiIndex(table, index)) {
|
|
60
|
+
const entries = columns.map((column) => ({
|
|
61
|
+
name: column,
|
|
62
|
+
type: columnType(dialect, (0, _hot_updater_plugin_core_internal.findPhysicalColumn)(table, column), true, true),
|
|
63
|
+
notNull: true
|
|
64
|
+
}));
|
|
65
|
+
return [{
|
|
66
|
+
kind: "table",
|
|
67
|
+
table: {
|
|
68
|
+
name: `${name}__${index.name}`,
|
|
69
|
+
columns: entries,
|
|
70
|
+
key: columns,
|
|
71
|
+
indexes: []
|
|
72
|
+
}
|
|
73
|
+
}];
|
|
74
|
+
}
|
|
75
|
+
if (!index.unique && columns.join() === table.key.join()) return [];
|
|
76
|
+
return [{
|
|
77
|
+
kind: "index",
|
|
78
|
+
name: shortSqlName(`${name}_${index.name}`),
|
|
79
|
+
unique: index.unique === true,
|
|
80
|
+
columns: index.unique ? index.eq : columns
|
|
81
|
+
}];
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
name,
|
|
85
|
+
columns: table.columns.map((column) => ({
|
|
86
|
+
name: column.name,
|
|
87
|
+
type: columnType(dialect, column, indexed.has(column.name)),
|
|
88
|
+
notNull: !column.nullable,
|
|
89
|
+
...column.default === void 0 ? {} : { default: column.default }
|
|
90
|
+
})),
|
|
91
|
+
key: table.key,
|
|
92
|
+
indexes
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
/** DDL for the tables' shapes: each table, then its indexes and index tables. */
|
|
96
|
+
const createTableStatements = (dialect, tables, tablePrefix = "") => {
|
|
97
|
+
const quote = (name) => quoteSql(dialect, name);
|
|
98
|
+
const list = (columns) => columns.map(quote).join(", ");
|
|
99
|
+
const render = (shape) => {
|
|
100
|
+
const definitions = shape.columns.map((column) => `${quote(column.name)} ${column.type}${column.notNull ? " NOT NULL" : ""}${column.default === void 0 ? "" : ` DEFAULT ${column.default}`}`);
|
|
101
|
+
definitions.push(`PRIMARY KEY (${list(shape.key)})`);
|
|
102
|
+
const after = [];
|
|
103
|
+
for (const index of shape.indexes) if (index.kind === "table") after.push(...render(index.table));
|
|
104
|
+
else if (dialect === "mysql") definitions.push(`${index.unique ? "UNIQUE " : ""}INDEX ${quote(index.name)} (${list(index.columns)})`);
|
|
105
|
+
else after.push(`CREATE ${index.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS ${quote(index.name)} ON ${quote(shape.name)} (${list(index.columns)})`);
|
|
106
|
+
return [`CREATE TABLE IF NOT EXISTS ${quote(shape.name)} (${definitions.join(", ")})`, ...after];
|
|
107
|
+
};
|
|
108
|
+
return sqlTableShapes(dialect, tables, tablePrefix).flatMap(render);
|
|
109
|
+
};
|
|
110
|
+
//#endregion
|
|
111
|
+
exports.createTableStatements = createTableStatements;
|
|
112
|
+
exports.isMultiIndex = isMultiIndex;
|
|
113
|
+
exports.quoteSql = quoteSql;
|
|
114
|
+
exports.shortSqlName = shortSqlName;
|
|
115
|
+
exports.sqlTableShapes = sqlTableShapes;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PhysicalIndex, PhysicalTable } from "@hot-updater/plugin-core/internal";
|
|
2
|
+
//#region src/database/sql/sqlSchema.d.ts
|
|
3
|
+
type SqlDialect = "postgresql" | "mysql" | "sqlite";
|
|
4
|
+
declare const isMultiIndex: (table: PhysicalTable, index: PhysicalIndex) => boolean;
|
|
5
|
+
/** DDL for the tables' shapes: each table, then its indexes and index tables. */
|
|
6
|
+
declare const createTableStatements: (dialect: SqlDialect, tables: readonly PhysicalTable[], tablePrefix?: string) => string[];
|
|
7
|
+
//#endregion
|
|
8
|
+
export { SqlDialect, createTableStatements, isMultiIndex };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PhysicalIndex, PhysicalTable } from "@hot-updater/plugin-core/internal";
|
|
2
|
+
//#region src/database/sql/sqlSchema.d.ts
|
|
3
|
+
type SqlDialect = "postgresql" | "mysql" | "sqlite";
|
|
4
|
+
declare const isMultiIndex: (table: PhysicalTable, index: PhysicalIndex) => boolean;
|
|
5
|
+
/** DDL for the tables' shapes: each table, then its indexes and index tables. */
|
|
6
|
+
declare const createTableStatements: (dialect: SqlDialect, tables: readonly PhysicalTable[], tablePrefix?: string) => string[];
|
|
7
|
+
//#endregion
|
|
8
|
+
export { SqlDialect, createTableStatements, isMultiIndex };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { DatabaseSchemaError, findPhysicalColumn, indexOrderColumns } from "@hot-updater/plugin-core/internal";
|
|
2
|
+
//#region src/database/sql/sqlSchema.ts
|
|
3
|
+
/** Quotes an identifier: backticks on MySQL, double quotes elsewhere. */
|
|
4
|
+
const quoteSql = (dialect, name) => dialect === "mysql" ? `\`${name.replaceAll("`", "``")}\`` : `"${name.replaceAll("\"", "\"\"")}"`;
|
|
5
|
+
const isMultiIndex = (table, index) => index.eq.some((column) => findPhysicalColumn(table, column).multi);
|
|
6
|
+
/** Keeps an identifier within PostgreSQL's 63 and MySQL's 64 characters. */
|
|
7
|
+
const shortSqlName = (name) => {
|
|
8
|
+
if (name.length <= 60) return name;
|
|
9
|
+
let hash = 2166136261;
|
|
10
|
+
for (const char of name) hash = Math.imul(hash ^ char.charCodeAt(0), 16777619) >>> 0;
|
|
11
|
+
return `${name.slice(0, 51)}_${hash.toString(36)}`;
|
|
12
|
+
};
|
|
13
|
+
/** The column type; `entry` types one value of a multi-valued column in its index table. */
|
|
14
|
+
const columnType = (dialect, column, indexed, entry = false) => {
|
|
15
|
+
if (column.multi && !entry || column.type === "json") return {
|
|
16
|
+
postgresql: "jsonb",
|
|
17
|
+
mysql: "json",
|
|
18
|
+
sqlite: "TEXT"
|
|
19
|
+
}[dialect];
|
|
20
|
+
if (column.type === "string") {
|
|
21
|
+
const length = column.maxLength ?? (indexed ? 255 : void 0);
|
|
22
|
+
if (dialect === "sqlite") return "TEXT";
|
|
23
|
+
if (dialect === "postgresql") return `${column.maxLength ? `varchar(${column.maxLength})` : "text"} COLLATE "C"`;
|
|
24
|
+
const charset = column.ascii ? "ascii COLLATE ascii_bin" : "utf8mb4 COLLATE utf8mb4_0900_bin";
|
|
25
|
+
return `${length ? `varchar(${length})` : "longtext"} CHARACTER SET ${charset}`;
|
|
26
|
+
}
|
|
27
|
+
if (column.type === "integer") return dialect === "sqlite" ? "INTEGER" : "bigint";
|
|
28
|
+
if (column.type === "number") return {
|
|
29
|
+
postgresql: "double precision",
|
|
30
|
+
mysql: "double",
|
|
31
|
+
sqlite: "REAL"
|
|
32
|
+
}[dialect];
|
|
33
|
+
return dialect === "sqlite" ? "INTEGER" : "boolean";
|
|
34
|
+
};
|
|
35
|
+
/** InnoDB's limit on the bytes of one key or index. */
|
|
36
|
+
const MYSQL_KEY_BYTES = 3072;
|
|
37
|
+
/** Refuses a MySQL key or index over InnoDB's limit before any DDL runs. */
|
|
38
|
+
const checkMysqlKey = (table, name, columns) => {
|
|
39
|
+
const bytes = columns.reduce((sum, column) => {
|
|
40
|
+
const { type, maxLength, ascii } = findPhysicalColumn(table, column);
|
|
41
|
+
if (type === "string") return sum + (maxLength ?? 255) * (ascii ? 1 : 4);
|
|
42
|
+
return sum + (type === "boolean" ? 1 : 8);
|
|
43
|
+
}, 0);
|
|
44
|
+
if (bytes > MYSQL_KEY_BYTES) throw new DatabaseSchemaError(`${table.name} ${name} needs ${bytes} bytes on MySQL, over its ${MYSQL_KEY_BYTES}; shorten its strings or mark ASCII ones ascii.`);
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Each table as the DDL creates it, for the DDL below and for ORM schema
|
|
48
|
+
* generators: binary collation, one index per declared index, and an index
|
|
49
|
+
* table `<table>__<index>` for each index over a multi-valued field, keyed by
|
|
50
|
+
* every column it holds.
|
|
51
|
+
*/
|
|
52
|
+
const sqlTableShapes = (dialect, tables, tablePrefix = "") => tables.map((table) => {
|
|
53
|
+
const name = tablePrefix + table.name;
|
|
54
|
+
const indexed = /* @__PURE__ */ new Set([...table.key, ...table.indexes.flatMap(({ eq, sort }) => [...eq, ...sort])]);
|
|
55
|
+
if (dialect === "mysql") checkMysqlKey(table, "key", table.key);
|
|
56
|
+
const indexes = table.indexes.flatMap((index) => {
|
|
57
|
+
const columns = [...index.eq, ...indexOrderColumns(table, index)];
|
|
58
|
+
if (dialect === "mysql") checkMysqlKey(table, `index ${index.name}`, columns);
|
|
59
|
+
if (isMultiIndex(table, index)) {
|
|
60
|
+
const entries = columns.map((column) => ({
|
|
61
|
+
name: column,
|
|
62
|
+
type: columnType(dialect, findPhysicalColumn(table, column), true, true),
|
|
63
|
+
notNull: true
|
|
64
|
+
}));
|
|
65
|
+
return [{
|
|
66
|
+
kind: "table",
|
|
67
|
+
table: {
|
|
68
|
+
name: `${name}__${index.name}`,
|
|
69
|
+
columns: entries,
|
|
70
|
+
key: columns,
|
|
71
|
+
indexes: []
|
|
72
|
+
}
|
|
73
|
+
}];
|
|
74
|
+
}
|
|
75
|
+
if (!index.unique && columns.join() === table.key.join()) return [];
|
|
76
|
+
return [{
|
|
77
|
+
kind: "index",
|
|
78
|
+
name: shortSqlName(`${name}_${index.name}`),
|
|
79
|
+
unique: index.unique === true,
|
|
80
|
+
columns: index.unique ? index.eq : columns
|
|
81
|
+
}];
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
name,
|
|
85
|
+
columns: table.columns.map((column) => ({
|
|
86
|
+
name: column.name,
|
|
87
|
+
type: columnType(dialect, column, indexed.has(column.name)),
|
|
88
|
+
notNull: !column.nullable,
|
|
89
|
+
...column.default === void 0 ? {} : { default: column.default }
|
|
90
|
+
})),
|
|
91
|
+
key: table.key,
|
|
92
|
+
indexes
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
/** DDL for the tables' shapes: each table, then its indexes and index tables. */
|
|
96
|
+
const createTableStatements = (dialect, tables, tablePrefix = "") => {
|
|
97
|
+
const quote = (name) => quoteSql(dialect, name);
|
|
98
|
+
const list = (columns) => columns.map(quote).join(", ");
|
|
99
|
+
const render = (shape) => {
|
|
100
|
+
const definitions = shape.columns.map((column) => `${quote(column.name)} ${column.type}${column.notNull ? " NOT NULL" : ""}${column.default === void 0 ? "" : ` DEFAULT ${column.default}`}`);
|
|
101
|
+
definitions.push(`PRIMARY KEY (${list(shape.key)})`);
|
|
102
|
+
const after = [];
|
|
103
|
+
for (const index of shape.indexes) if (index.kind === "table") after.push(...render(index.table));
|
|
104
|
+
else if (dialect === "mysql") definitions.push(`${index.unique ? "UNIQUE " : ""}INDEX ${quote(index.name)} (${list(index.columns)})`);
|
|
105
|
+
else after.push(`CREATE ${index.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS ${quote(index.name)} ON ${quote(shape.name)} (${list(index.columns)})`);
|
|
106
|
+
return [`CREATE TABLE IF NOT EXISTS ${quote(shape.name)} (${definitions.join(", ")})`, ...after];
|
|
107
|
+
};
|
|
108
|
+
return sqlTableShapes(dialect, tables, tablePrefix).flatMap(render);
|
|
109
|
+
};
|
|
110
|
+
//#endregion
|
|
111
|
+
export { createTableStatements, isMultiIndex, quoteSql, shortSqlName, sqlTableShapes };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const require_resolveSchema = require("../database/resolveSchema.cjs");
|
|
2
|
+
const require_schema = require("../core/schema.cjs");
|
|
3
|
+
const require_fence = require("../database/fence.cjs");
|
|
4
|
+
const require_builtIn = require("../plugins/builtIn.cjs");
|
|
5
|
+
const require_schema$1 = require("../plugins/api-keys/schema.cjs");
|
|
6
|
+
const require_plugins_api_keys_index = require("../plugins/api-keys/index.cjs");
|
|
7
|
+
const require_schema$2 = require("../plugins/insights/schema.cjs");
|
|
8
|
+
const require_plugins_insights_index = require("../plugins/insights/index.cjs");
|
|
9
|
+
const require_schemaSettings = require("./schemaSettings.cjs");
|
|
10
|
+
const require_engineMigrator = require("./engineMigrator.cjs");
|
|
11
|
+
//#region src/db/builtInDatabase.ts
|
|
12
|
+
/** Core and the built-in plugins: their tables keep their names. */
|
|
13
|
+
const builtInModules = [
|
|
14
|
+
require_schema.coreModule,
|
|
15
|
+
{
|
|
16
|
+
id: "insights",
|
|
17
|
+
schema: require_schema$2.insightsSchema
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: "apiKeys",
|
|
21
|
+
schema: require_schema$1.apiKeysSchema
|
|
22
|
+
}
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* Core's tables and the built-in plugins' (Insights and API keys): the tables
|
|
26
|
+
* every provider's tooling creates, whichever plugins a server runs.
|
|
27
|
+
*/
|
|
28
|
+
const builtInSchema = require_resolveSchema.resolveSchema(builtInModules);
|
|
29
|
+
/** The settings rows a provider's database is fenced by. */
|
|
30
|
+
const builtInSettings = {
|
|
31
|
+
[require_fence.ENGINE_SCHEMA_KEY]: "1",
|
|
32
|
+
"schema.core": require_schema.HOT_UPDATER_SCHEMA_VERSION,
|
|
33
|
+
"schema.insights": require_plugins_insights_index.insights().schemaVersion,
|
|
34
|
+
"schema.apiKeys": require_plugins_api_keys_index.apiKeys().schemaVersion
|
|
35
|
+
};
|
|
36
|
+
/** Creates the built-in tables, then writes their settings rows. */
|
|
37
|
+
const migrateBuiltInSchema = (adapter, name) => require_schemaSettings.migrateSchema(adapter, name, builtInSchema.tables, builtInSettings);
|
|
38
|
+
/** What `hot-updater db` creates for a server without third-party plugins. */
|
|
39
|
+
const builtInTarget = {
|
|
40
|
+
schema: builtInSchema,
|
|
41
|
+
settings: builtInSettings
|
|
42
|
+
};
|
|
43
|
+
const addedPlugins = (plugins) => plugins.filter((plugin) => !(require_builtIn.builtInPlugin in plugin));
|
|
44
|
+
/** Each third-party plugin's `schema.<id>` settings row. */
|
|
45
|
+
const addedSettings = (plugins) => Object.fromEntries(addedPlugins(plugins).map(({ id, schemaVersion }) => [`schema.${id}`, schemaVersion]));
|
|
46
|
+
/**
|
|
47
|
+
* What `hot-updater db` creates for a server's plugins: the built-in tables,
|
|
48
|
+
* then each third-party plugin's tables with its `schema.<id>` settings row.
|
|
49
|
+
*/
|
|
50
|
+
const toolingTargetOf = (plugins) => {
|
|
51
|
+
const settings = addedSettings(plugins);
|
|
52
|
+
if (Object.keys(settings).length === 0) return builtInTarget;
|
|
53
|
+
return {
|
|
54
|
+
schema: require_resolveSchema.resolveSchema([...builtInModules, ...addedPlugins(plugins).map(({ id, schema }) => ({
|
|
55
|
+
id,
|
|
56
|
+
schema,
|
|
57
|
+
namespace: id
|
|
58
|
+
}))]),
|
|
59
|
+
settings: {
|
|
60
|
+
...builtInSettings,
|
|
61
|
+
...settings
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* A provider's database on the storage engine: its adapter behind the schema
|
|
67
|
+
* fence, which checks the built-in settings rows before the first read or
|
|
68
|
+
* write and names `hot-updater db migrate` when they are missing or stale.
|
|
69
|
+
* When the adapter creates its own tables, `hot-updater db migrate` creates
|
|
70
|
+
* the built-in tables and the server's plugin tables, then writes their
|
|
71
|
+
* settings rows.
|
|
72
|
+
*/
|
|
73
|
+
const createEngineDatabase = ({ name, adapter, onCachedRoutesChange }) => {
|
|
74
|
+
const fenced = require_fence.withSchemaFence(adapter, name, builtInSettings);
|
|
75
|
+
const createMigrator = ({ schema, settings } = builtInTarget) => require_engineMigrator.createEngineMigrator({
|
|
76
|
+
adapterName: name,
|
|
77
|
+
adapter,
|
|
78
|
+
schema,
|
|
79
|
+
settings,
|
|
80
|
+
readSettings: async () => {
|
|
81
|
+
const rows = await require_fence.readSettings(adapter, Object.keys(settings)).catch((error) => {
|
|
82
|
+
if (require_fence.isMissingSchemaError(error)) return [];
|
|
83
|
+
throw error;
|
|
84
|
+
});
|
|
85
|
+
return new Map(rows.flatMap((row) => row === null ? [] : [[String(row.key), row.value]]));
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
name,
|
|
90
|
+
adapter: fenced,
|
|
91
|
+
...onCachedRoutesChange === void 0 ? {} : { onCachedRoutesChange },
|
|
92
|
+
...adapter.dispose === void 0 ? {} : { dispose: () => adapter.dispose() },
|
|
93
|
+
...adapter.migrations === void 0 ? {} : { createMigrator }
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
//#endregion
|
|
97
|
+
exports.addedSettings = addedSettings;
|
|
98
|
+
exports.builtInModules = builtInModules;
|
|
99
|
+
exports.builtInSchema = builtInSchema;
|
|
100
|
+
exports.builtInSettings = builtInSettings;
|
|
101
|
+
exports.builtInTarget = builtInTarget;
|
|
102
|
+
exports.createEngineDatabase = createEngineDatabase;
|
|
103
|
+
exports.migrateBuiltInSchema = migrateBuiltInSchema;
|
|
104
|
+
exports.toolingTargetOf = toolingTargetOf;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SchemaSettings } from "../database/fence.cjs";
|
|
2
|
+
import { ResolvedSchema } from "../database/resolveSchema.cjs";
|
|
3
|
+
import { ToolingDatabase, ToolingTarget } from "./types.cjs";
|
|
4
|
+
import "../database/index.cjs";
|
|
5
|
+
import { DatabaseAdapter } from "@hot-updater/plugin-core/internal";
|
|
6
|
+
//#region src/db/builtInDatabase.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Core's tables and the built-in plugins' (Insights and API keys): the tables
|
|
9
|
+
* every provider's tooling creates, whichever plugins a server runs.
|
|
10
|
+
*/
|
|
11
|
+
declare const builtInSchema: ResolvedSchema;
|
|
12
|
+
/** The settings rows a provider's database is fenced by. */
|
|
13
|
+
declare const builtInSettings: SchemaSettings;
|
|
14
|
+
/** Creates the built-in tables, then writes their settings rows. */
|
|
15
|
+
declare const migrateBuiltInSchema: (adapter: DatabaseAdapter, name: string) => Promise<void>;
|
|
16
|
+
/** What `hot-updater db` creates for a server without third-party plugins. */
|
|
17
|
+
declare const builtInTarget: ToolingTarget;
|
|
18
|
+
interface EngineDatabaseOptions {
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly adapter: DatabaseAdapter;
|
|
21
|
+
/**
|
|
22
|
+
* Purges a CDN's copies of the cacheable client routes. Core calls it after
|
|
23
|
+
* a committed write that changes what those routes answer, since only core
|
|
24
|
+
* knows which of its tables they read.
|
|
25
|
+
*/
|
|
26
|
+
readonly onCachedRoutesChange?: () => Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A provider's database on the storage engine: its adapter behind the schema
|
|
30
|
+
* fence, which checks the built-in settings rows before the first read or
|
|
31
|
+
* write and names `hot-updater db migrate` when they are missing or stale.
|
|
32
|
+
* When the adapter creates its own tables, `hot-updater db migrate` creates
|
|
33
|
+
* the built-in tables and the server's plugin tables, then writes their
|
|
34
|
+
* settings rows.
|
|
35
|
+
*/
|
|
36
|
+
declare const createEngineDatabase: ({ name, adapter, onCachedRoutesChange }: EngineDatabaseOptions) => ToolingDatabase;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { EngineDatabaseOptions, builtInSchema, builtInSettings, builtInTarget, createEngineDatabase, migrateBuiltInSchema };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SchemaSettings } from "../database/fence.mjs";
|
|
2
|
+
import { ResolvedSchema } from "../database/resolveSchema.mjs";
|
|
3
|
+
import { ToolingDatabase, ToolingTarget } from "./types.mjs";
|
|
4
|
+
import "../database/index.mjs";
|
|
5
|
+
import { DatabaseAdapter } from "@hot-updater/plugin-core/internal";
|
|
6
|
+
//#region src/db/builtInDatabase.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Core's tables and the built-in plugins' (Insights and API keys): the tables
|
|
9
|
+
* every provider's tooling creates, whichever plugins a server runs.
|
|
10
|
+
*/
|
|
11
|
+
declare const builtInSchema: ResolvedSchema;
|
|
12
|
+
/** The settings rows a provider's database is fenced by. */
|
|
13
|
+
declare const builtInSettings: SchemaSettings;
|
|
14
|
+
/** Creates the built-in tables, then writes their settings rows. */
|
|
15
|
+
declare const migrateBuiltInSchema: (adapter: DatabaseAdapter, name: string) => Promise<void>;
|
|
16
|
+
/** What `hot-updater db` creates for a server without third-party plugins. */
|
|
17
|
+
declare const builtInTarget: ToolingTarget;
|
|
18
|
+
interface EngineDatabaseOptions {
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly adapter: DatabaseAdapter;
|
|
21
|
+
/**
|
|
22
|
+
* Purges a CDN's copies of the cacheable client routes. Core calls it after
|
|
23
|
+
* a committed write that changes what those routes answer, since only core
|
|
24
|
+
* knows which of its tables they read.
|
|
25
|
+
*/
|
|
26
|
+
readonly onCachedRoutesChange?: () => Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A provider's database on the storage engine: its adapter behind the schema
|
|
30
|
+
* fence, which checks the built-in settings rows before the first read or
|
|
31
|
+
* write and names `hot-updater db migrate` when they are missing or stale.
|
|
32
|
+
* When the adapter creates its own tables, `hot-updater db migrate` creates
|
|
33
|
+
* the built-in tables and the server's plugin tables, then writes their
|
|
34
|
+
* settings rows.
|
|
35
|
+
*/
|
|
36
|
+
declare const createEngineDatabase: ({ name, adapter, onCachedRoutesChange }: EngineDatabaseOptions) => ToolingDatabase;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { EngineDatabaseOptions, builtInSchema, builtInSettings, builtInTarget, createEngineDatabase, migrateBuiltInSchema };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { resolveSchema } from "../database/resolveSchema.mjs";
|
|
2
|
+
import { HOT_UPDATER_SCHEMA_VERSION, coreModule } from "../core/schema.mjs";
|
|
3
|
+
import { ENGINE_SCHEMA_KEY, isMissingSchemaError, readSettings, withSchemaFence } from "../database/fence.mjs";
|
|
4
|
+
import { builtInPlugin } from "../plugins/builtIn.mjs";
|
|
5
|
+
import { apiKeysSchema } from "../plugins/api-keys/schema.mjs";
|
|
6
|
+
import { apiKeys } from "../plugins/api-keys/index.mjs";
|
|
7
|
+
import { insightsSchema } from "../plugins/insights/schema.mjs";
|
|
8
|
+
import { insights } from "../plugins/insights/index.mjs";
|
|
9
|
+
import { migrateSchema } from "./schemaSettings.mjs";
|
|
10
|
+
import { createEngineMigrator } from "./engineMigrator.mjs";
|
|
11
|
+
//#region src/db/builtInDatabase.ts
|
|
12
|
+
/** Core and the built-in plugins: their tables keep their names. */
|
|
13
|
+
const builtInModules = [
|
|
14
|
+
coreModule,
|
|
15
|
+
{
|
|
16
|
+
id: "insights",
|
|
17
|
+
schema: insightsSchema
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: "apiKeys",
|
|
21
|
+
schema: apiKeysSchema
|
|
22
|
+
}
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* Core's tables and the built-in plugins' (Insights and API keys): the tables
|
|
26
|
+
* every provider's tooling creates, whichever plugins a server runs.
|
|
27
|
+
*/
|
|
28
|
+
const builtInSchema = resolveSchema(builtInModules);
|
|
29
|
+
/** The settings rows a provider's database is fenced by. */
|
|
30
|
+
const builtInSettings = {
|
|
31
|
+
[ENGINE_SCHEMA_KEY]: "1",
|
|
32
|
+
"schema.core": HOT_UPDATER_SCHEMA_VERSION,
|
|
33
|
+
"schema.insights": insights().schemaVersion,
|
|
34
|
+
"schema.apiKeys": apiKeys().schemaVersion
|
|
35
|
+
};
|
|
36
|
+
/** Creates the built-in tables, then writes their settings rows. */
|
|
37
|
+
const migrateBuiltInSchema = (adapter, name) => migrateSchema(adapter, name, builtInSchema.tables, builtInSettings);
|
|
38
|
+
/** What `hot-updater db` creates for a server without third-party plugins. */
|
|
39
|
+
const builtInTarget = {
|
|
40
|
+
schema: builtInSchema,
|
|
41
|
+
settings: builtInSettings
|
|
42
|
+
};
|
|
43
|
+
const addedPlugins = (plugins) => plugins.filter((plugin) => !(builtInPlugin in plugin));
|
|
44
|
+
/** Each third-party plugin's `schema.<id>` settings row. */
|
|
45
|
+
const addedSettings = (plugins) => Object.fromEntries(addedPlugins(plugins).map(({ id, schemaVersion }) => [`schema.${id}`, schemaVersion]));
|
|
46
|
+
/**
|
|
47
|
+
* What `hot-updater db` creates for a server's plugins: the built-in tables,
|
|
48
|
+
* then each third-party plugin's tables with its `schema.<id>` settings row.
|
|
49
|
+
*/
|
|
50
|
+
const toolingTargetOf = (plugins) => {
|
|
51
|
+
const settings = addedSettings(plugins);
|
|
52
|
+
if (Object.keys(settings).length === 0) return builtInTarget;
|
|
53
|
+
return {
|
|
54
|
+
schema: resolveSchema([...builtInModules, ...addedPlugins(plugins).map(({ id, schema }) => ({
|
|
55
|
+
id,
|
|
56
|
+
schema,
|
|
57
|
+
namespace: id
|
|
58
|
+
}))]),
|
|
59
|
+
settings: {
|
|
60
|
+
...builtInSettings,
|
|
61
|
+
...settings
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* A provider's database on the storage engine: its adapter behind the schema
|
|
67
|
+
* fence, which checks the built-in settings rows before the first read or
|
|
68
|
+
* write and names `hot-updater db migrate` when they are missing or stale.
|
|
69
|
+
* When the adapter creates its own tables, `hot-updater db migrate` creates
|
|
70
|
+
* the built-in tables and the server's plugin tables, then writes their
|
|
71
|
+
* settings rows.
|
|
72
|
+
*/
|
|
73
|
+
const createEngineDatabase = ({ name, adapter, onCachedRoutesChange }) => {
|
|
74
|
+
const fenced = withSchemaFence(adapter, name, builtInSettings);
|
|
75
|
+
const createMigrator = ({ schema, settings } = builtInTarget) => createEngineMigrator({
|
|
76
|
+
adapterName: name,
|
|
77
|
+
adapter,
|
|
78
|
+
schema,
|
|
79
|
+
settings,
|
|
80
|
+
readSettings: async () => {
|
|
81
|
+
const rows = await readSettings(adapter, Object.keys(settings)).catch((error) => {
|
|
82
|
+
if (isMissingSchemaError(error)) return [];
|
|
83
|
+
throw error;
|
|
84
|
+
});
|
|
85
|
+
return new Map(rows.flatMap((row) => row === null ? [] : [[String(row.key), row.value]]));
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
name,
|
|
90
|
+
adapter: fenced,
|
|
91
|
+
...onCachedRoutesChange === void 0 ? {} : { onCachedRoutesChange },
|
|
92
|
+
...adapter.dispose === void 0 ? {} : { dispose: () => adapter.dispose() },
|
|
93
|
+
...adapter.migrations === void 0 ? {} : { createMigrator }
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
//#endregion
|
|
97
|
+
export { addedSettings, builtInModules, builtInSchema, builtInSettings, builtInTarget, createEngineDatabase, migrateBuiltInSchema, toolingTargetOf };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_api = require("../core/api.cjs");
|
|
2
3
|
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
3
4
|
let _hot_updater_core = require("@hot-updater/core");
|
|
4
5
|
let node_crypto = require("node:crypto");
|
|
5
|
-
node_crypto = require_runtime.__toESM(node_crypto);
|
|
6
|
+
node_crypto = require_runtime.__toESM(node_crypto, 1);
|
|
6
7
|
let node_path = require("node:path");
|
|
7
|
-
node_path = require_runtime.__toESM(node_path);
|
|
8
|
+
node_path = require_runtime.__toESM(node_path, 1);
|
|
8
9
|
let node_util = require("node:util");
|
|
9
10
|
let node_zlib = require("node:zlib");
|
|
10
11
|
let _hot_updater_bsdiff = require("@hot-updater/bsdiff");
|
|
@@ -90,11 +91,10 @@ function buildNextPatchState({ currentBundle, nextPatch, makePrimary }) {
|
|
|
90
91
|
return makePrimary ? [nextPatch, ...existingPatches] : [...existingPatches, nextPatch];
|
|
91
92
|
}
|
|
92
93
|
async function createBundleDiff({ baseBundleId, bundleId }, deps, options = {}) {
|
|
93
|
-
const
|
|
94
|
+
const core = require_api.createDatabaseCoreApi(deps.database);
|
|
94
95
|
if (!deps.storagePlugin) throw new Error("Storage plugin is not configured");
|
|
95
96
|
if (baseBundleId === bundleId) throw new Error("Base bundle must be different from the target bundle");
|
|
96
|
-
const baseBundle = await
|
|
97
|
-
const targetBundle = await database.getBundleById(bundleId);
|
|
97
|
+
const [baseBundle, targetBundle] = (await Promise.all([core.getBundle(baseBundleId), core.getBundle(bundleId)])).map((detail) => detail === null ? null : (0, _hot_updater_plugin_core.rowToBundle)(detail.bundle, detail.patches));
|
|
98
98
|
if (!baseBundle || !targetBundle) throw new Error("Bundle not found");
|
|
99
99
|
if (baseBundle.platform !== targetBundle.platform) throw new Error("Base bundle platform must match the target bundle");
|
|
100
100
|
if (baseBundle.id.localeCompare(targetBundle.id) >= 0) throw new Error("Base bundle must be older than the target bundle");
|
|
@@ -136,7 +136,7 @@ async function createBundleDiff({ baseBundleId, bundleId }, deps, options = {})
|
|
|
136
136
|
...targetBundle,
|
|
137
137
|
patches
|
|
138
138
|
};
|
|
139
|
-
await
|
|
139
|
+
await core.updateBundle(targetBundle.id, { patches });
|
|
140
140
|
if (previousPatch?.patchStorageUri && previousPatch.patchStorageUri !== patchUpload.storageUri) await deps.storagePlugin.delete({ storageUri: previousPatch.patchStorageUri }).catch(() => {});
|
|
141
141
|
return updatedBundle;
|
|
142
142
|
}
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import { Bundle,
|
|
2
|
-
|
|
1
|
+
import { Bundle, ConfiguredDatabase, StoragePluginWith } from "@hot-updater/plugin-core";
|
|
3
2
|
//#region src/db/createBundleDiff.d.ts
|
|
4
3
|
interface CreateBundleDiffInput {
|
|
5
4
|
baseBundleId: string;
|
|
6
5
|
bundleId: string;
|
|
7
6
|
}
|
|
8
7
|
interface CreateBundleDiffDependencies {
|
|
9
|
-
|
|
8
|
+
/** The config's database: a provider's, or `standaloneRepository`. */
|
|
9
|
+
database: ConfiguredDatabase;
|
|
10
10
|
storagePlugin: StoragePluginWith<"get" | "put" | "delete"> | null;
|
|
11
11
|
}
|
|
12
12
|
interface CreateBundleDiffOptions {
|
|
13
13
|
makePrimary?: boolean;
|
|
14
14
|
}
|
|
15
|
-
declare function createBundleDiff({
|
|
16
|
-
baseBundleId,
|
|
17
|
-
bundleId
|
|
18
|
-
}: CreateBundleDiffInput, deps: CreateBundleDiffDependencies, options?: CreateBundleDiffOptions): Promise<Bundle>;
|
|
15
|
+
declare function createBundleDiff({ baseBundleId, bundleId }: CreateBundleDiffInput, deps: CreateBundleDiffDependencies, options?: CreateBundleDiffOptions): Promise<Bundle>;
|
|
19
16
|
//#endregion
|
|
20
17
|
export { CreateBundleDiffDependencies, CreateBundleDiffInput, CreateBundleDiffOptions, createBundleDiff };
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import { Bundle,
|
|
2
|
-
|
|
1
|
+
import { Bundle, ConfiguredDatabase, StoragePluginWith } from "@hot-updater/plugin-core";
|
|
3
2
|
//#region src/db/createBundleDiff.d.ts
|
|
4
3
|
interface CreateBundleDiffInput {
|
|
5
4
|
baseBundleId: string;
|
|
6
5
|
bundleId: string;
|
|
7
6
|
}
|
|
8
7
|
interface CreateBundleDiffDependencies {
|
|
9
|
-
|
|
8
|
+
/** The config's database: a provider's, or `standaloneRepository`. */
|
|
9
|
+
database: ConfiguredDatabase;
|
|
10
10
|
storagePlugin: StoragePluginWith<"get" | "put" | "delete"> | null;
|
|
11
11
|
}
|
|
12
12
|
interface CreateBundleDiffOptions {
|
|
13
13
|
makePrimary?: boolean;
|
|
14
14
|
}
|
|
15
|
-
declare function createBundleDiff({
|
|
16
|
-
baseBundleId,
|
|
17
|
-
bundleId
|
|
18
|
-
}: CreateBundleDiffInput, deps: CreateBundleDiffDependencies, options?: CreateBundleDiffOptions): Promise<Bundle>;
|
|
15
|
+
declare function createBundleDiff({ baseBundleId, bundleId }: CreateBundleDiffInput, deps: CreateBundleDiffDependencies, options?: CreateBundleDiffOptions): Promise<Bundle>;
|
|
19
16
|
//#endregion
|
|
20
17
|
export { CreateBundleDiffDependencies, CreateBundleDiffInput, CreateBundleDiffOptions, createBundleDiff };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createDatabaseCoreApi } from "../core/api.mjs";
|
|
2
|
+
import { createBundleStorageKey, getManifestAssetDownloadPath, resolveManifestAssetStorageUri, rowToBundle } from "@hot-updater/plugin-core";
|
|
2
3
|
import { getAssetBaseStorageUri, getBundlePatch, getBundlePatches, getManifestStorageUri } from "@hot-updater/core";
|
|
3
4
|
import crypto from "node:crypto";
|
|
4
5
|
import path from "node:path";
|
|
@@ -87,11 +88,10 @@ function buildNextPatchState({ currentBundle, nextPatch, makePrimary }) {
|
|
|
87
88
|
return makePrimary ? [nextPatch, ...existingPatches] : [...existingPatches, nextPatch];
|
|
88
89
|
}
|
|
89
90
|
async function createBundleDiff({ baseBundleId, bundleId }, deps, options = {}) {
|
|
90
|
-
const
|
|
91
|
+
const core = createDatabaseCoreApi(deps.database);
|
|
91
92
|
if (!deps.storagePlugin) throw new Error("Storage plugin is not configured");
|
|
92
93
|
if (baseBundleId === bundleId) throw new Error("Base bundle must be different from the target bundle");
|
|
93
|
-
const baseBundle = await
|
|
94
|
-
const targetBundle = await database.getBundleById(bundleId);
|
|
94
|
+
const [baseBundle, targetBundle] = (await Promise.all([core.getBundle(baseBundleId), core.getBundle(bundleId)])).map((detail) => detail === null ? null : rowToBundle(detail.bundle, detail.patches));
|
|
95
95
|
if (!baseBundle || !targetBundle) throw new Error("Bundle not found");
|
|
96
96
|
if (baseBundle.platform !== targetBundle.platform) throw new Error("Base bundle platform must match the target bundle");
|
|
97
97
|
if (baseBundle.id.localeCompare(targetBundle.id) >= 0) throw new Error("Base bundle must be older than the target bundle");
|
|
@@ -133,7 +133,7 @@ async function createBundleDiff({ baseBundleId, bundleId }, deps, options = {})
|
|
|
133
133
|
...targetBundle,
|
|
134
134
|
patches
|
|
135
135
|
};
|
|
136
|
-
await
|
|
136
|
+
await core.updateBundle(targetBundle.id, { patches });
|
|
137
137
|
if (previousPatch?.patchStorageUri && previousPatch.patchStorageUri !== patchUpload.storageUri) await deps.storagePlugin.delete({ storageUri: previousPatch.patchStorageUri }).catch(() => {});
|
|
138
138
|
return updatedBundle;
|
|
139
139
|
}
|