@guanghechen/config 1.0.0-alpha.12 → 1.0.0-alpha.14

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 CHANGED
@@ -1,122 +1,108 @@
1
1
  # Change Log
2
2
 
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
3
+ All notable changes to this project will be documented in this file. See
4
+ [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- # [1.0.0-alpha.12](https://github.com/guanghechen/sora/compare/@guanghechen/config@1.0.0-alpha.11...@guanghechen/config@1.0.0-alpha.12) (2024-01-13)
6
+ # [1.0.0-alpha.14](https://github.com/guanghechen/sora/compare/@guanghechen/config@1.0.0-alpha.13...@guanghechen/config@1.0.0-alpha.14) (2024-01-21)
7
7
 
8
+ ### Performance Improvements
8
9
 
9
- ### Features
10
+ - 💄 fix lint
11
+ ([2d5bb6f](https://github.com/guanghechen/sora/commit/2d5bb6f03d0312a42c1117d95181df8b69de827a))
12
+ - 🎨 remove @guanghechen/mac
13
+ ([5bde7d0](https://github.com/guanghechen/sora/commit/5bde7d0aa38fa648518804c1c30662fe4bbfa6ac))
10
14
 
11
- * 🎨 add 'parse' method to parse config content ([9fbc4f0](https://github.com/guanghechen/sora/commit/9fbc4f090398c1a59894f81aa3facd1bc10aa60c))
15
+ # Change Log
12
16
 
17
+ All notable changes to this project will be documented in this file. See
18
+ [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
13
19
 
20
+ # [1.0.0-alpha.13](https://github.com/guanghechen/sora/compare/@guanghechen/config@1.0.0-alpha.12...@guanghechen/config@1.0.0-alpha.13) (2024-01-20)
14
21
 
22
+ ### Features
15
23
 
24
+ - 🎨 add MemoTextResource & rename TextFileResource to FileTextResource
25
+ ([fa9bb9c](https://github.com/guanghechen/sora/commit/fa9bb9c9d927a644dc1127ee48914f813a5611ab))
16
26
 
17
- # [1.0.0-alpha.11](https://github.com/guanghechen/sora/compare/@guanghechen/config@1.0.0-alpha.10...@guanghechen/config@1.0.0-alpha.11) (2024-01-02)
27
+ ### Performance Improvements
18
28
 
19
- **Note:** Version bump only for package @guanghechen/config
29
+ - ⬆️ fix dependencies & fix lint
30
+ ([b94c1da](https://github.com/guanghechen/sora/commit/b94c1dab2352201f11022e7aa5820c9da149cbb7))
31
+ - ⬆️ upgrade dependencies
32
+ ([1039cb9](https://github.com/guanghechen/sora/commit/1039cb979b9b760ffb02e3620b05a4320d0bd107))
20
33
 
34
+ # [1.0.0-alpha.12](https://github.com/guanghechen/sora/compare/@guanghechen/config@1.0.0-alpha.11...@guanghechen/config@1.0.0-alpha.12) (2024-01-13)
21
35
 
36
+ ### Features
22
37
 
38
+ - 🎨 add 'parse' method to parse config content
39
+ ([9fbc4f0](https://github.com/guanghechen/sora/commit/9fbc4f090398c1a59894f81aa3facd1bc10aa60c))
23
40
 
41
+ # [1.0.0-alpha.11](https://github.com/guanghechen/sora/compare/@guanghechen/config@1.0.0-alpha.10...@guanghechen/config@1.0.0-alpha.11) (2024-01-02)
24
42
 
25
- # [1.0.0-alpha.10](https://github.com/guanghechen/sora/compare/@guanghechen/config@1.0.0-alpha.9...@guanghechen/config@1.0.0-alpha.10) (2023-12-08)
43
+ **Note:** Version bump only for package @guanghechen/config
26
44
 
45
+ # [1.0.0-alpha.10](https://github.com/guanghechen/sora/compare/@guanghechen/config@1.0.0-alpha.9...@guanghechen/config@1.0.0-alpha.10) (2023-12-08)
27
46
 
28
47
  ### Performance Improvements
29
48
 
30
- * 🔧 update description ([83ce262](https://github.com/guanghechen/sora/commit/83ce26221ae681837c03eec4259c5b9bd07faffb))
31
-
32
-
33
-
34
-
49
+ - 🔧 update description
50
+ ([83ce262](https://github.com/guanghechen/sora/commit/83ce26221ae681837c03eec4259c5b9bd07faffb))
35
51
 
36
52
  # [1.0.0-alpha.9](https://github.com/guanghechen/sora/compare/@guanghechen/config@1.0.0-alpha.8...@guanghechen/config@1.0.0-alpha.9) (2023-12-04)
37
53
 
38
-
39
54
  ### Performance Improvements
40
55
 
41
- * 🔧 fix circular dependencies ([fc2a82d](https://github.com/guanghechen/sora/commit/fc2a82d6e5376c722f347f6765cc8df7ff6fd31f))
42
- * 💄 fix lint ([ad8c6ed](https://github.com/guanghechen/sora/commit/ad8c6edbcb04a5db1740bfeb64ef2173abf06311))
43
-
44
-
45
-
46
-
56
+ - 🔧 fix circular dependencies
57
+ ([fc2a82d](https://github.com/guanghechen/sora/commit/fc2a82d6e5376c722f347f6765cc8df7ff6fd31f))
58
+ - 💄 fix lint
59
+ ([ad8c6ed](https://github.com/guanghechen/sora/commit/ad8c6edbcb04a5db1740bfeb64ef2173abf06311))
47
60
 
48
61
  # [1.0.0-alpha.8](https://github.com/guanghechen/sora/compare/@guanghechen/config@1.0.0-alpha.7...@guanghechen/config@1.0.0-alpha.8) (2023-12-03)
49
62
 
50
-
51
63
  ### Performance Improvements
52
64
 
53
- * 🔧 fix lint ([4bc57d2](https://github.com/guanghechen/sora/commit/4bc57d2deabf2a4f144c7af46d45582387825ecb))
54
-
55
-
56
-
57
-
65
+ - 🔧 fix lint
66
+ ([4bc57d2](https://github.com/guanghechen/sora/commit/4bc57d2deabf2a4f144c7af46d45582387825ecb))
58
67
 
59
68
  # [1.0.0-alpha.7](https://github.com/guanghechen/sora/compare/@guanghechen/config@1.0.0-alpha.6...@guanghechen/config@1.0.0-alpha.7) (2023-12-02)
60
69
 
61
70
  **Note:** Version bump only for package @guanghechen/config
62
71
 
63
-
64
-
65
-
66
-
67
72
  # [1.0.0-alpha.6](https://github.com/guanghechen/sora/compare/@guanghechen/config@1.0.0-alpha.5...@guanghechen/config@1.0.0-alpha.6) (2023-11-29)
68
73
 
69
-
70
74
  ### Performance Improvements
71
75
 
72
- * 🔧 no longer to require node engine version in packages ([6dc2014](https://github.com/guanghechen/sora/commit/6dc2014122dd44bcadc893e2ee98697265e7d61e))
73
-
74
-
75
-
76
-
76
+ - 🔧 no longer to require node engine version in packages
77
+ ([6dc2014](https://github.com/guanghechen/sora/commit/6dc2014122dd44bcadc893e2ee98697265e7d61e))
77
78
 
78
79
  # [1.0.0-alpha.5](https://github.com/guanghechen/sora/compare/@guanghechen/config@1.0.0-alpha.4...@guanghechen/config@1.0.0-alpha.5) (2023-11-25)
79
80
 
80
-
81
81
  ### Performance Improvements
82
82
 
83
- * ⬆️ upgrade devDependencies ([85c97b7](https://github.com/guanghechen/sora/commit/85c97b734e30a44a5016f117862ec0ba1084a054))
84
-
85
-
86
-
87
-
83
+ - ⬆️ upgrade devDependencies
84
+ ([85c97b7](https://github.com/guanghechen/sora/commit/85c97b734e30a44a5016f117862ec0ba1084a054))
88
85
 
89
86
  # [1.0.0-alpha.4](https://github.com/guanghechen/sora/compare/@guanghechen/config@1.0.0-alpha.3...@guanghechen/config@1.0.0-alpha.4) (2023-11-18)
90
87
 
91
88
  **Note:** Version bump only for package @guanghechen/config
92
89
 
93
-
94
-
95
-
96
-
97
90
  # [1.0.0-alpha.3](https://github.com/guanghechen/sora/compare/@guanghechen/config@1.0.0-alpha.2...@guanghechen/config@1.0.0-alpha.3) (2023-11-18)
98
91
 
99
92
  **Note:** Version bump only for package @guanghechen/config
100
93
 
101
-
102
-
103
-
104
-
105
94
  # [1.0.0-alpha.2](https://github.com/guanghechen/sora/compare/@guanghechen/config@1.0.0-alpha.1...@guanghechen/config@1.0.0-alpha.2) (2023-11-18)
106
95
 
107
-
108
96
  ### Performance Improvements
109
97
 
110
- * chore: upgrade dependencies ([46cb847](https://github.com/guanghechen/sora/commit/46cb8470de325045eaa1737b096aa2cc100bd430))
111
- * 🔧 upgrade engine version requirement from '>= 16.0.0' to '>= 18.0.0' ([ddb9521](https://github.com/guanghechen/sora/commit/ddb9521b529b2ca838554794339b9e27ac80b8aa))
112
-
113
-
114
-
115
-
98
+ - chore: upgrade dependencies
99
+ ([46cb847](https://github.com/guanghechen/sora/commit/46cb8470de325045eaa1737b096aa2cc100bd430))
100
+ - 🔧 upgrade engine version requirement from '>= 16.0.0' to '>= 18.0.0'
101
+ ([ddb9521](https://github.com/guanghechen/sora/commit/ddb9521b529b2ca838554794339b9e27ac80b8aa))
116
102
 
117
103
  # 1.0.0-alpha.1 (2023-11-07)
118
104
 
119
-
120
105
  ### Features
121
106
 
122
- * ✨ add @guanghechen/config ([f982c65](https://github.com/guanghechen/sora/commit/f982c650b09cafe19311ba24bdd6a31af30b2fe2))
107
+ - ✨ add @guanghechen/config
108
+ ([f982c65](https://github.com/guanghechen/sora/commit/f982c650b09cafe19311ba24bdd6a31af30b2fe2))
package/lib/cjs/index.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var byte = require('@guanghechen/byte');
4
- var mac = require('@guanghechen/mac');
5
4
  var satisfies = require('semver/functions/satisfies');
5
+ var node_crypto = require('node:crypto');
6
6
  var config_types = require('@guanghechen/config.types');
7
7
 
8
8
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -21,6 +21,14 @@ function invariant(condition, message) {
21
21
  throw new Error(prefix + ': ' + (message instanceof Function ? message() : message));
22
22
  }
23
23
 
24
+ function calcMac(chunks, algorithm) {
25
+ const hash = node_crypto.createHash(algorithm);
26
+ for (const chunk of chunks)
27
+ hash.update(chunk);
28
+ const mac = hash.digest();
29
+ return Uint8Array.from(mac);
30
+ }
31
+
24
32
  const clazz = 'BaseConfigKeeper';
25
33
  class BaseConfigKeeper {
26
34
  hashAlgorithm;
@@ -67,7 +75,7 @@ class BaseConfigKeeper {
67
75
  invariant(this._instance !== undefined, `[${clazz}.save] No valid data holding.`);
68
76
  const data = await this.serialize(this._instance);
69
77
  const content = this.stringify(data);
70
- const __mac__ = byte.bytes2text(mac.calcMac([byte.text2bytes(content, 'utf8')], this.hashAlgorithm), 'hex');
78
+ const __mac__ = byte.bytes2text(calcMac([byte.text2bytes(content, 'utf8')], this.hashAlgorithm), 'hex');
71
79
  const __nonce__ = this.nonce(this._nonce);
72
80
  const config = {
73
81
  __version__: this.__version__,
@@ -86,8 +94,8 @@ class BaseConfigKeeper {
86
94
  invariant(typeof __version__ === 'string' && typeof __mac__ === 'string', () => `[${clazz}.load] Bad config, invalid fields. (${JSON.stringify(config)})`);
87
95
  invariant(this.compatible(__version__), `[${clazz}.load] Version not compatible. expect(${this.__compatible_version__}), received(${__version__})`);
88
96
  const content = this.stringify(data);
89
- const mac$1 = byte.bytes2text(mac.calcMac([byte.text2bytes(content, 'utf8')], this.hashAlgorithm), 'hex');
90
- invariant(mac$1 === config.__mac__, () => `[${clazz}.load] Bad config, mac is not matched.`);
97
+ const mac = byte.bytes2text(calcMac([byte.text2bytes(content, 'utf8')], this.hashAlgorithm), 'hex');
98
+ invariant(mac === config.__mac__, () => `[${clazz}.load] Bad config, mac is not matched.`);
91
99
  const instance = await this.deserialize(data);
92
100
  return instance;
93
101
  }
package/lib/esm/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { bytes2text, randomBytes, text2bytes } from '@guanghechen/byte';
2
- import { calcMac } from '@guanghechen/mac';
3
2
  import satisfies from 'semver/functions/satisfies.js';
3
+ import { createHash } from 'node:crypto';
4
4
  export * from '@guanghechen/config.types';
5
5
 
6
6
  const isProduction = process.env.NODE_ENV === 'production';
@@ -15,6 +15,14 @@ function invariant(condition, message) {
15
15
  throw new Error(prefix + ': ' + (message instanceof Function ? message() : message));
16
16
  }
17
17
 
18
+ function calcMac(chunks, algorithm) {
19
+ const hash = createHash(algorithm);
20
+ for (const chunk of chunks)
21
+ hash.update(chunk);
22
+ const mac = hash.digest();
23
+ return Uint8Array.from(mac);
24
+ }
25
+
18
26
  const clazz = 'BaseConfigKeeper';
19
27
  class BaseConfigKeeper {
20
28
  hashAlgorithm;
@@ -1,8 +1,9 @@
1
1
  import { IConfigKeeper, IConfig } from '@guanghechen/config.types';
2
2
  export * from '@guanghechen/config.types';
3
- import { IHashAlgorithm } from '@guanghechen/mac';
4
3
  import { ITextResource } from '@guanghechen/resource.types';
5
4
 
5
+ type IHashAlgorithm = 'md5' | 'sha1' | 'sha256' | 'sha512';
6
+
6
7
  interface IBaseConfigKeeperProps {
7
8
  /**
8
9
  * The resource which hold the config data.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guanghechen/config",
3
- "version": "1.0.0-alpha.12",
3
+ "version": "1.0.0-alpha.14",
4
4
  "author": {
5
5
  "name": "guanghechen",
6
6
  "url": "https://github.com/guanghechen/"
@@ -8,10 +8,10 @@
8
8
  "description": "Utilities for defining config followed by semantic version.",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/guanghechen/sora/tree/@guanghechen/config@1.0.0-alpha.11",
11
+ "url": "https://github.com/guanghechen/sora/tree/@guanghechen/config@1.0.0-alpha.13",
12
12
  "directory": "packages/config"
13
13
  },
14
- "homepage": "https://github.com/guanghechen/sora/tree/@guanghechen/config@1.0.0-alpha.11/packages/config#readme",
14
+ "homepage": "https://github.com/guanghechen/sora/tree/@guanghechen/config@1.0.0-alpha.13/packages/config#readme",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
@@ -42,12 +42,11 @@
42
42
  "dependencies": {
43
43
  "@guanghechen/byte": "^1.0.0-alpha.5",
44
44
  "@guanghechen/config.types": "^1.0.0-alpha.5",
45
- "@guanghechen/mac": "^1.0.0-alpha.4",
46
45
  "@guanghechen/resource.types": "^1.0.0-alpha.4",
47
46
  "semver": "^7.5.4"
48
47
  },
49
48
  "devDependencies": {
50
49
  "@guanghechen/internal": "^1.0.0-alpha.0"
51
50
  },
52
- "gitHead": "211a6b5e5664a3fd62d34e3de3e025241aeb4437"
51
+ "gitHead": "7df798c4579de2f64ddc74f238bc2a6ed1b40bb1"
53
52
  }