@hot-updater/server 1.0.0-rc.0 → 1.0.0-rc.2

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.
Files changed (210) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +1 -1
  2. package/dist/adapters/databaseConstraintErrors.cjs +0 -1
  3. package/dist/adapters/databasePluginUtils.cjs +0 -1
  4. package/dist/adapters/drizzle.cjs +11 -4
  5. package/dist/adapters/drizzle.d.cts +0 -1
  6. package/dist/adapters/drizzle.d.mts +0 -1
  7. package/dist/adapters/drizzle.mjs +12 -4
  8. package/dist/adapters/drizzleCrud.cjs +62 -1
  9. package/dist/adapters/drizzleCrud.mjs +61 -2
  10. package/dist/adapters/drizzleLazyDB.cjs +6 -1
  11. package/dist/adapters/drizzleLazyDB.mjs +6 -1
  12. package/dist/adapters/drizzleQuery.cjs +3 -2
  13. package/dist/adapters/drizzleQuery.mjs +3 -1
  14. package/dist/adapters/insightsTransaction.cjs +22 -0
  15. package/dist/adapters/insightsTransaction.mjs +22 -0
  16. package/dist/adapters/kysely.cjs +2 -1
  17. package/dist/adapters/kysely.d.cts +0 -1
  18. package/dist/adapters/kysely.d.mts +0 -1
  19. package/dist/adapters/kysely.mjs +3 -1
  20. package/dist/adapters/kyselyCrud.cjs +54 -3
  21. package/dist/adapters/kyselyCrud.mjs +54 -3
  22. package/dist/adapters/kyselyQuery.cjs +2 -2
  23. package/dist/adapters/kyselyQuery.mjs +2 -1
  24. package/dist/adapters/mongodb.cjs +27 -1
  25. package/dist/adapters/mongodb.d.cts +1 -1
  26. package/dist/adapters/mongodb.d.mts +1 -1
  27. package/dist/adapters/mongodb.mjs +28 -1
  28. package/dist/adapters/mongodbCollections.cjs +2 -0
  29. package/dist/adapters/mongodbCollections.mjs +2 -0
  30. package/dist/adapters/mongodbQuery.cjs +21 -4
  31. package/dist/adapters/mongodbQuery.mjs +21 -5
  32. package/dist/adapters/mongodbReads.cjs +91 -29
  33. package/dist/adapters/mongodbReads.mjs +92 -29
  34. package/dist/adapters/mongodbWrites.cjs +16 -2
  35. package/dist/adapters/mongodbWrites.mjs +18 -3
  36. package/dist/adapters/prisma.cjs +55 -7
  37. package/dist/adapters/prisma.d.cts +0 -1
  38. package/dist/adapters/prisma.d.mts +0 -1
  39. package/dist/adapters/prisma.mjs +56 -7
  40. package/dist/adapters/prismaQuery.cjs +0 -1
  41. package/dist/adapters/prismaRows.cjs +22 -1
  42. package/dist/adapters/prismaRows.mjs +22 -1
  43. package/dist/apiKeys.cjs +6 -2
  44. package/dist/apiKeys.d.cts +0 -1
  45. package/dist/apiKeys.d.mts +0 -1
  46. package/dist/apiKeys.mjs +3 -3
  47. package/dist/createHotUpdaterCore.cjs +27 -12
  48. package/dist/createHotUpdaterCore.d.cts +8 -8
  49. package/dist/createHotUpdaterCore.d.mts +8 -8
  50. package/dist/createHotUpdaterCore.mjs +26 -12
  51. package/dist/db/createBundleDiff.cjs +2 -2
  52. package/dist/db/createBundleDiff.d.cts +1 -5
  53. package/dist/db/createBundleDiff.d.mts +1 -5
  54. package/dist/db/databasePluginCore.cjs +0 -1
  55. package/dist/db/fixedMigrator.cjs +2 -2
  56. package/dist/db/fixedMigrator.mjs +2 -2
  57. package/dist/db/fixedMigratorMongo.cjs +6 -4
  58. package/dist/db/fixedMigratorMongo.mjs +6 -4
  59. package/dist/db/index.d.cts +0 -1
  60. package/dist/db/index.d.mts +0 -1
  61. package/dist/db/releaseCatalog.cjs +0 -1
  62. package/dist/db/releaseCatalog.d.cts +0 -1
  63. package/dist/db/releaseCatalog.d.mts +0 -1
  64. package/dist/db/schema/insightsCollation.cjs +14 -0
  65. package/dist/db/schema/insightsCollation.mjs +14 -0
  66. package/dist/db/schema/sql.cjs +11 -7
  67. package/dist/db/schema/sql.mjs +8 -8
  68. package/dist/db/schemaGenerators.cjs +28 -9
  69. package/dist/db/schemaGenerators.mjs +28 -9
  70. package/dist/db/schemaReadiness.cjs +2 -0
  71. package/dist/db/schemaReadiness.d.cts +1 -0
  72. package/dist/db/schemaReadiness.d.mts +1 -0
  73. package/dist/db/schemaReadiness.mjs +2 -0
  74. package/dist/db/sqlMigrationExecution.cjs +1 -1
  75. package/dist/db/sqlMigrationExecution.mjs +1 -0
  76. package/dist/db/types.cjs +3 -1
  77. package/dist/db/types.d.cts +3 -6
  78. package/dist/db/types.d.mts +3 -6
  79. package/dist/db/types.mjs +2 -2
  80. package/dist/db/updateArtifacts.cjs +0 -1
  81. package/dist/handler.cjs +5 -5
  82. package/dist/handler.d.cts +1 -2
  83. package/dist/handler.d.mts +1 -2
  84. package/dist/handler.mjs +5 -5
  85. package/dist/handlerReleaseCatalogRoutes.cjs +0 -1
  86. package/dist/handlerReleaseManagementRoutes.cjs +0 -1
  87. package/dist/handlerTypes.d.cts +0 -1
  88. package/dist/handlerTypes.d.mts +0 -1
  89. package/dist/handlerVersionRoutes.d.cts +1 -0
  90. package/dist/handlerVersionRoutes.d.mts +1 -0
  91. package/dist/index.cjs +2 -2
  92. package/dist/index.d.cts +4 -4
  93. package/dist/index.d.mts +4 -4
  94. package/dist/index.mjs +2 -2
  95. package/dist/insights/domain.d.cts +89 -0
  96. package/dist/insights/domain.d.mts +89 -0
  97. package/dist/insights/errors.cjs +15 -0
  98. package/dist/insights/errors.mjs +14 -0
  99. package/dist/{analytics → insights}/eventInput.cjs +58 -14
  100. package/dist/{analytics → insights}/eventInput.mjs +58 -16
  101. package/dist/insights/provider.cjs +314 -0
  102. package/dist/insights/provider.d.cts +6 -0
  103. package/dist/insights/provider.d.mts +6 -0
  104. package/dist/insights/provider.mjs +314 -0
  105. package/dist/insights/queryInput.cjs +93 -0
  106. package/dist/insights/queryInput.mjs +91 -0
  107. package/dist/insights/routes.cjs +58 -0
  108. package/dist/insights/routes.mjs +56 -0
  109. package/dist/insights/types.d.cts +32 -0
  110. package/dist/insights/types.d.mts +32 -0
  111. package/dist/node.d.cts +0 -1
  112. package/dist/node.d.mts +0 -1
  113. package/dist/package.cjs +1 -1
  114. package/dist/package.mjs +1 -1
  115. package/dist/schema/index.cjs +17 -3
  116. package/dist/schema/index.mjs +4 -4
  117. package/dist/schema/v1_0_0.cjs +72 -30
  118. package/dist/schema/v1_0_0.mjs +72 -31
  119. package/dist/storageAccess.cjs +0 -1
  120. package/dist/types/index.d.cts +0 -1
  121. package/dist/types/index.d.mts +0 -1
  122. package/package.json +7 -7
  123. package/src/adapters/databasePluginTestDatabase.ts +14 -0
  124. package/src/adapters/drizzle.spec.ts +99 -0
  125. package/src/adapters/drizzle.ts +22 -4
  126. package/src/adapters/drizzleCrud.ts +154 -2
  127. package/src/adapters/drizzleLazyDB.ts +17 -3
  128. package/src/adapters/insightsTransaction.ts +32 -0
  129. package/src/adapters/kysely.spec.ts +29 -0
  130. package/src/adapters/kysely.ts +10 -1
  131. package/src/adapters/kyselyCrud.ts +121 -0
  132. package/src/adapters/mongodb.integration.spec.ts +210 -0
  133. package/src/adapters/mongodb.spec.ts +69 -1
  134. package/src/adapters/mongodb.ts +66 -2
  135. package/src/adapters/mongodbCollections.ts +5 -0
  136. package/src/adapters/mongodbQuery.ts +32 -3
  137. package/src/adapters/mongodbReads.ts +69 -0
  138. package/src/adapters/mongodbTestClient.ts +41 -6
  139. package/src/adapters/mongodbTestFilter.ts +4 -1
  140. package/src/adapters/mongodbWrites.ts +27 -0
  141. package/src/adapters/prisma.spec.ts +97 -0
  142. package/src/adapters/prisma.ts +103 -3
  143. package/src/adapters/prismaRows.ts +37 -1
  144. package/src/adapters/prismaTestClient.ts +22 -5
  145. package/src/apiKeys.integration.spec.ts +3 -3
  146. package/src/createHotUpdaterCore.ts +30 -16
  147. package/src/db/databasePluginUpdateCheck.bench.ts +3 -0
  148. package/src/db/fixedMigrator.spec.ts +65 -0
  149. package/src/db/fixedMigratorMongo.spec.ts +56 -9
  150. package/src/db/fixedMigratorMongo.ts +10 -10
  151. package/src/db/index.spec.ts +8 -1
  152. package/src/db/schema/insightsCollation.ts +21 -0
  153. package/src/db/schema/sql.ts +8 -5
  154. package/src/db/schemaGenerators.ts +41 -13
  155. package/src/db/types.spec.ts +11 -3
  156. package/src/db/types.ts +13 -7
  157. package/src/handler-standalone.integration.spec.ts +6 -8
  158. package/src/handler.ts +12 -12
  159. package/src/index.ts +3 -3
  160. package/src/insights/domain.ts +103 -0
  161. package/src/insights/errors.ts +11 -0
  162. package/src/{analytics → insights}/eventInput.ts +71 -14
  163. package/src/insights/insights.integration.spec.ts +381 -0
  164. package/src/insights/provider.spec.ts +385 -0
  165. package/src/insights/provider.ts +591 -0
  166. package/src/insights/queryInput.ts +141 -0
  167. package/src/insights/routes.ts +104 -0
  168. package/src/insights/types.ts +55 -0
  169. package/src/schema/dsl-all-versions.spec.ts +3 -1
  170. package/src/schema/v1_0_0.spec.ts +77 -3
  171. package/src/schema/v1_0_0.ts +94 -30
  172. package/dist/analytics/bounded/activeOverview.cjs +0 -87
  173. package/dist/analytics/bounded/activeOverview.mjs +0 -85
  174. package/dist/analytics/bounded/installationSearch.cjs +0 -42
  175. package/dist/analytics/bounded/installationSearch.mjs +0 -42
  176. package/dist/analytics/bounded/persistence.cjs +0 -39
  177. package/dist/analytics/bounded/persistence.mjs +0 -38
  178. package/dist/analytics/bounded/provider.cjs +0 -170
  179. package/dist/analytics/bounded/provider.d.cts +0 -7
  180. package/dist/analytics/bounded/provider.d.mts +0 -7
  181. package/dist/analytics/bounded/provider.mjs +0 -170
  182. package/dist/analytics/bounded/scan.cjs +0 -144
  183. package/dist/analytics/bounded/scan.mjs +0 -138
  184. package/dist/analytics/domain.d.cts +0 -121
  185. package/dist/analytics/domain.d.mts +0 -121
  186. package/dist/analytics/errors.cjs +0 -22
  187. package/dist/analytics/errors.mjs +0 -20
  188. package/dist/analytics/persistence.d.cts +0 -6
  189. package/dist/analytics/persistence.d.mts +0 -6
  190. package/dist/analytics/queryInput.cjs +0 -58
  191. package/dist/analytics/queryInput.mjs +0 -55
  192. package/dist/analytics/routes.cjs +0 -63
  193. package/dist/analytics/routes.mjs +0 -61
  194. package/dist/analytics/types.d.cts +0 -17
  195. package/dist/analytics/types.d.mts +0 -17
  196. package/src/analytics/analytics.integration.spec.ts +0 -144
  197. package/src/analytics/bounded/activeOverview.spec.ts +0 -189
  198. package/src/analytics/bounded/activeOverview.ts +0 -148
  199. package/src/analytics/bounded/installationSearch.spec.ts +0 -130
  200. package/src/analytics/bounded/installationSearch.ts +0 -69
  201. package/src/analytics/bounded/persistence.ts +0 -43
  202. package/src/analytics/bounded/provider.spec.ts +0 -219
  203. package/src/analytics/bounded/provider.ts +0 -229
  204. package/src/analytics/bounded/scan.ts +0 -235
  205. package/src/analytics/domain.ts +0 -139
  206. package/src/analytics/errors.ts +0 -18
  207. package/src/analytics/persistence.ts +0 -10
  208. package/src/analytics/queryInput.ts +0 -102
  209. package/src/analytics/routes.ts +0 -123
  210. package/src/analytics/types.ts +0 -44
