@toa.io/norm 1.0.0-alpha.26 → 1.0.0-alpha.263

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/CHANGELOG.md ADDED
@@ -0,0 +1,48 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [1.0.0-alpha.263](https://github.com/toa-io/toa/compare/v1.0.0-alpha.262...v1.0.0-alpha.263) (2026-08-29)
7
+
8
+ **Note:** Version bump only for package @toa.io/norm
9
+
10
+
11
+
12
+
13
+
14
+ # [1.0.0-alpha.262](https://github.com/toa-io/toa/compare/v1.0.0-alpha.261...v1.0.0-alpha.262) (2026-08-28)
15
+
16
+
17
+ ### Features
18
+
19
+ * **introspection:** add the introspection extension ([a07ed86](https://github.com/toa-io/toa/commit/a07ed8651404258d544f3b6d8236e58cf4da09ac))
20
+ * **operations:** let a service claim a path prefix on the host ([02677d1](https://github.com/toa-io/toa/commit/02677d17fcd4222b07c3be458d93bcc496a016a8))
21
+
22
+
23
+
24
+
25
+
26
+ # [1.0.0-alpha.259](https://github.com/toa-io/toa/compare/v1.0.0-alpha.258...v1.0.0-alpha.259) (2026-08-24)
27
+
28
+ **Note:** Version bump only for package @toa.io/norm
29
+
30
+
31
+
32
+
33
+
34
+ # [1.0.0-alpha.257](https://github.com/toa-io/toa/compare/v1.0.0-alpha.256...v1.0.0-alpha.257) (2026-08-24)
35
+
36
+ **Note:** Version bump only for package @toa.io/norm
37
+
38
+
39
+
40
+
41
+
42
+ # [1.0.0-alpha.256](https://github.com/toa-io/toa/compare/v1.0.0-alpha.255...v1.0.0-alpha.256) (2026-08-23)
43
+
44
+
45
+ ### Features
46
+
47
+ * add toa mono and discover components at components/* ([787a111](https://github.com/toa-io/toa/commit/787a111c8f83e56ebc734801c97106c585d034ea))
48
+ * deploy a single mono image with toa deploy --mono ([a7f14f9](https://github.com/toa-io/toa/commit/a7f14f9877a280e9c74d16c195028b35d74fb15a))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/norm",
3
- "version": "1.0.0-alpha.26",
3
+ "version": "1.0.0-alpha.263",
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,10 @@
20
20
  "test": "echo \"Error: run tests from root\" && exit 1"
21
21
  },
22
22
  "dependencies": {
23
- "@toa.io/core": "1.0.0-alpha.26",
24
- "@toa.io/generic": "1.0.0-alpha.26",
25
- "@toa.io/schema": "1.0.0-alpha.26",
26
- "@toa.io/schemas": "1.0.0-alpha.26",
27
- "@toa.io/yaml": "1.0.0-alpha.26"
23
+ "@toa.io/core": "1.0.0-alpha.262",
24
+ "@toa.io/generic": "1.0.0-alpha.254",
25
+ "@toa.io/schemas": "1.0.0-alpha.263",
26
+ "@toa.io/yaml": "1.0.0-alpha.254"
28
27
  },
29
- "gitHead": "0ddd9260762d1fe2b8be88eb7b9725e3f7838299"
28
+ "gitHead": "165daa284bb7a75907a593fde359e3553b083417"
30
29
  }
@@ -10,11 +10,11 @@ function extensions (manifest) {
10
10
  const SHORTCUTS = {
11
11
  exposition: '@toa.io/extensions.exposition',
12
12
  realtime: '@toa.io/extensions.realtime',
13
- origins: '@toa.io/extensions.origins',
14
13
  configuration: '@toa.io/extensions.configuration',
15
14
  state: '@toa.io/extensions.state',
16
15
  stash: '@toa.io/extensions.stash',
17
- storages: '@toa.io/extensions.storages'
16
+ storages: '@toa.io/extensions.storages',
17
+ introspection: '@toa.io/extensions.introspection'
18
18
  }
19
19
 
20
20
  exports.extensions = extensions
@@ -4,7 +4,7 @@ const operations = (component) => {
4
4
  if (component.operations === undefined) return
5
5
 
6
6
  for (const [endpoint, operation] of Object.entries(component.operations)) {
7
- if (operation.type === 'computation' || operation.type === 'effect')
7
+ if (operation.scope === 'none')
8
8
  operation.query = false
9
9
 
10
10
  if (operation.bindings === undefined) operation.bindings = component.bindings
@@ -42,6 +42,11 @@ const collapse = (manifest, prototype) => {
42
42
  delete prototype.entity.schema.properties.id
43
43
  }
44
44
 
45
+ if (prototype.events !== undefined && manifest.events !== undefined)
46
+ for (const event of Object.keys(prototype.events))
47
+ if (event in manifest.events)
48
+ delete prototype.events[event]
49
+
45
50
  merge(manifest, { entity, events, extensions })
46
51
  }
47
52
 
@@ -1,11 +1,13 @@
1
1
  'use strict'
2
2
 
3
3
  const { hash } = require('@toa.io/generic')
4
- const assert = require('node:assert')
5
4
 
6
5
  // these defaults are required before validation
7
- const defaults = (manifest) => {
8
- if (manifest.name === undefined) manifest.name = protoName(manifest)
6
+ const defaults = (manifest, proto) => {
7
+ if (manifest.name === undefined)
8
+ if (proto) manifest.name = protoName(manifest)
9
+ else nameAfterDir(manifest)
10
+
9
11
  if (manifest.bindings === undefined) manifest.bindings = ['@toa.io/bindings.amqp']
10
12
  if (manifest.bridge === undefined) manifest.bridge = '@toa.io/bridges.node'
11
13
 
@@ -24,4 +26,13 @@ function protoName (manifest) {
24
26
  return 'proto' + hash(manifest.path)
25
27
  }
26
28
 
29
+ function nameAfterDir (manifest) {
30
+ const parts = manifest.path.split('/')
31
+ const dirname = parts[parts.length - 1]
32
+ const [name, namespace] = dirname.split('.').reverse()
33
+
34
+ manifest.name = name
35
+ manifest.namespace = namespace
36
+ }
37
+
27
38
  exports.defaults = defaults
@@ -25,7 +25,12 @@ const createResolver = (properties) => (property) => {
25
25
  function operations (manifest, resolver) {
26
26
  for (const operation of Object.values(manifest.operations)) {
27
27
  if (operation.input !== undefined) operation.input = schema(operation.input, resolver)
28
- if (operation.output !== undefined) operation.output = schema(operation.output, resolver)
28
+
29
+ if (operation.output !== undefined)
30
+ if (Array.isArray(operation.output) && operation.output.length === 1)
31
+ operation.output = [schema(operation.output[0], resolver)]
32
+ else
33
+ operation.output = schema(operation.output, resolver)
29
34
  }
30
35
 
31
36
  // forwarding
@@ -3,8 +3,10 @@
3
3
  const { directory: { find } } = require('@toa.io/filesystem')
4
4
  const { resolve } = require('../shortcuts')
5
5
 
6
+ const cache = {}
7
+
6
8
  const extensions = (manifest) => {
7
- if (manifest.extensions === undefined) return
9
+ manifest.extensions = Object.assign({}, PREDEFINED, manifest.extensions)
8
10
 
9
11
  const extensions = manifest.extensions
10
12
 
@@ -14,7 +16,8 @@ const extensions = (manifest) => {
14
16
  // relative path
15
17
  if (key[0] === '.') key = find(key, manifest.path)
16
18
 
17
- const extension = require(key)
19
+ cache[key] ??= require(key)
20
+ const extension = cache[key]
18
21
 
19
22
  if (extension.manifest !== undefined) {
20
23
  declaration = extension.manifest(declaration, manifest)
@@ -29,4 +32,10 @@ const extensions = (manifest) => {
29
32
  }
30
33
  }
31
34
 
35
+ const PREDEFINED = {
36
+ '@toa.io/extensions.telemetry': null,
37
+ '@toa.io/extensions.fetch': null,
38
+ '@toa.io/extensions.introspection': null
39
+ }
40
+
32
41
  exports.extensions = extensions
@@ -6,7 +6,8 @@ const bridge = async (root, manifest) => {
6
6
  await Promise.all([
7
7
  define(root, manifest, 'operations'),
8
8
  define(root, manifest, 'events'),
9
- define(root, manifest, 'receivers')
9
+ define(root, manifest, 'receivers'),
10
+ define(root, manifest, 'guards')
10
11
  ])
11
12
  }
12
13
 
@@ -19,7 +20,7 @@ const define = async (root, manifest, property) => {
19
20
  if (item.bridge === undefined || item.bridge === manifest.bridge) continue // default bridge later
20
21
 
21
22
  const bridge = item.bridge || manifest.bridge
22
- const { define } = require(bridge)
23
+ const define = req(bridge).define
23
24
  const definition = await define[singular](root, endpoint)
24
25
 
25
26
  merge(item, definition)
@@ -44,14 +45,27 @@ const define = async (root, manifest, property) => {
44
45
 
45
46
  const declared = manifest[property][endpoint]
46
47
 
47
- if (declared === undefined) manifest[property][endpoint] = item
48
- else merge(declared, item)
48
+ try {
49
+ if (declared === undefined) manifest[property][endpoint] = item
50
+ else merge(declared, item)
51
+ } catch (error) {
52
+ console.error(`Error merging ${singular} '${endpoint}' in ${root}`)
53
+ throw error
54
+ }
49
55
  }
50
56
  }
51
57
  }
52
58
 
59
+ const cache = {}
60
+
61
+ function req(mod) {
62
+ cache[mod] ??= require(mod)
63
+
64
+ return cache[mod]
65
+ }
66
+
53
67
  const scan = async (bridge, root, property) => {
54
- const { define } = require(bridge)
68
+ const define = req(bridge).define
55
69
 
56
70
  if (property in define)
57
71
  return define[property](root)
@@ -8,7 +8,7 @@ definitions:
8
8
  binding:
9
9
  type: string
10
10
  not:
11
- const: '@toa.io/bindings.loop' # loop is for system use only
11
+ const: "@toa.io/bindings.loop" # loop is for system use only
12
12
 
13
13
  type: object
14
14
  properties:
@@ -17,19 +17,19 @@ properties:
17
17
  nullable: true
18
18
  properties:
19
19
  prototype:
20
- $ref: '#/properties/prototype'
20
+ $ref: "#/properties/prototype"
21
21
  path:
22
22
  type: string
23
23
  operations:
24
24
  type: object
25
25
  propertyNames:
26
- $ref: '#/definitions/name'
26
+ $ref: "#/definitions/name"
27
27
  patternProperties:
28
- '.*':
28
+ ".*":
29
29
  type: object
30
30
  properties:
31
31
  bridge:
32
- $ref: '#/properties/bridge'
32
+ $ref: "#/properties/bridge"
33
33
 
34
34
  path:
35
35
  type: string
@@ -38,19 +38,23 @@ properties:
38
38
  type: object
39
39
  properties:
40
40
  id:
41
- $ref: 'definitions#/definitions/locator'
41
+ type: string
42
+ pattern: ^([a-zA-Z]+([_a-zA-Z0-9]*[a-zA-Z0-9]+)?)(\.([a-zA-Z]+([_a-zA-Z0-9]*[a-zA-Z0-9]+)?))$
42
43
  label:
43
- $ref: 'definitions#/definitions/label'
44
+ type: string
45
+ pattern: ^([a-zA-Z]+([_a-zA-Z0-9]*[a-zA-Z0-9]+)?)(-([a-zA-Z]+([_a-zA-Z0-9]*[a-zA-Z0-9]+)?))*$
44
46
 
45
47
  name:
46
- $ref: 'definitions#/definitions/token'
48
+ type: string
49
+ pattern: ^[a-zA-Z]([a-zA-Z0-9]{1,31})?$
47
50
 
48
51
  namespace:
49
- $ref: 'definitions#/definitions/token'
50
- default: 'default'
52
+ type: string
53
+ pattern: ^[a-zA-Z]([a-zA-Z0-9]{1,31})?$
54
+ default: "default"
51
55
  not:
52
56
  oneOf:
53
- - const: 'system'
57
+ - const: "system"
54
58
 
55
59
  version:
56
60
  type: string
@@ -60,15 +64,17 @@ properties:
60
64
  properties:
61
65
  image:
62
66
  type: string
67
+ run:
68
+ type: string
63
69
 
64
70
  entity:
65
71
  type: object
66
72
  properties:
67
73
  storage:
68
74
  type: string
69
- default: '@toa.io/storages.mongodb'
75
+ default: "@toa.io/storages.mongodb"
70
76
  schema:
71
- $ref: 'definitions#/definitions/schema'
77
+ $ref: https://json-schema.org/draft/2019-09/schema
72
78
  type: object
73
79
  properties:
74
80
  type:
@@ -78,24 +84,24 @@ properties:
78
84
  type: object
79
85
  propertyNames:
80
86
  oneOf:
81
- - $ref: '#/definitions/name'
87
+ - $ref: "#/definitions/name"
82
88
  - enum: [_version, _created, _updated, _deleted]
83
89
  unique:
84
90
  type: object
85
91
  patternProperties:
86
- '.*':
92
+ ".*":
87
93
  type: array
88
94
  items:
89
95
  type: string
90
96
  index:
91
97
  type: object
92
98
  patternProperties:
93
- '.*':
99
+ ".*":
94
100
  type: object
95
101
  patternProperties:
96
- '.*':
102
+ ".*":
97
103
  type: string
98
- enum: [asc, desc, hash]
104
+ enum: [asc, desc, hash, text]
99
105
  associated:
100
106
  type: boolean
101
107
  default: false
@@ -109,7 +115,7 @@ properties:
109
115
  type: array
110
116
  uniqueItems: true
111
117
  items:
112
- $ref: '#/definitions/binding'
118
+ $ref: "#/definitions/binding"
113
119
 
114
120
  bridge:
115
121
  type: string
@@ -117,27 +123,40 @@ properties:
117
123
  operations:
118
124
  type: object
119
125
  propertyNames:
120
- $ref: '#/definitions/name'
126
+ $ref: "#/definitions/name"
121
127
  patternProperties:
122
- '.*':
128
+ ".*":
123
129
  type: object
124
130
  properties:
125
131
  type:
126
- enum: [transition, observation, assignment, computation, effect]
132
+ enum:
133
+ [
134
+ transition,
135
+ observation,
136
+ assignment,
137
+ computation,
138
+ effect,
139
+ unmanaged,
140
+ ]
127
141
  scope:
128
- enum: [object, objects, changeset, none]
142
+ enum: [object, objects, changeset, stream, none]
129
143
  concurrency:
130
144
  enum: [none, retry]
131
145
  forward:
132
- $ref: '#/definitions/name'
146
+ $ref: "#/definitions/name"
133
147
  bridge:
134
148
  type: string
135
149
  bindings:
136
- $ref: '#/properties/bindings'
150
+ $ref: "#/properties/bindings"
137
151
  input:
138
- $ref: 'definitions#/definitions/schema'
152
+ $ref: https://json-schema.org/draft/2019-09/schema
139
153
  output:
140
- $ref: 'definitions#/definitions/schema'
154
+ $ref: https://json-schema.org/draft/2019-09/schema
155
+ default: {}
156
+ errors:
157
+ type: array
158
+ items:
159
+ type: string
141
160
  query:
142
161
  type: boolean
143
162
  required: [type, scope, bindings]
@@ -149,8 +168,8 @@ properties:
149
168
  then:
150
169
  properties:
151
170
  scope:
152
- enum: [object]
153
- if: # transition query: false
171
+ enum: [object, objects]
172
+ if: # not query: false
154
173
  not:
155
174
  properties:
156
175
  query:
@@ -158,6 +177,17 @@ properties:
158
177
  required: [query]
159
178
  then:
160
179
  required: [concurrency]
180
+ - if: # transition and scope=objects
181
+ properties:
182
+ type:
183
+ const: transition
184
+ scope:
185
+ const: objects
186
+ then:
187
+ properties:
188
+ query:
189
+ not:
190
+ const: false
161
191
  - if: # not transition
162
192
  not:
163
193
  properties:
@@ -174,7 +204,7 @@ properties:
174
204
  then:
175
205
  properties:
176
206
  scope:
177
- enum: [object, objects, none]
207
+ enum: [object, objects, stream, none]
178
208
  query:
179
209
  not:
180
210
  const: false
@@ -189,7 +219,7 @@ properties:
189
219
  - if: # computation
190
220
  properties:
191
221
  type:
192
- const: computation
222
+ enum: [computation, unmanaged]
193
223
  then:
194
224
  properties:
195
225
  scope:
@@ -205,20 +235,17 @@ properties:
205
235
  then:
206
236
  properties:
207
237
  scope:
208
- const: none
209
238
  default: none
210
- query:
211
- const: false
212
- default: false
239
+ enum: [object, objects, stream, none]
213
240
  additionalProperties: false
214
241
  additionalProperties: false
215
242
 
216
243
  events:
217
244
  type: object
218
245
  propertyNames:
219
- $ref: 'definitions#/definitions/name'
246
+ $ref: "#/definitions/name"
220
247
  patternProperties:
221
- '.*':
248
+ ".*":
222
249
  type: object
223
250
  properties:
224
251
  bridge:
@@ -226,7 +253,7 @@ properties:
226
253
  path:
227
254
  type: string
228
255
  binding:
229
- $ref: '#/definitions/binding'
256
+ $ref: "#/definitions/binding"
230
257
  conditioned:
231
258
  type: boolean
232
259
  default: false
@@ -239,17 +266,17 @@ properties:
239
266
  receivers:
240
267
  type: object
241
268
  patternProperties:
242
- '.*':
269
+ ".*":
243
270
  type: object
244
271
  properties:
245
272
  operation:
246
- $ref: 'definitions#/definitions/name'
273
+ $ref: "#/definitions/name"
247
274
  bridge:
248
275
  type: string
249
276
  binding:
250
277
  type: string
251
278
  source:
252
- $ref: 'definitions#/definitions/name'
279
+ $ref: "#/definitions/name"
253
280
  not:
254
281
  const: context
255
282
  path:
@@ -260,9 +287,22 @@ properties:
260
287
  adaptive:
261
288
  type: boolean
262
289
  default: false
290
+ arguments:
291
+ type: array
263
292
  required: [operation]
264
293
  additionalProperties: false
265
294
 
295
+ guards:
296
+ type: object
297
+ patternProperties:
298
+ ".*":
299
+ type: object
300
+ properties:
301
+ bridge: { type: string }
302
+ path: { type: string }
303
+ required: [bridge, path]
304
+ additionalProperties: false
305
+
266
306
  extensions:
267
307
  type: object
268
308
 
@@ -3,15 +3,15 @@
3
3
  const path = require('node:path')
4
4
 
5
5
  const { load } = require('@toa.io/yaml')
6
- const { Schema } = require('@toa.io/schema')
6
+ const schemas = require('@toa.io/schemas')
7
7
 
8
8
  const object = load.sync(path.resolve(__dirname, 'schema.yaml'))
9
- const schema = new Schema(object)
9
+ const schema = schemas.schema(object)
10
10
 
11
11
  const validate = (manifest) => {
12
12
  const error = schema.fit(manifest)
13
13
 
14
- if (error) throw new Error(error.message)
14
+ if (error) throw error
15
15
 
16
16
  if (manifest.events !== undefined) events(manifest)
17
17
  if (manifest.receivers !== undefined) receivers(manifest)
@@ -32,11 +32,11 @@ const receivers = (manifest) => {
32
32
  }
33
33
 
34
34
  if (!TYPES.has(manifest.operations[receiver.operation].type)) {
35
- throw new Error(`Receiver '${locator}' must refer to an operation of one of the allowed types: ${Array.from(TYPES).join(', ')}`)
35
+ throw new Error(`Receiver '${locator}' must refer to an operation of the allowed types: ${Array.from(TYPES).join(', ')}`)
36
36
  }
37
37
  }
38
38
  }
39
39
 
40
- const TYPES = new Set(['transition', 'effect'])
40
+ const TYPES = new Set(['transition', 'assignment', 'effect', 'unmanaged'])
41
41
 
42
42
  exports.validate = validate
@@ -3,7 +3,7 @@
3
3
  const extensions = async (context) => {
4
4
  const extensions = {}
5
5
  const components = context.components?.slice() ?? []
6
- const extracted = await extractExtensionComponents(components, extensions)
6
+ const extracted = await extractExtensionComponents(components, extensions, context.annotations)
7
7
 
8
8
  components.push(...extracted)
9
9
 
@@ -20,8 +20,9 @@ const extensions = async (context) => {
20
20
  return { extensions, components: extracted }
21
21
  }
22
22
 
23
- async function extractExtensionComponents (components, extensions) {
23
+ async function extractExtensionComponents (components, extensions, annotations) {
24
24
  const { component: load } = require('../../component')
25
+ const { load: loadDependency } = require('./load')
25
26
 
26
27
  const extracted = []
27
28
 
@@ -33,11 +34,14 @@ async function extractExtensionComponents (components, extensions) {
33
34
 
34
35
  extensions[reference] = []
35
36
 
36
- const mod = require(reference)
37
+ const { metadata, module: mod } = loadDependency(reference)
37
38
 
38
39
  if (mod.components === undefined) continue
39
40
 
40
- for (const path of mod.components().paths) {
41
+ // the annotation decides whether an extension contributes components at all
42
+ const annotation = annotations?.[metadata?.name ?? reference]
43
+
44
+ for (const path of mod.components(annotation).paths) {
41
45
  const component = await load(path)
42
46
 
43
47
  extracted.push(component)
@@ -48,7 +52,7 @@ async function extractExtensionComponents (components, extensions) {
48
52
  if (extracted.length === 0)
49
53
  return extracted
50
54
 
51
- const deeper = await extractExtensionComponents(extracted, extensions)
55
+ const deeper = await extractExtensionComponents(extracted, extensions, annotations)
52
56
 
53
57
  return extracted.concat(deeper)
54
58
  }
@@ -24,6 +24,15 @@ const resolve = (references, annotations) => {
24
24
  }
25
25
  }
26
26
 
27
+ for (const dependency of Object.keys(annotations)) {
28
+ const { module } = load(dependency)
29
+
30
+ if (!module.standalone || (dependency in dependencies))
31
+ continue
32
+
33
+ dependencies[dependency] = []
34
+ }
35
+
27
36
  return dependencies
28
37
  }
29
38
 
@@ -6,12 +6,10 @@ properties:
6
6
  version:
7
7
  type: string
8
8
  name:
9
- $ref: 'definitions#/definitions/label'
10
- description:
11
9
  type: string
12
- packages:
10
+ pattern: ^([a-zA-Z]+([_a-zA-Z0-9]*[a-zA-Z0-9]+)?)(-([a-zA-Z]+([_a-zA-Z0-9]*[a-zA-Z0-9]+)?))*$
11
+ description:
13
12
  type: string
14
- default: components/*
15
13
  build:
16
14
  type: object
17
15
  properties:
@@ -46,7 +44,7 @@ properties:
46
44
  - linux/amd64
47
45
  - linux/arm/v7
48
46
  - linux/arm64
49
- required: [base, platforms]
47
+ # required: [base]
50
48
  compositions:
51
49
  type: array
52
50
  minItems: 1
@@ -54,16 +52,67 @@ properties:
54
52
  type: object
55
53
  properties:
56
54
  name:
57
- $ref: 'definitions#/definitions/token'
55
+ type: string
56
+ pattern: ^[a-zA-Z]([a-zA-Z0-9]{1,31})?$
58
57
  image:
59
58
  type: string
60
59
  components:
61
60
  type: array
62
61
  minItems: 1
63
62
  items:
64
- $ref: 'definitions#/definitions/locator'
63
+ type: string
64
+ pattern: ^([a-zA-Z]+([_a-zA-Z0-9]*[a-zA-Z0-9]+)?)(\.([a-zA-Z]+([_a-zA-Z0-9]*[a-zA-Z0-9]+)?))$
65
+ resources:
66
+ $ref: '#/definitions/resources'
65
67
  required: [name, components]
68
+ mono:
69
+ type: object
70
+ additionalProperties: false
71
+ properties:
72
+ replicas:
73
+ type: integer
74
+ minimum: 1
75
+ resources:
76
+ $ref: '#/definitions/resources'
77
+ ingress:
78
+ type: object
79
+ additionalProperties: false
80
+ properties:
81
+ hosts:
82
+ type: array
83
+ minItems: 1
84
+ items:
85
+ type: string
86
+ class:
87
+ type: string
88
+ annotations:
89
+ type: object
90
+ default:
91
+ type: boolean
66
92
  annotations:
67
93
  type: object
94
+ resources:
95
+ $ref: '#/definitions/resources'
68
96
  required: [runtime, name, registry]
69
97
  additionalProperties: false
98
+
99
+ definitions:
100
+ # What a deployment may take. `null` deploys it without any, which is a decision
101
+ # rather than an omission — every deployment has to make one.
102
+ resources:
103
+ type: object
104
+ nullable: true
105
+ additionalProperties: false
106
+ properties:
107
+ cpu:
108
+ type: array
109
+ items:
110
+ type: string
111
+ minItems: 2
112
+ maxItems: 2
113
+ memory:
114
+ type: array
115
+ items:
116
+ type: string
117
+ minItems: 2
118
+ maxItems: 2
@@ -3,15 +3,12 @@
3
3
  const { resolve } = require('node:path')
4
4
 
5
5
  const { load } = require('@toa.io/yaml')
6
- const { Schema } = require('@toa.io/schema')
6
+ const schemas = require('@toa.io/schemas')
7
7
 
8
8
  const path = resolve(__dirname, 'schema.yaml')
9
9
  const object = load.sync(path)
10
- const schema = new Schema(object)
10
+ const schema = schemas.schema(object)
11
11
 
12
- /**
13
- * @param {toa.norm.context.Declaration} context
14
- */
15
12
  const validate = (context) => {
16
13
  schema.validate(context)
17
14
  }
package/src/component.js CHANGED
@@ -20,7 +20,7 @@ const {
20
20
  const component = async (path) => {
21
21
  const manifest = await load(path)
22
22
 
23
- normalize(manifest)
23
+ normalize(manifest, path)
24
24
  validate(manifest)
25
25
  extensions(manifest)
26
26
 
@@ -29,21 +29,21 @@ const component = async (path) => {
29
29
  return manifest
30
30
  }
31
31
 
32
- const load = async (path, base) => {
32
+ const load = async (path, base, proto = false) => {
33
33
  if (base !== undefined) path = find(path, base, MANIFEST)
34
34
 
35
35
  const file = join(path, MANIFEST)
36
- const manifest = /** @type {toa.norm.Component} */ await yaml(file) ?? {}
36
+ const manifest = await yaml(file) ?? {}
37
37
 
38
38
  manifest.path = path
39
39
 
40
- defaults(manifest)
40
+ defaults(manifest, proto)
41
41
  await expand(manifest)
42
42
 
43
43
  await merge(path, manifest)
44
44
 
45
45
  if (manifest.prototype !== null) {
46
- const prototype = await load(manifest.prototype, path)
46
+ const prototype = await load(manifest.prototype, path, true)
47
47
 
48
48
  collapse(manifest, prototype)
49
49
  }
package/src/context.js CHANGED
@@ -19,7 +19,6 @@ const {
19
19
  const context = async (root, environment = process.env.TOA_ENV) => {
20
20
  const path = resolve(root, CONTEXT)
21
21
  const context = /** @type {toa.norm.Context} */ await load(path)
22
- const pattern = resolve(root, context.packages)
23
22
 
24
23
  context.environment = environment
25
24
 
@@ -29,7 +28,7 @@ const context = async (root, environment = process.env.TOA_ENV) => {
29
28
 
30
29
  validate(context)
31
30
 
32
- const paths = await glob(pattern)
31
+ const paths = await glob(resolve(root, COMPONENTS))
33
32
 
34
33
  context.components = await Promise.all(paths.map(component))
35
34
  context.dependencies = await dependencies(context)
@@ -41,5 +40,6 @@ const context = async (root, environment = process.env.TOA_ENV) => {
41
40
  }
42
41
 
43
42
  const CONTEXT = 'context.toa.yaml'
43
+ const COMPONENTS = 'components/*'
44
44
 
45
45
  exports.context = context
package/src/shortcuts.js CHANGED
@@ -48,9 +48,10 @@ const SHORTCUTS = {
48
48
  exposition: '@toa.io/extensions.exposition',
49
49
  realtime: '@toa.io/extensions.realtime',
50
50
  configuration: '@toa.io/extensions.configuration',
51
- origins: '@toa.io/extensions.origins',
52
51
  stash: '@toa.io/extensions.stash',
53
- storages: '@toa.io/extensions.storages'
52
+ storages: '@toa.io/extensions.storages',
53
+ telemetry: '@toa.io/extensions.telemetry',
54
+ introspection: '@toa.io/extensions.introspection'
54
55
  }
55
56
 
56
57
  exports.recognize = recognize
@@ -1,9 +1,7 @@
1
1
  'use strict'
2
-
3
- const { dirname } = require('node:path')
4
2
  const clone = require('clone-deep')
5
3
 
6
- const { normalize } = require('../../src/.component')
4
+ const { normalize, extensions } = require('../../src/.component')
7
5
  const fixtures = require('./normalize.fixtures')
8
6
 
9
7
  let manifest
@@ -21,13 +19,23 @@ describe('operations', () => {
21
19
  })
22
20
 
23
21
  describe('extensions', () => {
24
- it('should resolve absolute references', () => {
25
- const origins = manifest.extensions['@toa.io/extensions.origins']
26
- const path = dirname(require.resolve('@toa.io/extensions.origins/package.json'))
22
+ it('should add predefined extensions', () => {
23
+ extensions(manifest)
27
24
 
28
- normalize(manifest)
25
+ expect(manifest.extensions['@toa.io/extensions.telemetry']).toBeNull()
26
+ expect(manifest.extensions['@toa.io/extensions.fetch']).toBeNull()
27
+ })
29
28
 
30
- expect(manifest.extensions[path]).toStrictEqual(origins)
29
+ it('should add predefined extensions without explicit declarations', () => {
30
+ delete manifest.extensions
31
+
32
+ extensions(manifest)
33
+
34
+ expect(manifest.extensions).toStrictEqual({
35
+ '@toa.io/extensions.telemetry': null,
36
+ '@toa.io/extensions.fetch': null,
37
+ '@toa.io/extensions.introspection': {}
38
+ })
31
39
  })
32
40
  })
33
41
 
@@ -1,5 +1,3 @@
1
- // noinspection JSUnresolvedVariable
2
-
3
1
  'use strict'
4
2
 
5
3
  const clone = require('clone-deep')
@@ -20,13 +18,13 @@ it('should be ok', () => {
20
18
  it('should provide error', () => {
21
19
  manifest.foo = 'bar'
22
20
 
23
- expect(() => validate(manifest)).toThrow(/must NOT have additional property/)
21
+ expect(() => validate(manifest)).toThrow()
24
22
  })
25
23
 
26
24
  it('should not have additional properties', () => {
27
25
  manifest.foo = 'bar'
28
26
 
29
- expect(() => validate(manifest)).toThrow(/must NOT have additional property/)
27
+ expect(() => validate(manifest)).toThrow()
30
28
  })
31
29
 
32
30
  describe('namespace', () => {
@@ -83,13 +81,13 @@ describe('entity', () => {
83
81
 
84
82
  it('should not have additional properties', () => {
85
83
  manifest.entity.foo = 'bar'
86
- expect(() => validate(manifest)).toThrow(/must NOT have additional property/)
84
+ expect(() => validate(manifest)).toThrow()
87
85
  })
88
86
 
89
87
  describe('schema', () => {
90
88
  it('should be required', () => {
91
89
  delete manifest.entity.schema
92
- expect(() => validate(manifest)).toThrow(/must have required property/)
90
+ expect(() => validate(manifest)).toThrow()
93
91
  })
94
92
 
95
93
  it('should be JSON schema object', () => {
@@ -99,7 +97,7 @@ describe('entity', () => {
99
97
 
100
98
  it('should be JSON schema object of type object', () => {
101
99
  manifest.entity.schema = { type: 'integer' }
102
- expect(() => validate(manifest)).toThrow(/must be equal to constant 'object'/)
100
+ expect(() => validate(manifest)).toThrow(/must be equal to constant/)
103
101
 
104
102
  manifest.entity.schema = {}
105
103
  validate(manifest)
@@ -154,7 +152,7 @@ describe('operations', () => {
154
152
 
155
153
  it('should not have additional properties', () => {
156
154
  manifest.operations.get.foo = 'bar'
157
- expect(() => validate(manifest)).toThrow(/additional property/)
155
+ expect(() => validate(manifest)).toThrow()
158
156
  })
159
157
 
160
158
  it('should have type (transition or observation)', () => {
@@ -176,8 +174,7 @@ describe('operations', () => {
176
174
  })
177
175
 
178
176
  it.each([
179
- ['computation', 'compute'],
180
- ['effect', 'affect']
177
+ ['computation', 'compute']
181
178
  ])('should set query: false for %s', async (_, operation) => {
182
179
  validate(manifest)
183
180
 
@@ -250,7 +247,7 @@ describe('receivers', () => {
250
247
  it('should throw if transition points to observation', () => {
251
248
  manifest.receivers['foo.bar.happened'].operation = 'get'
252
249
 
253
- expect(() => validate(manifest)).toThrow(/one of the allowed types/)
250
+ expect(() => validate(manifest)).toThrow(/of the allowed types/)
254
251
  })
255
252
 
256
253
  it('should throw if source has a name `context`', async () => {
@@ -21,7 +21,6 @@ const context = {
21
21
  name: 'test',
22
22
  description: 'context fixture',
23
23
  version: '0.0.0',
24
- packages: 'namespaces/**/*',
25
24
  registry: 'localhost:5000',
26
25
  components: [
27
26
  component('a.b'),
@@ -27,7 +27,6 @@ const context = {
27
27
  description: 'context fixture',
28
28
  version: '0.0.0',
29
29
  runtime: '0.0.0',
30
- packages: 'namespaces/**/*',
31
30
  registry: 'localhost:5000',
32
31
  components: [component('a.b'), component('b.a'), component('d.c')],
33
32
  compositions: [
@@ -9,7 +9,6 @@ const context = {
9
9
  name: 'test',
10
10
  description: 'context fixture',
11
11
  version: '0.0.0',
12
- packages: 'namespaces/**/*',
13
12
  registry: 'localhost:5000',
14
13
  compositions: [
15
14
  {
@@ -7,7 +7,6 @@ const context = {
7
7
  name: 'test',
8
8
  description: 'context fixture',
9
9
  version: '0.0.0',
10
- packages: 'namespaces/**/*',
11
10
  build: {
12
11
  command: 'echo test'
13
12
  },
@@ -45,12 +45,6 @@ describe('registry', () => {
45
45
  expect(() => validate(context)).toThrow(/required property 'registry'/)
46
46
  })
47
47
 
48
- it('should require base', () => {
49
- delete context.registry.base
50
-
51
- expect(() => validate(context)).toThrow(/required property 'base'/)
52
- })
53
-
54
48
  it('should set default platforms', () => {
55
49
  delete context.registry.platforms
56
50
 
@@ -72,13 +66,19 @@ it('should require name as label', () => {
72
66
  expect(() => validate(context)).not.toThrow(/pattern/)
73
67
  })
74
68
 
75
- it('should set default packages location', () => {
76
- delete context.packages
77
- expect(() => validate(context)).not.toThrow()
78
- expect(context.packages).toBe('components/*')
79
- })
80
-
81
69
  it('should require registry url', () => {
82
70
  delete context.registry
83
71
  expect(() => validate(context)).toThrow(/required/)
84
72
  })
73
+
74
+ it('should allow mono replicas and resources', () => {
75
+ context.mono = {
76
+ replicas: 2,
77
+ resources: {
78
+ cpu: ['200m', '2'],
79
+ memory: ['256Mi', '2Gi']
80
+ }
81
+ }
82
+
83
+ expect(() => validate(context)).not.toThrow()
84
+ })
@@ -5,13 +5,34 @@ interface Composition {
5
5
  components: string[]
6
6
  }
7
7
 
8
+ export interface Resources {
9
+ cpu?: [string, string]
10
+ memory?: [string, string]
11
+ }
12
+
13
+ export interface Mono {
14
+ replicas?: number
15
+ resources?: Resources
16
+ }
17
+
18
+ /**
19
+ * Cluster-level ingress configuration, applied to every service that declares one.
20
+ */
21
+ export interface Ingress {
22
+ hosts?: string[]
23
+ class?: string
24
+ annotations?: Record<string, string>
25
+ default?: boolean
26
+ }
27
+
8
28
  export interface Declaration {
9
29
  name: string
10
30
  description?: string
11
31
  version?: string
12
32
  runtime?: Runtime | string
13
33
  registry?: Registry | string
14
- packages?: string
15
34
  compositions?: Composition[]
35
+ mono?: Mono
36
+ ingress?: Ingress
16
37
  annotations?: Record<string, object>
17
38
  }