@toa.io/core 0.8.1-dev.1 → 0.20.0-alpha.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/core",
3
- "version": "0.8.1-dev.1",
3
+ "version": "0.20.0-alpha.0",
4
4
  "description": "Toa Core",
5
5
  "author": "temich <tema.gurtovoy@gmail.com>",
6
6
  "homepage": "https://github.com/toa-io/toa#readme",
@@ -12,18 +12,22 @@
12
12
  "url": "https://github.com/toa-io/toa/issues"
13
13
  },
14
14
  "main": "src/index.js",
15
+ "types": "types/index.d.ts",
15
16
  "publishConfig": {
16
17
  "access": "public"
17
18
  },
18
19
  "scripts": {
19
20
  "test": "echo \"Error: run tests from root\" && exit 1"
20
21
  },
22
+ "peerDependencies": {
23
+ "nopeable": "*"
24
+ },
21
25
  "dependencies": {
22
26
  "@rsql/parser": "1.2.4",
23
- "@toa.io/console": "0.6.0",
24
- "@toa.io/generic": "0.9.0-dev.1",
25
- "@toa.io/yaml": "0.7.3-dev.1",
27
+ "@toa.io/console": "0.20.0-alpha.0",
28
+ "@toa.io/generic": "0.20.0-alpha.0",
29
+ "@toa.io/yaml": "0.20.0-alpha.0",
26
30
  "clone-deep": "4.0.1"
27
31
  },
28
- "gitHead": "8b3fb929284365afb0d301756dfbcc549734dc99"
32
+ "gitHead": "d047190899218b5249901a01a2a4caec5b34cf09"
29
33
  }
package/src/call.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { Connector } = require('./connector')
4
+ const { Nope } = require('nopeable')
4
5
 
