@toa.io/bindings.loop 1.0.0-alpha.272 → 1.0.0-alpha.277

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/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.0.0-alpha.277](https://github.com/toa-io/toa/compare/v1.0.0-alpha.276...v1.0.0-alpha.277) (2026-09-03)
7
+
8
+ **Note:** Version bump only for package @toa.io/bindings.loop
9
+
10
+
11
+
12
+
13
+
14
+ # [1.0.0-alpha.273](https://github.com/toa-io/toa/compare/v1.0.0-alpha.272...v1.0.0-alpha.273) (2026-09-02)
15
+
16
+ **Note:** Version bump only for package @toa.io/bindings.loop
17
+
18
+
19
+
20
+
21
+
6
22
  # [1.0.0-alpha.272](https://github.com/toa-io/toa/compare/v1.0.0-alpha.271...v1.0.0-alpha.272) (2026-09-01)
7
23
 
8
24
 
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@toa.io/bindings.loop",
3
- "version": "1.0.0-alpha.272",
3
+ "version": "1.0.0-alpha.277",
4
+ "type": "module",
4
5
  "description": "Toa Loop Binding",
5
6
  "author": "temich <tema.gurtovoy@gmail.com>",
6
7
  "homepage": "https://github.com/toa-io/toa#readme",
@@ -19,8 +20,8 @@
19
20
  "test": "echo \"Error: run tests from root\" && exit 1"
20
21
  },
21
22
  "dependencies": {
22
- "@toa.io/core": "1.0.0-alpha.272",
23
- "@toa.io/generic": "1.0.0-alpha.272"
23
+ "@toa.io/core": "1.0.0-alpha.277",
24
+ "@toa.io/generic": "1.0.0-alpha.277"
24
25
  },
25
- "gitHead": "1a451755445935c04cf5b373bcc73942cac0bb10"
26
+ "gitHead": "0c0071418c2c56a44e621ba5ced5cdd23dff1738"
26
27
  }
package/src/consumer.js CHANGED
@@ -1,8 +1,6 @@
1
- 'use strict'
1
+ import { Connector } from '@toa.io/core'
2
2
 
