@toa.io/core 0.6.0-dev.0 → 0.6.0-dev.2

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2020-present Artem Gurtovoi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/core",
3
- "version": "0.6.0-dev.0",
3
+ "version": "0.6.0-dev.2",
4
4
  "description": "Toa Core",
5
5
  "author": "temich <tema.gurtovoy@gmail.com>",
6
6
  "homepage": "https://github.com/toa-io/toa#readme",
@@ -20,10 +20,10 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@rsql/parser": "1.2.4",
23
- "@toa.io/console": "0.4.0",
24
- "@toa.io/generic": "0.6.0-dev.0",
25
- "@toa.io/yaml": "0.6.0-dev.0",
23
+ "@toa.io/console": "0.6.0-dev.1",
24
+ "@toa.io/generic": "0.6.0-dev.1",
25
+ "@toa.io/yaml": "0.6.0-dev.1",
26
26
  "clone-deep": "4.0.1"
27
27
  },
28
- "gitHead": "2be07592325b2e4dc823e81d882a4e50bf50de24"
28
+ "gitHead": "6bd9397a983ffc543817e60cf64a3315206c4500"
29
29
  }
package/src/receiver.js CHANGED
@@ -13,9 +13,6 @@ class Receiver extends Connector {
13
13
  /** @type {boolean} */
14
14
  #adaptive
15
15
 
16
- /** @type {boolean} */
17
- #foreign
18
-
19
16
  /** @type {string} */
20
17
  #endpoint
21
18
 
@@ -34,11 +31,10 @@ class Receiver extends Connector {
34
31
  constructor (definition, local, bridge) {
35
32
  super()
36
33
 
37
- const { conditioned, adaptive, foreign, transition } = definition
34
+ const { conditioned, adaptive, transition } = definition
38
35
 
39
36
  this.#conditioned = conditioned
40
37
  this.#adaptive = adaptive
41
- this.#foreign = foreign
42
38
  this.#endpoint = transition
43
39
 
44
40
  this.#local = local
@@ -50,13 +46,13 @@ class Receiver extends Connector {
50
46
 
51
47
  /** @hot */
52
48
  async receive (message) {
53
- const { payload, extensions } = this.#parse(message)
49
+ const { payload, ...extensions } = message
54
50
 
55
51
  if (this.#conditioned && await this.#bridge.condition(payload) === false) return
56
52
 
57
53
  const request = await this.#request(payload)
58
54
 
59
- if (extensions !== undefined) add(request, extensions)
55
+ if (extensions) add(request, extensions)
60
56
 
61
57
  await this.#local.invoke(this.#endpoint, request)
62
58
  }
@@ -64,23 +60,6 @@ class Receiver extends Connector {
64
60
  async #request (payload) {
65
61
  return this.#adaptive ? await this.#bridge.request(payload) : payload
66
62
  }
67
-
68
- /**
69
- * @param {toa.core.Message | any} message
70
- * @return {{payload: any, extensions: object | undefined}}
71
- */
72
- #parse (message) {
73
- if (this.#foreign) {
74
- return {
75
- payload: message,
76
- extensions: undefined
77
- }
78
- }
79
-
80
- const { payload, ...extensions } = message
81
-
82
- return { payload, extensions }
83
- }
84
63
  }
85
64
 
86
65
  exports.Receiver = Receiver
@@ -93,18 +93,3 @@ describe('adaptive', () => {
93
93
  .toHaveBeenCalledWith(definition.transition, await fixtures.bridge.request.mock.results[0].value)
94
94
  })
95
95
  })
96
-
97
- describe('foreign', () => {
98
- beforeEach(() => {
99
- definition.foreign = true
100
- receiver = new Receiver(definition, fixtures.local, fixtures.bridge)
101
- })
102
-
103
- it('should wrap data from foreign event to payload', async () => {
104
- const payload = { foo: generate() }
105
-
106
- await receiver.receive(payload)
107
-
108
- expect(fixtures.local.invoke).toHaveBeenCalledWith(definition.transition, payload)
109
- })
110
- })
@@ -4,7 +4,7 @@ import * as _connector from './connector'
4
4
  declare namespace toa.core {
5
5
 
6
6
  interface Receiver extends _connector.Connector {
7
- receive(message: _message.Message | any): Promise<void>
7
+ receive(message: _message.Message): Promise<void>
8
8
  }
9
9
 
10
10
  }