@toa.io/norm 1.0.0-alpha.2 → 1.0.0-alpha.4

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": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.4",
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": "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"
23
+ "@toa.io/core": "1.0.0-alpha.4",
24
+ "@toa.io/generic": "1.0.0-alpha.4",
25
+ "@toa.io/schema": "1.0.0-alpha.4",
26
+ "@toa.io/schemas": "1.0.0-alpha.4",
27
+ "@toa.io/yaml": "1.0.0-alpha.4"
28
28
  },
29
- "gitHead": "7688e6e980a65c82ac2e459be4e355eebf406cd0"
29
+ "gitHead": "80a91c0d9c167484247a91e69a0c0a3c344f90d0"
30
30
  }
@@ -7,6 +7,7 @@ const { extensions } = require('./extensions')
7
7
  const { operations } = require('./operations')
8
8
  const { properties } = require('./properties')
9
9
  const { receivers } = require('./receivers')
10
+ const { version } = require('./version')
10
11
 
11
12
  exports.bridge = bridge
12
13
  exports.entity = entity
@@ -15,3 +16,4 @@ exports.extensions = extensions
15
16
  exports.operations = operations
16
17
  exports.properties = properties
17
18
  exports.receivers = receivers
19
+ exports.version = version
@@ -0,0 +1,19 @@
1
+ 'use strict'
2
+
3
+ function version (manifest) {
4
+ if (manifest.version === undefined) {
5
+ const bridge = require(manifest.bridge)
6
+
7
+ if ('version' in bridge)
8
+ manifest.version = bridge.version(manifest)
9
+ }
10
+
11
+ if (manifest.version === undefined) {
12
+ console.warn(`Component '${manifest.namespace ? manifest.namespace + '.' : ''}${manifest.name}' has no version`)
13
+
14
+ manifest.version = Math.random().toString(36).slice(2)
15
+ }
16
+
17
+ }
18
+
19
+ exports.version = version
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { hash } = require('@toa.io/generic')
4
+ const assert = require('node:assert')
4
5
 
5
6
  // these defaults are required before validation
6
7
  const defaults = (manifest) => {
@@ -17,9 +18,6 @@ const defaults = (manifest) => {
17
18
  }
18
19
 
19
20
  if (manifest.prototype === undefined) manifest.prototype = '@toa.io/prototype'
20
-
21
- // TODO: bridge.version()
22
- if (manifest.version === undefined) manifest.version = '0.0.0'
23
21
  }
24
22
 
25
23
  function protoName (manifest) {
@@ -7,7 +7,8 @@ const {
7
7
  events,
8
8
  receivers,
9
9
  extensions,
10
- properties
10
+ properties,
11
+ version
11
12
  } = require('./.expand')
12
13
 
13
14
  const expand = (manifest) => {
@@ -18,6 +19,7 @@ const expand = (manifest) => {
18
19
  receivers(manifest)
19
20
  properties(manifest)
20
21
  extensions(manifest)
22
+ version(manifest)
21
23
  }
22
24
 
23
25
  exports.expand = expand
@@ -53,7 +53,7 @@ properties:
53
53
  - const: 'system'
54
54
 
55
55
  version:
56
- $ref: 'definitions#/definitions/version'
56
+ type: string
57
57
 
58
58
  build:
59
59
  type: object
@@ -1,5 +1,7 @@
1
1
  'use strict'
2
2
 
3
+ const { resolve } = require('node:path')
4
+
3
5
  const connectors = (context, extracted) => {
4
6
  const connectors = {}
5
7
 
@@ -10,11 +12,14 @@ const connectors = (context, extracted) => {
10
12
 
11
13
  for (const component of components) {
12
14
  if (component.entity !== undefined) {
13
- if (connectors[component.entity.storage] === undefined) {
14
- connectors[component.entity.storage] = []
15
+ let storage = component.entity.storage
16
+
17
+ if (storage[0] === '.') {
18
+ storage = resolve(component.path, storage)
15
19
  }
16
20
 
17
- connectors[component.entity.storage].push(component)
21
+ connectors[storage] ??= []
22
+ connectors[storage].push(component)
18
23
  }
19
24
 
20
25
  const bindings = new Set()
@@ -4,7 +4,7 @@ $id: https://schemas.toa.io/0.0.0/context
4
4
  type: object
5
5
  properties:
6
6
  version:
7
- $ref: 'definitions#/definitions/version'
7
+ type: string
8
8
  name:
9
9
  $ref: 'definitions#/definitions/label'
10
10
  description:
@@ -20,7 +20,7 @@ properties:
20
20
  type: object
21
21
  properties:
22
22
  version:
23
- $ref: 'definitions#/definitions/version'
23
+ type: string
24
24
  registry:
25
25
  type: string
26
26
  format: uri
package/src/component.js CHANGED
@@ -13,7 +13,6 @@ const {
13
13
  collapse,
14
14
  dereference,
15
15
  defaults,
16
- dependencies,
17
16
  normalize,
18
17
  extensions
19
18
  } = require('./.component')
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const source = {
4
+ path: '',
4
5
  entity: {
5
6
  schema: {
6
7
  properties: {
@@ -21,14 +21,6 @@ describe('runtime', () => {
21
21
  expect(() => validate(context)).toThrow(/required/)
22
22
  })
23
23
 
24
- it('should require version as semver', () => {
25
- delete context.runtime.version
26
- expect(() => validate(context)).toThrow(/required/)
27
-
28
- context.runtime.version = '.'
29
- expect(() => validate(context)).toThrow(/pattern/)
30
- })
31
-
32
24
  it('should require registry to match uri format', () => {
33
25
  context.runtime.registry = 'not-a-uri'
34
26
  expect(() => validate(context)).toThrow(/must match format/)