@@ -1,4 +1,3 @@
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");
@@ -15,10 +14,13 @@ const findMongoRows = async (collections, input, session) => {
15
14
  ...require_mongodbCollections.mongoSessionOptions(session)
16
15
  }).skip(input.offset).limit(input.limit);
17
16
  if (rawOrderBy === void 0) return cursor.toArray();
18
- if (needsInMemoryOrder) return require_databasePluginUtils.sortRowsByOrder(await collections.bundles.find(require_mongodbCollections.activeBundleFilter(require_mongodbQuery.createMongoBundleWhere(input.where)), {
19
- projection: require_mongodbCollections.WITHOUT_INTERNAL_FIELDS,
20
- ...require_mongodbCollections.mongoSessionOptions(session)
21
- }).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
17
+ if (needsInMemoryOrder) {
18
+ const rows = await collections.bundles.find(require_mongodbCollections.activeBundleFilter(require_mongodbQuery.createMongoBundleWhere(input.where)), {
19
+ projection: require_mongodbCollections.WITHOUT_INTERNAL_FIELDS,
20
+ ...require_mongodbCollections.mongoSessionOptions(session)
21
+ }).toArray();
22
+ return require_databasePluginUtils.sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
23
+ }
22
24
  const sort = require_mongodbQuery.createMongoSort(input);
23
25
  return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
24
26
  }
