@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,48 @@
|
|
|
1
|
+
import "../database/engineReads.mjs";
|
|
2
|
+
import { HotUpdaterDatabase } from "../database/database.mjs";
|
|
3
|
+
import { ReleaseCatalogRequest } from "../db/releaseCatalog.mjs";
|
|
4
|
+
import { CoreSchema } from "./schema.mjs";
|
|
5
|
+
import { BundleDetail, BundlePatchRow, ChannelRow, KeysetInput, ReleaseCatalogRow, ReleaseFilter, ReleaseRow } from "@hot-updater/plugin-core";
|
|
6
|
+
import { ArtifactInfo, ReleaseCatalog } from "@hot-updater/core";
|
|
7
|
+
//#region src/core/reads.d.ts
|
|
8
|
+
type CoreDatabase = HotUpdaterDatabase<CoreSchema>;
|
|
9
|
+
interface CoreStorage {
|
|
10
|
+
readonly readStorageText?: (storageUri: string) => Promise<string | null>;
|
|
11
|
+
readonly resolveFileUrl: (storageUri: string | null) => Promise<string | null>;
|
|
12
|
+
}
|
|
13
|
+
/** Core's reads, each through one declared index or key. */
|
|
14
|
+
declare const createCoreReads: (db: CoreDatabase, storage: CoreStorage) => {
|
|
15
|
+
/** The update check: one point read of its scope's catalog. */
|
|
16
|
+
getReleaseCatalog(input: ReleaseCatalogRequest): Promise<ReleaseCatalog | null>;
|
|
17
|
+
/** Artifact resolution: one batch read of both bundles and one unique read of their patch. */
|
|
18
|
+
getArtifactInfo(targetBundleId: string, currentBundleId: string, artifactProtocolVersion: 1): Promise<ArtifactInfo | null>;
|
|
19
|
+
/** A bundle, its patches, and how many patches start from it. */
|
|
20
|
+
getBundle(id: string): Promise<BundleDetail | null>;
|
|
21
|
+
/** One page of the patches that start from a bundle, by target bundle id. */
|
|
22
|
+
/** Each base bundle's reference counter: one batch read of the bundle rows, and no patches. */
|
|
23
|
+
countBundleChildren(baseBundleIds: readonly string[]): Promise<Record<string, number>>;
|
|
24
|
+
listPatchesFromBase(baseBundleId: string, input: KeysetInput): Promise<BundlePatchRow[]>;
|
|
25
|
+
/** One page of bundles with their patches, oldest or newest first, optionally for one platform. */
|
|
26
|
+
listBundles(input: KeysetInput & {
|
|
27
|
+
readonly platform?: "ios" | "android";
|
|
28
|
+
}): Promise<BundleDetail[]>;
|
|
29
|
+
/** Bundles in total or for one platform: one counter row. */
|
|
30
|
+
countBundles(platform?: "ios" | "android"): Promise<number>;
|
|
31
|
+
/** Auto-patch bases for a new bundle: one point read of its scope's catalog. */
|
|
32
|
+
findBaseBundleIds(candidateKey: string, bundleId: string, limit: number): Promise<string[]>;
|
|
33
|
+
getRelease(id: string): Promise<ReleaseRow | null>;
|
|
34
|
+
/** One page of releases through the index its filter names. */
|
|
35
|
+
listReleases(input: KeysetInput & {
|
|
36
|
+
readonly filter: ReleaseFilter;
|
|
37
|
+
}): Promise<ReleaseRow[]>;
|
|
38
|
+
/** A scope's newest release id: `byScope` descending, limit 1. */
|
|
39
|
+
latestReleaseId(scopeKey: string): Promise<string | null>;
|
|
40
|
+
getReleaseCatalogRow(scopeKey: string): Promise<ReleaseCatalogRow | null>;
|
|
41
|
+
listReleaseCatalogs(input: KeysetInput): Promise<ReleaseCatalogRow[]>;
|
|
42
|
+
/** Every channel, by name. */
|
|
43
|
+
listChannels(): Promise<ChannelRow[]>;
|
|
44
|
+
findChannelByName(name: string): Promise<ChannelRow | null>;
|
|
45
|
+
};
|
|
46
|
+
type CoreReads = ReturnType<typeof createCoreReads>;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { type BundleDetail, CoreDatabase, CoreReads, CoreStorage, type KeysetInput, type ReleaseFilter, createCoreReads };
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { projectReleaseCatalogRow, releaseCatalogScopeKeyOf } from "../db/releaseCatalog.mjs";
|
|
2
|
+
import { resolveManifestArtifacts } from "../db/updateArtifacts.mjs";
|
|
3
|
+
import { baseBundleIdsOf, parseBaseCandidateKey } from "./baseCandidates.mjs";
|
|
4
|
+
import { rowToBundle } from "@hot-updater/plugin-core";
|
|
5
|
+
import { ARTIFACT_PROTOCOL_VERSION, NIL_UUID } from "@hot-updater/core";
|
|
6
|
+
//#region src/core/reads.ts
|
|
7
|
+
const PAGE = 500;
|
|
8
|
+
const pick = (fields) => (row) => Object.fromEntries(fields.map((field) => [field, row[field]]));
|
|
9
|
+
const toBundleRow = pick([
|
|
10
|
+
"id",
|
|
11
|
+
"platform",
|
|
12
|
+
"git_commit_hash",
|
|
13
|
+
"metadata",
|
|
14
|
+
"manifest_storage_uri",
|
|
15
|
+
"manifest_file_hash",
|
|
16
|
+
"asset_base_storage_uri"
|
|
17
|
+
]);
|
|
18
|
+
const toPatchRow = pick([
|
|
19
|
+
"id",
|
|
20
|
+
"bundle_id",
|
|
21
|
+
"base_bundle_id",
|
|
22
|
+
"base_file_hash",
|
|
23
|
+
"patch_file_hash",
|
|
24
|
+
"patch_storage_uri",
|
|
25
|
+
"byte_size",
|
|
26
|
+
"order_index"
|
|
27
|
+
]);
|
|
28
|
+
const toReleaseRow = pick([
|
|
29
|
+
"id",
|
|
30
|
+
"revision",
|
|
31
|
+
"scope_key",
|
|
32
|
+
"channel_id",
|
|
33
|
+
"platform",
|
|
34
|
+
"kind",
|
|
35
|
+
"bundle_id",
|
|
36
|
+
"strategy",
|
|
37
|
+
"target_app_version",
|
|
38
|
+
"fingerprint_hash",
|
|
39
|
+
"enabled",
|
|
40
|
+
"should_force_update",
|
|
41
|
+
"message",
|
|
42
|
+
"rollout_cohort_count",
|
|
43
|
+
"target_cohorts",
|
|
44
|
+
"operation",
|
|
45
|
+
"source_release_id",
|
|
46
|
+
"created_at_ms",
|
|
47
|
+
"updated_at_ms"
|
|
48
|
+
]);
|
|
49
|
+
const toCatalogRow = pick([
|
|
50
|
+
"scope_key",
|
|
51
|
+
"catalog_id",
|
|
52
|
+
"strategy",
|
|
53
|
+
"channel_id",
|
|
54
|
+
"channel_key",
|
|
55
|
+
"platform",
|
|
56
|
+
"fingerprint_hash",
|
|
57
|
+
"generation",
|
|
58
|
+
"payload",
|
|
59
|
+
"catalog_hash",
|
|
60
|
+
"byte_size",
|
|
61
|
+
"is_tombstone",
|
|
62
|
+
"updated_at_ms"
|
|
63
|
+
]);
|
|
64
|
+
const toChannelRow = pick(["id", "name"]);
|
|
65
|
+
/** Every page of one read, in order. */
|
|
66
|
+
const drain = async (read) => {
|
|
67
|
+
const rows = [];
|
|
68
|
+
let cursor;
|
|
69
|
+
do {
|
|
70
|
+
const page = await read(cursor === void 0 ? {} : { cursor });
|
|
71
|
+
rows.push(...page.rows);
|
|
72
|
+
cursor = page.next;
|
|
73
|
+
} while (cursor !== void 0);
|
|
74
|
+
return rows;
|
|
75
|
+
};
|
|
76
|
+
/** Core's reads, each through one declared index or key. */
|
|
77
|
+
const createCoreReads = (db, storage) => {
|
|
78
|
+
/** A bundle row's patches, exactly as many as its reference counter holds. */
|
|
79
|
+
const detail = async (row) => {
|
|
80
|
+
const count = row._refs_bundle_patches_bundle_id ?? 0;
|
|
81
|
+
const patches = [];
|
|
82
|
+
let cursor;
|
|
83
|
+
while (patches.length < count) {
|
|
84
|
+
const page = await db.findMany("bundle_patches", {
|
|
85
|
+
index: "byBundle",
|
|
86
|
+
where: { bundle_id: row.id },
|
|
87
|
+
limit: Math.min(count - patches.length, PAGE),
|
|
88
|
+
...cursor === void 0 ? {} : { cursor }
|
|
89
|
+
});
|
|
90
|
+
patches.push(...page.rows.map(toPatchRow));
|
|
91
|
+
if (page.next === void 0) break;
|
|
92
|
+
cursor = page.next;
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
bundle: toBundleRow(row),
|
|
96
|
+
patches,
|
|
97
|
+
childCount: row._refs_bundle_patches_base_bundle_id ?? 0
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
const after = (input) => input.after === void 0 ? {} : { range: (input.order ?? "asc") === "asc" ? { gt: input.after } : { lt: input.after } };
|
|
101
|
+
return {
|
|
102
|
+
/** The update check: one point read of its scope's catalog. */
|
|
103
|
+
async getReleaseCatalog(input) {
|
|
104
|
+
const scopeKey = releaseCatalogScopeKeyOf(input);
|
|
105
|
+
const row = await db.findOne("release_catalogs", { scope_key: scopeKey });
|
|
106
|
+
return projectReleaseCatalogRow(row === null ? null : toCatalogRow(row), input, scopeKey);
|
|
107
|
+
},
|
|
108
|
+
/** Artifact resolution: one batch read of both bundles and one unique read of their patch. */
|
|
109
|
+
async getArtifactInfo(targetBundleId, currentBundleId, artifactProtocolVersion) {
|
|
110
|
+
const { readStorageText } = storage;
|
|
111
|
+
if (artifactProtocolVersion !== ARTIFACT_PROTOCOL_VERSION || readStorageText === void 0) return null;
|
|
112
|
+
const withCurrent = currentBundleId !== NIL_UUID;
|
|
113
|
+
const [[target, current], patch] = await Promise.all([db.findByKeys("bundles", withCurrent ? [{ id: targetBundleId }, { id: currentBundleId }] : [{ id: targetBundleId }]), withCurrent ? db.findOne("bundle_patches", {
|
|
114
|
+
bundle_id: targetBundleId,
|
|
115
|
+
base_bundle_id: currentBundleId
|
|
116
|
+
}) : null]);
|
|
117
|
+
if (target === null || target === void 0) return null;
|
|
118
|
+
return resolveManifestArtifacts({
|
|
119
|
+
currentBundle: current ? rowToBundle(toBundleRow(current)) : null,
|
|
120
|
+
readStorageText,
|
|
121
|
+
resolveFileUrl: storage.resolveFileUrl,
|
|
122
|
+
targetBundle: rowToBundle(toBundleRow(target), patch === null ? [] : [toPatchRow(patch)])
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
/** A bundle, its patches, and how many patches start from it. */
|
|
126
|
+
async getBundle(id) {
|
|
127
|
+
const row = await db.findOne("bundles", { id });
|
|
128
|
+
return row === null ? null : detail(row);
|
|
129
|
+
},
|
|
130
|
+
/** One page of the patches that start from a bundle, by target bundle id. */
|
|
131
|
+
/** Each base bundle's reference counter: one batch read of the bundle rows, and no patches. */
|
|
132
|
+
async countBundleChildren(baseBundleIds) {
|
|
133
|
+
const ids = [...new Set(baseBundleIds)];
|
|
134
|
+
if (ids.length === 0) return {};
|
|
135
|
+
const rows = await db.findByKeys("bundles", ids.map((id) => ({ id })));
|
|
136
|
+
return Object.fromEntries(ids.map((id, position) => [id, rows[position]?._refs_bundle_patches_base_bundle_id ?? 0]));
|
|
137
|
+
},
|
|
138
|
+
async listPatchesFromBase(baseBundleId, input) {
|
|
139
|
+
return (await db.findMany("bundle_patches", {
|
|
140
|
+
index: "byBase",
|
|
141
|
+
where: { base_bundle_id: baseBundleId },
|
|
142
|
+
order: input.order ?? "asc",
|
|
143
|
+
limit: input.limit,
|
|
144
|
+
...after(input)
|
|
145
|
+
})).rows.map(toPatchRow);
|
|
146
|
+
},
|
|
147
|
+
/** One page of bundles with their patches, oldest or newest first, optionally for one platform. */
|
|
148
|
+
async listBundles(input) {
|
|
149
|
+
const page = input.platform === void 0 ? await db.findMany("bundles", {
|
|
150
|
+
index: "all",
|
|
151
|
+
where: {},
|
|
152
|
+
order: input.order ?? "asc",
|
|
153
|
+
limit: input.limit,
|
|
154
|
+
...after(input)
|
|
155
|
+
}) : await db.findMany("bundles", {
|
|
156
|
+
index: "byPlatform",
|
|
157
|
+
where: { platform: input.platform },
|
|
158
|
+
order: input.order ?? "asc",
|
|
159
|
+
limit: input.limit,
|
|
160
|
+
...after(input)
|
|
161
|
+
});
|
|
162
|
+
return Promise.all(page.rows.map(detail));
|
|
163
|
+
},
|
|
164
|
+
/** Bundles in total or for one platform: one counter row. */
|
|
165
|
+
async countBundles(platform) {
|
|
166
|
+
const { rows } = await db.findAggregates("bundle_totals", {
|
|
167
|
+
index: "byPlatform",
|
|
168
|
+
where: { platform_key: platform ?? "*" },
|
|
169
|
+
limit: 1
|
|
170
|
+
});
|
|
171
|
+
return rows[0]?.bundles ?? 0;
|
|
172
|
+
},
|
|
173
|
+
/** Auto-patch bases for a new bundle: one point read of its scope's catalog. */
|
|
174
|
+
async findBaseBundleIds(candidateKey, bundleId, limit) {
|
|
175
|
+
const query = parseBaseCandidateKey(candidateKey);
|
|
176
|
+
if (query === null) return [];
|
|
177
|
+
const row = await db.findOne("release_catalogs", { scope_key: query.scopeKey });
|
|
178
|
+
return row === null ? [] : baseBundleIdsOf(toCatalogRow(row), query.range, bundleId, limit);
|
|
179
|
+
},
|
|
180
|
+
async getRelease(id) {
|
|
181
|
+
const row = await db.findOne("releases", { id });
|
|
182
|
+
return row === null ? null : toReleaseRow(row);
|
|
183
|
+
},
|
|
184
|
+
/** One page of releases through the index its filter names. */
|
|
185
|
+
async listReleases(input) {
|
|
186
|
+
const { filter } = input;
|
|
187
|
+
const options = {
|
|
188
|
+
order: input.order ?? "asc",
|
|
189
|
+
limit: input.limit,
|
|
190
|
+
...after(input)
|
|
191
|
+
};
|
|
192
|
+
return (filter.kind === "all" ? await db.findMany("releases", {
|
|
193
|
+
index: "all",
|
|
194
|
+
where: {},
|
|
195
|
+
...options
|
|
196
|
+
}) : filter.kind === "bundle" ? await db.findMany("releases", {
|
|
197
|
+
index: "byBundle",
|
|
198
|
+
where: { bundle_id: filter.bundleId },
|
|
199
|
+
...options
|
|
200
|
+
}) : filter.kind === "scope" ? filter.enabled === void 0 ? await db.findMany("releases", {
|
|
201
|
+
index: "byScope",
|
|
202
|
+
where: { scope_key: filter.scopeKey },
|
|
203
|
+
...options
|
|
204
|
+
}) : await db.findMany("releases", {
|
|
205
|
+
index: "byScopeEnabled",
|
|
206
|
+
where: {
|
|
207
|
+
scope_key: filter.scopeKey,
|
|
208
|
+
enabled: filter.enabled
|
|
209
|
+
},
|
|
210
|
+
...options
|
|
211
|
+
}) : filter.enabled === void 0 ? await db.findMany("releases", {
|
|
212
|
+
index: "byChannelPlatform",
|
|
213
|
+
where: {
|
|
214
|
+
channel_id: filter.channelId,
|
|
215
|
+
platform: filter.platform
|
|
216
|
+
},
|
|
217
|
+
...options
|
|
218
|
+
}) : await db.findMany("releases", {
|
|
219
|
+
index: "byChannelPlatformEnabled",
|
|
220
|
+
where: {
|
|
221
|
+
channel_id: filter.channelId,
|
|
222
|
+
platform: filter.platform,
|
|
223
|
+
enabled: filter.enabled
|
|
224
|
+
},
|
|
225
|
+
...options
|
|
226
|
+
})).rows.map(toReleaseRow);
|
|
227
|
+
},
|
|
228
|
+
/** A scope's newest release id: `byScope` descending, limit 1. */
|
|
229
|
+
async latestReleaseId(scopeKey) {
|
|
230
|
+
const { rows } = await db.findMany("releases", {
|
|
231
|
+
index: "byScope",
|
|
232
|
+
where: { scope_key: scopeKey },
|
|
233
|
+
order: "desc",
|
|
234
|
+
limit: 1
|
|
235
|
+
});
|
|
236
|
+
return rows[0]?.id ?? null;
|
|
237
|
+
},
|
|
238
|
+
async getReleaseCatalogRow(scopeKey) {
|
|
239
|
+
const row = await db.findOne("release_catalogs", { scope_key: scopeKey });
|
|
240
|
+
return row === null ? null : toCatalogRow(row);
|
|
241
|
+
},
|
|
242
|
+
async listReleaseCatalogs(input) {
|
|
243
|
+
return (await db.findMany("release_catalogs", {
|
|
244
|
+
index: "all",
|
|
245
|
+
where: {},
|
|
246
|
+
order: input.order ?? "asc",
|
|
247
|
+
limit: input.limit,
|
|
248
|
+
...after(input)
|
|
249
|
+
})).rows.map(toCatalogRow);
|
|
250
|
+
},
|
|
251
|
+
/** Every channel, by name. */
|
|
252
|
+
async listChannels() {
|
|
253
|
+
return (await drain((page) => db.findMany("channels", {
|
|
254
|
+
index: "all",
|
|
255
|
+
where: {},
|
|
256
|
+
limit: PAGE,
|
|
257
|
+
...page
|
|
258
|
+
}))).map(toChannelRow);
|
|
259
|
+
},
|
|
260
|
+
async findChannelByName(name) {
|
|
261
|
+
const row = await db.findOne("channels", { name });
|
|
262
|
+
return row === null ? null : toChannelRow(row);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
//#endregion
|
|
267
|
+
export { createCoreReads, drain, toBundleRow, toCatalogRow, toChannelRow, toPatchRow, toReleaseRow };
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
const require_reads = require("./reads.cjs");
|
|
2
|
+
const require_writes = require("./writes.cjs");
|
|
3
|
+
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
4
|
+
let _hot_updater_core = require("@hot-updater/core");
|
|
5
|
+
//#region src/core/releases.ts
|
|
6
|
+
const PAGE = 500;
|
|
7
|
+
const fail = (code, message) => {
|
|
8
|
+
throw new _hot_updater_plugin_core.ReleaseCatalogMutationError(code, message);
|
|
9
|
+
};
|
|
10
|
+
const checkScope = (scope) => {
|
|
11
|
+
const channelKey = (0, _hot_updater_core.encodeChannelKey)(scope.channelName);
|
|
12
|
+
const expected = scope.strategy === "APP_VERSION" ? (0, _hot_updater_core.createReleaseCatalogScopeKey)({
|
|
13
|
+
channelKey,
|
|
14
|
+
platform: scope.platform,
|
|
15
|
+
strategy: "APP_VERSION"
|
|
16
|
+
}) : (0, _hot_updater_core.createReleaseCatalogScopeKey)({
|
|
17
|
+
channelKey,
|
|
18
|
+
fingerprintHash: scope.fingerprintHash ?? "",
|
|
19
|
+
platform: scope.platform,
|
|
20
|
+
strategy: "FINGERPRINT"
|
|
21
|
+
});
|
|
22
|
+
if (scope.strategy === "FINGERPRINT" !== (scope.fingerprintHash !== null) || scope.scopeKey !== expected) fail("INVALID_SCOPE", "Release catalog scope metadata is inconsistent");
|
|
23
|
+
};
|
|
24
|
+
/** A scope's enabled releases, all of them, under the catalog's guard. */
|
|
25
|
+
const enabledReleases = async (tx, scopeKey) => {
|
|
26
|
+
const rows = [];
|
|
27
|
+
let cursor;
|
|
28
|
+
do {
|
|
29
|
+
const page = await tx.findMany("releases", {
|
|
30
|
+
index: "byScopeEnabled",
|
|
31
|
+
where: {
|
|
32
|
+
scope_key: scopeKey,
|
|
33
|
+
enabled: true
|
|
34
|
+
},
|
|
35
|
+
limit: PAGE,
|
|
36
|
+
...cursor === void 0 ? {} : { cursor }
|
|
37
|
+
});
|
|
38
|
+
rows.push(...page.rows.map(require_reads.toReleaseRow));
|
|
39
|
+
cursor = page.next;
|
|
40
|
+
} while (cursor !== void 0);
|
|
41
|
+
return rows;
|
|
42
|
+
};
|
|
43
|
+
/** The scope's newest release id: `byScope` descending, limit 1. */
|
|
44
|
+
const latestReleaseId = async (tx, scopeKey) => {
|
|
45
|
+
const { rows } = await tx.findMany("releases", {
|
|
46
|
+
index: "byScope",
|
|
47
|
+
where: { scope_key: scopeKey },
|
|
48
|
+
order: "desc",
|
|
49
|
+
limit: 1
|
|
50
|
+
});
|
|
51
|
+
return rows[0]?.id ?? null;
|
|
52
|
+
};
|
|
53
|
+
/** Compiles `enabled` and writes it as the scope's next catalog generation. */
|
|
54
|
+
const writeCatalog = async (tx, scope, stored, enabled, updatedAtMs) => {
|
|
55
|
+
const compilation = await (0, _hot_updater_plugin_core.compileReleaseCatalog)({
|
|
56
|
+
strategy: scope.strategy,
|
|
57
|
+
releases: enabled.map(_hot_updater_plugin_core.releaseRowToRelease)
|
|
58
|
+
});
|
|
59
|
+
const generation = (stored.generation ?? 0) + 1;
|
|
60
|
+
if (!Number.isSafeInteger(generation)) fail("CATALOG_GENERATION_EXHAUSTED", `Catalog "${scope.scopeKey}" exhausted its generation counter`);
|
|
61
|
+
const catalog = {
|
|
62
|
+
scope_key: scope.scopeKey,
|
|
63
|
+
catalog_id: stored.catalog?.catalog_id ?? (0, _hot_updater_plugin_core.createUUIDv7)(),
|
|
64
|
+
strategy: scope.strategy,
|
|
65
|
+
channel_id: scope.channelId,
|
|
66
|
+
channel_key: (0, _hot_updater_core.encodeChannelKey)(scope.channelName),
|
|
67
|
+
platform: scope.platform,
|
|
68
|
+
fingerprint_hash: scope.fingerprintHash,
|
|
69
|
+
generation,
|
|
70
|
+
payload: compilation.canonicalPayload,
|
|
71
|
+
catalog_hash: compilation.catalogHash,
|
|
72
|
+
byte_size: compilation.byteSize,
|
|
73
|
+
is_tombstone: compilation.payload.releaseDescriptors.length === 0,
|
|
74
|
+
updated_at_ms: updatedAtMs
|
|
75
|
+
};
|
|
76
|
+
const { scope_key: _scopeKey, ...set } = catalog;
|
|
77
|
+
if (stored.row === null) tx.create("release_catalogs", catalog);
|
|
78
|
+
else tx.update("release_catalogs", stored.row, set);
|
|
79
|
+
return {
|
|
80
|
+
catalog,
|
|
81
|
+
compilation
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
/** The scope's catalog row, and its compiled catalog and generation if it has one. */
|
|
85
|
+
const readCatalog = async (tx, scopeKey) => {
|
|
86
|
+
const row = await tx.findOne("release_catalogs", { scope_key: scopeKey });
|
|
87
|
+
return {
|
|
88
|
+
row,
|
|
89
|
+
generation: row?.generation ?? null,
|
|
90
|
+
catalog: row === null ? null : require_reads.toCatalogRow(row)
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
/** A scope with releases and no compiled catalog lost its history. */
|
|
94
|
+
const assertHistory = (stored, hasReleases) => {
|
|
95
|
+
if (stored.catalog === null && hasReleases) fail("CATALOG_IDENTITY_MISSING", "Catalog history is missing. Restore its catalog row from backup before rebuilding or deploying.");
|
|
96
|
+
};
|
|
97
|
+
/** One release change and its scope's next catalog, inside `tx`. */
|
|
98
|
+
const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }) => {
|
|
99
|
+
checkScope(scope);
|
|
100
|
+
const stored = await readCatalog(tx, scope.scopeKey);
|
|
101
|
+
const enabled = await enabledReleases(tx, scope.scopeKey);
|
|
102
|
+
if (bundle !== void 0) {
|
|
103
|
+
require_writes.insertBundle(tx, bundle.row);
|
|
104
|
+
for (const patch of bundle.patches) tx.create("bundle_patches", patch);
|
|
105
|
+
}
|
|
106
|
+
let before = null;
|
|
107
|
+
let release;
|
|
108
|
+
if (change.operation === "insert") {
|
|
109
|
+
const latest = await latestReleaseId(tx, scope.scopeKey);
|
|
110
|
+
assertHistory(stored, latest !== null);
|
|
111
|
+
const floor = [latest, bundle && (0, _hot_updater_plugin_core.isUUIDv7)(bundle.row.id) ? bundle.row.id : null].filter((id) => id !== null).sort().at(-1);
|
|
112
|
+
const id = change.row.id ?? (0, _hot_updater_plugin_core.createUUIDv7After)(floor ?? null);
|
|
113
|
+
if (latest !== null && id <= latest) fail("NON_MONOTONIC_RELEASE_ID", `Release "${id}" must sort after "${latest}"`);
|
|
114
|
+
release = {
|
|
115
|
+
...change.row,
|
|
116
|
+
id
|
|
117
|
+
};
|
|
118
|
+
if (release.scope_key !== scope.scopeKey || release.channel_id !== scope.channelId || release.platform !== scope.platform || release.strategy !== scope.strategy || release.fingerprint_hash !== scope.fingerprintHash || release.revision !== 1) fail("INVALID_SCOPE", "Inserted Release does not match its catalog scope");
|
|
119
|
+
tx.create("releases", release);
|
|
120
|
+
} else {
|
|
121
|
+
const row = await tx.findOne("releases", { id: change.id });
|
|
122
|
+
if (row === null || row.scope_key !== scope.scopeKey) return fail("RELEASE_NOT_FOUND", `Release "${change.id}" was not found in scope "${scope.scopeKey}"`);
|
|
123
|
+
assertHistory(stored, true);
|
|
124
|
+
before = require_reads.toReleaseRow(row);
|
|
125
|
+
if (change.operation === "delete") {
|
|
126
|
+
await tx.delete("releases", row);
|
|
127
|
+
release = null;
|
|
128
|
+
} else {
|
|
129
|
+
const set = {
|
|
130
|
+
...change.update,
|
|
131
|
+
revision: before.revision + 1
|
|
132
|
+
};
|
|
133
|
+
tx.update("releases", row, set);
|
|
134
|
+
release = {
|
|
135
|
+
...before,
|
|
136
|
+
...set
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const changedId = before?.id ?? release?.id;
|
|
141
|
+
const next = [...enabled.filter(({ id }) => id !== changedId), ...release?.enabled ? [release] : []].sort((left, right) => left.id < right.id ? -1 : 1);
|
|
142
|
+
const { catalog, compilation } = await writeCatalog(tx, scope, stored, next, updatedAtMs);
|
|
143
|
+
return {
|
|
144
|
+
catalog,
|
|
145
|
+
release,
|
|
146
|
+
diagnostics: compilation.diagnostics
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Release changes rooted at their catalogs: each reads its scope's catalog
|
|
151
|
+
* and enabled releases, applies the change, and writes the next catalog
|
|
152
|
+
* generation, all in one transaction. A concurrent change in a scope bumps
|
|
153
|
+
* its catalog row, so this transaction reruns instead of publishing a stale
|
|
154
|
+
* catalog.
|
|
155
|
+
*/
|
|
156
|
+
const changeReleases = (db, inputs) => {
|
|
157
|
+
if (new Set(inputs.map(({ scope }) => scope.scopeKey)).size !== inputs.length) fail("INVALID_SCOPE", "A batch cannot change one catalog scope twice");
|
|
158
|
+
return db.transaction(async (tx) => {
|
|
159
|
+
const results = [];
|
|
160
|
+
for (const input of inputs) results.push(await changeRelease(tx, input));
|
|
161
|
+
return results;
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
/** Recompiles a scope's catalog from its enabled releases inside `tx`; an unchanged catalog is not rewritten. */
|
|
165
|
+
const rebuildScope = async (tx, scope, updatedAtMs) => {
|
|
166
|
+
checkScope(scope);
|
|
167
|
+
const stored = await readCatalog(tx, scope.scopeKey);
|
|
168
|
+
assertHistory(stored, await latestReleaseId(tx, scope.scopeKey) !== null);
|
|
169
|
+
const enabled = await enabledReleases(tx, scope.scopeKey);
|
|
170
|
+
const compilation = await (0, _hot_updater_plugin_core.compileReleaseCatalog)({
|
|
171
|
+
strategy: scope.strategy,
|
|
172
|
+
releases: enabled.map(_hot_updater_plugin_core.releaseRowToRelease)
|
|
173
|
+
});
|
|
174
|
+
const current = stored.catalog;
|
|
175
|
+
if (current !== null && current.strategy === scope.strategy && current.channel_id === scope.channelId && current.channel_key === (0, _hot_updater_core.encodeChannelKey)(scope.channelName) && current.platform === scope.platform && current.fingerprint_hash === scope.fingerprintHash && current.catalog_hash === compilation.catalogHash) return {
|
|
176
|
+
catalog: current,
|
|
177
|
+
current,
|
|
178
|
+
changed: false,
|
|
179
|
+
diagnostics: compilation.diagnostics
|
|
180
|
+
};
|
|
181
|
+
const written = await writeCatalog(tx, scope, stored, enabled, updatedAtMs);
|
|
182
|
+
return {
|
|
183
|
+
catalog: written.catalog,
|
|
184
|
+
current,
|
|
185
|
+
changed: true,
|
|
186
|
+
diagnostics: written.compilation.diagnostics
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
//#endregion
|
|
190
|
+
exports.changeRelease = changeRelease;
|
|
191
|
+
exports.changeReleases = changeReleases;
|
|
192
|
+
exports.readCatalog = readCatalog;
|
|
193
|
+
exports.rebuildScope = rebuildScope;
|