@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/dist/adapters/prisma.cjs
CHANGED
|
@@ -2,202 +2,227 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
require("../_virtual/_rolldown/runtime.cjs");
|
|
3
3
|
const require_registry = require("../db/schema/registry.cjs");
|
|
4
4
|
const require_schemaGenerators = require("../db/schemaGenerators.cjs");
|
|
5
|
-
const
|
|
5
|
+
const require_databaseConstraintErrors = require("./databaseConstraintErrors.cjs");
|
|
6
|
+
const require_databasePluginUtils = require("./databasePluginUtils.cjs");
|
|
7
|
+
const require_prismaQuery = require("./prismaQuery.cjs");
|
|
8
|
+
const require_prismaRows = require("./prismaRows.cjs");
|
|
6
9
|
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
7
|
-
let
|
|
10
|
+
let _hot_updater_plugin_core_internal = require("@hot-updater/plugin-core/internal");
|
|
8
11
|
//#region src/adapters/prisma.ts
|
|
9
|
-
const
|
|
10
|
-
|
|
12
|
+
const hasCallbackTransaction = (client) => "$transaction" in client && typeof client.$transaction === "function";
|
|
13
|
+
const runPrismaTransaction = (client, isolationLevel, callback) => {
|
|
14
|
+
const execute = () => isolationLevel === "serializable" ? client.$transaction(callback, { isolationLevel: "Serializable" }) : client.$transaction(callback);
|
|
15
|
+
if (isolationLevel === "default") return execute();
|
|
16
|
+
return (async () => {
|
|
17
|
+
for (let attempt = 0;; attempt += 1) try {
|
|
18
|
+
return await execute();
|
|
19
|
+
} catch (error) {
|
|
20
|
+
if (attempt >= 2 || typeof error !== "object" || error === null || !("code" in error) || error.code !== "P2034") throw error;
|
|
21
|
+
}
|
|
22
|
+
})();
|
|
11
23
|
};
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
if (!delegate || typeof delegate !== "object") throw new Error(`Prisma client is missing model delegate "${model}".`);
|
|
15
|
-
return delegate;
|
|
24
|
+
const assertPrismaProvider = (provider) => {
|
|
25
|
+
if (provider === "mongodb") throw new require_prismaRows.PrismaAdapterError("Prisma adapter does not support MongoDB; use mongodbAdapter instead");
|
|
16
26
|
};
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
...
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
27
|
+
const findMany = async (client, input, provider) => {
|
|
28
|
+
if (input.distinctOn !== void 0) throw new _hot_updater_plugin_core.DatabasePluginInputError("invalid-operation");
|
|
29
|
+
const rawOrderBy = input.orderBy;
|
|
30
|
+
const orderBy = require_prismaQuery.createPrismaOrderBy(rawOrderBy);
|
|
31
|
+
const rows = rawOrderBy !== void 0 && require_databasePluginUtils.hasNullOrderOverrides(rawOrderBy) ? require_databasePluginUtils.sortRowsByOrder(await require_prismaRows.getPrismaDelegate(client, input.model).findMany({ where: require_prismaQuery.createPrismaWhere(input.where, provider) }), rawOrderBy).slice(input.offset, input.offset + input.limit) : await require_prismaRows.getPrismaDelegate(client, input.model).findMany({
|
|
32
|
+
where: require_prismaQuery.createPrismaWhere(input.where, provider),
|
|
33
|
+
...orderBy ? { orderBy } : {},
|
|
34
|
+
skip: input.offset,
|
|
35
|
+
take: input.limit
|
|
36
|
+
});
|
|
37
|
+
switch (input.model) {
|
|
38
|
+
case "bundles": return require_prismaRows.parsePrismaRows(rows, require_prismaRows.parsePrismaBundleRow);
|
|
39
|
+
case "bundle_patches": return require_prismaRows.parsePrismaRows(rows, require_prismaRows.parsePrismaPatchRow);
|
|
40
|
+
case "bundle_events": return require_prismaRows.parsePrismaRows(rows, require_prismaRows.parsePrismaBundleEventRow);
|
|
41
|
+
case "channels": return require_prismaRows.parsePrismaRows(rows, require_prismaRows.parsePrismaChannelRow);
|
|
42
|
+
case "api_keys": return require_prismaRows.parsePrismaRows(rows, require_prismaRows.parsePrismaApiKeyRow);
|
|
43
|
+
case "releases": return require_prismaRows.parsePrismaRows(rows, require_prismaRows.parsePrismaReleaseRow);
|
|
44
|
+
case "release_catalogs": return require_prismaRows.parsePrismaRows(rows, require_prismaRows.parsePrismaReleaseCatalogRow);
|
|
45
|
+
}
|
|
37
46
|
};
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const patchMap = /* @__PURE__ */ new Map();
|
|
49
|
-
if (bundleIds.length === 0) return patchMap;
|
|
50
|
-
const rows = await patches.findMany({
|
|
51
|
-
where: { bundle_id: { in: [...bundleIds] } },
|
|
52
|
-
orderBy: { order_index: "asc" }
|
|
53
|
-
});
|
|
54
|
-
for (const row of rows) {
|
|
55
|
-
const patch = row;
|
|
56
|
-
const current = patchMap.get(patch.bundle_id) ?? [];
|
|
57
|
-
current.push(patch);
|
|
58
|
-
patchMap.set(patch.bundle_id, current);
|
|
59
|
-
}
|
|
60
|
-
return patchMap;
|
|
47
|
+
const assertPatchReferences = async (client, bundleId, baseBundleId) => {
|
|
48
|
+
const ids = Array.from(new Set([bundleId, baseBundleId]));
|
|
49
|
+
if (await require_prismaRows.getPrismaDelegate(client, "bundles").count({ where: { id: { in: ids } } }) !== ids.length) throw new require_prismaRows.PrismaAdapterError("patch references a missing bundle");
|
|
50
|
+
};
|
|
51
|
+
const createCrudImplementation = (client, provider, relationMode) => ({
|
|
52
|
+
deleteChannel: async ({ id }) => {
|
|
53
|
+
const channels = require_prismaRows.getPrismaDelegate(client, "channels");
|
|
54
|
+
if (await channels.findFirst({ where: { id } }) === null) return {
|
|
55
|
+
deleted: false,
|
|
56
|
+
reason: "not_found"
|
|
61
57
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
if (await require_prismaRows.getPrismaDelegate(client, "releases").count({ where: { channel_id: id } }) > 0) return {
|
|
59
|
+
deleted: false,
|
|
60
|
+
reason: "not_empty"
|
|
65
61
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
62
|
+
try {
|
|
63
|
+
await channels.deleteMany({ where: { id } });
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (require_databaseConstraintErrors.isChannelDeleteReferencedError(error)) return {
|
|
66
|
+
deleted: false,
|
|
67
|
+
reason: "not_empty"
|
|
68
|
+
};
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
return { deleted: true };
|
|
72
|
+
},
|
|
73
|
+
insertChannel: async (input) => {
|
|
74
|
+
const delegate = require_prismaRows.getPrismaDelegate(client, "channels");
|
|
75
|
+
const existing = await delegate.findFirst({ where: { name: input.row.name } });
|
|
76
|
+
if (existing !== null) return {
|
|
77
|
+
row: require_prismaRows.parsePrismaChannelRow(existing),
|
|
78
|
+
inserted: false
|
|
79
79
|
};
|
|
80
|
+
const row = require_prismaRows.parsePrismaChannelRow(await delegate.upsert({
|
|
81
|
+
where: { name: input.row.name },
|
|
82
|
+
create: input.row,
|
|
83
|
+
update: {}
|
|
84
|
+
}));
|
|
80
85
|
return {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (!row) return null;
|
|
84
|
-
return require_bundleRows.rowToBundle(row, (await fetchPatchMap([bundleId])).get(bundleId) ?? []);
|
|
85
|
-
},
|
|
86
|
-
async getBundles(options) {
|
|
87
|
-
const bundles = getDelegate(prisma, "bundles");
|
|
88
|
-
const offset = options.offset ?? 0;
|
|
89
|
-
const orderBy = options.orderBy ?? {
|
|
90
|
-
field: "id",
|
|
91
|
-
direction: "desc"
|
|
92
|
-
};
|
|
93
|
-
const where = prismaWhere(options.where);
|
|
94
|
-
const [total, rows] = await Promise.all([bundles.count({ where }), bundles.findMany({
|
|
95
|
-
where,
|
|
96
|
-
orderBy: { id: orderBy.direction },
|
|
97
|
-
skip: offset,
|
|
98
|
-
take: options.limit
|
|
99
|
-
})]);
|
|
100
|
-
const patchMap = await fetchPatchMap(rows.map((row) => String(row["id"])));
|
|
101
|
-
return {
|
|
102
|
-
data: rows.map((row) => require_bundleRows.rowToBundle(row, patchMap.get(String(row["id"])) ?? [])),
|
|
103
|
-
pagination: (0, _hot_updater_plugin_core.calculatePagination)(total, {
|
|
104
|
-
limit: options.limit,
|
|
105
|
-
offset
|
|
106
|
-
})
|
|
107
|
-
};
|
|
108
|
-
},
|
|
109
|
-
async getUpdateInfo(args, context) {
|
|
110
|
-
const bundles = getDelegate(prisma, "bundles");
|
|
111
|
-
if (args._updateStrategy === "appVersion") {
|
|
112
|
-
const channel = args.channel ?? "production";
|
|
113
|
-
const minBundleId = args.minBundleId ?? _hot_updater_core.NIL_UUID;
|
|
114
|
-
const rows = await bundles.findMany({
|
|
115
|
-
select: { target_app_version: true },
|
|
116
|
-
where: {
|
|
117
|
-
enabled: true,
|
|
118
|
-
platform: args.platform,
|
|
119
|
-
channel,
|
|
120
|
-
id: { gte: minBundleId },
|
|
121
|
-
target_app_version: { not: null }
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
const compatibleAppVersions = (0, _hot_updater_plugin_core.filterCompatibleAppVersions)(Array.from(new Set(rows.map((row) => row["target_app_version"]).filter((value) => typeof value === "string" && value.length > 0))), args.appVersion);
|
|
125
|
-
const updateBundles = compatibleAppVersions.length > 0 ? await bundles.findMany({
|
|
126
|
-
where: {
|
|
127
|
-
enabled: true,
|
|
128
|
-
platform: args.platform,
|
|
129
|
-
channel,
|
|
130
|
-
id: { gte: minBundleId },
|
|
131
|
-
target_app_version: { in: compatibleAppVersions }
|
|
132
|
-
},
|
|
133
|
-
orderBy: { id: "desc" }
|
|
134
|
-
}).then(mapRowsToBundles) : [];
|
|
135
|
-
return (0, _hot_updater_plugin_core.resolveUpdateInfoFromBundles)({
|
|
136
|
-
args: {
|
|
137
|
-
...args,
|
|
138
|
-
channel,
|
|
139
|
-
minBundleId
|
|
140
|
-
},
|
|
141
|
-
bundles: updateBundles,
|
|
142
|
-
context
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
const channel = args.channel ?? "production";
|
|
146
|
-
const minBundleId = args.minBundleId ?? _hot_updater_core.NIL_UUID;
|
|
147
|
-
const rows = await bundles.findMany({
|
|
148
|
-
where: {
|
|
149
|
-
enabled: true,
|
|
150
|
-
platform: args.platform,
|
|
151
|
-
channel,
|
|
152
|
-
id: { gte: minBundleId },
|
|
153
|
-
fingerprint_hash: args.fingerprintHash
|
|
154
|
-
},
|
|
155
|
-
orderBy: { id: "desc" }
|
|
156
|
-
});
|
|
157
|
-
return (0, _hot_updater_plugin_core.resolveUpdateInfoFromBundles)({
|
|
158
|
-
args: {
|
|
159
|
-
...args,
|
|
160
|
-
channel,
|
|
161
|
-
minBundleId
|
|
162
|
-
},
|
|
163
|
-
bundles: await mapRowsToBundles(rows),
|
|
164
|
-
context
|
|
165
|
-
});
|
|
166
|
-
},
|
|
167
|
-
async getChannels() {
|
|
168
|
-
const rows = await getDelegate(prisma, "bundles").findMany({
|
|
169
|
-
select: { channel: true },
|
|
170
|
-
orderBy: { channel: "asc" }
|
|
171
|
-
});
|
|
172
|
-
return Array.from(new Set(rows.map((row) => String(row["channel"]))));
|
|
173
|
-
},
|
|
174
|
-
async commitBundle({ changedSets }) {
|
|
175
|
-
await runInTransaction(async (client) => {
|
|
176
|
-
const bundles = getDelegate(client, "bundles");
|
|
177
|
-
const patches = getDelegate(client, "bundle_patches");
|
|
178
|
-
for (const change of changedSets) {
|
|
179
|
-
if (change.operation === "delete") {
|
|
180
|
-
await patches.deleteMany({ where: { bundle_id: change.data.id } });
|
|
181
|
-
await patches.deleteMany({ where: { base_bundle_id: change.data.id } });
|
|
182
|
-
await bundles.deleteMany({ where: { id: change.data.id } });
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
await upsertBundle(client, change.data);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
}
|
|
86
|
+
row,
|
|
87
|
+
inserted: row.id === input.row.id
|
|
189
88
|
};
|
|
190
|
-
}
|
|
89
|
+
},
|
|
90
|
+
create: async (input) => {
|
|
91
|
+
if (input.model === "bundle_patches") await assertPatchReferences(client, input.data.bundle_id, input.data.base_bundle_id);
|
|
92
|
+
const delegate = require_prismaRows.getPrismaDelegate(client, input.model);
|
|
93
|
+
let row;
|
|
94
|
+
if (input.onConflict === "ignore") {
|
|
95
|
+
const where = input.model === "channels" ? { name: input.data.name } : { hash: input.data.hash };
|
|
96
|
+
row = await delegate.upsert({
|
|
97
|
+
where,
|
|
98
|
+
create: input.data,
|
|
99
|
+
update: {}
|
|
100
|
+
});
|
|
101
|
+
} else row = await delegate.create({ data: input.data });
|
|
102
|
+
switch (input.model) {
|
|
103
|
+
case "bundles": return require_prismaRows.parsePrismaBundleRow(row);
|
|
104
|
+
case "bundle_patches": return require_prismaRows.parsePrismaPatchRow(row);
|
|
105
|
+
case "bundle_events": return require_prismaRows.parsePrismaBundleEventRow(row);
|
|
106
|
+
case "channels": return require_prismaRows.parsePrismaChannelRow(row);
|
|
107
|
+
case "api_keys": return require_prismaRows.parsePrismaApiKeyRow(row);
|
|
108
|
+
case "releases": return require_prismaRows.parsePrismaReleaseRow(row);
|
|
109
|
+
case "release_catalogs": return require_prismaRows.parsePrismaReleaseCatalogRow(row);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
update: async (input) => {
|
|
113
|
+
const id = input.where[0]?.value;
|
|
114
|
+
if (typeof id !== "string") throw new require_prismaRows.PrismaAdapterError(`${input.model} update requires a string id`);
|
|
115
|
+
if (input.model === "api_keys") {
|
|
116
|
+
const delegate = require_prismaRows.getPrismaDelegate(client, "api_keys");
|
|
117
|
+
if (await delegate.findFirst({ where: { id } }) === null) return null;
|
|
118
|
+
await delegate.update({
|
|
119
|
+
where: { id },
|
|
120
|
+
data: input.update
|
|
121
|
+
});
|
|
122
|
+
const stored = await delegate.findFirst({ where: { id } });
|
|
123
|
+
return stored === null ? null : require_prismaRows.parsePrismaApiKeyRow(stored);
|
|
124
|
+
}
|
|
125
|
+
if (input.model === "releases") {
|
|
126
|
+
const delegate = require_prismaRows.getPrismaDelegate(client, "releases");
|
|
127
|
+
if (await delegate.findFirst({ where: { id } }) === null) return null;
|
|
128
|
+
await delegate.update({
|
|
129
|
+
where: { id },
|
|
130
|
+
data: input.update
|
|
131
|
+
});
|
|
132
|
+
const stored = await delegate.findFirst({ where: { id } });
|
|
133
|
+
return stored === null ? null : require_prismaRows.parsePrismaReleaseRow(stored);
|
|
134
|
+
}
|
|
135
|
+
if (input.model === "release_catalogs") {
|
|
136
|
+
const delegate = require_prismaRows.getPrismaDelegate(client, "release_catalogs");
|
|
137
|
+
if (await delegate.findFirst({ where: { scope_key: id } }) === null) return null;
|
|
138
|
+
await delegate.update({
|
|
139
|
+
where: { scope_key: id },
|
|
140
|
+
data: input.update
|
|
141
|
+
});
|
|
142
|
+
const stored = await delegate.findFirst({ where: { scope_key: id } });
|
|
143
|
+
return stored === null ? null : require_prismaRows.parsePrismaReleaseCatalogRow(stored);
|
|
144
|
+
}
|
|
145
|
+
const delegate = require_prismaRows.getPrismaDelegate(client, "bundles");
|
|
146
|
+
if (delegate.updateMany === void 0) throw new require_prismaRows.PrismaAdapterError("model delegate \"bundles\" requires updateMany");
|
|
147
|
+
if (await delegate.findFirst({ where: { id } }) === null) return null;
|
|
148
|
+
await delegate.updateMany({
|
|
149
|
+
where: { id },
|
|
150
|
+
data: input.update
|
|
151
|
+
});
|
|
152
|
+
const stored = await delegate.findFirst({ where: { id } });
|
|
153
|
+
if (stored === null) return null;
|
|
154
|
+
return require_prismaRows.parsePrismaBundleRow(stored);
|
|
155
|
+
},
|
|
156
|
+
delete: async (input) => {
|
|
157
|
+
if (input.model === "bundles" && relationMode === "prisma") {
|
|
158
|
+
const ids = require_prismaRows.parsePrismaRows(await require_prismaRows.getPrismaDelegate(client, "bundles").findMany({ where: require_prismaQuery.createPrismaWhere(input.where, provider) }), require_prismaRows.parsePrismaBundleRow).map(({ id }) => id);
|
|
159
|
+
if (ids.length === 0) return;
|
|
160
|
+
await require_prismaRows.getPrismaDelegate(client, "bundle_patches").deleteMany({ where: { OR: [{ bundle_id: { in: ids } }, { base_bundle_id: { in: ids } }] } });
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
await require_prismaRows.getPrismaDelegate(client, input.model).deleteMany({ where: require_prismaQuery.createPrismaWhere(input.where, provider) });
|
|
164
|
+
} catch (error) {
|
|
165
|
+
if (input.model === "channels") require_databaseConstraintErrors.translateChannelDeleteError(error);
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
count: async (input) => {
|
|
170
|
+
if (input.distinct !== void 0) throw new _hot_updater_plugin_core.DatabasePluginInputError("invalid-operation");
|
|
171
|
+
return require_prismaRows.getPrismaDelegate(client, input.model).count({ where: require_prismaQuery.createPrismaWhere(input.where, provider) });
|
|
172
|
+
},
|
|
173
|
+
findOne: async (input) => {
|
|
174
|
+
const row = await require_prismaRows.getPrismaDelegate(client, input.model).findFirst({ where: require_prismaQuery.createPrismaWhere(input.where, provider) });
|
|
175
|
+
if (row === null) return null;
|
|
176
|
+
switch (input.model) {
|
|
177
|
+
case "bundles": return require_prismaRows.parsePrismaBundleRow(row);
|
|
178
|
+
case "bundle_patches": return require_prismaRows.parsePrismaPatchRow(row);
|
|
179
|
+
case "channels": return require_prismaRows.parsePrismaChannelRow(row);
|
|
180
|
+
case "api_keys": return require_prismaRows.parsePrismaApiKeyRow(row);
|
|
181
|
+
case "releases": return require_prismaRows.parsePrismaReleaseRow(row);
|
|
182
|
+
case "release_catalogs": return require_prismaRows.parsePrismaReleaseCatalogRow(row);
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
findMany: (input) => findMany(client, input, provider)
|
|
191
186
|
});
|
|
187
|
+
const createPrismaImplementation = (client, relationMode, provider) => {
|
|
188
|
+
const crud = createCrudImplementation(client, provider, relationMode);
|
|
189
|
+
const implementation = {
|
|
190
|
+
...crud,
|
|
191
|
+
deleteChannel: (input) => {
|
|
192
|
+
if (!hasCallbackTransaction(client)) throw new require_prismaRows.PrismaAdapterError("channel deletion requires callback transactions");
|
|
193
|
+
return runPrismaTransaction(client, "serializable", (transactionClient) => createCrudImplementation(transactionClient, provider, relationMode).deleteChannel(input));
|
|
194
|
+
},
|
|
195
|
+
delete: (input) => {
|
|
196
|
+
if (input.model !== "bundles" || relationMode === "foreign-keys") return crud.delete(input);
|
|
197
|
+
if (!hasCallbackTransaction(client)) throw new require_prismaRows.PrismaAdapterError("relation mode \"prisma\" requires callback transactions");
|
|
198
|
+
return runPrismaTransaction(client, "serializable", (transactionClient) => createCrudImplementation(transactionClient, provider, relationMode).delete(input));
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
if (relationMode === "prisma" && !hasCallbackTransaction(client)) throw new require_prismaRows.PrismaAdapterError("relation mode \"prisma\" requires callback transactions");
|
|
202
|
+
if (!hasCallbackTransaction(client)) return implementation;
|
|
203
|
+
if (relationMode === "prisma") implementation.create = (input) => runPrismaTransaction(client, "serializable", (transactionClient) => createCrudImplementation(transactionClient, provider, relationMode).create(input));
|
|
204
|
+
implementation.update = (input) => runPrismaTransaction(client, relationMode === "prisma" ? "serializable" : "default", (transactionClient) => createCrudImplementation(transactionClient, provider, relationMode).update(input));
|
|
205
|
+
return {
|
|
206
|
+
...implementation,
|
|
207
|
+
transaction: (callback) => runPrismaTransaction(client, "serializable", async (transactionClient) => {
|
|
208
|
+
return callback(createCrudImplementation(transactionClient, provider, relationMode));
|
|
209
|
+
})
|
|
210
|
+
};
|
|
211
|
+
};
|
|
192
212
|
const prismaAdapter = (config) => {
|
|
193
|
-
|
|
194
|
-
|
|
213
|
+
assertPrismaProvider(config.provider);
|
|
214
|
+
const adapter = (0, _hot_updater_plugin_core_internal.createDatabasePluginAdapter)("prisma", createPrismaImplementation(config.prisma, config.relationMode ?? "foreign-keys", config.provider));
|
|
215
|
+
return Object.assign((0, _hot_updater_plugin_core.createDatabasePlugin)({
|
|
216
|
+
name: "prisma",
|
|
217
|
+
models: adapter.models,
|
|
218
|
+
commit: adapter.commit
|
|
219
|
+
}), {
|
|
195
220
|
adapterName: "prisma",
|
|
196
221
|
provider: config.provider,
|
|
197
|
-
generateSchema: (version) => ({
|
|
222
|
+
generateSchema: ((version) => ({
|
|
198
223
|
code: require_schemaGenerators.generatePrismaSchema(config.provider, version === "latest" ? require_registry.hotUpdaterSchema : require_registry.getHotUpdaterSchemaVersion(version)),
|
|
199
224
|
path: "./prisma/schema/hot_updater.prisma"
|
|
200
|
-
})
|
|
225
|
+
}))
|
|
201
226
|
});
|
|
202
227
|
};
|
|
203
228
|
//#endregion
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DatabaseAdapterWithCapabilities, ORMSQLProvider } from "../db/types.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/adapters/prisma.d.ts
|
|
4
4
|
type PrismaRelationMode = "prisma" | "foreign-keys";
|
|
5
5
|
interface PrismaConfig {
|
|
6
6
|
readonly prisma: object;
|
|
7
|
-
readonly provider:
|
|
7
|
+
readonly provider: ORMSQLProvider;
|
|
8
8
|
readonly relationMode?: PrismaRelationMode;
|
|
9
9
|
readonly db?: unknown;
|
|
10
10
|
}
|
|
11
|
-
declare const prismaAdapter: (config: PrismaConfig) =>
|
|
11
|
+
declare const prismaAdapter: (config: PrismaConfig) => DatabaseAdapterWithCapabilities;
|
|
12
12
|
//#endregion
|
|
13
13
|
export { PrismaConfig, prismaAdapter };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DatabaseAdapterWithCapabilities, ORMSQLProvider } from "../db/types.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/adapters/prisma.d.ts
|
|
4
4
|
type PrismaRelationMode = "prisma" | "foreign-keys";
|
|
5
5
|
interface PrismaConfig {
|
|
6
6
|
readonly prisma: object;
|
|
7
|
-
readonly provider:
|
|
7
|
+
readonly provider: ORMSQLProvider;
|
|
8
8
|
readonly relationMode?: PrismaRelationMode;
|
|
9
9
|
readonly db?: unknown;
|
|
10
10
|
}
|
|
11
|
-
declare const prismaAdapter: (config: PrismaConfig) =>
|
|
11
|
+
declare const prismaAdapter: (config: PrismaConfig) => DatabaseAdapterWithCapabilities;
|
|
12
12
|
//#endregion
|
|
13
13
|
export { PrismaConfig, prismaAdapter };
|