@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
@@ -1,113 +0,0 @@
1
- 'use strict'
2
-
3
- const { generate } = require('randomstring')
4
- const { Locator } = require('../src/locator')
5
-
6
- /** @type {string} */
7
- let name
8
-
9
- /** @type {string} */
10
- let namespace
11
-
12
- /** @type {toa.core.Locator} */
13
- let locator
14
-
15
- beforeEach(() => {
16
- name = generate()
17
- namespace = generate()
18
-
19
- locator = new Locator(name, namespace)
20
- })
21
-
22
- it('should expose name and namespace', () => {
23
- expect(locator.name).toStrictEqual(name)
24
- expect(locator.namespace).toStrictEqual(namespace)
25
- })
26
-
27
- it('should expose id, label', () => {
28
- const id = locator.namespace + '.' + locator.name
29
- const label = locator.namespace.toLowerCase() + '-' + locator.name.toLowerCase()
30
-
31
- expect(locator.id).toStrictEqual(id)
32
- expect(locator.label).toStrictEqual(label)
33
- })
34
-
35
- it('should expose uppercase', () => {
36
- expect(locator.uppercase).toStrictEqual((locator.namespace + '_' + locator.name).toUpperCase())
37
- })
38
-
39
- it('should throw if name is undefined', () => {
40
- expect(() => new Locator(undefined, namespace)).toThrow(TypeError)
41
-
42
- // noinspection JSCheckFunctionSignatures
43
- expect(() => new Locator()).toThrow(TypeError)
44
- })
45
-
46
- it('should expose host', () => {
47
- expect(locator.hostname()).toStrictEqual((namespace + '-' + name).toLowerCase())
48
- })
49
-
50
- it('should expose host with given prefix', () => {
51
- const prefix = generate()
52
-
53
- expect(locator.hostname(prefix)).toStrictEqual((prefix + '-' + namespace + '-' + name).toLowerCase())
54
- })
55
-
56
- describe('global', () => {
57
- beforeEach(() => {
58
- locator = new Locator(name)
59
- })
60
-
61
- it('should not throw', () => undefined)
62
-
63
- it('should expose id', () => {
64
- expect(locator.id).toStrictEqual(name)
65
- })
66
-
67
- it('should expose label', () => {
68
- expect(locator.label).toStrictEqual(name.toLowerCase())
69
- })
70
-
71
- it('should expose uppercase', () => {
72
- expect(locator.uppercase).toStrictEqual(name.toUpperCase())
73
- })
74
-
75
- it('should expose hostname', () => {
76
- const type = generate()
77
-
78
- expect(locator.hostname(type)).toStrictEqual((type + '-' + name).toLowerCase())
79
- expect(locator.hostname()).toStrictEqual(name.toLowerCase())
80
- })
81
- })
82
-
83
- describe('parse', () => {
84
- it('should be', async () => {
85
- expect(Locator.parse).toBeInstanceOf(Function)
86
- })
87
-
88
- const namespace = generate()
89
- const name = generate()
90
- const id = `${namespace}.${name}`
91
-
92
- it('should parse id', async () => {
93
- const locator = Locator.parse(id)
94
-
95
- expect(locator.namespace).toStrictEqual(namespace)
96
- expect(locator.name).toStrictEqual(name)
97
- })
98
-
99
- it('should parse endpoint', async () => {
100
- const endpoint = `${id}.${generate()}`
101
- const locator = Locator.parse(endpoint)
102
-
103
- expect(locator.namespace).toStrictEqual(namespace)
104
- expect(locator.name).toStrictEqual(name)
105
- })
106
-
107
- it('should parse token as global', async () => {
108
- const locator = Locator.parse(name)
109
-
110
- expect(locator.namespace).toBeUndefined()
111
- expect(locator.name).toStrictEqual(name)
112
- })
113
- })
@@ -1,100 +0,0 @@
1
- 'use strict'
2
-
3
- const samples = {
4
- simple: {
5
- query: {
6
- criteria: 'name==Eddie'
7
- },
8
- parsed: {
9
- criteria: {
10
- type: 'COMPARISON',
11
- left: { type: 'SELECTOR', selector: 'name' },
12
- operator: '==',
13
- right: { type: 'VALUE', value: 'Eddie' }
14
- }
15
- },
16
- properties: {
17
- name: {
18
- type: 'string'
19
- }
20
- }
21
- },
22
-
23
- extended: {
24
- query: {
25
- criteria: 'flag==true;volume>2.1'
26
- },
27
- parsed: {
28
- criteria: {
29
- type: 'LOGIC',
30
- left: {
31
- type: 'COMPARISON',
32
- left: { type: 'SELECTOR', selector: 'flag' },
33
- operator: '==',
34
- right: { type: 'VALUE', value: true }
35
- },
36
- operator: ';',
37
- right: {
38
- type: 'COMPARISON',
39
- left: { type: 'SELECTOR', selector: 'volume' },
40
- operator: '>',
41
- right: { type: 'VALUE', value: 2.1 }
42
- }
43
- }
44
- },
45
- properties: {
46
- flag: {
47
- type: 'boolean'
48
- },
49
- volume: {
50
- type: 'number'
51
- }
52
- }
53
- },
54
-
55
- abc: {
56
- properties: {
57
- a: {
58
- type: 'string'
59
- },
60
- b: {
61
- type: 'string'
62
- },
63
- c: {
64
- type: 'string'
65
- }
66
- }
67
- },
68
-
69
- id: {
70
- properties: {
71
- id: {
72
- type: 'string'
73
- },
74
- name: {
75
- type: 'string'
76
- }
77
- },
78
- query: {
79
- id: '123',
80
- criteria: 'name==Eddie'
81
- },
82
- parsed: {
83
- id: '123',
84
- criteria: {
85
- type: 'COMPARISON',
86
- left: {
87
- type: 'SELECTOR',
88
- selector: 'name'
89
- },
90
- operator: '==',
91
- right: {
92
- type: 'VALUE',
93
- value: 'Eddie'
94
- }
95
- }
96
- }
97
- }
98
- }
99
-
100
- exports.samples = samples
@@ -1,86 +0,0 @@
1
- 'use strict'
2
-
3
- const { Query } = require('../src/query')
4
- const fixtures = require('./query.fixtures')
5
-
6
- beforeEach(() => {
7
- jest.clearAllMocks()
8
- })
9
-
10
- describe('criteria', () => {
11
- it('should not throw if no criteria', () => {
12
- const instance = new Query(fixtures.samples.simple.properties)
13
- const query = instance.parse({})
14
-
15
- expect(query.criteria).toBeUndefined()
16
- })
17
-
18
- it('should parse criteria', () => {
19
- const instance = new Query(fixtures.samples.simple.properties)
20
- const query = instance.parse(fixtures.samples.simple.query)
21
-
22
- expect(query.criteria).toEqual(fixtures.samples.simple.parsed.criteria)
23
- })
24
-
25
- it('should parse criteria with type coercion', () => {
26
- const instance = new Query(fixtures.samples.extended.properties)
27
- const query = instance.parse(fixtures.samples.extended.query)
28
-
29
- expect(query.criteria).toEqual(fixtures.samples.extended.parsed.criteria)
30
- })
31
-
32
- it('should throw on unknown properties', () => {
33
- const instance = new Query(fixtures.samples.simple.properties)
34
-
35
- expect(() => instance.parse({ criteria: 'lastname==Johnson' })).toThrow(/not defined/)
36
- })
37
-
38
- it('should parse id', () => {
39
- const instance = new Query(fixtures.samples.id.properties)
40
- const query = instance.parse({ ...fixtures.samples.id.query })
41
-
42
- expect(query).toStrictEqual(fixtures.samples.id.parsed)
43
- })
44
- })
45
-
46
- describe('options', () => {
47
- const instance = new Query(fixtures.samples.abc.properties)
48
-
49
- it('should not throw if no options', () => {
50
- const query = instance.parse({})
51
-
52
- expect(query.options).toBeUndefined()
53
- })
54
-
55
- describe('omit, limit', () => {
56
- it('should pass', () => {
57
- const input = { omit: 1, limit: 1 }
58
- const query = instance.parse(input)
59
-
60
- expect(query.options).toStrictEqual(input)
61
- })
62
- })
63
-
64
- describe('sort', () => {
65
- it('should set default values', () => {
66
- const sort = ['a', 'b:desc', 'c']
67
- const query = instance.parse({ sort })
68
-
69
- expect(query.options.sort).toStrictEqual([['a', 'asc'], ['b', 'desc'], ['c', 'asc']])
70
- })
71
-
72
- it('should throw on unknown properties', () => {
73
- const sort = ['d:asc']
74
-
75
- expect(() => instance.parse({ sort })).toThrow(/not defined/)
76
- })
77
- })
78
-
79
- describe('projection', () => {
80
- it('should throw on unknown properties', () => {
81
- const projection = ['a', 'b', 'c', 'd']
82
-
83
- expect(() => instance.parse({ projection })).toThrow(/not defined/)
84
- })
85
- })
86
- })
@@ -1,23 +0,0 @@
1
- 'use strict'
2
-
3
- const { generate } = require('randomstring')
4
-
5
- const definition = /** @type {toa.norm.component.Receiver} */ {
6
- operation: generate(),
7
- conditioned: false,
8
- adaptive: false
9
- }
10
-
11
- const local = /** @type {toa.core.Component} */ {
12
- invoke: jest.fn()
13
- }
14
-
15
- // noinspection JSCheckFunctionSignatures
16
- const bridge = /** @type {toa.core.bridges.Event} */ {
17
- condition: jest.fn(async (payload) => !(payload.reject === true)),
18
- request: jest.fn(async () => ({ input: generate() }))
19
- }
20
-
21
- exports.definition = definition
22
- exports.local = local
23
- exports.bridge = bridge
@@ -1,95 +0,0 @@
1
- 'use strict'
2
-
3
- const clone = require('clone-deep')
4
- const { generate } = require('randomstring')
5
- const { merge } = require('@toa.io/generic')
6
-
7
- jest.mock('../src/connector')
8
-
9
- const { Connector } = /** @type {{ Connector: jest.Mock<toa.core.Connector>}} */ require('../src/connector')
10
-
11
- const { Receiver } = require('../src/receiver')
12
- const fixtures = require('./receiver.fixtures')
13
-
14
- /** @type {toa.core.Receiver} */
15
- let receiver
16
-
17
- /** @type {toa.norm.component.Receiver} */
18
- let definition
19
-
20
- beforeEach(() => {
21
- jest.clearAllMocks()
22
-
23
- definition = clone(fixtures.definition)
24
- receiver = new Receiver(fixtures.definition, fixtures.local, fixtures.bridge)
25
- })
26
-
27
- it('should depend on local, bridge', () => {
28
- expect(Connector.mock.instances[0].depends).toHaveBeenCalledWith(fixtures.local)
29
- expect(Connector.mock.instances[0].depends).toHaveBeenCalledWith(fixtures.bridge)
30
- })
31
-
32
- it('should apply', async () => {
33
- const payload = { foo: 'bar' }
34
-
35
- await receiver.receive({ payload })
36
-
37
- expect(fixtures.local.invoke).toHaveBeenCalledWith(definition.operation, { input: payload })
38
- })
39
-
40
- it.each([[false], [true]])('should pass UI extensions (adaptive: %s)', async (adaptive) => {
41
- jest.clearAllMocks()
42
-
43
- definition.adaptive = adaptive
44
- receiver = new Receiver(definition, fixtures.local, fixtures.bridge)
45
-
46
- const payload = { foo: generate() }
47
- const extension = { [generate()]: generate() }
48
- const message = { payload, ...extension }
49
-
50
- await receiver.receive(message)
51
-
52
- const request = adaptive ? await fixtures.bridge.request.mock.results[0].value : { input: payload }
53
- const expected = merge(clone(request), extension)
54
-
55
- const argument = fixtures.local.invoke.mock.calls[0][1]
56
-
57
- expect(argument).toStrictEqual(expected)
58
- })
59
-
60
- describe('conditioned', () => {
61
- beforeEach(() => {
62
- definition.conditioned = true
63
- receiver = new Receiver(definition, fixtures.local, fixtures.bridge)
64
- })
65
-
66
- it('should test condition', async () => {
67
- const payload = { foo: 'bar' }
68
- await receiver.receive({ payload })
69
-
70
- expect(fixtures.bridge.condition).toHaveBeenCalledWith(payload)
71
- expect(fixtures.local.invoke).toHaveBeenCalledWith(definition.operation, { input: payload })
72
- })
73
-
74
- it('should not apply if condition is false', async () => {
75
- const payload = { reject: true }
76
- await receiver.receive({ payload })
77
-
78
- expect(fixtures.local.invoke).not.toHaveBeenCalled()
79
- })
80
- })
81
-
82
- describe('adaptive', () => {
83
- beforeEach(() => {
84
- definition.adaptive = true
85
- receiver = new Receiver(definition, fixtures.local, fixtures.bridge)
86
- })
87
-
88
- it('should apply', async () => {
89
- const payload = { reject: true }
90
- await receiver.receive({ payload })
91
-
92
- expect(fixtures.local.invoke)
93
- .toHaveBeenCalledWith(definition.operation, await fixtures.bridge.request.mock.results[0].value)
94
- })
95
- })
@@ -1,30 +0,0 @@
1
- 'use strict'
2
-
3
- const { generate } = require('randomstring')
4
- const { Reflection, Connector } = require('../')
5
-
6
- it('should export', () => {
7
- expect(Reflection).toBeDefined()
8
- })
9
-
10
- /** @type {toa.core.Reflection<string>} */
11
- let reflection
12
-
13
- const value = generate()
14
-
15
- /** @type {toa.core.reflection.Source<string>} */
16
- const source = async () => value
17
-
18
- beforeEach(() => {
19
- reflection = new Reflection(source)
20
- })
21
-
22
- it('should be a Connector', () => {
23
- expect(reflection).toBeInstanceOf(Connector)
24
- })
25
-
26
- it('should reflect', async () => {
27
- await reflection.connect()
28
-
29
- expect(reflection.value).toStrictEqual(value)
30
- })
@@ -1,47 +0,0 @@
1
- 'use strict'
2
-
3
- const { generate } = require('randomstring')
4
-
5
- const storage = {
6
- name: 'dummy',
7
- get: jest.fn(() => ({ id: generate() })),
8
- find: jest.fn(() => ([{ id: generate() }])),
9
- add: jest.fn(() => true),
10
- set: jest.fn(() => true),
11
- store: jest.fn(() => true)
12
- }
13
-
14
- const factory = {
15
- object: jest.fn(() => ({ [generate()]: generate() })),
16
- objects: jest.fn(() => ({ [generate()]: generate() }))
17
- }
18
-
19
- const query = generate()
20
-
21
- const entity = {
22
- get: jest.fn(() => ({ [generate()]: generate() })),
23
- event: jest.fn(() => ({
24
- state: { [generate()]: generate() }, changeset: { [generate()]: generate() }
25
- }))
26
- }
27
-
28
- const initial = {
29
- initial: true, ...entity
30
- }
31
-
32
- const unchanged = {
33
- ...entity,
34
- event: jest.fn(() => ({ state: { [generate()]: generate() }, changeset: {} }))
35
- }
36
-
37
- const emitter = {
38
- emit: jest.fn()
39
- }
40
-
41
- exports.storage = storage
42
- exports.factory = factory
43
- exports.emitter = emitter
44
- exports.query = query
45
- exports.entity = entity
46
- exports.initial = initial
47
- exports.unchanged = unchanged
@@ -1,46 +0,0 @@
1
- 'use strict'
2
-
3
- const { State } = require('../src/state')
4
- const fixtures = require('./state.fixtures')
5
-
6
- let state
7
-
8
- beforeEach(() => {
9
- jest.clearAllMocks()
10
-
11
- state = new State(fixtures.storage, fixtures.factory, fixtures.emitter)
12
- })
13
-
14
- it('should provide object', async () => {
15
- const entity = await state.object(fixtures.query)
16
-
17
- expect(fixtures.storage.get).toHaveBeenCalledWith(fixtures.query)
18
- expect(entity).toStrictEqual(fixtures.factory.object.mock.results[0].value)
19
- expect(fixtures.factory.object).toHaveBeenCalledWith(fixtures.storage.get.mock.results[0].value)
20
- })
21
-
22
- it('should provide objects', async () => {
23
- const set = await state.objects(fixtures.query)
24
-
25
- expect(fixtures.storage.find).toHaveBeenCalledWith(fixtures.query)
26
- expect(set).toStrictEqual(fixtures.factory.objects.mock.results[0].value)
27
- expect(fixtures.factory.objects).toHaveBeenCalledWith(fixtures.storage.find.mock.results[0].value)
28
- })
29
-
30
- it('should store entity', async () => {
31
- await state.commit(fixtures.initial)
32
-
33
- expect(fixtures.storage.store).toHaveBeenCalledWith(fixtures.initial.get.mock.results[0].value)
34
- })
35
-
36
- it('should emit', async () => {
37
- await state.commit(fixtures.entity)
38
-
39
- expect(fixtures.emitter.emit).toHaveBeenCalledWith(fixtures.entity.event.mock.results[0].value)
40
- })
41
-
42
- it('should not emit if state has not been changed', async () => {
43
- await state.commit(fixtures.unchanged)
44
-
45
- expect(fixtures.emitter.emit).not.toHaveBeenCalled()
46
- })
@@ -1,15 +0,0 @@
1
- 'use strict'
2
-
3
- const { generate } = require('randomstring')
4
-
5
- const binding = (index) => ({
6
- request: jest.fn(async (request) => {
7
- if (request?.pick !== undefined && request.pick !== index) return false
8
-
9
- return { output: generate() }
10
- })
11
- })
12
-
13
- const bindings = [0, 1, 2, 3, 4].map(binding)
14
-
15
- exports.bindings = bindings
@@ -1,46 +0,0 @@
1
- 'use strict'
2
-
3
- jest.mock('../src/connector')
4
-
5
- const { Connector } = require('../src/connector')
6
- const { Transmission } = require('../src/transmission')
7
- const { codes } = require('../src/exceptions')
8
- const fixtures = require('./transmission.fixtures')
9
-
10
- let transmission
11
-
12
- beforeEach(() => {
13
- jest.clearAllMocks()
14
- })
15
-
16
- beforeEach(() => {
17
- transmission = new Transmission(fixtures.bindings)
18
- })
19
-
20
- it('should be instance of Connector depending on bindings', () => {
21
- expect(transmission).toBeInstanceOf(Connector)
22
- expect(Connector.mock.instances[0].depends).toHaveBeenCalledWith(fixtures.bindings)
23
- })
24
-
25
- it('should pass arguments and return value', async () => {
26
- const request = { foo: 'bar' }
27
- const result = await transmission.request(request)
28
-
29
- expect(fixtures.bindings[0].request).toHaveBeenCalledWith(request)
30
- expect(result).toBe(await fixtures.bindings[0].request.mock.results[0].value)
31
- })
32
-
33
- it('should pick bindings sequentially', async () => {
34
- let result = await transmission.request()
35
- expect(result).toBe(await fixtures.bindings[0].request.mock.results[0].value)
36
-
37
- result = await transmission.request({ pick: 1 })
38
- expect(result).toBe(await fixtures.bindings[1].request.mock.results[0]?.value)
39
- })
40
-
41
- it('should throw exception if none succeeded', async () => {
42
- await expect(transmission.request({ pick: 5 })).rejects.toMatchObject({ code: codes.Transmission })
43
-
44
- fixtures.bindings.forEach((binding) =>
45
- expect(binding.request).toHaveBeenCalled())
46
- })
@@ -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
- }