@toa.io/bridges.node 0.7.1 → 0.8.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/bridges.node",
3
- "version": "0.7.1",
3
+ "version": "0.8.0-dev.0",
4
4
  "description": "Toa Node Bridge (inproc)",
5
5
  "homepage": "https://toa.io",
6
6
  "author": {
@@ -26,13 +26,13 @@
26
26
  "test": "echo \"Error: run tests from root\" && exit 1"
27
27
  },
28
28
  "dependencies": {
29
- "@toa.io/core": "0.7.1",
30
- "@toa.io/filesystem": "0.7.0",
31
- "@toa.io/generic": "0.7.0",
29
+ "@toa.io/core": "0.8.0-dev.0",
30
+ "@toa.io/filesystem": "0.7.1-dev.0",
31
+ "@toa.io/generic": "0.8.0-dev.0",
32
32
  "fast-glob": "3.2.7"
33
33
  },
34
34
  "devDependencies": {
35
35
  "clone-deep": "4.0.1"
36
36
  },
37
- "gitHead": "9989ea316ebf5698b1eee933e83a86e6a18b406b"
37
+ "gitHead": "5f1bfd167bb7919492d249f78bbcc6bd9fc645a4"
38
38
  }
@@ -0,0 +1,9 @@
1
+ 'use strict'
2
+
3
+ const { generate } = require('randomstring')
4
+
5
+ const aspect = {
6
+ invoke: jest.fn(async () => generate)
7
+ }
8
+
9
+ exports.aspect = aspect
@@ -0,0 +1,16 @@
1
+ 'use strict'
2
+
3
+ const { underlay } = require('@toa.io/generic')
4
+
5
+ /** @type {toa.node.shortcut} */
6
+ const amqp = (context, aspect) => {
7
+ context.amqp = underlay(async (segs, args) => {
8
+ if (segs.length !== 2) throw new Error(`AMQP aspect call should have 2 segments [${segs.join(', ')}] given`)
9
+
10
+ const [origin, method] = segs
11
+
12
+ return aspect.invoke(origin, method, ...args)
13
+ })
14
+ }
15
+
16
+ exports.amqp = amqp
@@ -0,0 +1,38 @@
1
+ 'use strict'
2
+
3
+ const { generate } = require('randomstring')
4
+ const { random } = require('@toa.io/generic')
5
+
6
+ const { aspect } = require('./.test/mock.aspect')
7
+ const { amqp } = require('./amqp')
8
+
9
+ it('should be', async () => {
10
+ expect(amqp).toBeInstanceOf(Function)
11
+ })
12
+
13
+ /** @type {toa.node.Context} */
14
+ let context
15
+
16
+ beforeEach(() => {
17
+ jest.clearAllMocks()
18
+
19
+ context = /** @type {toa.node.Context} */ {}
20
+
21
+ amqp(context, aspect)
22
+ })
23
+
24
+ it('should define shortcut', async () => {
25
+ expect(context.amqp).toBeDefined()
26
+ })
27
+
28
+ it('should call invoke', async () => {
29
+ const args = Array.from({ length: random(5) + 2 }, generate)
30
+
31
+ await context.amqp.test.emit(...args)
32
+
33
+ expect(aspect.invoke).toHaveBeenCalledWith('test', 'emit', ...args)
34
+ })
35
+
36
+ it('should throw if wrong amount of segments', async () => {
37
+ await expect(context.amqp.one.two.emit()).rejects.toThrow('AMQP aspect call should have 2 segments [one, two, emit] given')
38
+ })
@@ -3,8 +3,8 @@
3
3
  const { underlay } = require('@toa.io/generic')
4
4
 
5
5
  /** @type {toa.node.shortcut} */
