@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
|
@@ -1,364 +0,0 @@
|
|
|
1
|
-
import crypto from "node:crypto";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { promisify } from "node:util";
|
|
4
|
-
import { brotliDecompress } from "node:zlib";
|
|
5
|
-
|
|
6
|
-
import { hdiff } from "@hot-updater/bsdiff";
|
|
7
|
-
import {
|
|
8
|
-
getAssetBaseStorageUri,
|
|
9
|
-
getBundlePatch,
|
|
10
|
-
getBundlePatches,
|
|
11
|
-
getManifestStorageUri,
|
|
12
|
-
} from "@hot-updater/core";
|
|
13
|
-
import type {
|
|
14
|
-
Bundle,
|
|
15
|
-
BundleRepository,
|
|
16
|
-
StoragePluginWith,
|
|
17
|
-
} from "@hot-updater/plugin-core";
|
|
18
|
-
import {
|
|
19
|
-
createBundleStorageKey,
|
|
20
|
-
createDatabaseClient,
|
|
21
|
-
getManifestAssetDownloadPath,
|
|
22
|
-
resolveManifestAssetStorageUri,
|
|
23
|
-
} from "@hot-updater/plugin-core";
|
|
24
|
-
|
|
25
|
-
type BundleManifest = {
|
|
26
|
-
bundleId: string;
|
|
27
|
-
assets: Record<
|
|
28
|
-
string,
|
|
29
|
-
{
|
|
30
|
-
downloadByteSize?: unknown;
|
|
31
|
-
downloadFileHash?: unknown;
|
|
32
|
-
fileHash: string;
|
|
33
|
-
signature?: string;
|
|
34
|
-
}
|
|
35
|
-
>;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export interface CreateBundleDiffInput {
|
|
39
|
-
baseBundleId: string;
|
|
40
|
-
bundleId: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface CreateBundleDiffDependencies {
|
|
44
|
-
databasePlugin: BundleRepository;
|
|
45
|
-
storagePlugin: StoragePluginWith<"get" | "put" | "delete"> | null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface CreateBundleDiffOptions {
|
|
49
|
-
makePrimary?: boolean;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const HBC_ASSET_PATH_RE = /\.bundle$/;
|
|
53
|
-
const decompressBrotli = promisify(brotliDecompress);
|
|
54
|
-
|
|
55
|
-
const isBundleManifest = (value: unknown): value is BundleManifest => {
|
|
56
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const manifest = value as {
|
|
61
|
-
bundleId?: unknown;
|
|
62
|
-
assets?: unknown;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
if (typeof manifest.bundleId !== "string") {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (!manifest.assets || typeof manifest.assets !== "object") {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return Object.values(manifest.assets as Record<string, unknown>).every(
|
|
74
|
-
(asset) => {
|
|
75
|
-
if (!asset || typeof asset !== "object" || Array.isArray(asset)) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const manifestAsset = asset as {
|
|
80
|
-
fileHash?: unknown;
|
|
81
|
-
signature?: unknown;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
return (
|
|
85
|
-
typeof manifestAsset.fileHash === "string" &&
|
|
86
|
-
(manifestAsset.signature === undefined ||
|
|
87
|
-
typeof manifestAsset.signature === "string")
|
|
88
|
-
);
|
|
89
|
-
},
|
|
90
|
-
);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const getRelativeStorageDir = (relativePath: string) => {
|
|
94
|
-
const normalized = relativePath.replace(/\\/g, "/");
|
|
95
|
-
const dirname = path.posix.dirname(normalized);
|
|
96
|
-
return dirname === "." ? "" : dirname;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
async function downloadFromUrl(url: string) {
|
|
100
|
-
const response = await fetch(url);
|
|
101
|
-
if (!response.ok) {
|
|
102
|
-
throw new Error(`Failed to download storage object: ${response.status}`);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return new Uint8Array(await response.arrayBuffer());
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
async function downloadStorageBytes(
|
|
109
|
-
storageUri: string,
|
|
110
|
-
storagePlugin: StoragePluginWith<"get" | "put" | "delete"> | null,
|
|
111
|
-
) {
|
|
112
|
-
const protocol = new URL(storageUri).protocol.replace(":", "");
|
|
113
|
-
|
|
114
|
-
if (!storagePlugin || storagePlugin.protocol !== protocol) {
|
|
115
|
-
if (protocol === "http" || protocol === "https") {
|
|
116
|
-
return downloadFromUrl(storageUri);
|
|
117
|
-
}
|
|
118
|
-
if (!storagePlugin) {
|
|
119
|
-
throw new Error("Storage plugin is not configured");
|
|
120
|
-
}
|
|
121
|
-
throw new Error(`No storage plugin for protocol: ${protocol}`);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const { response } = await storagePlugin.get({ storageUri });
|
|
125
|
-
if (response === null) {
|
|
126
|
-
throw new Error(`Storage object not found: ${storageUri}`);
|
|
127
|
-
}
|
|
128
|
-
return new Uint8Array(await response.arrayBuffer());
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
async function fetchManifest(
|
|
132
|
-
bundle: Bundle,
|
|
133
|
-
storagePlugin: StoragePluginWith<"get" | "put" | "delete"> | null,
|
|
134
|
-
): Promise<BundleManifest> {
|
|
135
|
-
const manifestStorageUri = getManifestStorageUri(bundle);
|
|
136
|
-
if (!manifestStorageUri) {
|
|
137
|
-
throw new Error(`Bundle ${bundle.id} does not have manifest metadata`);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const manifestBytes = await downloadStorageBytes(
|
|
141
|
-
manifestStorageUri,
|
|
142
|
-
storagePlugin,
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
const payload: unknown = JSON.parse(new TextDecoder().decode(manifestBytes));
|
|
146
|
-
if (!isBundleManifest(payload)) {
|
|
147
|
-
throw new Error(`Invalid manifest payload for bundle ${bundle.id}`);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return payload;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function resolveHbcAssetPath(manifest: BundleManifest) {
|
|
154
|
-
const candidates = Object.keys(manifest.assets)
|
|
155
|
-
.sort((left, right) => left.localeCompare(right))
|
|
156
|
-
.filter((candidate) => HBC_ASSET_PATH_RE.test(candidate));
|
|
157
|
-
|
|
158
|
-
if (candidates.length === 0) {
|
|
159
|
-
throw new Error("No Hermes bundle asset found in manifest");
|
|
160
|
-
}
|
|
161
|
-
if (candidates.length > 1) {
|
|
162
|
-
throw new Error(
|
|
163
|
-
`Expected exactly one Hermes bundle asset in manifest, found ${candidates.length}: ${candidates.join(", ")}`,
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return candidates[0];
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
async function fetchAssetBytes(
|
|
171
|
-
bundle: Bundle,
|
|
172
|
-
assetPath: string,
|
|
173
|
-
manifest: BundleManifest,
|
|
174
|
-
storagePlugin: StoragePluginWith<"get" | "put" | "delete"> | null,
|
|
175
|
-
) {
|
|
176
|
-
const assetBaseStorageUri = getAssetBaseStorageUri(bundle);
|
|
177
|
-
if (!assetBaseStorageUri) {
|
|
178
|
-
throw new Error(`Bundle ${bundle.id} does not have asset storage metadata`);
|
|
179
|
-
}
|
|
180
|
-
const asset = manifest.assets[assetPath];
|
|
181
|
-
if (!asset) {
|
|
182
|
-
throw new Error(`Asset ${assetPath} is missing from manifest`);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const downloadPath = getManifestAssetDownloadPath(assetPath);
|
|
186
|
-
if (downloadPath !== assetPath) {
|
|
187
|
-
const compressedAssetStorageUri = resolveManifestAssetStorageUri({
|
|
188
|
-
assetBaseStorageUri,
|
|
189
|
-
assetPath: downloadPath,
|
|
190
|
-
downloadFileHash: asset.downloadFileHash,
|
|
191
|
-
fileHash: asset.fileHash,
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
let compressedBytes: Uint8Array | null = null;
|
|
195
|
-
try {
|
|
196
|
-
compressedBytes = await downloadStorageBytes(
|
|
197
|
-
compressedAssetStorageUri,
|
|
198
|
-
storagePlugin,
|
|
199
|
-
);
|
|
200
|
-
} catch (error) {
|
|
201
|
-
if (!(error instanceof Error)) throw error;
|
|
202
|
-
compressedBytes = null;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (compressedBytes) {
|
|
206
|
-
return new Uint8Array(await decompressBrotli(compressedBytes));
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const assetStorageUri = resolveManifestAssetStorageUri({
|
|
211
|
-
assetBaseStorageUri,
|
|
212
|
-
assetPath,
|
|
213
|
-
fileHash: asset.fileHash,
|
|
214
|
-
});
|
|
215
|
-
return downloadStorageBytes(assetStorageUri, storagePlugin);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
function buildNextPatchState({
|
|
219
|
-
currentBundle,
|
|
220
|
-
nextPatch,
|
|
221
|
-
makePrimary,
|
|
222
|
-
}: {
|
|
223
|
-
currentBundle: Bundle;
|
|
224
|
-
nextPatch: NonNullable<ReturnType<typeof getBundlePatch>>;
|
|
225
|
-
makePrimary: boolean;
|
|
226
|
-
}) {
|
|
227
|
-
const existingPatches = getBundlePatches(currentBundle).filter(
|
|
228
|
-
(patch) => patch.baseBundleId !== nextPatch.baseBundleId,
|
|
229
|
-
);
|
|
230
|
-
const orderedPatches = makePrimary
|
|
231
|
-
? [nextPatch, ...existingPatches]
|
|
232
|
-
: [...existingPatches, nextPatch];
|
|
233
|
-
|
|
234
|
-
return orderedPatches;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
export async function createBundleDiff(
|
|
238
|
-
{ baseBundleId, bundleId }: CreateBundleDiffInput,
|
|
239
|
-
deps: CreateBundleDiffDependencies,
|
|
240
|
-
options: CreateBundleDiffOptions = {},
|
|
241
|
-
) {
|
|
242
|
-
const database = createDatabaseClient(deps.databasePlugin);
|
|
243
|
-
|
|
244
|
-
if (!deps.storagePlugin) {
|
|
245
|
-
throw new Error("Storage plugin is not configured");
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if (baseBundleId === bundleId) {
|
|
249
|
-
throw new Error("Base bundle must be different from the target bundle");
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const baseBundle = await database.getBundleById(baseBundleId);
|
|
253
|
-
const targetBundle = await database.getBundleById(bundleId);
|
|
254
|
-
|
|
255
|
-
if (!baseBundle || !targetBundle) {
|
|
256
|
-
throw new Error("Bundle not found");
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
if (baseBundle.platform !== targetBundle.platform) {
|
|
260
|
-
throw new Error("Base bundle platform must match the target bundle");
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (baseBundle.id.localeCompare(targetBundle.id) >= 0) {
|
|
264
|
-
throw new Error("Base bundle must be older than the target bundle");
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
const [baseManifest, targetManifest] = await Promise.all([
|
|
268
|
-
fetchManifest(baseBundle, deps.storagePlugin),
|
|
269
|
-
fetchManifest(targetBundle, deps.storagePlugin),
|
|
270
|
-
]);
|
|
271
|
-
|
|
272
|
-
const baseAssetPath = resolveHbcAssetPath(baseManifest);
|
|
273
|
-
const targetAssetPath = resolveHbcAssetPath(targetManifest);
|
|
274
|
-
|
|
275
|
-
if (baseAssetPath !== targetAssetPath) {
|
|
276
|
-
throw new Error("Base and target Hermes asset paths do not match");
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
const baseAssetHash = baseManifest.assets[baseAssetPath]?.fileHash;
|
|
280
|
-
const targetAssetHash = targetManifest.assets[targetAssetPath]?.fileHash;
|
|
281
|
-
|
|
282
|
-
if (!baseAssetHash || !targetAssetHash) {
|
|
283
|
-
throw new Error("Hermes asset hash is missing from manifest");
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
if (baseAssetHash === targetAssetHash) {
|
|
287
|
-
throw new Error("Hermes bundle is unchanged; no diff patch is required");
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
const [baseBytes, targetBytes] = await Promise.all([
|
|
291
|
-
fetchAssetBytes(
|
|
292
|
-
baseBundle,
|
|
293
|
-
baseAssetPath,
|
|
294
|
-
baseManifest,
|
|
295
|
-
deps.storagePlugin,
|
|
296
|
-
),
|
|
297
|
-
fetchAssetBytes(
|
|
298
|
-
targetBundle,
|
|
299
|
-
targetAssetPath,
|
|
300
|
-
targetManifest,
|
|
301
|
-
deps.storagePlugin,
|
|
302
|
-
),
|
|
303
|
-
]);
|
|
304
|
-
|
|
305
|
-
const patchBytes = await hdiff(baseBytes, targetBytes);
|
|
306
|
-
const patchFileHash = crypto
|
|
307
|
-
.createHash("sha256")
|
|
308
|
-
.update(patchBytes)
|
|
309
|
-
.digest("hex");
|
|
310
|
-
const patchFilename = `${path.posix.basename(targetAssetPath)}.bsdiff`;
|
|
311
|
-
const previousPatch = getBundlePatch(targetBundle, baseBundle.id);
|
|
312
|
-
|
|
313
|
-
const uploadKey = createBundleStorageKey(
|
|
314
|
-
targetBundle.id,
|
|
315
|
-
"patches",
|
|
316
|
-
baseBundle.id,
|
|
317
|
-
patchFileHash,
|
|
318
|
-
getRelativeStorageDir(targetAssetPath),
|
|
319
|
-
patchFilename,
|
|
320
|
-
);
|
|
321
|
-
const patchUpload = await deps.storagePlugin.put({
|
|
322
|
-
key: uploadKey,
|
|
323
|
-
body: new ReadableStream<Uint8Array>({
|
|
324
|
-
start(controller) {
|
|
325
|
-
controller.enqueue(patchBytes);
|
|
326
|
-
controller.close();
|
|
327
|
-
},
|
|
328
|
-
}),
|
|
329
|
-
contentLength: patchBytes.byteLength,
|
|
330
|
-
contentType: "application/octet-stream",
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
const nextPatch = {
|
|
334
|
-
baseBundleId: baseBundle.id,
|
|
335
|
-
baseFileHash: baseAssetHash,
|
|
336
|
-
byteSize: patchBytes.byteLength,
|
|
337
|
-
patchFileHash,
|
|
338
|
-
patchStorageUri: patchUpload.storageUri,
|
|
339
|
-
};
|
|
340
|
-
const patches = buildNextPatchState({
|
|
341
|
-
currentBundle: targetBundle,
|
|
342
|
-
nextPatch,
|
|
343
|
-
makePrimary: options.makePrimary ?? true,
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
const updatedBundle: Bundle = {
|
|
347
|
-
...targetBundle,
|
|
348
|
-
patches,
|
|
349
|
-
};
|
|
350
|
-
await database.updateBundleById(targetBundle.id, updatedBundle);
|
|
351
|
-
|
|
352
|
-
if (
|
|
353
|
-
previousPatch?.patchStorageUri &&
|
|
354
|
-
previousPatch.patchStorageUri !== patchUpload.storageUri
|
|
355
|
-
) {
|
|
356
|
-
await deps.storagePlugin
|
|
357
|
-
.delete({ storageUri: previousPatch.patchStorageUri })
|
|
358
|
-
.catch(() => {
|
|
359
|
-
return;
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
return updatedBundle;
|
|
364
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { type DatabasePlugin } from "@hot-updater/plugin-core";
|
|
2
|
-
import { describe, expect, it, vi } from "vitest";
|
|
3
|
-
|
|
4
|
-
import { createInMemoryDatabasePlugin } from "../../../test-utils/test/inMemoryDatabasePlugin";
|
|
5
|
-
import { createDatabasePluginCore } from "./databasePluginCore";
|
|
6
|
-
import {
|
|
7
|
-
currentBundle,
|
|
8
|
-
resolveFileUrl,
|
|
9
|
-
} from "./databasePluginCore.testFixtures";
|
|
10
|
-
|
|
11
|
-
describe("createDatabasePluginCore", () => {
|
|
12
|
-
it("runs the schema readiness guard before a low plugin operation", async () => {
|
|
13
|
-
const plugin: DatabasePlugin = createInMemoryDatabasePlugin();
|
|
14
|
-
const beforeOperation = vi.fn(async () => {});
|
|
15
|
-
const core = createDatabasePluginCore(plugin, resolveFileUrl, {
|
|
16
|
-
beforeOperation,
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
await core.api.getChannels();
|
|
20
|
-
|
|
21
|
-
expect(beforeOperation).toHaveBeenCalledOnce();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("inserts an artifact without synthesizing a Release", async () => {
|
|
25
|
-
const plugin: DatabasePlugin = createInMemoryDatabasePlugin();
|
|
26
|
-
const core = createDatabasePluginCore(plugin, resolveFileUrl);
|
|
27
|
-
|
|
28
|
-
await core.api.insertBundle(currentBundle);
|
|
29
|
-
|
|
30
|
-
await expect(
|
|
31
|
-
core.api.getBundleById(currentBundle.id),
|
|
32
|
-
).resolves.toMatchObject(currentBundle);
|
|
33
|
-
await expect(
|
|
34
|
-
plugin.models.releases.findMany({
|
|
35
|
-
bundleId: currentBundle.id,
|
|
36
|
-
limit: 10,
|
|
37
|
-
}),
|
|
38
|
-
).resolves.toEqual([]);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("updates an artifact without requiring or mutating a Release", async () => {
|
|
42
|
-
const plugin: DatabasePlugin = createInMemoryDatabasePlugin();
|
|
43
|
-
const core = createDatabasePluginCore(plugin, resolveFileUrl);
|
|
44
|
-
await core.api.insertBundle(currentBundle);
|
|
45
|
-
await core.api.updateBundleById(currentBundle.id, {
|
|
46
|
-
storageUri: `r2://bucket/bundles/${currentBundle.id}/updated.zip`,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
await expect(
|
|
50
|
-
core.api.getBundleById(currentBundle.id),
|
|
51
|
-
).resolves.toMatchObject({
|
|
52
|
-
id: currentBundle.id,
|
|
53
|
-
storageUri: `r2://bucket/bundles/${currentBundle.id}/updated.zip`,
|
|
54
|
-
});
|
|
55
|
-
await expect(
|
|
56
|
-
plugin.models.releases.findMany({
|
|
57
|
-
bundleId: currentBundle.id,
|
|
58
|
-
limit: 10,
|
|
59
|
-
}),
|
|
60
|
-
).resolves.toEqual([]);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { Bundle } from "@hot-updater/core";
|
|
2
|
-
import {
|
|
3
|
-
createDatabaseClient,
|
|
4
|
-
type DatabasePlugin,
|
|
5
|
-
} from "@hot-updater/plugin-core";
|
|
6
|
-
|
|
7
|
-
export const currentBundle: Bundle = {
|
|
8
|
-
id: "00000000-0000-0000-0000-000000000001",
|
|
9
|
-
fileHash: "current-archive-hash",
|
|
10
|
-
gitCommitHash: null,
|
|
11
|
-
platform: "ios",
|
|
12
|
-
storageUri:
|
|
13
|
-
"r2://bucket/bundles/00000000-0000-0000-0000-000000000001/archive.zip",
|
|
14
|
-
archiveByteSize: 3_000_000_001,
|
|
15
|
-
manifestStorageUri:
|
|
16
|
-
"r2://bucket/bundles/00000000-0000-0000-0000-000000000001/manifest.json",
|
|
17
|
-
manifestFileHash: "sig:current-manifest",
|
|
18
|
-
assetBaseStorageUri: "r2://bucket/assets",
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const targetBundle: Bundle = {
|
|
22
|
-
...currentBundle,
|
|
23
|
-
id: "00000000-0000-0000-0000-000000000002",
|
|
24
|
-
fileHash: "target-archive-hash",
|
|
25
|
-
storageUri:
|
|
26
|
-
"r2://bucket/bundles/00000000-0000-0000-0000-000000000002/archive.zip",
|
|
27
|
-
manifestStorageUri:
|
|
28
|
-
"r2://bucket/bundles/00000000-0000-0000-0000-000000000002/manifest.json",
|
|
29
|
-
manifestFileHash: "sig:target-manifest",
|
|
30
|
-
assetBaseStorageUri: "r2://bucket/assets",
|
|
31
|
-
patches: [
|
|
32
|
-
{
|
|
33
|
-
baseBundleId: currentBundle.id,
|
|
34
|
-
baseFileHash: "current-bundle-hash",
|
|
35
|
-
patchFileHash: "patch-hash",
|
|
36
|
-
patchStorageUri:
|
|
37
|
-
"r2://bucket/bundles/00000000-0000-0000-0000-000000000002/patches/00000000-0000-0000-0000-000000000001/index.ios.bundle.bsdiff",
|
|
38
|
-
byteSize: 3_000_000_002,
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export const resolveFileUrl = async (storageUri: string | null) => {
|
|
44
|
-
if (!storageUri) return null;
|
|
45
|
-
const url = new URL(storageUri);
|
|
46
|
-
return `https://assets.example.com/${url.host}${url.pathname}`;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const seedBundles = async (plugin: DatabasePlugin): Promise<void> => {
|
|
50
|
-
const client = createDatabaseClient(plugin);
|
|
51
|
-
await client.insertBundle(currentBundle);
|
|
52
|
-
await client.insertBundle(targetBundle);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const manifests = new Map<string, string>([
|
|
56
|
-
[
|
|
57
|
-
currentBundle.manifestStorageUri ?? "",
|
|
58
|
-
JSON.stringify({
|
|
59
|
-
bundleId: currentBundle.id,
|
|
60
|
-
assets: {
|
|
61
|
-
"index.ios.bundle": { fileHash: "current-bundle-hash" },
|
|
62
|
-
"shared.png": { fileHash: "shared-hash" },
|
|
63
|
-
},
|
|
64
|
-
}),
|
|
65
|
-
],
|
|
66
|
-
[
|
|
67
|
-
targetBundle.manifestStorageUri ?? "",
|
|
68
|
-
JSON.stringify({
|
|
69
|
-
bundleId: targetBundle.id,
|
|
70
|
-
assets: {
|
|
71
|
-
"index.ios.bundle": { fileHash: "target-bundle-hash" },
|
|
72
|
-
"shared.png": { fileHash: "shared-hash" },
|
|
73
|
-
},
|
|
74
|
-
}),
|
|
75
|
-
],
|
|
76
|
-
]);
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import type { Bundle } from "@hot-updater/core";
|
|
2
|
-
import { decodeChannelKey } from "@hot-updater/core";
|
|
3
|
-
import {
|
|
4
|
-
type ChannelRow,
|
|
5
|
-
createDatabaseClient,
|
|
6
|
-
deleteRelease as deleteReleasePolicy,
|
|
7
|
-
preflightReleasePolicy as preflightReleasePolicyMutation,
|
|
8
|
-
rebuildReleaseCatalog as rebuildReleaseCatalogProjection,
|
|
9
|
-
updateReleasePolicy as updateReleasePolicyMutation,
|
|
10
|
-
} from "@hot-updater/plugin-core";
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
createArtifactResolver,
|
|
14
|
-
createReleaseCatalogReader,
|
|
15
|
-
} from "./releaseCatalog";
|
|
16
|
-
import type { DatabaseAPI, DatabasePlugin } from "./types";
|
|
17
|
-
|
|
18
|
-
export function createDatabasePluginCore(
|
|
19
|
-
database: DatabasePlugin,
|
|
20
|
-
resolveFileUrl: (storageUri: string | null) => Promise<string | null>,
|
|
21
|
-
options?: {
|
|
22
|
-
beforeOperation?: () => Promise<void>;
|
|
23
|
-
readStorageText?: (storageUri: string) => Promise<string | null>;
|
|
24
|
-
},
|
|
25
|
-
): {
|
|
26
|
-
api: DatabaseAPI;
|
|
27
|
-
adapterName: string;
|
|
28
|
-
createMigrator: () => never;
|
|
29
|
-
generateSchema: () => never;
|
|
30
|
-
} {
|
|
31
|
-
const client = createDatabaseClient(database);
|
|
32
|
-
const beforeOperation = options?.beforeOperation;
|
|
33
|
-
const getReleaseCatalog = createReleaseCatalogReader(database);
|
|
34
|
-
const getArtifact = createArtifactResolver({
|
|
35
|
-
database,
|
|
36
|
-
readStorageText: options?.readStorageText,
|
|
37
|
-
resolveFileUrl,
|
|
38
|
-
});
|
|
39
|
-
const api: DatabaseAPI = {
|
|
40
|
-
async getBundleById(id: string): Promise<Bundle | null> {
|
|
41
|
-
await beforeOperation?.();
|
|
42
|
-
return client.getBundleById(id);
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
async getReleaseCatalog(input) {
|
|
46
|
-
await beforeOperation?.();
|
|
47
|
-
return getReleaseCatalog(input);
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
async getArtifactInfo(targetBundleId, currentBundleId) {
|
|
51
|
-
await beforeOperation?.();
|
|
52
|
-
return getArtifact(targetBundleId, currentBundleId);
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
async getReleaseById(id) {
|
|
56
|
-
await beforeOperation?.();
|
|
57
|
-
return database.models.releases.findById(id);
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
async getReleasesByScope(input) {
|
|
61
|
-
await beforeOperation?.();
|
|
62
|
-
return database.models.releases.findManyByScope({
|
|
63
|
-
...input,
|
|
64
|
-
consistency: "strong",
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
async getReleases(input) {
|
|
69
|
-
await beforeOperation?.();
|
|
70
|
-
return database.models.releases.findMany(input);
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
async getReleaseCatalogByScopeKey(scopeKey) {
|
|
74
|
-
await beforeOperation?.();
|
|
75
|
-
return database.models.releaseCatalogs.findByScopeKey(scopeKey);
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
async getReleaseCatalogs(input) {
|
|
79
|
-
await beforeOperation?.();
|
|
80
|
-
return database.models.releaseCatalogs.findMany(input);
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
async updateReleasePolicy(input) {
|
|
84
|
-
await beforeOperation?.();
|
|
85
|
-
return updateReleasePolicyMutation({ database, ...input });
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
async preflightReleasePolicy(input) {
|
|
89
|
-
await beforeOperation?.();
|
|
90
|
-
return preflightReleasePolicyMutation({ database, ...input });
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
async deleteRelease(input) {
|
|
94
|
-
await beforeOperation?.();
|
|
95
|
-
return deleteReleasePolicy({ database, ...input });
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
async rebuildReleaseCatalog(scopeKey) {
|
|
99
|
-
await beforeOperation?.();
|
|
100
|
-
const catalog =
|
|
101
|
-
await database.models.releaseCatalogs.findByScopeKey(scopeKey);
|
|
102
|
-
if (catalog === null) {
|
|
103
|
-
throw new Error(`Release catalog "${scopeKey}" was not found.`);
|
|
104
|
-
}
|
|
105
|
-
return rebuildReleaseCatalogProjection({
|
|
106
|
-
database,
|
|
107
|
-
scope: {
|
|
108
|
-
channelId: catalog.channel_id,
|
|
109
|
-
channelName: decodeChannelKey(catalog.channel_key),
|
|
110
|
-
fingerprintHash: catalog.fingerprint_hash,
|
|
111
|
-
platform: catalog.platform,
|
|
112
|
-
scopeKey: catalog.scope_key,
|
|
113
|
-
strategy: catalog.strategy,
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
},
|
|
117
|
-
|
|
118
|
-
async commitDatabase(input) {
|
|
119
|
-
await beforeOperation?.();
|
|
120
|
-
return database.commit(input);
|
|
121
|
-
},
|
|
122
|
-
|
|
123
|
-
async getChannels(): Promise<readonly ChannelRow[]> {
|
|
124
|
-
await beforeOperation?.();
|
|
125
|
-
return client.getChannels();
|
|
126
|
-
},
|
|
127
|
-
|
|
128
|
-
async insertChannel(input) {
|
|
129
|
-
await beforeOperation?.();
|
|
130
|
-
return database.models.channels.insert(input);
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
async deleteChannel(input) {
|
|
134
|
-
await beforeOperation?.();
|
|
135
|
-
return database.models.channels.delete(input);
|
|
136
|
-
},
|
|
137
|
-
|
|
138
|
-
async getBundles(options) {
|
|
139
|
-
await beforeOperation?.();
|
|
140
|
-
return client.getBundles(options);
|
|
141
|
-
},
|
|
142
|
-
|
|
143
|
-
async insertBundle(bundle: Bundle): Promise<void> {
|
|
144
|
-
await beforeOperation?.();
|
|
145
|
-
await client.insertBundle(bundle);
|
|
146
|
-
},
|
|
147
|
-
|
|
148
|
-
async insertBundles(bundles: readonly Bundle[]): Promise<void> {
|
|
149
|
-
await beforeOperation?.();
|
|
150
|
-
await client.mutate(async (transaction) => {
|
|
151
|
-
for (const bundle of bundles) {
|
|
152
|
-
await transaction.insertBundle(bundle);
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
},
|
|
156
|
-
|
|
157
|
-
async updateBundleById(
|
|
158
|
-
bundleId: string,
|
|
159
|
-
update: Partial<Bundle>,
|
|
160
|
-
): Promise<void> {
|
|
161
|
-
await beforeOperation?.();
|
|
162
|
-
await client.updateBundleById(bundleId, update);
|
|
163
|
-
},
|
|
164
|
-
|
|
165
|
-
async deleteBundleById(bundleId: string): Promise<void> {
|
|
166
|
-
await beforeOperation?.();
|
|
167
|
-
await client.deleteBundleById(bundleId);
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
return {
|
|
172
|
-
api,
|
|
173
|
-
adapterName: database.name,
|
|
174
|
-
createMigrator: () => {
|
|
175
|
-
throw new Error(
|
|
176
|
-
"createMigrator is only available for Kysely/MongoDB database plugins.",
|
|
177
|
-
);
|
|
178
|
-
},
|
|
179
|
-
generateSchema: () => {
|
|
180
|
-
throw new Error(
|
|
181
|
-
"generateSchema is only available for Drizzle/Prisma database plugins.",
|
|
182
|
-
);
|
|
183
|
-
},
|
|
184
|
-
};
|
|
185
|
-
}
|