@toa.io/norm 0.24.0-alpha.17 → 0.24.0-alpha.19

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/norm",
3
- "version": "0.24.0-alpha.17",
3
+ "version": "0.24.0-alpha.19",
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.0-alpha.17",
24
- "@toa.io/generic": "0.24.0-alpha.17",
25
- "@toa.io/schema": "0.24.0-alpha.17",
26
- "@toa.io/schemas": "0.24.0-alpha.17",
27
- "@toa.io/yaml": "0.24.0-alpha.17"
23
+ "@toa.io/core": "0.24.0-alpha.19",
24
+ "@toa.io/generic": "0.24.0-alpha.19",
25
+ "@toa.io/schema": "0.24.0-alpha.19",
26
+ "@toa.io/schemas": "0.24.0-alpha.19",
27
+ "@toa.io/yaml": "0.24.0-alpha.19"
28
28
  },
29
- "gitHead": "6eddd2ce5172a38c0ae9c41017f23a28398cf839"
29
+ "gitHead": "5e251e2f9ec49448c0a038d7aa07b01ba2b8d065"
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 (manifest.entity === undefined) return
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
 
@@ -8,9 +8,13 @@ const defaults = (manifest) => {
8
8
  if (manifest.name === undefined) manifest.name = protoName(manifest)
9
9
  if (manifest.bindings === undefined) manifest.bindings = ['@toa.io/bindings.amqp']
10
10
  if (manifest.bridge === undefined) manifest.bridge = '@toa.io/bridges.node'
11
- if (manifest.entity === null || manifest.entity === undefined) manifest.entity = { storage: null }
12
- if (manifest.entity.storage === undefined) manifest.entity.storage = '@toa.io/storages.mongodb'
13
- if (manifest.entity.storage === null) manifest.entity.storage = '@toa.io/storages.null'
11
+
12
+ if ('entity' in manifest) {
13
+ if (manifest.entity.storage === null) manifest.entity.storage = '@toa.io/storages.null'
14
+
15
+ // moved to schema
16
+ // if (manifest.entity.storage === undefined) manifest.entity.storage = '@toa.io/storages.mongodb'
17
+ }
14
18
 
15
19
  // TODO: bridge.version()
16
20
  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 property = resolve(manifest.entity.schema.properties)
7
+ const resolver = createResolver(manifest.entity?.schema?.properties)
8
8
 
9
- schema(manifest.entity.schema, property)
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, property)
13
- if (operation.output !== undefined) operation.output = schema(operation.output, property)
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) => {
@@ -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: 'definitions#/definitions/name'
26
+ $ref: '#/definitions/name'
24
27
  patternProperties:
25
28
  '.*':
26
29
  type: object
@@ -63,6 +66,7 @@ properties:
63
66
  properties:
64
67
  storage:
65
68
  type: string
69
+ default: '@toa.io/storages.mongodb'
66
70
  schema:
67
71
  $ref: 'definitions#/definitions/schema'
68
72
  type: object
@@ -74,9 +78,12 @@ properties:
74
78
  type: object
75
79
  propertyNames:
76
80
  oneOf:
77
- - $ref: 'definitions#/definitions/name'
81
+ - $ref: '#/definitions/name'
78
82
  - enum: [_version]
79
- initialized:
83
+ dependent:
84
+ type: boolean
85
+ default: false
86
+ custom:
80
87
  type: boolean
81
88
  default: false
82
89
  required: [schema]
@@ -94,7 +101,7 @@ properties:
94
101
  operations:
95
102
  type: object
96
103
  propertyNames:
97
- $ref: 'definitions#/definitions/name'
104
+ $ref: '#/definitions/name'
98
105
  patternProperties:
99
106
  '.*':
100
107
  type: object
@@ -106,7 +113,7 @@ properties:
106
113
  concurrency:
107
114
  enum: [none, retry]
108
115
  forward:
109
- $ref: 'definitions#/definitions/name'
116
+ $ref: '#/definitions/name'
110
117
  bridge:
111
118
  type: string
112
119
  bindings:
package/src/component.js CHANGED
@@ -50,7 +50,7 @@ const load = async (path, base) => {
50
50
  }
51
51
 
52
52
  dereference(manifest)
53
- dependencies(manifest)
53
+ // dependencies(manifest)
54
54
 
55
55
  return manifest
56
56
  }
@@ -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('initialized', () => {
120
+ describe('dependent', () => {
121
121
  it('should provide default', () => {
122
122
  expect(() => validate(manifest)).not.toThrow()
123
- expect(manifest.entity.initialized).toBe(false)
123
+ expect(manifest.entity.dependent).toBe(false)
124
124
  })
125
125
  })
126
126
  })
@@ -18,8 +18,7 @@ const component = (id) => {
18
18
  name,
19
19
  id,
20
20
  label: `${namespace}-${name}`
21
- },
22
- entity: null
21
+ }
23
22
  }
24
23
  }
25
24
 
@@ -39,7 +39,7 @@ type Receiver = {
39
39
  type Entity = {
40
40
  schema: Object
41
41
  storage?: string
42
- initialized?: boolean
42
+ dependent?: boolean
43
43
  }
44
44
 
45
45
  type Declaration = {