@hot-updater/server 1.0.0-rc.2 → 1.0.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +12 -14
- package/dist/adapters/drizzle.cjs +32 -75
- package/dist/adapters/drizzle.d.cts +13 -5
- package/dist/adapters/drizzle.d.mts +13 -5
- package/dist/adapters/drizzle.mjs +32 -77
- package/dist/adapters/drizzleExecutor.cjs +114 -0
- package/dist/adapters/drizzleExecutor.d.cts +9 -0
- package/dist/adapters/drizzleExecutor.d.mts +9 -0
- package/dist/adapters/drizzleExecutor.mjs +112 -0
- package/dist/adapters/kysely.cjs +22 -31
- package/dist/adapters/kysely.d.cts +10 -6
- package/dist/adapters/kysely.d.mts +10 -6
- package/dist/adapters/kysely.mjs +23 -33
- package/dist/adapters/kyselyExecutor.cjs +32 -0
- package/dist/adapters/kyselyExecutor.d.cts +11 -0
- package/dist/adapters/kyselyExecutor.d.mts +11 -0
- package/dist/adapters/kyselyExecutor.mjs +32 -0
- package/dist/adapters/mongodb.cjs +18 -54
- package/dist/adapters/mongodb.d.cts +10 -5
- package/dist/adapters/mongodb.d.mts +10 -5
- package/dist/adapters/mongodb.mjs +19 -56
- package/dist/adapters/mongodbAdapter.cjs +192 -0
- package/dist/adapters/mongodbAdapter.d.cts +9 -0
- package/dist/adapters/mongodbAdapter.d.mts +9 -0
- package/dist/adapters/mongodbAdapter.mjs +191 -0
- package/dist/adapters/prisma.cjs +35 -267
- package/dist/adapters/prisma.d.cts +12 -7
- package/dist/adapters/prisma.d.mts +12 -7
- package/dist/adapters/prisma.mjs +36 -268
- package/dist/adapters/prismaExecutor.cjs +63 -0
- package/dist/adapters/prismaExecutor.mjs +63 -0
- package/dist/adapters/sqlProviders.cjs +14 -0
- package/dist/adapters/sqlProviders.mjs +14 -0
- package/dist/assembly/assemblePlugins.cjs +144 -0
- package/dist/assembly/assemblePlugins.d.cts +5 -0
- package/dist/assembly/assemblePlugins.d.mts +5 -0
- package/dist/assembly/assemblePlugins.mjs +139 -0
- package/dist/assembly/clientPlugins.cjs +88 -0
- package/dist/assembly/clientPlugins.mjs +88 -0
- package/dist/assembly/configError.d.cts +2 -0
- package/dist/assembly/configError.d.mts +2 -0
- package/dist/assembly/configError.mjs +2 -0
- package/dist/core/api.cjs +51 -0
- package/dist/core/api.d.cts +54 -0
- package/dist/core/api.d.mts +54 -0
- package/dist/core/api.mjs +51 -0
- package/dist/core/baseCandidates.cjs +28 -0
- package/dist/core/baseCandidates.mjs +28 -0
- package/dist/core/operations.cjs +351 -0
- package/dist/core/operations.mjs +351 -0
- package/dist/core/reads.cjs +273 -0
- package/dist/core/reads.d.cts +9 -0
- package/dist/core/reads.d.mts +9 -0
- package/dist/core/reads.mjs +267 -0
- package/dist/core/releases.cjs +193 -0
- package/dist/core/releases.mjs +190 -0
- package/dist/core/writes.cjs +96 -0
- package/dist/core/writes.mjs +91 -0
- package/dist/createHotUpdaterCore.cjs +72 -91
- package/dist/createHotUpdaterCore.d.cts +106 -38
- package/dist/createHotUpdaterCore.d.mts +106 -38
- package/dist/createHotUpdaterCore.mjs +74 -89
- package/dist/db/engineDrizzleSchema.cjs +53 -0
- package/dist/db/engineDrizzleSchema.mjs +53 -0
- package/dist/db/enginePrismaSchema.cjs +84 -0
- package/dist/db/enginePrismaSchema.d.cts +5 -0
- package/dist/db/enginePrismaSchema.d.mts +5 -0
- package/dist/db/enginePrismaSchema.mjs +83 -0
- package/dist/db/releaseCatalog.cjs +24 -47
- package/dist/db/releaseCatalog.mjs +20 -44
- package/dist/db/updateArtifacts.cjs +43 -72
- package/dist/db/updateArtifacts.mjs +40 -69
- package/dist/handler.cjs +59 -43
- package/dist/handler.d.cts +3 -5
- package/dist/handler.d.mts +3 -5
- package/dist/handler.mjs +61 -43
- package/dist/handlerAdminRoutes.cjs +374 -0
- package/dist/handlerAdminRoutes.mjs +372 -0
- package/dist/handlerParameters.cjs +6 -11
- package/dist/handlerParameters.mjs +6 -10
- package/dist/handlerReleaseCatalogRoutes.cjs +32 -15
- package/dist/handlerReleaseCatalogRoutes.mjs +32 -15
- package/dist/handlerTypes.d.cts +2 -55
- package/dist/handlerTypes.d.mts +2 -55
- package/dist/handlerVersionRoutes.cjs +20 -4
- package/dist/handlerVersionRoutes.mjs +20 -4
- package/dist/index.cjs +9 -9
- package/dist/index.d.cts +8 -9
- package/dist/index.d.mts +8 -9
- package/dist/index.mjs +3 -4
- package/dist/node.cjs +3 -6
- package/dist/node.d.cts +2 -2
- package/dist/node.d.mts +2 -2
- package/dist/node.mjs +4 -4
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugins/api-keys/index.cjs +9 -0
- package/dist/plugins/api-keys/index.d.cts +1 -0
- package/dist/plugins/api-keys/index.d.mts +1 -0
- package/dist/plugins/api-keys/index.mjs +2 -0
- package/dist/plugins/definePlugin.d.cts +2 -0
- package/dist/plugins/definePlugin.d.mts +2 -0
- package/dist/plugins/insights/index.cjs +9 -0
- package/dist/plugins/insights/index.d.cts +1 -0
- package/dist/plugins/insights/index.d.mts +1 -0
- package/dist/plugins/insights/index.mjs +2 -0
- package/dist/plugins/official.cjs +30 -0
- package/dist/plugins/official.mjs +29 -0
- package/dist/storageAccess.cjs +13 -10
- package/dist/storageAccess.mjs +13 -10
- package/dist/types/index.d.cts +2 -28
- package/dist/types/index.d.mts +2 -28
- package/package.json +26 -14
- package/dist/_virtual/_rolldown/runtime.cjs +0 -23
- package/dist/adapters/databaseConstraintErrors.cjs +0 -22
- package/dist/adapters/databaseConstraintErrors.mjs +0 -21
- package/dist/adapters/databasePluginUtils.cjs +0 -116
- package/dist/adapters/databasePluginUtils.mjs +0 -106
- package/dist/adapters/drizzleCrud.cjs +0 -311
- package/dist/adapters/drizzleCrud.mjs +0 -308
- package/dist/adapters/drizzleLazyDB.cjs +0 -106
- package/dist/adapters/drizzleLazyDB.mjs +0 -106
- package/dist/adapters/drizzleQuery.cjs +0 -69
- package/dist/adapters/drizzleQuery.mjs +0 -69
- package/dist/adapters/insightsTransaction.cjs +0 -22
- package/dist/adapters/insightsTransaction.mjs +0 -22
- package/dist/adapters/kyselyCrud.cjs +0 -305
- package/dist/adapters/kyselyCrud.mjs +0 -304
- package/dist/adapters/kyselyQuery.cjs +0 -56
- package/dist/adapters/kyselyQuery.mjs +0 -56
- package/dist/adapters/mongodbCollections.cjs +0 -38
- package/dist/adapters/mongodbCollections.mjs +0 -32
- package/dist/adapters/mongodbQuery.cjs +0 -94
- package/dist/adapters/mongodbQuery.mjs +0 -86
- package/dist/adapters/mongodbReads.cjs +0 -210
- package/dist/adapters/mongodbReads.mjs +0 -210
- package/dist/adapters/mongodbWrites.cjs +0 -148
- package/dist/adapters/mongodbWrites.mjs +0 -148
- package/dist/adapters/prismaQuery.cjs +0 -57
- package/dist/adapters/prismaQuery.mjs +0 -56
- package/dist/adapters/prismaRows.cjs +0 -219
- package/dist/adapters/prismaRows.mjs +0 -209
- package/dist/apiKeys.cjs +0 -143
- package/dist/apiKeys.d.cts +0 -49
- package/dist/apiKeys.d.mts +0 -49
- package/dist/apiKeys.mjs +0 -133
- package/dist/db/createBundleDiff.cjs +0 -144
- package/dist/db/createBundleDiff.d.cts +0 -16
- package/dist/db/createBundleDiff.d.mts +0 -16
- package/dist/db/createBundleDiff.mjs +0 -141
- package/dist/db/databasePluginCore.cjs +0 -137
- package/dist/db/databasePluginCore.mjs +0 -137
- package/dist/db/fixedMigrator.cjs +0 -79
- package/dist/db/fixedMigrator.mjs +0 -78
- package/dist/db/fixedMigratorMongo.cjs +0 -321
- package/dist/db/fixedMigratorMongo.mjs +0 -321
- package/dist/db/fixedMigratorShared.cjs +0 -23
- package/dist/db/fixedMigratorShared.mjs +0 -18
- package/dist/db/index.cjs +0 -27
- package/dist/db/index.d.cts +0 -12
- package/dist/db/index.d.mts +0 -12
- package/dist/db/index.mjs +0 -22
- package/dist/db/mongoMigrationExecution.cjs +0 -11
- package/dist/db/mongoMigrationExecution.mjs +0 -11
- package/dist/db/releaseCatalog.d.cts +0 -16
- package/dist/db/releaseCatalog.d.mts +0 -16
- package/dist/db/schema/insightsCollation.cjs +0 -14
- package/dist/db/schema/insightsCollation.mjs +0 -14
- package/dist/db/schema/mongodb.cjs +0 -25
- package/dist/db/schema/mongodb.mjs +0 -25
- package/dist/db/schema/registry.cjs +0 -21
- package/dist/db/schema/registry.mjs +0 -17
- package/dist/db/schema/sql.cjs +0 -105
- package/dist/db/schema/sql.mjs +0 -97
- package/dist/db/schema/sqlOperations.cjs +0 -27
- package/dist/db/schema/sqlOperations.mjs +0 -26
- package/dist/db/schemaGenerators.cjs +0 -275
- package/dist/db/schemaGenerators.mjs +0 -273
- package/dist/db/schemaReadiness.cjs +0 -26
- package/dist/db/schemaReadiness.d.cts +0 -9
- package/dist/db/schemaReadiness.d.mts +0 -9
- package/dist/db/schemaReadiness.mjs +0 -25
- package/dist/db/sqlMigrationExecution.cjs +0 -67
- package/dist/db/sqlMigrationExecution.mjs +0 -67
- package/dist/db/types.cjs +0 -22
- package/dist/db/types.d.cts +0 -118
- package/dist/db/types.d.mts +0 -118
- package/dist/db/types.mjs +0 -19
- package/dist/handlerBundleRoutes.cjs +0 -155
- package/dist/handlerBundleRoutes.mjs +0 -155
- package/dist/handlerReleaseManagementRoutes.cjs +0 -124
- package/dist/handlerReleaseManagementRoutes.mjs +0 -124
- package/dist/insights/domain.d.cts +0 -89
- package/dist/insights/domain.d.mts +0 -89
- package/dist/insights/errors.cjs +0 -15
- package/dist/insights/errors.mjs +0 -14
- package/dist/insights/eventInput.cjs +0 -155
- package/dist/insights/eventInput.mjs +0 -153
- package/dist/insights/provider.cjs +0 -314
- package/dist/insights/provider.d.cts +0 -6
- package/dist/insights/provider.d.mts +0 -6
- package/dist/insights/provider.mjs +0 -314
- package/dist/insights/queryInput.cjs +0 -93
- package/dist/insights/queryInput.mjs +0 -91
- package/dist/insights/routes.cjs +0 -58
- package/dist/insights/routes.mjs +0 -56
- package/dist/insights/types.d.cts +0 -32
- package/dist/insights/types.d.mts +0 -32
- package/dist/schema/dsl.cjs +0 -103
- package/dist/schema/dsl.mjs +0 -87
- package/dist/schema/index.cjs +0 -20
- package/dist/schema/index.mjs +0 -7
- package/dist/schema/settings.cjs +0 -9
- package/dist/schema/settings.mjs +0 -9
- package/dist/schema/types.cjs +0 -8
- package/dist/schema/types.mjs +0 -6
- package/dist/schema/v1_0_0.cjs +0 -406
- package/dist/schema/v1_0_0.mjs +0 -398
- package/src/adapters/databaseConstraintErrors.ts +0 -25
- package/src/adapters/databasePluginTestDatabase.ts +0 -120
- package/src/adapters/databasePluginUtils.spec.ts +0 -29
- package/src/adapters/databasePluginUtils.ts +0 -214
- package/src/adapters/drizzle.spec.ts +0 -336
- package/src/adapters/drizzle.ts +0 -162
- package/src/adapters/drizzleCrud.ts +0 -571
- package/src/adapters/drizzleLazyDB.ts +0 -271
- package/src/adapters/drizzleQuery.ts +0 -164
- package/src/adapters/insightsTransaction.ts +0 -32
- package/src/adapters/kysely.spec.ts +0 -174
- package/src/adapters/kysely.ts +0 -110
- package/src/adapters/kyselyCrud.ts +0 -709
- package/src/adapters/kyselyQuery.ts +0 -128
- package/src/adapters/mongodb.integration.spec.ts +0 -210
- package/src/adapters/mongodb.spec.ts +0 -209
- package/src/adapters/mongodb.ts +0 -138
- package/src/adapters/mongodbCollections.ts +0 -67
- package/src/adapters/mongodbQuery.ts +0 -255
- package/src/adapters/mongodbReads.ts +0 -380
- package/src/adapters/mongodbRows.spec.ts +0 -64
- package/src/adapters/mongodbRows.ts +0 -118
- package/src/adapters/mongodbTestClient.ts +0 -377
- package/src/adapters/mongodbTestFilter.ts +0 -169
- package/src/adapters/mongodbWrites.ts +0 -287
- package/src/adapters/prisma.spec.ts +0 -293
- package/src/adapters/prisma.ts +0 -565
- package/src/adapters/prismaQuery.ts +0 -129
- package/src/adapters/prismaRows.spec.ts +0 -98
- package/src/adapters/prismaRows.ts +0 -337
- package/src/adapters/prismaTestClient.ts +0 -413
- package/src/apiKeys.integration.spec.ts +0 -192
- package/src/apiKeys.spec.ts +0 -162
- package/src/apiKeys.ts +0 -220
- package/src/calculatePagination.ts +0 -34
- package/src/createHotUpdaterCore.ts +0 -246
- package/src/db/bundleRows.spec.ts +0 -164
- package/src/db/bundleRows.ts +0 -10
- package/src/db/createBundleDiff.spec.ts +0 -450
- package/src/db/createBundleDiff.ts +0 -364
- package/src/db/databasePluginCore.spec.ts +0 -62
- package/src/db/databasePluginCore.testFixtures.ts +0 -76
- package/src/db/databasePluginCore.ts +0 -185
- package/src/db/databasePluginUpdateCheck.bench.ts +0 -110
- package/src/db/fixedMigrator.spec.ts +0 -296
- package/src/db/fixedMigrator.ts +0 -147
- package/src/db/fixedMigratorMongo.spec.ts +0 -239
- package/src/db/fixedMigratorMongo.ts +0 -425
- package/src/db/fixedMigratorShared.ts +0 -36
- package/src/db/hotUpdaterSchema.ts +0 -5
- package/src/db/index.spec.ts +0 -1269
- package/src/db/index.ts +0 -47
- package/src/db/mongoMigrationExecution.ts +0 -23
- package/src/db/node-sqlite.d.ts +0 -25
- package/src/db/releaseCatalog.ts +0 -148
- package/src/db/schema/definitions.ts +0 -1
- package/src/db/schema/insightsCollation.ts +0 -21
- package/src/db/schema/mongodb.ts +0 -40
- package/src/db/schema/registry.ts +0 -55
- package/src/db/schema/sql.ts +0 -244
- package/src/db/schema/sqlOperations.ts +0 -63
- package/src/db/schema/types.ts +0 -1
- package/src/db/schemaGenerators.ts +0 -494
- package/src/db/schemaReadiness.ts +0 -34
- package/src/db/sqlMigrationExecution.spec.ts +0 -65
- package/src/db/sqlMigrationExecution.ts +0 -108
- package/src/db/types.spec.ts +0 -63
- package/src/db/types.ts +0 -228
- package/src/db/updateArtifacts.spec.ts +0 -359
- package/src/db/updateArtifacts.ts +0 -541
- package/src/handler-standalone.integration.spec.ts +0 -528
- package/src/handler.spec.ts +0 -190
- package/src/handler.testFixtures.ts +0 -30
- package/src/handler.ts +0 -245
- package/src/handlerAuth.integration.spec.ts +0 -33
- package/src/handlerBundleRoutes.ts +0 -259
- package/src/handlerErrors.ts +0 -7
- package/src/handlerManagement.spec.ts +0 -262
- package/src/handlerParameters.ts +0 -105
- package/src/handlerReleaseCatalogRoutes.ts +0 -154
- package/src/handlerReleaseManagementRoutes.ts +0 -213
- package/src/handlerTypes.ts +0 -96
- package/src/handlerVersionRoutes.ts +0 -12
- package/src/index.ts +0 -30
- package/src/insights/domain.ts +0 -103
- package/src/insights/errors.ts +0 -11
- package/src/insights/eventInput.ts +0 -225
- package/src/insights/insights.integration.spec.ts +0 -381
- package/src/insights/provider.spec.ts +0 -385
- package/src/insights/provider.ts +0 -591
- package/src/insights/queryInput.ts +0 -141
- package/src/insights/routes.ts +0 -104
- package/src/insights/types.ts +0 -55
- package/src/internalRouter.ts +0 -104
- package/src/node.spec.ts +0 -119
- package/src/node.ts +0 -111
- package/src/releaseCatalogRoutes.integration.spec.ts +0 -238
- package/src/runtime.spec.ts +0 -194
- package/src/runtime.testFixtures.ts +0 -71
- package/src/schema/dsl-all-versions.spec.ts +0 -37
- package/src/schema/dsl.ts +0 -187
- package/src/schema/index.ts +0 -10
- package/src/schema/settings.ts +0 -15
- package/src/schema/types.ts +0 -79
- package/src/schema/v1_0_0.spec.ts +0 -220
- package/src/schema/v1_0_0.ts +0 -529
- package/src/storageAccess.spec.ts +0 -152
- package/src/storageAccess.ts +0 -141
- package/src/types/index.ts +0 -34
- package/src/version.ts +0 -3
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BundleEventRow,
|
|
3
|
-
InsightsInstallationRow,
|
|
4
|
-
BundlePatchRow,
|
|
5
|
-
BundleRow,
|
|
6
|
-
ChannelRow,
|
|
7
|
-
ApiKeyRow,
|
|
8
|
-
ReleaseCatalogRow,
|
|
9
|
-
ReleaseRow,
|
|
10
|
-
} from "@hot-updater/plugin-core";
|
|
11
|
-
|
|
12
|
-
export type MongoTestRow =
|
|
13
|
-
| BundleEventRow
|
|
14
|
-
| InsightsInstallationRow
|
|
15
|
-
| BundlePatchRow
|
|
16
|
-
| BundleRow
|
|
17
|
-
| ChannelRow
|
|
18
|
-
| ApiKeyRow
|
|
19
|
-
| ReleaseRow
|
|
20
|
-
| ReleaseCatalogRow;
|
|
21
|
-
|
|
22
|
-
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
23
|
-
typeof value === "object" && value !== null;
|
|
24
|
-
|
|
25
|
-
export const readMongoTestField = (row: MongoTestRow, field: string): unknown =>
|
|
26
|
-
Object.entries(row).find(([key]) => key === field)?.[1];
|
|
27
|
-
|
|
28
|
-
const compare = (left: unknown, right: unknown): number => {
|
|
29
|
-
if (typeof left === "number" && typeof right === "number") {
|
|
30
|
-
return left - right;
|
|
31
|
-
}
|
|
32
|
-
if (typeof left === "string" && typeof right === "string") {
|
|
33
|
-
return Buffer.compare(Buffer.from(left), Buffer.from(right));
|
|
34
|
-
}
|
|
35
|
-
return 0;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const resolveExpression = (row: MongoTestRow, expression: unknown): unknown => {
|
|
39
|
-
if (typeof expression === "string" && expression.startsWith("$")) {
|
|
40
|
-
return readMongoTestField(row, expression.slice(1));
|
|
41
|
-
}
|
|
42
|
-
if (Array.isArray(expression)) {
|
|
43
|
-
return expression.map((item) => resolveExpression(row, item));
|
|
44
|
-
}
|
|
45
|
-
if (!isRecord(expression)) return expression;
|
|
46
|
-
if ("$literal" in expression) return expression["$literal"];
|
|
47
|
-
if ("$ifNull" in expression && Array.isArray(expression["$ifNull"])) {
|
|
48
|
-
const [value, fallback] = expression["$ifNull"];
|
|
49
|
-
const resolved = resolveExpression(row, value);
|
|
50
|
-
return resolved === null || resolved === undefined
|
|
51
|
-
? resolveExpression(row, fallback)
|
|
52
|
-
: resolved;
|
|
53
|
-
}
|
|
54
|
-
if ("$toLower" in expression) {
|
|
55
|
-
const value = resolveExpression(row, expression["$toLower"]);
|
|
56
|
-
return typeof value === "string" ? value.toLocaleLowerCase() : value;
|
|
57
|
-
}
|
|
58
|
-
for (const operator of ["$eq", "$ne", "$gt", "$gte", "$lt", "$lte"]) {
|
|
59
|
-
const operands = expression[operator];
|
|
60
|
-
if (!Array.isArray(operands)) continue;
|
|
61
|
-
const [left, right] = operands.map((item) => resolveExpression(row, item));
|
|
62
|
-
switch (operator) {
|
|
63
|
-
case "$eq":
|
|
64
|
-
return Object.is(left, right);
|
|
65
|
-
case "$ne":
|
|
66
|
-
return !Object.is(left, right);
|
|
67
|
-
case "$gt":
|
|
68
|
-
return compare(left, right) > 0;
|
|
69
|
-
case "$gte":
|
|
70
|
-
return compare(left, right) >= 0;
|
|
71
|
-
case "$lt":
|
|
72
|
-
return compare(left, right) < 0;
|
|
73
|
-
case "$lte":
|
|
74
|
-
return compare(left, right) <= 0;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if ("$in" in expression && Array.isArray(expression["$in"])) {
|
|
78
|
-
const [value, candidates] = expression["$in"].map((item) =>
|
|
79
|
-
resolveExpression(row, item),
|
|
80
|
-
);
|
|
81
|
-
return (
|
|
82
|
-
Array.isArray(candidates) &&
|
|
83
|
-
candidates.some((candidate) => Object.is(candidate, value))
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
if ("$not" in expression && Array.isArray(expression["$not"])) {
|
|
87
|
-
return !resolveExpression(row, expression["$not"][0]);
|
|
88
|
-
}
|
|
89
|
-
const regexMatch = expression["$regexMatch"];
|
|
90
|
-
if (isRecord(regexMatch)) {
|
|
91
|
-
const input = resolveExpression(row, regexMatch["input"]);
|
|
92
|
-
const regex = resolveExpression(row, regexMatch["regex"]);
|
|
93
|
-
const options = regexMatch["options"];
|
|
94
|
-
return (
|
|
95
|
-
typeof input === "string" &&
|
|
96
|
-
typeof regex === "string" &&
|
|
97
|
-
new RegExp(regex, options === "i" ? "i" : undefined).test(input)
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
return expression;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const matchesField = (current: unknown, condition: unknown): boolean => {
|
|
104
|
-
if (!isRecord(condition)) return Object.is(current, condition);
|
|
105
|
-
if ("$eq" in condition) return Object.is(current, condition["$eq"]);
|
|
106
|
-
if (typeof condition["$exists"] === "boolean") {
|
|
107
|
-
return condition["$exists"] ? current !== undefined : current === undefined;
|
|
108
|
-
}
|
|
109
|
-
if (Array.isArray(condition["$in"])) {
|
|
110
|
-
return condition["$in"].some((item) => Object.is(item, current));
|
|
111
|
-
}
|
|
112
|
-
if ("$ne" in condition && Object.is(current, condition["$ne"])) {
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
if ("$gte" in condition && compare(current, condition["$gte"]) < 0) {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
if ("$gt" in condition && compare(current, condition["$gt"]) <= 0) {
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
if ("$lte" in condition && compare(current, condition["$lte"]) > 0) {
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
if ("$lt" in condition && compare(current, condition["$lt"]) >= 0) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
return true;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
export const matchesMongoTestFilter = (
|
|
131
|
-
row: MongoTestRow,
|
|
132
|
-
filter: unknown,
|
|
133
|
-
): boolean => {
|
|
134
|
-
if (!isRecord(filter)) return true;
|
|
135
|
-
if ("$expr" in filter)
|
|
136
|
-
return Boolean(resolveExpression(row, filter["$expr"]));
|
|
137
|
-
const conjunction = filter["$and"];
|
|
138
|
-
if (Array.isArray(conjunction)) {
|
|
139
|
-
return conjunction.every((item) => matchesMongoTestFilter(row, item));
|
|
140
|
-
}
|
|
141
|
-
const disjunction = filter["$or"];
|
|
142
|
-
if (Array.isArray(disjunction)) {
|
|
143
|
-
return disjunction.some((item) => matchesMongoTestFilter(row, item));
|
|
144
|
-
}
|
|
145
|
-
return Object.entries(filter).every(([field, condition]) =>
|
|
146
|
-
matchesField(readMongoTestField(row, field), condition),
|
|
147
|
-
);
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
export const sortMongoTestRows = (
|
|
151
|
-
rows: MongoTestRow[],
|
|
152
|
-
sort: unknown,
|
|
153
|
-
): MongoTestRow[] => {
|
|
154
|
-
if (!isRecord(sort)) return rows;
|
|
155
|
-
const entries = Object.entries(sort);
|
|
156
|
-
if (entries.length === 0) return rows;
|
|
157
|
-
return rows.toSorted((left, right) => {
|
|
158
|
-
for (const [field, direction] of entries) {
|
|
159
|
-
const result = compare(
|
|
160
|
-
readMongoTestField(left, field),
|
|
161
|
-
readMongoTestField(right, field),
|
|
162
|
-
);
|
|
163
|
-
if (result !== 0) {
|
|
164
|
-
return direction === -1 ? -result : result;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return 0;
|
|
168
|
-
});
|
|
169
|
-
};
|
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
import type { BundlePatchRow } from "@hot-updater/plugin-core";
|
|
2
|
-
import { createUUIDv7 } from "@hot-updater/plugin-core";
|
|
3
|
-
import type { DatabasePluginImplementation } from "@hot-updater/plugin-core/internal";
|
|
4
|
-
import type { ClientSession, Collection } from "mongodb";
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
activeBundleFilter,
|
|
8
|
-
DELETION_TOKEN_FIELD,
|
|
9
|
-
type MongoBundleDocument,
|
|
10
|
-
type MongoCollections,
|
|
11
|
-
MongoAdapterConstraintError,
|
|
12
|
-
mongoSessionOptions,
|
|
13
|
-
WITHOUT_INTERNAL_FIELDS,
|
|
14
|
-
WITHOUT_MONGO_ID,
|
|
15
|
-
} from "./mongodbCollections";
|
|
16
|
-
import {
|
|
17
|
-
createMongoBundleWhere,
|
|
18
|
-
createMongoChannelWhere,
|
|
19
|
-
createMongoInstallationWhere,
|
|
20
|
-
createMongoApiKeyWhere,
|
|
21
|
-
createMongoPatchWhere,
|
|
22
|
-
createMongoReleaseCatalogWhere,
|
|
23
|
-
createMongoReleaseWhere,
|
|
24
|
-
} from "./mongodbQuery";
|
|
25
|
-
|
|
26
|
-
const assertPatchReferences = async (
|
|
27
|
-
bundles: Collection<MongoBundleDocument>,
|
|
28
|
-
patch: BundlePatchRow,
|
|
29
|
-
session?: ClientSession,
|
|
30
|
-
): Promise<void> => {
|
|
31
|
-
const ids = Array.from(new Set([patch.bundle_id, patch.base_bundle_id]));
|
|
32
|
-
const count = await bundles.countDocuments(
|
|
33
|
-
activeBundleFilter({ id: { $in: ids } }),
|
|
34
|
-
mongoSessionOptions(session),
|
|
35
|
-
);
|
|
36
|
-
if (count !== ids.length) {
|
|
37
|
-
throw new MongoAdapterConstraintError(
|
|
38
|
-
`patch "${patch.id}" references a missing bundle`,
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
type MongoWriteImplementation = Pick<
|
|
44
|
-
DatabasePluginImplementation,
|
|
45
|
-
"create" | "delete" | "deleteChannel" | "insertChannel" | "update"
|
|
46
|
-
>;
|
|
47
|
-
|
|
48
|
-
export const createMongoWrites = (
|
|
49
|
-
collections: MongoCollections,
|
|
50
|
-
session?: ClientSession,
|
|
51
|
-
): MongoWriteImplementation => ({
|
|
52
|
-
deleteChannel: async ({ id }) => {
|
|
53
|
-
if (session === undefined) {
|
|
54
|
-
throw new MongoAdapterConstraintError(
|
|
55
|
-
"channel deletion requires transaction support",
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
const locked = await collections.channels.updateOne(
|
|
59
|
-
{ id },
|
|
60
|
-
{ $set: { id } },
|
|
61
|
-
mongoSessionOptions(session),
|
|
62
|
-
);
|
|
63
|
-
if (locked.matchedCount !== 1) {
|
|
64
|
-
return { deleted: false, reason: "not_found" };
|
|
65
|
-
}
|
|
66
|
-
const referencedReleases = await collections.releases.countDocuments(
|
|
67
|
-
{ channel_id: id },
|
|
68
|
-
mongoSessionOptions(session),
|
|
69
|
-
);
|
|
70
|
-
if (referencedReleases > 0) {
|
|
71
|
-
return { deleted: false, reason: "not_empty" };
|
|
72
|
-
}
|
|
73
|
-
await collections.channels.deleteMany({ id }, mongoSessionOptions(session));
|
|
74
|
-
return { deleted: true };
|
|
75
|
-
},
|
|
76
|
-
insertChannel: async (input) => {
|
|
77
|
-
const result = await collections.channels.updateOne(
|
|
78
|
-
{ name: input.row.name },
|
|
79
|
-
{ $setOnInsert: input.row },
|
|
80
|
-
{ upsert: true, ...mongoSessionOptions(session) },
|
|
81
|
-
);
|
|
82
|
-
const row = await collections.channels.findOne(
|
|
83
|
-
{ name: input.row.name },
|
|
84
|
-
mongoSessionOptions(session),
|
|
85
|
-
);
|
|
86
|
-
if (row === null) {
|
|
87
|
-
throw new MongoAdapterConstraintError("channels.insert.return-existing");
|
|
88
|
-
}
|
|
89
|
-
return { row, inserted: result.upsertedCount === 1 };
|
|
90
|
-
},
|
|
91
|
-
create: async (input) => {
|
|
92
|
-
switch (input.model) {
|
|
93
|
-
case "bundles":
|
|
94
|
-
await collections.bundles.insertOne(
|
|
95
|
-
input.data,
|
|
96
|
-
mongoSessionOptions(session),
|
|
97
|
-
);
|
|
98
|
-
return input.data;
|
|
99
|
-
case "bundle_patches":
|
|
100
|
-
await assertPatchReferences(collections.bundles, input.data, session);
|
|
101
|
-
await collections.bundlePatches.insertOne(
|
|
102
|
-
input.data,
|
|
103
|
-
mongoSessionOptions(session),
|
|
104
|
-
);
|
|
105
|
-
try {
|
|
106
|
-
await assertPatchReferences(collections.bundles, input.data, session);
|
|
107
|
-
} catch (error) {
|
|
108
|
-
await collections.bundlePatches.deleteMany(
|
|
109
|
-
{ id: input.data.id },
|
|
110
|
-
mongoSessionOptions(session),
|
|
111
|
-
);
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
return input.data;
|
|
115
|
-
case "bundle_events":
|
|
116
|
-
await collections.bundleEvents.insertOne(
|
|
117
|
-
input.data,
|
|
118
|
-
mongoSessionOptions(session),
|
|
119
|
-
);
|
|
120
|
-
return input.data;
|
|
121
|
-
case "bundle_installations":
|
|
122
|
-
if (input.onConflict === "ignore") {
|
|
123
|
-
await collections.bundleInstallations.updateOne(
|
|
124
|
-
{ install_id: input.data.install_id },
|
|
125
|
-
{ $setOnInsert: input.data },
|
|
126
|
-
{ upsert: true, ...mongoSessionOptions(session) },
|
|
127
|
-
);
|
|
128
|
-
return input.data;
|
|
129
|
-
}
|
|
130
|
-
await collections.bundleInstallations.insertOne(
|
|
131
|
-
input.data,
|
|
132
|
-
mongoSessionOptions(session),
|
|
133
|
-
);
|
|
134
|
-
return input.data;
|
|
135
|
-
case "releases":
|
|
136
|
-
await collections.releases.insertOne(
|
|
137
|
-
input.data,
|
|
138
|
-
mongoSessionOptions(session),
|
|
139
|
-
);
|
|
140
|
-
return input.data;
|
|
141
|
-
case "release_catalogs":
|
|
142
|
-
await collections.releaseCatalogs.insertOne(
|
|
143
|
-
input.data,
|
|
144
|
-
mongoSessionOptions(session),
|
|
145
|
-
);
|
|
146
|
-
return input.data;
|
|
147
|
-
case "api_keys":
|
|
148
|
-
if (input.onConflict === "ignore") {
|
|
149
|
-
await collections.apiKeys.updateOne(
|
|
150
|
-
{ hash: input.data.hash },
|
|
151
|
-
{ $setOnInsert: input.data },
|
|
152
|
-
{ upsert: true, ...mongoSessionOptions(session) },
|
|
153
|
-
);
|
|
154
|
-
return input.data;
|
|
155
|
-
}
|
|
156
|
-
await collections.apiKeys.insertOne(
|
|
157
|
-
input.data,
|
|
158
|
-
mongoSessionOptions(session),
|
|
159
|
-
);
|
|
160
|
-
return input.data;
|
|
161
|
-
case "channels":
|
|
162
|
-
if (input.onConflict === "ignore") {
|
|
163
|
-
await collections.channels.updateOne(
|
|
164
|
-
{ name: input.data.name },
|
|
165
|
-
{ $setOnInsert: input.data },
|
|
166
|
-
{ upsert: true, ...mongoSessionOptions(session) },
|
|
167
|
-
);
|
|
168
|
-
return input.data;
|
|
169
|
-
}
|
|
170
|
-
await collections.channels.insertOne(
|
|
171
|
-
input.data,
|
|
172
|
-
mongoSessionOptions(session),
|
|
173
|
-
);
|
|
174
|
-
return input.data;
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
update: async (input) => {
|
|
178
|
-
if (input.model === "bundle_installations") {
|
|
179
|
-
return collections.bundleInstallations.findOneAndUpdate(
|
|
180
|
-
createMongoInstallationWhere(input.where),
|
|
181
|
-
{ $set: input.update },
|
|
182
|
-
{
|
|
183
|
-
projection: WITHOUT_MONGO_ID,
|
|
184
|
-
returnDocument: "after",
|
|
185
|
-
...mongoSessionOptions(session),
|
|
186
|
-
},
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
if (input.model === "api_keys") {
|
|
190
|
-
return collections.apiKeys.findOneAndUpdate(
|
|
191
|
-
createMongoApiKeyWhere(input.where),
|
|
192
|
-
{ $set: input.update },
|
|
193
|
-
{
|
|
194
|
-
projection: WITHOUT_INTERNAL_FIELDS,
|
|
195
|
-
returnDocument: "after",
|
|
196
|
-
...mongoSessionOptions(session),
|
|
197
|
-
},
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
if (input.model === "releases") {
|
|
201
|
-
return collections.releases.findOneAndUpdate(
|
|
202
|
-
createMongoReleaseWhere(input.where),
|
|
203
|
-
{ $set: input.update },
|
|
204
|
-
{
|
|
205
|
-
projection: WITHOUT_INTERNAL_FIELDS,
|
|
206
|
-
returnDocument: "after",
|
|
207
|
-
...mongoSessionOptions(session),
|
|
208
|
-
},
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
if (input.model === "release_catalogs") {
|
|
212
|
-
return collections.releaseCatalogs.findOneAndUpdate(
|
|
213
|
-
createMongoReleaseCatalogWhere(input.where),
|
|
214
|
-
{ $set: input.update },
|
|
215
|
-
{
|
|
216
|
-
projection: WITHOUT_INTERNAL_FIELDS,
|
|
217
|
-
returnDocument: "after",
|
|
218
|
-
...mongoSessionOptions(session),
|
|
219
|
-
},
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
return collections.bundles.findOneAndUpdate(
|
|
223
|
-
activeBundleFilter(createMongoBundleWhere(input.where)),
|
|
224
|
-
{ $set: input.update },
|
|
225
|
-
{
|
|
226
|
-
projection: WITHOUT_INTERNAL_FIELDS,
|
|
227
|
-
returnDocument: "after",
|
|
228
|
-
...mongoSessionOptions(session),
|
|
229
|
-
},
|
|
230
|
-
);
|
|
231
|
-
},
|
|
232
|
-
delete: async (input) => {
|
|
233
|
-
switch (input.model) {
|
|
234
|
-
case "bundle_patches":
|
|
235
|
-
await collections.bundlePatches.deleteMany(
|
|
236
|
-
createMongoPatchWhere(input.where),
|
|
237
|
-
mongoSessionOptions(session),
|
|
238
|
-
);
|
|
239
|
-
return;
|
|
240
|
-
case "bundles": {
|
|
241
|
-
const deletionToken = createUUIDv7();
|
|
242
|
-
await collections.bundles.updateMany(
|
|
243
|
-
createMongoBundleWhere(input.where),
|
|
244
|
-
{ $set: { [DELETION_TOKEN_FIELD]: deletionToken } },
|
|
245
|
-
mongoSessionOptions(session),
|
|
246
|
-
);
|
|
247
|
-
const rows = await collections.bundles
|
|
248
|
-
.find(
|
|
249
|
-
{ [DELETION_TOKEN_FIELD]: deletionToken },
|
|
250
|
-
{
|
|
251
|
-
projection: { _id: 0, id: 1 },
|
|
252
|
-
...mongoSessionOptions(session),
|
|
253
|
-
},
|
|
254
|
-
)
|
|
255
|
-
.toArray();
|
|
256
|
-
const ids = rows.map(({ id }) => id);
|
|
257
|
-
if (ids.length === 0) return;
|
|
258
|
-
await collections.bundlePatches.deleteMany(
|
|
259
|
-
{
|
|
260
|
-
$or: [
|
|
261
|
-
{ bundle_id: { $in: ids } },
|
|
262
|
-
{ base_bundle_id: { $in: ids } },
|
|
263
|
-
],
|
|
264
|
-
},
|
|
265
|
-
mongoSessionOptions(session),
|
|
266
|
-
);
|
|
267
|
-
await collections.bundles.deleteMany(
|
|
268
|
-
{ [DELETION_TOKEN_FIELD]: deletionToken },
|
|
269
|
-
mongoSessionOptions(session),
|
|
270
|
-
);
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
case "releases":
|
|
274
|
-
await collections.releases.deleteMany(
|
|
275
|
-
createMongoReleaseWhere(input.where),
|
|
276
|
-
mongoSessionOptions(session),
|
|
277
|
-
);
|
|
278
|
-
return;
|
|
279
|
-
case "channels":
|
|
280
|
-
await collections.channels.deleteMany(
|
|
281
|
-
createMongoChannelWhere(input.where),
|
|
282
|
-
mongoSessionOptions(session),
|
|
283
|
-
);
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
},
|
|
287
|
-
});
|