@hot-updater/plugin-core 1.0.0-rc.3 → 1.0.0-rc.30

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 (290) hide show
  1. package/README.md +33 -0
  2. package/dist/baseCandidateKey.cjs +50 -0
  3. package/dist/baseCandidateKey.d.cts +27 -0
  4. package/dist/baseCandidateKey.d.mts +27 -0
  5. package/dist/baseCandidateKey.mjs +49 -0
  6. package/dist/bundleStorageLayout.cjs +7 -0
  7. package/dist/bundleStorageLayout.d.cts +5 -1
  8. package/dist/bundleStorageLayout.d.mts +5 -1
  9. package/dist/bundleStorageLayout.mjs +7 -1
  10. package/dist/contentType.cjs +9 -0
  11. package/dist/contentType.d.cts +4 -0
  12. package/dist/contentType.d.mts +4 -0
  13. package/dist/contentType.mjs +7 -0
  14. package/dist/coreApi.d.cts +131 -0
  15. package/dist/coreApi.d.mts +131 -0
  16. package/dist/createStorageAdapter.cjs +8 -0
  17. package/dist/createStorageAdapter.d.cts +9 -0
  18. package/dist/createStorageAdapter.d.mts +9 -0
  19. package/dist/createStorageAdapter.mjs +7 -0
  20. package/dist/database/adapter.cjs +61 -0
  21. package/dist/database/adapter.d.cts +200 -0
  22. package/dist/database/adapter.d.mts +200 -0
  23. package/dist/database/adapter.mjs +55 -0
  24. package/dist/database/distinct.cjs +88 -0
  25. package/dist/database/distinct.d.cts +18 -0
  26. package/dist/database/distinct.d.mts +18 -0
  27. package/dist/database/distinct.mjs +85 -0
  28. package/dist/database/memoryAdapter.cjs +107 -0
  29. package/dist/database/memoryAdapter.d.cts +14 -0
  30. package/dist/database/memoryAdapter.d.mts +14 -0
  31. package/dist/database/memoryAdapter.mjs +107 -0
  32. package/dist/database/values.cjs +114 -0
  33. package/dist/database/values.d.cts +17 -0
  34. package/dist/database/values.d.mts +17 -0
  35. package/dist/database/values.mjs +104 -0
  36. package/dist/database/verifyAdapter.cjs +137 -0
  37. package/dist/database/verifyAdapter.d.cts +37 -0
  38. package/dist/database/verifyAdapter.d.mts +37 -0
  39. package/dist/database/verifyAdapter.mjs +136 -0
  40. package/dist/databaseErrors.cjs +30 -0
  41. package/dist/databaseErrors.d.cts +21 -0
  42. package/dist/databaseErrors.d.mts +21 -0
  43. package/dist/databaseErrors.mjs +28 -0
  44. package/dist/databaseJsonValue.cjs +6 -0
  45. package/dist/databaseJsonValue.d.cts +9 -2
  46. package/dist/databaseJsonValue.d.mts +9 -2
  47. package/dist/databaseJsonValue.mjs +6 -0
  48. package/dist/databaseMetadata.cjs +4 -4
  49. package/dist/databaseMetadata.mjs +3 -3
  50. package/dist/databaseRows.cjs +6 -12
  51. package/dist/databaseRows.d.cts +1 -1
  52. package/dist/databaseRows.d.mts +1 -1
  53. package/dist/databaseRows.mjs +1 -7
  54. package/dist/engine/core/schema.cjs +279 -0
  55. package/dist/engine/core/schema.d.cts +312 -0
  56. package/dist/engine/core/schema.d.mts +312 -0
  57. package/dist/engine/core/schema.mjs +277 -0
  58. package/dist/engine/createEngine.cjs +72 -0
  59. package/dist/engine/createEngine.d.cts +45 -0
  60. package/dist/engine/createEngine.d.mts +45 -0
  61. package/dist/engine/createEngine.mjs +72 -0
  62. package/dist/engine/database/aggregateBatching.cjs +627 -0
  63. package/dist/engine/database/aggregateBatching.mjs +626 -0
  64. package/dist/engine/database/cursor.cjs +42 -0
  65. package/dist/engine/database/cursor.mjs +38 -0
  66. package/dist/engine/database/database.cjs +68 -0
  67. package/dist/engine/database/database.mjs +68 -0
  68. package/dist/engine/database/engine.cjs +37 -0
  69. package/dist/engine/database/engine.mjs +37 -0
  70. package/dist/engine/database/engineAggregates.cjs +120 -0
  71. package/dist/engine/database/engineAggregates.mjs +117 -0
  72. package/dist/engine/database/engineReads.cjs +182 -0
  73. package/dist/engine/database/engineReads.d.cts +10 -0
  74. package/dist/engine/database/engineReads.d.mts +10 -0
  75. package/dist/engine/database/engineReads.mjs +181 -0
  76. package/dist/engine/database/engineTransaction.cjs +399 -0
  77. package/dist/engine/database/engineTransaction.d.cts +18 -0
  78. package/dist/engine/database/engineTransaction.d.mts +18 -0
  79. package/dist/engine/database/engineTransaction.mjs +398 -0
  80. package/dist/engine/database/fence.cjs +156 -0
  81. package/dist/engine/database/fence.d.cts +41 -0
  82. package/dist/engine/database/fence.d.mts +41 -0
  83. package/dist/engine/database/fence.mjs +149 -0
  84. package/dist/engine/database/kv/kvAdapter.cjs +293 -0
  85. package/dist/engine/database/kv/kvAdapter.d.cts +116 -0
  86. package/dist/engine/database/kv/kvAdapter.d.mts +116 -0
  87. package/dist/engine/database/kv/kvAdapter.mjs +292 -0
  88. package/dist/engine/database/readMeter.cjs +80 -0
  89. package/dist/engine/database/readMeter.d.cts +34 -0
  90. package/dist/engine/database/readMeter.d.mts +34 -0
  91. package/dist/engine/database/readMeter.mjs +79 -0
  92. package/dist/engine/database/resolveSchema.cjs +197 -0
  93. package/dist/engine/database/resolveSchema.d.cts +35 -0
  94. package/dist/engine/database/resolveSchema.d.mts +35 -0
  95. package/dist/engine/database/resolveSchema.mjs +195 -0
  96. package/dist/engine/database/retention.cjs +100 -0
  97. package/dist/engine/database/retention.mjs +98 -0
  98. package/dist/engine/database/sql/sqlAdapter.cjs +290 -0
  99. package/dist/engine/database/sql/sqlAdapter.d.cts +45 -0
  100. package/dist/engine/database/sql/sqlAdapter.d.mts +45 -0
  101. package/dist/engine/database/sql/sqlAdapter.mjs +288 -0
  102. package/dist/engine/database/sql/sqlSchema.cjs +175 -0
  103. package/dist/engine/database/sql/sqlSchema.d.cts +45 -0
  104. package/dist/engine/database/sql/sqlSchema.d.mts +45 -0
  105. package/dist/engine/database/sql/sqlSchema.mjs +169 -0
  106. package/dist/engine/db/coreDatabase.cjs +94 -0
  107. package/dist/engine/db/coreDatabase.d.cts +78 -0
  108. package/dist/engine/db/coreDatabase.d.mts +78 -0
  109. package/dist/engine/db/coreDatabase.mjs +86 -0
  110. package/dist/engine/db/engineMigrator.cjs +53 -0
  111. package/dist/engine/db/engineMigrator.mjs +53 -0
  112. package/dist/engine/db/engineSql.cjs +26 -0
  113. package/dist/engine/db/engineSql.d.cts +16 -0
  114. package/dist/engine/db/engineSql.d.mts +16 -0
  115. package/dist/engine/db/engineSql.mjs +25 -0
  116. package/dist/engine/db/engineSqlMigrator.cjs +67 -0
  117. package/dist/engine/db/engineSqlMigrator.d.cts +21 -0
  118. package/dist/engine/db/engineSqlMigrator.d.mts +21 -0
  119. package/dist/engine/db/engineSqlMigrator.mjs +67 -0
  120. package/dist/engine/db/fixedMigratorShared.cjs +12 -0
  121. package/dist/engine/db/fixedMigratorShared.mjs +11 -0
  122. package/dist/engine/db/schemaSettings.cjs +63 -0
  123. package/dist/engine/db/schemaSettings.d.cts +7 -0
  124. package/dist/engine/db/schemaSettings.d.mts +7 -0
  125. package/dist/engine/db/schemaSettings.mjs +62 -0
  126. package/dist/engine/db/settingsMigrator.cjs +94 -0
  127. package/dist/engine/db/settingsMigrator.d.cts +25 -0
  128. package/dist/engine/db/settingsMigrator.d.mts +25 -0
  129. package/dist/engine/db/settingsMigrator.mjs +91 -0
  130. package/dist/engine/db/types.d.cts +78 -0
  131. package/dist/engine/db/types.d.mts +78 -0
  132. package/dist/index.cjs +97 -49
  133. package/dist/index.d.cts +46 -22
  134. package/dist/index.d.mts +46 -22
  135. package/dist/index.mjs +32 -17
  136. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/comparison-DenM3wCn.cjs +0 -5
  137. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/comparison-DenM3wCn.mjs +1 -5
  138. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/range-DvX-Y6iv.cjs +8 -0
  139. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/range-DvX-Y6iv.mjs +9 -2
  140. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/set-CC5YeoYX.cjs +4 -0
  141. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/set-CC5YeoYX.mjs +4 -1
  142. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/version-CQ98ZBpL.cjs +0 -5
  143. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/version-CQ98ZBpL.mjs +2 -6
  144. package/dist/releaseCatalogCompiler.cjs +27 -26
  145. package/dist/releaseCatalogCompiler.d.cts +1 -2
  146. package/dist/releaseCatalogCompiler.d.mts +2 -3
  147. package/dist/releaseCatalogCompiler.mjs +5 -9
  148. package/dist/releaseCatalogMutation.cjs +0 -292
  149. package/dist/releaseCatalogMutation.d.cts +4 -45
  150. package/dist/releaseCatalogMutation.d.mts +4 -45
  151. package/dist/releaseCatalogMutation.mjs +1 -288
  152. package/dist/releaseManagement.cjs +0 -221
  153. package/dist/releaseManagement.d.cts +4 -28
  154. package/dist/releaseManagement.d.mts +4 -28
  155. package/dist/releaseManagement.mjs +1 -216
  156. package/dist/remoteBundleSigning.d.cts +2 -2
  157. package/dist/remoteBundleSigning.d.mts +2 -2
  158. package/dist/serverPlugin/busy.cjs +36 -0
  159. package/dist/serverPlugin/busy.d.cts +12 -0
  160. package/dist/serverPlugin/busy.d.mts +12 -0
  161. package/dist/serverPlugin/busy.mjs +36 -0
  162. package/dist/serverPlugin/configError.cjs +7 -0
  163. package/dist/serverPlugin/configError.d.cts +7 -0
  164. package/dist/serverPlugin/configError.d.mts +7 -0
  165. package/dist/serverPlugin/configError.mjs +7 -0
  166. package/dist/serverPlugin/coreReads.d.cts +48 -0
  167. package/dist/serverPlugin/coreReads.d.mts +48 -0
  168. package/dist/serverPlugin/databaseHandle.d.cts +105 -0
  169. package/dist/serverPlugin/databaseHandle.d.mts +105 -0
  170. package/dist/serverPlugin/definePlugin.cjs +5 -0
  171. package/dist/serverPlugin/definePlugin.d.cts +130 -0
  172. package/dist/serverPlugin/definePlugin.d.mts +130 -0
  173. package/dist/serverPlugin/definePlugin.mjs +5 -0
  174. package/dist/serverPlugin/definitions.d.cts +76 -0
  175. package/dist/serverPlugin/definitions.d.mts +76 -0
  176. package/dist/serverPlugin/errors.cjs +37 -0
  177. package/dist/serverPlugin/errors.d.cts +29 -0
  178. package/dist/serverPlugin/errors.d.mts +29 -0
  179. package/dist/serverPlugin/errors.mjs +32 -0
  180. package/dist/serverPlugin/schema.cjs +24 -0
  181. package/dist/serverPlugin/schema.d.cts +90 -0
  182. package/dist/serverPlugin/schema.d.mts +90 -0
  183. package/dist/serverPlugin/schema.mjs +23 -0
  184. package/dist/types/databaseConfig.cjs +5 -0
  185. package/dist/types/databaseConfig.d.cts +68 -0
  186. package/dist/types/databaseConfig.d.mts +68 -0
  187. package/dist/types/databaseConfig.mjs +5 -0
  188. package/dist/types/databaseOperations.d.cts +5 -180
  189. package/dist/types/databaseOperations.d.mts +5 -180
  190. package/dist/types/databaseRows.d.cts +5 -56
  191. package/dist/types/databaseRows.d.mts +5 -56
  192. package/dist/types/index.cjs +2 -0
  193. package/dist/types/index.d.cts +31 -97
  194. package/dist/types/index.d.mts +31 -97
  195. package/dist/types/index.mjs +2 -1
  196. package/dist/types/models.d.cts +14 -0
  197. package/dist/types/models.d.mts +14 -0
  198. package/dist/types/public.d.cts +4 -3
  199. package/dist/types/public.d.mts +4 -3
  200. package/dist/uuidv7.cjs +3 -3
  201. package/dist/uuidv7.d.cts +1 -1
  202. package/dist/uuidv7.d.mts +1 -1
  203. package/dist/uuidv7.mjs +1 -1
  204. package/package.json +10 -7
  205. package/dist/calculatePagination.cjs +0 -25
  206. package/dist/calculatePagination.d.cts +0 -12
  207. package/dist/calculatePagination.d.mts +0 -12
  208. package/dist/calculatePagination.mjs +0 -25
  209. package/dist/compressionFormat.cjs +0 -62
  210. package/dist/compressionFormat.d.cts +0 -33
  211. package/dist/compressionFormat.d.mts +0 -33
  212. package/dist/compressionFormat.mjs +0 -58
  213. package/dist/createDatabasePlugin.cjs +0 -920
  214. package/dist/createDatabasePlugin.d.cts +0 -28
  215. package/dist/createDatabasePlugin.d.mts +0 -28
  216. package/dist/createDatabasePlugin.mjs +0 -916
  217. package/dist/createStoragePlugin.cjs +0 -8
  218. package/dist/createStoragePlugin.d.cts +0 -9
  219. package/dist/createStoragePlugin.d.mts +0 -9
  220. package/dist/createStoragePlugin.mjs +0 -7
  221. package/dist/databaseClient.cjs +0 -117
  222. package/dist/databaseClient.d.cts +0 -32
  223. package/dist/databaseClient.d.mts +0 -32
  224. package/dist/databaseClient.mjs +0 -114
  225. package/dist/databaseClientReads.cjs +0 -115
  226. package/dist/databaseClientReads.mjs +0 -113
  227. package/dist/databaseClientUpdates.cjs +0 -40
  228. package/dist/databaseClientUpdates.d.cts +0 -11
  229. package/dist/databaseClientUpdates.d.mts +0 -11
  230. package/dist/databaseClientUpdates.mjs +0 -38
  231. package/dist/databasePluginCrud.cjs +0 -88
  232. package/dist/databasePluginCrud.d.cts +0 -4
  233. package/dist/databasePluginCrud.d.mts +0 -4
  234. package/dist/databasePluginCrud.mjs +0 -87
  235. package/dist/databasePluginCrudValidation.d.cts +0 -6
  236. package/dist/databasePluginCrudValidation.d.mts +0 -6
  237. package/dist/databasePluginCrudValidationErrors.cjs +0 -11
  238. package/dist/databasePluginCrudValidationErrors.d.cts +0 -9
  239. package/dist/databasePluginCrudValidationErrors.d.mts +0 -9
  240. package/dist/databasePluginCrudValidationErrors.mjs +0 -11
  241. package/dist/databasePluginCrudValidationFields.cjs +0 -321
  242. package/dist/databasePluginCrudValidationFields.d.cts +0 -1
  243. package/dist/databasePluginCrudValidationFields.d.mts +0 -1
  244. package/dist/databasePluginCrudValidationFields.mjs +0 -309
  245. package/dist/databasePluginCrudValidationMutations.cjs +0 -107
  246. package/dist/databasePluginCrudValidationMutations.d.cts +0 -1
  247. package/dist/databasePluginCrudValidationMutations.d.mts +0 -1
  248. package/dist/databasePluginCrudValidationMutations.mjs +0 -100
  249. package/dist/databasePluginCrudValidationQueries.cjs +0 -103
  250. package/dist/databasePluginCrudValidationQueries.d.cts +0 -2
  251. package/dist/databasePluginCrudValidationQueries.d.mts +0 -2
  252. package/dist/databasePluginCrudValidationQueries.mjs +0 -97
  253. package/dist/databasePluginCrudValidationRows.cjs +0 -55
  254. package/dist/databasePluginCrudValidationRows.d.cts +0 -1
  255. package/dist/databasePluginCrudValidationRows.d.mts +0 -1
  256. package/dist/databasePluginCrudValidationRows.mjs +0 -53
  257. package/dist/databasePluginTransaction.cjs +0 -7
  258. package/dist/databasePluginTransaction.mjs +0 -7
  259. package/dist/insightsContract.cjs +0 -157
  260. package/dist/insightsContract.d.cts +0 -11
  261. package/dist/insightsContract.d.mts +0 -11
  262. package/dist/insightsContract.mjs +0 -153
  263. package/dist/internal.cjs +0 -6
  264. package/dist/internal.d.cts +0 -10
  265. package/dist/internal.d.mts +0 -10
  266. package/dist/internal.mjs +0 -3
  267. package/dist/paginateBundles.cjs +0 -53
  268. package/dist/paginateBundles.d.cts +0 -13
  269. package/dist/paginateBundles.d.mts +0 -13
  270. package/dist/paginateBundles.mjs +0 -53
  271. package/dist/queryBundles.cjs +0 -34
  272. package/dist/queryBundles.d.cts +0 -9
  273. package/dist/queryBundles.d.mts +0 -9
  274. package/dist/queryBundles.mjs +0 -32
  275. package/dist/requestBundleCache.cjs +0 -22
  276. package/dist/requestBundleCache.d.cts +0 -8
  277. package/dist/requestBundleCache.d.mts +0 -8
  278. package/dist/requestBundleCache.mjs +0 -22
  279. package/dist/types/database.d.cts +0 -5
  280. package/dist/types/database.d.mts +0 -5
  281. package/dist/types/databaseFields.cjs +0 -105
  282. package/dist/types/databaseFields.d.cts +0 -13
  283. package/dist/types/databaseFields.d.mts +0 -13
  284. package/dist/types/databaseFields.mjs +0 -105
  285. package/dist/types/databasePlugin.d.cts +0 -298
  286. package/dist/types/databasePlugin.d.mts +0 -298
  287. package/dist/types/databaseQuery.d.cts +0 -46
  288. package/dist/types/databaseQuery.d.mts +0 -46
  289. package/dist/types/internal.d.cts +0 -8
  290. package/dist/types/internal.d.mts +0 -8
