@toa.io/userland 1.0.0-alpha.7 → 1.0.0-alpha.9
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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/userland",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.9",
|
|
4
4
|
"description": "Toa development kit",
|
|
5
5
|
"homepage": "https://toa.io",
|
|
6
6
|
"author": {
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
"main": "src/index.js",
|
|
25
25
|
"types": "types/index.d.ts",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@toa.io/boot": "1.0.0-alpha.
|
|
28
|
-
"@toa.io/core": "1.0.0-alpha.
|
|
29
|
-
"@toa.io/filesystem": "1.0.0-alpha.
|
|
30
|
-
"@toa.io/generic": "1.0.0-alpha.
|
|
31
|
-
"@toa.io/norm": "1.0.0-alpha.
|
|
32
|
-
"@toa.io/schemas": "1.0.0-alpha.
|
|
27
|
+
"@toa.io/boot": "1.0.0-alpha.9",
|
|
28
|
+
"@toa.io/core": "1.0.0-alpha.9",
|
|
29
|
+
"@toa.io/filesystem": "1.0.0-alpha.9",
|
|
30
|
+
"@toa.io/generic": "1.0.0-alpha.9",
|
|
31
|
+
"@toa.io/norm": "1.0.0-alpha.9",
|
|
32
|
+
"@toa.io/schemas": "1.0.0-alpha.9",
|
|
33
33
|
"@toa.io/storages.null": "0.22.0",
|
|
34
|
-
"@toa.io/yaml": "1.0.0-alpha.
|
|
34
|
+
"@toa.io/yaml": "1.0.0-alpha.9",
|
|
35
35
|
"tap": "16.3.4"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "017a3fa22e8c60654c240f8e55908773d44d4ed1"
|
|
38
38
|
}
|
package/readme.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# Toa development kit
|
|
2
2
|
|
|
3
3
|
- [Stage](./stage): integration tests framework (Node.js)
|
|
4
|
-
- [Samples](./samples): YAML-based declarative tests
|
|
5
|
-
- Features[^1]: Gherkin steps definition ([cucumber.js](https://github.com/cucumber/cucumber-js))
|
|
6
4
|
|
|
7
5
|
See [example](./example).
|
|
8
6
|
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
title: Should increment number
|
|
2
|
-
input:
|
|
3
|
-
value: 1
|
|
4
|
-
times: 1
|
|
5
|
-
output: 2
|
|
6
|
-
local:
|
|
7
|
-
add:
|
|
8
|
-
input:
|
|
9
|
-
a: 1
|
|
10
|
-
b: 1
|
|
11
|
-
output: 2
|
|
12
|
-
---
|
|
13
|
-
title: Should increment twice
|
|
14
|
-
input:
|
|
15
|
-
value: 0
|
|
16
|
-
times: 2
|
|
17
|
-
output: 2
|
|
18
|
-
local:
|
|
19
|
-
add:
|
|
20
|
-
- input:
|
|
21
|
-
a: 0
|
|
22
|
-
b: 1
|
|
23
|
-
output: 1
|
|
24
|
-
- input:
|
|
25
|
-
a: 1
|
|
26
|
-
b: 1
|
|
27
|
-
output: 2
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
title: Should create
|
|
2
|
-
input:
|
|
3
|
-
material: glass
|
|
4
|
-
volume: 1.5
|
|
5
|
-
next:
|
|
6
|
-
material: glass
|
|
7
|
-
volume: 1.5
|
|
8
|
-
---
|
|
9
|
-
title: Should update
|
|
10
|
-
input:
|
|
11
|
-
material: steel
|
|
12
|
-
current:
|
|
13
|
-
material: glass
|
|
14
|
-
volume: 1.5
|
|
15
|
-
next:
|
|
16
|
-
material: steel
|
|
17
|
-
volume: 1.5
|
|
18
|
-
---
|
|
19
|
-
title: Should emit `created` event
|
|
20
|
-
input:
|
|
21
|
-
material: glass
|
|
22
|
-
volume: 1.5
|
|
23
|
-
next:
|
|
24
|
-
material: glass
|
|
25
|
-
volume: 1.5
|
|
26
|
-
events:
|
|
27
|
-
created:
|
|
28
|
-
material: glass
|
|
29
|
-
volume: 1.5
|
|
30
|
-
---
|
|
31
|
-
title: Should emit `updated` event
|
|
32
|
-
input:
|
|
33
|
-
material: steel
|
|
34
|
-
current:
|
|
35
|
-
material: glass
|
|
36
|
-
volume: 1.5
|
|
37
|
-
next:
|
|
38
|
-
material: steel
|
|
39
|
-
volume: 1.5
|
|
40
|
-
events:
|
|
41
|
-
updated:
|
|
42
|
-
material: steel
|
|
43
|
-
volume: 1.5
|
|
Binary file
|
|
Binary file
|
package/samples/notes.md
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# Developer notes
|
|
2
|
-
|
|
3
|
-
## Extending Replay
|
|
4
|
-
|
|
5
|
-
1. Update [`example`](../example). `toa replay` should either fail or throw exception.
|
|
6
|
-
2. Add [feature](/features). It should fail.
|
|
7
|
-
3. If the new decorator is being developed:
|
|
8
|
-
1. Add the [decorator](/extensions/sampling/docs/replay.md).
|
|
9
|
-
2. Add [boot extension](/runtime/boot/src/extensions).
|
|
10
|
-
4. Update `suite` [translation](./src/.suite/.component/translate.js).
|
|
11
|
-
5. Ensure the feature is passing.
|
|
12
|
-
6. Ensure example is passing with `toa replay`.
|
package/samples/package.json
DELETED
package/samples/readme.md
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
# Samples
|
|
2
|
-
|
|
3
|
-
## TL;DR
|
|
4
|
-
|
|
5
|
-
<a href="https://miro.com/app/board/uXjVOoy0ImU=/?moveToWidget=3458764532091744292&cot=14">
|
|
6
|
-
<picture>
|
|
7
|
-
<source media="(prefers-color-scheme: dark)" srcset="./docs/sampling-dark.jpg">
|
|
8
|
-
<img alt="4D" width="640" height="435" src="./docs/sampling-light.jpg">
|
|
9
|
-
</picture>
|
|
10
|
-
</a>
|
|
11
|
-
|
|
12
|
-
See [features](/features/replay).
|
|
13
|
-
|
|
14
|
-
## Operation Samples
|
|
15
|
-
|
|
16
|
-
Sample is an object containing values of operation inputs (i.e.: request, context outputs and
|
|
17
|
-
current state) to be substituted and outcomes (reply, context calls, next state and events emission)
|
|
18
|
-
to be verified. See its [schema](./src/.replay/.suite/translate/schemas/operation.cos.yaml).
|
|
19
|
-
|
|
20
|
-
> Although `input` and `output` are declared as arbitrary values, they must conform to the
|
|
21
|
-
> corresponding operation schemas.
|
|
22
|
-
|
|
23
|
-
### Declaration
|
|
24
|
-
|
|
25
|
-
> Samples must be declared
|
|
26
|
-
> as [multi-document YAML files](https://yaml.org/spec/1.2.2/#22-structures).
|
|
27
|
-
|
|
28
|
-
Operation samples must be located under the `samples` directory in the component or context root.
|
|
29
|
-
Sample file names must follow the convention: `namespace.component.operation.yaml`, that is, be an
|
|
30
|
-
endpoint of the operation samples to be applied to. For component-level sample files `namespace`
|
|
31
|
-
and `name` must match corresponding component, therefore are optional.
|
|
32
|
-
|
|
33
|
-
## Message Samples
|
|
34
|
-
|
|
35
|
-
Message Sample is an object containing receiver's input (`payload`) to be substituted and
|
|
36
|
-
outcomes (`input` and `query`) to be verified. Message sample may contain the corresponding
|
|
37
|
-
operation
|
|
38
|
-
sample. See its [schema](./src/.replay/.suite/translate/schemas/message.cos.yaml).
|
|
39
|
-
|
|
40
|
-
> Message samples are only supported at [context level](#autonomy).
|
|
41
|
-
|
|
42
|
-
### Declaration
|
|
43
|
-
|
|
44
|
-
Operation samples must be located under the `samples/messages` directory in the component or context
|
|
45
|
-
root. Samples file names must follow the convention `namesace.component.event.yaml`, that is, be a
|
|
46
|
-
label of the event receiver is consuming.
|
|
47
|
-
|
|
48
|
-
#### Aspect Shortcuts
|
|
49
|
-
|
|
50
|
-
- `configuration` for [Configuration](/extensions/configuration)
|
|
51
|
-
- `state` for [State](/extensions/state)
|
|
52
|
-
- `http` for HTTP Aspect from [Origins](/extensions/origins)
|
|
53
|
-
|
|
54
|
-
#### Aspect Result Type Hints
|
|
55
|
-
|
|
56
|
-
When using aspect calls, there might be situations where the returned values cannot be adequately
|
|
57
|
-
described using YAML.
|
|
58
|
-
To address this issue, type hints can be used.
|
|
59
|
-
|
|
60
|
-
```yaml
|
|
61
|
-
state:
|
|
62
|
-
values:Map:
|
|
63
|
-
foo: 1
|
|
64
|
-
bar: 2
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
In the code snippet above, the `state` Aspect returns a `values` field of type Map.
|
|
68
|
-
|
|
69
|
-
```yaml
|
|
70
|
-
state:
|
|
71
|
-
values:Set: [foo, bar]
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
`sync` and `async` hints define functions:
|
|
75
|
-
|
|
76
|
-
```yaml
|
|
77
|
-
state:
|
|
78
|
-
get:sync: foo
|
|
79
|
-
request:async: bar
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
## Autonomy
|
|
83
|
-
|
|
84
|
-
Component level samples are *autonomous*, namely, does not assume actual remote calls as
|
|
85
|
-
replaying of component-level samples will boot only that component. Remote call attempt not declared
|
|
86
|
-
within sample will cause an exception.
|
|
87
|
-
See [examples](../example/components/math.calculations/samples).
|
|
88
|
-
|
|
89
|
-
For context level samples (integration samples), remote calls with non-declared outputs will be
|
|
90
|
-
actually performed. Replaying these samples will boot the composition with all components of the
|
|
91
|
-
context (so as required extensions). See [examples](../example/samples).
|
|
92
|
-
|
|
93
|
-
> Integration samples are more flexible and less sensitive to implementation details.
|
|
94
|
-
|
|
95
|
-
## Replay
|
|
96
|
-
|
|
97
|
-
### CLI
|
|
98
|
-
|
|
99
|
-
Samples may be replayed using [`toa replay`](/runtime/cli/readme.md#replay) command.
|
|
100
|
-
|
|
101
|
-
See [features](/features/cli/replay.feature).
|
|
102
|
-
|
|
103
|
-
### Framework
|
|
104
|
-
|
|
105
|
-
`async components(paths: string[], options?): boolean`
|
|
106
|
-
|
|
107
|
-
Replay component samples.
|
|
108
|
-
|
|
109
|
-
`async components(paths: string[], options?): boolean`
|
|
110
|
-
|
|
111
|
-
Replay context and its components' samples.
|
|
112
|
-
|
|
113
|
-
#### Options
|
|
114
|
-
|
|
115
|
-
<dl>
|
|
116
|
-
<dt><code><strong>id</strong>: string</code></dt>
|
|
117
|
-
<dd>Replay samples for a specified component</dd>
|
|
118
|
-
|
|
119
|
-
<dt><code><strong>integration</strong>: string</code></dt>
|
|
120
|
-
<dd>Replay samples for a specified component only</dd>
|
|
121
|
-
<dd></dd>
|
|
122
|
-
|
|
123
|
-
<dt><code><strong>operation</strong>: string</code></dt>
|
|
124
|
-
<dd>Replay samples for specified operation</dd>
|
|
125
|
-
|
|
126
|
-
<dt><code><strong>title</strong>: string</code></dt>
|
|
127
|
-
<dd>Replay samples with titles matching given regexp</dd>
|
|
128
|
-
|
|
129
|
-
</dl>
|
|
130
|
-
|
|
131
|
-
See [types](types/suite.d.ts).
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const stage = require('@toa.io/userland/stage')
|
|
4
|
-
|
|
5
|
-
const { operation } = require('./operation')
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @param {toa.core.Component} component
|
|
9
|
-
* @param {toa.samples.operations.Set} set
|
|
10
|
-
* @param {boolean} autonomous
|
|
11
|
-
* @returns {Function}
|
|
12
|
-
*/
|
|
13
|
-
const component = (component, set, autonomous) =>
|
|
14
|
-
async (test) => {
|
|
15
|
-
for (const [endpoint, samples] of Object.entries(set)) {
|
|
16
|
-
await test.test(endpoint, operation(component, endpoint, samples, autonomous))
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
exports.component = component
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { binding } = require('@toa.io/userland/stage').binding
|
|
4
|
-
|
|
5
|
-
const translate = require('./translate')
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @param {toa.samples.messages.Set} messages
|
|
9
|
-
* @param {boolean} autonomous
|
|
10
|
-
* @return {Function}
|
|
11
|
-
*/
|
|
12
|
-
const messages = (messages, autonomous) =>
|
|
13
|
-
async (test) => {
|
|
14
|
-
for (const [label, samples] of Object.entries(messages)) {
|
|
15
|
-
await test.test(label, message(label, samples, autonomous))
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @param {string} label
|
|
21
|
-
* @param {toa.samples.Message[]} samples
|
|
22
|
-
* @param {boolean} autonomous
|
|
23
|
-
* @returns {function}
|
|
24
|
-
*/
|
|
25
|
-
const message = (label, samples, autonomous) =>
|
|
26
|
-
async (test) => {
|
|
27
|
-
let n = 0
|
|
28
|
-
|
|
29
|
-
for (const sample of samples) {
|
|
30
|
-
n++
|
|
31
|
-
|
|
32
|
-
const message = translate.message(sample, autonomous)
|
|
33
|
-
const name = sample.title ?? 'Sample #' + n
|
|
34
|
-
|
|
35
|
-
await test.test(name, async () => binding.emit(label, message))
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
exports.messages = messages
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const translate = require('./translate')
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @param {toa.core.Component} remote
|
|
7
|
-
* @param {string} endpoint
|
|
8
|
-
* @param {toa.samples.Operation[]} samples
|
|
9
|
-
* @param {boolean} autonomous
|
|
10
|
-
* @returns {Function}
|
|
11
|
-
*/
|
|
12
|
-
const operation = (remote, endpoint, samples, autonomous) =>
|
|
13
|
-
async (test) => {
|
|
14
|
-
let n = 0
|
|
15
|
-
|
|
16
|
-
for (const operation of samples) {
|
|
17
|
-
n++
|
|
18
|
-
|
|
19
|
-
const request = translate.operation(operation, autonomous)
|
|
20
|
-
const name = operation.title ?? 'Sample #' + n
|
|
21
|
-
|
|
22
|
-
await test.test(name, async () => await remote.invoke(endpoint, request))
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
test.end()
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
exports.operation = operation
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { component } = require('./component')
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @param {toa.samples.suite.Operations} operations
|
|
7
|
-
* @param {Record<string, toa.core.Component>} components
|
|
8
|
-
* @param {boolean} autonomous
|
|
9
|
-
* @return {Function}
|
|
10
|
-
*/
|
|
11
|
-
const operations = (operations, components, autonomous) =>
|
|
12
|
-
async (test) => {
|
|
13
|
-
for (const [id, set] of Object.entries(operations)) {
|
|
14
|
-
const remote = components[id]
|
|
15
|
-
|
|
16
|
-
await test.test(id, component(remote, set, autonomous))
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
exports.operations = operations
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { add, defined } = require('@toa.io/generic')
|
|
4
|
-
const translate = require('../operation')
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @param {toa.samples.Message} declaration
|
|
8
|
-
* @param {boolean} autonomous
|
|
9
|
-
* @returns {toa.sampling.request.Sample}
|
|
10
|
-
*/
|
|
11
|
-
const request = (declaration, autonomous) => {
|
|
12
|
-
const { title, input, query } = declaration
|
|
13
|
-
|
|
14
|
-
/** @type {toa.sampling.request.Sample} */
|
|
15
|
-
const sample = declaration.request === undefined
|
|
16
|
-
? {}
|
|
17
|
-
: translate.operation(declaration.request, autonomous).sample
|
|
18
|
-
|
|
19
|
-
const request = defined({ input, query })
|
|
20
|
-
|
|
21
|
-
/** @type {Partial<toa.sampling.request.Sample>} */
|
|
22
|
-
const patch = { title, autonomous, request }
|
|
23
|
-
|
|
24
|
-
if (declaration.request === undefined) patch.terminate = true
|
|
25
|
-
|
|
26
|
-
add(sample, patch)
|
|
27
|
-
|
|
28
|
-
return sample
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
exports.request = request
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { plain } = require('@toa.io/generic')
|
|
4
|
-
const types = require('./types')
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @param {toa.sampling.request.Extensions} extensions
|
|
8
|
-
*/
|
|
9
|
-
function cast (extensions) {
|
|
10
|
-
for (const calls of Object.values(extensions)) calls.map(resolve)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @param {toa.sampling.request.extensions.Call} call
|
|
15
|
-
*/
|
|
16
|
-
function resolve (call) {
|
|
17
|
-
if (plain(call.result)) call.result = types.cast(call.result)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
exports.cast = cast
|
|
@@ -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
|