@toa.io/core 1.0.0-alpha.33 → 1.0.0-alpha.332

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 (289) 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 +203 -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 +21 -0
  15. package/transpiled/component.js +159 -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 +34 -0
  24. package/transpiled/context.js +71 -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 +47 -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 +156 -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 +43 -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 +31 -0
  48. package/transpiled/deliveries.js +49 -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 +146 -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 +27 -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 +119 -0
  81. package/transpiled/exceptions.js +230 -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 +86 -0
  108. package/transpiled/operation.js +240 -0
  109. package/transpiled/operation.js.map +1 -0
  110. package/transpiled/outbox.d.ts +45 -0
  111. package/transpiled/outbox.js +450 -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 +3 -0
  120. package/transpiled/query/criteria.js +67 -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 +35 -0
  124. package/transpiled/query/options.js.map +1 -0
  125. package/transpiled/query/property.d.ts +16 -0
  126. package/transpiled/query/property.js +30 -0
  127. package/transpiled/query/property.js.map +1 -0
  128. package/transpiled/query.d.ts +9 -0
  129. package/transpiled/query.js +57 -0
  130. package/transpiled/query.js.map +1 -0
  131. package/transpiled/receiver.d.ts +20 -0
  132. package/transpiled/receiver.js +113 -0
  133. package/transpiled/receiver.js.map +1 -0
  134. package/transpiled/reflection.d.ts +9 -0
  135. package/transpiled/reflection.js +13 -0
  136. package/transpiled/reflection.js.map +1 -0
  137. package/transpiled/regional.d.ts +22 -0
  138. package/transpiled/regional.js +55 -0
  139. package/transpiled/regional.js.map +1 -0
  140. package/transpiled/remote.d.ts +10 -0
  141. package/transpiled/remote.js +11 -0
  142. package/transpiled/remote.js.map +1 -0
  143. package/transpiled/rendering.d.ts +13 -0
  144. package/transpiled/rendering.js +21 -0
  145. package/transpiled/rendering.js.map +1 -0
  146. package/transpiled/safety.d.ts +5 -0
  147. package/transpiled/safety.js +26 -0
  148. package/transpiled/safety.js.map +1 -0
  149. package/transpiled/state.d.ts +36 -0
  150. package/transpiled/state.js +134 -0
  151. package/transpiled/state.js.map +1 -0
  152. package/transpiled/trail.d.ts +84 -0
  153. package/transpiled/trail.js +112 -0
  154. package/transpiled/trail.js.map +1 -0
  155. package/transpiled/transition.d.ts +14 -0
  156. package/transpiled/transition.js +53 -0
  157. package/transpiled/transition.js.map +1 -0
  158. package/transpiled/transmission.d.ts +8 -0
  159. package/transpiled/transmission.js +30 -0
  160. package/transpiled/transmission.js.map +1 -0
  161. package/transpiled/types/atomicity.d.ts +58 -0
  162. package/transpiled/types/atomicity.js +2 -0
  163. package/transpiled/types/atomicity.js.map +1 -0
  164. package/transpiled/types/bindings.d.ts +82 -0
  165. package/transpiled/types/bindings.js +2 -0
  166. package/transpiled/types/bindings.js.map +1 -0
  167. package/transpiled/types/bridges.d.ts +41 -0
  168. package/transpiled/types/bridges.js +2 -0
  169. package/transpiled/types/bridges.js.map +1 -0
  170. package/transpiled/types/extensions.d.ts +121 -0
  171. package/transpiled/types/extensions.js +2 -0
  172. package/transpiled/types/extensions.js.map +1 -0
  173. package/transpiled/types/inbox.d.ts +27 -0
  174. package/transpiled/types/inbox.js +2 -0
  175. package/transpiled/types/inbox.js.map +1 -0
  176. package/transpiled/types/index.d.ts +14 -0
  177. package/transpiled/types/index.js +9 -0
  178. package/transpiled/types/index.js.map +1 -0
  179. package/transpiled/types/message.d.ts +16 -0
  180. package/transpiled/types/message.js +2 -0
  181. package/transpiled/types/message.js.map +1 -0
  182. package/transpiled/types/operations.d.ts +15 -0
  183. package/transpiled/types/operations.js +2 -0
  184. package/transpiled/types/operations.js.map +1 -0
  185. package/transpiled/types/outbox.d.ts +93 -0
  186. package/transpiled/types/outbox.js +2 -0
  187. package/transpiled/types/outbox.js.map +1 -0
  188. package/transpiled/types/receiver.d.ts +9 -0
  189. package/transpiled/types/receiver.js +2 -0
  190. package/transpiled/types/receiver.js.map +1 -0
  191. package/transpiled/types/request.d.ts +123 -0
  192. package/transpiled/types/request.js +2 -0
  193. package/transpiled/types/request.js.map +1 -0
  194. package/transpiled/types/state.d.ts +9 -0
  195. package/transpiled/types/state.js +2 -0
  196. package/transpiled/types/state.js.map +1 -0
  197. package/transpiled/types/storages.d.ts +160 -0
  198. package/transpiled/types/storages.js +2 -0
  199. package/transpiled/types/storages.js.map +1 -0
  200. package/transpiled/unmanaged.d.ts +5 -0
  201. package/transpiled/unmanaged.js +7 -0
  202. package/transpiled/unmanaged.js.map +1 -0
  203. package/src/assignment.js +0 -31
  204. package/src/call.js +0 -42
  205. package/src/cascade.js +0 -35
  206. package/src/component.js +0 -41
  207. package/src/composition.js +0 -25
  208. package/src/connector.js +0 -183
  209. package/src/context.js +0 -55
  210. package/src/contract/conditions.js +0 -21
  211. package/src/contract/index.js +0 -7
  212. package/src/contract/reply.js +0 -25
  213. package/src/contract/request.js +0 -67
  214. package/src/contract/schemas/error.yaml +0 -9
  215. package/src/contract/schemas/index.js +0 -7
  216. package/src/contract/schemas/query.yaml +0 -30
  217. package/src/discovery.js +0 -44
  218. package/src/emission.js +0 -23
  219. package/src/entities/changeset.js +0 -38
  220. package/src/entities/entity.js +0 -74
  221. package/src/entities/factory.js +0 -33
  222. package/src/entities/index.js +0 -5
  223. package/src/entities/set.js +0 -15
  224. package/src/event.js +0 -40
  225. package/src/exceptions.js +0 -100
  226. package/src/exposition.js +0 -27
  227. package/src/index.js +0 -47
  228. package/src/locator.js +0 -54
  229. package/src/observation.js +0 -12
  230. package/src/operation.js +0 -80
  231. package/src/query/criteria.js +0 -41
  232. package/src/query/options.js +0 -40
  233. package/src/query.js +0 -41
  234. package/src/receiver.js +0 -61
  235. package/src/reflection.js +0 -28
  236. package/src/remote.js +0 -17
  237. package/src/state.js +0 -103
  238. package/src/transition.js +0 -67
  239. package/src/transmission.js +0 -33
  240. package/test/call.fixtures.js +0 -27
  241. package/test/call.test.js +0 -46
  242. package/test/component.fixtures.js +0 -21
  243. package/test/component.test.js +0 -40
  244. package/test/connector.fixtures.js +0 -40
  245. package/test/connector.test.js +0 -176
  246. package/test/context.fixtures.js +0 -18
  247. package/test/context.test.js +0 -29
  248. package/test/contract/conditions.test.js +0 -26
  249. package/test/contract/contract.fixtures.js +0 -33
  250. package/test/contract/request.test.js +0 -112
  251. package/test/emission.fixtures.js +0 -17
  252. package/test/emission.test.js +0 -35
  253. package/test/entities/entity.fixtures.js +0 -29
  254. package/test/entities/entity.test.js +0 -65
  255. package/test/entities/factory.fixtures.js +0 -18
  256. package/test/entities/factory.test.js +0 -48
  257. package/test/entities/set.fixtures.js +0 -11
  258. package/test/entities/set.test.js +0 -12
  259. package/test/event.fixtures.js +0 -29
  260. package/test/event.test.js +0 -118
  261. package/test/locator.test.js +0 -113
  262. package/test/query.fixtures.js +0 -100
  263. package/test/query.test.js +0 -86
  264. package/test/receiver.fixtures.js +0 -23
  265. package/test/receiver.test.js +0 -95
  266. package/test/reflection.test.js +0 -30
  267. package/test/state.fixtures.js +0 -47
  268. package/test/state.test.js +0 -46
  269. package/test/transmission.fixtures.js +0 -15
  270. package/test/transmission.test.js +0 -46
  271. package/types/bindings.d.ts +0 -40
  272. package/types/bridges.ts +0 -30
  273. package/types/component.d.ts +0 -9
  274. package/types/connector.d.ts +0 -18
  275. package/types/context.d.ts +0 -21
  276. package/types/entity.d.ts +0 -46
  277. package/types/event.d.ts +0 -11
  278. package/types/exception.d.ts +0 -4
  279. package/types/extensions.d.ts +0 -29
  280. package/types/index.ts +0 -14
  281. package/types/locator.d.ts +0 -13
  282. package/types/message.d.ts +0 -3
  283. package/types/operations.d.ts +0 -2
  284. package/types/query.d.ts +0 -15
  285. package/types/receiver.d.ts +0 -12
  286. package/types/reflection.d.ts +0 -14
  287. package/types/request.d.ts +0 -23
  288. package/types/state.d.ts +0 -35
  289. package/types/storages.d.ts +0 -71
