@toa.io/bindings.loop 1.0.0-alpha.32 → 1.0.0-alpha.321

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 ADDED
@@ -0,0 +1,182 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [1.0.0-alpha.321](https://github.com/toa-io/toa/compare/v1.0.0-alpha.320...v1.0.0-alpha.321) (2026-09-28)
7
+
8
+ **Note:** Version bump only for package @toa.io/bindings.loop
9
+
10
+
11
+
12
+
13
+
14
+ # [1.0.0-alpha.320](https://github.com/toa-io/toa/compare/v1.0.0-alpha.319...v1.0.0-alpha.320) (2026-09-28)
15
+
16
+ **Note:** Version bump only for package @toa.io/bindings.loop
17
+
18
+
19
+
20
+
21
+
22
+ # [1.0.0-alpha.319](https://github.com/toa-io/toa/compare/v1.0.0-alpha.318...v1.0.0-alpha.319) (2026-09-27)
23
+
24
+ **Note:** Version bump only for package @toa.io/bindings.loop
25
+
26
+
27
+
28
+
29
+
30
+ # [1.0.0-alpha.315](https://github.com/toa-io/toa/compare/v1.0.0-alpha.314...v1.0.0-alpha.315) (2026-09-23)
31
+
32
+ **Note:** Version bump only for package @toa.io/bindings.loop
33
+
34
+
35
+
36
+
37
+
38
+ # [1.0.0-alpha.314](https://github.com/toa-io/toa/compare/v1.0.0-alpha.313...v1.0.0-alpha.314) (2026-09-19)
39
+
40
+ **Note:** Version bump only for package @toa.io/bindings.loop
41
+
42
+
43
+
44
+
45
+
46
+ # [1.0.0-alpha.312](https://github.com/toa-io/toa/compare/v1.0.0-alpha.311...v1.0.0-alpha.312) (2026-09-18)
47
+
48
+ **Note:** Version bump only for package @toa.io/bindings.loop
49
+
50
+
51
+
52
+
53
+
54
+ # [1.0.0-alpha.311](https://github.com/toa-io/toa/compare/v1.0.0-alpha.310...v1.0.0-alpha.311) (2026-09-17)
55
+
56
+ **Note:** Version bump only for package @toa.io/bindings.loop
57
+
58
+
59
+
60
+
61
+
62
+ # [1.0.0-alpha.310](https://github.com/toa-io/toa/compare/v1.0.0-alpha.309...v1.0.0-alpha.310) (2026-09-16)
63
+
64
+ **Note:** Version bump only for package @toa.io/bindings.loop
65
+
66
+
67
+
68
+
69
+
70
+ # [1.0.0-alpha.308](https://github.com/toa-io/toa/compare/v1.0.0-alpha.307...v1.0.0-alpha.308) (2026-09-15)
71
+
72
+ **Note:** Version bump only for package @toa.io/bindings.loop
73
+
74
+
75
+
76
+
77
+
78
+ # [1.0.0-alpha.306](https://github.com/toa-io/toa/compare/v1.0.0-alpha.305...v1.0.0-alpha.306) (2026-09-14)
79
+
80
+ **Note:** Version bump only for package @toa.io/bindings.loop
81
+
82
+
83
+
84
+
85
+
86
+ # [1.0.0-alpha.305](https://github.com/toa-io/toa/compare/v1.0.0-alpha.304...v1.0.0-alpha.305) (2026-09-13)
87
+
88
+ **Note:** Version bump only for package @toa.io/bindings.loop
89
+
90
+
91
+
92
+
93
+
94
+ # [1.0.0-alpha.304](https://github.com/toa-io/toa/compare/v1.0.0-alpha.303...v1.0.0-alpha.304) (2026-09-13)
95
+
96
+ **Note:** Version bump only for package @toa.io/bindings.loop
97
+
98
+
99
+
100
+
101
+
102
+ # [1.0.0-alpha.303](https://github.com/toa-io/toa/compare/v1.0.0-alpha.302...v1.0.0-alpha.303) (2026-09-12)
103
+
104
+ **Note:** Version bump only for package @toa.io/bindings.loop
105
+
106
+
107
+
108
+
109
+
110
+ # [1.0.0-alpha.302](https://github.com/toa-io/toa/compare/v1.0.0-alpha.301...v1.0.0-alpha.302) (2026-09-11)
111
+
112
+ **Note:** Version bump only for package @toa.io/bindings.loop
113
+
114
+
115
+
116
+
117
+
118
+ # [1.0.0-alpha.301](https://github.com/toa-io/toa/compare/v1.0.0-alpha.300...v1.0.0-alpha.301) (2026-09-11)
119
+
120
+ **Note:** Version bump only for package @toa.io/bindings.loop
121
+
122
+
123
+
124
+
125
+
126
+ # [1.0.0-alpha.300](https://github.com/toa-io/toa/compare/v1.0.0-alpha.299...v1.0.0-alpha.300) (2026-09-11)
127
+
128
+ ### Features
129
+
130
+ * **core:** a call may name the process it goes to, and wait for a set time ([7d8adb2](https://github.com/toa-io/toa/commit/7d8adb2772a95ff45ae5374efdedfb5a857fbbe9))
131
+
132
+
133
+ # [1.0.0-alpha.299](https://github.com/toa-io/toa/compare/v1.0.0-alpha.298...v1.0.0-alpha.299) (2026-09-10)
134
+
135
+ **Note:** Version bump only for package @toa.io/bindings.loop
136
+
137
+
138
+
139
+
140
+
141
+ # [1.0.0-alpha.293](https://github.com/toa-io/toa/compare/v1.0.0-alpha.292...v1.0.0-alpha.293) (2026-09-07)
142
+
143
+ **Note:** Version bump only for package @toa.io/bindings.loop
144
+
145
+
146
+
147
+
148
+
149
+ # [1.0.0-alpha.292](https://github.com/toa-io/toa/compare/v1.0.0-alpha.291...v1.0.0-alpha.292) (2026-09-07)
150
+
151
+ ### Features
152
+
153
+ * **definitions:** what a package declares is read from one package ([7052341](https://github.com/toa-io/toa/commit/70523411b5d9e2b204c999aa02365173f3bb518d))
154
+
155
+
156
+ # [1.0.0-alpha.291](https://github.com/toa-io/toa/compare/v1.0.0-alpha.290...v1.0.0-alpha.291) (2026-09-07)
157
+
158
+ **Note:** Version bump only for package @toa.io/bindings.loop
159
+
160
+
161
+
162
+
163
+
164
+ # [1.0.0-alpha.289](https://github.com/toa-io/toa/compare/v1.0.0-alpha.288...v1.0.0-alpha.289) (2026-09-07)
165
+
166
+ **Note:** Version bump only for package @toa.io/bindings.loop
167
+
168
+
169
+
170
+
171
+
172
+ # [1.0.0-alpha.288](https://github.com/toa-io/toa/compare/v1.0.0-alpha.287...v1.0.0-alpha.288) (2026-09-06)
173
+
174
+ **Note:** Version bump only for package @toa.io/bindings.loop
175
+
176
+
177
+
178
+
179
+
180
+ # [1.0.0-alpha.287](https://github.com/toa-io/toa/compare/v1.0.0-alpha.286...v1.0.0-alpha.287) (2026-09-06)
181
+
182
+ **Note:** Version bump only for package @toa.io/bindings.loop
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@toa.io/bindings.loop",
3
- "version": "1.0.0-alpha.32",
3
+ "version": "1.0.0-alpha.321",
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,7 +20,8 @@
19
20
  "test": "echo \"Error: run tests from root\" && exit 1"
20
21
  },
21
22
  "dependencies": {
22
- "@toa.io/generic": "1.0.0-alpha.32"
23
+ "@toa.io/core": "1.0.0-alpha.321",
24
+ "@toa.io/generic": "1.0.0-alpha.311"
23
25
  },
24
- "gitHead": "93ceb53797363abb77eb9c550db77e906691d42a"
26
+ "gitHead": "fa850e861a0c748d7364ccf7c8a09ce26973fc04"
25
27
  }
package/src/consumer.js CHANGED
@@ -1,13 +1,11 @@
1
- 'use strict'
1
+ import { Connector, instance } 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
9
7
 
10
- constructor (bindings, locator, endpoint) {
8
+ constructor(bindings, locator, endpoint) {
11
9
  super()
12
10
 
13
11
  this.#bindings = bindings
@@ -15,12 +13,16 @@ class Consumer extends Connector {
15
13
  this.#endpoint = endpoint
16
14
  }
17
15
 
18
- async request (request) {
16
+ /**
17
+ * An addressed call is served here when it names this process, and handed to the next binding
18
+ * when it names another: the call is for that process, whichever replica composes the component here.
19
+ */
20
+ async request(request, terms) {
21
+ if (terms?.instance !== undefined && terms.instance !== instance()) return false
22
+
19
23
  const invoke = this.#bindings[this.#locator.id]?.[this.#endpoint]
20
24
 
21
25
  if (invoke === undefined) return false
22
26
  else return invoke(request)
23
27
  }
24
28
  }
25
-
26
- exports.Consumer = Consumer
package/src/factory.js CHANGED
@@ -1,18 +1,14 @@
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
- producer (locator, endpoints, producer) {
7
+ producer(locator, endpoints, producer) {
10
8
  return new Producer(this.#bindings, locator, endpoints, producer)
11
9
  }
12
10
 
13
- consumer (locator, endpoint) {
11
+ consumer(locator, endpoint) {
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 @@
1
- 'use strict'
2
-
3
- const { Factory } = require('./factory')
4
-
5
- exports.Factory = Factory
6
- exports.properties = { async: false }
1
+ export { Factory } from './factory.js'
package/src/producer.js CHANGED
@@ -1,13 +1,11 @@
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
9
7
 
10
- constructor (bindings, locator, endpoints, producer) {
8
+ constructor(bindings, locator, endpoints, producer) {
11
9
  super()
12
10
 
13
11
  if (bindings[locator.id] === undefined) bindings[locator.id] = {}
@@ -19,19 +17,18 @@ class Producer extends Connector {
19
17
  this.depends(producer)
20
18
  }
21
19
 
22
- async open () {
20
+ async open() {
23
21
  this.#endpoints.forEach((endpoint) => this.#operation(endpoint))
24
22
  }
25
23
 
26
- async close () {
24
+ async close() {
27
25
  this.#endpoints.forEach((endpoint) => delete this.#binding[endpoint])
28
26
  }
29
27
 
30
- #operation (endpoint) {
31
- if (this.#binding[endpoint] !== undefined) throw new Error(`Loop binding endpoint '${endpoint}' already exists`)
28
+ #operation(endpoint) {
29
+ if (this.#binding[endpoint] !== undefined)
30
+ throw new Error(`Loop binding endpoint '${endpoint}' already exists`)
32
31
 
33
32
  this.#binding[endpoint] = async (request) => this.#producer.invoke(endpoint, request)
34
33
  }
35
34
  }
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,105 @@
1
+ import { it, before, after, beforeEach, afterEach } 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
+ import { instance } from '@toa.io/core'
7
+
8
+ import { Factory } from '../src/factory.js'
9
+ import * as fixtures from './fixtures.js'
10
+
11
+ const factory = new Factory()
12
+ const producer = factory.producer(
13
+ fixtures.component.locator,
14
+ fixtures.endpoints,
15
+ fixtures.component
16
+ )
17
+
18
+ let consumer, endpoint
19
+
20
+ before(async () => {
21
+ await producer.connect()
22
+ })
23
+
24
+ after(async () => {
25
+ await producer.disconnect()
26
+ })
27
+
28
+ beforeEach(async () => {
29
+ resetCalls()
30
+
31
+ endpoint = sample(fixtures.endpoints)
32
+ consumer = factory.consumer(fixtures.component.locator, endpoint)
33
+
34
+ await consumer.connect()
35
+ })
36
+
37
+ afterEach(async () => {
38
+ await consumer.disconnect()
39
+ })
40
+
41
+ it('should bind', async () => {
42
+ const r1 = await consumer.request(1)
43
+ const r2 = await consumer.request(2)
44
+
45
+ const calls = fixtures.component.invoke.mock.calls
46
+
47
+ assert.strictEqual(calls.length, 2)
48
+ assert.deepStrictEqual(calls[0].arguments, [endpoint, 1])
49
+ assert.deepStrictEqual(calls[1].arguments, [endpoint, 2])
50
+
51
+ assert.strictEqual(r1, await calls[0].result)
52
+ assert.strictEqual(r2, await calls[1].result)
53
+ })
54
+
55
+ it('should serve an addressed call that names this process', async () => {
56
+ const result = await consumer.request(3, { instance: instance() })
57
+ const calls = fixtures.component.invoke.mock.calls
58
+
59
+ assert.strictEqual(calls.length, 1)
60
+ assert.strictEqual(result, await calls[0].result)
61
+ })
62
+
63
+ // a call for another process runs on that process, though the component is composed here too
64
+ it('should hand an addressed call that names another process to the next binding', async () => {
65
+ const result = await consumer.request(4, { instance: 'another' })
66
+
67
+ assert.strictEqual(result, false)
68
+ assert.strictEqual(fixtures.component.invoke.mock.calls.length, 0)
69
+ })
70
+
71
+ it('should return false if no binding', async () => {
72
+ const consumer = factory.consumer({ id: 'not.existent' }, endpoint)
73
+ const result = await consumer.request()
74
+
75
+ assert.strictEqual(result, false)
76
+ })
77
+
78
+ it('should not depend on initialization order', async () => {
79
+ const component = clone(fixtures.component)
80
+
81
+ component.locator.id = 'other.name'
82
+
83
+ const consumer = factory.consumer(component.locator, endpoint)
84
+ await consumer.connect()
85
+
86
+ assert.strictEqual(await consumer.request(), false)
87
+
88
+ const producer = factory.producer(component.locator, fixtures.endpoints, component)
89
+ await producer.connect()
90
+
91
+ assert.strictEqual(
92
+ await consumer.request(),
93
+ await component.invoke.mock.calls[0].result
94
+ )
95
+ })
96
+
97
+ function resetCalls(target = [fixtures], seen = new Set()) {
98
+ if (target === null || typeof target !== 'object' || seen.has(target)) return
99
+
100
+ seen.add(target)
101
+
102
+ for (const value of Object.values(target))
103
+ if (typeof value === 'function' && value.mock !== undefined) value.mock.resetCalls()
104
+ else resetCalls(value, seen)
105
+ }
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
- })