@toa.io/bridges.node 0.20.0-alpha.1 → 0.20.0-alpha.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/bridges.node",
3
- "version": "0.20.0-alpha.1",
3
+ "version": "0.20.0-alpha.2",
4
4
  "description": "Toa Node Bridge (inproc)",
5
5
  "homepage": "https://toa.io",
6
6
  "author": {
@@ -29,13 +29,13 @@
29
29
  "nopeable": "*"
30
30
  },
31
31
  "dependencies": {
32
- "@toa.io/core": "0.20.0-alpha.1",
33
- "@toa.io/filesystem": "0.20.0-alpha.1",
34
- "@toa.io/generic": "0.20.0-alpha.1",
32
+ "@toa.io/core": "0.20.0-alpha.2",
33
+ "@toa.io/filesystem": "0.20.0-alpha.2",
34
+ "@toa.io/generic": "0.20.0-alpha.2",
35
35
  "fast-glob": "3.2.7"
36
36
  },
37
37
  "devDependencies": {
38
38
  "clone-deep": "4.0.1"
39
39
  },
40
- "gitHead": "d1a5369c0ee4ee423f792b83e9753fd2fd943cce"
40
+ "gitHead": "d6e8c5bdae26e2beb66f4d7f37f71a3494fe9fcb"
41
41
  }
@@ -2,6 +2,7 @@
2
2
 
3
3
  const { Nope } = require('nopeable')
4
4
  const { Connector } = require('@toa.io/core')
5
+ const { Readable } = require('node:stream')
5
6
 
6
7
  class Runner extends Connector {
7
8
  /** @type {toa.node.Algorithm} */
@@ -27,9 +28,18 @@ class Runner extends Connector {
27
28
  const reply = await this.#algorithm.execute(input, state)
28
29
 
29
30
  if (reply instanceof Nope) return { error: reply }
30
- else if (reply === undefined) return undefined
31
+ else if (isGenerator(reply)) return Readable.from(reply)
32
+ else if (reply instanceof Readable) return reply
31
33
  else return { output: reply }
32
34
  }
33
35
  }
34
36
 
37
+ function isGenerator (object) {
38
+ const constructor = object?.constructor?.[Symbol.toStringTag]
39
+
40
+ return constructor !== undefined &&
41
+ (constructor === 'AsyncGeneratorFunction' ||
42
+ constructor === 'GeneratorFunction')
43
+ }
44
+
35
45
  exports.Runner = Runner
@@ -10,7 +10,7 @@ const define = (descriptor) => {
10
10
  /** @type {toa.node.define.operations.Definition} */
11
11
  const definition = {}
12
12
 
13
- definition.type = /** @type {typeof toa.norm.component.Operation.type} */ name
13
+ definition.type = name
14
14
 
15
15
  if (node.params.length > 1) definition.scope = scope(node.params[1].name)
16
16
  if (node.params.length === 0) definition.input = null
@@ -29,7 +29,7 @@ const test = (statement, type) => {
29
29
 
30
30
  /**
31
31
  * @param {string} name
32
- * @returns {typeof toa.norm.component.Operation.scope}
32
+ * @returns {string}
33
33
  */
34
34
  const scope = (name) => scopes.includes(name) ? name : undefined
35
35
 
@@ -1,6 +1,6 @@
1
1
  import { bridges } from '@toa.io/core/types'
2
2
  import * as _context from './context'
3
- import * as _core from '@toa.io/core/types';
3
+ import * as _core from '@toa.io/core/types'
4
4
 
5
5
  declare namespace toa.node {
6
6
 
@@ -16,11 +16,11 @@ declare namespace toa.node {
16
16
  }
17
17
 
18
18
  interface Algorithm {
19
- mount?(context: _context.Context): Promise<void> | void
19
+ mount? (context: _context.Context): Promise<void> | void
20
20
 
21
- execute(input: any, scope: object | object[]): Promise<_core.Reply>
21
+ execute (input: any, scope: object | object[]): Promise<any>
22
22
 
23
- execute(input: any): Promise<_core.Reply>
23
+ execute (input: any): Promise<_core.Reply>
24
24
  }
25
25
 
26
26
  }