@@ -28,23 +30,53 @@ const findMongoRows = async (collections, input, session) => {
28
30
  ...require_mongodbCollections.mongoSessionOptions(session)
29
31
  }).skip(input.offset).limit(input.limit);
30
32
  if (rawOrderBy === void 0) return cursor.toArray();
31
- if (needsInMemoryOrder) return require_databasePluginUtils.sortRowsByOrder(await collections.bundlePatches.find(require_mongodbQuery.createMongoPatchWhere(input.where), {
32
- projection: require_mongodbCollections.WITHOUT_MONGO_ID,
33
- ...require_mongodbCollections.mongoSessionOptions(session)
34
- }).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
33
+ if (needsInMemoryOrder) {
34
+ const rows = await collections.bundlePatches.find(require_mongodbQuery.createMongoPatchWhere(input.where), {
35
+ projection: require_mongodbCollections.WITHOUT_MONGO_ID,
36
+ ...require_mongodbCollections.mongoSessionOptions(session)
37
+ }).toArray();
38
+ return require_databasePluginUtils.sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
39
+ }
35
40
  const sort = require_mongodbQuery.createMongoSort(input);
36
41
  return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
37
42
  }
38
43
  case "bundle_events": {
39
44
  const cursor = collections.bundleEvents.find(require_mongodbQuery.createMongoEventWhere(input.where), {
40
45
  projection: require_mongodbCollections.WITHOUT_MONGO_ID,
41
- ...require_mongodbCollections.mongoSessionOptions(session)
46
+ ...require_mongodbCollections.mongoSessionOptions(session),
47
+ collation: { locale: "simple" },
48
+ readPreference: "primary"
42
49
  }).skip(input.offset).limit(input.limit);
43
50
  if (rawOrderBy === void 0) return cursor.toArray();
44
- if (needsInMemoryOrder) return require_databasePluginUtils.sortRowsByOrder(await collections.bundleEvents.find(require_mongodbQuery.createMongoEventWhere(input.where), {
51
+ if (needsInMemoryOrder) {
52
+ const rows = await collections.bundleEvents.find(require_mongodbQuery.createMongoEventWhere(input.where), {
53
+ projection: require_mongodbCollections.WITHOUT_MONGO_ID,
54
+ ...require_mongodbCollections.mongoSessionOptions(session),
55
+ collation: { locale: "simple" },
56
+ readPreference: "primary"
57
+ }).toArray();
58
+ return require_databasePluginUtils.sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
59
+ }
60
+ const sort = require_mongodbQuery.createMongoSort(input);
61
+ return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
62
+ }
63
+ case "bundle_installations": {
64
+ const cursor = collections.bundleInstallations.find(require_mongodbQuery.createMongoInstallationWhere(input.where), {
45
65
  projection: require_mongodbCollections.WITHOUT_MONGO_ID,
46
- ...require_mongodbCollections.mongoSessionOptions(session)
47
- }).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
66
+ ...require_mongodbCollections.mongoSessionOptions(session),
67
+ collation: { locale: "simple" },
68
+ readPreference: "primary"
69
+ }).skip(input.offset).limit(input.limit);
70
+ if (rawOrderBy === void 0) return cursor.toArray();
71
+ if (needsInMemoryOrder) {
72
+ const rows = await collections.bundleInstallations.find(require_mongodbQuery.createMongoInstallationWhere(input.where), {
73
+ projection: require_mongodbCollections.WITHOUT_MONGO_ID,
74
+ ...require_mongodbCollections.mongoSessionOptions(session),
75
+ collation: { locale: "simple" },
76
+ readPreference: "primary"
77
+ }).toArray();
78
+ return require_databasePluginUtils.sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
79
+ }
48
80
  const sort = require_mongodbQuery.createMongoSort(input);
49
81
  return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
50
82
  }
@@ -54,10 +86,13 @@ const findMongoRows = async (collections, input, session) => {
54
86
  ...require_mongodbCollections.mongoSessionOptions(session)
55
87
  }).skip(input.offset).limit(input.limit);
56
88
  if (rawOrderBy === void 0) return cursor.toArray();
