@hot-updater/server 1.0.0-rc.0 → 1.0.0-rc.14
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/_virtual/_rolldown/runtime.cjs +1 -1
- package/dist/adapters/databaseConstraintErrors.cjs +0 -1
- package/dist/adapters/databasePluginUtils.cjs +14 -1
- package/dist/adapters/databasePluginUtils.mjs +14 -2
- package/dist/adapters/drizzle.cjs +9 -4
- package/dist/adapters/drizzle.d.cts +0 -1
- package/dist/adapters/drizzle.d.mts +0 -1
- package/dist/adapters/drizzle.mjs +10 -4
- package/dist/adapters/drizzleCrud.cjs +93 -3
- package/dist/adapters/drizzleCrud.mjs +93 -5
- package/dist/adapters/drizzleLazyDB.cjs +2 -0
- package/dist/adapters/drizzleLazyDB.mjs +2 -0
- package/dist/adapters/drizzleQuery.cjs +3 -2
- package/dist/adapters/drizzleQuery.mjs +3 -1
- package/dist/adapters/kysely.cjs +1 -1
- package/dist/adapters/kysely.d.cts +0 -1
- package/dist/adapters/kysely.d.mts +0 -1
- package/dist/adapters/kysely.mjs +2 -1
- package/dist/adapters/kyselyCrud.cjs +44 -5
- package/dist/adapters/kyselyCrud.mjs +45 -6
- package/dist/adapters/kyselyQuery.cjs +2 -2
- package/dist/adapters/kyselyQuery.mjs +2 -1
- package/dist/adapters/mongodb.cjs +36 -1
- package/dist/adapters/mongodb.d.cts +1 -1
- package/dist/adapters/mongodb.d.mts +1 -1
- package/dist/adapters/mongodb.mjs +36 -0
- package/dist/adapters/mongodbCollections.cjs +2 -0
- package/dist/adapters/mongodbCollections.mjs +2 -0
- package/dist/adapters/mongodbQuery.cjs +17 -4
- package/dist/adapters/mongodbQuery.mjs +17 -4
- package/dist/adapters/mongodbReads.cjs +88 -30
- package/dist/adapters/mongodbReads.mjs +88 -29
- package/dist/adapters/mongodbWrites.cjs +1 -2
- package/dist/adapters/mongodbWrites.mjs +1 -1
- package/dist/adapters/prisma.cjs +44 -7
- package/dist/adapters/prisma.d.cts +0 -1
- package/dist/adapters/prisma.d.mts +0 -1
- package/dist/adapters/prisma.mjs +44 -6
- package/dist/adapters/prismaInsights.cjs +99 -0
- package/dist/adapters/prismaInsights.mjs +97 -0
- package/dist/adapters/prismaQuery.cjs +0 -1
- package/dist/adapters/prismaRows.cjs +7 -8
- package/dist/adapters/prismaRows.mjs +8 -8
- package/dist/apiKeys.cjs +6 -2
- package/dist/apiKeys.d.cts +0 -1
- package/dist/apiKeys.d.mts +0 -1
- package/dist/apiKeys.mjs +3 -3
- package/dist/createHotUpdaterCore.cjs +27 -12
- package/dist/createHotUpdaterCore.d.cts +8 -8
- package/dist/createHotUpdaterCore.d.mts +8 -8
- package/dist/createHotUpdaterCore.mjs +26 -12
- package/dist/db/createBundleDiff.cjs +2 -2
- package/dist/db/createBundleDiff.d.cts +1 -5
- package/dist/db/createBundleDiff.d.mts +1 -5
- package/dist/db/databasePluginCore.cjs +0 -1
- package/dist/db/fixedMigrator.cjs +2 -2
- package/dist/db/fixedMigrator.mjs +2 -2
- package/dist/db/fixedMigratorMongo.cjs +6 -4
- package/dist/db/fixedMigratorMongo.mjs +6 -4
- package/dist/db/index.d.cts +0 -1
- package/dist/db/index.d.mts +0 -1
- package/dist/db/releaseCatalog.cjs +0 -1
- package/dist/db/releaseCatalog.d.cts +0 -1
- package/dist/db/releaseCatalog.d.mts +0 -1
- package/dist/db/schema/insightsCollation.cjs +14 -0
- package/dist/db/schema/insightsCollation.mjs +14 -0
- package/dist/db/schema/sql.cjs +11 -7
- package/dist/db/schema/sql.mjs +8 -8
- package/dist/db/schemaGenerators.cjs +29 -9
- package/dist/db/schemaGenerators.mjs +29 -9
- package/dist/db/schemaReadiness.cjs +2 -0
- package/dist/db/schemaReadiness.d.cts +1 -0
- package/dist/db/schemaReadiness.d.mts +1 -0
- package/dist/db/schemaReadiness.mjs +2 -0
- package/dist/db/sqlMigrationExecution.cjs +1 -1
- package/dist/db/sqlMigrationExecution.mjs +1 -0
- package/dist/db/types.cjs +3 -1
- package/dist/db/types.d.cts +3 -6
- package/dist/db/types.d.mts +3 -6
- package/dist/db/types.mjs +2 -2
- package/dist/db/updateArtifacts.cjs +0 -1
- package/dist/handler.cjs +5 -5
- package/dist/handler.d.cts +1 -2
- package/dist/handler.d.mts +1 -2
- package/dist/handler.mjs +5 -5
- package/dist/handlerReleaseCatalogRoutes.cjs +0 -1
- package/dist/handlerReleaseManagementRoutes.cjs +0 -1
- package/dist/handlerTypes.d.cts +0 -1
- package/dist/handlerTypes.d.mts +0 -1
- package/dist/handlerVersionRoutes.d.cts +1 -0
- package/dist/handlerVersionRoutes.d.mts +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +2 -2
- package/dist/insights/domain.d.cts +92 -0
- package/dist/insights/domain.d.mts +92 -0
- package/dist/insights/errors.cjs +15 -0
- package/dist/insights/errors.mjs +14 -0
- package/dist/{analytics → insights}/eventInput.cjs +61 -16
- package/dist/{analytics → insights}/eventInput.mjs +61 -18
- package/dist/insights/provider.cjs +332 -0
- package/dist/insights/provider.d.cts +6 -0
- package/dist/insights/provider.d.mts +6 -0
- package/dist/insights/provider.mjs +332 -0
- package/dist/insights/queryInput.cjs +93 -0
- package/dist/insights/queryInput.mjs +91 -0
- package/dist/insights/routes.cjs +58 -0
- package/dist/insights/routes.mjs +56 -0
- package/dist/insights/types.d.cts +32 -0
- package/dist/insights/types.d.mts +32 -0
- package/dist/node.d.cts +0 -1
- package/dist/node.d.mts +0 -1
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/schema/index.cjs +17 -3
- package/dist/schema/index.mjs +4 -4
- package/dist/schema/v1_0_0.cjs +64 -35
- package/dist/schema/v1_0_0.mjs +64 -36
- package/dist/storageAccess.cjs +0 -1
- package/dist/types/index.d.cts +0 -1
- package/dist/types/index.d.mts +0 -1
- package/package.json +7 -7
- package/src/adapters/databasePluginTestDatabase.ts +15 -5
- package/src/adapters/databasePluginUtils.ts +24 -0
- package/src/adapters/drizzle.spec.ts +203 -5
- package/src/adapters/drizzle.ts +16 -4
- package/src/adapters/drizzleCrud.ts +200 -9
- package/src/adapters/drizzleLazyDB.ts +33 -6
- package/src/adapters/kysely.spec.ts +62 -0
- package/src/adapters/kysely.ts +7 -1
- package/src/adapters/kyselyCrud.ts +115 -7
- package/src/adapters/kyselyInsights.spec.ts +168 -0
- package/src/adapters/mongodb.integration.spec.ts +483 -0
- package/src/adapters/mongodb.spec.ts +89 -0
- package/src/adapters/mongodb.ts +59 -1
- package/src/adapters/mongodbCollections.ts +16 -0
- package/src/adapters/mongodbQuery.ts +22 -3
- package/src/adapters/mongodbReads.ts +78 -2
- package/src/adapters/mongodbTestClient.ts +107 -6
- package/src/adapters/mongodbTestFilter.ts +5 -1
- package/src/adapters/mongodbWrites.ts +1 -0
- package/src/adapters/prisma.spec.ts +270 -0
- package/src/adapters/prisma.ts +75 -2
- package/src/adapters/prismaInsights.ts +190 -0
- package/src/adapters/prismaRows.ts +17 -10
- package/src/adapters/prismaTestClient.ts +89 -7
- package/src/apiKeys.integration.spec.ts +3 -3
- package/src/createHotUpdaterCore.ts +30 -16
- package/src/db/databasePluginUpdateCheck.bench.ts +10 -0
- package/src/db/fixedMigrator.spec.ts +63 -0
- package/src/db/fixedMigratorMongo.spec.ts +70 -9
- package/src/db/fixedMigratorMongo.ts +10 -10
- package/src/db/index.spec.ts +6 -1
- package/src/db/schema/insightsCollation.ts +21 -0
- package/src/db/schema/sql.ts +8 -5
- package/src/db/schemaGenerators.ts +42 -13
- package/src/db/types.spec.ts +11 -3
- package/src/db/types.ts +13 -7
- package/src/handler-standalone.integration.spec.ts +6 -8
- package/src/handler.ts +12 -12
- package/src/index.ts +3 -3
- package/src/insights/domain.ts +106 -0
- package/src/insights/errors.ts +11 -0
- package/src/{analytics → insights}/eventInput.ts +66 -16
- package/src/insights/insights.integration.spec.ts +475 -0
- package/src/insights/provider.spec.ts +396 -0
- package/src/insights/provider.ts +611 -0
- package/src/insights/queryInput.ts +142 -0
- package/src/insights/routes.ts +104 -0
- package/src/insights/types.ts +55 -0
- package/src/schema/dsl-all-versions.spec.ts +1 -1
- package/src/schema/v1_0_0.spec.ts +77 -3
- package/src/schema/v1_0_0.ts +83 -37
- package/dist/analytics/bounded/activeOverview.cjs +0 -87
- package/dist/analytics/bounded/activeOverview.mjs +0 -85
- package/dist/analytics/bounded/installationSearch.cjs +0 -42
- package/dist/analytics/bounded/installationSearch.mjs +0 -42
- package/dist/analytics/bounded/persistence.cjs +0 -39
- package/dist/analytics/bounded/persistence.mjs +0 -38
- package/dist/analytics/bounded/provider.cjs +0 -170
- package/dist/analytics/bounded/provider.d.cts +0 -7
- package/dist/analytics/bounded/provider.d.mts +0 -7
- package/dist/analytics/bounded/provider.mjs +0 -170
- package/dist/analytics/bounded/scan.cjs +0 -144
- package/dist/analytics/bounded/scan.mjs +0 -138
- package/dist/analytics/domain.d.cts +0 -121
- package/dist/analytics/domain.d.mts +0 -121
- package/dist/analytics/errors.cjs +0 -22
- package/dist/analytics/errors.mjs +0 -20
- package/dist/analytics/persistence.d.cts +0 -6
- package/dist/analytics/persistence.d.mts +0 -6
- package/dist/analytics/queryInput.cjs +0 -58
- package/dist/analytics/queryInput.mjs +0 -55
- package/dist/analytics/routes.cjs +0 -63
- package/dist/analytics/routes.mjs +0 -61
- package/dist/analytics/types.d.cts +0 -17
- package/dist/analytics/types.d.mts +0 -17
- package/src/analytics/analytics.integration.spec.ts +0 -144
- package/src/analytics/bounded/activeOverview.spec.ts +0 -189
- package/src/analytics/bounded/activeOverview.ts +0 -148
- package/src/analytics/bounded/installationSearch.spec.ts +0 -130
- package/src/analytics/bounded/installationSearch.ts +0 -69
- package/src/analytics/bounded/persistence.ts +0 -43
- package/src/analytics/bounded/provider.spec.ts +0 -219
- package/src/analytics/bounded/provider.ts +0 -229
- package/src/analytics/bounded/scan.ts +0 -235
- package/src/analytics/domain.ts +0 -139
- package/src/analytics/errors.ts +0 -18
- package/src/analytics/persistence.ts +0 -10
- package/src/analytics/queryInput.ts +0 -102
- package/src/analytics/routes.ts +0 -123
- package/src/analytics/types.ts +0 -44
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
1
|
const require_databasePluginUtils = require("./databasePluginUtils.cjs");
|
|
3
2
|
const require_mongodbCollections = require("./mongodbCollections.cjs");
|
|
4
3
|
const require_mongodbQuery = require("./mongodbQuery.cjs");
|
|
5
4
|
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
5
|
+
let _hot_updater_plugin_core_internal = require("@hot-updater/plugin-core/internal");
|
|
6
6
|
//#region src/adapters/mongodbReads.ts
|
|
7
7
|
const findMongoRows = async (collections, input, session) => {
|
|
8
8
|
if (input.limit === 0) return [];
|
|
@@ -15,10 +15,13 @@ const findMongoRows = async (collections, input, session) => {
|
|
|
15
15
|
...require_mongodbCollections.mongoSessionOptions(session)
|
|
16
16
|
}).skip(input.offset).limit(input.limit);
|
|
17
17
|
if (rawOrderBy === void 0) return cursor.toArray();
|
|
18
|
-
if (needsInMemoryOrder)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
if (needsInMemoryOrder) {
|
|
19
|
+
const rows = await collections.bundles.find(require_mongodbCollections.activeBundleFilter(require_mongodbQuery.createMongoBundleWhere(input.where)), {
|
|
20
|
+
projection: require_mongodbCollections.WITHOUT_INTERNAL_FIELDS,
|
|
21
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
22
|
+
}).toArray();
|
|
23
|
+
return require_databasePluginUtils.sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
24
|
+
}
|
|
22
25
|
const sort = require_mongodbQuery.createMongoSort(input);
|
|
23
26
|
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
24
27
|
}
|
|
@@ -28,23 +31,33 @@ const findMongoRows = async (collections, input, session) => {
|
|
|
28
31
|
...require_mongodbCollections.mongoSessionOptions(session)
|
|
29
32
|
}).skip(input.offset).limit(input.limit);
|
|
30
33
|
if (rawOrderBy === void 0) return cursor.toArray();
|
|
31
|
-
if (needsInMemoryOrder)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
if (needsInMemoryOrder) {
|
|
35
|
+
const rows = await collections.bundlePatches.find(require_mongodbQuery.createMongoPatchWhere(input.where), {
|
|
36
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
37
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
38
|
+
}).toArray();
|
|
39
|
+
return require_databasePluginUtils.sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
40
|
+
}
|
|
35
41
|
const sort = require_mongodbQuery.createMongoSort(input);
|
|
36
42
|
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
37
43
|
}
|
|
38
44
|
case "bundle_events": {
|
|
39
45
|
const cursor = collections.bundleEvents.find(require_mongodbQuery.createMongoEventWhere(input.where), {
|
|
40
46
|
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
41
|
-
...require_mongodbCollections.mongoSessionOptions(session)
|
|
47
|
+
...require_mongodbCollections.mongoSessionOptions(session),
|
|
48
|
+
collation: { locale: "simple" },
|
|
49
|
+
readPreference: "primary"
|
|
42
50
|
}).skip(input.offset).limit(input.limit);
|
|
43
51
|
if (rawOrderBy === void 0) return cursor.toArray();
|
|
44
|
-
if (needsInMemoryOrder)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
if (needsInMemoryOrder) {
|
|
53
|
+
const rows = await collections.bundleEvents.find(require_mongodbQuery.createMongoEventWhere(input.where), {
|
|
54
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
55
|
+
...require_mongodbCollections.mongoSessionOptions(session),
|
|
56
|
+
collation: { locale: "simple" },
|
|
57
|
+
readPreference: "primary"
|
|
58
|
+
}).toArray();
|
|
59
|
+
return require_databasePluginUtils.sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
60
|
+
}
|
|
48
61
|
const sort = require_mongodbQuery.createMongoSort(input);
|
|
49
62
|
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
50
63
|
}
|
|
@@ -54,10 +67,13 @@ const findMongoRows = async (collections, input, session) => {
|
|
|
54
67
|
...require_mongodbCollections.mongoSessionOptions(session)
|
|
55
68
|
}).skip(input.offset).limit(input.limit);
|
|
56
69
|
if (rawOrderBy === void 0) return cursor.toArray();
|
|
57
|
-
if (needsInMemoryOrder)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
70
|
+
if (needsInMemoryOrder) {
|
|
71
|
+
const rows = await collections.apiKeys.find(require_mongodbQuery.createMongoApiKeyWhere(input.where), {
|
|
72
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
73
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
74
|
+
}).toArray();
|
|
75
|
+
return require_databasePluginUtils.sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
76
|
+
}
|
|
61
77
|
const sort = require_mongodbQuery.createMongoSort(input);
|
|
62
78
|
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
63
79
|
}
|
|
@@ -67,10 +83,13 @@ const findMongoRows = async (collections, input, session) => {
|
|
|
67
83
|
...require_mongodbCollections.mongoSessionOptions(session)
|
|
68
84
|
}).skip(input.offset).limit(input.limit);
|
|
69
85
|
if (rawOrderBy === void 0) return cursor.toArray();
|
|
70
|
-
if (needsInMemoryOrder)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
86
|
+
if (needsInMemoryOrder) {
|
|
87
|
+
const rows = await collections.channels.find(require_mongodbQuery.createMongoChannelWhere(input.where), {
|
|
88
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
89
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
90
|
+
}).toArray();
|
|
91
|
+
return require_databasePluginUtils.sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
92
|
+
}
|
|
74
93
|
const sort = require_mongodbQuery.createMongoSort(input);
|
|
75
94
|
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
76
95
|
}
|
|
@@ -80,10 +99,13 @@ const findMongoRows = async (collections, input, session) => {
|
|
|
80
99
|
...require_mongodbCollections.mongoSessionOptions(session)
|
|
81
100
|
}).skip(input.offset).limit(input.limit);
|
|
82
101
|
if (rawOrderBy === void 0) return cursor.toArray();
|
|
83
|
-
if (needsInMemoryOrder)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
102
|
+
if (needsInMemoryOrder) {
|
|
103
|
+
const rows = await collections.releases.find(require_mongodbQuery.createMongoReleaseWhere(input.where), {
|
|
104
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
105
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
106
|
+
}).toArray();
|
|
107
|
+
return require_databasePluginUtils.sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
108
|
+
}
|
|
87
109
|
const sort = require_mongodbQuery.createMongoSort(input);
|
|
88
110
|
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
89
111
|
}
|
|
@@ -93,22 +115,58 @@ const findMongoRows = async (collections, input, session) => {
|
|
|
93
115
|
...require_mongodbCollections.mongoSessionOptions(session)
|
|
94
116
|
}).skip(input.offset).limit(input.limit);
|
|
95
117
|
if (rawOrderBy === void 0) return cursor.toArray();
|
|
96
|
-
if (needsInMemoryOrder)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
118
|
+
if (needsInMemoryOrder) {
|
|
119
|
+
const rows = await collections.releaseCatalogs.find(require_mongodbQuery.createMongoReleaseCatalogWhere(input.where), {
|
|
120
|
+
projection: require_mongodbCollections.WITHOUT_MONGO_ID,
|
|
121
|
+
...require_mongodbCollections.mongoSessionOptions(session)
|
|
122
|
+
}).toArray();
|
|
123
|
+
return require_databasePluginUtils.sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
124
|
+
}
|
|
100
125
|
const sort = require_mongodbQuery.createMongoSort(input);
|
|
101
126
|
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
102
127
|
}
|
|
103
128
|
}
|
|
104
129
|
};
|
|
105
130
|
const createMongoReads = (collections, session) => ({
|
|
131
|
+
async findLatestInsightsEvents(input) {
|
|
132
|
+
return collections.bundleEventHeads.aggregate([
|
|
133
|
+
{ $match: require_mongodbQuery.createMongoEventWhere((0, _hot_updater_plugin_core_internal.latestInsightsWhere)(input)) },
|
|
134
|
+
{ $sort: { install_id: 1 } },
|
|
135
|
+
{ $limit: "installId" in input ? 1 : input.limit },
|
|
136
|
+
{ $lookup: {
|
|
137
|
+
from: "bundle_events",
|
|
138
|
+
localField: "id",
|
|
139
|
+
foreignField: "id",
|
|
140
|
+
as: "event"
|
|
141
|
+
} },
|
|
142
|
+
{ $unwind: "$event" },
|
|
143
|
+
{ $replaceRoot: { newRoot: "$event" } },
|
|
144
|
+
{ $project: require_mongodbCollections.WITHOUT_MONGO_ID }
|
|
145
|
+
], {
|
|
146
|
+
...require_mongodbCollections.mongoSessionOptions(session),
|
|
147
|
+
collation: { locale: "simple" },
|
|
148
|
+
readPreference: "primary"
|
|
149
|
+
}).toArray();
|
|
150
|
+
},
|
|
151
|
+
async countLatestInsightsEvents(input) {
|
|
152
|
+
return (await collections.bundleEventHeads.aggregate([{ $match: { $or: (0, _hot_updater_plugin_core_internal.latestInsightsCountGroups)(input).map(require_mongodbQuery.createMongoEventWhere) } }, { $count: "count" }], {
|
|
153
|
+
...require_mongodbCollections.mongoSessionOptions(session),
|
|
154
|
+
collation: { locale: "simple" },
|
|
155
|
+
readPreference: "primary"
|
|
156
|
+
}).toArray())[0]?.count ?? 0;
|
|
157
|
+
},
|
|
106
158
|
count: async (input) => {
|
|
107
159
|
if (input.distinct !== void 0) throw new _hot_updater_plugin_core.DatabasePluginInputError("invalid-operation");
|
|
108
160
|
switch (input.model) {
|
|
109
161
|
case "bundles": return collections.bundles.countDocuments(require_mongodbCollections.activeBundleFilter(require_mongodbQuery.createMongoBundleWhere(input.where)), require_mongodbCollections.mongoSessionOptions(session));
|
|
110
162
|
case "bundle_patches": return collections.bundlePatches.countDocuments(require_mongodbQuery.createMongoPatchWhere(input.where), require_mongodbCollections.mongoSessionOptions(session));
|
|
111
163
|
case "releases": return collections.releases.countDocuments(require_mongodbQuery.createMongoReleaseWhere(input.where), require_mongodbCollections.mongoSessionOptions(session));
|
|
164
|
+
case "bundle_events": return collections.bundleEvents.countDocuments(require_mongodbQuery.createMongoEventWhere(input.where), {
|
|
165
|
+
...require_mongodbCollections.mongoSessionOptions(session),
|
|
166
|
+
collation: { locale: "simple" },
|
|
167
|
+
readPreference: "primary",
|
|
168
|
+
...session === void 0 ? { readConcern: { level: "snapshot" } } : {}
|
|
169
|
+
});
|
|
112
170
|
}
|
|
113
171
|
},
|
|
114
172
|
findOne: async (input) => {
|
|
@@ -2,6 +2,7 @@ import { hasNullOrderOverrides, sortRowsByOrder } from "./databasePluginUtils.mj
|
|
|
2
2
|
import { WITHOUT_INTERNAL_FIELDS, WITHOUT_MONGO_ID, activeBundleFilter, mongoSessionOptions } from "./mongodbCollections.mjs";
|
|
3
3
|
import { createMongoApiKeyWhere, createMongoBundleWhere, createMongoChannelWhere, createMongoEventWhere, createMongoPatchWhere, createMongoReleaseCatalogWhere, createMongoReleaseWhere, createMongoSort } from "./mongodbQuery.mjs";
|
|
4
4
|
import { DatabasePluginInputError } from "@hot-updater/plugin-core";
|
|
5
|
+
import { latestInsightsCountGroups, latestInsightsWhere } from "@hot-updater/plugin-core/internal";
|
|
5
6
|
//#region src/adapters/mongodbReads.ts
|
|
6
7
|
const findMongoRows = async (collections, input, session) => {
|
|
7
8
|
if (input.limit === 0) return [];
|
|
@@ -14,10 +15,13 @@ const findMongoRows = async (collections, input, session) => {
|
|
|
14
15
|
...mongoSessionOptions(session)
|
|
15
16
|
}).skip(input.offset).limit(input.limit);
|
|
16
17
|
if (rawOrderBy === void 0) return cursor.toArray();
|
|
17
|
-
if (needsInMemoryOrder)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
if (needsInMemoryOrder) {
|
|
19
|
+
const rows = await collections.bundles.find(activeBundleFilter(createMongoBundleWhere(input.where)), {
|
|
20
|
+
projection: WITHOUT_INTERNAL_FIELDS,
|
|
21
|
+
...mongoSessionOptions(session)
|
|
22
|
+
}).toArray();
|
|
23
|
+
return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
24
|
+
}
|
|
21
25
|
const sort = createMongoSort(input);
|
|
22
26
|
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
23
27
|
}
|
|
@@ -27,23 +31,33 @@ const findMongoRows = async (collections, input, session) => {
|
|
|
27
31
|
...mongoSessionOptions(session)
|
|
28
32
|
}).skip(input.offset).limit(input.limit);
|
|
29
33
|
if (rawOrderBy === void 0) return cursor.toArray();
|
|
30
|
-
if (needsInMemoryOrder)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
if (needsInMemoryOrder) {
|
|
35
|
+
const rows = await collections.bundlePatches.find(createMongoPatchWhere(input.where), {
|
|
36
|
+
projection: WITHOUT_MONGO_ID,
|
|
37
|
+
...mongoSessionOptions(session)
|
|
38
|
+
}).toArray();
|
|
39
|
+
return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
40
|
+
}
|
|
34
41
|
const sort = createMongoSort(input);
|
|
35
42
|
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
36
43
|
}
|
|
37
44
|
case "bundle_events": {
|
|
38
45
|
const cursor = collections.bundleEvents.find(createMongoEventWhere(input.where), {
|
|
39
46
|
projection: WITHOUT_MONGO_ID,
|
|
40
|
-
...mongoSessionOptions(session)
|
|
47
|
+
...mongoSessionOptions(session),
|
|
48
|
+
collation: { locale: "simple" },
|
|
49
|
+
readPreference: "primary"
|
|
41
50
|
}).skip(input.offset).limit(input.limit);
|
|
42
51
|
if (rawOrderBy === void 0) return cursor.toArray();
|
|
43
|
-
if (needsInMemoryOrder)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
52
|
+
if (needsInMemoryOrder) {
|
|
53
|
+
const rows = await collections.bundleEvents.find(createMongoEventWhere(input.where), {
|
|
54
|
+
projection: WITHOUT_MONGO_ID,
|
|
55
|
+
...mongoSessionOptions(session),
|
|
56
|
+
collation: { locale: "simple" },
|
|
57
|
+
readPreference: "primary"
|
|
58
|
+
}).toArray();
|
|
59
|
+
return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
60
|
+
}
|
|
47
61
|
const sort = createMongoSort(input);
|
|
48
62
|
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
49
63
|
}
|
|
@@ -53,10 +67,13 @@ const findMongoRows = async (collections, input, session) => {
|
|
|
53
67
|
...mongoSessionOptions(session)
|
|
54
68
|
}).skip(input.offset).limit(input.limit);
|
|
55
69
|
if (rawOrderBy === void 0) return cursor.toArray();
|
|
56
|
-
if (needsInMemoryOrder)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
70
|
+
if (needsInMemoryOrder) {
|
|
71
|
+
const rows = await collections.apiKeys.find(createMongoApiKeyWhere(input.where), {
|
|
72
|
+
projection: WITHOUT_MONGO_ID,
|
|
73
|
+
...mongoSessionOptions(session)
|
|
74
|
+
}).toArray();
|
|
75
|
+
return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
76
|
+
}
|
|
60
77
|
const sort = createMongoSort(input);
|
|
61
78
|
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
62
79
|
}
|
|
@@ -66,10 +83,13 @@ const findMongoRows = async (collections, input, session) => {
|
|
|
66
83
|
...mongoSessionOptions(session)
|
|
67
84
|
}).skip(input.offset).limit(input.limit);
|
|
68
85
|
if (rawOrderBy === void 0) return cursor.toArray();
|
|
69
|
-
if (needsInMemoryOrder)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
86
|
+
if (needsInMemoryOrder) {
|
|
87
|
+
const rows = await collections.channels.find(createMongoChannelWhere(input.where), {
|
|
88
|
+
projection: WITHOUT_MONGO_ID,
|
|
89
|
+
...mongoSessionOptions(session)
|
|
90
|
+
}).toArray();
|
|
91
|
+
return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
92
|
+
}
|
|
73
93
|
const sort = createMongoSort(input);
|
|
74
94
|
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
75
95
|
}
|
|
@@ -79,10 +99,13 @@ const findMongoRows = async (collections, input, session) => {
|
|
|
79
99
|
...mongoSessionOptions(session)
|
|
80
100
|
}).skip(input.offset).limit(input.limit);
|
|
81
101
|
if (rawOrderBy === void 0) return cursor.toArray();
|
|
82
|
-
if (needsInMemoryOrder)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
102
|
+
if (needsInMemoryOrder) {
|
|
103
|
+
const rows = await collections.releases.find(createMongoReleaseWhere(input.where), {
|
|
104
|
+
projection: WITHOUT_MONGO_ID,
|
|
105
|
+
...mongoSessionOptions(session)
|
|
106
|
+
}).toArray();
|
|
107
|
+
return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
108
|
+
}
|
|
86
109
|
const sort = createMongoSort(input);
|
|
87
110
|
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
88
111
|
}
|
|
@@ -92,22 +115,58 @@ const findMongoRows = async (collections, input, session) => {
|
|
|
92
115
|
...mongoSessionOptions(session)
|
|
93
116
|
}).skip(input.offset).limit(input.limit);
|
|
94
117
|
if (rawOrderBy === void 0) return cursor.toArray();
|
|
95
|
-
if (needsInMemoryOrder)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
118
|
+
if (needsInMemoryOrder) {
|
|
119
|
+
const rows = await collections.releaseCatalogs.find(createMongoReleaseCatalogWhere(input.where), {
|
|
120
|
+
projection: WITHOUT_MONGO_ID,
|
|
121
|
+
...mongoSessionOptions(session)
|
|
122
|
+
}).toArray();
|
|
123
|
+
return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
|
|
124
|
+
}
|
|
99
125
|
const sort = createMongoSort(input);
|
|
100
126
|
return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
|
|
101
127
|
}
|
|
102
128
|
}
|
|
103
129
|
};
|
|
104
130
|
const createMongoReads = (collections, session) => ({
|
|
131
|
+
async findLatestInsightsEvents(input) {
|
|
132
|
+
return collections.bundleEventHeads.aggregate([
|
|
133
|
+
{ $match: createMongoEventWhere(latestInsightsWhere(input)) },
|
|
134
|
+
{ $sort: { install_id: 1 } },
|
|
135
|
+
{ $limit: "installId" in input ? 1 : input.limit },
|
|
136
|
+
{ $lookup: {
|
|
137
|
+
from: "bundle_events",
|
|
138
|
+
localField: "id",
|
|
139
|
+
foreignField: "id",
|
|
140
|
+
as: "event"
|
|
141
|
+
} },
|
|
142
|
+
{ $unwind: "$event" },
|
|
143
|
+
{ $replaceRoot: { newRoot: "$event" } },
|
|
144
|
+
{ $project: WITHOUT_MONGO_ID }
|
|
145
|
+
], {
|
|
146
|
+
...mongoSessionOptions(session),
|
|
147
|
+
collation: { locale: "simple" },
|
|
148
|
+
readPreference: "primary"
|
|
149
|
+
}).toArray();
|
|
150
|
+
},
|
|
151
|
+
async countLatestInsightsEvents(input) {
|
|
152
|
+
return (await collections.bundleEventHeads.aggregate([{ $match: { $or: latestInsightsCountGroups(input).map(createMongoEventWhere) } }, { $count: "count" }], {
|
|
153
|
+
...mongoSessionOptions(session),
|
|
154
|
+
collation: { locale: "simple" },
|
|
155
|
+
readPreference: "primary"
|
|
156
|
+
}).toArray())[0]?.count ?? 0;
|
|
157
|
+
},
|
|
105
158
|
count: async (input) => {
|
|
106
159
|
if (input.distinct !== void 0) throw new DatabasePluginInputError("invalid-operation");
|
|
107
160
|
switch (input.model) {
|
|
108
161
|
case "bundles": return collections.bundles.countDocuments(activeBundleFilter(createMongoBundleWhere(input.where)), mongoSessionOptions(session));
|
|
109
162
|
case "bundle_patches": return collections.bundlePatches.countDocuments(createMongoPatchWhere(input.where), mongoSessionOptions(session));
|
|
110
163
|
case "releases": return collections.releases.countDocuments(createMongoReleaseWhere(input.where), mongoSessionOptions(session));
|
|
164
|
+
case "bundle_events": return collections.bundleEvents.countDocuments(createMongoEventWhere(input.where), {
|
|
165
|
+
...mongoSessionOptions(session),
|
|
166
|
+
collation: { locale: "simple" },
|
|
167
|
+
readPreference: "primary",
|
|
168
|
+
...session === void 0 ? { readConcern: { level: "snapshot" } } : {}
|
|
169
|
+
});
|
|
111
170
|
}
|
|
112
171
|
},
|
|
113
172
|
findOne: async (input) => {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
1
|
const require_mongodbCollections = require("./mongodbCollections.cjs");
|
|
3
2
|
const require_mongodbQuery = require("./mongodbQuery.cjs");
|
|
4
3
|
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
5
4
|
//#region src/adapters/mongodbWrites.ts
|
|
6
5
|
const assertPatchReferences = async (bundles, patch, session) => {
|
|
7
|
-
const ids = Array.from(new Set([patch.bundle_id, patch.base_bundle_id]));
|
|
6
|
+
const ids = Array.from(/* @__PURE__ */ new Set([patch.bundle_id, patch.base_bundle_id]));
|
|
8
7
|
if (await bundles.countDocuments(require_mongodbCollections.activeBundleFilter({ id: { $in: ids } }), require_mongodbCollections.mongoSessionOptions(session)) !== ids.length) throw new require_mongodbCollections.MongoAdapterConstraintError(`patch "${patch.id}" references a missing bundle`);
|
|
9
8
|
};
|
|
10
9
|
const createMongoWrites = (collections, session) => ({
|
|
@@ -3,7 +3,7 @@ import { createMongoApiKeyWhere, createMongoBundleWhere, createMongoChannelWhere
|
|
|
3
3
|
import { createUUIDv7 } from "@hot-updater/plugin-core";
|
|
4
4
|
//#region src/adapters/mongodbWrites.ts
|
|
5
5
|
const assertPatchReferences = async (bundles, patch, session) => {
|
|
6
|
-
const ids = Array.from(new Set([patch.bundle_id, patch.base_bundle_id]));
|
|
6
|
+
const ids = Array.from(/* @__PURE__ */ new Set([patch.bundle_id, patch.base_bundle_id]));
|
|
7
7
|
if (await bundles.countDocuments(activeBundleFilter({ id: { $in: ids } }), mongoSessionOptions(session)) !== ids.length) throw new MongoAdapterConstraintError(`patch "${patch.id}" references a missing bundle`);
|
|
8
8
|
};
|
|
9
9
|
const createMongoWrites = (collections, session) => ({
|
package/dist/adapters/prisma.cjs
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("../_virtual/_rolldown/runtime.cjs");
|
|
3
2
|
const require_registry = require("../db/schema/registry.cjs");
|
|
4
3
|
const require_schemaGenerators = require("../db/schemaGenerators.cjs");
|
|
5
4
|
const require_databaseConstraintErrors = require("./databaseConstraintErrors.cjs");
|
|
6
5
|
const require_databasePluginUtils = require("./databasePluginUtils.cjs");
|
|
7
|
-
const require_prismaQuery = require("./prismaQuery.cjs");
|
|
8
6
|
const require_prismaRows = require("./prismaRows.cjs");
|
|
7
|
+
const require_prismaInsights = require("./prismaInsights.cjs");
|
|
8
|
+
const require_prismaQuery = require("./prismaQuery.cjs");
|
|
9
9
|
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
10
10
|
let _hot_updater_plugin_core_internal = require("@hot-updater/plugin-core/internal");
|
|
11
11
|
//#region src/adapters/prisma.ts
|
|
12
12
|
const hasCallbackTransaction = (client) => "$transaction" in client && typeof client.$transaction === "function";
|
|
13
|
-
const runPrismaTransaction = (client, isolationLevel, callback) => {
|
|
13
|
+
const runPrismaTransaction = (client, isolationLevel, callback, retryUniqueConflict = false) => {
|
|
14
14
|
const execute = () => isolationLevel === "serializable" ? client.$transaction(callback, { isolationLevel: "Serializable" }) : client.$transaction(callback);
|
|
15
15
|
if (isolationLevel === "default") return execute();
|
|
16
16
|
return (async () => {
|
|
17
17
|
for (let attempt = 0;; attempt += 1) try {
|
|
18
18
|
return await execute();
|
|
19
19
|
} catch (error) {
|
|
20
|
-
if (attempt >= 2 || typeof error !== "object" || error === null || !("code" in error) || error.code !== "P2034") throw error;
|
|
20
|
+
if (attempt >= 2 || typeof error !== "object" || error === null || !("code" in error) || error.code !== "P2034" && !(error.code === "P2010" && "meta" in error && typeof error.meta === "object" && error.meta !== null && "code" in error.meta && error.meta.code === "40001") && !(retryUniqueConflict && error.code === "P2002")) throw error;
|
|
21
21
|
}
|
|
22
22
|
})();
|
|
23
23
|
};
|
|
@@ -45,7 +45,7 @@ const findMany = async (client, input, provider) => {
|
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
const assertPatchReferences = async (client, bundleId, baseBundleId) => {
|
|
48
|
-
const ids = Array.from(new Set([bundleId, baseBundleId]));
|
|
48
|
+
const ids = Array.from(/* @__PURE__ */ new Set([bundleId, baseBundleId]));
|
|
49
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
50
|
};
|
|
51
51
|
const createCrudImplementation = (client, provider, relationMode) => ({
|
|
@@ -155,7 +155,8 @@ const createCrudImplementation = (client, provider, relationMode) => ({
|
|
|
155
155
|
},
|
|
156
156
|
delete: async (input) => {
|
|
157
157
|
if (input.model === "bundles" && relationMode === "prisma") {
|
|
158
|
-
const
|
|
158
|
+
const rows = await require_prismaRows.getPrismaDelegate(client, "bundles").findMany({ where: require_prismaQuery.createPrismaWhere(input.where, provider) });
|
|
159
|
+
const ids = require_prismaRows.parsePrismaRows(rows, require_prismaRows.parsePrismaBundleRow).map(({ id }) => id);
|
|
159
160
|
if (ids.length === 0) return;
|
|
160
161
|
await require_prismaRows.getPrismaDelegate(client, "bundle_patches").deleteMany({ where: { OR: [{ bundle_id: { in: ids } }, { base_bundle_id: { in: ids } }] } });
|
|
161
162
|
}
|
|
@@ -188,6 +189,29 @@ const createPrismaImplementation = (client, relationMode, provider) => {
|
|
|
188
189
|
const crud = createCrudImplementation(client, provider, relationMode);
|
|
189
190
|
const implementation = {
|
|
190
191
|
...crud,
|
|
192
|
+
async recordInsights({ event }) {
|
|
193
|
+
if (!hasCallbackTransaction(client)) return require_prismaInsights.recordPrismaEventWithCte(client, provider, event);
|
|
194
|
+
const events = require_prismaRows.getPrismaDelegate(client, "bundle_events");
|
|
195
|
+
try {
|
|
196
|
+
await runPrismaTransaction(client, provider === "cockroachdb" ? "serializable" : "default", async (transaction) => {
|
|
197
|
+
await require_prismaRows.getPrismaDelegate(transaction, "bundle_events").create({ data: event });
|
|
198
|
+
await require_prismaInsights.updatePrismaEventHead(transaction, provider, event);
|
|
199
|
+
});
|
|
200
|
+
} catch (error) {
|
|
201
|
+
if (typeof error !== "object" || error === null || !("code" in error) || error.code !== "P2002") throw error;
|
|
202
|
+
if (await events.findFirst({ where: { id: event.id } }) === null) throw error;
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
async findLatestInsightsEvents(input) {
|
|
206
|
+
const rows = await require_prismaInsights.queryPrismaLatestEvents(client, provider, input);
|
|
207
|
+
if (typeof rows === "number") throw new require_prismaRows.PrismaAdapterError("invalid latest-event rows");
|
|
208
|
+
return rows;
|
|
209
|
+
},
|
|
210
|
+
async countLatestInsightsEvents(input) {
|
|
211
|
+
const count = await require_prismaInsights.queryPrismaLatestEvents(client, provider, input);
|
|
212
|
+
if (typeof count !== "number") throw new require_prismaRows.PrismaAdapterError("invalid latest-event count");
|
|
213
|
+
return count;
|
|
214
|
+
},
|
|
191
215
|
deleteChannel: (input) => {
|
|
192
216
|
if (!hasCallbackTransaction(client)) throw new require_prismaRows.PrismaAdapterError("channel deletion requires callback transactions");
|
|
193
217
|
return runPrismaTransaction(client, "serializable", (transactionClient) => createCrudImplementation(transactionClient, provider, relationMode).deleteChannel(input));
|
|
@@ -212,9 +236,22 @@ const createPrismaImplementation = (client, relationMode, provider) => {
|
|
|
212
236
|
const prismaAdapter = (config) => {
|
|
213
237
|
assertPrismaProvider(config.provider);
|
|
214
238
|
const adapter = (0, _hot_updater_plugin_core_internal.createDatabasePluginAdapter)("prisma", createPrismaImplementation(config.prisma, config.relationMode ?? "foreign-keys", config.provider));
|
|
239
|
+
const unsupportedMssqlInsights = async () => {
|
|
240
|
+
throw new require_prismaRows.PrismaAdapterError("SQL Server Insights is unsupported: string keys pad trailing spaces and do not provide the required exact UTF-8 identity ordering");
|
|
241
|
+
};
|
|
242
|
+
const insights = config.provider === "mssql" ? {
|
|
243
|
+
recordEvent: unsupportedMssqlInsights,
|
|
244
|
+
listEvents: unsupportedMssqlInsights,
|
|
245
|
+
findLatestEvents: unsupportedMssqlInsights,
|
|
246
|
+
countLatestEvents: unsupportedMssqlInsights,
|
|
247
|
+
countEvents: unsupportedMssqlInsights
|
|
248
|
+
} : adapter.models.insights;
|
|
215
249
|
return Object.assign((0, _hot_updater_plugin_core.createDatabasePlugin)({
|
|
216
250
|
name: "prisma",
|
|
217
|
-
models:
|
|
251
|
+
models: {
|
|
252
|
+
...adapter.models,
|
|
253
|
+
insights
|
|
254
|
+
},
|
|
218
255
|
commit: adapter.commit
|
|
219
256
|
}), {
|
|
220
257
|
adapterName: "prisma",
|
package/dist/adapters/prisma.mjs
CHANGED
|
@@ -2,20 +2,21 @@ import { getHotUpdaterSchemaVersion, hotUpdaterSchema } from "../db/schema/regis
|
|
|
2
2
|
import { generatePrismaSchema } from "../db/schemaGenerators.mjs";
|
|
3
3
|
import { isChannelDeleteReferencedError, translateChannelDeleteError } from "./databaseConstraintErrors.mjs";
|
|
4
4
|
import { hasNullOrderOverrides, sortRowsByOrder } from "./databasePluginUtils.mjs";
|
|
5
|
-
import { createPrismaOrderBy, createPrismaWhere } from "./prismaQuery.mjs";
|
|
6
5
|
import { PrismaAdapterError, getPrismaDelegate, parsePrismaApiKeyRow, parsePrismaBundleEventRow, parsePrismaBundleRow, parsePrismaChannelRow, parsePrismaPatchRow, parsePrismaReleaseCatalogRow, parsePrismaReleaseRow, parsePrismaRows } from "./prismaRows.mjs";
|
|
6
|
+
import { queryPrismaLatestEvents, recordPrismaEventWithCte, updatePrismaEventHead } from "./prismaInsights.mjs";
|
|
7
|
+
import { createPrismaOrderBy, createPrismaWhere } from "./prismaQuery.mjs";
|
|
7
8
|
import { DatabasePluginInputError, createDatabasePlugin } from "@hot-updater/plugin-core";
|
|
8
9
|
import { createDatabasePluginAdapter } from "@hot-updater/plugin-core/internal";
|
|
9
10
|
//#region src/adapters/prisma.ts
|
|
10
11
|
const hasCallbackTransaction = (client) => "$transaction" in client && typeof client.$transaction === "function";
|
|
11
|
-
const runPrismaTransaction = (client, isolationLevel, callback) => {
|
|
12
|
+
const runPrismaTransaction = (client, isolationLevel, callback, retryUniqueConflict = false) => {
|
|
12
13
|
const execute = () => isolationLevel === "serializable" ? client.$transaction(callback, { isolationLevel: "Serializable" }) : client.$transaction(callback);
|
|
13
14
|
if (isolationLevel === "default") return execute();
|
|
14
15
|
return (async () => {
|
|
15
16
|
for (let attempt = 0;; attempt += 1) try {
|
|
16
17
|
return await execute();
|
|
17
18
|
} catch (error) {
|
|
18
|
-
if (attempt >= 2 || typeof error !== "object" || error === null || !("code" in error) || error.code !== "P2034") throw error;
|
|
19
|
+
if (attempt >= 2 || typeof error !== "object" || error === null || !("code" in error) || error.code !== "P2034" && !(error.code === "P2010" && "meta" in error && typeof error.meta === "object" && error.meta !== null && "code" in error.meta && error.meta.code === "40001") && !(retryUniqueConflict && error.code === "P2002")) throw error;
|
|
19
20
|
}
|
|
20
21
|
})();
|
|
21
22
|
};
|
|
@@ -43,7 +44,7 @@ const findMany = async (client, input, provider) => {
|
|
|
43
44
|
}
|
|
44
45
|
};
|
|
45
46
|
const assertPatchReferences = async (client, bundleId, baseBundleId) => {
|
|
46
|
-
const ids = Array.from(new Set([bundleId, baseBundleId]));
|
|
47
|
+
const ids = Array.from(/* @__PURE__ */ new Set([bundleId, baseBundleId]));
|
|
47
48
|
if (await getPrismaDelegate(client, "bundles").count({ where: { id: { in: ids } } }) !== ids.length) throw new PrismaAdapterError("patch references a missing bundle");
|
|
48
49
|
};
|
|
49
50
|
const createCrudImplementation = (client, provider, relationMode) => ({
|
|
@@ -153,7 +154,8 @@ const createCrudImplementation = (client, provider, relationMode) => ({
|
|
|
153
154
|
},
|
|
154
155
|
delete: async (input) => {
|
|
155
156
|
if (input.model === "bundles" && relationMode === "prisma") {
|
|
156
|
-
const
|
|
157
|
+
const rows = await getPrismaDelegate(client, "bundles").findMany({ where: createPrismaWhere(input.where, provider) });
|
|
158
|
+
const ids = parsePrismaRows(rows, parsePrismaBundleRow).map(({ id }) => id);
|
|
157
159
|
if (ids.length === 0) return;
|
|
158
160
|
await getPrismaDelegate(client, "bundle_patches").deleteMany({ where: { OR: [{ bundle_id: { in: ids } }, { base_bundle_id: { in: ids } }] } });
|
|
159
161
|
}
|
|
@@ -186,6 +188,29 @@ const createPrismaImplementation = (client, relationMode, provider) => {
|
|
|
186
188
|
const crud = createCrudImplementation(client, provider, relationMode);
|
|
187
189
|
const implementation = {
|
|
188
190
|
...crud,
|
|
191
|
+
async recordInsights({ event }) {
|
|
192
|
+
if (!hasCallbackTransaction(client)) return recordPrismaEventWithCte(client, provider, event);
|
|
193
|
+
const events = getPrismaDelegate(client, "bundle_events");
|
|
194
|
+
try {
|
|
195
|
+
await runPrismaTransaction(client, provider === "cockroachdb" ? "serializable" : "default", async (transaction) => {
|
|
196
|
+
await getPrismaDelegate(transaction, "bundle_events").create({ data: event });
|
|
197
|
+
await updatePrismaEventHead(transaction, provider, event);
|
|
198
|
+
});
|
|
199
|
+
} catch (error) {
|
|
200
|
+
if (typeof error !== "object" || error === null || !("code" in error) || error.code !== "P2002") throw error;
|
|
201
|
+
if (await events.findFirst({ where: { id: event.id } }) === null) throw error;
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
async findLatestInsightsEvents(input) {
|
|
205
|
+
const rows = await queryPrismaLatestEvents(client, provider, input);
|
|
206
|
+
if (typeof rows === "number") throw new PrismaAdapterError("invalid latest-event rows");
|
|
207
|
+
return rows;
|
|
208
|
+
},
|
|
209
|
+
async countLatestInsightsEvents(input) {
|
|
210
|
+
const count = await queryPrismaLatestEvents(client, provider, input);
|
|
211
|
+
if (typeof count !== "number") throw new PrismaAdapterError("invalid latest-event count");
|
|
212
|
+
return count;
|
|
213
|
+
},
|
|
189
214
|
deleteChannel: (input) => {
|
|
190
215
|
if (!hasCallbackTransaction(client)) throw new PrismaAdapterError("channel deletion requires callback transactions");
|
|
191
216
|
return runPrismaTransaction(client, "serializable", (transactionClient) => createCrudImplementation(transactionClient, provider, relationMode).deleteChannel(input));
|
|
@@ -210,9 +235,22 @@ const createPrismaImplementation = (client, relationMode, provider) => {
|
|
|
210
235
|
const prismaAdapter = (config) => {
|
|
211
236
|
assertPrismaProvider(config.provider);
|
|
212
237
|
const adapter = createDatabasePluginAdapter("prisma", createPrismaImplementation(config.prisma, config.relationMode ?? "foreign-keys", config.provider));
|
|
238
|
+
const unsupportedMssqlInsights = async () => {
|
|
239
|
+
throw new PrismaAdapterError("SQL Server Insights is unsupported: string keys pad trailing spaces and do not provide the required exact UTF-8 identity ordering");
|
|
240
|
+
};
|
|
241
|
+
const insights = config.provider === "mssql" ? {
|
|
242
|
+
recordEvent: unsupportedMssqlInsights,
|
|
243
|
+
listEvents: unsupportedMssqlInsights,
|
|
244
|
+
findLatestEvents: unsupportedMssqlInsights,
|
|
245
|
+
countLatestEvents: unsupportedMssqlInsights,
|
|
246
|
+
countEvents: unsupportedMssqlInsights
|
|
247
|
+
} : adapter.models.insights;
|
|
213
248
|
return Object.assign(createDatabasePlugin({
|
|
214
249
|
name: "prisma",
|
|
215
|
-
models:
|
|
250
|
+
models: {
|
|
251
|
+
...adapter.models,
|
|
252
|
+
insights
|
|
253
|
+
},
|
|
216
254
|
commit: adapter.commit
|
|
217
255
|
}), {
|
|
218
256
|
adapterName: "prisma",
|