@toa.io/userland 1.0.0-alpha.3 → 1.0.0-alpha.30
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 +9 -9
- package/readme.md +0 -2
- package/stage/src/binding/consumer.js +2 -0
- package/stage/src/binding/emitter.js +1 -0
- package/stage/test/binding/emitter.test.js +26 -2
- package/example/components/echo/samples/get.yaml +0 -12
- package/example/components/echo/samples/signal.yaml +0 -4
- package/example/components/math.calculations/samples/add.yaml +0 -10
- package/example/components/math.calculations/samples/assets/ab.yaml +0 -2
- package/example/components/math.calculations/samples/increment.yaml +0 -27
- package/example/components/math.proxy/samples/add.yaml +0 -11
- package/example/components/tea.pots/samples/same.yaml +0 -8
- package/example/components/tea.pots/samples/transit.yaml +0 -43
- package/example/components/web/samples/get.yaml +0 -8
- package/example/samples/math.proxy.add.yaml +0 -5
- package/example/samples/messages/store.orders.created.yaml +0 -8
- package/samples/docs/sampling-dark.jpg +0 -0
- package/samples/docs/sampling-light.jpg +0 -0
- package/samples/notes.md +0 -12
- package/samples/package.json +0 -5
- package/samples/readme.md +0 -131
- package/samples/src/.replay/.suite/component.js +0 -20
- package/samples/src/.replay/.suite/index.js +0 -7
- package/samples/src/.replay/.suite/messages.js +0 -39
- package/samples/src/.replay/.suite/operation.js +0 -28
- package/samples/src/.replay/.suite/operations.js +0 -20
- package/samples/src/.replay/.suite/translate/.message/index.js +0 -5
- package/samples/src/.replay/.suite/translate/.message/request.js +0 -31
- package/samples/src/.replay/.suite/translate/.operation/.prepare/cast.js +0 -20
- package/samples/src/.replay/.suite/translate/.operation/.prepare/cast.test.js +0 -94
- package/samples/src/.replay/.suite/translate/.operation/.prepare/expand.js +0 -14
- package/samples/src/.replay/.suite/translate/.operation/.prepare/index.js +0 -7
- package/samples/src/.replay/.suite/translate/.operation/.prepare/shortcuts/.aspect.js +0 -26
- package/samples/src/.replay/.suite/translate/.operation/.prepare/shortcuts/configuration.js +0 -5
- package/samples/src/.replay/.suite/translate/.operation/.prepare/shortcuts/http.js +0 -5
- package/samples/src/.replay/.suite/translate/.operation/.prepare/shortcuts/index.js +0 -9
- package/samples/src/.replay/.suite/translate/.operation/.prepare/shortcuts/state.js +0 -5
- package/samples/src/.replay/.suite/translate/.operation/.prepare/types/async.js +0 -3
- package/samples/src/.replay/.suite/translate/.operation/.prepare/types/cast.js +0 -26
- package/samples/src/.replay/.suite/translate/.operation/.prepare/types/index.js +0 -5
- package/samples/src/.replay/.suite/translate/.operation/.prepare/types/map.js +0 -3
- package/samples/src/.replay/.suite/translate/.operation/.prepare/types/set.js +0 -3
- package/samples/src/.replay/.suite/translate/.operation/.prepare/types/sync.js +0 -3
- package/samples/src/.replay/.suite/translate/.operation/calls.js +0 -49
- package/samples/src/.replay/.suite/translate/.operation/cleanup.js +0 -16
- package/samples/src/.replay/.suite/translate/.operation/events.js +0 -16
- package/samples/src/.replay/.suite/translate/.operation/index.js +0 -11
- package/samples/src/.replay/.suite/translate/.operation/prepare.js +0 -14
- package/samples/src/.replay/.suite/translate/index.js +0 -7
- package/samples/src/.replay/.suite/translate/message.js +0 -26
- package/samples/src/.replay/.suite/translate/operation.js +0 -47
- package/samples/src/.replay/.suite/translate/schemas/index.js +0 -7
- package/samples/src/.replay/.suite/translate/schemas/message.cos.yaml +0 -10
- package/samples/src/.replay/.suite/translate/schemas/operation.cos.yaml +0 -23
- package/samples/src/.replay/index.js +0 -7
- package/samples/src/.replay/stage.js +0 -60
- package/samples/src/.replay/suite.js +0 -23
- package/samples/src/.replay/test.js +0 -19
- package/samples/src/components.js +0 -13
- package/samples/src/context.js +0 -23
- package/samples/src/index.js +0 -9
- package/samples/src/replay.js +0 -16
- package/samples/src/suite/.read/filter.js +0 -15
- package/samples/src/suite/.read/index.js +0 -7
- package/samples/src/suite/.read/messages.js +0 -40
- package/samples/src/suite/.read/operations.js +0 -51
- package/samples/src/suite/.read/parse.js +0 -20
- package/samples/src/suite/components.js +0 -31
- package/samples/src/suite/context.js +0 -20
- package/samples/src/suite/index.js +0 -7
- package/samples/test/components.test.js +0 -42
- package/samples/test/context/components/dummy/manifest.toa.yaml +0 -2
- package/samples/test/context/components/dummy/samples/do.yaml +0 -11
- package/samples/test/context/components/dummy/samples/dummies.dummy.do.yaml +0 -11
- package/samples/test/context/components/dummy/samples/dummies.dummy.undo.yaml +0 -7
- package/samples/test/context/components/dummy/samples/messages/somewhere.something.happened.yaml +0 -6
- package/samples/test/context/components/pot/manifest.toa.yaml +0 -2
- package/samples/test/context/components/pot/samples/do.yaml +0 -11
- package/samples/test/context/components/pot/samples/messages/somewhere.something.happened.yaml +0 -6
- package/samples/test/context/context.toa.yaml +0 -3
- package/samples/test/context/samples/dummies.dummy.observe.yaml +0 -6
- package/samples/test/context/samples/dummies.dummy.transit.yaml +0 -10
- package/samples/test/context/samples/messages/somewhere.something.happened.yaml +0 -6
- package/samples/test/context.fixtures.js +0 -8
- package/samples/test/context.test.js +0 -82
- package/samples/test/replay.mock.js +0 -7
- package/samples/test/replay.test.js +0 -152
- package/samples/test/replay.translate.message.fixtures.js +0 -24
- package/samples/test/replay.translate.message.test.js +0 -119
- package/samples/test/replay.translate.mock.js +0 -17
- package/samples/test/replay.translate.operation.fixtures.js +0 -107
- package/samples/test/replay.translate.operation.test.js +0 -68
- package/samples/test/stage.mock.js +0 -30
- package/samples/test/suite.components.test.js +0 -122
- package/samples/test/suite.context.test.js +0 -79
- package/samples/test/suite.mock.js +0 -10
- package/samples/types/index.d.ts +0 -8
- package/samples/types/message.d.ts +0 -24
- package/samples/types/operation.d.ts +0 -36
- package/samples/types/replay.d.ts +0 -13
- package/samples/types/suite.d.ts +0 -31
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { cast } = require('./')
|
|
4
|
-
|
|
5
|
-
it('should be', async () => {
|
|
6
|
-
expect(cast).toBeInstanceOf(Function)
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
it('should cast to a Map', async () => {
|
|
10
|
-
/** @type {toa.sampling.request.Extensions} */
|
|
11
|
-
const extensions = {
|
|
12
|
-
state: [{
|
|
13
|
-
result: {
|
|
14
|
-
'value:Map': { foo: 'bar' }
|
|
15
|
-
}
|
|
16
|
-
}]
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
cast(extensions)
|
|
20
|
-
|
|
21
|
-
const value = /** @type {Map} */ extensions.state[0].result.value
|
|
22
|
-
|
|
23
|
-
expect(value).toBeDefined()
|
|
24
|
-
expect(value).toBeInstanceOf(Map)
|
|
25
|
-
expect(Array.from(value.keys())).toStrictEqual(['foo'])
|
|
26
|
-
expect(value.get('foo')).toStrictEqual('bar')
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('should not throw if result is undefined', async () => {
|
|
30
|
-
const extensions = { state: [{}] }
|
|
31
|
-
|
|
32
|
-
expect(() => cast(extensions)).not.toThrow()
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('should cast to a Set', async () => {
|
|
36
|
-
const names = ['Mary', 'Bob', 'Elizabeth']
|
|
37
|
-
|
|
38
|
-
/** @type {toa.sampling.request.Extensions} */
|
|
39
|
-
const extensions = {
|
|
40
|
-
state: [{
|
|
41
|
-
result: {
|
|
42
|
-
'names:Set': names
|
|
43
|
-
}
|
|
44
|
-
}]
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
cast(extensions)
|
|
48
|
-
|
|
49
|
-
const set = /** @type {Map} */ extensions.state[0].result.names
|
|
50
|
-
|
|
51
|
-
expect(set).toBeDefined()
|
|
52
|
-
expect(set).toBeInstanceOf(Set)
|
|
53
|
-
expect(Array.from(set)).toStrictEqual(names)
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
it('should cast to a Function', async () => {
|
|
57
|
-
const extensions = {
|
|
58
|
-
foo: [{
|
|
59
|
-
result: {
|
|
60
|
-
'resolve:sync': 'hello'
|
|
61
|
-
}
|
|
62
|
-
}]
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
cast(extensions)
|
|
66
|
-
|
|
67
|
-
const resolve = extensions.foo[0].result.resolve
|
|
68
|
-
|
|
69
|
-
expect(resolve).toBeDefined()
|
|
70
|
-
expect(resolve).toBeInstanceOf(Function)
|
|
71
|
-
expect(resolve()).toStrictEqual('hello')
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
it('should cast to async Function', async () => {
|
|
75
|
-
const extensions = {
|
|
76
|
-
foo: [{
|
|
77
|
-
result: {
|
|
78
|
-
'resolve:async': 'hello'
|
|
79
|
-
}
|
|
80
|
-
}]
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
cast(extensions)
|
|
84
|
-
|
|
85
|
-
const resolve = extensions.foo[0].result.resolve
|
|
86
|
-
|
|
87
|
-
expect(resolve).toBeDefined()
|
|
88
|
-
expect(resolve).toBeInstanceOf(Function)
|
|
89
|
-
|
|
90
|
-
const promise = resolve()
|
|
91
|
-
|
|
92
|
-
expect(promise).toBeInstanceOf(Promise)
|
|
93
|
-
await expect(promise).resolves.toStrictEqual('hello')
|
|
94
|
-
})
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const shortcuts = require('./shortcuts')
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @param {toa.samples.Operation & Object} declaration
|
|
7
|
-
*/
|
|
8
|
-
function expand (declaration) {
|
|
9
|
-
for (const [shortcut, expand] of Object.entries(shortcuts)) {
|
|
10
|
-
if (shortcut in declaration) expand(declaration)
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
exports.expand = expand
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const aspect = (name) =>
|
|
4
|
-
/**
|
|
5
|
-
* @param {toa.samples.Operation & Record<string, any>} declaration
|
|
6
|
-
*/
|
|
7
|
-
(declaration) => {
|
|
8
|
-
const value = declaration[name]
|
|
9
|
-
|
|
10
|
-
delete declaration[name]
|
|
11
|
-
|
|
12
|
-
if (declaration.extensions === undefined) declaration.extensions = {}
|
|
13
|
-
|
|
14
|
-
if (name in declaration.extensions) throw new Error(`${name} aspect sample is ambiguous`)
|
|
15
|
-
|
|
16
|
-
/** @type {toa.sampling.request.extensions.Call} */
|
|
17
|
-
const call = {
|
|
18
|
-
result: value,
|
|
19
|
-
permanent: true
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
declaration.extensions[name] = [call]
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
exports.aspect = aspect
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { map } = require('@toa.io/generic')
|
|
4
|
-
|
|
5
|
-
const types = {
|
|
6
|
-
Map: require('./map'),
|
|
7
|
-
Set: require('./set'),
|
|
8
|
-
sync: require('./sync'),
|
|
9
|
-
async: require('./async')
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function cast (value) {
|
|
13
|
-
return map(value, replace)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function replace (key, value) {
|
|
17
|
-
const [name, type] = key.split(':')
|
|
18
|
-
|
|
19
|
-
if (!(type in types)) return
|
|
20
|
-
|
|
21
|
-
const typed = types[type](value)
|
|
22
|
-
|
|
23
|
-
return [name, typed]
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
exports.cast = cast
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { defined } = require('@toa.io/generic')
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @param {toa.samples.operation.Calls} calls
|
|
7
|
-
* @returns {toa.sampling.request.context.Calls}
|
|
8
|
-
*/
|
|
9
|
-
const calls = (calls) => {
|
|
10
|
-
/** @type {toa.sampling.request.context.Calls} */
|
|
11
|
-
const output = {}
|
|
12
|
-
|
|
13
|
-
for (let [endpoint, samples] of Object.entries(calls)) {
|
|
14
|
-
if (!Array.isArray(samples)) samples = [samples]
|
|
15
|
-
|
|
16
|
-
const target = []
|
|
17
|
-
|
|
18
|
-
for (const sample of samples) {
|
|
19
|
-
const translation = call(sample)
|
|
20
|
-
|
|
21
|
-
target.push(translation)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
output[endpoint] = target
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return output
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @param {toa.samples.operation.Call} call
|
|
32
|
-
* @returns {toa.sampling.request.context.Call}
|
|
33
|
-
*/
|
|
34
|
-
const call = (call) => {
|
|
35
|
-
let request
|
|
36
|
-
let reply
|
|
37
|
-
|
|
38
|
-
const sample = {}
|
|
39
|
-
const { input, query, output } = call
|
|
40
|
-
|
|
41
|
-
if (input !== undefined || query !== undefined) request = defined({ input, query })
|
|
42
|
-
if (output !== undefined) reply = { output }
|
|
43
|
-
if (request !== undefined) sample.request = request
|
|
44
|
-
if (reply !== undefined) sample.reply = reply
|
|
45
|
-
|
|
46
|
-
return sample
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
exports.calls = calls
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { defined, empty } = require('@toa.io/generic')
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @param {toa.sampling.request.Sample} sample
|
|
7
|
-
*/
|
|
8
|
-
const cleanup = (sample) => {
|
|
9
|
-
for (const [key, value] of Object.entries(sample)) {
|
|
10
|
-
if (value === undefined || (typeof value === 'object' && empty(defined(value)))) {
|
|
11
|
-
delete sample[key]
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
exports.cleanup = cleanup
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {toa.samples.operations.Events} events
|
|
5
|
-
* @returns {toa.sampling.request.Events}
|
|
6
|
-
*/
|
|
7
|
-
const events = (events) => {
|
|
8
|
-
/** @type {toa.sampling.request.Events} */
|
|
9
|
-
const set = {}
|
|
10
|
-
|
|
11
|
-
for (const [label, sample] of Object.entries(events)) set[label] = { payload: sample }
|
|
12
|
-
|
|
13
|
-
return set
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
exports.events = events
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { calls } = require('./calls')
|
|
4
|
-
const { events } = require('./events')
|
|
5
|
-
const { cleanup } = require('./cleanup')
|
|
6
|
-
const { prepare } = require('./prepare')
|
|
7
|
-
|
|
8
|
-
exports.calls = calls
|
|
9
|
-
exports.events = events
|
|
10
|
-
exports.cleanup = cleanup
|
|
11
|
-
exports.prepare = prepare
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { cast, expand } = require('./.prepare')
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @param {toa.samples.Operation & Object} declaration
|
|
7
|
-
*/
|
|
8
|
-
const prepare = (declaration) => {
|
|
9
|
-
expand(declaration)
|
|
10
|
-
|
|
11
|
-
if ('extensions' in declaration) cast(declaration.extensions)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
exports.prepare = prepare
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { schemas } = require('./schemas')
|
|
4
|
-
const translate = require('./.message')
|
|
5
|
-
|
|
6
|
-
const schema = schemas.schema('message')
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @param {toa.samples.Message} declaration
|
|
10
|
-
* @param {boolean} autonomous
|
|
11
|
-
* @param {string} component
|
|
12
|
-
* @returns {toa.sampling.Message}
|
|
13
|
-
*/
|
|
14
|
-
const message = (declaration, autonomous, component) => {
|
|
15
|
-
schema.validate(declaration)
|
|
16
|
-
|
|
17
|
-
const payload = declaration.payload
|
|
18
|
-
const request = translate.request(declaration, autonomous)
|
|
19
|
-
|
|
20
|
-
/** @type {toa.sampling.messages.Sample} */
|
|
21
|
-
const sample = { authentic: true, component, request }
|
|
22
|
-
|
|
23
|
-
return { payload, sample }
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
exports.message = message
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const transform = require('./.operation')
|
|
4
|
-
const { schemas } = require('./schemas')
|
|
5
|
-
|
|
6
|
-
const schema = schemas.schema('operation')
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @param {toa.samples.Operation} declaration
|
|
10
|
-
* @param {boolean} autonomous
|
|
11
|
-
* @returns {toa.sampling.Request}
|
|
12
|
-
*/
|
|
13
|
-
const operation = (declaration, autonomous) => {
|
|
14
|
-
transform.prepare(declaration)
|
|
15
|
-
schema.validate(declaration)
|
|
16
|
-
|
|
17
|
-
const { title, input, output, local, remote, current, next, extensions } = declaration
|
|
18
|
-
const reply = { output }
|
|
19
|
-
const storage = { current, next }
|
|
20
|
-
|
|
21
|
-
/** @type {toa.sampling.request.Context} */
|
|
22
|
-
let context = {}
|
|
23
|
-
|
|
24
|
-
/** @type {toa.sampling.request.Events} */
|
|
25
|
-
let events
|
|
26
|
-
|
|
27
|
-
if (local !== undefined) context.local = transform.calls(local)
|
|
28
|
-
if (remote !== undefined) context.remote = transform.calls(remote)
|
|
29
|
-
if (declaration.events !== undefined) events = transform.events(declaration.events)
|
|
30
|
-
|
|
31
|
-
const sample = /** @type {toa.sampling.request.Sample} */ {
|
|
32
|
-
authentic: true,
|
|
33
|
-
autonomous,
|
|
34
|
-
title,
|
|
35
|
-
reply,
|
|
36
|
-
context,
|
|
37
|
-
storage,
|
|
38
|
-
events,
|
|
39
|
-
extensions
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
transform.cleanup(sample)
|
|
43
|
-
|
|
44
|
-
return { input, sample }
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
exports.operation = operation
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
autonomous: boolean
|
|
2
|
-
title: string
|
|
3
|
-
input: ~
|
|
4
|
-
output: ~
|
|
5
|
-
local: &calls
|
|
6
|
-
~+:
|
|
7
|
-
input: ~
|
|
8
|
-
query:
|
|
9
|
-
id: string
|
|
10
|
-
criteria: string
|
|
11
|
-
omit: number
|
|
12
|
-
limit: number
|
|
13
|
-
output: ~
|
|
14
|
-
remote: *calls
|
|
15
|
-
current+: object
|
|
16
|
-
next: object
|
|
17
|
-
events:
|
|
18
|
-
~: object
|
|
19
|
-
extensions:
|
|
20
|
-
~:
|
|
21
|
-
- arguments: [~]
|
|
22
|
-
result: ~
|
|
23
|
-
permanent: boolean
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const stage = require('@toa.io/userland/stage')
|
|
4
|
-
const storage = require.resolve('@toa.io/storages.null')
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @param {string[]} paths
|
|
8
|
-
* @param {boolean} autonomous
|
|
9
|
-
* @return {Promise<Record<string, toa.core.Component>>}
|
|
10
|
-
*/
|
|
11
|
-
async function setup (paths, autonomous) {
|
|
12
|
-
if (!autonomous) return remotes(paths)
|
|
13
|
-
else return components(paths)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async function remotes (paths) {
|
|
17
|
-
await stage.composition(paths)
|
|
18
|
-
|
|
19
|
-
const remotes = {}
|
|
20
|
-
|
|
21
|
-
for (const path of paths) {
|
|
22
|
-
const id = await getId(path)
|
|
23
|
-
|
|
24
|
-
remotes[id] = await stage.remote(id)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return remotes
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async function components (paths) {
|
|
31
|
-
const components = {}
|
|
32
|
-
|
|
33
|
-
process.env.TOA_SAMPLING_AUTONOMOUS = '1'
|
|
34
|
-
|
|
35
|
-
for (const path of paths) {
|
|
36
|
-
const id = await getId(path)
|
|
37
|
-
|
|
38
|
-
components[id] = await stage.component(path, { storage })
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
delete process.env.TOA_SAMPLING_AUTONOMOUS
|
|
42
|
-
|
|
43
|
-
return components
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async function getId (path) {
|
|
47
|
-
const manifest = await stage.manifest(path)
|
|
48
|
-
|
|
49
|
-
return manifest.locator.id
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @return {Promise<void>}
|
|
54
|
-
*/
|
|
55
|
-
async function shutdown () {
|
|
56
|
-
await stage.shutdown()
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
exports.setup = setup
|
|
60
|
-
exports.shutdown = shutdown
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const replay = require('./.suite')
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @param {toa.samples.Suite} suite
|
|
7
|
-
* @param {Record<string, toa.core.Component>} components
|
|
8
|
-
* @returns {Function}
|
|
9
|
-
*/
|
|
10
|
-
const suite = (suite, components) =>
|
|
11
|
-
async (test) => {
|
|
12
|
-
if ('operations' in suite) {
|
|
13
|
-
await test.test('Operations', replay.operations(suite.operations, components, suite.autonomous))
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if ('messages' in suite) {
|
|
17
|
-
await test.test('Messages', replay.messages(suite.messages, suite.autonomous))
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
test.end()
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
exports.suite = suite
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const tap = require('tap')
|
|
4
|
-
|
|
5
|
-
const replay = require('./suite')
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @param {toa.samples.Suite} suite
|
|
9
|
-
* @param {Record<string, toa.core.Component>} components
|
|
10
|
-
* @param {object} options
|
|
11
|
-
* @return {Promise<boolean>}
|
|
12
|
-
*/
|
|
13
|
-
const test = async (suite, components, options) => {
|
|
14
|
-
const result = await tap.test(suite.title, options, replay.suite(suite, components))
|
|
15
|
-
|
|
16
|
-
return result === null ? false : result.ok
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
exports.test = test
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { components: load } = require('./suite')
|
|
4
|
-
const { replay } = require('./replay')
|
|
5
|
-
|
|
6
|
-
/** @type {toa.samples.replay.components} */
|
|
7
|
-
const components = async (paths, options = {}) => {
|
|
8
|
-
const suite = await load(paths, options)
|
|
9
|
-
|
|
10
|
-
return await replay(suite, paths, options.runner)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
exports.components = components
|
package/samples/src/context.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const norm = require('@toa.io/norm')
|
|
4
|
-
|
|
5
|
-
const test = require('./components')
|
|
6
|
-
const { context: load } = require('./suite')
|
|
7
|
-
const { replay } = require('./replay')
|
|
8
|
-
|
|
9
|
-
/** @type {toa.samples.replay.context} */
|
|
10
|
-
const context = async (path, options = {}) => {
|
|
11
|
-
const context = await norm.context(path)
|
|
12
|
-
const suite = await load(path, options)
|
|
13
|
-
const paths = context.components.map((component) => component.path)
|
|
14
|
-
|
|
15
|
-
let ok = true
|
|
16
|
-
|
|
17
|
-
if (options.integration !== true) ok = await test.components(paths, options)
|
|
18
|
-
if (ok && options.autonomous !== true) ok = await replay(suite, paths, options.runner)
|
|
19
|
-
|
|
20
|
-
return ok
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
exports.context = context
|
package/samples/src/index.js
DELETED
package/samples/src/replay.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { test, stage } = require('./.replay')
|
|
4
|
-
|
|
5
|
-
/** @type {toa.samples.replay.replay} */
|
|
6
|
-
const replay = async (suite, paths, options = undefined) => {
|
|
7
|
-
const components = await stage.setup(paths, suite.autonomous)
|
|
8
|
-
|
|
9
|
-
const ok = await test(suite, components, options)
|
|
10
|
-
|
|
11
|
-
await stage.shutdown()
|
|
12
|
-
|
|
13
|
-
return ok
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
exports.replay = replay
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @template {{ title: string }} T
|
|
5
|
-
* @param {T[]} samples
|
|
6
|
-
* @param {string} expression
|
|
7
|
-
* @returns {T}
|
|
8
|
-
*/
|
|
9
|
-
function filter (samples, expression) {
|
|
10
|
-
const rx = new RegExp(expression)
|
|
11
|
-
|
|
12
|
-
return samples.filter((sample) => rx.test(sample.title))
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
exports.filter = filter
|