@thi.ng/resolve-map 6.1.0 → 6.2.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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2022-05-23T11:18:39Z
3
+ - **Last updated**: 2022-07-07T12:39:33Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,16 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [6.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/resolve-map@6.2.0) (2022-07-07)
13
+
14
+ #### 🚀 Features
15
+
16
+ - unwrap all resolved() values in result ([888fa33](https://github.com/thi-ng/umbrella/commit/888fa33))
17
+ - add unwrapResolved() to unwrap any values wrapped via `resolved()`
18
+ - update resolveMap/Array()
19
+ - update doc strings
20
+ - update tests
21
+
12
22
  ## [6.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/resolve-map@6.1.0) (2022-05-23)
13
23
 
14
24
  #### 🚀 Features
package/README.md CHANGED
@@ -76,7 +76,7 @@ node --experimental-repl-await
76
76
  > const resolveMap = await import("@thi.ng/resolve-map");
77
77
  ```
78
78
 
79
- Package sizes (gzipped, pre-treeshake): ESM: 1.03 KB
79
+ Package sizes (gzipped, pre-treeshake): ESM: 1.08 KB
80
80
 
81
81
  ## Dependencies
82
82
 
@@ -302,10 +302,11 @@ res.e(2);
302
302
 
303
303
  Values can be protected from further resolution attempts by wrapping them via
304
304
  [`resolved()`](https://docs.thi.ng/umbrella/resolve-map/modules.html#resolved).
305
- The wrapped value can be later obtained via the standard [`IDeref`
306
- interface/mechanism](https://docs.thi.ng/umbrella/api/interfaces/IDeref.html).
307
- In lookup/resolution functions, the unwrapped value will be supplied, no
308
- `.deref()` necessary there.
305
+ These wrapped values are only used during the resolution phase and the final
306
+ result object/array will only contain the original, unwrapped values. Unwrapped
307
+ values will also be supplied to any lookup functions, no
308
+ [`.deref()`](https://docs.thi.ng/umbrella/api/interfaces/IDeref.html) necessary
309
+ there.
309
310
 
310
311
  ## Authors
311
312
 
package/index.d.ts CHANGED
@@ -20,9 +20,10 @@ export declare type LookupPath = NumOrString[];
20
20
  * level (the original object passed to this function).
21
21
  *
22
22
  * Values can be protected from further resolution attempts by wrapping them via
23
- * {@link resolved}. The wrapped value can be later obtained via the standard
24
- * {@link @thi.ng/api#IDeref} interface/mechanism. In lookup functions, the
25
- * unwrapped value will be supplied, no `.deref()` necessary there.
23
+ * {@link resolved}. These wrapped values are only used during the resolution
24
+ * phase and the final result object/array will only contain the original,
25
+ * unwrapped values. Unwrapped values will also be supplied to any lookup
26
+ * functions, no `.deref()` necessary there.
26
27
  *
27
28
  * @example
28
29
  * ```ts
package/index.js CHANGED
@@ -16,19 +16,21 @@ export function resolve(root, prefix = "@") {
16
16
  }
17
17
  return root;
18
18
  }
19
+ /** @internal */
19
20
  const resolveMap = (obj, prefix, root, path = [], resolved = {}, stack = []) => {
20
21
  root = root || obj;
21
22
  for (let k in obj) {
22
23
  _resolve(root, [...path, k], resolved, stack, prefix);
23
24
  }
24
- return obj;
25
+ return path.length ? obj : unwrapResolved(obj, resolved);
25
26
  };
27
+ /** @internal */
26
28
  const resolveArray = (arr, prefix, root, path = [], resolved = {}, stack = []) => {
27
29
  root = root || arr;
28
30
  for (let k = 0, n = arr.length; k < n; k++) {
29
31
  _resolve(root, [...path, k], resolved, stack, prefix);
30
32
  }
31
- return arr;
33
+ return path.length ? arr : unwrapResolved(arr, resolved);
32
34
  };
33
35
  /**
34
36
  * The actual recursive resolution mechanism. Takes root object, key
@@ -40,6 +42,8 @@ const resolveArray = (arr, prefix, root, path = [], resolved = {}, stack = []) =
40
42
  * @param path -
41
43
  * @param resolved -
42
44
  * @param stack -
45
+ *
46
+ * @internal
43
47
  */
44
48
  const _resolve = (root, path, resolved, stack, prefix) => {
45
49
  const pathID = path.join("/");
@@ -95,6 +99,8 @@ const _resolve = (root, path, resolved, stack, prefix) => {
95
99
  * @param root -
96
100
  * @param path -
97
101
  * @param resolved -
102
+ *
103
+ * @internal
98
104
  */
99
105
  const resolvePath = (root, path, resolved, stack, prefix) => {
100
106
  // temporarily remove current path to avoid cycle detection
@@ -123,6 +129,8 @@ const resolvePath = (root, path, resolved, stack, prefix) => {
123
129
  * @param resolve -
124
130
  * @param pathID - current base path for marking
125
131
  * @param resolved -
132
+ *
133
+ * @internal
126
134
  */
127
135
  const resolveFunction = (fn, resolve, pathID, resolved) => {
128
136
  const match = RE_ARGS.exec(fn.toString());
@@ -142,6 +150,7 @@ const resolveFunction = (fn, resolve, pathID, resolved) => {
142
150
  markResolved(res, pathID, resolved);
143
151
  return res;
144
152
  };
153
+ /** @internal */
145
154
  const markResolved = (v, path, resolved) => {
146
155
  resolved[path] = true;
147
156
  if (isPlainObject(v)) {
@@ -151,6 +160,7 @@ const markResolved = (v, path, resolved) => {
151
160
  markArrayResolved(v, path, resolved);
152
161
  }
153
162
  };
163
+ /** @internal */
154
164
  const markObjResolved = (obj, path, resolved) => {
155
165
  let v, p;
156
166
  for (let k in obj) {
@@ -159,6 +169,7 @@ const markObjResolved = (obj, path, resolved) => {
159
169
  markResolved(v, p, resolved);
160
170
  }
161
171
  };
172
+ /** @internal */
162
173
  const markArrayResolved = (arr, path, resolved) => {
163
174
  let v, p;
164
175
  for (let i = 0, n = arr.length; i < n; i++) {
@@ -237,3 +248,19 @@ const getInUnsafe = (obj, path) => {
237
248
  }
238
249
  return [res, isResolved];
239
250
  };
251
+ /**
252
+ * Unwraps all known values wrapped using {@link Resolved} in-place.
253
+ *
254
+ * @param root
255
+ * @param resolved
256
+ *
257
+ * @internal
258
+ */
259
+ const unwrapResolved = (root, resolved) => {
260
+ for (let path in resolved) {
261
+ const $path = path.split("/");
262
+ const val = getInUnsafe(root, $path);
263
+ val[1] && mutInUnsafe(root, $path, val[0]);
264
+ }
265
+ return root;
266
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/resolve-map",
3
- "version": "6.1.0",
3
+ "version": "6.2.0",
4
4
  "description": "DAG resolution of vanilla objects & arrays with internally linked values",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -34,18 +34,18 @@
34
34
  "test": "testament test"
35
35
  },
36
36
  "dependencies": {
37
- "@thi.ng/api": "^8.3.6",
38
- "@thi.ng/checks": "^3.1.6",
39
- "@thi.ng/errors": "^2.1.6",
40
- "@thi.ng/paths": "^5.1.6"
37
+ "@thi.ng/api": "^8.3.7",
38
+ "@thi.ng/checks": "^3.2.1",
39
+ "@thi.ng/errors": "^2.1.7",
40
+ "@thi.ng/paths": "^5.1.8"
41
41
  },
42
42
  "devDependencies": {
43
- "@microsoft/api-extractor": "^7.23.1",
44
- "@thi.ng/testament": "^0.2.7",
43
+ "@microsoft/api-extractor": "^7.25.0",
44
+ "@thi.ng/testament": "^0.2.8",
45
45
  "rimraf": "^3.0.2",
46
46
  "tools": "^0.0.1",
47
- "typedoc": "^0.22.15",
48
- "typescript": "^4.6.4"
47
+ "typedoc": "^0.22.17",
48
+ "typescript": "^4.7.3"
49
49
  },
50
50
  "keywords": [
51
51
  "configuration",
@@ -76,5 +76,5 @@
76
76
  ],
77
77
  "year": 2018
78
78
  },
79
- "gitHead": "0b6722006c2abbd917f115be290402c380fec87b\n"
79
+ "gitHead": "04acabdda49dfcfe8cdcf044401f25ce23c872d0\n"
80
80
  }