57
- if (needsInMemoryOrder) return require_databasePluginUtils.sortRowsByOrder(await collections.apiKeys.find(require_mongodbQuery.createMongoApiKeyWhere(input.where), {
58
- projection: require_mongodbCollections.WITHOUT_MONGO_ID,
59
- ...require_mongodbCollections.mongoSessionOptions(session)
60
- }).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
89
+ if (needsInMemoryOrder) {
90
+ const rows = await collections.apiKeys.find(require_mongodbQuery.createMongoApiKeyWhere(input.where), {
91
+ projection: require_mongodbCollections.WITHOUT_MONGO_ID,
92
+ ...require_mongodbCollections.mongoSessionOptions(session)
93
+ }).toArray();
94
+ return require_databasePluginUtils.sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
95
+ }
61
96
  const sort = require_mongodbQuery.createMongoSort(input);
62
97
  return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
63
98
  }
@@ -67,10 +102,13 @@ const findMongoRows = async (collections, input, session) => {
67
102
  ...require_mongodbCollections.mongoSessionOptions(session)
68
103
  }).skip(input.offset).limit(input.limit);
69
104
  if (rawOrderBy === void 0) return cursor.toArray();
70
- if (needsInMemoryOrder) return require_databasePluginUtils.sortRowsByOrder(await collections.channels.find(require_mongodbQuery.createMongoChannelWhere(input.where), {
71
- projection: require_mongodbCollections.WITHOUT_MONGO_ID,
72
- ...require_mongodbCollections.mongoSessionOptions(session)
73
- }).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
105
+ if (needsInMemoryOrder) {
106
+ const rows = await collections.channels.find(require_mongodbQuery.createMongoChannelWhere(input.where), {
107
+ projection: require_mongodbCollections.WITHOUT_MONGO_ID,
108
+ ...require_mongodbCollections.mongoSessionOptions(session)
109
+ }).toArray();
110
+ return require_databasePluginUtils.sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
111
+ }
74
112
  const sort = require_mongodbQuery.createMongoSort(input);
75
113
  return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
76
114
  }
@@ -80,10 +118,13 @@ const findMongoRows = async (collections, input, session) => {
80
118
  ...require_mongodbCollections.mongoSessionOptions(session)
81
119
  }).skip(input.offset).limit(input.limit);
82
120
  if (rawOrderBy === void 0) return cursor.toArray();
83
- if (needsInMemoryOrder) return require_databasePluginUtils.sortRowsByOrder(await collections.releases.find(require_mongodbQuery.createMongoReleaseWhere(input.where), {
84
- projection: require_mongodbCollections.WITHOUT_MONGO_ID,
85
- ...require_mongodbCollections.mongoSessionOptions(session)
86
- }).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
121
+ if (needsInMemoryOrder) {
122
+ const rows = await collections.releases.find(require_mongodbQuery.createMongoReleaseWhere(input.where), {
123
+ projection: require_mongodbCollections.WITHOUT_MONGO_ID,
124
+ ...require_mongodbCollections.mongoSessionOptions(session)
125
+ }).toArray();
126
+ return require_databasePluginUtils.sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
127
+ }
87
128
  const sort = require_mongodbQuery.createMongoSort(input);
88
129
  return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
89
130
  }
@@ -93,10 +134,13 @@ const findMongoRows = async (collections, input, session) => {
93
134
  ...require_mongodbCollections.mongoSessionOptions(session)
94
135
  }).skip(input.offset).limit(input.limit);
95
136
  if (rawOrderBy === void 0) return cursor.toArray();
96
- if (needsInMemoryOrder) return require_databasePluginUtils.sortRowsByOrder(await collections.releaseCatalogs.find(require_mongodbQuery.createMongoReleaseCatalogWhere(input.where), {
97
- projection: require_mongodbCollections.WITHOUT_MONGO_ID,
98
- ...require_mongodbCollections.mongoSessionOptions(session)
99
- }).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
137
+ if (needsInMemoryOrder) {
138
+ const rows = await collections.releaseCatalogs.find(require_mongodbQuery.createMongoReleaseCatalogWhere(input.where), {
139
+ projection: require_mongodbCollections.WITHOUT_MONGO_ID,
140
+ ...require_mongodbCollections.mongoSessionOptions(session)
141
+ }).toArray();
142
+ return require_databasePluginUtils.sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
143
+ }
100
144
  const sort = require_mongodbQuery.createMongoSort(input);
101
145
  return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
102
146
  }
@@ -109,6 +153,18 @@ const createMongoReads = (collections, session) => ({
109
153
  case "bundles": return collections.bundles.countDocuments(require_mongodbCollections.activeBundleFilter(require_mongodbQuery.createMongoBundleWhere(input.where)), require_mongodbCollections.mongoSessionOptions(session));
110
154
  case "bundle_patches": return collections.bundlePatches.countDocuments(require_mongodbQuery.createMongoPatchWhere(input.where), require_mongodbCollections.mongoSessionOptions(session));
111
155
  case "releases": return collections.releases.countDocuments(require_mongodbQuery.createMongoReleaseWhere(input.where), require_mongodbCollections.mongoSessionOptions(session));
156
+ case "bundle_installations": return collections.bundleInstallations.countDocuments(require_mongodbQuery.createMongoInstallationWhere(input.where), {
157
+ ...require_mongodbCollections.mongoSessionOptions(session),
158
+ collation: { locale: "simple" },
159
+ readPreference: "primary",
160
+ ...session === void 0 ? { readConcern: { level: "snapshot" } } : {}
161
+ });
162
+ case "bundle_events": return collections.bundleEvents.countDocuments(require_mongodbQuery.createMongoEventWhere(input.where), {
163
+ ...require_mongodbCollections.mongoSessionOptions(session),
164
+ collation: { locale: "simple" },
165
+ readPreference: "primary",
166
+ ...session === void 0 ? { readConcern: { level: "snapshot" } } : {}
167
+ });
112
168
  }
113
169
  },
114
170
  findOne: async (input) => {
@@ -137,6 +193,12 @@ const createMongoReads = (collections, session) => ({
137
193
  projection: require_mongodbCollections.WITHOUT_MONGO_ID,
138
194
  ...require_mongodbCollections.mongoSessionOptions(session)
139
195
  });
196
+ case "bundle_installations": return collections.bundleInstallations.findOne(require_mongodbQuery.createMongoInstallationWhere(input.where), {
197
+ projection: require_mongodbCollections.WITHOUT_MONGO_ID,
198
+ ...require_mongodbCollections.mongoSessionOptions(session),
199
+ collation: { locale: "simple" },
200
+ readPreference: "primary"
201
+ });
140
202
  }
