@toa.io/userland 0.20.0-dev.9 → 0.20.0
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/example/.env +9 -0
- package/example/components/echo/manifest.toa.yaml +2 -0
- package/example/components/math.calculations/operations/increment.js +1 -3
- package/example/components/math.calculations/samples/add.yaml +1 -1
- package/example/components/web/manifest.toa.yaml +1 -1
- package/example/components/web/operations/get.js +4 -4
- package/example/context.toa.yaml +7 -0
- package/example/stage/call.test.js +1 -4
- package/example/stage/events.test.js +2 -3
- package/package.json +10 -10
- package/samples/readme.md +5 -5
- package/samples/test/replay.translate.message.test.js +2 -6
- package/samples/test/replay.translate.operation.test.js +1 -1
- package/stage/src/composition.js +3 -3
- package/stage/src/index.js +1 -0
- package/stage/types/index.d.ts +8 -20
package/example/.env
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
TOA_ENV=local
|
|
2
|
+
TOA_AMQP_CONTEXT=eyIuIjpbImFtcXA6Ly9sb2NhbGhvc3QiXX0=
|
|
3
|
+
TOA_AMQP_CONTEXT__USERNAME=developer
|
|
4
|
+
TOA_AMQP_CONTEXT__PASSWORD=secret
|
|
5
|
+
TOA_MONGODB_TEA_POTS=mongodb://localhost
|
|
6
|
+
TOA_MONGODB_TEA_POTS_USERNAME=developer
|
|
7
|
+
TOA_MONGODB_TEA_POTS_PASSWORD=secret
|
|
8
|
+
TOA_ORIGINS_DEFAULT_WEB_DEV=http://localhost
|
|
9
|
+
TOA_ORIGINS_DEFAULT_WEB__PROPERTIES=3gAA
|
|
@@ -4,9 +4,7 @@ async function computation (input, context) {
|
|
|
4
4
|
let value = input.value
|
|
5
5
|
|
|
6
6
|
for (let i = 0; i < input.times; i++) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
value = reply.output
|
|
7
|
+
value = await context.local.add({ input: { a: value, b: 1 } })
|
|
10
8
|
}
|
|
11
9
|
|
|
12
10
|
return value
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const { Nope } = require('nopeable')
|
|
4
|
+
|
|
3
5
|
async function computation (_, context) {
|
|
4
6
|
const response = await context.http.dev.path.to.resource.get()
|
|
5
7
|
const type = response.headers.get('content-type')
|
|
6
8
|
|
|
7
|
-
if (type !== 'application/json') return
|
|
8
|
-
|
|
9
|
-
const output = await response.json()
|
|
9
|
+
if (type !== 'application/json') return new Nope(0, 'Unsupported media type ' + type)
|
|
10
10
|
|
|
11
|
-
return
|
|
11
|
+
return await response.json()
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
exports.computation = computation
|
package/example/context.toa.yaml
CHANGED
|
@@ -6,10 +6,7 @@ const stage = require('@toa.io/userland/stage')
|
|
|
6
6
|
|
|
7
7
|
const root = resolve(__dirname, '../components')
|
|
8
8
|
|
|
9
|
-
/** @type {toa.core.Component} */
|
|
10
9
|
let echo
|
|
11
|
-
|
|
12
|
-
/** @type {toa.core.Component} */
|
|
13
10
|
let math
|
|
14
11
|
|
|
15
12
|
beforeAll(async () => {
|
|
@@ -32,7 +29,7 @@ afterAll(async () => {
|
|
|
32
29
|
it('should call endpoint', async () => {
|
|
33
30
|
const reply = await echo.invoke('signal', {})
|
|
34
31
|
|
|
35
|
-
expect(reply
|
|
32
|
+
expect(reply).toStrictEqual('quack')
|
|
36
33
|
})
|
|
37
34
|
|
|
38
35
|
it('should throw on invalid input', async () => {
|
|
@@ -6,7 +6,6 @@ const stage = require('@toa.io/userland/stage')
|
|
|
6
6
|
const binding = stage.binding.binding
|
|
7
7
|
const root = resolve(__dirname, '../components')
|
|
8
8
|
|
|
9
|
-
/** @type {toa.core.Component} */
|
|
10
9
|
let remote
|
|
11
10
|
|
|
12
11
|
beforeAll(async () => {
|
|
@@ -27,7 +26,7 @@ afterAll(async () => {
|
|
|
27
26
|
|
|
28
27
|
it('should receive event', async () => {
|
|
29
28
|
const created = await remote.invoke('transit', { input: { material: 'glass' } })
|
|
30
|
-
const id = created.
|
|
29
|
+
const id = created.id
|
|
31
30
|
const payload = { pot: id }
|
|
32
31
|
const message = { payload }
|
|
33
32
|
const request = { query: { id } }
|
|
@@ -36,7 +35,7 @@ it('should receive event', async () => {
|
|
|
36
35
|
|
|
37
36
|
const reply = await remote.invoke('observe', request)
|
|
38
37
|
|
|
39
|
-
expect(reply.
|
|
38
|
+
expect(reply.booked).toStrictEqual(true)
|
|
40
39
|
})
|
|
41
40
|
|
|
42
41
|
it('should emit event', async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/userland",
|
|
3
|
-
"version": "0.20.0
|
|
3
|
+
"version": "0.20.0",
|
|
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": "0.20.0
|
|
28
|
-
"@toa.io/core": "0.20.0
|
|
29
|
-
"@toa.io/filesystem": "0.20.0
|
|
30
|
-
"@toa.io/generic": "0.20.0
|
|
31
|
-
"@toa.io/norm": "0.20.0
|
|
32
|
-
"@toa.io/schemas": "0.20.0
|
|
33
|
-
"@toa.io/storages.null": "0.20.0
|
|
34
|
-
"@toa.io/yaml": "0.20.0
|
|
27
|
+
"@toa.io/boot": "0.20.0",
|
|
28
|
+
"@toa.io/core": "0.20.0",
|
|
29
|
+
"@toa.io/filesystem": "0.20.0",
|
|
30
|
+
"@toa.io/generic": "0.20.0",
|
|
31
|
+
"@toa.io/norm": "0.20.0",
|
|
32
|
+
"@toa.io/schemas": "0.20.0",
|
|
33
|
+
"@toa.io/storages.null": "0.20.0",
|
|
34
|
+
"@toa.io/yaml": "0.20.0",
|
|
35
35
|
"tap": "16.3.4"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "28fc4b45c224c3683acaaf0e4abd1eb04e07b408"
|
|
38
38
|
}
|
package/samples/readme.md
CHANGED
|
@@ -33,7 +33,8 @@ and `name` must match corresponding component, therefore are optional.
|
|
|
33
33
|
## Message Samples
|
|
34
34
|
|
|
35
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
|
|
36
|
+
outcomes (`input` and `query`) to be verified. Message sample may contain the corresponding
|
|
37
|
+
operation
|
|
37
38
|
sample. See its [schema](./src/.replay/.suite/translate/schemas/message.cos.yaml).
|
|
38
39
|
|
|
39
40
|
> Message samples are only supported at [context level](#autonomy).
|
|
@@ -52,7 +53,8 @@ label of the event receiver is consuming.
|
|
|
52
53
|
|
|
53
54
|
#### Aspect Result Type Hints
|
|
54
55
|
|
|
55
|
-
When using aspect calls, there might be situations where the returned values cannot be adequately
|
|
56
|
+
When using aspect calls, there might be situations where the returned values cannot be adequately
|
|
57
|
+
described using YAML.
|
|
56
58
|
To address this issue, type hints can be used.
|
|
57
59
|
|
|
58
60
|
```yaml
|
|
@@ -62,7 +64,7 @@ state:
|
|
|
62
64
|
bar: 2
|
|
63
65
|
```
|
|
64
66
|
|
|
65
|
-
In the
|
|
67
|
+
In the code snippet above, the `state` Aspect returns a `values` field of type Map.
|
|
66
68
|
|
|
67
69
|
```yaml
|
|
68
70
|
state:
|
|
@@ -92,8 +94,6 @@ context (so as required extensions). See [examples](../example/samples).
|
|
|
92
94
|
|
|
93
95
|
## Replay
|
|
94
96
|
|
|
95
|
-
> Replaying samples requires local deployment environment.
|
|
96
|
-
|
|
97
97
|
### CLI
|
|
98
98
|
|
|
99
99
|
Samples may be replayed using [`toa replay`](/runtime/cli/readme.md#replay) command.
|
|
@@ -108,16 +108,12 @@ describe('validation', () => {
|
|
|
108
108
|
expect(check).toThrow('must be string')
|
|
109
109
|
})
|
|
110
110
|
|
|
111
|
-
it.each(['input', 'query'])('should throw if request.%s is defined', async (key) => {
|
|
111
|
+
it.each([['input', 'query']])('should throw if request.%s is defined', async (key) => {
|
|
112
112
|
expect.assertions(1)
|
|
113
113
|
|
|
114
114
|
declaration[key] = { id: generate() }
|
|
115
115
|
declaration.request = /** @type {toa.samples.Operation} */ { [key]: { id: generate() } }
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
check()
|
|
119
|
-
} catch (exception) {
|
|
120
|
-
expect(exception).toMatchObject({ path: '/request' })
|
|
121
|
-
}
|
|
117
|
+
expect(() => check()).toThrow('/request')
|
|
122
118
|
})
|
|
123
119
|
})
|
|
@@ -35,7 +35,7 @@ describe('validation', () => {
|
|
|
35
35
|
it('should not allow additional properties', () => {
|
|
36
36
|
declaration.foo = generate()
|
|
37
37
|
|
|
38
|
-
expect(() => translate(declaration, true)).toThrow('
|
|
38
|
+
expect(() => translate(declaration, true)).toThrow('not expected')
|
|
39
39
|
})
|
|
40
40
|
})
|
|
41
41
|
|
package/stage/src/composition.js
CHANGED
|
@@ -6,9 +6,9 @@ const { state } = require('./state')
|
|
|
6
6
|
const binding = require.resolve('./binding')
|
|
7
7
|
|
|
8
8
|
/** @type {toa.stage.Composition} */
|
|
9
|
-
const composition = async (paths) => {
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const composition = async (paths, options) => {
|
|
10
|
+
options ??= { bindings: [binding] }
|
|
11
|
+
|
|
12
12
|
const composition = await boot.composition(paths, options)
|
|
13
13
|
|
|
14
14
|
await composition.connect()
|
package/stage/src/index.js
CHANGED
package/stage/types/index.d.ts
CHANGED
|
@@ -2,28 +2,16 @@ import * as _core from '@toa.io/core/types'
|
|
|
2
2
|
import * as _norm from '@toa.io/norm/types'
|
|
3
3
|
import * as _composition from '@toa.io/boot/types/composition'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
type Manifest = (path: string) => Promise<_norm.Component>
|
|
7
|
-
type Component = (path: string, options?: _composition.Options) => Promise<_core.Component>
|
|
8
|
-
type Composition = (paths: string[]) => Promise<void>
|
|
9
|
-
type Remote = (id: string) => Promise<_core.Component>
|
|
10
|
-
type Shutdown = () => Promise<void>
|
|
5
|
+
export function manifest (path: string): Promise<_norm.Component>
|
|
11
6
|
|
|
12
|
-
|
|
13
|
-
manifest: toa.stage.Manifest
|
|
14
|
-
component: toa.stage.Component
|
|
15
|
-
composition: toa.stage.Composition
|
|
16
|
-
remote: toa.stage.Remote
|
|
17
|
-
shutdown: toa.stage.Shutdown
|
|
18
|
-
}
|
|
19
|
-
}
|
|
7
|
+
export function component (path: string): Promise<_core.Component>
|
|
20
8
|
|
|
21
|
-
export
|
|
9
|
+
export function composition (paths: string[], options?: _composition.Options): Promise<void>
|
|
22
10
|
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
export
|
|
11
|
+
export function compose (paths: string[]): Promise<void>
|
|
12
|
+
|
|
13
|
+
export function remote (id: string): Promise<_core.Component>
|
|
14
|
+
|
|
15
|
+
export function shutdown (): Promise<void>
|
|
28
16
|
|
|
29
17
|
export * as binding from './binding'
|