@toa.io/core 1.0.0-alpha.32 → 1.0.0-alpha.321

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 (286) hide show
  1. package/package.json +28 -12
  2. package/transpiled/abandon.d.ts +9 -0
  3. package/transpiled/abandon.js +37 -0
  4. package/transpiled/abandon.js.map +1 -0
  5. package/transpiled/assignment.d.ts +6 -0
  6. package/transpiled/assignment.js +25 -0
  7. package/transpiled/assignment.js.map +1 -0
  8. package/transpiled/call.d.ts +10 -0
  9. package/transpiled/call.js +187 -0
  10. package/transpiled/call.js.map +1 -0
  11. package/transpiled/cascade.d.ts +7 -0
  12. package/transpiled/cascade.js +28 -0
  13. package/transpiled/cascade.js.map +1 -0
  14. package/transpiled/component.d.ts +17 -0
  15. package/transpiled/component.js +151 -0
  16. package/transpiled/component.js.map +1 -0
  17. package/transpiled/composition.d.ts +6 -0
  18. package/transpiled/composition.js +20 -0
  19. package/transpiled/composition.js.map +1 -0
  20. package/transpiled/connector.d.ts +71 -0
  21. package/transpiled/connector.js +248 -0
  22. package/transpiled/connector.js.map +1 -0
  23. package/transpiled/context.d.ts +25 -0
  24. package/transpiled/context.js +55 -0
  25. package/transpiled/context.js.map +1 -0
  26. package/transpiled/contract/component.d.ts +37 -0
  27. package/transpiled/contract/component.js +94 -0
  28. package/transpiled/contract/component.js.map +1 -0
  29. package/transpiled/contract/contract.d.ts +10 -0
  30. package/transpiled/contract/contract.js +14 -0
  31. package/transpiled/contract/contract.js.map +1 -0
  32. package/transpiled/contract/index.d.ts +4 -0
  33. package/transpiled/contract/index.js +5 -0
  34. package/transpiled/contract/index.js.map +1 -0
  35. package/transpiled/contract/reply.d.ts +7 -0
  36. package/transpiled/contract/reply.js +48 -0
  37. package/transpiled/contract/reply.js.map +1 -0
  38. package/transpiled/contract/request.d.ts +49 -0
  39. package/transpiled/contract/request.js +152 -0
  40. package/transpiled/contract/request.js.map +1 -0
  41. package/transpiled/contract/schemas.d.ts +4 -0
  42. package/transpiled/contract/schemas.js +38 -0
  43. package/transpiled/contract/schemas.js.map +1 -0
  44. package/transpiled/contract/system.d.ts +33 -0
  45. package/transpiled/contract/system.js +76 -0
  46. package/transpiled/contract/system.js.map +1 -0
  47. package/transpiled/deliveries.d.ts +22 -0
  48. package/transpiled/deliveries.js +31 -0
  49. package/transpiled/deliveries.js.map +1 -0
  50. package/transpiled/effect.d.ts +7 -0
  51. package/transpiled/effect.js +13 -0
  52. package/transpiled/effect.js.map +1 -0
  53. package/transpiled/emission.d.ts +10 -0
  54. package/transpiled/emission.js +16 -0
  55. package/transpiled/emission.js.map +1 -0
  56. package/transpiled/encoded.d.ts +16 -0
  57. package/transpiled/encoded.js +25 -0
  58. package/transpiled/encoded.js.map +1 -0
  59. package/transpiled/entities/changeset.d.ts +10 -0
  60. package/transpiled/entities/changeset.js +27 -0
  61. package/transpiled/entities/changeset.js.map +1 -0
  62. package/transpiled/entities/entity.d.ts +19 -0
  63. package/transpiled/entities/entity.js +137 -0
  64. package/transpiled/entities/entity.js.map +1 -0
  65. package/transpiled/entities/factory.d.ts +27 -0
  66. package/transpiled/entities/factory.js +38 -0
  67. package/transpiled/entities/factory.js.map +1 -0
  68. package/transpiled/entities/index.d.ts +5 -0
  69. package/transpiled/entities/index.js +6 -0
  70. package/transpiled/entities/index.js.map +1 -0
  71. package/transpiled/entities/newid.d.ts +11 -0
  72. package/transpiled/entities/newid.js +41 -0
  73. package/transpiled/entities/newid.js.map +1 -0
  74. package/transpiled/entities/set.d.ts +10 -0
  75. package/transpiled/entities/set.js +19 -0
  76. package/transpiled/entities/set.js.map +1 -0
  77. package/transpiled/event.d.ts +20 -0
  78. package/transpiled/event.js +65 -0
  79. package/transpiled/event.js.map +1 -0
  80. package/transpiled/exceptions.d.ts +110 -0
  81. package/transpiled/exceptions.js +215 -0
  82. package/transpiled/exceptions.js.map +1 -0
  83. package/transpiled/gate.d.ts +40 -0
  84. package/transpiled/gate.js +84 -0
  85. package/transpiled/gate.js.map +1 -0
  86. package/transpiled/guard.d.ts +7 -0
  87. package/transpiled/guard.js +12 -0
  88. package/transpiled/guard.js.map +1 -0
  89. package/transpiled/halting.d.ts +16 -0
  90. package/transpiled/halting.js +25 -0
  91. package/transpiled/halting.js.map +1 -0
  92. package/transpiled/index.d.ts +45 -0
  93. package/transpiled/index.js +37 -0
  94. package/transpiled/index.js.map +1 -0
  95. package/transpiled/instance.d.ts +10 -0
  96. package/transpiled/instance.js +30 -0
  97. package/transpiled/instance.js.map +1 -0
  98. package/transpiled/locator.d.ts +12 -0
  99. package/transpiled/locator.js +32 -0
  100. package/transpiled/locator.js.map +1 -0
  101. package/transpiled/measurements.d.ts +20 -0
  102. package/transpiled/measurements.js +40 -0
  103. package/transpiled/measurements.js.map +1 -0
  104. package/transpiled/observation.d.ts +7 -0
  105. package/transpiled/observation.js +14 -0
  106. package/transpiled/observation.js.map +1 -0
  107. package/transpiled/operation.d.ts +77 -0
  108. package/transpiled/operation.js +216 -0
  109. package/transpiled/operation.js.map +1 -0
  110. package/transpiled/outbox.d.ts +45 -0
  111. package/transpiled/outbox.js +448 -0
  112. package/transpiled/outbox.js.map +1 -0
  113. package/transpiled/outbox.measurements.d.ts +4 -0
  114. package/transpiled/outbox.measurements.js +38 -0
  115. package/transpiled/outbox.measurements.js.map +1 -0
  116. package/transpiled/parts.d.ts +20 -0
  117. package/transpiled/parts.js +23 -0
  118. package/transpiled/parts.js.map +1 -0
  119. package/transpiled/query/criteria.d.ts +6 -0
  120. package/transpiled/query/criteria.js +177 -0
  121. package/transpiled/query/criteria.js.map +1 -0
  122. package/transpiled/query/options.d.ts +3 -0
  123. package/transpiled/query/options.js +34 -0
  124. package/transpiled/query/options.js.map +1 -0
  125. package/transpiled/query.d.ts +9 -0
  126. package/transpiled/query.js +57 -0
  127. package/transpiled/query.js.map +1 -0
  128. package/transpiled/receiver.d.ts +20 -0
  129. package/transpiled/receiver.js +113 -0
  130. package/transpiled/receiver.js.map +1 -0
  131. package/transpiled/reflection.d.ts +9 -0
  132. package/transpiled/reflection.js +13 -0
  133. package/transpiled/reflection.js.map +1 -0
  134. package/transpiled/regional.d.ts +22 -0
  135. package/transpiled/regional.js +55 -0
  136. package/transpiled/regional.js.map +1 -0
  137. package/transpiled/remote.d.ts +10 -0
  138. package/transpiled/remote.js +11 -0
  139. package/transpiled/remote.js.map +1 -0
  140. package/transpiled/rendering.d.ts +13 -0
  141. package/transpiled/rendering.js +21 -0
  142. package/transpiled/rendering.js.map +1 -0
  143. package/transpiled/safety.d.ts +5 -0
  144. package/transpiled/safety.js +26 -0
  145. package/transpiled/safety.js.map +1 -0
  146. package/transpiled/state.d.ts +36 -0
  147. package/transpiled/state.js +131 -0
  148. package/transpiled/state.js.map +1 -0
  149. package/transpiled/trail.d.ts +78 -0
  150. package/transpiled/trail.js +112 -0
  151. package/transpiled/trail.js.map +1 -0
  152. package/transpiled/transition.d.ts +14 -0
  153. package/transpiled/transition.js +51 -0
  154. package/transpiled/transition.js.map +1 -0
  155. package/transpiled/transmission.d.ts +8 -0
  156. package/transpiled/transmission.js +30 -0
  157. package/transpiled/transmission.js.map +1 -0
  158. package/transpiled/types/atomicity.d.ts +58 -0
  159. package/transpiled/types/atomicity.js +2 -0
  160. package/transpiled/types/atomicity.js.map +1 -0
  161. package/transpiled/types/bindings.d.ts +82 -0
  162. package/transpiled/types/bindings.js +2 -0
  163. package/transpiled/types/bindings.js.map +1 -0
  164. package/transpiled/types/bridges.d.ts +41 -0
  165. package/transpiled/types/bridges.js +2 -0
  166. package/transpiled/types/bridges.js.map +1 -0
  167. package/transpiled/types/extensions.d.ts +121 -0
  168. package/transpiled/types/extensions.js +2 -0
  169. package/transpiled/types/extensions.js.map +1 -0
  170. package/transpiled/types/inbox.d.ts +27 -0
  171. package/transpiled/types/inbox.js +2 -0
  172. package/transpiled/types/inbox.js.map +1 -0
  173. package/transpiled/types/index.d.ts +14 -0
  174. package/transpiled/types/index.js +9 -0
  175. package/transpiled/types/index.js.map +1 -0
  176. package/transpiled/types/message.d.ts +16 -0
  177. package/transpiled/types/message.js +2 -0
  178. package/transpiled/types/message.js.map +1 -0
  179. package/transpiled/types/operations.d.ts +15 -0
  180. package/transpiled/types/operations.js +2 -0
  181. package/transpiled/types/operations.js.map +1 -0
  182. package/transpiled/types/outbox.d.ts +93 -0
  183. package/transpiled/types/outbox.js +2 -0
  184. package/transpiled/types/outbox.js.map +1 -0
  185. package/transpiled/types/receiver.d.ts +9 -0
  186. package/transpiled/types/receiver.js +2 -0
  187. package/transpiled/types/receiver.js.map +1 -0
  188. package/transpiled/types/request.d.ts +119 -0
  189. package/transpiled/types/request.js +2 -0
  190. package/transpiled/types/request.js.map +1 -0
  191. package/transpiled/types/state.d.ts +9 -0
  192. package/transpiled/types/state.js +2 -0
  193. package/transpiled/types/state.js.map +1 -0
  194. package/transpiled/types/storages.d.ts +158 -0
  195. package/transpiled/types/storages.js +2 -0
  196. package/transpiled/types/storages.js.map +1 -0
  197. package/transpiled/unmanaged.d.ts +5 -0
  198. package/transpiled/unmanaged.js +7 -0
  199. package/transpiled/unmanaged.js.map +1 -0
  200. package/src/assignment.js +0 -31
  201. package/src/call.js +0 -42
  202. package/src/cascade.js +0 -35
  203. package/src/component.js +0 -41
  204. package/src/composition.js +0 -25
  205. package/src/connector.js +0 -183
  206. package/src/context.js +0 -55
  207. package/src/contract/conditions.js +0 -21
  208. package/src/contract/index.js +0 -7
  209. package/src/contract/reply.js +0 -25
  210. package/src/contract/request.js +0 -67
  211. package/src/contract/schemas/error.yaml +0 -9
  212. package/src/contract/schemas/index.js +0 -7
  213. package/src/contract/schemas/query.yaml +0 -30
  214. package/src/discovery.js +0 -44
  215. package/src/emission.js +0 -23
  216. package/src/entities/changeset.js +0 -38
  217. package/src/entities/entity.js +0 -74
  218. package/src/entities/factory.js +0 -33
  219. package/src/entities/index.js +0 -5
  220. package/src/entities/set.js +0 -15
  221. package/src/event.js +0 -40
  222. package/src/exceptions.js +0 -100
  223. package/src/exposition.js +0 -27
  224. package/src/index.js +0 -47
  225. package/src/locator.js +0 -54
  226. package/src/observation.js +0 -20
  227. package/src/operation.js +0 -69
  228. package/src/query/criteria.js +0 -41
  229. package/src/query/options.js +0 -40
  230. package/src/query.js +0 -41
  231. package/src/receiver.js +0 -61
  232. package/src/reflection.js +0 -28
  233. package/src/remote.js +0 -17
  234. package/src/state.js +0 -99
  235. package/src/transition.js +0 -67
  236. package/src/transmission.js +0 -33
  237. package/test/call.fixtures.js +0 -27
  238. package/test/call.test.js +0 -46
  239. package/test/component.fixtures.js +0 -21
  240. package/test/component.test.js +0 -40
  241. package/test/connector.fixtures.js +0 -40
  242. package/test/connector.test.js +0 -176
  243. package/test/context.fixtures.js +0 -18
  244. package/test/context.test.js +0 -29
  245. package/test/contract/conditions.test.js +0 -26
  246. package/test/contract/contract.fixtures.js +0 -33
  247. package/test/contract/request.test.js +0 -112
  248. package/test/emission.fixtures.js +0 -17
  249. package/test/emission.test.js +0 -35
  250. package/test/entities/entity.fixtures.js +0 -29
  251. package/test/entities/entity.test.js +0 -65
  252. package/test/entities/factory.fixtures.js +0 -18
  253. package/test/entities/factory.test.js +0 -48
  254. package/test/entities/set.fixtures.js +0 -11
  255. package/test/entities/set.test.js +0 -12
  256. package/test/event.fixtures.js +0 -29
  257. package/test/event.test.js +0 -118
  258. package/test/locator.test.js +0 -113
  259. package/test/query.fixtures.js +0 -100
  260. package/test/query.test.js +0 -86
  261. package/test/receiver.fixtures.js +0 -23
  262. package/test/receiver.test.js +0 -95
  263. package/test/reflection.test.js +0 -30
  264. package/test/state.fixtures.js +0 -47
  265. package/test/state.test.js +0 -46
  266. package/test/transmission.fixtures.js +0 -15
  267. package/test/transmission.test.js +0 -46
  268. package/types/bindings.d.ts +0 -40
  269. package/types/bridges.ts +0 -30
  270. package/types/component.d.ts +0 -9
  271. package/types/connector.d.ts +0 -18
  272. package/types/context.d.ts +0 -21
  273. package/types/entity.d.ts +0 -46
  274. package/types/event.d.ts +0 -11
  275. package/types/exception.d.ts +0 -4
  276. package/types/extensions.d.ts +0 -29
  277. package/types/index.ts +0 -14
  278. package/types/locator.d.ts +0 -13
  279. package/types/message.d.ts +0 -3
  280. package/types/operations.d.ts +0 -2
  281. package/types/query.d.ts +0 -15
  282. package/types/receiver.d.ts +0 -12
  283. package/types/reflection.d.ts +0 -14
  284. package/types/request.d.ts +0 -23
  285. package/types/state.d.ts +0 -35
  286. package/types/storages.d.ts +0 -71
