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

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 (283) 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 +15 -0
  15. package/transpiled/component.js +148 -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 +44 -0
  93. package/transpiled/index.js +36 -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 +73 -0
  108. package/transpiled/operation.js +213 -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/remote.d.ts +10 -0
  135. package/transpiled/remote.js +11 -0
  136. package/transpiled/remote.js.map +1 -0
  137. package/transpiled/rendering.d.ts +13 -0
  138. package/transpiled/rendering.js +21 -0
  139. package/transpiled/rendering.js.map +1 -0
  140. package/transpiled/safety.d.ts +5 -0
  141. package/transpiled/safety.js +26 -0
  142. package/transpiled/safety.js.map +1 -0
  143. package/transpiled/state.d.ts +36 -0
  144. package/transpiled/state.js +131 -0
  145. package/transpiled/state.js.map +1 -0
  146. package/transpiled/trail.d.ts +78 -0
  147. package/transpiled/trail.js +112 -0
  148. package/transpiled/trail.js.map +1 -0
  149. package/transpiled/transition.d.ts +14 -0
  150. package/transpiled/transition.js +51 -0
  151. package/transpiled/transition.js.map +1 -0
  152. package/transpiled/transmission.d.ts +8 -0
  153. package/transpiled/transmission.js +30 -0
  154. package/transpiled/transmission.js.map +1 -0
  155. package/transpiled/types/atomicity.d.ts +58 -0
  156. package/transpiled/types/atomicity.js +2 -0
  157. package/transpiled/types/atomicity.js.map +1 -0
  158. package/transpiled/types/bindings.d.ts +82 -0
  159. package/transpiled/types/bindings.js +2 -0
  160. package/transpiled/types/bindings.js.map +1 -0
  161. package/transpiled/types/bridges.d.ts +41 -0
  162. package/transpiled/types/bridges.js +2 -0
  163. package/transpiled/types/bridges.js.map +1 -0
  164. package/transpiled/types/extensions.d.ts +121 -0
  165. package/transpiled/types/extensions.js +2 -0
  166. package/transpiled/types/extensions.js.map +1 -0
  167. package/transpiled/types/inbox.d.ts +27 -0
  168. package/transpiled/types/inbox.js +2 -0
  169. package/transpiled/types/inbox.js.map +1 -0
  170. package/transpiled/types/index.d.ts +14 -0
  171. package/transpiled/types/index.js +9 -0
  172. package/transpiled/types/index.js.map +1 -0
  173. package/transpiled/types/message.d.ts +16 -0
  174. package/transpiled/types/message.js +2 -0
  175. package/transpiled/types/message.js.map +1 -0
  176. package/transpiled/types/operations.d.ts +15 -0
  177. package/transpiled/types/operations.js +2 -0
  178. package/transpiled/types/operations.js.map +1 -0
  179. package/transpiled/types/outbox.d.ts +68 -0
  180. package/transpiled/types/outbox.js +2 -0
  181. package/transpiled/types/outbox.js.map +1 -0
  182. package/transpiled/types/receiver.d.ts +9 -0
  183. package/transpiled/types/receiver.js +2 -0
  184. package/transpiled/types/receiver.js.map +1 -0
  185. package/transpiled/types/request.d.ts +119 -0
  186. package/transpiled/types/request.js +2 -0
  187. package/transpiled/types/request.js.map +1 -0
  188. package/transpiled/types/state.d.ts +9 -0
  189. package/transpiled/types/state.js +2 -0
  190. package/transpiled/types/state.js.map +1 -0
  191. package/transpiled/types/storages.d.ts +154 -0
  192. package/transpiled/types/storages.js +2 -0
  193. package/transpiled/types/storages.js.map +1 -0
  194. package/transpiled/unmanaged.d.ts +5 -0
  195. package/transpiled/unmanaged.js +7 -0
  196. package/transpiled/unmanaged.js.map +1 -0
  197. package/src/assignment.js +0 -31
  198. package/src/call.js +0 -42
  199. package/src/cascade.js +0 -35
  200. package/src/component.js +0 -41
  201. package/src/composition.js +0 -25
  202. package/src/connector.js +0 -183
  203. package/src/context.js +0 -55
  204. package/src/contract/conditions.js +0 -21
  205. package/src/contract/index.js +0 -7
  206. package/src/contract/reply.js +0 -25
  207. package/src/contract/request.js +0 -67
  208. package/src/contract/schemas/error.yaml +0 -9
  209. package/src/contract/schemas/index.js +0 -7
  210. package/src/contract/schemas/query.yaml +0 -30
  211. package/src/discovery.js +0 -44
  212. package/src/emission.js +0 -23
  213. package/src/entities/changeset.js +0 -38
  214. package/src/entities/entity.js +0 -74
  215. package/src/entities/factory.js +0 -33
  216. package/src/entities/index.js +0 -5
  217. package/src/entities/set.js +0 -15
  218. package/src/event.js +0 -40
  219. package/src/exceptions.js +0 -100
  220. package/src/exposition.js +0 -27
  221. package/src/index.js +0 -47
  222. package/src/locator.js +0 -54
  223. package/src/observation.js +0 -20
  224. package/src/operation.js +0 -69
  225. package/src/query/criteria.js +0 -41
  226. package/src/query/options.js +0 -40
  227. package/src/query.js +0 -41
  228. package/src/receiver.js +0 -61
  229. package/src/reflection.js +0 -28
  230. package/src/remote.js +0 -17
  231. package/src/state.js +0 -99
  232. package/src/transition.js +0 -67
  233. package/src/transmission.js +0 -33
  234. package/test/call.fixtures.js +0 -27
  235. package/test/call.test.js +0 -46
  236. package/test/component.fixtures.js +0 -21
  237. package/test/component.test.js +0 -40
  238. package/test/connector.fixtures.js +0 -40
  239. package/test/connector.test.js +0 -176
  240. package/test/context.fixtures.js +0 -18
  241. package/test/context.test.js +0 -29
  242. package/test/contract/conditions.test.js +0 -26
  243. package/test/contract/contract.fixtures.js +0 -33
  244. package/test/contract/request.test.js +0 -112
  245. package/test/emission.fixtures.js +0 -17
  246. package/test/emission.test.js +0 -35
  247. package/test/entities/entity.fixtures.js +0 -29
  248. package/test/entities/entity.test.js +0 -65
  249. package/test/entities/factory.fixtures.js +0 -18
  250. package/test/entities/factory.test.js +0 -48
  251. package/test/entities/set.fixtures.js +0 -11
  252. package/test/entities/set.test.js +0 -12
  253. package/test/event.fixtures.js +0 -29
  254. package/test/event.test.js +0 -118
  255. package/test/locator.test.js +0 -113
  256. package/test/query.fixtures.js +0 -100
  257. package/test/query.test.js +0 -86
  258. package/test/receiver.fixtures.js +0 -23
  259. package/test/receiver.test.js +0 -95
  260. package/test/reflection.test.js +0 -30
  261. package/test/state.fixtures.js +0 -47
  262. package/test/state.test.js +0 -46
  263. package/test/transmission.fixtures.js +0 -15
  264. package/test/transmission.test.js +0 -46
  265. package/types/bindings.d.ts +0 -40
  266. package/types/bridges.ts +0 -30
  267. package/types/component.d.ts +0 -9
  268. package/types/connector.d.ts +0 -18
  269. package/types/context.d.ts +0 -21
  270. package/types/entity.d.ts +0 -46
  271. package/types/event.d.ts +0 -11
  272. package/types/exception.d.ts +0 -4
  273. package/types/extensions.d.ts +0 -29
  274. package/types/index.ts +0 -14
  275. package/types/locator.d.ts +0 -13
  276. package/types/message.d.ts +0 -3
  277. package/types/operations.d.ts +0 -2
  278. package/types/query.d.ts +0 -15
  279. package/types/receiver.d.ts +0 -12
  280. package/types/reflection.d.ts +0 -14
  281. package/types/request.d.ts +0 -23
  282. package/types/state.d.ts +0 -35
  283. package/types/storages.d.ts +0 -71
