@toa.io/norm 0.24.0-alpha.9 → 1.0.0-alpha.2
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 +7 -7
- package/src/.component/.expand/entity.js +1 -1
- package/src/.component/collapse.js +6 -2
- package/src/.component/defaults.js +10 -4
- package/src/.component/dereference.js +19 -11
- package/src/.component/merge.js +7 -1
- package/src/.component/schema.yaml +18 -5
- package/src/.context/.dependencies/connectors.js +6 -4
- package/src/.context/schema.yaml +2 -0
- package/src/component.js +1 -1
- package/src/shortcuts.js +1 -0
- package/test/component/collapse.test.js +0 -13
- package/test/component/validate.test.js +2 -2
- package/test/context/dereference.fixtures.js +1 -2
- package/types/component.d.ts +3 -5
- package/types/context.d.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/norm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-alpha.2",
|
|
4
4
|
"description": "Toa declarations normalization and validation",
|
|
5
5
|
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/toa-io/toa#readme",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@toa.io/core": "0.
|
|
24
|
-
"@toa.io/generic": "0.
|
|
25
|
-
"@toa.io/schema": "0.
|
|
26
|
-
"@toa.io/schemas": "0.
|
|
27
|
-
"@toa.io/yaml": "0.
|
|
23
|
+
"@toa.io/core": "1.0.0-alpha.2",
|
|
24
|
+
"@toa.io/generic": "1.0.0-alpha.2",
|
|
25
|
+
"@toa.io/schema": "1.0.0-alpha.2",
|
|
26
|
+
"@toa.io/schemas": "1.0.0-alpha.2",
|
|
27
|
+
"@toa.io/yaml": "1.0.0-alpha.2"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "7688e6e980a65c82ac2e459be4e355eebf406cd0"
|
|
30
30
|
}
|
|
@@ -5,7 +5,7 @@ const { expand } = require('@toa.io/schemas')
|
|
|
5
5
|
const { resolve } = require('../../shortcuts')
|
|
6
6
|
|
|
7
7
|
function entity (manifest) {
|
|
8
|
-
if (
|
|
8
|
+
if (!('entity' in manifest)) return
|
|
9
9
|
if ('schema' in manifest.entity) manifest.entity.schema = expand(manifest.entity.schema)
|
|
10
10
|
|
|
11
11
|
manifest.entity.storage = resolve(manifest.entity.storage)
|
|
@@ -34,10 +34,14 @@ const collapse = (manifest, prototype) => {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
delete prototype.entity?.storage // ???
|
|
38
|
-
|
|
39
37
|
const { entity, events, extensions } = prototype
|
|
40
38
|
|
|
39
|
+
if (manifest.entity?.schema?.properties.id !== undefined && entity?.schema?.properties.id !== undefined) {
|
|
40
|
+
manifest.entity.custom = true
|
|
41
|
+
|
|
42
|
+
delete prototype.entity.schema.properties.id
|
|
43
|
+
}
|
|
44
|
+
|
|
41
45
|
merge(manifest, { entity, events, extensions })
|
|
42
46
|
}
|
|
43
47
|
|
|
@@ -4,13 +4,19 @@ const { hash } = require('@toa.io/generic')
|
|
|
4
4
|
|
|
5
5
|
// these defaults are required before validation
|
|
6
6
|
const defaults = (manifest) => {
|
|
7
|
-
if (manifest.prototype === undefined) manifest.prototype = '@toa.io/prototype'
|
|
8
7
|
if (manifest.name === undefined) manifest.name = protoName(manifest)
|
|
9
8
|
if (manifest.bindings === undefined) manifest.bindings = ['@toa.io/bindings.amqp']
|
|
10
9
|
if (manifest.bridge === undefined) manifest.bridge = '@toa.io/bridges.node'
|
|
11
|
-
|
|
12
|
-
if (
|
|
13
|
-
|
|
10
|
+
|
|
11
|
+
if ('entity' in manifest) {
|
|
12
|
+
if (manifest.entity.storage === null)
|
|
13
|
+
manifest.entity.storage = '@toa.io/storages.null'
|
|
14
|
+
} else {
|
|
15
|
+
if (manifest.prototype === undefined)
|
|
16
|
+
manifest.prototype = null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (manifest.prototype === undefined) manifest.prototype = '@toa.io/prototype'
|
|
14
20
|
|
|
15
21
|
// TODO: bridge.version()
|
|
16
22
|
if (manifest.version === undefined) manifest.version = '0.0.0'
|
|
@@ -4,13 +4,28 @@ const { merge } = require('@toa.io/generic')
|
|
|
4
4
|
|
|
5
5
|
const dereference = (manifest) => {
|
|
6
6
|
// schemas
|
|
7
|
-
const
|
|
7
|
+
const resolver = createResolver(manifest.entity?.schema?.properties)
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
if (manifest.entity !== undefined)
|
|
10
|
+
schema(manifest.entity.schema, resolver)
|
|
10
11
|
|
|
12
|
+
if ('operations' in manifest)
|
|
13
|
+
operations(manifest, resolver)
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const createResolver = (properties) => (property) => {
|
|
18
|
+
if (properties?.[property] === undefined) {
|
|
19
|
+
throw new Error(`Referenced property '${property}' is not defined`)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return properties[property]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function operations (manifest, resolver) {
|
|
11
26
|
for (const operation of Object.values(manifest.operations)) {
|
|
12
|
-
if (operation.input !== undefined) operation.input = schema(operation.input,
|
|
13
|
-
if (operation.output !== undefined) operation.output = schema(operation.output,
|
|
27
|
+
if (operation.input !== undefined) operation.input = schema(operation.input, resolver)
|
|
28
|
+
if (operation.output !== undefined) operation.output = schema(operation.output, resolver)
|
|
14
29
|
}
|
|
15
30
|
|
|
16
31
|
// forwarding
|
|
@@ -21,14 +36,7 @@ const dereference = (manifest) => {
|
|
|
21
36
|
for (const operation of Object.values(manifest.operations)) {
|
|
22
37
|
delete operation.forwarded
|
|
23
38
|
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const resolve = (schema) => (property) => {
|
|
27
|
-
if (schema[property] === undefined) {
|
|
28
|
-
throw new Error(`Referenced property '${property}' is not defined`)
|
|
29
|
-
}
|
|
30
39
|
|
|
31
|
-
return schema[property]
|
|
32
40
|
}
|
|
33
41
|
|
|
34
42
|
const schema = (object, resolve) => {
|
package/src/.component/merge.js
CHANGED
|
@@ -28,6 +28,10 @@ const define = async (root, manifest, property) => {
|
|
|
28
28
|
|
|
29
29
|
// default bridge
|
|
30
30
|
const definition = await scan(manifest.bridge, root, property)
|
|
31
|
+
|
|
32
|
+
if (definition === undefined)
|
|
33
|
+
return
|
|
34
|
+
|
|
31
35
|
const items = Object.entries(definition)
|
|
32
36
|
|
|
33
37
|
if (items.length) {
|
|
@@ -49,7 +53,9 @@ const define = async (root, manifest, property) => {
|
|
|
49
53
|
const scan = async (bridge, root, property) => {
|
|
50
54
|
const { define } = require(bridge)
|
|
51
55
|
|
|
52
|
-
|
|
56
|
+
if (property in define)
|
|
57
|
+
return define[property](root)
|
|
58
|
+
else return undefined
|
|
53
59
|
}
|
|
54
60
|
|
|
55
61
|
exports.merge = bridge
|
|
@@ -2,6 +2,9 @@ $schema: https://json-schema.org/draft/2019-09/schema
|
|
|
2
2
|
$id: https://schemas.toa.io/0.0.0/manifest
|
|
3
3
|
|
|
4
4
|
definitions:
|
|
5
|
+
name:
|
|
6
|
+
type: string
|
|
7
|
+
pattern: ^[a-zA-Z]+([_a-zA-Z0-9]*[a-zA-Z0-9]+)?$
|
|
5
8
|
binding:
|
|
6
9
|
type: string
|
|
7
10
|
not:
|
|
@@ -20,7 +23,7 @@ properties:
|
|
|
20
23
|
operations:
|
|
21
24
|
type: object
|
|
22
25
|
propertyNames:
|
|
23
|
-
$ref: '
|
|
26
|
+
$ref: '#/definitions/name'
|
|
24
27
|
patternProperties:
|
|
25
28
|
'.*':
|
|
26
29
|
type: object
|
|
@@ -52,11 +55,18 @@ properties:
|
|
|
52
55
|
version:
|
|
53
56
|
$ref: 'definitions#/definitions/version'
|
|
54
57
|
|
|
58
|
+
build:
|
|
59
|
+
type: object
|
|
60
|
+
properties:
|
|
61
|
+
image:
|
|
62
|
+
type: string
|
|
63
|
+
|
|
55
64
|
entity:
|
|
56
65
|
type: object
|
|
57
66
|
properties:
|
|
58
67
|
storage:
|
|
59
68
|
type: string
|
|
69
|
+
default: '@toa.io/storages.mongodb'
|
|
60
70
|
schema:
|
|
61
71
|
$ref: 'definitions#/definitions/schema'
|
|
62
72
|
type: object
|
|
@@ -68,9 +78,12 @@ properties:
|
|
|
68
78
|
type: object
|
|
69
79
|
propertyNames:
|
|
70
80
|
oneOf:
|
|
71
|
-
- $ref: '
|
|
81
|
+
- $ref: '#/definitions/name'
|
|
72
82
|
- enum: [_version]
|
|
73
|
-
|
|
83
|
+
dependent:
|
|
84
|
+
type: boolean
|
|
85
|
+
default: false
|
|
86
|
+
custom:
|
|
74
87
|
type: boolean
|
|
75
88
|
default: false
|
|
76
89
|
required: [schema]
|
|
@@ -88,7 +101,7 @@ properties:
|
|
|
88
101
|
operations:
|
|
89
102
|
type: object
|
|
90
103
|
propertyNames:
|
|
91
|
-
$ref: '
|
|
104
|
+
$ref: '#/definitions/name'
|
|
92
105
|
patternProperties:
|
|
93
106
|
'.*':
|
|
94
107
|
type: object
|
|
@@ -100,7 +113,7 @@ properties:
|
|
|
100
113
|
concurrency:
|
|
101
114
|
enum: [none, retry]
|
|
102
115
|
forward:
|
|
103
|
-
$ref: '
|
|
116
|
+
$ref: '#/definitions/name'
|
|
104
117
|
bridge:
|
|
105
118
|
type: string
|
|
106
119
|
bindings:
|
|
@@ -9,11 +9,13 @@ const connectors = (context, extracted) => {
|
|
|
9
9
|
) ?? []
|
|
10
10
|
|
|
11
11
|
for (const component of components) {
|
|
12
|
-
if (
|
|
13
|
-
connectors[component.entity.storage]
|
|
14
|
-
|
|
12
|
+
if (component.entity !== undefined) {
|
|
13
|
+
if (connectors[component.entity.storage] === undefined) {
|
|
14
|
+
connectors[component.entity.storage] = []
|
|
15
|
+
}
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
connectors[component.entity.storage].push(component)
|
|
18
|
+
}
|
|
17
19
|
|
|
18
20
|
const bindings = new Set()
|
|
19
21
|
|
package/src/.context/schema.yaml
CHANGED
package/src/component.js
CHANGED
package/src/shortcuts.js
CHANGED
|
@@ -41,6 +41,7 @@ const recognize = (shortcuts, object, group) => {
|
|
|
41
41
|
const SHORTCUTS = {
|
|
42
42
|
amqp: '@toa.io/bindings.amqp',
|
|
43
43
|
node: '@toa.io/bridges.node',
|
|
44
|
+
bash: '@toa.io/bridges.bash',
|
|
44
45
|
mongodb: '@toa.io/storages.mongodb',
|
|
45
46
|
sql: '@toa.io/storages.sql',
|
|
46
47
|
queues: '@toa.io/storages.queues',
|
|
@@ -30,19 +30,6 @@ it('should remove prototype property', () => {
|
|
|
30
30
|
})
|
|
31
31
|
|
|
32
32
|
describe('entity', () => {
|
|
33
|
-
it('should ignore storage', () => {
|
|
34
|
-
const source = { entity: { storage: 'foo' } }
|
|
35
|
-
const prototype = { entity: { storage: 'bar' } }
|
|
36
|
-
const manifest = clone(source)
|
|
37
|
-
|
|
38
|
-
collapse(manifest, prototype)
|
|
39
|
-
expect(manifest).toStrictEqual(source)
|
|
40
|
-
|
|
41
|
-
delete manifest.entity.storage
|
|
42
|
-
collapse(manifest, prototype)
|
|
43
|
-
expect(manifest).toStrictEqual({ entity: {} })
|
|
44
|
-
})
|
|
45
|
-
|
|
46
33
|
it('should merge entity schema', () => {
|
|
47
34
|
const manifest = clone(samples.entity.manifest)
|
|
48
35
|
|
|
@@ -117,10 +117,10 @@ describe('entity', () => {
|
|
|
117
117
|
})
|
|
118
118
|
})
|
|
119
119
|
|
|
120
|
-
describe('
|
|
120
|
+
describe('dependent', () => {
|
|
121
121
|
it('should provide default', () => {
|
|
122
122
|
expect(() => validate(manifest)).not.toThrow()
|
|
123
|
-
expect(manifest.entity.
|
|
123
|
+
expect(manifest.entity.dependent).toBe(false)
|
|
124
124
|
})
|
|
125
125
|
})
|
|
126
126
|
})
|
package/types/component.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ type Map = {
|
|
|
4
4
|
[id: string]: Component
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
type Operation = {
|
|
7
|
+
export type Operation = {
|
|
8
8
|
type: operations.type
|
|
9
9
|
scope?: operations.scope
|
|
10
10
|
bindings?: string[]
|
|
@@ -14,9 +14,7 @@ type Operation = {
|
|
|
14
14
|
query?: boolean
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
type Operations =
|
|
18
|
-
[key: string]: Operation
|
|
19
|
-
}
|
|
17
|
+
export type Operations = Record<string, Operation>
|
|
20
18
|
|
|
21
19
|
type Event = {
|
|
22
20
|
binding: string
|
|
@@ -39,7 +37,7 @@ type Receiver = {
|
|
|
39
37
|
type Entity = {
|
|
40
38
|
schema: Object
|
|
41
39
|
storage?: string
|
|
42
|
-
|
|
40
|
+
dependent?: boolean
|
|
43
41
|
}
|
|
44
42
|
|
|
45
43
|
type Declaration = {
|
package/types/context.d.ts
CHANGED