@toa.io/core 0.8.1 → 1.0.0-dev.0
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.
- package/package.json +3 -3
- package/src/receiver.js +7 -7
- package/test/receiver.fixtures.js +1 -1
- package/test/receiver.test.js +4 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-dev.0",
|
|
4
4
|
"description": "Toa Core",
|
|
5
5
|
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/toa-io/toa#readme",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"@rsql/parser": "1.2.4",
|
|
23
23
|
"@toa.io/console": "0.6.0",
|
|
24
24
|
"@toa.io/generic": "0.9.0",
|
|
25
|
-
"@toa.io/yaml": "0.7.
|
|
25
|
+
"@toa.io/yaml": "0.7.4-dev.0",
|
|
26
26
|
"clone-deep": "4.0.1"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "2417f76be3783bd7f790cb4580e4139f2c3ff580"
|
|
29
29
|
}
|
package/src/receiver.js
CHANGED
|
@@ -19,29 +19,29 @@ class Receiver extends Connector {
|
|
|
19
19
|
/** @type {toa.core.Component} */
|
|
20
20
|
#local
|
|
21
21
|
|
|
22
|
-
/** @type {toa.core.bridges.
|
|
22
|
+
/** @type {toa.core.bridges.Receiver} */
|
|
23
23
|
#bridge
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
*
|
|
27
27
|
* @param {toa.norm.component.Receiver} definition
|
|
28
28
|
* @param {toa.core.Component} local
|
|
29
|
-
* @param {toa.core.bridges.
|
|
29
|
+
* @param {toa.core.bridges.Receiver} bridge
|
|
30
30
|
*/
|
|
31
31
|
constructor (definition, local, bridge) {
|
|
32
32
|
super()
|
|
33
33
|
|
|
34
|
-
const { conditioned, adaptive,
|
|
34
|
+
const { conditioned, adaptive, operation } = definition
|
|
35
35
|
|
|
36
36
|
this.#conditioned = conditioned
|
|
37
37
|
this.#adaptive = adaptive
|
|
38
|
-
this.#endpoint =
|
|
38
|
+
this.#endpoint = operation
|
|
39
39
|
|
|
40
40
|
this.#local = local
|
|
41
41
|
this.#bridge = bridge
|
|
42
42
|
|
|
43
43
|
this.depends(local)
|
|
44
|
-
this.depends(bridge)
|
|
44
|
+
if (bridge !== undefined) this.depends(bridge)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/** @hot */
|
|
@@ -52,13 +52,13 @@ class Receiver extends Connector {
|
|
|
52
52
|
|
|
53
53
|
const request = await this.#request(payload)
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
add(request, extensions)
|
|
56
56
|
|
|
57
57
|
await this.#local.invoke(this.#endpoint, request)
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
async #request (payload) {
|
|
61
|
-
return this.#adaptive ? await this.#bridge.request(payload) : payload
|
|
61
|
+
return this.#adaptive ? await this.#bridge.request(payload) : { input: payload }
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
package/test/receiver.test.js
CHANGED
|
@@ -34,7 +34,7 @@ it('should apply', async () => {
|
|
|
34
34
|
|
|
35
35
|
await receiver.receive({ payload })
|
|
36
36
|
|
|
37
|
-
expect(fixtures.local.invoke).toHaveBeenCalledWith(definition.
|
|
37
|
+
expect(fixtures.local.invoke).toHaveBeenCalledWith(definition.operation, { input: payload })
|
|
38
38
|
})
|
|
39
39
|
|
|
40
40
|
it.each([[false], [true]])('should pass UI extensions (adaptive: %s)', async (adaptive) => {
|
|
@@ -49,7 +49,7 @@ it.each([[false], [true]])('should pass UI extensions (adaptive: %s)', async (ad
|
|
|
49
49
|
|
|
50
50
|
await receiver.receive(message)
|
|
51
51
|
|
|
52
|
-
const request = adaptive ? await fixtures.bridge.request.mock.results[0].value : payload
|
|
52
|
+
const request = adaptive ? await fixtures.bridge.request.mock.results[0].value : { input: payload }
|
|
53
53
|
const expected = merge(clone(request), extension)
|
|
54
54
|
|
|
55
55
|
const argument = fixtures.local.invoke.mock.calls[0][1]
|
|
@@ -68,7 +68,7 @@ describe('conditioned', () => {
|
|
|
68
68
|
await receiver.receive({ payload })
|
|
69
69
|
|
|
70
70
|
expect(fixtures.bridge.condition).toHaveBeenCalledWith(payload)
|
|
71
|
-
expect(fixtures.local.invoke).toHaveBeenCalledWith(definition.
|
|
71
|
+
expect(fixtures.local.invoke).toHaveBeenCalledWith(definition.operation, { input: payload })
|
|
72
72
|
})
|
|
73
73
|
|
|
74
74
|
it('should not apply if condition is false', async () => {
|
|
@@ -90,6 +90,6 @@ describe('adaptive', () => {
|
|
|
90
90
|
await receiver.receive({ payload })
|
|
91
91
|
|
|
92
92
|
expect(fixtures.local.invoke)
|
|
93
|
-
.toHaveBeenCalledWith(definition.
|
|
93
|
+
.toHaveBeenCalledWith(definition.operation, await fixtures.bridge.request.mock.results[0].value)
|
|
94
94
|
})
|
|
95
95
|
})
|