@toa.io/core 1.0.0-alpha.29 → 1.0.0-alpha.291

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 (304) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/package.json +22 -12
  3. package/source/assignment.ts +27 -0
  4. package/source/call.ts +63 -0
  5. package/source/cascade.ts +32 -0
  6. package/source/component.ts +83 -0
  7. package/source/composition.ts +27 -0
  8. package/source/connector.ts +217 -0
  9. package/source/context.ts +68 -0
  10. package/source/contract/contract.ts +23 -0
  11. package/source/contract/index.ts +2 -0
  12. package/source/contract/reply.ts +56 -0
  13. package/source/contract/request.ts +140 -0
  14. package/source/contract/schemas.ts +39 -0
  15. package/source/discovery.ts +53 -0
  16. package/source/effect.ts +14 -0
  17. package/source/emission.ts +21 -0
  18. package/source/entities/changeset.ts +37 -0
  19. package/source/entities/entity.ts +137 -0
  20. package/source/entities/factory.ts +52 -0
  21. package/source/entities/index.ts +4 -0
  22. package/source/entities/newid.ts +9 -0
  23. package/source/entities/set.ts +27 -0
  24. package/source/event.ts +57 -0
  25. package/source/exceptions.ts +133 -0
  26. package/source/exposition.ts +33 -0
  27. package/source/guard.ts +16 -0
  28. package/source/index.ts +36 -0
  29. package/source/locator.ts +37 -0
  30. package/source/observation.ts +16 -0
  31. package/source/operation.ts +139 -0
  32. package/source/outbox/index.ts +1 -0
  33. package/source/outbox/outbox.ts +341 -0
  34. package/source/query/criteria.ts +90 -0
  35. package/source/query/options.ts +35 -0
  36. package/source/query.ts +67 -0
  37. package/source/receiver.ts +120 -0
  38. package/source/reflection.ts +20 -0
  39. package/source/remote.ts +20 -0
  40. package/source/state.ts +179 -0
  41. package/source/transition.ts +79 -0
  42. package/source/transmission.ts +38 -0
  43. package/source/types/atomicity.ts +63 -0
  44. package/source/types/bindings.ts +59 -0
  45. package/source/types/bridges.ts +54 -0
  46. package/source/types/extensions.ts +89 -0
  47. package/source/types/index.ts +14 -0
  48. package/{types/message.d.ts → source/types/message.ts} +2 -0
  49. package/source/types/operations.ts +31 -0
  50. package/source/types/outbox.ts +35 -0
  51. package/source/types/receiver.ts +10 -0
  52. package/source/types/request.ts +54 -0
  53. package/source/types/state.ts +9 -0
  54. package/source/types/storages.ts +134 -0
  55. package/source/unmanaged.ts +8 -0
  56. package/test/call.fixtures.js +10 -12
  57. package/test/call.test.js +42 -9
  58. package/test/component.fixtures.js +5 -8
  59. package/test/component.test.js +27 -10
  60. package/test/connector.fixtures.js +29 -13
  61. package/test/connector.test.js +128 -38
  62. package/test/context.fixtures.js +8 -12
  63. package/test/context.test.js +19 -8
  64. package/test/contract/conditions.test.js +15 -9
  65. package/test/contract/contract.fixtures.js +11 -16
  66. package/test/contract/request.test.js +130 -46
  67. package/test/discovery.test.js +71 -0
  68. package/test/emission.fixtures.js +6 -10
  69. package/test/emission.test.js +37 -12
  70. package/test/entities/entity.fixtures.js +11 -16
  71. package/test/entities/entity.test.js +105 -50
  72. package/test/entities/factory.fixtures.js +26 -13
  73. package/test/entities/factory.test.js +68 -17
  74. package/test/entities/set.fixtures.js +6 -8
  75. package/test/entities/set.test.js +6 -5
  76. package/test/event.fixtures.js +9 -14
  77. package/test/event.test.js +78 -34
  78. package/test/locator.test.js +32 -25
  79. package/test/outbox.test.js +202 -0
  80. package/test/query.fixtures.js +1 -5
  81. package/test/query.test.js +111 -14
  82. package/test/receiver.fixtures.js +9 -12
  83. package/test/receiver.test.js +80 -31
  84. package/test/reflection.test.js +9 -8
  85. package/test/state.fixtures.js +33 -31
  86. package/test/state.test.js +135 -19
  87. package/test/transmission.fixtures.js +4 -6
  88. package/test/transmission.test.js +47 -16
  89. package/transpiled/assignment.d.ts +6 -0
  90. package/transpiled/assignment.js +20 -0
  91. package/transpiled/assignment.js.map +1 -0
  92. package/transpiled/call.d.ts +10 -0
  93. package/transpiled/call.js +52 -0
  94. package/transpiled/call.js.map +1 -0
  95. package/transpiled/cascade.d.ts +7 -0
  96. package/transpiled/cascade.js +28 -0
  97. package/transpiled/cascade.js.map +1 -0
  98. package/transpiled/component.d.ts +15 -0
  99. package/transpiled/component.js +61 -0
  100. package/transpiled/component.js.map +1 -0
  101. package/transpiled/composition.d.ts +6 -0
  102. package/transpiled/composition.js +23 -0
  103. package/transpiled/composition.js.map +1 -0
  104. package/transpiled/connector.d.ts +47 -0
  105. package/transpiled/connector.js +185 -0
  106. package/transpiled/connector.js.map +1 -0
  107. package/transpiled/context.d.ts +18 -0
  108. package/transpiled/context.js +42 -0
  109. package/transpiled/context.js.map +1 -0
  110. package/transpiled/contract/contract.d.ts +10 -0
  111. package/transpiled/contract/contract.js +14 -0
  112. package/transpiled/contract/contract.js.map +1 -0
  113. package/transpiled/contract/index.d.ts +2 -0
  114. package/transpiled/contract/index.js +3 -0
  115. package/transpiled/contract/index.js.map +1 -0
  116. package/transpiled/contract/reply.d.ts +7 -0
  117. package/transpiled/contract/reply.js +48 -0
  118. package/transpiled/contract/reply.js.map +1 -0
  119. package/transpiled/contract/request.d.ts +29 -0
  120. package/transpiled/contract/request.js +103 -0
  121. package/transpiled/contract/request.js.map +1 -0
  122. package/transpiled/contract/schemas.d.ts +4 -0
  123. package/transpiled/contract/schemas.js +36 -0
  124. package/transpiled/contract/schemas.js.map +1 -0
  125. package/transpiled/discovery.d.ts +12 -0
  126. package/transpiled/discovery.js +34 -0
  127. package/transpiled/discovery.js.map +1 -0
  128. package/transpiled/effect.d.ts +5 -0
  129. package/transpiled/effect.js +11 -0
  130. package/transpiled/effect.js.map +1 -0
  131. package/transpiled/emission.d.ts +8 -0
  132. package/transpiled/emission.js +14 -0
  133. package/transpiled/emission.js.map +1 -0
  134. package/transpiled/entities/changeset.d.ts +10 -0
  135. package/transpiled/entities/changeset.js +27 -0
  136. package/transpiled/entities/changeset.js.map +1 -0
  137. package/transpiled/entities/entity.d.ts +19 -0
  138. package/transpiled/entities/entity.js +109 -0
  139. package/transpiled/entities/entity.js.map +1 -0
  140. package/transpiled/entities/factory.d.ts +22 -0
  141. package/transpiled/entities/factory.js +34 -0
  142. package/transpiled/entities/factory.js.map +1 -0
  143. package/transpiled/entities/index.d.ts +4 -0
  144. package/transpiled/entities/index.js +5 -0
  145. package/transpiled/entities/index.js.map +1 -0
  146. package/transpiled/entities/newid.d.ts +1 -0
  147. package/transpiled/entities/newid.js +7 -0
  148. package/transpiled/entities/newid.js.map +1 -0
  149. package/transpiled/entities/set.d.ts +10 -0
  150. package/transpiled/entities/set.js +19 -0
  151. package/transpiled/entities/set.js.map +1 -0
  152. package/transpiled/event.d.ts +14 -0
  153. package/transpiled/event.js +38 -0
  154. package/transpiled/event.js.map +1 -0
  155. package/transpiled/exceptions.d.ts +61 -0
  156. package/transpiled/exceptions.js +93 -0
  157. package/transpiled/exceptions.js.map +1 -0
  158. package/transpiled/exposition.d.ts +18 -0
  159. package/transpiled/exposition.js +18 -0
  160. package/transpiled/exposition.js.map +1 -0
  161. package/transpiled/guard.d.ts +7 -0
  162. package/transpiled/guard.js +12 -0
  163. package/transpiled/guard.js.map +1 -0
  164. package/transpiled/index.d.ts +35 -0
  165. package/transpiled/index.js +29 -0
  166. package/transpiled/index.js.map +1 -0
  167. package/transpiled/locator.d.ts +12 -0
  168. package/transpiled/locator.js +32 -0
  169. package/transpiled/locator.js.map +1 -0
  170. package/transpiled/observation.d.ts +5 -0
  171. package/transpiled/observation.js +12 -0
  172. package/transpiled/observation.js.map +1 -0
  173. package/transpiled/operation.d.ts +49 -0
  174. package/transpiled/operation.js +78 -0
  175. package/transpiled/operation.js.map +1 -0
  176. package/transpiled/outbox/index.d.ts +1 -0
  177. package/transpiled/outbox/index.js +2 -0
  178. package/transpiled/outbox/index.js.map +1 -0
  179. package/transpiled/outbox/outbox.d.ts +46 -0
  180. package/transpiled/outbox/outbox.js +268 -0
  181. package/transpiled/outbox/outbox.js.map +1 -0
  182. package/transpiled/query/criteria.d.ts +6 -0
  183. package/transpiled/query/criteria.js +74 -0
  184. package/transpiled/query/criteria.js.map +1 -0
  185. package/transpiled/query/options.d.ts +3 -0
  186. package/transpiled/query/options.js +27 -0
  187. package/transpiled/query/options.js.map +1 -0
  188. package/transpiled/query.d.ts +9 -0
  189. package/transpiled/query.js +57 -0
  190. package/transpiled/query.js.map +1 -0
  191. package/transpiled/receiver.d.ts +20 -0
  192. package/transpiled/receiver.js +92 -0
  193. package/transpiled/receiver.js.map +1 -0
  194. package/transpiled/reflection.d.ts +9 -0
  195. package/transpiled/reflection.js +13 -0
  196. package/transpiled/reflection.js.map +1 -0
  197. package/transpiled/remote.d.ts +10 -0
  198. package/transpiled/remote.js +12 -0
  199. package/transpiled/remote.js.map +1 -0
  200. package/transpiled/state.d.ts +33 -0
  201. package/transpiled/state.js +126 -0
  202. package/transpiled/state.js.map +1 -0
  203. package/transpiled/transition.d.ts +14 -0
  204. package/transpiled/transition.js +51 -0
  205. package/transpiled/transition.js.map +1 -0
  206. package/transpiled/transmission.d.ts +8 -0
  207. package/transpiled/transmission.js +30 -0
  208. package/transpiled/transmission.js.map +1 -0
  209. package/transpiled/types/atomicity.d.ts +56 -0
  210. package/transpiled/types/atomicity.js +2 -0
  211. package/transpiled/types/atomicity.js.map +1 -0
  212. package/transpiled/types/bindings.d.ts +42 -0
  213. package/transpiled/types/bindings.js +2 -0
  214. package/transpiled/types/bindings.js.map +1 -0
  215. package/transpiled/types/bridges.d.ts +38 -0
  216. package/transpiled/types/bridges.js +2 -0
  217. package/transpiled/types/bridges.js.map +1 -0
  218. package/transpiled/types/extensions.d.ts +62 -0
  219. package/transpiled/types/extensions.js +2 -0
  220. package/transpiled/types/extensions.js.map +1 -0
  221. package/transpiled/types/index.d.ts +13 -0
  222. package/transpiled/types/index.js +8 -0
  223. package/transpiled/types/index.js.map +1 -0
  224. package/transpiled/types/message.d.ts +5 -0
  225. package/transpiled/types/message.js +2 -0
  226. package/transpiled/types/message.js.map +1 -0
  227. package/transpiled/types/operations.d.ts +15 -0
  228. package/transpiled/types/operations.js +2 -0
  229. package/transpiled/types/operations.js.map +1 -0
  230. package/transpiled/types/outbox.d.ts +28 -0
  231. package/transpiled/types/outbox.js +2 -0
  232. package/transpiled/types/outbox.js.map +1 -0
  233. package/transpiled/types/receiver.d.ts +9 -0
  234. package/transpiled/types/receiver.js +2 -0
  235. package/transpiled/types/receiver.js.map +1 -0
  236. package/transpiled/types/request.d.ts +55 -0
  237. package/transpiled/types/request.js +2 -0
  238. package/transpiled/types/request.js.map +1 -0
  239. package/transpiled/types/state.d.ts +9 -0
  240. package/transpiled/types/state.js +2 -0
  241. package/transpiled/types/state.js.map +1 -0
  242. package/transpiled/types/storages.d.ts +111 -0
  243. package/transpiled/types/storages.js +2 -0
  244. package/transpiled/types/storages.js.map +1 -0
  245. package/transpiled/unmanaged.d.ts +5 -0
  246. package/transpiled/unmanaged.js +7 -0
  247. package/transpiled/unmanaged.js.map +1 -0
  248. package/tsconfig.json +10 -0
  249. package/tsconfig.tsbuildinfo +1 -0
  250. package/src/assignment.js +0 -31
  251. package/src/call.js +0 -42
  252. package/src/cascade.js +0 -36
  253. package/src/component.js +0 -41
  254. package/src/composition.js +0 -25
  255. package/src/connector.js +0 -183
  256. package/src/context.js +0 -55
  257. package/src/contract/conditions.js +0 -21
  258. package/src/contract/index.js +0 -7
  259. package/src/contract/reply.js +0 -25
  260. package/src/contract/request.js +0 -67
  261. package/src/contract/schemas/error.yaml +0 -9
  262. package/src/contract/schemas/index.js +0 -7
  263. package/src/contract/schemas/query.yaml +0 -30
  264. package/src/discovery.js +0 -44
  265. package/src/emission.js +0 -23
  266. package/src/entities/changeset.js +0 -43
  267. package/src/entities/entity.js +0 -73
  268. package/src/entities/factory.js +0 -33
  269. package/src/entities/index.js +0 -5
  270. package/src/entities/set.js +0 -15
  271. package/src/event.js +0 -40
  272. package/src/exceptions.js +0 -100
  273. package/src/exposition.js +0 -27
  274. package/src/index.js +0 -47
  275. package/src/locator.js +0 -54
  276. package/src/observation.js +0 -20
  277. package/src/operation.js +0 -69
  278. package/src/query/criteria.js +0 -41
  279. package/src/query/options.js +0 -40
  280. package/src/query.js +0 -41
  281. package/src/receiver.js +0 -65
  282. package/src/reflection.js +0 -28
  283. package/src/remote.js +0 -17
  284. package/src/state.js +0 -99
  285. package/src/transition.js +0 -73
  286. package/src/transmission.js +0 -33
  287. package/types/bindings.d.ts +0 -40
  288. package/types/bridges.ts +0 -30
  289. package/types/component.d.ts +0 -9
  290. package/types/connector.d.ts +0 -18
  291. package/types/context.d.ts +0 -21
  292. package/types/entity.d.ts +0 -46
  293. package/types/event.d.ts +0 -11
  294. package/types/exception.d.ts +0 -4
  295. package/types/extensions.d.ts +0 -29
  296. package/types/index.ts +0 -14
  297. package/types/locator.d.ts +0 -13
  298. package/types/operations.d.ts +0 -2
  299. package/types/query.d.ts +0 -15
  300. package/types/receiver.d.ts +0 -12
  301. package/types/reflection.d.ts +0 -14
  302. package/types/request.d.ts +0 -23
  303. package/types/state.d.ts +0 -35
  304. package/types/storages.d.ts +0 -71