@@ -0,0 +1,230 @@
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
+ /** the process that took a call does not serve the operation it names; another may */
36
+ Unserved: 408,
37
+ /** a chain that came back to where it had been, or went further than a chain goes */
38
+ Loop: 500,
39
+ /** a component asked for something its manifest does not declare */
40
+ Misuse: 600,
41
+ /** a run command pauses what nothing takes again: `pause` with no `resume` */
42
+ Irresumable: 601,
43
+ /** a call to a component nothing this process was given states */
44
+ Unstated: 602,
45
+ /** what an operation continued by an extension was answered cannot be kept: a stream */
46
+ Unrecordable: 603,
47
+ /** a call to an operation that is made once, made by a transition that is retried */
48
+ Unrepeatable: 604
49
+ };
50
+ export class Exception {
51
+ code;
52
+ message;
53
+ cause;
54
+ constructor(code, message, cause) {
55
+ this.code = code;
56
+ this.message = message;
57
+ if (cause !== undefined)
58
+ this.cause = cause;
59
+ }
60
+ }
61
+ export class SystemException extends Exception {
62
+ stack;
63
+ constructor(error) {
64
+ super(codes.System, typeof error === 'string' ? error : error.message);
65
+ if (typeof error !== 'string' && error.stack !== undefined)
66
+ this.stack = error.stack;
67
+ }
68
+ }
69
+ /**
70
+ * A call refused for where it has been rather than for what it says. Named, and so permanent:
71
+ * the chain is deterministic, and another attempt reproduces it hop for hop.
72
+ */
73
+ export class LoopException extends Exception {
74
+ /** the whole chain, so what is set aside can be read without guessing */
75
+ trail;
76
+ constructor(message, trail) {
77
+ super(codes.Loop, message);
78
+ this.trail = trail;
79
+ }
80
+ }
81
+ export class ContractException extends Exception {
82
+ constructor(code, error, cause) {
83
+ super(code ?? codes.Contract, typeof error === 'string' ? error : (error?.message ?? ''), cause);
84
+ if (typeof error === 'object' && error !== null)
85
+ for (const k of [
86
+ 'keyword',
87
+ 'instancePath',
88
+ 'schemaPath',
89
+ 'params',
90
+ 'propertyName'
91
+ ])
92
+ if (k in error)
93
+ this[k] = error[k];
94
+ }
95
+ }
96
+ export class RequestContractException extends ContractException {
97
+ constructor(error, cause) {
98
+ super(codes.RequestContract, error, cause);
99
+ }
100
+ }
101
+ export class ResponseContractException extends ContractException {
102
+ constructor(error, cause) {
103
+ super(codes.ResponseContract, error, cause);
104
+ }
105
+ }
106
+ export class EntityContractException extends ContractException {
107
+ constructor(error, cause) {
108
+ super(codes.EntityContract, error, cause);
109
+ }
110
+ }
111
+ export class EntityGuardException extends ContractException {
112
+ constructor(name, cause) {
113
+ super(codes.EntityGuard, name, cause);
114
+ }
115
+ }
116
+ function derive(name) {
117
+ const classname = name + 'Exception';
118
+ const derived = class extends Exception {
119
+ constructor(message, cause) {
120
+ super(codes[name], message === undefined ? classname : `${classname}: ${message}`, cause);
121
+ }
122
+ };
123
+ // the name is the class's own, and a class expression has none worth reporting
124
+ Object.defineProperty(derived, 'name', { value: classname });
125
+ return derived;
126
+ }
127
+ export const RequestSyntaxException = derive('RequestSyntax');
128
+ export const RequestConflictException = derive('RequestConflict');
129
+ export const QuerySyntaxException = derive('QuerySyntax');
130
+ export const StateException = derive('State');
131
+ export const StateNotFoundException = derive('StateNotFound');
132
+ export const StatePreconditionException = derive('StatePrecondition');
133
+ export const StateConcurrencyException = derive('StateConcurrency');
134
+ export const StateInitializationException = derive('StateInitialization');
135
+ export const DuplicateException = derive('Duplicate');
136
+ export const DuplicateCallException = derive('DuplicateCall');
137
+ export const StateHistoryException = derive('StateHistory');
138
+ export const CommunicationException = derive('Communication');
139
+ export const TransmissionException = derive('Transmission');
140
+ export const EndpointException = derive('Endpoint');
141
+ export const AddresseeException = derive('Addressee');
142
+ export const AbandonedException = derive('Abandoned');
143
+ export const DisposedException = derive('Disposed');
144
+ export const SafetyException = derive('Safety');
145
+ export const UnreachableException = derive('Unreachable');
146
+ export const UnservedException = derive('Unserved');
147
+ export const MisuseException = derive('Misuse');
148
+ export const IrresumableException = derive('Irresumable');
149
+ export const UnstatedException = derive('Unstated');
150
+ export const UnrecordableException = derive('Unrecordable');
151
+ export const UnrepeatableException = derive('Unrepeatable');
152
+ export const names = swap(codes);
153
+ // #endregion
154
+ /**
155
+ * Whether a failure means the same thing on a later attempt.
156
+ *
157
+ * Every code answers, and the answer is here rather than inferred: `Record<keyof typeof codes>`
158
+ * refuses to compile until a code added later says which it is. What core names, core raised on
159
+ * purpose — a contract does not start fitting, a version that has passed does not come back.
160
+ * `System` is the exception that proves it: it is a code like any other, and what it wraps is
161
+ * whatever reached core from below, which is the kind that passes.
162
+ */
163
+ const OUTCOME = {
164
+ // whatever the algorithm or a connector threw: core neither chose it nor can read it
165
+ System: 'transient',
166
+ Contract: 'permanent',
167
+ RequestSyntax: 'permanent',
168
+ RequestContract: 'permanent',
169
+ RequestConflict: 'permanent',
170
+ ResponseContract: 'permanent',
171
+ EntityContract: 'permanent',
172
+ EntityGuard: 'permanent',
173
+ QuerySyntax: 'permanent',
174
+ State: 'permanent',
175
+ // an event about an entity can outrun the one that creates it; nothing promises order
176
+ StateNotFound: 'transient',
177
+ // an entity's version only grows, so one that has passed does not start matching
178
+ StatePrecondition: 'permanent',
179
+ // the compare-and-swap lost, which is the case a later attempt exists for
180
+ StateConcurrency: 'transient',
181
+ StateInitialization: 'permanent',
182
+ Duplicate: 'permanent',
183
+ // a call that has been made stays made: another attempt is refused by the same record
184
+ DuplicateCall: 'permanent',
185
+ // history a storage has let go of does not come back
186
+ StateHistory: 'permanent',
187
+ Communication: 'transient',
188
+ // nothing is listening on that queue yet — a deployment in progress, most of the time
189
+ Transmission: 'transient',
190
+ // its sibling, and the other way round: nothing carried the call is a moment,
191
+ // there is nothing to carry it to is a fact
192
+ Endpoint: 'permanent',
193
+ // a process that lost its broker connection claims its name again once it is restored
194
+ Addressee: 'transient',
195
+ // what the caller gave up on may have run, and may run yet
196
+ Abandoned: 'transient',
197
+ // the tree is gone and a resume builds another, so the same context never works again
198
+ Disposed: 'permanent',
199
+ // a transition does not become an observation, and the request goes on saying it only reads
200
+ Safety: 'permanent',
201
+ // a replica that is starting, restarting or being deployed is one that answers in a moment
202
+ Unreachable: 'transient',
203
+ // a component is replaced a process at a time, and a process of its other release may serve it
204
+ Unserved: 'transient',
205
+ // the chain is deterministic, so another attempt walks it again: a retry is another cycle
206
+ Loop: 'permanent',
207
+ // what a component did not declare, it does not declare on the next attempt either
208
+ Misuse: 'permanent',
209
+ // the component is refused at start, so nothing reaches it to be attempted twice
210
+ Irresumable: 'permanent',
211
+ // a remote is built once and held, so what this process was not given, it is not given later
212
+ Unstated: 'permanent',
213
+ // the same step answers with the same kind of thing on the next attempt, and is refused again
214
+ Unrecordable: 'permanent',
215
+ // a transition that is retried is retried on the next attempt too, and makes the same call
216
+ Unrepeatable: 'permanent'
217
+ };
218
+ const PERMANENT = new Set(Object.entries(OUTCOME)
219
+ .filter(([, outcome]) => outcome === 'permanent')
220
+ .map(([name]) => codes[name]));
221
+ /**
222
+ * Takes `unknown` because a caller has caught something rather than been handed an `Exception`.
223
+ * Anything core did not raise — an error from a driver, a rejection with no code at all — is not
224
+ * on the list, and is therefore worth trying again.
225
+ */
226
+ export function permanent(exception) {
227
+ const code = exception?.code;
228
+ return code !== undefined && PERMANENT.has(code);
229
+ }
230
+ //# sourceMappingURL=exceptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../source/exceptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAGtC,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,MAAM,EAAE,CAAC;IAET,QAAQ,EAAE,GAAG;IACb,aAAa,EAAE,GAAG;IAClB,eAAe,EAAE,GAAG;IACpB,eAAe,EAAE,GAAG;IACpB,gBAAgB,EAAE,GAAG;IACrB,cAAc,EAAE,GAAG;IACnB,WAAW,EAAE,GAAG;IAChB,WAAW,EAAE,GAAG;IAEhB,KAAK,EAAE,GAAG;IACV,aAAa,EAAE,GAAG;IAClB,iBAAiB,EAAE,GAAG;IACtB,gBAAgB,EAAE,GAAG;IACrB,mBAAmB,EAAE,GAAG;IACxB,SAAS,EAAE,GAAG;IACd,8DAA8D;IAC9D,aAAa,EAAE,GAAG;IAClB,+EAA+E;IAC/E,YAAY,EAAE,GAAG;IAEjB,aAAa,EAAE,GAAG;IAClB,YAAY,EAAE,GAAG;IACjB,QAAQ,EAAE,GAAG;IACb,oDAAoD;IACpD,SAAS,EAAE,GAAG;IACd,mEAAmE;IACnE,SAAS,EAAE,GAAG;IACd,qFAAqF;IACrF,QAAQ,EAAE,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E,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,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;IACrE,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,IAAI,CAAC,OAAO,GAAG,CAAC;QAC3B,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QAEtB,IAAI,IAAI,KAAK,IAAI;YAAE,OAAM;QAEzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,SAAS,GAAG,OA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AAC,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,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,SAA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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,G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