@rimbu/deep 0.11.2 → 0.12.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/dist/main/deep.js +211 -0
- package/dist/main/deep.js.map +1 -0
- package/dist/main/index.js +7 -9
- package/dist/main/index.js.map +1 -1
- package/dist/main/internal.js +6 -4
- package/dist/main/internal.js.map +1 -1
- package/dist/main/match.js +160 -199
- package/dist/main/match.js.map +1 -1
- package/dist/main/patch.js +101 -125
- package/dist/main/patch.js.map +1 -1
- package/dist/main/path.js +109 -62
- package/dist/main/path.js.map +1 -1
- package/dist/main/protected.js +0 -19
- package/dist/main/protected.js.map +1 -1
- package/dist/main/selector.js +40 -0
- package/dist/main/selector.js.map +1 -0
- package/dist/main/tuple.js.map +1 -1
- package/dist/module/deep.js +192 -0
- package/dist/module/deep.js.map +1 -0
- package/dist/module/index.js +9 -1
- package/dist/module/index.js.map +1 -1
- package/dist/module/internal.js +4 -4
- package/dist/module/internal.js.map +1 -1
- package/dist/module/match.js +159 -179
- package/dist/module/match.js.map +1 -1
- package/dist/module/patch.js +91 -112
- package/dist/module/patch.js.map +1 -1
- package/dist/module/path.js +99 -44
- package/dist/module/path.js.map +1 -1
- package/dist/module/protected.js +1 -17
- package/dist/module/protected.js.map +1 -1
- package/dist/module/selector.js +36 -0
- package/dist/module/selector.js.map +1 -0
- package/dist/module/tuple.js.map +1 -1
- package/dist/types/deep.d.ts +284 -0
- package/dist/types/index.d.ts +10 -1
- package/dist/types/internal.d.ts +7 -4
- package/dist/types/match.d.ts +74 -80
- package/dist/types/patch.d.ts +57 -50
- package/dist/types/path.d.ts +177 -34
- package/dist/types/protected.d.ts +1 -16
- package/dist/types/selector.d.ts +47 -0
- package/dist/types/tuple.d.ts +10 -0
- package/package.json +4 -4
- package/src/deep.ts +362 -0
- package/src/index.ts +14 -10
- package/src/internal.ts +7 -4
- package/src/match.ts +396 -212
- package/src/patch.ts +173 -176
- package/src/path.ts +400 -74
- package/src/protected.ts +14 -25
- package/src/selector.ts +90 -0
- package/src/tuple.ts +12 -0
package/dist/module/match.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.js","sourceRoot":"","sources":["../../src/match.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"match.js","sourceRoot":"","sources":["../../src/match.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,GAGX,MAAM,aAAa,CAAC;AAkIrB;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,KAAK,CACnB,MAAS,EACT,OAAoB,EACpB,iBAAuC,SAAS;IAEhD,OAAO,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAc,EAAE,cAAc,CAAC,CAAC;AAC5E,CAAC;AAED;;GAEG;AACH,SAAS,UAAU,CACjB,MAAS,EACT,MAAS,EACT,IAAO,EACP,OAAgC,EAChC,cAAoC;IAEpC,IAAI,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;QAC9B,6DAA6D;QAC7D,OAAO,IAAI,CAAC;KACb;IAED,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,EAAE;QAC7C,mFAAmF;QACnF,qBAAqB;QACrB,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,IAAI,CAClB,SAAS,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,0BAA0B,OAAO,EAAE,CACnE,CAAC;QAEF,OAAO,KAAK,CAAC;KACd;IAED,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE;QAChC,sDAAsD;QACtD,MAAM,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAE1C,IAAI,CAAC,MAAM,EAAE;YACX,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,IAAI,CAClB,+EAA+E,CAChF,CAAC;SACH;QAED,OAAO,MAAM,CAAC;KACf;IAED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vB,MAAM,MAAM,GAAG,UAAU,CACvB,MAAM,EACN,MAAM,EACN,IAAI,EACJ,QAAQ,CAAC,KAAK,CAAU,EACxB,cAAc,CACf,CAAC;gBAEF,IAAI,MAAM,EAAE;oBACV,IAAI,SAAS,EAAE;wBACb,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,IAAI,CAClB,kDAAkD,CACnD,CAAC;wBAEF,OAAO,KAAK,CAAC;qBACd;oBAED,SAAS,GAAG,IAAI,CAAC;iBAClB;aACF;YAED,IAAI,CAAC,SAAS,EAAE;gBACd,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,IAAI,CAAC,4CAA4C,CAAC,CAAC;aACpE;YAED,OAAO,SAAS,CAAC;SAClB;QACD,KAAK,MAAM,CAAC,CAAC;YACX,mCAAmC;YACnC,OAAO,EAAE,KAAK,GAAG,MAAM,EAAE;gBACvB,MAAM,MAAM,GAAG,UAAU,CACvB,MAAM,EACN,MAAM,EACN,IAAI,EACJ,QAAQ,CAAC,KAAK,CAAU,EACxB,cAAc,CACf,CAAC;gBAEF,IAAI,MAAM,EAAE;oBACV,OAAO,IAAI,CAAC;iBACb;aACF;YAED,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,IAAI,CAAC,0CAA0C,CAAC,CAAC;YAEjE,OAAO,KAAK,CAAC;SACd;KACF;AACH,CAAC"}
|
package/dist/module/patch.js
CHANGED
|
@@ -1,136 +1,115 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export var Patch;
|
|
3
|
-
(function (Patch) {
|
|
4
|
-
/**
|
|
5
|
-
* Returns a function that patches a given `value` with the given `patchItems`.
|
|
6
|
-
* @typeparam T - the patch value type
|
|
7
|
-
* @typeparam Q - the input value type
|
|
8
|
-
* @param patchItems - a number of `Patch` objects that patch a given value of type T.
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* const items = [{ a: 1, b: 'a' }, { a: 2, b: 'b' }]
|
|
12
|
-
* items.map(Patch.create({ a: v => v + 1 }))
|
|
13
|
-
* // => [{ a: 2, b: 'a' }, { a: 3, b: 'b' }]
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
function create(...patchItems) {
|
|
17
|
-
return (value) => patch(value, ...patchItems);
|
|
18
|
-
}
|
|
19
|
-
Patch.create = create;
|
|
20
|
-
})(Patch || (Patch = {}));
|
|
21
|
-
class NestedObj {
|
|
22
|
-
constructor(patchDataItems) {
|
|
23
|
-
this.patchDataItems = patchDataItems;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Returns a nested patch object based on the given `patchDataItems` that work on a subpart
|
|
28
|
-
* of a larger object to be patched.
|
|
29
|
-
* @typeparam T - the input value type
|
|
30
|
-
* @typeparam R - the root object type
|
|
31
|
-
* @typeparam Q - the patch type
|
|
32
|
-
* @param patchDataItems - a number of `Patch` objects to be applied to the subpart of the object
|
|
33
|
-
* @example
|
|
34
|
-
* ```ts
|
|
35
|
-
* patch({ a: 1, b: { c: true, d: 'a' } }, { b: patchNested({ d: 'b' }) })
|
|
36
|
-
* // => { a: 1, b: { c: true, d: 'b' } }
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export function patchNested(...patchDataItems) {
|
|
40
|
-
return new NestedObj(patchDataItems);
|
|
41
|
-
}
|
|
1
|
+
import { isPlainObj } from '@rimbu/base';
|
|
42
2
|
/**
|
|
43
3
|
* Returns an immutably updated version of the given `value` where the given `patchItems` have been
|
|
44
4
|
* applied to the result.
|
|
5
|
+
* The Rimbu patch notation is as follows:
|
|
6
|
+
* - if the target is a simple value or array, the patch can be the same type or a function returning the same type
|
|
7
|
+
* - if the target is a tuple (array of fixed length), the patch be the same type or an object containing numeric keys with patches indicating the tuple index to patch
|
|
8
|
+
* - if the target is an object, the patch can be the same type, or an array containing partial keys with their patches for the object
|
|
9
|
+
* @typeparam T - the type of the value to patch
|
|
10
|
+
* @typeparam TE - a utility type
|
|
11
|
+
* @typeparam TT - a utility type
|
|
45
12
|
* @param value - the input value to patch
|
|
46
|
-
* @param
|
|
13
|
+
* @param patchItem - the `Patch` value to apply to the input value
|
|
47
14
|
* @example
|
|
48
15
|
* ```ts
|
|
49
16
|
* const input = { a: 1, b: { c: true, d: 'a' } }
|
|
50
|
-
* patch(input, { a: 2 }) // => { a: 2, b: { c: true, d: 'a' } }
|
|
51
|
-
* patch(input
|
|
17
|
+
* patch(input, [{ a: 2 }]) // => { a: 2, b: { c: true, d: 'a' } }
|
|
18
|
+
* patch(input, [{ b: [{ c: (v) => !v }] }] )
|
|
52
19
|
* // => { a: 1, b: { c: false, d: 'a' } }
|
|
53
|
-
* patch(input:
|
|
20
|
+
* patch(input: [{ a: (v) => v + 1, b: [{ d: 'q' }] }] )
|
|
54
21
|
* // => { a: 2, b: { c: true, d: 'q' } }
|
|
55
22
|
* ```
|
|
56
23
|
*/
|
|
57
|
-
export function patch(value,
|
|
58
|
-
|
|
59
|
-
const changedRef = { changed: false };
|
|
60
|
-
const result = processPatch(newValue, newValue, patchItems, changedRef);
|
|
61
|
-
if (changedRef.changed)
|
|
62
|
-
return result;
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
function processPatch(value, root, patchDataItems, changedRef) {
|
|
66
|
-
let i = -1;
|
|
67
|
-
const len = patchDataItems.length;
|
|
68
|
-
while (++i < len) {
|
|
69
|
-
const patchItem = patchDataItems[i];
|
|
70
|
-
if (patchItem instanceof Function) {
|
|
71
|
-
const item = patchItem(patchNested);
|
|
72
|
-
if (item instanceof NestedObj) {
|
|
73
|
-
processPatch(value, root, item.patchDataItems, changedRef);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
processPatchObj(value, root, item, changedRef);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
processPatchObj(value, root, patchItem, changedRef);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return value;
|
|
24
|
+
export function patch(value, patchItem) {
|
|
25
|
+
return patchEntry(value, value, value, patchItem);
|
|
84
26
|
}
|
|
85
|
-
function
|
|
86
|
-
if (
|
|
27
|
+
function patchEntry(value, parent, root, patchItem) {
|
|
28
|
+
if (Object.is(value, patchItem)) {
|
|
29
|
+
// patching a value with itself never changes the value
|
|
87
30
|
return value;
|
|
88
31
|
}
|
|
89
|
-
if (
|
|
90
|
-
|
|
32
|
+
if (typeof value === 'function') {
|
|
33
|
+
// function input, directly return patch
|
|
34
|
+
return patchItem;
|
|
91
35
|
}
|
|
92
|
-
if (
|
|
93
|
-
|
|
36
|
+
if (typeof patchItem === 'function') {
|
|
37
|
+
// function patch always needs to be resolved first
|
|
38
|
+
const item = patchItem(value, parent, root);
|
|
39
|
+
return patchEntry(value, parent, root, item);
|
|
94
40
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
41
|
+
if (isPlainObj(value)) {
|
|
42
|
+
// value is plain object
|
|
43
|
+
return patchPlainObj(value, root, patchItem);
|
|
44
|
+
}
|
|
45
|
+
if (Array.isArray(value)) {
|
|
46
|
+
// value is tuple or array
|
|
47
|
+
return patchArr(value, root, patchItem);
|
|
48
|
+
}
|
|
49
|
+
// value is primitive type or complex object
|
|
50
|
+
return patchItem;
|
|
51
|
+
}
|
|
52
|
+
function patchPlainObj(value, root, patchItem) {
|
|
53
|
+
if (!Array.isArray(patchItem)) {
|
|
54
|
+
// the patch is a complete replacement of the current value
|
|
55
|
+
return patchItem;
|
|
56
|
+
}
|
|
57
|
+
// patch is an array of partial updates
|
|
58
|
+
// copy the input value
|
|
59
|
+
const result = Object.assign({}, value);
|
|
60
|
+
let anyChange = false;
|
|
61
|
+
// loop over patches in array
|
|
62
|
+
for (const entry of patchItem) {
|
|
63
|
+
// update root if needed
|
|
64
|
+
const currentRoot = value === root ? Object.assign({}, result) : root;
|
|
65
|
+
// loop over all the patch keys
|
|
66
|
+
for (const key in entry) {
|
|
67
|
+
// patch the value at the given key with the patch at that key
|
|
68
|
+
const currentValue = result[key];
|
|
69
|
+
const newValue = patchEntry(currentValue, value, currentRoot, entry[key]);
|
|
70
|
+
if (!Object.is(currentValue, newValue)) {
|
|
71
|
+
// if value changed, set it in result and mark change
|
|
72
|
+
anyChange = true;
|
|
73
|
+
result[key] = newValue;
|
|
74
|
+
}
|
|
119
75
|
}
|
|
120
76
|
}
|
|
77
|
+
if (anyChange) {
|
|
78
|
+
// something changed, return new value
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
// nothing changed, return old value
|
|
121
82
|
return value;
|
|
122
83
|
}
|
|
123
|
-
function
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
84
|
+
function patchArr(value, root, patchItem) {
|
|
85
|
+
if (Array.isArray(patchItem)) {
|
|
86
|
+
// value is a normal array
|
|
87
|
+
// patch is a complete replacement of current array
|
|
88
|
+
return patchItem;
|
|
89
|
+
}
|
|
90
|
+
// value is a tuple
|
|
91
|
+
// patch is an object containing numeric keys with function values
|
|
92
|
+
// that update the tuple at the given indices
|
|
93
|
+
// copy the tuple
|
|
94
|
+
const result = [...value];
|
|
95
|
+
let anyChange = false;
|
|
96
|
+
// loop over all index keys in object
|
|
97
|
+
for (const index in patchItem) {
|
|
98
|
+
const numIndex = index;
|
|
99
|
+
// patch the tuple at the given index
|
|
100
|
+
const currentValue = result[numIndex];
|
|
101
|
+
const newValue = patchEntry(currentValue, value, root, patchItem[index]);
|
|
102
|
+
if (!Object.is(newValue, currentValue)) {
|
|
103
|
+
// if value changed, set it in result and mark change
|
|
104
|
+
anyChange = true;
|
|
105
|
+
result[numIndex] = newValue;
|
|
131
106
|
}
|
|
132
|
-
return value;
|
|
133
107
|
}
|
|
134
|
-
|
|
108
|
+
if (anyChange) {
|
|
109
|
+
// something changed, return new value
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
// nothing changed, return old value
|
|
113
|
+
return value;
|
|
135
114
|
}
|
|
136
115
|
//# sourceMappingURL=patch.js.map
|
package/dist/module/patch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../src/patch.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../src/patch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,UAAU,EAAc,MAAM,aAAa,CAAC;AAwFzE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,KAAK,CACnB,KAAQ,EACR,SAAwB;IAExB,OAAO,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAqB,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,UAAU,CACjB,KAAQ,EACR,MAAS,EACT,IAAO,EACP,SAAkC;IAElC,IAAI,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE;QAC/B,uDAAuD;QACvD,OAAO,KAAK,CAAC;KACd;IAED,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE;QAC/B,wCAAwC;QACxC,OAAO,SAAc,CAAC;KACvB;IAED,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE;QACnC,mDAAmD;QACnD,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAE5C,OAAO,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;KAC9C;IAED,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE;QACrB,wBAAwB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CAAC;AACf,CAAC;AAED,SAAS,QAAQ,CACf,KAAQ,EACR,IAAO,EACP,SAAiC;IAEjC,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;QAC5B,0BAA0B;QAC1B,mDAAmD;QAEnD,OAAO,SAAS,CAAC;KAClB;IAED,mBAAmB;IACnB,kEAAkE;IAClE,6CAA6C;IAE7C,iBAAiB;IACjB,MAAM,MAAM,GAAG,CAAC,GAAG,KAAK,CAAM,CAAC;IAC/B,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,qCAAqC;IACrC,KAAK,MAAM,KAAK,IAAI,SAAS,EAAE;QAC7B,MAAM,QAAQ,GAAG,KAAsB,CAAC;QAExC,qCAAqC;QACrC,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;QACtC,MAAM,QAAQ,GAAG,UAAU,CACzB,YAAY,EACZ,KAAK,EACL,IAAI,EACH,SAAiB,CAAC,KAAK,CAAC,CAC1B,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,YAAY,CAAC,EAAE;YACtC,qDAAqD;YACrD,SAAS,GAAG,IAAI,CAAC;YACjB,MAAM,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;SAC7B;KACF;IAED,IAAI,SAAS,EAAE;QACb,sCAAsC;QACtC,OAAO,MAAM,CAAC;KACf;IAED,oCAAoC;IACpC,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/module/path.js
CHANGED
|
@@ -1,53 +1,108 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Deep } from './internal';
|
|
2
2
|
export var Path;
|
|
3
3
|
(function (Path) {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @typeparam T - the object type to select in
|
|
7
|
-
* @typeparam P - a Path in object type T
|
|
8
|
-
* @param source - the object to select in
|
|
9
|
-
* @param path - the path into the object
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* console.log(Path.get({ a: { b: { c: 5 } } }), 'a.b')
|
|
13
|
-
* // => { c: 5 }
|
|
14
|
-
* console.log(Path.get({ a: { b: { c: 5 } } }), 'a.b.c')
|
|
15
|
-
* // => 5
|
|
16
|
-
* ```
|
|
5
|
+
* Regular expression used to split a path string into tokens.
|
|
17
6
|
*/
|
|
18
|
-
|
|
19
|
-
const items = path.split('.');
|
|
20
|
-
let result = source;
|
|
21
|
-
for (const item of items) {
|
|
22
|
-
result = result[item];
|
|
23
|
-
}
|
|
24
|
-
return result;
|
|
25
|
-
}
|
|
26
|
-
Path.get = get;
|
|
7
|
+
Path.stringSplitRegex = /\?\.|\.|\[|\]/g;
|
|
27
8
|
/**
|
|
28
|
-
*
|
|
29
|
-
* @param
|
|
30
|
-
* @param path - the path in the object to update
|
|
31
|
-
* @param value - the new value to set at the given position
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* console.log(Path.update({ a: { b: { c: 5 } } }, 'a.b.c', v => v + 5)
|
|
35
|
-
* // => { a: { b: { c: 6 } } }
|
|
36
|
-
* ```
|
|
9
|
+
* Return the given `path` string split into an array of subpaths.
|
|
10
|
+
* @param path - the input string path
|
|
37
11
|
*/
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
const last = items.pop();
|
|
41
|
-
const root = {};
|
|
42
|
-
let current = root;
|
|
43
|
-
for (const item of items) {
|
|
44
|
-
const next = {};
|
|
45
|
-
current[item] = patchNested(next);
|
|
46
|
-
current = next;
|
|
47
|
-
}
|
|
48
|
-
current[last] = value;
|
|
49
|
-
return patch(source, root);
|
|
12
|
+
function stringSplit(path) {
|
|
13
|
+
return path.split(Path.stringSplitRegex);
|
|
50
14
|
}
|
|
51
|
-
Path.
|
|
15
|
+
Path.stringSplit = stringSplit;
|
|
52
16
|
})(Path || (Path = {}));
|
|
17
|
+
/**
|
|
18
|
+
* Returns the value resulting from selecting the given `path` in the given `source` object.
|
|
19
|
+
* It supports optional chaining for nullable values or values that may be undefined, and also
|
|
20
|
+
* for accessing objects inside an array.
|
|
21
|
+
* There is currently no support for forcing non-null (the `!` operator).
|
|
22
|
+
* @typeparam T - the object type to select in
|
|
23
|
+
* @typeparam P - a Path in object type T
|
|
24
|
+
* @param source - the object to select in
|
|
25
|
+
* @param path - the path into the object
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const value = { a: { b: { c: [{ d: 5 }, { d: 6 }] } } }
|
|
29
|
+
* Deep.getAt(value, 'a.b');
|
|
30
|
+
* // => { c: 5 }
|
|
31
|
+
* Deep.getAt(value, 'a.b.c');
|
|
32
|
+
* // => [{ d: 5 }, { d: 5 }]
|
|
33
|
+
* Deep.getAt(value, 'a.b.c[1]');
|
|
34
|
+
* // => { d: 6 }
|
|
35
|
+
* Deep.getAt(value, 'a.b.c[1]?.d');
|
|
36
|
+
* // => 6
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function getAt(source, path) {
|
|
40
|
+
if (path === '') {
|
|
41
|
+
// empty path always directly returns source value
|
|
42
|
+
return source;
|
|
43
|
+
}
|
|
44
|
+
const items = Path.stringSplit(path);
|
|
45
|
+
// start with `source` as result value
|
|
46
|
+
let result = source;
|
|
47
|
+
for (const item of items) {
|
|
48
|
+
if (undefined === item || item === '' || item === '[') {
|
|
49
|
+
// ignore irrelevant items
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (undefined === result || null === result) {
|
|
53
|
+
// optional chaining assumed and no value available, skip rest of path and return undefined
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
// set current result to subpath value
|
|
57
|
+
result = result[item];
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Patches the value at the given path in the source to the given value.
|
|
63
|
+
* Because the path to update must exist in the `source` object, optional
|
|
64
|
+
* chaining and array indexing is not allowed.
|
|
65
|
+
* @param source - the object to update
|
|
66
|
+
* @param path - the path in the object to update
|
|
67
|
+
* @param patchItem - the patch for the value at the given path
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const value = { a: { b: { c: 5 } } };
|
|
71
|
+
* Deep.patchAt(value, 'a.b.c', v => v + 5);
|
|
72
|
+
* // => { a: { b: { c: 6 } } }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export function patchAt(source, path, patchItem) {
|
|
76
|
+
if (path === '') {
|
|
77
|
+
return Deep.patch(source, patchItem);
|
|
78
|
+
}
|
|
79
|
+
const items = Path.stringSplit(path);
|
|
80
|
+
// creates a patch object based on the current path
|
|
81
|
+
function createPatchPart(index, target) {
|
|
82
|
+
if (index === items.length) {
|
|
83
|
+
// processed all items, return the input `patchItem`
|
|
84
|
+
return patchItem;
|
|
85
|
+
}
|
|
86
|
+
const item = items[index];
|
|
87
|
+
if (undefined === item || item === '') {
|
|
88
|
+
// empty items can be ignored
|
|
89
|
+
return createPatchPart(index + 1, target);
|
|
90
|
+
}
|
|
91
|
+
if (item === '[') {
|
|
92
|
+
// next item is array index, set arrayMode to true
|
|
93
|
+
return createPatchPart(index + 1, target);
|
|
94
|
+
}
|
|
95
|
+
// create object with subPart as property key, and the restuls of processing next parts as value
|
|
96
|
+
const result = {
|
|
97
|
+
[item]: createPatchPart(index + 1, target[item]),
|
|
98
|
+
};
|
|
99
|
+
if (Array.isArray(target)) {
|
|
100
|
+
// target in source object is array/tuple, so the patch should be object
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
// target in source is not an array, so it patch should be an array
|
|
104
|
+
return [result];
|
|
105
|
+
}
|
|
106
|
+
return Deep.patch(source, createPatchPart(0, source));
|
|
107
|
+
}
|
|
53
108
|
//# sourceMappingURL=path.js.map
|
package/dist/module/path.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.js","sourceRoot":"","sources":["../../src/path.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"path.js","sourceRoot":"","sources":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K,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAErC,mDAAmD;IACnD,SAAS,eAAe,CAAC,KAAa,EAAE,MAAW;QACjD,IAAI,KAAK,KAAK,KAAK,CAAC,MAAM,EAAE;YAC1B,oDAAoD;YACpD,OAAO,SAAS,CAAC;SAClB;QAED,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QAE1B,IAAI,SAAS,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE,EAAE;YACrC,6BAA6B;YAC7B,OAAO,eAAe,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;SAC3C;QAED,IAAI,IAAI,KAAK,GAAG,EAAE;YAChB,kDAAkD;YAClD,OAAO,eAAe,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;SAC3C;QAED,gGAAgG;QAChG,MAAM,MAAM,GAAG;YACb,CAAC,IAAI,CAAC,EAAE,eAAe,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;SACjD,CAAC;QAEF,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YACzB,wEAAwE;YACxE,OAAO,MAAM,CAAC;SACf;QAED,mEAAmE;QACnE,OAAO,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
package/dist/module/protected.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Returns the same value wrapped in the `Protected` type.
|
|
3
|
-
* @param value - the value to wrap
|
|
4
|
-
* @note does not perform any runtime protection, it is only a utility to easily add the `Protected`
|
|
5
|
-
* type to a value
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* const obj = Protected({ a: 1, b: { c: true, d: [1] } })
|
|
9
|
-
* obj.a = 2 // compiler error: a is readonly
|
|
10
|
-
* obj.b.c = false // compiler error: c is readonly
|
|
11
|
-
* obj.b.d.push(2) // compiler error: d is a readonly array
|
|
12
|
-
* (obj as any).b.d.push(2) // will actually mutate the object
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
export function Protected(value) {
|
|
16
|
-
return value;
|
|
17
|
-
}
|
|
1
|
+
export {};
|
|
18
2
|
//# sourceMappingURL=protected.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protected.js","sourceRoot":"","sources":["../../src/protected.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"protected.js","sourceRoot":"","sources":["../../src/protected.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Deep } from './internal';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the result of applying the given `selector` shape to the given `source` value.
|
|
4
|
+
* @typeparam T - the patch value type
|
|
5
|
+
* @typeparam SL - the selector shape type
|
|
6
|
+
* @param source - the source value to select from
|
|
7
|
+
* @param selector - a shape indicating the selection from the source values
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const item = { a: { b: 1, c: 'a' } };
|
|
11
|
+
* Deep.select(item, { q: 'a.c', y: ['a.b', 'a.c'], z: (v) => v.a.b + 1 });
|
|
12
|
+
* // => { q: 'a', y: [1, 'a'], z: 2 }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export function select(source, selector) {
|
|
16
|
+
if (typeof selector === 'function') {
|
|
17
|
+
// selector is function, resolve selector function
|
|
18
|
+
return selector(source);
|
|
19
|
+
}
|
|
20
|
+
else if (typeof selector === 'string') {
|
|
21
|
+
// selector is string path, get the value at the given path
|
|
22
|
+
return Deep.getAt(source, selector);
|
|
23
|
+
}
|
|
24
|
+
else if (Array.isArray(selector)) {
|
|
25
|
+
// selector is tuple, get each tuple item value
|
|
26
|
+
return selector.map((s) => select(source, s));
|
|
27
|
+
}
|
|
28
|
+
// selector is object
|
|
29
|
+
const result = {};
|
|
30
|
+
for (const key in selector) {
|
|
31
|
+
// set each selected object key to the selector value
|
|
32
|
+
result[key] = select(source, selector[key]);
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=selector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selector.js","sourceRoot":"","sources":["../../src/selector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAwB,MAAM,YAAY,CAAC;AAkDxD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,MAAM,CACpB,MAAS,EACT,QAA4B;IAE5B,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;QAClC,kDAAkD;QAClD,OAAQ,QAAgB,CAAC,MAAsB,CAAC,CAAC;KAClD;SAAM,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;QACvC,2DAA2D;QAC3D,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,QAAuB,CAAQ,CAAC;KAC3D;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAClC,+CAA+C;QAC/C,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAQ,CAAC;KACtD;IAED,qBAAqB;IAErB,MAAM,MAAM,GAAQ,EAAE,CAAC;IAEvB,KAAK,MAAM,GAAG,IAAI,QAAe,EAAE;QACjC,qDAAqD;QACrD,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAG,QAAgB,CAAC,GAAG,CAAC,CAAC,CAAC;KACtD;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/module/tuple.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tuple.js","sourceRoot":"","sources":["../../src/tuple.ts"],"names":[],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