@hot-updater/server 1.0.0-rc.2 → 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 +32 -75
- package/dist/adapters/drizzle.d.cts +13 -5
- package/dist/adapters/drizzle.d.mts +13 -5
- package/dist/adapters/drizzle.mjs +32 -77
- 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 +22 -31
- package/dist/adapters/kysely.d.cts +10 -6
- package/dist/adapters/kysely.d.mts +10 -6
- package/dist/adapters/kysely.mjs +23 -33
- package/dist/adapters/kyselyExecutor.cjs +32 -0
- package/dist/adapters/kyselyExecutor.d.cts +11 -0
- package/dist/adapters/kyselyExecutor.d.mts +11 -0
- package/dist/adapters/kyselyExecutor.mjs +32 -0
- package/dist/adapters/mongodb.cjs +18 -54
- package/dist/adapters/mongodb.d.cts +10 -5
- package/dist/adapters/mongodb.d.mts +10 -5
- package/dist/adapters/mongodb.mjs +19 -56
- package/dist/adapters/mongodbAdapter.cjs +192 -0
- package/dist/adapters/mongodbAdapter.d.cts +9 -0
- package/dist/adapters/mongodbAdapter.d.mts +9 -0
- package/dist/adapters/mongodbAdapter.mjs +191 -0
- package/dist/adapters/prisma.cjs +35 -267
- package/dist/adapters/prisma.d.cts +12 -7
- package/dist/adapters/prisma.d.mts +12 -7
- package/dist/adapters/prisma.mjs +36 -268
- package/dist/adapters/prismaExecutor.cjs +63 -0
- package/dist/adapters/prismaExecutor.mjs +63 -0
- package/dist/adapters/sqlProviders.cjs +14 -0
- package/dist/adapters/sqlProviders.mjs +14 -0
- package/dist/assembly/assemblePlugins.cjs +144 -0
- package/dist/assembly/assemblePlugins.d.cts +5 -0
- package/dist/assembly/assemblePlugins.d.mts +5 -0
- package/dist/assembly/assemblePlugins.mjs +139 -0
- package/dist/assembly/clientPlugins.cjs +88 -0
- package/dist/assembly/clientPlugins.mjs +88 -0
- package/dist/assembly/configError.d.cts +2 -0
- package/dist/assembly/configError.d.mts +2 -0
- package/dist/assembly/configError.mjs +2 -0
- package/dist/core/api.cjs +51 -0
- package/dist/core/api.d.cts +54 -0
- package/dist/core/api.d.mts +54 -0
- package/dist/core/api.mjs +51 -0
- package/dist/core/baseCandidates.cjs +28 -0
- package/dist/core/baseCandidates.mjs +28 -0
- package/dist/core/operations.cjs +351 -0
- package/dist/core/operations.mjs +351 -0
- package/dist/core/reads.cjs +273 -0
- package/dist/core/reads.d.cts +9 -0
- package/dist/core/reads.d.mts +9 -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/writes.cjs +96 -0
- package/dist/core/writes.mjs +91 -0
- package/dist/createHotUpdaterCore.cjs +72 -91
- package/dist/createHotUpdaterCore.d.cts +106 -38
- package/dist/createHotUpdaterCore.d.mts +106 -38
- package/dist/createHotUpdaterCore.mjs +74 -89
- package/dist/db/engineDrizzleSchema.cjs +53 -0
- package/dist/db/engineDrizzleSchema.mjs +53 -0
- package/dist/db/enginePrismaSchema.cjs +84 -0
- package/dist/db/enginePrismaSchema.d.cts +5 -0
- package/dist/db/enginePrismaSchema.d.mts +5 -0
- package/dist/db/enginePrismaSchema.mjs +83 -0
- package/dist/db/releaseCatalog.cjs +24 -47
- package/dist/db/releaseCatalog.mjs +20 -44
- package/dist/db/updateArtifacts.cjs +43 -72
- package/dist/db/updateArtifacts.mjs +40 -69
- package/dist/handler.cjs +59 -43
- package/dist/handler.d.cts +3 -5
- package/dist/handler.d.mts +3 -5
- package/dist/handler.mjs +61 -43
- package/dist/handlerAdminRoutes.cjs +374 -0
- package/dist/handlerAdminRoutes.mjs +372 -0
- package/dist/handlerParameters.cjs +6 -11
- package/dist/handlerParameters.mjs +6 -10
- package/dist/handlerReleaseCatalogRoutes.cjs +32 -15
- package/dist/handlerReleaseCatalogRoutes.mjs +32 -15
- package/dist/handlerTypes.d.cts +2 -55
- package/dist/handlerTypes.d.mts +2 -55
- package/dist/handlerVersionRoutes.cjs +20 -4
- package/dist/handlerVersionRoutes.mjs +20 -4
- package/dist/index.cjs +9 -9
- package/dist/index.d.cts +8 -9
- package/dist/index.d.mts +8 -9
- package/dist/index.mjs +3 -4
- package/dist/node.cjs +3 -6
- package/dist/node.d.cts +2 -2
- package/dist/node.d.mts +2 -2
- 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 +9 -0
- package/dist/plugins/api-keys/index.d.cts +1 -0
- package/dist/plugins/api-keys/index.d.mts +1 -0
- package/dist/plugins/api-keys/index.mjs +2 -0
- package/dist/plugins/definePlugin.d.cts +2 -0
- package/dist/plugins/definePlugin.d.mts +2 -0
- package/dist/plugins/insights/index.cjs +9 -0
- package/dist/plugins/insights/index.d.cts +1 -0
- package/dist/plugins/insights/index.d.mts +1 -0
- package/dist/plugins/insights/index.mjs +2 -0
- 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 +2 -28
- package/dist/types/index.d.mts +2 -28
- package/package.json +26 -14
- package/dist/_virtual/_rolldown/runtime.cjs +0 -23
- package/dist/adapters/databaseConstraintErrors.cjs +0 -22
- package/dist/adapters/databaseConstraintErrors.mjs +0 -21
- package/dist/adapters/databasePluginUtils.cjs +0 -116
- package/dist/adapters/databasePluginUtils.mjs +0 -106
- package/dist/adapters/drizzleCrud.cjs +0 -311
- package/dist/adapters/drizzleCrud.mjs +0 -308
- package/dist/adapters/drizzleLazyDB.cjs +0 -106
- package/dist/adapters/drizzleLazyDB.mjs +0 -106
- package/dist/adapters/drizzleQuery.cjs +0 -69
- package/dist/adapters/drizzleQuery.mjs +0 -69
- package/dist/adapters/insightsTransaction.cjs +0 -22
- package/dist/adapters/insightsTransaction.mjs +0 -22
- package/dist/adapters/kyselyCrud.cjs +0 -305
- package/dist/adapters/kyselyCrud.mjs +0 -304
- package/dist/adapters/kyselyQuery.cjs +0 -56
- package/dist/adapters/kyselyQuery.mjs +0 -56
- package/dist/adapters/mongodbCollections.cjs +0 -38
- package/dist/adapters/mongodbCollections.mjs +0 -32
- package/dist/adapters/mongodbQuery.cjs +0 -94
- package/dist/adapters/mongodbQuery.mjs +0 -86
- package/dist/adapters/mongodbReads.cjs +0 -210
- package/dist/adapters/mongodbReads.mjs +0 -210
- package/dist/adapters/mongodbWrites.cjs +0 -148
- package/dist/adapters/mongodbWrites.mjs +0 -148
- package/dist/adapters/prismaQuery.cjs +0 -57
- package/dist/adapters/prismaQuery.mjs +0 -56
- package/dist/adapters/prismaRows.cjs +0 -219
- package/dist/adapters/prismaRows.mjs +0 -209
- package/dist/apiKeys.cjs +0 -143
- package/dist/apiKeys.d.cts +0 -49
- package/dist/apiKeys.d.mts +0 -49
- package/dist/apiKeys.mjs +0 -133
- package/dist/db/createBundleDiff.cjs +0 -144
- package/dist/db/createBundleDiff.d.cts +0 -16
- package/dist/db/createBundleDiff.d.mts +0 -16
- package/dist/db/createBundleDiff.mjs +0 -141
- package/dist/db/databasePluginCore.cjs +0 -137
- 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 -321
- package/dist/db/fixedMigratorMongo.mjs +0 -321
- package/dist/db/fixedMigratorShared.cjs +0 -23
- package/dist/db/fixedMigratorShared.mjs +0 -18
- package/dist/db/index.cjs +0 -27
- package/dist/db/index.d.cts +0 -12
- package/dist/db/index.d.mts +0 -12
- package/dist/db/index.mjs +0 -22
- package/dist/db/mongoMigrationExecution.cjs +0 -11
- package/dist/db/mongoMigrationExecution.mjs +0 -11
- package/dist/db/releaseCatalog.d.cts +0 -16
- package/dist/db/releaseCatalog.d.mts +0 -16
- package/dist/db/schema/insightsCollation.cjs +0 -14
- package/dist/db/schema/insightsCollation.mjs +0 -14
- 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 -105
- 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 -275
- package/dist/db/schemaGenerators.mjs +0 -273
- package/dist/db/schemaReadiness.cjs +0 -26
- package/dist/db/schemaReadiness.d.cts +0 -9
- package/dist/db/schemaReadiness.d.mts +0 -9
- package/dist/db/schemaReadiness.mjs +0 -25
- package/dist/db/sqlMigrationExecution.cjs +0 -67
- package/dist/db/sqlMigrationExecution.mjs +0 -67
- package/dist/db/types.cjs +0 -22
- package/dist/db/types.d.cts +0 -118
- package/dist/db/types.d.mts +0 -118
- package/dist/db/types.mjs +0 -19
- package/dist/handlerBundleRoutes.cjs +0 -155
- package/dist/handlerBundleRoutes.mjs +0 -155
- package/dist/handlerReleaseManagementRoutes.cjs +0 -124
- package/dist/handlerReleaseManagementRoutes.mjs +0 -124
- package/dist/insights/domain.d.cts +0 -89
- package/dist/insights/domain.d.mts +0 -89
- package/dist/insights/errors.cjs +0 -15
- package/dist/insights/errors.mjs +0 -14
- package/dist/insights/eventInput.cjs +0 -155
- package/dist/insights/eventInput.mjs +0 -153
- package/dist/insights/provider.cjs +0 -314
- package/dist/insights/provider.d.cts +0 -6
- package/dist/insights/provider.d.mts +0 -6
- package/dist/insights/provider.mjs +0 -314
- package/dist/insights/queryInput.cjs +0 -93
- package/dist/insights/queryInput.mjs +0 -91
- package/dist/insights/routes.cjs +0 -58
- package/dist/insights/routes.mjs +0 -56
- package/dist/insights/types.d.cts +0 -32
- package/dist/insights/types.d.mts +0 -32
- package/dist/schema/dsl.cjs +0 -103
- package/dist/schema/dsl.mjs +0 -87
- package/dist/schema/index.cjs +0 -20
- 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 -406
- package/dist/schema/v1_0_0.mjs +0 -398
- package/src/adapters/databaseConstraintErrors.ts +0 -25
- package/src/adapters/databasePluginTestDatabase.ts +0 -120
- package/src/adapters/databasePluginUtils.spec.ts +0 -29
- package/src/adapters/databasePluginUtils.ts +0 -214
- package/src/adapters/drizzle.spec.ts +0 -336
- package/src/adapters/drizzle.ts +0 -162
- package/src/adapters/drizzleCrud.ts +0 -571
- package/src/adapters/drizzleLazyDB.ts +0 -271
- package/src/adapters/drizzleQuery.ts +0 -164
- package/src/adapters/insightsTransaction.ts +0 -32
- package/src/adapters/kysely.spec.ts +0 -174
- package/src/adapters/kysely.ts +0 -110
- package/src/adapters/kyselyCrud.ts +0 -709
- package/src/adapters/kyselyQuery.ts +0 -128
- package/src/adapters/mongodb.integration.spec.ts +0 -210
- package/src/adapters/mongodb.spec.ts +0 -209
- package/src/adapters/mongodb.ts +0 -138
- package/src/adapters/mongodbCollections.ts +0 -67
- package/src/adapters/mongodbQuery.ts +0 -255
- package/src/adapters/mongodbReads.ts +0 -380
- package/src/adapters/mongodbRows.spec.ts +0 -64
- package/src/adapters/mongodbRows.ts +0 -118
- package/src/adapters/mongodbTestClient.ts +0 -377
- package/src/adapters/mongodbTestFilter.ts +0 -169
- package/src/adapters/mongodbWrites.ts +0 -287
- package/src/adapters/prisma.spec.ts +0 -293
- package/src/adapters/prisma.ts +0 -565
- package/src/adapters/prismaQuery.ts +0 -129
- package/src/adapters/prismaRows.spec.ts +0 -98
- package/src/adapters/prismaRows.ts +0 -337
- package/src/adapters/prismaTestClient.ts +0 -413
- package/src/apiKeys.integration.spec.ts +0 -192
- package/src/apiKeys.spec.ts +0 -162
- package/src/apiKeys.ts +0 -220
- package/src/calculatePagination.ts +0 -34
- package/src/createHotUpdaterCore.ts +0 -246
- package/src/db/bundleRows.spec.ts +0 -164
- package/src/db/bundleRows.ts +0 -10
- package/src/db/createBundleDiff.spec.ts +0 -450
- package/src/db/createBundleDiff.ts +0 -364
- 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 -110
- package/src/db/fixedMigrator.spec.ts +0 -296
- package/src/db/fixedMigrator.ts +0 -147
- package/src/db/fixedMigratorMongo.spec.ts +0 -239
- package/src/db/fixedMigratorMongo.ts +0 -425
- package/src/db/fixedMigratorShared.ts +0 -36
- package/src/db/hotUpdaterSchema.ts +0 -5
- package/src/db/index.spec.ts +0 -1269
- package/src/db/index.ts +0 -47
- package/src/db/mongoMigrationExecution.ts +0 -23
- package/src/db/node-sqlite.d.ts +0 -25
- package/src/db/releaseCatalog.ts +0 -148
- package/src/db/schema/definitions.ts +0 -1
- package/src/db/schema/insightsCollation.ts +0 -21
- package/src/db/schema/mongodb.ts +0 -40
- package/src/db/schema/registry.ts +0 -55
- package/src/db/schema/sql.ts +0 -244
- package/src/db/schema/sqlOperations.ts +0 -63
- package/src/db/schema/types.ts +0 -1
- package/src/db/schemaGenerators.ts +0 -494
- 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 -63
- package/src/db/types.ts +0 -228
- package/src/db/updateArtifacts.spec.ts +0 -359
- package/src/db/updateArtifacts.ts +0 -541
- package/src/handler-standalone.integration.spec.ts +0 -528
- package/src/handler.spec.ts +0 -190
- package/src/handler.testFixtures.ts +0 -30
- package/src/handler.ts +0 -245
- package/src/handlerAuth.integration.spec.ts +0 -33
- package/src/handlerBundleRoutes.ts +0 -259
- package/src/handlerErrors.ts +0 -7
- package/src/handlerManagement.spec.ts +0 -262
- package/src/handlerParameters.ts +0 -105
- package/src/handlerReleaseCatalogRoutes.ts +0 -154
- package/src/handlerReleaseManagementRoutes.ts +0 -213
- package/src/handlerTypes.ts +0 -96
- package/src/handlerVersionRoutes.ts +0 -12
- package/src/index.ts +0 -30
- package/src/insights/domain.ts +0 -103
- package/src/insights/errors.ts +0 -11
- package/src/insights/eventInput.ts +0 -225
- package/src/insights/insights.integration.spec.ts +0 -381
- package/src/insights/provider.spec.ts +0 -385
- package/src/insights/provider.ts +0 -591
- package/src/insights/queryInput.ts +0 -141
- package/src/insights/routes.ts +0 -104
- package/src/insights/types.ts +0 -55
- package/src/internalRouter.ts +0 -104
- package/src/node.spec.ts +0 -119
- package/src/node.ts +0 -111
- package/src/releaseCatalogRoutes.integration.spec.ts +0 -238
- package/src/runtime.spec.ts +0 -194
- package/src/runtime.testFixtures.ts +0 -71
- package/src/schema/dsl-all-versions.spec.ts +0 -37
- 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 -220
- package/src/schema/v1_0_0.ts +0 -529
- package/src/storageAccess.spec.ts +0 -152
- package/src/storageAccess.ts +0 -141
- package/src/types/index.ts +0 -34
- package/src/version.ts +0 -3
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { createCoreReads } from "../core/reads.mjs";
|
|
2
|
+
import { createCoreApi } from "../core/api.mjs";
|
|
3
|
+
import { HotUpdaterConfigError } from "./configError.mjs";
|
|
4
|
+
import { checkReservedId } from "../plugins/official.mjs";
|
|
5
|
+
import { clientPluginsOf } from "./clientPlugins.mjs";
|
|
6
|
+
import { createEngine } from "@hot-updater/plugin-core";
|
|
7
|
+
//#region src/assembly/assemblePlugins.ts
|
|
8
|
+
const PLUGIN_KEYS = /* @__PURE__ */ new Set([
|
|
9
|
+
"id",
|
|
10
|
+
"provides",
|
|
11
|
+
"schemaVersion",
|
|
12
|
+
"schema",
|
|
13
|
+
"namespace",
|
|
14
|
+
"init",
|
|
15
|
+
"cli"
|
|
16
|
+
]);
|
|
17
|
+
const CLI_KEYS = /* @__PURE__ */ new Set(["clientCredential", "clientPlugin"]);
|
|
18
|
+
const INSTANCE_KEYS = /* @__PURE__ */ new Set([
|
|
19
|
+
"api",
|
|
20
|
+
"endpoints",
|
|
21
|
+
"clientAuth"
|
|
22
|
+
]);
|
|
23
|
+
const METHODS = /* @__PURE__ */ new Set([
|
|
24
|
+
"GET",
|
|
25
|
+
"POST",
|
|
26
|
+
"PUT",
|
|
27
|
+
"PATCH",
|
|
28
|
+
"DELETE"
|
|
29
|
+
]);
|
|
30
|
+
/** An id that prefixes table names is a SQL name; one that does not may use camelCase. */
|
|
31
|
+
const PREFIX_ID = /^[a-z][a-z0-9_]*$/u;
|
|
32
|
+
const UNPREFIXED_ID = /^[a-z][A-Za-z0-9_]*$/u;
|
|
33
|
+
const PATH = /^(\/(:?[A-Za-z0-9_.~-]+))+$/u;
|
|
34
|
+
const fail = (message) => {
|
|
35
|
+
throw new HotUpdaterConfigError(message);
|
|
36
|
+
};
|
|
37
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
38
|
+
const checkPlugin = (value, at) => {
|
|
39
|
+
if (!isRecord(value)) return fail(`${at} is not a plugin.`);
|
|
40
|
+
if ("kind" in value) fail(`${at} has a kind; core is built in and is never passed as a plugin.`);
|
|
41
|
+
const unknown = Object.keys(value).find((key) => !PLUGIN_KEYS.has(key));
|
|
42
|
+
if (unknown !== void 0) fail(`${at} has an unknown key "${unknown}".`);
|
|
43
|
+
const plugin = value;
|
|
44
|
+
if (plugin.namespace !== void 0 && plugin.namespace !== false) fail(`${at} may only set namespace: false.`);
|
|
45
|
+
const pattern = plugin.namespace === false ? UNPREFIXED_ID : PREFIX_ID;
|
|
46
|
+
if (typeof plugin.id !== "string" || !pattern.test(plugin.id)) fail(`${at} needs an id matching ${pattern.source}.`);
|
|
47
|
+
if (plugin.id === "core") fail(`${at} uses the id "core", which is core's own.`);
|
|
48
|
+
checkReservedId(value, at);
|
|
49
|
+
if (typeof plugin.schemaVersion !== "string" || !isRecord(plugin.schema) || typeof plugin.init !== "function") fail(`Plugin "${plugin.id}" needs a schemaVersion, a schema, and init.`);
|
|
50
|
+
const provides = plugin.provides;
|
|
51
|
+
if (provides !== void 0 && (!isRecord(provides) || Object.entries(provides).some(([key, flag]) => key !== "clientAuth" || flag !== true))) fail(`Plugin "${plugin.id}" may only declare provides: { clientAuth: true }.`);
|
|
52
|
+
const cli = value.cli;
|
|
53
|
+
if (cli !== void 0) {
|
|
54
|
+
if (!isRecord(cli) || Object.keys(cli).some((key) => !CLI_KEYS.has(key))) fail(`Plugin "${plugin.id}" cli may only hold clientCredential and clientPlugin.`);
|
|
55
|
+
if (cli.clientCredential !== void 0 && plugin.provides?.clientAuth !== true) fail(`Plugin "${plugin.id}" adds cli.clientCredential without declaring provides: { clientAuth: true }.`);
|
|
56
|
+
}
|
|
57
|
+
return plugin;
|
|
58
|
+
};
|
|
59
|
+
const checkEndpoint = (id, value) => {
|
|
60
|
+
const endpoint = isRecord(value) ? value : {};
|
|
61
|
+
if (!METHODS.has(endpoint.method) || typeof endpoint.path !== "string" || !PATH.test(endpoint.path) || endpoint.access !== "client" && endpoint.access !== "admin" || typeof endpoint.handler !== "function") fail(`Plugin "${id}" has an endpoint that needs a method, a path like /name/:param, access "client" or "admin", and a handler.`);
|
|
62
|
+
return {
|
|
63
|
+
...endpoint,
|
|
64
|
+
plugin: id
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
const checkInstance = (plugin, instance) => {
|
|
68
|
+
const { id } = plugin;
|
|
69
|
+
if (!isRecord(instance)) return fail(`Plugin "${id}" init returned no instance.`);
|
|
70
|
+
if (typeof instance.then === "function") fail(`Plugin "${id}" init returned a promise; init must be synchronous.`);
|
|
71
|
+
const unknown = Object.keys(instance).find((key) => !INSTANCE_KEYS.has(key));
|
|
72
|
+
if (unknown !== void 0 || !("api" in instance)) fail(`Plugin "${id}" init must return { api, endpoints?, clientAuth? }${unknown === void 0 ? "" : `, not "${unknown}"`}.`);
|
|
73
|
+
const declared = plugin.provides?.clientAuth === true;
|
|
74
|
+
const clientAuth = instance.clientAuth;
|
|
75
|
+
if (declared !== (clientAuth !== void 0)) fail(declared ? `Plugin "${id}" declares provides: { clientAuth: true } but its instance has no clientAuth.` : `Plugin "${id}" returns clientAuth without declaring provides: { clientAuth: true }.`);
|
|
76
|
+
if (clientAuth !== void 0 && (typeof clientAuth.authenticate !== "function" || !Array.isArray(clientAuth.varyHeaders) || !clientAuth.varyHeaders.every((header) => typeof header === "string"))) fail(`Plugin "${id}" clientAuth needs varyHeaders and authenticate.`);
|
|
77
|
+
const endpoints = instance.endpoints ?? [];
|
|
78
|
+
if (!Array.isArray(endpoints)) fail(`Plugin "${id}" endpoints must be an array.`);
|
|
79
|
+
return {
|
|
80
|
+
api: instance.api,
|
|
81
|
+
clientAuth,
|
|
82
|
+
endpoints: endpoints.map((endpoint) => checkEndpoint(id, endpoint))
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Checks every plugin, runs each `init` once against one engine over the
|
|
87
|
+
* database, and collects APIs, endpoints, and clientAuth. Core's reads run
|
|
88
|
+
* on the same engine, so plugins read core through `ctx.core`.
|
|
89
|
+
*/
|
|
90
|
+
const assemblePlugins = (value, database, { now = Date.now, storage = { resolveFileUrl: async () => null } } = {}) => {
|
|
91
|
+
if (!Array.isArray(value)) return fail("plugins must be an array of plugins.");
|
|
92
|
+
const plugins = value.map((plugin, position) => checkPlugin(plugin, `plugins[${position}]`));
|
|
93
|
+
const ids = /* @__PURE__ */ new Set();
|
|
94
|
+
for (const { id } of plugins) {
|
|
95
|
+
if (ids.has(id)) fail(`Plugin "${id}" is registered twice.`);
|
|
96
|
+
ids.add(id);
|
|
97
|
+
}
|
|
98
|
+
clientPluginsOf(plugins);
|
|
99
|
+
const engine = createEngine(database, {
|
|
100
|
+
plugins,
|
|
101
|
+
now
|
|
102
|
+
});
|
|
103
|
+
const { onCachedRoutesChange } = database;
|
|
104
|
+
const core = createCoreApi(engine.core, storage, {
|
|
105
|
+
now,
|
|
106
|
+
...onCachedRoutesChange === void 0 ? {} : { onCachedRoutesChange: () => onCachedRoutesChange.call(database) }
|
|
107
|
+
});
|
|
108
|
+
const reads = createCoreReads(engine.core, storage);
|
|
109
|
+
const api = {};
|
|
110
|
+
const endpoints = [];
|
|
111
|
+
let clientAuth;
|
|
112
|
+
for (const plugin of plugins) {
|
|
113
|
+
const instance = checkInstance(plugin, plugin.init({
|
|
114
|
+
db: engine.database(plugin),
|
|
115
|
+
core: reads,
|
|
116
|
+
now
|
|
117
|
+
}));
|
|
118
|
+
if (instance.clientAuth !== void 0) {
|
|
119
|
+
if (clientAuth !== void 0) fail(`Plugins "${clientAuth.plugin}" and "${plugin.id}" both provide clientAuth; keep one.`);
|
|
120
|
+
const provided = instance.clientAuth;
|
|
121
|
+
clientAuth = {
|
|
122
|
+
plugin: plugin.id,
|
|
123
|
+
varyHeaders: provided.varyHeaders,
|
|
124
|
+
authenticate: (headers) => provided.authenticate(headers)
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
endpoints.push(...instance.endpoints);
|
|
128
|
+
api[plugin.id] = instance.api;
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
core,
|
|
132
|
+
api,
|
|
133
|
+
endpoints,
|
|
134
|
+
...clientAuth === void 0 ? {} : { clientAuth },
|
|
135
|
+
flush: engine.flush
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
//#endregion
|
|
139
|
+
export { HotUpdaterConfigError, assemblePlugins };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const require_official = require("../plugins/official.cjs");
|
|
2
|
+
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
3
|
+
//#region src/assembly/clientPlugins.ts
|
|
4
|
+
const EXPORT_NAME = /^[A-Za-z_$][\w$]*$/u;
|
|
5
|
+
/**
|
|
6
|
+
* Names app code cannot import as they are: reserved words, and the names
|
|
7
|
+
* the printed app code declares itself.
|
|
8
|
+
*/
|
|
9
|
+
const UNAVAILABLE_NAMES = /* @__PURE__ */ new Set([
|
|
10
|
+
"App",
|
|
11
|
+
"HotUpdater",
|
|
12
|
+
"arguments",
|
|
13
|
+
"await",
|
|
14
|
+
"break",
|
|
15
|
+
"case",
|
|
16
|
+
"catch",
|
|
17
|
+
"class",
|
|
18
|
+
"const",
|
|
19
|
+
"continue",
|
|
20
|
+
"debugger",
|
|
21
|
+
"default",
|
|
22
|
+
"delete",
|
|
23
|
+
"do",
|
|
24
|
+
"else",
|
|
25
|
+
"enum",
|
|
26
|
+
"eval",
|
|
27
|
+
"export",
|
|
28
|
+
"extends",
|
|
29
|
+
"false",
|
|
30
|
+
"finally",
|
|
31
|
+
"for",
|
|
32
|
+
"function",
|
|
33
|
+
"if",
|
|
34
|
+
"implements",
|
|
35
|
+
"import",
|
|
36
|
+
"in",
|
|
37
|
+
"instanceof",
|
|
38
|
+
"interface",
|
|
39
|
+
"let",
|
|
40
|
+
"new",
|
|
41
|
+
"null",
|
|
42
|
+
"package",
|
|
43
|
+
"private",
|
|
44
|
+
"protected",
|
|
45
|
+
"public",
|
|
46
|
+
"return",
|
|
47
|
+
"static",
|
|
48
|
+
"super",
|
|
49
|
+
"switch",
|
|
50
|
+
"this",
|
|
51
|
+
"throw",
|
|
52
|
+
"true",
|
|
53
|
+
"try",
|
|
54
|
+
"typeof",
|
|
55
|
+
"var",
|
|
56
|
+
"void",
|
|
57
|
+
"while",
|
|
58
|
+
"with",
|
|
59
|
+
"yield"
|
|
60
|
+
]);
|
|
61
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
62
|
+
/**
|
|
63
|
+
* The client plugins an app adds for the plugins, each once, in plugin
|
|
64
|
+
* order: what init prints in `HotUpdater.init`'s `plugins`. A malformed one,
|
|
65
|
+
* or one name from two modules, throws `HotUpdaterConfigError`.
|
|
66
|
+
*/
|
|
67
|
+
const clientPluginsOf = (plugins) => {
|
|
68
|
+
if (!Array.isArray(plugins)) throw new _hot_updater_plugin_core.HotUpdaterConfigError("plugins must be an array of plugins.");
|
|
69
|
+
const found = [];
|
|
70
|
+
plugins.forEach((plugin, position) => require_official.checkReservedId(plugin, `plugins[${position}]`));
|
|
71
|
+
for (const plugin of plugins) {
|
|
72
|
+
if (!isRecord(plugin) || !isRecord(plugin.cli)) continue;
|
|
73
|
+
const value = plugin.cli.clientPlugin;
|
|
74
|
+
if (value === void 0) continue;
|
|
75
|
+
const id = String(plugin.id);
|
|
76
|
+
if (!isRecord(value) || typeof value.module !== "string" || value.module === "" || typeof value.name !== "string" || !EXPORT_NAME.test(value.name) || UNAVAILABLE_NAMES.has(value.name)) throw new _hot_updater_plugin_core.HotUpdaterConfigError(`Plugin "${id}" cli.clientPlugin needs a module and an export name the app can import: an identifier other than a reserved word, App, or HotUpdater.`);
|
|
77
|
+
const { module, name } = value;
|
|
78
|
+
const named = found.find((entry) => entry.name === name);
|
|
79
|
+
if (named === void 0) found.push({
|
|
80
|
+
module,
|
|
81
|
+
name
|
|
82
|
+
});
|
|
83
|
+
else if (named.module !== module) throw new _hot_updater_plugin_core.HotUpdaterConfigError(`Plugin "${id}" names the client plugin "${name}" from ${module}, but another plugin names it from ${named.module}.`);
|
|
84
|
+
}
|
|
85
|
+
return found;
|
|
86
|
+
};
|
|
87
|
+
//#endregion
|
|
88
|
+
exports.clientPluginsOf = clientPluginsOf;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { HotUpdaterConfigError } from "./configError.mjs";
|
|
2
|
+
import { checkReservedId } from "../plugins/official.mjs";
|
|
3
|
+
//#region src/assembly/clientPlugins.ts
|
|
4
|
+
const EXPORT_NAME = /^[A-Za-z_$][\w$]*$/u;
|
|
5
|
+
/**
|
|
6
|
+
* Names app code cannot import as they are: reserved words, and the names
|
|
7
|
+
* the printed app code declares itself.
|
|
8
|
+
*/
|
|
9
|
+
const UNAVAILABLE_NAMES = /* @__PURE__ */ new Set([
|
|
10
|
+
"App",
|
|
11
|
+
"HotUpdater",
|
|
12
|
+
"arguments",
|
|
13
|
+
"await",
|
|
14
|
+
"break",
|
|
15
|
+
"case",
|
|
16
|
+
"catch",
|
|
17
|
+
"class",
|
|
18
|
+
"const",
|
|
19
|
+
"continue",
|
|
20
|
+
"debugger",
|
|
21
|
+
"default",
|
|
22
|
+
"delete",
|
|
23
|
+
"do",
|
|
24
|
+
"else",
|
|
25
|
+
"enum",
|
|
26
|
+
"eval",
|
|
27
|
+
"export",
|
|
28
|
+
"extends",
|
|
29
|
+
"false",
|
|
30
|
+
"finally",
|
|
31
|
+
"for",
|
|
32
|
+
"function",
|
|
33
|
+
"if",
|
|
34
|
+
"implements",
|
|
35
|
+
"import",
|
|
36
|
+
"in",
|
|
37
|
+
"instanceof",
|
|
38
|
+
"interface",
|
|
39
|
+
"let",
|
|
40
|
+
"new",
|
|
41
|
+
"null",
|
|
42
|
+
"package",
|
|
43
|
+
"private",
|
|
44
|
+
"protected",
|
|
45
|
+
"public",
|
|
46
|
+
"return",
|
|
47
|
+
"static",
|
|
48
|
+
"super",
|
|
49
|
+
"switch",
|
|
50
|
+
"this",
|
|
51
|
+
"throw",
|
|
52
|
+
"true",
|
|
53
|
+
"try",
|
|
54
|
+
"typeof",
|
|
55
|
+
"var",
|
|
56
|
+
"void",
|
|
57
|
+
"while",
|
|
58
|
+
"with",
|
|
59
|
+
"yield"
|
|
60
|
+
]);
|
|
61
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
62
|
+
/**
|
|
63
|
+
* The client plugins an app adds for the plugins, each once, in plugin
|
|
64
|
+
* order: what init prints in `HotUpdater.init`'s `plugins`. A malformed one,
|
|
65
|
+
* or one name from two modules, throws `HotUpdaterConfigError`.
|
|
66
|
+
*/
|
|
67
|
+
const clientPluginsOf = (plugins) => {
|
|
68
|
+
if (!Array.isArray(plugins)) throw new HotUpdaterConfigError("plugins must be an array of plugins.");
|
|
69
|
+
const found = [];
|
|
70
|
+
plugins.forEach((plugin, position) => checkReservedId(plugin, `plugins[${position}]`));
|
|
71
|
+
for (const plugin of plugins) {
|
|
72
|
+
if (!isRecord(plugin) || !isRecord(plugin.cli)) continue;
|
|
73
|
+
const value = plugin.cli.clientPlugin;
|
|
74
|
+
if (value === void 0) continue;
|
|
75
|
+
const id = String(plugin.id);
|
|
76
|
+
if (!isRecord(value) || typeof value.module !== "string" || value.module === "" || typeof value.name !== "string" || !EXPORT_NAME.test(value.name) || UNAVAILABLE_NAMES.has(value.name)) throw new HotUpdaterConfigError(`Plugin "${id}" cli.clientPlugin needs a module and an export name the app can import: an identifier other than a reserved word, App, or HotUpdater.`);
|
|
77
|
+
const { module, name } = value;
|
|
78
|
+
const named = found.find((entry) => entry.name === name);
|
|
79
|
+
if (named === void 0) found.push({
|
|
80
|
+
module,
|
|
81
|
+
name
|
|
82
|
+
});
|
|
83
|
+
else if (named.module !== module) throw new HotUpdaterConfigError(`Plugin "${id}" names the client plugin "${name}" from ${module}, but another plugin names it from ${named.module}.`);
|
|
84
|
+
}
|
|
85
|
+
return found;
|
|
86
|
+
};
|
|
87
|
+
//#endregion
|
|
88
|
+
export { clientPluginsOf };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const require_reads = require("./reads.cjs");
|
|
2
|
+
const require_operations = require("./operations.cjs");
|
|
3
|
+
//#region src/core/api.ts
|
|
4
|
+
/**
|
|
5
|
+
* The update check answers from one Release Catalog row, so a transaction
|
|
6
|
+
* changes what the cacheable client routes answer only when it writes one.
|
|
7
|
+
* The purge runs once, after the attempt that commits.
|
|
8
|
+
*/
|
|
9
|
+
const purgingCachedRoutes = (db, onCachedRoutesChange) => {
|
|
10
|
+
if (onCachedRoutesChange === void 0) return db;
|
|
11
|
+
return {
|
|
12
|
+
...db,
|
|
13
|
+
async transaction(fn) {
|
|
14
|
+
let changed = false;
|
|
15
|
+
const result = await db.transaction((tx) => {
|
|
16
|
+
changed = false;
|
|
17
|
+
return fn({
|
|
18
|
+
...tx,
|
|
19
|
+
create: (model, row) => {
|
|
20
|
+
changed ||= model === "release_catalogs";
|
|
21
|
+
tx.create(model, row);
|
|
22
|
+
},
|
|
23
|
+
update: (model, row, set) => {
|
|
24
|
+
changed ||= model === "release_catalogs";
|
|
25
|
+
tx.update(model, row, set);
|
|
26
|
+
},
|
|
27
|
+
delete: (model, row) => {
|
|
28
|
+
changed ||= model === "release_catalogs";
|
|
29
|
+
return tx.delete(model, row);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
if (changed) await onCachedRoutesChange();
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
/** Core's reads and typed writes over one database handle. */
|
|
39
|
+
const createCoreApi = (db, storage, options = {}) => {
|
|
40
|
+
const reads = require_reads.createCoreReads(db, storage);
|
|
41
|
+
return {
|
|
42
|
+
...reads,
|
|
43
|
+
...require_operations.createCoreOperations(purgingCachedRoutes(db, options.onCachedRoutesChange), options),
|
|
44
|
+
/** One read, which checks the schema settings first. */
|
|
45
|
+
ready: async () => {
|
|
46
|
+
await reads.listReleaseCatalogs({ limit: 1 });
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
exports.createCoreApi = createCoreApi;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { CoreDatabase, CoreStorage } from "./reads.cjs";
|
|
2
|
+
//#region src/core/api.d.ts
|
|
3
|
+
interface CoreApiOptions {
|
|
4
|
+
readonly now?: () => number;
|
|
5
|
+
/** The database's CDN purge, called after a write that changes a Release Catalog. */
|
|
6
|
+
readonly onCachedRoutesChange?: () => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
/** Core's reads and typed writes over one database handle. */
|
|
9
|
+
declare const createCoreApi: (db: CoreDatabase, storage: CoreStorage, options?: CoreApiOptions) => {
|
|
10
|
+
/** One read, which checks the schema settings first. */
|
|
11
|
+
ready: () => Promise<void>;
|
|
12
|
+
deploy: (deployments: readonly import("@hot-updater/plugin-core").Deployment[]) => Promise<import("@hot-updater/plugin-core").ReleaseCatalogMutationResult[]>;
|
|
13
|
+
updateReleasePolicy: (input: import("@hot-updater/plugin-core").ReleaseTarget & {
|
|
14
|
+
readonly patch: import("@hot-updater/plugin-core").ReleasePolicyPatch;
|
|
15
|
+
}) => Promise<import("@hot-updater/plugin-core").ReleaseCatalogMutationResult>;
|
|
16
|
+
preflightReleasePolicy: (input: import("@hot-updater/plugin-core").ReleaseTarget & {
|
|
17
|
+
readonly patch: import("@hot-updater/plugin-core").ReleasePolicyPatch;
|
|
18
|
+
}) => Promise<import("@hot-updater/plugin-core").ReleaseCatalogMutationPreflight>;
|
|
19
|
+
deleteRelease: (input: import("@hot-updater/plugin-core").ReleaseTarget) => Promise<import("@hot-updater/plugin-core").ReleaseCatalogMutationResult>;
|
|
20
|
+
promoteRelease: (input: import("@hot-updater/plugin-core").ReleaseTarget & {
|
|
21
|
+
readonly targetChannel: string;
|
|
22
|
+
readonly action?: "copy" | "move";
|
|
23
|
+
}) => Promise<import("@hot-updater/plugin-core").PromoteReleaseResult>;
|
|
24
|
+
rebuildReleaseCatalog: (scopeKey: string) => Promise<import("@hot-updater/plugin-core").ReleaseCatalogRebuildResult>;
|
|
25
|
+
preflightReleaseCatalogRebuild: (scopeKey: string) => Promise<import("@hot-updater/plugin-core").ReleaseCatalogRebuildPreflight>;
|
|
26
|
+
ensureChannel: (name: string) => Promise<import("@hot-updater/plugin-core").ChannelRow>;
|
|
27
|
+
deleteChannel: (id: string) => Promise<import("@hot-updater/plugin-core").ChannelDeleteResult>;
|
|
28
|
+
updateBundle: (id: string, update: Partial<Omit<import("@hot-updater/protocol").Bundle, "id" | "patches">> & {
|
|
29
|
+
readonly patches?: import("@hot-updater/protocol").Bundle["patches"];
|
|
30
|
+
}) => Promise<void>;
|
|
31
|
+
deleteBundles: (ids: readonly string[]) => Promise<void>;
|
|
32
|
+
getReleaseCatalog(input: import("@hot-updater/plugin-core").ReleaseCatalogRequest): Promise<import("@hot-updater/protocol").ReleaseCatalog | null>;
|
|
33
|
+
getArtifactInfo(targetBundleId: string, currentBundleId: string, artifactProtocolVersion: 1): Promise<import("@hot-updater/protocol").ArtifactInfo | null>;
|
|
34
|
+
getBundle(id: string): Promise<import("@hot-updater/plugin-core").BundleDetail | null>;
|
|
35
|
+
countBundleChildren(baseBundleIds: readonly string[]): Promise<Record<string, number>>;
|
|
36
|
+
listPatchesFromBase(baseBundleId: string, input: import("@hot-updater/plugin-core").KeysetInput): Promise<import("@hot-updater/plugin-core").BundlePatchRow[]>;
|
|
37
|
+
listBundles(input: import("@hot-updater/plugin-core").KeysetInput & {
|
|
38
|
+
readonly platform?: "ios" | "android";
|
|
39
|
+
}): Promise<import("@hot-updater/plugin-core").BundleDetail[]>;
|
|
40
|
+
countBundles(platform?: "ios" | "android"): Promise<number>;
|
|
41
|
+
findBaseBundleIds(candidateKey: string, bundleId: string, limit: number): Promise<string[]>;
|
|
42
|
+
getRelease(id: string): Promise<import("@hot-updater/plugin-core").ReleaseRow | null>;
|
|
43
|
+
listReleases(input: import("@hot-updater/plugin-core").KeysetInput & {
|
|
44
|
+
readonly filter: import("@hot-updater/plugin-core").ReleaseFilter;
|
|
45
|
+
}): Promise<import("@hot-updater/plugin-core").ReleaseRow[]>;
|
|
46
|
+
latestReleaseId(scopeKey: string): Promise<string | null>;
|
|
47
|
+
getReleaseCatalogRow(scopeKey: string): Promise<import("@hot-updater/plugin-core").ReleaseCatalogRow | null>;
|
|
48
|
+
listReleaseCatalogs(input: import("@hot-updater/plugin-core").KeysetInput): Promise<import("@hot-updater/plugin-core").ReleaseCatalogRow[]>;
|
|
49
|
+
listChannels(): Promise<import("@hot-updater/plugin-core").ChannelRow[]>;
|
|
50
|
+
findChannelByName(name: string): Promise<import("@hot-updater/plugin-core").ChannelRow | null>;
|
|
51
|
+
};
|
|
52
|
+
type CoreApi = ReturnType<typeof createCoreApi>;
|
|
53
|
+
//#endregion
|
|
54
|
+
export { CoreApi, CoreApiOptions, createCoreApi };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { CoreDatabase, CoreStorage } from "./reads.mjs";
|
|
2
|
+
//#region src/core/api.d.ts
|
|
3
|
+
interface CoreApiOptions {
|
|
4
|
+
readonly now?: () => number;
|
|
5
|
+
/** The database's CDN purge, called after a write that changes a Release Catalog. */
|
|
6
|
+
readonly onCachedRoutesChange?: () => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
/** Core's reads and typed writes over one database handle. */
|
|
9
|
+
declare const createCoreApi: (db: CoreDatabase, storage: CoreStorage, options?: CoreApiOptions) => {
|
|
10
|
+
/** One read, which checks the schema settings first. */
|
|
11
|
+
ready: () => Promise<void>;
|
|
12
|
+
deploy: (deployments: readonly import("@hot-updater/plugin-core").Deployment[]) => Promise<import("@hot-updater/plugin-core").ReleaseCatalogMutationResult[]>;
|
|
13
|
+
updateReleasePolicy: (input: import("@hot-updater/plugin-core").ReleaseTarget & {
|
|
14
|
+
readonly patch: import("@hot-updater/plugin-core").ReleasePolicyPatch;
|
|
15
|
+
}) => Promise<import("@hot-updater/plugin-core").ReleaseCatalogMutationResult>;
|
|
16
|
+
preflightReleasePolicy: (input: import("@hot-updater/plugin-core").ReleaseTarget & {
|
|
17
|
+
readonly patch: import("@hot-updater/plugin-core").ReleasePolicyPatch;
|
|
18
|
+
}) => Promise<import("@hot-updater/plugin-core").ReleaseCatalogMutationPreflight>;
|
|
19
|
+
deleteRelease: (input: import("@hot-updater/plugin-core").ReleaseTarget) => Promise<import("@hot-updater/plugin-core").ReleaseCatalogMutationResult>;
|
|
20
|
+
promoteRelease: (input: import("@hot-updater/plugin-core").ReleaseTarget & {
|
|
21
|
+
readonly targetChannel: string;
|
|
22
|
+
readonly action?: "copy" | "move";
|
|
23
|
+
}) => Promise<import("@hot-updater/plugin-core").PromoteReleaseResult>;
|
|
24
|
+
rebuildReleaseCatalog: (scopeKey: string) => Promise<import("@hot-updater/plugin-core").ReleaseCatalogRebuildResult>;
|
|
25
|
+
preflightReleaseCatalogRebuild: (scopeKey: string) => Promise<import("@hot-updater/plugin-core").ReleaseCatalogRebuildPreflight>;
|
|
26
|
+
ensureChannel: (name: string) => Promise<import("@hot-updater/plugin-core").ChannelRow>;
|
|
27
|
+
deleteChannel: (id: string) => Promise<import("@hot-updater/plugin-core").ChannelDeleteResult>;
|
|
28
|
+
updateBundle: (id: string, update: Partial<Omit<import("@hot-updater/protocol").Bundle, "id" | "patches">> & {
|
|
29
|
+
readonly patches?: import("@hot-updater/protocol").Bundle["patches"];
|
|
30
|
+
}) => Promise<void>;
|
|
31
|
+
deleteBundles: (ids: readonly string[]) => Promise<void>;
|
|
32
|
+
getReleaseCatalog(input: import("@hot-updater/plugin-core").ReleaseCatalogRequest): Promise<import("@hot-updater/protocol").ReleaseCatalog | null>;
|
|
33
|
+
getArtifactInfo(targetBundleId: string, currentBundleId: string, artifactProtocolVersion: 1): Promise<import("@hot-updater/protocol").ArtifactInfo | null>;
|
|
34
|
+
getBundle(id: string): Promise<import("@hot-updater/plugin-core").BundleDetail | null>;
|
|
35
|
+
countBundleChildren(baseBundleIds: readonly string[]): Promise<Record<string, number>>;
|
|
36
|
+
listPatchesFromBase(baseBundleId: string, input: import("@hot-updater/plugin-core").KeysetInput): Promise<import("@hot-updater/plugin-core").BundlePatchRow[]>;
|
|
37
|
+
listBundles(input: import("@hot-updater/plugin-core").KeysetInput & {
|
|
38
|
+
readonly platform?: "ios" | "android";
|
|
39
|
+
}): Promise<import("@hot-updater/plugin-core").BundleDetail[]>;
|
|
40
|
+
countBundles(platform?: "ios" | "android"): Promise<number>;
|
|
41
|
+
findBaseBundleIds(candidateKey: string, bundleId: string, limit: number): Promise<string[]>;
|
|
42
|
+
getRelease(id: string): Promise<import("@hot-updater/plugin-core").ReleaseRow | null>;
|
|
43
|
+
listReleases(input: import("@hot-updater/plugin-core").KeysetInput & {
|
|
44
|
+
readonly filter: import("@hot-updater/plugin-core").ReleaseFilter;
|
|
45
|
+
}): Promise<import("@hot-updater/plugin-core").ReleaseRow[]>;
|
|
46
|
+
latestReleaseId(scopeKey: string): Promise<string | null>;
|
|
47
|
+
getReleaseCatalogRow(scopeKey: string): Promise<import("@hot-updater/plugin-core").ReleaseCatalogRow | null>;
|
|
48
|
+
listReleaseCatalogs(input: import("@hot-updater/plugin-core").KeysetInput): Promise<import("@hot-updater/plugin-core").ReleaseCatalogRow[]>;
|
|
49
|
+
listChannels(): Promise<import("@hot-updater/plugin-core").ChannelRow[]>;
|
|
50
|
+
findChannelByName(name: string): Promise<import("@hot-updater/plugin-core").ChannelRow | null>;
|
|
51
|
+
};
|
|
52
|
+
type CoreApi = ReturnType<typeof createCoreApi>;
|
|
53
|
+
//#endregion
|
|
54
|
+
export { CoreApi, CoreApiOptions, createCoreApi };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createCoreReads } from "./reads.mjs";
|
|
2
|
+
import { createCoreOperations } from "./operations.mjs";
|
|
3
|
+
//#region src/core/api.ts
|
|
4
|
+
/**
|
|
5
|
+
* The update check answers from one Release Catalog row, so a transaction
|
|
6
|
+
* changes what the cacheable client routes answer only when it writes one.
|
|
7
|
+
* The purge runs once, after the attempt that commits.
|
|
8
|
+
*/
|
|
9
|
+
const purgingCachedRoutes = (db, onCachedRoutesChange) => {
|
|
10
|
+
if (onCachedRoutesChange === void 0) return db;
|
|
11
|
+
return {
|
|
12
|
+
...db,
|
|
13
|
+
async transaction(fn) {
|
|
14
|
+
let changed = false;
|
|
15
|
+
const result = await db.transaction((tx) => {
|
|
16
|
+
changed = false;
|
|
17
|
+
return fn({
|
|
18
|
+
...tx,
|
|
19
|
+
create: (model, row) => {
|
|
20
|
+
changed ||= model === "release_catalogs";
|
|
21
|
+
tx.create(model, row);
|
|
22
|
+
},
|
|
23
|
+
update: (model, row, set) => {
|
|
24
|
+
changed ||= model === "release_catalogs";
|
|
25
|
+
tx.update(model, row, set);
|
|
26
|
+
},
|
|
27
|
+
delete: (model, row) => {
|
|
28
|
+
changed ||= model === "release_catalogs";
|
|
29
|
+
return tx.delete(model, row);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
if (changed) await onCachedRoutesChange();
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
/** Core's reads and typed writes over one database handle. */
|
|
39
|
+
const createCoreApi = (db, storage, options = {}) => {
|
|
40
|
+
const reads = createCoreReads(db, storage);
|
|
41
|
+
return {
|
|
42
|
+
...reads,
|
|
43
|
+
...createCoreOperations(purgingCachedRoutes(db, options.onCachedRoutesChange), options),
|
|
44
|
+
/** One read, which checks the schema settings first. */
|
|
45
|
+
ready: async () => {
|
|
46
|
+
await reads.listReleaseCatalogs({ limit: 1 });
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
export { createCoreApi };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const require_releaseCatalog = require("../db/releaseCatalog.cjs");
|
|
2
|
+
let verkit = require("verkit");
|
|
3
|
+
//#region src/core/baseCandidates.ts
|
|
4
|
+
/** A compiled segment as a range: its version when it holds exactly one. */
|
|
5
|
+
const segmentRange = ({ lower, upper }) => lower?.inclusive && upper?.inclusive && lower.version === upper.version ? lower.version : [lower === null ? "" : `${lower.inclusive ? ">=" : ">"}${lower.version}`, upper === null ? "" : `${upper.inclusive ? "<=" : "<"}${upper.version}`].join(" ").trim() || "*";
|
|
6
|
+
/**
|
|
7
|
+
* Auto-patch bases from a scope's compiled Release Catalog, which holds
|
|
8
|
+
* every enabled bundle release of the scope: those whose range intersects
|
|
9
|
+
* `range` (all of them in a fingerprint scope), newest release first, each
|
|
10
|
+
* bundle once and older than `bundleId`, at most `limit`.
|
|
11
|
+
*/
|
|
12
|
+
const baseBundleIdsOf = (row, range, bundleId, limit) => {
|
|
13
|
+
const catalog = require_releaseCatalog.parseCompiledCatalog(row.payload, row.strategy);
|
|
14
|
+
const serving = new Set(catalog.strategy === "FINGERPRINT" ? catalog.rollbackReleaseIndexes : catalog.segments.flatMap((segment) => range !== null && (0, verkit.rangesIntersect)(range, segmentRange(segment)) ? segment.rollbackReleaseIndexes : []));
|
|
15
|
+
const newestFirst = catalog.releaseDescriptors.map((descriptor, index) => ({
|
|
16
|
+
descriptor,
|
|
17
|
+
index
|
|
18
|
+
})).sort((left, right) => left.descriptor.releaseId < right.descriptor.releaseId ? 1 : -1);
|
|
19
|
+
const ids = [];
|
|
20
|
+
for (const { descriptor, index } of newestFirst) {
|
|
21
|
+
if (ids.length >= limit) break;
|
|
22
|
+
const id = descriptor.bundleId;
|
|
23
|
+
if (serving.has(index) && descriptor.kind === "BUNDLE" && id !== null && id < bundleId && !ids.includes(id)) ids.push(id);
|
|
24
|
+
}
|
|
25
|
+
return ids;
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.baseBundleIdsOf = baseBundleIdsOf;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { parseCompiledCatalog } from "../db/releaseCatalog.mjs";
|
|
2
|
+
import { rangesIntersect } from "verkit";
|
|
3
|
+
//#region src/core/baseCandidates.ts
|
|
4
|
+
/** A compiled segment as a range: its version when it holds exactly one. */
|
|
5
|
+
const segmentRange = ({ lower, upper }) => lower?.inclusive && upper?.inclusive && lower.version === upper.version ? lower.version : [lower === null ? "" : `${lower.inclusive ? ">=" : ">"}${lower.version}`, upper === null ? "" : `${upper.inclusive ? "<=" : "<"}${upper.version}`].join(" ").trim() || "*";
|
|
6
|
+
/**
|
|
7
|
+
* Auto-patch bases from a scope's compiled Release Catalog, which holds
|
|
8
|
+
* every enabled bundle release of the scope: those whose range intersects
|
|
9
|
+
* `range` (all of them in a fingerprint scope), newest release first, each
|
|
10
|
+
* bundle once and older than `bundleId`, at most `limit`.
|
|
11
|
+
*/
|
|
12
|
+
const baseBundleIdsOf = (row, range, bundleId, limit) => {
|
|
13
|
+
const catalog = parseCompiledCatalog(row.payload, row.strategy);
|
|
14
|
+
const serving = new Set(catalog.strategy === "FINGERPRINT" ? catalog.rollbackReleaseIndexes : catalog.segments.flatMap((segment) => range !== null && rangesIntersect(range, segmentRange(segment)) ? segment.rollbackReleaseIndexes : []));
|
|
15
|
+
const newestFirst = catalog.releaseDescriptors.map((descriptor, index) => ({
|
|
16
|
+
descriptor,
|
|
17
|
+
index
|
|
18
|
+
})).sort((left, right) => left.descriptor.releaseId < right.descriptor.releaseId ? 1 : -1);
|
|
19
|
+
const ids = [];
|
|
20
|
+
for (const { descriptor, index } of newestFirst) {
|
|
21
|
+
if (ids.length >= limit) break;
|
|
22
|
+
const id = descriptor.bundleId;
|
|
23
|
+
if (serving.has(index) && descriptor.kind === "BUNDLE" && id !== null && id < bundleId && !ids.includes(id)) ids.push(id);
|
|
24
|
+
}
|
|
25
|
+
return ids;
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
28
|
+
export { baseBundleIdsOf };
|