@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,215 @@
1
+ import { swap } from '@toa.io/generic';
2
+ export const codes = {
3
+ System: 0,
4
+ Contract: 200,
5
+ RequestSyntax: 201,
6
+ RequestContract: 202,
7
+ RequestConflict: 203,
8
+ ResponseContract: 211,
9
+ EntityContract: 212,
10
+ EntityGuard: 213,
11
+ QuerySyntax: 221,
12
+ State: 300,
13
+ StateNotFound: 302,
14
+ StatePrecondition: 303,
15
+ StateConcurrency: 304,
16
+ StateInitialization: 305,
17
+ Duplicate: 306,
18
+ /** this call has been made, and what it changed is changed */
19
+ DuplicateCall: 307,
20
+ /** a stream token names a point of the storage's history it no longer holds */
21
+ StateHistory: 308,
22
+ Communication: 400,
23
+ Transmission: 401,
24
+ Endpoint: 402,
25
+ /** nothing held the name an addressed call named */
26
+ Addressee: 403,
27
+ /** the caller stopped waiting, and what it called may still run */
28
+ Abandoned: 404,
29
+ /** the tree the call was made through has been taken down, and is not coming back */
30
+ Disposed: 405,
31
+ /** a call to an operation that may change state, made under a request that may only read */
32
+ Safety: 406,
33
+ /** nothing answered at the address of the component a streamed call was made to */
34
+ Unreachable: 407,
35
+ /** a chain that came back to where it had been, or went further than a chain goes */
36
+ Loop: 500,
37
+ /** a component asked for something its manifest does not declare */
38
+ Misuse: 600,
39
+ /** a run command pauses what nothing takes again: `pause` with no `resume` */
40
+ Irresumable: 601,
41
+ /** a call to a component nothing this process was given states */
42
+ Unstated: 602
43
+ };
44
+ export class Exception {
45
+ code;
46
+ message;
47
+ cause;
48
+ constructor(code, message, cause) {
49
+ this.code = code;
50
+ this.message = message;
51
+ if (cause !== undefined)
52
+ this.cause = cause;
53
+ }
54
+ }
55
+ export class SystemException extends Exception {
56
+ stack;
57
+ constructor(error) {
58
+ super(codes.System, typeof error === 'string' ? error : error.message);
59
+ if (typeof error !== 'string' && error.stack !== undefined)
60
+ this.stack = error.stack;
61
+ }
62
+ }
63
+ /**
64
+ * A call refused for where it has been rather than for what it says. Named, and so permanent:
65
+ * the chain is deterministic, and another attempt reproduces it hop for hop.
66
+ */
67
+ export class LoopException extends Exception {
68
+ /** the whole chain, so what is set aside can be read without guessing */
69
+ trail;
70
+ constructor(message, trail) {
71
+ super(codes.Loop, message);
72
+ this.trail = trail;
73
+ }
74
+ }
75
+ export class ContractException extends Exception {
76
+ constructor(code, error, cause) {
77
+ super(code ?? codes.Contract, typeof error === 'string' ? error : (error?.message ?? ''), cause);
78
+ if (typeof error === 'object' && error !== null)
79
+ for (const k of [
80
+ 'keyword',
81
+ 'instancePath',
82
+ 'schemaPath',
83
+ 'params',
84
+ 'propertyName'
85
+ ])
86
+ if (k in error)
87
+ this[k] = error[k];
88
+ }
89
+ }
90
+ export class RequestContractException extends ContractException {
91
+ constructor(error, cause) {
92
+ super(codes.RequestContract, error, cause);
93
+ }
94
+ }
95
+ export class ResponseContractException extends ContractException {
96
+ constructor(error, cause) {
97
+ super(codes.ResponseContract, error, cause);
98
+ }
99
+ }
100
+ export class EntityContractException extends ContractException {
101
+ constructor(error, cause) {
102
+ super(codes.EntityContract, error, cause);
103
+ }
104
+ }
105
+ export class EntityGuardException extends ContractException {
106
+ constructor(name, cause) {
107
+ super(codes.EntityGuard, name, cause);
108
+ }
109
+ }
110
+ function derive(name) {
111
+ const classname = name + 'Exception';
112
+ const derived = class extends Exception {
113
+ constructor(message, cause) {
114
+ super(codes[name], message === undefined ? classname : `${classname}: ${message}`, cause);
115
+ }
116
+ };
117
+ // the name is the class's own, and a class expression has none worth reporting
118
+ Object.defineProperty(derived, 'name', { value: classname });
119
+ return derived;
120
+ }
121
+ export const RequestSyntaxException = derive('RequestSyntax');
122
+ export const RequestConflictException = derive('RequestConflict');
123
+ export const QuerySyntaxException = derive('QuerySyntax');
124
+ export const StateException = derive('State');
125
+ export const StateNotFoundException = derive('StateNotFound');
126
+ export const StatePreconditionException = derive('StatePrecondition');
127
+ export const StateConcurrencyException = derive('StateConcurrency');
128
+ export const StateInitializationException = derive('StateInitialization');
129
+ export const DuplicateException = derive('Duplicate');
130
+ export const DuplicateCallException = derive('DuplicateCall');
131
+ export const StateHistoryException = derive('StateHistory');
132
+ export const CommunicationException = derive('Communication');
133
+ export const TransmissionException = derive('Transmission');
134
+ export const EndpointException = derive('Endpoint');
135
+ export const AddresseeException = derive('Addressee');
136
+ export const AbandonedException = derive('Abandoned');
137
+ export const DisposedException = derive('Disposed');
138
+ export const SafetyException = derive('Safety');
139
+ export const UnreachableException = derive('Unreachable');
140
+ export const MisuseException = derive('Misuse');
141
+ export const IrresumableException = derive('Irresumable');
142
+ export const UnstatedException = derive('Unstated');
143
+ export const names = swap(codes);
144
+ // #endregion
145
+ /**
146
+ * Whether a failure means the same thing on a later attempt.
147
+ *
148
+ * Every code answers, and the answer is here rather than inferred: `Record<keyof typeof codes>`
149
+ * refuses to compile until a code added later says which it is. What core names, core raised on
150
+ * purpose — a contract does not start fitting, a version that has passed does not come back.
151
+ * `System` is the exception that proves it: it is a code like any other, and what it wraps is
152
+ * whatever reached core from below, which is the kind that passes.
153
+ */
154
+ const OUTCOME = {
155
+ // whatever the algorithm or a connector threw: core neither chose it nor can read it
156
+ System: 'transient',
157
+ Contract: 'permanent',
158
+ RequestSyntax: 'permanent',
159
+ RequestContract: 'permanent',
160
+ RequestConflict: 'permanent',
161
+ ResponseContract: 'permanent',
162
+ EntityContract: 'permanent',
163
+ EntityGuard: 'permanent',
164
+ QuerySyntax: 'permanent',
165
+ State: 'permanent',
166
+ // an event about an entity can outrun the one that creates it; nothing promises order
167
+ StateNotFound: 'transient',
168
+ // an entity's version only grows, so one that has passed does not start matching
169
+ StatePrecondition: 'permanent',
170
+ // the compare-and-swap lost, which is the case a later attempt exists for
171
+ StateConcurrency: 'transient',
172
+ StateInitialization: 'permanent',
173
+ Duplicate: 'permanent',
174
+ // a call that has been made stays made: another attempt is refused by the same record
175
+ DuplicateCall: 'permanent',
176
+ // history a storage has let go of does not come back
177
+ StateHistory: 'permanent',
178
+ Communication: 'transient',
179
+ // nothing is listening on that queue yet — a deployment in progress, most of the time
180
+ Transmission: 'transient',
181
+ // its sibling, and the other way round: nothing carried the call is a moment,
182
+ // there is nothing to carry it to is a fact
183
+ Endpoint: 'permanent',
184
+ // a process that lost its broker connection claims its name again once it is restored
185
+ Addressee: 'transient',
186
+ // what the caller gave up on may have run, and may run yet
187
+ Abandoned: 'transient',
188
+ // the tree is gone and a resume builds another, so the same context never works again
189
+ Disposed: 'permanent',
190
+ // a transition does not become an observation, and the request goes on saying it only reads
191
+ Safety: 'permanent',
192
+ // a replica that is starting, restarting or being deployed is one that answers in a moment
193
+ Unreachable: 'transient',
194
+ // the chain is deterministic, so another attempt walks it again: a retry is another cycle
195
+ Loop: 'permanent',
196
+ // what a component did not declare, it does not declare on the next attempt either
197
+ Misuse: 'permanent',
198
+ // the component is refused at start, so nothing reaches it to be attempted twice
199
+ Irresumable: 'permanent',
200
+ // a remote is built once and held, so what this process was not given, it is not given later
201
+ Unstated: 'permanent'
202
+ };
203
+ const PERMANENT = new Set(Object.entries(OUTCOME)
204
+ .filter(([, outcome]) => outcome === 'permanent')
205
+ .map(([name]) => codes[name]));
206
+ /**
207
+ * Takes `unknown` because a caller has caught something rather than been handed an `Exception`.
208
+ * Anything core did not raise — an error from a driver, a rejection with no code at all — is not
209
+ * on the list, and is therefore worth trying again.
210
+ */
211
+ export function permanent(exception) {
212
+ const code = exception?.code;
213
+ return code !== undefined && PERMANENT.has(code);
214
+ }
215
+ //# sourceMappingURL=exceptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../source/exceptions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F,WAAW,EAAE,WAAW;IACxB,6FAA6F;IAC7F,QAAQ,EAAE,WAAW;CACtB,CAAA;AAED,MAAM,SAAS,GAAG,IAAI,GAAG,CACvB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;KACpB,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,KAAK,WAAW,CAAC;KAChD,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAA0B,CAAC,CAAC,CACtD,CAAA;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,SAAkB;IAC1C,MAAM,IAAI,GAAI,SAAmC,EAAE,IAAI,CAAA;IAEvD,OAAO,IAAI,KAAK,SAAS,IAAI,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AAClD,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { Connector } from './connector.ts';
2
+ /**
3
+ * A part of a tree that a halt takes down and builds again.
4
+ *
5
+ * What it holds it *owns*, rather than depends on: a connector with a live dependant refuses to
6
+ * disconnect, and the one way past that refusal skips `close()` with it. A subtree nobody links
7
+ * has neither problem, so the teardown here is the one a shutdown performs.
8
+ *
9
+ * And the subtree is discarded rather than kept, because what comes back is built anew: a sealed
10
+ * communication, a receiver that has stopped announcing, an algorithm that has been unmounted —
11
+ * none of them are asked to work a second time. Nothing outlives a halt but what is above it.
12
+ */
13
+ export declare class Gate extends Connector {
14
+ private readonly build;
15
+ private live;
16
+ /** While halted, when what this holds comes back; `0` where it is not halted. */
17
+ private resumesAt;
18
+ constructor(build: () => Promise<Connector>);
19
+ /** Whether what this holds is up. */
20
+ holding(): boolean;
21
+ /**
22
+ * Seconds until what this holds is back, and `0` where it is up or is not coming back.
23
+ *
24
+ * What sits above a gate answers for it while it is down — the gateway keeps its port and
25
+ * replies `503` rather than closing it — and this is what such a reply says to come back
26
+ * after.
27
+ */
28
+ remaining(): number;
29
+ /**
30
+ * @param seconds how long it stays down, where it is coming back
31
+ */
32
+ down(seconds?: number): Promise<void>;
33
+ up(): Promise<void>;
34
+ /** What a gate holds is not a dependency, so the walks that stop a tree are led into it. */
35
+ halt(visited?: Set<Connector>): Promise<void>;
36
+ restore(visited?: Set<Connector>): Promise<void>;
37
+ debug(node?: Record<string, any>): Record<string, any>;
38
+ protected open(): Promise<void>;
39
+ protected close(): Promise<void>;
40
+ }
@@ -0,0 +1,84 @@
1
+ import { Connector } from './connector.js';
2
+ /**
3
+ * A part of a tree that a halt takes down and builds again.
4
+ *
5
+ * What it holds it *owns*, rather than depends on: a connector with a live dependant refuses to
6
+ * disconnect, and the one way past that refusal skips `close()` with it. A subtree nobody links
7
+ * has neither problem, so the teardown here is the one a shutdown performs.
8
+ *
9
+ * And the subtree is discarded rather than kept, because what comes back is built anew: a sealed
10
+ * communication, a receiver that has stopped announcing, an algorithm that has been unmounted —
11
+ * none of them are asked to work a second time. Nothing outlives a halt but what is above it.
12
+ */
13
+ export class Gate extends Connector {
14
+ build;
15
+ live = null;
16
+ /** While halted, when what this holds comes back; `0` where it is not halted. */
17
+ resumesAt = 0;
18
+ constructor(build) {
19
+ super();
20
+ this.build = build;
21
+ }
22
+ /** Whether what this holds is up. */
23
+ holding() {
24
+ return this.live !== null;
25
+ }
26
+ /**
27
+ * Seconds until what this holds is back, and `0` where it is up or is not coming back.
28
+ *
29
+ * What sits above a gate answers for it while it is down — the gateway keeps its port and
30
+ * replies `503` rather than closing it — and this is what such a reply says to come back
31
+ * after.
32
+ */
33
+ remaining() {
34
+ if (this.resumesAt === 0)
35
+ return 0;
36
+ return Math.max(0, Math.ceil((this.resumesAt - Date.now()) / 1000));
37
+ }
38
+ /**
39
+ * @param seconds how long it stays down, where it is coming back
40
+ */
41
+ async down(seconds = 0) {
42
+ const live = this.live;
43
+ if (live === null)
44
+ return;
45
+ this.live = null;
46
+ this.resumesAt = seconds === 0 ? 0 : Date.now() + seconds * 1000;
47
+ await live.disconnect();
48
+ }
49
+ async up() {
50
+ this.resumesAt = 0;
51
+ if (this.live !== null)
52
+ return;
53
+ const live = await this.build();
54
+ // held only once it is up: a build that throws leaves nothing to take down
55
+ await live.connect();
56
+ this.live = live;
57
+ }
58
+ /** What a gate holds is not a dependency, so the walks that stop a tree are led into it. */
59
+ async halt(visited = new Set()) {
60
+ if (visited.has(this))
61
+ return;
62
+ await super.halt(visited);
63
+ await this.live?.halt(visited);
64
+ }
65
+ async restore(visited = new Set()) {
66
+ if (visited.has(this))
67
+ return;
68
+ await this.live?.restore(visited);
69
+ await super.restore(visited);
70
+ }
71
+ debug(node = {}) {
72
+ super.debug(node);
73
+ // what a gate holds is not a dependency, so the walk does not reach it on its own
74
+ this.live?.debug(node[this.id]);
75
+ return node;
76
+ }
77
+ async open() {
78
+ await this.up();
79
+ }
80
+ async close() {
81
+ await this.down();
82
+ }
83
+ }
84
+ //# sourceMappingURL=gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gate.js","sourceRoot":"","sources":["../source/gate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C;;;;;;;;;;GAUG;AACH,MAAM,OAAO,IAAK,SAAQ,SAAS;IAChB,KAAK,CAA0B;IACxC,IAAI,GAAqB,IAAI,CAAA;IAErC,iFAAiF;IACzE,SAAS,GAAG,CAAC,CAAA;IAErB,YAAmB,KAA+B;QAChD,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,qCAAqC;IAC9B,OAAO;QACZ,OAAO,IAAI,CAAC,IAAI,KAAK,IAAI,CAAA;IAC3B,CAAC;IAED;;;;;;OAMG;IACI,SAAS;QACd,IAAI,IAAI,CAAC,SAAS,KAAK,CAAC;YAAE,OAAO,CAAC,CAAA;QAElC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,GAAG,IAAI,C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,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC9B,CAAC;IAEe,KAAK,CAAC,IAAI,GAAwB,EAAE;QAClD,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAEjB,kFAAkF;QAClF,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;QAE/B,OAAO,IAAI,CAAA;IACb,CAAC;IAEkB,KAAK,CAAC,IAAI;QAC3B,MAAM,IAAI,CAAC,EAAE,EAAE,CAAA;IACjB,CAAC;IAEkB,KAAK,CAAC,KAAK;QAC5B,MAAM,IAAI,CAAC,IAAI,EAAE,CAAA;IACnB,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ import type { Guard as Bridge } from './types/bridges.ts';
2
+ export declare class Guard {
3
+ #private;
4
+ readonly name: string;
5
+ constructor(name: string, bridge: Bridge);
6
+ fit(state: object, origin: object | null): boolean;
7
+ }
@@ -0,0 +1,12 @@
1
+ export class Guard {
2
+ name;
3
+ #bridge;
4
+ constructor(name, bridge) {
5
+ this.name = name;
6
+ this.#bridge = bridge;
7
+ }
8
+ fit(state, origin) {
9
+ return this.#bridge.fit(state, origin);
10
+ }
11
+ }
12
+ //# sourceMappingURL=guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guard.js","sourceRoot":"","sources":["../source/guard.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,KAAK;IACA,IAAI,CAAQ;IAEnB,OAAO,CAAQ;IAExB,YAAmB,IAAY,EAAE,MAAc;QAC7C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;IACvB,CAAC;IAEM,GAAG,CAAC,KAAa,EAAE,MAAqB;QAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;IACxC,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Whether this process is halting.
3
+ *
4
+ * A halt is the one teardown that is not a shutdown: the process stays, and what it held is
5
+ * built again. Two things read this and act differently because of it — a connection gives up
6
+ * the replies it is waiting for rather than holding the teardown open for a peer that is
7
+ * halting too, and a rejection from a tree that has been taken down is reported rather than
8
+ * fatal, because the process is in exactly the state the runtime put it in.
9
+ *
10
+ * Ambient, like the instance name and the invocation chain, and for the same reason: a process
11
+ * may carry two copies of this module, and an answer from one of them answers for half a
12
+ * process.
13
+ */
14
+ export declare function begin(): void;
15
+ export declare function end(): void;
16
+ export declare function underway(): boolean;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Whether this process is halting.
3
+ *
4
+ * A halt is the one teardown that is not a shutdown: the process stays, and what it held is
5
+ * built again. Two things read this and act differently because of it — a connection gives up
6
+ * the replies it is waiting for rather than holding the teardown open for a peer that is
7
+ * halting too, and a rejection from a tree that has been taken down is reported rather than
8
+ * fatal, because the process is in exactly the state the runtime put it in.
9
+ *
10
+ * Ambient, like the instance name and the invocation chain, and for the same reason: a process
11
+ * may carry two copies of this module, and an answer from one of them answers for half a
12
+ * process.
13
+ */
14
+ const KEY = Symbol.for('toa.core.halting');
15
+ const store = (globalThis[KEY] ??= { underway: false });
16
+ export function begin() {
17
+ store.underway = true;
18
+ }
19
+ export function end() {
20
+ store.underway = false;
21
+ }
22
+ export function underway() {
23
+ return store.underway;
24
+ }
25
+ //# sourceMappingURL=halting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"halting.js","sourceRoot":"","sources":["../source/halting.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;AAI1C,MAAM,KAAK,GAAG,CAAE,UAAoB,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAA;AAElE,MAAM,UAAU,KAAK;IACnB,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAA;AACvB,CAAC;AAED,MAAM,UAAU,GAAG;IACjB,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAA;AACxB,CAAC;AAED,MAAM,UAAU,QAAQ;IACtB,OAAO,KAAK,CAAC,QAAQ,CAAA;AACvB,CAAC"}
@@ -0,0 +1,45 @@
1
+ export { Assignment } from './assignment.ts';
2
+ export { Call } from './call.ts';
3
+ export { Cascade } from './cascade.ts';
4
+ export { Component } from './component.ts';
5
+ export { Composition } from './composition.ts';
6
+ export { Connector } from './connector.ts';
7
+ export { Context } from './context.ts';
8
+ export { Encoded } from './encoded.ts';
9
+ export { Effect } from './effect.ts';
10
+ export { Emission } from './emission.ts';
11
+ export { Event } from './event.ts';
12
+ export { Rendering } from './rendering.ts';
13
+ export { Regional } from './regional.ts';
14
+ export { Gate } from './gate.ts';
15
+ export { Locator } from './locator.ts';
16
+ export { Observation } from './observation.ts';
17
+ export { Outbox } from './outbox.ts';
18
+ export { Operation } from './operation.ts';
19
+ export { Query } from './query.ts';
20
+ export { Receiver } from './receiver.ts';
21
+ export { Reflection } from './reflection.ts';
22
+ export { Remote } from './remote.ts';
23
+ export { State } from './state.ts';
24
+ export { Transition } from './transition.ts';
25
+ export { Transmission } from './transmission.ts';
26
+ export { Unmanaged } from './unmanaged.ts';
27
+ export { Guard } from './guard.ts';
28
+ export { instance } from './instance.ts';
29
+ export { safe } from './safety.ts';
30
+ export * as deliveries from './deliveries.ts';
31
+ export * as entities from './entities/index.ts';
32
+ export * as halting from './halting.ts';
33
+ export * as exceptions from './exceptions.ts';
34
+ export * as parts from './parts.ts';
35
+ export * as trail from './trail.ts';
36
+ export * as contract from './contract/index.ts';
37
+ export type { Exception } from './exceptions.ts';
38
+ export type { Part } from './parts.ts';
39
+ export type { Invocable } from './component.ts';
40
+ export type { Explicable } from './remote.ts';
41
+ export type { Scoped, Store } from './operation.ts';
42
+ export type { Source as ReflectionSource } from './reflection.ts';
43
+ export type { Explanation } from './contract/request.ts';
44
+ export type { Contract } from './contract/component.ts';
45
+ export type { JSONSchema } from './contract/schemas.ts';
@@ -0,0 +1,37 @@
1
+ export { Assignment } from './assignment.js';
2
+ export { Call } from './call.js';
3
+ export { Cascade } from './cascade.js';
4
+ export { Component } from './component.js';
5
+ export { Composition } from './composition.js';
6
+ export { Connector } from './connector.js';
7
+ export { Context } from './context.js';
8
+ export { Encoded } from './encoded.js';
9
+ export { Effect } from './effect.js';
10
+ export { Emission } from './emission.js';
11
+ export { Event } from './event.js';
12
+ export { Rendering } from './rendering.js';
13
+ export { Regional } from './regional.js';
14
+ export { Gate } from './gate.js';
15
+ export { Locator } from './locator.js';
16
+ export { Observation } from './observation.js';
17
+ export { Outbox } from './outbox.js';
18
+ export { Operation } from './operation.js';
19
+ export { Query } from './query.js';
20
+ export { Receiver } from './receiver.js';
21
+ export { Reflection } from './reflection.js';
22
+ export { Remote } from './remote.js';
23
+ export { State } from './state.js';
24
+ export { Transition } from './transition.js';
25
+ export { Transmission } from './transmission.js';
26
+ export { Unmanaged } from './unmanaged.js';
27
+ export { Guard } from './guard.js';
28
+ export { instance } from './instance.js';
29
+ export { safe } from './safety.js';
30
+ export * as deliveries from './deliveries.js';
31
+ export * as entities from './entities/index.js';
32
+ export * as halting from './halting.js';
33
+ export * as exceptions from './exceptions.js';
34
+ export * as parts from './parts.js';
35
+ export * as trail from './trail.js';
36
+ export * as contract from './contract/index.js';
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,SAAS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Q,MAAM,qBAAqB,CAAA;AAC/C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The name this process answers addressed calls under, and what a call to one of its stateful
3
+ * operations names: given by `TOA_INSTANCE`, or generated once.
4
+ *
5
+ * It is kept where every copy of this package reads it, because a binding and a component loaded
6
+ * against two copies must agree on whose name a call carries.
7
+ */
8
+ export declare function instance(): string;
9
+ /** How long an addressed call waits where it names no timeout of its own, in milliseconds. */
10
+ export declare function timeout(): number;
@@ -0,0 +1,30 @@
1
+ import { environment } from '@toa.io/generic';
2
+ import { newid } from './entities/newid.js';
3
+ const KEY = Symbol.for('toa.core.instance');
4
+ // what a queue name may carry, short enough that one made of it stays within a broker's limit
5
+ const NAME = /^[\w.:-]{1,64}$/;
6
+ const TIMEOUT = 5000;
7
+ /**
8
+ * The name this process answers addressed calls under, and what a call to one of its stateful
9
+ * operations names: given by `TOA_INSTANCE`, or generated once.
10
+ *
11
+ * It is kept where every copy of this package reads it, because a binding and a component loaded
12
+ * against two copies must agree on whose name a call carries.
13
+ */
14
+ export function instance() {
15
+ return (globalThis[KEY] ??= named());
16
+ }
17
+ /** How long an addressed call waits where it names no timeout of its own, in milliseconds. */
18
+ export function timeout() {
19
+ const value = Number(environment.get('TOA_ADDRESSED_TIMEOUT'));
20
+ return Number.isInteger(value) && value > 0 ? value : TIMEOUT;
21
+ }
22
+ function named() {
23
+ const given = environment.get('TOA_INSTANCE');
24
+ if (given === undefined)
25
+ return newid();
26
+ if (!NAME.test(given))
27
+ throw new Error(`TOA_INSTANCE '${given}' must be 1 to 64 letters, digits, '_', '-', '.' or ':'`);
28
+ return given;
29
+ }
30
+ //# sourceMappingURL=instance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instance.js","sourceRoot":"","sources":["../source/instance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAE3C,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;AAI3C,8FAA8F;AAC9F,MAAM,IAAI,GAAG,iBAAiB,CAAA;AAE9B,MAAM,OAAO,GAAG,IAAI,CAAA;AAEpB;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,CAAE,UAAoB,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE,CAAC,CAAA;AACjD,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,OAAO;IACrB,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC,CAAA;IAE9D,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAA;AAC/D,CAAC;AAED,SAAS,KAAK;IACZ,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;IAE7C,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,EAAE,CAAA;IAEvC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;QACnB,MAAM,IAAI,KAAK,CACb,iBAAiB,KAAK,yDAAyD,CAChF,CAAA;IAEH,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,12 @@
1
+ /** Where a component is, as every name derived from it. */
2
+ export declare class Locator {
3
+ readonly name: string;
4
+ readonly namespace: string | undefined;
5
+ readonly id: string;
6
+ readonly label: string;
7
+ readonly uppercase: string;
8
+ readonly lowercase: string;
9
+ constructor(name: string, namespace?: string);
10
+ static parse(string: string): Locator;
11
+ hostname(prefix?: string): string;
12
+ }
@@ -0,0 +1,32 @@
1
+ import { concat } from '@toa.io/generic';
2
+ /** Where a component is, as every name derived from it. */
3
+ export class Locator {
4
+ name;
5
+ namespace;
6
+ id;
7
+ label;
8
+ uppercase;
9
+ lowercase;
10
+ constructor(name, namespace) {
11
+ if (name === undefined)
12
+ throw new TypeError('Locator name must be defined');
13
+ this.name = name;
14
+ this.namespace = namespace;
15
+ this.id = concat(namespace, '.') + name;
16
+ this.label = (concat(namespace, '-') + name).toLowerCase();
17
+ this.uppercase = (concat(namespace, '_') + name).toUpperCase();
18
+ this.lowercase = (concat(namespace, '_') + name).toLowerCase();
19
+ }
20
+ static parse(string) {
21
+ const [namespace, name] = string.split(DOT);
22
+ if (name === undefined)
23
+ return new Locator(namespace);
24
+ else
25
+ return new Locator(name, namespace);
26
+ }
27
+ hostname(prefix) {
28
+ return concat(prefix?.toLowerCase(), '-') + this.label;
29
+ }
30
+ }
31
+ const DOT = '.';
32
+ //# sourceMappingURL=locator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locator.js","sourceRoot":"","sources":["../source/locator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAExC,2DAA2D;AAC3D,MAAM,OAAO,OAAO;IACF,IAAI,CAAQ;IACZ,SAAS,CAAoB;IAE7B,EAAE,CAAQ;IACV,KAAK,CAAQ;IACb,SAAS,CAAQ;IACjB,SAAS,CAAQ;IAEjC,YAAmB,IAAY,EAAE,SAAkB;QACjD,IAAI,IAAI,KAAK,SAAS;YAAE,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAA;QAE3E,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAE1B,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;QACvC,IAAI,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE,CAAA;QAC1D,IAAI,CAAC,SAAS,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE,CAAA;QAC9D,IAAI,CAAC,SAAS,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE,CAAA;IAChE,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,MAAc;QAChC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAE3C,IAAI,IAAI,KAAK,SAAS;YAAE,OAAO,IAAI,OAAO,CAAC,SAAS,CAAC,CAAA;;YAChD,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;IAC1C,CAAC;IAEM,QAAQ,CAAC,MAAe;QAC7B,OAAO,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAA;IACxD,CAAC;CACF;AAED,MAAM,GAAG,GAAG,GAAG,CAAA"}
@@ -0,0 +1,20 @@
1
+ /** Prometheus' own ladder, in seconds: from five milliseconds to ten seconds. */
2
+ export declare const DURATIONS: number[];
3
+ export declare const operation: {
4
+ duration: import("openspan").Histogram;
5
+ /** a refusal the operation chose: the operation working */
6
+ errors: import("openspan").Counter;
7
+ /** a failure nobody chose; `outcome` says whether another attempt could pass */
8
+ exceptions: import("openspan").Counter;
9
+ inflight: import("openspan").Gauge;
10
+ };
11
+ export declare const call: {
12
+ duration: import("openspan").Histogram;
13
+ /** only what the transmission raised: what the callee sent back is counted where it happened */
14
+ exceptions: import("openspan").Counter;
15
+ /** callers waiting, which is held for the whole round trip and not only while one runs */
16
+ inflight: import("openspan").Gauge;
17
+ };
18
+ export declare const event: {
19
+ publish: import("openspan").Histogram;
20
+ };