@toa.io/core 0.20.0-dev.2 → 0.20.0-dev.20
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 +6 -5
- package/src/call.js +13 -3
- package/src/contract/request.js +1 -1
- package/src/observation.js +5 -0
- package/src/operation.js +10 -5
- package/src/state.js +2 -2
- package/src/transition.js +4 -1
- package/test/call.test.js +2 -2
- package/test/contract/contract.fixtures.js +2 -1
- package/types/connector.d.ts +10 -16
- package/types/extensions.d.ts +8 -8
- package/types/index.d.ts +1 -0
- package/types/locator.d.ts +8 -12
- package/types/request.d.ts +1 -0
- /package/types/{component.ts → component.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/core",
|
|
3
|
-
"version": "0.20.0-dev.
|
|
3
|
+
"version": "0.20.0-dev.20",
|
|
4
4
|
"description": "Toa Core",
|
|
5
5
|
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/toa-io/toa#readme",
|
|
@@ -12,6 +12,7 @@
|
|
|
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
|
},
|
|
@@ -20,10 +21,10 @@
|
|
|
20
21
|
},
|
|
21
22
|
"dependencies": {
|
|
22
23
|
"@rsql/parser": "1.2.4",
|
|
23
|
-
"@toa.io/console": "0.20.0-dev.
|
|
24
|
-
"@toa.io/generic": "0.20.0-dev.
|
|
25
|
-
"@toa.io/yaml": "0.20.0-dev.
|
|
24
|
+
"@toa.io/console": "0.20.0-dev.20",
|
|
25
|
+
"@toa.io/generic": "0.20.0-dev.20",
|
|
26
|
+
"@toa.io/yaml": "0.20.0-dev.20",
|
|
26
27
|
"clone-deep": "4.0.1"
|
|
27
28
|
},
|
|
28
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "52c962bc17b71f3e7890ec53870f8b93fda720a0"
|
|
29
30
|
}
|
package/src/call.js
CHANGED
|
@@ -15,14 +15,24 @@ 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
|
|
|
21
|
-
|
|
24
|
+
request.authentic = true
|
|
22
25
|
|
|
23
|
-
|
|
26
|
+
const reply = await this.#transmitter.request(request)
|
|
24
27
|
|
|
25
|
-
return
|
|
28
|
+
if (reply === null) return null
|
|
29
|
+
else {
|
|
30
|
+
const { exception, ...rest } = reply
|
|
31
|
+
|
|
32
|
+
if (exception !== undefined) throw exception
|
|
33
|
+
|
|
34
|
+
return rest
|
|
35
|
+
}
|
|
26
36
|
}
|
|
27
37
|
}
|
|
28
38
|
|
package/src/contract/request.js
CHANGED
|
@@ -13,7 +13,7 @@ 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) {
|
package/src/observation.js
CHANGED
package/src/operation.js
CHANGED
|
@@ -7,26 +7,31 @@ class Operation extends Connector {
|
|
|
7
7
|
scope
|
|
8
8
|
|
|
9
9
|
#cascade
|
|
10
|
-
#
|
|
10
|
+
#contracts
|
|
11
11
|
#query
|
|
12
12
|
#scope
|
|
13
13
|
|
|
14
|
-
constructor (cascade, scope,
|
|
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.#
|
|
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.
|
|
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.#
|
|
60
|
+
this.#contracts.reply.fit(reply)
|
|
56
61
|
|
|
57
62
|
store.reply = reply
|
|
58
63
|
}
|
package/src/state.js
CHANGED
|
@@ -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
|
-
|
|
46
|
+
if (record === null) return null
|
|
47
|
+
else return this.#entity.object(record)
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
async objects (query) {
|
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
|
|
package/test/call.test.js
CHANGED
|
@@ -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
|
}
|
package/types/connector.d.ts
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
export class Connector {
|
|
2
|
+
public id: string
|
|
3
|
+
public connected: boolean
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
id: string
|
|
5
|
-
connected: boolean
|
|
5
|
+
public connect (): Promise<void>
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
public disconnect (interrupt?: boolean): Promise<void>
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
protected depends (connector: Connector | Connector[]): Connector
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
link (connector: Connector): void
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
protected open (): Promise<void>
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
close(): Promise<void>
|
|
18
|
-
|
|
19
|
-
dispose(): Promise<void>
|
|
20
|
-
}
|
|
15
|
+
protected close (): Promise<void>
|
|
21
16
|
|
|
17
|
+
protected dispose (): Promise<void>
|
|
22
18
|
}
|
|
23
|
-
|
|
24
|
-
export type Connector = toa.core.Connector
|
package/types/extensions.d.ts
CHANGED
|
@@ -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, declaration: object): _core.Connector
|
|
11
11
|
|
|
12
|
-
aspect?(locator: _core.Locator, declaration: object): Aspect | Aspect[]
|
|
12
|
+
aspect? (locator: _core.Locator, declaration: object): 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'
|
package/types/locator.d.ts
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
export class Locator {
|
|
2
|
+
public readonly name: string
|
|
3
|
+
public readonly namespace: string
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
public readonly id: string
|
|
6
|
+
public readonly label: string
|
|
7
|
+
public readonly uppercase: string
|
|
6
8
|
|
|
7
|
-
|
|
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
|
package/types/request.d.ts
CHANGED
|
File without changes
|