package/src/locator.js DELETED
@@ -1,54 +0,0 @@
1
- 'use strict'
2
-
3
- const { concat } = require('@toa.io/generic')
4
-
5
- /**
6
- * @implements {toa.core.Locator}
7
- */
8
- class Locator {
9
- name
10
- namespace
11
-
12
- id
13
- label
14
- uppercase
15
- lowercase
16
-
17
- /**
18
- * @param {string} name
19
- * @param {string} [namespace]
20
- */
21
- constructor (name, namespace) {
22
- if (name === undefined) throw new TypeError('Locator name must be defined')
23
-
24
- this.name = name
25
- this.namespace = namespace
26
-
27
- this.id = concat(namespace, '.') + name
28
- this.label = (concat(namespace, '-') + name).toLowerCase()
29
- this.uppercase = (concat(namespace, '_') + name).toUpperCase()
30
- this.lowercase = (concat(namespace, '_') + name).toLowerCase()
31
- }
32
-
33
- hostname (prefix) {
34
- return concat(prefix?.toLowerCase(), '-') + this.label
35
- }
36
-
37
- /**
38
- * @param {string} string
39
- * @returns {Locator}
40
- */
41
- static parse (string) {
42
- const [namespace, name] = string.split(DOT)
43
-
44
- if (name === undefined) {
45
- return new Locator(namespace)
46
- } else {
47
- return new Locator(name, namespace)
48
- }
49
- }
50
- }
51
-
52
- const DOT = '.'
53
-
54
- exports.Locator = Locator
@@ -1,20 +0,0 @@
1
- 'use strict'
2
-
3
- const { Operation } = require('./operation')
4
-
5
- class Observation extends Operation {
6
- async acquire (store) {
7
- const scope = await this.query(store.request.query)
8
- const state = scope === null ? null : scope.get()
9
-
10
- store.scope = scope
11
- store.state = state
12
- }
13
-
14
- async run (store) {
15
- if (store.scope === null) store.reply = null
16
- else await super.run(store)
17
- }
18
- }
19
-
20
- exports.Observation = Observation
package/src/operation.js DELETED
@@ -1,69 +0,0 @@
1
- 'use strict'
2
-
3
- const { Connector } = require('./connector')
4
- const { SystemException } = require('./exceptions')
5
-
6
- class Operation extends Connector {
7
- scope
8
-
9
- #cascade
10
- #contracts
11
- #query
12
- #scope
13
-
14
- constructor (cascade, scope, contracts, query, definition) {
15
- super()
16
-
17
- this.scope = scope
18
-
19
- this.#cascade = cascade
20
- this.#contracts = contracts
21
- this.#query = query
22
- this.#scope = definition.scope
23
-
24
- this.depends(cascade)
25
- }
26
-
27
- async invoke (request) {
28
- try {
29
- if (request.authentic !== true) this.#contracts.request.fit(request)
30
- if ('query' in request) request.query = this.#query.parse(request.query)
31
-
32
- const store = { request }
33
-
34
- return await this.process(store)
35
- } catch (e) {
36
- const exception = e instanceof Error ? new SystemException(e) : e
37
-
38
- return { exception }
39
- }
40
- }
41
-
42
- async process (store) {
43
- await this.acquire(store)
44
- await this.run(store)
45
- await this.commit(store)
46
-
47
- return store.reply
48
- }
49
-
50
- async acquire () {}
51
-
52
- async run (store) {
53
- const { request, state } = store
54
- // noinspection UnnecessaryLocalVariableJS
55
- const reply = await this.#cascade.run(request.input, state) || {}
56
-
57
- // this.#contracts.reply.fit(reply)
58
-
59
- store.reply = reply
60
- }
61
-
62
- async commit () {}
63
-
64
- async query (query) {
65
- return this.scope[this.#scope](query)
66
- }
67
- }
68
-
69
- exports.Operation = Operation
@@ -1,41 +0,0 @@
1
- 'use strict'
2
-
3
- const { parse } = require('@rsql/parser')
4
- const { QuerySyntaxException } = require('../exceptions')
5
-
6
- const criteria = (criteria, properties) => {
7
- let ast
8
-
9
- try {
10
- ast = parse(criteria)
11
- } catch (e) {
12
- throw new QuerySyntaxException(e.message)
13
- }
14
-
15
- if (properties !== undefined) coerce(ast, properties)
16
-
17
- return ast
18
- }
19
-
20
- const coerce = (node, properties) => {
21
- if (node.type === 'COMPARISON' && node.left?.type === 'SELECTOR' && node.right?.type === 'VALUE') {
22
- const property = properties[node.left.selector]
23
-
24
- if (property === undefined) {
25
- throw new QuerySyntaxException(`Criteria selector '${node.left.selector}' is not defined`)
26
- }
27
-
28
- if (COERCE[property.type] !== undefined) { node.right.value = COERCE[property.type](node.right.value) }
29
- } else {
30
- if (node.left !== undefined) coerce(node.left, properties)
31
- if (node.right !== undefined) coerce(node.right, properties)
32
- }
33
- }
34
-
35
- const COERCE = {
36
- number: Number.parseFloat,
37
- integer: Number.parseInt,
38
- boolean: (value) => value === 'true'
39
- }
40
-
41
- exports.criteria = criteria
@@ -1,40 +0,0 @@
1
- 'use strict'
2
-
3
- const { QuerySyntaxException } = require('../exceptions')
4
-
5
- const options = (options, properties, system) => {
6
- if (options.sort !== undefined) options.sort = sort(options.sort, properties)
7
-
8
- if (options.projection !== undefined) projection(options.projection, properties)
9
-
10
- return options
11
- }
12
-
13
- const sort = (sort, properties) => {
14
- const result = []
15
-
16
- for (const sorting of sort) {
17
- const [property, direction] = sorting.split(':')
18
-
19
- if (properties[property] === undefined) {
20
- throw new QuerySyntaxException(`Sort property '${property}' is not defined`)
21
- }
22
-
23
- result.push([property, direction || 'asc'])
24
- }
25
-
26
- return result
27
- }
28
-
29
- const projection = (projection, properties) => {
30
- for (const property of projection) {
31
- if (properties[property] === undefined) {
32
- throw new QuerySyntaxException(`Projection property '${property}' is not defined`)
33
- }
34
- }
35
-
36
- if (projection.includes('_version') === false)
37
- projection.push('_version')
38
- }
39
-
40
- exports.options = options
package/src/query.js DELETED
@@ -1,41 +0,0 @@
1
- 'use strict'
2
-
3
- const { empty } = require('@toa.io/generic')
4
- const parse = { ...require('./query/criteria'), ...require('./query/options') }
5
-
6
- class Query {
7
- #properties
8
- #system
9
-
10
- constructor (properties) {
11
- this.#properties = properties
12
- this.#system = Object.keys(properties).filter((key) => properties[key].system === true)
13
- }
14
-
15
- /**
16
- * @param {toa.core.request.Query} query
17
- * @returns {toa.core.storages.Query}
18
- */
19
- parse (query) {
20
- /** @type {toa.core.storages.Query} */
21
- const result = {}
22
- const { id, version, criteria, ...rest } = query
23
-
24
- const options = this.#options(rest)
25
-
26
- if (id !== undefined) result.id = id
27
- if (version !== undefined) result.version = version
28
- if (criteria !== undefined) result.criteria = parse.criteria(criteria, this.#properties)
29
- if (options !== undefined) result.options = options
30
-
31
- return result
32
- }
33
-
34
- #options (options) {
35
- if (empty(options)) return
36
-
37
- return parse.options(options, this.#properties, this.#system)
38
- }
39
- }
40
-
41
- exports.Query = Query
package/src/receiver.js DELETED
@@ -1,65 +0,0 @@
1
- 'use strict'
2
-
3
- const { add } = require('@toa.io/generic')
4
- const { Connector } = require('./connector')
5
-
6
- /**
7
- * @implements {toa.core.Receiver}
8
- */
9
- class Receiver extends Connector {
10
- /** @type {boolean} */
11
- #conditioned
12
-
13
- /** @type {boolean} */
14
- #adaptive
15
-
16
- /** @type {string} */
17
- #endpoint
18
-
19
- /** @type {toa.core.Component} */
20
- #local
21
-
22
- /** @type {toa.core.bridges.Receiver} */
23
- #bridge
24
-
25
- /**
26
- *
27
- * @param {toa.norm.component.Receiver} definition
28
- * @param {toa.core.Component} local
29
- * @param {toa.core.bridges.Receiver} bridge
30
- */
31
- constructor (definition, local, bridge) {
32
- super()
33
-
34
- const { conditioned, adaptive, operation } = definition
35
-
36
- this.#conditioned = conditioned
37
- this.#adaptive = adaptive
38
- this.#endpoint = operation
39
-
40
- this.#local = local
41
- this.#bridge = bridge
42
-
43
- this.depends(local)
44
- if (bridge !== undefined) this.depends(bridge)
45
- }
46
-
47
- /** @hot */
48
- async receive (message) {
49
- const { payload, ...extensions } = message
50
-
51
- if (this.#conditioned && await this.#bridge.condition(payload) === false) return
52
-
53
- const request = await this.#request(payload)
54
-
55
- add(request, extensions)
56
-
57
- await this.#local.invoke(this.#endpoint, request)
58
- }
59
-
60
- async #request (payload) {
61
- return this.#adaptive ? await this.#bridge.request(payload) : { input: payload }
62
- }
63
- }
64
-
65
- exports.Receiver = Receiver
package/src/reflection.js DELETED
@@ -1,28 +0,0 @@
1
- 'use strict'
2
-
3
- const { Connector } = require('./connector')
4
-
5
- /**
6
- * @implements {toa.core.Reflection}
7
- */
8
- class Reflection extends Connector {
9
- /** @type {toa.core.reflection.Source} */
10
- #source
11
-
12
- value
13
-
14
- /**
15
- * @param {toa.core.reflection.Source} source
16
- */
17
- constructor (source) {
18
- super()
19
-
20
- this.#source = source
21
- }
22
-
23
- async open () {
24
- this.value = await this.#source()
25
- }
26
- }
27
-
28
- exports.Reflection = Reflection
package/src/remote.js DELETED
@@ -1,17 +0,0 @@
1
- 'use strict'
2
-
3
- const { console } = require('@toa.io/console')
4
-
5
- const { Component } = require('./component')
6
-
7
- class Remote extends Component {
8
- async open () {
9
- console.info(`Remote '${this.locator.id}' connected`)
10
- }
11
-
12
- async dispose () {
13
- console.info(`Remote '${this.locator.id}' disconnected`)
14
- }
15
- }
16
-
17
- exports.Remote = Remote
package/src/state.js DELETED
@@ -1,99 +0,0 @@
1
- 'use strict'
2
-
3
- const { empty } = require('@toa.io/generic')
4
-
5
- const {
6
- StatePreconditionException,
7
- StateNotFoundException
8
- } = require('./exceptions')
9
-
10
- class State {
11
- #associated
12
- #storage
13
- #entity
14
- #emission
15
-
16
- constructor (storage, entity, emission, associated) {
17
- this.#storage = storage
18
- this.#entity = entity
19
- this.#emission = emission
20
- this.#associated = associated === true
21
- }
22
-
23
- init (id) {
24
- return this.#entity.init(id)
25
- }
26
-
27
- async object (query) {
28
- const record = await this.#storage.get(query)
29
-
30
- if (record === null) {
31
- if (this.#associated && query.id !== undefined && query.version === undefined) {
32
- return this.init(query.id)
33
- } else if (query.version !== undefined) throw new StatePreconditionException()
34
- }
35
-
36
- if (record === null) {
37
- return null
38
- } else {
39
- return this.#entity.object(record)
40
- }
41
- }
42
-
43
- async objects (query) {
44
- const recordset = await this.#storage.find(query)
45
-
46
- return this.#entity.objects(recordset)
47
- }
48
-
49
- changeset (query) {
50
- return this.#entity.changeset(query)
51
- }
52
-
53
- none () {
54
- return null
55
- }
56
-
57
- async commit (state) {
58
- const event = state.event()
59
-
60
- let ok = true
61
-
62
- if (!empty(event.changeset)) {
63
- const object = state.get()
64
-
65
- ok = await this.#storage.store(object)
66
-
67
- // #20
68
- if (ok === true) {
69
- await this.#emission.emit(event)
70
- }
71
- }
72
-
73
- return ok
74
- }
75
-
76
- async apply (state) {
77
- const changeset = state.export()
78
-
79
- const result = await this.#storage.upsert(state.query, changeset)
80
-
81
- if (result === null) {
82
- if (state.query.version !== undefined) {
83
- throw new StatePreconditionException()
84
- } else {
85
- throw new StateNotFoundException()
86
- }
87
- } else {
88
- // same as above
89
- await this.#emission.emit({
90
- changeset,
91
- state: result
92
- })
93
- }
94
-
95
- return result
96
- }
97
- }
98
-
99
- exports.State = State
package/src/transition.js DELETED
@@ -1,73 +0,0 @@
1
- 'use strict'
2
-
3
- const { retry } = require('@toa.io/generic')
4
-
5
- const { Operation } = require('./operation')
6
- const {
7
- StateConcurrencyException,
8
- StateNotFoundException
9
- } = require('./exceptions')
10
-
11
- class Transition extends Operation {
12
- #concurrency
13
-
14
- constructor (cascade, scope, contract, query, definition) {
15
- super(cascade, scope, contract, query, definition)
16
-
17
- this.#concurrency = definition.concurrency
18
- }
19
-
20
- async process (store) {
21
- return retry((retry) => this.#retry(store, retry), RETRY)
22
- }
23
-
24
- async acquire (store) {
25
- const { request } = store
26
-
27
- store.scope = request.query ? await this.query(request.query) : this.scope.init()
28
-
29
- if (store.scope === null) {
30
- throw new StateNotFoundException()
31
- }
32
-
33
- store.state = store.scope.get()
34
- }
35
-
36
- async commit (store) {
37
- const {
38
- scope,
39
- state,
40
- reply,
41
- retry
42
- } = store
43
-
44
- if (reply.error !== undefined) return
45
-
46
- scope.set(state)
47
-
48
- const result = await this.scope.commit(scope)
49
-
50
- if (result === false) {
51
- if (this.#concurrency === 'retry') {
52
- return retry()
53
- } else {
54
- throw new StateConcurrencyException()
55
- }
56
- }
57
- }
58
-
59
- async #retry (store, retry) {
60
- store.retry = retry
61
-
62
- return super.process(store)
63
- }
64
- }
65
-
66
- const RETRY = {
67
- base: 10,
68
- max: 5000,
69
- dispersion: 1,
70
- retries: Infinity
71
- }
72
-
73
- exports.Transition = Transition
@@ -1,33 +0,0 @@
1
- 'use strict'
2
-
3
- const { Connector } = require('./connector')
4
- const { TransmissionException } = require('./exceptions')
5
-
6
- class Transmission extends Connector {
7
- #bindings
8
-
9
- constructor (bindings) {
10
- super()
11
-
12
- this.#bindings = bindings
13
- this.depends(bindings)
14
- }
15
-
16
- async request (request) {
17
- let reply = false
18
- let i = 0
19
-
20
- while (reply === false && i < this.#bindings.length) {
21
- reply = await this.#bindings[i].request(request)
22
- i++
23
- }
24
-
25
- if (reply === false) {
26
- throw new TransmissionException(`All (${this.#bindings.length}) bindings rejected.`)
27
- }
28
-
29
- return reply
30
- }
31
- }
32
-
33
- exports.Transmission = Transmission
@@ -1,40 +0,0 @@
1
- import * as _core from './index'
2
-
3
- declare namespace toa.core.bindings{
4
-
5
- type Properties = {
6
- async?: boolean
7
- }
8
-
9
- interface Consumer extends _core.Connector{
10
- request (request: Request): Promise<_core.Reply>
11
- }
12
-
13
- interface Emitter extends _core.Connector{
14
- emit (message: _core.Message): Promise<void>
15
- }
16
-
17
- interface Broadcast<L> extends _core.Connector{
18
- transmit<T> (label: L, payload: T): Promise<void>
19
-
20
- receive<T> (label: L, callback: (payload: T) => void | Promise<void>): Promise<void>
21
- }
22
-
23
- interface Factory{
24
- producer? (locator: _core.Locator, endpoints: Array<string>, producer: _core.Component): _core.Connector
25
-
26
- consumer? (locator: _core.Locator, endpoint: string): Consumer
27
-
28
- emitter? (locator: _core.Locator, label: string): Emitter
29
-
30
- receiver? (locator: _core.Locator, label: string, group: string, receiver: _core.Receiver): _core.Connector
31
-
32
- broadcast? (name: string, group?: string): Broadcast
33
- }
34
-
35
- }
36
-
37
- export type Emitter = toa.core.bindings.Emitter
38
- export type Factory = toa.core.bindings.Factory
39
- export type Properties = toa.core.bindings.Properties
40
- export type Broadcast<L = any> = toa.core.bindings.Broadcast<L>
package/types/bridges.ts DELETED
@@ -1,30 +0,0 @@
1
- import type { Request, Reply } from './request'
2
- import type { Context } from './context'
3
-
4
- export interface Algorithm {
5
- mount: (context?: Context) => Promise<void>
6
-
7
- execute: ((input: any, scope: object | object[]) => Promise<Reply>) |
8
- ((input: any) => Promise<Reply>) |
9
- (() => Promise<Reply>)
10
- }
11
-
12
- export interface Event {
13
- condition: (object: object) => Promise<boolean>
14
-
15
- payload: (object: object) => Promise<object>
16
- }
17
-
18
- export interface Receiver {
19
- condition: (object: object) => Promise<boolean>
20
-
21
- request: (object: object) => Promise<Request>
22
- }
23
-
24
- export interface Factory {
25
- algorithm?: (path: string, name: string, context: Context) => Algorithm
26
-
27
- event?: (path: string, label: string) => Event
28
-
29
- receiver?: (path: string, label: string) => Receiver
30
- }
@@ -1,9 +0,0 @@
1
- import { Connector } from './connector'
2
- import { Locator } from './locator'
3
- import { Request } from './request'
4
-
5
- export interface Component extends Connector{
6
- locator: Locator
7
-
8
- invoke<T = any> (endpoint: string, request: Request): Promise<T>
9
- }
@@ -1,18 +0,0 @@
1
- export class Connector {
2
- public id: string
3
- public connected: boolean
4
-
5
- public connect (): Promise<void>
6
-
7
- public disconnect (interrupt?: boolean): Promise<void>
8
-
9
- public depends (connector: Connector | Connector[]): Connector
10
-
11
- link (connector: Connector): void
12
-
13
- protected open (): Promise<void> | void
14
-
15
- protected close (): Promise<void> | void
16
-
17
- protected dispose (): Promise<void> | void
18
- }