@toa.io/userland 1.0.0-alpha.32 → 1.0.0-alpha.320
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 +269 -0
- package/example/components/echo/manifest.toa.yaml +15 -5
- package/example/components/echo/operations/get.js +1 -5
- package/example/components/echo/operations/resolve.js +1 -5
- package/example/components/echo/operations/signal.js +3 -7
- package/example/components/math.calculations/manifest.toa.yaml +19 -6
- package/example/components/math.calculations/operations/add.js +1 -5
- package/example/components/math.calculations/operations/increment.js +1 -5
- package/example/components/math.proxy/manifest.toa.yaml +8 -3
- package/example/components/math.proxy/operations/add.js +1 -5
- package/example/components/tea.pots/manifest.toa.yaml +29 -9
- package/example/components/tea.pots/operations/same.js +1 -5
- package/example/components/tea.pots/receivers/store.orders.created.js +1 -5
- package/example/components/web/manifest.toa.yaml +2 -4
- package/example/components/web/operations/get.js +3 -8
- package/example/context.toa.yaml +2 -7
- package/example/stage/call.test.js +17 -10
- package/example/stage/events.test.js +63 -16
- package/example/stage/invoke.test.js +12 -9
- package/package.json +18 -13
- package/stage/package.json +1 -0
- package/stage/src/component.js +3 -7
- package/stage/src/composition.js +3 -7
- package/stage/src/index.js +9 -16
- package/stage/src/manifest.js +2 -6
- package/stage/src/map.js +15 -0
- package/stage/src/quiescence.js +16 -0
- package/stage/src/remote.js +11 -8
- package/stage/src/service.js +11 -10
- package/stage/src/shutdown.js +16 -6
- package/stage/src/state.js +2 -4
- package/stage/src/workload.js +55 -0
- package/stage/test/boot.mock.js +10 -11
- package/stage/test/component.test.js +20 -10
- package/stage/test/composition.test.js +11 -9
- package/stage/test/manifest.test.js +15 -8
- package/stage/test/remote.test.js +14 -12
- package/stage/test/shutdown.test.js +28 -15
- package/stage/test/state.mock.js +5 -6
- package/stage/test/state.test.js +13 -12
- package/stage/types/index.d.ts +21 -8
- package/stage/types/state.d.ts +3 -4
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import { it, mock as mocking } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import { generate } from 'randomstring'
|
|
5
|
+
import * as _boot from './boot.mock.js'
|
|
4
6
|
|
|
5
7
|
const mock = {
|
|
6
|
-
boot:
|
|
8
|
+
boot: _boot
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
mocking.module('@toa.io/boot', { namedExports: mock.boot })
|
|
10
12
|
|
|
11
|
-
const stage =
|
|
13
|
+
const stage = await import('../src/index.js')
|
|
12
14
|
|
|
13
15
|
it('should be', () => {
|
|
14
|
-
|
|
16
|
+
assert.notStrictEqual(stage.remote, undefined)
|
|
15
17
|
})
|
|
16
18
|
|
|
17
19
|
it('should connect remote', async () => {
|
|
@@ -21,12 +23,12 @@ it('should connect remote', async () => {
|
|
|
21
23
|
|
|
22
24
|
const remote = await stage.remote(id)
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
assert.ok(mock.boot.remote.mock.callCount() > 0)
|
|
27
|
+
assert.deepStrictEqual(remote, await mock.boot.remote.mock.calls[0].result)
|
|
28
|
+
assert.ok(remote.connect.mock.callCount() > 0)
|
|
27
29
|
|
|
28
|
-
const locator = mock.boot.remote.mock.calls[0][0]
|
|
30
|
+
const locator = mock.boot.remote.mock.calls[0].arguments[0]
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
assert.notStrictEqual(locator, undefined)
|
|
33
|
+
assert.partialDeepStrictEqual(locator, { name, namespace })
|
|
32
34
|
})
|
|
@@ -1,24 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
import { it, beforeEach, mock as mocking } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import { generate } from 'randomstring'
|
|
5
|
+
import * as _boot from './boot.mock.js'
|
|
6
|
+
import * as _state from './state.mock.js'
|
|
4
7
|
|
|
5
8
|
const mock = {
|
|
6
|
-
boot:
|
|
7
|
-
state:
|
|
9
|
+
boot: _boot,
|
|
10
|
+
state: _state
|
|
8
11
|
}
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
mocking.module('@toa.io/boot', { namedExports: mock.boot })
|
|
14
|
+
mocking.module('../src/state', { namedExports: mock.state })
|
|
12
15
|
|
|
13
|
-
const { state } =
|
|
14
|
-
const stage =
|
|
16
|
+
const { state } = await import('../src/state.js')
|
|
17
|
+
const stage = await import('../src/index.js')
|
|
15
18
|
|
|
16
19
|
beforeEach(() => {
|
|
17
|
-
|
|
20
|
+
resetCalls()
|
|
18
21
|
})
|
|
19
22
|
|
|
20
23
|
it('should be', () => {
|
|
21
|
-
|
|
24
|
+
assert.notStrictEqual(stage.shutdown, undefined)
|
|
22
25
|
})
|
|
23
26
|
|
|
24
27
|
it('should disconnect components', async () => {
|
|
@@ -27,7 +30,7 @@ it('should disconnect components', async () => {
|
|
|
27
30
|
|
|
28
31
|
await stage.shutdown()
|
|
29
32
|
|
|
30
|
-
|
|
33
|
+
assert.ok(component.disconnect.mock.callCount() > 0)
|
|
31
34
|
})
|
|
32
35
|
|
|
33
36
|
it('should disconnect compositions', async () => {
|
|
@@ -36,9 +39,9 @@ it('should disconnect compositions', async () => {
|
|
|
36
39
|
await stage.composition(paths)
|
|
37
40
|
await stage.shutdown()
|
|
38
41
|
|
|
39
|
-
const composition = await mock.boot.composition.mock.
|
|
42
|
+
const composition = await mock.boot.composition.mock.calls[0].result
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
assert.ok(composition.disconnect.mock.callCount() > 0)
|
|
42
45
|
})
|
|
43
46
|
|
|
44
47
|
it('should disconnect remotes', async () => {
|
|
@@ -47,11 +50,21 @@ it('should disconnect remotes', async () => {
|
|
|
47
50
|
const remote = await stage.remote(id)
|
|
48
51
|
await stage.shutdown()
|
|
49
52
|
|
|
50
|
-
|
|
53
|
+
assert.ok(remote.disconnect.mock.callCount() > 0)
|
|
51
54
|
})
|
|
52
55
|
|
|
53
56
|
it('should reset state', async () => {
|
|
54
57
|
await stage.shutdown()
|
|
55
58
|
|
|
56
|
-
|
|
59
|
+
assert.ok(state.reset.mock.callCount() > 0)
|
|
57
60
|
})
|
|
61
|
+
|
|
62
|
+
function resetCalls(target = [assert, mock, stage], seen = new Set()) {
|
|
63
|
+
if (target === null || typeof target !== 'object' || seen.has(target)) return
|
|
64
|
+
|
|
65
|
+
seen.add(target)
|
|
66
|
+
|
|
67
|
+
for (const value of Object.values(target))
|
|
68
|
+
if (typeof value === 'function' && value.mock !== undefined) value.mock.resetCalls()
|
|
69
|
+
else resetCalls(value, seen)
|
|
70
|
+
}
|
package/stage/test/state.mock.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { mock } from 'node:test'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// this module defines the replacement, so it still sees the real one
|
|
4
|
+
import * as original from '../src/state.js'
|
|
4
5
|
|
|
5
|
-
const reset =
|
|
6
|
-
const state = { ...original.state, reset }
|
|
7
|
-
|
|
8
|
-
module.exports = { state }
|
|
6
|
+
const reset = mock.fn(() => original.state.reset())
|
|
7
|
+
export const state = { ...original.state, reset }
|
package/stage/test/state.test.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import { it } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import { state } from '../src/state.js'
|
|
4
5
|
|
|
5
6
|
it('should be', () => {
|
|
6
|
-
|
|
7
|
+
assert.notStrictEqual(state, undefined)
|
|
7
8
|
})
|
|
8
9
|
|
|
9
10
|
it('should reset', () => {
|
|
10
|
-
const component = /** @type {toa.core.Component} */ 1
|
|
11
|
-
const composition = /** @type {toa.core.Connector} */ 2
|
|
12
|
-
const remote = /** @type {toa.core.Component} */ 3
|
|
11
|
+
const component = /** @type {import('@toa.io/core').Component} */ 1
|
|
12
|
+
const composition = /** @type {import('@toa.io/core').Connector} */ 2
|
|
13
|
+
const remote = /** @type {import('@toa.io/core').Component} */ 3
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
assert.deepStrictEqual(state.components.length, 0)
|
|
16
|
+
assert.deepStrictEqual(state.compositions.length, 0)
|
|
17
|
+
assert.deepStrictEqual(state.remotes.length, 0)
|
|
17
18
|
|
|
18
19
|
state.components.push(component)
|
|
19
20
|
state.compositions.push(composition)
|
|
@@ -21,7 +22,7 @@ it('should reset', () => {
|
|
|
21
22
|
|
|
22
23
|
state.reset()
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
assert.deepStrictEqual(state.components.length, 0)
|
|
26
|
+
assert.deepStrictEqual(state.compositions.length, 0)
|
|
27
|
+
assert.deepStrictEqual(state.remotes.length, 0)
|
|
27
28
|
})
|
package/stage/types/index.d.ts
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
|
-
import * as _core from '@toa.io/core'
|
|
1
|
+
import type * as _core from '@toa.io/core'
|
|
2
2
|
import * as _norm from '@toa.io/norm/types'
|
|
3
3
|
import * as _composition from '@toa.io/boot/types/composition'
|
|
4
|
+
import type * as _boot from '@toa.io/boot'
|
|
4
5
|
|
|
5
|
-
export function manifest
|
|
6
|
+
export function manifest(path: string): Promise<_norm.Component>
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
/** what this process is given about the components it calls */
|
|
9
|
+
export function map(contracts: Record<string, _norm.Contract> | undefined): void
|
|
8
10
|
|
|
9
|
-
export function
|
|
11
|
+
export function component(path: string): Promise<_core.Component>
|
|
10
12
|
|
|
11
|
-
export function
|
|
13
|
+
export function composition(
|
|
14
|
+
paths: string[],
|
|
15
|
+
options?: _composition.Options
|
|
16
|
+
): Promise<void>
|
|
12
17
|
|
|
13
|
-
export function
|
|
18
|
+
export function compose(paths: string[]): Promise<void>
|
|
14
19
|
|
|
15
|
-
|
|
20
|
+
/** the same components as a process runs them: behind a gate, with the residents beside */
|
|
21
|
+
export function workload(
|
|
22
|
+
paths: string[],
|
|
23
|
+
options?: _composition.Options
|
|
24
|
+
): Promise<_boot.Workload>
|
|
16
25
|
|
|
17
|
-
export function
|
|
26
|
+
export function serve(ref: string): Promise<_core.Component>
|
|
27
|
+
|
|
28
|
+
export function remote(id: string): Promise<_core.Component>
|
|
29
|
+
|
|
30
|
+
export function shutdown(): Promise<void>
|
package/stage/types/state.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import * as _core from '@toa.io/core'
|
|
2
|
-
|
|
3
|
-
declare namespace toa.stage{
|
|
1
|
+
import type * as _core from '@toa.io/core'
|
|
4
2
|
|
|
3
|
+
declare namespace toa.stage {
|
|
5
4
|
type State = {
|
|
6
5
|
reset: () => void
|
|
7
6
|
components: _core.Component[]
|
|
8
7
|
compositions: _core.Connector[]
|
|
8
|
+
workloads: _core.Connector[]
|
|
9
9
|
services: _core.Connector[]
|
|
10
10
|
remotes: _core.Component[]
|
|
11
11
|
}
|
|
12
|
-
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
export type State = toa.stage.State
|