package/src/receiver.js DELETED
@@ -1,61 +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 {unknown[]} */
20
- #arguments
21
-
22
- #local
23
-
24
- #bridge
25
-
26
- constructor (definition, local, bridge) {
27
- super()
28
-
29
- const { conditioned, adaptive, operation } = definition
30
-
31
- this.#conditioned = conditioned
32
- this.#adaptive = adaptive
33
- this.#endpoint = operation
34
- this.#arguments = definition.arguments
35
-
36
- this.#local = local
37
- this.#bridge = bridge
38
-
39
- this.depends(local)
40
- if (bridge !== undefined) this.depends(bridge)
41
- }
42
-
43
- /** @hot */
44
- async receive (message) {
45
- const { payload, ...extensions } = message
46
-
47
- if (this.#conditioned && await this.#bridge.condition(payload) === false) return
48
-
49
- const request = await this.#request(payload)
50
-
51
- add(request, extensions)
52
-
53
- await this.#local.invoke(this.#endpoint, request)
54
- }
55
-
56
- async #request (payload) {
57
- return this.#adaptive ? await this.#bridge.request(payload, ...(this.#arguments ?? [])) : { input: payload }
58
- }
59
- }
60
-
61
- 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,67 +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 { scope, state, reply, retry } = store
38
-
39
- if (reply.error !== undefined) return
40
-
41
- scope.set(state)
42
-
43
- const result = await this.scope.commit(scope)
44
-
45
- if (result === false) {
46
- if (this.#concurrency === 'retry')
47
- return retry()
48
- else
49
- throw new StateConcurrencyException()
50
- }
51
- }
52
-
53
- async #retry (store, retry) {
54
- store.retry = retry
55
-
56
- return super.process(store)
57
- }
58
- }
59
-
60
- const RETRY = {
61
- base: 10,
62
- max: 5000,
63
- dispersion: 1,
64
- retries: Infinity
65
- }
66
-
67
- 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,27 +0,0 @@
1
- 'use strict'
2
-
3
- const { generate } = require('randomstring')
4
-
5
- // noinspection JSCheckFunctionSignatures
6
- const transmission = {
7
- request: jest.fn((request) => ({ [request.invalid ? 'exception' : 'output']: generate() })),
8
- link: jest.fn()
9
- }
10
-
11
- const contract = {
12
- fit: jest.fn(() => null)
13
- }
14
-
15
- const request = () => ({
16
- ok: {
17
- input: { [generate()]: generate() },
18
- query: { [generate()]: generate() }
19
- },
20
- bad: {
21
- invalid: true
22
- }
23
- })
24
-
25
- exports.transmission = transmission
26
- exports.contract = contract
27
- exports.request = request
package/test/call.test.js DELETED
@@ -1,46 +0,0 @@
1
- 'use strict'
2
-
3
- const fixtures = require('./call.fixtures')
4
- const { Call } = require('../src/call')
5
-
6
- let call
7
-
8
- beforeEach(() => {
9
- jest.clearAllMocks()
10
-
11
- call = new Call(fixtures.transmission, fixtures.contract)
12
- })
13
-
14
- it('should depend on transmission', () => {
15
- expect(fixtures.transmission.link).toHaveBeenLastCalledWith(call)
16
- })
17
-
18
- it('should call transmission', async () => {
19
- const request = fixtures.request().ok
20
-
21
- await call.invoke(request)
22
-
23
- expect(fixtures.transmission.request).toHaveBeenCalledWith(request)
24
- })
25
-
26
- it('should fit request', async () => {
27
- const request = fixtures.request().ok
28
-
29
- await call.invoke(request)
30
-
31
- expect(fixtures.contract.fit).toHaveBeenLastCalledWith(request)
32
- })
33
-
34
- it('should return reply', async () => {
35
- const request = fixtures.request().ok
36
-
37
- const reply = await call.invoke(request)
38
-
39
- expect(reply).toStrictEqual(fixtures.transmission.request.mock.results[0].value.output)
40
- })
41
-
42
- it('should throw received exceptions', async () => {
43
- const request = fixtures.request().bad
44
-
45
- await expect(call.invoke(request)).rejects.toBeDefined()
46
- })
@@ -1,21 +0,0 @@
1
- 'use strict'
2
-
3
- const randomstring = require('randomstring')
4
-
5
- const invocation = () => jest.fn(() => randomstring.generate())
6
-
7
- const invocations = {
8
- foo: {
9
- invoke: invocation('foo'),
10
- link: () => null
11
- },
12
- bar: {
13
- invoke: invocation('bar'),
14
- link: () => null
15
- }
16
- }
17
-
18
- const locator = {}
19
-
20
- exports.invocations = invocations
21
- exports.locator = locator
@@ -1,40 +0,0 @@
1
- 'use strict'
2
-
3
- const { Component } = require('../src/component')
4
- const { codes } = require('../src/exceptions')
5
- const fixtures = require('./component.fixtures')
6
-
7
- describe('Invocations', () => {
8
- const name = ['foo', 'bar'][Math.floor(2 * Math.random())]
9
- const invocation = fixtures.invocations[name]
10
- const component = new Component(fixtures.locator, fixtures.invocations)
11
-
12
- beforeEach(() => {
13
- jest.clearAllMocks()
14
- })
15
-
16
- it('should invoke', async () => {
17
- await component.invoke(name)
18
-
19
- expect(invocation.invoke).toBeCalled()
20
- })
21
-
22
- it('should throw on unknown invocation name', async () => {
23
- await expect(() => component.invoke('baz'))
24
- .rejects.toMatchObject({ code: codes.NotImplemented })
25
- })
26
-
27
- it('should invoke input and query', async () => {
28
- const input = { test: Math.random() }
29
- const query = { test: Math.random() }
30
- await component.invoke(name, { input, query })
31
-
32
- expect(invocation.invoke).toBeCalledWith({ input, query })
33
- })
34
-
35
- it('should return io', async () => {
36
- const io = await component.invoke(name)
37
-
38
- expect(io).toBe(fixtures.invocations[name].invoke.mock.results[0].value)
39
- })
40
- })
@@ -1,40 +0,0 @@
1
- 'use strict'
2
-
3
- const { random, timeout } = require('@toa.io/generic')
4
- const { Connector } = require('../src/connector')
5
-
6
- class TestConnector extends Connector {
7
- #label
8
- #seq
9
-
10
- constructor (label, seq) {
11
- super()
12
-
13
- this.#seq = seq
14
- this.#label = label
15
- }
16
-
17
- async open () {
18
- await timeout(random(10))
19
- this.#seq.push(`+${this.#label}`)
20
- }
21
-
22
- async close () {
23
- await timeout(random(10))
24
- this.#seq.push(`-${this.#label}`)
25
- }
26
-
27
- async dispose () {
28
- this.#seq.push(`*${this.#label}`)
29
- }
30
- }
31
-
32
- class FailingConnector extends Connector {
33
- async open () {
34
- await timeout(random(10))
35
- throw new Error('FailingConnector')
36
- }
37
- }
38
-
39
- exports.TestConnector = TestConnector
40
- exports.FailingConnector = FailingConnector
@@ -1,176 +0,0 @@
1
- 'use strict'
2
-
3
- const fixtures = require('./connector.fixtures')
4
-
5
- let sequence
6
-
7
- beforeEach(() => {
8
- sequence = []
9
- })
10
-
11
- describe('callbacks', () => {
12
- let a
13
-
14
- beforeEach(() => {
15
- a = new fixtures.TestConnector('a', sequence)
16
- })
17
-
18
- it('should call connection', async () => {
19
- await a.connect()
20
- expect(sequence).toEqual(['+a'])
21
- })
22
-
23
- it('should call disconnection', async () => {
24
- await a.connect()
25
- await a.disconnect()
26
-
27
- expect(sequence.indexOf('+a')).toBeLessThan(sequence.indexOf('-a'))
28
- })
29
-
30
- it('should reconnect', async () => {
31
- await a.connect()
32
- await a.reconnect()
33
- await a.reconnect()
34
-
35
- expect(sequence).toEqual(['+a', '-a', '*a', '+a', '-a', '*a', '+a'])
36
- })
37
- })
38
-
39
- describe('dependencies', () => {
40
- let a
41
- let b
42
- let c
43
- let d
44
-
45
- beforeEach(() => {
46
- a = new fixtures.TestConnector('a', sequence)
47
- b = new fixtures.TestConnector('b', sequence)
48
- c = new fixtures.TestConnector('c', sequence)
49
- d = new fixtures.TestConnector('d', sequence)
50
- })
51
-
52
- it('should wait dependencies on connection', async () => {
53
- a.depends(b).depends(c)
54
- a.depends(d)
55
-
56
- await a.connect()
57
-
58
- expect(sequence.indexOf('+c')).toBeLessThan(sequence.indexOf('+b'))
59
- expect(sequence.indexOf('+b')).toBeLessThan(sequence.indexOf('+a'))
60
- expect(sequence.indexOf('+d')).toBeLessThan(sequence.indexOf('+a'))
61
- })
62
-
63
- it('should wait array of connectors', async () => {
64
- a.depends([b, d])
65
- b.depends(c)
66
- d.depends(c)
67
-
68
- await a.connect()
69
-
70
- expect(sequence.indexOf('+c')).toBeLessThan(sequence.indexOf('+b'))
71
- expect(sequence.indexOf('+c')).toBeLessThan(sequence.indexOf('+d'))
72
- expect(sequence.indexOf('+b')).toBeLessThan(sequence.indexOf('+a'))
73
- expect(sequence.indexOf('+d')).toBeLessThan(sequence.indexOf('+a'))
74
- })
75
-
76
- it('should wait array(1) of connectors', async () => {
77
- a.depends([b])
78
- b.depends(c)
79
-
80
- await a.connect()
81
-
82
- expect(sequence.indexOf('+c')).toBeLessThan(sequence.indexOf('+b'))
83
- expect(sequence.indexOf('+b')).toBeLessThan(sequence.indexOf('+a'))
84
- })
85
-
86
- it('should throw on empty array', async () => {
87
- expect(() => a.depends([])).toThrow(/must not be empty/)
88
- })
89
-
90
- it('should await 2-way dependencies', async () => {
91
- a.depends([b, c, d])
92
- d.depends([b, c])
93
-
94
- await a.connect()
95
-
96
- expect(sequence.indexOf('+b')).toBeLessThan(sequence.indexOf('+a'))
97
- expect(sequence.indexOf('+c')).toBeLessThan(sequence.indexOf('+a'))
98
- expect(sequence.indexOf('+d')).toBeLessThan(sequence.indexOf('+a'))
99
-
100
- expect(sequence.indexOf('+b')).toBeLessThan(sequence.indexOf('+d'))
101
- expect(sequence.indexOf('+c')).toBeLessThan(sequence.indexOf('+d'))
102
- })
103
-
104
- it('should disconnect before dependencies', async () => {
105
- a.depends(b).depends(c)
106
- b.depends(d)
107
-
108
- await a.disconnect()
109
-
110
- expect(sequence.indexOf('-a')).toBeLessThan(sequence.indexOf('-b'))
111
- expect(sequence.indexOf('-b')).toBeLessThan(sequence.indexOf('-c'))
112
- expect(sequence.indexOf('-b')).toBeLessThan(sequence.indexOf('-d'))
113
- })
114
-
115
- it('should call disconnected', async () => {
116
- a.depends(b).depends(c)
117
- b.depends(d)
118
-
119
- await a.disconnect()
120
-
121
- expect(sequence.indexOf('*c')).toBeLessThan(sequence.indexOf('*b'))
122
- expect(sequence.indexOf('*b')).toBeLessThan(sequence.indexOf('*a'))
123
- expect(sequence.indexOf('*d')).toBeLessThan(sequence.indexOf('*b'))
124
- expect(sequence.indexOf('*a')).toBe(sequence.length - 1)
125
- })
126
-
127
- it('should disconnect if no parents left', async () => {
128
- a.depends(c)
129
- b.depends(c)
130
-
131
- await a.connect()
132
- await b.connect()
133
-
134
- expect(sequence).toEqual(['+c', '+a', '+b'])
135
-
136
- await a.disconnect()
137
-
138
- expect(sequence).toEqual(['+c', '+a', '+b', '-a', '*a'])
139
-
140
- await b.disconnect()
141
-
142
- expect(sequence).toEqual(['+c', '+a', '+b', '-a', '*a', '-b', '-c', '*c', '*b'])
143
- })
144
-
145
- it('should throw if depends not on Connector', async () => {
146
- expect(() => a.depends({})).toThrow()
147
- })
148
-
149
- describe('errors', () => {
150
- let f
151
-
152
- beforeEach(() => {
153
- f = new fixtures.FailingConnector()
154
- })
155
-
156
- it('should disconnect on fail', async () => {
157
- f.depends(b).depends(c)
158
-
159
- await expect(f.connect()).rejects.toThrow('FailingConnector')
160
- expect(sequence).toEqual(['+c', '+b', '-b', '-c', '*c', '*b'])
161
- })
162
-
163
- it('should interrupt connection chain', async () => {
164
- a.depends(f).depends(c)
165
- f.depends(d)
166
-
167
- await expect(a.connect()).rejects.toThrow('FailingConnector')
168
-
169
- expect(sequence.indexOf('+c')).toBeLessThan(sequence.indexOf('-c'))
170
- expect(sequence.indexOf('+d')).toBeLessThan(sequence.indexOf('-d'))
171
-
172
- expect(sequence.indexOf('+a')).toBe(-1)
173
- expect(sequence.indexOf('-a')).toBe(-1)
174
- })
175
- })
176
- })
@@ -1,18 +0,0 @@
1
- 'use strict'
2
-
3
- const { Connector } = require('../src/connector')
4
-
5
- const local = {
6
- link: jest.fn()
7
- }
8
-
9
- const discover = jest.fn(() => ({
10
- invoke: jest.fn(),
11
- link: jest.fn()
12
- }))
13
-
14
- const aspects = [new Connector(), new Connector()]
15
-
16
- exports.local = local
17
- exports.discover = discover
18
- exports.aspects = aspects