@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,67 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BundleEventRow,
|
|
3
|
-
InsightsInstallationRow,
|
|
4
|
-
BundlePatchRow,
|
|
5
|
-
BundleRow,
|
|
6
|
-
ChannelRow,
|
|
7
|
-
ApiKeyRow,
|
|
8
|
-
ReleaseCatalogRow,
|
|
9
|
-
ReleaseRow,
|
|
10
|
-
} from "@hot-updater/plugin-core";
|
|
11
|
-
import type { ClientSession, Collection, MongoClient } from "mongodb";
|
|
12
|
-
|
|
13
|
-
export class MongoAdapterConstraintError extends Error {
|
|
14
|
-
readonly name = "MongoAdapterConstraintError";
|
|
15
|
-
|
|
16
|
-
constructor(readonly reason: string) {
|
|
17
|
-
super(`MongoDB adapter constraint failed: ${reason}`);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const WITHOUT_MONGO_ID = { _id: 0 } as const;
|
|
22
|
-
export const DELETION_TOKEN_FIELD = "_hot_updater_deletion_token" as const;
|
|
23
|
-
|
|
24
|
-
export type MongoBundleDocument = BundleRow & {
|
|
25
|
-
readonly [DELETION_TOKEN_FIELD]?: string;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const WITHOUT_INTERNAL_FIELDS = {
|
|
29
|
-
...WITHOUT_MONGO_ID,
|
|
30
|
-
[DELETION_TOKEN_FIELD]: 0,
|
|
31
|
-
} as const;
|
|
32
|
-
|
|
33
|
-
export const activeBundleFilter = (where: object) => ({
|
|
34
|
-
$and: [where, { [DELETION_TOKEN_FIELD]: { $exists: false } }],
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
export type MongoCollections = {
|
|
38
|
-
readonly bundles: Collection<MongoBundleDocument>;
|
|
39
|
-
readonly bundlePatches: Collection<BundlePatchRow>;
|
|
40
|
-
readonly bundleEvents: Collection<BundleEventRow>;
|
|
41
|
-
readonly bundleInstallations: Collection<InsightsInstallationRow>;
|
|
42
|
-
readonly channels: Collection<ChannelRow>;
|
|
43
|
-
readonly apiKeys: Collection<ApiKeyRow>;
|
|
44
|
-
readonly releases: Collection<ReleaseRow>;
|
|
45
|
-
readonly releaseCatalogs: Collection<ReleaseCatalogRow>;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export const createMongoCollections = (
|
|
49
|
-
client: MongoClient,
|
|
50
|
-
): MongoCollections => {
|
|
51
|
-
const database = client.db();
|
|
52
|
-
return {
|
|
53
|
-
bundles: database.collection<MongoBundleDocument>("bundles"),
|
|
54
|
-
bundlePatches: database.collection<BundlePatchRow>("bundle_patches"),
|
|
55
|
-
bundleEvents: database.collection<BundleEventRow>("bundle_events"),
|
|
56
|
-
bundleInstallations: database.collection<InsightsInstallationRow>(
|
|
57
|
-
"bundle_installations",
|
|
58
|
-
),
|
|
59
|
-
channels: database.collection<ChannelRow>("channels"),
|
|
60
|
-
apiKeys: database.collection<ApiKeyRow>("api_keys"),
|
|
61
|
-
releases: database.collection<ReleaseRow>("releases"),
|
|
62
|
-
releaseCatalogs: database.collection<ReleaseCatalogRow>("release_catalogs"),
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export const mongoSessionOptions = (session?: ClientSession) =>
|
|
67
|
-
session === undefined ? {} : { session };
|
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ApiKeyRow,
|
|
3
|
-
BundleEventRow,
|
|
4
|
-
BundlePatchRow,
|
|
5
|
-
BundleRow,
|
|
6
|
-
ChannelRow,
|
|
7
|
-
InsightsInstallationRow,
|
|
8
|
-
ReleaseCatalogRow,
|
|
9
|
-
ReleaseRow,
|
|
10
|
-
} from "@hot-updater/plugin-core";
|
|
11
|
-
import type {
|
|
12
|
-
DatabaseModel,
|
|
13
|
-
DatabaseOrderBy,
|
|
14
|
-
DatabaseWhere,
|
|
15
|
-
} from "@hot-updater/plugin-core/internal";
|
|
16
|
-
import type { Document, Filter, Sort } from "mongodb";
|
|
17
|
-
|
|
18
|
-
type AnyDatabaseWhere = {
|
|
19
|
-
readonly [TModel in DatabaseModel]: DatabaseWhere<TModel>;
|
|
20
|
-
}[DatabaseModel];
|
|
21
|
-
type AnyDatabaseOrderBy = {
|
|
22
|
-
readonly [TModel in DatabaseModel]: DatabaseOrderBy<TModel>;
|
|
23
|
-
}[DatabaseModel];
|
|
24
|
-
|
|
25
|
-
const escapeRegularExpression = (value: string): string =>
|
|
26
|
-
value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
27
|
-
|
|
28
|
-
function literal(value: unknown): Document {
|
|
29
|
-
return { $literal: value };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const stringExpression = (
|
|
33
|
-
field: string,
|
|
34
|
-
operator: "contains" | "ends_with" | "starts_with",
|
|
35
|
-
value: string,
|
|
36
|
-
mode: "insensitive" | "sensitive" | undefined,
|
|
37
|
-
): Document => {
|
|
38
|
-
const escaped = escapeRegularExpression(value);
|
|
39
|
-
const regex =
|
|
40
|
-
operator === "starts_with"
|
|
41
|
-
? `^${escaped}`
|
|
42
|
-
: operator === "ends_with"
|
|
43
|
-
? `${escaped}$`
|
|
44
|
-
: escaped;
|
|
45
|
-
return {
|
|
46
|
-
$regexMatch: {
|
|
47
|
-
input: { $ifNull: [`$${field}`, ""] },
|
|
48
|
-
regex: literal(regex),
|
|
49
|
-
...(mode === "insensitive" ? { options: "i" } : {}),
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const predicate = (where: AnyDatabaseWhere): Document => {
|
|
55
|
-
const field = `$${where.field}`;
|
|
56
|
-
switch (where.operator) {
|
|
57
|
-
case undefined:
|
|
58
|
-
case "eq":
|
|
59
|
-
return {
|
|
60
|
-
$expr:
|
|
61
|
-
"mode" in where &&
|
|
62
|
-
where.mode === "insensitive" &&
|
|
63
|
-
typeof where.value === "string"
|
|
64
|
-
? {
|
|
65
|
-
$eq: [
|
|
66
|
-
{ $toLower: { $ifNull: [field, ""] } },
|
|
67
|
-
literal(where.value.toLocaleLowerCase()),
|
|
68
|
-
],
|
|
69
|
-
}
|
|
70
|
-
: { $eq: [field, literal(where.value)] },
|
|
71
|
-
};
|
|
72
|
-
case "ne": {
|
|
73
|
-
const comparison =
|
|
74
|
-
"mode" in where && where.mode === "insensitive"
|
|
75
|
-
? {
|
|
76
|
-
$ne: [
|
|
77
|
-
{ $toLower: { $ifNull: [field, ""] } },
|
|
78
|
-
literal(where.value.toLocaleLowerCase()),
|
|
79
|
-
],
|
|
80
|
-
}
|
|
81
|
-
: { $ne: [field, literal(where.value)] };
|
|
82
|
-
return where.value === null
|
|
83
|
-
? { $expr: comparison }
|
|
84
|
-
: {
|
|
85
|
-
$and: [{ $expr: { $ne: [field, null] } }, { $expr: comparison }],
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
case "gt":
|
|
89
|
-
case "gte":
|
|
90
|
-
case "lt":
|
|
91
|
-
case "lte":
|
|
92
|
-
return {
|
|
93
|
-
$and: [
|
|
94
|
-
{ $expr: { $ne: [field, null] } },
|
|
95
|
-
{ $expr: { [`$${where.operator}`]: [field, literal(where.value)] } },
|
|
96
|
-
],
|
|
97
|
-
};
|
|
98
|
-
case "in":
|
|
99
|
-
return { $expr: { $in: [field, literal(where.value)] } };
|
|
100
|
-
case "not_in":
|
|
101
|
-
return where.value.length === 0
|
|
102
|
-
? { $expr: { $not: [{ $in: [field, literal(where.value)] }] } }
|
|
103
|
-
: {
|
|
104
|
-
$and: [
|
|
105
|
-
{ $expr: { $ne: [field, null] } },
|
|
106
|
-
{ $expr: { $not: [{ $in: [field, literal(where.value)] }] } },
|
|
107
|
-
],
|
|
108
|
-
};
|
|
109
|
-
case "contains":
|
|
110
|
-
case "starts_with":
|
|
111
|
-
case "ends_with":
|
|
112
|
-
return {
|
|
113
|
-
$expr: stringExpression(
|
|
114
|
-
where.field,
|
|
115
|
-
where.operator,
|
|
116
|
-
where.value,
|
|
117
|
-
where.mode,
|
|
118
|
-
),
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const createMongoWhereDocument = (
|
|
124
|
-
where: readonly AnyDatabaseWhere[] | undefined,
|
|
125
|
-
toPredicate: (condition: AnyDatabaseWhere) => Document = predicate,
|
|
126
|
-
): Document => {
|
|
127
|
-
const items = Array.isArray(where) ? where : [];
|
|
128
|
-
const first = items[0];
|
|
129
|
-
if (first === undefined) return {};
|
|
130
|
-
|
|
131
|
-
let result = toPredicate(first);
|
|
132
|
-
for (const item of items.slice(1)) {
|
|
133
|
-
result = {
|
|
134
|
-
[item.connector === "OR" ? "$or" : "$and"]: [result, toPredicate(item)],
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
return result;
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
// Fixed Insights predicates use native fields so equality/range indexes apply.
|
|
141
|
-
const insightsPredicate = (where: AnyDatabaseWhere): Document => {
|
|
142
|
-
if ("mode" in where && where.mode === "insensitive") return predicate(where);
|
|
143
|
-
switch (where.operator) {
|
|
144
|
-
case undefined:
|
|
145
|
-
case "eq":
|
|
146
|
-
return { [where.field]: { $eq: where.value } };
|
|
147
|
-
case "gt":
|
|
148
|
-
case "gte":
|
|
149
|
-
case "lt":
|
|
150
|
-
case "lte":
|
|
151
|
-
case "in":
|
|
152
|
-
return { [where.field]: { [`$${where.operator}`]: where.value } };
|
|
153
|
-
default:
|
|
154
|
-
return predicate(where);
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
export function createMongoBundleWhere(
|
|
159
|
-
where: readonly DatabaseWhere<"bundles">[] | undefined,
|
|
160
|
-
): Filter<BundleRow>;
|
|
161
|
-
export function createMongoBundleWhere(
|
|
162
|
-
where: readonly DatabaseWhere<"bundles">[] | undefined,
|
|
163
|
-
): Document {
|
|
164
|
-
return createMongoWhereDocument(where);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export function createMongoPatchWhere(
|
|
168
|
-
where: readonly DatabaseWhere<"bundle_patches">[] | undefined,
|
|
169
|
-
): Filter<BundlePatchRow>;
|
|
170
|
-
export function createMongoPatchWhere(
|
|
171
|
-
where: readonly DatabaseWhere<"bundle_patches">[] | undefined,
|
|
172
|
-
): Document {
|
|
173
|
-
return createMongoWhereDocument(where);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export function createMongoEventWhere(
|
|
177
|
-
where: readonly DatabaseWhere<"bundle_events">[] | undefined,
|
|
178
|
-
): Filter<BundleEventRow>;
|
|
179
|
-
export function createMongoEventWhere(
|
|
180
|
-
where: readonly DatabaseWhere<"bundle_events">[] | undefined,
|
|
181
|
-
): Document {
|
|
182
|
-
return createMongoWhereDocument(where, insightsPredicate);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export function createMongoInstallationWhere(
|
|
186
|
-
where: readonly DatabaseWhere<"bundle_installations">[] | undefined,
|
|
187
|
-
): Filter<InsightsInstallationRow>;
|
|
188
|
-
export function createMongoInstallationWhere(
|
|
189
|
-
where: readonly DatabaseWhere<"bundle_installations">[] | undefined,
|
|
190
|
-
): Document {
|
|
191
|
-
return createMongoWhereDocument(where, insightsPredicate);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
export function createMongoApiKeyWhere(
|
|
195
|
-
where: readonly DatabaseWhere<"api_keys">[] | undefined,
|
|
196
|
-
): Filter<ApiKeyRow>;
|
|
197
|
-
export function createMongoApiKeyWhere(
|
|
198
|
-
where: readonly DatabaseWhere<"api_keys">[] | undefined,
|
|
199
|
-
): Document {
|
|
200
|
-
return createMongoWhereDocument(where);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export function createMongoChannelWhere(
|
|
204
|
-
where: readonly DatabaseWhere<"channels">[] | undefined,
|
|
205
|
-
): Filter<ChannelRow>;
|
|
206
|
-
export function createMongoChannelWhere(
|
|
207
|
-
where: readonly DatabaseWhere<"channels">[] | undefined,
|
|
208
|
-
): Document {
|
|
209
|
-
return createMongoWhereDocument(where);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export function createMongoReleaseWhere(
|
|
213
|
-
where: readonly DatabaseWhere<"releases">[] | undefined,
|
|
214
|
-
): Filter<ReleaseRow>;
|
|
215
|
-
export function createMongoReleaseWhere(
|
|
216
|
-
where: readonly DatabaseWhere<"releases">[] | undefined,
|
|
217
|
-
): Document {
|
|
218
|
-
return createMongoWhereDocument(where);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export function createMongoReleaseCatalogWhere(
|
|
222
|
-
where: readonly DatabaseWhere<"release_catalogs">[] | undefined,
|
|
223
|
-
): Filter<ReleaseCatalogRow>;
|
|
224
|
-
export function createMongoReleaseCatalogWhere(
|
|
225
|
-
where: readonly DatabaseWhere<"release_catalogs">[] | undefined,
|
|
226
|
-
): Document {
|
|
227
|
-
return createMongoWhereDocument(where);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
export const createMongoSort = (
|
|
231
|
-
input:
|
|
232
|
-
| {
|
|
233
|
-
readonly orderBy?: AnyDatabaseOrderBy;
|
|
234
|
-
}
|
|
235
|
-
| AnyDatabaseOrderBy
|
|
236
|
-
| undefined,
|
|
237
|
-
): Sort | undefined => {
|
|
238
|
-
const clauses:
|
|
239
|
-
| readonly { field: string; direction: "asc" | "desc" }[]
|
|
240
|
-
| undefined = Array.isArray(input)
|
|
241
|
-
? (input as readonly { field: string; direction: "asc" | "desc" }[])
|
|
242
|
-
: input && "orderBy" in input && Array.isArray(input.orderBy)
|
|
243
|
-
? (input.orderBy as readonly {
|
|
244
|
-
field: string;
|
|
245
|
-
direction: "asc" | "desc";
|
|
246
|
-
}[])
|
|
247
|
-
: undefined;
|
|
248
|
-
if (clauses === undefined || clauses.length === 0) return undefined;
|
|
249
|
-
return Object.fromEntries(
|
|
250
|
-
clauses.map((clause) => [
|
|
251
|
-
clause.field,
|
|
252
|
-
clause.direction === "asc" ? 1 : -1,
|
|
253
|
-
]),
|
|
254
|
-
);
|
|
255
|
-
};
|
|
@@ -1,380 +0,0 @@
|
|
|
1
|
-
import { DatabasePluginInputError } from "@hot-updater/plugin-core";
|
|
2
|
-
import type {
|
|
3
|
-
DatabaseImplementationResult,
|
|
4
|
-
DatabasePluginImplementation,
|
|
5
|
-
FindManyDatabaseImplementationInput,
|
|
6
|
-
} from "@hot-updater/plugin-core/internal";
|
|
7
|
-
import type { ClientSession } from "mongodb";
|
|
8
|
-
|
|
9
|
-
import { hasNullOrderOverrides, sortRowsByOrder } from "./databasePluginUtils";
|
|
10
|
-
import {
|
|
11
|
-
activeBundleFilter,
|
|
12
|
-
type MongoCollections,
|
|
13
|
-
mongoSessionOptions,
|
|
14
|
-
WITHOUT_INTERNAL_FIELDS,
|
|
15
|
-
WITHOUT_MONGO_ID,
|
|
16
|
-
} from "./mongodbCollections";
|
|
17
|
-
import {
|
|
18
|
-
createMongoBundleWhere,
|
|
19
|
-
createMongoChannelWhere,
|
|
20
|
-
createMongoApiKeyWhere,
|
|
21
|
-
createMongoEventWhere,
|
|
22
|
-
createMongoInstallationWhere,
|
|
23
|
-
createMongoPatchWhere,
|
|
24
|
-
createMongoReleaseCatalogWhere,
|
|
25
|
-
createMongoReleaseWhere,
|
|
26
|
-
createMongoSort,
|
|
27
|
-
} from "./mongodbQuery";
|
|
28
|
-
|
|
29
|
-
const findMongoRows = async (
|
|
30
|
-
collections: MongoCollections,
|
|
31
|
-
input: FindManyDatabaseImplementationInput,
|
|
32
|
-
session?: ClientSession,
|
|
33
|
-
): Promise<readonly DatabaseImplementationResult[]> => {
|
|
34
|
-
if (input.limit === 0) return [];
|
|
35
|
-
const rawOrderBy = input.orderBy;
|
|
36
|
-
const needsInMemoryOrder = hasNullOrderOverrides(rawOrderBy);
|
|
37
|
-
switch (input.model) {
|
|
38
|
-
case "bundles": {
|
|
39
|
-
const cursor = collections.bundles
|
|
40
|
-
.find(activeBundleFilter(createMongoBundleWhere(input.where)), {
|
|
41
|
-
projection: WITHOUT_INTERNAL_FIELDS,
|
|
42
|
-
...mongoSessionOptions(session),
|
|
43
|
-
})
|
|
44
|
-
.skip(input.offset)
|
|
45
|
-
.limit(input.limit);
|
|
46
|
-
if (rawOrderBy === undefined) return cursor.toArray();
|
|
47
|
-
if (needsInMemoryOrder) {
|
|
48
|
-
const rows = await collections.bundles
|
|
49
|
-
.find(activeBundleFilter(createMongoBundleWhere(input.where)), {
|
|
50
|
-
projection: WITHOUT_INTERNAL_FIELDS,
|
|
51
|
-
...mongoSessionOptions(session),
|
|
52
|
-
})
|
|
53
|
-
.toArray();
|
|
54
|
-
return sortRowsByOrder(rows, rawOrderBy).slice(
|
|
55
|
-
input.offset,
|
|
56
|
-
input.offset + input.limit,
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
const sort = createMongoSort(input);
|
|
60
|
-
return sort === undefined
|
|
61
|
-
? cursor.toArray()
|
|
62
|
-
: cursor.sort(sort).toArray();
|
|
63
|
-
}
|
|
64
|
-
case "bundle_patches": {
|
|
65
|
-
const cursor = collections.bundlePatches
|
|
66
|
-
.find(createMongoPatchWhere(input.where), {
|
|
67
|
-
projection: WITHOUT_MONGO_ID,
|
|
68
|
-
...mongoSessionOptions(session),
|
|
69
|
-
})
|
|
70
|
-
.skip(input.offset)
|
|
71
|
-
.limit(input.limit);
|
|
72
|
-
if (rawOrderBy === undefined) return cursor.toArray();
|
|
73
|
-
if (needsInMemoryOrder) {
|
|
74
|
-
const rows = await collections.bundlePatches
|
|
75
|
-
.find(createMongoPatchWhere(input.where), {
|
|
76
|
-
projection: WITHOUT_MONGO_ID,
|
|
77
|
-
...mongoSessionOptions(session),
|
|
78
|
-
})
|
|
79
|
-
.toArray();
|
|
80
|
-
return sortRowsByOrder(rows, rawOrderBy).slice(
|
|
81
|
-
input.offset,
|
|
82
|
-
input.offset + input.limit,
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
const sort = createMongoSort(input);
|
|
86
|
-
return sort === undefined
|
|
87
|
-
? cursor.toArray()
|
|
88
|
-
: cursor.sort(sort).toArray();
|
|
89
|
-
}
|
|
90
|
-
case "bundle_events": {
|
|
91
|
-
const cursor = collections.bundleEvents
|
|
92
|
-
.find(createMongoEventWhere(input.where), {
|
|
93
|
-
projection: WITHOUT_MONGO_ID,
|
|
94
|
-
...mongoSessionOptions(session),
|
|
95
|
-
collation: { locale: "simple" },
|
|
96
|
-
readPreference: "primary",
|
|
97
|
-
})
|
|
98
|
-
.skip(input.offset)
|
|
99
|
-
.limit(input.limit);
|
|
100
|
-
if (rawOrderBy === undefined) return cursor.toArray();
|
|
101
|
-
if (needsInMemoryOrder) {
|
|
102
|
-
const rows = await collections.bundleEvents
|
|
103
|
-
.find(createMongoEventWhere(input.where), {
|
|
104
|
-
projection: WITHOUT_MONGO_ID,
|
|
105
|
-
...mongoSessionOptions(session),
|
|
106
|
-
collation: { locale: "simple" },
|
|
107
|
-
readPreference: "primary",
|
|
108
|
-
})
|
|
109
|
-
.toArray();
|
|
110
|
-
return sortRowsByOrder(rows, rawOrderBy).slice(
|
|
111
|
-
input.offset,
|
|
112
|
-
input.offset + input.limit,
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
const sort = createMongoSort(input);
|
|
116
|
-
return sort === undefined
|
|
117
|
-
? cursor.toArray()
|
|
118
|
-
: cursor.sort(sort).toArray();
|
|
119
|
-
}
|
|
120
|
-
case "bundle_installations": {
|
|
121
|
-
const cursor = collections.bundleInstallations
|
|
122
|
-
.find(createMongoInstallationWhere(input.where), {
|
|
123
|
-
projection: WITHOUT_MONGO_ID,
|
|
124
|
-
...mongoSessionOptions(session),
|
|
125
|
-
collation: { locale: "simple" },
|
|
126
|
-
readPreference: "primary",
|
|
127
|
-
})
|
|
128
|
-
.skip(input.offset)
|
|
129
|
-
.limit(input.limit);
|
|
130
|
-
if (rawOrderBy === undefined) return cursor.toArray();
|
|
131
|
-
if (needsInMemoryOrder) {
|
|
132
|
-
const rows = await collections.bundleInstallations
|
|
133
|
-
.find(createMongoInstallationWhere(input.where), {
|
|
134
|
-
projection: WITHOUT_MONGO_ID,
|
|
135
|
-
...mongoSessionOptions(session),
|
|
136
|
-
collation: { locale: "simple" },
|
|
137
|
-
readPreference: "primary",
|
|
138
|
-
})
|
|
139
|
-
.toArray();
|
|
140
|
-
return sortRowsByOrder(rows, rawOrderBy).slice(
|
|
141
|
-
input.offset,
|
|
142
|
-
input.offset + input.limit,
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
const sort = createMongoSort(input);
|
|
146
|
-
return sort === undefined
|
|
147
|
-
? cursor.toArray()
|
|
148
|
-
: cursor.sort(sort).toArray();
|
|
149
|
-
}
|
|
150
|
-
case "api_keys": {
|
|
151
|
-
const cursor = collections.apiKeys
|
|
152
|
-
.find(createMongoApiKeyWhere(input.where), {
|
|
153
|
-
projection: WITHOUT_MONGO_ID,
|
|
154
|
-
...mongoSessionOptions(session),
|
|
155
|
-
})
|
|
156
|
-
.skip(input.offset)
|
|
157
|
-
.limit(input.limit);
|
|
158
|
-
if (rawOrderBy === undefined) return cursor.toArray();
|
|
159
|
-
if (needsInMemoryOrder) {
|
|
160
|
-
const rows = await collections.apiKeys
|
|
161
|
-
.find(createMongoApiKeyWhere(input.where), {
|
|
162
|
-
projection: WITHOUT_MONGO_ID,
|
|
163
|
-
...mongoSessionOptions(session),
|
|
164
|
-
})
|
|
165
|
-
.toArray();
|
|
166
|
-
return sortRowsByOrder(rows, rawOrderBy).slice(
|
|
167
|
-
input.offset,
|
|
168
|
-
input.offset + input.limit,
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
const sort = createMongoSort(input);
|
|
172
|
-
return sort === undefined
|
|
173
|
-
? cursor.toArray()
|
|
174
|
-
: cursor.sort(sort).toArray();
|
|
175
|
-
}
|
|
176
|
-
case "channels": {
|
|
177
|
-
const cursor = collections.channels
|
|
178
|
-
.find(createMongoChannelWhere(input.where), {
|
|
179
|
-
projection: WITHOUT_MONGO_ID,
|
|
180
|
-
...mongoSessionOptions(session),
|
|
181
|
-
})
|
|
182
|
-
.skip(input.offset)
|
|
183
|
-
.limit(input.limit);
|
|
184
|
-
if (rawOrderBy === undefined) return cursor.toArray();
|
|
185
|
-
if (needsInMemoryOrder) {
|
|
186
|
-
const rows = await collections.channels
|
|
187
|
-
.find(createMongoChannelWhere(input.where), {
|
|
188
|
-
projection: WITHOUT_MONGO_ID,
|
|
189
|
-
...mongoSessionOptions(session),
|
|
190
|
-
})
|
|
191
|
-
.toArray();
|
|
192
|
-
return sortRowsByOrder(rows, rawOrderBy).slice(
|
|
193
|
-
input.offset,
|
|
194
|
-
input.offset + input.limit,
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
const sort = createMongoSort(input);
|
|
198
|
-
return sort === undefined
|
|
199
|
-
? cursor.toArray()
|
|
200
|
-
: cursor.sort(sort).toArray();
|
|
201
|
-
}
|
|
202
|
-
case "releases": {
|
|
203
|
-
const cursor = collections.releases
|
|
204
|
-
.find(createMongoReleaseWhere(input.where), {
|
|
205
|
-
projection: WITHOUT_MONGO_ID,
|
|
206
|
-
...mongoSessionOptions(session),
|
|
207
|
-
})
|
|
208
|
-
.skip(input.offset)
|
|
209
|
-
.limit(input.limit);
|
|
210
|
-
if (rawOrderBy === undefined) return cursor.toArray();
|
|
211
|
-
if (needsInMemoryOrder) {
|
|
212
|
-
const rows = await collections.releases
|
|
213
|
-
.find(createMongoReleaseWhere(input.where), {
|
|
214
|
-
projection: WITHOUT_MONGO_ID,
|
|
215
|
-
...mongoSessionOptions(session),
|
|
216
|
-
})
|
|
217
|
-
.toArray();
|
|
218
|
-
return sortRowsByOrder(rows, rawOrderBy).slice(
|
|
219
|
-
input.offset,
|
|
220
|
-
input.offset + input.limit,
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
const sort = createMongoSort(input);
|
|
224
|
-
return sort === undefined
|
|
225
|
-
? cursor.toArray()
|
|
226
|
-
: cursor.sort(sort).toArray();
|
|
227
|
-
}
|
|
228
|
-
case "release_catalogs": {
|
|
229
|
-
const cursor = collections.releaseCatalogs
|
|
230
|
-
.find(createMongoReleaseCatalogWhere(input.where), {
|
|
231
|
-
projection: WITHOUT_MONGO_ID,
|
|
232
|
-
...mongoSessionOptions(session),
|
|
233
|
-
})
|
|
234
|
-
.skip(input.offset)
|
|
235
|
-
.limit(input.limit);
|
|
236
|
-
if (rawOrderBy === undefined) return cursor.toArray();
|
|
237
|
-
if (needsInMemoryOrder) {
|
|
238
|
-
const rows = await collections.releaseCatalogs
|
|
239
|
-
.find(createMongoReleaseCatalogWhere(input.where), {
|
|
240
|
-
projection: WITHOUT_MONGO_ID,
|
|
241
|
-
...mongoSessionOptions(session),
|
|
242
|
-
})
|
|
243
|
-
.toArray();
|
|
244
|
-
return sortRowsByOrder(rows, rawOrderBy).slice(
|
|
245
|
-
input.offset,
|
|
246
|
-
input.offset + input.limit,
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
const sort = createMongoSort(input);
|
|
250
|
-
return sort === undefined
|
|
251
|
-
? cursor.toArray()
|
|
252
|
-
: cursor.sort(sort).toArray();
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
type MongoReadImplementation = Pick<
|
|
258
|
-
DatabasePluginImplementation,
|
|
259
|
-
"count" | "findMany" | "findOne"
|
|
260
|
-
>;
|
|
261
|
-
|
|
262
|
-
export const createMongoReads = (
|
|
263
|
-
collections: MongoCollections,
|
|
264
|
-
session?: ClientSession,
|
|
265
|
-
): MongoReadImplementation => ({
|
|
266
|
-
count: async (input) => {
|
|
267
|
-
if (input.distinct !== undefined) {
|
|
268
|
-
throw new DatabasePluginInputError("invalid-operation");
|
|
269
|
-
}
|
|
270
|
-
switch (input.model) {
|
|
271
|
-
case "bundles":
|
|
272
|
-
return collections.bundles.countDocuments(
|
|
273
|
-
activeBundleFilter(createMongoBundleWhere(input.where)),
|
|
274
|
-
mongoSessionOptions(session),
|
|
275
|
-
);
|
|
276
|
-
case "bundle_patches":
|
|
277
|
-
return collections.bundlePatches.countDocuments(
|
|
278
|
-
createMongoPatchWhere(input.where),
|
|
279
|
-
mongoSessionOptions(session),
|
|
280
|
-
);
|
|
281
|
-
case "releases":
|
|
282
|
-
return collections.releases.countDocuments(
|
|
283
|
-
createMongoReleaseWhere(input.where),
|
|
284
|
-
mongoSessionOptions(session),
|
|
285
|
-
);
|
|
286
|
-
case "bundle_installations":
|
|
287
|
-
return collections.bundleInstallations.countDocuments(
|
|
288
|
-
createMongoInstallationWhere(input.where),
|
|
289
|
-
{
|
|
290
|
-
...mongoSessionOptions(session),
|
|
291
|
-
collation: { locale: "simple" },
|
|
292
|
-
readPreference: "primary",
|
|
293
|
-
...(session === undefined
|
|
294
|
-
? { readConcern: { level: "snapshot" } }
|
|
295
|
-
: {}),
|
|
296
|
-
},
|
|
297
|
-
);
|
|
298
|
-
case "bundle_events":
|
|
299
|
-
return collections.bundleEvents.countDocuments(
|
|
300
|
-
createMongoEventWhere(input.where),
|
|
301
|
-
{
|
|
302
|
-
...mongoSessionOptions(session),
|
|
303
|
-
collation: { locale: "simple" },
|
|
304
|
-
readPreference: "primary",
|
|
305
|
-
...(session === undefined
|
|
306
|
-
? { readConcern: { level: "snapshot" } }
|
|
307
|
-
: {}),
|
|
308
|
-
},
|
|
309
|
-
);
|
|
310
|
-
}
|
|
311
|
-
},
|
|
312
|
-
findOne: async (input) => {
|
|
313
|
-
switch (input.model) {
|
|
314
|
-
case "bundles":
|
|
315
|
-
return collections.bundles.findOne(
|
|
316
|
-
activeBundleFilter(createMongoBundleWhere(input.where)),
|
|
317
|
-
{
|
|
318
|
-
projection: WITHOUT_INTERNAL_FIELDS,
|
|
319
|
-
...mongoSessionOptions(session),
|
|
320
|
-
},
|
|
321
|
-
);
|
|
322
|
-
case "channels":
|
|
323
|
-
return collections.channels.findOne(
|
|
324
|
-
createMongoChannelWhere(input.where),
|
|
325
|
-
{
|
|
326
|
-
projection: WITHOUT_MONGO_ID,
|
|
327
|
-
...mongoSessionOptions(session),
|
|
328
|
-
},
|
|
329
|
-
);
|
|
330
|
-
case "api_keys":
|
|
331
|
-
return collections.apiKeys.findOne(
|
|
332
|
-
createMongoApiKeyWhere(input.where),
|
|
333
|
-
{
|
|
334
|
-
projection: WITHOUT_MONGO_ID,
|
|
335
|
-
...mongoSessionOptions(session),
|
|
336
|
-
},
|
|
337
|
-
);
|
|
338
|
-
case "bundle_patches":
|
|
339
|
-
return collections.bundlePatches.findOne(
|
|
340
|
-
createMongoPatchWhere(input.where),
|
|
341
|
-
{
|
|
342
|
-
projection: WITHOUT_MONGO_ID,
|
|
343
|
-
...mongoSessionOptions(session),
|
|
344
|
-
},
|
|
345
|
-
);
|
|
346
|
-
case "releases":
|
|
347
|
-
return collections.releases.findOne(
|
|
348
|
-
createMongoReleaseWhere(input.where),
|
|
349
|
-
{
|
|
350
|
-
projection: WITHOUT_MONGO_ID,
|
|
351
|
-
...mongoSessionOptions(session),
|
|
352
|
-
},
|
|
353
|
-
);
|
|
354
|
-
case "release_catalogs":
|
|
355
|
-
return collections.releaseCatalogs.findOne(
|
|
356
|
-
createMongoReleaseCatalogWhere(input.where),
|
|
357
|
-
{
|
|
358
|
-
projection: WITHOUT_MONGO_ID,
|
|
359
|
-
...mongoSessionOptions(session),
|
|
360
|
-
},
|
|
361
|
-
);
|
|
362
|
-
case "bundle_installations":
|
|
363
|
-
return collections.bundleInstallations.findOne(
|
|
364
|
-
createMongoInstallationWhere(input.where),
|
|
365
|
-
{
|
|
366
|
-
projection: WITHOUT_MONGO_ID,
|
|
367
|
-
...mongoSessionOptions(session),
|
|
368
|
-
collation: { locale: "simple" },
|
|
369
|
-
readPreference: "primary",
|
|
370
|
-
},
|
|
371
|
-
);
|
|
372
|
-
}
|
|
373
|
-
},
|
|
374
|
-
findMany: (input) => {
|
|
375
|
-
if (input.distinctOn !== undefined) {
|
|
376
|
-
throw new DatabasePluginInputError("invalid-operation");
|
|
377
|
-
}
|
|
378
|
-
return findMongoRows(collections, input, session);
|
|
379
|
-
},
|
|
380
|
-
});
|