@hot-updater/server 1.0.0-rc.18 → 1.0.0-rc.21
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/LICENSE +12 -14
- package/dist/adapters/drizzle.cjs +6 -8
- package/dist/adapters/drizzle.d.cts +2 -2
- package/dist/adapters/drizzle.d.mts +2 -2
- package/dist/adapters/drizzle.mjs +1 -3
- package/dist/adapters/drizzleExecutor.d.cts +1 -1
- package/dist/adapters/drizzleExecutor.d.mts +1 -1
- package/dist/adapters/kysely.cjs +4 -6
- package/dist/adapters/kysely.d.cts +3 -3
- package/dist/adapters/kysely.d.mts +3 -3
- package/dist/adapters/kysely.mjs +1 -3
- package/dist/adapters/kyselyExecutor.d.cts +1 -2
- package/dist/adapters/kyselyExecutor.d.mts +1 -2
- package/dist/adapters/mongodb.cjs +10 -21
- package/dist/adapters/mongodb.d.cts +1 -1
- package/dist/adapters/mongodb.d.mts +1 -1
- package/dist/adapters/mongodb.mjs +9 -20
- package/dist/adapters/mongodbAdapter.cjs +11 -11
- package/dist/adapters/mongodbAdapter.d.cts +1 -1
- package/dist/adapters/mongodbAdapter.d.mts +1 -1
- package/dist/adapters/mongodbAdapter.mjs +1 -1
- package/dist/adapters/prisma.cjs +7 -9
- package/dist/adapters/prisma.d.cts +1 -1
- package/dist/adapters/prisma.d.mts +1 -1
- package/dist/adapters/prisma.mjs +1 -3
- package/dist/adapters/prismaExecutor.cjs +2 -3
- package/dist/adapters/prismaExecutor.mjs +1 -2
- package/dist/adapters/sqlProviders.cjs +7 -2
- package/dist/adapters/sqlProviders.mjs +6 -1
- package/dist/assembly/assemblePlugins.cjs +26 -48
- package/dist/assembly/assemblePlugins.d.cts +2 -5
- package/dist/assembly/assemblePlugins.d.mts +2 -5
- package/dist/assembly/assemblePlugins.mjs +19 -45
- package/dist/assembly/clientPlugins.cjs +6 -4
- package/dist/assembly/clientPlugins.mjs +2 -0
- package/dist/assembly/configError.d.cts +1 -6
- package/dist/assembly/configError.d.mts +1 -6
- package/dist/assembly/configError.mjs +1 -6
- package/dist/core/api.cjs +0 -40
- package/dist/core/api.d.cts +5 -16
- package/dist/core/api.d.mts +5 -16
- package/dist/core/api.mjs +1 -37
- package/dist/core/baseCandidates.cjs +0 -43
- package/dist/core/baseCandidates.mjs +2 -43
- package/dist/core/operations.cjs +13 -12
- package/dist/core/operations.mjs +6 -5
- package/dist/core/reads.cjs +4 -4
- package/dist/core/reads.d.cts +2 -41
- package/dist/core/reads.d.mts +2 -41
- package/dist/core/reads.mjs +3 -3
- package/dist/core/releases.cjs +6 -6
- package/dist/core/releases.mjs +1 -1
- package/dist/core/writes.cjs +2 -2
- package/dist/core/writes.mjs +1 -1
- package/dist/createHotUpdaterCore.cjs +39 -39
- package/dist/createHotUpdaterCore.d.cts +61 -8
- package/dist/createHotUpdaterCore.d.mts +61 -8
- package/dist/createHotUpdaterCore.mjs +35 -32
- package/dist/db/engineDrizzleSchema.cjs +3 -4
- package/dist/db/engineDrizzleSchema.mjs +1 -2
- package/dist/db/enginePrismaSchema.cjs +4 -5
- package/dist/db/enginePrismaSchema.d.cts +1 -1
- package/dist/db/enginePrismaSchema.d.mts +1 -1
- package/dist/db/enginePrismaSchema.mjs +1 -2
- package/dist/db/releaseCatalog.cjs +6 -6
- package/dist/db/releaseCatalog.mjs +1 -1
- package/dist/db/updateArtifacts.cjs +6 -6
- package/dist/db/updateArtifacts.mjs +1 -1
- package/dist/handler.cjs +3 -4
- package/dist/handler.mjs +1 -1
- package/dist/handlerAdminRoutes.cjs +1 -2
- package/dist/handlerAdminRoutes.mjs +1 -2
- package/dist/handlerVersionRoutes.cjs +2 -2
- package/dist/handlerVersionRoutes.mjs +2 -2
- package/dist/index.cjs +9 -2
- package/dist/index.d.cts +4 -3
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +2 -1
- package/dist/node.cjs +3 -6
- package/dist/node.d.cts +3 -3
- package/dist/node.d.mts +3 -3
- package/dist/node.mjs +4 -4
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugins/api-keys/index.cjs +8 -52
- package/dist/plugins/api-keys/index.d.cts +1 -84
- package/dist/plugins/api-keys/index.d.mts +1 -84
- package/dist/plugins/api-keys/index.mjs +2 -49
- package/dist/plugins/definePlugin.d.cts +2 -200
- package/dist/plugins/definePlugin.d.mts +2 -200
- package/dist/plugins/insights/index.cjs +7 -126
- package/dist/plugins/insights/index.d.cts +1 -398
- package/dist/plugins/insights/index.d.mts +1 -398
- package/dist/plugins/insights/index.mjs +2 -121
- package/dist/plugins/official.cjs +30 -0
- package/dist/plugins/official.mjs +29 -0
- package/dist/storageAccess.cjs +13 -10
- package/dist/storageAccess.mjs +13 -10
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.mts +1 -1
- package/package.json +15 -37
- package/dist/_virtual/_rolldown/runtime.cjs +0 -23
- package/dist/assembly/clientPlugins.d.cts +0 -16
- package/dist/assembly/clientPlugins.d.mts +0 -16
- package/dist/assembly/configError.cjs +0 -7
- package/dist/assembly/databasePlugins.cjs +0 -27
- package/dist/assembly/databasePlugins.d.cts +0 -43
- package/dist/assembly/databasePlugins.d.mts +0 -43
- package/dist/assembly/databasePlugins.mjs +0 -26
- package/dist/assembly/pluginCli.cjs +0 -125
- package/dist/assembly/pluginCli.d.cts +0 -59
- package/dist/assembly/pluginCli.d.mts +0 -59
- package/dist/assembly/pluginCli.mjs +0 -121
- package/dist/core/baseCandidates.d.cts +0 -17
- package/dist/core/baseCandidates.d.mts +0 -17
- package/dist/core/schema.cjs +0 -279
- package/dist/core/schema.d.cts +0 -307
- package/dist/core/schema.d.mts +0 -307
- package/dist/core/schema.mjs +0 -277
- package/dist/database/aggregateBatching.cjs +0 -626
- package/dist/database/aggregateBatching.d.cts +0 -10
- package/dist/database/aggregateBatching.d.mts +0 -10
- package/dist/database/aggregateBatching.mjs +0 -625
- package/dist/database/busy.cjs +0 -36
- package/dist/database/busy.d.cts +0 -12
- package/dist/database/busy.d.mts +0 -12
- package/dist/database/busy.mjs +0 -36
- package/dist/database/cursor.cjs +0 -44
- package/dist/database/cursor.d.cts +0 -7
- package/dist/database/cursor.d.mts +0 -7
- package/dist/database/cursor.mjs +0 -40
- package/dist/database/database.cjs +0 -63
- package/dist/database/database.d.cts +0 -136
- package/dist/database/database.d.mts +0 -136
- package/dist/database/database.mjs +0 -63
- package/dist/database/definitions.d.cts +0 -78
- package/dist/database/definitions.d.mts +0 -78
- package/dist/database/engine.cjs +0 -37
- package/dist/database/engine.d.cts +0 -41
- package/dist/database/engine.d.mts +0 -41
- package/dist/database/engine.mjs +0 -37
- package/dist/database/engineAggregates.cjs +0 -118
- package/dist/database/engineAggregates.mjs +0 -115
- package/dist/database/engineReads.cjs +0 -182
- package/dist/database/engineReads.d.cts +0 -35
- package/dist/database/engineReads.d.mts +0 -35
- package/dist/database/engineReads.mjs +0 -181
- package/dist/database/engineTransaction.cjs +0 -399
- package/dist/database/engineTransaction.d.cts +0 -26
- package/dist/database/engineTransaction.d.mts +0 -26
- package/dist/database/engineTransaction.mjs +0 -398
- package/dist/database/errors.cjs +0 -27
- package/dist/database/errors.d.cts +0 -21
- package/dist/database/errors.d.mts +0 -21
- package/dist/database/errors.mjs +0 -24
- package/dist/database/fence.cjs +0 -125
- package/dist/database/fence.d.cts +0 -42
- package/dist/database/fence.d.mts +0 -42
- package/dist/database/fence.mjs +0 -117
- package/dist/database/index.cjs +0 -136
- package/dist/database/index.d.cts +0 -18
- package/dist/database/index.d.mts +0 -18
- package/dist/database/index.mjs +0 -16
- package/dist/database/kv/kvAdapter.cjs +0 -285
- package/dist/database/kv/kvAdapter.d.cts +0 -109
- package/dist/database/kv/kvAdapter.d.mts +0 -109
- package/dist/database/kv/kvAdapter.mjs +0 -284
- package/dist/database/resolveSchema.cjs +0 -199
- package/dist/database/resolveSchema.d.cts +0 -42
- package/dist/database/resolveSchema.d.mts +0 -42
- package/dist/database/resolveSchema.mjs +0 -196
- package/dist/database/retention.cjs +0 -92
- package/dist/database/retention.mjs +0 -90
- package/dist/database/schema.cjs +0 -24
- package/dist/database/schema.d.cts +0 -90
- package/dist/database/schema.d.mts +0 -90
- package/dist/database/schema.mjs +0 -23
- package/dist/database/sql/sqlAdapter.cjs +0 -290
- package/dist/database/sql/sqlAdapter.d.cts +0 -46
- package/dist/database/sql/sqlAdapter.d.mts +0 -46
- package/dist/database/sql/sqlAdapter.mjs +0 -287
- package/dist/database/sql/sqlSchema.cjs +0 -171
- package/dist/database/sql/sqlSchema.d.cts +0 -8
- package/dist/database/sql/sqlSchema.d.mts +0 -8
- package/dist/database/sql/sqlSchema.mjs +0 -165
- package/dist/db/coreDatabase.cjs +0 -85
- package/dist/db/coreDatabase.d.cts +0 -57
- package/dist/db/coreDatabase.d.mts +0 -57
- package/dist/db/coreDatabase.mjs +0 -78
- package/dist/db/createBundleDiff.cjs +0 -144
- package/dist/db/createBundleDiff.d.cts +0 -17
- package/dist/db/createBundleDiff.d.mts +0 -17
- package/dist/db/createBundleDiff.mjs +0 -141
- package/dist/db/engineMigrator.cjs +0 -53
- package/dist/db/engineMigrator.mjs +0 -53
- package/dist/db/engineSql.cjs +0 -26
- package/dist/db/engineSql.d.cts +0 -17
- package/dist/db/engineSql.d.mts +0 -17
- package/dist/db/engineSql.mjs +0 -25
- package/dist/db/engineSqlMigrator.cjs +0 -66
- package/dist/db/engineSqlMigrator.mjs +0 -66
- package/dist/db/fixedMigratorShared.cjs +0 -12
- package/dist/db/fixedMigratorShared.mjs +0 -11
- package/dist/db/index.cjs +0 -50
- package/dist/db/index.d.cts +0 -23
- package/dist/db/index.d.mts +0 -23
- package/dist/db/index.mjs +0 -33
- package/dist/db/releaseCatalog.d.cts +0 -16
- package/dist/db/releaseCatalog.d.mts +0 -16
- package/dist/db/schemaSettings.cjs +0 -63
- package/dist/db/schemaSettings.d.cts +0 -12
- package/dist/db/schemaSettings.d.mts +0 -12
- package/dist/db/schemaSettings.mjs +0 -62
- package/dist/db/settingsMigrator.cjs +0 -92
- package/dist/db/settingsMigrator.mjs +0 -89
- package/dist/db/types.cjs +0 -11
- package/dist/db/types.d.cts +0 -78
- package/dist/db/types.d.mts +0 -78
- package/dist/db/types.mjs +0 -10
- package/dist/diff.cjs +0 -3
- package/dist/diff.d.cts +0 -2
- package/dist/diff.d.mts +0 -2
- package/dist/diff.mjs +0 -2
- package/dist/plugins/api-keys/apiKeys.cjs +0 -139
- package/dist/plugins/api-keys/apiKeys.d.cts +0 -27
- package/dist/plugins/api-keys/apiKeys.d.mts +0 -27
- package/dist/plugins/api-keys/apiKeys.mjs +0 -129
- package/dist/plugins/api-keys/cli.cjs +0 -115
- package/dist/plugins/api-keys/cli.mjs +0 -114
- package/dist/plugins/api-keys/model.cjs +0 -58
- package/dist/plugins/api-keys/model.d.cts +0 -26
- package/dist/plugins/api-keys/model.d.mts +0 -26
- package/dist/plugins/api-keys/model.mjs +0 -58
- package/dist/plugins/api-keys/schema.cjs +0 -38
- package/dist/plugins/api-keys/schema.d.cts +0 -44
- package/dist/plugins/api-keys/schema.d.mts +0 -44
- package/dist/plugins/api-keys/schema.mjs +0 -39
- package/dist/plugins/definePlugin.cjs +0 -5
- package/dist/plugins/definePlugin.mjs +0 -5
- package/dist/plugins/index.cjs +0 -38
- package/dist/plugins/index.d.cts +0 -12
- package/dist/plugins/index.d.mts +0 -12
- package/dist/plugins/index.mjs +0 -9
- package/dist/plugins/insights/contract.cjs +0 -193
- package/dist/plugins/insights/contract.mjs +0 -189
- package/dist/plugins/insights/domain.d.cts +0 -149
- package/dist/plugins/insights/domain.d.mts +0 -149
- package/dist/plugins/insights/errors.cjs +0 -15
- package/dist/plugins/insights/errors.mjs +0 -14
- package/dist/plugins/insights/eventInput.cjs +0 -284
- package/dist/plugins/insights/eventInput.mjs +0 -282
- package/dist/plugins/insights/eventRow.cjs +0 -49
- package/dist/plugins/insights/eventRow.d.cts +0 -64
- package/dist/plugins/insights/eventRow.d.mts +0 -64
- package/dist/plugins/insights/eventRow.mjs +0 -47
- package/dist/plugins/insights/model.cjs +0 -17
- package/dist/plugins/insights/model.d.cts +0 -10
- package/dist/plugins/insights/model.d.mts +0 -10
- package/dist/plugins/insights/model.mjs +0 -17
- package/dist/plugins/insights/modelTypes.d.cts +0 -176
- package/dist/plugins/insights/modelTypes.d.mts +0 -176
- package/dist/plugins/insights/overview.cjs +0 -109
- package/dist/plugins/insights/overview.d.cts +0 -15
- package/dist/plugins/insights/overview.d.mts +0 -15
- package/dist/plugins/insights/overview.mjs +0 -107
- package/dist/plugins/insights/provider.cjs +0 -375
- package/dist/plugins/insights/provider.d.cts +0 -6
- package/dist/plugins/insights/provider.d.mts +0 -6
- package/dist/plugins/insights/provider.mjs +0 -374
- package/dist/plugins/insights/queryInput.cjs +0 -93
- package/dist/plugins/insights/queryInput.mjs +0 -91
- package/dist/plugins/insights/reads.cjs +0 -681
- package/dist/plugins/insights/reads.d.cts +0 -61
- package/dist/plugins/insights/reads.d.mts +0 -61
- package/dist/plugins/insights/reads.mjs +0 -674
- package/dist/plugins/insights/recordEvent.cjs +0 -319
- package/dist/plugins/insights/recordEvent.d.cts +0 -18
- package/dist/plugins/insights/recordEvent.d.mts +0 -18
- package/dist/plugins/insights/recordEvent.mjs +0 -316
- package/dist/plugins/insights/routes.cjs +0 -96
- package/dist/plugins/insights/routes.mjs +0 -95
- package/dist/plugins/insights/schema.cjs +0 -489
- package/dist/plugins/insights/schema.d.cts +0 -698
- package/dist/plugins/insights/schema.d.mts +0 -698
- package/dist/plugins/insights/schema.mjs +0 -483
- package/dist/plugins/insights/testing/eventRow.d.mts +0 -64
- package/dist/plugins/insights/testing/expectInsightsIndex.mjs +0 -18
- package/dist/plugins/insights/testing/fixtures.d.mts +0 -8
- package/dist/plugins/insights/testing/fixtures.mjs +0 -25
- package/dist/plugins/insights/testing/index.d.mts +0 -24
- package/dist/plugins/insights/testing/index.mjs +0 -25
- package/dist/plugins/insights/testing/insightsModelTests.mjs +0 -714
- package/dist/plugins/insights/testing/modelTypes.d.mts +0 -176
- package/dist/plugins/insights/testing/setupInsightsHttpTestSuite.d.mts +0 -11
- package/dist/plugins/insights/testing/setupInsightsHttpTestSuite.mjs +0 -107
- package/dist/plugins/insights/testing/setupInsightsModelTestSuite.d.mts +0 -11
- package/dist/plugins/insights/testing/setupInsightsModelTestSuite.mjs +0 -31
- package/dist/plugins/insights/testing/types.d.mts +0 -26
- package/dist/plugins/insights/types.d.cts +0 -33
- package/dist/plugins/insights/types.d.mts +0 -33
- package/src/adapters/drizzle.conformance.integration.spec.ts +0 -34
- package/src/adapters/drizzle.readBudgets.integration.spec.ts +0 -43
- package/src/adapters/drizzle.spec.ts +0 -314
- package/src/adapters/drizzle.ts +0 -64
- package/src/adapters/drizzleExecutor.ts +0 -166
- package/src/adapters/kysely.conformance.integration.spec.ts +0 -36
- package/src/adapters/kysely.readBudgets.integration.spec.ts +0 -44
- package/src/adapters/kysely.spec.ts +0 -244
- package/src/adapters/kysely.ts +0 -46
- package/src/adapters/kyselyExecutor.ts +0 -53
- package/src/adapters/mongodb.integration.spec.ts +0 -271
- package/src/adapters/mongodb.readBudgets.integration.spec.ts +0 -61
- package/src/adapters/mongodb.ts +0 -45
- package/src/adapters/mongodbAdapter.ts +0 -307
- package/src/adapters/prisma.conformance.integration.spec.ts +0 -36
- package/src/adapters/prisma.integration.spec.ts +0 -146
- package/src/adapters/prisma.readBudgets.integration.spec.ts +0 -43
- package/src/adapters/prisma.spec.ts +0 -257
- package/src/adapters/prisma.ts +0 -74
- package/src/adapters/prismaExecutor.ts +0 -107
- package/src/adapters/prismaTestClients.ts +0 -182
- package/src/adapters/sqlProviders.ts +0 -14
- package/src/assembly/assemblePlugins.ts +0 -302
- package/src/assembly/assembly.spec.ts +0 -377
- package/src/assembly/assembly.types.spec.ts +0 -203
- package/src/assembly/clientPlugins.ts +0 -113
- package/src/assembly/configError.ts +0 -4
- package/src/assembly/databasePlugins.spec.ts +0 -71
- package/src/assembly/databasePlugins.ts +0 -102
- package/src/assembly/pluginCli.spec.ts +0 -254
- package/src/assembly/pluginCli.ts +0 -248
- package/src/assembly/pluginRoutes.spec.ts +0 -186
- package/src/core/api.ts +0 -139
- package/src/core/baseCandidates.spec.ts +0 -378
- package/src/core/baseCandidates.ts +0 -136
- package/src/core/index.ts +0 -44
- package/src/core/operations.spec.ts +0 -415
- package/src/core/operations.ts +0 -551
- package/src/core/reads.spec.ts +0 -300
- package/src/core/reads.ts +0 -417
- package/src/core/releases.spec.ts +0 -308
- package/src/core/releases.ts +0 -345
- package/src/core/schema.ts +0 -173
- package/src/core/writes.ts +0 -160
- package/src/createHotUpdaterCore.ts +0 -260
- package/src/database/aggregateBatching.spec.ts +0 -577
- package/src/database/aggregateBatching.ts +0 -803
- package/src/database/busy.spec.ts +0 -45
- package/src/database/busy.ts +0 -50
- package/src/database/cursor.ts +0 -65
- package/src/database/database.ts +0 -366
- package/src/database/database.types.spec.ts +0 -135
- package/src/database/definitions.ts +0 -76
- package/src/database/engine.ts +0 -62
- package/src/database/engineAggregates.spec.ts +0 -536
- package/src/database/engineAggregates.ts +0 -189
- package/src/database/engineReads.spec.ts +0 -219
- package/src/database/engineReads.ts +0 -304
- package/src/database/engineTransaction.spec.ts +0 -710
- package/src/database/engineTransaction.ts +0 -582
- package/src/database/errors.ts +0 -30
- package/src/database/fence.spec.ts +0 -223
- package/src/database/fence.ts +0 -175
- package/src/database/index.ts +0 -160
- package/src/database/kv/kvAdapter.batching.integration.spec.ts +0 -15
- package/src/database/kv/kvAdapter.conformance.integration.spec.ts +0 -19
- package/src/database/kv/kvAdapter.readBudgets.integration.spec.ts +0 -17
- package/src/database/kv/kvAdapter.spec.ts +0 -595
- package/src/database/kv/kvAdapter.ts +0 -479
- package/src/database/kv/kvTestStore.ts +0 -118
- package/src/database/memory.readBudgets.integration.spec.ts +0 -13
- package/src/database/resolveSchema.spec.ts +0 -230
- package/src/database/resolveSchema.ts +0 -375
- package/src/database/retention.spec.ts +0 -314
- package/src/database/retention.ts +0 -129
- package/src/database/schema.ts +0 -213
- package/src/database/schema.types.spec.ts +0 -94
- package/src/database/sql/docker-compose.yml +0 -36
- package/src/database/sql/sqlAdapter.integration.spec.ts +0 -145
- package/src/database/sql/sqlAdapter.readBudgets.integration.spec.ts +0 -123
- package/src/database/sql/sqlAdapter.spec.ts +0 -343
- package/src/database/sql/sqlAdapter.ts +0 -552
- package/src/database/sql/sqlSchema.ts +0 -286
- package/src/database/sql/sqlTestExecutors.ts +0 -183
- package/src/databaseTestSuite.spec.ts +0 -44
- package/src/db/bundleRows.spec.ts +0 -164
- package/src/db/bundleRows.ts +0 -10
- package/src/db/coreDatabase.ts +0 -153
- package/src/db/createBundleDiff.spec.ts +0 -464
- package/src/db/createBundleDiff.ts +0 -370
- package/src/db/engineDrizzleSchema.ts +0 -72
- package/src/db/engineMigrator.ts +0 -105
- package/src/db/enginePrismaSchema.ts +0 -147
- package/src/db/engineSql.spec.ts +0 -130
- package/src/db/engineSql.ts +0 -48
- package/src/db/engineSqlMigrator.ts +0 -116
- package/src/db/fixedMigratorShared.ts +0 -17
- package/src/db/index.spec.ts +0 -554
- package/src/db/index.ts +0 -93
- package/src/db/node-sqlite.d.ts +0 -25
- package/src/db/pluginTables.spec.ts +0 -248
- package/src/db/releaseCatalog.ts +0 -106
- package/src/db/schemaSettings.ts +0 -104
- package/src/db/settingsMigrator.spec.ts +0 -65
- package/src/db/settingsMigrator.ts +0 -152
- package/src/db/types.ts +0 -82
- package/src/db/updateArtifacts.spec.ts +0 -235
- package/src/db/updateArtifacts.ts +0 -473
- package/src/db/updateCheck.bench.ts +0 -47
- package/src/diff.ts +0 -6
- package/src/handler-standalone.integration.spec.ts +0 -321
- package/src/handler.spec.ts +0 -273
- package/src/handler.testFixtures.ts +0 -25
- package/src/handler.ts +0 -302
- package/src/handlerAdminRoutes.spec.ts +0 -183
- package/src/handlerAdminRoutes.ts +0 -536
- package/src/handlerAuth.integration.spec.ts +0 -33
- package/src/handlerErrors.ts +0 -7
- package/src/handlerManagement.spec.ts +0 -202
- package/src/handlerParameters.ts +0 -105
- package/src/handlerReleaseCatalogRoutes.ts +0 -176
- package/src/handlerTypes.ts +0 -19
- package/src/handlerVersionRoutes.ts +0 -25
- package/src/index.ts +0 -13
- package/src/internalRouter.ts +0 -104
- package/src/lintRules.spec.ts +0 -76
- package/src/node.spec.ts +0 -119
- package/src/node.ts +0 -111
- package/src/plugins/api-keys/apiKeys.integration.spec.ts +0 -92
- package/src/plugins/api-keys/apiKeys.spec.ts +0 -166
- package/src/plugins/api-keys/apiKeys.ts +0 -214
- package/src/plugins/api-keys/apiKeysPlugin.spec.ts +0 -168
- package/src/plugins/api-keys/cli.spec.ts +0 -187
- package/src/plugins/api-keys/cli.ts +0 -140
- package/src/plugins/api-keys/index.ts +0 -73
- package/src/plugins/api-keys/model.ts +0 -88
- package/src/plugins/api-keys/schema.ts +0 -22
- package/src/plugins/definePlugin.ts +0 -242
- package/src/plugins/index.ts +0 -73
- package/src/plugins/insights/contract.spec.ts +0 -285
- package/src/plugins/insights/contract.ts +0 -372
- package/src/plugins/insights/domain.ts +0 -176
- package/src/plugins/insights/errors.ts +0 -11
- package/src/plugins/insights/eventInput.ts +0 -381
- package/src/plugins/insights/eventRow.ts +0 -209
- package/src/plugins/insights/index.ts +0 -222
- package/src/plugins/insights/insights.integration.spec.ts +0 -921
- package/src/plugins/insights/insightsRollout.integration.spec.ts +0 -186
- package/src/plugins/insights/model.spec.ts +0 -64
- package/src/plugins/insights/model.ts +0 -18
- package/src/plugins/insights/modelTypes.ts +0 -197
- package/src/plugins/insights/overview.spec.ts +0 -64
- package/src/plugins/insights/overview.ts +0 -214
- package/src/plugins/insights/provider.spec.ts +0 -585
- package/src/plugins/insights/provider.ts +0 -704
- package/src/plugins/insights/queryInput.ts +0 -142
- package/src/plugins/insights/reads.spec.ts +0 -1013
- package/src/plugins/insights/reads.ts +0 -1037
- package/src/plugins/insights/recordEvent.spec.ts +0 -897
- package/src/plugins/insights/recordEvent.ts +0 -476
- package/src/plugins/insights/retention.spec.ts +0 -115
- package/src/plugins/insights/routes.ts +0 -149
- package/src/plugins/insights/schema.ts +0 -409
- package/src/plugins/insights/testing/expectInsightsIndex.spec.ts +0 -42
- package/src/plugins/insights/testing/expectInsightsIndex.ts +0 -20
- package/src/plugins/insights/testing/fixtures.ts +0 -30
- package/src/plugins/insights/testing/index.ts +0 -45
- package/src/plugins/insights/testing/insightsModelTests.ts +0 -860
- package/src/plugins/insights/testing/setupInsightsHttpTestSuite.ts +0 -152
- package/src/plugins/insights/testing/setupInsightsModelTestSuite.ts +0 -36
- package/src/plugins/insights/testing/types.ts +0 -30
- package/src/plugins/insights/types.ts +0 -55
- package/src/plugins/pluginTestHarness.spec.ts +0 -56
- package/src/readBudgets.testFixtures.ts +0 -15
- package/src/releaseCatalogRoutes.integration.spec.ts +0 -200
- package/src/retention.spec.ts +0 -73
- package/src/runtime.spec.ts +0 -207
- package/src/runtime.testFixtures.ts +0 -60
- package/src/runtimeBundles.integration.spec.ts +0 -112
- package/src/storageAccess.spec.ts +0 -152
- package/src/storageAccess.ts +0 -141
- package/src/testUtilsMutation.integration.spec.ts +0 -216
- package/src/testUtilsPackage.integration.spec.ts +0 -180
- package/src/types/index.ts +0 -2
- package/src/version.ts +0 -3
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
import { DATABASE_VERSION_COLUMN, DatabaseAdapterContractError, canonicalJson, compareUtf8, expiresAt, findPhysicalIndex, indexEntries, indexOrderColumns, indexOrderTuple, matchesQuery, rowKey } from "@hot-updater/plugin-core/internal";
|
|
2
|
-
//#region src/database/kv/kvAdapter.ts
|
|
3
|
-
const SEPARATOR = "";
|
|
4
|
-
/** Order-preserving text for key values; each value ends in the lowest code point any encoding uses. */
|
|
5
|
-
const encodeKvKey = (values) => values.map((value) => {
|
|
6
|
-
if (typeof value === "boolean") return `${Number(value)}${SEPARATOR}`;
|
|
7
|
-
if (typeof value === "number") {
|
|
8
|
-
const view = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(8));
|
|
9
|
-
view.setFloat64(0, value === 0 ? 0 : value);
|
|
10
|
-
const mask = view.getUint32(0) >>> 31 ? [-1, -1] : [1 << 31, 0];
|
|
11
|
-
return `${[0, 4].map((at, word) => ((view.getUint32(at) ^ mask[word]) >>> 0).toString(16).padStart(8, "0")).join("")}${SEPARATOR}`;
|
|
12
|
-
}
|
|
13
|
-
let text = "";
|
|
14
|
-
for (const char of value) text += char < "" ? `\u0002${String.fromCharCode(char.charCodeAt(0) + 1)}` : char;
|
|
15
|
-
return `${text}${SEPARATOR}`;
|
|
16
|
-
}).join("");
|
|
17
|
-
/** The first sort key after every key that starts with `prefix`. */
|
|
18
|
-
const pastPrefix = (prefix) => `${prefix.slice(0, -1)}\u0002`;
|
|
19
|
-
/** A unique item's sort key, and an index item's when its order is empty. */
|
|
20
|
-
const ONLY = "#";
|
|
21
|
-
/** An index whose eq and order columns are the key, in order, reads the row items. */
|
|
22
|
-
const inKeyOrder = (table, index) => {
|
|
23
|
-
const columns = [...index.eq, ...indexOrderColumns(table, index)];
|
|
24
|
-
return !index.unique && columns.length === table.key.length && columns.every((column, position) => column === table.key[position]);
|
|
25
|
-
};
|
|
26
|
-
const same = (left, right, columns) => columns.every((name) => canonicalJson(left[name]) === canonicalJson(right[name]));
|
|
27
|
-
/**
|
|
28
|
-
* The storage adapter over a key-value store. A row is one item at
|
|
29
|
-
* `pk = <table>`, `sk = enc(key)`; each index not in key order adds an item
|
|
30
|
-
* per entry at `pk = <table>#<index>#enc(eq)`, `sk = enc(order)`, and each
|
|
31
|
-
* unique entry one item at `sk = "#"`, written only where no other row holds
|
|
32
|
-
* it. Index items hold a copy of the row without `_v` or counters, so an
|
|
33
|
-
* increment, which changes only those, never makes them stale.
|
|
34
|
-
*/
|
|
35
|
-
const createKvAdapter = ({ store, tablePrefix = "" }) => {
|
|
36
|
-
const layouts = /* @__PURE__ */ new WeakMap();
|
|
37
|
-
const layoutOf = (table) => {
|
|
38
|
-
const known = layouts.get(table);
|
|
39
|
-
if (known) return known;
|
|
40
|
-
const counters = table.columns.filter((column) => column.default !== void 0 && column.name !== DATABASE_VERSION_COLUMN).map((column) => column.name);
|
|
41
|
-
const layout = {
|
|
42
|
-
table,
|
|
43
|
-
rows: tablePrefix + table.name,
|
|
44
|
-
copied: table.columns.map((column) => column.name).filter((name) => name !== DATABASE_VERSION_COLUMN && !counters.includes(name)),
|
|
45
|
-
counters,
|
|
46
|
-
indexed: table.indexes.filter((index) => !inKeyOrder(table, index))
|
|
47
|
-
};
|
|
48
|
-
layouts.set(table, layout);
|
|
49
|
-
return layout;
|
|
50
|
-
};
|
|
51
|
-
const rowItem = (layout, key) => ({
|
|
52
|
-
pk: layout.rows,
|
|
53
|
-
sk: encodeKvKey(key)
|
|
54
|
-
});
|
|
55
|
-
const partition = (layout, index, eq) => `${layout.rows}#${index.name}#${encodeKvKey(eq)}`;
|
|
56
|
-
const copyOf = (layout, row) => Object.fromEntries(layout.copied.map((name) => [name, row[name] ?? null]));
|
|
57
|
-
/** The expiry every item of `row` carries, for a table with retention. */
|
|
58
|
-
const stamp = (table, row) => {
|
|
59
|
-
const at = row && expiresAt(table, row);
|
|
60
|
-
return at === void 0 ? {} : { expiresAt: at };
|
|
61
|
-
};
|
|
62
|
-
/** Every index and unique item a row has, by address. */
|
|
63
|
-
const itemsOf = (layout, row) => {
|
|
64
|
-
const items = /* @__PURE__ */ new Map();
|
|
65
|
-
for (const index of row === null ? [] : layout.indexed) for (const eq of indexEntries(layout.table, index, row)) {
|
|
66
|
-
const pk = partition(layout, index, eq);
|
|
67
|
-
const sk = index.unique ? ONLY : encodeKvKey(indexOrderTuple(layout.table, index, row)) || ONLY;
|
|
68
|
-
items.set(JSON.stringify([pk, sk]), {
|
|
69
|
-
key: {
|
|
70
|
-
pk,
|
|
71
|
-
sk
|
|
72
|
-
},
|
|
73
|
-
unique: index.unique === true
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
return items;
|
|
77
|
-
};
|
|
78
|
-
/** Moves a row's index items from `before` to `after`; a unique entry is taken only where no row holds it. */
|
|
79
|
-
const indexOps = (layout, before, after) => {
|
|
80
|
-
const old = itemsOf(layout, before);
|
|
81
|
-
const next = itemsOf(layout, after);
|
|
82
|
-
const ops = [...old].filter(([id]) => !next.has(id)).map(([, item]) => ({
|
|
83
|
-
type: "delete",
|
|
84
|
-
key: item.key
|
|
85
|
-
}));
|
|
86
|
-
const copy = after && copyOf(layout, after);
|
|
87
|
-
const unchanged = before !== null && copy !== null && same(before, copy, layout.copied);
|
|
88
|
-
for (const [id, item] of next) {
|
|
89
|
-
if (old.has(id) && unchanged) continue;
|
|
90
|
-
const taken = item.unique && !old.has(id);
|
|
91
|
-
ops.push({
|
|
92
|
-
type: "put",
|
|
93
|
-
key: item.key,
|
|
94
|
-
value: copy,
|
|
95
|
-
condition: taken ? { exists: false } : void 0,
|
|
96
|
-
...stamp(layout.table, after)
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
return ops;
|
|
100
|
-
};
|
|
101
|
-
/** The item ops of one adapter op: its row item first, then its index items. */
|
|
102
|
-
const plan = (op) => {
|
|
103
|
-
const layout = layoutOf(op.table);
|
|
104
|
-
const key = rowItem(layout, op.type === "insert" ? rowKey(op.table, op.row) : op.key);
|
|
105
|
-
const guard = op.type === "insert" ? { exists: false } : op.guard;
|
|
106
|
-
const condition = guard && ("v" in guard ? { v: guard.v } : guard);
|
|
107
|
-
switch (op.type) {
|
|
108
|
-
case "check": return [{
|
|
109
|
-
type: "check",
|
|
110
|
-
key,
|
|
111
|
-
condition
|
|
112
|
-
}];
|
|
113
|
-
case "increment":
|
|
114
|
-
if (layout.indexed.length > 0 && (op.init !== void 0 || Object.keys(op.by).some((name) => layout.copied.includes(name)))) throw new DatabaseAdapterContractError(`${op.table.name} has index copies: an increment may change only counters of an existing row.`);
|
|
115
|
-
return [{
|
|
116
|
-
type: "add",
|
|
117
|
-
key,
|
|
118
|
-
by: {
|
|
119
|
-
...op.by,
|
|
120
|
-
[DATABASE_VERSION_COLUMN]: 1
|
|
121
|
-
},
|
|
122
|
-
init: op.init,
|
|
123
|
-
condition: condition ?? (op.init ? void 0 : { exists: true }),
|
|
124
|
-
...stamp(op.table, op.init)
|
|
125
|
-
}];
|
|
126
|
-
case "delete": return [{
|
|
127
|
-
type: "delete",
|
|
128
|
-
key,
|
|
129
|
-
condition
|
|
130
|
-
}, ...indexOps(layout, op.previous, null)];
|
|
131
|
-
default: {
|
|
132
|
-
const before = op.type === "insert" ? null : op.previous;
|
|
133
|
-
const row = op.type === "insert" ? op.row : {
|
|
134
|
-
...op.previous,
|
|
135
|
-
...op.set,
|
|
136
|
-
[DATABASE_VERSION_COLUMN]: op.guard.v + 1
|
|
137
|
-
};
|
|
138
|
-
return [{
|
|
139
|
-
type: "put",
|
|
140
|
-
key,
|
|
141
|
-
value: row,
|
|
142
|
-
condition,
|
|
143
|
-
...stamp(op.table, row)
|
|
144
|
-
}, ...indexOps(layout, before, row)];
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
/**
|
|
149
|
-
* One op per item. Only unique items of two rows can meet: one op frees
|
|
150
|
-
* the value and another takes it. That becomes one unconditional put, as
|
|
151
|
-
* the freeing op's guard already holds the value's owner. Two rows taking
|
|
152
|
-
* one value fail at the later op.
|
|
153
|
-
*/
|
|
154
|
-
const compile = (ops) => {
|
|
155
|
-
const items = /* @__PURE__ */ new Map();
|
|
156
|
-
for (const [origin, op] of ops.entries()) for (const kv of plan(op)) {
|
|
157
|
-
const id = JSON.stringify([kv.key.pk, kv.key.sk]);
|
|
158
|
-
const earlier = items.get(id);
|
|
159
|
-
const put = [earlier, {
|
|
160
|
-
op: kv,
|
|
161
|
-
origin
|
|
162
|
-
}].find((planned) => planned?.op.type === "put");
|
|
163
|
-
if (earlier === void 0) items.set(id, {
|
|
164
|
-
op: kv,
|
|
165
|
-
origin
|
|
166
|
-
});
|
|
167
|
-
else if (put?.op.type === "put" && [earlier.op, kv].some(({ type }) => type === "delete")) items.set(id, {
|
|
168
|
-
op: {
|
|
169
|
-
...put.op,
|
|
170
|
-
condition: void 0
|
|
171
|
-
},
|
|
172
|
-
origin
|
|
173
|
-
});
|
|
174
|
-
else return { failedOp: origin };
|
|
175
|
-
}
|
|
176
|
-
return { items: [...items.values()] };
|
|
177
|
-
};
|
|
178
|
-
const encoder = new TextEncoder();
|
|
179
|
-
const sizeOf = ({ op }) => encoder.encode(op.key.pk + op.key.sk + JSON.stringify(op.type === "put" ? op.value : op.type === "add" ? op.init : null)).length;
|
|
180
|
-
/** Fills counters from the rows; a row that still equals its copy is returned whole, `_v` included. */
|
|
181
|
-
const complete = async (layout, copies) => {
|
|
182
|
-
if (layout.counters.length === 0 || copies.length === 0) return copies;
|
|
183
|
-
const rows = await store.get(copies.map((copy) => rowItem(layout, rowKey(layout.table, copy))));
|
|
184
|
-
return copies.map((copy, at) => {
|
|
185
|
-
const row = rows[at];
|
|
186
|
-
if (row && same(row, copy, layout.copied)) return row;
|
|
187
|
-
const counters = layout.counters.map((name) => [name, row?.[name] ?? 0]);
|
|
188
|
-
return {
|
|
189
|
-
...copy,
|
|
190
|
-
...Object.fromEntries(counters)
|
|
191
|
-
};
|
|
192
|
-
});
|
|
193
|
-
};
|
|
194
|
-
/**
|
|
195
|
-
* A request's sort keys within its partition, from `gte` up to `lt`; null
|
|
196
|
-
* when none can match. Every encoding ends in the separator, so the keys
|
|
197
|
-
* that start with a prefix end right before `pastPrefix` of it.
|
|
198
|
-
*/
|
|
199
|
-
const rangeOf = (prefix, request) => {
|
|
200
|
-
const edge = (bound, lower) => {
|
|
201
|
-
if (bound === void 0) return prefix === "" ? void 0 : lower ? prefix : pastPrefix(prefix);
|
|
202
|
-
const text = prefix + encodeKvKey(bound.values);
|
|
203
|
-
if (text === "") return bound.inclusive ? void 0 : null;
|
|
204
|
-
return lower === bound.inclusive ? text : pastPrefix(text);
|
|
205
|
-
};
|
|
206
|
-
const gte = edge(request.lower, true);
|
|
207
|
-
const lt = edge(request.upper, false);
|
|
208
|
-
if (gte === null || lt === null) return null;
|
|
209
|
-
if (gte !== void 0 && lt !== void 0 && compareUtf8(gte, lt) >= 0) return null;
|
|
210
|
-
if (lt === void 0) return {
|
|
211
|
-
gte,
|
|
212
|
-
lt
|
|
213
|
-
};
|
|
214
|
-
return {
|
|
215
|
-
gte,
|
|
216
|
-
lt,
|
|
217
|
-
lte: lt.endsWith(SEPARATOR) ? lt.slice(0, -1) : lt
|
|
218
|
-
};
|
|
219
|
-
};
|
|
220
|
-
return {
|
|
221
|
-
id: store.id,
|
|
222
|
-
fits(ops) {
|
|
223
|
-
const { items } = compile(ops);
|
|
224
|
-
if (items === void 0) return true;
|
|
225
|
-
const { items: most, bytes, itemBytes = bytes, keyBytes } = store.limits;
|
|
226
|
-
const sizes = items.map(sizeOf);
|
|
227
|
-
const length = (text) => encoder.encode(text).length;
|
|
228
|
-
return items.length <= most && sizes.reduce((sum, size) => sum + size, 0) <= bytes && sizes.every((size) => size <= itemBytes) && (keyBytes === void 0 || items.every(({ op }) => length(op.key.pk) <= keyBytes.pk && length(op.key.sk) <= keyBytes.sk));
|
|
229
|
-
},
|
|
230
|
-
get: (table, keys) => store.get(keys.map((key) => rowItem(layoutOf(table), key))),
|
|
231
|
-
async query(table, request) {
|
|
232
|
-
const layout = layoutOf(table);
|
|
233
|
-
const index = findPhysicalIndex(table, request.index);
|
|
234
|
-
if (index.unique) {
|
|
235
|
-
const key = {
|
|
236
|
-
pk: partition(layout, index, request.eq),
|
|
237
|
-
sk: ONLY
|
|
238
|
-
};
|
|
239
|
-
const [copy] = await store.get([key]);
|
|
240
|
-
const found = copy && matchesQuery(table, index, request, copy);
|
|
241
|
-
return complete(layout, found ? [copy] : []);
|
|
242
|
-
}
|
|
243
|
-
const own = inKeyOrder(table, index);
|
|
244
|
-
const range = rangeOf(own ? encodeKvKey(request.eq) : "", request);
|
|
245
|
-
if (range === null) return [];
|
|
246
|
-
const pk = own ? layout.rows : partition(layout, index, request.eq);
|
|
247
|
-
const rows = [];
|
|
248
|
-
let after;
|
|
249
|
-
while (rows.length < request.limit) {
|
|
250
|
-
const { items, more } = await store.query({
|
|
251
|
-
pk,
|
|
252
|
-
...range,
|
|
253
|
-
order: request.order,
|
|
254
|
-
limit: request.limit - rows.length,
|
|
255
|
-
after
|
|
256
|
-
});
|
|
257
|
-
rows.push(...items.map((item) => item.value));
|
|
258
|
-
if (!more || items.length === 0) break;
|
|
259
|
-
after = items.at(-1).sk;
|
|
260
|
-
}
|
|
261
|
-
return own ? rows : complete(layout, rows);
|
|
262
|
-
},
|
|
263
|
-
async write(ops) {
|
|
264
|
-
const { items, failedOp } = compile(ops);
|
|
265
|
-
if (items === void 0) return {
|
|
266
|
-
ok: false,
|
|
267
|
-
failedOp
|
|
268
|
-
};
|
|
269
|
-
const result = await store.write(items.map(({ op }) => op));
|
|
270
|
-
return !result.ok && "failedOp" in result ? {
|
|
271
|
-
ok: false,
|
|
272
|
-
failedOp: items[result.failedOp].origin
|
|
273
|
-
} : result;
|
|
274
|
-
},
|
|
275
|
-
...store.deleteConsumed === void 0 ? {} : { deleteConsumed: (table, rows) => {
|
|
276
|
-
const layout = layoutOf(table);
|
|
277
|
-
return store.deleteConsumed(rows.flatMap((row) => [rowItem(layout, rowKey(table, row)), ...[...itemsOf(layout, row).values()].map(({ key }) => key)]));
|
|
278
|
-
} },
|
|
279
|
-
migrations: { apply: async () => store.migrations?.apply() },
|
|
280
|
-
...store.dispose === void 0 ? {} : { dispose: () => store.dispose() }
|
|
281
|
-
};
|
|
282
|
-
};
|
|
283
|
-
//#endregion
|
|
284
|
-
export { createKvAdapter, encodeKvKey };
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
const require_retention = require("./retention.cjs");
|
|
2
|
-
let _hot_updater_plugin_core_internal = require("@hot-updater/plugin-core/internal");
|
|
3
|
-
//#region src/database/resolveSchema.ts
|
|
4
|
-
const SHARD_COLUMN = "_shard";
|
|
5
|
-
const MAX_SHARDS = 64;
|
|
6
|
-
const NAME = /^[a-z][a-z0-9_]*$/u;
|
|
7
|
-
const INDEX_NAME = /^[A-Za-z][A-Za-z0-9_]*$/u;
|
|
8
|
-
const tableName = (module, model) => module.namespace ? `${module.namespace}_${model}` : model;
|
|
9
|
-
const integer = (name, defaulted = false) => ({
|
|
10
|
-
name,
|
|
11
|
-
type: "integer",
|
|
12
|
-
nullable: false,
|
|
13
|
-
...defaulted ? { default: 0 } : {}
|
|
14
|
-
});
|
|
15
|
-
/** A declared or derived field's type, and whether it holds several values. */
|
|
16
|
-
const fieldType = (model, name) => {
|
|
17
|
-
const field = model.fields[name] ?? (model.kind === "table" ? model.derived[name] : void 0);
|
|
18
|
-
return field && {
|
|
19
|
-
type: field.type,
|
|
20
|
-
multi: "multi" in field && !!field.multi
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
const metricsOf = (model) => [
|
|
24
|
-
...model.counters,
|
|
25
|
-
...model.gauges,
|
|
26
|
-
...model.distinct
|
|
27
|
-
];
|
|
28
|
-
/** Field names, the key, and each field's options. */
|
|
29
|
-
const fieldProblems = (definition, add) => {
|
|
30
|
-
const names = [...Object.keys(definition.fields), ...definition.kind === "table" ? Object.keys(definition.derived) : metricsOf(definition)];
|
|
31
|
-
for (const name of new Set(names)) {
|
|
32
|
-
if (!NAME.test(name)) add(`field "${name}" must match ${NAME.source}`);
|
|
33
|
-
if (names.indexOf(name) !== names.lastIndexOf(name)) add(`field "${name}" is declared twice`);
|
|
34
|
-
}
|
|
35
|
-
const { key } = definition;
|
|
36
|
-
if (key.length === 0) add("key is empty");
|
|
37
|
-
if (new Set(key).size !== key.length) add("key repeats a field");
|
|
38
|
-
for (const name of key) {
|
|
39
|
-
const field = definition.fields[name];
|
|
40
|
-
if (field === void 0) add(`key field "${name}" is not a declared field`);
|
|
41
|
-
else if (field.required === false) add(`key field "${name}" is nullable`);
|
|
42
|
-
else if (field.type === "json") add(`key field "${name}" is json`);
|
|
43
|
-
}
|
|
44
|
-
for (const [name, { type, maxLength, ascii }] of Object.entries(definition.fields)) {
|
|
45
|
-
if (maxLength !== void 0 && (type !== "string" || !Number.isSafeInteger(maxLength) || maxLength < 1)) add(`field "${name}" has an invalid maxLength`);
|
|
46
|
-
if (ascii && type !== "string") add(`field "${name}" is ascii but not a string`);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
/** A table's derived fields and references. */
|
|
50
|
-
const tableProblems = (definition, add, table) => {
|
|
51
|
-
for (const [name, derived] of Object.entries(definition.derived)) {
|
|
52
|
-
if (typeof derived.compute !== "function") add(`derived field "${name}" has no compute function`);
|
|
53
|
-
if (derived.multi && derived.type === "json") add(`derived field "${name}" cannot be multi-valued json`);
|
|
54
|
-
}
|
|
55
|
-
for (const [name, { type, references }] of Object.entries(definition.fields)) {
|
|
56
|
-
if (references === void 0) continue;
|
|
57
|
-
const target = table(references.model);
|
|
58
|
-
const targetKey = target?.key.length === 1 ? target.fields[target.key[0]] : void 0;
|
|
59
|
-
if (targetKey === void 0) add(`field "${name}" references "${references.model}", which is not a single-key table of this module`);
|
|
60
|
-
else if (targetKey.type !== type) add(`field "${name}" and the key of "${references.model}" differ in type`);
|
|
61
|
-
if (references.onDelete === "cascade" && !Object.values(definition.indexes).some(({ eq }) => eq.length === 1 && eq[0] === name)) add(`cascade on "${name}" needs an index whose eq is exactly [${name}]`);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
/** An aggregate's identity, metrics, and shards. */
|
|
65
|
-
const aggregateProblems = (definition, add) => {
|
|
66
|
-
const identity = Object.keys(definition.fields);
|
|
67
|
-
if (definition.key.join("\0") !== identity.join("\0")) add(`key must list the identity fields in declaration order: ${identity.join(", ")}`);
|
|
68
|
-
if (metricsOf(definition).length === 0) add("aggregate has no metrics");
|
|
69
|
-
if (definition.distinct.length > 0 && definition.counters.length + definition.gauges.length > 0) add("distinct sketches need an aggregate of their own");
|
|
70
|
-
const { shards } = definition;
|
|
71
|
-
if (!Number.isSafeInteger(shards) || shards < 1 || shards > 64) add(`shards must be 1–64`);
|
|
72
|
-
};
|
|
73
|
-
/** Every problem in one model's declaration, its roots and references included. */
|
|
74
|
-
const problemsOf = (module, model, definition) => {
|
|
75
|
-
const problems = [];
|
|
76
|
-
const add = (message) => problems.push(`${module.id}.${model}: ${message}`);
|
|
77
|
-
const table = (name) => {
|
|
78
|
-
const target = module.schema[name];
|
|
79
|
-
return target?.kind === "table" ? target : void 0;
|
|
80
|
-
};
|
|
81
|
-
if (!NAME.test(model)) add("model names use lowercase letters, digits, and _");
|
|
82
|
-
fieldProblems(definition, add);
|
|
83
|
-
for (const [name, index] of Object.entries(definition.indexes)) {
|
|
84
|
-
const columns = [...index.eq, ...index.sort];
|
|
85
|
-
if (!INDEX_NAME.test(name)) add(`index "${name}" must match ${INDEX_NAME.source}`);
|
|
86
|
-
if (columns.length === 0) add(`index "${name}" has no fields`);
|
|
87
|
-
if (index.unique && index.sort.length > 0) add(`unique index "${name}" cannot sort`);
|
|
88
|
-
if (columns.filter((column) => {
|
|
89
|
-
const type = fieldType(definition, column);
|
|
90
|
-
if (type === void 0) add(`index "${name}" names undeclared field "${column}"`);
|
|
91
|
-
else if (type.type === "json") add(`index "${name}" names json field "${column}"`);
|
|
92
|
-
else if (type.multi && index.sort.includes(column)) add(`index "${name}" sorts by multi-valued field "${column}"`);
|
|
93
|
-
return type?.type !== "json" && type?.multi;
|
|
94
|
-
}).length > 1) add(`index "${name}" has more than one multi-valued field`);
|
|
95
|
-
if (index.root === void 0) continue;
|
|
96
|
-
const root = table(index.root.model);
|
|
97
|
-
if (root === void 0) add(`index "${name}" is rooted at unknown table "${index.root.model}"`);
|
|
98
|
-
else if (root.key.length > index.eq.length || root.key.some((field, position) => fieldType(definition, index.eq[position])?.type !== root.fields[field].type)) add(`index "${name}" eq must start with the key of "${index.root.model}"`);
|
|
99
|
-
}
|
|
100
|
-
if (definition.kind === "table") tableProblems(definition, add, table);
|
|
101
|
-
else aggregateProblems(definition, add);
|
|
102
|
-
for (const problem of require_retention.retentionProblems(module.schema, model)) add(problem);
|
|
103
|
-
return problems;
|
|
104
|
-
};
|
|
105
|
-
/** Rejects invalid module schemas at startup, listing every problem. */
|
|
106
|
-
const validateSchema = (modules) => {
|
|
107
|
-
const problems = [];
|
|
108
|
-
const owners = /* @__PURE__ */ new Map();
|
|
109
|
-
for (const module of modules) for (const [model, definition] of Object.entries(module.schema)) {
|
|
110
|
-
const name = tableName(module, model);
|
|
111
|
-
const owner = owners.get(name);
|
|
112
|
-
if (owner !== void 0) problems.push(`${module.id}.${model}: table "${name}" is also declared by ${owner}`);
|
|
113
|
-
owners.set(name, `${module.id}.${model}`);
|
|
114
|
-
problems.push(...problemsOf(module, model, definition));
|
|
115
|
-
}
|
|
116
|
-
if (problems.length > 0) throw new _hot_updater_plugin_core_internal.DatabaseSchemaError(`Invalid database schema:\n- ${problems.join("\n- ")}`);
|
|
117
|
-
};
|
|
118
|
-
const indexesOf = (definition) => [...Object.entries(definition.indexes).map(([name, index]) => ({
|
|
119
|
-
name,
|
|
120
|
-
eq: [...index.eq],
|
|
121
|
-
sort: [...index.sort],
|
|
122
|
-
...index.unique ? { unique: true } : {}
|
|
123
|
-
})), ...Object.entries(definition.fields).flatMap(([name, field]) => field.unique ? [{
|
|
124
|
-
name,
|
|
125
|
-
eq: [name],
|
|
126
|
-
sort: [],
|
|
127
|
-
unique: true
|
|
128
|
-
}] : [])];
|
|
129
|
-
/** Validates the modules, then resolves them into physical tables with engine columns. */
|
|
130
|
-
const resolveSchema = (modules) => {
|
|
131
|
-
validateSchema(modules);
|
|
132
|
-
const references = [];
|
|
133
|
-
for (const module of modules) for (const [model, definition] of Object.entries(module.schema)) {
|
|
134
|
-
if (definition.kind !== "table") continue;
|
|
135
|
-
const table = tableName(module, model);
|
|
136
|
-
for (const [field, { references: to }] of Object.entries(definition.fields)) {
|
|
137
|
-
if (to === void 0) continue;
|
|
138
|
-
const { onDelete } = to;
|
|
139
|
-
const target = tableName(module, to.model);
|
|
140
|
-
const counter = onDelete === "none" ? {} : { counter: `_refs_${table}_${field}` };
|
|
141
|
-
references.push({
|
|
142
|
-
table,
|
|
143
|
-
field,
|
|
144
|
-
target,
|
|
145
|
-
onDelete,
|
|
146
|
-
...counter
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
const models = /* @__PURE__ */ new Map();
|
|
151
|
-
for (const module of modules) for (const [model, definition] of Object.entries(module.schema)) {
|
|
152
|
-
const name = tableName(module, model);
|
|
153
|
-
const referencedBy = references.filter(({ target }) => target === name);
|
|
154
|
-
const columns = Object.entries(definition.fields).map(([field, { type, required, maxLength, ascii }]) => ({
|
|
155
|
-
name: field,
|
|
156
|
-
type,
|
|
157
|
-
nullable: required === false,
|
|
158
|
-
...maxLength === void 0 ? {} : { maxLength },
|
|
159
|
-
...ascii ? { ascii } : {}
|
|
160
|
-
}));
|
|
161
|
-
if (definition.kind === "table") for (const [field, { type, multi }] of Object.entries(definition.derived)) columns.push({
|
|
162
|
-
name: field,
|
|
163
|
-
type,
|
|
164
|
-
nullable: true,
|
|
165
|
-
...multi ? { multi } : {}
|
|
166
|
-
});
|
|
167
|
-
else columns.push(integer(SHARD_COLUMN), ...[...definition.counters, ...definition.gauges].map((metric) => integer(metric)), ...definition.distinct.map((metric) => ({
|
|
168
|
-
name: metric,
|
|
169
|
-
type: "string",
|
|
170
|
-
nullable: true
|
|
171
|
-
})));
|
|
172
|
-
for (const { counter } of referencedBy) if (counter !== void 0) columns.push(integer(counter, true));
|
|
173
|
-
columns.push(integer(_hot_updater_plugin_core_internal.DATABASE_VERSION_COLUMN, true));
|
|
174
|
-
models.set(name, {
|
|
175
|
-
module: module.id,
|
|
176
|
-
model,
|
|
177
|
-
definition,
|
|
178
|
-
table: {
|
|
179
|
-
name,
|
|
180
|
-
columns,
|
|
181
|
-
key: definition.kind === "aggregate" ? [...definition.key, SHARD_COLUMN] : [...definition.key],
|
|
182
|
-
indexes: indexesOf(definition),
|
|
183
|
-
...require_retention.physicalRetention(definition)
|
|
184
|
-
},
|
|
185
|
-
references: references.filter(({ table }) => table === name),
|
|
186
|
-
referencedBy,
|
|
187
|
-
roots: new Map(Object.entries(definition.indexes).flatMap(([index, { root }]) => root === void 0 ? [] : [[index, tableName(module, root.model)]]))
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
return {
|
|
191
|
-
models,
|
|
192
|
-
tables: [...models.values()].map(({ table }) => table)
|
|
193
|
-
};
|
|
194
|
-
};
|
|
195
|
-
//#endregion
|
|
196
|
-
exports.MAX_SHARDS = MAX_SHARDS;
|
|
197
|
-
exports.SHARD_COLUMN = SHARD_COLUMN;
|
|
198
|
-
exports.resolveSchema = resolveSchema;
|
|
199
|
-
exports.validateSchema = validateSchema;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { ModelShape, ReferenceAction, SchemaShape } from "./definitions.cjs";
|
|
2
|
-
import { PhysicalTable } from "@hot-updater/plugin-core/internal";
|
|
3
|
-
//#region src/database/resolveSchema.d.ts
|
|
4
|
-
declare const SHARD_COLUMN = "_shard";
|
|
5
|
-
declare const MAX_SHARDS = 64;
|
|
6
|
-
interface SchemaModule {
|
|
7
|
-
readonly id: string;
|
|
8
|
-
readonly schema: SchemaShape;
|
|
9
|
-
/** Prefixes this module's table names; a plugin uses its id unless it sets `namespace: false`. */
|
|
10
|
-
readonly namespace?: string;
|
|
11
|
-
}
|
|
12
|
-
interface ResolvedReference {
|
|
13
|
-
/** The child table and the field that holds the parent key. */
|
|
14
|
-
readonly table: string;
|
|
15
|
-
readonly field: string;
|
|
16
|
-
readonly target: string;
|
|
17
|
-
readonly onDelete: ReferenceAction;
|
|
18
|
-
/** The counter column on the parent; absent for `none`. */
|
|
19
|
-
readonly counter?: string;
|
|
20
|
-
}
|
|
21
|
-
interface ResolvedModel {
|
|
22
|
-
readonly module: string;
|
|
23
|
-
/** The model name as its module declares it. */
|
|
24
|
-
readonly model: string;
|
|
25
|
-
readonly table: PhysicalTable;
|
|
26
|
-
readonly definition: ModelShape;
|
|
27
|
-
readonly references: readonly ResolvedReference[];
|
|
28
|
-
readonly referencedBy: readonly ResolvedReference[];
|
|
29
|
-
/** Index name to the physical name of its root table. */
|
|
30
|
-
readonly roots: ReadonlyMap<string, string>;
|
|
31
|
-
}
|
|
32
|
-
interface ResolvedSchema {
|
|
33
|
-
/** By physical table name. */
|
|
34
|
-
readonly models: ReadonlyMap<string, ResolvedModel>;
|
|
35
|
-
readonly tables: readonly PhysicalTable[];
|
|
36
|
-
}
|
|
37
|
-
/** Rejects invalid module schemas at startup, listing every problem. */
|
|
38
|
-
declare const validateSchema: (modules: readonly SchemaModule[]) => void;
|
|
39
|
-
/** Validates the modules, then resolves them into physical tables with engine columns. */
|
|
40
|
-
declare const resolveSchema: (modules: readonly SchemaModule[]) => ResolvedSchema;
|
|
41
|
-
//#endregion
|
|
42
|
-
export { MAX_SHARDS, ResolvedModel, ResolvedReference, ResolvedSchema, SHARD_COLUMN, SchemaModule, resolveSchema, validateSchema };
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { ModelShape, ReferenceAction, SchemaShape } from "./definitions.mjs";
|
|
2
|
-
import { PhysicalTable } from "@hot-updater/plugin-core/internal";
|
|
3
|
-
//#region src/database/resolveSchema.d.ts
|
|
4
|
-
declare const SHARD_COLUMN = "_shard";
|
|
5
|
-
declare const MAX_SHARDS = 64;
|
|
6
|
-
interface SchemaModule {
|
|
7
|
-
readonly id: string;
|
|
8
|
-
readonly schema: SchemaShape;
|
|
9
|
-
/** Prefixes this module's table names; a plugin uses its id unless it sets `namespace: false`. */
|
|
10
|
-
readonly namespace?: string;
|
|
11
|
-
}
|
|
12
|
-
interface ResolvedReference {
|
|
13
|
-
/** The child table and the field that holds the parent key. */
|
|
14
|
-
readonly table: string;
|
|
15
|
-
readonly field: string;
|
|
16
|
-
readonly target: string;
|
|
17
|
-
readonly onDelete: ReferenceAction;
|
|
18
|
-
/** The counter column on the parent; absent for `none`. */
|
|
19
|
-
readonly counter?: string;
|
|
20
|
-
}
|
|
21
|
-
interface ResolvedModel {
|
|
22
|
-
readonly module: string;
|
|
23
|
-
/** The model name as its module declares it. */
|
|
24
|
-
readonly model: string;
|
|
25
|
-
readonly table: PhysicalTable;
|
|
26
|
-
readonly definition: ModelShape;
|
|
27
|
-
readonly references: readonly ResolvedReference[];
|
|
28
|
-
readonly referencedBy: readonly ResolvedReference[];
|
|
29
|
-
/** Index name to the physical name of its root table. */
|
|
30
|
-
readonly roots: ReadonlyMap<string, string>;
|
|
31
|
-
}
|
|
32
|
-
interface ResolvedSchema {
|
|
33
|
-
/** By physical table name. */
|
|
34
|
-
readonly models: ReadonlyMap<string, ResolvedModel>;
|
|
35
|
-
readonly tables: readonly PhysicalTable[];
|
|
36
|
-
}
|
|
37
|
-
/** Rejects invalid module schemas at startup, listing every problem. */
|
|
38
|
-
declare const validateSchema: (modules: readonly SchemaModule[]) => void;
|
|
39
|
-
/** Validates the modules, then resolves them into physical tables with engine columns. */
|
|
40
|
-
declare const resolveSchema: (modules: readonly SchemaModule[]) => ResolvedSchema;
|
|
41
|
-
//#endregion
|
|
42
|
-
export { MAX_SHARDS, ResolvedModel, ResolvedReference, ResolvedSchema, SHARD_COLUMN, SchemaModule, resolveSchema, validateSchema };
|