@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,123 @@
|
|
|
1
|
+
import { FieldType } from "./definitions.cjs";
|
|
2
|
+
import { SchemaModule } from "./resolveSchema.cjs";
|
|
3
|
+
import { AggregateDefinition, FieldValue, ModuleSchema, RowOf, TableDefinition } from "./schema.cjs";
|
|
4
|
+
import { EngineReadCount, Page, ReadInput } from "./engineReads.cjs";
|
|
5
|
+
import { TransactionEngine } from "./engineTransaction.cjs";
|
|
6
|
+
import { DatabaseEngineOptions, ReadMeasurement } from "./engine.cjs";
|
|
7
|
+
import { DatabaseKeyValue, StoredRow } from "@hot-updater/plugin-core/internal";
|
|
8
|
+
//#region src/database/database.d.ts
|
|
9
|
+
type TableNames<S extends ModuleSchema> = { [K in keyof S]: S[K] extends TableDefinition ? K : never; }[keyof S] & string;
|
|
10
|
+
type AggregateNames<S extends ModuleSchema> = { [K in keyof S]: S[K] extends AggregateDefinition ? K : never; }[keyof S] & string;
|
|
11
|
+
/** Reference counters: how many rows of another table point at this one. */
|
|
12
|
+
type RefColumns = {
|
|
13
|
+
readonly [K: `_refs_${string}`]: number;
|
|
14
|
+
};
|
|
15
|
+
/** Engine columns every stored row carries. */
|
|
16
|
+
type EngineColumns = {
|
|
17
|
+
readonly _v: number;
|
|
18
|
+
} & RefColumns;
|
|
19
|
+
type DerivedValues<TDerived> = { -readonly [K in keyof TDerived]: TDerived[K] extends FieldType ? FieldValue<TDerived[K]> | readonly FieldValue<TDerived[K]>[] | null : never; };
|
|
20
|
+
type Values<TModel> = TModel extends TableDefinition<infer TFields, infer TDerived> ? RowOf<TFields> & DerivedValues<TDerived> : TModel extends AggregateDefinition<infer TFields, infer TMetric, infer _TIndexes, infer TSketch> ? RowOf<TFields> & { -readonly [K in TMetric]: number; } & { -readonly [K in TSketch]: string; } : never;
|
|
21
|
+
/** A row read in a transaction, `_v` included, so the transaction can write it back. */
|
|
22
|
+
type TableRow<TModel> = Values<TModel> & EngineColumns;
|
|
23
|
+
/** A row read outside a transaction, without `_v`, which only a transaction's guard uses. */
|
|
24
|
+
type ReadRow<TModel> = Values<TModel> & RefColumns;
|
|
25
|
+
type AggregateRow<TModel> = Values<TModel>;
|
|
26
|
+
type IndexesOf<TModel> = TModel extends {
|
|
27
|
+
readonly indexes: infer I;
|
|
28
|
+
} ? I : never;
|
|
29
|
+
type IndexName<TModel> = keyof IndexesOf<TModel> & string;
|
|
30
|
+
type IndexFields<TModel, TIndex, TPart extends "eq" | "sort"> = IndexesOf<TModel>[TIndex & keyof IndexesOf<TModel>] extends { readonly [P in TPart]: readonly (infer F)[]; } ? F & keyof Values<TModel> : never;
|
|
31
|
+
type KeyValueOf<TModel, TField extends keyof Values<TModel>> = Exclude<Values<TModel>[TField], null | readonly unknown[]>;
|
|
32
|
+
type FirstOrderField<TModel, TIndex> = IndexesOf<TModel>[TIndex & keyof IndexesOf<TModel>] extends {
|
|
33
|
+
readonly sort: readonly [infer F, ...unknown[]];
|
|
34
|
+
} ? F & keyof Values<TModel> : TModel extends {
|
|
35
|
+
readonly key: readonly (infer K)[];
|
|
36
|
+
} ? K & keyof Values<TModel> : never;
|
|
37
|
+
interface ReadOptions<TModel, TIndex> {
|
|
38
|
+
readonly index: TIndex;
|
|
39
|
+
/** Every eq field of the index; null never matches. */
|
|
40
|
+
readonly where: { readonly [F in IndexFields<TModel, TIndex, "eq">]: KeyValueOf<TModel, F>; };
|
|
41
|
+
/** Bounds on the first order field, or on a prefix of the order tuple (sort fields, then the key). */
|
|
42
|
+
readonly range?: { readonly [B in "gt" | "gte" | "lt" | "lte"]?: KeyValueOf<TModel, FirstOrderField<TModel, TIndex>> | readonly [KeyValueOf<TModel, FirstOrderField<TModel, TIndex>>, ...DatabaseKeyValue[]]; };
|
|
43
|
+
readonly order?: "asc" | "desc";
|
|
44
|
+
readonly limit: number;
|
|
45
|
+
readonly cursor?: string;
|
|
46
|
+
}
|
|
47
|
+
type UniqueLookups<TModel> = TModel extends TableDefinition<infer TFields, infer _D, infer TIndexes> ? { [F in keyof TFields]: TFields[F] extends {
|
|
48
|
+
readonly unique: true;
|
|
49
|
+
} ? { readonly [P in F]: KeyValueOf<TModel, P & keyof Values<TModel>>; } : never; }[keyof TFields] | { [I in keyof TIndexes]: TIndexes[I] extends {
|
|
50
|
+
readonly unique: true;
|
|
51
|
+
readonly eq: readonly (infer E)[];
|
|
52
|
+
} ? { readonly [P in E & string]: KeyValueOf<TModel, P & keyof Values<TModel>>; } : never; }[keyof TIndexes] : never;
|
|
53
|
+
/** A table's key values. */
|
|
54
|
+
type KeyLookup<TModel> = TModel extends TableDefinition<infer _F> ? { readonly [K in TModel["key"][number]]: KeyValueOf<TModel, K & keyof Values<TModel>>; } : never;
|
|
55
|
+
/** The key, or the eq fields of a unique index. */
|
|
56
|
+
type Lookup<TModel> = KeyLookup<TModel> | UniqueLookups<TModel>;
|
|
57
|
+
type RootedIndexName<TModel> = { [I in keyof IndexesOf<TModel>]: IndexesOf<TModel>[I] extends {
|
|
58
|
+
readonly root: object;
|
|
59
|
+
} ? I : never; }[keyof IndexesOf<TModel>] & string;
|
|
60
|
+
type OptionalFields<TFields> = { [K in keyof TFields]: TFields[K] extends {
|
|
61
|
+
readonly required: false;
|
|
62
|
+
} ? K : never; }[keyof TFields];
|
|
63
|
+
/** Declared fields, optional ones omittable; derived fields and engine columns are computed. */
|
|
64
|
+
type CreateRow<TModel> = TModel extends TableDefinition<infer TFields> ? Omit<RowOf<TFields>, OptionalFields<TFields>> & Partial<Pick<RowOf<TFields>, OptionalFields<TFields>>> : never;
|
|
65
|
+
/** Changed non-key fields. */
|
|
66
|
+
type UpdateSet<TModel> = TModel extends TableDefinition<infer TFields, infer _D, infer _I, infer TKey> ? Partial<Omit<RowOf<TFields>, TKey[number]>> : never;
|
|
67
|
+
type AggregateIdentity<TModel> = TModel extends AggregateDefinition<infer TFields> ? RowOf<TFields> : never;
|
|
68
|
+
/** Counter and gauge deltas, and sketches to merge. */
|
|
69
|
+
type AggregateChanges<TModel> = TModel extends AggregateDefinition<infer _F, infer TMetric, infer _I, infer TSketch> ? { readonly [K in TMetric]?: number; } & { readonly [K in TSketch]?: string; } : never;
|
|
70
|
+
/** Reads are recorded and guarded at commit; writes apply only if every guard holds. */
|
|
71
|
+
interface HotUpdaterTransaction<S extends ModuleSchema> {
|
|
72
|
+
findOne<M extends TableNames<S>>(model: M, lookup: Lookup<S[M]>): Promise<TableRow<S[M]> | null>;
|
|
73
|
+
/** Rooted indexes only: the parent row guards the whole range. */
|
|
74
|
+
findMany<M extends TableNames<S>, I extends RootedIndexName<S[M]>>(model: M, options: ReadOptions<S[M], I>): Promise<Page<TableRow<S[M]>>>;
|
|
75
|
+
create<M extends TableNames<S>>(model: M, row: CreateRow<S[M]>): void;
|
|
76
|
+
/** Patches a row this transaction read, by key or through a rooted range. */
|
|
77
|
+
update<M extends TableNames<S>>(model: M, row: TableRow<S[M]>, set: UpdateSet<S[M]>): void;
|
|
78
|
+
/** Deletes a row this transaction read, cascading to its children first. */
|
|
79
|
+
delete<M extends TableNames<S>>(model: M, row: TableRow<S[M]>): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Changes one shard row of an aggregate. Gauges of a sharded aggregate need
|
|
82
|
+
* `shardBy`, so every change keyed by one value lands on one shard.
|
|
83
|
+
*/
|
|
84
|
+
aggregate<M extends AggregateNames<S>>(model: M, identity: AggregateIdentity<S[M]>, changes: AggregateChanges<S[M]>, options?: {
|
|
85
|
+
readonly shardBy?: string;
|
|
86
|
+
}): void;
|
|
87
|
+
}
|
|
88
|
+
/** A table name, or the reason an aggregate cannot be read this way. */
|
|
89
|
+
type FindManyModel<S extends ModuleSchema, M> = M extends TableNames<S> ? M : "findMany reads tables; read aggregates with findAggregates";
|
|
90
|
+
/** An aggregate name, or the reason a table cannot be read this way. */
|
|
91
|
+
type FindAggregatesModel<S extends ModuleSchema, M> = M extends AggregateNames<S> ? M : "findAggregates reads aggregates; read tables with findMany";
|
|
92
|
+
/** A module's database handle. There is no count, offset, or free-form filter. */
|
|
93
|
+
interface HotUpdaterDatabase<S extends ModuleSchema> {
|
|
94
|
+
findOne<M extends TableNames<S>>(model: M, lookup: Lookup<S[M]>): Promise<ReadRow<S[M]> | null>;
|
|
95
|
+
/** Rows by key in one batch read, in the keys' order. */
|
|
96
|
+
findByKeys<M extends TableNames<S>>(model: M, keys: readonly KeyLookup<S[M]>[]): Promise<(ReadRow<S[M]> | null)[]>;
|
|
97
|
+
findMany<M extends keyof S & string, I extends IndexName<S[M]>>(model: FindManyModel<S, M>, options: ReadOptions<S[M], I>): Promise<Page<ReadRow<S[M]>>>;
|
|
98
|
+
findAggregates<M extends keyof S & string, I extends IndexName<S[M]>>(model: FindAggregatesModel<S, M>, options: ReadOptions<S[M], I>): Promise<Page<AggregateRow<S[M]>>>;
|
|
99
|
+
/** Reruns `fn` when a guarded read changed, within a jittered retry budget. */
|
|
100
|
+
transaction<R>(fn: (tx: HotUpdaterTransaction<S>) => Promise<R>): Promise<R>;
|
|
101
|
+
}
|
|
102
|
+
/** The engine plus `database(module)`, which hands a module its typed handle. */
|
|
103
|
+
declare const createDatabaseEngine: (options: DatabaseEngineOptions) => {
|
|
104
|
+
database<S extends ModuleSchema>(module: SchemaModule & {
|
|
105
|
+
readonly schema: S;
|
|
106
|
+
}): HotUpdaterDatabase<S>;
|
|
107
|
+
reads: {
|
|
108
|
+
maxPageSize: number;
|
|
109
|
+
reads: {
|
|
110
|
+
total: () => EngineReadCount;
|
|
111
|
+
reset: () => void;
|
|
112
|
+
};
|
|
113
|
+
findByKeys: (name: string, lookups: readonly Readonly<Record<string, DatabaseKeyValue>>[]) => Promise<(StoredRow | null)[]>;
|
|
114
|
+
findOne(name: string, lookup: Readonly<Record<string, DatabaseKeyValue>>): Promise<StoredRow | null>;
|
|
115
|
+
findMany(name: string, input: ReadInput): Promise<Page<StoredRow>>;
|
|
116
|
+
findAggregates(name: string, input: ReadInput): Promise<Page<StoredRow>>;
|
|
117
|
+
};
|
|
118
|
+
transaction: <R>(fn: (tx: TransactionEngine) => Promise<R>) => Promise<R>;
|
|
119
|
+
measureReads<T>(read: () => Promise<T>): Promise<ReadMeasurement<T>>;
|
|
120
|
+
};
|
|
121
|
+
type DatabaseEngine = ReturnType<typeof createDatabaseEngine>;
|
|
122
|
+
//#endregion
|
|
123
|
+
export { AggregateChanges, AggregateIdentity, AggregateRow, CreateRow, DatabaseEngine, EngineColumns, FindAggregatesModel, FindManyModel, HotUpdaterDatabase, HotUpdaterTransaction, KeyLookup, Lookup, ReadOptions, ReadRow, TableRow, UpdateSet, createDatabaseEngine };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { FieldType } from "./definitions.mjs";
|
|
2
|
+
import { SchemaModule } from "./resolveSchema.mjs";
|
|
3
|
+
import { AggregateDefinition, FieldValue, ModuleSchema, RowOf, TableDefinition } from "./schema.mjs";
|
|
4
|
+
import { EngineReadCount, Page, ReadInput } from "./engineReads.mjs";
|
|
5
|
+
import { TransactionEngine } from "./engineTransaction.mjs";
|
|
6
|
+
import { DatabaseEngineOptions, ReadMeasurement } from "./engine.mjs";
|
|
7
|
+
import { DatabaseKeyValue, StoredRow } from "@hot-updater/plugin-core/internal";
|
|
8
|
+
//#region src/database/database.d.ts
|
|
9
|
+
type TableNames<S extends ModuleSchema> = { [K in keyof S]: S[K] extends TableDefinition ? K : never; }[keyof S] & string;
|
|
10
|
+
type AggregateNames<S extends ModuleSchema> = { [K in keyof S]: S[K] extends AggregateDefinition ? K : never; }[keyof S] & string;
|
|
11
|
+
/** Reference counters: how many rows of another table point at this one. */
|
|
12
|
+
type RefColumns = {
|
|
13
|
+
readonly [K: `_refs_${string}`]: number;
|
|
14
|
+
};
|
|
15
|
+
/** Engine columns every stored row carries. */
|
|
16
|
+
type EngineColumns = {
|
|
17
|
+
readonly _v: number;
|
|
18
|
+
} & RefColumns;
|
|
19
|
+
type DerivedValues<TDerived> = { -readonly [K in keyof TDerived]: TDerived[K] extends FieldType ? FieldValue<TDerived[K]> | readonly FieldValue<TDerived[K]>[] | null : never; };
|
|
20
|
+
type Values<TModel> = TModel extends TableDefinition<infer TFields, infer TDerived> ? RowOf<TFields> & DerivedValues<TDerived> : TModel extends AggregateDefinition<infer TFields, infer TMetric, infer _TIndexes, infer TSketch> ? RowOf<TFields> & { -readonly [K in TMetric]: number; } & { -readonly [K in TSketch]: string; } : never;
|
|
21
|
+
/** A row read in a transaction, `_v` included, so the transaction can write it back. */
|
|
22
|
+
type TableRow<TModel> = Values<TModel> & EngineColumns;
|
|
23
|
+
/** A row read outside a transaction, without `_v`, which only a transaction's guard uses. */
|
|
24
|
+
type ReadRow<TModel> = Values<TModel> & RefColumns;
|
|
25
|
+
type AggregateRow<TModel> = Values<TModel>;
|
|
26
|
+
type IndexesOf<TModel> = TModel extends {
|
|
27
|
+
readonly indexes: infer I;
|
|
28
|
+
} ? I : never;
|
|
29
|
+
type IndexName<TModel> = keyof IndexesOf<TModel> & string;
|
|
30
|
+
type IndexFields<TModel, TIndex, TPart extends "eq" | "sort"> = IndexesOf<TModel>[TIndex & keyof IndexesOf<TModel>] extends { readonly [P in TPart]: readonly (infer F)[]; } ? F & keyof Values<TModel> : never;
|
|
31
|
+
type KeyValueOf<TModel, TField extends keyof Values<TModel>> = Exclude<Values<TModel>[TField], null | readonly unknown[]>;
|
|
32
|
+
type FirstOrderField<TModel, TIndex> = IndexesOf<TModel>[TIndex & keyof IndexesOf<TModel>] extends {
|
|
33
|
+
readonly sort: readonly [infer F, ...unknown[]];
|
|
34
|
+
} ? F & keyof Values<TModel> : TModel extends {
|
|
35
|
+
readonly key: readonly (infer K)[];
|
|
36
|
+
} ? K & keyof Values<TModel> : never;
|
|
37
|
+
interface ReadOptions<TModel, TIndex> {
|
|
38
|
+
readonly index: TIndex;
|
|
39
|
+
/** Every eq field of the index; null never matches. */
|
|
40
|
+
readonly where: { readonly [F in IndexFields<TModel, TIndex, "eq">]: KeyValueOf<TModel, F>; };
|
|
41
|
+
/** Bounds on the first order field, or on a prefix of the order tuple (sort fields, then the key). */
|
|
42
|
+
readonly range?: { readonly [B in "gt" | "gte" | "lt" | "lte"]?: KeyValueOf<TModel, FirstOrderField<TModel, TIndex>> | readonly [KeyValueOf<TModel, FirstOrderField<TModel, TIndex>>, ...DatabaseKeyValue[]]; };
|
|
43
|
+
readonly order?: "asc" | "desc";
|
|
44
|
+
readonly limit: number;
|
|
45
|
+
readonly cursor?: string;
|
|
46
|
+
}
|
|
47
|
+
type UniqueLookups<TModel> = TModel extends TableDefinition<infer TFields, infer _D, infer TIndexes> ? { [F in keyof TFields]: TFields[F] extends {
|
|
48
|
+
readonly unique: true;
|
|
49
|
+
} ? { readonly [P in F]: KeyValueOf<TModel, P & keyof Values<TModel>>; } : never; }[keyof TFields] | { [I in keyof TIndexes]: TIndexes[I] extends {
|
|
50
|
+
readonly unique: true;
|
|
51
|
+
readonly eq: readonly (infer E)[];
|
|
52
|
+
} ? { readonly [P in E & string]: KeyValueOf<TModel, P & keyof Values<TModel>>; } : never; }[keyof TIndexes] : never;
|
|
53
|
+
/** A table's key values. */
|
|
54
|
+
type KeyLookup<TModel> = TModel extends TableDefinition<infer _F> ? { readonly [K in TModel["key"][number]]: KeyValueOf<TModel, K & keyof Values<TModel>>; } : never;
|
|
55
|
+
/** The key, or the eq fields of a unique index. */
|
|
56
|
+
type Lookup<TModel> = KeyLookup<TModel> | UniqueLookups<TModel>;
|
|
57
|
+
type RootedIndexName<TModel> = { [I in keyof IndexesOf<TModel>]: IndexesOf<TModel>[I] extends {
|
|
58
|
+
readonly root: object;
|
|
59
|
+
} ? I : never; }[keyof IndexesOf<TModel>] & string;
|
|
60
|
+
type OptionalFields<TFields> = { [K in keyof TFields]: TFields[K] extends {
|
|
61
|
+
readonly required: false;
|
|
62
|
+
} ? K : never; }[keyof TFields];
|
|
63
|
+
/** Declared fields, optional ones omittable; derived fields and engine columns are computed. */
|
|
64
|
+
type CreateRow<TModel> = TModel extends TableDefinition<infer TFields> ? Omit<RowOf<TFields>, OptionalFields<TFields>> & Partial<Pick<RowOf<TFields>, OptionalFields<TFields>>> : never;
|
|
65
|
+
/** Changed non-key fields. */
|
|
66
|
+
type UpdateSet<TModel> = TModel extends TableDefinition<infer TFields, infer _D, infer _I, infer TKey> ? Partial<Omit<RowOf<TFields>, TKey[number]>> : never;
|
|
67
|
+
type AggregateIdentity<TModel> = TModel extends AggregateDefinition<infer TFields> ? RowOf<TFields> : never;
|
|
68
|
+
/** Counter and gauge deltas, and sketches to merge. */
|
|
69
|
+
type AggregateChanges<TModel> = TModel extends AggregateDefinition<infer _F, infer TMetric, infer _I, infer TSketch> ? { readonly [K in TMetric]?: number; } & { readonly [K in TSketch]?: string; } : never;
|
|
70
|
+
/** Reads are recorded and guarded at commit; writes apply only if every guard holds. */
|
|
71
|
+
interface HotUpdaterTransaction<S extends ModuleSchema> {
|
|
72
|
+
findOne<M extends TableNames<S>>(model: M, lookup: Lookup<S[M]>): Promise<TableRow<S[M]> | null>;
|
|
73
|
+
/** Rooted indexes only: the parent row guards the whole range. */
|
|
74
|
+
findMany<M extends TableNames<S>, I extends RootedIndexName<S[M]>>(model: M, options: ReadOptions<S[M], I>): Promise<Page<TableRow<S[M]>>>;
|
|
75
|
+
create<M extends TableNames<S>>(model: M, row: CreateRow<S[M]>): void;
|
|
76
|
+
/** Patches a row this transaction read, by key or through a rooted range. */
|
|
77
|
+
update<M extends TableNames<S>>(model: M, row: TableRow<S[M]>, set: UpdateSet<S[M]>): void;
|
|
78
|
+
/** Deletes a row this transaction read, cascading to its children first. */
|
|
79
|
+
delete<M extends TableNames<S>>(model: M, row: TableRow<S[M]>): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Changes one shard row of an aggregate. Gauges of a sharded aggregate need
|
|
82
|
+
* `shardBy`, so every change keyed by one value lands on one shard.
|
|
83
|
+
*/
|
|
84
|
+
aggregate<M extends AggregateNames<S>>(model: M, identity: AggregateIdentity<S[M]>, changes: AggregateChanges<S[M]>, options?: {
|
|
85
|
+
readonly shardBy?: string;
|
|
86
|
+
}): void;
|
|
87
|
+
}
|
|
88
|
+
/** A table name, or the reason an aggregate cannot be read this way. */
|
|
89
|
+
type FindManyModel<S extends ModuleSchema, M> = M extends TableNames<S> ? M : "findMany reads tables; read aggregates with findAggregates";
|
|
90
|
+
/** An aggregate name, or the reason a table cannot be read this way. */
|
|
91
|
+
type FindAggregatesModel<S extends ModuleSchema, M> = M extends AggregateNames<S> ? M : "findAggregates reads aggregates; read tables with findMany";
|
|
92
|
+
/** A module's database handle. There is no count, offset, or free-form filter. */
|
|
93
|
+
interface HotUpdaterDatabase<S extends ModuleSchema> {
|
|
94
|
+
findOne<M extends TableNames<S>>(model: M, lookup: Lookup<S[M]>): Promise<ReadRow<S[M]> | null>;
|
|
95
|
+
/** Rows by key in one batch read, in the keys' order. */
|
|
96
|
+
findByKeys<M extends TableNames<S>>(model: M, keys: readonly KeyLookup<S[M]>[]): Promise<(ReadRow<S[M]> | null)[]>;
|
|
97
|
+
findMany<M extends keyof S & string, I extends IndexName<S[M]>>(model: FindManyModel<S, M>, options: ReadOptions<S[M], I>): Promise<Page<ReadRow<S[M]>>>;
|
|
98
|
+
findAggregates<M extends keyof S & string, I extends IndexName<S[M]>>(model: FindAggregatesModel<S, M>, options: ReadOptions<S[M], I>): Promise<Page<AggregateRow<S[M]>>>;
|
|
99
|
+
/** Reruns `fn` when a guarded read changed, within a jittered retry budget. */
|
|
100
|
+
transaction<R>(fn: (tx: HotUpdaterTransaction<S>) => Promise<R>): Promise<R>;
|
|
101
|
+
}
|
|
102
|
+
/** The engine plus `database(module)`, which hands a module its typed handle. */
|
|
103
|
+
declare const createDatabaseEngine: (options: DatabaseEngineOptions) => {
|
|
104
|
+
database<S extends ModuleSchema>(module: SchemaModule & {
|
|
105
|
+
readonly schema: S;
|
|
106
|
+
}): HotUpdaterDatabase<S>;
|
|
107
|
+
reads: {
|
|
108
|
+
maxPageSize: number;
|
|
109
|
+
reads: {
|
|
110
|
+
total: () => EngineReadCount;
|
|
111
|
+
reset: () => void;
|
|
112
|
+
};
|
|
113
|
+
findByKeys: (name: string, lookups: readonly Readonly<Record<string, DatabaseKeyValue>>[]) => Promise<(StoredRow | null)[]>;
|
|
114
|
+
findOne(name: string, lookup: Readonly<Record<string, DatabaseKeyValue>>): Promise<StoredRow | null>;
|
|
115
|
+
findMany(name: string, input: ReadInput): Promise<Page<StoredRow>>;
|
|
116
|
+
findAggregates(name: string, input: ReadInput): Promise<Page<StoredRow>>;
|
|
117
|
+
};
|
|
118
|
+
transaction: <R>(fn: (tx: TransactionEngine) => Promise<R>) => Promise<R>;
|
|
119
|
+
measureReads<T>(read: () => Promise<T>): Promise<ReadMeasurement<T>>;
|
|
120
|
+
};
|
|
121
|
+
type DatabaseEngine = ReturnType<typeof createDatabaseEngine>;
|
|
122
|
+
//#endregion
|
|
123
|
+
export { AggregateChanges, AggregateIdentity, AggregateRow, CreateRow, DatabaseEngine, EngineColumns, FindAggregatesModel, FindManyModel, HotUpdaterDatabase, HotUpdaterTransaction, KeyLookup, Lookup, ReadOptions, ReadRow, TableRow, UpdateSet, createDatabaseEngine };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { assertOutsideTransaction } from "./engineTransaction.mjs";
|
|
2
|
+
import { createEngine } from "./engine.mjs";
|
|
3
|
+
import { DATABASE_VERSION_COLUMN } from "@hot-updater/plugin-core/internal";
|
|
4
|
+
//#region src/database/database.ts
|
|
5
|
+
/** The engine plus `database(module)`, which hands a module its typed handle. */
|
|
6
|
+
const createDatabaseEngine = (options) => {
|
|
7
|
+
const engine = createEngine(options);
|
|
8
|
+
const { reads } = engine;
|
|
9
|
+
const outside = (read) => (...args) => {
|
|
10
|
+
assertOutsideTransaction();
|
|
11
|
+
return read(...args);
|
|
12
|
+
};
|
|
13
|
+
/** No read outside a transaction returns `_v`, which a key-value index copy lacks. */
|
|
14
|
+
const bare = (row) => row && Object.fromEntries(Object.entries(row).filter(([column]) => column !== DATABASE_VERSION_COLUMN));
|
|
15
|
+
const barePage = async (page) => {
|
|
16
|
+
const { rows, next } = await page;
|
|
17
|
+
return {
|
|
18
|
+
rows: rows.map(bare),
|
|
19
|
+
...next === void 0 ? {} : { next }
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
...engine,
|
|
24
|
+
database(module) {
|
|
25
|
+
const name = (model) => module.namespace ? `${module.namespace}_${model}` : model;
|
|
26
|
+
return {
|
|
27
|
+
findOne: outside(async (model, lookup) => bare(await reads.findOne(name(model), lookup))),
|
|
28
|
+
findByKeys: outside(async (model, keys) => (await reads.findByKeys(name(model), keys)).map(bare)),
|
|
29
|
+
findMany: outside((model, input) => barePage(reads.findMany(name(model), input))),
|
|
30
|
+
findAggregates: outside((model, input) => barePage(reads.findAggregates(name(model), input))),
|
|
31
|
+
transaction: (fn) => engine.transaction((tx) => fn({
|
|
32
|
+
findOne: (model, lookup) => tx.findOne(name(model), lookup),
|
|
33
|
+
findMany: (model, input) => tx.findMany(name(model), input),
|
|
34
|
+
create: (model, row) => tx.create(name(model), row),
|
|
35
|
+
update: (model, row, set) => tx.update(name(model), row, set),
|
|
36
|
+
delete: (model, row) => tx.delete(name(model), row),
|
|
37
|
+
aggregate: (model, identity, changes, options) => tx.aggregate(name(model), identity, changes, options)
|
|
38
|
+
}))
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
export { createDatabaseEngine };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//#region src/database/definitions.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The model declarations the engine reads. `defineTable` and
|
|
4
|
+
* `defineAggregate` (./schema) build them with typed rows.
|
|
5
|
+
*/
|
|
6
|
+
type FieldType = "string" | "integer" | "number" | "boolean" | "json";
|
|
7
|
+
type ReferenceAction = "restrict" | "cascade" | "none";
|
|
8
|
+
interface FieldReference {
|
|
9
|
+
readonly model: string;
|
|
10
|
+
readonly onDelete: ReferenceAction;
|
|
11
|
+
}
|
|
12
|
+
interface FieldDefinition<TType extends FieldType = FieldType> {
|
|
13
|
+
readonly type: TType;
|
|
14
|
+
/** Defaults to true; an optional field stores null. */
|
|
15
|
+
readonly required?: boolean;
|
|
16
|
+
/** Adds a unique index named after the field. */
|
|
17
|
+
readonly unique?: true;
|
|
18
|
+
/** Strings: the maximum length; unbounded text when absent. */
|
|
19
|
+
readonly maxLength?: number;
|
|
20
|
+
/** Strings: ASCII only, so a long key fits MySQL's 3,072-byte index limit. */
|
|
21
|
+
readonly ascii?: true;
|
|
22
|
+
readonly references?: FieldReference;
|
|
23
|
+
}
|
|
24
|
+
interface IndexDefinition<TField extends string = string> {
|
|
25
|
+
readonly eq: readonly TField[];
|
|
26
|
+
readonly sort: readonly TField[];
|
|
27
|
+
/** The eq values identify at most one row. */
|
|
28
|
+
readonly unique?: true;
|
|
29
|
+
/** `eq` starts with the key of a `model` row, which every child write bumps. */
|
|
30
|
+
readonly root?: {
|
|
31
|
+
readonly model: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** A field computed on every write and stored as a real column. */
|
|
35
|
+
interface DerivedShape {
|
|
36
|
+
readonly type: FieldType;
|
|
37
|
+
/** Up to 16 values; the row is indexed once per value. */
|
|
38
|
+
readonly multi?: true;
|
|
39
|
+
/** Null, or an empty list, leaves the row out of indexes on this field. */
|
|
40
|
+
compute(row: never): unknown;
|
|
41
|
+
}
|
|
42
|
+
interface TableShape {
|
|
43
|
+
readonly kind: "table";
|
|
44
|
+
readonly fields: Readonly<Record<string, FieldDefinition>>;
|
|
45
|
+
readonly key: readonly string[];
|
|
46
|
+
readonly derived: Readonly<Record<string, DerivedShape>>;
|
|
47
|
+
readonly indexes: Readonly<Record<string, IndexDefinition>>;
|
|
48
|
+
}
|
|
49
|
+
interface AggregateShape {
|
|
50
|
+
readonly kind: "aggregate";
|
|
51
|
+
/** Identity fields; `key` lists them in declaration order. */
|
|
52
|
+
readonly fields: Readonly<Record<string, FieldDefinition>>;
|
|
53
|
+
readonly key: readonly string[];
|
|
54
|
+
/** Blind increments. */
|
|
55
|
+
readonly counters: readonly string[];
|
|
56
|
+
/** Read, merged, and written back per shard; a row at zero is deleted. */
|
|
57
|
+
readonly gauges: readonly string[];
|
|
58
|
+
/** HLL sketches, kept in aggregates of their own. */
|
|
59
|
+
readonly distinct: readonly string[];
|
|
60
|
+
/** Fixed once data exists. */
|
|
61
|
+
readonly shards: number;
|
|
62
|
+
readonly indexes: Readonly<Record<string, IndexDefinition>>;
|
|
63
|
+
}
|
|
64
|
+
type ModelShape = TableShape | AggregateShape;
|
|
65
|
+
/** A module's models by name: core, or one plugin. */
|
|
66
|
+
type SchemaShape = Readonly<Record<string, ModelShape>>;
|
|
67
|
+
//#endregion
|
|
68
|
+
export { AggregateShape, DerivedShape, FieldDefinition, FieldReference, FieldType, IndexDefinition, ModelShape, ReferenceAction, SchemaShape, TableShape };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//#region src/database/definitions.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The model declarations the engine reads. `defineTable` and
|
|
4
|
+
* `defineAggregate` (./schema) build them with typed rows.
|
|
5
|
+
*/
|
|
6
|
+
type FieldType = "string" | "integer" | "number" | "boolean" | "json";
|
|
7
|
+
type ReferenceAction = "restrict" | "cascade" | "none";
|
|
8
|
+
interface FieldReference {
|
|
9
|
+
readonly model: string;
|
|
10
|
+
readonly onDelete: ReferenceAction;
|
|
11
|
+
}
|
|
12
|
+
interface FieldDefinition<TType extends FieldType = FieldType> {
|
|
13
|
+
readonly type: TType;
|
|
14
|
+
/** Defaults to true; an optional field stores null. */
|
|
15
|
+
readonly required?: boolean;
|
|
16
|
+
/** Adds a unique index named after the field. */
|
|
17
|
+
readonly unique?: true;
|
|
18
|
+
/** Strings: the maximum length; unbounded text when absent. */
|
|
19
|
+
readonly maxLength?: number;
|
|
20
|
+
/** Strings: ASCII only, so a long key fits MySQL's 3,072-byte index limit. */
|
|
21
|
+
readonly ascii?: true;
|
|
22
|
+
readonly references?: FieldReference;
|
|
23
|
+
}
|
|
24
|
+
interface IndexDefinition<TField extends string = string> {
|
|
25
|
+
readonly eq: readonly TField[];
|
|
26
|
+
readonly sort: readonly TField[];
|
|
27
|
+
/** The eq values identify at most one row. */
|
|
28
|
+
readonly unique?: true;
|
|
29
|
+
/** `eq` starts with the key of a `model` row, which every child write bumps. */
|
|
30
|
+
readonly root?: {
|
|
31
|
+
readonly model: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** A field computed on every write and stored as a real column. */
|
|
35
|
+
interface DerivedShape {
|
|
36
|
+
readonly type: FieldType;
|
|
37
|
+
/** Up to 16 values; the row is indexed once per value. */
|
|
38
|
+
readonly multi?: true;
|
|
39
|
+
/** Null, or an empty list, leaves the row out of indexes on this field. */
|
|
40
|
+
compute(row: never): unknown;
|
|
41
|
+
}
|
|
42
|
+
interface TableShape {
|
|
43
|
+
readonly kind: "table";
|
|
44
|
+
readonly fields: Readonly<Record<string, FieldDefinition>>;
|
|
45
|
+
readonly key: readonly string[];
|
|
46
|
+
readonly derived: Readonly<Record<string, DerivedShape>>;
|
|
47
|
+
readonly indexes: Readonly<Record<string, IndexDefinition>>;
|
|
48
|
+
}
|
|
49
|
+
interface AggregateShape {
|
|
50
|
+
readonly kind: "aggregate";
|
|
51
|
+
/** Identity fields; `key` lists them in declaration order. */
|
|
52
|
+
readonly fields: Readonly<Record<string, FieldDefinition>>;
|
|
53
|
+
readonly key: readonly string[];
|
|
54
|
+
/** Blind increments. */
|
|
55
|
+
readonly counters: readonly string[];
|
|
56
|
+
/** Read, merged, and written back per shard; a row at zero is deleted. */
|
|
57
|
+
readonly gauges: readonly string[];
|
|
58
|
+
/** HLL sketches, kept in aggregates of their own. */
|
|
59
|
+
readonly distinct: readonly string[];
|
|
60
|
+
/** Fixed once data exists. */
|
|
61
|
+
readonly shards: number;
|
|
62
|
+
readonly indexes: Readonly<Record<string, IndexDefinition>>;
|
|
63
|
+
}
|
|
64
|
+
type ModelShape = TableShape | AggregateShape;
|
|
65
|
+
/** A module's models by name: core, or one plugin. */
|
|
66
|
+
type SchemaShape = Readonly<Record<string, ModelShape>>;
|
|
67
|
+
//#endregion
|
|
68
|
+
export { AggregateShape, DerivedShape, FieldDefinition, FieldReference, FieldType, IndexDefinition, ModelShape, ReferenceAction, SchemaShape, TableShape };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const require_engineReads = require("./engineReads.cjs");
|
|
2
|
+
const require_engineTransaction = require("./engineTransaction.cjs");
|
|
3
|
+
let _hot_updater_plugin_core_internal = require("@hot-updater/plugin-core/internal");
|
|
4
|
+
//#region src/database/engine.ts
|
|
5
|
+
/** Storage semantics over one adapter, addressed by physical table name. */
|
|
6
|
+
const createEngine = ({ adapter: given, schema, maxPageSize, verify, retry }) => {
|
|
7
|
+
const verified = verify ? (0, _hot_updater_plugin_core_internal.verifyAdapter)(given) : void 0;
|
|
8
|
+
const adapter = verified ?? given;
|
|
9
|
+
const reads = require_engineReads.createEngineReads({
|
|
10
|
+
adapter,
|
|
11
|
+
schema,
|
|
12
|
+
maxPageSize
|
|
13
|
+
});
|
|
14
|
+
const { transaction } = require_engineTransaction.createTransactions({
|
|
15
|
+
adapter,
|
|
16
|
+
schema,
|
|
17
|
+
reads,
|
|
18
|
+
retry
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
reads,
|
|
22
|
+
transaction,
|
|
23
|
+
/** Runs `read` and reports what it read at both boundaries (verify mode only). */
|
|
24
|
+
async measureReads(read) {
|
|
25
|
+
if (verified === void 0) throw new Error("measureReads needs an engine created with verify: true.");
|
|
26
|
+
verified.reads.reset();
|
|
27
|
+
reads.reads.reset();
|
|
28
|
+
return {
|
|
29
|
+
result: await read(),
|
|
30
|
+
adapter: verified.reads.total(),
|
|
31
|
+
engine: reads.reads.total()
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.createEngine = createEngine;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ResolvedSchema } from "./resolveSchema.cjs";
|
|
2
|
+
import { EngineReadCount, Page, ReadInput } from "./engineReads.cjs";
|
|
3
|
+
import { RetryOptions, TransactionEngine } from "./engineTransaction.cjs";
|
|
4
|
+
import { DatabaseAdapter, DatabaseReadCount } from "@hot-updater/plugin-core/internal";
|
|
5
|
+
//#region src/database/engine.d.ts
|
|
6
|
+
interface DatabaseEngineOptions {
|
|
7
|
+
readonly adapter: DatabaseAdapter;
|
|
8
|
+
readonly schema: ResolvedSchema;
|
|
9
|
+
readonly maxPageSize?: number;
|
|
10
|
+
/** Checks every adapter call against the contract and meters adapter reads. */
|
|
11
|
+
readonly verify?: boolean;
|
|
12
|
+
readonly retry?: RetryOptions;
|
|
13
|
+
}
|
|
14
|
+
interface ReadMeasurement<T> {
|
|
15
|
+
readonly result: T;
|
|
16
|
+
/** Point reads and rows the adapter returned. */
|
|
17
|
+
readonly adapter: DatabaseReadCount;
|
|
18
|
+
/** Calls and rows (logical rows for aggregates) returned to callers. */
|
|
19
|
+
readonly engine: EngineReadCount;
|
|
20
|
+
}
|
|
21
|
+
/** Storage semantics over one adapter, addressed by physical table name. */
|
|
22
|
+
declare const createEngine: ({ adapter: given, schema, maxPageSize, verify, retry }: DatabaseEngineOptions) => {
|
|
23
|
+
reads: {
|
|
24
|
+
maxPageSize: number;
|
|
25
|
+
reads: {
|
|
26
|
+
total: () => EngineReadCount;
|
|
27
|
+
reset: () => void;
|
|
28
|
+
};
|
|
29
|
+
findByKeys: (name: string, lookups: readonly Readonly<Record<string, import("@hot-updater/plugin-core/internal").DatabaseKeyValue>>[]) => Promise<(import("@hot-updater/plugin-core/internal").StoredRow | null)[]>;
|
|
30
|
+
findOne(name: string, lookup: Readonly<Record<string, import("@hot-updater/plugin-core/internal").DatabaseKeyValue>>): Promise<import("@hot-updater/plugin-core/internal").StoredRow | null>;
|
|
31
|
+
findMany(name: string, input: ReadInput): Promise<Page<import("@hot-updater/plugin-core/internal").StoredRow>>;
|
|
32
|
+
findAggregates(name: string, input: ReadInput): Promise<Page<import("@hot-updater/plugin-core/internal").StoredRow>>;
|
|
33
|
+
};
|
|
34
|
+
transaction: <R>(fn: (tx: TransactionEngine) => Promise<R>) => Promise<R>;
|
|
35
|
+
/** Runs `read` and reports what it read at both boundaries (verify mode only). */
|
|
36
|
+
measureReads<T>(read: () => Promise<T>): Promise<ReadMeasurement<T>>;
|
|
37
|
+
};
|
|
38
|
+
type Engine = ReturnType<typeof createEngine>;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { DatabaseEngineOptions, Engine, ReadMeasurement, createEngine };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ResolvedSchema } from "./resolveSchema.mjs";
|
|
2
|
+
import { EngineReadCount, Page, ReadInput } from "./engineReads.mjs";
|
|
3
|
+
import { RetryOptions, TransactionEngine } from "./engineTransaction.mjs";
|
|
4
|
+
import { DatabaseAdapter, DatabaseReadCount } from "@hot-updater/plugin-core/internal";
|
|
5
|
+
//#region src/database/engine.d.ts
|
|
6
|
+
interface DatabaseEngineOptions {
|
|
7
|
+
readonly adapter: DatabaseAdapter;
|
|
8
|
+
readonly schema: ResolvedSchema;
|
|
9
|
+
readonly maxPageSize?: number;
|
|
10
|
+
/** Checks every adapter call against the contract and meters adapter reads. */
|
|
11
|
+
readonly verify?: boolean;
|
|
12
|
+
readonly retry?: RetryOptions;
|
|
13
|
+
}
|
|
14
|
+
interface ReadMeasurement<T> {
|
|
15
|
+
readonly result: T;
|
|
16
|
+
/** Point reads and rows the adapter returned. */
|
|
17
|
+
readonly adapter: DatabaseReadCount;
|
|
18
|
+
/** Calls and rows (logical rows for aggregates) returned to callers. */
|
|
19
|
+
readonly engine: EngineReadCount;
|
|
20
|
+
}
|
|
21
|
+
/** Storage semantics over one adapter, addressed by physical table name. */
|
|
22
|
+
declare const createEngine: ({ adapter: given, schema, maxPageSize, verify, retry }: DatabaseEngineOptions) => {
|
|
23
|
+
reads: {
|
|
24
|
+
maxPageSize: number;
|
|
25
|
+
reads: {
|
|
26
|
+
total: () => EngineReadCount;
|
|
27
|
+
reset: () => void;
|
|
28
|
+
};
|
|
29
|
+
findByKeys: (name: string, lookups: readonly Readonly<Record<string, import("@hot-updater/plugin-core/internal").DatabaseKeyValue>>[]) => Promise<(import("@hot-updater/plugin-core/internal").StoredRow | null)[]>;
|
|
30
|
+
findOne(name: string, lookup: Readonly<Record<string, import("@hot-updater/plugin-core/internal").DatabaseKeyValue>>): Promise<import("@hot-updater/plugin-core/internal").StoredRow | null>;
|
|
31
|
+
findMany(name: string, input: ReadInput): Promise<Page<import("@hot-updater/plugin-core/internal").StoredRow>>;
|
|
32
|
+
findAggregates(name: string, input: ReadInput): Promise<Page<import("@hot-updater/plugin-core/internal").StoredRow>>;
|
|
33
|
+
};
|
|
34
|
+
transaction: <R>(fn: (tx: TransactionEngine) => Promise<R>) => Promise<R>;
|
|
35
|
+
/** Runs `read` and reports what it read at both boundaries (verify mode only). */
|
|
36
|
+
measureReads<T>(read: () => Promise<T>): Promise<ReadMeasurement<T>>;
|
|
37
|
+
};
|
|
38
|
+
type Engine = ReturnType<typeof createEngine>;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { DatabaseEngineOptions, Engine, ReadMeasurement, createEngine };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createEngineReads } from "./engineReads.mjs";
|
|
2
|
+
import { createTransactions } from "./engineTransaction.mjs";
|
|
3
|
+
import { verifyAdapter } from "@hot-updater/plugin-core/internal";
|
|
4
|
+
//#region src/database/engine.ts
|
|
5
|
+
/** Storage semantics over one adapter, addressed by physical table name. */
|
|
6
|
+
const createEngine = ({ adapter: given, schema, maxPageSize, verify, retry }) => {
|
|
7
|
+
const verified = verify ? verifyAdapter(given) : void 0;
|
|
8
|
+
const adapter = verified ?? given;
|
|
9
|
+
const reads = createEngineReads({
|
|
10
|
+
adapter,
|
|
11
|
+
schema,
|
|
12
|
+
maxPageSize
|
|
13
|
+
});
|
|
14
|
+
const { transaction } = createTransactions({
|
|
15
|
+
adapter,
|
|
16
|
+
schema,
|
|
17
|
+
reads,
|
|
18
|
+
retry
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
reads,
|
|
22
|
+
transaction,
|
|
23
|
+
/** Runs `read` and reports what it read at both boundaries (verify mode only). */
|
|
24
|
+
async measureReads(read) {
|
|
25
|
+
if (verified === void 0) throw new Error("measureReads needs an engine created with verify: true.");
|
|
26
|
+
verified.reads.reset();
|
|
27
|
+
reads.reads.reset();
|
|
28
|
+
return {
|
|
29
|
+
result: await read(),
|
|
30
|
+
adapter: verified.reads.total(),
|
|
31
|
+
engine: reads.reads.total()
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
export { createEngine };
|