@toa.io/bridges.node 1.0.0-alpha.28 → 1.0.0-alpha.29

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": "1.0.0-alpha.28",
3
+ "version": "1.0.0-alpha.29",
4
4
  "description": "Toa Node Bridge (inproc)",
5
5
  "homepage": "https://toa.io",
6
6
  "author": {
@@ -26,14 +26,14 @@
26
26
  "test": "echo \"Error: run tests from root\" && exit 1"
27
27
  },
28
28
  "dependencies": {
29
- "@toa.io/core": "1.0.0-alpha.28",
30
- "@toa.io/filesystem": "1.0.0-alpha.28",
31
- "@toa.io/generic": "1.0.0-alpha.28",
29
+ "@toa.io/core": "1.0.0-alpha.29",
30
+ "@toa.io/filesystem": "1.0.0-alpha.29",
31
+ "@toa.io/generic": "1.0.0-alpha.29",
32
32
  "fast-glob": "3.2.7",
33
33
  "matchacho": "0.3.5"
34
34
  },
35
35
  "devDependencies": {
36
36
  "clone-deep": "4.0.1"
37
37
  },
38
- "gitHead": "89c3b7d1314e357c9e33df8d95f8d46954cd3bcf"
38
+ "gitHead": "186d0e17c12a9016b8076edf925963cbb32b9219"
39
39
  }
package/src/context.js CHANGED
@@ -54,7 +54,8 @@ class Context extends Connector {
54
54
 
55
55
  map[aspect.name] = aspect.invoke.bind(aspect)
56
56
 
57
- if (aspect.name in shortcuts) shortcuts[aspect.name](this, aspect)
57
+ if (aspect.name in shortcuts)
58
+ shortcuts[aspect.name](this, aspect)
58
59
  }
59
60
 
60
61
  return map
@@ -1,11 +1,12 @@
1
1
  'use strict'
2
2
 
3
3
  const { underlay } = require('@toa.io/generic')
4
+ const assert = require('node:assert')
4
5
 
5
6
  /** @type {toa.node.shortcut} */
6
- const amqp = (context, aspect) => {
7
+ function amqp (context, aspect) {
7
8
  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
+ assert(segs.length === 2, `AMQP aspect call should have 2 segments [${segs.join(', ')}] given`)
9
10
 
10
11
  const [origin, method] = segs
11
12
 
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  /** @type {toa.node.shortcut} */
4
- const configuration = (context, aspect) => {
4
+ function configuration (context, aspect) {
5
5
  Object.defineProperty(context, 'configuration', {
6
6
  get: () => aspect.invoke()
7
7
  })
@@ -3,7 +3,7 @@
3
3
  const { underlay } = require('@toa.io/generic')
4
4
 
5
5
  /** @type {toa.node.shortcut} */
6
- const http = (context, aspect) => {
6
+ function http (context, aspect) {
7
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
 
@@ -6,6 +6,7 @@ const { configuration } = require('./configuration')
6
6
  const { state } = require('./state')
7
7
  const { stash } = require('./stash')
8
8
  const { storages } = require('./storages')
9
+ const { pubsub } = require('./pubsub')
9
10
 
10
11
  exports.http = http
11
12
  exports.amqp = amqp
@@ -13,3 +14,4 @@ exports.configuration = configuration
13
14
  exports.state = state
14
15
  exports.stash = stash
15
16
  exports.storages = storages
17
+ exports.pubsub = pubsub
@@ -0,0 +1,16 @@
1
+ 'use strict'
2
+
3
+ const { underlay } = require('@toa.io/generic')
4
+ const assert = require('node:assert')
5
+
6
+ function pubsub (context, aspect) {
7
+ context.pubsub = underlay(async (segs, args) => {
8
+ assert(segs.length === 2, `Pub/Sub aspect call should have 2 segments [${segs.join(', ')}] given`)
9
+
10
+ const [origin, method] = segs
11
+
12
+ return aspect.invoke(method, origin, ...args)
13
+ })
14
+ }
15
+
16
+ exports.pubsub = pubsub
@@ -3,7 +3,7 @@
3
3
  const { underlay } = require('@toa.io/generic')
4
4
 
5
5
  /** @type {toa.node.shortcut} */
6
- const stash = (context, aspect) => {
6
+ function stash (context, aspect) {
7
7
  context.stash = underlay(async (segs, args) => {
8
8
  if (segs.length !== 1)
9
9
  throw new Error(`Stash aspect call should have 1 segment, [${segs.join(', ')}] given`)
@@ -3,7 +3,7 @@
3
3
  const { generate } = require('@toa.io/generic')
4
4
 
5
5
  /** @type {toa.node.shortcut} */
6
- const state = (context, aspect) => {
6
+ function state (context, aspect) {
7
7
  context.state = generate((segs, value) => {
8
8
  if (value === undefined) return get(aspect, segs)
9
9
  else set(aspect, segs, value)