@rimbu/deep 0.14.5 → 1.0.0-alpha.2
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/{src/deep.ts → dist/bun/deep.mts} +7 -7
- package/{src/index.ts → dist/bun/index.mts} +5 -5
- package/dist/bun/internal.mts +8 -0
- package/{src/match.ts → dist/bun/match.mts} +6 -6
- package/{src/patch.ts → dist/bun/patch.mts} +9 -4
- package/{src/path.ts → dist/bun/path.mts} +2 -2
- package/{src/selector.ts → dist/bun/selector.mts} +1 -1
- package/dist/cjs/deep.cjs +590 -0
- package/dist/cjs/index.cjs +663 -0
- package/dist/cjs/internal.cjs +583 -0
- package/dist/cjs/match.cjs +376 -0
- package/dist/cjs/patch.cjs +105 -0
- package/dist/cjs/path.cjs +585 -0
- package/dist/cjs/protected.cjs +18 -0
- package/dist/cjs/selector.cjs +581 -0
- package/dist/cjs/tuple.cjs +73 -0
- package/dist/{module/deep.js → esm/deep.mjs} +6 -6
- package/dist/esm/deep.mjs.map +1 -0
- package/dist/{module/index.js → esm/index.mjs} +5 -5
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/internal.mjs +5 -0
- package/dist/esm/internal.mjs.map +1 -0
- package/dist/{module/match.js → esm/match.mjs} +21 -21
- package/dist/esm/match.mjs.map +1 -0
- package/dist/{module/patch.js → esm/patch.mjs} +5 -5
- package/dist/esm/patch.mjs.map +1 -0
- package/dist/{module/path.js → esm/path.mjs} +2 -2
- package/dist/esm/path.mjs.map +1 -0
- package/dist/esm/protected.mjs +2 -0
- package/dist/esm/protected.mjs.map +1 -0
- package/dist/{module/selector.js → esm/selector.mjs} +2 -2
- package/dist/esm/selector.mjs.map +1 -0
- package/dist/{module/tuple.js → esm/tuple.mjs} +1 -1
- package/dist/esm/tuple.mjs.map +1 -0
- package/dist/types/{deep.d.ts → deep.d.mts} +6 -6
- package/dist/types/{index.d.ts → index.d.mts} +5 -5
- package/dist/types/internal.d.mts +7 -0
- package/dist/types/{match.d.ts → match.d.mts} +3 -3
- package/dist/types/{patch.d.ts → patch.d.mts} +3 -3
- package/dist/types/{path.d.ts → path.d.mts} +2 -2
- package/dist/types/{selector.d.ts → selector.d.mts} +1 -1
- package/package.json +29 -23
- package/src/deep.mts +364 -0
- package/src/index.mts +23 -0
- package/src/internal.mts +8 -0
- package/src/match.mts +700 -0
- package/src/patch.mts +262 -0
- package/src/path.mts +430 -0
- package/src/protected.mts +30 -0
- package/src/selector.mts +90 -0
- package/src/tuple.mts +197 -0
- package/dist/main/deep.js +0 -211
- package/dist/main/deep.js.map +0 -1
- package/dist/main/index.js +0 -19
- package/dist/main/index.js.map +0 -1
- package/dist/main/internal.js +0 -9
- package/dist/main/internal.js.map +0 -1
- package/dist/main/match.js +0 -284
- package/dist/main/match.js.map +0 -1
- package/dist/main/patch.js +0 -133
- package/dist/main/patch.js.map +0 -1
- package/dist/main/path.js +0 -126
- package/dist/main/path.js.map +0 -1
- package/dist/main/protected.js +0 -3
- package/dist/main/protected.js.map +0 -1
- package/dist/main/selector.js +0 -40
- package/dist/main/selector.js.map +0 -1
- package/dist/main/tuple.js +0 -164
- package/dist/main/tuple.js.map +0 -1
- package/dist/module/deep.js.map +0 -1
- package/dist/module/index.js.map +0 -1
- package/dist/module/internal.js +0 -4
- package/dist/module/internal.js.map +0 -1
- package/dist/module/match.js.map +0 -1
- package/dist/module/patch.js.map +0 -1
- package/dist/module/path.js.map +0 -1
- package/dist/module/protected.js +0 -2
- package/dist/module/protected.js.map +0 -1
- package/dist/module/selector.js.map +0 -1
- package/dist/module/tuple.js.map +0 -1
- package/dist/types/internal.d.ts +0 -7
- package/src/internal.ts +0 -8
- /package/{src/protected.ts → dist/bun/protected.mts} +0 -0
- /package/{src/tuple.ts → dist/bun/tuple.mts} +0 -0
- /package/dist/types/{protected.d.ts → protected.d.mts} +0 -0
- /package/dist/types/{tuple.d.ts → tuple.d.mts} +0 -0
package/dist/main/match.js
DELETED
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.match = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var base_1 = require("@rimbu/base");
|
|
6
|
-
/**
|
|
7
|
-
* Returns true if the given `value` object matches the given `matcher`, false otherwise.
|
|
8
|
-
* @typeparam T - the input value type
|
|
9
|
-
* @typeparam C - utility type
|
|
10
|
-
* @param source - the value to match (should be a plain object)
|
|
11
|
-
* @param matcher - a matcher object or a function taking the matcher API and returning a match object
|
|
12
|
-
* @param failureLog - (optional) a string array that can be passed to collect reasons why the match failed
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* const input = { a: 1, b: { c: true, d: 'a' } }
|
|
16
|
-
* match(input, { a: 1 }) // => true
|
|
17
|
-
* match(input, { a: 2 }) // => false
|
|
18
|
-
* match(input, { a: (v) => v > 10 }) // => false
|
|
19
|
-
* match(input, { b: { c: true }}) // => true
|
|
20
|
-
* match(input, (['every', { a: (v) => v > 0 }, { b: { c: true } }]) // => true
|
|
21
|
-
* match(input, { b: { c: (v, parent, root) => v && parent.d.length > 0 && root.a > 0 } })
|
|
22
|
-
* // => true
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
function match(source, matcher, failureLog) {
|
|
26
|
-
return matchEntry(source, source, source, matcher, failureLog);
|
|
27
|
-
}
|
|
28
|
-
exports.match = match;
|
|
29
|
-
/**
|
|
30
|
-
* Match a generic match entry against the given source.
|
|
31
|
-
*/
|
|
32
|
-
function matchEntry(source, parent, root, matcher, failureLog) {
|
|
33
|
-
if (Object.is(source, matcher)) {
|
|
34
|
-
// value and target are exactly the same, always will be true
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
if (matcher === null || matcher === undefined) {
|
|
38
|
-
// these matchers can only be direct matches, and previously it was determined that
|
|
39
|
-
// they are not equal
|
|
40
|
-
failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("value ".concat(JSON.stringify(source), " did not match matcher ").concat(matcher));
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
if (typeof source === 'function') {
|
|
44
|
-
// function source values can only be directly matched
|
|
45
|
-
var result = Object.is(source, matcher);
|
|
46
|
-
if (!result) {
|
|
47
|
-
failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("both value and matcher are functions, but they do not have the same reference");
|
|
48
|
-
}
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
if (typeof matcher === 'function') {
|
|
52
|
-
// resolve match function first
|
|
53
|
-
var matcherResult = matcher(source, parent, root);
|
|
54
|
-
if (typeof matcherResult === 'boolean') {
|
|
55
|
-
// function resulted in a direct match result
|
|
56
|
-
if (!matcherResult) {
|
|
57
|
-
failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("function matcher returned false for value ".concat(JSON.stringify(source)));
|
|
58
|
-
}
|
|
59
|
-
return matcherResult;
|
|
60
|
-
}
|
|
61
|
-
// function resulted in a value that needs to be further matched
|
|
62
|
-
return matchEntry(source, parent, root, matcherResult, failureLog);
|
|
63
|
-
}
|
|
64
|
-
if ((0, base_1.isPlainObj)(source)) {
|
|
65
|
-
// source ia a plain object, can be partially matched
|
|
66
|
-
return matchPlainObj(source, parent, root, matcher, failureLog);
|
|
67
|
-
}
|
|
68
|
-
if (Array.isArray(source)) {
|
|
69
|
-
// source is an array
|
|
70
|
-
return matchArr(source, parent, root, matcher, failureLog);
|
|
71
|
-
}
|
|
72
|
-
// already determined above that the source and matcher are not equal
|
|
73
|
-
failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("value ".concat(JSON.stringify(source), " does not match given matcher ").concat(JSON.stringify(matcher)));
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Match an array matcher against the given source.
|
|
78
|
-
*/
|
|
79
|
-
function matchArr(source, parent, root, matcher, failureLog) {
|
|
80
|
-
if (Array.isArray(matcher)) {
|
|
81
|
-
// directly compare array contents
|
|
82
|
-
var length_1 = source.length;
|
|
83
|
-
if (length_1 !== matcher.length) {
|
|
84
|
-
// if lengths not equal, arrays are not equal
|
|
85
|
-
failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("array lengths are not equal: value length ".concat(source.length, " !== matcher length ").concat(matcher.length));
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
// loop over arrays, matching every value
|
|
89
|
-
var index = -1;
|
|
90
|
-
while (++index < length_1) {
|
|
91
|
-
if (!matchEntry(source[index], source, root, matcher[index], failureLog)) {
|
|
92
|
-
// item did not match, return false
|
|
93
|
-
failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("index ".concat(index, " does not match with value ").concat(JSON.stringify(source[index]), " and matcher ").concat(matcher[index]));
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
// all items are equal
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
// matcher is plain object
|
|
101
|
-
if (typeof matcher === 'object' && null !== matcher) {
|
|
102
|
-
if ("every" in matcher) {
|
|
103
|
-
return matchCompound(source, parent, root, tslib_1.__spreadArray(['every'], tslib_1.__read(matcher.every), false), failureLog);
|
|
104
|
-
}
|
|
105
|
-
if ("some" in matcher) {
|
|
106
|
-
return matchCompound(source, parent, root, tslib_1.__spreadArray(['some'], tslib_1.__read(matcher.some), false), failureLog);
|
|
107
|
-
}
|
|
108
|
-
if ("none" in matcher) {
|
|
109
|
-
return matchCompound(source, parent, root, tslib_1.__spreadArray(['none'], tslib_1.__read(matcher.none), false), failureLog);
|
|
110
|
-
}
|
|
111
|
-
if ("single" in matcher) {
|
|
112
|
-
return matchCompound(source, parent, root, tslib_1.__spreadArray(['single'], tslib_1.__read(matcher.single), false), failureLog);
|
|
113
|
-
}
|
|
114
|
-
if ("someItem" in matcher) {
|
|
115
|
-
return matchTraversal(source, root, 'someItem', matcher.someItem, failureLog);
|
|
116
|
-
}
|
|
117
|
-
if ("everyItem" in matcher) {
|
|
118
|
-
return matchTraversal(source, root, 'everyItem', matcher.everyItem, failureLog);
|
|
119
|
-
}
|
|
120
|
-
if ("noneItem" in matcher) {
|
|
121
|
-
return matchTraversal(source, root, 'noneItem', matcher.noneItem, failureLog);
|
|
122
|
-
}
|
|
123
|
-
if ("singleItem" in matcher) {
|
|
124
|
-
return matchTraversal(source, root, 'singleItem', matcher.singleItem, failureLog);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
// matcher is plain object with index keys
|
|
128
|
-
for (var index in matcher) {
|
|
129
|
-
var matcherAtIndex = matcher[index];
|
|
130
|
-
if (!(index in source)) {
|
|
131
|
-
// source does not have item at given index
|
|
132
|
-
failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("index ".concat(index, " does not exist in source ").concat(JSON.stringify(source), " but should match matcher ").concat(JSON.stringify(matcherAtIndex)));
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
// match the source item at the given index
|
|
136
|
-
var result = matchEntry(source[index], source, root, matcherAtIndex, failureLog);
|
|
137
|
-
if (!result) {
|
|
138
|
-
// item did not match
|
|
139
|
-
failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("index ".concat(index, " does not match with value ").concat(JSON.stringify(source[index]), " and matcher ").concat(JSON.stringify(matcherAtIndex)));
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
// all items match
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Match an object matcher against the given source.
|
|
148
|
-
*/
|
|
149
|
-
function matchPlainObj(source, parent, root, matcher, failureLog) {
|
|
150
|
-
if (Array.isArray(matcher)) {
|
|
151
|
-
// the matcher is of compound type
|
|
152
|
-
return matchCompound(source, parent, root, matcher, failureLog);
|
|
153
|
-
}
|
|
154
|
-
// partial object props matcher
|
|
155
|
-
for (var key in matcher) {
|
|
156
|
-
if (!(key in source)) {
|
|
157
|
-
// the source does not have the given key
|
|
158
|
-
failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("key ".concat(key, " is specified in matcher but not present in value ").concat(JSON.stringify(source)));
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
// match the source value at the given key with the matcher at given key
|
|
162
|
-
var result = matchEntry(source[key], source, root, matcher[key], failureLog);
|
|
163
|
-
if (!result) {
|
|
164
|
-
failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("key ".concat(key, " does not match in value ").concat(JSON.stringify(source[key]), " with matcher ").concat(JSON.stringify(matcher[key])));
|
|
165
|
-
return false;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
// all properties match
|
|
169
|
-
return true;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Match a compound matcher against the given source.
|
|
173
|
-
*/
|
|
174
|
-
function matchCompound(source, parent, root, compound, failureLog) {
|
|
175
|
-
// first item indicates compound match type
|
|
176
|
-
var matchType = compound[0];
|
|
177
|
-
var length = compound.length;
|
|
178
|
-
// start at index 1
|
|
179
|
-
var index = 0;
|
|
180
|
-
switch (matchType) {
|
|
181
|
-
case 'every': {
|
|
182
|
-
while (++index < length) {
|
|
183
|
-
// if any item does not match, return false
|
|
184
|
-
var result = matchEntry(source, parent, root, compound[index], failureLog);
|
|
185
|
-
if (!result) {
|
|
186
|
-
failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in compound \"every\": match at index ".concat(index, " failed"));
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
case 'none': {
|
|
193
|
-
// if any item matches, return false
|
|
194
|
-
while (++index < length) {
|
|
195
|
-
var result = matchEntry(source, parent, root, compound[index], failureLog);
|
|
196
|
-
if (result) {
|
|
197
|
-
failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in compound \"none\": match at index ".concat(index, " succeeded"));
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return true;
|
|
202
|
-
}
|
|
203
|
-
case 'single': {
|
|
204
|
-
// if not exactly one item matches, return false
|
|
205
|
-
var onePassed = false;
|
|
206
|
-
while (++index < length) {
|
|
207
|
-
var result = matchEntry(source, parent, root, compound[index], failureLog);
|
|
208
|
-
if (result) {
|
|
209
|
-
if (onePassed) {
|
|
210
|
-
failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in compound \"single\": multiple matches succeeded");
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
onePassed = true;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
if (!onePassed) {
|
|
217
|
-
failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in compound \"single\": no matches succeeded");
|
|
218
|
-
}
|
|
219
|
-
return onePassed;
|
|
220
|
-
}
|
|
221
|
-
case 'some': {
|
|
222
|
-
// if any item matches, return true
|
|
223
|
-
while (++index < length) {
|
|
224
|
-
var result = matchEntry(source, parent, root, compound[index], failureLog);
|
|
225
|
-
if (result) {
|
|
226
|
-
return true;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in compound \"some\": no matches succeeded");
|
|
230
|
-
return false;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
function matchTraversal(source, root, matchType, matcher, failureLog) {
|
|
235
|
-
var index = -1;
|
|
236
|
-
var length = source.length;
|
|
237
|
-
switch (matchType) {
|
|
238
|
-
case 'someItem': {
|
|
239
|
-
while (++index < length) {
|
|
240
|
-
if (matchEntry(source[index], source, root, matcher, failureLog)) {
|
|
241
|
-
return true;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in array traversal \"someItem\": no items matched given matcher");
|
|
245
|
-
return false;
|
|
246
|
-
}
|
|
247
|
-
case 'everyItem': {
|
|
248
|
-
while (++index < length) {
|
|
249
|
-
if (!matchEntry(source[index], source, root, matcher, failureLog)) {
|
|
250
|
-
failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in array traversal \"everyItem\": at least one item did not match given matcher");
|
|
251
|
-
return false;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return true;
|
|
255
|
-
}
|
|
256
|
-
case 'noneItem': {
|
|
257
|
-
while (++index < length) {
|
|
258
|
-
if (matchEntry(source[index], source, root, matcher, failureLog)) {
|
|
259
|
-
failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in array traversal \"noneItem\": at least one item matched given matcher");
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
return true;
|
|
264
|
-
}
|
|
265
|
-
case 'singleItem': {
|
|
266
|
-
var singleMatched = false;
|
|
267
|
-
while (++index < length) {
|
|
268
|
-
if (matchEntry(source[index], source, root, matcher, failureLog)) {
|
|
269
|
-
if (singleMatched) {
|
|
270
|
-
failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in array traversal \"singleItem\": more than one item matched given matcher");
|
|
271
|
-
return false;
|
|
272
|
-
}
|
|
273
|
-
singleMatched = true;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
if (!singleMatched) {
|
|
277
|
-
failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in array traversal \"singleItem\": no item matched given matcher");
|
|
278
|
-
return false;
|
|
279
|
-
}
|
|
280
|
-
return true;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
//# sourceMappingURL=match.js.map
|
package/dist/main/match.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"match.js","sourceRoot":"","sources":["../../src/match.ts"],"names":[],"mappings":";;;;AAAA,oCAMqB;AA0KrB;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,KAAK,CACnB,MAAS,EACT,OAAoB,EACpB,UAA6B;IAE7B,OAAO,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAc,EAAE,UAAU,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;aACF;YAED,OAAO,IAAI,CAAC;SACb;QACD,KAAK,UAAU,CAAC,CAAC;YACf,OAAO,EAAE,KAAK,GAAG,MAAM,EAAE;gBACvB,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE;oBAChE,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,CACd,0EAAwE,CACzE,CAAC;oBACF,OAAO,KAAK,CAAC;iBACd;aACF;YAED,OAAO,IAAI,CAAC;SACb;QACD,KAAK,YAAY,CAAC,CAAC;YACjB,IAAI,aAAa,GAAG,KAAK,CAAC;YAE1B,OAAO,EAAE,KAAK,GAAG,MAAM,EAAE;gBACvB,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE;oBAChE,IAAI,aAAa,EAAE;wBACjB,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,CACd,6EAA2E,CAC5E,CAAC;wBAEF,OAAO,KAAK,CAAC;qBACd;oBAED,aAAa,GAAG,IAAI,CAAC;iBACtB;aACF;YAED,IAAI,CAAC,aAAa,EAAE;gBAClB,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,CACd,kEAAgE,CACjE,CAAC;gBAEF,OAAO,KAAK,CAAC;aACd;YAED,OAAO,IAAI,CAAC;SACb;KACF;AACH,CAAC"}
|
package/dist/main/patch.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.patch = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var base_1 = require("@rimbu/base");
|
|
6
|
-
/**
|
|
7
|
-
* Returns an immutably updated version of the given `value` where the given `patchItems` have been
|
|
8
|
-
* applied to the result.
|
|
9
|
-
* The Rimbu patch notation is as follows:
|
|
10
|
-
* - if the target is a simple value or array, the patch can be the same type or a function returning the same type
|
|
11
|
-
* - 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
|
|
12
|
-
* - 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
|
|
13
|
-
* @typeparam T - the type of the value to patch
|
|
14
|
-
* @typeparam TE - a utility type
|
|
15
|
-
* @typeparam TT - a utility type
|
|
16
|
-
* @param value - the input value to patch
|
|
17
|
-
* @param patchItem - the `Patch` value to apply to the input value
|
|
18
|
-
* @example
|
|
19
|
-
* ```ts
|
|
20
|
-
* const input = { a: 1, b: { c: true, d: 'a' } }
|
|
21
|
-
* patch(input, [{ a: 2 }]) // => { a: 2, b: { c: true, d: 'a' } }
|
|
22
|
-
* patch(input, [{ b: [{ c: (v) => !v }] }] )
|
|
23
|
-
* // => { a: 1, b: { c: false, d: 'a' } }
|
|
24
|
-
* patch(input: [{ a: (v) => v + 1, b: [{ d: 'q' }] }] )
|
|
25
|
-
* // => { a: 2, b: { c: true, d: 'q' } }
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
function patch(value, patchItem) {
|
|
29
|
-
return patchEntry(value, value, value, patchItem);
|
|
30
|
-
}
|
|
31
|
-
exports.patch = patch;
|
|
32
|
-
function patchEntry(value, parent, root, patchItem) {
|
|
33
|
-
if (Object.is(value, patchItem)) {
|
|
34
|
-
// patching a value with itself never changes the value
|
|
35
|
-
return value;
|
|
36
|
-
}
|
|
37
|
-
if (typeof value === 'function') {
|
|
38
|
-
// function input, directly return patch
|
|
39
|
-
return patchItem;
|
|
40
|
-
}
|
|
41
|
-
if (typeof patchItem === 'function') {
|
|
42
|
-
// function patch always needs to be resolved first
|
|
43
|
-
var item = patchItem(value, parent, root);
|
|
44
|
-
return patchEntry(value, parent, root, item);
|
|
45
|
-
}
|
|
46
|
-
if ((0, base_1.isPlainObj)(value)) {
|
|
47
|
-
// value is plain object
|
|
48
|
-
return patchPlainObj(value, root, patchItem);
|
|
49
|
-
}
|
|
50
|
-
if (Array.isArray(value)) {
|
|
51
|
-
// value is tuple or array
|
|
52
|
-
return patchArr(value, root, patchItem);
|
|
53
|
-
}
|
|
54
|
-
// value is primitive type or complex object
|
|
55
|
-
return patchItem;
|
|
56
|
-
}
|
|
57
|
-
function patchPlainObj(value, root, patchItem) {
|
|
58
|
-
var e_1, _a;
|
|
59
|
-
if (!Array.isArray(patchItem)) {
|
|
60
|
-
// the patch is a complete replacement of the current value
|
|
61
|
-
return patchItem;
|
|
62
|
-
}
|
|
63
|
-
// patch is an array of partial updates
|
|
64
|
-
// copy the input value
|
|
65
|
-
var result = tslib_1.__assign({}, value);
|
|
66
|
-
var anyChange = false;
|
|
67
|
-
try {
|
|
68
|
-
// loop over patches in array
|
|
69
|
-
for (var patchItem_1 = tslib_1.__values(patchItem), patchItem_1_1 = patchItem_1.next(); !patchItem_1_1.done; patchItem_1_1 = patchItem_1.next()) {
|
|
70
|
-
var entry = patchItem_1_1.value;
|
|
71
|
-
// update root if needed
|
|
72
|
-
var currentRoot = value === root ? tslib_1.__assign({}, result) : root;
|
|
73
|
-
// keep current updated result as parent
|
|
74
|
-
var parent_1 = tslib_1.__assign({}, result);
|
|
75
|
-
// loop over all the patch keys
|
|
76
|
-
for (var key in entry) {
|
|
77
|
-
// patch the value at the given key with the patch at that key
|
|
78
|
-
var currentValue = result[key];
|
|
79
|
-
var newValue = patchEntry(currentValue, parent_1, currentRoot, entry[key]);
|
|
80
|
-
if (!Object.is(currentValue, newValue)) {
|
|
81
|
-
// if value changed, set it in result and mark change
|
|
82
|
-
anyChange = true;
|
|
83
|
-
result[key] = newValue;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
89
|
-
finally {
|
|
90
|
-
try {
|
|
91
|
-
if (patchItem_1_1 && !patchItem_1_1.done && (_a = patchItem_1.return)) _a.call(patchItem_1);
|
|
92
|
-
}
|
|
93
|
-
finally { if (e_1) throw e_1.error; }
|
|
94
|
-
}
|
|
95
|
-
if (anyChange) {
|
|
96
|
-
// something changed, return new value
|
|
97
|
-
return result;
|
|
98
|
-
}
|
|
99
|
-
// nothing changed, return old value
|
|
100
|
-
return value;
|
|
101
|
-
}
|
|
102
|
-
function patchArr(value, root, patchItem) {
|
|
103
|
-
if (Array.isArray(patchItem)) {
|
|
104
|
-
// value is a normal array
|
|
105
|
-
// patch is a complete replacement of current array
|
|
106
|
-
return patchItem;
|
|
107
|
-
}
|
|
108
|
-
// value is a tuple
|
|
109
|
-
// patch is an object containing numeric keys with function values
|
|
110
|
-
// that update the tuple at the given indices
|
|
111
|
-
// copy the tuple
|
|
112
|
-
var result = tslib_1.__spreadArray([], tslib_1.__read(value), false);
|
|
113
|
-
var anyChange = false;
|
|
114
|
-
// loop over all index keys in object
|
|
115
|
-
for (var index in patchItem) {
|
|
116
|
-
var numIndex = index;
|
|
117
|
-
// patch the tuple at the given index
|
|
118
|
-
var currentValue = result[numIndex];
|
|
119
|
-
var newValue = patchEntry(currentValue, value, root, patchItem[index]);
|
|
120
|
-
if (!Object.is(newValue, currentValue)) {
|
|
121
|
-
// if value changed, set it in result and mark change
|
|
122
|
-
anyChange = true;
|
|
123
|
-
result[numIndex] = newValue;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
if (anyChange) {
|
|
127
|
-
// something changed, return new value
|
|
128
|
-
return result;
|
|
129
|
-
}
|
|
130
|
-
// nothing changed, return old value
|
|
131
|
-
return value;
|
|
132
|
-
}
|
|
133
|
-
//# sourceMappingURL=patch.js.map
|
package/dist/main/patch.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../src/patch.ts"],"names":[],"mappings":";;;;AAAA,oCAAyE;AAwFzE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,KAAK,CACnB,KAAQ,EACR,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AY,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;QACtC,IAAM,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/main/path.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.patchAt = exports.getAt = exports.Path = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var internal_1 = require("./internal");
|
|
6
|
-
var Path;
|
|
7
|
-
(function (Path) {
|
|
8
|
-
/**
|
|
9
|
-
* Regular expression used to split a path string into tokens.
|
|
10
|
-
*/
|
|
11
|
-
Path.stringSplitRegex = /\?\.|\.|\[|\]/g;
|
|
12
|
-
/**
|
|
13
|
-
* Return the given `path` string split into an array of subpaths.
|
|
14
|
-
* @param path - the input string path
|
|
15
|
-
*/
|
|
16
|
-
function stringSplit(path) {
|
|
17
|
-
return path.split(Path.stringSplitRegex);
|
|
18
|
-
}
|
|
19
|
-
Path.stringSplit = stringSplit;
|
|
20
|
-
})(Path = exports.Path || (exports.Path = {}));
|
|
21
|
-
/**
|
|
22
|
-
* Returns the value resulting from selecting the given `path` in the given `source` object.
|
|
23
|
-
* It supports optional chaining for nullable values or values that may be undefined, and also
|
|
24
|
-
* for accessing objects inside an array.
|
|
25
|
-
* There is currently no support for forcing non-null (the `!` operator).
|
|
26
|
-
* @typeparam T - the object type to select in
|
|
27
|
-
* @typeparam P - a Path in object type T
|
|
28
|
-
* @param source - the object to select in
|
|
29
|
-
* @param path - the path into the object
|
|
30
|
-
* @example
|
|
31
|
-
* ```ts
|
|
32
|
-
* const value = { a: { b: { c: [{ d: 5 }, { d: 6 }] } } }
|
|
33
|
-
* Deep.getAt(value, 'a.b');
|
|
34
|
-
* // => { c: 5 }
|
|
35
|
-
* Deep.getAt(value, 'a.b.c');
|
|
36
|
-
* // => [{ d: 5 }, { d: 5 }]
|
|
37
|
-
* Deep.getAt(value, 'a.b.c[1]');
|
|
38
|
-
* // => { d: 6 }
|
|
39
|
-
* Deep.getAt(value, 'a.b.c[1]?.d');
|
|
40
|
-
* // => 6
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
function getAt(source, path) {
|
|
44
|
-
var e_1, _a;
|
|
45
|
-
if (path === '') {
|
|
46
|
-
// empty path always directly returns source value
|
|
47
|
-
return source;
|
|
48
|
-
}
|
|
49
|
-
var items = Path.stringSplit(path);
|
|
50
|
-
// start with `source` as result value
|
|
51
|
-
var result = source;
|
|
52
|
-
try {
|
|
53
|
-
for (var items_1 = tslib_1.__values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
|
54
|
-
var item = items_1_1.value;
|
|
55
|
-
if (undefined === item || item === '' || item === '[') {
|
|
56
|
-
// ignore irrelevant items
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
if (undefined === result || null === result) {
|
|
60
|
-
// optional chaining assumed and no value available, skip rest of path and return undefined
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
// set current result to subpath value
|
|
64
|
-
result = result[item];
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
68
|
-
finally {
|
|
69
|
-
try {
|
|
70
|
-
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
|
|
71
|
-
}
|
|
72
|
-
finally { if (e_1) throw e_1.error; }
|
|
73
|
-
}
|
|
74
|
-
return result;
|
|
75
|
-
}
|
|
76
|
-
exports.getAt = getAt;
|
|
77
|
-
/**
|
|
78
|
-
* Patches the value at the given path in the source to the given value.
|
|
79
|
-
* Because the path to update must exist in the `source` object, optional
|
|
80
|
-
* chaining and array indexing is not allowed.
|
|
81
|
-
* @param source - the object to update
|
|
82
|
-
* @param path - the path in the object to update
|
|
83
|
-
* @param patchItem - the patch for the value at the given path
|
|
84
|
-
* @example
|
|
85
|
-
* ```ts
|
|
86
|
-
* const value = { a: { b: { c: 5 } } };
|
|
87
|
-
* Deep.patchAt(value, 'a.b.c', v => v + 5);
|
|
88
|
-
* // => { a: { b: { c: 6 } } }
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
function patchAt(source, path, patchItem) {
|
|
92
|
-
if (path === '') {
|
|
93
|
-
return internal_1.Deep.patch(source, patchItem);
|
|
94
|
-
}
|
|
95
|
-
var items = Path.stringSplit(path);
|
|
96
|
-
// creates a patch object based on the current path
|
|
97
|
-
function createPatchPart(index, target) {
|
|
98
|
-
var _a;
|
|
99
|
-
if (index === items.length) {
|
|
100
|
-
// processed all items, return the input `patchItem`
|
|
101
|
-
return patchItem;
|
|
102
|
-
}
|
|
103
|
-
var item = items[index];
|
|
104
|
-
if (undefined === item || item === '') {
|
|
105
|
-
// empty items can be ignored
|
|
106
|
-
return createPatchPart(index + 1, target);
|
|
107
|
-
}
|
|
108
|
-
if (item === '[') {
|
|
109
|
-
// next item is array index, set arrayMode to true
|
|
110
|
-
return createPatchPart(index + 1, target);
|
|
111
|
-
}
|
|
112
|
-
// create object with subPart as property key, and the restuls of processing next parts as value
|
|
113
|
-
var result = (_a = {},
|
|
114
|
-
_a[item] = createPatchPart(index + 1, target[item]),
|
|
115
|
-
_a);
|
|
116
|
-
if (Array.isArray(target)) {
|
|
117
|
-
// target in source object is array/tuple, so the patch should be object
|
|
118
|
-
return result;
|
|
119
|
-
}
|
|
120
|
-
// target in source is not an array, so it patch should be an array
|
|
121
|
-
return [result];
|
|
122
|
-
}
|
|
123
|
-
return internal_1.Deep.patch(source, createPatchPart(0, source));
|
|
124
|
-
}
|
|
125
|
-
exports.patchAt = patchAt;
|
|
126
|
-
//# sourceMappingURL=path.js.map
|
package/dist/main/path.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"path.js","sourceRoot":"","sources":["../../src/path.ts"],"names":[],"mappings":";;;;AACA,uCAAyC;AAGzC,IAAiB,IAAI,CAsTpB;AAtTD,WAAiB,IAAI;IAqSnB;;OAEG;IACU,qBAAgB,GAAG,gBAAgB,CAAC;IAOjD;;;OAGG;IACH,SAAgB,WAAW,CAAC,IAAY;QACtC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC3C,CAAC;IAFe,gBAAW,cAE1B,CAAA;AACH,CAAC,EAtTgB,IAAI,GAAJ,YAAI,KAAJ,YAAI,QAsTpB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,KAAK,CACnB,MAAS,EACT,IAAO;;IAEP,IAAI,IAAI,KAAK,EAAE,EAAE;QACf,kDAAkD;QAClD,OAAO,MAAa,CAAC;KACtB;IAED,IAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAErC,sCAAsC;IACtC,IAAI,MAAM,GAAG,MAAa,CAAC;;QAE3B,KAAmB,IAAA,UAAA,iBAAA,KAAK,CAAA,4BAAA,+CAAE;YAArB,IAAM,IAAI,kBAAA;YACb,IAAI,SAAS,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE,IAAI,IAAI,KAAK,GAAG,EAAE;gBACrD,0BAA0B;gBAC1B,SAAS;aACV;YAED,IAAI,SAAS,KAAK,MAAM,IAAI,IAAI,KAAK,MAAM,EAAE;gBAC3C,2FAA2F;gBAC3F,OAAO,SAAgB,CAAC;aACzB;YAED,sCAAsC;Y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ACxD,CAAC;AA7CD,0BA6CC"}
|
package/dist/main/protected.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"protected.js","sourceRoot":"","sources":["../../src/protected.ts"],"names":[],"mappings":""}
|
package/dist/main/selector.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.select = void 0;
|
|
4
|
-
var internal_1 = require("./internal");
|
|
5
|
-
/**
|
|
6
|
-
* Returns the result of applying the given `selector` shape to the given `source` value.
|
|
7
|
-
* @typeparam T - the patch value type
|
|
8
|
-
* @typeparam SL - the selector shape type
|
|
9
|
-
* @param source - the source value to select from
|
|
10
|
-
* @param selector - a shape indicating the selection from the source values
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* const item = { a: { b: 1, c: 'a' } };
|
|
14
|
-
* Deep.select(item, { q: 'a.c', y: ['a.b', 'a.c'], z: (v) => v.a.b + 1 });
|
|
15
|
-
* // => { q: 'a', y: [1, 'a'], z: 2 }
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
function select(source, selector) {
|
|
19
|
-
if (typeof selector === 'function') {
|
|
20
|
-
// selector is function, resolve selector function
|
|
21
|
-
return selector(source);
|
|
22
|
-
}
|
|
23
|
-
else if (typeof selector === 'string') {
|
|
24
|
-
// selector is string path, get the value at the given path
|
|
25
|
-
return internal_1.Deep.getAt(source, selector);
|
|
26
|
-
}
|
|
27
|
-
else if (Array.isArray(selector)) {
|
|
28
|
-
// selector is tuple, get each tuple item value
|
|
29
|
-
return selector.map(function (s) { return select(source, s); });
|
|
30
|
-
}
|
|
31
|
-
// selector is object
|
|
32
|
-
var result = {};
|
|
33
|
-
for (var key in selector) {
|
|
34
|
-
// set each selected object key to the selector value
|
|
35
|
-
result[key] = select(source, selector[key]);
|
|
36
|
-
}
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
exports.select = select;
|
|
40
|
-
//# sourceMappingURL=selector.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selector.js","sourceRoot":"","sources":["../../src/selector.ts"],"names":[],"mappings":";;;AACA,uCAAwD;AAkDxD;;;;;;;;;;;;GAYG;AACH,SAAgB,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,eAAI,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,UAAC,CAAC,IAAK,OAAA,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,EAAjB,CAAiB,CAAQ,CAAC;KACtD;IAED,qBAAqB;IAErB,IAAM,MAAM,GAAQ,EAAE,CAAC;IAEvB,KAAK,IAAM,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;AAzBD,wBAyBC"}
|