@nodesecure/rc 1.3.0 → 1.4.0
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/README.md +73 -18
- package/dist/functions/memoize.d.ts +14 -0
- package/dist/functions/memoize.js +20 -0
- package/dist/functions/memoize.js.map +1 -0
- package/dist/functions/read.d.ts +6 -0
- package/dist/functions/read.js +5 -1
- package/dist/functions/read.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://user-images.githubusercontent.com/4438263/216045720-779bf16d-1d35-409f-a0e6-4019bda8edde.jpg" alt="@nodesecure/rc">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://github.com/NodeSecure/rc">
|
|
7
|
+
<img src="https://img.shields.io/badge/dynamic/json.svg?style=for-the-badge&url=https://raw.githubusercontent.com/NodeSecure/rc/master/package.json&query=$.version&label=Version" alt="npm version">
|
|
8
|
+
</a>
|
|
9
|
+
<a href="https://github.com/NodeSecure/rc/blob/master/LICENSE">
|
|
10
|
+
<img src="https://img.shields.io/github/license/Naereen/StrapDown.js.svg?style=for-the-badge" alt="license">
|
|
11
|
+
</a>
|
|
12
|
+
<a href="https://api.securityscorecards.dev/projects/github.com/NodeSecure/rc">
|
|
13
|
+
<img src="https://api.securityscorecards.dev/projects/github.com/NodeSecure/rc/badge?style=for-the-badge" alt="ossf scorecard">
|
|
14
|
+
</a>
|
|
15
|
+
<a href="https://github.com/NodeSecure/rc/actions?query=workflow%3A%22Node.js+CI%22">
|
|
16
|
+
<img src="https://img.shields.io/github/actions/workflow/status/NodeSecure/rc/main.yml?style=for-the-badge" alt="github ci workflow">
|
|
17
|
+
</a>
|
|
18
|
+
</p>
|
|
9
19
|
|
|
10
20
|
NodeSecure runtime configuration.
|
|
11
21
|
|
|
@@ -25,7 +35,7 @@ $ yarn add @nodesecure/rc
|
|
|
25
35
|
|
|
26
36
|
## Usage example
|
|
27
37
|
|
|
28
|
-
|
|
38
|
+
read:
|
|
29
39
|
|
|
30
40
|
```ts
|
|
31
41
|
import * as RC from "@nodesecure/rc";
|
|
@@ -36,7 +46,7 @@ const configurationPayload = (
|
|
|
36
46
|
console.log(configurationPayload);
|
|
37
47
|
```
|
|
38
48
|
|
|
39
|
-
|
|
49
|
+
write:
|
|
40
50
|
|
|
41
51
|
```ts
|
|
42
52
|
import assert from "node:assert/strict";
|
|
@@ -51,6 +61,22 @@ const result = (await RC.write(void 0, writeOpts)).unwrap();
|
|
|
51
61
|
assert.strictEqual(result, void 0);
|
|
52
62
|
```
|
|
53
63
|
|
|
64
|
+
memoize/memoized:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import * as RC from "@nodesecure/rc";
|
|
68
|
+
import assert from "node:assert";
|
|
69
|
+
|
|
70
|
+
const configurationPayload = (
|
|
71
|
+
await RC.read(void 0, { createMode: "ci" })
|
|
72
|
+
).unwrap()
|
|
73
|
+
|
|
74
|
+
RC.memoize(configurationPayload, { overwrite: true });
|
|
75
|
+
|
|
76
|
+
const memoizedPayload = RC.memoized();
|
|
77
|
+
assert.deepEqual(configurationPayload, memoizedPayload);
|
|
78
|
+
```
|
|
79
|
+
|
|
54
80
|
> 👀 .read and .write return Rust like [Result](https://doc.rust-lang.org/std/result/) object. Under the hood we use [ts-results](https://github.com/vultix/ts-results) to achieve this.
|
|
55
81
|
|
|
56
82
|
## API
|
|
@@ -73,6 +99,12 @@ interface createReadOptions {
|
|
|
73
99
|
* @default `minimal`
|
|
74
100
|
*/
|
|
75
101
|
createMode?: RCGenerationMode | RCGenerationMode[];
|
|
102
|
+
/**
|
|
103
|
+
* RC automatic caching option. This option allows to cache a configuration passed in parameter.
|
|
104
|
+
*
|
|
105
|
+
* @default false
|
|
106
|
+
*/
|
|
107
|
+
memoize?: boolean;
|
|
76
108
|
}
|
|
77
109
|
|
|
78
110
|
export type readOptions = RequireAtLeastOne<
|
|
@@ -115,6 +147,28 @@ export interface writePartialPayload {
|
|
|
115
147
|
|
|
116
148
|
export type writeOptions = writeCompletePayload | writePartialPayload;
|
|
117
149
|
```
|
|
150
|
+
### memoize(payload: Partial< RC >, options: memoizeOptions = {}): void
|
|
151
|
+
By default, the memory API overwrites the previous stored payload. When the `OVERWRITE` option is `false`, it merges new properties with existing properties.
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
export interface memoizeOptions {
|
|
155
|
+
overwrite?: boolean;
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
The `overwrite` option is used to specify whether data should be overwritten or merged.
|
|
159
|
+
|
|
160
|
+
### memoized(options: memoizedOptions): Partial< RC > | null
|
|
161
|
+
This method returns null, when the default value is null, otherwise, it returns the current value of `memoizedValue`.
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
export interface memoizedOptions {
|
|
165
|
+
defaultValue: Partial<RC>;
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
If the `defaultValue` property is at null, then this value will be returned when `memoized` is called.
|
|
169
|
+
|
|
170
|
+
### clearMemoized(): void
|
|
171
|
+
Clear/reset memoized RC
|
|
118
172
|
|
|
119
173
|
### homedir(): string
|
|
120
174
|
|
|
@@ -168,9 +222,7 @@ console.log(RC.JSONSchema);
|
|
|
168
222
|
## Contributors ✨
|
|
169
223
|
|
|
170
224
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
171
|
-
|
|
172
|
-
[](#contributors-)
|
|
173
|
-
|
|
225
|
+
[](#contributors-)
|
|
174
226
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
175
227
|
|
|
176
228
|
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
|
@@ -179,11 +231,14 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
179
231
|
<!-- prettier-ignore-start -->
|
|
180
232
|
<!-- markdownlint-disable -->
|
|
181
233
|
<table>
|
|
182
|
-
<
|
|
183
|
-
<
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
234
|
+
<tbody>
|
|
235
|
+
<tr>
|
|
236
|
+
<td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/thomas-gentilhomme/"><img src="https://avatars.githubusercontent.com/u/4438263?v=4?s=100" width="100px;" alt="Gentilhomme"/><br /><sub><b>Gentilhomme</b></sub></a><br /><a href="https://github.com/NodeSecure/rc/commits?author=fraxken" title="Code">💻</a> <a href="https://github.com/NodeSecure/rc/issues?q=author%3Afraxken" title="Bug reports">🐛</a> <a href="https://github.com/NodeSecure/rc/pulls?q=is%3Apr+reviewed-by%3Afraxken" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/NodeSecure/rc/commits?author=fraxken" title="Documentation">📖</a> <a href="#security-fraxken" title="Security">🛡️</a></td>
|
|
237
|
+
<td align="center" valign="top" width="14.28%"><a href="https://dev.to/antoinecoulon"><img src="https://avatars.githubusercontent.com/u/43391199?v=4?s=100" width="100px;" alt="Antoine Coulon"/><br /><sub><b>Antoine Coulon</b></sub></a><br /><a href="https://github.com/NodeSecure/rc/commits?author=antoine-coulon" title="Code">💻</a> <a href="https://github.com/NodeSecure/rc/issues?q=author%3Aantoine-coulon" title="Bug reports">🐛</a> <a href="https://github.com/NodeSecure/rc/pulls?q=is%3Apr+reviewed-by%3Aantoine-coulon" title="Reviewed Pull Requests">👀</a></td>
|
|
238
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/PierreDemailly"><img src="https://avatars.githubusercontent.com/u/39910767?v=4?s=100" width="100px;" alt="PierreD"/><br /><sub><b>PierreD</b></sub></a><br /><a href="https://github.com/NodeSecure/rc/commits?author=PierreDemailly" title="Code">💻</a></td>
|
|
239
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/fabnguess"><img src="https://avatars.githubusercontent.com/u/72697416?v=4?s=100" width="100px;" alt="Kouadio Fabrice Nguessan"/><br /><sub><b>Kouadio Fabrice Nguessan</b></sub></a><br /><a href="https://github.com/NodeSecure/rc/commits?author=fabnguess" title="Code">💻</a> <a href="#maintenance-fabnguess" title="Maintenance">🚧</a></td>
|
|
240
|
+
</tr>
|
|
241
|
+
</tbody>
|
|
187
242
|
</table>
|
|
188
243
|
|
|
189
244
|
<!-- markdownlint-restore -->
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RC } from "../rc.js";
|
|
2
|
+
export interface memoizeOptions {
|
|
3
|
+
/**
|
|
4
|
+
* If enabled it will overwrite (crush) the previous memoized RC
|
|
5
|
+
* @default true
|
|
6
|
+
*/
|
|
7
|
+
overwrite?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function memoize(payload: Partial<RC>, options?: memoizeOptions): void;
|
|
10
|
+
export interface memoizedOptions {
|
|
11
|
+
defaultValue: Partial<RC>;
|
|
12
|
+
}
|
|
13
|
+
export declare function memoized(options?: memoizedOptions): Partial<RC> | null;
|
|
14
|
+
export declare function clearMemoized(): void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Import Third-party Dependencies
|
|
2
|
+
import merge from "lodash.merge";
|
|
3
|
+
let memoizedValue = null;
|
|
4
|
+
export function memoize(payload, options = {}) {
|
|
5
|
+
const { overwrite = true } = options;
|
|
6
|
+
if (memoizedValue === null || overwrite) {
|
|
7
|
+
memoizedValue = payload;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
memoizedValue = merge({}, memoizedValue, payload);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export function memoized(options) {
|
|
14
|
+
const { defaultValue = null } = options ?? {};
|
|
15
|
+
return memoizedValue ?? defaultValue;
|
|
16
|
+
}
|
|
17
|
+
export function clearMemoized() {
|
|
18
|
+
memoizedValue = null;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=memoize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../src/functions/memoize.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,OAAO,KAAK,MAAM,cAAc,CAAC;AAKjC,IAAI,aAAa,GAAuB,IAAI,CAAC;AAU7C,MAAM,UAAU,OAAO,CACrB,OAAoB,EACpB,UAA0B,EAAE;IAE5B,MAAM,EAAE,SAAS,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IAErC,IAAI,aAAa,KAAK,IAAI,IAAI,SAAS,EAAE;QACvC,aAAa,GAAG,OAAO,CAAC;KACzB;SACI;QACH,aAAa,GAAG,KAAK,CAAC,EAAE,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;KACnD;AACH,CAAC;AAMD,MAAM,UAAU,QAAQ,CACtB,OAAyB;IAEzB,MAAM,EAAE,YAAY,GAAG,IAAI,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAE9C,OAAO,aAAa,IAAI,YAAY,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,aAAa,GAAG,IAAI,CAAC;AACvB,CAAC"}
|
package/dist/functions/read.d.ts
CHANGED
|
@@ -15,6 +15,12 @@ interface createReadOptions {
|
|
|
15
15
|
* @default `minimal`
|
|
16
16
|
*/
|
|
17
17
|
createMode?: RCGenerationMode | RCGenerationMode[];
|
|
18
|
+
/**
|
|
19
|
+
* RC automatic caching option. This option allows to cache a configuration passed in parameter.
|
|
20
|
+
*
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
memoize?: boolean;
|
|
18
24
|
}
|
|
19
25
|
export type readOptions = RequireAtLeastOne<createReadOptions, "createIfDoesNotExist" | "createMode">;
|
|
20
26
|
export declare function read(location?: string, options?: readOptions): Promise<Result<RC, NodeJS.ErrnoException>>;
|
package/dist/functions/read.js
CHANGED
|
@@ -7,11 +7,12 @@ import TR from "ts-results";
|
|
|
7
7
|
// Import Internal Dependencies
|
|
8
8
|
import { JSONSchema, generateDefaultRC } from "../rc.js";
|
|
9
9
|
import * as CONSTANTS from "../constants.js";
|
|
10
|
+
import { memoize } from "./memoize.js";
|
|
10
11
|
// CONSTANTS
|
|
11
12
|
const { Ok, Err } = TR;
|
|
12
13
|
export async function read(location = process.cwd(), options = Object.create(null)) {
|
|
13
14
|
try {
|
|
14
|
-
const { createIfDoesNotExist = Boolean(options.createMode), createMode } = options;
|
|
15
|
+
const { createIfDoesNotExist = Boolean(options.createMode), createMode, memoize: memoizeRc = false } = options;
|
|
15
16
|
const cfgPath = path.join(location, CONSTANTS.CONFIGURATION_NAME);
|
|
16
17
|
const cfg = new Config(cfgPath, {
|
|
17
18
|
defaultSchema: JSONSchema,
|
|
@@ -22,6 +23,9 @@ export async function read(location = process.cwd(), options = Object.create(nul
|
|
|
22
23
|
await once(cfg, "configWritten");
|
|
23
24
|
}
|
|
24
25
|
const result = cfg.payload;
|
|
26
|
+
if (memoizeRc) {
|
|
27
|
+
memoize(result);
|
|
28
|
+
}
|
|
25
29
|
await cfg.close();
|
|
26
30
|
return new Ok(result);
|
|
27
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../src/functions/read.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC,kCAAkC;AAClC,OAAO,MAAM,MAAM,gBAAgB,CAAC;AACpC,OAAO,EAAc,MAAM,YAAY,CAAC;AAGxC,+BAA+B;AAC/B,OAAO,EAAM,UAAU,EAAE,iBAAiB,EAAoB,MAAM,UAAU,CAAC;AAC/E,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"read.js","sourceRoot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,OAAO,CAAC;QAE3B,IAAI,SAAS,EAAE;YACb,OAAO,CAAC,MAAM,CAAC,CAAC;SACjB;QAED,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;QAElB,OAAO,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC;KACvB;IACD,OAAO,KAAK,EAAE;QACZ,OAAO,IAAI,GAAG,CAAC,KAA8B,CAAC,CAAC;KAChD;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAM,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAM,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nodesecure/rc",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "NodeSecure runtime configuration",
|
|
5
5
|
"exports": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -35,31 +35,31 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://github.com/NodeSecure/rc#readme",
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@nodesecure/eslint-config": "^1.
|
|
38
|
+
"@nodesecure/eslint-config": "^1.7.0",
|
|
39
39
|
"@types/chai": "^4.3.4",
|
|
40
40
|
"@types/lodash.merge": "^4.6.7",
|
|
41
41
|
"@types/mocha": "^10.0.1",
|
|
42
|
-
"@types/node": "^18.
|
|
42
|
+
"@types/node": "^18.15.3",
|
|
43
43
|
"@types/zen-observable": "^0.8.3",
|
|
44
44
|
"ajv": "^8.12.0",
|
|
45
45
|
"c8": "^7.12.0",
|
|
46
46
|
"chai": "^4.3.7",
|
|
47
|
-
"eslint": "^8.
|
|
48
|
-
"lodash.merge": "^4.6.2",
|
|
47
|
+
"eslint": "^8.36.0",
|
|
49
48
|
"mocha": "^10.2.0",
|
|
50
49
|
"tape": "^5.6.3",
|
|
51
50
|
"ts-node": "^10.9.1",
|
|
52
|
-
"tsd": "^0.
|
|
53
|
-
"typescript": "^
|
|
51
|
+
"tsd": "^0.28.0",
|
|
52
|
+
"typescript": "^5.0.2"
|
|
54
53
|
},
|
|
55
54
|
"dependencies": {
|
|
56
|
-
"@nodesecure/i18n": "^2.
|
|
57
|
-
"@nodesecure/js-x-ray": "^
|
|
55
|
+
"@nodesecure/i18n": "^3.2.0",
|
|
56
|
+
"@nodesecure/js-x-ray": "^6.0.1",
|
|
58
57
|
"@nodesecure/vuln": "^1.7.0",
|
|
59
58
|
"@slimio/config": "^1.2.0",
|
|
59
|
+
"lodash.merge": "^4.6.2",
|
|
60
60
|
"ts-results": "^3.3.0",
|
|
61
61
|
"tslib": "^2.4.1",
|
|
62
|
-
"type-fest": "^3.
|
|
62
|
+
"type-fest": "^3.6.1"
|
|
63
63
|
},
|
|
64
64
|
"tsd": {
|
|
65
65
|
"directory": "test/types",
|