@toa.io/userland 1.0.0-alpha.6 → 1.0.0-alpha.8
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/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,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
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { join, basename } = require('node:path')
|
|
4
|
-
const { file: { glob } } = require('@toa.io/filesystem')
|
|
5
|
-
const yaml = require('@toa.io/yaml')
|
|
6
|
-
|
|
7
|
-
const { filter } = require('./filter')
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @param {string} path
|
|
11
|
-
* @param {toa.samples.suite.Options} options
|
|
12
|
-
* @returns {Promise<toa.samples.messages.Set>}
|
|
13
|
-
*/
|
|
14
|
-
const messages = async (path, options) => {
|
|
15
|
-
/** @type {toa.samples.messages.Set} */
|
|
16
|
-
const messages = {}
|
|
17
|
-
|
|
18
|
-
const pattern = join(path, DIRECTORY, PATTERN)
|
|
19
|
-
const files = await glob(pattern)
|
|
20
|
-
|
|
21
|
-
for (const file of files) {
|
|
22
|
-
const label = basename(file, EXTENSION)
|
|
23
|
-
|
|
24
|
-
let samples = /** @type {toa.samples.Message[]} */ await yaml.load.all(file)
|
|
25
|
-
|
|
26
|
-
if (options.id !== undefined) samples.forEach((sample) => (sample.component = options.id))
|
|
27
|
-
if (options.component !== undefined) samples = samples.filter((sample) => sample.component === options.component)
|
|
28
|
-
if (options.title !== undefined) samples = filter(samples, options.title)
|
|
29
|
-
|
|
30
|
-
messages[label] = samples
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return messages
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const DIRECTORY = 'samples/messages'
|
|
37
|
-
const EXTENSION = '.yaml'
|
|
38
|
-
const PATTERN = '*' + EXTENSION
|
|
39
|
-
|
|
40
|
-
exports.messages = messages
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { basename, join } = require('node:path')
|
|
4
|
-
const { file: { glob } } = require('@toa.io/filesystem')
|
|
5
|
-
const { merge } = require('@toa.io/generic')
|
|
6
|
-
const yaml = require('@toa.io/yaml')
|
|
7
|
-
|
|
8
|
-
const { parse } = require('./parse')
|
|
9
|
-
const { filter } = require('./filter')
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @param {string} path
|
|
13
|
-
* @param {toa.samples.suite.Options} options
|
|
14
|
-
* @returns {Promise<toa.samples.suite.Operations>}
|
|
15
|
-
*/
|
|
16
|
-
const operations = async (path, options) => {
|
|
17
|
-
/** @type {toa.samples.suite.Operations} */
|
|
18
|
-
const operations = {}
|
|
19
|
-
|
|
20
|
-
const pattern = join(path, DIRECTORY, PATTERN)
|
|
21
|
-
const files = await glob(pattern)
|
|
22
|
-
|
|
23
|
-
for (const file of files) {
|
|
24
|
-
const name = basename(file, EXTENSION)
|
|
25
|
-
const [component, operation] = parse(name, options.id)
|
|
26
|
-
|
|
27
|
-
if (options.component !== undefined && component !== options.component) continue
|
|
28
|
-
if (options.operation !== undefined && operation !== options.operation) continue
|
|
29
|
-
|
|
30
|
-
let samples = /** @type {toa.samples.Operation[]} */ await yaml.load.all(file)
|
|
31
|
-
|
|
32
|
-
if (options.title !== undefined) samples = filter(samples, options.title)
|
|
33
|
-
if (samples.length === 0) continue
|
|
34
|
-
|
|
35
|
-
if (operations[component] === undefined) operations[component] = {}
|
|
36
|
-
|
|
37
|
-
/** @type {toa.samples.operations.Set} */
|
|
38
|
-
const set = operations[component]
|
|
39
|
-
|
|
40
|
-
if (set[operation] === undefined) set[operation] = samples
|
|
41
|
-
else set[operation] = /** @type {toa.samples.Operation[]} */ merge(set[operation], samples)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return operations
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const DIRECTORY = 'samples'
|
|
48
|
-
const EXTENSION = '.yaml'
|
|
49
|
-
const PATTERN = '*' + EXTENSION
|
|
50
|
-
|
|
51
|
-
exports.operations = operations
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {string} name
|
|
5
|
-
* @param {string} [def]
|
|
6
|
-
* @returns {[string, string]}
|
|
7
|
-
*/
|
|
8
|
-
const parse = (name, def) => {
|
|
9
|
-
const parts = name.split('.')
|
|
10
|
-
const [endpoint, component, namespace] = parts.reverse()
|
|
11
|
-
const id = namespace === undefined ? def : namespace + '.' + component
|
|
12
|
-
|
|
13
|
-
if (id !== undefined && def !== undefined && id !== def) {
|
|
14
|
-
throw new Error(`Component id mismatch: '${id}' expected, '${component}' given`)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return [id, endpoint]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
exports.parse = parse
|