6
- const origins = (context, aspect) => {
7
- context.origins = underlay(async (segs, args) => {
6
+ const http = (context, aspect) => {
7
+ context.http = underlay(async (segs, args) => {
8
8
  if (segs.length < 2) throw new Error(`Origins call requires at least 2 arguments, ${segs.length} given`)
9
9
 
10
10
  const name = segs.shift()
@@ -17,4 +17,4 @@ const origins = (context, aspect) => {
17
17
  })
18
18
  }
19
19
 
20
- exports.origins = origins
20
+ exports.http = http
@@ -1,9 +1,11 @@
1
1
  'use strict'
2
2
 
3
- const { origins } = require('./origins')
3
+ const { http } = require('./http')
4
+ const { amqp } = require('./amqp')
4
5
  const { configuration } = require('./configuration')
5
6
  const { state } = require('./state')
6
7
 
7
- exports.origins = origins
8
+ exports.http = http
9
+ exports.amqp = amqp
8
10
  exports.configuration = configuration
9
11
  exports.state = state
@@ -5,7 +5,7 @@ const context = /** @type {toa.core.Context} */ {
5
5
  call: jest.fn(),
6
6
  aspects: [
7
7
  {
8
- name: 'origins',
8
+ name: 'http',
9
9
  invoke: jest.fn()
10
10
  }
11
11
  ],
@@ -2,7 +2,7 @@
2
2
 
3
3
  const { generate } = require('randomstring')
4
4
 
5
- const fixtures = require('./context.origins.fixtures')
5
+ const fixtures = require('./context.http.fixtures')
6
6
  const { Context } = require('../src/context')
7
7
 
8
8
  const origins = fixtures.context.aspects[0]
@@ -18,14 +18,14 @@ beforeEach(async () => {
18
18
  })
19
19
 
20
20
  it('should expose aspect', async () => {
21
- expect(context.aspects.origins).toBeDefined()
21
+ expect(context.aspects.http).toBeDefined()
22
22
  })
23
23
 
24
24
  it('should invoke', async () => {
25
25
  const name = generate()
26
26
  const arg = { [generate()]: generate() }
27
27
 
28
- await context.origins[name].baz.quu.get(arg)
28
+ await context.http[name].baz.quu.get(arg)
29
29
 
30
30
  expect(origins.invoke).toHaveBeenCalled()
31
31
  expect(origins.invoke).toHaveBeenCalledWith(name, 'baz/quu', expect.objectContaining(arg), undefined)
@@ -34,20 +34,20 @@ it('should invoke', async () => {
34
34
  it('should define request method', async () => {
35
35
  const arg = { [generate()]: generate() }
36
36
 
37
- await context.origins.foo.post(arg)
38
- await context.origins.bar.baz.put()
37
+ await context.http.foo.post(arg)
38
+ await context.http.bar.baz.put()
39
39
 
40
40
  expect(origins.invoke).toHaveBeenNthCalledWith(1, 'foo', '', { method: 'POST', ...arg }, undefined)
41
41
  expect(origins.invoke).toHaveBeenNthCalledWith(2, 'bar', 'baz', { method: 'PUT' }, undefined)
42
42
  })
43
43
 
44
44
  it('should throw if no origin name specified', async () => {
45
- await expect(context.origins.get()).rejects.toThrow(/at least 2 arguments/)
45
+ await expect(context.http.get()).rejects.toThrow(/at least 2 arguments/)
46
46
  })
47
47
 
48
48
  it('should pass options', async () => {
49
49
  const options = { [generate()]: generate() }
50
- await context.origins.foo.post({}, options)
50
+ await context.http.foo.post({}, options)
51
51
 
52
52
  expect(origins.invoke.mock.calls[0][3]).toStrictEqual(options)
53
53
  })
@@ -10,7 +10,8 @@ declare namespace toa.node {
10
10
  aspects: Record<string, Function>
11
11
 
12
12
  // known extensions
13
- origins?: Underlay
13
+ http?: Underlay
14
+ amqp?: Underlay
14
15
  configuration?: object
15
16
  state?: object
16
17
  }