@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,210 +0,0 @@
|
|
|
1
|
-
import { hasNullOrderOverrides, sortRowsByOrder } from "./databasePluginUtils.mjs";
|
|
2
|
-
import { WITHOUT_INTERNAL_FIELDS, WITHOUT_MONGO_ID, activeBundleFilter, mongoSessionOptions } from "./mongodbCollections.mjs";
|
|
3
|
-
import { createMongoApiKeyWhere, createMongoBundleWhere, createMongoChannelWhere, createMongoEventWhere, createMongoInstallationWhere, createMongoPatchWhere, createMongoReleaseCatalogWhere, createMongoReleaseWhere, createMongoSort } from "./mongodbQuery.mjs";
|
|
4
|
-
import { DatabasePluginInputError } from "@hot-updater/plugin-core";
|
|
5
|
-
//#region src/adapters/mongodbReads.ts
|
|
6
|
-
const findMongoRows = async (collections, input, session) => {
|
|
7
|
-
if (input.limit === 0) return [];
|
|
8
|
-
const rawOrderBy = input.orderBy;
|
|
9
|
-
const needsInMemoryOrder = hasNullOrderOverrides(rawOrderBy);
|
|
10
|
-
switch (input.model) {
|
|
11
|
-
case "bundles": {
|
|
12
|
-
const cursor = collections.bundles.find(activeBundleFilter(createMongoBundleWhere(input.where)), {
|
|
13
|
-
projection: WITHOUT_INTERNAL_FIELDS,
|
|
14
|
-
...mongoSessionOptions(session)
|
|
15
|
-
}).skip(input.offset).limit(input.limit);
|
|
16
|
-
if (rawOrderBy === void 0) return cursor.toArray();
|
|
17
|
-
if (needsInMemoryOrder) {
|
|
18
|
-
const rows = await collections.bundles.find(activeBundleFilter(createMongoBundleWhere(input.where)), {
|
|
19
|
-
projection: WITHOUT_INTERNAL_FIELDS,
|
|
20
|
-
...mongoSessionOptions(session)
|
|
21
|
-
}).toArray();
|
|
22
|
-
return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
23
|
-
}
|
|
24
|
-
const sort = createMongoSort(input);
|
|
25
|
-
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
26
|
-
}
|
|
27
|
-
case "bundle_patches": {
|
|
28
|
-
const cursor = collections.bundlePatches.find(createMongoPatchWhere(input.where), {
|
|
29
|
-
projection: WITHOUT_MONGO_ID,
|
|
30
|
-
...mongoSessionOptions(session)
|
|
31
|
-
}).skip(input.offset).limit(input.limit);
|
|
32
|
-
if (rawOrderBy === void 0) return cursor.toArray();
|
|
33
|
-
if (needsInMemoryOrder) {
|
|
34
|
-
const rows = await collections.bundlePatches.find(createMongoPatchWhere(input.where), {
|
|
35
|
-
projection: WITHOUT_MONGO_ID,
|
|
36
|
-
...mongoSessionOptions(session)
|
|
37
|
-
}).toArray();
|
|
38
|
-
return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
39
|
-
}
|
|
40
|
-
const sort = createMongoSort(input);
|
|
41
|
-
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
42
|
-
}
|
|
43
|
-
case "bundle_events": {
|
|
44
|
-
const cursor = collections.bundleEvents.find(createMongoEventWhere(input.where), {
|
|
45
|
-
projection: WITHOUT_MONGO_ID,
|
|
46
|
-
...mongoSessionOptions(session),
|
|
47
|
-
collation: { locale: "simple" },
|
|
48
|
-
readPreference: "primary"
|
|
49
|
-
}).skip(input.offset).limit(input.limit);
|
|
50
|
-
if (rawOrderBy === void 0) return cursor.toArray();
|
|
51
|
-
if (needsInMemoryOrder) {
|
|
52
|
-
const rows = await collections.bundleEvents.find(createMongoEventWhere(input.where), {
|
|
53
|
-
projection: WITHOUT_MONGO_ID,
|
|
54
|
-
...mongoSessionOptions(session),
|
|
55
|
-
collation: { locale: "simple" },
|
|
56
|
-
readPreference: "primary"
|
|
57
|
-
}).toArray();
|
|
58
|
-
return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
59
|
-
}
|
|
60
|
-
const sort = createMongoSort(input);
|
|
61
|
-
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
62
|
-
}
|
|
63
|
-
case "bundle_installations": {
|
|
64
|
-
const cursor = collections.bundleInstallations.find(createMongoInstallationWhere(input.where), {
|
|
65
|
-
projection: WITHOUT_MONGO_ID,
|
|
66
|
-
...mongoSessionOptions(session),
|
|
67
|
-
collation: { locale: "simple" },
|
|
68
|
-
readPreference: "primary"
|
|
69
|
-
}).skip(input.offset).limit(input.limit);
|
|
70
|
-
if (rawOrderBy === void 0) return cursor.toArray();
|
|
71
|
-
if (needsInMemoryOrder) {
|
|
72
|
-
const rows = await collections.bundleInstallations.find(createMongoInstallationWhere(input.where), {
|
|
73
|
-
projection: WITHOUT_MONGO_ID,
|
|
74
|
-
...mongoSessionOptions(session),
|
|
75
|
-
collation: { locale: "simple" },
|
|
76
|
-
readPreference: "primary"
|
|
77
|
-
}).toArray();
|
|
78
|
-
return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
79
|
-
}
|
|
80
|
-
const sort = createMongoSort(input);
|
|
81
|
-
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
82
|
-
}
|
|
83
|
-
case "api_keys": {
|
|
84
|
-
const cursor = collections.apiKeys.find(createMongoApiKeyWhere(input.where), {
|
|
85
|
-
projection: WITHOUT_MONGO_ID,
|
|
86
|
-
...mongoSessionOptions(session)
|
|
87
|
-
}).skip(input.offset).limit(input.limit);
|
|
88
|
-
if (rawOrderBy === void 0) return cursor.toArray();
|
|
89
|
-
if (needsInMemoryOrder) {
|
|
90
|
-
const rows = await collections.apiKeys.find(createMongoApiKeyWhere(input.where), {
|
|
91
|
-
projection: WITHOUT_MONGO_ID,
|
|
92
|
-
...mongoSessionOptions(session)
|
|
93
|
-
}).toArray();
|
|
94
|
-
return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
95
|
-
}
|
|
96
|
-
const sort = createMongoSort(input);
|
|
97
|
-
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
98
|
-
}
|
|
99
|
-
case "channels": {
|
|
100
|
-
const cursor = collections.channels.find(createMongoChannelWhere(input.where), {
|
|
101
|
-
projection: WITHOUT_MONGO_ID,
|
|
102
|
-
...mongoSessionOptions(session)
|
|
103
|
-
}).skip(input.offset).limit(input.limit);
|
|
104
|
-
if (rawOrderBy === void 0) return cursor.toArray();
|
|
105
|
-
if (needsInMemoryOrder) {
|
|
106
|
-
const rows = await collections.channels.find(createMongoChannelWhere(input.where), {
|
|
107
|
-
projection: WITHOUT_MONGO_ID,
|
|
108
|
-
...mongoSessionOptions(session)
|
|
109
|
-
}).toArray();
|
|
110
|
-
return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
111
|
-
}
|
|
112
|
-
const sort = createMongoSort(input);
|
|
113
|
-
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
114
|
-
}
|
|
115
|
-
case "releases": {
|
|
116
|
-
const cursor = collections.releases.find(createMongoReleaseWhere(input.where), {
|
|
117
|
-
projection: WITHOUT_MONGO_ID,
|
|
118
|
-
...mongoSessionOptions(session)
|
|
119
|
-
}).skip(input.offset).limit(input.limit);
|
|
120
|
-
if (rawOrderBy === void 0) return cursor.toArray();
|
|
121
|
-
if (needsInMemoryOrder) {
|
|
122
|
-
const rows = await collections.releases.find(createMongoReleaseWhere(input.where), {
|
|
123
|
-
projection: WITHOUT_MONGO_ID,
|
|
124
|
-
...mongoSessionOptions(session)
|
|
125
|
-
}).toArray();
|
|
126
|
-
return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
127
|
-
}
|
|
128
|
-
const sort = createMongoSort(input);
|
|
129
|
-
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
130
|
-
}
|
|
131
|
-
case "release_catalogs": {
|
|
132
|
-
const cursor = collections.releaseCatalogs.find(createMongoReleaseCatalogWhere(input.where), {
|
|
133
|
-
projection: WITHOUT_MONGO_ID,
|
|
134
|
-
...mongoSessionOptions(session)
|
|
135
|
-
}).skip(input.offset).limit(input.limit);
|
|
136
|
-
if (rawOrderBy === void 0) return cursor.toArray();
|
|
137
|
-
if (needsInMemoryOrder) {
|
|
138
|
-
const rows = await collections.releaseCatalogs.find(createMongoReleaseCatalogWhere(input.where), {
|
|
139
|
-
projection: WITHOUT_MONGO_ID,
|
|
140
|
-
...mongoSessionOptions(session)
|
|
141
|
-
}).toArray();
|
|
142
|
-
return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
143
|
-
}
|
|
144
|
-
const sort = createMongoSort(input);
|
|
145
|
-
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
const createMongoReads = (collections, session) => ({
|
|
150
|
-
count: async (input) => {
|
|
151
|
-
if (input.distinct !== void 0) throw new DatabasePluginInputError("invalid-operation");
|
|
152
|
-
switch (input.model) {
|
|
153
|
-
case "bundles": return collections.bundles.countDocuments(activeBundleFilter(createMongoBundleWhere(input.where)), mongoSessionOptions(session));
|
|
154
|
-
case "bundle_patches": return collections.bundlePatches.countDocuments(createMongoPatchWhere(input.where), mongoSessionOptions(session));
|
|
155
|
-
case "releases": return collections.releases.countDocuments(createMongoReleaseWhere(input.where), mongoSessionOptions(session));
|
|
156
|
-
case "bundle_installations": return collections.bundleInstallations.countDocuments(createMongoInstallationWhere(input.where), {
|
|
157
|
-
...mongoSessionOptions(session),
|
|
158
|
-
collation: { locale: "simple" },
|
|
159
|
-
readPreference: "primary",
|
|
160
|
-
...session === void 0 ? { readConcern: { level: "snapshot" } } : {}
|
|
161
|
-
});
|
|
162
|
-
case "bundle_events": return collections.bundleEvents.countDocuments(createMongoEventWhere(input.where), {
|
|
163
|
-
...mongoSessionOptions(session),
|
|
164
|
-
collation: { locale: "simple" },
|
|
165
|
-
readPreference: "primary",
|
|
166
|
-
...session === void 0 ? { readConcern: { level: "snapshot" } } : {}
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
findOne: async (input) => {
|
|
171
|
-
switch (input.model) {
|
|
172
|
-
case "bundles": return collections.bundles.findOne(activeBundleFilter(createMongoBundleWhere(input.where)), {
|
|
173
|
-
projection: WITHOUT_INTERNAL_FIELDS,
|
|
174
|
-
...mongoSessionOptions(session)
|
|
175
|
-
});
|
|
176
|
-
case "channels": return collections.channels.findOne(createMongoChannelWhere(input.where), {
|
|
177
|
-
projection: WITHOUT_MONGO_ID,
|
|
178
|
-
...mongoSessionOptions(session)
|
|
179
|
-
});
|
|
180
|
-
case "api_keys": return collections.apiKeys.findOne(createMongoApiKeyWhere(input.where), {
|
|
181
|
-
projection: WITHOUT_MONGO_ID,
|
|
182
|
-
...mongoSessionOptions(session)
|
|
183
|
-
});
|
|
184
|
-
case "bundle_patches": return collections.bundlePatches.findOne(createMongoPatchWhere(input.where), {
|
|
185
|
-
projection: WITHOUT_MONGO_ID,
|
|
186
|
-
...mongoSessionOptions(session)
|
|
187
|
-
});
|
|
188
|
-
case "releases": return collections.releases.findOne(createMongoReleaseWhere(input.where), {
|
|
189
|
-
projection: WITHOUT_MONGO_ID,
|
|
190
|
-
...mongoSessionOptions(session)
|
|
191
|
-
});
|
|
192
|
-
case "release_catalogs": return collections.releaseCatalogs.findOne(createMongoReleaseCatalogWhere(input.where), {
|
|
193
|
-
projection: WITHOUT_MONGO_ID,
|
|
194
|
-
...mongoSessionOptions(session)
|
|
195
|
-
});
|
|
196
|
-
case "bundle_installations": return collections.bundleInstallations.findOne(createMongoInstallationWhere(input.where), {
|
|
197
|
-
projection: WITHOUT_MONGO_ID,
|
|
198
|
-
...mongoSessionOptions(session),
|
|
199
|
-
collation: { locale: "simple" },
|
|
200
|
-
readPreference: "primary"
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
},
|
|
204
|
-
findMany: (input) => {
|
|
205
|
-
if (input.distinctOn !== void 0) throw new DatabasePluginInputError("invalid-operation");
|
|
206
|
-
return findMongoRows(collections, input, session);
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
//#endregion
|
|
210
|
-
export { createMongoReads };
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
const require_mongodbCollections = require("./mongodbCollections.cjs");
|
|
2
|
-
const require_mongodbQuery = require("./mongodbQuery.cjs");
|
|
3
|
-
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
4
|
-
//#region src/adapters/mongodbWrites.ts
|
|
5
|
-
const assertPatchReferences = async (bundles, patch, session) => {
|
|
6
|
-
const ids = Array.from(/* @__PURE__ */ new Set([patch.bundle_id, patch.base_bundle_id]));
|
|
7
|
-
if (await bundles.countDocuments(require_mongodbCollections.activeBundleFilter({ id: { $in: ids } }), require_mongodbCollections.mongoSessionOptions(session)) !== ids.length) throw new require_mongodbCollections.MongoAdapterConstraintError(`patch "${patch.id}" references a missing bundle`);
|
|
8
|
-
};
|
|
9
|
-
const createMongoWrites = (collections, session) => ({
|
|
10
|
-
deleteChannel: async ({ id }) => {
|
|
11
|
-
if (session === void 0) throw new require_mongodbCollections.MongoAdapterConstraintError("channel deletion requires transaction support");
|
|
12
|
-
if ((await collections.channels.updateOne({ id }, { $set: { id } }, require_mongodbCollections.mongoSessionOptions(session))).matchedCount !== 1) return {
|
|
13
|
-
deleted: false,
|
|
14
|
-
reason: "not_found"
|
|
15
|
-
};
|
|
16
|
-
if (await collections.releases.countDocuments({ channel_id: id }, require_mongodbCollections.mongoSessionOptions(session)) > 0) return {
|
|
17
|
-
deleted: false,
|
|
18
|
-
reason: "not_empty"
|
|
19
|
-
};
|
|
20
|
-
await collections.channels.deleteMany({ id }, require_mongodbCollections.mongoSessionOptions(session));
|
|
21
|
-
return { deleted: true };
|
|
22
|
-
},
|
|
23
|
-
insertChannel: async (input) => {
|
|
24
|
-
const result = await collections.channels.updateOne({ name: input.row.name }, { $setOnInsert: input.row }, {
|
|
25
|
-
upsert: true,
|
|
26
|
-
...require_mongodbCollections.mongoSessionOptions(session)
|
|
27
|
-
});
|
|
28
|
-
const row = await collections.channels.findOne({ name: input.row.name }, require_mongodbCollections.mongoSessionOptions(session));
|
|
29
|
-
if (row === null) throw new require_mongodbCollections.MongoAdapterConstraintError("channels.insert.return-existing");
|
|
30
|
-
return {
|
|
31
|
-
row,
|
|
32
|
-
inserted: result.upsertedCount === 1
|
|
33
|
-
};
|
|
34
|
-
},
|
|
35
|
-
create: async (input) => {
|
|
36
|
-
switch (input.model) {
|
|
37
|
-
case "bundles":
|
|
38
|
-
await collections.bundles.insertOne(input.data, require_mongodbCollections.mongoSessionOptions(session));
|
|
39
|
-
return input.data;
|
|
40
|
-
case "bundle_patches":
|
|
41
|
-
await assertPatchReferences(collections.bundles, input.data, session);
|
|
42
|
-
await collections.bundlePatches.insertOne(input.data, require_mongodbCollections.mongoSessionOptions(session));
|
|
43
|
-
try {
|
|
44
|
-
await assertPatchReferences(collections.bundles, input.data, session);
|
|
45
|
-
} catch (error) {
|
|
46
|
-
await collections.bundlePatches.deleteMany({ id: input.data.id }, require_mongodbCollections.mongoSessionOptions(session));
|
|
47
|
-
throw error;
|
|
48
|
-
}
|
|
49
|
-
return input.data;
|
|
50
|
-
case "bundle_events":
|
|
51
|
-
await collections.bundleEvents.insertOne(input.data, require_mongodbCollections.mongoSessionOptions(session));
|
|
52
|
-
return input.data;
|
|
53
|
-
case "bundle_installations":
|
|
54
|
-
if (input.onConflict === "ignore") {
|
|
55
|
-
await collections.bundleInstallations.updateOne({ install_id: input.data.install_id }, { $setOnInsert: input.data }, {
|
|
56
|
-
upsert: true,
|
|
57
|
-
...require_mongodbCollections.mongoSessionOptions(session)
|
|
58
|
-
});
|
|
59
|
-
return input.data;
|
|
60
|
-
}
|
|
61
|
-
await collections.bundleInstallations.insertOne(input.data, require_mongodbCollections.mongoSessionOptions(session));
|
|
62
|
-
return input.data;
|
|
63
|
-
case "releases":
|
|
64
|
-
await collections.releases.insertOne(input.data, require_mongodbCollections.mongoSessionOptions(session));
|
|
65
|
-
return input.data;
|
|
66
|
-
case "release_catalogs":
|
|
67
|
-
await collections.releaseCatalogs.insertOne(input.data, require_mongodbCollections.mongoSessionOptions(session));
|
|
68
|
-
return input.data;
|
|
69
|
-
case "api_keys":
|
|
70
|
-
if (input.onConflict === "ignore") {
|
|
71
|
-
await collections.apiKeys.updateOne({ hash: input.data.hash }, { $setOnInsert: input.data }, {
|
|
72
|
-
upsert: true,
|
|
73
|
-
...require_mongodbCollections.mongoSessionOptions(session)
|
|
74
|
-
});
|
|
75
|
-
return input.data;
|
|
76
|
-
}
|
|
77
|
-
await collections.apiKeys.insertOne(input.data, require_mongodbCollections.mongoSessionOptions(session));
|
|
78
|
-
return input.data;
|
|
79
|
-
case "channels":
|
|
80
|
-
if (input.onConflict === "ignore") {
|
|
81
|
-
await collections.channels.updateOne({ name: input.data.name }, { $setOnInsert: input.data }, {
|
|
82
|
-
upsert: true,
|
|
83
|
-
...require_mongodbCollections.mongoSessionOptions(session)
|
|
84
|
-
});
|
|
85
|
-
return input.data;
|
|
86
|
-
}
|
|
87
|
-
await collections.channels.insertOne(input.data, require_mongodbCollections.mongoSessionOptions(session));
|
|
88
|
-
return input.data;
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
update: async (input) => {
|
|
92
|
-
if (input.model === "bundle_installations") return collections.bundleInstallations.findOneAndUpdate(require_mongodbQuery.createMongoInstallationWhere(input.where), { $set: input.update }, {
|
|
93
|
-
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
94
|
-
returnDocument: "after",
|
|
95
|
-
...require_mongodbCollections.mongoSessionOptions(session)
|
|
96
|
-
});
|
|
97
|
-
if (input.model === "api_keys") return collections.apiKeys.findOneAndUpdate(require_mongodbQuery.createMongoApiKeyWhere(input.where), { $set: input.update }, {
|
|
98
|
-
projection: require_mongodbCollections.WITHOUT_INTERNAL_FIELDS,
|
|
99
|
-
returnDocument: "after",
|
|
100
|
-
...require_mongodbCollections.mongoSessionOptions(session)
|
|
101
|
-
});
|
|
102
|
-
if (input.model === "releases") return collections.releases.findOneAndUpdate(require_mongodbQuery.createMongoReleaseWhere(input.where), { $set: input.update }, {
|
|
103
|
-
projection: require_mongodbCollections.WITHOUT_INTERNAL_FIELDS,
|
|
104
|
-
returnDocument: "after",
|
|
105
|
-
...require_mongodbCollections.mongoSessionOptions(session)
|
|
106
|
-
});
|
|
107
|
-
if (input.model === "release_catalogs") return collections.releaseCatalogs.findOneAndUpdate(require_mongodbQuery.createMongoReleaseCatalogWhere(input.where), { $set: input.update }, {
|
|
108
|
-
projection: require_mongodbCollections.WITHOUT_INTERNAL_FIELDS,
|
|
109
|
-
returnDocument: "after",
|
|
110
|
-
...require_mongodbCollections.mongoSessionOptions(session)
|
|
111
|
-
});
|
|
112
|
-
return collections.bundles.findOneAndUpdate(require_mongodbCollections.activeBundleFilter(require_mongodbQuery.createMongoBundleWhere(input.where)), { $set: input.update }, {
|
|
113
|
-
projection: require_mongodbCollections.WITHOUT_INTERNAL_FIELDS,
|
|
114
|
-
returnDocument: "after",
|
|
115
|
-
...require_mongodbCollections.mongoSessionOptions(session)
|
|
116
|
-
});
|
|
117
|
-
},
|
|
118
|
-
delete: async (input) => {
|
|
119
|
-
switch (input.model) {
|
|
120
|
-
case "bundle_patches":
|
|
121
|
-
await collections.bundlePatches.deleteMany(require_mongodbQuery.createMongoPatchWhere(input.where), require_mongodbCollections.mongoSessionOptions(session));
|
|
122
|
-
return;
|
|
123
|
-
case "bundles": {
|
|
124
|
-
const deletionToken = (0, _hot_updater_plugin_core.createUUIDv7)();
|
|
125
|
-
await collections.bundles.updateMany(require_mongodbQuery.createMongoBundleWhere(input.where), { $set: { [require_mongodbCollections.DELETION_TOKEN_FIELD]: deletionToken } }, require_mongodbCollections.mongoSessionOptions(session));
|
|
126
|
-
const ids = (await collections.bundles.find({ [require_mongodbCollections.DELETION_TOKEN_FIELD]: deletionToken }, {
|
|
127
|
-
projection: {
|
|
128
|
-
_id: 0,
|
|
129
|
-
id: 1
|
|
130
|
-
},
|
|
131
|
-
...require_mongodbCollections.mongoSessionOptions(session)
|
|
132
|
-
}).toArray()).map(({ id }) => id);
|
|
133
|
-
if (ids.length === 0) return;
|
|
134
|
-
await collections.bundlePatches.deleteMany({ $or: [{ bundle_id: { $in: ids } }, { base_bundle_id: { $in: ids } }] }, require_mongodbCollections.mongoSessionOptions(session));
|
|
135
|
-
await collections.bundles.deleteMany({ [require_mongodbCollections.DELETION_TOKEN_FIELD]: deletionToken }, require_mongodbCollections.mongoSessionOptions(session));
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
case "releases":
|
|
139
|
-
await collections.releases.deleteMany(require_mongodbQuery.createMongoReleaseWhere(input.where), require_mongodbCollections.mongoSessionOptions(session));
|
|
140
|
-
return;
|
|
141
|
-
case "channels":
|
|
142
|
-
await collections.channels.deleteMany(require_mongodbQuery.createMongoChannelWhere(input.where), require_mongodbCollections.mongoSessionOptions(session));
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
//#endregion
|
|
148
|
-
exports.createMongoWrites = createMongoWrites;
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { DELETION_TOKEN_FIELD, MongoAdapterConstraintError, WITHOUT_INTERNAL_FIELDS, WITHOUT_MONGO_ID, activeBundleFilter, mongoSessionOptions } from "./mongodbCollections.mjs";
|
|
2
|
-
import { createMongoApiKeyWhere, createMongoBundleWhere, createMongoChannelWhere, createMongoInstallationWhere, createMongoPatchWhere, createMongoReleaseCatalogWhere, createMongoReleaseWhere } from "./mongodbQuery.mjs";
|
|
3
|
-
import { createUUIDv7 } from "@hot-updater/plugin-core";
|
|
4
|
-
//#region src/adapters/mongodbWrites.ts
|
|
5
|
-
const assertPatchReferences = async (bundles, patch, session) => {
|
|
6
|
-
const ids = Array.from(/* @__PURE__ */ new Set([patch.bundle_id, patch.base_bundle_id]));
|
|
7
|
-
if (await bundles.countDocuments(activeBundleFilter({ id: { $in: ids } }), mongoSessionOptions(session)) !== ids.length) throw new MongoAdapterConstraintError(`patch "${patch.id}" references a missing bundle`);
|
|
8
|
-
};
|
|
9
|
-
const createMongoWrites = (collections, session) => ({
|
|
10
|
-
deleteChannel: async ({ id }) => {
|
|
11
|
-
if (session === void 0) throw new MongoAdapterConstraintError("channel deletion requires transaction support");
|
|
12
|
-
if ((await collections.channels.updateOne({ id }, { $set: { id } }, mongoSessionOptions(session))).matchedCount !== 1) return {
|
|
13
|
-
deleted: false,
|
|
14
|
-
reason: "not_found"
|
|
15
|
-
};
|
|
16
|
-
if (await collections.releases.countDocuments({ channel_id: id }, mongoSessionOptions(session)) > 0) return {
|
|
17
|
-
deleted: false,
|
|
18
|
-
reason: "not_empty"
|
|
19
|
-
};
|
|
20
|
-
await collections.channels.deleteMany({ id }, mongoSessionOptions(session));
|
|
21
|
-
return { deleted: true };
|
|
22
|
-
},
|
|
23
|
-
insertChannel: async (input) => {
|
|
24
|
-
const result = await collections.channels.updateOne({ name: input.row.name }, { $setOnInsert: input.row }, {
|
|
25
|
-
upsert: true,
|
|
26
|
-
...mongoSessionOptions(session)
|
|
27
|
-
});
|
|
28
|
-
const row = await collections.channels.findOne({ name: input.row.name }, mongoSessionOptions(session));
|
|
29
|
-
if (row === null) throw new MongoAdapterConstraintError("channels.insert.return-existing");
|
|
30
|
-
return {
|
|
31
|
-
row,
|
|
32
|
-
inserted: result.upsertedCount === 1
|
|
33
|
-
};
|
|
34
|
-
},
|
|
35
|
-
create: async (input) => {
|
|
36
|
-
switch (input.model) {
|
|
37
|
-
case "bundles":
|
|
38
|
-
await collections.bundles.insertOne(input.data, mongoSessionOptions(session));
|
|
39
|
-
return input.data;
|
|
40
|
-
case "bundle_patches":
|
|
41
|
-
await assertPatchReferences(collections.bundles, input.data, session);
|
|
42
|
-
await collections.bundlePatches.insertOne(input.data, mongoSessionOptions(session));
|
|
43
|
-
try {
|
|
44
|
-
await assertPatchReferences(collections.bundles, input.data, session);
|
|
45
|
-
} catch (error) {
|
|
46
|
-
await collections.bundlePatches.deleteMany({ id: input.data.id }, mongoSessionOptions(session));
|
|
47
|
-
throw error;
|
|
48
|
-
}
|
|
49
|
-
return input.data;
|
|
50
|
-
case "bundle_events":
|
|
51
|
-
await collections.bundleEvents.insertOne(input.data, mongoSessionOptions(session));
|
|
52
|
-
return input.data;
|
|
53
|
-
case "bundle_installations":
|
|
54
|
-
if (input.onConflict === "ignore") {
|
|
55
|
-
await collections.bundleInstallations.updateOne({ install_id: input.data.install_id }, { $setOnInsert: input.data }, {
|
|
56
|
-
upsert: true,
|
|
57
|
-
...mongoSessionOptions(session)
|
|
58
|
-
});
|
|
59
|
-
return input.data;
|
|
60
|
-
}
|
|
61
|
-
await collections.bundleInstallations.insertOne(input.data, mongoSessionOptions(session));
|
|
62
|
-
return input.data;
|
|
63
|
-
case "releases":
|
|
64
|
-
await collections.releases.insertOne(input.data, mongoSessionOptions(session));
|
|
65
|
-
return input.data;
|
|
66
|
-
case "release_catalogs":
|
|
67
|
-
await collections.releaseCatalogs.insertOne(input.data, mongoSessionOptions(session));
|
|
68
|
-
return input.data;
|
|
69
|
-
case "api_keys":
|
|
70
|
-
if (input.onConflict === "ignore") {
|
|
71
|
-
await collections.apiKeys.updateOne({ hash: input.data.hash }, { $setOnInsert: input.data }, {
|
|
72
|
-
upsert: true,
|
|
73
|
-
...mongoSessionOptions(session)
|
|
74
|
-
});
|
|
75
|
-
return input.data;
|
|
76
|
-
}
|
|
77
|
-
await collections.apiKeys.insertOne(input.data, mongoSessionOptions(session));
|
|
78
|
-
return input.data;
|
|
79
|
-
case "channels":
|
|
80
|
-
if (input.onConflict === "ignore") {
|
|
81
|
-
await collections.channels.updateOne({ name: input.data.name }, { $setOnInsert: input.data }, {
|
|
82
|
-
upsert: true,
|
|
83
|
-
...mongoSessionOptions(session)
|
|
84
|
-
});
|
|
85
|
-
return input.data;
|
|
86
|
-
}
|
|
87
|
-
await collections.channels.insertOne(input.data, mongoSessionOptions(session));
|
|
88
|
-
return input.data;
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
update: async (input) => {
|
|
92
|
-
if (input.model === "bundle_installations") return collections.bundleInstallations.findOneAndUpdate(createMongoInstallationWhere(input.where), { $set: input.update }, {
|
|
93
|
-
projection: WITHOUT_MONGO_ID,
|
|
94
|
-
returnDocument: "after",
|
|
95
|
-
...mongoSessionOptions(session)
|
|
96
|
-
});
|
|
97
|
-
if (input.model === "api_keys") return collections.apiKeys.findOneAndUpdate(createMongoApiKeyWhere(input.where), { $set: input.update }, {
|
|
98
|
-
projection: WITHOUT_INTERNAL_FIELDS,
|
|
99
|
-
returnDocument: "after",
|
|
100
|
-
...mongoSessionOptions(session)
|
|
101
|
-
});
|
|
102
|
-
if (input.model === "releases") return collections.releases.findOneAndUpdate(createMongoReleaseWhere(input.where), { $set: input.update }, {
|
|
103
|
-
projection: WITHOUT_INTERNAL_FIELDS,
|
|
104
|
-
returnDocument: "after",
|
|
105
|
-
...mongoSessionOptions(session)
|
|
106
|
-
});
|
|
107
|
-
if (input.model === "release_catalogs") return collections.releaseCatalogs.findOneAndUpdate(createMongoReleaseCatalogWhere(input.where), { $set: input.update }, {
|
|
108
|
-
projection: WITHOUT_INTERNAL_FIELDS,
|
|
109
|
-
returnDocument: "after",
|
|
110
|
-
...mongoSessionOptions(session)
|
|
111
|
-
});
|
|
112
|
-
return collections.bundles.findOneAndUpdate(activeBundleFilter(createMongoBundleWhere(input.where)), { $set: input.update }, {
|
|
113
|
-
projection: WITHOUT_INTERNAL_FIELDS,
|
|
114
|
-
returnDocument: "after",
|
|
115
|
-
...mongoSessionOptions(session)
|
|
116
|
-
});
|
|
117
|
-
},
|
|
118
|
-
delete: async (input) => {
|
|
119
|
-
switch (input.model) {
|
|
120
|
-
case "bundle_patches":
|
|
121
|
-
await collections.bundlePatches.deleteMany(createMongoPatchWhere(input.where), mongoSessionOptions(session));
|
|
122
|
-
return;
|
|
123
|
-
case "bundles": {
|
|
124
|
-
const deletionToken = createUUIDv7();
|
|
125
|
-
await collections.bundles.updateMany(createMongoBundleWhere(input.where), { $set: { [DELETION_TOKEN_FIELD]: deletionToken } }, mongoSessionOptions(session));
|
|
126
|
-
const ids = (await collections.bundles.find({ [DELETION_TOKEN_FIELD]: deletionToken }, {
|
|
127
|
-
projection: {
|
|
128
|
-
_id: 0,
|
|
129
|
-
id: 1
|
|
130
|
-
},
|
|
131
|
-
...mongoSessionOptions(session)
|
|
132
|
-
}).toArray()).map(({ id }) => id);
|
|
133
|
-
if (ids.length === 0) return;
|
|
134
|
-
await collections.bundlePatches.deleteMany({ $or: [{ bundle_id: { $in: ids } }, { base_bundle_id: { $in: ids } }] }, mongoSessionOptions(session));
|
|
135
|
-
await collections.bundles.deleteMany({ [DELETION_TOKEN_FIELD]: deletionToken }, mongoSessionOptions(session));
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
case "releases":
|
|
139
|
-
await collections.releases.deleteMany(createMongoReleaseWhere(input.where), mongoSessionOptions(session));
|
|
140
|
-
return;
|
|
141
|
-
case "channels":
|
|
142
|
-
await collections.channels.deleteMany(createMongoChannelWhere(input.where), mongoSessionOptions(session));
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
//#endregion
|
|
148
|
-
export { createMongoWrites };
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
2
|
-
//#region src/adapters/prismaQuery.ts
|
|
3
|
-
const stringFilter = (operator, value, mode) => {
|
|
4
|
-
return {
|
|
5
|
-
[operator === "starts_with" ? "startsWith" : operator === "ends_with" ? "endsWith" : "contains"]: value,
|
|
6
|
-
...mode ? { mode } : {}
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
const SQL_PATTERN_METACHARACTERS = /[%_\\]/u;
|
|
10
|
-
const MONGODB_PATTERN_METACHARACTERS = /[.*+?^${}()|[\]\\]/u;
|
|
11
|
-
const prismaMode = (mode, provider) => {
|
|
12
|
-
if (mode === "insensitive" || mode === "sensitive" && provider !== "postgresql") throw new _hot_updater_plugin_core.DatabasePluginInputError("invalid-operation");
|
|
13
|
-
return mode === "sensitive" ? "default" : void 0;
|
|
14
|
-
};
|
|
15
|
-
const assertLiteralPattern = (value, provider) => {
|
|
16
|
-
if ((provider === "mongodb" ? MONGODB_PATTERN_METACHARACTERS : SQL_PATTERN_METACHARACTERS).test(value)) throw new _hot_updater_plugin_core.DatabasePluginInputError("invalid-operation");
|
|
17
|
-
};
|
|
18
|
-
const predicate = (where, provider) => {
|
|
19
|
-
const mode = prismaMode("mode" in where ? where.mode : void 0, provider);
|
|
20
|
-
switch (where.operator) {
|
|
21
|
-
case void 0:
|
|
22
|
-
case "eq": return { [where.field]: mode ? {
|
|
23
|
-
equals: where.value,
|
|
24
|
-
mode
|
|
25
|
-
} : where.value };
|
|
26
|
-
case "ne": return { [where.field]: {
|
|
27
|
-
not: where.value,
|
|
28
|
-
...mode ? { mode } : {}
|
|
29
|
-
} };
|
|
30
|
-
case "gt":
|
|
31
|
-
case "gte":
|
|
32
|
-
case "lt":
|
|
33
|
-
case "lte": return { [where.field]: { [where.operator]: where.value } };
|
|
34
|
-
case "in": return { [where.field]: { in: where.value } };
|
|
35
|
-
case "not_in": return { [where.field]: { notIn: where.value } };
|
|
36
|
-
case "contains":
|
|
37
|
-
case "starts_with":
|
|
38
|
-
case "ends_with":
|
|
39
|
-
assertLiteralPattern(where.value, provider);
|
|
40
|
-
return { [where.field]: stringFilter(where.operator, where.value, mode) };
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
const createPrismaWhere = (where, provider) => {
|
|
44
|
-
const items = where ?? [];
|
|
45
|
-
const first = items[0];
|
|
46
|
-
if (first === void 0) return {};
|
|
47
|
-
let result = predicate(first, provider);
|
|
48
|
-
for (const item of items.slice(1)) result = { [item.connector === "OR" ? "OR" : "AND"]: [result, predicate(item, provider)] };
|
|
49
|
-
return result;
|
|
50
|
-
};
|
|
51
|
-
const createPrismaOrderBy = (orderBy) => {
|
|
52
|
-
if (orderBy === void 0) return void 0;
|
|
53
|
-
return (Array.isArray(orderBy) ? orderBy : [orderBy]).map((clause) => ({ [clause.field]: clause.direction }));
|
|
54
|
-
};
|
|
55
|
-
//#endregion
|
|
56
|
-
exports.createPrismaOrderBy = createPrismaOrderBy;
|
|
57
|
-
exports.createPrismaWhere = createPrismaWhere;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { DatabasePluginInputError } from "@hot-updater/plugin-core";
|
|
2
|
-
//#region src/adapters/prismaQuery.ts
|
|
3
|
-
const stringFilter = (operator, value, mode) => {
|
|
4
|
-
return {
|
|
5
|
-
[operator === "starts_with" ? "startsWith" : operator === "ends_with" ? "endsWith" : "contains"]: value,
|
|
6
|
-
...mode ? { mode } : {}
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
const SQL_PATTERN_METACHARACTERS = /[%_\\]/u;
|
|
10
|
-
const MONGODB_PATTERN_METACHARACTERS = /[.*+?^${}()|[\]\\]/u;
|
|
11
|
-
const prismaMode = (mode, provider) => {
|
|
12
|
-
if (mode === "insensitive" || mode === "sensitive" && provider !== "postgresql") throw new DatabasePluginInputError("invalid-operation");
|
|
13
|
-
return mode === "sensitive" ? "default" : void 0;
|
|
14
|
-
};
|
|
15
|
-
const assertLiteralPattern = (value, provider) => {
|
|
16
|
-
if ((provider === "mongodb" ? MONGODB_PATTERN_METACHARACTERS : SQL_PATTERN_METACHARACTERS).test(value)) throw new DatabasePluginInputError("invalid-operation");
|
|
17
|
-
};
|
|
18
|
-
const predicate = (where, provider) => {
|
|
19
|
-
const mode = prismaMode("mode" in where ? where.mode : void 0, provider);
|
|
20
|
-
switch (where.operator) {
|
|
21
|
-
case void 0:
|
|
22
|
-
case "eq": return { [where.field]: mode ? {
|
|
23
|
-
equals: where.value,
|
|
24
|
-
mode
|
|
25
|
-
} : where.value };
|
|
26
|
-
case "ne": return { [where.field]: {
|
|
27
|
-
not: where.value,
|
|
28
|
-
...mode ? { mode } : {}
|
|
29
|
-
} };
|
|
30
|
-
case "gt":
|
|
31
|
-
case "gte":
|
|
32
|
-
case "lt":
|
|
33
|
-
case "lte": return { [where.field]: { [where.operator]: where.value } };
|
|
34
|
-
case "in": return { [where.field]: { in: where.value } };
|
|
35
|
-
case "not_in": return { [where.field]: { notIn: where.value } };
|
|
36
|
-
case "contains":
|
|
37
|
-
case "starts_with":
|
|
38
|
-
case "ends_with":
|
|
39
|
-
assertLiteralPattern(where.value, provider);
|
|
40
|
-
return { [where.field]: stringFilter(where.operator, where.value, mode) };
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
const createPrismaWhere = (where, provider) => {
|
|
44
|
-
const items = where ?? [];
|
|
45
|
-
const first = items[0];
|
|
46
|
-
if (first === void 0) return {};
|
|
47
|
-
let result = predicate(first, provider);
|
|
48
|
-
for (const item of items.slice(1)) result = { [item.connector === "OR" ? "OR" : "AND"]: [result, predicate(item, provider)] };
|
|
49
|
-
return result;
|
|
50
|
-
};
|
|
51
|
-
const createPrismaOrderBy = (orderBy) => {
|
|
52
|
-
if (orderBy === void 0) return void 0;
|
|
53
|
-
return (Array.isArray(orderBy) ? orderBy : [orderBy]).map((clause) => ({ [clause.field]: clause.direction }));
|
|
54
|
-
};
|
|
55
|
-
//#endregion
|
|
56
|
-
export { createPrismaOrderBy, createPrismaWhere };
|