@toa.io/userland 0.20.0-dev.8 → 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 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
@@ -11,3 +11,5 @@ operations:
11
11
 
12
12
  configuration:
13
13
  signal: quack
14
+
15
+ state: ~
@@ -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
- const reply = await context.local.add({ input: { a: value, b: 1 } })
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,6 +1,6 @@
1
1
  title: Should add numbers
2
2
  input:
3
- $import: assets/ab.yaml
3
+ <assign: assets/ab.yaml
4
4
  output: 3
5
5
  ---
6
6
  title: Should add negative numbers
@@ -5,4 +5,4 @@ operations:
5
5
  output: object
6
6
 
7
7
  origins:
8
- dev: https://null
8
+ dev: http://api.example.com
@@ -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 { error: { code: 0, message: 'Unsupported media type ' + type } }
8
-
9
- const output = await response.json()
9
+ if (type !== 'application/json') return new Nope(0, 'Unsupported media type ' + type)
10
10
 
11
- return { output }
11
+ return await response.json()
12
12
  }
13
13
 
14
14
  exports.computation = computation
@@ -1,3 +1,10 @@
1
1
  name: examples
2
2
  packages: components/*
3
3
  registry: example
4
+
5
+ amqp: amqp://localhost
6
+ mongodb: mongodb://localhost
7
+
8
+ origins:
9
+ default.web:
10
+ dev: http://localhost
@@ -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.output).toStrictEqual('quack')
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.output.id
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.output.booked).toStrictEqual(true)
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-dev.8",
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-dev.8",
28
- "@toa.io/core": "0.20.0-dev.8",
29
- "@toa.io/filesystem": "0.20.0-dev.8",
30
- "@toa.io/generic": "0.20.0-dev.8",
31
- "@toa.io/norm": "0.20.0-dev.8",
32
- "@toa.io/schemas": "0.20.0-dev.8",
33
- "@toa.io/storages.null": "0.20.0-dev.8",
34
- "@toa.io/yaml": "0.20.0-dev.8",
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": "d8c08ec7def70ad93de06541af497cce8c4c1b50"
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 operation
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 described using YAML.
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 above code snippet, the `state` Aspect returns a `values` field of type Map.
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
- try {
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('must NOT have additional properties')
38
+ expect(() => translate(declaration, true)).toThrow('not expected')
39
39
  })
40
40
  })
41
41
 
@@ -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
- /** @type {toa.boot.composition.Options} */
11
- const options = { bindings: [binding] }
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()
@@ -10,6 +10,7 @@ const binding = require('./binding')
10
10
  exports.manifest = manifest
11
11
  exports.component = component
12
12
  exports.composition = composition
13
+ exports.compose = composition
13
14
  exports.remote = remote
14
15
  exports.shutdown = shutdown
15
16
  exports.binding = binding
@@ -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
- declare namespace toa.stage {
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
- interface Stage {
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 type Stage = toa.stage.Stage
9
+ export function composition (paths: string[], options?: _composition.Options): Promise<void>
22
10
 
23
- export const manifest: toa.stage.Manifest
24
- export const component: toa.stage.Component
25
- export const composition: toa.stage.Composition
26
- export const remote: toa.stage.Remote
27
- export const shutdown: toa.stage.Shutdown
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'