@@ -0,0 +1,137 @@
1
+ import { environment } from '@toa.io/generic';
2
+ import { EntityContractException, EntityGuardException } from '../exceptions.js';
3
+ import { newid } from './newid.js';
4
+ export class Entity {
5
+ deleted = false;
6
+ #schema;
7
+ #blank;
8
+ #guards;
9
+ #origin = null;
10
+ #state;
11
+ #mutable = true;
12
+ /**
13
+ * A record makes an entity of what a storage holds; a string, or nothing at all, makes a
14
+ * blank one under that identity, out of what the component declared a record starts as.
15
+ *
16
+ * @param blank what the component declares a record holds before anything is written to it
17
+ * @param mutable whether the entity may be modified and committed
18
+ */
19
+ // eslint-disable-next-line max-params
20
+ constructor(schema, blank, argument, guards, mutable = true) {
21
+ this.#schema = schema;
22
+ this.#blank = blank;
23
+ this.#guards = guards;
24
+ if (typeof argument === 'object')
25
+ this.#acquire(argument, mutable);
26
+ else
27
+ this.#write(this.#compose(argument ?? newid()));
28
+ }
29
+ get() {
30
+ return this.#state;
31
+ }
32
+ set(value) {
33
+ if (!this.#mutable)
34
+ throw new Error('Entity acquired by a read-only operation cannot be modified');
35
+ this.#guard(value);
36
+ const error = this.#schema.fit(value);
37
+ if (error !== null)
38
+ throw new EntityContractException(error, value);
39
+ this.#revive(value);
40
+ this.#write(value);
41
+ }
42
+ event(input) {
43
+ return {
44
+ origin: this.#origin,
45
+ state: this.#state,
46
+ trailers: this.#state.TRAILERS,
47
+ input
48
+ };
49
+ }
50
+ /**
51
+ * The origin is the pre-image a commit diffs the new state against. An operation that
52
+ * cannot commit has nothing to diff, so it takes the record as it came from the storage
53
+ * instead of paying for a deep copy of every record it read.
54
+ */
55
+ #acquire(record, mutable) {
56
+ this.#mutable = mutable;
57
+ if (!mutable) {
58
+ this.#write(record);
59
+ return;
60
+ }
61
+ this.#write(structuredClone(record));
62
+ this.#origin = record;
63
+ }
64
+ /**
65
+ * A blank is not validated: what the component declared is fitted once, at boot, and the
66
+ * system properties are the runtime's own. It is copied because every entity the component
67
+ * makes is written over its own.
68
+ */
69
+ #compose(id) {
70
+ // `REGION` here as well as in `#write`, because a record is validated before it is written
71
+ // and what is composed is about to be written here: it is this region's
72
+ return {
73
+ id,
74
+ VERSION: 0,
75
+ DELETED: null,
76
+ REGION,
77
+ ...structuredClone(this.#blank)
78
+ };
79
+ }
80
+ #guard(value) {
81
+ if (this.#guards === undefined)
82
+ return;
83
+ for (const guard of this.#guards) {
84
+ const ok = guard.fit(value, this.#origin);
85
+ if (ok === false)
86
+ throw new EntityGuardException(guard.name, value);
87
+ }
88
+ }
89
+ // deletion is only expressed as a new DELETED timestamp,
90
+ // so committing over a tombstone without touching it means revival
91
+ #revive(value) {
92
+ if (this.#origin?.DELETED == null || value.DELETED !== this.#origin.DELETED)
93
+ return;
94
+ value.DELETED = null;
95
+ this.deleted = false;
96
+ }
97
+ #write(value) {
98
+ if (!('TRAILERS' in value))
99
+ Object.defineProperty(value, 'TRAILERS', {
100
+ writable: false,
101
+ configurable: false,
102
+ enumerable: false,
103
+ value: {}
104
+ });
105
+ /*
106
+ * The system properties are the runtime's to write, and a record does not always come from
107
+ * a storage that wrote them: a component may bring its own, and one that answers with an
108
+ * id and a version has left the rest to whoever asked. Filling them in here is what makes
109
+ * a record's shape the runtime's guarantee rather than a storage's promise, and what lets
110
+ * the entity require them.
111
+ */
112
+ value.CREATED ??= Date.now();
113
+ value.UPDATED ??= value.CREATED;
114
+ value.VERSION ??= 0;
115
+ value.DELETED ??= null;
116
+ value.REGION ??= REGION;
117
+ if (value.DELETED !== null)
118
+ this.deleted = true;
119
+ // beside the version and the timestamp, and for the same reason: all three say what the
120
+ // write did, so all three change only where there is one. A record read here keeps the
121
+ // region that wrote it, which is not necessarily this one — that is the whole of what it
122
+ // is for, and stamping it on the way in would answer every read with the wrong region.
123
+ if (this.#state !== undefined) {
124
+ value.UPDATED = Date.now();
125
+ value.VERSION++;
126
+ value.REGION = REGION;
127
+ }
128
+ this.#state = value;
129
+ }
130
+ }
131
+ /**
132
+ * The rank of the region this deployment is, from what deployed it. An application that is one
133
+ * region has none and writes `0`, which is what the first region is and what a record written
134
+ * before any of this existed is backfilled with.
135
+ */
136
+ const REGION = Number(environment.get('TOA_REGION') ?? 0);
137
+ //# sourceMappingURL=entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity.js","sourceRoot":"","sources":["../../source/entities/entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAChF,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAMlC,MAAM,OAAO,MAAM;IACV,OAAO,GAAG,KAAK,CAAA;IAEb,OAAO,CAAQ;IACf,MAAM,CAAQ;IACd,OAAO,CAAqB;IACrC,OAAO,GAAkB,IAAI,CAAA;IAC7B,MAAM,CAAS;IACf,QAAQ,GAAG,IAAI,CAAA;IAEf;;;;;;OAMG;IACH,sCAAsC;IACtC,YACE,MAAc,EACd,KAAa,EACb,QAA0B,EAC1B,MAAgB,EAChB,OAAO,GAAG,IAAI;QAEd,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;QACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;QAErB,IAAI,OAAO,QAAQ,KAAK,QAAQ;YAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;;YAC7D,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ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;YAAE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QAE/C,wFAAwF;QACxF,uFAAuF;QACvF,yFAAyF;QACzF,uFAAuF;QACvF,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC9B,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;YAC1B,KAAK,CAAC,OAAO,EAAE,CAAA;YACf,KAAK,CAAC,MAAM,GAAG,MAAM,CAAA;QACvB,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;IACrB,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAA"}
@@ -0,0 +1,27 @@
1
+ import { Entity } from './entity.ts';
2
+ import { EntitySet } from './set.ts';
3
+ import { Changeset } from './changeset.ts';
4
+ import type { Schema } from '@toa.io/schemas';
5
+ import type { Guard } from '../guard.ts';
6
+ import type { Query, Record } from '../types/storages.ts';
7
+ /** The two schemas a component's records are held to, and what a new one starts as. */
8
+ export interface Schemas {
9
+ /** what a stored record must fit */
10
+ entity: Schema;
11
+ /** what a changeset must fit: the same properties, none of them required */
12
+ changeset: Schema;
13
+ }
14
+ export declare class Factory {
15
+ #private;
16
+ constructor(schemas: Schemas, blank: object, guards?: Guard[]);
17
+ /**
18
+ * What these values would make of a record, held to what a record must be. It starts from a
19
+ * blank rather than from the declared properties alone, because what is validated is the
20
+ * record and a record carries what the runtime writes into every one of them.
21
+ */
22
+ fit(values: object): void;
23
+ init(id?: string): Entity;
24
+ object(record: Record, mutable?: boolean): Entity;
25
+ objects(recordset: Record[], init?: string[], mutable?: boolean): EntitySet;
26
+ changeset(query: Query): Changeset;
27
+ }
@@ -0,0 +1,38 @@
1
+ import { Entity } from './entity.js';
2
+ import { EntitySet } from './set.js';
3
+ import { Changeset } from './changeset.js';
4
+ export class Factory {
5
+ #schemas;
6
+ #blank;
7
+ #guards;
8
+ constructor(schemas, blank, guards) {
9
+ this.#schemas = schemas;
10
+ this.#blank = blank;
11
+ this.#guards = guards;
12
+ }
13
+ /**
14
+ * What these values would make of a record, held to what a record must be. It starts from a
15
+ * blank rather than from the declared properties alone, because what is validated is the
16
+ * record and a record carries what the runtime writes into every one of them.
17
+ */
18
+ fit(values) {
19
+ this.#schemas.entity.validate({ ...this.init().get(), ...values }, 'Entity');
20
+ }
21
+ init(id) {
22
+ return new Entity(this.#schemas.entity, this.#blank, id, this.#guards);
23
+ }
24
+ object(record, mutable = true) {
25
+ return new Entity(this.#schemas.entity, this.#blank, record, this.#guards, mutable);
26
+ }
27
+ objects(recordset, init, mutable = true) {
28
+ const set = recordset.map((record) => this.object(record, mutable));
29
+ if (init !== undefined)
30
+ for (const id of init)
31
+ set.unshift(this.init(id));
32
+ return new EntitySet(set);
33
+ }
34
+ changeset(query) {
35
+ return new Changeset(this.#schemas.changeset, query);
36
+ }
37
+ }
38
+ //# sourceMappingURL=factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../source/entities/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAc1C,MAAM,OAAO,OAAO;IACT,QAAQ,CAAS;IACjB,MAAM,CAAQ;IACd,OAAO,CAAqB;IAErC,YAAmB,OAAgB,EAAE,KAAa,EAAE,MAAgB;QAClE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;QACvB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;IACvB,CAAC;IAED;;;;OAIG;IACI,GAAG,CAAC,MAAc;QACvB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,QAAQ,CAAC,CAAA;IAC9E,CAAC;IAEM,IAAI,CAAC,EAAW;QACrB,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;IACxE,CAAC;IAEM,MAAM,CAAC,MAAc,EAAE,OAAO,GAAG,IAAI;QAC1C,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACrF,CAAC;IAEM,OAAO,CAAC,SAAmB,EAAE,IAAe,EAAE,OAAO,GAAG,IAAI;QACjE,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;QAEnE,IAAI,IAAI,KAAK,SAAS;YAAE,KAAK,MAAM,EAAE,IAAI,IAAI;gBAAE,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;QAEzE,OAAO,IAAI,SAAS,CAAC,GAAG,CAAC,CAAA;IAC3B,CAAC;IAEM,SAAS,CAAC,KAAY;QAC3B,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;IACtD,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ export { derive, newid } from './newid.ts';
2
+ export { Factory } from './factory.ts';
3
+ export { Entity } from './entity.ts';
4
+ export { EntitySet } from './set.ts';
5
+ export { Changeset } from './changeset.ts';
@@ -0,0 +1,6 @@
1
+ export { derive, newid } from './newid.js';
2
+ export { Factory } from './factory.js';
3
+ export { Entity } from './entity.js';
4
+ export { EntitySet } from './set.js';
5
+ export { Changeset } from './changeset.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/entities/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA"}
@@ -0,0 +1,11 @@
1
+ export declare function newid(): string;
2
+ /**
3
+ * An id that is a function of what it is made of, in the shape `newid` produces, so that an `_id`
4
+ * is one kind of thing wherever it came from.
5
+ *
6
+ * What it is for is a call whose identity must be the same on every run that makes it: the same
7
+ * duplicate then produces the same identity, and whatever it reaches refuses its own copy. A
8
+ * name-based uuid is exactly that function: version 5 of RFC 9562, the bytes `uuid.v5` produces,
9
+ * hashed here with the namespace already parsed, since a call derives one on every call it makes.
10
+ */
11
+ export declare function derive(...parts: Array<string | number>): string;
@@ -0,0 +1,41 @@
1
+ import { createHash } from 'node:crypto';
2
+ import * as uuid from 'uuid';
3
+ export function newid() {
4
+ const buf = Buffer.alloc(16);
5
+ uuid.v7(undefined, buf);
6
+ return buf.toString('hex');
7
+ }
8
+ /**
9
+ * An id that is a function of what it is made of, in the shape `newid` produces, so that an `_id`
10
+ * is one kind of thing wherever it came from.
11
+ *
12
+ * What it is for is a call whose identity must be the same on every run that makes it: the same
13
+ * duplicate then produces the same identity, and whatever it reaches refuses its own copy. A
14
+ * name-based uuid is exactly that function: version 5 of RFC 9562, the bytes `uuid.v5` produces,
15
+ * hashed here with the namespace already parsed, since a call derives one on every call it makes.
16
+ */
17
+ export function derive(...parts) {
18
+ const hash = createHash('sha1').update(NAMESPACE).update(name(parts), 'utf8').digest();
19
+ hash[6] = (hash[6] & 0x0f) | 0x50;
20
+ hash[8] = (hash[8] & 0x3f) | 0x80;
21
+ return hash.toString('hex', 0, 16);
22
+ }
23
+ /**
24
+ * Each part behind its own length, so that no two different sets of parts read as one name
25
+ * whatever a part happens to contain — a separator alone would have `a` and `b:c` name what
26
+ * `a:b` and `c` do, and this decides whether two calls are one call.
27
+ */
28
+ function name(parts) {
29
+ let name = '';
30
+ for (const part of parts) {
31
+ const value = String(part);
32
+ name += value.length + ':' + value;
33
+ }
34
+ return name;
35
+ }
36
+ /**
37
+ * Toa's own, `26bd9bc6-675c-4465-9b42-9e008b20befe`, so that a name derived here collides with
38
+ * nothing derived elsewhere.
39
+ */
40
+ const NAMESPACE = Buffer.from('26bd9bc6675c44659b429e008b20befe', 'hex');
41
+ //# sourceMappingURL=newid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"newid.js","sourceRoot":"","sources":["../../source/entities/newid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAE5B,MAAM,UAAU,KAAK;IACnB,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IAE5B,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,CAAC,CAAA;IAEvB,OAAO,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,MAAM,CAAC,GAAG,KAA6B;IACrD,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC,MAAM,EAAE,CAAA;IAEtF,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAA;IACjC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAA;IAEjC,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA;AACpC,CAAC;AAED;;;;GAIG;AACH,SAAS,IAAI,CAAC,KAA6B;IACzC,IAAI,IAAI,GAAG,EAAE,CAAA;IAEb,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;QAE1B,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,GAAG,GAAG,KAAK,CAAA;IACpC,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;GAGG;AACH,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAA"}
@@ -0,0 +1,10 @@
1
+ import type { Entity } from './entity.ts';
2
+ import type { Record } from '../types/storages.ts';
3
+ import type { Event } from '../types/state.ts';
4
+ export declare class EntitySet {
5
+ #private;
6
+ constructor(set: Entity[]);
7
+ get(): Record[];
8
+ set(values: Record[]): void;
9
+ events(input?: object): Event[];
10
+ }
@@ -0,0 +1,19 @@
1
+ import { SystemException } from '../exceptions.js';
2
+ export class EntitySet {
3
+ #set;
4
+ constructor(set) {
5
+ this.#set = set;
6
+ }
7
+ get() {
8
+ return this.#set.map((entity) => entity.get());
9
+ }
10
+ set(values) {
11
+ if (values.length !== this.#set.length)
12
+ throw new SystemException('Objects array must not be modified');
13
+ values.forEach((value, index) => this.#set[index].set(value));
14
+ }
15
+ events(input) {
16
+ return this.#set.map((entity) => entity.event(input));
17
+ }
18
+ }
19
+ //# sourceMappingURL=set.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set.js","sourceRoot":"","sources":["../../source/entities/set.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAKlD,MAAM,OAAO,SAAS;IACX,IAAI,CAAU;IAEvB,YAAmB,GAAa;QAC9B,IAAI,CAAC,IAAI,GAAG,GAAG,CAAA;IACjB,CAAC;IAEM,GAAG;QACR,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAA;IAChD,CAAC;IAEM,GAAG,CAAC,MAAgB;QACzB,IAAI,MAAM,CAAC,MAAM,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM;YACpC,MAAM,IAAI,eAAe,CAAC,oCAAoC,CAAC,CAAA;QAEjE,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;IAC/D,CAAC;IAEM,MAAM,CAAC,KAAc;QAC1B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;IACvD,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ import { Connector } from './connector.ts';
2
+ import type { Emitter } from './types/bindings.ts';
3
+ import type { Event as Bridge } from './types/bridges.ts';
4
+ import type { Row } from './types/outbox.ts';
5
+ export interface Definition {
6
+ conditioned?: boolean;
7
+ subjective?: boolean;
8
+ label?: string;
9
+ }
10
+ export interface Raised {
11
+ payload: unknown;
12
+ }
13
+ export declare class Event extends Connector {
14
+ #private;
15
+ /** `emitter` is `null` for an event that is rendered and never published: see `Rendering` */
16
+ constructor(definition: Definition, emitter: Emitter | null, bridge?: Bridge);
17
+ /** What the row raises this event with, or `null` where its condition does not hold. */
18
+ render(row: Row): Promise<Raised | null>;
19
+ emit(row: Row): Promise<void>;
20
+ }
@@ -0,0 +1,65 @@
1
+ import { console, current, encode } from 'openspan';
2
+ import { Connector } from './connector.js';
3
+ import { derive } from './entities/newid.js';
4
+ import * as measure from './measurements.js';
5
+ export class Event extends Connector {
6
+ #emitter;
7
+ #bridge;
8
+ #conditioned;
9
+ #subjective;
10
+ #label;
11
+ /** `emitter` is `null` for an event that is rendered and never published: see `Rendering` */
12
+ constructor(definition, emitter, bridge) {
13
+ super();
14
+ this.#conditioned = definition.conditioned;
15
+ this.#subjective = definition.subjective;
16
+ this.#label = definition.label ?? 'event';
17
+ this.#emitter = emitter;
18
+ this.#bridge = bridge;
19
+ if (emitter !== null)
20
+ this.depends(emitter);
21
+ if (bridge !== undefined)
22
+ this.depends(bridge);
23
+ }
24
+ /** What the row raises this event with, or `null` where its condition does not hold. */
25
+ async render(row) {
26
+ const event = row.event;
27
+ if (this.#conditioned !== false && (await this.#bridge?.condition(event)) !== true)
28
+ return null;
29
+ const payload = this.#subjective === true ? await this.#bridge?.payload(event) : event.state;
30
+ return { payload };
31
+ }
32
+ async emit(row) {
33
+ const raised = await this.render(row);
34
+ if (raised !== null) {
35
+ const { payload } = raised;
36
+ /*
37
+ * The row is committed once, so its id is what makes every publication of it one message:
38
+ * the immediate path, the pump that may run an hour later in another replica, and a
39
+ * redelivery of what either sent. Derived with the label rather than the row id itself,
40
+ * because one row is published as several events and a component may consume two of them —
41
+ * one identity across both would have the second refused as a duplicate of the first.
42
+ */
43
+ const message = { payload, id: derive(row.id, this.#label) };
44
+ // the chain the change was made by, so a receiver of this continues it rather than
45
+ // starting one; read off the row, because the pump publishes off the operation's path
46
+ if (row.trail !== undefined)
47
+ message.trail = row.trail;
48
+ const options = {
49
+ name: `${this.#label} publish`,
50
+ kind: 'producer',
51
+ attributes: { 'messaging.destination.name': this.#label },
52
+ measure: { histogram: measure.event.publish, labels: { event: this.#label } }
53
+ };
54
+ await console.span(options, async () => {
55
+ const context = current();
56
+ if (context !== undefined)
57
+ message.telemetry = encode(context);
58
+ if (this.#emitter === null)
59
+ throw new Error(`Event '${this.#label}' is not published`);
60
+ await this.#emitter.emit(message);
61
+ });
62
+ }
63
+ }
64
+ }
65
+ //# sourceMappingURL=event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.js","sourceRoot":"","sources":["../source/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAoB,MAAM,UAAU,CAAA;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,KAAK,OAAO,MAAM,mBAAmB,CAAA;AAgB5C,MAAM,OAAO,KAAM,SAAQ,SAAS;IACzB,QAAQ,CAAgB;IACxB,OAAO,CAAoB;IAC3B,YAAY,CAAqB;IACjC,WAAW,CAAqB;IAChC,MAAM,CAAQ;IAEvB,6FAA6F;IAC7F,YAAmB,UAAsB,EAAE,OAAuB,EAAE,MAAe;QACjF,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,WAAW,CAAA;QAC1C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,UAAU,CAAA;QACxC,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,KAAK,IAAI,OAAO,CAAA;QACzC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;QACvB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;QAErB,IAAI,OAAO,KAAK,IAAI;YAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAE3C,IAAI,MAAM,KAAK,SAAS;YAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAChD,CAAC;IAED,wFAAwF;IACjF,KAAK,CAAC,MAAM,CAAC,GAAQ;QAC1B,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAA;QAEvB,IAAI,IAAI,CAAC,YAAY,KAAK,KAAK,IAAI,CAAC,MAA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S;oBAAE,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;gBAE9D,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI;oBACxB,MAAM,IAAI,KAAK,CAAC,UAAU,IAAI,CAAC,MAAM,oBAAoB,CAAC,CAAA;gBAE5D,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YACnC,CAAC,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,110 @@
1
+ import type { SchemaError } from '@toa.io/schemas';
2
+ export declare const codes: {
3
+ System: number;
4
+ Contract: number;
5
+ RequestSyntax: number;
6
+ RequestContract: number;
7
+ RequestConflict: number;
8
+ ResponseContract: number;
9
+ EntityContract: number;
10
+ EntityGuard: number;
11
+ QuerySyntax: number;
12
+ State: number;
13
+ StateNotFound: number;
14
+ StatePrecondition: number;
15
+ StateConcurrency: number;
16
+ StateInitialization: number;
17
+ Duplicate: number;
18
+ /** this call has been made, and what it changed is changed */
19
+ DuplicateCall: number;
20
+ /** a stream token names a point of the storage's history it no longer holds */
21
+ StateHistory: number;
22
+ Communication: number;
23
+ Transmission: number;
24
+ Endpoint: number;
25
+ /** nothing held the name an addressed call named */
26
+ Addressee: number;
27
+ /** the caller stopped waiting, and what it called may still run */
28
+ Abandoned: number;
29
+ /** the tree the call was made through has been taken down, and is not coming back */
30
+ Disposed: number;
31
+ /** a call to an operation that may change state, made under a request that may only read */
32
+ Safety: number;
33
+ /** nothing answered at the address of the component a streamed call was made to */
34
+ Unreachable: number;
35
+ /** a chain that came back to where it had been, or went further than a chain goes */
36
+ Loop: number;
37
+ /** a component asked for something its manifest does not declare */
38
+ Misuse: number;
39
+ /** a run command pauses what nothing takes again: `pause` with no `resume` */
40
+ Irresumable: number;
41
+ /** a call to a component nothing this process was given states */
42
+ Unstated: number;
43
+ };
44
+ export declare class Exception {
45
+ readonly code: number;
46
+ readonly message: string;
47
+ cause?: unknown;
48
+ /** what a contract exception copies off the schema error it refused with */
49
+ [key: string]: unknown;
50
+ constructor(code: number, message: string, cause?: unknown);
51
+ }
52
+ export declare class SystemException extends Exception {
53
+ readonly stack?: string;
54
+ constructor(error: Error | string);
55
+ }
56
+ /**
57
+ * A call refused for where it has been rather than for what it says. Named, and so permanent:
58
+ * the chain is deterministic, and another attempt reproduces it hop for hop.
59
+ */
60
+ export declare class LoopException extends Exception {
61
+ /** the whole chain, so what is set aside can be read without guessing */
62
+ readonly trail: string[];
63
+ constructor(message: string, trail: string[]);
64
+ }
65
+ export declare class ContractException extends Exception {
66
+ constructor(code: number | undefined, error: SchemaError | string | null, cause?: unknown);
67
+ }
68
+ export declare class RequestContractException extends ContractException {
69
+ constructor(error: SchemaError | string, cause?: unknown);
70
+ }
71
+ export declare class ResponseContractException extends ContractException {
72
+ constructor(error: SchemaError | string, cause?: unknown);
73
+ }
74
+ export declare class EntityContractException extends ContractException {
75
+ constructor(error: SchemaError | string, cause?: unknown);
76
+ }
77
+ export declare class EntityGuardException extends ContractException {
78
+ constructor(name: string, cause?: unknown);
79
+ }
80
+ type Derived = new (message?: string, cause?: unknown) => Exception;
81
+ export declare const RequestSyntaxException: Derived;
82
+ export declare const RequestConflictException: Derived;
83
+ export declare const QuerySyntaxException: Derived;
84
+ export declare const StateException: Derived;
85
+ export declare const StateNotFoundException: Derived;
86
+ export declare const StatePreconditionException: Derived;
87
+ export declare const StateConcurrencyException: Derived;
88
+ export declare const StateInitializationException: Derived;
89
+ export declare const DuplicateException: Derived;
90
+ export declare const DuplicateCallException: Derived;
91
+ export declare const StateHistoryException: Derived;
92
+ export declare const CommunicationException: Derived;
93
+ export declare const TransmissionException: Derived;
94
+ export declare const EndpointException: Derived;
95
+ export declare const AddresseeException: Derived;
96
+ export declare const AbandonedException: Derived;
97
+ export declare const DisposedException: Derived;
98
+ export declare const SafetyException: Derived;
99
+ export declare const UnreachableException: Derived;
100
+ export declare const MisuseException: Derived;
101
+ export declare const IrresumableException: Derived;
102
+ export declare const UnstatedException: Derived;
103
+ export declare const names: Record<string, string>;
104
+ /**
105
+ * Takes `unknown` because a caller has caught something rather than been handed an `Exception`.
106
+ * Anything core did not raise — an error from a driver, a rejection with no code at all — is not
107
+ * on the list, and is therefore worth trying again.
108
+ */
109
+ export declare function permanent(exception: unknown): boolean;
110
+ export {};