@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,29 +0,0 @@
1
- 'use strict'
2
-
3
- const fixtures = require('./context.fixtures')
4
- const { Context } = require('../src/context')
5
-
6
- /** @type {toa.core.Context} */
7
- let context
8
-
9
- beforeEach(() => {
10
- jest.clearAllMocks()
11
-
12
- context = new Context(fixtures.local, fixtures.discover, fixtures.aspects)
13
- })
14
-
15
- it('should expose aspects', () => {
16
- expect(context.aspects).toBeDefined()
17
- expect(context.aspects).toStrictEqual(fixtures.aspects)
18
- })
19
-
20
- describe('call', () => {
21
- it('should discover once', async () => {
22
- const request = {}
23
-
24
- await context.call('a', 'b', 'c', request)
25
- await context.call('a', 'b', 'c', request)
26
-
27
- expect(fixtures.discover).toHaveBeenCalledTimes(1)
28
- })
29
- })
@@ -1,26 +0,0 @@
1
- 'use strict'
2
-
3
- const { generate } = require('randomstring')
4
-
5
- const { Conditions } = require('../../src/contract/conditions')
6
- const fixtures = require('./contract.fixtures')
7
-
8
- let conditions
9
-
10
- beforeEach(() => {
11
- conditions = new Conditions(fixtures.schema)
12
- })
13
-
14
- it('should fit value', () => {
15
- const value = { foo: generate() }
16
-
17
- conditions.fit(value)
18
-
19
- expect(fixtures.schema.fit).toHaveBeenCalledWith(value)
20
- })
21
-
22
- it('should throw on invalid value', () => {
23
- const value = { invalid: true }
24
-
25
- expect(() => conditions.fit(value)).toThrow()
26
- })
@@ -1,33 +0,0 @@
1
- 'use strict'
2
-
3
- const { generate } = require('randomstring')
4
- const { load } = require('@toa.io/yaml')
5
- const { resolve } = require('path')
6
-
7
- // noinspection JSCheckFunctionSignatures
8
- const schema = {
9
- fit: jest.fn((input) => (input.invalid ? { message: generate() } : null))
10
- }
11
-
12
- const query = {
13
- parse: jest.fn(() => ({ [generate()]: generate() }))
14
- }
15
-
16
- const declaration = {}
17
-
18
- const schemas = {
19
- request: {
20
- type: 'object',
21
- properties: {
22
- input: { type: 'null' },
23
- query: load.sync(resolve(__dirname, '../../src/contract/schemas/query.yaml')),
24
- authentic: { type: 'boolean' }
25
- },
26
- additionalProperties: true
27
- }
28
- }
29
-
30
- exports.schema = schema
31
- exports.query = query
32
- exports.declaration = declaration
33
- exports.schemas = schemas
@@ -1,112 +0,0 @@
1
- 'use strict'
2
-
3
- const clone = require('clone-deep')
4
- const { generate } = require('randomstring')
5
-
6
- jest.mock('../../src/contract/conditions')
7
-
8
- const { Request } = require('../../src/contract/request')
9
- const { Conditions } = require('../../src/contract/conditions')
10
- const fixtures = require('./contract.fixtures')
11
-
12
- let contract
13
-
14
- beforeEach(() => {
15
- jest.clearAllMocks()
16
-
17
- contract = new Request(fixtures.schema)
18
- })
19
-
20
- const dummy = { schema: { properties: {} } }
21
-
22
- it('should extend Conditions', () => {
23
- expect(contract).toBeInstanceOf(Conditions)
24
- expect(Conditions).toHaveBeenCalledWith(fixtures.schema)
25
- })
26
-
27
- it('should fit request', () => {
28
- const request = { [generate()]: generate() }
29
-
30
- contract.fit(request)
31
-
32
- expect(Conditions.mock.instances[0].fit).toHaveBeenCalledWith(request)
33
- })
34
-
35
- describe('schema', () => {
36
- let schema
37
-
38
- beforeEach(() => {
39
- schema = clone(fixtures.schemas.request)
40
- })
41
-
42
- it('should provide schema', () => {
43
- expect(Request.schema({}, dummy)).toBeDefined()
44
- })
45
-
46
- it('should add required input if defined', () => {
47
- const input = { type: 'number' }
48
-
49
- expect(Request.schema({ input }, dummy).properties.input).toStrictEqual(input)
50
- })
51
-
52
- it('should set input as null if undefined', async () => {
53
- expect(Request.schema({}, dummy).properties.input).toStrictEqual({ type: 'null' })
54
- })
55
-
56
- it('should contain query if declaration.query is not defined', () => {
57
- expect(Request.schema({}, dummy).properties.query).toBeDefined()
58
- })
59
-
60
- it('should not contain query if declaration.query is false', () => {
61
- schema.properties.query = { type: 'null' }
62
- expect(Request.schema({ query: false }, dummy)).toStrictEqual(schema)
63
- })
64
-
65
- it('should require query if declaration.query is true', () => {
66
- schema.required = ['query']
67
- expect(Request.schema({ query: true }, dummy).required).toStrictEqual(expect.arrayContaining(['query']))
68
- })
69
-
70
- it('should forbid projection for non observations', () => {
71
- expect(Request.schema({ type: 'transition' }, dummy).properties.query.properties.projection)
72
- .toBe(undefined)
73
-
74
- expect(Request.schema({ type: 'assignment' }, dummy).properties.query.properties.projection)
75
- .toBe(undefined)
76
-
77
- expect(Request.schema({ type: 'observation' }, dummy).properties.query.properties.projection)
78
- .toBeDefined()
79
- })
80
-
81
- it('should forbid version for observations', () => {
82
- expect(Request.schema({ type: 'transition' }, dummy).properties.query.properties.version)
83
- .toBeDefined()
84
-
85
- expect(Request.schema({ type: 'observation' }, dummy).properties.query.properties.version)
86
- .toBe(undefined)
87
- })
88
-
89
- it('should allow omit, limit only for set observations', () => {
90
- const schema = Request.schema({ type: 'transition' }, dummy)
91
- const transition = schema.properties.query.properties
92
-
93
- expect(transition.omit).toBeUndefined()
94
- expect(transition.limit).toBeUndefined()
95
-
96
- const object = Request.schema({
97
- type: 'observation',
98
- scope: 'object'
99
- }, dummy).properties.query.properties
100
-
101
- expect(object.omit).toBeUndefined()
102
- expect(object.limit).toBeUndefined()
103
-
104
- const objects = Request.schema({
105
- type: 'observation',
106
- scope: 'objects'
107
- }, dummy).properties.query.properties
108
-
109
- expect(objects.omit).toBeDefined()
110
- expect(objects.limit).toBeDefined()
111
- })
112
- })
@@ -1,17 +0,0 @@
1
- 'use strict'
2
-
3
- const { generate } = require('randomstring')
4
-
5
- // noinspection JSCheckFunctionSignatures
6
- const events = [0, 1, 2].map((index) => ({
7
- emit: jest.fn(async (state) => ({ ...state, event: index }))
8
- }))
9
-
10
- const event = {
11
- origin: { [generate()]: generate() },
12
- state: { [generate()]: generate() },
13
- changeset: { [generate()]: generate() }
14
- }
15
-
16
- exports.events = events
17
- exports.event = event
@@ -1,35 +0,0 @@
1
- 'use strict'
2
-
3
- jest.mock('../src/connector')
4
-
5
- const clone = require('clone-deep')
6
-
7
- const { Connector } = require('../src/connector')
8
- const { Emission } = require('../src/emission')
9
- const fixtures = require('./emission.fixtures')
10
-
11
- let emission, event
12
-
13
- beforeEach(async () => {
14
- jest.clearAllMocks()
15
-
16
- emission = new Emission(fixtures.events)
17
- event = clone(fixtures.event)
18
-
19
- await emission.open()
20
- })
21
-
22
- it('should depend on events', () => {
23
- expect(emission).toBeInstanceOf(Connector)
24
- expect(Connector.mock.instances[0].depends).toHaveBeenCalledWith(fixtures.events)
25
- })
26
-
27
- it('should emit events', async () => {
28
- expect.assertions(fixtures.events.length)
29
-
30
- await emission.emit(event)
31
-
32
- for (const evt of fixtures.events) {
33
- expect(evt.emit).toHaveBeenCalledWith(event)
34
- }
35
- })
@@ -1,29 +0,0 @@
1
- 'use strict'
2
-
3
- const { generate } = require('randomstring')
4
-
5
- // noinspection JSCheckFunctionSignatures
6
- const schema = {
7
- fit: jest.fn((object) =>
8
- (object.fail ? { [generate()]: generate() } : null)),
9
-
10
- defaults: jest.fn(() => ({ [generate()]: generate() }))
11
- }
12
-
13
- const state = () => ({
14
- id: generate(),
15
- foo: generate(),
16
- _created: generate(),
17
- _updated: generate(),
18
- _deleted: generate(),
19
- _version: 0
20
- })
21
-
22
- const failed = () => ({
23
- ...state(),
24
- fail: true
25
- })
26
-
27
- exports.schema = schema
28
- exports.state = state
29
- exports.failed = failed
@@ -1,65 +0,0 @@
1
- 'use strict'
2
-
3
- const { Entity } = require('../../src/entities/entity')
4
- const fixtures = require('./entity.fixtures')
5
-
6
- beforeEach(() => {
7
- jest.clearAllMocks()
8
- })
9
-
10
- describe('new', () => {
11
- it('should throw on schema error', () => {
12
- const entity = new Entity(fixtures.schema)
13
-
14
- expect(() => entity.set(fixtures.failed())).toThrow()
15
- })
16
-
17
- it('should provide state', () => {
18
- const entity = new Entity(fixtures.schema)
19
- const state = fixtures.state()
20
-
21
- entity.set(state)
22
-
23
- expect(entity.get()).toEqual(state)
24
- })
25
- })
26
-
27
- describe('argument', () => {
28
- it('should provide initial state if no argument passed', () => {
29
- const entity = new Entity(fixtures.schema)
30
- const defaults = fixtures.schema.defaults.mock.results[0].value
31
- const expected = {
32
- ...defaults,
33
- _version: 0
34
- }
35
-
36
- expect(entity.get()).toStrictEqual(expect.objectContaining(expected))
37
- })
38
-
39
- it('should set state', () => {
40
- const state = fixtures.state()
41
- const entity = new Entity(fixtures.schema, state)
42
-
43
- expect(entity.get()).toEqual(state)
44
- })
45
- })
46
-
47
- it('should provide event', () => {
48
- const origin = fixtures.state()
49
- const entity = new Entity(fixtures.schema, origin)
50
- const state = entity.get()
51
-
52
- state.foo = 'new value'
53
- entity.set(state)
54
-
55
- const event = entity.event()
56
-
57
- expect(event).toEqual(expect.objectContaining({
58
- state,
59
- origin,
60
- changeset: expect.objectContaining({
61
- foo: 'new value',
62
- _version: 1
63
- })
64
- }))
65
- })
@@ -1,18 +0,0 @@
1
- 'use strict'
2
-
3
- const randomstring = require('randomstring')
4
-
5
- const schema = { [randomstring.generate()]: randomstring.generate() }
6
- const storage = { id: jest.fn(() => randomstring.generate()) }
7
- const entity = { [randomstring.generate()]: randomstring.generate() }
8
- const set = Array.from(Array(5))
9
- .map((_, index) => ({ id: index, [randomstring.generate()]: randomstring.generate() }))
10
-
11
- const Entity = jest.fn().mockImplementation(function () { this.id = randomstring.generate() })
12
- const EntitySet = jest.fn().mockImplementation(function () {})
13
-
14
- exports.schema = schema
15
- exports.storage = storage
16
- exports.entity = entity
17
- exports.set = set
18
- exports.mock = { Entity, EntitySet }
@@ -1,48 +0,0 @@
1
- 'use strict'
2
-
3
- const { generate } = require('randomstring')
4
-
5
- const fixtures = require('./factory.fixtures')
6
- const mock = fixtures.mock
7
-
8
- jest.mock('../../src/entities/entity', () => ({ Entity: mock.Entity }))
9
- jest.mock('../../src/entities/set', () => ({ EntitySet: mock.EntitySet }))
10
-
11
- const { Factory } = require('../../src/entities/factory')
12
-
13
- let factory
14
-
15
- beforeEach(async () => {
16
- jest.clearAllMocks()
17
-
18
- factory = new Factory(fixtures.schema, () => fixtures.storage.id())
19
- })
20
-
21
- it('should create initial', () => {
22
- const id = generate()
23
- const initial = factory.init(id)
24
-
25
- expect(initial).toBeInstanceOf(mock.Entity)
26
- expect(initial.constructor).toHaveBeenCalledWith(fixtures.schema, id)
27
- })
28
-
29
- it('should create instance', () => {
30
- const object = factory.object(fixtures.entity)
31
-
32
- expect(object).toBeInstanceOf(mock.Entity)
33
- expect(object.constructor).toHaveBeenCalledWith(fixtures.schema, fixtures.entity)
34
- })
35
-
36
- it('should create set', () => {
37
- const objects = factory.objects(fixtures.set)
38
-
39
- expect(objects).toBeInstanceOf(mock.EntitySet)
40
-
41
- const instances = fixtures.set.map((entity, index) => {
42
- expect(mock.Entity).toHaveBeenNthCalledWith(index + 1, fixtures.schema, entity)
43
-
44
- return mock.Entity.mock.instances[index]
45
- })
46
-
47
- expect(objects.constructor).toHaveBeenCalledWith(instances)
48
- })
@@ -1,11 +0,0 @@
1
- 'use strict'
2
-
3
- const { generate } = require('randomstring')
4
-
5
- const set = [
6
- { get: jest.fn(() => ({ [generate()]: generate() })) },
7
- { get: jest.fn(() => ({ [generate()]: generate() })) },
8
- { get: jest.fn(() => ({ [generate()]: generate() })) }
9
- ]
10
-
11
- exports.set = set
@@ -1,12 +0,0 @@
1
- 'use strict'
2
-
3
- const { EntitySet } = require('../../src/entities/set')
4
- const fixtures = require('./set.fixtures')
5
-
6
- it('should provide state', () => {
7
- const set = new EntitySet(fixtures.set)
8
- const state = set.get()
9
- const expected = fixtures.set.map((entity) => entity.get.mock.results[0].value)
10
-
11
- expect(state).toStrictEqual(expected)
12
- })
@@ -1,29 +0,0 @@
1
- 'use strict'
2
-
3
- const { generate } = require('randomstring')
4
-
5
- const definition = {
6
- conditioned: true,
7
- subjective: true
8
- }
9
-
10
- // noinspection JSCheckFunctionSignatures
11
- const bridge = {
12
- condition: jest.fn(async (origin) => !origin.falsy),
13
- payload: jest.fn(async () => ({ [generate()]: generate() }))
14
- }
15
-
16
- const binding = {
17
- emit: jest.fn()
18
- }
19
-
20
- const event = {
21
- origin: { [generate()]: generate() },
22
- state: { [generate()]: generate() },
23
- changeset: { [generate()]: generate() }
24
- }
25
-
26
- exports.bridge = bridge
27
- exports.binding = binding
28
- exports.definition = definition
29
- exports.event = event
@@ -1,118 +0,0 @@
1
- 'use strict'
2
-
3
- const clone = require('clone-deep')
4
-
5
- jest.mock('../src/connector')
6
-
7
- const { Connector } = require('../src/connector')
8
- const { Event } = require('../src/event')
9
- const fixtures = require('./event.fixtures')
10
-
11
- let event, emit
12
-
13
- beforeEach(() => {
14
- jest.clearAllMocks()
15
-
16
- event = new Event(fixtures.definition, fixtures.binding, fixtures.bridge)
17
- emit = () => event.emit(fixtures.event)
18
- })
19
-
20
- it('should depend on binding', () => {
21
- expect(event).toBeInstanceOf(Connector)
22
- expect(Connector.mock.instances[0].depends).toHaveBeenCalledWith(fixtures.binding)
23
- })
24
-
25
- it('should depend on bridge if provided', () => {
26
- expect(Connector.mock.instances[0].depends).toHaveBeenCalledWith(fixtures.bridge)
27
-
28
- event = new Event(fixtures.definition, fixtures.binding)
29
- expect(Connector.mock.instances[1].depends).not.toHaveBeenCalledWith(fixtures.bridge)
30
- })
31
-
32
- describe('condition', () => {
33
- describe('conditioned', () => {
34
- it('should call condition', async () => {
35
- await emit()
36
-
37
- expect(fixtures.bridge.condition).toHaveBeenCalledWith(fixtures.event)
38
- })
39
-
40
- it('should emit if condition returns true', async () => {
41
- await emit()
42
-
43
- const payload = await fixtures.bridge.payload.mock.results[0].value
44
- const message = { payload }
45
- expect(fixtures.binding.emit).toHaveBeenCalledWith(message)
46
- })
47
-
48
- it('should not emit if condition returns false', async () => {
49
- const origin = clone(fixtures.event.origin)
50
-
51
- origin.falsy = true
52
-
53
- await event.emit(origin, fixtures.event.changeset, fixtures.event.state)
54
-
55
- expect(fixtures.binding.emit).not.toHaveBeenCalled()
56
- })
57
- })
58
-
59
- describe('unconditioned', () => {
60
- beforeEach(() => {
61
- const definition = clone(fixtures.definition)
62
-
63
- definition.conditioned = false
64
-
65
- event = new Event(definition, fixtures.binding, fixtures.bridge)
66
- })
67
-
68
- it('should not call condition', async () => {
69
- await event.emit(fixtures.event.origin, fixtures.event.changeset, fixtures.event.state)
70
-
71
- expect(fixtures.bridge.condition).not.toHaveBeenCalledWith()
72
-
73
- const payload = await fixtures.bridge.payload.mock.results[0].value
74
- const message = { payload }
75
-
76
- expect(fixtures.binding.emit).toHaveBeenCalledWith(message)
77
- })
78
- })
79
- })
80
-
81
- describe('payload', () => {
82
- describe('subjective', () => {
83
- it('should emit payload', async () => {
84
- await emit()
85
-
86
- const payload = await fixtures.bridge.payload.mock.results[0].value
87
- const message = { payload }
88
-
89
- expect(fixtures.binding.emit).toHaveBeenCalledWith(message)
90
- })
91
- })
92
-
93
- describe('objective', () => {
94
- beforeEach(() => {
95
- const definition = clone(fixtures.definition)
96
-
97
- definition.subjective = false
98
-
99
- event = new Event(definition, fixtures.binding, fixtures.bridge)
100
- emit = () => event.emit(fixtures.event)
101
- })
102
-
103
- it('should not call payload', async () => {
104
- await emit()
105
-
106
- expect(fixtures.bridge.payload).not.toHaveBeenCalled()
107
- })
108
-
109
- it('should return state as payload', async () => {
110
- await emit()
111
-
112
- const payload = fixtures.event.state
113
- const message = { payload }
114
-
115
- expect(fixtures.binding.emit).toHaveBeenCalledWith(message)
116
- })
117
- })
118
- })