141
203
  },
142
204
  findMany: (input) => {
@@ -1,6 +1,6 @@
1
1
  import { hasNullOrderOverrides, sortRowsByOrder } from "./databasePluginUtils.mjs";
2
2
  import { WITHOUT_INTERNAL_FIELDS, WITHOUT_MONGO_ID, activeBundleFilter, mongoSessionOptions } from "./mongodbCollections.mjs";
3
- import { createMongoApiKeyWhere, createMongoBundleWhere, createMongoChannelWhere, createMongoEventWhere, createMongoPatchWhere, createMongoReleaseCatalogWhere, createMongoReleaseWhere, createMongoSort } from "./mongodbQuery.mjs";
3
+ import { createMongoApiKeyWhere, createMongoBundleWhere, createMongoChannelWhere, createMongoEventWhere, createMongoInstallationWhere, createMongoPatchWhere, createMongoReleaseCatalogWhere, createMongoReleaseWhere, createMongoSort } from "./mongodbQuery.mjs";
4
4
  import { DatabasePluginInputError } from "@hot-updater/plugin-core";
5
5
  //#region src/adapters/mongodbReads.ts
6
6
  const findMongoRows = async (collections, input, session) => {
@@ -14,10 +14,13 @@ const findMongoRows = async (collections, input, session) => {
14
14
  ...mongoSessionOptions(session)
15
15
  }).skip(input.offset).limit(input.limit);
16
16
  if (rawOrderBy === void 0) return cursor.toArray();
17
- if (needsInMemoryOrder) return sortRowsByOrder(await collections.bundles.find(activeBundleFilter(createMongoBundleWhere(input.where)), {
18
- projection: WITHOUT_INTERNAL_FIELDS,
19
- ...mongoSessionOptions(session)
20
- }).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
17
+ if (needsInMemoryOrder) {
18
+ const rows = await collections.bundles.find(activeBundleFilter(createMongoBundleWhere(input.where)), {
19
+ projection: WITHOUT_INTERNAL_FIELDS,
20
+ ...mongoSessionOptions(session)
21
+ }).toArray();
22
+ return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
23
+ }
21
24
  const sort = createMongoSort(input);
22
25
  return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
23
26
  }
@@ -27,23 +30,53 @@ const findMongoRows = async (collections, input, session) => {
27
30
  ...mongoSessionOptions(session)
28
31
  }).skip(input.offset).limit(input.limit);
29
32
  if (rawOrderBy === void 0) return cursor.toArray();
30
- if (needsInMemoryOrder) return sortRowsByOrder(await collections.bundlePatches.find(createMongoPatchWhere(input.where), {
31
- projection: WITHOUT_MONGO_ID,
32
- ...mongoSessionOptions(session)
33
- }).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
33
+ if (needsInMemoryOrder) {
34
+ const rows = await collections.bundlePatches.find(createMongoPatchWhere(input.where), {
35
+ projection: WITHOUT_MONGO_ID,
36
+ ...mongoSessionOptions(session)
37
+ }).toArray();
38
+ return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
39
+ }
34
40
  const sort = createMongoSort(input);
35
41
  return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
36
42
  }
37
43
  case "bundle_events": {
38
44
  const cursor = collections.bundleEvents.find(createMongoEventWhere(input.where), {
39
45
  projection: WITHOUT_MONGO_ID,
40
- ...mongoSessionOptions(session)
46
+ ...mongoSessionOptions(session),
47
+ collation: { locale: "simple" },
48
+ readPreference: "primary"
41
49
  }).skip(input.offset).limit(input.limit);
42
50
  if (rawOrderBy === void 0) return cursor.toArray();
43
- if (needsInMemoryOrder) return sortRowsByOrder(await collections.bundleEvents.find(createMongoEventWhere(input.where), {
51
+ if (needsInMemoryOrder) {
52
+ const rows = await collections.bundleEvents.find(createMongoEventWhere(input.where), {
53
+ projection: WITHOUT_MONGO_ID,
54
+ ...mongoSessionOptions(session),
55
+ collation: { locale: "simple" },
56
+ readPreference: "primary"
57
+ }).toArray();
58
+ return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
59
+ }
60
+ const sort = createMongoSort(input);
61
+ return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
62
+ }
63
+ case "bundle_installations": {
64
+ const cursor = collections.bundleInstallations.find(createMongoInstallationWhere(input.where), {
44
65
  projection: WITHOUT_MONGO_ID,
45
- ...mongoSessionOptions(session)
46
- }).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
66
+ ...mongoSessionOptions(session),
67
+ collation: { locale: "simple" },
68
+ readPreference: "primary"
69
+ }).skip(input.offset).limit(input.limit);
70
+ if (rawOrderBy === void 0) return cursor.toArray();
71
+ if (needsInMemoryOrder) {
72
+ const rows = await collections.bundleInstallations.find(createMongoInstallationWhere(input.where), {
73
+ projection: WITHOUT_MONGO_ID,
74
+ ...mongoSessionOptions(session),
75
+ collation: { locale: "simple" },
76
+ readPreference: "primary"
77
+ }).toArray();
78
+ return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
79
+ }
47
80
  const sort = createMongoSort(input);
48
81
  return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
49
82
  }
@@ -53,10 +86,13 @@ const findMongoRows = async (collections, input, session) => {
53
86
  ...mongoSessionOptions(session)
54
87
  }).skip(input.offset).limit(input.limit);
55
88
  if (rawOrderBy === void 0) return cursor.toArray();
56
- if (needsInMemoryOrder) return sortRowsByOrder(await collections.apiKeys.find(createMongoApiKeyWhere(input.where), {
57
- projection: WITHOUT_MONGO_ID,
58
- ...mongoSessionOptions(session)
59
- }).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
89
+ if (needsInMemoryOrder) {
90
+ const rows = await collections.apiKeys.find(createMongoApiKeyWhere(input.where), {
91
+ projection: WITHOUT_MONGO_ID,
92
+ ...mongoSessionOptions(session)
93
+ }).toArray();
94
+ return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
95
+ }
60
96
  const sort = createMongoSort(input);
61
97
  return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
62
98
  }
@@ -66,10 +102,13 @@ const findMongoRows = async (collections, input, session) => {
66
102
  ...mongoSessionOptions(session)
67
103
  }).skip(input.offset).limit(input.limit);