3
- const { Connector } = require('@toa.io/core')
4
-
5
- class Consumer extends Connector {
3
+ export class Consumer extends Connector {
6
4
  #bindings
7
5
  #locator
8
6
  #endpoint
@@ -22,5 +20,3 @@ class Consumer extends Connector {
22
20
  else return invoke(request)
23
21
  }
24
22
  }
25
-
26
- exports.Consumer = Consumer
package/src/factory.js CHANGED
@@ -1,9 +1,7 @@
1
- 'use strict'
1
+ import { Producer } from './producer.js'
2
+ import { Consumer } from './consumer.js'
2
3
 
3
- const { Producer } = require('./producer')
4
- const { Consumer } = require('./consumer')
5
-
6
- class Factory {
4
+ export class Factory {
7
5
  #bindings = {}
8
6
 
9
7
  producer (locator, endpoints, producer) {
@@ -14,5 +12,3 @@ class Factory {
14
12
  return new Consumer(this.#bindings, locator, endpoint)
15
13
  }
16
14
  }
17
-
18
- exports.Factory = Factory
package/src/index.js CHANGED
@@ -1,6 +1,3 @@
1
- 'use strict'
1
+ export const properties = { async: false, local: true }
2
2
 
3
- const { Factory } = require('./factory')
4
-
5
- exports.Factory = Factory
6
- exports.properties = { async: false, local: true }
3
+ export { Factory } from './factory.js'
package/src/producer.js CHANGED
@@ -1,8 +1,6 @@
1
- 'use strict'
1
+ import { Connector } from '@toa.io/core'
2
2
 
3
- const { Connector } = require('@toa.io/core')
4
-
5
- class Producer extends Connector {
3
+ export class Producer extends Connector {
6
4
  #binding
7
5
  #endpoints
8
6
  #producer
@@ -33,5 +31,3 @@ class Producer extends Connector {
33
31
  this.#binding[endpoint] = async (request) => this.#producer.invoke(endpoint, request)
34
32
  }
35
33
  }
36
-
37
- exports.Producer = Producer
package/test/fixtures.js CHANGED
@@ -1,8 +1,8 @@
1
- 'use strict'
1
+ import { mock } from 'node:test'
2
2
 
3
- const { generate } = require('randomstring')
3
+ import { generate } from 'randomstring'
4
4
 
5
- const component = {
5
+ export const component = {
6
6
  locator: {
7
7
  id: 'foo.bar',
8
8
  operations: [
@@ -17,21 +17,17 @@ const component = {
17
17
  }
18
18
  ]
19
19
  },
20
- invoke: jest.fn(async () => generate()),
20
+ invoke: mock.fn(async () => generate()),
21
21
  link: () => null,
22
22
  connect: () => null,
23
23
  disconnect: () => null
24
24
  }
25
25
 
26
- const endpoints = ['get', 'add', 'discover']
26
+ export const endpoints = ['get', 'add', 'discover']
27
27
 
28
- const exposition = {
28
+ export const exposition = {
29
29
  locator: {
30
30
  id: 'foo.bar'
31
31
  },
32
- invoke: jest.fn(async () => generate())
32
+ invoke: mock.fn(async () => generate())
33
33
  }
34
-
35
- exports.component = component
36
- exports.endpoints = endpoints
37
- exports.exposition = exposition
@@ -0,0 +1,81 @@
1
+ import { it, before, after, beforeEach, afterEach, mock } from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import clone from 'clone-deep'
5
+ import { sample } from '@toa.io/generic'
6
+
7
+ import { Factory } from '../src/factory.js'
8
+ import * as fixtures from './fixtures.js'
9
+
10
+ const factory = new Factory()
11
+ const producer = factory.producer(fixtures.component.locator, fixtures.endpoints, fixtures.component)
12
+
13
+ let consumer, endpoint
14
+
15
+ before(async () => {
16
+ await producer.connect()
17
+ })
18
+
19
+ after(async () => {
20
+ await producer.disconnect()
21
+ })
22
+
23
+ beforeEach(async () => {
24
+ resetCalls()
25
+
26
+ endpoint = sample(fixtures.endpoints)
27
+ consumer = factory.consumer(fixtures.component.locator, endpoint)
28
+
29
+ await consumer.connect()
30
+ })
31
+
32
+ afterEach(async () => {
33
+ await consumer.disconnect()
34
+ })
35
+
36
+ it('should bind', async () => {
37
+ const r1 = await consumer.request(1)
38
+ const r2 = await consumer.request(2)
39
+
40
+ const calls = fixtures.component.invoke.mock.calls
41
+
42
+ assert.strictEqual(calls.length, 2)
43
+ assert.deepStrictEqual(calls[0].arguments, [endpoint, 1])
44
+ assert.deepStrictEqual(calls[1].arguments, [endpoint, 2])
45
+
46
+ assert.strictEqual(r1, await calls[0].result)
47
+ assert.strictEqual(r2, await calls[1].result)
48
+ })
49
+
50
+ it('should return false if no binding', async () => {
51
+ const consumer = factory.consumer({ id: 'not.existent' }, endpoint)
52
+ const result = await consumer.request()
53
+
54
+ assert.strictEqual(result, false)
55
+ })
56
+
57
+ it('should not depend on initialization order', async () => {
58
+ const component = clone(fixtures.component)
59
+
60
+ component.locator.id = 'other.name'
61
+
62
+ const consumer = factory.consumer(component.locator, endpoint)
63
+ await consumer.connect()
64
+
65
+ assert.strictEqual(await consumer.request(), false)
66
+
67
+ const producer = factory.producer(component.locator, fixtures.endpoints, component)
68
+ await producer.connect()
69
+
70
+ assert.strictEqual(await consumer.request(), await component.invoke.mock.calls[0].result)
71
+ })
72
+
73
+ function resetCalls (target = [fixtures], seen = new Set()) {
74
+ if (target === null || typeof target !== 'object' || seen.has(target)) return
75
+
76
+ seen.add(target)
77
+
78
+ for (const value of Object.values(target))
79
+ if (typeof value === 'function' && value.mock !== undefined) value.mock.resetCalls()
80
+ else resetCalls(value, seen)
81
+ }
@@ -1,7 +1,8 @@
1
- 'use strict'
1
+ import { it } from 'node:test'
2
+ import assert from 'node:assert/strict'
2
3
 
3
- const { properties } = require('../')
4
+ import { properties } from '../src/index.js'
4
5
 
5
6
  it('should export properties', async () => {
6
- expect(properties).toStrictEqual({ async: false, local: true })
7
+ assert.deepStrictEqual(properties, { async: false, local: true })
7
8
  })
package/test/test.js DELETED
@@ -1,68 +0,0 @@
1
- 'use strict'
2
-
3
- const clone = require('clone-deep')
4
- const { sample } = require('@toa.io/generic')
5
-
6
- const { Factory } = require('../src/factory')
7
- const fixtures = require('./fixtures')
8
-
9
- const factory = new Factory()
10
- const producer = factory.producer(fixtures.component.locator, fixtures.endpoints, fixtures.component)
11
-
12
- let consumer, endpoint
13
-
14
- beforeAll(async () => {
15
- await producer.connect()
16
- })
17
-
18
- afterAll(async () => {
19
- await producer.disconnect()
20
- })
21
-
22
- beforeEach(async () => {
23
- jest.clearAllMocks()
24
-
25
- endpoint = sample(fixtures.endpoints)
26
- consumer = factory.consumer(fixtures.component.locator, endpoint)
27
-
28
- await consumer.connect()
29
- })
30
-
31
- afterEach(async () => {
32
- await consumer.disconnect()
33
- })
34
-
35
- it('should bind', async () => {
36
- const r1 = await consumer.request(1)
37
- const r2 = await consumer.request(2)
38
-
39
- expect(fixtures.component.invoke).toHaveBeenCalledTimes(2)
40
- expect(fixtures.component.invoke).toHaveBeenNthCalledWith(1, endpoint, 1)
41
- expect(fixtures.component.invoke).toHaveBeenNthCalledWith(2, endpoint, 2)
42
-
43
- expect(r1).toBe(await fixtures.component.invoke.mock.results[0].value)
44
- expect(r2).toBe(await fixtures.component.invoke.mock.results[1].value)
45
- })
46
-
47
- it('should return false if no binding', async () => {
48
- const consumer = factory.consumer({ id: 'not.existent' }, endpoint)
49
- const result = await consumer.request()
50
-
51
- expect(result).toBe(false)
52
- })
53
-
54
- it('should not depend on initialization order', async () => {
55
- const component = clone(fixtures.component)
56
-
57
- component.locator.id = 'other.name'
58
-
59
- const consumer = factory.consumer(component.locator, endpoint)
60
- await consumer.connect()
61
-
62
- expect(await consumer.request()).toBe(false)
63
-
64
- const producer = factory.producer(component.locator, fixtures.endpoints, component)
65
- await producer.connect()
66
-
67
- expect(await consumer.request()).toBe(await component.invoke.mock.results[0].value)
68
- })