@hot-updater/server 0.36.7 → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/databaseConstraintErrors.cjs +23 -0
- package/dist/adapters/databaseConstraintErrors.mjs +21 -0
- package/dist/adapters/databasePluginUtils.cjs +117 -0
- package/dist/adapters/databasePluginUtils.mjs +106 -0
- package/dist/adapters/drizzle.cjs +53 -176
- package/dist/adapters/drizzle.d.cts +6 -4
- package/dist/adapters/drizzle.d.mts +6 -4
- package/dist/adapters/drizzle.mjs +54 -177
- package/dist/adapters/drizzleCrud.cjs +250 -0
- package/dist/adapters/drizzleCrud.mjs +249 -0
- package/dist/adapters/drizzleLazyDB.cjs +84 -36
- package/dist/adapters/drizzleLazyDB.mjs +84 -36
- package/dist/adapters/drizzleQuery.cjs +68 -0
- package/dist/adapters/drizzleQuery.mjs +67 -0
- package/dist/adapters/kysely.cjs +18 -138
- package/dist/adapters/kysely.d.cts +3 -12
- package/dist/adapters/kysely.d.mts +3 -12
- package/dist/adapters/kysely.mjs +19 -139
- package/dist/adapters/kyselyCrud.cjs +254 -0
- package/dist/adapters/kyselyCrud.mjs +253 -0
- package/dist/adapters/kyselyQuery.cjs +56 -0
- package/dist/adapters/kyselyQuery.mjs +55 -0
- package/dist/adapters/mongodb.cjs +21 -174
- package/dist/adapters/mongodb.d.cts +3 -2
- package/dist/adapters/mongodb.d.mts +3 -2
- package/dist/adapters/mongodb.mjs +21 -174
- package/dist/adapters/mongodbCollections.cjs +36 -0
- package/dist/adapters/mongodbCollections.mjs +30 -0
- package/dist/adapters/mongodbQuery.cjs +77 -0
- package/dist/adapters/mongodbQuery.mjs +70 -0
- package/dist/adapters/mongodbReads.cjs +148 -0
- package/dist/adapters/mongodbReads.mjs +147 -0
- package/dist/adapters/mongodbWrites.cjs +134 -0
- package/dist/adapters/mongodbWrites.mjs +133 -0
- package/dist/adapters/prisma.cjs +205 -180
- package/dist/adapters/prisma.d.cts +3 -3
- package/dist/adapters/prisma.d.mts +3 -3
- package/dist/adapters/prisma.mjs +206 -181
- package/dist/adapters/prismaQuery.cjs +58 -0
- package/dist/adapters/prismaQuery.mjs +56 -0
- package/dist/adapters/prismaRows.cjs +198 -0
- package/dist/adapters/prismaRows.mjs +188 -0
- package/dist/apiKeys.cjs +139 -0
- package/dist/apiKeys.d.cts +50 -0
- package/dist/apiKeys.d.mts +50 -0
- package/dist/apiKeys.mjs +133 -0
- package/dist/createHotUpdaterCore.cjs +48 -26
- package/dist/createHotUpdaterCore.d.cts +49 -17
- package/dist/createHotUpdaterCore.d.mts +49 -17
- package/dist/createHotUpdaterCore.mjs +51 -29
- package/dist/db/createBundleDiff.cjs +45 -68
- package/dist/db/createBundleDiff.d.cts +3 -3
- package/dist/db/createBundleDiff.d.mts +3 -3
- package/dist/db/createBundleDiff.mjs +47 -68
- package/dist/db/databasePluginCore.cjs +138 -0
- package/dist/db/databasePluginCore.mjs +137 -0
- package/dist/db/fixedMigrator.cjs +36 -93
- package/dist/db/fixedMigrator.mjs +36 -93
- package/dist/db/fixedMigratorMongo.cjs +319 -0
- package/dist/db/fixedMigratorMongo.mjs +319 -0
- package/dist/db/fixedMigratorShared.cjs +23 -0
- package/dist/db/fixedMigratorShared.mjs +18 -0
- package/dist/db/mongoMigrationExecution.cjs +11 -0
- package/dist/db/mongoMigrationExecution.mjs +11 -0
- package/dist/db/releaseCatalog.cjs +66 -0
- package/dist/db/releaseCatalog.d.cts +17 -0
- package/dist/db/releaseCatalog.d.mts +17 -0
- package/dist/db/releaseCatalog.mjs +64 -0
- package/dist/db/schema/mongodb.cjs +14 -6
- package/dist/db/schema/mongodb.mjs +14 -6
- package/dist/db/schema/registry.cjs +0 -2
- package/dist/db/schema/registry.mjs +1 -2
- package/dist/db/schema/sql.cjs +31 -14
- package/dist/db/schema/sql.mjs +32 -13
- package/dist/db/schema/sqlOperations.cjs +4 -4
- package/dist/db/schema/sqlOperations.mjs +5 -5
- package/dist/db/schemaGenerators.cjs +52 -18
- package/dist/db/schemaGenerators.mjs +52 -18
- package/dist/db/schemaReadiness.cjs +4 -3
- package/dist/db/schemaReadiness.mjs +4 -3
- package/dist/db/sqlMigrationExecution.cjs +67 -0
- package/dist/db/sqlMigrationExecution.mjs +66 -0
- package/dist/db/types.cjs +2 -6
- package/dist/db/types.d.cts +60 -16
- package/dist/db/types.d.mts +60 -16
- package/dist/db/types.mjs +3 -6
- package/dist/db/updateArtifacts.cjs +114 -60
- package/dist/db/updateArtifacts.mjs +117 -62
- package/dist/handler.cjs +108 -282
- package/dist/handler.d.cts +3 -46
- package/dist/handler.d.mts +3 -46
- package/dist/handler.mjs +107 -281
- package/dist/handlerBundleRoutes.cjs +155 -0
- package/dist/handlerBundleRoutes.mjs +155 -0
- package/dist/handlerErrors.cjs +9 -0
- package/dist/handlerErrors.mjs +9 -0
- package/dist/handlerParameters.cjs +39 -0
- package/dist/handlerParameters.mjs +34 -0
- package/dist/handlerReleaseCatalogRoutes.cjs +111 -0
- package/dist/handlerReleaseCatalogRoutes.mjs +110 -0
- package/dist/handlerReleaseManagementRoutes.cjs +125 -0
- package/dist/handlerReleaseManagementRoutes.mjs +124 -0
- package/dist/handlerTypes.d.cts +63 -0
- package/dist/handlerTypes.d.mts +63 -0
- package/dist/handlerVersionRoutes.cjs +10 -0
- package/dist/handlerVersionRoutes.d.cts +4 -0
- package/dist/handlerVersionRoutes.d.mts +4 -0
- package/dist/handlerVersionRoutes.mjs +9 -0
- package/dist/index.cjs +10 -1
- package/dist/index.d.cts +9 -3
- package/dist/index.d.mts +9 -3
- package/dist/index.mjs +5 -2
- package/dist/insights/bounded/activeOverview.cjs +87 -0
- package/dist/insights/bounded/activeOverview.mjs +85 -0
- package/dist/insights/bounded/installationSearch.cjs +42 -0
- package/dist/insights/bounded/installationSearch.mjs +42 -0
- package/dist/insights/bounded/persistence.cjs +39 -0
- package/dist/insights/bounded/persistence.mjs +38 -0
- package/dist/insights/bounded/provider.cjs +170 -0
- package/dist/insights/bounded/provider.d.cts +7 -0
- package/dist/insights/bounded/provider.d.mts +7 -0
- package/dist/insights/bounded/provider.mjs +170 -0
- package/dist/insights/bounded/scan.cjs +144 -0
- package/dist/insights/bounded/scan.mjs +138 -0
- package/dist/insights/domain.d.cts +121 -0
- package/dist/insights/domain.d.mts +121 -0
- package/dist/insights/errors.cjs +22 -0
- package/dist/insights/errors.mjs +20 -0
- package/dist/insights/eventInput.cjs +111 -0
- package/dist/insights/eventInput.mjs +111 -0
- package/dist/insights/persistence.d.cts +6 -0
- package/dist/insights/persistence.d.mts +6 -0
- package/dist/insights/queryInput.cjs +58 -0
- package/dist/insights/queryInput.mjs +55 -0
- package/dist/insights/routes.cjs +63 -0
- package/dist/insights/routes.mjs +61 -0
- package/dist/insights/types.d.cts +17 -0
- package/dist/insights/types.d.mts +17 -0
- package/dist/node.cjs +19 -12
- package/dist/node.d.cts +15 -10
- package/dist/node.d.mts +15 -10
- package/dist/node.mjs +19 -13
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/schema/dsl.cjs +19 -2
- package/dist/schema/dsl.mjs +17 -3
- package/dist/schema/index.cjs +1 -8
- package/dist/schema/index.mjs +2 -8
- package/dist/schema/types.cjs +3 -1
- package/dist/schema/types.mjs +3 -2
- package/dist/schema/v1_0_0.cjs +364 -0
- package/dist/schema/v1_0_0.mjs +357 -0
- package/dist/storageAccess.cjs +69 -25
- package/dist/storageAccess.mjs +68 -25
- package/dist/types/index.d.cts +4 -3
- package/dist/types/index.d.mts +5 -4
- package/package.json +8 -7
- package/src/adapters/databaseConstraintErrors.ts +25 -0
- package/src/adapters/databasePluginTestDatabase.ts +106 -0
- package/src/adapters/databasePluginUtils.spec.ts +29 -0
- package/src/adapters/databasePluginUtils.ts +214 -0
- package/src/adapters/drizzle.spec.ts +208 -47
- package/src/adapters/drizzle.ts +106 -293
- package/src/adapters/drizzleCrud.ts +419 -0
- package/src/adapters/drizzleLazyDB.ts +206 -100
- package/src/adapters/drizzleQuery.ts +164 -0
- package/src/adapters/kysely.spec.ts +126 -88
- package/src/adapters/kysely.ts +76 -334
- package/src/adapters/kyselyCrud.ts +588 -0
- package/src/adapters/kyselyQuery.ts +128 -0
- package/src/adapters/mongodb.spec.ts +141 -0
- package/src/adapters/mongodb.ts +60 -288
- package/src/adapters/mongodbCollections.ts +62 -0
- package/src/adapters/mongodbQuery.ts +226 -0
- package/src/adapters/mongodbReads.ts +311 -0
- package/src/adapters/mongodbRows.spec.ts +64 -0
- package/src/adapters/mongodbRows.ts +118 -0
- package/src/adapters/mongodbTestClient.ts +342 -0
- package/src/adapters/mongodbTestFilter.ts +166 -0
- package/src/adapters/mongodbWrites.ts +260 -0
- package/src/adapters/prisma.spec.ts +196 -0
- package/src/adapters/prisma.ts +417 -292
- package/src/adapters/prismaQuery.ts +129 -0
- package/src/adapters/prismaRows.spec.ts +98 -0
- package/src/adapters/prismaRows.ts +301 -0
- package/src/adapters/prismaTestClient.ts +396 -0
- package/src/apiKeys.integration.spec.ts +192 -0
- package/src/apiKeys.spec.ts +162 -0
- package/src/apiKeys.ts +220 -0
- package/src/createHotUpdaterCore.ts +164 -100
- package/src/db/bundleRows.spec.ts +164 -0
- package/src/db/bundleRows.ts +10 -140
- package/src/db/createBundleDiff.spec.ts +172 -127
- package/src/db/createBundleDiff.ts +91 -110
- package/src/db/databasePluginCore.spec.ts +62 -0
- package/src/db/databasePluginCore.testFixtures.ts +76 -0
- package/src/db/databasePluginCore.ts +185 -0
- package/src/db/databasePluginUpdateCheck.bench.ts +107 -0
- package/src/db/fixedMigrator.spec.ts +184 -42
- package/src/db/fixedMigrator.ts +64 -205
- package/src/db/fixedMigratorMongo.spec.ts +192 -0
- package/src/db/fixedMigratorMongo.ts +425 -0
- package/src/db/fixedMigratorShared.ts +36 -0
- package/src/db/hotUpdaterSchema.ts +0 -1
- package/src/db/index.spec.ts +333 -1025
- package/src/db/mongoMigrationExecution.ts +23 -0
- package/src/db/node-sqlite.d.ts +25 -0
- package/src/db/releaseCatalog.ts +148 -0
- package/src/db/schema/mongodb.ts +20 -6
- package/src/db/schema/sql.ts +52 -11
- package/src/db/schema/sqlOperations.ts +5 -4
- package/src/db/schemaGenerators.ts +107 -23
- package/src/db/schemaReadiness.ts +2 -1
- package/src/db/sqlMigrationExecution.spec.ts +65 -0
- package/src/db/sqlMigrationExecution.ts +108 -0
- package/src/db/types.spec.ts +55 -0
- package/src/db/types.ts +129 -65
- package/src/db/updateArtifacts.spec.ts +359 -0
- package/src/db/updateArtifacts.ts +290 -126
- package/src/handler-standalone.integration.spec.ts +401 -364
- package/src/handler.spec.ts +137 -582
- package/src/handler.testFixtures.ts +30 -0
- package/src/handler.ts +218 -616
- package/src/handlerAuth.integration.spec.ts +33 -0
- package/src/handlerBundleRoutes.ts +259 -0
- package/src/handlerErrors.ts +7 -0
- package/src/handlerManagement.spec.ts +262 -0
- package/src/handlerParameters.ts +105 -0
- package/src/handlerReleaseCatalogRoutes.ts +154 -0
- package/src/handlerReleaseManagementRoutes.ts +213 -0
- package/src/handlerTypes.ts +96 -0
- package/src/handlerVersionRoutes.ts +12 -0
- package/src/index.ts +22 -2
- package/src/insights/bounded/activeOverview.spec.ts +189 -0
- package/src/insights/bounded/activeOverview.ts +148 -0
- package/src/insights/bounded/installationSearch.spec.ts +130 -0
- package/src/insights/bounded/installationSearch.ts +69 -0
- package/src/insights/bounded/persistence.ts +43 -0
- package/src/insights/bounded/provider.spec.ts +219 -0
- package/src/insights/bounded/provider.ts +229 -0
- package/src/insights/bounded/scan.ts +235 -0
- package/src/insights/domain.ts +139 -0
- package/src/insights/errors.ts +18 -0
- package/src/insights/eventInput.ts +168 -0
- package/src/insights/insights.integration.spec.ts +144 -0
- package/src/insights/persistence.ts +10 -0
- package/src/insights/queryInput.ts +102 -0
- package/src/insights/routes.ts +123 -0
- package/src/insights/types.ts +44 -0
- package/src/node.spec.ts +79 -10
- package/src/node.ts +20 -17
- package/src/releaseCatalogRoutes.integration.spec.ts +238 -0
- package/src/runtime.spec.ts +126 -959
- package/src/runtime.testFixtures.ts +71 -0
- package/src/schema/dsl-all-versions.spec.ts +26 -17
- package/src/schema/dsl.ts +41 -2
- package/src/schema/index.ts +3 -9
- package/src/schema/types.ts +9 -3
- package/src/schema/v1_0_0.spec.ts +146 -0
- package/src/schema/v1_0_0.ts +465 -0
- package/src/storageAccess.spec.ts +127 -32
- package/src/storageAccess.ts +106 -55
- package/src/types/index.ts +2 -1
- package/dist/db/bundleRows.cjs +0 -82
- package/dist/db/bundleRows.d.cts +0 -33
- package/dist/db/bundleRows.d.mts +0 -33
- package/dist/db/bundleRows.mjs +0 -79
- package/dist/db/pluginCore.cjs +0 -242
- package/dist/db/pluginCore.mjs +0 -241
- package/dist/db/schema/sqlMigrations.cjs +0 -74
- package/dist/db/schema/sqlMigrations.mjs +0 -73
- package/dist/db/schemaEnhancements.cjs +0 -20
- package/dist/db/schemaEnhancements.mjs +0 -19
- package/dist/route.cjs +0 -7
- package/dist/route.mjs +0 -7
- package/dist/schema/v0_21_0.cjs +0 -38
- package/dist/schema/v0_21_0.mjs +0 -37
- package/dist/schema/v0_29_0.cjs +0 -45
- package/dist/schema/v0_29_0.mjs +0 -44
- package/dist/schema/v0_31_0.cjs +0 -82
- package/dist/schema/v0_31_0.mjs +0 -80
- package/src/db/pluginCore.spec.ts +0 -1095
- package/src/db/pluginCore.ts +0 -475
- package/src/db/pluginUpdateCheck.bench.ts +0 -254
- package/src/db/schema/sqlMigrations.ts +0 -219
- package/src/db/schemaEnhancements.ts +0 -55
- package/src/route.ts +0 -7
- package/src/schema/v0_21_0.ts +0 -52
- package/src/schema/v0_29_0.ts +0 -62
- package/src/schema/v0_31_0.spec.ts +0 -73
- package/src/schema/v0_31_0.ts +0 -120
package/src/storageAccess.ts
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
parseStorageDownloadPath,
|
|
3
|
+
type StoragePluginWith,
|
|
4
4
|
} from "@hot-updater/plugin-core";
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return fileUrl;
|
|
11
|
-
}
|
|
12
|
-
} catch {
|
|
13
|
-
// Fall through to the runtime-specific error below.
|
|
6
|
+
const assertRemoteUrl = (value: string) => {
|
|
7
|
+
const protocol = new URL(value).protocol;
|
|
8
|
+
if (protocol !== "http:" && protocol !== "https:") {
|
|
9
|
+
throw new Error("Storage getDownloadUrl must resolve to an HTTP(S) URL.");
|
|
14
10
|
}
|
|
15
|
-
|
|
16
|
-
throw new Error(
|
|
17
|
-
"Storage plugin returned a local file path; runtime update checks require an HTTP(S) download URL.",
|
|
18
|
-
);
|
|
11
|
+
return value;
|
|
19
12
|
};
|
|
20
13
|
|
|
21
14
|
const getStorageProtocol = (storageUri: string) =>
|
|
@@ -24,66 +17,124 @@ const getStorageProtocol = (storageUri: string) =>
|
|
|
24
17
|
const isRemoteUrlProtocol = (protocol: string) =>
|
|
25
18
|
protocol === "http" || protocol === "https";
|
|
26
19
|
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
const resolveDownloadPath = (value: string, storageUri: string) => {
|
|
21
|
+
const parsed = parseStorageDownloadPath(value);
|
|
22
|
+
if (!parsed || parsed.storageUri !== storageUri) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
"Storage getDownloadUrl must return an HTTP(S) URL or a valid storage download path.",
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const tokensEqual = (left: string, right: string) => {
|
|
31
|
+
const leftBytes = new TextEncoder().encode(left);
|
|
32
|
+
const rightBytes = new TextEncoder().encode(right);
|
|
33
|
+
let difference = leftBytes.length ^ rightBytes.length;
|
|
34
|
+
const length = Math.max(leftBytes.length, rightBytes.length);
|
|
35
|
+
for (let index = 0; index < length; index += 1) {
|
|
36
|
+
difference |= (leftBytes[index] ?? 0) ^ (rightBytes[index] ?? 0);
|
|
37
|
+
}
|
|
38
|
+
return difference === 0;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const createStorageAccess = (
|
|
42
|
+
storagePlugins: StoragePluginWith<"get">[],
|
|
29
43
|
) => {
|
|
30
|
-
const
|
|
31
|
-
|
|
44
|
+
const protocols = new Set<string>();
|
|
45
|
+
for (const storage of storagePlugins) {
|
|
46
|
+
if (protocols.has(storage.protocol)) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`Multiple storage plugins handle protocol: ${storage.protocol}`,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
protocols.add(storage.protocol);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const findStorage = (protocol: string) =>
|
|
55
|
+
storagePlugins.find((item) => item.protocol === protocol);
|
|
56
|
+
|
|
57
|
+
const readStorageResponse = async (
|
|
58
|
+
storageUri: string,
|
|
59
|
+
): Promise<Response | null> => {
|
|
60
|
+
const protocol = getStorageProtocol(storageUri);
|
|
61
|
+
const storage = findStorage(protocol);
|
|
62
|
+
if (storage) return (await storage.get({ storageUri })).response;
|
|
63
|
+
|
|
64
|
+
if (isRemoteUrlProtocol(protocol)) {
|
|
65
|
+
const response = await fetch(storageUri);
|
|
66
|
+
return response.ok ? response : null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
throw new Error(`No storage plugin for protocol: ${protocol}`);
|
|
32
70
|
};
|
|
33
71
|
|
|
34
72
|
const resolveFileUrl = async (
|
|
35
73
|
storageUri: string | null,
|
|
36
|
-
context?: HotUpdaterContext<TContext>,
|
|
37
74
|
): Promise<string | null> => {
|
|
38
|
-
if (!storageUri)
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
75
|
+
if (!storageUri) return null;
|
|
41
76
|
|
|
42
77
|
const protocol = getStorageProtocol(storageUri);
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
78
|
+
const storage = findStorage(protocol);
|
|
79
|
+
if (!storage) {
|
|
80
|
+
if (isRemoteUrlProtocol(protocol)) return storageUri;
|
|
81
|
+
throw new Error(`No storage plugin for protocol: ${protocol}`);
|
|
82
|
+
}
|
|
83
|
+
if (!storage.getDownloadUrl) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
`Storage plugin "${storage.name}" does not implement getDownloadUrl.`,
|
|
48
86
|
);
|
|
49
|
-
const { fileUrl } = downloadTarget;
|
|
50
|
-
if (!fileUrl) {
|
|
51
|
-
throw new Error("Storage plugin returned empty fileUrl");
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return assertRemoteDownloadUrl(fileUrl);
|
|
55
87
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return
|
|
88
|
+
const { url: downloadUrl } = await storage.getDownloadUrl({ storageUri });
|
|
89
|
+
try {
|
|
90
|
+
return assertRemoteUrl(downloadUrl);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (/^[a-z][a-z\d+.-]*:/i.test(downloadUrl)) throw error;
|
|
59
93
|
}
|
|
60
|
-
|
|
61
|
-
throw new Error(`No storage plugin for protocol: ${protocol}`);
|
|
94
|
+
return resolveDownloadPath(downloadUrl, storageUri);
|
|
62
95
|
};
|
|
63
96
|
|
|
64
97
|
const readStorageText = async (
|
|
65
98
|
storageUri: string,
|
|
66
|
-
context?: HotUpdaterContext<TContext>,
|
|
67
99
|
): Promise<string | null> => {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return plugin.profiles.runtime.readText(storageUri, context);
|
|
72
|
-
}
|
|
100
|
+
const response = await readStorageResponse(storageUri);
|
|
101
|
+
return response?.text() ?? null;
|
|
102
|
+
};
|
|
73
103
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
104
|
+
const downloadStorageObject = storagePlugins.some(
|
|
105
|
+
(storage) => storage.getDownloadUrl !== undefined,
|
|
106
|
+
)
|
|
107
|
+
? async (
|
|
108
|
+
storageUriToken: string,
|
|
109
|
+
encodedSignature: string,
|
|
110
|
+
): Promise<Response | null> => {
|
|
111
|
+
const requestedPath = `/storage/${storageUriToken}/${encodedSignature}`;
|
|
112
|
+
const requested = parseStorageDownloadPath(requestedPath);
|
|
113
|
+
if (!requested) return null;
|
|
114
|
+
let storage: StoragePluginWith<"get"> | undefined;
|
|
115
|
+
try {
|
|
116
|
+
storage = findStorage(getStorageProtocol(requested.storageUri));
|
|
117
|
+
} catch {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
if (!storage?.getDownloadUrl) return null;
|
|
121
|
+
const { url: downloadUrl } = await storage.getDownloadUrl({
|
|
122
|
+
storageUri: requested.storageUri,
|
|
123
|
+
});
|
|
124
|
+
try {
|
|
125
|
+
new URL(downloadUrl);
|
|
126
|
+
return null;
|
|
127
|
+
} catch {
|
|
128
|
+
if (/^[a-z][a-z\d+.-]*:/i.test(downloadUrl)) return null;
|
|
129
|
+
}
|
|
130
|
+
if (!tokensEqual(downloadUrl, requestedPath)) return null;
|
|
131
|
+
return (await storage.get({ storageUri: requested.storageUri }))
|
|
132
|
+
.response;
|
|
78
133
|
}
|
|
79
|
-
|
|
80
|
-
return response.text();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
throw new Error(`No storage plugin for protocol: ${protocol}`);
|
|
84
|
-
};
|
|
134
|
+
: undefined;
|
|
85
135
|
|
|
86
136
|
return {
|
|
137
|
+
downloadStorageObject,
|
|
87
138
|
readStorageText,
|
|
88
139
|
resolveFileUrl,
|
|
89
140
|
};
|
package/src/types/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Bundle } from "@hot-updater/core";
|
|
2
|
+
import type { ChannelRow } from "@hot-updater/plugin-core";
|
|
2
3
|
|
|
3
4
|
export type { Bundle } from "@hot-updater/core";
|
|
4
5
|
export type { HotUpdaterAPI } from "../createHotUpdaterCore";
|
|
@@ -29,5 +30,5 @@ export interface Paginated<TData> extends DataResponse<TData> {
|
|
|
29
30
|
export type PaginatedResult = Paginated<Bundle[]>;
|
|
30
31
|
|
|
31
32
|
export type ChannelsResponse = DataResponse<{
|
|
32
|
-
channels:
|
|
33
|
+
channels: readonly ChannelRow[];
|
|
33
34
|
}>;
|
package/dist/db/bundleRows.cjs
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
const require_updateArtifacts = require("./updateArtifacts.cjs");
|
|
3
|
-
let _hot_updater_core = require("@hot-updater/core");
|
|
4
|
-
//#region src/db/bundleRows.ts
|
|
5
|
-
const parseTargetCohorts = (value) => {
|
|
6
|
-
if (!value) return null;
|
|
7
|
-
if (Array.isArray(value)) return value.filter((item) => typeof item === "string");
|
|
8
|
-
if (typeof value !== "string") return null;
|
|
9
|
-
try {
|
|
10
|
-
const parsed = JSON.parse(value);
|
|
11
|
-
return Array.isArray(parsed) ? parsed.filter((item) => typeof item === "string") : null;
|
|
12
|
-
} catch {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
const buildBundlePatchId = (bundleId, baseBundleId) => `${bundleId}:${baseBundleId}`;
|
|
17
|
-
const bundleToRow = (bundle) => ({
|
|
18
|
-
id: bundle.id,
|
|
19
|
-
platform: bundle.platform,
|
|
20
|
-
should_force_update: bundle.shouldForceUpdate,
|
|
21
|
-
enabled: bundle.enabled,
|
|
22
|
-
file_hash: bundle.fileHash,
|
|
23
|
-
git_commit_hash: bundle.gitCommitHash,
|
|
24
|
-
message: bundle.message,
|
|
25
|
-
channel: bundle.channel,
|
|
26
|
-
storage_uri: bundle.storageUri,
|
|
27
|
-
target_app_version: bundle.targetAppVersion,
|
|
28
|
-
fingerprint_hash: bundle.fingerprintHash,
|
|
29
|
-
metadata: (0, _hot_updater_core.stripBundleArtifactMetadata)(bundle.metadata) ?? {},
|
|
30
|
-
manifest_storage_uri: (0, _hot_updater_core.getManifestStorageUri)(bundle),
|
|
31
|
-
manifest_file_hash: (0, _hot_updater_core.getManifestFileHash)(bundle),
|
|
32
|
-
asset_base_storage_uri: (0, _hot_updater_core.getAssetBaseStorageUri)(bundle),
|
|
33
|
-
rollout_cohort_count: bundle.rolloutCohortCount ?? _hot_updater_core.DEFAULT_ROLLOUT_COHORT_COUNT,
|
|
34
|
-
target_cohorts: bundle.targetCohorts ?? null
|
|
35
|
-
});
|
|
36
|
-
const bundleToPatchRows = (bundle) => (0, _hot_updater_core.getBundlePatches)(bundle).map((patch, index) => ({
|
|
37
|
-
id: buildBundlePatchId(bundle.id, patch.baseBundleId),
|
|
38
|
-
bundle_id: bundle.id,
|
|
39
|
-
base_bundle_id: patch.baseBundleId,
|
|
40
|
-
base_file_hash: patch.baseFileHash,
|
|
41
|
-
patch_file_hash: patch.patchFileHash,
|
|
42
|
-
patch_storage_uri: patch.patchStorageUri,
|
|
43
|
-
order_index: index
|
|
44
|
-
}));
|
|
45
|
-
const mapPatchRowToPatch = (record) => ({
|
|
46
|
-
baseBundleId: record.base_bundle_id,
|
|
47
|
-
baseFileHash: record.base_file_hash,
|
|
48
|
-
patchFileHash: record.patch_file_hash,
|
|
49
|
-
patchStorageUri: record.patch_storage_uri
|
|
50
|
-
});
|
|
51
|
-
const rowToBundle = (record, patchRecords = []) => {
|
|
52
|
-
const patches = patchRecords.slice().sort((left, right) => (left.order_index ?? 0) - (right.order_index ?? 0) || left.base_bundle_id.localeCompare(right.base_bundle_id)).map(mapPatchRowToPatch);
|
|
53
|
-
const primaryPatch = patches[0] ?? null;
|
|
54
|
-
return {
|
|
55
|
-
id: record.id,
|
|
56
|
-
platform: record.platform,
|
|
57
|
-
shouldForceUpdate: Boolean(record.should_force_update),
|
|
58
|
-
enabled: Boolean(record.enabled),
|
|
59
|
-
fileHash: record.file_hash,
|
|
60
|
-
gitCommitHash: record.git_commit_hash ?? null,
|
|
61
|
-
message: record.message ?? null,
|
|
62
|
-
channel: record.channel,
|
|
63
|
-
storageUri: record.storage_uri,
|
|
64
|
-
targetAppVersion: record.target_app_version ?? null,
|
|
65
|
-
fingerprintHash: record.fingerprint_hash ?? null,
|
|
66
|
-
metadata: require_updateArtifacts.parseBundleMetadata(record.metadata),
|
|
67
|
-
manifestStorageUri: record.manifest_storage_uri ?? null,
|
|
68
|
-
manifestFileHash: record.manifest_file_hash ?? null,
|
|
69
|
-
assetBaseStorageUri: record.asset_base_storage_uri ?? null,
|
|
70
|
-
patches,
|
|
71
|
-
patchBaseBundleId: primaryPatch?.baseBundleId ?? null,
|
|
72
|
-
patchBaseFileHash: primaryPatch?.baseFileHash ?? null,
|
|
73
|
-
patchFileHash: primaryPatch?.patchFileHash ?? null,
|
|
74
|
-
patchStorageUri: primaryPatch?.patchStorageUri ?? null,
|
|
75
|
-
rolloutCohortCount: record.rollout_cohort_count ?? _hot_updater_core.DEFAULT_ROLLOUT_COHORT_COUNT,
|
|
76
|
-
targetCohorts: parseTargetCohorts(record.target_cohorts)
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
//#endregion
|
|
80
|
-
exports.bundleToPatchRows = bundleToPatchRows;
|
|
81
|
-
exports.bundleToRow = bundleToRow;
|
|
82
|
-
exports.rowToBundle = rowToBundle;
|
package/dist/db/bundleRows.d.cts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Bundle } from "@hot-updater/core";
|
|
2
|
-
|
|
3
|
-
//#region src/db/bundleRows.d.ts
|
|
4
|
-
type BundleRow = {
|
|
5
|
-
readonly id: string;
|
|
6
|
-
readonly platform: string;
|
|
7
|
-
readonly should_force_update: unknown;
|
|
8
|
-
readonly enabled: unknown;
|
|
9
|
-
readonly file_hash: string;
|
|
10
|
-
readonly git_commit_hash: string | null;
|
|
11
|
-
readonly message: string | null;
|
|
12
|
-
readonly channel: string;
|
|
13
|
-
readonly storage_uri: string;
|
|
14
|
-
readonly target_app_version: string | null;
|
|
15
|
-
readonly fingerprint_hash: string | null;
|
|
16
|
-
readonly metadata?: unknown;
|
|
17
|
-
readonly manifest_storage_uri?: string | null;
|
|
18
|
-
readonly manifest_file_hash?: string | null;
|
|
19
|
-
readonly asset_base_storage_uri?: string | null;
|
|
20
|
-
readonly rollout_cohort_count?: number | null;
|
|
21
|
-
readonly target_cohorts?: unknown;
|
|
22
|
-
};
|
|
23
|
-
type BundlePatchRow = {
|
|
24
|
-
readonly id: string;
|
|
25
|
-
readonly bundle_id: string;
|
|
26
|
-
readonly base_bundle_id: string;
|
|
27
|
-
readonly base_file_hash: string;
|
|
28
|
-
readonly patch_file_hash: string;
|
|
29
|
-
readonly patch_storage_uri: string;
|
|
30
|
-
readonly order_index?: number | null;
|
|
31
|
-
};
|
|
32
|
-
//#endregion
|
|
33
|
-
export { BundlePatchRow, BundleRow };
|
package/dist/db/bundleRows.d.mts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Bundle } from "@hot-updater/core";
|
|
2
|
-
|
|
3
|
-
//#region src/db/bundleRows.d.ts
|
|
4
|
-
type BundleRow = {
|
|
5
|
-
readonly id: string;
|
|
6
|
-
readonly platform: string;
|
|
7
|
-
readonly should_force_update: unknown;
|
|
8
|
-
readonly enabled: unknown;
|
|
9
|
-
readonly file_hash: string;
|
|
10
|
-
readonly git_commit_hash: string | null;
|
|
11
|
-
readonly message: string | null;
|
|
12
|
-
readonly channel: string;
|
|
13
|
-
readonly storage_uri: string;
|
|
14
|
-
readonly target_app_version: string | null;
|
|
15
|
-
readonly fingerprint_hash: string | null;
|
|
16
|
-
readonly metadata?: unknown;
|
|
17
|
-
readonly manifest_storage_uri?: string | null;
|
|
18
|
-
readonly manifest_file_hash?: string | null;
|
|
19
|
-
readonly asset_base_storage_uri?: string | null;
|
|
20
|
-
readonly rollout_cohort_count?: number | null;
|
|
21
|
-
readonly target_cohorts?: unknown;
|
|
22
|
-
};
|
|
23
|
-
type BundlePatchRow = {
|
|
24
|
-
readonly id: string;
|
|
25
|
-
readonly bundle_id: string;
|
|
26
|
-
readonly base_bundle_id: string;
|
|
27
|
-
readonly base_file_hash: string;
|
|
28
|
-
readonly patch_file_hash: string;
|
|
29
|
-
readonly patch_storage_uri: string;
|
|
30
|
-
readonly order_index?: number | null;
|
|
31
|
-
};
|
|
32
|
-
//#endregion
|
|
33
|
-
export { BundlePatchRow, BundleRow };
|
package/dist/db/bundleRows.mjs
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { parseBundleMetadata } from "./updateArtifacts.mjs";
|
|
2
|
-
import { DEFAULT_ROLLOUT_COHORT_COUNT, getAssetBaseStorageUri, getBundlePatches, getManifestFileHash, getManifestStorageUri, stripBundleArtifactMetadata } from "@hot-updater/core";
|
|
3
|
-
//#region src/db/bundleRows.ts
|
|
4
|
-
const parseTargetCohorts = (value) => {
|
|
5
|
-
if (!value) return null;
|
|
6
|
-
if (Array.isArray(value)) return value.filter((item) => typeof item === "string");
|
|
7
|
-
if (typeof value !== "string") return null;
|
|
8
|
-
try {
|
|
9
|
-
const parsed = JSON.parse(value);
|
|
10
|
-
return Array.isArray(parsed) ? parsed.filter((item) => typeof item === "string") : null;
|
|
11
|
-
} catch {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
const buildBundlePatchId = (bundleId, baseBundleId) => `${bundleId}:${baseBundleId}`;
|
|
16
|
-
const bundleToRow = (bundle) => ({
|
|
17
|
-
id: bundle.id,
|
|
18
|
-
platform: bundle.platform,
|
|
19
|
-
should_force_update: bundle.shouldForceUpdate,
|
|
20
|
-
enabled: bundle.enabled,
|
|
21
|
-
file_hash: bundle.fileHash,
|
|
22
|
-
git_commit_hash: bundle.gitCommitHash,
|
|
23
|
-
message: bundle.message,
|
|
24
|
-
channel: bundle.channel,
|
|
25
|
-
storage_uri: bundle.storageUri,
|
|
26
|
-
target_app_version: bundle.targetAppVersion,
|
|
27
|
-
fingerprint_hash: bundle.fingerprintHash,
|
|
28
|
-
metadata: stripBundleArtifactMetadata(bundle.metadata) ?? {},
|
|
29
|
-
manifest_storage_uri: getManifestStorageUri(bundle),
|
|
30
|
-
manifest_file_hash: getManifestFileHash(bundle),
|
|
31
|
-
asset_base_storage_uri: getAssetBaseStorageUri(bundle),
|
|
32
|
-
rollout_cohort_count: bundle.rolloutCohortCount ?? DEFAULT_ROLLOUT_COHORT_COUNT,
|
|
33
|
-
target_cohorts: bundle.targetCohorts ?? null
|
|
34
|
-
});
|
|
35
|
-
const bundleToPatchRows = (bundle) => getBundlePatches(bundle).map((patch, index) => ({
|
|
36
|
-
id: buildBundlePatchId(bundle.id, patch.baseBundleId),
|
|
37
|
-
bundle_id: bundle.id,
|
|
38
|
-
base_bundle_id: patch.baseBundleId,
|
|
39
|
-
base_file_hash: patch.baseFileHash,
|
|
40
|
-
patch_file_hash: patch.patchFileHash,
|
|
41
|
-
patch_storage_uri: patch.patchStorageUri,
|
|
42
|
-
order_index: index
|
|
43
|
-
}));
|
|
44
|
-
const mapPatchRowToPatch = (record) => ({
|
|
45
|
-
baseBundleId: record.base_bundle_id,
|
|
46
|
-
baseFileHash: record.base_file_hash,
|
|
47
|
-
patchFileHash: record.patch_file_hash,
|
|
48
|
-
patchStorageUri: record.patch_storage_uri
|
|
49
|
-
});
|
|
50
|
-
const rowToBundle = (record, patchRecords = []) => {
|
|
51
|
-
const patches = patchRecords.slice().sort((left, right) => (left.order_index ?? 0) - (right.order_index ?? 0) || left.base_bundle_id.localeCompare(right.base_bundle_id)).map(mapPatchRowToPatch);
|
|
52
|
-
const primaryPatch = patches[0] ?? null;
|
|
53
|
-
return {
|
|
54
|
-
id: record.id,
|
|
55
|
-
platform: record.platform,
|
|
56
|
-
shouldForceUpdate: Boolean(record.should_force_update),
|
|
57
|
-
enabled: Boolean(record.enabled),
|
|
58
|
-
fileHash: record.file_hash,
|
|
59
|
-
gitCommitHash: record.git_commit_hash ?? null,
|
|
60
|
-
message: record.message ?? null,
|
|
61
|
-
channel: record.channel,
|
|
62
|
-
storageUri: record.storage_uri,
|
|
63
|
-
targetAppVersion: record.target_app_version ?? null,
|
|
64
|
-
fingerprintHash: record.fingerprint_hash ?? null,
|
|
65
|
-
metadata: parseBundleMetadata(record.metadata),
|
|
66
|
-
manifestStorageUri: record.manifest_storage_uri ?? null,
|
|
67
|
-
manifestFileHash: record.manifest_file_hash ?? null,
|
|
68
|
-
assetBaseStorageUri: record.asset_base_storage_uri ?? null,
|
|
69
|
-
patches,
|
|
70
|
-
patchBaseBundleId: primaryPatch?.baseBundleId ?? null,
|
|
71
|
-
patchBaseFileHash: primaryPatch?.baseFileHash ?? null,
|
|
72
|
-
patchFileHash: primaryPatch?.patchFileHash ?? null,
|
|
73
|
-
patchStorageUri: primaryPatch?.patchStorageUri ?? null,
|
|
74
|
-
rolloutCohortCount: record.rollout_cohort_count ?? DEFAULT_ROLLOUT_COHORT_COUNT,
|
|
75
|
-
targetCohorts: parseTargetCohorts(record.target_cohorts)
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
|
-
//#endregion
|
|
79
|
-
export { bundleToPatchRows, bundleToRow, rowToBundle };
|
package/dist/db/pluginCore.cjs
DELETED
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
const require_schemaEnhancements = require("./schemaEnhancements.cjs");
|
|
3
|
-
const require_updateArtifacts = require("./updateArtifacts.cjs");
|
|
4
|
-
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
5
|
-
let _hot_updater_core = require("@hot-updater/core");
|
|
6
|
-
//#region src/db/pluginCore.ts
|
|
7
|
-
const PAGE_SIZE = 100;
|
|
8
|
-
const DESC_ORDER = {
|
|
9
|
-
field: "id",
|
|
10
|
-
direction: "desc"
|
|
11
|
-
};
|
|
12
|
-
const bundleMatchesQueryWhere = (bundle, where) => {
|
|
13
|
-
if (!where) return true;
|
|
14
|
-
if (where.channel !== void 0 && bundle.channel !== where.channel) return false;
|
|
15
|
-
if (where.platform !== void 0 && bundle.platform !== where.platform) return false;
|
|
16
|
-
if (where.enabled !== void 0 && bundle.enabled !== where.enabled) return false;
|
|
17
|
-
if (where.id?.eq !== void 0 && bundle.id !== where.id.eq) return false;
|
|
18
|
-
if (where.id?.gt !== void 0 && bundle.id.localeCompare(where.id.gt) <= 0) return false;
|
|
19
|
-
if (where.id?.gte !== void 0 && bundle.id.localeCompare(where.id.gte) < 0) return false;
|
|
20
|
-
if (where.id?.lt !== void 0 && bundle.id.localeCompare(where.id.lt) >= 0) return false;
|
|
21
|
-
if (where.id?.lte !== void 0 && bundle.id.localeCompare(where.id.lte) > 0) return false;
|
|
22
|
-
if (where.id?.in && !where.id.in.includes(bundle.id)) return false;
|
|
23
|
-
if (where.targetAppVersionNotNull && bundle.targetAppVersion === null) return false;
|
|
24
|
-
if (where.targetAppVersion !== void 0 && bundle.targetAppVersion !== where.targetAppVersion) return false;
|
|
25
|
-
if (where.targetAppVersionIn && !where.targetAppVersionIn.includes(bundle.targetAppVersion ?? "")) return false;
|
|
26
|
-
if (where.fingerprintHash !== void 0 && bundle.fingerprintHash !== where.fingerprintHash) return false;
|
|
27
|
-
return true;
|
|
28
|
-
};
|
|
29
|
-
const sortBundles = (bundles, orderBy) => {
|
|
30
|
-
const direction = orderBy?.direction ?? "desc";
|
|
31
|
-
return bundles.slice().sort((a, b) => {
|
|
32
|
-
const result = a.id.localeCompare(b.id);
|
|
33
|
-
return direction === "asc" ? result : -result;
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
const makeResponse = (bundle, status) => ({
|
|
37
|
-
id: bundle.id,
|
|
38
|
-
message: bundle.message,
|
|
39
|
-
shouldForceUpdate: status === "ROLLBACK" ? true : bundle.shouldForceUpdate,
|
|
40
|
-
status,
|
|
41
|
-
storageUri: bundle.storageUri,
|
|
42
|
-
fileHash: bundle.fileHash
|
|
43
|
-
});
|
|
44
|
-
const INIT_BUNDLE_ROLLBACK_UPDATE_INFO = {
|
|
45
|
-
message: null,
|
|
46
|
-
id: _hot_updater_core.NIL_UUID,
|
|
47
|
-
shouldForceUpdate: true,
|
|
48
|
-
status: "ROLLBACK",
|
|
49
|
-
storageUri: null,
|
|
50
|
-
fileHash: null
|
|
51
|
-
};
|
|
52
|
-
function createPluginDatabaseCore(getPlugin, resolveFileUrl, options) {
|
|
53
|
-
const coreOptions = options;
|
|
54
|
-
const runWithMutationPlugin = async (operation) => {
|
|
55
|
-
const plugin = coreOptions?.createMutationPlugin?.() ?? getPlugin();
|
|
56
|
-
try {
|
|
57
|
-
return await operation(plugin);
|
|
58
|
-
} finally {
|
|
59
|
-
if (coreOptions?.createMutationPlugin) await coreOptions.cleanupMutationPlugin?.(plugin);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
const getSortedBundlePage = async (options, context) => {
|
|
63
|
-
const result = await getPlugin().getBundles({
|
|
64
|
-
...options,
|
|
65
|
-
orderBy: options.orderBy ?? DESC_ORDER
|
|
66
|
-
}, context);
|
|
67
|
-
return {
|
|
68
|
-
...result,
|
|
69
|
-
data: sortBundles(result.data, options.orderBy ?? DESC_ORDER)
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
const isEligibleForUpdate = (bundle, cohort) => {
|
|
73
|
-
return (0, _hot_updater_core.isCohortEligibleForUpdate)(bundle.id, cohort, bundle.rolloutCohortCount, bundle.targetCohorts);
|
|
74
|
-
};
|
|
75
|
-
const findUpdateInfoByScanning = async ({ args, queryWhere, isCandidate, context }) => {
|
|
76
|
-
let after;
|
|
77
|
-
while (true) {
|
|
78
|
-
const { data, pagination } = await getSortedBundlePage({
|
|
79
|
-
where: queryWhere,
|
|
80
|
-
limit: PAGE_SIZE,
|
|
81
|
-
orderBy: DESC_ORDER,
|
|
82
|
-
...after ? { cursor: { after } } : {}
|
|
83
|
-
}, context);
|
|
84
|
-
for (const bundle of data) {
|
|
85
|
-
if (!bundleMatchesQueryWhere(bundle, queryWhere) || !isCandidate(bundle)) continue;
|
|
86
|
-
if (args.bundleId === _hot_updater_core.NIL_UUID) {
|
|
87
|
-
if (isEligibleForUpdate(bundle, args.cohort)) return makeResponse(bundle, "UPDATE");
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
const compareResult = bundle.id.localeCompare(args.bundleId);
|
|
91
|
-
if (compareResult > 0) {
|
|
92
|
-
if (isEligibleForUpdate(bundle, args.cohort)) return makeResponse(bundle, "UPDATE");
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
if (compareResult === 0) {
|
|
96
|
-
if (isEligibleForUpdate(bundle, args.cohort)) return null;
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
return makeResponse(bundle, "ROLLBACK");
|
|
100
|
-
}
|
|
101
|
-
if (!pagination.hasNextPage) break;
|
|
102
|
-
after = data.at(-1)?.id;
|
|
103
|
-
if (!after) break;
|
|
104
|
-
}
|
|
105
|
-
if (args.bundleId === _hot_updater_core.NIL_UUID) return null;
|
|
106
|
-
if (args.minBundleId && args.bundleId.localeCompare(args.minBundleId) <= 0) return null;
|
|
107
|
-
return INIT_BUNDLE_ROLLBACK_UPDATE_INFO;
|
|
108
|
-
};
|
|
109
|
-
const getBaseWhere = ({ platform, channel, minBundleId }) => ({
|
|
110
|
-
platform,
|
|
111
|
-
channel,
|
|
112
|
-
enabled: true,
|
|
113
|
-
id: { gte: minBundleId }
|
|
114
|
-
});
|
|
115
|
-
return {
|
|
116
|
-
api: {
|
|
117
|
-
async getBundleById(id, context) {
|
|
118
|
-
await coreOptions?.beforeOperation?.();
|
|
119
|
-
return getPlugin().getBundleById(id, context);
|
|
120
|
-
},
|
|
121
|
-
async getUpdateInfo(args, context) {
|
|
122
|
-
await coreOptions?.beforeOperation?.();
|
|
123
|
-
const directGetUpdateInfo = getPlugin().getUpdateInfo;
|
|
124
|
-
if (directGetUpdateInfo) return context === void 0 ? await directGetUpdateInfo(args) : await directGetUpdateInfo(args, context);
|
|
125
|
-
const channel = args.channel ?? "production";
|
|
126
|
-
const minBundleId = args.minBundleId ?? _hot_updater_core.NIL_UUID;
|
|
127
|
-
const baseWhere = getBaseWhere({
|
|
128
|
-
platform: args.platform,
|
|
129
|
-
channel,
|
|
130
|
-
minBundleId
|
|
131
|
-
});
|
|
132
|
-
if (args._updateStrategy === "fingerprint") return findUpdateInfoByScanning({
|
|
133
|
-
args,
|
|
134
|
-
queryWhere: {
|
|
135
|
-
...baseWhere,
|
|
136
|
-
fingerprintHash: args.fingerprintHash
|
|
137
|
-
},
|
|
138
|
-
context,
|
|
139
|
-
isCandidate: (bundle) => {
|
|
140
|
-
return bundle.enabled && bundle.platform === args.platform && bundle.channel === channel && bundle.id.localeCompare(minBundleId) >= 0 && bundle.fingerprintHash === args.fingerprintHash;
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
return findUpdateInfoByScanning({
|
|
144
|
-
args,
|
|
145
|
-
queryWhere: { ...baseWhere },
|
|
146
|
-
context,
|
|
147
|
-
isCandidate: (bundle) => {
|
|
148
|
-
return bundle.enabled && bundle.platform === args.platform && bundle.channel === channel && bundle.id.localeCompare(minBundleId) >= 0 && !!bundle.targetAppVersion && (0, _hot_updater_plugin_core.semverSatisfies)(bundle.targetAppVersion, args.appVersion);
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
},
|
|
152
|
-
async getAppUpdateInfo(args, context) {
|
|
153
|
-
const info = await this.getUpdateInfo(args, context);
|
|
154
|
-
if (!info) return null;
|
|
155
|
-
const { storageUri, ...rest } = info;
|
|
156
|
-
const readStorageText = coreOptions?.readStorageText;
|
|
157
|
-
if (info.id === _hot_updater_core.NIL_UUID || !readStorageText) {
|
|
158
|
-
const fileUrl = await resolveFileUrl(storageUri ?? null, context);
|
|
159
|
-
return {
|
|
160
|
-
...rest,
|
|
161
|
-
fileUrl
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
const requestBundles = (0, _hot_updater_plugin_core.createRequestUpdateBundleResolver)(context);
|
|
165
|
-
const getCurrentBundle = () => {
|
|
166
|
-
if (args.bundleId === _hot_updater_core.NIL_UUID) return null;
|
|
167
|
-
const seededCurrentBundle = requestBundles.peek(args.bundleId);
|
|
168
|
-
if (seededCurrentBundle || requestBundles.hasSeededBundles()) return seededCurrentBundle;
|
|
169
|
-
return requestBundles.getById(args.bundleId, () => getPlugin().getBundleById(args.bundleId, context));
|
|
170
|
-
};
|
|
171
|
-
const [fileUrl, targetBundle, currentBundle] = await Promise.all([
|
|
172
|
-
resolveFileUrl(storageUri ?? null, context),
|
|
173
|
-
requestBundles.getById(info.id, () => getPlugin().getBundleById(info.id, context)),
|
|
174
|
-
getCurrentBundle()
|
|
175
|
-
]);
|
|
176
|
-
const baseResponse = {
|
|
177
|
-
...rest,
|
|
178
|
-
fileUrl
|
|
179
|
-
};
|
|
180
|
-
const manifestArtifacts = await require_updateArtifacts.resolveManifestArtifacts({
|
|
181
|
-
currentBundle,
|
|
182
|
-
resolveFileUrl,
|
|
183
|
-
readStorageText,
|
|
184
|
-
targetBundle,
|
|
185
|
-
context
|
|
186
|
-
});
|
|
187
|
-
if (!manifestArtifacts) return baseResponse;
|
|
188
|
-
return {
|
|
189
|
-
...baseResponse,
|
|
190
|
-
...manifestArtifacts
|
|
191
|
-
};
|
|
192
|
-
},
|
|
193
|
-
async getChannels(context) {
|
|
194
|
-
await coreOptions?.beforeOperation?.();
|
|
195
|
-
return getPlugin().getChannels(context);
|
|
196
|
-
},
|
|
197
|
-
async getBundles(options, context) {
|
|
198
|
-
await coreOptions?.beforeOperation?.();
|
|
199
|
-
return getPlugin().getBundles(options, context);
|
|
200
|
-
},
|
|
201
|
-
async insertBundle(bundle, context) {
|
|
202
|
-
await coreOptions?.beforeOperation?.();
|
|
203
|
-
require_schemaEnhancements.assertBundlePersistenceConstraints(bundle);
|
|
204
|
-
await runWithMutationPlugin(async (plugin) => {
|
|
205
|
-
await plugin.appendBundle(bundle, context);
|
|
206
|
-
await plugin.commitBundle(context);
|
|
207
|
-
});
|
|
208
|
-
},
|
|
209
|
-
async updateBundleById(bundleId, newBundle, context) {
|
|
210
|
-
await coreOptions?.beforeOperation?.();
|
|
211
|
-
await runWithMutationPlugin(async (plugin) => {
|
|
212
|
-
const current = await plugin.getBundleById(bundleId, context);
|
|
213
|
-
if (!current) throw new Error("targetBundleId not found");
|
|
214
|
-
require_schemaEnhancements.assertBundlePersistenceConstraints({
|
|
215
|
-
...current,
|
|
216
|
-
...newBundle
|
|
217
|
-
});
|
|
218
|
-
await plugin.updateBundle(bundleId, newBundle, context);
|
|
219
|
-
await plugin.commitBundle(context);
|
|
220
|
-
});
|
|
221
|
-
},
|
|
222
|
-
async deleteBundleById(bundleId, context) {
|
|
223
|
-
await coreOptions?.beforeOperation?.();
|
|
224
|
-
await runWithMutationPlugin(async (plugin) => {
|
|
225
|
-
const bundle = await plugin.getBundleById(bundleId, context);
|
|
226
|
-
if (!bundle) return;
|
|
227
|
-
await plugin.deleteBundle(bundle, context);
|
|
228
|
-
await plugin.commitBundle(context);
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
},
|
|
232
|
-
adapterName: getPlugin().name,
|
|
233
|
-
createMigrator: () => {
|
|
234
|
-
throw new Error("createMigrator is only available for Kysely/MongoDB database adapters.");
|
|
235
|
-
},
|
|
236
|
-
generateSchema: () => {
|
|
237
|
-
throw new Error("generateSchema is only available for Drizzle/Prisma database adapters.");
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
//#endregion
|
|
242
|
-
exports.createPluginDatabaseCore = createPluginDatabaseCore;
|