68
104
  if (rawOrderBy === void 0) return cursor.toArray();
69
- if (needsInMemoryOrder) return sortRowsByOrder(await collections.channels.find(createMongoChannelWhere(input.where), {
70
- projection: WITHOUT_MONGO_ID,
71
- ...mongoSessionOptions(session)
72
- }).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
105
+ if (needsInMemoryOrder) {
106
+ const rows = await collections.channels.find(createMongoChannelWhere(input.where), {
107
+ projection: WITHOUT_MONGO_ID,
108
+ ...mongoSessionOptions(session)
109
+ }).toArray();
110
+ return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
111
+ }
73
112
  const sort = createMongoSort(input);
74
113
  return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
75
114
  }
@@ -79,10 +118,13 @@ const findMongoRows = async (collections, input, session) => {
79
118
  ...mongoSessionOptions(session)
80
119
  }).skip(input.offset).limit(input.limit);
81
120
  if (rawOrderBy === void 0) return cursor.toArray();
82
- if (needsInMemoryOrder) return sortRowsByOrder(await collections.releases.find(createMongoReleaseWhere(input.where), {
83
- projection: WITHOUT_MONGO_ID,
84
- ...mongoSessionOptions(session)
85
- }).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
121
+ if (needsInMemoryOrder) {
122
+ const rows = await collections.releases.find(createMongoReleaseWhere(input.where), {
123
+ projection: WITHOUT_MONGO_ID,
124
+ ...mongoSessionOptions(session)
125
+ }).toArray();
126
+ return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
127
+ }
86
128
  const sort = createMongoSort(input);
87
129
  return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
88
130
  }
@@ -92,10 +134,13 @@ const findMongoRows = async (collections, input, session) => {
92
134
  ...mongoSessionOptions(session)
93
135
  }).skip(input.offset).limit(input.limit);
94
136
  if (rawOrderBy === void 0) return cursor.toArray();
95
- if (needsInMemoryOrder) return sortRowsByOrder(await collections.releaseCatalogs.find(createMongoReleaseCatalogWhere(input.where), {
96
- projection: WITHOUT_MONGO_ID,
97
- ...mongoSessionOptions(session)
98
- }).toArray(), rawOrderBy).slice(input.offset, input.offset + input.limit);
137
+ if (needsInMemoryOrder) {
138
+ const rows = await collections.releaseCatalogs.find(createMongoReleaseCatalogWhere(input.where), {
139
+ projection: WITHOUT_MONGO_ID,
140
+ ...mongoSessionOptions(session)
141
+ }).toArray();
142
+ return sortRowsByOrder(rows, rawOrderBy).slice(input.offset, input.offset + input.limit);
143
+ }
99
144
  const sort = createMongoSort(input);
100
145
  return sort === void 0 ? cursor.toArray() : cursor.sort(sort).toArray();
101
146
  }
@@ -108,6 +153,18 @@ const createMongoReads = (collections, session) => ({
108
153
  case "bundles": return collections.bundles.countDocuments(activeBundleFilter(createMongoBundleWhere(input.where)), mongoSessionOptions(session));
109
154
  case "bundle_patches": return collections.bundlePatches.countDocuments(createMongoPatchWhere(input.where), mongoSessionOptions(session));
110
155
  case "releases": return collections.releases.countDocuments(createMongoReleaseWhere(input.where), mongoSessionOptions(session));
156
+ case "bundle_installations": return collections.bundleInstallations.countDocuments(createMongoInstallationWhere(input.where), {
157
+ ...mongoSessionOptions(session),
158
+ collation: { locale: "simple" },
159
+ readPreference: "primary",
160
+ ...session === void 0 ? { readConcern: { level: "snapshot" } } : {}
161
+ });
162
+ case "bundle_events": return collections.bundleEvents.countDocuments(createMongoEventWhere(input.where), {
163
+ ...mongoSessionOptions(session),
164
+ collation: { locale: "simple" },
165
+ readPreference: "primary",
166
+ ...session === void 0 ? { readConcern: { level: "snapshot" } } : {}
167
+ });
111
168
  }
112
169
  },
113
170
  findOne: async (input) => {
@@ -136,6 +193,12 @@ const createMongoReads = (collections, session) => ({
136
193
  projection: WITHOUT_MONGO_ID,
137
194
  ...mongoSessionOptions(session)
138
195
  });
196
+ case "bundle_installations": return collections.bundleInstallations.findOne(createMongoInstallationWhere(input.where), {
197
+ projection: WITHOUT_MONGO_ID,
198
+ ...mongoSessionOptions(session),
199
+ collation: { locale: "simple" },
200
+ readPreference: "primary"
201
+ });
139
202
  }
140
203
  },