5
6
  class Call extends Connector {
6
7
  #transmitter
@@ -18,11 +19,21 @@ class Call extends Connector {
18
19
  async invoke (request = {}) {
19
20
  this.#contract.fit(request)
20
21
 
21
- const { exception, ...reply } = await this.#transmitter.request(request)
22
+ // avoid validation on the recipient's side
23
+ request.authentic = true
22
24
 
23
- if (exception) throw exception
25
+ const reply = await this.#transmitter.request(request)
24
26
 
25
- return reply
27
+ if (reply === null) return null
28
+ else {
29
+ if (reply.exception !== undefined)
30
+ throw reply.exception
31
+
32
+ if (reply.error !== undefined)
33
+ return new Nope(reply.error)
34
+
35
+ return reply.output
36
+ }
26
37
  }
27
38
  }
28
39
 
package/src/cascade.js CHANGED
@@ -5,27 +5,31 @@ const { Connector } = require('./connector')
5
5
 
6
6
  class Cascade extends Connector {
7
7
  #bridges
8
+ #last
8
9
 
9
10
  constructor (bridges) {
10
11
  super()
11
12
 
12
13
  this.#bridges = bridges
14
+ this.#last = bridges[bridges.length - 1]
13
15
 
14
16
  this.depends(bridges)
15
17
  }
16
18
 
17
19
  async run (...args) {
18
- const reply = {}
19
-
20
- for (const bridge of this.#bridges) {
21
- const partial = await bridge.execute(...args)
22
-
23
- if (partial.error) return { error: partial.error }
24
-
25
- merge(reply, partial)
26
- }
27
-
28
- return reply
20
+ // const reply = {}
21
+ //
22
+ // for (const bridge of this.#bridges) {
23
+ // const partial = await bridge.execute(...args)
24
+ //
25
+ // if (partial.error) return { error: partial.error }
26
+ //
27
+ // merge(reply, partial)
28
+ // }
29
+ //
30
+ // return reply
31
+
32
+ return this.#last.execute(...args)
29
33
  }
30
34
  }
31
35
 
@@ -13,11 +13,10 @@ class Request extends Conditions {
13
13
  * @returns {toa.schema.JSON}
14
14
  */
15
15
  static schema (definition) {
16
- const schema = { type: 'object', properties: {}, additionalProperties: true }
16
+ const schema = { type: 'object', properties: { authentic: { type: 'boolean' } }, additionalProperties: true }
17
17
  const required = []
18
18
 
19
19
  if (definition.input !== undefined) {
20
- definition.input.additionalProperties = false
21
20
  schema.properties.input = definition.input
22
21
  required.push('input')
23
22
  } else {
@@ -1,7 +1,9 @@
1
+ type: object
1
2
  properties:
2
3
  code:
3
- type: integer
4
- minimum: 0
4
+ anyOf:
5
+ - type: integer
6
+ - type: string
5
7
  message:
6
8
  type: string
7
- required: [code, message]
9
+ required: [code]
@@ -1,3 +1,4 @@
1
+ type: object
1
2
  properties:
2
3
  id:
3
4
  $ref: https://schemas.toa.io/0.0.0/definitions#/definitions/id
package/src/discovery.js CHANGED
@@ -30,7 +30,7 @@ class Discovery extends Connector {
30
30
  const warning = () => console.warn(`Waiting for lookup response from '${id}'...`)
31
31
  const timeout = setTimeout(warning, TIMEOUT)
32
32
 
33
- const { output } = await this.#lookups[id].invoke()
33
+ const output = await this.#lookups[id].invoke()
34
34
 
35
35
  console.debug(`Lookup response from '${id}' received`)
36
36
  clearTimeout(timeout)
package/src/exceptions.js CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict'
2
2
 
3
+ const { swap } = require('@toa.io/generic')
4
+
3
5
  const codes = {
4
6
  System: 0,
5
7
  NotImplemented: 10,
@@ -93,4 +95,5 @@ for (const [name, code] of Object.entries(codes)) {
93
95
  }
94
96
 
95
97
  exports.codes = codes
98
+ exports.names = swap(codes)
96
99
  // #endregion
@@ -14,6 +14,11 @@ class Observation extends Operation {
14
14
  store.scope = scope
15
15
  store.state = state
16
16
  }
17
+
18
+ async run (store) {
19
+ if (store.scope === null) store.reply = null
20
+ else await super.run(store)
21
+ }
17
22
  }
18
23
 
19
24
  exports.Observation = Observation
package/src/operation.js CHANGED
@@ -7,17 +7,17 @@ class Operation extends Connector {
7
7
  scope
8
8
 
9
9
  #cascade
10
- #contract
10
+ #contracts
11
11
  #query
12
12
  #scope
13
13
 
14
- constructor (cascade, scope, contract, query, definition) {
14
+ constructor (cascade, scope, contracts, query, definition) {
15
15
  super()
16
16
 
17
17
  this.scope = scope
18
18
 
19
19
  this.#cascade = cascade
20
- this.#contract = contract
20
+ this.#contracts = contracts
21
21
  this.#query = query
22
22
  this.#scope = definition.scope
23
23
 
@@ -26,7 +26,8 @@ class Operation extends Connector {
26
26
 
27
27
  async invoke (request) {
28
28
  try {
29
- if (request.query) request.query = this.#query.parse(request.query)
29
+ if (request.authentic !== true) this.#contracts.request.fit(request)
30
+ if ('query' in request) request.query = this.#query.parse(request.query)
30
31
 
31
32
  const store = { request }
32
33
 
@@ -52,7 +53,7 @@ class Operation extends Connector {
52
53
  const { request, state } = store
53
54
  const reply = await this.#cascade.run(request.input, state) || {}
54
55
 
55
- this.#contract.fit(reply)
56
+ this.#contracts.reply.fit(reply)
56
57
 
57
58
  store.reply = reply
58
59
  }
package/src/receiver.js CHANGED
@@ -19,29 +19,29 @@ class Receiver extends Connector {
19
19
  /** @type {toa.core.Component} */
20
20
  #local
21
21
 
22
- /** @type {toa.core.bridges.Event} */
22
+ /** @type {toa.core.bridges.Receiver} */
23
23
  #bridge
24
24
 
25
25
  /**
26
26
  *
27
27
  * @param {toa.norm.component.Receiver} definition
28
28
  * @param {toa.core.Component} local
29
- * @param {toa.core.bridges.Event} bridge
29
+ * @param {toa.core.bridges.Receiver} bridge
30
30
  */
31
31
  constructor (definition, local, bridge) {
32
32
  super()
33
33
 
34
- const { conditioned, adaptive, transition } = definition
34
+ const { conditioned, adaptive, operation } = definition
35
35
 
36
36
  this.#conditioned = conditioned
37
37
  this.#adaptive = adaptive
38
- this.#endpoint = transition
38
+ this.#endpoint = operation
39
39
 
40
40
  this.#local = local
41
41
  this.#bridge = bridge
42
42
 
43
43
  this.depends(local)
44
- this.depends(bridge)
44
+ if (bridge !== undefined) this.depends(bridge)
45
45
  }
46
46
 
47
47
  /** @hot */
@@ -52,13 +52,13 @@ class Receiver extends Connector {
52
52
 
53
53
  const request = await this.#request(payload)
54
54
 
55
- if (extensions) add(request, extensions)
55
+ add(request, extensions)
56
56
 
57
57
  await this.#local.invoke(this.#endpoint, request)
58
58
  }
59
59
 
60
60
  async #request (payload) {
61
- return this.#adaptive ? await this.#bridge.request(payload) : payload
61
+ return this.#adaptive ? await this.#bridge.request(payload) : { input: payload }
62
62
  }
63
63
  }
64
64
 
package/src/state.js CHANGED
@@ -28,9 +28,9 @@ class State {
28
28
  }
29
29
 
30
30
  init (id) {
31
- if (this.#initialized === true && id === undefined) {
32
- throw new StateInitializationException('Cannot initialize entity which is initialized. Use request.query.id to access.')
33
- }
31
+ // if (this.#initialized === true && id === undefined) {
32
+ // throw new StateInitializationException('Cannot initialize entity which is initialized. Use request.query.id to access.')
33
+ // }
34
34
 
35
35
  return this.#entity.init(id)
36
36
  }
@@ -41,10 +41,10 @@ class State {
41
41
  if (record === null) {
42
42
  if (this.#initialized && query.id !== undefined && query.version === undefined) return this.init(query.id)
43
43
  else if (query.version !== undefined) throw new StatePreconditionException()
44
- else throw new StateNotFoundException()
45
44
  }
46
45
 
47
- return this.#entity.object(record)
46
+ if (record === null) return null
47
+ else return this.#entity.object(record)
48
48
  }
49
49
 
50
50
  async objects (query) {
@@ -94,7 +94,7 @@ class State {
94
94
  else throw new StateNotFoundException()
95
95
  }
96
96
 
97
- // TODO: same as above
97
+ // same as above
98
98
  await this.#emission.emit({ changeset, state: result })
99
99
  }
100
100
  }
package/src/transition.js CHANGED
@@ -3,7 +3,7 @@
3
3
  const { retry } = require('@toa.io/generic')
4
4
 
5
5
  const { Operation } = require('./operation')
6
- const { StateConcurrencyException } = require('./exceptions')
6
+ const { StateConcurrencyException, StateNotFoundException } = require('./exceptions')
7
7
 
8
8
  class Transition extends Operation {
9
9
  #concurrency
@@ -22,6 +22,9 @@ class Transition extends Operation {
22
22
  const { request } = store
23
23
 
24
24
  store.scope = request.query ? await this.query(request.query) : this.scope.init()
25
+
26
+ if (store.scope === null) throw new StateNotFoundException()
27
+
25
28
  store.state = store.scope.get()
26
29
  }
27
30
 
@@ -4,7 +4,8 @@ const { generate } = require('randomstring')
4
4
 
5
5
  // noinspection JSCheckFunctionSignatures
6
6
  const transmission = {
7
- request: jest.fn((request) => ({ [request.invalid ? 'exception' : generate()]: generate() }))
7
+ request: jest.fn((request) => ({ [request.invalid ? 'exception' : 'output']: generate() })),
8
+ link: jest.fn()
8
9
  }
9
10
 
10
11
  const contract = {
package/test/call.test.js CHANGED
@@ -1,11 +1,7 @@
1
1
  'use strict'
2
2
 
3
- const { Call } = require('../src/call')
4
3
  const fixtures = require('./call.fixtures')
5
-
6
- jest.mock('../src/connector')
7
-
8
- const { Connector } = require('../src/connector')
4
+ const { Call } = require('../src/call')
9
5
 
10
6
  let call
11
7
 
@@ -16,9 +12,7 @@ beforeEach(() => {
16
12
  })
17
13
 
18
14
  it('should depend on transmission', () => {
19
- expect(call).toBeInstanceOf(Connector)
20
- expect(call).toBe(Connector.mock.instances[0])
21
- expect(Connector.mock.instances[0].depends).toHaveBeenCalledWith(fixtures.transmission)
15
+ expect(fixtures.transmission.link).toHaveBeenLastCalledWith(call)
22
16
  })
23
17
 
24
18
  it('should call transmission', async () => {
@@ -42,7 +36,7 @@ it('should return reply', async () => {
42
36
 
43
37
  const reply = await call.invoke(request)
44
38
 
45
- expect(reply).toStrictEqual(fixtures.transmission.request.mock.results[0].value)
39
+ expect(reply).toStrictEqual(fixtures.transmission.request.mock.results[0].value.output)
46
40
  })
47
41
 
48
42
  it('should throw received exceptions', async () => {
@@ -20,7 +20,8 @@ const schemas = {
20
20
  type: 'object',
21
21
  properties: {
22
22
  input: { type: 'null' },
23
- query: load.sync(resolve(__dirname, '../../src/contract/schemas/query.yaml'))
23
+ query: load.sync(resolve(__dirname, '../../src/contract/schemas/query.yaml')),
24
+ authentic: { type: 'boolean' }
24
25
  },
25
26
  additionalProperties: true
26
27
  }
@@ -3,7 +3,7 @@
3
3
  const { generate } = require('randomstring')
4
4
 
5
5
  const definition = /** @type {toa.norm.component.Receiver} */ {
6
- transition: generate(),
6
+ operation: generate(),
7
7
  conditioned: false,
8
8
  adaptive: false
9
9
  }
@@ -34,7 +34,7 @@ it('should apply', async () => {
34
34
 
35
35
  await receiver.receive({ payload })
36
36
 
37
- expect(fixtures.local.invoke).toHaveBeenCalledWith(definition.transition, payload)
37
+ expect(fixtures.local.invoke).toHaveBeenCalledWith(definition.operation, { input: payload })
38
38
  })
39
39
 
40
40
  it.each([[false], [true]])('should pass UI extensions (adaptive: %s)', async (adaptive) => {
@@ -49,7 +49,7 @@ it.each([[false], [true]])('should pass UI extensions (adaptive: %s)', async (ad
49
49
 
50
50
  await receiver.receive(message)
51
51
 
52
- const request = adaptive ? await fixtures.bridge.request.mock.results[0].value : payload
52
+ const request = adaptive ? await fixtures.bridge.request.mock.results[0].value : { input: payload }
53
53
  const expected = merge(clone(request), extension)
54
54
 
55
55
  const argument = fixtures.local.invoke.mock.calls[0][1]
@@ -68,7 +68,7 @@ describe('conditioned', () => {
68
68
  await receiver.receive({ payload })
69
69
 
70
70
  expect(fixtures.bridge.condition).toHaveBeenCalledWith(payload)
71
- expect(fixtures.local.invoke).toHaveBeenCalledWith(definition.transition, payload)
71
+ expect(fixtures.local.invoke).toHaveBeenCalledWith(definition.operation, { input: payload })
72
72
  })
73
73
 
74
74
  it('should not apply if condition is false', async () => {
@@ -90,6 +90,6 @@ describe('adaptive', () => {
90
90
  await receiver.receive({ payload })
91
91
 
92
92
  expect(fixtures.local.invoke)
93
- .toHaveBeenCalledWith(definition.transition, await fixtures.bridge.request.mock.results[0].value)
93
+ .toHaveBeenCalledWith(definition.operation, await fixtures.bridge.request.mock.results[0].value)
94
94
  })
95
95
  })
@@ -7,29 +7,29 @@ declare namespace toa.core.bindings {
7
7
  }
8
8
 
9
9
  interface Consumer extends _core.Connector {
10
- request(request: Request): Promise<_core.Reply>
10
+ request (request: Request): Promise<_core.Reply>
11
11
  }
12
12
 
13
13
  interface Emitter extends _core.Connector {
14
- emit(message: _core.Message): Promise<void>
14
+ emit (message: _core.Message): Promise<void>
15
15
  }
16
16
 
17
- interface Broadcast extends _core.Connector {
18
- transmit(label: string, payload: object): Promise<void>
17
+ interface Broadcast<L> extends _core.Connector {
18
+ transmit<T> (label: L, payload: T): Promise<void>
19
19
 
20
- receive(label: string, callback: (payload: object) => Promise<void>): Promise<void>
20
+ receive<T> (label: L, callback: (payload: T) => void | Promise<void>): Promise<void>
21
21
  }
22
22
 
23
23
  interface Factory {
24
- producer?(locator: _core.Locator, endpoints: Array<string>, producer: _core.Component): _core.Connector
24
+ producer? (locator: _core.Locator, endpoints: Array<string>, producer: _core.Component): _core.Connector
25
25
 
26
- consumer?(locator: _core.Locator, endpoint: string): Consumer
26
+ consumer? (locator: _core.Locator, endpoint: string): Consumer
27
27
 
28
- emitter?(locator: _core.Locator, label: string): Emitter
28
+ emitter? (locator: _core.Locator, label: string): Emitter
29
29
 
30
- receiver?(locator: _core.Locator, label: string, group: string, receiver: _core.Receiver): _core.Connector
30
+ receiver? (locator: _core.Locator, label: string, group: string, receiver: _core.Receiver): _core.Connector
31
31
 
32
- broadcast?(name: string, group?: string): Broadcast
32
+ broadcast? (name: string, group?: string): Broadcast
33
33
  }
34
34
 
35
35
  }
@@ -37,3 +37,4 @@ declare namespace toa.core.bindings {
37
37
  export type Emitter = toa.core.bindings.Emitter
38
38
  export type Factory = toa.core.bindings.Factory
39
39
  export type Properties = toa.core.bindings.Properties
40
+ export type Broadcast<L> = toa.core.bindings.Broadcast<L>
@@ -0,0 +1,10 @@
1
+ import { Connector } from './connector'
2
+ import { Locator } from './locator'
3
+ import { Request } from './request'
4
+ import { type Nopeable } from 'nopeable'
5
+
6
+ export interface Component extends Connector {
7
+ locator: Locator
8
+
9
+ invoke<T> (endpoint: string, request: Request): Promise<T>
10
+ }
@@ -1,24 +1,18 @@
1
- declare namespace toa.core {
1
+ export class Connector {
2
+ public id: string
3
+ public connected: boolean
2
4
 
3
- interface Connector {
4
- id: string
5
- connected: boolean
5
+ public connect (): Promise<void>
6
6
 
7
- depends(connector: Connector): Connector
7
+ public disconnect (interrupt?: boolean): Promise<void>
8
8
 
9
- link(connector: Connector): void
9
+ public depends (connector: Connector | Connector[]): Connector
10
10
 
11
- connect(): Promise<void>
11
+ link (connector: Connector): void
12
12
 
13
- disconnect(interrupt?: boolean): Promise<void>
13
+ protected open (): Promise<void> | void
14
14
 
15
- open(): Promise<void>
16
-
17
- close(): Promise<void>
18
-
19
- dispose(): Promise<void>
20
- }
15
+ protected close (): Promise<void> | void
21
16
 
17
+ protected dispose (): Promise<void> | void
22
18
  }
23
-
24
- export type Connector = toa.core.Connector
@@ -1,10 +1,4 @@
1
- declare namespace toa.core {
2
-
3
- interface Exception {
4
- code: number
5
- message: string
6
- }
7
-
1
+ export interface Exception {
2
+ code: number
3
+ message: string
8
4
  }
9
-
10
- export type Exception = toa.core.Exception
@@ -7,21 +7,21 @@ import * as _bindings from './bindings'
7
7
  declare namespace toa.core.extensions {
8
8
 
9
9
  interface Factory {
10
- tenant?(locator: _core.Locator, declaration: object): _core.Connector
10
+ tenant? (locator: _core.Locator, manifest: object): _core.Connector
11
11
 
12
- aspect?(locator: _core.Locator, declaration: object): Aspect | Aspect[]
12
+ aspect? (locator: _core.Locator, manifest: object | null): Aspect | Aspect[]
13
13
 
14
- service?(name?: string): _core.Connector
14
+ service? (name?: string): _core.Connector | null
15
15
 
16
- component?(component: _component.Component): _component.Component
16
+ component? (component: _component.Component): _component.Component
17
17
 
18
- context?(context: _context.Context): _context.Context
18
+ context? (context: _context.Context): _context.Context
19
19
 
20
- storage?(storage: _storages.Storage): _storages.Storage
20
+ storage? (storage: _storages.Storage): _storages.Storage
21
21
 
22
- emitter?(emitter: _bindings.Emitter, label: string): _bindings.Emitter
22
+ emitter? (emitter: _bindings.Emitter, label: string): _bindings.Emitter
23
23
 
24
- receiver?(receiver: _core.Receiver, locator: _core.Locator): _core.Receiver
24
+ receiver? (receiver: _core.Receiver, locator: _core.Locator): _core.Receiver
25
25
  }
26
26
 
27
27
  interface Aspect extends _core.Connector {
package/types/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * as bindings from './bindings'
2
2
  export * as extensions from './extensions'
3
3
  export * as storages from './storages'
4
4
  export * as bridges from './bridges'
5
+ export * as operations from './operations'
5
6
 
6
7
  export { Component } from './component'
7
8
  export { Connector } from './connector'
@@ -10,5 +11,4 @@ export { Exception } from './exception'
10
11
  export { Locator } from './locator'
11
12
  export { Receiver } from './receiver'
12
13
  export { Message } from './message'
13
- export { Reply } from './reply'
14
- export { Request, Query } from './request'
14
+ export { Request, Query, Reply } from './request'
@@ -1,16 +1,12 @@
1
- declare namespace toa.core {
1
+ export class Locator {
2
+ public readonly name: string
3
+ public readonly namespace: string
2
4
 
3
- interface Locator {
4
- name: string
5
- namespace: string
5
+ public readonly id: string
6
+ public readonly label: string
7
+ public readonly uppercase: string
6
8
 
7
- id: string
8
- label: string
9
- uppercase: string
10
-
11
- hostname(type?: string): string
12
- }
9
+ constructor (name: string, namespace?: string)
13
10
 
11
+ hostname (type?: string): string
14
12
  }
15
-
16
- export type Locator = toa.core.Locator
@@ -0,0 +1,2 @@
1
+ export type type = 'transition' | 'observation' | 'assignment' | 'computation' | 'effect'
2
+ export type scope = 'object' | 'objects' | 'changeset'
@@ -1,16 +1,14 @@
1
- // noinspection ES6UnusedImports
2
-
3
- import { Connector } from './connector'
1
+ import * as _core from './connector'
4
2
 
5
3
  declare namespace toa.core {
6
4
 
7
- namespace reflection {
8
- type Source = () => Promise<any>
9
- }
5
+ namespace reflection {
6
+ type Source = () => Promise<any>
7
+ }
10
8
 
11
- interface Reflection<T> extends Connector {
12
- value: T
13
- }
9
+ interface Reflection<T> extends _core.Connector {
10
+ value: T
11
+ }
14
12
  }
15
13
 
16
14
  export type Source = toa.core.reflection.Source
@@ -1,25 +1,23 @@
1
- declare namespace toa.core {
1
+ import { Exception } from './exception'
2
2
 
3
- namespace request {
4
-
5
- interface Query {
6
- id?: string
7
- criteria?: string
8
- omit?: number
9
- limit?: number
10
- sort?: Array<string>
11
- projection?: Array<string>
12
- version?: number
13
- }
14
-
15
- }
16
-
17
- type Request = {
18
- input?: any
19
- query?: request.Query
20
- }
3
+ export interface Query {
4
+ id?: string
5
+ criteria?: string
6
+ omit?: number
7
+ limit?: number
8
+ sort?: Array<string>
9
+ projection?: Array<string>
10
+ version?: number
11
+ }
21
12
 
13
+ export interface Request {
14
+ input?: any
15
+ query?: Query
16
+ authentic?: boolean
22
17
  }
23
18
 
24
- export type Request = toa.core.Request
25
- export type Query = toa.core.request.Query
19
+ export interface Reply {
20
+ output?: any
21
+ error?: object
22
+ exception?: Exception
23
+ }
@@ -1,11 +0,0 @@
1
- 'use strict'
2
-
3
- const bridges = ['a', 'b', 'c'].map((index) => ({
4
- execute: jest.fn((request) => {
5
- if (request?.error === index) return { error: index }
6
-
7
- return { output: { [index]: true } }
8
- })
9
- }))
10
-
11
- exports.bridges = bridges
@@ -1,42 +0,0 @@
1
- 'use strict'
2
-
3
- jest.mock('../src/connector')
4
-
5
- const clone = require('clone-deep')
6
-
7
- const { Connector } = require('../src/connector')
8
- const { Cascade } = require('../src/cascade')
9
- const fixtures = require('./cascade.fixtures')
10
-
11
- let cascade
12
-
13
- beforeEach(() => {
14
- jest.clearAllMocks()
15
-
16
- cascade = new Cascade(clone(fixtures.bridges))
17
- })
18
-
19
- it('should depend on bridges', () => {
20
- expect(cascade).toBeInstanceOf(Connector)
21
- expect(Connector.mock.instances[0].depends).toHaveBeenCalledWith(fixtures.bridges)
22
- })
23
-
24
- it('should call bridges.execute', async () => {
25
- const args = [1, 2]
26
- await cascade.run(...args)
27
-
28
- for (const bridge of fixtures.bridges) expect(bridge.execute).toHaveBeenCalledWith(...args)
29
- })
30
-
31
- it('should merge output', async () => {
32
- const reply = await cascade.run()
33
-
34
- expect(reply).toStrictEqual({ output: { a: true, b: true, c: true } })
35
- })
36
-
37
- it('should interrupt on error', async () => {
38
- const reply = await cascade.run({ error: 'b' })
39
-
40
- expect(reply).toStrictEqual({ error: 'b' })
41
- expect(fixtures.bridges[2].execute).not.toHaveBeenCalled()
42
- })
@@ -1,16 +0,0 @@
1
- import * as _connector from './connector'
2
- import * as _locator from './locator'
3
- import * as _request from './request'
4
- import * as _reply from './reply'
5
-
6
- declare namespace toa.core {
7
-
8
- interface Component extends _connector.Connector {
9
- locator: _locator.Locator
10
-
11
- invoke(endpoint: string, request: _request.Request): Promise<_reply.Reply>
12
- }
13
-
14
- }
15
-
16
- export type Component = toa.core.Component
package/types/reply.d.ts DELETED
@@ -1,15 +0,0 @@
1
- // noinspection ES6UnusedImports
2
-
3
- import { Exception } from './exception'
4
-
5
- declare namespace toa.core {
6
-
7
- interface Reply {
8
- output?: Object
9
- error?: Object
10
- exception?: Exception
11
- }
12
-
13
- }
14
-
15
- export type Reply = toa.core.Reply