@toa.io/norm 0.20.0-dev.3 → 0.20.0-dev.30

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.20.0-dev.3",
3
+ "version": "0.20.0-dev.30",
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",
@@ -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
  },
@@ -19,11 +20,11 @@
19
20
  "test": "echo \"Error: run tests from root\" && exit 1"
20
21
  },
21
22
  "dependencies": {
22
- "@toa.io/core": "0.20.0-dev.3",
23
- "@toa.io/generic": "0.20.0-dev.3",
24
- "@toa.io/schema": "0.20.0-dev.3",
25
- "@toa.io/schemas": "0.20.0-dev.3",
26
- "@toa.io/yaml": "0.20.0-dev.3"
23
+ "@toa.io/core": "0.20.0-dev.30",
24
+ "@toa.io/generic": "0.20.0-dev.30",
25
+ "@toa.io/schema": "0.20.0-dev.30",
26
+ "@toa.io/schemas": "0.20.0-dev.30",
27
+ "@toa.io/yaml": "0.20.0-dev.30"
27
28
  },
28
- "gitHead": "3eabf45761f4cf211e1e4c331933ec60b4a828a7"
29
+ "gitHead": "61c8e74a336385265767e9fd37d49128cb51b17f"
29
30
  }
@@ -10,7 +10,9 @@ function extensions (manifest) {
10
10
  const SHORTCUTS = {
11
11
  exposition: '@toa.io/extensions.exposition',
12
12
  origins: '@toa.io/extensions.origins',
13
- configuration: '@toa.io/extensions.configuration'
13
+ configuration: '@toa.io/extensions.configuration',
14
+ state: '@toa.io/extensions.state',
15
+ stash: '@toa.io/extensions.stash'
14
16
  }
15
17
 
16
18
  exports.extensions = extensions
@@ -1,11 +1,13 @@
1
1
  'use strict'
2
2
 
3
+ const { hash } = require('@toa.io/generic')
4
+
3
5
  // these defaults are required before validation
4
6
  const defaults = (manifest) => {
5
7
  if (manifest.prototype === undefined) manifest.prototype = '@toa.io/prototype'
8
+ if (manifest.name === undefined) manifest.name = protoName(manifest)
6
9
  if (manifest.bindings === undefined) manifest.bindings = ['@toa.io/bindings.amqp']
7
10
  if (manifest.bridge === undefined) manifest.bridge = '@toa.io/bridges.node'
8
-
9
11
  if (manifest.entity === null || manifest.entity === undefined) manifest.entity = { storage: null }
10
12
  if (manifest.entity.storage === undefined) manifest.entity.storage = '@toa.io/storages.mongodb'
11
13
  if (manifest.entity.storage === null) manifest.entity.storage = '@toa.io/storages.null'
@@ -14,4 +16,8 @@ const defaults = (manifest) => {
14
16
  if (manifest.version === undefined) manifest.version = '0.0.0'
15
17
  }
16
18
 
19
+ function protoName (manifest) {
20
+ return 'proto' + hash(manifest.path)
21
+ }
22
+
17
23
  exports.defaults = defaults
@@ -1,10 +1,8 @@
1
1
  'use strict'
2
2
 
3
- const { convolve } = require('@toa.io/generic')
4
3
  const { events, operations, extensions, receivers } = require('./.normalize')
5
4
 
6
5
  const normalize = (component, environment) => {
7
- convolve(component, environment)
8
6
  operations(component)
9
7
  events(component)
10
8
  receivers(component)
@@ -20,7 +20,7 @@ properties:
20
20
  operations:
21
21
  type: object
22
22
  propertyNames:
23
- $ref: 'definitions#/definitions/token'
23
+ $ref: 'definitions#/definitions/name'
24
24
  patternProperties:
25
25
  '.*':
26
26
  type: object
@@ -39,14 +39,15 @@ properties:
39
39
  label:
40
40
  $ref: 'definitions#/definitions/label'
41
41
 
42
+ name:
43
+ $ref: 'definitions#/definitions/token'
44
+
42
45
  namespace:
43
46
  $ref: 'definitions#/definitions/token'
44
47
  default: 'default'
45
48
  not:
46
49
  oneOf:
47
50
  - const: 'system'
48
- name:
49
- $ref: 'definitions#/definitions/token'
50
51
 
51
52
  version:
52
53
  $ref: 'definitions#/definitions/version'
@@ -67,12 +68,12 @@ properties:
67
68
  type: object
68
69
  propertyNames:
69
70
  oneOf:
70
- - $ref: 'definitions#/definitions/token'
71
- - enum: [ _version ]
71
+ - $ref: 'definitions#/definitions/name'
72
+ - enum: [_version]
72
73
  initialized:
73
74
  type: boolean
74
75
  default: false
75
- required: [ schema ]
76
+ required: [schema]
76
77
  additionalProperties: false
77
78
 
78
79
  bindings:
@@ -88,19 +89,19 @@ properties:
88
89
  operations:
89
90
  type: object
90
91
  propertyNames:
91
- $ref: 'definitions#/definitions/token'
92
+ $ref: 'definitions#/definitions/name'
92
93
  patternProperties:
93
94
  '.*':
94
95
  type: object
95
96
  properties:
96
97
  type:
97
- enum: [ transition, observation, assignment, computation, effect ]
98
+ enum: [transition, observation, assignment, computation, effect]
98
99
  scope:
99
- enum: [ object, objects, changeset, none ]
100
+ enum: [object, objects, changeset, none]
100
101
  concurrency:
101
- enum: [ none, retry ]
102
+ enum: [none, retry]
102
103
  forward:
103
- $ref: 'definitions#/definitions/token'
104
+ $ref: 'definitions#/definitions/name'
104
105
  bridge:
105
106
  type: string
106
107
  bindings:
@@ -111,7 +112,7 @@ properties:
111
112
  $ref: 'definitions#/definitions/schema'
112
113
  query:
113
114
  type: boolean
114
- required: [ type, scope, bindings ]
115
+ required: [type, scope, bindings]
115
116
  allOf:
116
117
  - if: # transition
117
118
  properties:
@@ -120,15 +121,15 @@ properties:
120
121
  then:
121
122
  properties:
122
123
  scope:
123
- enum: [ object ]
124
+ enum: [object]
124
125
  if: # transition query: false
125
126
  not:
126
127
  properties:
127
128
  query:
128
129
  const: false
129
- required: [ query ]
130
+ required: [query]
130
131
  then:
131
- required: [ concurrency ]
132
+ required: [concurrency]
132
133
  - if: # not transition
133
134
  not:
134
135
  properties:
@@ -145,7 +146,7 @@ properties:
145
146
  then:
146
147
  properties:
147
148
  scope:
148
- enum: [ object, objects, none ]
149
+ enum: [object, objects, none]
149
150
  query:
150
151
  not:
151
152
  const: false
@@ -156,7 +157,7 @@ properties:
156
157
  then:
157
158
  properties:
158
159
  scope:
159
- enum: [ changeset ]
160
+ enum: [changeset]
160
161
  - if: # computation
161
162
  properties:
162
163
  type:
@@ -181,7 +182,7 @@ properties:
181
182
  events:
182
183
  type: object
183
184
  propertyNames:
184
- $ref: 'definitions#/definitions/token'
185
+ $ref: 'definitions#/definitions/name'
185
186
  patternProperties:
186
187
  '.*':
187
188
  type: object
@@ -198,7 +199,7 @@ properties:
198
199
  subjective:
199
200
  type: boolean
200
201
  default: false
201
- required: [ bridge, path ]
202
+ required: [bridge, path]
202
203
  additionalProperties: false
203
204
 
204
205
  receivers:
@@ -208,13 +209,13 @@ properties:
208
209
  type: object
209
210
  properties:
210
211
  operation:
211
- $ref: 'definitions#/definitions/token'
212
+ $ref: 'definitions#/definitions/name'
212
213
  bridge:
213
214
  type: string
214
215
  binding:
215
216
  type: string
216
217
  source:
217
- $ref: 'definitions#/definitions/token'
218
+ $ref: 'definitions#/definitions/name'
218
219
  path:
219
220
  type: string
220
221
  conditioned:
@@ -223,7 +224,7 @@ properties:
223
224
  adaptive:
224
225
  type: boolean
225
226
  default: false
226
- required: [ operation ]
227
+ required: [operation]
227
228
  additionalProperties: false
228
229
 
229
230
  extensions:
package/src/component.js CHANGED
@@ -35,7 +35,7 @@ const load = async (path, base) => {
35
35
  if (base !== undefined) path = find(path, base, MANIFEST)
36
36
 
37
37
  const file = join(path, MANIFEST)
38
- const manifest = /** @type {toa.norm.Component} */ await yaml(file)
38
+ const manifest = /** @type {toa.norm.Component} */ await yaml(file) ?? {}
39
39
 
40
40
  manifest.path = path
41
41
 
package/src/context.js CHANGED
@@ -19,7 +19,7 @@ const {
19
19
  /**
20
20
  * @type {toa.norm.context.Constructor}
21
21
  */
22
- const context = async (root, environment = undefined) => {
22
+ const context = async (root, environment = process.env.TOA_ENV) => {
23
23
  const path = resolve(root, CONTEXT)
24
24
  const context = /** @type {toa.norm.Context} */ await load(path)
25
25
  const pattern = resolve(root, context.packages)
package/src/shortcuts.js CHANGED
@@ -47,7 +47,8 @@ const SHORTCUTS = {
47
47
  queues: '@toa.io/storages.queues',
48
48
  exposition: '@toa.io/extensions.exposition',
49
49
  configuration: '@toa.io/extensions.configuration',
50
- origins: '@toa.io/extensions.origins'
50
+ origins: '@toa.io/extensions.origins',
51
+ stash: '@toa.io/extensions.stash'
51
52
  }
52
53
 
53
54
  exports.recognize = recognize
@@ -12,13 +12,6 @@ beforeEach(() => {
12
12
  manifest = clone(fixtures.operations)
13
13
  })
14
14
 
15
- describe('environment', () => {
16
- it('should convolve with environment argument', () => {
17
- normalize(manifest, 'local')
18
- expect(manifest.operations.add.bindings).toStrictEqual(['foo'])
19
- })
20
- })
21
-
22
15
  describe('operations', () => {
23
16
  it('should set default bindings', () => {
24
17
  normalize(manifest)
@@ -37,14 +37,14 @@ describe('namespace', () => {
37
37
  manifest.namespace = 'foo_'
38
38
  expect(() => validate(manifest)).toThrow(/must match pattern/)
39
39
 
40
- manifest.namespace = 'foo-'
40
+ manifest.namespace = 'foo_bar'
41
41
  expect(() => validate(manifest)).toThrow(/must match pattern/)
42
42
 
43
- manifest.namespace = 'foo-BAR'
44
- expect(() => validate(manifest)).not.toThrow()
43
+ manifest.namespace = 'foo-'
44
+ expect(() => validate(manifest)).toThrow(/must match pattern/)
45
45
 
46
- manifest.namespace = 'foo_bar'
47
- expect(() => validate(manifest)).not.toThrow()
46
+ manifest.namespace = 'foo-bar'
47
+ expect(() => validate(manifest)).toThrow('must match pattern')
48
48
 
49
49
  manifest.namespace = 'FooBar12'
50
50
  expect(() => validate(manifest)).not.toThrow()
@@ -230,7 +230,7 @@ describe('operations', () => {
230
230
 
231
231
  describe('receivers', () => {
232
232
  it('should throw if transition points to undefined operation', () => {
233
- manifest.receivers['foo.bar.happened'].operation = 'not-exists'
233
+ manifest.receivers['foo.bar.happened'].operation = 'notExists'
234
234
 
235
235
  expect(() => validate(manifest)).toThrow(/refers to undefined operation/)
236
236
  })
@@ -0,0 +1,17 @@
1
+ import { Composition, Registry, Runtime } from '../context'
2
+
3
+ interface Composition {
4
+ name: string,
5
+ components: string[]
6
+ }
7
+
8
+ export interface Declaration {
9
+ name: string
10
+ description?: string
11
+ version?: string
12
+ runtime?: Runtime | string
13
+ registry?: Registry | string
14
+ packages?: string
15
+ compositions?: Composition[]
16
+ annotations?: Record<string, object>
17
+ }
@@ -1,76 +1,40 @@
1
1
  import * as _component from './component'
2
2
  import { Locator } from '@toa.io/core/types'
3
+ import type { Declaration } from './context/declaration'
3
4
 
4
- declare namespace toa.norm {
5
-
6
- namespace context {
7
-
8
- interface Runtime {
9
- version: string
10
- registry?: string
11
- proxy?: string
12
- }
13
-
14
- interface Registry {
15
- base?: string
16
- platforms?: string[] | null
17
- build?: {
18
- arguments?: string[]
19
- run?: string
20
- }
21
- }
22
-
23
- interface Composition {
24
- name: string,
25
- components: string[] | _component.Component[]
26
- }
27
-
28
- namespace dependencies {
29
-
30
- type Instance = {
31
- locator: Locator
32
- manifest?: Object
33
- }
34
-
35
- type References = {
36
- [reference: string]: _component.Component[]
37
- }
38
-
39
- }
40
-
41
- interface Dependencies {
42
- [reference: string]: dependencies.Instance[]
43
- }
44
-
45
- interface Declaration {
46
- name: string
47
- description?: string
48
- version?: string
49
- runtime?: Runtime | string
50
- registry?: Registry | string
51
- packages?: string
52
- compositions?: Composition[]
53
- annotations?: Record<string, object>
54
- }
55
-
56
- type Constructor = (path: string, environment?: string) => Promise<Context>
57
- }
5
+ interface Runtime {
6
+ version: string
7
+ registry?: string
8
+ proxy?: string
9
+ }
58
10
 
59
- interface Context extends context.Declaration {
60
- runtime?: context.Runtime
61
- environment?: string
62
- registry?: context.Registry
63
- components?: _component.Component[]
64
- dependencies?: context.Dependencies
65
- }
11
+ interface Registry {
12
+ base?: string
13
+ platforms?: string[] | null
14
+ build?: {
15
+ arguments?: string[]
16
+ run?: string
17
+ },
18
+ credentials: string
19
+ }
66
20
 
21
+ interface Composition {
22
+ name: string,
23
+ components: _component.Component[]
67
24
  }
68
25
 
69
- export type Composition = toa.norm.context.Composition
70
- export type Context = toa.norm.Context
26
+ export interface Dependency {
27
+ locator: Locator
28
+ manifest?: object
29
+ }
71
30
 
72
- export namespace dependencies {
73
- export type Instance = toa.norm.context.dependencies.Instance
31
+ interface Context extends Declaration {
32
+ runtime?: Runtime
33
+ environment?: string
34
+ registry?: Registry
35
+ compositions?: Composition[]
36
+ components?: _component.Component[]
37
+ dependencies?: Record<string, Dependency[]>
74
38
  }
75
39
 
76
- export const context: toa.norm.context.Constructor
40
+ export function context (path: string, environment?: string): Promise<Context>
package/types/index.d.ts CHANGED
@@ -1,5 +1 @@
1
- export { component } from './component'
2
- export { context } from './context'
3
-
4
- export type { Composition, dependencies } from './context'
5
- export type { Component, Operation } from './component'
1
+ export * as context from './context'