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

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
@@ -0,0 +1,398 @@
1
+ import { DatabaseAmbiguousCommitError, DatabaseConflictError, DatabaseConstraintError, DatabaseQueryError, DatabaseTransactionError } from "../../serverPlugin/errors.mjs";
2
+ import { rowKey } from "../../database/adapter.mjs";
3
+ import { canonicalJson, compareTuples, indexEntries } from "../../database/values.mjs";
4
+ import { NegativeGaugeError, compileAggregates, recordAggregate } from "./engineAggregates.mjs";
5
+ //#region src/engine/database/engineTransaction.ts
6
+ /** A row this attempt read changed while it ran; the attempt reruns. */
7
+ var StaleReadError = class extends Error {};
8
+ const idOf = (table, key) => JSON.stringify([table, key]);
9
+ const versionOf = (row) => Number(row["_v"]);
10
+ const isKeyed = (value) => value !== null && value !== void 0;
11
+ const misuse = (table, message) => new DatabaseTransactionError(`${table}: ${message}`);
12
+ const once = (table) => misuse(table, "a transaction writes one key once.");
13
+ const hooks = globalThis.process?.getBuiltinModule?.("node:async_hooks");
14
+ /** Where the runtime tracks async context, `db.*` inside a transaction throws. */
15
+ const transactionScope = hooks && new hooks.AsyncLocalStorage();
16
+ const assertOutsideTransaction = () => {
17
+ if (transactionScope?.getStore() !== void 0) throw new DatabaseTransactionError("Inside transaction(), read and write through its handle; db and core are not part of it.");
18
+ };
19
+ const createTransactions = ({ adapter, schema, reads, retry = {} }) => {
20
+ const { attempts = 8, baseDelayMs = 5, maxDelayMs = 250, onRetry } = retry;
21
+ const { modelOf } = reads;
22
+ /**
23
+ * A key-value index copy has no `_v`. A transaction guards what it reads,
24
+ * so it reads such a row whole, and reruns if it changed since the copy.
25
+ */
26
+ const complete = async ({ table }, rows) => {
27
+ const copies = rows.filter((row) => !("_v" in row));
28
+ if (copies.length === 0) return [...rows];
29
+ const current = await adapter.get(table, copies.map((copy) => rowKey(table, copy)));
30
+ return rows.map((row) => {
31
+ const at = copies.indexOf(row);
32
+ if (at < 0) return row;
33
+ const whole = current[at];
34
+ if (!whole || Object.keys(row).some((column) => canonicalJson(row[column]) !== canonicalJson(whole[column]))) throw new StaleReadError();
35
+ return whole;
36
+ });
37
+ };
38
+ const attempt = async (fn) => {
39
+ const read = /* @__PURE__ */ new Map();
40
+ /** Rows of rooted ranges: their root guards them, so they need no check of their own. */
41
+ const ranged = /* @__PURE__ */ new Map();
42
+ const writes = /* @__PURE__ */ new Map();
43
+ /** Deleted keys, children before their parents. */
44
+ const deleted = [];
45
+ const aggregates = /* @__PURE__ */ new Map();
46
+ let open = true;
47
+ let failure;
48
+ /** A failed call fails the attempt even when `fn` catches it. */
49
+ const step = (method) => (...args) => {
50
+ if (!open) throw new DatabaseTransactionError("The transaction has ended.");
51
+ const fail = (error) => {
52
+ failure ??= { error };
53
+ throw error;
54
+ };
55
+ try {
56
+ const result = method(...args);
57
+ return result instanceof Promise ? result.catch(fail) : result;
58
+ } catch (error) {
59
+ return fail(error);
60
+ }
61
+ };
62
+ const remember = (model, key, row) => {
63
+ const id = idOf(model.table.name, key);
64
+ const known = read.get(id);
65
+ if (known !== void 0 && (known && row ? versionOf(known) !== versionOf(row) : known !== row)) throw new StaleReadError();
66
+ read.set(id, row);
67
+ return row;
68
+ };
69
+ const readRow = ({ table }, row) => {
70
+ const id = idOf(table.name, rowKey(table, row));
71
+ const known = read.get(id) ?? ranged.get(id);
72
+ if (known && versionOf(known) === versionOf(row)) return known;
73
+ throw misuse(table.name, "update and delete take a row this transaction read.");
74
+ };
75
+ const checkFields = ({ table, definition: { fields } }, values, creating) => {
76
+ for (const field of Object.keys(values)) if (!(field in fields) || !creating && table.key.includes(field)) throw misuse(table.name, `${field} cannot be ${creating ? "set" : "changed"}.`);
77
+ for (const [field, { required }] of Object.entries(fields)) if (required !== false && (creating || field in values) && !isKeyed(values[field])) throw misuse(table.name, `${field} is required.`);
78
+ };
79
+ /** Adds counter deltas to a key's pending op; an empty `by` still bumps `_v`. */
80
+ const bump = (model, key, by) => {
81
+ const id = idOf(model.table.name, key);
82
+ const pending = writes.get(id);
83
+ if (pending === void 0) writes.set(id, {
84
+ model,
85
+ key,
86
+ type: "increment",
87
+ row: { ...by }
88
+ });
89
+ else if (pending.type !== "delete") for (const [column, delta] of Object.entries(by)) pending.row[column] = Number(pending.row[column] ?? pending.read?.[column] ?? 0) + delta;
90
+ else if (Object.values(by).some((delta) => delta > 0)) throw new DatabaseConstraintError("not_found", model.table.name);
91
+ };
92
+ /** Moves parent counters when a reference changes and bumps every rooted parent. */
93
+ const touchParents = (model, before, after) => {
94
+ for (const { field, counter, target } of model.references) {
95
+ const [from, to] = [before?.[field], after?.[field]];
96
+ if (counter === void 0 || from === to) continue;
97
+ if (isKeyed(from)) bump(modelOf(target), [from], { [counter]: -1 });
98
+ if (isKeyed(to)) bump(modelOf(target), [to], { [counter]: 1 });
99
+ }
100
+ for (const [index, root] of model.roots) {
101
+ const parent = modelOf(root);
102
+ const { eq } = model.table.indexes.find(({ name }) => name === index);
103
+ for (const row of [before, after]) {
104
+ const key = eq.slice(0, parent.table.key.length).map((field) => row?.[field]);
105
+ if (row && key.every(isKeyed)) bump(parent, key, {});
106
+ }
107
+ }
108
+ };
109
+ const derive = ({ definition }, row) => {
110
+ if (definition.kind === "table") for (const [name, derived] of Object.entries(definition.derived)) row[name] = derived.compute(row);
111
+ return row;
112
+ };
113
+ /** Deletes a row after its cascaded children, or refuses a restricted delete. */
114
+ const remove = async (model, known) => {
115
+ const { table } = model;
116
+ const key = rowKey(table, known);
117
+ const id = idOf(table.name, key);
118
+ const pending = writes.get(id);
119
+ if (pending?.type === "delete") return;
120
+ if (pending && pending.type !== "increment") throw once(table.name);
121
+ writes.set(id, {
122
+ model,
123
+ key,
124
+ type: "delete",
125
+ row: {},
126
+ read: known
127
+ });
128
+ touchParents(model, known, null);
129
+ for (const reference of model.referencedBy) {
130
+ const { counter, field, onDelete, table: name } = reference;
131
+ if (counter === void 0) continue;
132
+ const stored = Number(known[counter] ?? 0);
133
+ const added = Number(pending?.row[counter] ?? 0);
134
+ if (added > 0) throw new DatabaseConstraintError("referenced", table.name);
135
+ if (stored + added <= 0) continue;
136
+ if (onDelete === "restrict") {
137
+ const [current] = await adapter.get(table, [key]);
138
+ if (current && versionOf(current) === versionOf(known)) throw new DatabaseConstraintError("referenced", table.name);
139
+ throw new StaleReadError();
140
+ }
141
+ const child = modelOf(name);
142
+ const index = child.table.indexes.find(({ eq }) => eq.length === 1 && eq[0] === field);
143
+ let cursor;
144
+ let seen = 0;
145
+ do {
146
+ const page = await reads.findMany(name, {
147
+ index: index.name,
148
+ where: { [field]: key[0] },
149
+ limit: Math.min(stored - seen, reads.maxPageSize),
150
+ ...cursor === void 0 ? {} : { cursor }
151
+ });
152
+ for (const row of await complete(child, page.rows)) {
153
+ remember(child, rowKey(child.table, row), row);
154
+ await remove(child, row);
155
+ }
156
+ seen += page.rows.length;
157
+ cursor = page.next;
158
+ } while (cursor !== void 0 && seen < stored);
159
+ }
160
+ deleted.push(id);
161
+ };
162
+ const tx = {
163
+ findOne: step(async (name, lookup) => {
164
+ const model = modelOf(name);
165
+ const { table } = model;
166
+ const found = await reads.findOne(name, lookup);
167
+ if (found === null && !table.key.every((field) => field in lookup)) return null;
168
+ const [row = null] = found ? await complete(model, [found]) : [];
169
+ const key = row ? rowKey(table, row) : table.key.map((field) => lookup[field]);
170
+ return remember(model, key, row);
171
+ }),
172
+ findMany: step(async (name, input) => {
173
+ const model = modelOf(name);
174
+ const root = model.roots.get(input.index);
175
+ if (root === void 0) throw new DatabaseQueryError(`${name}.${input.index} is not rooted; a transaction reads a range only under a guarded parent.`);
176
+ const parent = modelOf(root);
177
+ const { eq } = model.table.indexes.find(({ name: index }) => index === input.index);
178
+ const where = input.where ?? {};
179
+ const lookup = Object.fromEntries(parent.table.key.map((field, at) => [field, where[eq[at]]]));
180
+ remember(parent, Object.values(lookup), await reads.findOne(root, lookup));
181
+ const found = await reads.findMany(name, input);
182
+ const rows = await complete(model, found.rows);
183
+ for (const row of rows) ranged.set(idOf(name, rowKey(model.table, row)), row);
184
+ return {
185
+ ...found,
186
+ rows
187
+ };
188
+ }),
189
+ create: step((name, values) => {
190
+ const model = modelOf(name);
191
+ checkFields(model, values, true);
192
+ const defaults = model.table.columns.flatMap((column) => column.nullable || column.default !== void 0 ? [[column.name, column.default ?? null]] : []);
193
+ const row = derive(model, {
194
+ ...Object.fromEntries(defaults),
195
+ ...values
196
+ });
197
+ const key = rowKey(model.table, row);
198
+ const id = idOf(name, key);
199
+ const pending = writes.get(id);
200
+ if (pending && pending.type !== "increment") throw once(name);
201
+ for (const [column, delta] of Object.entries(pending?.row ?? {})) row[column] = Number(row[column]) + Number(delta);
202
+ writes.set(id, {
203
+ model,
204
+ key,
205
+ type: "insert",
206
+ row
207
+ });
208
+ touchParents(model, null, row);
209
+ }),
210
+ update: step((name, row, set) => {
211
+ const model = modelOf(name);
212
+ const known = readRow(model, row);
213
+ checkFields(model, set, false);
214
+ const key = rowKey(model.table, known);
215
+ const id = idOf(name, key);
216
+ const pending = writes.get(id);
217
+ if (pending?.type === "insert" || pending?.type === "delete") throw once(name);
218
+ const before = pending?.type === "patch" ? {
219
+ ...known,
220
+ ...pending.row
221
+ } : known;
222
+ const next = derive(model, {
223
+ ...before,
224
+ ...set
225
+ });
226
+ const changed = Object.entries(next).filter(([column, value]) => column !== "_v" && JSON.stringify(value) !== JSON.stringify(known[column]));
227
+ const patch = Object.fromEntries(changed);
228
+ writes.set(id, {
229
+ model,
230
+ key,
231
+ type: "patch",
232
+ row: patch,
233
+ read: known
234
+ });
235
+ if (pending?.type === "increment") bump(model, key, pending.row);
236
+ touchParents(model, before, next);
237
+ }),
238
+ delete: step(async (name, row) => {
239
+ const model = modelOf(name);
240
+ await remove(model, readRow(model, row));
241
+ }),
242
+ aggregate: step((name, identity, values, options) => {
243
+ const model = modelOf(name, "aggregate");
244
+ recordAggregate(aggregates, model, identity, values, options?.shardBy);
245
+ })
246
+ };
247
+ try {
248
+ const result = await (transactionScope ? transactionScope.run(tx, () => fn(tx)) : fn(tx));
249
+ if (failure) throw failure.error;
250
+ return {
251
+ result,
252
+ read,
253
+ ops: compile(writes, read, deleted),
254
+ aggregates: [...aggregates.values()]
255
+ };
256
+ } catch (error) {
257
+ throw failure?.error instanceof StaleReadError ? failure.error : error;
258
+ } finally {
259
+ open = false;
260
+ }
261
+ };
262
+ /** Inserts first, then patches and increments, then checks, then deletes, children before parents. */
263
+ const compile = (writes, read, deleted) => {
264
+ const toOp = (id) => {
265
+ const { model, key, type, row, read: previous } = writes.get(id);
266
+ const { table } = model;
267
+ if (type === "insert") return {
268
+ type,
269
+ table,
270
+ row
271
+ };
272
+ if (type === "increment") {
273
+ const known = read.get(id);
274
+ const by = row;
275
+ return known ? {
276
+ type,
277
+ table,
278
+ key,
279
+ by,
280
+ guard: { v: versionOf(known) }
281
+ } : {
282
+ type,
283
+ table,
284
+ key,
285
+ by
286
+ };
287
+ }
288
+ const guard = { v: versionOf(previous) };
289
+ return type === "patch" ? {
290
+ type,
291
+ table,
292
+ key,
293
+ set: row,
294
+ guard,
295
+ previous
296
+ } : {
297
+ type,
298
+ table,
299
+ key,
300
+ guard,
301
+ previous
302
+ };
303
+ };
304
+ const checks = [...read].flatMap(([id, row]) => {
305
+ if (row === null || writes.has(id)) return [];
306
+ const { table } = schema.models.get(JSON.parse(id)[0]);
307
+ const guard = { v: versionOf(row) };
308
+ return [{
309
+ type: "check",
310
+ table,
311
+ key: rowKey(table, row),
312
+ guard
313
+ }];
314
+ });
315
+ const ofType = (...types) => [...writes.keys()].filter((id) => types.includes(writes.get(id).type));
316
+ return [
317
+ ...[...ofType("insert"), ...ofType("patch", "increment")].map(toOp),
318
+ ...checks,
319
+ ...deleted.map(toOp)
320
+ ];
321
+ };
322
+ /** Only a constraint the current state confirms is reported; anything else reruns. */
323
+ const classify = async (op, read) => {
324
+ if (op.type === "check" || op.type === "delete") return void 0;
325
+ if (op.type === "increment" && op.guard) return void 0;
326
+ const { table } = op;
327
+ const key = op.type === "insert" ? rowKey(table, op.row) : op.key;
328
+ const [current] = await adapter.get(table, [key]);
329
+ if (op.type === "increment") return current ? void 0 : "not_found";
330
+ if (op.type === "insert" && current) {
331
+ const known = read.get(idOf(table.name, key));
332
+ return known === null || known !== void 0 && versionOf(known) !== versionOf(current) ? void 0 : "exists";
333
+ }
334
+ if (op.type === "patch" && current?.["_v"] !== op.guard.v) return;
335
+ const row = op.type === "insert" ? op.row : {
336
+ ...current,
337
+ ...op.set
338
+ };
339
+ for (const index of table.indexes) {
340
+ if (!index.unique) continue;
341
+ for (const eq of indexEntries(table, index, row)) if ((await adapter.query(table, {
342
+ index: index.name,
343
+ eq,
344
+ order: "asc",
345
+ limit: 2
346
+ })).some((other) => compareTuples(rowKey(table, other), key))) return "unique";
347
+ }
348
+ };
349
+ return { async transaction(fn) {
350
+ assertOutsideTransaction();
351
+ let run;
352
+ let negative;
353
+ for (let round = 0; round < attempts; round += 1) {
354
+ const delay = round && Math.min(maxDelayMs, baseDelayMs * 2 ** (round - 1));
355
+ if (delay > 0) await new Promise((resolve) => setTimeout(resolve, delay / 2 + Math.random() * (delay / 2)));
356
+ run ??= await attempt(fn).catch((error) => {
357
+ if (error instanceof StaleReadError) return void 0;
358
+ throw error;
359
+ });
360
+ if (run === void 0) {
361
+ onRetry?.("rerun", round + 1);
362
+ continue;
363
+ }
364
+ let aggregates;
365
+ try {
366
+ aggregates = await compileAggregates(adapter, run.aggregates);
367
+ } catch (error) {
368
+ if (!(error instanceof NegativeGaugeError)) throw error;
369
+ negative = error;
370
+ onRetry?.("rerun", round + 1);
371
+ run = void 0;
372
+ continue;
373
+ }
374
+ const ops = [...run.ops, ...aggregates];
375
+ if (ops.length <= 1 && ops.every(({ type }) => type === "check")) return run.result;
376
+ if (!adapter.fits(ops)) throw new DatabaseConstraintError("too_large", ops[0].table.name);
377
+ let outcome;
378
+ try {
379
+ outcome = await adapter.write(ops);
380
+ } catch (cause) {
381
+ throw new DatabaseAmbiguousCommitError("The commit outcome is unknown.", { cause });
382
+ }
383
+ if (outcome.ok) return run.result;
384
+ const failed = "failedOp" in outcome ? outcome.failedOp : void 0;
385
+ if (failed === void 0 || failed >= run.ops.length) {
386
+ onRetry?.("resend", round + 1);
387
+ continue;
388
+ }
389
+ const reason = await classify(ops[failed], run.read);
390
+ if (reason) throw new DatabaseConstraintError(reason, ops[failed].table.name);
391
+ onRetry?.("rerun", round + 1);
392
+ run = void 0;
393
+ }
394
+ throw negative ?? new DatabaseConflictError(`The transaction conflicted ${attempts} times.`);
395
+ } };
396
+ };
397
+ //#endregion
398
+ export { assertOutsideTransaction, createTransactions };
@@ -0,0 +1,156 @@
1
+ //#region src/engine/database/fence.ts
2
+ /**
3
+ * The settings rows migrations write, last, and the fence reads; retention
4
+ * passes keep their lease here too. Tooling that creates the tables creates
5
+ * this one with them: an ORM's schema generator, a provider's setup, and an
6
+ * access policy that names the tables a server reads.
7
+ */
8
+ const SETTINGS_TABLE = {
9
+ name: "private_hot_updater_settings",
10
+ columns: [
11
+ {
12
+ name: "key",
13
+ type: "string",
14
+ nullable: false,
15
+ maxLength: 255
16
+ },
17
+ {
18
+ name: "value",
19
+ type: "string",
20
+ nullable: false,
21
+ maxLength: 255
22
+ },
23
+ {
24
+ name: "_v",
25
+ type: "integer",
26
+ nullable: false,
27
+ default: 0
28
+ }
29
+ ],
30
+ key: ["key"],
31
+ indexes: []
32
+ };
33
+ /** The engine's storage-layout generation; it changes only with a migration. */
34
+ const ENGINE_SCHEMA_KEY = "schema.engine";
35
+ const CORE_SCHEMA_KEY = "schema.core";
36
+ const stored = ({ key, expected, found }) => `"${key}" is ${found === null ? "missing" : `"${found}"`}; expected "${expected}"`;
37
+ const settingMessage = (adapterName, { key, expected, found }) => `Hot Updater schema setting "${key}" for ${adapterName} is ${found === null ? "missing" : `"${found}"`}; expected "${expected}". ${key === "schema.engine" ? "Create a new empty database and run `hot-updater db migrate`; databases from before the storage engine are not converted." : "Run `hot-updater db migrate`."}`;
38
+ /** The plugin a `schema.<id>` setting belongs to; undefined for core's and the engine's. */
39
+ const pluginOf = ({ key }) => key.startsWith("schema.") && key !== "schema.engine" && key !== CORE_SCHEMA_KEY ? key.slice(7) : void 0;
40
+ const listed = (items) => items.length < 2 ? items.join("") : `${items.slice(0, -1).join(", ")} and ${items.at(-1)}`;
41
+ /** How to create plugins' tables when the fence was given no fix. */
42
+ const PLUGIN_TABLES_FIX = "Run `hot-updater db migrate`. A managed server runs only its provider's plugins, and rerunning `hot-updater init --provider <provider>` applies the provider's migrations. Run `hot-updater db` commands in the server's project: they load the server file named on the command line, or src/hotUpdater.* or src/db.*, and don't read hot-updater.config.ts.";
43
+ const pluginsMessage = (adapterName, plugins, settings, fix) => `The tables of ${plugins.length === 1 ? "plugin" : "plugins"} ${listed(plugins.map((id) => `"${id}"`))} are not migrated on ${adapterName}: schema ${settings.length === 1 ? "setting" : "settings"} ${settings.map(stored).join(", and ")}. ${fix}`;
44
+ /** The database needs `hot-updater db migrate`, or a new database; the handler answers 503. */
45
+ var HotUpdaterSchemaMigrationRequiredError = class extends Error {
46
+ adapterName;
47
+ currentVersion;
48
+ setting;
49
+ /** Every setting the fence found missing or different; `setting` is the first. */
50
+ settings;
51
+ /**
52
+ * The ids of the plugins whose `schema.<id>` setting is among them: the
53
+ * plugins whose tables a migration has yet to create or change.
54
+ */
55
+ plugins;
56
+ constructor(adapterName, currentVersion, setting, options) {
57
+ const settings = options?.settings ?? (setting === void 0 ? [] : [setting]);
58
+ const plugins = settings.flatMap((mismatch) => pluginOf(mismatch) ?? []);
59
+ super(setting === void 0 ? currentVersion === void 0 ? `Hot Updater database schema is not initialized for ${adapterName}. Run \`hot-updater db migrate\` before using this adapter.` : `Hot Updater v1 cannot migrate schema ${currentVersion} in place. Create a new empty database and run \`hot-updater db migrate\`.` : plugins.length > 0 && plugins.length === settings.length ? pluginsMessage(adapterName, plugins, settings, options?.fix ?? PLUGIN_TABLES_FIX) : settingMessage(adapterName, setting), options?.cause === void 0 ? void 0 : { cause: options.cause });
60
+ this.adapterName = adapterName;
61
+ this.currentVersion = currentVersion;
62
+ this.setting = setting;
63
+ this.name = "HotUpdaterSchemaMigrationRequiredError";
64
+ this.settings = settings;
65
+ this.plugins = plugins;
66
+ }
67
+ };
68
+ /** Driver codes for a table or column the database lacks. */
69
+ const MISSING_SCHEMA_CODES = /* @__PURE__ */ new Set([
70
+ "42P01",
71
+ "42703",
72
+ "ER_NO_SUCH_TABLE",
73
+ "ER_BAD_FIELD_ERROR"
74
+ ]);
75
+ const MISSING_SCHEMA_MESSAGE = /no such (?:table|column)|(?:relation|column) .+ does not exist|table .+ doesn't exist|unknown column/iu;
76
+ /**
77
+ * Whether a read failed because a table or column is missing, so the
78
+ * database needs migrations. ORMs may wrap the driver's error in `cause`.
79
+ */
80
+ const isMissingSchemaError = (error) => {
81
+ for (let depth = 0; error instanceof Object && depth < 8; depth += 1) {
82
+ const { code, message, cause } = error;
83
+ if (MISSING_SCHEMA_CODES.has(String(code)) || typeof message === "string" && MISSING_SCHEMA_MESSAGE.test(message)) return true;
84
+ error = cause;
85
+ }
86
+ return false;
87
+ };
88
+ const readSettings = (adapter, keys) => adapter.get(SETTINGS_TABLE, keys.map((key) => [key]));
89
+ /**
90
+ * Throws unless every expected setting is stored with its value: one batch
91
+ * read. The error lists every setting missing or different; `fix` says how
92
+ * to create the plugins' tables on this database.
93
+ */
94
+ const checkSchemaFence = async (adapter, adapterName, expected, fix) => {
95
+ const keys = Object.keys(expected);
96
+ let rows;
97
+ try {
98
+ rows = await readSettings(adapter, keys);
99
+ } catch (cause) {
100
+ if (!isMissingSchemaError(cause)) throw cause;
101
+ throw new HotUpdaterSchemaMigrationRequiredError(adapterName, void 0, {
102
+ key: ENGINE_SCHEMA_KEY,
103
+ expected: "1",
104
+ found: null
105
+ }, { cause });
106
+ }
107
+ const settings = keys.flatMap((key, position) => {
108
+ const found = rows[position]?.value;
109
+ return found === expected[key] ? [] : [{
110
+ key,
111
+ expected: expected[key],
112
+ found: typeof found === "string" ? found : null
113
+ }];
114
+ });
115
+ const [first] = settings;
116
+ if (first !== void 0) throw new HotUpdaterSchemaMigrationRequiredError(adapterName, void 0, first, {
117
+ settings,
118
+ ...fix === void 0 ? {} : { fix }
119
+ });
120
+ };
121
+ /** The database name a fenced adapter carries, so a server can fence its plugins' rows too. */
122
+ const FENCED = Symbol.for("@hot-updater/server/schema-fence");
123
+ /** The database name an adapter behind the schema fence reports under. */
124
+ const fencedName = (adapter) => adapter[FENCED];
125
+ /**
126
+ * The adapter behind the schema fence: a process's first read or write
127
+ * checks the settings first. Success is kept; a failure is checked again on
128
+ * the next call.
129
+ */
130
+ const withSchemaFence = (adapter, adapterName, expected, fix) => {
131
+ let ready;
132
+ const fence = () => {
133
+ ready ??= checkSchemaFence(adapter, adapterName, expected, fix).catch((error) => {
134
+ ready = void 0;
135
+ throw error;
136
+ });
137
+ return ready;
138
+ };
139
+ return {
140
+ ...adapter,
141
+ [FENCED]: adapterName,
142
+ get: (table, keys) => fence().then(() => adapter.get(table, keys)),
143
+ query: (table, request) => fence().then(() => adapter.query(table, request)),
144
+ write: (ops) => fence().then(() => adapter.write(ops)),
145
+ ...adapter.prune && { prune: (table, before, limit) => fence().then(() => adapter.prune(table, before, limit)) }
146
+ };
147
+ };
148
+ //#endregion
149
+ exports.ENGINE_SCHEMA_KEY = ENGINE_SCHEMA_KEY;
150
+ exports.HotUpdaterSchemaMigrationRequiredError = HotUpdaterSchemaMigrationRequiredError;
151
+ exports.SETTINGS_TABLE = SETTINGS_TABLE;
152
+ exports.checkSchemaFence = checkSchemaFence;
153
+ exports.fencedName = fencedName;
154
+ exports.isMissingSchemaError = isMissingSchemaError;
155
+ exports.readSettings = readSettings;
156
+ exports.withSchemaFence = withSchemaFence;
@@ -0,0 +1,41 @@
1
+ import { PhysicalTable } from "../../database/adapter.cjs";
2
+ //#region src/engine/database/fence.d.ts
3
+ /**
4
+ * The settings rows migrations write, last, and the fence reads; retention
5
+ * passes keep their lease here too. Tooling that creates the tables creates
6
+ * this one with them: an ORM's schema generator, a provider's setup, and an
7
+ * access policy that names the tables a server reads.
8
+ */
9
+ declare const SETTINGS_TABLE: PhysicalTable;
10
+ /** A schema setting the fence found missing or different. */
11
+ interface SchemaSettingMismatch {
12
+ readonly key: string;
13
+ readonly expected: string;
14
+ readonly found: string | null;
15
+ }
16
+ /** The database needs `hot-updater db migrate`, or a new database; the handler answers 503. */
17
+ declare class HotUpdaterSchemaMigrationRequiredError extends Error {
18
+ readonly adapterName: string;
19
+ readonly currentVersion: string | undefined;
20
+ readonly setting?: SchemaSettingMismatch | undefined;
21
+ /** Every setting the fence found missing or different; `setting` is the first. */
22
+ readonly settings: readonly SchemaSettingMismatch[];
23
+ /**
24
+ * The ids of the plugins whose `schema.<id>` setting is among them: the
25
+ * plugins whose tables a migration has yet to create or change.
26
+ */
27
+ readonly plugins: readonly string[];
28
+ constructor(adapterName: string, currentVersion: string | undefined, setting?: SchemaSettingMismatch | undefined, options?: ErrorOptions & {
29
+ /** Every mismatch, when the fence found more than `setting`. */
30
+ readonly settings?: readonly SchemaSettingMismatch[];
31
+ /** How to create the plugins' tables on this database. */
32
+ readonly fix?: string;
33
+ });
34
+ }
35
+ /**
36
+ * Settings keys and the values a process expects, `schema.engine` included:
37
+ * a `ToolingTarget`'s settings.
38
+ */
39
+ type SchemaSettings = Readonly<Record<string, string>>;
40
+ //#endregion
41
+ export { HotUpdaterSchemaMigrationRequiredError, SETTINGS_TABLE, SchemaSettingMismatch, SchemaSettings };
@@ -0,0 +1,41 @@
1
+ import { PhysicalTable } from "../../database/adapter.mjs";
2
+ //#region src/engine/database/fence.d.ts
3
+ /**
4
+ * The settings rows migrations write, last, and the fence reads; retention
5
+ * passes keep their lease here too. Tooling that creates the tables creates
6
+ * this one with them: an ORM's schema generator, a provider's setup, and an
7
+ * access policy that names the tables a server reads.
8
+ */
9
+ declare const SETTINGS_TABLE: PhysicalTable;
10
+ /** A schema setting the fence found missing or different. */
11
+ interface SchemaSettingMismatch {
12
+ readonly key: string;
13
+ readonly expected: string;
14
+ readonly found: string | null;
15
+ }
16
+ /** The database needs `hot-updater db migrate`, or a new database; the handler answers 503. */
17
+ declare class HotUpdaterSchemaMigrationRequiredError extends Error {
18
+ readonly adapterName: string;
19
+ readonly currentVersion: string | undefined;
20
+ readonly setting?: SchemaSettingMismatch | undefined;
21
+ /** Every setting the fence found missing or different; `setting` is the first. */
22
+ readonly settings: readonly SchemaSettingMismatch[];
23
+ /**
24
+ * The ids of the plugins whose `schema.<id>` setting is among them: the
25
+ * plugins whose tables a migration has yet to create or change.
26
+ */
27
+ readonly plugins: readonly string[];
28
+ constructor(adapterName: string, currentVersion: string | undefined, setting?: SchemaSettingMismatch | undefined, options?: ErrorOptions & {
29
+ /** Every mismatch, when the fence found more than `setting`. */
30
+ readonly settings?: readonly SchemaSettingMismatch[];
31
+ /** How to create the plugins' tables on this database. */
32
+ readonly fix?: string;
33
+ });
34
+ }
35
+ /**
36
+ * Settings keys and the values a process expects, `schema.engine` included:
37
+ * a `ToolingTarget`'s settings.
38
+ */
39
+ type SchemaSettings = Readonly<Record<string, string>>;
40
+ //#endregion
41
+ export { HotUpdaterSchemaMigrationRequiredError, SETTINGS_TABLE, SchemaSettingMismatch, SchemaSettings };