@hot-updater/server 0.36.7 → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/databaseConstraintErrors.cjs +23 -0
- package/dist/adapters/databaseConstraintErrors.mjs +21 -0
- package/dist/adapters/databasePluginUtils.cjs +117 -0
- package/dist/adapters/databasePluginUtils.mjs +106 -0
- package/dist/adapters/drizzle.cjs +53 -176
- package/dist/adapters/drizzle.d.cts +6 -4
- package/dist/adapters/drizzle.d.mts +6 -4
- package/dist/adapters/drizzle.mjs +54 -177
- package/dist/adapters/drizzleCrud.cjs +250 -0
- package/dist/adapters/drizzleCrud.mjs +249 -0
- package/dist/adapters/drizzleLazyDB.cjs +84 -36
- package/dist/adapters/drizzleLazyDB.mjs +84 -36
- package/dist/adapters/drizzleQuery.cjs +68 -0
- package/dist/adapters/drizzleQuery.mjs +67 -0
- package/dist/adapters/kysely.cjs +18 -138
- package/dist/adapters/kysely.d.cts +3 -12
- package/dist/adapters/kysely.d.mts +3 -12
- package/dist/adapters/kysely.mjs +19 -139
- package/dist/adapters/kyselyCrud.cjs +254 -0
- package/dist/adapters/kyselyCrud.mjs +253 -0
- package/dist/adapters/kyselyQuery.cjs +56 -0
- package/dist/adapters/kyselyQuery.mjs +55 -0
- package/dist/adapters/mongodb.cjs +21 -174
- package/dist/adapters/mongodb.d.cts +3 -2
- package/dist/adapters/mongodb.d.mts +3 -2
- package/dist/adapters/mongodb.mjs +21 -174
- package/dist/adapters/mongodbCollections.cjs +36 -0
- package/dist/adapters/mongodbCollections.mjs +30 -0
- package/dist/adapters/mongodbQuery.cjs +77 -0
- package/dist/adapters/mongodbQuery.mjs +70 -0
- package/dist/adapters/mongodbReads.cjs +148 -0
- package/dist/adapters/mongodbReads.mjs +147 -0
- package/dist/adapters/mongodbWrites.cjs +134 -0
- package/dist/adapters/mongodbWrites.mjs +133 -0
- package/dist/adapters/prisma.cjs +205 -180
- package/dist/adapters/prisma.d.cts +3 -3
- package/dist/adapters/prisma.d.mts +3 -3
- package/dist/adapters/prisma.mjs +206 -181
- package/dist/adapters/prismaQuery.cjs +58 -0
- package/dist/adapters/prismaQuery.mjs +56 -0
- package/dist/adapters/prismaRows.cjs +198 -0
- package/dist/adapters/prismaRows.mjs +188 -0
- package/dist/apiKeys.cjs +139 -0
- package/dist/apiKeys.d.cts +50 -0
- package/dist/apiKeys.d.mts +50 -0
- package/dist/apiKeys.mjs +133 -0
- package/dist/createHotUpdaterCore.cjs +48 -26
- package/dist/createHotUpdaterCore.d.cts +49 -17
- package/dist/createHotUpdaterCore.d.mts +49 -17
- package/dist/createHotUpdaterCore.mjs +51 -29
- package/dist/db/createBundleDiff.cjs +45 -68
- package/dist/db/createBundleDiff.d.cts +3 -3
- package/dist/db/createBundleDiff.d.mts +3 -3
- package/dist/db/createBundleDiff.mjs +47 -68
- package/dist/db/databasePluginCore.cjs +138 -0
- package/dist/db/databasePluginCore.mjs +137 -0
- package/dist/db/fixedMigrator.cjs +36 -93
- package/dist/db/fixedMigrator.mjs +36 -93
- package/dist/db/fixedMigratorMongo.cjs +319 -0
- package/dist/db/fixedMigratorMongo.mjs +319 -0
- package/dist/db/fixedMigratorShared.cjs +23 -0
- package/dist/db/fixedMigratorShared.mjs +18 -0
- package/dist/db/mongoMigrationExecution.cjs +11 -0
- package/dist/db/mongoMigrationExecution.mjs +11 -0
- package/dist/db/releaseCatalog.cjs +66 -0
- package/dist/db/releaseCatalog.d.cts +17 -0
- package/dist/db/releaseCatalog.d.mts +17 -0
- package/dist/db/releaseCatalog.mjs +64 -0
- package/dist/db/schema/mongodb.cjs +14 -6
- package/dist/db/schema/mongodb.mjs +14 -6
- package/dist/db/schema/registry.cjs +0 -2
- package/dist/db/schema/registry.mjs +1 -2
- package/dist/db/schema/sql.cjs +31 -14
- package/dist/db/schema/sql.mjs +32 -13
- package/dist/db/schema/sqlOperations.cjs +4 -4
- package/dist/db/schema/sqlOperations.mjs +5 -5
- package/dist/db/schemaGenerators.cjs +52 -18
- package/dist/db/schemaGenerators.mjs +52 -18
- package/dist/db/schemaReadiness.cjs +4 -3
- package/dist/db/schemaReadiness.mjs +4 -3
- package/dist/db/sqlMigrationExecution.cjs +67 -0
- package/dist/db/sqlMigrationExecution.mjs +66 -0
- package/dist/db/types.cjs +2 -6
- package/dist/db/types.d.cts +60 -16
- package/dist/db/types.d.mts +60 -16
- package/dist/db/types.mjs +3 -6
- package/dist/db/updateArtifacts.cjs +114 -60
- package/dist/db/updateArtifacts.mjs +117 -62
- package/dist/handler.cjs +108 -282
- package/dist/handler.d.cts +3 -46
- package/dist/handler.d.mts +3 -46
- package/dist/handler.mjs +107 -281
- package/dist/handlerBundleRoutes.cjs +155 -0
- package/dist/handlerBundleRoutes.mjs +155 -0
- package/dist/handlerErrors.cjs +9 -0
- package/dist/handlerErrors.mjs +9 -0
- package/dist/handlerParameters.cjs +39 -0
- package/dist/handlerParameters.mjs +34 -0
- package/dist/handlerReleaseCatalogRoutes.cjs +111 -0
- package/dist/handlerReleaseCatalogRoutes.mjs +110 -0
- package/dist/handlerReleaseManagementRoutes.cjs +125 -0
- package/dist/handlerReleaseManagementRoutes.mjs +124 -0
- package/dist/handlerTypes.d.cts +63 -0
- package/dist/handlerTypes.d.mts +63 -0
- package/dist/handlerVersionRoutes.cjs +10 -0
- package/dist/handlerVersionRoutes.d.cts +4 -0
- package/dist/handlerVersionRoutes.d.mts +4 -0
- package/dist/handlerVersionRoutes.mjs +9 -0
- package/dist/index.cjs +10 -1
- package/dist/index.d.cts +9 -3
- package/dist/index.d.mts +9 -3
- package/dist/index.mjs +5 -2
- package/dist/insights/bounded/activeOverview.cjs +87 -0
- package/dist/insights/bounded/activeOverview.mjs +85 -0
- package/dist/insights/bounded/installationSearch.cjs +42 -0
- package/dist/insights/bounded/installationSearch.mjs +42 -0
- package/dist/insights/bounded/persistence.cjs +39 -0
- package/dist/insights/bounded/persistence.mjs +38 -0
- package/dist/insights/bounded/provider.cjs +170 -0
- package/dist/insights/bounded/provider.d.cts +7 -0
- package/dist/insights/bounded/provider.d.mts +7 -0
- package/dist/insights/bounded/provider.mjs +170 -0
- package/dist/insights/bounded/scan.cjs +144 -0
- package/dist/insights/bounded/scan.mjs +138 -0
- package/dist/insights/domain.d.cts +121 -0
- package/dist/insights/domain.d.mts +121 -0
- package/dist/insights/errors.cjs +22 -0
- package/dist/insights/errors.mjs +20 -0
- package/dist/insights/eventInput.cjs +111 -0
- package/dist/insights/eventInput.mjs +111 -0
- package/dist/insights/persistence.d.cts +6 -0
- package/dist/insights/persistence.d.mts +6 -0
- package/dist/insights/queryInput.cjs +58 -0
- package/dist/insights/queryInput.mjs +55 -0
- package/dist/insights/routes.cjs +63 -0
- package/dist/insights/routes.mjs +61 -0
- package/dist/insights/types.d.cts +17 -0
- package/dist/insights/types.d.mts +17 -0
- package/dist/node.cjs +19 -12
- package/dist/node.d.cts +15 -10
- package/dist/node.d.mts +15 -10
- package/dist/node.mjs +19 -13
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/schema/dsl.cjs +19 -2
- package/dist/schema/dsl.mjs +17 -3
- package/dist/schema/index.cjs +1 -8
- package/dist/schema/index.mjs +2 -8
- package/dist/schema/types.cjs +3 -1
- package/dist/schema/types.mjs +3 -2
- package/dist/schema/v1_0_0.cjs +364 -0
- package/dist/schema/v1_0_0.mjs +357 -0
- package/dist/storageAccess.cjs +69 -25
- package/dist/storageAccess.mjs +68 -25
- package/dist/types/index.d.cts +4 -3
- package/dist/types/index.d.mts +5 -4
- package/package.json +8 -7
- package/src/adapters/databaseConstraintErrors.ts +25 -0
- package/src/adapters/databasePluginTestDatabase.ts +106 -0
- package/src/adapters/databasePluginUtils.spec.ts +29 -0
- package/src/adapters/databasePluginUtils.ts +214 -0
- package/src/adapters/drizzle.spec.ts +208 -47
- package/src/adapters/drizzle.ts +106 -293
- package/src/adapters/drizzleCrud.ts +419 -0
- package/src/adapters/drizzleLazyDB.ts +206 -100
- package/src/adapters/drizzleQuery.ts +164 -0
- package/src/adapters/kysely.spec.ts +126 -88
- package/src/adapters/kysely.ts +76 -334
- package/src/adapters/kyselyCrud.ts +588 -0
- package/src/adapters/kyselyQuery.ts +128 -0
- package/src/adapters/mongodb.spec.ts +141 -0
- package/src/adapters/mongodb.ts +60 -288
- package/src/adapters/mongodbCollections.ts +62 -0
- package/src/adapters/mongodbQuery.ts +226 -0
- package/src/adapters/mongodbReads.ts +311 -0
- package/src/adapters/mongodbRows.spec.ts +64 -0
- package/src/adapters/mongodbRows.ts +118 -0
- package/src/adapters/mongodbTestClient.ts +342 -0
- package/src/adapters/mongodbTestFilter.ts +166 -0
- package/src/adapters/mongodbWrites.ts +260 -0
- package/src/adapters/prisma.spec.ts +196 -0
- package/src/adapters/prisma.ts +417 -292
- package/src/adapters/prismaQuery.ts +129 -0
- package/src/adapters/prismaRows.spec.ts +98 -0
- package/src/adapters/prismaRows.ts +301 -0
- package/src/adapters/prismaTestClient.ts +396 -0
- package/src/apiKeys.integration.spec.ts +192 -0
- package/src/apiKeys.spec.ts +162 -0
- package/src/apiKeys.ts +220 -0
- package/src/createHotUpdaterCore.ts +164 -100
- package/src/db/bundleRows.spec.ts +164 -0
- package/src/db/bundleRows.ts +10 -140
- package/src/db/createBundleDiff.spec.ts +172 -127
- package/src/db/createBundleDiff.ts +91 -110
- package/src/db/databasePluginCore.spec.ts +62 -0
- package/src/db/databasePluginCore.testFixtures.ts +76 -0
- package/src/db/databasePluginCore.ts +185 -0
- package/src/db/databasePluginUpdateCheck.bench.ts +107 -0
- package/src/db/fixedMigrator.spec.ts +184 -42
- package/src/db/fixedMigrator.ts +64 -205
- package/src/db/fixedMigratorMongo.spec.ts +192 -0
- package/src/db/fixedMigratorMongo.ts +425 -0
- package/src/db/fixedMigratorShared.ts +36 -0
- package/src/db/hotUpdaterSchema.ts +0 -1
- package/src/db/index.spec.ts +333 -1025
- package/src/db/mongoMigrationExecution.ts +23 -0
- package/src/db/node-sqlite.d.ts +25 -0
- package/src/db/releaseCatalog.ts +148 -0
- package/src/db/schema/mongodb.ts +20 -6
- package/src/db/schema/sql.ts +52 -11
- package/src/db/schema/sqlOperations.ts +5 -4
- package/src/db/schemaGenerators.ts +107 -23
- package/src/db/schemaReadiness.ts +2 -1
- package/src/db/sqlMigrationExecution.spec.ts +65 -0
- package/src/db/sqlMigrationExecution.ts +108 -0
- package/src/db/types.spec.ts +55 -0
- package/src/db/types.ts +129 -65
- package/src/db/updateArtifacts.spec.ts +359 -0
- package/src/db/updateArtifacts.ts +290 -126
- package/src/handler-standalone.integration.spec.ts +401 -364
- package/src/handler.spec.ts +137 -582
- package/src/handler.testFixtures.ts +30 -0
- package/src/handler.ts +218 -616
- package/src/handlerAuth.integration.spec.ts +33 -0
- package/src/handlerBundleRoutes.ts +259 -0
- package/src/handlerErrors.ts +7 -0
- package/src/handlerManagement.spec.ts +262 -0
- package/src/handlerParameters.ts +105 -0
- package/src/handlerReleaseCatalogRoutes.ts +154 -0
- package/src/handlerReleaseManagementRoutes.ts +213 -0
- package/src/handlerTypes.ts +96 -0
- package/src/handlerVersionRoutes.ts +12 -0
- package/src/index.ts +22 -2
- package/src/insights/bounded/activeOverview.spec.ts +189 -0
- package/src/insights/bounded/activeOverview.ts +148 -0
- package/src/insights/bounded/installationSearch.spec.ts +130 -0
- package/src/insights/bounded/installationSearch.ts +69 -0
- package/src/insights/bounded/persistence.ts +43 -0
- package/src/insights/bounded/provider.spec.ts +219 -0
- package/src/insights/bounded/provider.ts +229 -0
- package/src/insights/bounded/scan.ts +235 -0
- package/src/insights/domain.ts +139 -0
- package/src/insights/errors.ts +18 -0
- package/src/insights/eventInput.ts +168 -0
- package/src/insights/insights.integration.spec.ts +144 -0
- package/src/insights/persistence.ts +10 -0
- package/src/insights/queryInput.ts +102 -0
- package/src/insights/routes.ts +123 -0
- package/src/insights/types.ts +44 -0
- package/src/node.spec.ts +79 -10
- package/src/node.ts +20 -17
- package/src/releaseCatalogRoutes.integration.spec.ts +238 -0
- package/src/runtime.spec.ts +126 -959
- package/src/runtime.testFixtures.ts +71 -0
- package/src/schema/dsl-all-versions.spec.ts +26 -17
- package/src/schema/dsl.ts +41 -2
- package/src/schema/index.ts +3 -9
- package/src/schema/types.ts +9 -3
- package/src/schema/v1_0_0.spec.ts +146 -0
- package/src/schema/v1_0_0.ts +465 -0
- package/src/storageAccess.spec.ts +127 -32
- package/src/storageAccess.ts +106 -55
- package/src/types/index.ts +2 -1
- package/dist/db/bundleRows.cjs +0 -82
- package/dist/db/bundleRows.d.cts +0 -33
- package/dist/db/bundleRows.d.mts +0 -33
- package/dist/db/bundleRows.mjs +0 -79
- package/dist/db/pluginCore.cjs +0 -242
- package/dist/db/pluginCore.mjs +0 -241
- package/dist/db/schema/sqlMigrations.cjs +0 -74
- package/dist/db/schema/sqlMigrations.mjs +0 -73
- package/dist/db/schemaEnhancements.cjs +0 -20
- package/dist/db/schemaEnhancements.mjs +0 -19
- package/dist/route.cjs +0 -7
- package/dist/route.mjs +0 -7
- package/dist/schema/v0_21_0.cjs +0 -38
- package/dist/schema/v0_21_0.mjs +0 -37
- package/dist/schema/v0_29_0.cjs +0 -45
- package/dist/schema/v0_29_0.mjs +0 -44
- package/dist/schema/v0_31_0.cjs +0 -82
- package/dist/schema/v0_31_0.mjs +0 -80
- package/src/db/pluginCore.spec.ts +0 -1095
- package/src/db/pluginCore.ts +0 -475
- package/src/db/pluginUpdateCheck.bench.ts +0 -254
- package/src/db/schema/sqlMigrations.ts +0 -219
- package/src/db/schemaEnhancements.ts +0 -55
- package/src/route.ts +0 -7
- package/src/schema/v0_21_0.ts +0 -52
- package/src/schema/v0_29_0.ts +0 -62
- package/src/schema/v0_31_0.spec.ts +0 -73
- package/src/schema/v0_31_0.ts +0 -120
|
@@ -1,182 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { createMongoMigrator } from "../db/fixedMigratorMongo.mjs";
|
|
2
|
+
import { createMongoCollections } from "./mongodbCollections.mjs";
|
|
3
|
+
import { createMongoReads } from "./mongodbReads.mjs";
|
|
4
|
+
import { createMongoWrites } from "./mongodbWrites.mjs";
|
|
5
|
+
import { createDatabasePlugin } from "@hot-updater/plugin-core";
|
|
6
|
+
import { createDatabasePluginAdapter } from "@hot-updater/plugin-core/internal";
|
|
5
7
|
//#region src/adapters/mongodb.ts
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
...
|
|
10
|
-
...
|
|
11
|
-
...where?.fingerprintHash !== void 0 ? where.fingerprintHash === null ? { fingerprint_hash: { $in: [null, ""] } } : { fingerprint_hash: where.fingerprintHash } : {},
|
|
12
|
-
...where?.id ? { id: {
|
|
13
|
-
...where.id.eq !== void 0 ? { $eq: where.id.eq } : {},
|
|
14
|
-
...where.id.gt !== void 0 ? { $gt: where.id.gt } : {},
|
|
15
|
-
...where.id.gte !== void 0 ? { $gte: where.id.gte } : {},
|
|
16
|
-
...where.id.lt !== void 0 ? { $lt: where.id.lt } : {},
|
|
17
|
-
...where.id.lte !== void 0 ? { $lte: where.id.lte } : {},
|
|
18
|
-
...where.id.in !== void 0 ? { $in: where.id.in } : {}
|
|
19
|
-
} } : {}
|
|
8
|
+
const createMongoImplementation = (client, session) => {
|
|
9
|
+
const collections = createMongoCollections(client);
|
|
10
|
+
return {
|
|
11
|
+
...createMongoWrites(collections, session),
|
|
12
|
+
...createMongoReads(collections, session)
|
|
20
13
|
};
|
|
21
|
-
const targetAppVersionFilters = [];
|
|
22
|
-
if (where?.targetAppVersion !== void 0) targetAppVersionFilters.push(where.targetAppVersion === null ? { target_app_version: { $in: [null, ""] } } : { target_app_version: where.targetAppVersion });
|
|
23
|
-
if (where?.targetAppVersionIn) targetAppVersionFilters.push({ target_app_version: { $in: where.targetAppVersionIn } });
|
|
24
|
-
if (where?.targetAppVersionNotNull) targetAppVersionFilters.push({ target_app_version: {
|
|
25
|
-
$exists: true,
|
|
26
|
-
$nin: [null, ""]
|
|
27
|
-
} });
|
|
28
|
-
const filters = [...Object.keys(baseFilter).length > 0 ? [baseFilter] : [], ...targetAppVersionFilters];
|
|
29
|
-
if (filters.length === 0) return {};
|
|
30
|
-
if (filters.length === 1) return filters[0] ?? {};
|
|
31
|
-
return { $and: filters };
|
|
32
14
|
};
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const bundles = db.collection("bundles");
|
|
38
|
-
const patches = db.collection("bundle_patches");
|
|
39
|
-
const fetchPatchMap = async (bundleIds) => {
|
|
40
|
-
const patchMap = /* @__PURE__ */ new Map();
|
|
41
|
-
if (bundleIds.length === 0) return patchMap;
|
|
42
|
-
const rows = await patches.find({ bundle_id: { $in: [...bundleIds] } }).sort({ order_index: 1 }).toArray();
|
|
43
|
-
for (const row of rows) {
|
|
44
|
-
const current = patchMap.get(row.bundle_id) ?? [];
|
|
45
|
-
current.push(row);
|
|
46
|
-
patchMap.set(row.bundle_id, current);
|
|
47
|
-
}
|
|
48
|
-
return patchMap;
|
|
49
|
-
};
|
|
50
|
-
const mapRowsToBundles = async (rows) => {
|
|
51
|
-
const patchMap = await fetchPatchMap(rows.map((row) => row.id));
|
|
52
|
-
return rows.map((row) => rowToBundle(row, patchMap.get(row.id) ?? []));
|
|
53
|
-
};
|
|
54
|
-
const isTransactionUnsupported = (error) => error instanceof Error && /Transaction numbers are only allowed|replica set member or mongos|Transaction API error/i.test(error.message);
|
|
55
|
-
const runInTransaction = async (operation) => {
|
|
56
|
-
if (typeof client.startSession !== "function") return operation(void 0);
|
|
57
|
-
const session = client.startSession();
|
|
58
|
-
try {
|
|
59
|
-
if (typeof session.withTransaction !== "function") return await operation(session);
|
|
60
|
-
let result;
|
|
61
|
-
await session.withTransaction(async () => {
|
|
62
|
-
result = await operation(session);
|
|
63
|
-
});
|
|
64
|
-
return result;
|
|
65
|
-
} catch (error) {
|
|
66
|
-
if (isTransactionUnsupported(error)) return operation(void 0);
|
|
67
|
-
throw error;
|
|
68
|
-
} finally {
|
|
69
|
-
await session.endSession();
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
const replaceBundle = async (bundle, session) => {
|
|
73
|
-
const row = bundleToRow(bundle);
|
|
74
|
-
await bundles.updateOne({ id: bundle.id }, { $set: row }, {
|
|
75
|
-
session,
|
|
76
|
-
upsert: true
|
|
77
|
-
});
|
|
78
|
-
await patches.deleteMany({ bundle_id: bundle.id }, { session });
|
|
79
|
-
const patchRows = bundleToPatchRows(bundle);
|
|
80
|
-
if (patchRows.length > 0) await patches.insertMany(patchRows, { session });
|
|
81
|
-
};
|
|
82
|
-
const deleteByBundleId = async (collection, field, bundleId, session) => {
|
|
83
|
-
await collection.deleteMany({ [field]: bundleId }, { session });
|
|
84
|
-
};
|
|
85
|
-
return {
|
|
86
|
-
async getBundleById(bundleId) {
|
|
87
|
-
const row = await bundles.findOne({ id: bundleId });
|
|
88
|
-
if (!row) return null;
|
|
89
|
-
return rowToBundle(row, (await fetchPatchMap([bundleId])).get(bundleId) ?? []);
|
|
90
|
-
},
|
|
91
|
-
async getBundles(options) {
|
|
92
|
-
const offset = options.offset ?? 0;
|
|
93
|
-
const orderBy = options.orderBy ?? {
|
|
94
|
-
field: "id",
|
|
95
|
-
direction: "desc"
|
|
96
|
-
};
|
|
97
|
-
const where = mongoWhere(options.where);
|
|
98
|
-
const [total, rows] = await Promise.all([bundles.countDocuments(where), bundles.find(where).sort({ id: orderBy.direction === "asc" ? 1 : -1 }).skip(offset).limit(options.limit).toArray()]);
|
|
99
|
-
const patchMap = await fetchPatchMap(rows.map((row) => row.id));
|
|
100
|
-
return {
|
|
101
|
-
data: rows.map((row) => rowToBundle(row, patchMap.get(row.id) ?? [])),
|
|
102
|
-
pagination: calculatePagination(total, {
|
|
103
|
-
limit: options.limit,
|
|
104
|
-
offset
|
|
105
|
-
})
|
|
106
|
-
};
|
|
107
|
-
},
|
|
108
|
-
async getUpdateInfo(args, context) {
|
|
109
|
-
if (args._updateStrategy === "appVersion") {
|
|
110
|
-
const channel = args.channel ?? "production";
|
|
111
|
-
const minBundleId = args.minBundleId ?? NIL_UUID;
|
|
112
|
-
const rows = await bundles.find({
|
|
113
|
-
enabled: true,
|
|
114
|
-
platform: args.platform,
|
|
115
|
-
channel,
|
|
116
|
-
id: { $gte: minBundleId },
|
|
117
|
-
target_app_version: {
|
|
118
|
-
$exists: true,
|
|
119
|
-
$nin: [null, ""]
|
|
120
|
-
}
|
|
121
|
-
}).project({ target_app_version: 1 }).toArray();
|
|
122
|
-
const compatibleAppVersions = filterCompatibleAppVersions(Array.from(new Set(rows.map((row) => row.target_app_version).filter((value) => typeof value === "string" && value.length > 0))), args.appVersion);
|
|
123
|
-
const updateRows = compatibleAppVersions.length > 0 ? await bundles.find({
|
|
124
|
-
enabled: true,
|
|
125
|
-
platform: args.platform,
|
|
126
|
-
channel,
|
|
127
|
-
id: { $gte: minBundleId },
|
|
128
|
-
target_app_version: { $in: compatibleAppVersions }
|
|
129
|
-
}).sort({ id: -1 }).toArray() : [];
|
|
130
|
-
return resolveUpdateInfoFromBundles({
|
|
131
|
-
args: {
|
|
132
|
-
...args,
|
|
133
|
-
channel,
|
|
134
|
-
minBundleId
|
|
135
|
-
},
|
|
136
|
-
bundles: await mapRowsToBundles(updateRows),
|
|
137
|
-
context
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
const channel = args.channel ?? "production";
|
|
141
|
-
const minBundleId = args.minBundleId ?? NIL_UUID;
|
|
142
|
-
const rows = await bundles.find({
|
|
143
|
-
enabled: true,
|
|
144
|
-
platform: args.platform,
|
|
145
|
-
channel,
|
|
146
|
-
id: { $gte: minBundleId },
|
|
147
|
-
fingerprint_hash: args.fingerprintHash
|
|
148
|
-
}).sort({ id: -1 }).toArray();
|
|
149
|
-
return resolveUpdateInfoFromBundles({
|
|
150
|
-
args: {
|
|
151
|
-
...args,
|
|
152
|
-
channel,
|
|
153
|
-
minBundleId
|
|
154
|
-
},
|
|
155
|
-
bundles: await mapRowsToBundles(rows),
|
|
156
|
-
context
|
|
157
|
-
});
|
|
158
|
-
},
|
|
159
|
-
async getChannels() {
|
|
160
|
-
return (await bundles.distinct("channel")).filter((channel) => typeof channel === "string").sort((left, right) => left.localeCompare(right));
|
|
161
|
-
},
|
|
162
|
-
async commitBundle({ changedSets }) {
|
|
163
|
-
await runInTransaction(async (session) => {
|
|
164
|
-
for (const change of changedSets) {
|
|
165
|
-
if (change.operation === "delete") {
|
|
166
|
-
await deleteByBundleId(patches, "bundle_id", change.data.id, session);
|
|
167
|
-
await deleteByBundleId(patches, "base_bundle_id", change.data.id, session);
|
|
168
|
-
await bundles.deleteMany({ id: change.data.id }, { session });
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
await replaceBundle(change.data, session);
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
}
|
|
15
|
+
const createTransactionalMongoImplementation = (client) => ({
|
|
16
|
+
...createMongoImplementation(client),
|
|
17
|
+
deleteChannel: (input) => client.withSession((session) => session.withTransaction(() => createMongoImplementation(client, session).deleteChannel(input))),
|
|
18
|
+
transaction: (callback) => client.withSession((session) => session.withTransaction(() => callback(createMongoImplementation(client, session))))
|
|
177
19
|
});
|
|
178
20
|
const mongoAdapter = (config) => {
|
|
179
|
-
|
|
21
|
+
const adapter = createDatabasePluginAdapter("mongodb", config.transactions === true ? createTransactionalMongoImplementation(config.client) : createMongoImplementation(config.client));
|
|
22
|
+
return Object.assign(createDatabasePlugin({
|
|
23
|
+
name: "mongodb",
|
|
24
|
+
models: adapter.models,
|
|
25
|
+
commit: adapter.commit
|
|
26
|
+
}), {
|
|
180
27
|
adapterName: "mongodb",
|
|
181
28
|
provider: "mongodb",
|
|
182
29
|
createMigrator: () => createMongoMigrator(config.client)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/adapters/mongodbCollections.ts
|
|
2
|
+
var MongoAdapterConstraintError = class extends Error {
|
|
3
|
+
name = "MongoAdapterConstraintError";
|
|
4
|
+
constructor(reason) {
|
|
5
|
+
super(`MongoDB adapter constraint failed: ${reason}`);
|
|
6
|
+
this.reason = reason;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
const WITHOUT_MONGO_ID = { _id: 0 };
|
|
10
|
+
const DELETION_TOKEN_FIELD = "_hot_updater_deletion_token";
|
|
11
|
+
const WITHOUT_INTERNAL_FIELDS = {
|
|
12
|
+
...WITHOUT_MONGO_ID,
|
|
13
|
+
[DELETION_TOKEN_FIELD]: 0
|
|
14
|
+
};
|
|
15
|
+
const activeBundleFilter = (where) => ({ $and: [where, { [DELETION_TOKEN_FIELD]: { $exists: false } }] });
|
|
16
|
+
const createMongoCollections = (client) => {
|
|
17
|
+
const database = client.db();
|
|
18
|
+
return {
|
|
19
|
+
bundles: database.collection("bundles"),
|
|
20
|
+
bundlePatches: database.collection("bundle_patches"),
|
|
21
|
+
bundleEvents: database.collection("bundle_events"),
|
|
22
|
+
channels: database.collection("channels"),
|
|
23
|
+
apiKeys: database.collection("api_keys"),
|
|
24
|
+
releases: database.collection("releases"),
|
|
25
|
+
releaseCatalogs: database.collection("release_catalogs")
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const mongoSessionOptions = (session) => session === void 0 ? {} : { session };
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.DELETION_TOKEN_FIELD = DELETION_TOKEN_FIELD;
|
|
31
|
+
exports.MongoAdapterConstraintError = MongoAdapterConstraintError;
|
|
32
|
+
exports.WITHOUT_INTERNAL_FIELDS = WITHOUT_INTERNAL_FIELDS;
|
|
33
|
+
exports.WITHOUT_MONGO_ID = WITHOUT_MONGO_ID;
|
|
34
|
+
exports.activeBundleFilter = activeBundleFilter;
|
|
35
|
+
exports.createMongoCollections = createMongoCollections;
|
|
36
|
+
exports.mongoSessionOptions = mongoSessionOptions;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/adapters/mongodbCollections.ts
|
|
2
|
+
var MongoAdapterConstraintError = class extends Error {
|
|
3
|
+
name = "MongoAdapterConstraintError";
|
|
4
|
+
constructor(reason) {
|
|
5
|
+
super(`MongoDB adapter constraint failed: ${reason}`);
|
|
6
|
+
this.reason = reason;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
const WITHOUT_MONGO_ID = { _id: 0 };
|
|
10
|
+
const DELETION_TOKEN_FIELD = "_hot_updater_deletion_token";
|
|
11
|
+
const WITHOUT_INTERNAL_FIELDS = {
|
|
12
|
+
...WITHOUT_MONGO_ID,
|
|
13
|
+
[DELETION_TOKEN_FIELD]: 0
|
|
14
|
+
};
|
|
15
|
+
const activeBundleFilter = (where) => ({ $and: [where, { [DELETION_TOKEN_FIELD]: { $exists: false } }] });
|
|
16
|
+
const createMongoCollections = (client) => {
|
|
17
|
+
const database = client.db();
|
|
18
|
+
return {
|
|
19
|
+
bundles: database.collection("bundles"),
|
|
20
|
+
bundlePatches: database.collection("bundle_patches"),
|
|
21
|
+
bundleEvents: database.collection("bundle_events"),
|
|
22
|
+
channels: database.collection("channels"),
|
|
23
|
+
apiKeys: database.collection("api_keys"),
|
|
24
|
+
releases: database.collection("releases"),
|
|
25
|
+
releaseCatalogs: database.collection("release_catalogs")
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const mongoSessionOptions = (session) => session === void 0 ? {} : { session };
|
|
29
|
+
//#endregion
|
|
30
|
+
export { DELETION_TOKEN_FIELD, MongoAdapterConstraintError, WITHOUT_INTERNAL_FIELDS, WITHOUT_MONGO_ID, activeBundleFilter, createMongoCollections, mongoSessionOptions };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
//#region src/adapters/mongodbQuery.ts
|
|
2
|
+
const escapeRegularExpression = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3
|
+
function literal(value) {
|
|
4
|
+
return { $literal: value };
|
|
5
|
+
}
|
|
6
|
+
const stringExpression = (field, operator, value, mode) => {
|
|
7
|
+
const escaped = escapeRegularExpression(value);
|
|
8
|
+
const regex = operator === "starts_with" ? `^${escaped}` : operator === "ends_with" ? `${escaped}$` : escaped;
|
|
9
|
+
return { $regexMatch: {
|
|
10
|
+
input: { $ifNull: [`$${field}`, ""] },
|
|
11
|
+
regex: literal(regex),
|
|
12
|
+
...mode === "insensitive" ? { options: "i" } : {}
|
|
13
|
+
} };
|
|
14
|
+
};
|
|
15
|
+
const predicate = (where) => {
|
|
16
|
+
const field = `$${where.field}`;
|
|
17
|
+
switch (where.operator) {
|
|
18
|
+
case void 0:
|
|
19
|
+
case "eq": return { $expr: "mode" in where && where.mode === "insensitive" && typeof where.value === "string" ? { $eq: [{ $toLower: { $ifNull: [field, ""] } }, literal(where.value.toLocaleLowerCase())] } : { $eq: [field, literal(where.value)] } };
|
|
20
|
+
case "ne": {
|
|
21
|
+
const comparison = "mode" in where && where.mode === "insensitive" ? { $ne: [{ $toLower: { $ifNull: [field, ""] } }, literal(where.value.toLocaleLowerCase())] } : { $ne: [field, literal(where.value)] };
|
|
22
|
+
return where.value === null ? { $expr: comparison } : { $and: [{ $expr: { $ne: [field, null] } }, { $expr: comparison }] };
|
|
23
|
+
}
|
|
24
|
+
case "gt":
|
|
25
|
+
case "gte":
|
|
26
|
+
case "lt":
|
|
27
|
+
case "lte": return { $and: [{ $expr: { $ne: [field, null] } }, { $expr: { [`$${where.operator}`]: [field, literal(where.value)] } }] };
|
|
28
|
+
case "in": return { $expr: { $in: [field, literal(where.value)] } };
|
|
29
|
+
case "not_in": return where.value.length === 0 ? { $expr: { $not: [{ $in: [field, literal(where.value)] }] } } : { $and: [{ $expr: { $ne: [field, null] } }, { $expr: { $not: [{ $in: [field, literal(where.value)] }] } }] };
|
|
30
|
+
case "contains":
|
|
31
|
+
case "starts_with":
|
|
32
|
+
case "ends_with": return { $expr: stringExpression(where.field, where.operator, where.value, where.mode) };
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const createMongoWhereDocument = (where) => {
|
|
36
|
+
const items = Array.isArray(where) ? where : [];
|
|
37
|
+
const first = items[0];
|
|
38
|
+
if (first === void 0) return {};
|
|
39
|
+
let result = predicate(first);
|
|
40
|
+
for (const item of items.slice(1)) result = { [item.connector === "OR" ? "$or" : "$and"]: [result, predicate(item)] };
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
function createMongoBundleWhere(where) {
|
|
44
|
+
return createMongoWhereDocument(where);
|
|
45
|
+
}
|
|
46
|
+
function createMongoPatchWhere(where) {
|
|
47
|
+
return createMongoWhereDocument(where);
|
|
48
|
+
}
|
|
49
|
+
function createMongoEventWhere(where) {
|
|
50
|
+
return createMongoWhereDocument(where);
|
|
51
|
+
}
|
|
52
|
+
function createMongoApiKeyWhere(where) {
|
|
53
|
+
return createMongoWhereDocument(where);
|
|
54
|
+
}
|
|
55
|
+
function createMongoChannelWhere(where) {
|
|
56
|
+
return createMongoWhereDocument(where);
|
|
57
|
+
}
|
|
58
|
+
function createMongoReleaseWhere(where) {
|
|
59
|
+
return createMongoWhereDocument(where);
|
|
60
|
+
}
|
|
61
|
+
function createMongoReleaseCatalogWhere(where) {
|
|
62
|
+
return createMongoWhereDocument(where);
|
|
63
|
+
}
|
|
64
|
+
const createMongoSort = (input) => {
|
|
65
|
+
const clauses = Array.isArray(input) ? input : input && "orderBy" in input && Array.isArray(input.orderBy) ? input.orderBy : void 0;
|
|
66
|
+
if (clauses === void 0 || clauses.length === 0) return void 0;
|
|
67
|
+
return Object.fromEntries(clauses.map((clause) => [clause.field, clause.direction === "asc" ? 1 : -1]));
|
|
68
|
+
};
|
|
69
|
+
//#endregion
|
|
70
|
+
exports.createMongoApiKeyWhere = createMongoApiKeyWhere;
|
|
71
|
+
exports.createMongoBundleWhere = createMongoBundleWhere;
|
|
72
|
+
exports.createMongoChannelWhere = createMongoChannelWhere;
|
|
73
|
+
exports.createMongoEventWhere = createMongoEventWhere;
|
|
74
|
+
exports.createMongoPatchWhere = createMongoPatchWhere;
|
|
75
|
+
exports.createMongoReleaseCatalogWhere = createMongoReleaseCatalogWhere;
|
|
76
|
+
exports.createMongoReleaseWhere = createMongoReleaseWhere;
|
|
77
|
+
exports.createMongoSort = createMongoSort;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//#region src/adapters/mongodbQuery.ts
|
|
2
|
+
const escapeRegularExpression = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3
|
+
function literal(value) {
|
|
4
|
+
return { $literal: value };
|
|
5
|
+
}
|
|
6
|
+
const stringExpression = (field, operator, value, mode) => {
|
|
7
|
+
const escaped = escapeRegularExpression(value);
|
|
8
|
+
const regex = operator === "starts_with" ? `^${escaped}` : operator === "ends_with" ? `${escaped}$` : escaped;
|
|
9
|
+
return { $regexMatch: {
|
|
10
|
+
input: { $ifNull: [`$${field}`, ""] },
|
|
11
|
+
regex: literal(regex),
|
|
12
|
+
...mode === "insensitive" ? { options: "i" } : {}
|
|
13
|
+
} };
|
|
14
|
+
};
|
|
15
|
+
const predicate = (where) => {
|
|
16
|
+
const field = `$${where.field}`;
|
|
17
|
+
switch (where.operator) {
|
|
18
|
+
case void 0:
|
|
19
|
+
case "eq": return { $expr: "mode" in where && where.mode === "insensitive" && typeof where.value === "string" ? { $eq: [{ $toLower: { $ifNull: [field, ""] } }, literal(where.value.toLocaleLowerCase())] } : { $eq: [field, literal(where.value)] } };
|
|
20
|
+
case "ne": {
|
|
21
|
+
const comparison = "mode" in where && where.mode === "insensitive" ? { $ne: [{ $toLower: { $ifNull: [field, ""] } }, literal(where.value.toLocaleLowerCase())] } : { $ne: [field, literal(where.value)] };
|
|
22
|
+
return where.value === null ? { $expr: comparison } : { $and: [{ $expr: { $ne: [field, null] } }, { $expr: comparison }] };
|
|
23
|
+
}
|
|
24
|
+
case "gt":
|
|
25
|
+
case "gte":
|
|
26
|
+
case "lt":
|
|
27
|
+
case "lte": return { $and: [{ $expr: { $ne: [field, null] } }, { $expr: { [`$${where.operator}`]: [field, literal(where.value)] } }] };
|
|
28
|
+
case "in": return { $expr: { $in: [field, literal(where.value)] } };
|
|
29
|
+
case "not_in": return where.value.length === 0 ? { $expr: { $not: [{ $in: [field, literal(where.value)] }] } } : { $and: [{ $expr: { $ne: [field, null] } }, { $expr: { $not: [{ $in: [field, literal(where.value)] }] } }] };
|
|
30
|
+
case "contains":
|
|
31
|
+
case "starts_with":
|
|
32
|
+
case "ends_with": return { $expr: stringExpression(where.field, where.operator, where.value, where.mode) };
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const createMongoWhereDocument = (where) => {
|
|
36
|
+
const items = Array.isArray(where) ? where : [];
|
|
37
|
+
const first = items[0];
|
|
38
|
+
if (first === void 0) return {};
|
|
39
|
+
let result = predicate(first);
|
|
40
|
+
for (const item of items.slice(1)) result = { [item.connector === "OR" ? "$or" : "$and"]: [result, predicate(item)] };
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
function createMongoBundleWhere(where) {
|
|
44
|
+
return createMongoWhereDocument(where);
|
|
45
|
+
}
|
|
46
|
+
function createMongoPatchWhere(where) {
|
|
47
|
+
return createMongoWhereDocument(where);
|
|
48
|
+
}
|
|
49
|
+
function createMongoEventWhere(where) {
|
|
50
|
+
return createMongoWhereDocument(where);
|
|
51
|
+
}
|
|
52
|
+
function createMongoApiKeyWhere(where) {
|
|
53
|
+
return createMongoWhereDocument(where);
|
|
54
|
+
}
|
|
55
|
+
function createMongoChannelWhere(where) {
|
|
56
|
+
return createMongoWhereDocument(where);
|
|
57
|
+
}
|
|
58
|
+
function createMongoReleaseWhere(where) {
|
|
59
|
+
return createMongoWhereDocument(where);
|
|
60
|
+
}
|
|
61
|
+
function createMongoReleaseCatalogWhere(where) {
|
|
62
|
+
return createMongoWhereDocument(where);
|
|
63
|
+
}
|
|
64
|
+
const createMongoSort = (input) => {
|
|
65
|
+
const clauses = Array.isArray(input) ? input : input && "orderBy" in input && Array.isArray(input.orderBy) ? input.orderBy : void 0;
|
|
66
|
+
if (clauses === void 0 || clauses.length === 0) return void 0;
|
|
67
|
+
return Object.fromEntries(clauses.map((clause) => [clause.field, clause.direction === "asc" ? 1 : -1]));
|
|
68
|
+
};
|
|
69
|
+
//#endregion
|
|
70
|
+
export { createMongoApiKeyWhere, createMongoBundleWhere, createMongoChannelWhere, createMongoEventWhere, createMongoPatchWhere, createMongoReleaseCatalogWhere, createMongoReleaseWhere, createMongoSort };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_databasePluginUtils = require("./databasePluginUtils.cjs");
|
|
3
|
+
const require_mongodbCollections = require("./mongodbCollections.cjs");
|
|
4
|
+
const require_mongodbQuery = require("./mongodbQuery.cjs");
|
|
5
|
+
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
6
|
+
//#region src/adapters/mongodbReads.ts
|
|
7
|
+
const findMongoRows = async (collections, input, session) => {
|
|
8
|
+
if (input.limit === 0) return [];
|
|
9
|
+
const rawOrderBy = input.orderBy;
|
|
10
|
+
const needsInMemoryOrder = require_databasePluginUtils.hasNullOrderOverrides(rawOrderBy);
|
|
11
|
+
switch (input.model) {
|
|
12
|
+
case "bundles": {
|
|
13
|
+
const cursor = collections.bundles.find(require_mongodbCollections.activeBundleFilter(require_mongodbQuery.createMongoBundleWhere(input.where)), {
|
|
14
|
+
projection: require_mongodbCollections.WITHOUT_INTERNAL_FIELDS,
|
|
15
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
16
|
+
}).skip(input.offset).limit(input.limit);
|
|
17
|
+
if (rawOrderBy === void 0) return cursor.toArray();
|
|
18
|
+
if (needsInMemoryOrder) return require_databasePluginUtils.sortRowsByOrder(await collections.bundles.find(require_mongodbCollections.activeBundleFilter(require_mongodbQuery.createMongoBundleWhere(input.where)), {
|
|
19
|
+
projection: require_mongodbCollections.WITHOUT_INTERNAL_FIELDS,
|
|
20
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
21
|
+
}).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
22
|
+
const sort = require_mongodbQuery.createMongoSort(input);
|
|
23
|
+
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
24
|
+
}
|
|
25
|
+
case "bundle_patches": {
|
|
26
|
+
const cursor = collections.bundlePatches.find(require_mongodbQuery.createMongoPatchWhere(input.where), {
|
|
27
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
28
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
29
|
+
}).skip(input.offset).limit(input.limit);
|
|
30
|
+
if (rawOrderBy === void 0) return cursor.toArray();
|
|
31
|
+
if (needsInMemoryOrder) return require_databasePluginUtils.sortRowsByOrder(await collections.bundlePatches.find(require_mongodbQuery.createMongoPatchWhere(input.where), {
|
|
32
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
33
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
34
|
+
}).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
35
|
+
const sort = require_mongodbQuery.createMongoSort(input);
|
|
36
|
+
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
37
|
+
}
|
|
38
|
+
case "bundle_events": {
|
|
39
|
+
const cursor = collections.bundleEvents.find(require_mongodbQuery.createMongoEventWhere(input.where), {
|
|
40
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
41
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
42
|
+
}).skip(input.offset).limit(input.limit);
|
|
43
|
+
if (rawOrderBy === void 0) return cursor.toArray();
|
|
44
|
+
if (needsInMemoryOrder) return require_databasePluginUtils.sortRowsByOrder(await collections.bundleEvents.find(require_mongodbQuery.createMongoEventWhere(input.where), {
|
|
45
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
46
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
47
|
+
}).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
48
|
+
const sort = require_mongodbQuery.createMongoSort(input);
|
|
49
|
+
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
50
|
+
}
|
|
51
|
+
case "api_keys": {
|
|
52
|
+
const cursor = collections.apiKeys.find(require_mongodbQuery.createMongoApiKeyWhere(input.where), {
|
|
53
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
54
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
55
|
+
}).skip(input.offset).limit(input.limit);
|
|
56
|
+
if (rawOrderBy === void 0) return cursor.toArray();
|
|
57
|
+
if (needsInMemoryOrder) return require_databasePluginUtils.sortRowsByOrder(await collections.apiKeys.find(require_mongodbQuery.createMongoApiKeyWhere(input.where), {
|
|
58
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
59
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
60
|
+
}).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
61
|
+
const sort = require_mongodbQuery.createMongoSort(input);
|
|
62
|
+
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
63
|
+
}
|
|
64
|
+
case "channels": {
|
|
65
|
+
const cursor = collections.channels.find(require_mongodbQuery.createMongoChannelWhere(input.where), {
|
|
66
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
67
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
68
|
+
}).skip(input.offset).limit(input.limit);
|
|
69
|
+
if (rawOrderBy === void 0) return cursor.toArray();
|
|
70
|
+
if (needsInMemoryOrder) return require_databasePluginUtils.sortRowsByOrder(await collections.channels.find(require_mongodbQuery.createMongoChannelWhere(input.where), {
|
|
71
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
72
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
73
|
+
}).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
74
|
+
const sort = require_mongodbQuery.createMongoSort(input);
|
|
75
|
+
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
76
|
+
}
|
|
77
|
+
case "releases": {
|
|
78
|
+
const cursor = collections.releases.find(require_mongodbQuery.createMongoReleaseWhere(input.where), {
|
|
79
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
80
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
81
|
+
}).skip(input.offset).limit(input.limit);
|
|
82
|
+
if (rawOrderBy === void 0) return cursor.toArray();
|
|
83
|
+
if (needsInMemoryOrder) return require_databasePluginUtils.sortRowsByOrder(await collections.releases.find(require_mongodbQuery.createMongoReleaseWhere(input.where), {
|
|
84
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
85
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
86
|
+
}).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
87
|
+
const sort = require_mongodbQuery.createMongoSort(input);
|
|
88
|
+
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
89
|
+
}
|
|
90
|
+
case "release_catalogs": {
|
|
91
|
+
const cursor = collections.releaseCatalogs.find(require_mongodbQuery.createMongoReleaseCatalogWhere(input.where), {
|
|
92
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
93
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
94
|
+
}).skip(input.offset).limit(input.limit);
|
|
95
|
+
if (rawOrderBy === void 0) return cursor.toArray();
|
|
96
|
+
if (needsInMemoryOrder) return require_databasePluginUtils.sortRowsByOrder(await collections.releaseCatalogs.find(require_mongodbQuery.createMongoReleaseCatalogWhere(input.where), {
|
|
97
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
98
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
99
|
+
}).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
100
|
+
const sort = require_mongodbQuery.createMongoSort(input);
|
|
101
|
+
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const createMongoReads = (collections, session) => ({
|
|
106
|
+
count: async (input) => {
|
|
107
|
+
if (input.distinct !== void 0) throw new _hot_updater_plugin_core.DatabasePluginInputError("invalid-operation");
|
|
108
|
+
switch (input.model) {
|
|
109
|
+
case "bundles": return collections.bundles.countDocuments(require_mongodbCollections.activeBundleFilter(require_mongodbQuery.createMongoBundleWhere(input.where)), require_mongodbCollections.mongoSessionOptions(session));
|
|
110
|
+
case "bundle_patches": return collections.bundlePatches.countDocuments(require_mongodbQuery.createMongoPatchWhere(input.where), require_mongodbCollections.mongoSessionOptions(session));
|
|
111
|
+
case "releases": return collections.releases.countDocuments(require_mongodbQuery.createMongoReleaseWhere(input.where), require_mongodbCollections.mongoSessionOptions(session));
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
findOne: async (input) => {
|
|
115
|
+
switch (input.model) {
|
|
116
|
+
case "bundles": return collections.bundles.findOne(require_mongodbCollections.activeBundleFilter(require_mongodbQuery.createMongoBundleWhere(input.where)), {
|
|
117
|
+
projection: require_mongodbCollections.WITHOUT_INTERNAL_FIELDS,
|
|
118
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
119
|
+
});
|
|
120
|
+
case "channels": return collections.channels.findOne(require_mongodbQuery.createMongoChannelWhere(input.where), {
|
|
121
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
122
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
123
|
+
});
|
|
124
|
+
case "api_keys": return collections.apiKeys.findOne(require_mongodbQuery.createMongoApiKeyWhere(input.where), {
|
|
125
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
126
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
127
|
+
});
|
|
128
|
+
case "bundle_patches": return collections.bundlePatches.findOne(require_mongodbQuery.createMongoPatchWhere(input.where), {
|
|
129
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
130
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
131
|
+
});
|
|
132
|
+
case "releases": return collections.releases.findOne(require_mongodbQuery.createMongoReleaseWhere(input.where), {
|
|
133
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
134
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
135
|
+
});
|
|
136
|
+
case "release_catalogs": return collections.releaseCatalogs.findOne(require_mongodbQuery.createMongoReleaseCatalogWhere(input.where), {
|
|
137
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
138
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
findMany: (input) => {
|
|
143
|
+
if (input.distinctOn !== void 0) throw new _hot_updater_plugin_core.DatabasePluginInputError("invalid-operation");
|
|
144
|
+
return findMongoRows(collections, input, session);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
//#endregion
|
|
148
|
+
exports.createMongoReads = createMongoReads;
|