@hot-updater/server 0.36.7 → 1.0.0-rc.0
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/analytics/bounded/activeOverview.cjs +87 -0
- package/dist/analytics/bounded/activeOverview.mjs +85 -0
- package/dist/analytics/bounded/installationSearch.cjs +42 -0
- package/dist/analytics/bounded/installationSearch.mjs +42 -0
- package/dist/analytics/bounded/persistence.cjs +39 -0
- package/dist/analytics/bounded/persistence.mjs +38 -0
- package/dist/analytics/bounded/provider.cjs +170 -0
- package/dist/analytics/bounded/provider.d.cts +7 -0
- package/dist/analytics/bounded/provider.d.mts +7 -0
- package/dist/analytics/bounded/provider.mjs +170 -0
- package/dist/analytics/bounded/scan.cjs +144 -0
- package/dist/analytics/bounded/scan.mjs +138 -0
- package/dist/analytics/domain.d.cts +121 -0
- package/dist/analytics/domain.d.mts +121 -0
- package/dist/analytics/errors.cjs +22 -0
- package/dist/analytics/errors.mjs +20 -0
- package/dist/analytics/eventInput.cjs +111 -0
- package/dist/analytics/eventInput.mjs +111 -0
- package/dist/analytics/persistence.d.cts +6 -0
- package/dist/analytics/persistence.d.mts +6 -0
- package/dist/analytics/queryInput.cjs +58 -0
- package/dist/analytics/queryInput.mjs +55 -0
- package/dist/analytics/routes.cjs +63 -0
- package/dist/analytics/routes.mjs +61 -0
- package/dist/analytics/types.d.cts +17 -0
- package/dist/analytics/types.d.mts +17 -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/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/analytics/analytics.integration.spec.ts +144 -0
- package/src/analytics/bounded/activeOverview.spec.ts +189 -0
- package/src/analytics/bounded/activeOverview.ts +148 -0
- package/src/analytics/bounded/installationSearch.spec.ts +130 -0
- package/src/analytics/bounded/installationSearch.ts +69 -0
- package/src/analytics/bounded/persistence.ts +43 -0
- package/src/analytics/bounded/provider.spec.ts +219 -0
- package/src/analytics/bounded/provider.ts +229 -0
- package/src/analytics/bounded/scan.ts +235 -0
- package/src/analytics/domain.ts +139 -0
- package/src/analytics/errors.ts +18 -0
- package/src/analytics/eventInput.ts +168 -0
- package/src/analytics/persistence.ts +10 -0
- package/src/analytics/queryInput.ts +102 -0
- package/src/analytics/routes.ts +123 -0
- package/src/analytics/types.ts +44 -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/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/db/pluginCore.ts
DELETED
|
@@ -1,475 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AppUpdateAvailableInfo,
|
|
3
|
-
AppVersionGetBundlesArgs,
|
|
4
|
-
Bundle,
|
|
5
|
-
FingerprintGetBundlesArgs,
|
|
6
|
-
GetBundlesArgs,
|
|
7
|
-
Platform,
|
|
8
|
-
UpdateInfo,
|
|
9
|
-
} from "@hot-updater/core";
|
|
10
|
-
import { isCohortEligibleForUpdate, NIL_UUID } from "@hot-updater/core";
|
|
11
|
-
import {
|
|
12
|
-
type DatabaseBundleQueryOptions,
|
|
13
|
-
type DatabaseBundleQueryOrder,
|
|
14
|
-
type DatabaseBundleQueryWhere,
|
|
15
|
-
type DatabasePlugin,
|
|
16
|
-
createRequestUpdateBundleResolver,
|
|
17
|
-
type HotUpdaterContext,
|
|
18
|
-
semverSatisfies,
|
|
19
|
-
} from "@hot-updater/plugin-core";
|
|
20
|
-
|
|
21
|
-
import { assertBundlePersistenceConstraints } from "./schemaEnhancements";
|
|
22
|
-
import type { DatabaseAPI } from "./types";
|
|
23
|
-
import { resolveManifestArtifacts } from "./updateArtifacts";
|
|
24
|
-
|
|
25
|
-
const PAGE_SIZE = 100;
|
|
26
|
-
const DESC_ORDER = { field: "id", direction: "desc" } as const;
|
|
27
|
-
|
|
28
|
-
const bundleMatchesQueryWhere = (
|
|
29
|
-
bundle: Bundle,
|
|
30
|
-
where: DatabaseBundleQueryWhere | undefined,
|
|
31
|
-
) => {
|
|
32
|
-
if (!where) return true;
|
|
33
|
-
if (where.channel !== undefined && bundle.channel !== where.channel)
|
|
34
|
-
return false;
|
|
35
|
-
if (where.platform !== undefined && bundle.platform !== where.platform)
|
|
36
|
-
return false;
|
|
37
|
-
if (where.enabled !== undefined && bundle.enabled !== where.enabled)
|
|
38
|
-
return false;
|
|
39
|
-
if (where.id?.eq !== undefined && bundle.id !== where.id.eq) return false;
|
|
40
|
-
if (where.id?.gt !== undefined && bundle.id.localeCompare(where.id.gt) <= 0)
|
|
41
|
-
return false;
|
|
42
|
-
if (where.id?.gte !== undefined && bundle.id.localeCompare(where.id.gte) < 0)
|
|
43
|
-
return false;
|
|
44
|
-
if (where.id?.lt !== undefined && bundle.id.localeCompare(where.id.lt) >= 0)
|
|
45
|
-
return false;
|
|
46
|
-
if (where.id?.lte !== undefined && bundle.id.localeCompare(where.id.lte) > 0)
|
|
47
|
-
return false;
|
|
48
|
-
if (where.id?.in && !where.id.in.includes(bundle.id)) return false;
|
|
49
|
-
if (where.targetAppVersionNotNull && bundle.targetAppVersion === null) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
if (
|
|
53
|
-
where.targetAppVersion !== undefined &&
|
|
54
|
-
bundle.targetAppVersion !== where.targetAppVersion
|
|
55
|
-
) {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
if (
|
|
59
|
-
where.targetAppVersionIn &&
|
|
60
|
-
!where.targetAppVersionIn.includes(bundle.targetAppVersion ?? "")
|
|
61
|
-
) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
if (
|
|
65
|
-
where.fingerprintHash !== undefined &&
|
|
66
|
-
bundle.fingerprintHash !== where.fingerprintHash
|
|
67
|
-
) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
return true;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const sortBundles = (
|
|
74
|
-
bundles: Bundle[],
|
|
75
|
-
orderBy: DatabaseBundleQueryOrder | undefined,
|
|
76
|
-
) => {
|
|
77
|
-
const direction = orderBy?.direction ?? "desc";
|
|
78
|
-
return bundles.slice().sort((a, b) => {
|
|
79
|
-
const result = a.id.localeCompare(b.id);
|
|
80
|
-
return direction === "asc" ? result : -result;
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const makeResponse = (
|
|
85
|
-
bundle: Bundle,
|
|
86
|
-
status: "UPDATE" | "ROLLBACK",
|
|
87
|
-
): UpdateInfo => ({
|
|
88
|
-
id: bundle.id,
|
|
89
|
-
message: bundle.message,
|
|
90
|
-
shouldForceUpdate: status === "ROLLBACK" ? true : bundle.shouldForceUpdate,
|
|
91
|
-
status,
|
|
92
|
-
storageUri: bundle.storageUri,
|
|
93
|
-
fileHash: bundle.fileHash,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const INIT_BUNDLE_ROLLBACK_UPDATE_INFO: UpdateInfo = {
|
|
97
|
-
message: null,
|
|
98
|
-
id: NIL_UUID,
|
|
99
|
-
shouldForceUpdate: true,
|
|
100
|
-
status: "ROLLBACK",
|
|
101
|
-
storageUri: null,
|
|
102
|
-
fileHash: null,
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export function createPluginDatabaseCore<TContext = unknown>(
|
|
106
|
-
getPlugin: () => DatabasePlugin<TContext>,
|
|
107
|
-
resolveFileUrl: (
|
|
108
|
-
storageUri: string | null,
|
|
109
|
-
context?: HotUpdaterContext<TContext>,
|
|
110
|
-
) => Promise<string | null>,
|
|
111
|
-
options?: {
|
|
112
|
-
createMutationPlugin?: () => DatabasePlugin<TContext>;
|
|
113
|
-
cleanupMutationPlugin?: (
|
|
114
|
-
plugin: DatabasePlugin<TContext>,
|
|
115
|
-
) => Promise<void> | void;
|
|
116
|
-
beforeOperation?: () => Promise<void>;
|
|
117
|
-
readStorageText?: (
|
|
118
|
-
storageUri: string,
|
|
119
|
-
context?: HotUpdaterContext<TContext>,
|
|
120
|
-
) => Promise<string | null>;
|
|
121
|
-
},
|
|
122
|
-
): {
|
|
123
|
-
api: DatabaseAPI<TContext>;
|
|
124
|
-
adapterName: string;
|
|
125
|
-
createMigrator: () => never;
|
|
126
|
-
generateSchema: () => never;
|
|
127
|
-
} {
|
|
128
|
-
const coreOptions = options;
|
|
129
|
-
const runWithMutationPlugin = async <T>(
|
|
130
|
-
operation: (plugin: DatabasePlugin<TContext>) => Promise<T>,
|
|
131
|
-
): Promise<T> => {
|
|
132
|
-
const plugin = coreOptions?.createMutationPlugin?.() ?? getPlugin();
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
return await operation(plugin);
|
|
136
|
-
} finally {
|
|
137
|
-
if (coreOptions?.createMutationPlugin) {
|
|
138
|
-
await coreOptions.cleanupMutationPlugin?.(plugin);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
const getSortedBundlePage = async (
|
|
144
|
-
options: DatabaseBundleQueryOptions,
|
|
145
|
-
context?: HotUpdaterContext<TContext>,
|
|
146
|
-
): Promise<Awaited<ReturnType<DatabasePlugin<TContext>["getBundles"]>>> => {
|
|
147
|
-
const result = await getPlugin().getBundles(
|
|
148
|
-
{
|
|
149
|
-
...options,
|
|
150
|
-
orderBy: options.orderBy ?? DESC_ORDER,
|
|
151
|
-
},
|
|
152
|
-
context,
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
return {
|
|
156
|
-
...result,
|
|
157
|
-
data: sortBundles(result.data, options.orderBy ?? DESC_ORDER),
|
|
158
|
-
};
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
const isEligibleForUpdate = (
|
|
162
|
-
bundle: Bundle,
|
|
163
|
-
cohort: string | undefined,
|
|
164
|
-
): boolean => {
|
|
165
|
-
return isCohortEligibleForUpdate(
|
|
166
|
-
bundle.id,
|
|
167
|
-
cohort,
|
|
168
|
-
bundle.rolloutCohortCount,
|
|
169
|
-
bundle.targetCohorts,
|
|
170
|
-
);
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
const findUpdateInfoByScanning = async ({
|
|
174
|
-
args,
|
|
175
|
-
queryWhere,
|
|
176
|
-
isCandidate,
|
|
177
|
-
context,
|
|
178
|
-
}: {
|
|
179
|
-
args: AppVersionGetBundlesArgs | FingerprintGetBundlesArgs;
|
|
180
|
-
queryWhere: DatabaseBundleQueryWhere;
|
|
181
|
-
isCandidate: (bundle: Bundle) => boolean;
|
|
182
|
-
context?: HotUpdaterContext<TContext>;
|
|
183
|
-
}): Promise<UpdateInfo | null> => {
|
|
184
|
-
let after: string | undefined;
|
|
185
|
-
|
|
186
|
-
while (true) {
|
|
187
|
-
const { data, pagination } = await getSortedBundlePage(
|
|
188
|
-
{
|
|
189
|
-
where: queryWhere,
|
|
190
|
-
limit: PAGE_SIZE,
|
|
191
|
-
orderBy: DESC_ORDER,
|
|
192
|
-
...(after
|
|
193
|
-
? {
|
|
194
|
-
cursor: {
|
|
195
|
-
after,
|
|
196
|
-
},
|
|
197
|
-
}
|
|
198
|
-
: {}),
|
|
199
|
-
},
|
|
200
|
-
context,
|
|
201
|
-
);
|
|
202
|
-
|
|
203
|
-
for (const bundle of data) {
|
|
204
|
-
if (
|
|
205
|
-
!bundleMatchesQueryWhere(bundle, queryWhere) ||
|
|
206
|
-
!isCandidate(bundle)
|
|
207
|
-
) {
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (args.bundleId === NIL_UUID) {
|
|
212
|
-
if (isEligibleForUpdate(bundle, args.cohort)) {
|
|
213
|
-
return makeResponse(bundle, "UPDATE");
|
|
214
|
-
}
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const compareResult = bundle.id.localeCompare(args.bundleId);
|
|
219
|
-
|
|
220
|
-
if (compareResult > 0) {
|
|
221
|
-
if (isEligibleForUpdate(bundle, args.cohort)) {
|
|
222
|
-
return makeResponse(bundle, "UPDATE");
|
|
223
|
-
}
|
|
224
|
-
continue;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (compareResult === 0) {
|
|
228
|
-
if (isEligibleForUpdate(bundle, args.cohort)) {
|
|
229
|
-
return null;
|
|
230
|
-
}
|
|
231
|
-
continue;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
return makeResponse(bundle, "ROLLBACK");
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
if (!pagination.hasNextPage) {
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
after = data.at(-1)?.id;
|
|
242
|
-
if (!after) {
|
|
243
|
-
break;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (args.bundleId === NIL_UUID) {
|
|
248
|
-
return null;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
if (
|
|
252
|
-
args.minBundleId &&
|
|
253
|
-
args.bundleId.localeCompare(args.minBundleId) <= 0
|
|
254
|
-
) {
|
|
255
|
-
return null;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
return INIT_BUNDLE_ROLLBACK_UPDATE_INFO;
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
const getBaseWhere = ({
|
|
262
|
-
platform,
|
|
263
|
-
channel,
|
|
264
|
-
minBundleId,
|
|
265
|
-
}: {
|
|
266
|
-
platform: Platform;
|
|
267
|
-
channel: string;
|
|
268
|
-
minBundleId: string;
|
|
269
|
-
}): DatabaseBundleQueryWhere => ({
|
|
270
|
-
platform,
|
|
271
|
-
channel,
|
|
272
|
-
enabled: true,
|
|
273
|
-
id: {
|
|
274
|
-
gte: minBundleId,
|
|
275
|
-
},
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
const api: DatabaseAPI<TContext> = {
|
|
279
|
-
async getBundleById(
|
|
280
|
-
id: string,
|
|
281
|
-
context?: HotUpdaterContext<TContext>,
|
|
282
|
-
): Promise<Bundle | null> {
|
|
283
|
-
await coreOptions?.beforeOperation?.();
|
|
284
|
-
return getPlugin().getBundleById(id, context);
|
|
285
|
-
},
|
|
286
|
-
|
|
287
|
-
async getUpdateInfo(
|
|
288
|
-
args: GetBundlesArgs,
|
|
289
|
-
context?: HotUpdaterContext<TContext>,
|
|
290
|
-
): Promise<UpdateInfo | null> {
|
|
291
|
-
await coreOptions?.beforeOperation?.();
|
|
292
|
-
const plugin = getPlugin();
|
|
293
|
-
const directGetUpdateInfo = plugin.getUpdateInfo;
|
|
294
|
-
if (directGetUpdateInfo) {
|
|
295
|
-
return context === undefined
|
|
296
|
-
? await directGetUpdateInfo(args)
|
|
297
|
-
: await directGetUpdateInfo(args, context);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
const channel = args.channel ?? "production";
|
|
301
|
-
const minBundleId = args.minBundleId ?? NIL_UUID;
|
|
302
|
-
const baseWhere = getBaseWhere({
|
|
303
|
-
platform: args.platform,
|
|
304
|
-
channel,
|
|
305
|
-
minBundleId,
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
if (args._updateStrategy === "fingerprint") {
|
|
309
|
-
return findUpdateInfoByScanning({
|
|
310
|
-
args,
|
|
311
|
-
queryWhere: {
|
|
312
|
-
...baseWhere,
|
|
313
|
-
fingerprintHash: args.fingerprintHash,
|
|
314
|
-
},
|
|
315
|
-
context,
|
|
316
|
-
isCandidate: (bundle) => {
|
|
317
|
-
return (
|
|
318
|
-
bundle.enabled &&
|
|
319
|
-
bundle.platform === args.platform &&
|
|
320
|
-
bundle.channel === channel &&
|
|
321
|
-
bundle.id.localeCompare(minBundleId) >= 0 &&
|
|
322
|
-
bundle.fingerprintHash === args.fingerprintHash
|
|
323
|
-
);
|
|
324
|
-
},
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
return findUpdateInfoByScanning({
|
|
329
|
-
args,
|
|
330
|
-
queryWhere: {
|
|
331
|
-
...baseWhere,
|
|
332
|
-
},
|
|
333
|
-
context,
|
|
334
|
-
isCandidate: (bundle) => {
|
|
335
|
-
return (
|
|
336
|
-
bundle.enabled &&
|
|
337
|
-
bundle.platform === args.platform &&
|
|
338
|
-
bundle.channel === channel &&
|
|
339
|
-
bundle.id.localeCompare(minBundleId) >= 0 &&
|
|
340
|
-
!!bundle.targetAppVersion &&
|
|
341
|
-
semverSatisfies(bundle.targetAppVersion, args.appVersion)
|
|
342
|
-
);
|
|
343
|
-
},
|
|
344
|
-
});
|
|
345
|
-
},
|
|
346
|
-
|
|
347
|
-
async getAppUpdateInfo(
|
|
348
|
-
args: GetBundlesArgs,
|
|
349
|
-
context?: HotUpdaterContext<TContext>,
|
|
350
|
-
): Promise<AppUpdateAvailableInfo | null> {
|
|
351
|
-
const info = await this.getUpdateInfo(args, context);
|
|
352
|
-
if (!info) {
|
|
353
|
-
return null;
|
|
354
|
-
}
|
|
355
|
-
const { storageUri, ...rest } = info;
|
|
356
|
-
|
|
357
|
-
const readStorageText = coreOptions?.readStorageText;
|
|
358
|
-
if (info.id === NIL_UUID || !readStorageText) {
|
|
359
|
-
const fileUrl = await resolveFileUrl(storageUri ?? null, context);
|
|
360
|
-
const baseResponse: AppUpdateAvailableInfo = { ...rest, fileUrl };
|
|
361
|
-
return baseResponse;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
const requestBundles = createRequestUpdateBundleResolver(context);
|
|
365
|
-
const getCurrentBundle = () => {
|
|
366
|
-
if (args.bundleId === NIL_UUID) {
|
|
367
|
-
return null;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
const seededCurrentBundle = requestBundles.peek(args.bundleId);
|
|
371
|
-
if (seededCurrentBundle || requestBundles.hasSeededBundles()) {
|
|
372
|
-
return seededCurrentBundle;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
return requestBundles.getById(args.bundleId, () =>
|
|
376
|
-
getPlugin().getBundleById(args.bundleId, context),
|
|
377
|
-
);
|
|
378
|
-
};
|
|
379
|
-
const [fileUrl, targetBundle, currentBundle] = await Promise.all([
|
|
380
|
-
resolveFileUrl(storageUri ?? null, context),
|
|
381
|
-
requestBundles.getById(info.id, () =>
|
|
382
|
-
getPlugin().getBundleById(info.id, context),
|
|
383
|
-
),
|
|
384
|
-
getCurrentBundle(),
|
|
385
|
-
]);
|
|
386
|
-
const baseResponse: AppUpdateAvailableInfo = { ...rest, fileUrl };
|
|
387
|
-
const manifestArtifacts = await resolveManifestArtifacts({
|
|
388
|
-
currentBundle,
|
|
389
|
-
resolveFileUrl,
|
|
390
|
-
readStorageText,
|
|
391
|
-
targetBundle,
|
|
392
|
-
context,
|
|
393
|
-
});
|
|
394
|
-
if (!manifestArtifacts) {
|
|
395
|
-
return baseResponse;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
return {
|
|
399
|
-
...baseResponse,
|
|
400
|
-
...manifestArtifacts,
|
|
401
|
-
};
|
|
402
|
-
},
|
|
403
|
-
|
|
404
|
-
async getChannels(
|
|
405
|
-
context?: HotUpdaterContext<TContext>,
|
|
406
|
-
): Promise<string[]> {
|
|
407
|
-
await coreOptions?.beforeOperation?.();
|
|
408
|
-
return getPlugin().getChannels(context);
|
|
409
|
-
},
|
|
410
|
-
|
|
411
|
-
async getBundles(options, context?: HotUpdaterContext<TContext>) {
|
|
412
|
-
await coreOptions?.beforeOperation?.();
|
|
413
|
-
return getPlugin().getBundles(options, context);
|
|
414
|
-
},
|
|
415
|
-
|
|
416
|
-
async insertBundle(
|
|
417
|
-
bundle: Bundle,
|
|
418
|
-
context?: HotUpdaterContext<TContext>,
|
|
419
|
-
): Promise<void> {
|
|
420
|
-
await coreOptions?.beforeOperation?.();
|
|
421
|
-
assertBundlePersistenceConstraints(bundle);
|
|
422
|
-
await runWithMutationPlugin(async (plugin) => {
|
|
423
|
-
await plugin.appendBundle(bundle, context);
|
|
424
|
-
await plugin.commitBundle(context);
|
|
425
|
-
});
|
|
426
|
-
},
|
|
427
|
-
|
|
428
|
-
async updateBundleById(
|
|
429
|
-
bundleId: string,
|
|
430
|
-
newBundle: Partial<Bundle>,
|
|
431
|
-
context?: HotUpdaterContext<TContext>,
|
|
432
|
-
): Promise<void> {
|
|
433
|
-
await coreOptions?.beforeOperation?.();
|
|
434
|
-
await runWithMutationPlugin(async (plugin) => {
|
|
435
|
-
const current = await plugin.getBundleById(bundleId, context);
|
|
436
|
-
if (!current) {
|
|
437
|
-
throw new Error("targetBundleId not found");
|
|
438
|
-
}
|
|
439
|
-
assertBundlePersistenceConstraints({ ...current, ...newBundle });
|
|
440
|
-
await plugin.updateBundle(bundleId, newBundle, context);
|
|
441
|
-
await plugin.commitBundle(context);
|
|
442
|
-
});
|
|
443
|
-
},
|
|
444
|
-
|
|
445
|
-
async deleteBundleById(
|
|
446
|
-
bundleId: string,
|
|
447
|
-
context?: HotUpdaterContext<TContext>,
|
|
448
|
-
): Promise<void> {
|
|
449
|
-
await coreOptions?.beforeOperation?.();
|
|
450
|
-
await runWithMutationPlugin(async (plugin) => {
|
|
451
|
-
const bundle = await plugin.getBundleById(bundleId, context);
|
|
452
|
-
if (!bundle) {
|
|
453
|
-
return;
|
|
454
|
-
}
|
|
455
|
-
await plugin.deleteBundle(bundle, context);
|
|
456
|
-
await plugin.commitBundle(context);
|
|
457
|
-
});
|
|
458
|
-
},
|
|
459
|
-
};
|
|
460
|
-
|
|
461
|
-
return {
|
|
462
|
-
api,
|
|
463
|
-
adapterName: getPlugin().name,
|
|
464
|
-
createMigrator: () => {
|
|
465
|
-
throw new Error(
|
|
466
|
-
"createMigrator is only available for Kysely/MongoDB database adapters.",
|
|
467
|
-
);
|
|
468
|
-
},
|
|
469
|
-
generateSchema: () => {
|
|
470
|
-
throw new Error(
|
|
471
|
-
"generateSchema is only available for Drizzle/Prisma database adapters.",
|
|
472
|
-
);
|
|
473
|
-
},
|
|
474
|
-
};
|
|
475
|
-
}
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
import { bench, describe } from "vitest";
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
DatabaseBundleQueryOptions,
|
|
5
|
-
DatabaseBundleQueryWhere,
|
|
6
|
-
DatabasePlugin,
|
|
7
|
-
} from "../../../../plugins/plugin-core/src";
|
|
8
|
-
import {
|
|
9
|
-
paginateBundles,
|
|
10
|
-
semverSatisfies,
|
|
11
|
-
} from "../../../../plugins/plugin-core/src";
|
|
12
|
-
import type {
|
|
13
|
-
AppVersionGetBundlesArgs,
|
|
14
|
-
Bundle,
|
|
15
|
-
Platform,
|
|
16
|
-
UpdateInfo,
|
|
17
|
-
} from "../../../core/src";
|
|
18
|
-
import {
|
|
19
|
-
DEFAULT_ROLLOUT_COHORT_COUNT,
|
|
20
|
-
isCohortEligibleForUpdate,
|
|
21
|
-
NIL_UUID,
|
|
22
|
-
} from "../../../core/src";
|
|
23
|
-
import { createPluginDatabaseCore } from "./pluginCore";
|
|
24
|
-
|
|
25
|
-
const BUNDLE_COUNT = 20_000;
|
|
26
|
-
const BENCH_APP_VERSION = "1.0.0";
|
|
27
|
-
const BENCH_PLATFORM = "ios" as const;
|
|
28
|
-
const BENCH_CHANNEL = "production";
|
|
29
|
-
|
|
30
|
-
const cloneBundle = (bundle: Bundle): Bundle => ({
|
|
31
|
-
...bundle,
|
|
32
|
-
metadata: bundle.metadata
|
|
33
|
-
? structuredClone(bundle.metadata)
|
|
34
|
-
: bundle.metadata,
|
|
35
|
-
targetCohorts: bundle.targetCohorts ? [...bundle.targetCohorts] : null,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const bundleMatchesWhere = (
|
|
39
|
-
bundle: Bundle,
|
|
40
|
-
where: DatabaseBundleQueryWhere | undefined,
|
|
41
|
-
) => {
|
|
42
|
-
if (!where) return true;
|
|
43
|
-
if (where.channel !== undefined && bundle.channel !== where.channel)
|
|
44
|
-
return false;
|
|
45
|
-
if (where.platform !== undefined && bundle.platform !== where.platform)
|
|
46
|
-
return false;
|
|
47
|
-
if (where.enabled !== undefined && bundle.enabled !== where.enabled)
|
|
48
|
-
return false;
|
|
49
|
-
if (where.id?.eq !== undefined && bundle.id !== where.id.eq) return false;
|
|
50
|
-
if (where.id?.gt !== undefined && bundle.id.localeCompare(where.id.gt) <= 0)
|
|
51
|
-
return false;
|
|
52
|
-
if (where.id?.gte !== undefined && bundle.id.localeCompare(where.id.gte) < 0)
|
|
53
|
-
return false;
|
|
54
|
-
if (where.id?.lt !== undefined && bundle.id.localeCompare(where.id.lt) >= 0)
|
|
55
|
-
return false;
|
|
56
|
-
if (where.id?.lte !== undefined && bundle.id.localeCompare(where.id.lte) > 0)
|
|
57
|
-
return false;
|
|
58
|
-
if (where.id?.in && !where.id.in.includes(bundle.id)) return false;
|
|
59
|
-
if (where.targetAppVersionNotNull && bundle.targetAppVersion === null) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
if (
|
|
63
|
-
where.targetAppVersion !== undefined &&
|
|
64
|
-
bundle.targetAppVersion !== where.targetAppVersion
|
|
65
|
-
) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
if (
|
|
69
|
-
where.targetAppVersionIn &&
|
|
70
|
-
!where.targetAppVersionIn.includes(bundle.targetAppVersion ?? "")
|
|
71
|
-
) {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
if (
|
|
75
|
-
where.fingerprintHash !== undefined &&
|
|
76
|
-
bundle.fingerprintHash !== where.fingerprintHash
|
|
77
|
-
) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
return true;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const createBundle = (
|
|
84
|
-
index: number,
|
|
85
|
-
{
|
|
86
|
-
platform = BENCH_PLATFORM,
|
|
87
|
-
channel = BENCH_CHANNEL,
|
|
88
|
-
targetAppVersion = "*",
|
|
89
|
-
enabled = true,
|
|
90
|
-
}: {
|
|
91
|
-
platform?: Platform;
|
|
92
|
-
channel?: string;
|
|
93
|
-
targetAppVersion?: string | null;
|
|
94
|
-
enabled?: boolean;
|
|
95
|
-
} = {},
|
|
96
|
-
): Bundle => ({
|
|
97
|
-
id: `00000000-0000-0000-0000-${String(index).padStart(12, "0")}`,
|
|
98
|
-
platform,
|
|
99
|
-
shouldForceUpdate: false,
|
|
100
|
-
enabled,
|
|
101
|
-
fileHash: `hash-${index}`,
|
|
102
|
-
gitCommitHash: `commit-${index}`,
|
|
103
|
-
message: `bundle-${index}`,
|
|
104
|
-
channel,
|
|
105
|
-
storageUri: `s3://bench/bundles/${index}.zip`,
|
|
106
|
-
targetAppVersion,
|
|
107
|
-
fingerprintHash: `fingerprint-${index % 10}`,
|
|
108
|
-
metadata: { app_version: String(index) },
|
|
109
|
-
rolloutCohortCount: DEFAULT_ROLLOUT_COHORT_COUNT,
|
|
110
|
-
targetCohorts: null,
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
const createBenchPlugin = (bundles: Bundle[]): DatabasePlugin => {
|
|
114
|
-
const bundlesById = new Map(bundles.map((bundle) => [bundle.id, bundle]));
|
|
115
|
-
|
|
116
|
-
const sortByDirection = (direction: "asc" | "desc" | undefined): Bundle[] => {
|
|
117
|
-
const sorted = bundles.slice().sort((a, b) => a.id.localeCompare(b.id));
|
|
118
|
-
return direction === "asc" ? sorted : sorted.reverse();
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
return {
|
|
122
|
-
name: "bench-plugin",
|
|
123
|
-
async getBundleById(bundleId) {
|
|
124
|
-
return bundlesById.get(bundleId) ?? null;
|
|
125
|
-
},
|
|
126
|
-
async getBundles(options: DatabaseBundleQueryOptions) {
|
|
127
|
-
const { where, limit, cursor, orderBy } = options;
|
|
128
|
-
const source = sortByDirection(orderBy?.direction);
|
|
129
|
-
const matched = source.filter((bundle) =>
|
|
130
|
-
bundleMatchesWhere(bundle, where),
|
|
131
|
-
);
|
|
132
|
-
const paginated = paginateBundles({
|
|
133
|
-
bundles: matched.map(cloneBundle),
|
|
134
|
-
limit,
|
|
135
|
-
cursor,
|
|
136
|
-
orderBy,
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
return paginated;
|
|
140
|
-
},
|
|
141
|
-
async getChannels() {
|
|
142
|
-
return [...new Set(bundles.map((bundle) => bundle.channel))];
|
|
143
|
-
},
|
|
144
|
-
async updateBundle() {
|
|
145
|
-
throw new Error("Not implemented for benchmark");
|
|
146
|
-
},
|
|
147
|
-
async appendBundle() {
|
|
148
|
-
throw new Error("Not implemented for benchmark");
|
|
149
|
-
},
|
|
150
|
-
async commitBundle() {},
|
|
151
|
-
async deleteBundle() {
|
|
152
|
-
throw new Error("Not implemented for benchmark");
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const oldPluginCoreGetUpdateInfo = async (
|
|
158
|
-
plugin: DatabasePlugin,
|
|
159
|
-
args: AppVersionGetBundlesArgs,
|
|
160
|
-
): Promise<UpdateInfo | null> => {
|
|
161
|
-
const where: DatabaseBundleQueryWhere = {
|
|
162
|
-
channel: args.channel ?? BENCH_CHANNEL,
|
|
163
|
-
platform: args.platform,
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
const { pagination } = await plugin.getBundles({
|
|
167
|
-
where,
|
|
168
|
-
limit: 1,
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
if (pagination.total === 0) {
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const { data } = await plugin.getBundles({
|
|
176
|
-
where,
|
|
177
|
-
limit: pagination.total,
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
for (const bundle of data) {
|
|
181
|
-
if (!bundle.enabled) {
|
|
182
|
-
continue;
|
|
183
|
-
}
|
|
184
|
-
if (bundle.platform !== args.platform) {
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
if (bundle.channel !== (args.channel ?? BENCH_CHANNEL)) {
|
|
188
|
-
continue;
|
|
189
|
-
}
|
|
190
|
-
if (!bundle.targetAppVersion) {
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
if (!semverSatisfies(bundle.targetAppVersion, args.appVersion)) {
|
|
194
|
-
continue;
|
|
195
|
-
}
|
|
196
|
-
if (
|
|
197
|
-
!isCohortEligibleForUpdate(
|
|
198
|
-
bundle.id,
|
|
199
|
-
args.cohort,
|
|
200
|
-
bundle.rolloutCohortCount,
|
|
201
|
-
bundle.targetCohorts,
|
|
202
|
-
)
|
|
203
|
-
) {
|
|
204
|
-
continue;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return {
|
|
208
|
-
id: bundle.id,
|
|
209
|
-
message: bundle.message,
|
|
210
|
-
shouldForceUpdate: bundle.shouldForceUpdate,
|
|
211
|
-
status: "UPDATE",
|
|
212
|
-
storageUri: bundle.storageUri,
|
|
213
|
-
fileHash: bundle.fileHash,
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return null;
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
describe("plugin update check benchmark", () => {
|
|
221
|
-
const bundles = Array.from({ length: BUNDLE_COUNT }, (_, index) =>
|
|
222
|
-
createBundle(index + 1),
|
|
223
|
-
);
|
|
224
|
-
|
|
225
|
-
const args: AppVersionGetBundlesArgs = {
|
|
226
|
-
_updateStrategy: "appVersion",
|
|
227
|
-
appVersion: BENCH_APP_VERSION,
|
|
228
|
-
bundleId: NIL_UUID,
|
|
229
|
-
platform: BENCH_PLATFORM,
|
|
230
|
-
channel: BENCH_CHANNEL,
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
const plugin = createBenchPlugin(bundles);
|
|
234
|
-
const currentApi = createPluginDatabaseCore(
|
|
235
|
-
() => plugin,
|
|
236
|
-
async () => null,
|
|
237
|
-
).api;
|
|
238
|
-
|
|
239
|
-
bench(
|
|
240
|
-
"pluginCore legacy full fetch",
|
|
241
|
-
async () => {
|
|
242
|
-
await oldPluginCoreGetUpdateInfo(plugin, args);
|
|
243
|
-
},
|
|
244
|
-
{ warmupIterations: 5, iterations: 20 },
|
|
245
|
-
);
|
|
246
|
-
|
|
247
|
-
bench(
|
|
248
|
-
"pluginCore current paged fetch",
|
|
249
|
-
async () => {
|
|
250
|
-
await currentApi.getUpdateInfo(args);
|
|
251
|
-
},
|
|
252
|
-
{ warmupIterations: 5, iterations: 20 },
|
|
253
|
-
);
|
|
254
|
-
});
|