@hot-updater/server 1.0.0-rc.2 → 1.0.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +12 -14
- package/dist/adapters/drizzle.cjs +32 -75
- package/dist/adapters/drizzle.d.cts +13 -5
- package/dist/adapters/drizzle.d.mts +13 -5
- package/dist/adapters/drizzle.mjs +32 -77
- package/dist/adapters/drizzleExecutor.cjs +114 -0
- package/dist/adapters/drizzleExecutor.d.cts +9 -0
- package/dist/adapters/drizzleExecutor.d.mts +9 -0
- package/dist/adapters/drizzleExecutor.mjs +112 -0
- package/dist/adapters/kysely.cjs +22 -31
- package/dist/adapters/kysely.d.cts +10 -6
- package/dist/adapters/kysely.d.mts +10 -6
- package/dist/adapters/kysely.mjs +23 -33
- package/dist/adapters/kyselyExecutor.cjs +32 -0
- package/dist/adapters/kyselyExecutor.d.cts +11 -0
- package/dist/adapters/kyselyExecutor.d.mts +11 -0
- package/dist/adapters/kyselyExecutor.mjs +32 -0
- package/dist/adapters/mongodb.cjs +18 -54
- package/dist/adapters/mongodb.d.cts +10 -5
- package/dist/adapters/mongodb.d.mts +10 -5
- package/dist/adapters/mongodb.mjs +19 -56
- package/dist/adapters/mongodbAdapter.cjs +192 -0
- package/dist/adapters/mongodbAdapter.d.cts +9 -0
- package/dist/adapters/mongodbAdapter.d.mts +9 -0
- package/dist/adapters/mongodbAdapter.mjs +191 -0
- package/dist/adapters/prisma.cjs +35 -267
- package/dist/adapters/prisma.d.cts +12 -7
- package/dist/adapters/prisma.d.mts +12 -7
- package/dist/adapters/prisma.mjs +36 -268
- package/dist/adapters/prismaExecutor.cjs +63 -0
- package/dist/adapters/prismaExecutor.mjs +63 -0
- package/dist/adapters/sqlProviders.cjs +14 -0
- package/dist/adapters/sqlProviders.mjs +14 -0
- package/dist/assembly/assemblePlugins.cjs +144 -0
- package/dist/assembly/assemblePlugins.d.cts +5 -0
- package/dist/assembly/assemblePlugins.d.mts +5 -0
- package/dist/assembly/assemblePlugins.mjs +139 -0
- package/dist/assembly/clientPlugins.cjs +88 -0
- package/dist/assembly/clientPlugins.mjs +88 -0
- package/dist/assembly/configError.d.cts +2 -0
- package/dist/assembly/configError.d.mts +2 -0
- package/dist/assembly/configError.mjs +2 -0
- package/dist/core/api.cjs +51 -0
- package/dist/core/api.d.cts +54 -0
- package/dist/core/api.d.mts +54 -0
- package/dist/core/api.mjs +51 -0
- package/dist/core/baseCandidates.cjs +28 -0
- package/dist/core/baseCandidates.mjs +28 -0
- package/dist/core/operations.cjs +351 -0
- package/dist/core/operations.mjs +351 -0
- package/dist/core/reads.cjs +273 -0
- package/dist/core/reads.d.cts +9 -0
- package/dist/core/reads.d.mts +9 -0
- package/dist/core/reads.mjs +267 -0
- package/dist/core/releases.cjs +193 -0
- package/dist/core/releases.mjs +190 -0
- package/dist/core/writes.cjs +96 -0
- package/dist/core/writes.mjs +91 -0
- package/dist/createHotUpdaterCore.cjs +72 -91
- package/dist/createHotUpdaterCore.d.cts +106 -38
- package/dist/createHotUpdaterCore.d.mts +106 -38
- package/dist/createHotUpdaterCore.mjs +74 -89
- package/dist/db/engineDrizzleSchema.cjs +53 -0
- package/dist/db/engineDrizzleSchema.mjs +53 -0
- package/dist/db/enginePrismaSchema.cjs +84 -0
- package/dist/db/enginePrismaSchema.d.cts +5 -0
- package/dist/db/enginePrismaSchema.d.mts +5 -0
- package/dist/db/enginePrismaSchema.mjs +83 -0
- package/dist/db/releaseCatalog.cjs +24 -47
- package/dist/db/releaseCatalog.mjs +20 -44
- package/dist/db/updateArtifacts.cjs +43 -72
- package/dist/db/updateArtifacts.mjs +40 -69
- package/dist/handler.cjs +59 -43
- package/dist/handler.d.cts +3 -5
- package/dist/handler.d.mts +3 -5
- package/dist/handler.mjs +61 -43
- package/dist/handlerAdminRoutes.cjs +374 -0
- package/dist/handlerAdminRoutes.mjs +372 -0
- package/dist/handlerParameters.cjs +6 -11
- package/dist/handlerParameters.mjs +6 -10
- package/dist/handlerReleaseCatalogRoutes.cjs +32 -15
- package/dist/handlerReleaseCatalogRoutes.mjs +32 -15
- package/dist/handlerTypes.d.cts +2 -55
- package/dist/handlerTypes.d.mts +2 -55
- package/dist/handlerVersionRoutes.cjs +20 -4
- package/dist/handlerVersionRoutes.mjs +20 -4
- package/dist/index.cjs +9 -9
- package/dist/index.d.cts +8 -9
- package/dist/index.d.mts +8 -9
- package/dist/index.mjs +3 -4
- package/dist/node.cjs +3 -6
- package/dist/node.d.cts +2 -2
- package/dist/node.d.mts +2 -2
- package/dist/node.mjs +4 -4
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugins/api-keys/index.cjs +9 -0
- package/dist/plugins/api-keys/index.d.cts +1 -0
- package/dist/plugins/api-keys/index.d.mts +1 -0
- package/dist/plugins/api-keys/index.mjs +2 -0
- package/dist/plugins/definePlugin.d.cts +2 -0
- package/dist/plugins/definePlugin.d.mts +2 -0
- package/dist/plugins/insights/index.cjs +9 -0
- package/dist/plugins/insights/index.d.cts +1 -0
- package/dist/plugins/insights/index.d.mts +1 -0
- package/dist/plugins/insights/index.mjs +2 -0
- package/dist/plugins/official.cjs +30 -0
- package/dist/plugins/official.mjs +29 -0
- package/dist/storageAccess.cjs +13 -10
- package/dist/storageAccess.mjs +13 -10
- package/dist/types/index.d.cts +2 -28
- package/dist/types/index.d.mts +2 -28
- package/package.json +26 -14
- package/dist/_virtual/_rolldown/runtime.cjs +0 -23
- package/dist/adapters/databaseConstraintErrors.cjs +0 -22
- package/dist/adapters/databaseConstraintErrors.mjs +0 -21
- package/dist/adapters/databasePluginUtils.cjs +0 -116
- package/dist/adapters/databasePluginUtils.mjs +0 -106
- package/dist/adapters/drizzleCrud.cjs +0 -311
- package/dist/adapters/drizzleCrud.mjs +0 -308
- package/dist/adapters/drizzleLazyDB.cjs +0 -106
- package/dist/adapters/drizzleLazyDB.mjs +0 -106
- package/dist/adapters/drizzleQuery.cjs +0 -69
- package/dist/adapters/drizzleQuery.mjs +0 -69
- package/dist/adapters/insightsTransaction.cjs +0 -22
- package/dist/adapters/insightsTransaction.mjs +0 -22
- package/dist/adapters/kyselyCrud.cjs +0 -305
- package/dist/adapters/kyselyCrud.mjs +0 -304
- package/dist/adapters/kyselyQuery.cjs +0 -56
- package/dist/adapters/kyselyQuery.mjs +0 -56
- package/dist/adapters/mongodbCollections.cjs +0 -38
- package/dist/adapters/mongodbCollections.mjs +0 -32
- package/dist/adapters/mongodbQuery.cjs +0 -94
- package/dist/adapters/mongodbQuery.mjs +0 -86
- package/dist/adapters/mongodbReads.cjs +0 -210
- package/dist/adapters/mongodbReads.mjs +0 -210
- package/dist/adapters/mongodbWrites.cjs +0 -148
- package/dist/adapters/mongodbWrites.mjs +0 -148
- package/dist/adapters/prismaQuery.cjs +0 -57
- package/dist/adapters/prismaQuery.mjs +0 -56
- package/dist/adapters/prismaRows.cjs +0 -219
- package/dist/adapters/prismaRows.mjs +0 -209
- package/dist/apiKeys.cjs +0 -143
- package/dist/apiKeys.d.cts +0 -49
- package/dist/apiKeys.d.mts +0 -49
- package/dist/apiKeys.mjs +0 -133
- package/dist/db/createBundleDiff.cjs +0 -144
- package/dist/db/createBundleDiff.d.cts +0 -16
- package/dist/db/createBundleDiff.d.mts +0 -16
- package/dist/db/createBundleDiff.mjs +0 -141
- package/dist/db/databasePluginCore.cjs +0 -137
- package/dist/db/databasePluginCore.mjs +0 -137
- package/dist/db/fixedMigrator.cjs +0 -79
- package/dist/db/fixedMigrator.mjs +0 -78
- package/dist/db/fixedMigratorMongo.cjs +0 -321
- package/dist/db/fixedMigratorMongo.mjs +0 -321
- package/dist/db/fixedMigratorShared.cjs +0 -23
- package/dist/db/fixedMigratorShared.mjs +0 -18
- package/dist/db/index.cjs +0 -27
- package/dist/db/index.d.cts +0 -12
- package/dist/db/index.d.mts +0 -12
- package/dist/db/index.mjs +0 -22
- package/dist/db/mongoMigrationExecution.cjs +0 -11
- package/dist/db/mongoMigrationExecution.mjs +0 -11
- package/dist/db/releaseCatalog.d.cts +0 -16
- package/dist/db/releaseCatalog.d.mts +0 -16
- package/dist/db/schema/insightsCollation.cjs +0 -14
- package/dist/db/schema/insightsCollation.mjs +0 -14
- package/dist/db/schema/mongodb.cjs +0 -25
- package/dist/db/schema/mongodb.mjs +0 -25
- package/dist/db/schema/registry.cjs +0 -21
- package/dist/db/schema/registry.mjs +0 -17
- package/dist/db/schema/sql.cjs +0 -105
- package/dist/db/schema/sql.mjs +0 -97
- package/dist/db/schema/sqlOperations.cjs +0 -27
- package/dist/db/schema/sqlOperations.mjs +0 -26
- package/dist/db/schemaGenerators.cjs +0 -275
- package/dist/db/schemaGenerators.mjs +0 -273
- package/dist/db/schemaReadiness.cjs +0 -26
- package/dist/db/schemaReadiness.d.cts +0 -9
- package/dist/db/schemaReadiness.d.mts +0 -9
- package/dist/db/schemaReadiness.mjs +0 -25
- package/dist/db/sqlMigrationExecution.cjs +0 -67
- package/dist/db/sqlMigrationExecution.mjs +0 -67
- package/dist/db/types.cjs +0 -22
- package/dist/db/types.d.cts +0 -118
- package/dist/db/types.d.mts +0 -118
- package/dist/db/types.mjs +0 -19
- package/dist/handlerBundleRoutes.cjs +0 -155
- package/dist/handlerBundleRoutes.mjs +0 -155
- package/dist/handlerReleaseManagementRoutes.cjs +0 -124
- package/dist/handlerReleaseManagementRoutes.mjs +0 -124
- package/dist/insights/domain.d.cts +0 -89
- package/dist/insights/domain.d.mts +0 -89
- package/dist/insights/errors.cjs +0 -15
- package/dist/insights/errors.mjs +0 -14
- package/dist/insights/eventInput.cjs +0 -155
- package/dist/insights/eventInput.mjs +0 -153
- package/dist/insights/provider.cjs +0 -314
- package/dist/insights/provider.d.cts +0 -6
- package/dist/insights/provider.d.mts +0 -6
- package/dist/insights/provider.mjs +0 -314
- package/dist/insights/queryInput.cjs +0 -93
- package/dist/insights/queryInput.mjs +0 -91
- package/dist/insights/routes.cjs +0 -58
- package/dist/insights/routes.mjs +0 -56
- package/dist/insights/types.d.cts +0 -32
- package/dist/insights/types.d.mts +0 -32
- package/dist/schema/dsl.cjs +0 -103
- package/dist/schema/dsl.mjs +0 -87
- package/dist/schema/index.cjs +0 -20
- package/dist/schema/index.mjs +0 -7
- package/dist/schema/settings.cjs +0 -9
- package/dist/schema/settings.mjs +0 -9
- package/dist/schema/types.cjs +0 -8
- package/dist/schema/types.mjs +0 -6
- package/dist/schema/v1_0_0.cjs +0 -406
- package/dist/schema/v1_0_0.mjs +0 -398
- package/src/adapters/databaseConstraintErrors.ts +0 -25
- package/src/adapters/databasePluginTestDatabase.ts +0 -120
- package/src/adapters/databasePluginUtils.spec.ts +0 -29
- package/src/adapters/databasePluginUtils.ts +0 -214
- package/src/adapters/drizzle.spec.ts +0 -336
- package/src/adapters/drizzle.ts +0 -162
- package/src/adapters/drizzleCrud.ts +0 -571
- package/src/adapters/drizzleLazyDB.ts +0 -271
- package/src/adapters/drizzleQuery.ts +0 -164
- package/src/adapters/insightsTransaction.ts +0 -32
- package/src/adapters/kysely.spec.ts +0 -174
- package/src/adapters/kysely.ts +0 -110
- package/src/adapters/kyselyCrud.ts +0 -709
- package/src/adapters/kyselyQuery.ts +0 -128
- package/src/adapters/mongodb.integration.spec.ts +0 -210
- package/src/adapters/mongodb.spec.ts +0 -209
- package/src/adapters/mongodb.ts +0 -138
- package/src/adapters/mongodbCollections.ts +0 -67
- package/src/adapters/mongodbQuery.ts +0 -255
- package/src/adapters/mongodbReads.ts +0 -380
- package/src/adapters/mongodbRows.spec.ts +0 -64
- package/src/adapters/mongodbRows.ts +0 -118
- package/src/adapters/mongodbTestClient.ts +0 -377
- package/src/adapters/mongodbTestFilter.ts +0 -169
- package/src/adapters/mongodbWrites.ts +0 -287
- package/src/adapters/prisma.spec.ts +0 -293
- package/src/adapters/prisma.ts +0 -565
- package/src/adapters/prismaQuery.ts +0 -129
- package/src/adapters/prismaRows.spec.ts +0 -98
- package/src/adapters/prismaRows.ts +0 -337
- package/src/adapters/prismaTestClient.ts +0 -413
- package/src/apiKeys.integration.spec.ts +0 -192
- package/src/apiKeys.spec.ts +0 -162
- package/src/apiKeys.ts +0 -220
- package/src/calculatePagination.ts +0 -34
- package/src/createHotUpdaterCore.ts +0 -246
- package/src/db/bundleRows.spec.ts +0 -164
- package/src/db/bundleRows.ts +0 -10
- package/src/db/createBundleDiff.spec.ts +0 -450
- package/src/db/createBundleDiff.ts +0 -364
- package/src/db/databasePluginCore.spec.ts +0 -62
- package/src/db/databasePluginCore.testFixtures.ts +0 -76
- package/src/db/databasePluginCore.ts +0 -185
- package/src/db/databasePluginUpdateCheck.bench.ts +0 -110
- package/src/db/fixedMigrator.spec.ts +0 -296
- package/src/db/fixedMigrator.ts +0 -147
- package/src/db/fixedMigratorMongo.spec.ts +0 -239
- package/src/db/fixedMigratorMongo.ts +0 -425
- package/src/db/fixedMigratorShared.ts +0 -36
- package/src/db/hotUpdaterSchema.ts +0 -5
- package/src/db/index.spec.ts +0 -1269
- package/src/db/index.ts +0 -47
- package/src/db/mongoMigrationExecution.ts +0 -23
- package/src/db/node-sqlite.d.ts +0 -25
- package/src/db/releaseCatalog.ts +0 -148
- package/src/db/schema/definitions.ts +0 -1
- package/src/db/schema/insightsCollation.ts +0 -21
- package/src/db/schema/mongodb.ts +0 -40
- package/src/db/schema/registry.ts +0 -55
- package/src/db/schema/sql.ts +0 -244
- package/src/db/schema/sqlOperations.ts +0 -63
- package/src/db/schema/types.ts +0 -1
- package/src/db/schemaGenerators.ts +0 -494
- package/src/db/schemaReadiness.ts +0 -34
- package/src/db/sqlMigrationExecution.spec.ts +0 -65
- package/src/db/sqlMigrationExecution.ts +0 -108
- package/src/db/types.spec.ts +0 -63
- package/src/db/types.ts +0 -228
- package/src/db/updateArtifacts.spec.ts +0 -359
- package/src/db/updateArtifacts.ts +0 -541
- package/src/handler-standalone.integration.spec.ts +0 -528
- package/src/handler.spec.ts +0 -190
- package/src/handler.testFixtures.ts +0 -30
- package/src/handler.ts +0 -245
- package/src/handlerAuth.integration.spec.ts +0 -33
- package/src/handlerBundleRoutes.ts +0 -259
- package/src/handlerErrors.ts +0 -7
- package/src/handlerManagement.spec.ts +0 -262
- package/src/handlerParameters.ts +0 -105
- package/src/handlerReleaseCatalogRoutes.ts +0 -154
- package/src/handlerReleaseManagementRoutes.ts +0 -213
- package/src/handlerTypes.ts +0 -96
- package/src/handlerVersionRoutes.ts +0 -12
- package/src/index.ts +0 -30
- package/src/insights/domain.ts +0 -103
- package/src/insights/errors.ts +0 -11
- package/src/insights/eventInput.ts +0 -225
- package/src/insights/insights.integration.spec.ts +0 -381
- package/src/insights/provider.spec.ts +0 -385
- package/src/insights/provider.ts +0 -591
- package/src/insights/queryInput.ts +0 -141
- package/src/insights/routes.ts +0 -104
- package/src/insights/types.ts +0 -55
- package/src/internalRouter.ts +0 -104
- package/src/node.spec.ts +0 -119
- package/src/node.ts +0 -111
- package/src/releaseCatalogRoutes.integration.spec.ts +0 -238
- package/src/runtime.spec.ts +0 -194
- package/src/runtime.testFixtures.ts +0 -71
- package/src/schema/dsl-all-versions.spec.ts +0 -37
- package/src/schema/dsl.ts +0 -187
- package/src/schema/index.ts +0 -10
- package/src/schema/settings.ts +0 -15
- package/src/schema/types.ts +0 -79
- package/src/schema/v1_0_0.spec.ts +0 -220
- package/src/schema/v1_0_0.ts +0 -529
- package/src/storageAccess.spec.ts +0 -152
- package/src/storageAccess.ts +0 -141
- package/src/types/index.ts +0 -34
- package/src/version.ts +0 -3
package/src/db/types.spec.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { createInMemoryDatabasePlugin } from "../../../test-utils/test/inMemoryDatabasePlugin";
|
|
4
|
-
import { isDatabasePlugin } from "./types";
|
|
5
|
-
|
|
6
|
-
describe("isDatabasePlugin", () => {
|
|
7
|
-
it("accepts a direct fixed-model plugin object", () => {
|
|
8
|
-
const plugin = createInMemoryDatabasePlugin();
|
|
9
|
-
|
|
10
|
-
const result = isDatabasePlugin(plugin);
|
|
11
|
-
|
|
12
|
-
expect(result).toBe(true);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it("rejects a v1 factory and malformed required domains", () => {
|
|
16
|
-
const plugin = createInMemoryDatabasePlugin();
|
|
17
|
-
const factory = () => plugin;
|
|
18
|
-
const malformedBundles = {
|
|
19
|
-
...plugin,
|
|
20
|
-
models: {
|
|
21
|
-
...plugin.models,
|
|
22
|
-
bundles: { ...plugin.models.bundles, findMany: null },
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
const missingInsights = {
|
|
26
|
-
...plugin,
|
|
27
|
-
models: { ...plugin.models, insights: undefined },
|
|
28
|
-
};
|
|
29
|
-
const malformedInsights = {
|
|
30
|
-
...plugin,
|
|
31
|
-
models: {
|
|
32
|
-
...plugin.models,
|
|
33
|
-
insights: { ...plugin.models.insights, listEvents: null },
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
const malformedChannels = {
|
|
37
|
-
...plugin,
|
|
38
|
-
models: {
|
|
39
|
-
...plugin.models,
|
|
40
|
-
channels: { ...plugin.models.channels, delete: null },
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
const malformedApiKeys = {
|
|
44
|
-
...plugin,
|
|
45
|
-
models: {
|
|
46
|
-
...plugin.models,
|
|
47
|
-
apiKeys: {
|
|
48
|
-
...plugin.models.apiKeys,
|
|
49
|
-
revoke: null,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
const malformedDispose = { ...plugin, dispose: null };
|
|
54
|
-
|
|
55
|
-
expect(isDatabasePlugin(factory)).toBe(false);
|
|
56
|
-
expect(isDatabasePlugin(malformedBundles)).toBe(false);
|
|
57
|
-
expect(isDatabasePlugin(missingInsights)).toBe(false);
|
|
58
|
-
expect(isDatabasePlugin(malformedInsights)).toBe(false);
|
|
59
|
-
expect(isDatabasePlugin(malformedChannels)).toBe(false);
|
|
60
|
-
expect(isDatabasePlugin(malformedApiKeys)).toBe(false);
|
|
61
|
-
expect(isDatabasePlugin(malformedDispose)).toBe(false);
|
|
62
|
-
});
|
|
63
|
-
});
|
package/src/db/types.ts
DELETED
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
import type { ArtifactInfo, Bundle } from "@hot-updater/core";
|
|
2
|
-
import type {
|
|
3
|
-
ChannelDeleteInput,
|
|
4
|
-
ChannelDeleteResult,
|
|
5
|
-
ChannelInsertInput,
|
|
6
|
-
ChannelInsertResult,
|
|
7
|
-
ChannelRow,
|
|
8
|
-
DatabaseCommit,
|
|
9
|
-
DatabaseCommitResult,
|
|
10
|
-
DatabasePlugin as DatabasePluginContract,
|
|
11
|
-
ReleaseCatalogMutationPreflight,
|
|
12
|
-
ReleaseCatalogMutationResult,
|
|
13
|
-
ReleaseCatalogRebuildResult,
|
|
14
|
-
ReleaseCatalogRow,
|
|
15
|
-
ReleasePolicyPatch,
|
|
16
|
-
ReleaseRow,
|
|
17
|
-
} from "@hot-updater/plugin-core";
|
|
18
|
-
|
|
19
|
-
import type { PaginatedResult } from "../types";
|
|
20
|
-
|
|
21
|
-
export const sqlProviders = [
|
|
22
|
-
"sqlite",
|
|
23
|
-
"cockroachdb",
|
|
24
|
-
"mysql",
|
|
25
|
-
"postgresql",
|
|
26
|
-
"mssql",
|
|
27
|
-
] as const;
|
|
28
|
-
|
|
29
|
-
export const noSqlProviders = ["mongodb"] as const;
|
|
30
|
-
export const providers = [...sqlProviders, ...noSqlProviders] as const;
|
|
31
|
-
|
|
32
|
-
export type ORMProvider = (typeof providers)[number];
|
|
33
|
-
export type ORMSQLProvider = (typeof sqlProviders)[number];
|
|
34
|
-
export type RelationMode = "foreign-keys" | "fumadb";
|
|
35
|
-
|
|
36
|
-
export interface MigrateOptions {
|
|
37
|
-
mode?: "from-schema" | "from-database";
|
|
38
|
-
updateSettings?: boolean;
|
|
39
|
-
unsafe?: boolean;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export type MigrationOperation =
|
|
43
|
-
| {
|
|
44
|
-
type: "create-table";
|
|
45
|
-
value: {
|
|
46
|
-
ormName: string;
|
|
47
|
-
columns: Record<string, { ormName: string; type: string }>;
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
| { type: "custom"; description: string }
|
|
51
|
-
| { type: "custom"; sql: string }
|
|
52
|
-
| { type: "custom"; key: string; value: unknown };
|
|
53
|
-
|
|
54
|
-
export interface MigrationResult {
|
|
55
|
-
operations: MigrationOperation[];
|
|
56
|
-
execute: () => Promise<void>;
|
|
57
|
-
getSQL?: () => string;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface Migrator {
|
|
61
|
-
getVersion: () => Promise<string | undefined>;
|
|
62
|
-
getNameVariants: () => Promise<unknown>;
|
|
63
|
-
next: () => Promise<{ version: string } | undefined>;
|
|
64
|
-
previous: () => Promise<{ version: string } | undefined>;
|
|
65
|
-
up: (options?: MigrateOptions) => Promise<MigrationResult>;
|
|
66
|
-
down: (options?: MigrateOptions) => Promise<MigrationResult>;
|
|
67
|
-
migrateTo: (
|
|
68
|
-
version: string,
|
|
69
|
-
options?: MigrateOptions,
|
|
70
|
-
) => Promise<MigrationResult>;
|
|
71
|
-
migrateToLatest: (options?: MigrateOptions) => Promise<MigrationResult>;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export type SchemaGenerator = (
|
|
75
|
-
version: string | "latest",
|
|
76
|
-
name?: string,
|
|
77
|
-
) => {
|
|
78
|
-
code: string;
|
|
79
|
-
path: string;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export interface DatabaseAdapterCapabilities {
|
|
83
|
-
adapterName?: string;
|
|
84
|
-
provider?: ORMProvider;
|
|
85
|
-
createMigrator?: () => Migrator;
|
|
86
|
-
generateSchema?: SchemaGenerator;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export type DatabaseAdapterWithCapabilities = DatabasePluginContract &
|
|
90
|
-
DatabaseAdapterCapabilities;
|
|
91
|
-
|
|
92
|
-
export type DatabasePlugin = DatabaseAdapterWithCapabilities;
|
|
93
|
-
|
|
94
|
-
export function isDatabasePlugin(plugin: unknown): plugin is DatabasePlugin {
|
|
95
|
-
return (
|
|
96
|
-
typeof plugin === "object" &&
|
|
97
|
-
plugin !== null &&
|
|
98
|
-
"name" in plugin &&
|
|
99
|
-
typeof plugin.name === "string" &&
|
|
100
|
-
"models" in plugin &&
|
|
101
|
-
typeof plugin.models === "object" &&
|
|
102
|
-
plugin.models !== null &&
|
|
103
|
-
"bundles" in plugin.models &&
|
|
104
|
-
typeof plugin.models.bundles === "object" &&
|
|
105
|
-
plugin.models.bundles !== null &&
|
|
106
|
-
"findById" in plugin.models.bundles &&
|
|
107
|
-
typeof plugin.models.bundles.findById === "function" &&
|
|
108
|
-
"findMany" in plugin.models.bundles &&
|
|
109
|
-
typeof plugin.models.bundles.findMany === "function" &&
|
|
110
|
-
"count" in plugin.models.bundles &&
|
|
111
|
-
typeof plugin.models.bundles.count === "function" &&
|
|
112
|
-
"bundlePatches" in plugin.models &&
|
|
113
|
-
typeof plugin.models.bundlePatches === "object" &&
|
|
114
|
-
plugin.models.bundlePatches !== null &&
|
|
115
|
-
"findByBundleIds" in plugin.models.bundlePatches &&
|
|
116
|
-
typeof plugin.models.bundlePatches.findByBundleIds === "function" &&
|
|
117
|
-
"channels" in plugin.models &&
|
|
118
|
-
typeof plugin.models.channels === "object" &&
|
|
119
|
-
plugin.models.channels !== null &&
|
|
120
|
-
"insert" in plugin.models.channels &&
|
|
121
|
-
typeof plugin.models.channels.insert === "function" &&
|
|
122
|
-
"list" in plugin.models.channels &&
|
|
123
|
-
typeof plugin.models.channels.list === "function" &&
|
|
124
|
-
"delete" in plugin.models.channels &&
|
|
125
|
-
typeof plugin.models.channels.delete === "function" &&
|
|
126
|
-
"insights" in plugin.models &&
|
|
127
|
-
typeof plugin.models.insights === "object" &&
|
|
128
|
-
plugin.models.insights !== null &&
|
|
129
|
-
"record" in plugin.models.insights &&
|
|
130
|
-
typeof plugin.models.insights.record === "function" &&
|
|
131
|
-
"listEvents" in plugin.models.insights &&
|
|
132
|
-
typeof plugin.models.insights.listEvents === "function" &&
|
|
133
|
-
"findInstallations" in plugin.models.insights &&
|
|
134
|
-
typeof plugin.models.insights.findInstallations === "function" &&
|
|
135
|
-
"countEvents" in plugin.models.insights &&
|
|
136
|
-
typeof plugin.models.insights.countEvents === "function" &&
|
|
137
|
-
"countInstallations" in plugin.models.insights &&
|
|
138
|
-
typeof plugin.models.insights.countInstallations === "function" &&
|
|
139
|
-
"apiKeys" in plugin.models &&
|
|
140
|
-
typeof plugin.models.apiKeys === "object" &&
|
|
141
|
-
plugin.models.apiKeys !== null &&
|
|
142
|
-
"create" in plugin.models.apiKeys &&
|
|
143
|
-
typeof plugin.models.apiKeys.create === "function" &&
|
|
144
|
-
"findByHash" in plugin.models.apiKeys &&
|
|
145
|
-
typeof plugin.models.apiKeys.findByHash === "function" &&
|
|
146
|
-
"list" in plugin.models.apiKeys &&
|
|
147
|
-
typeof plugin.models.apiKeys.list === "function" &&
|
|
148
|
-
"revoke" in plugin.models.apiKeys &&
|
|
149
|
-
typeof plugin.models.apiKeys.revoke === "function" &&
|
|
150
|
-
"commit" in plugin &&
|
|
151
|
-
typeof plugin.commit === "function" &&
|
|
152
|
-
(!("dispose" in plugin) ||
|
|
153
|
-
plugin.dispose === undefined ||
|
|
154
|
-
typeof plugin.dispose === "function")
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export function getSQLProvider(
|
|
159
|
-
provider: ORMProvider | undefined,
|
|
160
|
-
): ORMSQLProvider | undefined {
|
|
161
|
-
if (!provider) {
|
|
162
|
-
return undefined;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return (sqlProviders as readonly string[]).includes(provider)
|
|
166
|
-
? (provider as ORMSQLProvider)
|
|
167
|
-
: undefined;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export interface DatabaseAPI {
|
|
171
|
-
getBundleById(id: string): Promise<Bundle | null>;
|
|
172
|
-
getReleaseCatalog(
|
|
173
|
-
input: import("./releaseCatalog").ReleaseCatalogRequest,
|
|
174
|
-
): Promise<import("@hot-updater/core").ReleaseCatalog | null>;
|
|
175
|
-
getArtifactInfo(
|
|
176
|
-
targetBundleId: string,
|
|
177
|
-
currentBundleId: string,
|
|
178
|
-
): Promise<ArtifactInfo | null>;
|
|
179
|
-
getReleaseById(id: string): Promise<ReleaseRow | null>;
|
|
180
|
-
getReleasesByScope(input: {
|
|
181
|
-
readonly scopeKey: string;
|
|
182
|
-
readonly afterReleaseId?: string;
|
|
183
|
-
readonly limit: number;
|
|
184
|
-
}): Promise<readonly ReleaseRow[]>;
|
|
185
|
-
getReleases(input: {
|
|
186
|
-
readonly afterReleaseId?: string;
|
|
187
|
-
readonly beforeReleaseId?: string;
|
|
188
|
-
readonly bundleId?: string;
|
|
189
|
-
readonly channelId?: string;
|
|
190
|
-
readonly enabled?: boolean;
|
|
191
|
-
readonly platform?: "ios" | "android";
|
|
192
|
-
readonly targetAppVersion?: string;
|
|
193
|
-
readonly limit: number;
|
|
194
|
-
}): Promise<readonly ReleaseRow[]>;
|
|
195
|
-
getReleaseCatalogByScopeKey(
|
|
196
|
-
scopeKey: string,
|
|
197
|
-
): Promise<ReleaseCatalogRow | null>;
|
|
198
|
-
getReleaseCatalogs(input: {
|
|
199
|
-
readonly afterScopeKey?: string;
|
|
200
|
-
readonly limit: number;
|
|
201
|
-
}): Promise<readonly ReleaseCatalogRow[]>;
|
|
202
|
-
updateReleasePolicy(input: {
|
|
203
|
-
readonly expectedRevision?: number;
|
|
204
|
-
readonly patch: ReleasePolicyPatch;
|
|
205
|
-
readonly releaseId: string;
|
|
206
|
-
}): Promise<ReleaseCatalogMutationResult>;
|
|
207
|
-
preflightReleasePolicy(input: {
|
|
208
|
-
readonly expectedRevision?: number;
|
|
209
|
-
readonly patch: ReleasePolicyPatch;
|
|
210
|
-
readonly releaseId: string;
|
|
211
|
-
}): Promise<ReleaseCatalogMutationPreflight>;
|
|
212
|
-
deleteRelease(input: {
|
|
213
|
-
readonly expectedRevision?: number;
|
|
214
|
-
readonly releaseId: string;
|
|
215
|
-
}): Promise<ReleaseCatalogMutationResult>;
|
|
216
|
-
rebuildReleaseCatalog(scopeKey: string): Promise<ReleaseCatalogRebuildResult>;
|
|
217
|
-
commitDatabase(input: DatabaseCommit): Promise<DatabaseCommitResult>;
|
|
218
|
-
getChannels(): Promise<readonly ChannelRow[]>;
|
|
219
|
-
insertChannel(input: ChannelInsertInput): Promise<ChannelInsertResult>;
|
|
220
|
-
deleteChannel(input: ChannelDeleteInput): Promise<ChannelDeleteResult>;
|
|
221
|
-
getBundles(
|
|
222
|
-
options: import("@hot-updater/plugin-core").DatabaseBundleQueryOptions,
|
|
223
|
-
): Promise<PaginatedResult>;
|
|
224
|
-
insertBundle(bundle: Bundle): Promise<void>;
|
|
225
|
-
insertBundles(bundles: readonly Bundle[]): Promise<void>;
|
|
226
|
-
updateBundleById(bundleId: string, newBundle: Partial<Bundle>): Promise<void>;
|
|
227
|
-
deleteBundleById(bundleId: string): Promise<void>;
|
|
228
|
-
}
|
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
import { NIL_UUID, type Bundle } from "@hot-updater/core";
|
|
2
|
-
import { createDatabaseClient } from "@hot-updater/plugin-core";
|
|
3
|
-
import { describe, expect, it, vi } from "vitest";
|
|
4
|
-
|
|
5
|
-
import { createInMemoryDatabasePlugin } from "../../../test-utils/test/inMemoryDatabasePlugin";
|
|
6
|
-
import { createArtifactResolver } from "./releaseCatalog";
|
|
7
|
-
import { resolveManifestArtifacts } from "./updateArtifacts";
|
|
8
|
-
|
|
9
|
-
type TestManifestAsset = {
|
|
10
|
-
downloadByteSize?: unknown;
|
|
11
|
-
downloadFileHash?: unknown;
|
|
12
|
-
fileHash: string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const CURRENT_BUNDLE_ID = "00000000-0000-0000-0000-000000000101";
|
|
16
|
-
const TARGET_BUNDLE_ID = "00000000-0000-0000-0000-000000000102";
|
|
17
|
-
const CURRENT_MANIFEST_URI = `s3://test-bucket/bundles/${CURRENT_BUNDLE_ID}/manifest.json`;
|
|
18
|
-
const TARGET_MANIFEST_URI = `s3://test-bucket/bundles/${TARGET_BUNDLE_ID}/manifest.json`;
|
|
19
|
-
const PATCH_STORAGE_URI = `s3://test-bucket/bundles/${TARGET_BUNDLE_ID}/patches/${CURRENT_BUNDLE_ID}/patch.bsdiff`;
|
|
20
|
-
const VALID_DOWNLOAD_FILE_HASH = "a".repeat(64);
|
|
21
|
-
|
|
22
|
-
const getUtf8ByteSize = (value: string) =>
|
|
23
|
-
new TextEncoder().encode(value).byteLength;
|
|
24
|
-
|
|
25
|
-
const createBundle = (
|
|
26
|
-
id: string,
|
|
27
|
-
archiveByteSize: number,
|
|
28
|
-
overrides: Partial<Bundle> = {},
|
|
29
|
-
): Bundle => ({
|
|
30
|
-
archiveByteSize,
|
|
31
|
-
assetBaseStorageUri: "s3://test-bucket/assets",
|
|
32
|
-
fileHash: `${id}-archive-hash`,
|
|
33
|
-
gitCommitHash: null,
|
|
34
|
-
id,
|
|
35
|
-
manifestFileHash: `${id}-manifest-hash`,
|
|
36
|
-
manifestStorageUri:
|
|
37
|
-
id === CURRENT_BUNDLE_ID ? CURRENT_MANIFEST_URI : TARGET_MANIFEST_URI,
|
|
38
|
-
platform: "ios",
|
|
39
|
-
storageUri: `s3://test-bucket/bundles/${id}/bundle.zip`,
|
|
40
|
-
...overrides,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
async function runScenario({
|
|
44
|
-
archiveByteSize,
|
|
45
|
-
archiveUrlUsable = true,
|
|
46
|
-
assetPath = "index.ios.bundle",
|
|
47
|
-
patchByteSize,
|
|
48
|
-
resolveUrl,
|
|
49
|
-
targetAsset,
|
|
50
|
-
targetManifestSuffix = "",
|
|
51
|
-
}: {
|
|
52
|
-
archiveByteSize: number | ((manifestByteSize: number) => number);
|
|
53
|
-
archiveUrlUsable?: boolean;
|
|
54
|
-
assetPath?: string;
|
|
55
|
-
patchByteSize?: unknown;
|
|
56
|
-
resolveUrl?: (storageUri: string) => Promise<string | null>;
|
|
57
|
-
targetAsset: TestManifestAsset;
|
|
58
|
-
targetManifestSuffix?: string;
|
|
59
|
-
}) {
|
|
60
|
-
const currentManifestText = JSON.stringify({
|
|
61
|
-
assets: {
|
|
62
|
-
[assetPath]: {
|
|
63
|
-
fileHash: "current-file-hash",
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
bundleId: CURRENT_BUNDLE_ID,
|
|
67
|
-
});
|
|
68
|
-
const targetManifestText = `${JSON.stringify({
|
|
69
|
-
assets: {
|
|
70
|
-
[assetPath]: targetAsset,
|
|
71
|
-
},
|
|
72
|
-
bundleId: TARGET_BUNDLE_ID,
|
|
73
|
-
})}${targetManifestSuffix}`;
|
|
74
|
-
const manifestByteSize = getUtf8ByteSize(targetManifestText);
|
|
75
|
-
const resolvedArchiveByteSize =
|
|
76
|
-
typeof archiveByteSize === "function"
|
|
77
|
-
? archiveByteSize(manifestByteSize)
|
|
78
|
-
: archiveByteSize;
|
|
79
|
-
const hasPatch = patchByteSize !== undefined;
|
|
80
|
-
const currentBundle = createBundle(CURRENT_BUNDLE_ID, 1_024);
|
|
81
|
-
const targetBundle = createBundle(
|
|
82
|
-
TARGET_BUNDLE_ID,
|
|
83
|
-
resolvedArchiveByteSize,
|
|
84
|
-
hasPatch
|
|
85
|
-
? {
|
|
86
|
-
patches: [
|
|
87
|
-
{
|
|
88
|
-
baseBundleId: CURRENT_BUNDLE_ID,
|
|
89
|
-
baseFileHash: "current-file-hash",
|
|
90
|
-
byteSize: patchByteSize as number,
|
|
91
|
-
patchFileHash: "patch-file-hash",
|
|
92
|
-
patchStorageUri: PATCH_STORAGE_URI,
|
|
93
|
-
},
|
|
94
|
-
],
|
|
95
|
-
}
|
|
96
|
-
: {},
|
|
97
|
-
);
|
|
98
|
-
const storageTexts = new Map([
|
|
99
|
-
[CURRENT_MANIFEST_URI, currentManifestText],
|
|
100
|
-
[TARGET_MANIFEST_URI, targetManifestText],
|
|
101
|
-
]);
|
|
102
|
-
const resolveFileUrl = vi.fn(async (storageUri: string | null) => {
|
|
103
|
-
if (!storageUri) return null;
|
|
104
|
-
if (resolveUrl) return resolveUrl(storageUri);
|
|
105
|
-
return `https://download.example.com/${encodeURIComponent(storageUri)}`;
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
const result = await resolveManifestArtifacts({
|
|
109
|
-
archiveUrlUsable,
|
|
110
|
-
currentBundle,
|
|
111
|
-
readStorageText: async (storageUri) => storageTexts.get(storageUri) ?? null,
|
|
112
|
-
resolveFileUrl,
|
|
113
|
-
targetBundle,
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
return {
|
|
117
|
-
manifestByteSize,
|
|
118
|
-
resolveFileUrl,
|
|
119
|
-
result,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
describe("resolveManifestArtifacts", () => {
|
|
124
|
-
it("uses raw UTF-8 manifest bytes and selects archive at equal size", async () => {
|
|
125
|
-
const { resolveFileUrl, result } = await runScenario({
|
|
126
|
-
archiveByteSize: (manifestByteSize) => manifestByteSize + 7,
|
|
127
|
-
assetPath: "assets/한글.png",
|
|
128
|
-
targetAsset: {
|
|
129
|
-
downloadByteSize: 7,
|
|
130
|
-
fileHash: "target-file-hash",
|
|
131
|
-
},
|
|
132
|
-
targetManifestSuffix: "\n",
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
expect(result).toBeNull();
|
|
136
|
-
expect(resolveFileUrl).not.toHaveBeenCalled();
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it("accepts a valid download hash and size pair on a raw asset", async () => {
|
|
140
|
-
const { resolveFileUrl, result } = await runScenario({
|
|
141
|
-
archiveByteSize: (manifestByteSize) => manifestByteSize + 7,
|
|
142
|
-
assetPath: "assets/logo.png",
|
|
143
|
-
targetAsset: {
|
|
144
|
-
downloadByteSize: 7,
|
|
145
|
-
downloadFileHash: VALID_DOWNLOAD_FILE_HASH,
|
|
146
|
-
fileHash: "target-file-hash",
|
|
147
|
-
},
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
expect(result).toBeNull();
|
|
151
|
-
expect(resolveFileUrl).not.toHaveBeenCalled();
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it("treats an invalid present hash on a raw asset as unknown cost", async () => {
|
|
155
|
-
const { resolveFileUrl, result } = await runScenario({
|
|
156
|
-
archiveByteSize: 1,
|
|
157
|
-
assetPath: "assets/logo.png",
|
|
158
|
-
targetAsset: {
|
|
159
|
-
downloadByteSize: 100,
|
|
160
|
-
downloadFileHash: "INVALID",
|
|
161
|
-
fileHash: "target-file-hash",
|
|
162
|
-
},
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
expect(result).not.toBeNull();
|
|
166
|
-
expect(resolveFileUrl).toHaveBeenCalledWith(
|
|
167
|
-
"s3://test-bucket/assets/sha256/ta/target-file-hash.png",
|
|
168
|
-
);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it.each([
|
|
172
|
-
["missing", undefined],
|
|
173
|
-
["invalid", "INVALID"],
|
|
174
|
-
])(
|
|
175
|
-
"treats a Brotli asset as unknown cost when its download hash is %s",
|
|
176
|
-
async (_label, downloadFileHash) => {
|
|
177
|
-
const { resolveFileUrl, result } = await runScenario({
|
|
178
|
-
archiveByteSize: 1,
|
|
179
|
-
targetAsset: {
|
|
180
|
-
downloadByteSize: 100,
|
|
181
|
-
downloadFileHash,
|
|
182
|
-
fileHash: "target-file-hash",
|
|
183
|
-
},
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
expect(result).not.toBeNull();
|
|
187
|
-
expect(resolveFileUrl).toHaveBeenCalledWith(
|
|
188
|
-
"s3://test-bucket/assets/sha256/ta/target-file-hash.br",
|
|
189
|
-
);
|
|
190
|
-
},
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
it.each([
|
|
194
|
-
["keeps", 9, true],
|
|
195
|
-
["omits", 10, false],
|
|
196
|
-
])(
|
|
197
|
-
"%s a %i-byte patch when the file is 10 bytes",
|
|
198
|
-
async (_action, patchByteSize, expectsPatch) => {
|
|
199
|
-
const { resolveFileUrl, result } = await runScenario({
|
|
200
|
-
archiveByteSize: (manifestByteSize) => manifestByteSize + 1_000,
|
|
201
|
-
patchByteSize,
|
|
202
|
-
targetAsset: {
|
|
203
|
-
downloadByteSize: 10,
|
|
204
|
-
downloadFileHash: VALID_DOWNLOAD_FILE_HASH,
|
|
205
|
-
fileHash: "target-file-hash",
|
|
206
|
-
},
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
expect(result?.changedAssets?.["index.ios.bundle"]?.patch).toEqual(
|
|
210
|
-
expectsPatch
|
|
211
|
-
? expect.objectContaining({ patchUrl: expect.any(String) })
|
|
212
|
-
: undefined,
|
|
213
|
-
);
|
|
214
|
-
expect(resolveFileUrl).toHaveBeenCalledWith(
|
|
215
|
-
`s3://test-bucket/assets/sha256/aa/${VALID_DOWNLOAD_FILE_HASH}.br`,
|
|
216
|
-
);
|
|
217
|
-
expect(resolveFileUrl).toHaveBeenCalledWith(PATCH_STORAGE_URI);
|
|
218
|
-
},
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
it("keeps a larger patch when the file and archive URLs are unavailable", async () => {
|
|
222
|
-
const fileStorageUri = `s3://test-bucket/assets/sha256/aa/${VALID_DOWNLOAD_FILE_HASH}.br`;
|
|
223
|
-
const { result } = await runScenario({
|
|
224
|
-
archiveByteSize: 1,
|
|
225
|
-
archiveUrlUsable: false,
|
|
226
|
-
patchByteSize: 100,
|
|
227
|
-
resolveUrl: async (storageUri) =>
|
|
228
|
-
storageUri === fileStorageUri
|
|
229
|
-
? null
|
|
230
|
-
: `https://download.example.com/${encodeURIComponent(storageUri)}`,
|
|
231
|
-
targetAsset: {
|
|
232
|
-
downloadByteSize: 50,
|
|
233
|
-
downloadFileHash: VALID_DOWNLOAD_FILE_HASH,
|
|
234
|
-
fileHash: "target-file-hash",
|
|
235
|
-
},
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
expect(result?.changedAssets?.["index.ios.bundle"]).toEqual({
|
|
239
|
-
fileHash: "target-file-hash",
|
|
240
|
-
patch: expect.objectContaining({
|
|
241
|
-
patchUrl: expect.any(String),
|
|
242
|
-
}),
|
|
243
|
-
});
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
it("recalculates from the file when an unknown-size patch URL is unavailable", async () => {
|
|
247
|
-
const { resolveFileUrl, result } = await runScenario({
|
|
248
|
-
archiveByteSize: (manifestByteSize) => manifestByteSize + 50,
|
|
249
|
-
patchByteSize: Number.NaN,
|
|
250
|
-
resolveUrl: async (storageUri) =>
|
|
251
|
-
storageUri === PATCH_STORAGE_URI
|
|
252
|
-
? null
|
|
253
|
-
: `https://download.example.com/${encodeURIComponent(storageUri)}`,
|
|
254
|
-
targetAsset: {
|
|
255
|
-
downloadByteSize: 100,
|
|
256
|
-
downloadFileHash: VALID_DOWNLOAD_FILE_HASH,
|
|
257
|
-
fileHash: "target-file-hash",
|
|
258
|
-
},
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
expect(result).toBeNull();
|
|
262
|
-
expect(resolveFileUrl).toHaveBeenCalledWith(PATCH_STORAGE_URI);
|
|
263
|
-
expect(resolveFileUrl).toHaveBeenCalledWith(
|
|
264
|
-
`s3://test-bucket/assets/sha256/aa/${VALID_DOWNLOAD_FILE_HASH}.br`,
|
|
265
|
-
);
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
it("recalculates from a known patch when the file fallback cost is unknown", async () => {
|
|
269
|
-
const { result } = await runScenario({
|
|
270
|
-
archiveByteSize: (manifestByteSize) => manifestByteSize + 50,
|
|
271
|
-
patchByteSize: 100,
|
|
272
|
-
targetAsset: {
|
|
273
|
-
downloadByteSize: 100,
|
|
274
|
-
fileHash: "target-file-hash",
|
|
275
|
-
},
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
expect(result).toBeNull();
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
it("keeps the manifest path when safe addition overflows", async () => {
|
|
282
|
-
const { result } = await runScenario({
|
|
283
|
-
archiveByteSize: 1,
|
|
284
|
-
assetPath: "assets/logo.png",
|
|
285
|
-
targetAsset: {
|
|
286
|
-
downloadByteSize: Number.MAX_SAFE_INTEGER,
|
|
287
|
-
fileHash: "target-file-hash",
|
|
288
|
-
},
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
expect(result).not.toBeNull();
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
it("keeps the manifest path when a byte size is invalid", async () => {
|
|
295
|
-
const { result } = await runScenario({
|
|
296
|
-
archiveByteSize: 1,
|
|
297
|
-
assetPath: "assets/logo.png",
|
|
298
|
-
targetAsset: {
|
|
299
|
-
downloadByteSize: -1,
|
|
300
|
-
fileHash: "target-file-hash",
|
|
301
|
-
},
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
expect(result).not.toBeNull();
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
it("does not select archive when its URL is unavailable", async () => {
|
|
308
|
-
const { result } = await runScenario({
|
|
309
|
-
archiveByteSize: 1,
|
|
310
|
-
archiveUrlUsable: false,
|
|
311
|
-
assetPath: "assets/logo.png",
|
|
312
|
-
targetAsset: {
|
|
313
|
-
downloadByteSize: 100,
|
|
314
|
-
fileHash: "target-file-hash",
|
|
315
|
-
},
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
expect(result).not.toBeNull();
|
|
319
|
-
});
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
describe("createArtifactResolver", () => {
|
|
323
|
-
it("returns usable manifest artifacts when the archive URL is null", async () => {
|
|
324
|
-
const databasePlugin = createInMemoryDatabasePlugin();
|
|
325
|
-
const database = createDatabaseClient(databasePlugin);
|
|
326
|
-
const targetManifestText = JSON.stringify({
|
|
327
|
-
assets: {
|
|
328
|
-
"assets/logo.png": {
|
|
329
|
-
downloadByteSize: 100,
|
|
330
|
-
fileHash: "target-file-hash",
|
|
331
|
-
},
|
|
332
|
-
},
|
|
333
|
-
bundleId: TARGET_BUNDLE_ID,
|
|
334
|
-
});
|
|
335
|
-
const targetBundle = createBundle(TARGET_BUNDLE_ID, 1);
|
|
336
|
-
await database.insertBundle(targetBundle);
|
|
337
|
-
|
|
338
|
-
const resolver = createArtifactResolver({
|
|
339
|
-
database: databasePlugin,
|
|
340
|
-
readStorageText: async (storageUri) =>
|
|
341
|
-
storageUri === TARGET_MANIFEST_URI ? targetManifestText : null,
|
|
342
|
-
resolveFileUrl: async (storageUri) =>
|
|
343
|
-
storageUri === targetBundle.storageUri
|
|
344
|
-
? null
|
|
345
|
-
: `https://download.example.com/${encodeURIComponent(storageUri ?? "")}`,
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
await expect(resolver(TARGET_BUNDLE_ID, NIL_UUID)).resolves.toMatchObject({
|
|
349
|
-
changedAssets: {
|
|
350
|
-
"assets/logo.png": {
|
|
351
|
-
file: { url: expect.any(String) },
|
|
352
|
-
fileHash: "target-file-hash",
|
|
353
|
-
},
|
|
354
|
-
},
|
|
355
|
-
fileUrl: null,
|
|
356
|
-
manifestUrl: expect.any(String),
|
|
357
|
-
});
|
|
358
|
-
});
|
|
359
|
-
});
|