@toa.io/core 0.8.1 → 0.20.0-dev.10

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",
3
+ "version": "0.20.0-dev.10",
4
4
  "description": "Toa Core",
5
5
  "author": "temich <tema.gurtovoy@gmail.com>",
6
6
  "homepage": "https://github.com/toa-io/toa#readme",
@@ -20,10 +20,10 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@rsql/parser": "1.2.4",
23
- "@toa.io/console": "0.6.0",
24
- "@toa.io/generic": "0.9.0",
25
- "@toa.io/yaml": "0.7.3",
23
+ "@toa.io/console": "0.20.0-dev.10",
24
+ "@toa.io/generic": "0.20.0-dev.10",
25
+ "@toa.io/yaml": "0.20.0-dev.10",
26
26
  "clone-deep": "4.0.1"
27
27
  },
28
- "gitHead": "a5019af0ad7b08182d0f245af3382f96a7e22d71"
28
+ "gitHead": "cd3ffb1ae1af014f13a62ef9fc8ada58d8688e4a"
29
29
  }
package/src/call.js CHANGED
@@ -15,9 +15,14 @@ class Call extends Connector {
15
15
  this.depends(transmitter)
16
16
  }
17
17
 
18
+ /**
19
+ * @param {toa.core.Request} request
20
+ */
18
21
  async invoke (request = {}) {
19
22
  this.#contract.fit(request)
20
23
 
24
+ request.authentic = true
25
+
21
26
  const { exception, ...reply } = await this.#transmitter.request(request)
22
27
 
23
28
  if (exception) throw exception
@@ -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,8 @@
1
+ type: object
1
2
  properties:
2
3
  code:
3
4
  type: integer
4
5
  minimum: 0
5
6
  message:
6
7
  type: string
7
- required: [code, message]
8
+ required: [ code, message ]
@@ -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/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
package/src/operation.js CHANGED
@@ -7,26 +7,31 @@ 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
 
24
24
  this.depends(cascade)
25
25
  }
26
26
 
27
+ /**
28
+ * @param {toa.core.Request} request
29
+ * @return {Promise<toa.core.Reply>}
30
+ */
27
31
  async invoke (request) {
28
32
  try {
29
- if (request.query) request.query = this.#query.parse(request.query)
33
+ if (request.authentic !== true) this.#contracts.request.fit(request)
34
+ if ('query' in request) request.query = this.#query.parse(request.query)
30
35
 
31
36
  const store = { request }
32
37
 
@@ -52,7 +57,7 @@ class Operation extends Connector {
52
57
  const { request, state } = store
53
58
  const reply = await this.#cascade.run(request.input, state) || {}
54
59
 
55
- this.#contract.fit(reply)
60
+ this.#contracts.reply.fit(reply)
56
61
 
57
62
  store.reply = reply
58
63
  }
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
 
@@ -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
  })
@@ -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
@@ -17,6 +17,7 @@ declare namespace toa.core {
17
17
  type Request = {
18
18
  input?: any
19
19
  query?: request.Query
20
+ authentic?: boolean
20
21
  }
21
22
 
22
23
  }