141
204
  findMany: (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) => ({
@@ -51,6 +50,16 @@ const createMongoWrites = (collections, session) => ({
51
50
  case "bundle_events":
52
51
  await collections.bundleEvents.insertOne(input.data, require_mongodbCollections.mongoSessionOptions(session));
53
52
  return input.data;
53
+ case "bundle_installations":
54
+ if (input.onConflict === "ignore") {
55
+ await collections.bundleInstallations.updateOne({ install_id: input.data.install_id }, { $setOnInsert: input.data }, {
56
+ upsert: true,
57
+ ...require_mongodbCollections.mongoSessionOptions(session)
58
+ });
59
+ return input.data;
60
+ }
61
+ await collections.bundleInstallations.insertOne(input.data, require_mongodbCollections.mongoSessionOptions(session));
62
+ return input.data;
54
63
  case "releases":
55
64
  await collections.releases.insertOne(input.data, require_mongodbCollections.mongoSessionOptions(session));
56
65
  return input.data;
@@ -80,6 +89,11 @@ const createMongoWrites = (collections, session) => ({
80
89
  }
81
90
  },
82
91
  update: async (input) => {
92
+ if (input.model === "bundle_installations") return collections.bundleInstallations.findOneAndUpdate(require_mongodbQuery.createMongoInstallationWhere(input.where), { $set: input.update }, {
93
+ projection: require_mongodbCollections.WITHOUT_MONGO_ID,
94
+ returnDocument: "after",
95
+ ...require_mongodbCollections.mongoSessionOptions(session)
96
+ });
83
97
  if (input.model === "api_keys") return collections.apiKeys.findOneAndUpdate(require_mongodbQuery.createMongoApiKeyWhere(input.where), { $set: input.update }, {
84
98
  projection: require_mongodbCollections.WITHOUT_INTERNAL_FIELDS,
85
99
  returnDocument: "after",
@@ -1,9 +1,9 @@
1
- import { DELETION_TOKEN_FIELD, MongoAdapterConstraintError, WITHOUT_INTERNAL_FIELDS, activeBundleFilter, mongoSessionOptions } from "./mongodbCollections.mjs";
2
- import { createMongoApiKeyWhere, createMongoBundleWhere, createMongoChannelWhere, createMongoPatchWhere, createMongoReleaseCatalogWhere, createMongoReleaseWhere } from "./mongodbQuery.mjs";
1
+ import { DELETION_TOKEN_FIELD, MongoAdapterConstraintError, WITHOUT_INTERNAL_FIELDS, WITHOUT_MONGO_ID, activeBundleFilter, mongoSessionOptions } from "./mongodbCollections.mjs";
2
+ import { createMongoApiKeyWhere, createMongoBundleWhere, createMongoChannelWhere, createMongoInstallationWhere, createMongoPatchWhere, createMongoReleaseCatalogWhere, createMongoReleaseWhere } from "./mongodbQuery.mjs";
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) => ({
@@ -50,6 +50,16 @@ const createMongoWrites = (collections, session) => ({
50
50
  case "bundle_events":
51
51
  await collections.bundleEvents.insertOne(input.data, mongoSessionOptions(session));
52
52
  return input.data;
53
+ case "bundle_installations":
54
+ if (input.onConflict === "ignore") {
55
+ await collections.bundleInstallations.updateOne({ install_id: input.data.install_id }, { $setOnInsert: input.data }, {
56
+ upsert: true,
57
+ ...mongoSessionOptions(session)
58
+ });
59
+ return input.data;
60
+ }
61
+ await collections.bundleInstallations.insertOne(input.data, mongoSessionOptions(session));
62
+ return input.data;
53
63
  case "releases":
54
64
  await collections.releases.insertOne(input.data, mongoSessionOptions(session));
55
65
  return input.data;
@@ -79,6 +89,11 @@ const createMongoWrites = (collections, session) => ({
79
89
  }
80
90
  },
81
91
  update: async (input) => {
92
+ if (input.model === "bundle_installations") return collections.bundleInstallations.findOneAndUpdate(createMongoInstallationWhere(input.where), { $set: input.update }, {
93
+ projection: WITHOUT_MONGO_ID,
94
+ returnDocument: "after",
95
+ ...mongoSessionOptions(session)
96
+ });
82
97
  if (input.model === "api_keys") return collections.apiKeys.findOneAndUpdate(createMongoApiKeyWhere(input.where), { $set: input.update }, {
83
98
  projection: WITHOUT_INTERNAL_FIELDS,
84
99
  returnDocument: "after",
@@ -1,5 +1,4 @@
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");
@@ -10,14 +9,14 @@ let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
10
9
  let _hot_updater_plugin_core_internal = require("@hot-updater/plugin-core/internal");
11
10
  //#region src/adapters/prisma.ts
12
11
  const hasCallbackTransaction = (client) => "$transaction" in client && typeof client.$transaction === "function";
13
- const runPrismaTransaction = (client, isolationLevel, callback) => {
12
+ const runPrismaTransaction = (client, isolationLevel, callback, retryUniqueConflict = false) => {
14
13
  const execute = () => isolationLevel === "serializable" ? client.$transaction(callback, { isolationLevel: "Serializable" }) : client.$transaction(callback);
15
14
  if (isolationLevel === "default") return execute();
16
15
  return (async () => {
17
16
  for (let attempt = 0;; attempt += 1) try {
18
17
  return await execute();
19
18
  } catch (error) {
20
- 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" && !(retryUniqueConflict && error.code === "P2002")) throw error;
21
20
  }
22
21
  })();
23
22
  };
@@ -38,6 +37,7 @@ const findMany = async (client, input, provider) => {
38
37
  case "bundles": return require_prismaRows.parsePrismaRows(rows, require_prismaRows.parsePrismaBundleRow);
39
38
  case "bundle_patches": return require_prismaRows.parsePrismaRows(rows, require_prismaRows.parsePrismaPatchRow);
40
39
  case "bundle_events": return require_prismaRows.parsePrismaRows(rows, require_prismaRows.parsePrismaBundleEventRow);
40
+ case "bundle_installations": return require_prismaRows.parsePrismaRows(rows, require_prismaRows.parsePrismaInsightsInstallationRow);
41
41
  case "channels": return require_prismaRows.parsePrismaRows(rows, require_prismaRows.parsePrismaChannelRow);
42
42
  case "api_keys": return require_prismaRows.parsePrismaRows(rows, require_prismaRows.parsePrismaApiKeyRow);
43
43
  case "releases": return require_prismaRows.parsePrismaRows(rows, require_prismaRows.parsePrismaReleaseRow);
@@ -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) => ({
@@ -92,7 +92,7 @@ const createCrudImplementation = (client, provider, relationMode) => ({
92
92
  const delegate = require_prismaRows.getPrismaDelegate(client, input.model);
93
93
  let row;
94
94
  if (input.onConflict === "ignore") {
95
- const where = input.model === "channels" ? { name: input.data.name } : { hash: input.data.hash };
95
+ const where = input.model === "channels" ? { name: input.data.name } : input.model === "api_keys" ? { hash: input.data.hash } : { install_id: input.data.install_id };
96
96
  row = await delegate.upsert({
97
97
  where,
98
98
  create: input.data,
@@ -103,6 +103,7 @@ const createCrudImplementation = (client, provider, relationMode) => ({
103
103
  case "bundles": return require_prismaRows.parsePrismaBundleRow(row);
104
104
  case "bundle_patches": return require_prismaRows.parsePrismaPatchRow(row);
105
105
  case "bundle_events": return require_prismaRows.parsePrismaBundleEventRow(row);
106
+ case "bundle_installations": return require_prismaRows.parsePrismaInsightsInstallationRow(row);
106
107
  case "channels": return require_prismaRows.parsePrismaChannelRow(row);
107
108
  case "api_keys": return require_prismaRows.parsePrismaApiKeyRow(row);
108
109
  case "releases": return require_prismaRows.parsePrismaReleaseRow(row);
@@ -110,6 +111,18 @@ const createCrudImplementation = (client, provider, relationMode) => ({
110
111
  }
111
112
  },
112
113
  update: async (input) => {
114
+ if (input.model === "bundle_installations") {
115
+ const installId = input.where.find((item) => item.field === "install_id" && (item.operator === void 0 || item.operator === "eq") && typeof item.value === "string")?.value;
116
+ if (typeof installId !== "string") throw new require_prismaRows.PrismaAdapterError("bundle_installations update requires install_id");
117
+ const delegate = require_prismaRows.getPrismaDelegate(client, "bundle_installations");
118
+ if (delegate.updateMany === void 0) throw new require_prismaRows.PrismaAdapterError("model delegate \"bundle_installations\" requires updateMany");
119
+ if ((await delegate.updateMany({
120
+ where: require_prismaQuery.createPrismaWhere(input.where, provider),
121
+ data: input.update
122
+ })).count === 0) return null;
123
+ const stored = await delegate.findFirst({ where: { install_id: installId } });
124
+ return stored === null ? null : require_prismaRows.parsePrismaInsightsInstallationRow(stored);
125
+ }
113
126
  const id = input.where[0]?.value;
114
127
  if (typeof id !== "string") throw new require_prismaRows.PrismaAdapterError(`${input.model} update requires a string id`);
115
128
  if (input.model === "api_keys") {
@@ -155,7 +168,8 @@ const createCrudImplementation = (client, provider, relationMode) => ({
155
168
  },
156
169
  delete: async (input) => {
157
170
  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);
171
+ const rows = await require_prismaRows.getPrismaDelegate(client, "bundles").findMany({ where: require_prismaQuery.createPrismaWhere(input.where, provider) });
172
+ const ids = require_prismaRows.parsePrismaRows(rows, require_prismaRows.parsePrismaBundleRow).map(({ id }) => id);
159
173
  if (ids.length === 0) return;
160
174
  await require_prismaRows.getPrismaDelegate(client, "bundle_patches").deleteMany({ where: { OR: [{ bundle_id: { in: ids } }, { base_bundle_id: { in: ids } }] } });
161
175
  }
@@ -180,6 +194,7 @@ const createCrudImplementation = (client, provider, relationMode) => ({
180
194
  case "api_keys": return require_prismaRows.parsePrismaApiKeyRow(row);
181
195
  case "releases": return require_prismaRows.parsePrismaReleaseRow(row);
182
196
  case "release_catalogs": return require_prismaRows.parsePrismaReleaseCatalogRow(row);
197
+ case "bundle_installations": return require_prismaRows.parsePrismaInsightsInstallationRow(row);
183
198
  }
184
199
  },
185
200
  findMany: (input) => findMany(client, input, provider)
@@ -188,6 +203,26 @@ const createPrismaImplementation = (client, relationMode, provider) => {
188
203
  const crud = createCrudImplementation(client, provider, relationMode);
189
204
  const implementation = {
190
205
  ...crud,
206
+ recordInsights: (input) => {
207
+ if (!hasCallbackTransaction(client)) throw new require_prismaRows.PrismaAdapterError("Insights recording requires callback transactions");
208
+ return runPrismaTransaction(client, "serializable", async (transactionClient) => {
209
+ const events = require_prismaRows.getPrismaDelegate(transactionClient, "bundle_events");
210
+ if (await events.findFirst({ where: { id: input.event.id } }) !== null) return;
211
+ await events.create({ data: input.event });
212
+ const installations = require_prismaRows.getPrismaDelegate(transactionClient, "bundle_installations");
213
+ const existing = await installations.findFirst({ where: { install_id: input.installation.install_id } });
214
+ if (existing === null) {
215
+ await installations.create({ data: input.installation });
216
+ return;
217
+ }
218
+ const current = require_prismaRows.parsePrismaInsightsInstallationRow(existing);
219
+ if (current.received_at_ms > input.installation.received_at_ms || current.received_at_ms === input.installation.received_at_ms && current.id >= input.installation.id) return;
220
+ await installations.update({
221
+ where: { install_id: input.installation.install_id },
222
+ data: input.installation
223
+ });
224
+ }, true);
225
+ },
191
226
  deleteChannel: (input) => {
192
227
  if (!hasCallbackTransaction(client)) throw new require_prismaRows.PrismaAdapterError("channel deletion requires callback transactions");
193
228
  return runPrismaTransaction(client, "serializable", (transactionClient) => createCrudImplementation(transactionClient, provider, relationMode).deleteChannel(input));
@@ -212,9 +247,22 @@ const createPrismaImplementation = (client, relationMode, provider) => {
212
247
  const prismaAdapter = (config) => {
213
248
  assertPrismaProvider(config.provider);
214
249
  const adapter = (0, _hot_updater_plugin_core_internal.createDatabasePluginAdapter)("prisma", createPrismaImplementation(config.prisma, config.relationMode ?? "foreign-keys", config.provider));
250
+ const unsupportedMssqlInsights = async () => {
251
+ 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");
252
+ };
253
+ const insights = config.provider === "mssql" ? {
254
+ record: unsupportedMssqlInsights,
255
+ listEvents: unsupportedMssqlInsights,
256
+ findInstallations: unsupportedMssqlInsights,
257
+ countInstallations: unsupportedMssqlInsights,
258
+ countEvents: unsupportedMssqlInsights
259
+ } : adapter.models.insights;
215
260
  return Object.assign((0, _hot_updater_plugin_core.createDatabasePlugin)({
216
261
  name: "prisma",
217
- models: adapter.models,
262
+ models: {
263
+ ...adapter.models,
264
+ insights
265
+ },
218
266
  commit: adapter.commit
219
267
  }), {
220
268
  adapterName: "prisma",
@@ -1,5 +1,4 @@
1
1
  import { DatabaseAdapterWithCapabilities, ORMSQLProvider } from "../db/types.cjs";
2
-
3
2
  //#region src/adapters/prisma.d.ts
4
3
  type PrismaRelationMode = "prisma" | "foreign-keys";
5
4
  interface PrismaConfig {
@@ -1,5 +1,4 @@
1
1
  import { DatabaseAdapterWithCapabilities, ORMSQLProvider } from "../db/types.mjs";
2
-
3
2
  //#region src/adapters/prisma.d.ts
4
3
  type PrismaRelationMode = "prisma" | "foreign-keys";
5
4
  interface PrismaConfig {