@@ -1,97 +0,0 @@
1
- import { DatabasePluginInputError } from "./databasePluginCrudValidationErrors.mjs";
2
- import { isBooleanField, isNumberField, isRecord, isStringField, modelValidators, sortableFields, validateField, validateFields } from "./databasePluginCrudValidationFields.mjs";
3
- //#region src/databasePluginCrudValidationQueries.ts
4
- const validateSelect = (model, select) => {
5
- if (select === void 0) return;
6
- if (!Array.isArray(select) || select.length === 0) throw new DatabasePluginInputError("empty-select");
7
- if (!select.every((field) => typeof field === "string")) throw new DatabasePluginInputError("invalid-query");
8
- validateFields(model, select);
9
- };
10
- const validateWhereValue = (model, condition) => {
11
- const field = condition.field;
12
- if (typeof field !== "string") throw new DatabasePluginInputError("invalid-query");
13
- validateField(model, field);
14
- const operator = condition.operator ?? "eq";
15
- const value = condition.value;
16
- const mode = condition.mode;
17
- if (mode !== void 0 && mode !== "sensitive" && mode !== "insensitive") throw new DatabasePluginInputError("invalid-query");
18
- switch (operator) {
19
- case "eq":
20
- case "ne":
21
- if (!(isStringField(field) || isNumberField(field) || isBooleanField(field)) || !modelValidators[model][field]?.(value) || mode !== void 0 && (!isStringField(field) || typeof value !== "string")) throw new DatabasePluginInputError("invalid-query");
22
- return;
23
- case "gt":
24
- case "gte":
25
- case "lt":
26
- case "lte":
27
- if (mode !== void 0 || !(isStringField(field) || isNumberField(field)) || value === null || !modelValidators[model][field]?.(value)) throw new DatabasePluginInputError("invalid-query");
28
- return;
29
- case "in":
30
- case "not_in":
31
- if (!Array.isArray(value) || mode !== void 0) throw new DatabasePluginInputError("invalid-query");
32
- if (!(isStringField(field) || isNumberField(field) || isBooleanField(field))) throw new DatabasePluginInputError("invalid-query");
33
- if (!value.every((item) => modelValidators[model][field]?.(item))) throw new DatabasePluginInputError("invalid-query");
34
- return;
35
- case "contains":
36
- case "starts_with":
37
- case "ends_with":
38
- if (!isStringField(field) || typeof value !== "string" || !modelValidators[model][field]?.(value)) throw new DatabasePluginInputError("invalid-query");
39
- return;
40
- default: throw new DatabasePluginInputError("invalid-query");
41
- }
42
- };
43
- const validateWhere = (model, where) => {
44
- if (where === void 0) return;
45
- if (!Array.isArray(where)) throw new DatabasePluginInputError("invalid-query");
46
- for (const item of where) {
47
- if (!isRecord(item)) throw new DatabasePluginInputError("invalid-query");
48
- if (item.connector !== void 0 && item.connector !== "AND" && item.connector !== "OR") throw new DatabasePluginInputError("invalid-query");
49
- validateWhereValue(model, item);
50
- }
51
- };
52
- const validateDistinctFields = (model, fields) => {
53
- if (fields === void 0) return void 0;
54
- if (!Array.isArray(fields) || fields.length === 0) throw new DatabasePluginInputError("invalid-distinct");
55
- if (!fields.every((field) => typeof field === "string")) throw new DatabasePluginInputError("invalid-distinct");
56
- validateFields(model, fields);
57
- return fields;
58
- };
59
- const validateOrderBy = (model, orderBy) => {
60
- if (orderBy === void 0) return void 0;
61
- if (!Array.isArray(orderBy) || orderBy.length === 0) throw new DatabasePluginInputError("invalid-query");
62
- const fields = /* @__PURE__ */ new Set();
63
- return orderBy.map((clause) => {
64
- if (!isRecord(clause) || typeof clause.field !== "string") throw new DatabasePluginInputError("invalid-query");
65
- validateField(model, clause.field);
66
- if (!sortableFields[model].has(clause.field)) throw new DatabasePluginInputError("invalid-query");
67
- if (clause.direction !== "asc" && clause.direction !== "desc") throw new DatabasePluginInputError("invalid-query");
68
- if (clause.nulls !== void 0 && clause.nulls !== "first" && clause.nulls !== "last") throw new DatabasePluginInputError("invalid-query");
69
- if (fields.has(clause.field)) throw new DatabasePluginInputError("invalid-operation");
70
- fields.add(clause.field);
71
- return clause;
72
- });
73
- };
74
- const validateDistinctOn = (model, distinctOn, orderBy) => {
75
- if (distinctOn === void 0) return;
76
- if (!isRecord(distinctOn)) throw new DatabasePluginInputError("invalid-distinct");
77
- const fields = validateDistinctFields(model, distinctOn.fields);
78
- if (fields === void 0 || orderBy === void 0) throw new DatabasePluginInputError("invalid-distinct");
79
- for (const [index, field] of fields.entries()) if (orderBy[index]?.field !== field) throw new DatabasePluginInputError("invalid-distinct");
80
- };
81
- const validatePagination = (limit, offset) => {
82
- const effectiveLimit = limit ?? 100;
83
- const effectiveOffset = offset ?? 0;
84
- if (limit !== void 0 && (!Number.isSafeInteger(limit) || limit < 0) || offset !== void 0 && (!Number.isSafeInteger(offset) || offset < 0) || !Number.isSafeInteger(effectiveOffset + effectiveLimit)) throw new DatabasePluginInputError("invalid-pagination");
85
- };
86
- const validateBundlePagination = (options) => {
87
- if (!Number.isSafeInteger(options.limit) || options.limit <= 0 || options.page !== void 0 && (!Number.isSafeInteger(options.page) || options.page <= 0) || options.page !== void 0 && options.cursor !== void 0) throw new DatabasePluginInputError("invalid-pagination");
88
- const cursor = options.cursor;
89
- if (cursor === void 0) return;
90
- if (!isRecord(cursor)) throw new DatabasePluginInputError("invalid-pagination");
91
- const hasAfter = Object.hasOwn(cursor, "after");
92
- if (hasAfter === Object.hasOwn(cursor, "before")) throw new DatabasePluginInputError("invalid-pagination");
93
- const value = hasAfter ? cursor.after : cursor.before;
94
- if (typeof value !== "string" || value.length === 0) throw new DatabasePluginInputError("invalid-pagination");
95
- };
96
- //#endregion
97
- export { validateBundlePagination, validateDistinctFields, validateDistinctOn, validateOrderBy, validatePagination, validateSelect, validateWhere };
@@ -1,55 +0,0 @@
1
- const require_databasePluginCrudValidationErrors = require("./databasePluginCrudValidationErrors.cjs");
2
- const require_databaseFields = require("./types/databaseFields.cjs");
3
- const require_databasePluginCrudValidationFields = require("./databasePluginCrudValidationFields.cjs");
4
- //#region src/databasePluginCrudValidationRows.ts
5
- const hasValidReleaseInvariants = (data) => {
6
- const kind = data.kind;
7
- const bundleId = data.bundle_id;
8
- const strategy = data.strategy;
9
- const targetAppVersion = data.target_app_version;
10
- const fingerprintHash = data.fingerprint_hash;
11
- return (kind === "BUNDLE" && typeof bundleId === "string" || kind === "EMBEDDED" && bundleId === null) && (strategy === "APP_VERSION" && typeof targetAppVersion === "string" && fingerprintHash === null || strategy === "FINGERPRINT" && targetAppVersion === null && typeof fingerprintHash === "string");
12
- };
13
- const hasValidBundleEventInvariants = (data) => (data.type === "UPDATE_APPLIED" || data.type === "RECOVERED") && typeof data.from_bundle_id === "string" && (data.update_strategy === "fingerprint" || data.update_strategy === "appVersion") || data.type === "UNCHANGED" && data.from_bundle_id === null && data.update_strategy === null;
14
- const validateCreateData = (model, data) => {
15
- if (!require_databasePluginCrudValidationFields.isRecord(data)) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-data");
16
- require_databasePluginCrudValidationFields.validateFields(model, Object.keys(data));
17
- for (const field of require_databaseFields.databaseFields[model]) {
18
- const validator = require_databasePluginCrudValidationFields.modelValidators[model][field];
19
- if (!Object.hasOwn(data, field) || !validator || !validator(Reflect.get(data, field))) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-data");
20
- }
21
- if (model === "bundles" && data.target_app_version === null && data.fingerprint_hash === null) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-data");
22
- if (model === "releases" && !hasValidReleaseInvariants(data)) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-data");
23
- if (model === "release_catalogs" && (data.strategy === "APP_VERSION" && data.fingerprint_hash !== null || data.strategy === "FINGERPRINT" && typeof data.fingerprint_hash !== "string")) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-data");
24
- if (model === "bundle_events" && !hasValidBundleEventInvariants(data)) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-data");
25
- };
26
- const selectRow = (row, input) => {
27
- const { select } = input;
28
- if (!select) return row;
29
- return Object.fromEntries(select.map((field) => [field, Reflect.get(row, field)]));
30
- };
31
- const validateResult = (model, row, select) => {
32
- if (!require_databasePluginCrudValidationFields.isRecord(row)) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-result");
33
- const fields = select ?? require_databaseFields.databaseFields[model];
34
- for (const field of fields) {
35
- const validator = require_databasePluginCrudValidationFields.modelValidators[model][field];
36
- if (!Object.hasOwn(row, field) || !validator || !validator(Reflect.get(row, field))) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-result");
37
- }
38
- if (model === "bundles" && Object.hasOwn(row, "target_app_version") && Object.hasOwn(row, "fingerprint_hash") && Reflect.get(row, "target_app_version") === null && Reflect.get(row, "fingerprint_hash") === null) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-result");
39
- if (model === "releases" && [
40
- "kind",
41
- "bundle_id",
42
- "strategy",
43
- "target_app_version",
44
- "fingerprint_hash"
45
- ].every((field) => Object.hasOwn(row, field)) && !hasValidReleaseInvariants(row)) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-result");
46
- if (model === "bundle_events" && [
47
- "type",
48
- "from_bundle_id",
49
- "update_strategy"
50
- ].every((field) => Object.hasOwn(row, field)) && !hasValidBundleEventInvariants(row)) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-result");
51
- };
52
- //#endregion
53
- exports.selectRow = selectRow;
54
- exports.validateCreateData = validateCreateData;
55
- exports.validateResult = validateResult;
@@ -1 +0,0 @@
1
- import "./types/internal.cjs";
@@ -1 +0,0 @@
1
- import "./types/internal.mjs";
@@ -1,53 +0,0 @@
1
- import { DatabasePluginInputError } from "./databasePluginCrudValidationErrors.mjs";
2
- import { databaseFields } from "./types/databaseFields.mjs";
3
- import { isRecord, modelValidators, validateFields } from "./databasePluginCrudValidationFields.mjs";
4
- //#region src/databasePluginCrudValidationRows.ts
5
- const hasValidReleaseInvariants = (data) => {
6
- const kind = data.kind;
7
- const bundleId = data.bundle_id;
8
- const strategy = data.strategy;
9
- const targetAppVersion = data.target_app_version;
10
- const fingerprintHash = data.fingerprint_hash;
11
- return (kind === "BUNDLE" && typeof bundleId === "string" || kind === "EMBEDDED" && bundleId === null) && (strategy === "APP_VERSION" && typeof targetAppVersion === "string" && fingerprintHash === null || strategy === "FINGERPRINT" && targetAppVersion === null && typeof fingerprintHash === "string");
12
- };
13
- const hasValidBundleEventInvariants = (data) => (data.type === "UPDATE_APPLIED" || data.type === "RECOVERED") && typeof data.from_bundle_id === "string" && (data.update_strategy === "fingerprint" || data.update_strategy === "appVersion") || data.type === "UNCHANGED" && data.from_bundle_id === null && data.update_strategy === null;
14
- const validateCreateData = (model, data) => {
15
- if (!isRecord(data)) throw new DatabasePluginInputError("invalid-data");
16
- validateFields(model, Object.keys(data));
17
- for (const field of databaseFields[model]) {
18
- const validator = modelValidators[model][field];
19
- if (!Object.hasOwn(data, field) || !validator || !validator(Reflect.get(data, field))) throw new DatabasePluginInputError("invalid-data");
20
- }
21
- if (model === "bundles" && data.target_app_version === null && data.fingerprint_hash === null) throw new DatabasePluginInputError("invalid-data");
22
- if (model === "releases" && !hasValidReleaseInvariants(data)) throw new DatabasePluginInputError("invalid-data");
23
- if (model === "release_catalogs" && (data.strategy === "APP_VERSION" && data.fingerprint_hash !== null || data.strategy === "FINGERPRINT" && typeof data.fingerprint_hash !== "string")) throw new DatabasePluginInputError("invalid-data");
24
- if (model === "bundle_events" && !hasValidBundleEventInvariants(data)) throw new DatabasePluginInputError("invalid-data");
25
- };
26
- const selectRow = (row, input) => {
27
- const { select } = input;
28
- if (!select) return row;
29
- return Object.fromEntries(select.map((field) => [field, Reflect.get(row, field)]));
30
- };
31
- const validateResult = (model, row, select) => {
32
- if (!isRecord(row)) throw new DatabasePluginInputError("invalid-result");
33
- const fields = select ?? databaseFields[model];
34
- for (const field of fields) {
35
- const validator = modelValidators[model][field];
36
- if (!Object.hasOwn(row, field) || !validator || !validator(Reflect.get(row, field))) throw new DatabasePluginInputError("invalid-result");
37
- }
38
- if (model === "bundles" && Object.hasOwn(row, "target_app_version") && Object.hasOwn(row, "fingerprint_hash") && Reflect.get(row, "target_app_version") === null && Reflect.get(row, "fingerprint_hash") === null) throw new DatabasePluginInputError("invalid-result");
39
- if (model === "releases" && [
40
- "kind",
41
- "bundle_id",
42
- "strategy",
43
- "target_app_version",
44
- "fingerprint_hash"
45
- ].every((field) => Object.hasOwn(row, field)) && !hasValidReleaseInvariants(row)) throw new DatabasePluginInputError("invalid-result");
46
- if (model === "bundle_events" && [
47
- "type",
48
- "from_bundle_id",
49
- "update_strategy"
50
- ].every((field) => Object.hasOwn(row, field)) && !hasValidBundleEventInvariants(row)) throw new DatabasePluginInputError("invalid-result");
51
- };
52
- //#endregion
53
- export { selectRow, validateCreateData, validateResult };
@@ -1,7 +0,0 @@
1
- const require_databasePluginCrud = require("./databasePluginCrud.cjs");
2
- //#region src/databasePluginTransaction.ts
3
- const createTransactionDatabasePlugin = (implementation) => {
4
- return require_databasePluginCrud.createDatabasePluginCrud(implementation);
5
- };
6
- //#endregion
7
- exports.createTransactionDatabasePlugin = createTransactionDatabasePlugin;
@@ -1,7 +0,0 @@
1
- import { createDatabasePluginCrud } from "./databasePluginCrud.mjs";
2
- //#region src/databasePluginTransaction.ts
3
- const createTransactionDatabasePlugin = (implementation) => {
4
- return createDatabasePluginCrud(implementation);
5
- };
6
- //#endregion
7
- export { createTransactionDatabasePlugin };
@@ -1,157 +0,0 @@
1
- const require_databasePluginCrudValidationErrors = require("./databasePluginCrudValidationErrors.cjs");
2
- const require_databasePluginCrudValidationFields = require("./databasePluginCrudValidationFields.cjs");
3
- const require_databasePluginCrudValidationRows = require("./databasePluginCrudValidationRows.cjs");
4
- let _hot_updater_core = require("@hot-updater/core");
5
- //#region src/insightsContract.ts
6
- const encoder = new TextEncoder();
7
- /** Exact UTF-8 byte ordering, without case folding or Unicode normalization. */
8
- const compareInsightsText = (left, right) => {
9
- const a = encoder.encode(left);
10
- const b = encoder.encode(right);
11
- for (let index = 0; index < Math.min(a.length, b.length); index += 1) if (a[index] !== b[index]) return a[index] - b[index];
12
- return a.length - b.length;
13
- };
14
- const isWellFormedText = (value) => {
15
- for (const character of value) {
16
- const point = character.codePointAt(0);
17
- if (point >= 55296 && point <= 57343) return false;
18
- }
19
- return true;
20
- };
21
- const isIdentity = (value) => typeof value === "string" && value.length > 0 && value.length <= 255 && isWellFormedText(value);
22
- const isText = (value) => typeof value === "string" && value.length > 0 && isWellFormedText(value);
23
- const isTimestamp = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
24
- const isLimit = (value) => isTimestamp(value) && value >= 1 && value <= 101;
25
- const hasOnlyKeys = (value, keys) => Object.keys(value).every((key) => keys.includes(key));
26
- const hasScope = (value) => (value.platform === "ios" || value.platform === "android") && isText(value.channel);
27
- const isBundleFilter = (value, withKind = false) => {
28
- if (!require_databasePluginCrudValidationFields.isRecord(value) || !hasScope(value)) return false;
29
- const keys = [
30
- "platform",
31
- "channel",
32
- "type",
33
- ...withKind ? ["kind"] : []
34
- ];
35
- return value.type === "RECOVERED" ? isText(value.fromBundleId) && hasOnlyKeys(value, [...keys, "fromBundleId"]) : (value.type === "UPDATE_APPLIED" || value.type === "UNCHANGED") && isText(value.toBundleId) && hasOnlyKeys(value, [...keys, "toBundleId"]);
36
- };
37
- const isEventFilter = (value) => {
38
- if (!require_databasePluginCrudValidationFields.isRecord(value)) return false;
39
- if (value.kind === "all") return hasOnlyKeys(value, ["kind"]);
40
- if (value.kind === "installationMovement") return isIdentity(value.installId) && hasOnlyKeys(value, ["kind", "installId"]);
41
- return value.kind === "bundle" && isBundleFilter(value, true);
42
- };
43
- const validateRow = (model, row, result = false) => {
44
- try {
45
- require_databasePluginCrudValidationRows.validateCreateData(model, row);
46
- if (!require_databasePluginCrudValidationFields.isRecord(row) || typeof row.id !== "string" || !(0, _hot_updater_core.isUUIDv7)(row.id) || Object.values(row).some((value) => typeof value === "string" && !isWellFormedText(value))) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-data");
47
- } catch (error) {
48
- if (result) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-result");
49
- throw error;
50
- }
51
- };
52
- /** Prepare the full latest-state candidate; the provider owns winning writes. */
53
- const toInsightsInstallationRow = (event) => {
54
- validateRow("bundle_events", event);
55
- return {
56
- id: event.id,
57
- install_id: event.install_id,
58
- user_id: event.user_id,
59
- username: event.username,
60
- to_bundle_id: event.to_bundle_id,
61
- type: event.type,
62
- platform: event.platform,
63
- app_version: event.app_version,
64
- channel: event.channel,
65
- cohort: event.cohort,
66
- received_at_ms: event.received_at_ms
67
- };
68
- };
69
- /** Unchanged reports are not bundle movements. */
70
- const isInsightsMovementEvent = (event) => event.type === "UPDATE_APPLIED" || event.type === "RECOVERED";
71
- const matchesInsightsEventFilter = (event, filter) => {
72
- if (filter.kind === "all") return true;
73
- if (filter.kind === "installationMovement") return event.install_id === filter.installId && isInsightsMovementEvent(event);
74
- return event.type === filter.type && event.platform === filter.platform && event.channel === filter.channel && (filter.type === "RECOVERED" ? event.from_bundle_id === filter.fromBundleId : event.to_bundle_id === filter.toBundleId);
75
- };
76
- const invalidQuery = () => {
77
- throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-query");
78
- };
79
- const invalidResult = () => {
80
- throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-result");
81
- };
82
- const validateCount = (count) => isTimestamp(count) ? count : invalidResult();
83
- /** Validate custom and bundled providers at the same public boundary. */
84
- const createValidatedInsightsModel = (model) => ({
85
- async record(input) {
86
- if (!require_databasePluginCrudValidationFields.isRecord(input) || !hasOnlyKeys(input, ["event", "installation"])) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-data");
87
- const expected = toInsightsInstallationRow(input.event);
88
- validateRow("bundle_installations", input.installation);
89
- if (Object.entries(expected).some(([field, value]) => Reflect.get(input.installation, field) !== value)) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-data");
90
- await model.record(input);
91
- },
92
- async listEvents(input) {
93
- if (!require_databasePluginCrudValidationFields.isRecord(input) || !hasOnlyKeys(input, [
94
- "filter",
95
- "sinceMs",
96
- "beforeReceivedAtMs",
97
- "after",
98
- "limit"
99
- ]) || !isEventFilter(input.filter) || !isLimit(input.limit) || !isTimestamp(input.beforeReceivedAtMs) || input.sinceMs !== void 0 && !isTimestamp(input.sinceMs)) invalidQuery();
100
- const sinceMs = input.sinceMs ?? 0;
101
- if (sinceMs > input.beforeReceivedAtMs || input.after !== void 0 && (!require_databasePluginCrudValidationFields.isRecord(input.after) || !hasOnlyKeys(input.after, ["receivedAtMs", "id"]) || !isTimestamp(input.after.receivedAtMs) || typeof input.after.id !== "string" || !(0, _hot_updater_core.isUUIDv7)(input.after.id) || input.after.receivedAtMs < sinceMs || input.after.receivedAtMs >= input.beforeReceivedAtMs)) invalidQuery();
102
- const rows = await model.listEvents(input);
103
- if (!Array.isArray(rows) || rows.length > input.limit) invalidResult();
104
- let previous = input.after;
105
- for (const row of rows) {
106
- validateRow("bundle_events", row, true);
107
- if (row.received_at_ms < sinceMs || row.received_at_ms >= input.beforeReceivedAtMs || !matchesInsightsEventFilter(row, input.filter) || previous !== void 0 && (row.received_at_ms > previous.receivedAtMs || row.received_at_ms === previous.receivedAtMs && row.id >= previous.id)) invalidResult();
108
- previous = {
109
- receivedAtMs: row.received_at_ms,
110
- id: row.id
111
- };
112
- }
113
- return rows;
114
- },
115
- async findInstallations(input) {
116
- if (!require_databasePluginCrudValidationFields.isRecord(input)) invalidQuery();
117
- if ("installId" in input) {
118
- if (!hasOnlyKeys(input, ["installId"]) || !isIdentity(input.installId)) invalidQuery();
119
- } else if (!hasOnlyKeys(input, [
120
- "userId",
121
- "afterInstallId",
122
- "limit"
123
- ]) || !isIdentity(input.userId) || !isLimit(input.limit) || input.afterInstallId !== void 0 && !isIdentity(input.afterInstallId)) invalidQuery();
124
- const rows = await model.findInstallations(input);
125
- if (!Array.isArray(rows) || rows.length > ("installId" in input ? 1 : input.limit)) invalidResult();
126
- let previous = "installId" in input ? void 0 : input.afterInstallId;
127
- for (const row of rows) {
128
- validateRow("bundle_installations", row, true);
129
- if ("installId" in input ? row.install_id !== input.installId : row.user_id !== input.userId || previous !== void 0 && compareInsightsText(row.install_id, previous) <= 0) invalidResult();
130
- previous = row.install_id;
131
- }
132
- return rows;
133
- },
134
- async countInstallations(input) {
135
- if (!require_databasePluginCrudValidationFields.isRecord(input) || !hasOnlyKeys(input, [
136
- "platform",
137
- "channel",
138
- "sinceMs",
139
- "bundleId"
140
- ]) || !hasScope(input) || !isTimestamp(input.sinceMs) || input.bundleId !== void 0 && !isText(input.bundleId)) invalidQuery();
141
- return validateCount(await model.countInstallations(input));
142
- },
143
- async countEvents(input) {
144
- if (!require_databasePluginCrudValidationFields.isRecord(input) || !hasOnlyKeys(input, [
145
- "filter",
146
- "sinceMs",
147
- "beforeReceivedAtMs"
148
- ]) || !isBundleFilter(input.filter) || !isTimestamp(input.sinceMs) || !isTimestamp(input.beforeReceivedAtMs) || input.sinceMs > input.beforeReceivedAtMs) invalidQuery();
149
- return validateCount(await model.countEvents(input));
150
- }
151
- });
152
- //#endregion
153
- exports.compareInsightsText = compareInsightsText;
154
- exports.createValidatedInsightsModel = createValidatedInsightsModel;
155
- exports.isInsightsMovementEvent = isInsightsMovementEvent;
156
- exports.matchesInsightsEventFilter = matchesInsightsEventFilter;
157
- exports.toInsightsInstallationRow = toInsightsInstallationRow;
@@ -1,11 +0,0 @@
1
- import { BundleEventRow, InsightsInstallationRow } from "./types/databaseRows.cjs";
2
- import "./types/index.cjs";
3
- //#region src/insightsContract.d.ts
4
- /** Exact UTF-8 byte ordering, without case folding or Unicode normalization. */
5
- declare const compareInsightsText: (left: string, right: string) => number;
6
- /** Prepare the full latest-state candidate; the provider owns winning writes. */
7
- declare const toInsightsInstallationRow: (event: BundleEventRow) => InsightsInstallationRow;
8
- /** Unchanged reports are not bundle movements. */
9
- declare const isInsightsMovementEvent: (event: Pick<BundleEventRow, "type">) => boolean;
10
- //#endregion
11
- export { compareInsightsText, isInsightsMovementEvent, toInsightsInstallationRow };
@@ -1,11 +0,0 @@
1
- import { BundleEventRow, InsightsInstallationRow } from "./types/databaseRows.mjs";
2
- import "./types/index.mjs";
3
- //#region src/insightsContract.d.ts
4
- /** Exact UTF-8 byte ordering, without case folding or Unicode normalization. */
5
- declare const compareInsightsText: (left: string, right: string) => number;
6
- /** Prepare the full latest-state candidate; the provider owns winning writes. */
7
- declare const toInsightsInstallationRow: (event: BundleEventRow) => InsightsInstallationRow;
8
- /** Unchanged reports are not bundle movements. */
9
- declare const isInsightsMovementEvent: (event: Pick<BundleEventRow, "type">) => boolean;
10
- //#endregion
11
- export { compareInsightsText, isInsightsMovementEvent, toInsightsInstallationRow };
@@ -1,153 +0,0 @@
1
- import { DatabasePluginInputError } from "./databasePluginCrudValidationErrors.mjs";
2
- import { isUUIDv7 } from "./uuidv7.mjs";
3
- import { isRecord } from "./databasePluginCrudValidationFields.mjs";
4
- import { validateCreateData } from "./databasePluginCrudValidationRows.mjs";
5
- //#region src/insightsContract.ts
6
- const encoder = new TextEncoder();
7
- /** Exact UTF-8 byte ordering, without case folding or Unicode normalization. */
8
- const compareInsightsText = (left, right) => {
9
- const a = encoder.encode(left);
10
- const b = encoder.encode(right);
11
- for (let index = 0; index < Math.min(a.length, b.length); index += 1) if (a[index] !== b[index]) return a[index] - b[index];
12
- return a.length - b.length;
13
- };
14
- const isWellFormedText = (value) => {
15
- for (const character of value) {
16
- const point = character.codePointAt(0);
17
- if (point >= 55296 && point <= 57343) return false;
18
- }
19
- return true;
20
- };
21
- const isIdentity = (value) => typeof value === "string" && value.length > 0 && value.length <= 255 && isWellFormedText(value);
22
- const isText = (value) => typeof value === "string" && value.length > 0 && isWellFormedText(value);
23
- const isTimestamp = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
24
- const isLimit = (value) => isTimestamp(value) && value >= 1 && value <= 101;
25
- const hasOnlyKeys = (value, keys) => Object.keys(value).every((key) => keys.includes(key));
26
- const hasScope = (value) => (value.platform === "ios" || value.platform === "android") && isText(value.channel);
27
- const isBundleFilter = (value, withKind = false) => {
28
- if (!isRecord(value) || !hasScope(value)) return false;
29
- const keys = [
30
- "platform",
31
- "channel",
32
- "type",
33
- ...withKind ? ["kind"] : []
34
- ];
35
- return value.type === "RECOVERED" ? isText(value.fromBundleId) && hasOnlyKeys(value, [...keys, "fromBundleId"]) : (value.type === "UPDATE_APPLIED" || value.type === "UNCHANGED") && isText(value.toBundleId) && hasOnlyKeys(value, [...keys, "toBundleId"]);
36
- };
37
- const isEventFilter = (value) => {
38
- if (!isRecord(value)) return false;
39
- if (value.kind === "all") return hasOnlyKeys(value, ["kind"]);
40
- if (value.kind === "installationMovement") return isIdentity(value.installId) && hasOnlyKeys(value, ["kind", "installId"]);
41
- return value.kind === "bundle" && isBundleFilter(value, true);
42
- };
43
- const validateRow = (model, row, result = false) => {
44
- try {
45
- validateCreateData(model, row);
46
- if (!isRecord(row) || typeof row.id !== "string" || !isUUIDv7(row.id) || Object.values(row).some((value) => typeof value === "string" && !isWellFormedText(value))) throw new DatabasePluginInputError("invalid-data");
47
- } catch (error) {
48
- if (result) throw new DatabasePluginInputError("invalid-result");
49
- throw error;
50
- }
51
- };
52
- /** Prepare the full latest-state candidate; the provider owns winning writes. */
53
- const toInsightsInstallationRow = (event) => {
54
- validateRow("bundle_events", event);
55
- return {
56
- id: event.id,
57
- install_id: event.install_id,
58
- user_id: event.user_id,
59
- username: event.username,
60
- to_bundle_id: event.to_bundle_id,
61
- type: event.type,
62
- platform: event.platform,
63
- app_version: event.app_version,
64
- channel: event.channel,
65
- cohort: event.cohort,
66
- received_at_ms: event.received_at_ms
67
- };
68
- };
69
- /** Unchanged reports are not bundle movements. */
70
- const isInsightsMovementEvent = (event) => event.type === "UPDATE_APPLIED" || event.type === "RECOVERED";
71
- const matchesInsightsEventFilter = (event, filter) => {
72
- if (filter.kind === "all") return true;
73
- if (filter.kind === "installationMovement") return event.install_id === filter.installId && isInsightsMovementEvent(event);
74
- return event.type === filter.type && event.platform === filter.platform && event.channel === filter.channel && (filter.type === "RECOVERED" ? event.from_bundle_id === filter.fromBundleId : event.to_bundle_id === filter.toBundleId);
75
- };
76
- const invalidQuery = () => {
77
- throw new DatabasePluginInputError("invalid-query");
78
- };
79
- const invalidResult = () => {
80
- throw new DatabasePluginInputError("invalid-result");
81
- };
82
- const validateCount = (count) => isTimestamp(count) ? count : invalidResult();
83
- /** Validate custom and bundled providers at the same public boundary. */
84
- const createValidatedInsightsModel = (model) => ({
85
- async record(input) {
86
- if (!isRecord(input) || !hasOnlyKeys(input, ["event", "installation"])) throw new DatabasePluginInputError("invalid-data");
87
- const expected = toInsightsInstallationRow(input.event);
88
- validateRow("bundle_installations", input.installation);
89
- if (Object.entries(expected).some(([field, value]) => Reflect.get(input.installation, field) !== value)) throw new DatabasePluginInputError("invalid-data");
90
- await model.record(input);
91
- },
92
- async listEvents(input) {
93
- if (!isRecord(input) || !hasOnlyKeys(input, [
94
- "filter",
95
- "sinceMs",
96
- "beforeReceivedAtMs",
97
- "after",
98
- "limit"
99
- ]) || !isEventFilter(input.filter) || !isLimit(input.limit) || !isTimestamp(input.beforeReceivedAtMs) || input.sinceMs !== void 0 && !isTimestamp(input.sinceMs)) invalidQuery();
100
- const sinceMs = input.sinceMs ?? 0;
101
- if (sinceMs > input.beforeReceivedAtMs || input.after !== void 0 && (!isRecord(input.after) || !hasOnlyKeys(input.after, ["receivedAtMs", "id"]) || !isTimestamp(input.after.receivedAtMs) || typeof input.after.id !== "string" || !isUUIDv7(input.after.id) || input.after.receivedAtMs < sinceMs || input.after.receivedAtMs >= input.beforeReceivedAtMs)) invalidQuery();
102
- const rows = await model.listEvents(input);
103
- if (!Array.isArray(rows) || rows.length > input.limit) invalidResult();
104
- let previous = input.after;
105
- for (const row of rows) {
106
- validateRow("bundle_events", row, true);
107
- if (row.received_at_ms < sinceMs || row.received_at_ms >= input.beforeReceivedAtMs || !matchesInsightsEventFilter(row, input.filter) || previous !== void 0 && (row.received_at_ms > previous.receivedAtMs || row.received_at_ms === previous.receivedAtMs && row.id >= previous.id)) invalidResult();
108
- previous = {
109
- receivedAtMs: row.received_at_ms,
110
- id: row.id
111
- };
112
- }
113
- return rows;
114
- },
115
- async findInstallations(input) {
116
- if (!isRecord(input)) invalidQuery();
117
- if ("installId" in input) {
118
- if (!hasOnlyKeys(input, ["installId"]) || !isIdentity(input.installId)) invalidQuery();
119
- } else if (!hasOnlyKeys(input, [
120
- "userId",
121
- "afterInstallId",
122
- "limit"
123
- ]) || !isIdentity(input.userId) || !isLimit(input.limit) || input.afterInstallId !== void 0 && !isIdentity(input.afterInstallId)) invalidQuery();
124
- const rows = await model.findInstallations(input);
125
- if (!Array.isArray(rows) || rows.length > ("installId" in input ? 1 : input.limit)) invalidResult();
126
- let previous = "installId" in input ? void 0 : input.afterInstallId;
127
- for (const row of rows) {
128
- validateRow("bundle_installations", row, true);
129
- if ("installId" in input ? row.install_id !== input.installId : row.user_id !== input.userId || previous !== void 0 && compareInsightsText(row.install_id, previous) <= 0) invalidResult();
130
- previous = row.install_id;
131
- }
132
- return rows;
133
- },
134
- async countInstallations(input) {
135
- if (!isRecord(input) || !hasOnlyKeys(input, [
136
- "platform",
137
- "channel",
138
- "sinceMs",
139
- "bundleId"
140
- ]) || !hasScope(input) || !isTimestamp(input.sinceMs) || input.bundleId !== void 0 && !isText(input.bundleId)) invalidQuery();
141
- return validateCount(await model.countInstallations(input));
142
- },
143
- async countEvents(input) {
144
- if (!isRecord(input) || !hasOnlyKeys(input, [
145
- "filter",
146
- "sinceMs",
147
- "beforeReceivedAtMs"
148
- ]) || !isBundleFilter(input.filter) || !isTimestamp(input.sinceMs) || !isTimestamp(input.beforeReceivedAtMs) || input.sinceMs > input.beforeReceivedAtMs) invalidQuery();
149
- return validateCount(await model.countEvents(input));
150
- }
151
- });
152
- //#endregion
153
- export { compareInsightsText, createValidatedInsightsModel, isInsightsMovementEvent, matchesInsightsEventFilter, toInsightsInstallationRow };
package/dist/internal.cjs DELETED
@@ -1,6 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_databaseFields = require("./types/databaseFields.cjs");
3
- const require_createDatabasePlugin = require("./createDatabasePlugin.cjs");
4
- exports.DatabaseRowReferencedError = require_createDatabasePlugin.DatabaseRowReferencedError;
5
- exports.createDatabasePluginAdapter = require_createDatabasePlugin.createDatabasePluginAdapter;
6
- exports.databaseFields = require_databaseFields.databaseFields;
@@ -1,10 +0,0 @@
1
- import { ApiKeyRow, BundleEventRow, BundleEventRowBase, BundlePatchRow, BundleRow, ChannelRow, DatabaseBundleMetadata, DatabaseField, DatabaseJsonObject, DatabaseJsonValue, DatabaseModel, DatabaseModelMap, DatabaseRow, InsightsInstallationRow, ReleaseCatalogRow, ReleaseRow } from "./types/databaseRows.cjs";
2
- import { ApiKeyModel, BundleModel, BundleModelQuery, BundlePatchModel, BundleRepository, BundleRepositoryChange, BundleRepositoryCommit, ChannelDeleteInput, ChannelDeleteResult, ChannelInsertInput, ChannelInsertResult, ChannelModel, DatabaseChange, DatabaseCommit, DatabaseCommitExpectation, DatabaseCommitResult, DatabaseModels, DatabasePlugin, InsightsBundleEventFilter, InsightsCountEventsInput, InsightsCountInstallationsInput, InsightsEventCursor, InsightsEventFilter, InsightsFindInstallationsInput, InsightsListEventsInput, InsightsModel, InsightsRecordInput, InsightsScope, ReleaseCatalogModel, ReleaseModel } from "./types/databasePlugin.cjs";
3
- import { DatabaseDistinctFields, DatabaseDistinctOn, DatabaseOrderBy, DatabaseSelect, DatabaseSortBy, DatabaseSortClause, DatabaseSortNulls, DatabaseStringComparisonMode, DatabaseWhere, DatabaseWhereConnector, DatabaseWhereOperator, SelectedDatabaseRow } from "./types/databaseQuery.cjs";
4
- import { ApiKeyRowUpdate, BundleRowUpdate, CountBundlesDatabaseImplementationInput, CountBundlesDatabaseInput, CountDatabaseImplementationInput, CountDatabaseInput, CountDatabaseModel, CreateDatabaseImplementationInput, CreateDatabaseInput, CreateDatabaseModel, DatabaseCapability, DatabaseDeleteModel, DatabaseFindOneModel, DatabaseImplementationResult, DatabaseModelCapabilities, DatabaseModelsWithCapability, DatabasePluginCrud, DatabasePluginImplementation, DatabaseRowUpdate, DeleteDatabaseImplementationInput, DeleteDatabaseInput, DeleteDatabaseModel, FindManyDatabaseImplementationInput, FindManyDatabaseInput, FindManyDatabaseModel, FindManyDatabasePluginInput, FindOneDatabaseImplementationInput, FindOneDatabaseInput, FindOneDatabaseModel, InsightsInstallationRowUpdate, ReleaseCatalogRowUpdate, ReleaseRowUpdate, SelectedDatabaseInputRow, TransactionDatabasePluginImplementation, UpdateBundleDatabaseImplementationInput, UpdateBundleDatabaseInput, UpdateDatabaseImplementationInput, UpdateDatabaseInput, UpdateDatabaseModel } from "./types/databaseOperations.cjs";
5
- import { BuiltIns, HasMultipleCallSignatures, Primitive, RequiredDeep } from "./types/utils.cjs";
6
- import { ApplePlatform, BasePluginArgs, BuildPlugin, BuildPluginConfig, Bundle, BundleSigningPlugin, ConfigInput, DatabaseBundleCursor, DatabaseBundleIdFilter, DatabaseBundleQueryOptions, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere, FingerprintExtraSources, IosBuildDestination, LocalSigningConfig, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, Paginated, PaginatedResult, PaginationInfo, Platform, PlatformConfig, SigningConfig, StorageDeleteInput, StorageDeleteResult, StorageExistsInput, StorageExistsResult, StorageGetDownloadUrlInput, StorageGetDownloadUrlResult, StorageGetInput, StorageGetResult, StorageObject, StoragePlugin, StoragePutInput, StoragePutResult, supportedIosPlatforms } from "./types/index.cjs";
7
- import { databaseFields } from "./types/databaseFields.cjs";
8
- import "./types/internal.cjs";
9
- import { DatabasePluginAdapter, DatabaseRowReferencedError, createDatabasePluginAdapter } from "./createDatabasePlugin.cjs";
10
- export { type ApiKeyModel, type ApiKeyRow, type ApiKeyRowUpdate, type ApplePlatform, type BasePluginArgs, type BuildPlugin, type BuildPluginConfig, type BuiltIns, type Bundle, type BundleEventRow, type BundleEventRowBase, type BundleModel, type BundleModelQuery, type BundlePatchModel, type BundlePatchRow, type BundleRepository, type BundleRepositoryChange, type BundleRepositoryCommit, type BundleRow, type BundleRowUpdate, type BundleSigningPlugin, type ChannelDeleteInput, type ChannelDeleteResult, type ChannelInsertInput, type ChannelInsertResult, type ChannelModel, type ChannelRow, type ConfigInput, type CountBundlesDatabaseImplementationInput, type CountBundlesDatabaseInput, type CountDatabaseImplementationInput, type CountDatabaseInput, type CountDatabaseModel, type CreateDatabaseImplementationInput, type CreateDatabaseInput, type CreateDatabaseModel, type DatabaseBundleCursor, type DatabaseBundleIdFilter, type DatabaseBundleMetadata, type DatabaseBundleQueryOptions, type DatabaseBundleQueryOrder, type DatabaseBundleQueryWhere, type DatabaseCapability, type DatabaseChange, type DatabaseCommit, type DatabaseCommitExpectation, type DatabaseCommitResult, type DatabaseDeleteModel, type DatabaseDistinctFields, type DatabaseDistinctOn, type DatabaseField, type DatabaseFindOneModel, type DatabaseImplementationResult, type DatabaseJsonObject, type DatabaseJsonValue, type DatabaseModel, type DatabaseModelCapabilities, type DatabaseModelMap, type DatabaseModels, type DatabaseModelsWithCapability, type DatabaseOrderBy, type DatabasePlugin, type DatabasePluginAdapter, type DatabasePluginCrud, type DatabasePluginImplementation, type DatabaseRow, DatabaseRowReferencedError, type DatabaseRowUpdate, type DatabaseSelect, type DatabaseSortBy, type DatabaseSortClause, type DatabaseSortNulls, type DatabaseStringComparisonMode, type DatabaseWhere, type DatabaseWhereConnector, type DatabaseWhereOperator, type DeleteDatabaseImplementationInput, type DeleteDatabaseInput, type DeleteDatabaseModel, type FindManyDatabaseImplementationInput, type FindManyDatabaseInput, type FindManyDatabaseModel, type FindManyDatabasePluginInput, type FindOneDatabaseImplementationInput, type FindOneDatabaseInput, type FindOneDatabaseModel, type FingerprintExtraSources, type HasMultipleCallSignatures, type InsightsBundleEventFilter, type InsightsCountEventsInput, type InsightsCountInstallationsInput, type InsightsEventCursor, type InsightsEventFilter, type InsightsFindInstallationsInput, type InsightsInstallationRow, type InsightsInstallationRowUpdate, type InsightsListEventsInput, type InsightsModel, type InsightsRecordInput, type InsightsScope, type IosBuildDestination, type LocalSigningConfig, type NativeBuildAndroidScheme, type NativeBuildArgs, type NativeBuildIosScheme, type NativeBuildOptions, type Paginated, type PaginatedResult, type PaginationInfo, type Platform, type PlatformConfig, type Primitive, type ReleaseCatalogModel, type ReleaseCatalogRow, type ReleaseCatalogRowUpdate, type ReleaseModel, type ReleaseRow, type ReleaseRowUpdate, type RequiredDeep, type SelectedDatabaseInputRow, type SelectedDatabaseRow, type SigningConfig, type StorageDeleteInput, type StorageDeleteResult, type StorageExistsInput, type StorageExistsResult, type StorageGetDownloadUrlInput, type StorageGetDownloadUrlResult, type StorageGetInput, type StorageGetResult, type StorageObject, type StoragePlugin, type StoragePutInput, type StoragePutResult, type TransactionDatabasePluginImplementation, type UpdateBundleDatabaseImplementationInput, type UpdateBundleDatabaseInput, type UpdateDatabaseImplementationInput, type UpdateDatabaseInput, type UpdateDatabaseModel, createDatabasePluginAdapter, databaseFields, type supportedIosPlatforms };
@@ -1,10 +0,0 @@
1
- import { ApiKeyRow, BundleEventRow, BundleEventRowBase, BundlePatchRow, BundleRow, ChannelRow, DatabaseBundleMetadata, DatabaseField, DatabaseJsonObject, DatabaseJsonValue, DatabaseModel, DatabaseModelMap, DatabaseRow, InsightsInstallationRow, ReleaseCatalogRow, ReleaseRow } from "./types/databaseRows.mjs";
2
- import { ApiKeyModel, BundleModel, BundleModelQuery, BundlePatchModel, BundleRepository, BundleRepositoryChange, BundleRepositoryCommit, ChannelDeleteInput, ChannelDeleteResult, ChannelInsertInput, ChannelInsertResult, ChannelModel, DatabaseChange, DatabaseCommit, DatabaseCommitExpectation, DatabaseCommitResult, DatabaseModels, DatabasePlugin, InsightsBundleEventFilter, InsightsCountEventsInput, InsightsCountInstallationsInput, InsightsEventCursor, InsightsEventFilter, InsightsFindInstallationsInput, InsightsListEventsInput, InsightsModel, InsightsRecordInput, InsightsScope, ReleaseCatalogModel, ReleaseModel } from "./types/databasePlugin.mjs";
3
- import { DatabaseDistinctFields, DatabaseDistinctOn, DatabaseOrderBy, DatabaseSelect, DatabaseSortBy, DatabaseSortClause, DatabaseSortNulls, DatabaseStringComparisonMode, DatabaseWhere, DatabaseWhereConnector, DatabaseWhereOperator, SelectedDatabaseRow } from "./types/databaseQuery.mjs";
4
- import { ApiKeyRowUpdate, BundleRowUpdate, CountBundlesDatabaseImplementationInput, CountBundlesDatabaseInput, CountDatabaseImplementationInput, CountDatabaseInput, CountDatabaseModel, CreateDatabaseImplementationInput, CreateDatabaseInput, CreateDatabaseModel, DatabaseCapability, DatabaseDeleteModel, DatabaseFindOneModel, DatabaseImplementationResult, DatabaseModelCapabilities, DatabaseModelsWithCapability, DatabasePluginCrud, DatabasePluginImplementation, DatabaseRowUpdate, DeleteDatabaseImplementationInput, DeleteDatabaseInput, DeleteDatabaseModel, FindManyDatabaseImplementationInput, FindManyDatabaseInput, FindManyDatabaseModel, FindManyDatabasePluginInput, FindOneDatabaseImplementationInput, FindOneDatabaseInput, FindOneDatabaseModel, InsightsInstallationRowUpdate, ReleaseCatalogRowUpdate, ReleaseRowUpdate, SelectedDatabaseInputRow, TransactionDatabasePluginImplementation, UpdateBundleDatabaseImplementationInput, UpdateBundleDatabaseInput, UpdateDatabaseImplementationInput, UpdateDatabaseInput, UpdateDatabaseModel } from "./types/databaseOperations.mjs";
5
- import { BuiltIns, HasMultipleCallSignatures, Primitive, RequiredDeep } from "./types/utils.mjs";
6
- import { ApplePlatform, BasePluginArgs, BuildPlugin, BuildPluginConfig, Bundle, BundleSigningPlugin, ConfigInput, DatabaseBundleCursor, DatabaseBundleIdFilter, DatabaseBundleQueryOptions, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere, FingerprintExtraSources, IosBuildDestination, LocalSigningConfig, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, Paginated, PaginatedResult, PaginationInfo, Platform, PlatformConfig, SigningConfig, StorageDeleteInput, StorageDeleteResult, StorageExistsInput, StorageExistsResult, StorageGetDownloadUrlInput, StorageGetDownloadUrlResult, StorageGetInput, StorageGetResult, StorageObject, StoragePlugin, StoragePutInput, StoragePutResult, supportedIosPlatforms } from "./types/index.mjs";
7
- import { databaseFields } from "./types/databaseFields.mjs";
8
- import "./types/internal.mjs";
9
- import { DatabasePluginAdapter, DatabaseRowReferencedError, createDatabasePluginAdapter } from "./createDatabasePlugin.mjs";
10
- export { type ApiKeyModel, type ApiKeyRow, type ApiKeyRowUpdate, type ApplePlatform, type BasePluginArgs, type BuildPlugin, type BuildPluginConfig, type BuiltIns, type Bundle, type BundleEventRow, type BundleEventRowBase, type BundleModel, type BundleModelQuery, type BundlePatchModel, type BundlePatchRow, type BundleRepository, type BundleRepositoryChange, type BundleRepositoryCommit, type BundleRow, type BundleRowUpdate, type BundleSigningPlugin, type ChannelDeleteInput, type ChannelDeleteResult, type ChannelInsertInput, type ChannelInsertResult, type ChannelModel, type ChannelRow, type ConfigInput, type CountBundlesDatabaseImplementationInput, type CountBundlesDatabaseInput, type CountDatabaseImplementationInput, type CountDatabaseInput, type CountDatabaseModel, type CreateDatabaseImplementationInput, type CreateDatabaseInput, type CreateDatabaseModel, type DatabaseBundleCursor, type DatabaseBundleIdFilter, type DatabaseBundleMetadata, type DatabaseBundleQueryOptions, type DatabaseBundleQueryOrder, type DatabaseBundleQueryWhere, type DatabaseCapability, type DatabaseChange, type DatabaseCommit, type DatabaseCommitExpectation, type DatabaseCommitResult, type DatabaseDeleteModel, type DatabaseDistinctFields, type DatabaseDistinctOn, type DatabaseField, type DatabaseFindOneModel, type DatabaseImplementationResult, type DatabaseJsonObject, type DatabaseJsonValue, type DatabaseModel, type DatabaseModelCapabilities, type DatabaseModelMap, type DatabaseModels, type DatabaseModelsWithCapability, type DatabaseOrderBy, type DatabasePlugin, type DatabasePluginAdapter, type DatabasePluginCrud, type DatabasePluginImplementation, type DatabaseRow, DatabaseRowReferencedError, type DatabaseRowUpdate, type DatabaseSelect, type DatabaseSortBy, type DatabaseSortClause, type DatabaseSortNulls, type DatabaseStringComparisonMode, type DatabaseWhere, type DatabaseWhereConnector, type DatabaseWhereOperator, type DeleteDatabaseImplementationInput, type DeleteDatabaseInput, type DeleteDatabaseModel, type FindManyDatabaseImplementationInput, type FindManyDatabaseInput, type FindManyDatabaseModel, type FindManyDatabasePluginInput, type FindOneDatabaseImplementationInput, type FindOneDatabaseInput, type FindOneDatabaseModel, type FingerprintExtraSources, type HasMultipleCallSignatures, type InsightsBundleEventFilter, type InsightsCountEventsInput, type InsightsCountInstallationsInput, type InsightsEventCursor, type InsightsEventFilter, type InsightsFindInstallationsInput, type InsightsInstallationRow, type InsightsInstallationRowUpdate, type InsightsListEventsInput, type InsightsModel, type InsightsRecordInput, type InsightsScope, type IosBuildDestination, type LocalSigningConfig, type NativeBuildAndroidScheme, type NativeBuildArgs, type NativeBuildIosScheme, type NativeBuildOptions, type Paginated, type PaginatedResult, type PaginationInfo, type Platform, type PlatformConfig, type Primitive, type ReleaseCatalogModel, type ReleaseCatalogRow, type ReleaseCatalogRowUpdate, type ReleaseModel, type ReleaseRow, type ReleaseRowUpdate, type RequiredDeep, type SelectedDatabaseInputRow, type SelectedDatabaseRow, type SigningConfig, type StorageDeleteInput, type StorageDeleteResult, type StorageExistsInput, type StorageExistsResult, type StorageGetDownloadUrlInput, type StorageGetDownloadUrlResult, type StorageGetInput, type StorageGetResult, type StorageObject, type StoragePlugin, type StoragePutInput, type StoragePutResult, type TransactionDatabasePluginImplementation, type UpdateBundleDatabaseImplementationInput, type UpdateBundleDatabaseInput, type UpdateDatabaseImplementationInput, type UpdateDatabaseInput, type UpdateDatabaseModel, createDatabasePluginAdapter, databaseFields, type supportedIosPlatforms };
package/dist/internal.mjs DELETED
@@ -1,3 +0,0 @@
1
- import { databaseFields } from "./types/databaseFields.mjs";
2
- import { DatabaseRowReferencedError, createDatabasePluginAdapter } from "./createDatabasePlugin.mjs";
3
- export { DatabaseRowReferencedError, createDatabasePluginAdapter, databaseFields };