@hot-updater/server 0.36.6 → 1.0.0-rc.0
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/analytics/bounded/activeOverview.cjs +87 -0
- package/dist/analytics/bounded/activeOverview.mjs +85 -0
- package/dist/analytics/bounded/installationSearch.cjs +42 -0
- package/dist/analytics/bounded/installationSearch.mjs +42 -0
- package/dist/analytics/bounded/persistence.cjs +39 -0
- package/dist/analytics/bounded/persistence.mjs +38 -0
- package/dist/analytics/bounded/provider.cjs +170 -0
- package/dist/analytics/bounded/provider.d.cts +7 -0
- package/dist/analytics/bounded/provider.d.mts +7 -0
- package/dist/analytics/bounded/provider.mjs +170 -0
- package/dist/analytics/bounded/scan.cjs +144 -0
- package/dist/analytics/bounded/scan.mjs +138 -0
- package/dist/analytics/domain.d.cts +121 -0
- package/dist/analytics/domain.d.mts +121 -0
- package/dist/analytics/errors.cjs +22 -0
- package/dist/analytics/errors.mjs +20 -0
- package/dist/analytics/eventInput.cjs +111 -0
- package/dist/analytics/eventInput.mjs +111 -0
- package/dist/analytics/persistence.d.cts +6 -0
- package/dist/analytics/persistence.d.mts +6 -0
- package/dist/analytics/queryInput.cjs +58 -0
- package/dist/analytics/queryInput.mjs +55 -0
- package/dist/analytics/routes.cjs +63 -0
- package/dist/analytics/routes.mjs +61 -0
- package/dist/analytics/types.d.cts +17 -0
- package/dist/analytics/types.d.mts +17 -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/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/analytics/analytics.integration.spec.ts +144 -0
- package/src/analytics/bounded/activeOverview.spec.ts +189 -0
- package/src/analytics/bounded/activeOverview.ts +148 -0
- package/src/analytics/bounded/installationSearch.spec.ts +130 -0
- package/src/analytics/bounded/installationSearch.ts +69 -0
- package/src/analytics/bounded/persistence.ts +43 -0
- package/src/analytics/bounded/provider.spec.ts +219 -0
- package/src/analytics/bounded/provider.ts +229 -0
- package/src/analytics/bounded/scan.ts +235 -0
- package/src/analytics/domain.ts +139 -0
- package/src/analytics/errors.ts +18 -0
- package/src/analytics/eventInput.ts +168 -0
- package/src/analytics/persistence.ts +10 -0
- package/src/analytics/queryInput.ts +102 -0
- package/src/analytics/routes.ts +123 -0
- package/src/analytics/types.ts +44 -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/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
package/src/adapters/prisma.ts
CHANGED
|
@@ -1,340 +1,465 @@
|
|
|
1
|
-
import { NIL_UUID } from "@hot-updater/core";
|
|
2
|
-
import type {
|
|
3
|
-
Bundle,
|
|
4
|
-
DatabaseBundleQueryOptions,
|
|
5
|
-
DatabaseBundleQueryWhere,
|
|
6
|
-
} from "@hot-updater/plugin-core";
|
|
7
1
|
import {
|
|
8
|
-
calculatePagination,
|
|
9
2
|
createDatabasePlugin,
|
|
10
|
-
|
|
11
|
-
resolveUpdateInfoFromBundles,
|
|
3
|
+
DatabasePluginInputError,
|
|
12
4
|
} from "@hot-updater/plugin-core";
|
|
13
|
-
|
|
14
5
|
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
type
|
|
18
|
-
type
|
|
19
|
-
|
|
20
|
-
} from "
|
|
6
|
+
createDatabasePluginAdapter,
|
|
7
|
+
type DatabaseImplementationResult,
|
|
8
|
+
type DatabasePluginImplementation,
|
|
9
|
+
type FindManyDatabaseImplementationInput,
|
|
10
|
+
type TransactionDatabasePluginImplementation,
|
|
11
|
+
} from "@hot-updater/plugin-core/internal";
|
|
12
|
+
|
|
21
13
|
import {
|
|
22
14
|
getHotUpdaterSchemaVersion,
|
|
23
15
|
hotUpdaterSchema,
|
|
24
16
|
} from "../db/schema/registry";
|
|
25
17
|
import { generatePrismaSchema } from "../db/schemaGenerators";
|
|
26
18
|
import type {
|
|
27
|
-
|
|
19
|
+
DatabaseAdapterWithCapabilities,
|
|
28
20
|
ORMProvider,
|
|
21
|
+
ORMSQLProvider,
|
|
29
22
|
SchemaGenerator,
|
|
30
23
|
} from "../db/types";
|
|
24
|
+
import {
|
|
25
|
+
isChannelDeleteReferencedError,
|
|
26
|
+
translateChannelDeleteError,
|
|
27
|
+
} from "./databaseConstraintErrors";
|
|
28
|
+
import { hasNullOrderOverrides, sortRowsByOrder } from "./databasePluginUtils";
|
|
29
|
+
import { createPrismaOrderBy, createPrismaWhere } from "./prismaQuery";
|
|
30
|
+
import {
|
|
31
|
+
getPrismaDelegate,
|
|
32
|
+
parsePrismaBundleEventRow,
|
|
33
|
+
parsePrismaBundleRow,
|
|
34
|
+
parsePrismaChannelRow,
|
|
35
|
+
parsePrismaApiKeyRow,
|
|
36
|
+
parsePrismaPatchRow,
|
|
37
|
+
parsePrismaReleaseCatalogRow,
|
|
38
|
+
parsePrismaReleaseRow,
|
|
39
|
+
parsePrismaRows,
|
|
40
|
+
PrismaAdapterError,
|
|
41
|
+
} from "./prismaRows";
|
|
31
42
|
|
|
32
43
|
type PrismaRelationMode = "prisma" | "foreign-keys";
|
|
33
44
|
|
|
34
|
-
type
|
|
35
|
-
readonly
|
|
36
|
-
readonly createMany: (args: unknown) => Promise<unknown>;
|
|
37
|
-
readonly deleteMany: (args?: unknown) => Promise<unknown>;
|
|
38
|
-
readonly findFirst: (
|
|
39
|
-
args?: unknown,
|
|
40
|
-
) => Promise<Record<string, unknown> | null>;
|
|
41
|
-
readonly findMany: (args?: unknown) => Promise<Record<string, unknown>[]>;
|
|
42
|
-
readonly upsert: (args: unknown) => Promise<unknown>;
|
|
45
|
+
type PrismaTransactionOptions = {
|
|
46
|
+
readonly isolationLevel: "Serializable";
|
|
43
47
|
};
|
|
44
48
|
|
|
45
|
-
type
|
|
46
|
-
readonly $transaction
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
type PrismaTransactionClient = object & {
|
|
50
|
+
readonly $transaction: <TResult>(
|
|
51
|
+
callback: (client: object) => Promise<TResult>,
|
|
52
|
+
options?: PrismaTransactionOptions,
|
|
53
|
+
) => Promise<TResult>;
|
|
49
54
|
};
|
|
50
55
|
|
|
51
56
|
export interface PrismaConfig {
|
|
52
57
|
readonly prisma: object;
|
|
53
|
-
readonly provider:
|
|
58
|
+
readonly provider: ORMSQLProvider;
|
|
54
59
|
readonly relationMode?: PrismaRelationMode;
|
|
55
60
|
readonly db?: unknown;
|
|
56
61
|
}
|
|
57
62
|
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
) =>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
const hasCallbackTransaction = (
|
|
64
|
+
client: object,
|
|
65
|
+
): client is PrismaTransactionClient =>
|
|
66
|
+
"$transaction" in client && typeof client.$transaction === "function";
|
|
67
|
+
|
|
68
|
+
const runPrismaTransaction = <TResult>(
|
|
69
|
+
client: PrismaTransactionClient,
|
|
70
|
+
isolationLevel: "default" | "serializable",
|
|
71
|
+
callback: (client: object) => Promise<TResult>,
|
|
72
|
+
): Promise<TResult> => {
|
|
73
|
+
const execute = () =>
|
|
74
|
+
isolationLevel === "serializable"
|
|
75
|
+
? client.$transaction(callback, { isolationLevel: "Serializable" })
|
|
76
|
+
: client.$transaction(callback);
|
|
77
|
+
if (isolationLevel === "default") return execute();
|
|
78
|
+
|
|
79
|
+
return (async () => {
|
|
80
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
81
|
+
try {
|
|
82
|
+
return await execute();
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (
|
|
85
|
+
attempt >= 2 ||
|
|
86
|
+
typeof error !== "object" ||
|
|
87
|
+
error === null ||
|
|
88
|
+
!("code" in error) ||
|
|
89
|
+
error.code !== "P2034"
|
|
90
|
+
) {
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
})();
|
|
68
96
|
};
|
|
69
97
|
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (!delegate || typeof delegate !== "object") {
|
|
76
|
-
throw new Error(`Prisma client is missing model delegate "${model}".`);
|
|
98
|
+
const assertPrismaProvider = (provider: ORMProvider): void => {
|
|
99
|
+
if (provider === "mongodb") {
|
|
100
|
+
throw new PrismaAdapterError(
|
|
101
|
+
"Prisma adapter does not support MongoDB; use mongodbAdapter instead",
|
|
102
|
+
);
|
|
77
103
|
}
|
|
78
|
-
return delegate as PrismaDelegate;
|
|
79
104
|
};
|
|
80
105
|
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
106
|
+
const findMany = async (
|
|
107
|
+
client: object,
|
|
108
|
+
input: FindManyDatabaseImplementationInput,
|
|
109
|
+
provider: ORMSQLProvider,
|
|
110
|
+
): Promise<readonly DatabaseImplementationResult[]> => {
|
|
111
|
+
if (input.distinctOn !== undefined) {
|
|
112
|
+
throw new DatabasePluginInputError("invalid-operation");
|
|
87
113
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
114
|
+
const rawOrderBy = input.orderBy;
|
|
115
|
+
const orderBy = createPrismaOrderBy(rawOrderBy);
|
|
116
|
+
const shouldSortInMemory =
|
|
117
|
+
rawOrderBy !== undefined && hasNullOrderOverrides(rawOrderBy);
|
|
118
|
+
const rows = shouldSortInMemory
|
|
119
|
+
? sortRowsByOrder(
|
|
120
|
+
(await getPrismaDelegate(client, input.model).findMany({
|
|
121
|
+
where: createPrismaWhere(input.where, provider),
|
|
122
|
+
})) as Record<string, unknown>[],
|
|
123
|
+
rawOrderBy,
|
|
124
|
+
).slice(input.offset, input.offset + input.limit)
|
|
125
|
+
: await getPrismaDelegate(client, input.model).findMany({
|
|
126
|
+
where: createPrismaWhere(input.where, provider),
|
|
127
|
+
...(orderBy ? { orderBy } : {}),
|
|
128
|
+
skip: input.offset,
|
|
129
|
+
take: input.limit,
|
|
130
|
+
});
|
|
131
|
+
switch (input.model) {
|
|
132
|
+
case "bundles":
|
|
133
|
+
return parsePrismaRows(rows, parsePrismaBundleRow);
|
|
134
|
+
case "bundle_patches":
|
|
135
|
+
return parsePrismaRows(rows, parsePrismaPatchRow);
|
|
136
|
+
case "bundle_events":
|
|
137
|
+
return parsePrismaRows(rows, parsePrismaBundleEventRow);
|
|
138
|
+
case "channels":
|
|
139
|
+
return parsePrismaRows(rows, parsePrismaChannelRow);
|
|
140
|
+
case "api_keys":
|
|
141
|
+
return parsePrismaRows(rows, parsePrismaApiKeyRow);
|
|
142
|
+
case "releases":
|
|
143
|
+
return parsePrismaRows(rows, parsePrismaReleaseRow);
|
|
144
|
+
case "release_catalogs":
|
|
145
|
+
return parsePrismaRows(rows, parsePrismaReleaseCatalogRow);
|
|
97
146
|
}
|
|
147
|
+
};
|
|
98
148
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
...(where.id.gte !== undefined ? { gte: where.id.gte } : {}),
|
|
112
|
-
...(where.id.lt !== undefined ? { lt: where.id.lt } : {}),
|
|
113
|
-
...(where.id.lte !== undefined ? { lte: where.id.lte } : {}),
|
|
114
|
-
...(where.id.in !== undefined ? { in: where.id.in } : {}),
|
|
115
|
-
},
|
|
116
|
-
}
|
|
117
|
-
: {}),
|
|
118
|
-
...(targetAppVersionFilters.length > 0
|
|
119
|
-
? { AND: targetAppVersionFilters }
|
|
120
|
-
: {}),
|
|
121
|
-
};
|
|
149
|
+
const assertPatchReferences = async (
|
|
150
|
+
client: object,
|
|
151
|
+
bundleId: string,
|
|
152
|
+
baseBundleId: string,
|
|
153
|
+
): Promise<void> => {
|
|
154
|
+
const ids = Array.from(new Set([bundleId, baseBundleId]));
|
|
155
|
+
const count = await getPrismaDelegate(client, "bundles").count({
|
|
156
|
+
where: { id: { in: ids } },
|
|
157
|
+
});
|
|
158
|
+
if (count !== ids.length) {
|
|
159
|
+
throw new PrismaAdapterError("patch references a missing bundle");
|
|
160
|
+
}
|
|
122
161
|
};
|
|
123
162
|
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
163
|
+
const createCrudImplementation = (
|
|
164
|
+
client: object,
|
|
165
|
+
provider: ORMSQLProvider,
|
|
166
|
+
relationMode: PrismaRelationMode,
|
|
167
|
+
): TransactionDatabasePluginImplementation &
|
|
168
|
+
Pick<DatabasePluginImplementation, "deleteChannel" | "insertChannel"> => ({
|
|
169
|
+
deleteChannel: async ({ id }) => {
|
|
170
|
+
const channels = getPrismaDelegate(client, "channels");
|
|
171
|
+
const existing = await channels.findFirst({ where: { id } });
|
|
172
|
+
if (existing === null) return { deleted: false, reason: "not_found" };
|
|
173
|
+
const referencedReleases = await getPrismaDelegate(
|
|
174
|
+
client,
|
|
175
|
+
"releases",
|
|
176
|
+
).count({ where: { channel_id: id } });
|
|
177
|
+
if (referencedReleases > 0) {
|
|
178
|
+
return { deleted: false, reason: "not_empty" };
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
await channels.deleteMany({ where: { id } });
|
|
182
|
+
} catch (error) {
|
|
183
|
+
if (isChannelDeleteReferencedError(error)) {
|
|
184
|
+
return { deleted: false, reason: "not_empty" };
|
|
133
185
|
}
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
return { deleted: true };
|
|
189
|
+
},
|
|
190
|
+
insertChannel: async (input) => {
|
|
191
|
+
const delegate = getPrismaDelegate(client, "channels");
|
|
192
|
+
const existing = await delegate.findFirst({
|
|
193
|
+
where: { name: input.row.name },
|
|
194
|
+
});
|
|
195
|
+
if (existing !== null) {
|
|
196
|
+
return { row: parsePrismaChannelRow(existing), inserted: false };
|
|
197
|
+
}
|
|
198
|
+
const row = parsePrismaChannelRow(
|
|
199
|
+
await delegate.upsert({
|
|
200
|
+
where: { name: input.row.name },
|
|
201
|
+
create: input.row,
|
|
202
|
+
update: {},
|
|
203
|
+
}),
|
|
204
|
+
);
|
|
205
|
+
return { row, inserted: row.id === input.row.id };
|
|
206
|
+
},
|
|
207
|
+
create: async (input) => {
|
|
208
|
+
if (input.model === "bundle_patches") {
|
|
209
|
+
await assertPatchReferences(
|
|
210
|
+
client,
|
|
211
|
+
input.data.bundle_id,
|
|
212
|
+
input.data.base_bundle_id,
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
const delegate = getPrismaDelegate(client, input.model);
|
|
216
|
+
let row: unknown;
|
|
217
|
+
if (input.onConflict === "ignore") {
|
|
218
|
+
const where =
|
|
219
|
+
input.model === "channels"
|
|
220
|
+
? { name: input.data.name }
|
|
221
|
+
: { hash: input.data.hash };
|
|
222
|
+
row = await delegate.upsert({
|
|
223
|
+
where,
|
|
224
|
+
create: input.data,
|
|
225
|
+
update: {},
|
|
143
226
|
});
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
227
|
+
} else {
|
|
228
|
+
row = await delegate.create({ data: input.data });
|
|
229
|
+
}
|
|
230
|
+
switch (input.model) {
|
|
231
|
+
case "bundles":
|
|
232
|
+
return parsePrismaBundleRow(row);
|
|
233
|
+
case "bundle_patches":
|
|
234
|
+
return parsePrismaPatchRow(row);
|
|
235
|
+
case "bundle_events":
|
|
236
|
+
return parsePrismaBundleEventRow(row);
|
|
237
|
+
case "channels":
|
|
238
|
+
return parsePrismaChannelRow(row);
|
|
239
|
+
case "api_keys":
|
|
240
|
+
return parsePrismaApiKeyRow(row);
|
|
241
|
+
case "releases":
|
|
242
|
+
return parsePrismaReleaseRow(row);
|
|
243
|
+
case "release_catalogs":
|
|
244
|
+
return parsePrismaReleaseCatalogRow(row);
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
update: async (input) => {
|
|
248
|
+
const id = input.where[0]?.value;
|
|
249
|
+
if (typeof id !== "string") {
|
|
250
|
+
throw new PrismaAdapterError(
|
|
251
|
+
`${input.model} update requires a string id`,
|
|
157
252
|
);
|
|
158
|
-
|
|
159
|
-
|
|
253
|
+
}
|
|
254
|
+
if (input.model === "api_keys") {
|
|
255
|
+
const delegate = getPrismaDelegate(client, "api_keys");
|
|
256
|
+
const current = await delegate.findFirst({ where: { id } });
|
|
257
|
+
if (current === null) return null;
|
|
258
|
+
await delegate.update({ where: { id }, data: input.update });
|
|
259
|
+
const stored = await delegate.findFirst({ where: { id } });
|
|
260
|
+
return stored === null ? null : parsePrismaApiKeyRow(stored);
|
|
261
|
+
}
|
|
262
|
+
if (input.model === "releases") {
|
|
263
|
+
const delegate = getPrismaDelegate(client, "releases");
|
|
264
|
+
const current = await delegate.findFirst({ where: { id } });
|
|
265
|
+
if (current === null) return null;
|
|
266
|
+
await delegate.update({ where: { id }, data: input.update });
|
|
267
|
+
const stored = await delegate.findFirst({ where: { id } });
|
|
268
|
+
return stored === null ? null : parsePrismaReleaseRow(stored);
|
|
269
|
+
}
|
|
270
|
+
if (input.model === "release_catalogs") {
|
|
271
|
+
const delegate = getPrismaDelegate(client, "release_catalogs");
|
|
272
|
+
const current = await delegate.findFirst({ where: { scope_key: id } });
|
|
273
|
+
if (current === null) return null;
|
|
274
|
+
await delegate.update({ where: { scope_key: id }, data: input.update });
|
|
275
|
+
const stored = await delegate.findFirst({ where: { scope_key: id } });
|
|
276
|
+
return stored === null ? null : parsePrismaReleaseCatalogRow(stored);
|
|
277
|
+
}
|
|
278
|
+
const delegate = getPrismaDelegate(client, "bundles");
|
|
279
|
+
if (delegate.updateMany === undefined) {
|
|
280
|
+
throw new PrismaAdapterError(
|
|
281
|
+
'model delegate "bundles" requires updateMany',
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
const current = await delegate.findFirst({ where: { id } });
|
|
285
|
+
if (current === null) return null;
|
|
286
|
+
await delegate.updateMany({
|
|
287
|
+
where: { id },
|
|
288
|
+
data: input.update,
|
|
289
|
+
});
|
|
290
|
+
const stored = await delegate.findFirst({ where: { id } });
|
|
291
|
+
if (stored === null) return null;
|
|
292
|
+
return parsePrismaBundleRow(stored);
|
|
293
|
+
},
|
|
294
|
+
delete: async (input) => {
|
|
295
|
+
if (input.model === "bundles" && relationMode === "prisma") {
|
|
296
|
+
const rows = await getPrismaDelegate(client, "bundles").findMany({
|
|
297
|
+
where: createPrismaWhere(input.where, provider),
|
|
298
|
+
});
|
|
299
|
+
const ids = parsePrismaRows(rows, parsePrismaBundleRow).map(
|
|
300
|
+
({ id }) => id,
|
|
160
301
|
);
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const bundles = getDelegate(client, "bundles");
|
|
167
|
-
const patches = getDelegate(client, "bundle_patches");
|
|
168
|
-
const row = bundleToRow(bundle);
|
|
169
|
-
const { id, ...update } = row;
|
|
170
|
-
await bundles.upsert({
|
|
171
|
-
where: { id },
|
|
172
|
-
create: row,
|
|
173
|
-
update,
|
|
302
|
+
if (ids.length === 0) return;
|
|
303
|
+
await getPrismaDelegate(client, "bundle_patches").deleteMany({
|
|
304
|
+
where: {
|
|
305
|
+
OR: [{ bundle_id: { in: ids } }, { base_bundle_id: { in: ids } }],
|
|
306
|
+
},
|
|
174
307
|
});
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
308
|
+
}
|
|
309
|
+
try {
|
|
310
|
+
await getPrismaDelegate(client, input.model).deleteMany({
|
|
311
|
+
where: createPrismaWhere(input.where, provider),
|
|
312
|
+
});
|
|
313
|
+
} catch (error) {
|
|
314
|
+
if (input.model === "channels") {
|
|
315
|
+
translateChannelDeleteError(error);
|
|
179
316
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
options: DatabaseBundleQueryOptions & { offset?: number },
|
|
191
|
-
) {
|
|
192
|
-
const bundles = getDelegate(prisma, "bundles");
|
|
193
|
-
const offset = options.offset ?? 0;
|
|
194
|
-
const orderBy = options.orderBy ?? { field: "id", direction: "desc" };
|
|
195
|
-
const where = prismaWhere(options.where);
|
|
196
|
-
const [total, rows] = await Promise.all([
|
|
197
|
-
bundles.count({ where }),
|
|
198
|
-
bundles.findMany({
|
|
199
|
-
where,
|
|
200
|
-
orderBy: { id: orderBy.direction },
|
|
201
|
-
skip: offset,
|
|
202
|
-
take: options.limit,
|
|
203
|
-
}),
|
|
204
|
-
]);
|
|
205
|
-
const patchMap = await fetchPatchMap(
|
|
206
|
-
rows.map((row) => String(row["id"])),
|
|
207
|
-
);
|
|
208
|
-
return {
|
|
209
|
-
data: rows.map((row) =>
|
|
210
|
-
rowToBundle(
|
|
211
|
-
row as BundleRow,
|
|
212
|
-
patchMap.get(String(row["id"])) ?? [],
|
|
213
|
-
),
|
|
214
|
-
),
|
|
215
|
-
pagination: calculatePagination(total, {
|
|
216
|
-
limit: options.limit,
|
|
217
|
-
offset,
|
|
218
|
-
}),
|
|
219
|
-
};
|
|
220
|
-
},
|
|
221
|
-
async getUpdateInfo(args, context) {
|
|
222
|
-
const bundles = getDelegate(prisma, "bundles");
|
|
223
|
-
|
|
224
|
-
if (args._updateStrategy === "appVersion") {
|
|
225
|
-
const channel = args.channel ?? "production";
|
|
226
|
-
const minBundleId = args.minBundleId ?? NIL_UUID;
|
|
227
|
-
const rows = await bundles.findMany({
|
|
228
|
-
select: { target_app_version: true },
|
|
229
|
-
where: {
|
|
230
|
-
enabled: true,
|
|
231
|
-
platform: args.platform,
|
|
232
|
-
channel,
|
|
233
|
-
id: { gte: minBundleId },
|
|
234
|
-
target_app_version: { not: null },
|
|
235
|
-
},
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
const targetAppVersions = Array.from(
|
|
239
|
-
new Set(
|
|
240
|
-
rows
|
|
241
|
-
.map((row) => row["target_app_version"])
|
|
242
|
-
.filter(
|
|
243
|
-
(value): value is string =>
|
|
244
|
-
typeof value === "string" && value.length > 0,
|
|
245
|
-
),
|
|
246
|
-
),
|
|
247
|
-
);
|
|
248
|
-
const compatibleAppVersions = filterCompatibleAppVersions(
|
|
249
|
-
targetAppVersions,
|
|
250
|
-
args.appVersion,
|
|
251
|
-
);
|
|
252
|
-
const updateBundles =
|
|
253
|
-
compatibleAppVersions.length > 0
|
|
254
|
-
? await bundles
|
|
255
|
-
.findMany({
|
|
256
|
-
where: {
|
|
257
|
-
enabled: true,
|
|
258
|
-
platform: args.platform,
|
|
259
|
-
channel,
|
|
260
|
-
id: { gte: minBundleId },
|
|
261
|
-
target_app_version: { in: compatibleAppVersions },
|
|
262
|
-
},
|
|
263
|
-
orderBy: { id: "desc" },
|
|
264
|
-
})
|
|
265
|
-
.then(mapRowsToBundles)
|
|
266
|
-
: [];
|
|
267
|
-
|
|
268
|
-
return resolveUpdateInfoFromBundles({
|
|
269
|
-
args: { ...args, channel, minBundleId },
|
|
270
|
-
bundles: updateBundles,
|
|
271
|
-
context,
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
const channel = args.channel ?? "production";
|
|
276
|
-
const minBundleId = args.minBundleId ?? NIL_UUID;
|
|
277
|
-
const rows = await bundles.findMany({
|
|
278
|
-
where: {
|
|
279
|
-
enabled: true,
|
|
280
|
-
platform: args.platform,
|
|
281
|
-
channel,
|
|
282
|
-
id: { gte: minBundleId },
|
|
283
|
-
fingerprint_hash: args.fingerprintHash,
|
|
284
|
-
},
|
|
285
|
-
orderBy: { id: "desc" },
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
return resolveUpdateInfoFromBundles({
|
|
289
|
-
args: { ...args, channel, minBundleId },
|
|
290
|
-
bundles: await mapRowsToBundles(rows),
|
|
291
|
-
context,
|
|
292
|
-
});
|
|
293
|
-
},
|
|
294
|
-
async getChannels() {
|
|
295
|
-
const bundles = getDelegate(prisma, "bundles");
|
|
296
|
-
const rows = await bundles.findMany({
|
|
297
|
-
select: { channel: true },
|
|
298
|
-
orderBy: { channel: "asc" },
|
|
299
|
-
});
|
|
300
|
-
return Array.from(new Set(rows.map((row) => String(row["channel"]))));
|
|
301
|
-
},
|
|
302
|
-
async commitBundle({ changedSets }) {
|
|
303
|
-
await runInTransaction(async (client) => {
|
|
304
|
-
const bundles = getDelegate(client, "bundles");
|
|
305
|
-
const patches = getDelegate(client, "bundle_patches");
|
|
306
|
-
for (const change of changedSets) {
|
|
307
|
-
if (change.operation === "delete") {
|
|
308
|
-
await patches.deleteMany({
|
|
309
|
-
where: { bundle_id: change.data.id },
|
|
310
|
-
});
|
|
311
|
-
await patches.deleteMany({
|
|
312
|
-
where: { base_bundle_id: change.data.id },
|
|
313
|
-
});
|
|
314
|
-
await bundles.deleteMany({ where: { id: change.data.id } });
|
|
315
|
-
continue;
|
|
316
|
-
}
|
|
317
|
-
await upsertBundle(client, change.data);
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
},
|
|
321
|
-
};
|
|
317
|
+
throw error;
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
count: async (input) => {
|
|
321
|
+
if (input.distinct !== undefined) {
|
|
322
|
+
throw new DatabasePluginInputError("invalid-operation");
|
|
323
|
+
}
|
|
324
|
+
return getPrismaDelegate(client, input.model).count({
|
|
325
|
+
where: createPrismaWhere(input.where, provider),
|
|
326
|
+
});
|
|
322
327
|
},
|
|
328
|
+
findOne: async (input) => {
|
|
329
|
+
const row = await getPrismaDelegate(client, input.model).findFirst({
|
|
330
|
+
where: createPrismaWhere(input.where, provider),
|
|
331
|
+
});
|
|
332
|
+
if (row === null) return null;
|
|
333
|
+
switch (input.model) {
|
|
334
|
+
case "bundles":
|
|
335
|
+
return parsePrismaBundleRow(row);
|
|
336
|
+
case "bundle_patches":
|
|
337
|
+
return parsePrismaPatchRow(row);
|
|
338
|
+
case "channels":
|
|
339
|
+
return parsePrismaChannelRow(row);
|
|
340
|
+
case "api_keys":
|
|
341
|
+
return parsePrismaApiKeyRow(row);
|
|
342
|
+
case "releases":
|
|
343
|
+
return parsePrismaReleaseRow(row);
|
|
344
|
+
case "release_catalogs":
|
|
345
|
+
return parsePrismaReleaseCatalogRow(row);
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
findMany: (input) => findMany(client, input, provider),
|
|
323
349
|
});
|
|
324
350
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
351
|
+
const createPrismaImplementation = (
|
|
352
|
+
client: object,
|
|
353
|
+
relationMode: PrismaRelationMode,
|
|
354
|
+
provider: ORMSQLProvider,
|
|
355
|
+
): DatabasePluginImplementation => {
|
|
356
|
+
const crud = createCrudImplementation(client, provider, relationMode);
|
|
357
|
+
const implementation: DatabasePluginImplementation = {
|
|
358
|
+
...crud,
|
|
359
|
+
deleteChannel: (input) => {
|
|
360
|
+
if (!hasCallbackTransaction(client)) {
|
|
361
|
+
throw new PrismaAdapterError(
|
|
362
|
+
"channel deletion requires callback transactions",
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
return runPrismaTransaction(client, "serializable", (transactionClient) =>
|
|
366
|
+
createCrudImplementation(
|
|
367
|
+
transactionClient,
|
|
368
|
+
provider,
|
|
369
|
+
relationMode,
|
|
370
|
+
).deleteChannel(input),
|
|
371
|
+
);
|
|
372
|
+
},
|
|
373
|
+
delete: (input) => {
|
|
374
|
+
if (input.model !== "bundles" || relationMode === "foreign-keys") {
|
|
375
|
+
return crud.delete(input);
|
|
376
|
+
}
|
|
377
|
+
if (!hasCallbackTransaction(client)) {
|
|
378
|
+
throw new PrismaAdapterError(
|
|
379
|
+
'relation mode "prisma" requires callback transactions',
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
return runPrismaTransaction(client, "serializable", (transactionClient) =>
|
|
383
|
+
createCrudImplementation(
|
|
384
|
+
transactionClient,
|
|
385
|
+
provider,
|
|
386
|
+
relationMode,
|
|
387
|
+
).delete(input),
|
|
388
|
+
);
|
|
389
|
+
},
|
|
390
|
+
};
|
|
391
|
+
if (relationMode === "prisma" && !hasCallbackTransaction(client)) {
|
|
392
|
+
throw new PrismaAdapterError(
|
|
393
|
+
'relation mode "prisma" requires callback transactions',
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
if (!hasCallbackTransaction(client)) return implementation;
|
|
397
|
+
if (relationMode === "prisma") {
|
|
398
|
+
implementation.create = (input) =>
|
|
399
|
+
runPrismaTransaction(client, "serializable", (transactionClient) =>
|
|
400
|
+
createCrudImplementation(
|
|
401
|
+
transactionClient,
|
|
402
|
+
provider,
|
|
403
|
+
relationMode,
|
|
404
|
+
).create(input),
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
implementation.update = (input) =>
|
|
408
|
+
runPrismaTransaction(
|
|
409
|
+
client,
|
|
410
|
+
relationMode === "prisma" ? "serializable" : "default",
|
|
411
|
+
(transactionClient) =>
|
|
412
|
+
createCrudImplementation(
|
|
413
|
+
transactionClient,
|
|
414
|
+
provider,
|
|
415
|
+
relationMode,
|
|
416
|
+
).update(input),
|
|
417
|
+
);
|
|
418
|
+
return {
|
|
419
|
+
...implementation,
|
|
420
|
+
transaction: (callback) =>
|
|
421
|
+
runPrismaTransaction(
|
|
422
|
+
client,
|
|
423
|
+
"serializable",
|
|
424
|
+
async (transactionClient) => {
|
|
425
|
+
return callback(
|
|
426
|
+
createCrudImplementation(transactionClient, provider, relationMode),
|
|
427
|
+
);
|
|
428
|
+
},
|
|
336
429
|
),
|
|
337
|
-
|
|
430
|
+
};
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
export const prismaAdapter = (
|
|
434
|
+
config: PrismaConfig,
|
|
435
|
+
): DatabaseAdapterWithCapabilities => {
|
|
436
|
+
assertPrismaProvider(config.provider);
|
|
437
|
+
const adapter = createDatabasePluginAdapter(
|
|
438
|
+
"prisma",
|
|
439
|
+
createPrismaImplementation(
|
|
440
|
+
config.prisma,
|
|
441
|
+
config.relationMode ?? "foreign-keys",
|
|
442
|
+
config.provider,
|
|
443
|
+
),
|
|
444
|
+
);
|
|
445
|
+
return Object.assign(
|
|
446
|
+
createDatabasePlugin({
|
|
447
|
+
name: "prisma",
|
|
448
|
+
models: adapter.models,
|
|
449
|
+
commit: adapter.commit,
|
|
338
450
|
}),
|
|
339
|
-
|
|
451
|
+
{
|
|
452
|
+
adapterName: "prisma",
|
|
453
|
+
provider: config.provider,
|
|
454
|
+
generateSchema: ((version) => ({
|
|
455
|
+
code: generatePrismaSchema(
|
|
456
|
+
config.provider,
|
|
457
|
+
version === "latest"
|
|
458
|
+
? hotUpdaterSchema
|
|
459
|
+
: getHotUpdaterSchemaVersion(version),
|
|
460
|
+
),
|
|
461
|
+
path: "./prisma/schema/hot_updater.prisma",
|
|
462
|
+
})) satisfies SchemaGenerator,
|
|
463
|
+
},
|
|
464
|
+
);
|
|
340
465
|
};
|