@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
package/dist/apiKeys.mjs
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
//#region src/apiKeys.ts
|
|
2
|
-
const API_KEY_HEADER_NAME = "x-api-key";
|
|
3
|
-
const BASE64URL_32_PATTERN = /^[A-Za-z0-9_-]{43}$/u;
|
|
4
|
-
const bytesToBase64Url = (bytes) => {
|
|
5
|
-
let binary = "";
|
|
6
|
-
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
7
|
-
return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/u, "");
|
|
8
|
-
};
|
|
9
|
-
const isApiKey = (value) => {
|
|
10
|
-
if (!BASE64URL_32_PATTERN.test(value)) return false;
|
|
11
|
-
try {
|
|
12
|
-
const base64 = value.replaceAll("-", "+").replaceAll("_", "/");
|
|
13
|
-
const binary = atob(`${base64}=`);
|
|
14
|
-
const bytes = Uint8Array.from(binary, (character) => character.charCodeAt(0));
|
|
15
|
-
return bytes.byteLength === 32 && bytesToBase64Url(bytes) === value;
|
|
16
|
-
} catch {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
const normalizeApiKeyHeaderName = (value = API_KEY_HEADER_NAME) => {
|
|
21
|
-
if (typeof value !== "string" || value.length === 0) throw new TypeError("clientAccess.headerName must be a valid header name.");
|
|
22
|
-
try {
|
|
23
|
-
const headers = new Headers();
|
|
24
|
-
headers.set(value, "");
|
|
25
|
-
return headers.keys().next().value;
|
|
26
|
-
} catch {
|
|
27
|
-
throw new TypeError("clientAccess.headerName must be a valid header name.");
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
const hashApiKey = async (apiKey) => {
|
|
31
|
-
if (!isApiKey(apiKey)) throw new TypeError("API key must be a canonical 32-byte base64url value.");
|
|
32
|
-
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(apiKey));
|
|
33
|
-
return bytesToBase64Url(new Uint8Array(digest));
|
|
34
|
-
};
|
|
35
|
-
const apiKeyId = () => {
|
|
36
|
-
const bytes = /* @__PURE__ */ new Uint8Array(16);
|
|
37
|
-
crypto.getRandomValues(bytes);
|
|
38
|
-
return `api-${bytesToBase64Url(bytes)}`;
|
|
39
|
-
};
|
|
40
|
-
const normalizeApiKeyName = (name) => {
|
|
41
|
-
const normalized = name.trim();
|
|
42
|
-
if (normalized.length === 0 || normalized.length > 64 || /[\p{Cc}\p{Cf}]/u.test(normalized)) throw new TypeError("API key names must contain 1-64 visible characters.");
|
|
43
|
-
return normalized;
|
|
44
|
-
};
|
|
45
|
-
const toApiKeyMetadata = ({ hash: _hash, ...metadata }) => Object.freeze(metadata);
|
|
46
|
-
const registerApiKey = async (input) => {
|
|
47
|
-
const hash = await hashApiKey(input.apiKey);
|
|
48
|
-
const createdAtMs = input.createdAtMs ?? Date.now();
|
|
49
|
-
if (!Number.isSafeInteger(createdAtMs) || createdAtMs < 0) throw new TypeError("API key creation time must be non-negative.");
|
|
50
|
-
const record = Object.freeze({
|
|
51
|
-
created_at_ms: createdAtMs,
|
|
52
|
-
hash,
|
|
53
|
-
id: apiKeyId(),
|
|
54
|
-
name: normalizeApiKeyName(input.name),
|
|
55
|
-
prefix: input.apiKey.slice(0, 6),
|
|
56
|
-
revoked_at_ms: null,
|
|
57
|
-
role: "client"
|
|
58
|
-
});
|
|
59
|
-
if (await input.apiKeys.create(record) === "existing") {
|
|
60
|
-
const existing = await input.apiKeys.findByHash(hash);
|
|
61
|
-
if (existing === null || existing.revoked_at_ms !== null) throw new Error("The API key has been revoked.");
|
|
62
|
-
return Object.freeze({
|
|
63
|
-
apiKey: input.apiKey,
|
|
64
|
-
record: toApiKeyMetadata(existing)
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
return Object.freeze({
|
|
68
|
-
apiKey: input.apiKey,
|
|
69
|
-
record: toApiKeyMetadata(record)
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
const createApiKey = (input) => {
|
|
73
|
-
const bytes = /* @__PURE__ */ new Uint8Array(32);
|
|
74
|
-
crypto.getRandomValues(bytes);
|
|
75
|
-
return registerApiKey({
|
|
76
|
-
apiKey: bytesToBase64Url(bytes),
|
|
77
|
-
apiKeys: input.apiKeys,
|
|
78
|
-
name: input.name
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Provisions the client API key used by managed init.
|
|
83
|
-
*
|
|
84
|
-
* A saved plaintext key is registered idempotently; otherwise a new key is
|
|
85
|
-
* created. Callers must persist or display the returned plaintext because the
|
|
86
|
-
* database stores only its hash.
|
|
87
|
-
*/
|
|
88
|
-
const provisionApiKey = (input) => {
|
|
89
|
-
const existingApiKey = input.existingApiKey?.trim();
|
|
90
|
-
return existingApiKey ? registerApiKey({
|
|
91
|
-
apiKey: existingApiKey,
|
|
92
|
-
apiKeys: input.apiKeys,
|
|
93
|
-
name: input.name
|
|
94
|
-
}) : createApiKey({
|
|
95
|
-
apiKeys: input.apiKeys,
|
|
96
|
-
name: input.name
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
const authenticateApiKey = async (input) => {
|
|
100
|
-
const apiKey = input.request.headers.get(normalizeApiKeyHeaderName(input.headerName));
|
|
101
|
-
if (apiKey === null || !isApiKey(apiKey)) return false;
|
|
102
|
-
const hash = await hashApiKey(apiKey);
|
|
103
|
-
await input.beforeLookup?.();
|
|
104
|
-
const record = await input.apiKeys.findByHash(hash);
|
|
105
|
-
return record !== null && record.hash === hash && record.role === "client" && record.revoked_at_ms === null;
|
|
106
|
-
};
|
|
107
|
-
const createApiKeyManagement = (input) => Object.freeze({
|
|
108
|
-
async create({ name }) {
|
|
109
|
-
await input.beforeOperation();
|
|
110
|
-
const created = await createApiKey({
|
|
111
|
-
apiKeys: input.apiKeys,
|
|
112
|
-
name
|
|
113
|
-
});
|
|
114
|
-
return Object.freeze({
|
|
115
|
-
apiKey: created.apiKey,
|
|
116
|
-
record: created.record
|
|
117
|
-
});
|
|
118
|
-
},
|
|
119
|
-
async list() {
|
|
120
|
-
await input.beforeOperation();
|
|
121
|
-
return Object.freeze((await input.apiKeys.list()).map(toApiKeyMetadata));
|
|
122
|
-
},
|
|
123
|
-
async revoke({ id }) {
|
|
124
|
-
await input.beforeOperation();
|
|
125
|
-
const record = await input.apiKeys.revoke({
|
|
126
|
-
id,
|
|
127
|
-
revokedAtMs: Date.now()
|
|
128
|
-
});
|
|
129
|
-
return record === null ? null : toApiKeyMetadata(record);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
//#endregion
|
|
133
|
-
export { API_KEY_HEADER_NAME, apiKeyId, authenticateApiKey, createApiKey, createApiKeyManagement, hashApiKey, isApiKey, normalizeApiKeyHeaderName, normalizeApiKeyName, provisionApiKey, registerApiKey };
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
3
|
-
let _hot_updater_core = require("@hot-updater/core");
|
|
4
|
-
let node_crypto = require("node:crypto");
|
|
5
|
-
node_crypto = require_runtime.__toESM(node_crypto, 1);
|
|
6
|
-
let node_path = require("node:path");
|
|
7
|
-
node_path = require_runtime.__toESM(node_path, 1);
|
|
8
|
-
let node_util = require("node:util");
|
|
9
|
-
let node_zlib = require("node:zlib");
|
|
10
|
-
let _hot_updater_bsdiff = require("@hot-updater/bsdiff");
|
|
11
|
-
//#region src/db/createBundleDiff.ts
|
|
12
|
-
const HBC_ASSET_PATH_RE = /\.bundle$/;
|
|
13
|
-
const decompressBrotli = (0, node_util.promisify)(node_zlib.brotliDecompress);
|
|
14
|
-
const isBundleManifest = (value) => {
|
|
15
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
16
|
-
const manifest = value;
|
|
17
|
-
if (typeof manifest.bundleId !== "string") return false;
|
|
18
|
-
if (!manifest.assets || typeof manifest.assets !== "object") return false;
|
|
19
|
-
return Object.values(manifest.assets).every((asset) => {
|
|
20
|
-
if (!asset || typeof asset !== "object" || Array.isArray(asset)) return false;
|
|
21
|
-
const manifestAsset = asset;
|
|
22
|
-
return typeof manifestAsset.fileHash === "string" && (manifestAsset.signature === void 0 || typeof manifestAsset.signature === "string");
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
const getRelativeStorageDir = (relativePath) => {
|
|
26
|
-
const normalized = relativePath.replace(/\\/g, "/");
|
|
27
|
-
const dirname = node_path.default.posix.dirname(normalized);
|
|
28
|
-
return dirname === "." ? "" : dirname;
|
|
29
|
-
};
|
|
30
|
-
async function downloadFromUrl(url) {
|
|
31
|
-
const response = await fetch(url);
|
|
32
|
-
if (!response.ok) throw new Error(`Failed to download storage object: ${response.status}`);
|
|
33
|
-
return new Uint8Array(await response.arrayBuffer());
|
|
34
|
-
}
|
|
35
|
-
async function downloadStorageBytes(storageUri, storagePlugin) {
|
|
36
|
-
const protocol = new URL(storageUri).protocol.replace(":", "");
|
|
37
|
-
if (!storagePlugin || storagePlugin.protocol !== protocol) {
|
|
38
|
-
if (protocol === "http" || protocol === "https") return downloadFromUrl(storageUri);
|
|
39
|
-
if (!storagePlugin) throw new Error("Storage plugin is not configured");
|
|
40
|
-
throw new Error(`No storage plugin for protocol: ${protocol}`);
|
|
41
|
-
}
|
|
42
|
-
const { response } = await storagePlugin.get({ storageUri });
|
|
43
|
-
if (response === null) throw new Error(`Storage object not found: ${storageUri}`);
|
|
44
|
-
return new Uint8Array(await response.arrayBuffer());
|
|
45
|
-
}
|
|
46
|
-
async function fetchManifest(bundle, storagePlugin) {
|
|
47
|
-
const manifestStorageUri = (0, _hot_updater_core.getManifestStorageUri)(bundle);
|
|
48
|
-
if (!manifestStorageUri) throw new Error(`Bundle ${bundle.id} does not have manifest metadata`);
|
|
49
|
-
const manifestBytes = await downloadStorageBytes(manifestStorageUri, storagePlugin);
|
|
50
|
-
const payload = JSON.parse(new TextDecoder().decode(manifestBytes));
|
|
51
|
-
if (!isBundleManifest(payload)) throw new Error(`Invalid manifest payload for bundle ${bundle.id}`);
|
|
52
|
-
return payload;
|
|
53
|
-
}
|
|
54
|
-
function resolveHbcAssetPath(manifest) {
|
|
55
|
-
const candidates = Object.keys(manifest.assets).sort((left, right) => left.localeCompare(right)).filter((candidate) => HBC_ASSET_PATH_RE.test(candidate));
|
|
56
|
-
if (candidates.length === 0) throw new Error("No Hermes bundle asset found in manifest");
|
|
57
|
-
if (candidates.length > 1) throw new Error(`Expected exactly one Hermes bundle asset in manifest, found ${candidates.length}: ${candidates.join(", ")}`);
|
|
58
|
-
return candidates[0];
|
|
59
|
-
}
|
|
60
|
-
async function fetchAssetBytes(bundle, assetPath, manifest, storagePlugin) {
|
|
61
|
-
const assetBaseStorageUri = (0, _hot_updater_core.getAssetBaseStorageUri)(bundle);
|
|
62
|
-
if (!assetBaseStorageUri) throw new Error(`Bundle ${bundle.id} does not have asset storage metadata`);
|
|
63
|
-
const asset = manifest.assets[assetPath];
|
|
64
|
-
if (!asset) throw new Error(`Asset ${assetPath} is missing from manifest`);
|
|
65
|
-
const downloadPath = (0, _hot_updater_plugin_core.getManifestAssetDownloadPath)(assetPath);
|
|
66
|
-
if (downloadPath !== assetPath) {
|
|
67
|
-
const compressedAssetStorageUri = (0, _hot_updater_plugin_core.resolveManifestAssetStorageUri)({
|
|
68
|
-
assetBaseStorageUri,
|
|
69
|
-
assetPath: downloadPath,
|
|
70
|
-
downloadFileHash: asset.downloadFileHash,
|
|
71
|
-
fileHash: asset.fileHash
|
|
72
|
-
});
|
|
73
|
-
let compressedBytes = null;
|
|
74
|
-
try {
|
|
75
|
-
compressedBytes = await downloadStorageBytes(compressedAssetStorageUri, storagePlugin);
|
|
76
|
-
} catch (error) {
|
|
77
|
-
if (!(error instanceof Error)) throw error;
|
|
78
|
-
compressedBytes = null;
|
|
79
|
-
}
|
|
80
|
-
if (compressedBytes) return new Uint8Array(await decompressBrotli(compressedBytes));
|
|
81
|
-
}
|
|
82
|
-
return downloadStorageBytes((0, _hot_updater_plugin_core.resolveManifestAssetStorageUri)({
|
|
83
|
-
assetBaseStorageUri,
|
|
84
|
-
assetPath,
|
|
85
|
-
fileHash: asset.fileHash
|
|
86
|
-
}), storagePlugin);
|
|
87
|
-
}
|
|
88
|
-
function buildNextPatchState({ currentBundle, nextPatch, makePrimary }) {
|
|
89
|
-
const existingPatches = (0, _hot_updater_core.getBundlePatches)(currentBundle).filter((patch) => patch.baseBundleId !== nextPatch.baseBundleId);
|
|
90
|
-
return makePrimary ? [nextPatch, ...existingPatches] : [...existingPatches, nextPatch];
|
|
91
|
-
}
|
|
92
|
-
async function createBundleDiff({ baseBundleId, bundleId }, deps, options = {}) {
|
|
93
|
-
const database = (0, _hot_updater_plugin_core.createDatabaseClient)(deps.databasePlugin);
|
|
94
|
-
if (!deps.storagePlugin) throw new Error("Storage plugin is not configured");
|
|
95
|
-
if (baseBundleId === bundleId) throw new Error("Base bundle must be different from the target bundle");
|
|
96
|
-
const baseBundle = await database.getBundleById(baseBundleId);
|
|
97
|
-
const targetBundle = await database.getBundleById(bundleId);
|
|
98
|
-
if (!baseBundle || !targetBundle) throw new Error("Bundle not found");
|
|
99
|
-
if (baseBundle.platform !== targetBundle.platform) throw new Error("Base bundle platform must match the target bundle");
|
|
100
|
-
if (baseBundle.id.localeCompare(targetBundle.id) >= 0) throw new Error("Base bundle must be older than the target bundle");
|
|
101
|
-
const [baseManifest, targetManifest] = await Promise.all([fetchManifest(baseBundle, deps.storagePlugin), fetchManifest(targetBundle, deps.storagePlugin)]);
|
|
102
|
-
const baseAssetPath = resolveHbcAssetPath(baseManifest);
|
|
103
|
-
const targetAssetPath = resolveHbcAssetPath(targetManifest);
|
|
104
|
-
if (baseAssetPath !== targetAssetPath) throw new Error("Base and target Hermes asset paths do not match");
|
|
105
|
-
const baseAssetHash = baseManifest.assets[baseAssetPath]?.fileHash;
|
|
106
|
-
const targetAssetHash = targetManifest.assets[targetAssetPath]?.fileHash;
|
|
107
|
-
if (!baseAssetHash || !targetAssetHash) throw new Error("Hermes asset hash is missing from manifest");
|
|
108
|
-
if (baseAssetHash === targetAssetHash) throw new Error("Hermes bundle is unchanged; no diff patch is required");
|
|
109
|
-
const [baseBytes, targetBytes] = await Promise.all([fetchAssetBytes(baseBundle, baseAssetPath, baseManifest, deps.storagePlugin), fetchAssetBytes(targetBundle, targetAssetPath, targetManifest, deps.storagePlugin)]);
|
|
110
|
-
const patchBytes = await (0, _hot_updater_bsdiff.hdiff)(baseBytes, targetBytes);
|
|
111
|
-
const patchFileHash = node_crypto.default.createHash("sha256").update(patchBytes).digest("hex");
|
|
112
|
-
const patchFilename = `${node_path.default.posix.basename(targetAssetPath)}.bsdiff`;
|
|
113
|
-
const previousPatch = (0, _hot_updater_core.getBundlePatch)(targetBundle, baseBundle.id);
|
|
114
|
-
const uploadKey = (0, _hot_updater_plugin_core.createBundleStorageKey)(targetBundle.id, "patches", baseBundle.id, patchFileHash, getRelativeStorageDir(targetAssetPath), patchFilename);
|
|
115
|
-
const patchUpload = await deps.storagePlugin.put({
|
|
116
|
-
key: uploadKey,
|
|
117
|
-
body: new ReadableStream({ start(controller) {
|
|
118
|
-
controller.enqueue(patchBytes);
|
|
119
|
-
controller.close();
|
|
120
|
-
} }),
|
|
121
|
-
contentLength: patchBytes.byteLength,
|
|
122
|
-
contentType: "application/octet-stream"
|
|
123
|
-
});
|
|
124
|
-
const patches = buildNextPatchState({
|
|
125
|
-
currentBundle: targetBundle,
|
|
126
|
-
nextPatch: {
|
|
127
|
-
baseBundleId: baseBundle.id,
|
|
128
|
-
baseFileHash: baseAssetHash,
|
|
129
|
-
byteSize: patchBytes.byteLength,
|
|
130
|
-
patchFileHash,
|
|
131
|
-
patchStorageUri: patchUpload.storageUri
|
|
132
|
-
},
|
|
133
|
-
makePrimary: options.makePrimary ?? true
|
|
134
|
-
});
|
|
135
|
-
const updatedBundle = {
|
|
136
|
-
...targetBundle,
|
|
137
|
-
patches
|
|
138
|
-
};
|
|
139
|
-
await database.updateBundleById(targetBundle.id, updatedBundle);
|
|
140
|
-
if (previousPatch?.patchStorageUri && previousPatch.patchStorageUri !== patchUpload.storageUri) await deps.storagePlugin.delete({ storageUri: previousPatch.patchStorageUri }).catch(() => {});
|
|
141
|
-
return updatedBundle;
|
|
142
|
-
}
|
|
143
|
-
//#endregion
|
|
144
|
-
exports.createBundleDiff = createBundleDiff;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Bundle, BundleRepository, StoragePluginWith } from "@hot-updater/plugin-core";
|
|
2
|
-
//#region src/db/createBundleDiff.d.ts
|
|
3
|
-
interface CreateBundleDiffInput {
|
|
4
|
-
baseBundleId: string;
|
|
5
|
-
bundleId: string;
|
|
6
|
-
}
|
|
7
|
-
interface CreateBundleDiffDependencies {
|
|
8
|
-
databasePlugin: BundleRepository;
|
|
9
|
-
storagePlugin: StoragePluginWith<"get" | "put" | "delete"> | null;
|
|
10
|
-
}
|
|
11
|
-
interface CreateBundleDiffOptions {
|
|
12
|
-
makePrimary?: boolean;
|
|
13
|
-
}
|
|
14
|
-
declare function createBundleDiff({ baseBundleId, bundleId }: CreateBundleDiffInput, deps: CreateBundleDiffDependencies, options?: CreateBundleDiffOptions): Promise<Bundle>;
|
|
15
|
-
//#endregion
|
|
16
|
-
export { CreateBundleDiffDependencies, CreateBundleDiffInput, CreateBundleDiffOptions, createBundleDiff };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Bundle, BundleRepository, StoragePluginWith } from "@hot-updater/plugin-core";
|
|
2
|
-
//#region src/db/createBundleDiff.d.ts
|
|
3
|
-
interface CreateBundleDiffInput {
|
|
4
|
-
baseBundleId: string;
|
|
5
|
-
bundleId: string;
|
|
6
|
-
}
|
|
7
|
-
interface CreateBundleDiffDependencies {
|
|
8
|
-
databasePlugin: BundleRepository;
|
|
9
|
-
storagePlugin: StoragePluginWith<"get" | "put" | "delete"> | null;
|
|
10
|
-
}
|
|
11
|
-
interface CreateBundleDiffOptions {
|
|
12
|
-
makePrimary?: boolean;
|
|
13
|
-
}
|
|
14
|
-
declare function createBundleDiff({ baseBundleId, bundleId }: CreateBundleDiffInput, deps: CreateBundleDiffDependencies, options?: CreateBundleDiffOptions): Promise<Bundle>;
|
|
15
|
-
//#endregion
|
|
16
|
-
export { CreateBundleDiffDependencies, CreateBundleDiffInput, CreateBundleDiffOptions, createBundleDiff };
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { createBundleStorageKey, createDatabaseClient, getManifestAssetDownloadPath, resolveManifestAssetStorageUri } from "@hot-updater/plugin-core";
|
|
2
|
-
import { getAssetBaseStorageUri, getBundlePatch, getBundlePatches, getManifestStorageUri } from "@hot-updater/core";
|
|
3
|
-
import crypto from "node:crypto";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import { promisify } from "node:util";
|
|
6
|
-
import { brotliDecompress } from "node:zlib";
|
|
7
|
-
import { hdiff } from "@hot-updater/bsdiff";
|
|
8
|
-
//#region src/db/createBundleDiff.ts
|
|
9
|
-
const HBC_ASSET_PATH_RE = /\.bundle$/;
|
|
10
|
-
const decompressBrotli = promisify(brotliDecompress);
|
|
11
|
-
const isBundleManifest = (value) => {
|
|
12
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
13
|
-
const manifest = value;
|
|
14
|
-
if (typeof manifest.bundleId !== "string") return false;
|
|
15
|
-
if (!manifest.assets || typeof manifest.assets !== "object") return false;
|
|
16
|
-
return Object.values(manifest.assets).every((asset) => {
|
|
17
|
-
if (!asset || typeof asset !== "object" || Array.isArray(asset)) return false;
|
|
18
|
-
const manifestAsset = asset;
|
|
19
|
-
return typeof manifestAsset.fileHash === "string" && (manifestAsset.signature === void 0 || typeof manifestAsset.signature === "string");
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
const getRelativeStorageDir = (relativePath) => {
|
|
23
|
-
const normalized = relativePath.replace(/\\/g, "/");
|
|
24
|
-
const dirname = path.posix.dirname(normalized);
|
|
25
|
-
return dirname === "." ? "" : dirname;
|
|
26
|
-
};
|
|
27
|
-
async function downloadFromUrl(url) {
|
|
28
|
-
const response = await fetch(url);
|
|
29
|
-
if (!response.ok) throw new Error(`Failed to download storage object: ${response.status}`);
|
|
30
|
-
return new Uint8Array(await response.arrayBuffer());
|
|
31
|
-
}
|
|
32
|
-
async function downloadStorageBytes(storageUri, storagePlugin) {
|
|
33
|
-
const protocol = new URL(storageUri).protocol.replace(":", "");
|
|
34
|
-
if (!storagePlugin || storagePlugin.protocol !== protocol) {
|
|
35
|
-
if (protocol === "http" || protocol === "https") return downloadFromUrl(storageUri);
|
|
36
|
-
if (!storagePlugin) throw new Error("Storage plugin is not configured");
|
|
37
|
-
throw new Error(`No storage plugin for protocol: ${protocol}`);
|
|
38
|
-
}
|
|
39
|
-
const { response } = await storagePlugin.get({ storageUri });
|
|
40
|
-
if (response === null) throw new Error(`Storage object not found: ${storageUri}`);
|
|
41
|
-
return new Uint8Array(await response.arrayBuffer());
|
|
42
|
-
}
|
|
43
|
-
async function fetchManifest(bundle, storagePlugin) {
|
|
44
|
-
const manifestStorageUri = getManifestStorageUri(bundle);
|
|
45
|
-
if (!manifestStorageUri) throw new Error(`Bundle ${bundle.id} does not have manifest metadata`);
|
|
46
|
-
const manifestBytes = await downloadStorageBytes(manifestStorageUri, storagePlugin);
|
|
47
|
-
const payload = JSON.parse(new TextDecoder().decode(manifestBytes));
|
|
48
|
-
if (!isBundleManifest(payload)) throw new Error(`Invalid manifest payload for bundle ${bundle.id}`);
|
|
49
|
-
return payload;
|
|
50
|
-
}
|
|
51
|
-
function resolveHbcAssetPath(manifest) {
|
|
52
|
-
const candidates = Object.keys(manifest.assets).sort((left, right) => left.localeCompare(right)).filter((candidate) => HBC_ASSET_PATH_RE.test(candidate));
|
|
53
|
-
if (candidates.length === 0) throw new Error("No Hermes bundle asset found in manifest");
|
|
54
|
-
if (candidates.length > 1) throw new Error(`Expected exactly one Hermes bundle asset in manifest, found ${candidates.length}: ${candidates.join(", ")}`);
|
|
55
|
-
return candidates[0];
|
|
56
|
-
}
|
|
57
|
-
async function fetchAssetBytes(bundle, assetPath, manifest, storagePlugin) {
|
|
58
|
-
const assetBaseStorageUri = getAssetBaseStorageUri(bundle);
|
|
59
|
-
if (!assetBaseStorageUri) throw new Error(`Bundle ${bundle.id} does not have asset storage metadata`);
|
|
60
|
-
const asset = manifest.assets[assetPath];
|
|
61
|
-
if (!asset) throw new Error(`Asset ${assetPath} is missing from manifest`);
|
|
62
|
-
const downloadPath = getManifestAssetDownloadPath(assetPath);
|
|
63
|
-
if (downloadPath !== assetPath) {
|
|
64
|
-
const compressedAssetStorageUri = resolveManifestAssetStorageUri({
|
|
65
|
-
assetBaseStorageUri,
|
|
66
|
-
assetPath: downloadPath,
|
|
67
|
-
downloadFileHash: asset.downloadFileHash,
|
|
68
|
-
fileHash: asset.fileHash
|
|
69
|
-
});
|
|
70
|
-
let compressedBytes = null;
|
|
71
|
-
try {
|
|
72
|
-
compressedBytes = await downloadStorageBytes(compressedAssetStorageUri, storagePlugin);
|
|
73
|
-
} catch (error) {
|
|
74
|
-
if (!(error instanceof Error)) throw error;
|
|
75
|
-
compressedBytes = null;
|
|
76
|
-
}
|
|
77
|
-
if (compressedBytes) return new Uint8Array(await decompressBrotli(compressedBytes));
|
|
78
|
-
}
|
|
79
|
-
return downloadStorageBytes(resolveManifestAssetStorageUri({
|
|
80
|
-
assetBaseStorageUri,
|
|
81
|
-
assetPath,
|
|
82
|
-
fileHash: asset.fileHash
|
|
83
|
-
}), storagePlugin);
|
|
84
|
-
}
|
|
85
|
-
function buildNextPatchState({ currentBundle, nextPatch, makePrimary }) {
|
|
86
|
-
const existingPatches = getBundlePatches(currentBundle).filter((patch) => patch.baseBundleId !== nextPatch.baseBundleId);
|
|
87
|
-
return makePrimary ? [nextPatch, ...existingPatches] : [...existingPatches, nextPatch];
|
|
88
|
-
}
|
|
89
|
-
async function createBundleDiff({ baseBundleId, bundleId }, deps, options = {}) {
|
|
90
|
-
const database = createDatabaseClient(deps.databasePlugin);
|
|
91
|
-
if (!deps.storagePlugin) throw new Error("Storage plugin is not configured");
|
|
92
|
-
if (baseBundleId === bundleId) throw new Error("Base bundle must be different from the target bundle");
|
|
93
|
-
const baseBundle = await database.getBundleById(baseBundleId);
|
|
94
|
-
const targetBundle = await database.getBundleById(bundleId);
|
|
95
|
-
if (!baseBundle || !targetBundle) throw new Error("Bundle not found");
|
|
96
|
-
if (baseBundle.platform !== targetBundle.platform) throw new Error("Base bundle platform must match the target bundle");
|
|
97
|
-
if (baseBundle.id.localeCompare(targetBundle.id) >= 0) throw new Error("Base bundle must be older than the target bundle");
|
|
98
|
-
const [baseManifest, targetManifest] = await Promise.all([fetchManifest(baseBundle, deps.storagePlugin), fetchManifest(targetBundle, deps.storagePlugin)]);
|
|
99
|
-
const baseAssetPath = resolveHbcAssetPath(baseManifest);
|
|
100
|
-
const targetAssetPath = resolveHbcAssetPath(targetManifest);
|
|
101
|
-
if (baseAssetPath !== targetAssetPath) throw new Error("Base and target Hermes asset paths do not match");
|
|
102
|
-
const baseAssetHash = baseManifest.assets[baseAssetPath]?.fileHash;
|
|
103
|
-
const targetAssetHash = targetManifest.assets[targetAssetPath]?.fileHash;
|
|
104
|
-
if (!baseAssetHash || !targetAssetHash) throw new Error("Hermes asset hash is missing from manifest");
|
|
105
|
-
if (baseAssetHash === targetAssetHash) throw new Error("Hermes bundle is unchanged; no diff patch is required");
|
|
106
|
-
const [baseBytes, targetBytes] = await Promise.all([fetchAssetBytes(baseBundle, baseAssetPath, baseManifest, deps.storagePlugin), fetchAssetBytes(targetBundle, targetAssetPath, targetManifest, deps.storagePlugin)]);
|
|
107
|
-
const patchBytes = await hdiff(baseBytes, targetBytes);
|
|
108
|
-
const patchFileHash = crypto.createHash("sha256").update(patchBytes).digest("hex");
|
|
109
|
-
const patchFilename = `${path.posix.basename(targetAssetPath)}.bsdiff`;
|
|
110
|
-
const previousPatch = getBundlePatch(targetBundle, baseBundle.id);
|
|
111
|
-
const uploadKey = createBundleStorageKey(targetBundle.id, "patches", baseBundle.id, patchFileHash, getRelativeStorageDir(targetAssetPath), patchFilename);
|
|
112
|
-
const patchUpload = await deps.storagePlugin.put({
|
|
113
|
-
key: uploadKey,
|
|
114
|
-
body: new ReadableStream({ start(controller) {
|
|
115
|
-
controller.enqueue(patchBytes);
|
|
116
|
-
controller.close();
|
|
117
|
-
} }),
|
|
118
|
-
contentLength: patchBytes.byteLength,
|
|
119
|
-
contentType: "application/octet-stream"
|
|
120
|
-
});
|
|
121
|
-
const patches = buildNextPatchState({
|
|
122
|
-
currentBundle: targetBundle,
|
|
123
|
-
nextPatch: {
|
|
124
|
-
baseBundleId: baseBundle.id,
|
|
125
|
-
baseFileHash: baseAssetHash,
|
|
126
|
-
byteSize: patchBytes.byteLength,
|
|
127
|
-
patchFileHash,
|
|
128
|
-
patchStorageUri: patchUpload.storageUri
|
|
129
|
-
},
|
|
130
|
-
makePrimary: options.makePrimary ?? true
|
|
131
|
-
});
|
|
132
|
-
const updatedBundle = {
|
|
133
|
-
...targetBundle,
|
|
134
|
-
patches
|
|
135
|
-
};
|
|
136
|
-
await database.updateBundleById(targetBundle.id, updatedBundle);
|
|
137
|
-
if (previousPatch?.patchStorageUri && previousPatch.patchStorageUri !== patchUpload.storageUri) await deps.storagePlugin.delete({ storageUri: previousPatch.patchStorageUri }).catch(() => {});
|
|
138
|
-
return updatedBundle;
|
|
139
|
-
}
|
|
140
|
-
//#endregion
|
|
141
|
-
export { createBundleDiff };
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
const require_releaseCatalog = require("./releaseCatalog.cjs");
|
|
2
|
-
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
3
|
-
let _hot_updater_core = require("@hot-updater/core");
|
|
4
|
-
//#region src/db/databasePluginCore.ts
|
|
5
|
-
function createDatabasePluginCore(database, resolveFileUrl, options) {
|
|
6
|
-
const client = (0, _hot_updater_plugin_core.createDatabaseClient)(database);
|
|
7
|
-
const beforeOperation = options?.beforeOperation;
|
|
8
|
-
const getReleaseCatalog = require_releaseCatalog.createReleaseCatalogReader(database);
|
|
9
|
-
const getArtifact = require_releaseCatalog.createArtifactResolver({
|
|
10
|
-
database,
|
|
11
|
-
readStorageText: options?.readStorageText,
|
|
12
|
-
resolveFileUrl
|
|
13
|
-
});
|
|
14
|
-
return {
|
|
15
|
-
api: {
|
|
16
|
-
async getBundleById(id) {
|
|
17
|
-
await beforeOperation?.();
|
|
18
|
-
return client.getBundleById(id);
|
|
19
|
-
},
|
|
20
|
-
async getReleaseCatalog(input) {
|
|
21
|
-
await beforeOperation?.();
|
|
22
|
-
return getReleaseCatalog(input);
|
|
23
|
-
},
|
|
24
|
-
async getArtifactInfo(targetBundleId, currentBundleId) {
|
|
25
|
-
await beforeOperation?.();
|
|
26
|
-
return getArtifact(targetBundleId, currentBundleId);
|
|
27
|
-
},
|
|
28
|
-
async getReleaseById(id) {
|
|
29
|
-
await beforeOperation?.();
|
|
30
|
-
return database.models.releases.findById(id);
|
|
31
|
-
},
|
|
32
|
-
async getReleasesByScope(input) {
|
|
33
|
-
await beforeOperation?.();
|
|
34
|
-
return database.models.releases.findManyByScope({
|
|
35
|
-
...input,
|
|
36
|
-
consistency: "strong"
|
|
37
|
-
});
|
|
38
|
-
},
|
|
39
|
-
async getReleases(input) {
|
|
40
|
-
await beforeOperation?.();
|
|
41
|
-
return database.models.releases.findMany(input);
|
|
42
|
-
},
|
|
43
|
-
async getReleaseCatalogByScopeKey(scopeKey) {
|
|
44
|
-
await beforeOperation?.();
|
|
45
|
-
return database.models.releaseCatalogs.findByScopeKey(scopeKey);
|
|
46
|
-
},
|
|
47
|
-
async getReleaseCatalogs(input) {
|
|
48
|
-
await beforeOperation?.();
|
|
49
|
-
return database.models.releaseCatalogs.findMany(input);
|
|
50
|
-
},
|
|
51
|
-
async updateReleasePolicy(input) {
|
|
52
|
-
await beforeOperation?.();
|
|
53
|
-
return (0, _hot_updater_plugin_core.updateReleasePolicy)({
|
|
54
|
-
database,
|
|
55
|
-
...input
|
|
56
|
-
});
|
|
57
|
-
},
|
|
58
|
-
async preflightReleasePolicy(input) {
|
|
59
|
-
await beforeOperation?.();
|
|
60
|
-
return (0, _hot_updater_plugin_core.preflightReleasePolicy)({
|
|
61
|
-
database,
|
|
62
|
-
...input
|
|
63
|
-
});
|
|
64
|
-
},
|
|
65
|
-
async deleteRelease(input) {
|
|
66
|
-
await beforeOperation?.();
|
|
67
|
-
return (0, _hot_updater_plugin_core.deleteRelease)({
|
|
68
|
-
database,
|
|
69
|
-
...input
|
|
70
|
-
});
|
|
71
|
-
},
|
|
72
|
-
async rebuildReleaseCatalog(scopeKey) {
|
|
73
|
-
await beforeOperation?.();
|
|
74
|
-
const catalog = await database.models.releaseCatalogs.findByScopeKey(scopeKey);
|
|
75
|
-
if (catalog === null) throw new Error(`Release catalog "${scopeKey}" was not found.`);
|
|
76
|
-
return (0, _hot_updater_plugin_core.rebuildReleaseCatalog)({
|
|
77
|
-
database,
|
|
78
|
-
scope: {
|
|
79
|
-
channelId: catalog.channel_id,
|
|
80
|
-
channelName: (0, _hot_updater_core.decodeChannelKey)(catalog.channel_key),
|
|
81
|
-
fingerprintHash: catalog.fingerprint_hash,
|
|
82
|
-
platform: catalog.platform,
|
|
83
|
-
scopeKey: catalog.scope_key,
|
|
84
|
-
strategy: catalog.strategy
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
},
|
|
88
|
-
async commitDatabase(input) {
|
|
89
|
-
await beforeOperation?.();
|
|
90
|
-
return database.commit(input);
|
|
91
|
-
},
|
|
92
|
-
async getChannels() {
|
|
93
|
-
await beforeOperation?.();
|
|
94
|
-
return client.getChannels();
|
|
95
|
-
},
|
|
96
|
-
async insertChannel(input) {
|
|
97
|
-
await beforeOperation?.();
|
|
98
|
-
return database.models.channels.insert(input);
|
|
99
|
-
},
|
|
100
|
-
async deleteChannel(input) {
|
|
101
|
-
await beforeOperation?.();
|
|
102
|
-
return database.models.channels.delete(input);
|
|
103
|
-
},
|
|
104
|
-
async getBundles(options) {
|
|
105
|
-
await beforeOperation?.();
|
|
106
|
-
return client.getBundles(options);
|
|
107
|
-
},
|
|
108
|
-
async insertBundle(bundle) {
|
|
109
|
-
await beforeOperation?.();
|
|
110
|
-
await client.insertBundle(bundle);
|
|
111
|
-
},
|
|
112
|
-
async insertBundles(bundles) {
|
|
113
|
-
await beforeOperation?.();
|
|
114
|
-
await client.mutate(async (transaction) => {
|
|
115
|
-
for (const bundle of bundles) await transaction.insertBundle(bundle);
|
|
116
|
-
});
|
|
117
|
-
},
|
|
118
|
-
async updateBundleById(bundleId, update) {
|
|
119
|
-
await beforeOperation?.();
|
|
120
|
-
await client.updateBundleById(bundleId, update);
|
|
121
|
-
},
|
|
122
|
-
async deleteBundleById(bundleId) {
|
|
123
|
-
await beforeOperation?.();
|
|
124
|
-
await client.deleteBundleById(bundleId);
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
adapterName: database.name,
|
|
128
|
-
createMigrator: () => {
|
|
129
|
-
throw new Error("createMigrator is only available for Kysely/MongoDB database plugins.");
|
|
130
|
-
},
|
|
131
|
-
generateSchema: () => {
|
|
132
|
-
throw new Error("generateSchema is only available for Drizzle/Prisma database plugins.");
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
//#endregion
|
|
137
|
-
exports.createDatabasePluginCore = createDatabasePluginCore;
|