@toa.io/bridges.node 1.0.0-alpha.182 → 1.0.0-alpha.190

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.182",
3
+ "version": "1.0.0-alpha.190",
4
4
  "description": "Toa Node Bridge (inproc)",
5
5
  "homepage": "https://toa.io",
6
6
  "author": {
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@babel/parser": "7.24.7",
30
- "@toa.io/core": "1.0.0-alpha.182",
30
+ "@toa.io/core": "1.0.0-alpha.190",
31
31
  "@toa.io/filesystem": "1.0.0-alpha.173",
32
32
  "@toa.io/generic": "1.0.0-alpha.173",
33
33
  "fast-glob": "3.2.7",
@@ -36,5 +36,5 @@
36
36
  "devDependencies": {
37
37
  "clone-deep": "4.0.1"
38
38
  },
39
- "gitHead": "99d0b79680455e8746274bcfa07a5674e8514bff"
39
+ "gitHead": "494b1c8f05c21f377f1152a9d89df5cbbd1001de"
40
40
  }
@@ -0,0 +1,22 @@
1
+ 'use strict'
2
+
3
+ const load = require('../load')
4
+
5
+ const guard = async (root, label) => {
6
+ const module = await load.guard(root, label)
7
+
8
+ if (module.guard === undefined)
9
+ throw new Error(`Guard ${label} not found`)
10
+
11
+ return module.guard
12
+ }
13
+
14
+ const guards = async (root) => {
15
+ const modules = await load.guards(root)
16
+ const guards = modules.filter(([, module]) => module.guard !== undefined)
17
+
18
+ return Object.fromEntries(guards.map(([name, module]) => [name, {}]))
19
+ }
20
+
21
+ exports.guard = guard
22
+ exports.guards = guards
@@ -3,7 +3,9 @@
3
3
  const { events } = require('./events')
4
4
  const { receivers } = require('./receivers')
5
5
  const { operations } = require('./operations')
6
+ const { guards } = require('./guards')
6
7
 
7
8
  exports.events = events
8
9
  exports.receivers = receivers
9
10
  exports.operations = operations
11
+ exports.guards = guards
package/src/factory.js CHANGED
@@ -4,6 +4,7 @@ const load = require('./load')
4
4
  const { Runner } = require('./algorithms/runner')
5
5
  const { Event } = require('./event')
6
6
  const { Receiver } = require('./receiver')
7
+ const { Guard } = require('./guard')
7
8
  const { Context } = require('./context')
8
9
  const { extract } = require('./define/operations')
9
10
 
@@ -29,6 +30,13 @@ class Factory {
29
30
 
30
31
  return new Receiver(receiver)
31
32
  }
33
+
34
+ guard (root, label, context) {
35
+ const guard = load.guard(root, label)
36
+ const ctx = new Context(context)
37
+
38
+ return new Guard(guard, ctx)
39
+ }
32
40
  }
33
41
 
34
42
  /**
package/src/guard.js ADDED
@@ -0,0 +1,17 @@
1
+ 'use strict'
2
+
3
+ class Guard {
4
+ #guard
5
+ #context
6
+
7
+ constructor (guard, context) {
8
+ this.#guard = guard
9
+ this.#context = context
10
+ }
11
+
12
+ fit (state) {
13
+ return this.#guard.guard(state, this.#context)
14
+ }
15
+ }
16
+
17
+ exports.Guard = Guard
package/src/load.js CHANGED
@@ -6,6 +6,7 @@ const { file: { glob } } = require('@toa.io/filesystem')
6
6
  const operation = (root, name) => load(root, OPERATIONS_DIRECTORY, name)
7
7
  const event = (root, name) => load(root, EVENTS_DIRECTORY, name)
8
8
  const receiver = (root, name) => load(root, RECEIVERS_DIRECTORY, name)
9
+ const guard = (root, name) => load(root, GUARDS_DIRECTORY, name)
9
10
 
10
11
  const scan = (directory) => async (root) => {
11
12
  const pattern = resolve(root, directory, '*' + EXTENSION)
@@ -20,10 +21,13 @@ const EXTENSION = '.js'
20
21
  const EVENTS_DIRECTORY = 'events'
21
22
  const RECEIVERS_DIRECTORY = 'receivers'
22
23
  const OPERATIONS_DIRECTORY = 'operations'
24
+ const GUARDS_DIRECTORY = 'guards'
23
25
 
24
26
  exports.operation = operation
25
27
  exports.event = event
26
28
  exports.receiver = receiver
29
+ exports.guard = guard
27
30
  exports.operations = scan(OPERATIONS_DIRECTORY)
28
31
  exports.events = scan(EVENTS_DIRECTORY)
29
32
  exports.receivers = scan(RECEIVERS_DIRECTORY)
33
+ exports.guards = scan(GUARDS_DIRECTORY)