@toa.io/norm 1.0.0-alpha.6 → 1.0.0-alpha.7

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.6",
3
+ "version": "1.0.0-alpha.7",
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.6",
24
- "@toa.io/generic": "1.0.0-alpha.6",
25
- "@toa.io/schema": "1.0.0-alpha.6",
26
- "@toa.io/schemas": "1.0.0-alpha.6",
27
- "@toa.io/yaml": "1.0.0-alpha.6"
23
+ "@toa.io/core": "1.0.0-alpha.7",
24
+ "@toa.io/generic": "1.0.0-alpha.7",
25
+ "@toa.io/schema": "1.0.0-alpha.7",
26
+ "@toa.io/schemas": "1.0.0-alpha.7",
27
+ "@toa.io/yaml": "1.0.0-alpha.7"
28
28
  },
29
- "gitHead": "f28d629a9477646e267a8af8479cc1bb10d62c80"
29
+ "gitHead": "4f5ac0bc342d4b7bd469fbe5c74266f050b55c9f"
30
30
  }
@@ -1,19 +1,45 @@
1
1
  'use strict'
2
2
 
3
- function version (manifest) {
4
- if (manifest.version === undefined) {
5
- const bridge = require(manifest.bridge)
3
+ const { join } = require('node:path')
4
+ const { createHash } = require('node:crypto')
5
+ const fs = require('node:fs/promises')
6
+ const { createReadStream } = require('node:fs')
7
+ const { once } = require('node:events')
6
8
 
7
- if ('version' in bridge)
8
- manifest.version = bridge.version(manifest)
9
- }
9
+ async function version (manifest) {
10
+ manifest.version ??= await hash(manifest.path)
11
+ }
12
+
13
+ async function hash (path) {
14
+ const hash = await hashd(path)
15
+
16
+ return hash.digest('hex').slice(0, 8)
17
+ }
10
18
 
11
- if (manifest.version === undefined) {
12
- console.warn(`Component '${manifest.namespace ? manifest.namespace + '.' : ''}${manifest.name}' has no version`)
19
+ /**
20
+ * @param {string} path
21
+ * @param {import('node:crypto').Hash} hash
22
+ */
23
+ async function hashd (path, hash = createHash('sha256')) {
24
+ const stat = await fs.stat(path)
13
25
 
14
- manifest.version = Math.random().toString(36).slice(2)
26
+ if (stat.isFile()) {
27
+ const stream = createReadStream(path)
28
+
29
+ stream.pipe(hash, { end: false })
30
+
31
+ return await once(stream, 'end')
15
32
  }
16
33
 
34
+ if (stat.isDirectory()) {
35
+ const entries = await fs.opendir(path)
36
+
37
+ for await (const entry of entries) {
38
+ await hashd(join(path, entry.name), hash)
39
+ }
40
+
41
+ return hash
42
+ }
17
43
  }
18
44
 
19
45
  exports.version = version
@@ -11,7 +11,7 @@ const {
11
11
  version
12
12
  } = require('./.expand')
13
13
 
14
- const expand = (manifest) => {
14
+ async function expand (manifest) {
15
15
  entity(manifest)
16
16
  bridge(manifest)
17
17
  operations(manifest)
@@ -19,7 +19,8 @@ const expand = (manifest) => {
19
19
  receivers(manifest)
20
20
  properties(manifest)
21
21
  extensions(manifest)
22
- version(manifest)
22
+
23
+ await version(manifest)
23
24
  }
24
25
 
25
26
  exports.expand = expand
package/src/component.js CHANGED
@@ -38,7 +38,7 @@ const load = async (path, base) => {
38
38
  manifest.path = path
39
39
 
40
40
  defaults(manifest)
41
- expand(manifest)
41
+ await expand(manifest)
42
42
 
43
43
  await merge(path, manifest)
44
44