@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
|
@@ -0,0 +1,663 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.mts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
Deep: () => deep_exports,
|
|
24
|
+
Path: () => Path,
|
|
25
|
+
Tuple: () => Tuple,
|
|
26
|
+
getAt: () => getAt,
|
|
27
|
+
getAtWith: () => getAtWith,
|
|
28
|
+
match: () => match,
|
|
29
|
+
matchAt: () => matchAt,
|
|
30
|
+
matchAtWith: () => matchAtWith,
|
|
31
|
+
matchWith: () => matchWith,
|
|
32
|
+
patch: () => patch,
|
|
33
|
+
patchAt: () => patchAt,
|
|
34
|
+
patchAtWith: () => patchAtWith,
|
|
35
|
+
patchWith: () => patchWith,
|
|
36
|
+
protect: () => protect,
|
|
37
|
+
select: () => select,
|
|
38
|
+
selectAt: () => selectAt,
|
|
39
|
+
selectAtWith: () => selectAtWith,
|
|
40
|
+
selectWith: () => selectWith,
|
|
41
|
+
withType: () => withType
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(src_exports);
|
|
44
|
+
|
|
45
|
+
// src/tuple.mts
|
|
46
|
+
var import_base = require("@rimbu/base");
|
|
47
|
+
var Tuple;
|
|
48
|
+
((Tuple2) => {
|
|
49
|
+
function of(...values) {
|
|
50
|
+
return values;
|
|
51
|
+
}
|
|
52
|
+
Tuple2.of = of;
|
|
53
|
+
function getIndex(tuple, index) {
|
|
54
|
+
return tuple[index];
|
|
55
|
+
}
|
|
56
|
+
Tuple2.getIndex = getIndex;
|
|
57
|
+
function first(tuple) {
|
|
58
|
+
return tuple[0];
|
|
59
|
+
}
|
|
60
|
+
Tuple2.first = first;
|
|
61
|
+
function second(tuple) {
|
|
62
|
+
return tuple[1];
|
|
63
|
+
}
|
|
64
|
+
Tuple2.second = second;
|
|
65
|
+
function last(tuple) {
|
|
66
|
+
return tuple[tuple.length - 1];
|
|
67
|
+
}
|
|
68
|
+
Tuple2.last = last;
|
|
69
|
+
function updateAt(tuple, index, updater) {
|
|
70
|
+
return import_base.Arr.update(tuple, index, updater);
|
|
71
|
+
}
|
|
72
|
+
Tuple2.updateAt = updateAt;
|
|
73
|
+
function append(tuple, ...values) {
|
|
74
|
+
return [...tuple, ...values];
|
|
75
|
+
}
|
|
76
|
+
Tuple2.append = append;
|
|
77
|
+
function concat(tuple1, tuple2) {
|
|
78
|
+
return tuple1.concat(tuple2);
|
|
79
|
+
}
|
|
80
|
+
Tuple2.concat = concat;
|
|
81
|
+
function init(tuple) {
|
|
82
|
+
return import_base.Arr.init(tuple);
|
|
83
|
+
}
|
|
84
|
+
Tuple2.init = init;
|
|
85
|
+
function tail(tuple) {
|
|
86
|
+
return import_base.Arr.tail(tuple);
|
|
87
|
+
}
|
|
88
|
+
Tuple2.tail = tail;
|
|
89
|
+
})(Tuple || (Tuple = {}));
|
|
90
|
+
|
|
91
|
+
// src/path.mts
|
|
92
|
+
var Path;
|
|
93
|
+
((Path3) => {
|
|
94
|
+
Path3.stringSplitRegex = /\?\.|\.|\[|\]/g;
|
|
95
|
+
function stringSplit(path) {
|
|
96
|
+
return path.split(Path3.stringSplitRegex);
|
|
97
|
+
}
|
|
98
|
+
Path3.stringSplit = stringSplit;
|
|
99
|
+
})(Path || (Path = {}));
|
|
100
|
+
function getAt(source, path) {
|
|
101
|
+
if (path === "") {
|
|
102
|
+
return source;
|
|
103
|
+
}
|
|
104
|
+
const items = Path.stringSplit(path);
|
|
105
|
+
let result = source;
|
|
106
|
+
for (const item of items) {
|
|
107
|
+
if (void 0 === item || item === "" || item === "[") {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (void 0 === result || null === result) {
|
|
111
|
+
return void 0;
|
|
112
|
+
}
|
|
113
|
+
result = result[item];
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
function patchAt(source, path, patchItem) {
|
|
118
|
+
if (path === "") {
|
|
119
|
+
return deep_exports.patch(source, patchItem);
|
|
120
|
+
}
|
|
121
|
+
const items = Path.stringSplit(path);
|
|
122
|
+
function createPatchPart(index, target) {
|
|
123
|
+
if (index === items.length) {
|
|
124
|
+
return patchItem;
|
|
125
|
+
}
|
|
126
|
+
const item = items[index];
|
|
127
|
+
if (void 0 === item || item === "") {
|
|
128
|
+
return createPatchPart(index + 1, target);
|
|
129
|
+
}
|
|
130
|
+
if (item === "[") {
|
|
131
|
+
return createPatchPart(index + 1, target);
|
|
132
|
+
}
|
|
133
|
+
const result = {
|
|
134
|
+
[item]: createPatchPart(index + 1, target[item])
|
|
135
|
+
};
|
|
136
|
+
if (Array.isArray(target)) {
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
return [result];
|
|
140
|
+
}
|
|
141
|
+
return deep_exports.patch(source, createPatchPart(0, source));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/match.mts
|
|
145
|
+
var import_base2 = require("@rimbu/base");
|
|
146
|
+
function match(source, matcher, failureLog) {
|
|
147
|
+
return matchEntry(source, source, source, matcher, failureLog);
|
|
148
|
+
}
|
|
149
|
+
function matchEntry(source, parent, root, matcher, failureLog) {
|
|
150
|
+
if (Object.is(source, matcher)) {
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
if (matcher === null || matcher === void 0) {
|
|
154
|
+
failureLog?.push(
|
|
155
|
+
`value ${JSON.stringify(source)} did not match matcher ${matcher}`
|
|
156
|
+
);
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
if (typeof source === "function") {
|
|
160
|
+
const result = Object.is(source, matcher);
|
|
161
|
+
if (!result) {
|
|
162
|
+
failureLog?.push(
|
|
163
|
+
`both value and matcher are functions, but they do not have the same reference`
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
if (typeof matcher === "function") {
|
|
169
|
+
const matcherResult = matcher(source, parent, root);
|
|
170
|
+
if (typeof matcherResult === "boolean") {
|
|
171
|
+
if (!matcherResult) {
|
|
172
|
+
failureLog?.push(
|
|
173
|
+
`function matcher returned false for value ${JSON.stringify(source)}`
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
return matcherResult;
|
|
177
|
+
}
|
|
178
|
+
return matchEntry(source, parent, root, matcherResult, failureLog);
|
|
179
|
+
}
|
|
180
|
+
if ((0, import_base2.isPlainObj)(source)) {
|
|
181
|
+
return matchPlainObj(source, parent, root, matcher, failureLog);
|
|
182
|
+
}
|
|
183
|
+
if (Array.isArray(source)) {
|
|
184
|
+
return matchArr(source, parent, root, matcher, failureLog);
|
|
185
|
+
}
|
|
186
|
+
failureLog?.push(
|
|
187
|
+
`value ${JSON.stringify(
|
|
188
|
+
source
|
|
189
|
+
)} does not match given matcher ${JSON.stringify(matcher)}`
|
|
190
|
+
);
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
function matchArr(source, parent, root, matcher, failureLog) {
|
|
194
|
+
if (Array.isArray(matcher)) {
|
|
195
|
+
const length = source.length;
|
|
196
|
+
if (length !== matcher.length) {
|
|
197
|
+
failureLog?.push(
|
|
198
|
+
`array lengths are not equal: value length ${source.length} !== matcher length ${matcher.length}`
|
|
199
|
+
);
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
let index = -1;
|
|
203
|
+
while (++index < length) {
|
|
204
|
+
if (!matchEntry(source[index], source, root, matcher[index], failureLog)) {
|
|
205
|
+
failureLog?.push(
|
|
206
|
+
`index ${index} does not match with value ${JSON.stringify(
|
|
207
|
+
source[index]
|
|
208
|
+
)} and matcher ${matcher[index]}`
|
|
209
|
+
);
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
if (typeof matcher === "object" && null !== matcher) {
|
|
216
|
+
if (`every` in matcher) {
|
|
217
|
+
return matchCompound(
|
|
218
|
+
source,
|
|
219
|
+
parent,
|
|
220
|
+
root,
|
|
221
|
+
["every", ...matcher.every],
|
|
222
|
+
failureLog
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
if (`some` in matcher) {
|
|
226
|
+
return matchCompound(
|
|
227
|
+
source,
|
|
228
|
+
parent,
|
|
229
|
+
root,
|
|
230
|
+
["some", ...matcher.some],
|
|
231
|
+
failureLog
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
if (`none` in matcher) {
|
|
235
|
+
return matchCompound(
|
|
236
|
+
source,
|
|
237
|
+
parent,
|
|
238
|
+
root,
|
|
239
|
+
["none", ...matcher.none],
|
|
240
|
+
failureLog
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
if (`single` in matcher) {
|
|
244
|
+
return matchCompound(
|
|
245
|
+
source,
|
|
246
|
+
parent,
|
|
247
|
+
root,
|
|
248
|
+
["single", ...matcher.single],
|
|
249
|
+
failureLog
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
if (`someItem` in matcher) {
|
|
253
|
+
return matchTraversal(
|
|
254
|
+
source,
|
|
255
|
+
root,
|
|
256
|
+
"someItem",
|
|
257
|
+
matcher.someItem,
|
|
258
|
+
failureLog
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
if (`everyItem` in matcher) {
|
|
262
|
+
return matchTraversal(
|
|
263
|
+
source,
|
|
264
|
+
root,
|
|
265
|
+
"everyItem",
|
|
266
|
+
matcher.everyItem,
|
|
267
|
+
failureLog
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
if (`noneItem` in matcher) {
|
|
271
|
+
return matchTraversal(
|
|
272
|
+
source,
|
|
273
|
+
root,
|
|
274
|
+
"noneItem",
|
|
275
|
+
matcher.noneItem,
|
|
276
|
+
failureLog
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
if (`singleItem` in matcher) {
|
|
280
|
+
return matchTraversal(
|
|
281
|
+
source,
|
|
282
|
+
root,
|
|
283
|
+
"singleItem",
|
|
284
|
+
matcher.singleItem,
|
|
285
|
+
failureLog
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
for (const index in matcher) {
|
|
290
|
+
const matcherAtIndex = matcher[index];
|
|
291
|
+
if (!(index in source)) {
|
|
292
|
+
failureLog?.push(
|
|
293
|
+
`index ${index} does not exist in source ${JSON.stringify(
|
|
294
|
+
source
|
|
295
|
+
)} but should match matcher ${JSON.stringify(matcherAtIndex)}`
|
|
296
|
+
);
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
const result = matchEntry(
|
|
300
|
+
source[index],
|
|
301
|
+
source,
|
|
302
|
+
root,
|
|
303
|
+
matcherAtIndex,
|
|
304
|
+
failureLog
|
|
305
|
+
);
|
|
306
|
+
if (!result) {
|
|
307
|
+
failureLog?.push(
|
|
308
|
+
`index ${index} does not match with value ${JSON.stringify(
|
|
309
|
+
source[index]
|
|
310
|
+
)} and matcher ${JSON.stringify(matcherAtIndex)}`
|
|
311
|
+
);
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
function matchPlainObj(source, parent, root, matcher, failureLog) {
|
|
318
|
+
if (Array.isArray(matcher)) {
|
|
319
|
+
return matchCompound(source, parent, root, matcher, failureLog);
|
|
320
|
+
}
|
|
321
|
+
for (const key in matcher) {
|
|
322
|
+
if (!(key in source)) {
|
|
323
|
+
failureLog?.push(
|
|
324
|
+
`key ${key} is specified in matcher but not present in value ${JSON.stringify(
|
|
325
|
+
source
|
|
326
|
+
)}`
|
|
327
|
+
);
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
const result = matchEntry(
|
|
331
|
+
source[key],
|
|
332
|
+
source,
|
|
333
|
+
root,
|
|
334
|
+
matcher[key],
|
|
335
|
+
failureLog
|
|
336
|
+
);
|
|
337
|
+
if (!result) {
|
|
338
|
+
failureLog?.push(
|
|
339
|
+
`key ${key} does not match in value ${JSON.stringify(
|
|
340
|
+
source[key]
|
|
341
|
+
)} with matcher ${JSON.stringify(matcher[key])}`
|
|
342
|
+
);
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return true;
|
|
347
|
+
}
|
|
348
|
+
function matchCompound(source, parent, root, compound, failureLog) {
|
|
349
|
+
const matchType = compound[0];
|
|
350
|
+
const length = compound.length;
|
|
351
|
+
let index = 0;
|
|
352
|
+
switch (matchType) {
|
|
353
|
+
case "every": {
|
|
354
|
+
while (++index < length) {
|
|
355
|
+
const result = matchEntry(
|
|
356
|
+
source,
|
|
357
|
+
parent,
|
|
358
|
+
root,
|
|
359
|
+
compound[index],
|
|
360
|
+
failureLog
|
|
361
|
+
);
|
|
362
|
+
if (!result) {
|
|
363
|
+
failureLog?.push(
|
|
364
|
+
`in compound "every": match at index ${index} failed`
|
|
365
|
+
);
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return true;
|
|
370
|
+
}
|
|
371
|
+
case "none": {
|
|
372
|
+
while (++index < length) {
|
|
373
|
+
const result = matchEntry(
|
|
374
|
+
source,
|
|
375
|
+
parent,
|
|
376
|
+
root,
|
|
377
|
+
compound[index],
|
|
378
|
+
failureLog
|
|
379
|
+
);
|
|
380
|
+
if (result) {
|
|
381
|
+
failureLog?.push(
|
|
382
|
+
`in compound "none": match at index ${index} succeeded`
|
|
383
|
+
);
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return true;
|
|
388
|
+
}
|
|
389
|
+
case "single": {
|
|
390
|
+
let onePassed = false;
|
|
391
|
+
while (++index < length) {
|
|
392
|
+
const result = matchEntry(
|
|
393
|
+
source,
|
|
394
|
+
parent,
|
|
395
|
+
root,
|
|
396
|
+
compound[index],
|
|
397
|
+
failureLog
|
|
398
|
+
);
|
|
399
|
+
if (result) {
|
|
400
|
+
if (onePassed) {
|
|
401
|
+
failureLog?.push(
|
|
402
|
+
`in compound "single": multiple matches succeeded`
|
|
403
|
+
);
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
onePassed = true;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
if (!onePassed) {
|
|
410
|
+
failureLog?.push(`in compound "single": no matches succeeded`);
|
|
411
|
+
}
|
|
412
|
+
return onePassed;
|
|
413
|
+
}
|
|
414
|
+
case "some": {
|
|
415
|
+
while (++index < length) {
|
|
416
|
+
const result = matchEntry(
|
|
417
|
+
source,
|
|
418
|
+
parent,
|
|
419
|
+
root,
|
|
420
|
+
compound[index],
|
|
421
|
+
failureLog
|
|
422
|
+
);
|
|
423
|
+
if (result) {
|
|
424
|
+
return true;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
failureLog?.push(`in compound "some": no matches succeeded`);
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
function matchTraversal(source, root, matchType, matcher, failureLog) {
|
|
433
|
+
let index = -1;
|
|
434
|
+
const length = source.length;
|
|
435
|
+
switch (matchType) {
|
|
436
|
+
case "someItem": {
|
|
437
|
+
while (++index < length) {
|
|
438
|
+
if (matchEntry(source[index], source, root, matcher, failureLog)) {
|
|
439
|
+
return true;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
failureLog?.push(
|
|
443
|
+
`in array traversal "someItem": no items matched given matcher`
|
|
444
|
+
);
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
case "everyItem": {
|
|
448
|
+
while (++index < length) {
|
|
449
|
+
if (!matchEntry(source[index], source, root, matcher, failureLog)) {
|
|
450
|
+
failureLog?.push(
|
|
451
|
+
`in array traversal "everyItem": at least one item did not match given matcher`
|
|
452
|
+
);
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
return true;
|
|
457
|
+
}
|
|
458
|
+
case "noneItem": {
|
|
459
|
+
while (++index < length) {
|
|
460
|
+
if (matchEntry(source[index], source, root, matcher, failureLog)) {
|
|
461
|
+
failureLog?.push(
|
|
462
|
+
`in array traversal "noneItem": at least one item matched given matcher`
|
|
463
|
+
);
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
return true;
|
|
468
|
+
}
|
|
469
|
+
case "singleItem": {
|
|
470
|
+
let singleMatched = false;
|
|
471
|
+
while (++index < length) {
|
|
472
|
+
if (matchEntry(source[index], source, root, matcher, failureLog)) {
|
|
473
|
+
if (singleMatched) {
|
|
474
|
+
failureLog?.push(
|
|
475
|
+
`in array traversal "singleItem": more than one item matched given matcher`
|
|
476
|
+
);
|
|
477
|
+
return false;
|
|
478
|
+
}
|
|
479
|
+
singleMatched = true;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
if (!singleMatched) {
|
|
483
|
+
failureLog?.push(
|
|
484
|
+
`in array traversal "singleItem": no item matched given matcher`
|
|
485
|
+
);
|
|
486
|
+
return false;
|
|
487
|
+
}
|
|
488
|
+
return true;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// src/deep.mts
|
|
494
|
+
var deep_exports = {};
|
|
495
|
+
__export(deep_exports, {
|
|
496
|
+
getAt: () => getAt,
|
|
497
|
+
getAtWith: () => getAtWith,
|
|
498
|
+
match: () => match,
|
|
499
|
+
matchAt: () => matchAt,
|
|
500
|
+
matchAtWith: () => matchAtWith,
|
|
501
|
+
matchWith: () => matchWith,
|
|
502
|
+
patch: () => patch,
|
|
503
|
+
patchAt: () => patchAt,
|
|
504
|
+
patchAtWith: () => patchAtWith,
|
|
505
|
+
patchWith: () => patchWith,
|
|
506
|
+
protect: () => protect,
|
|
507
|
+
select: () => select,
|
|
508
|
+
selectAt: () => selectAt,
|
|
509
|
+
selectAtWith: () => selectAtWith,
|
|
510
|
+
selectWith: () => selectWith,
|
|
511
|
+
withType: () => withType
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
// src/patch.mts
|
|
515
|
+
var import_base3 = require("@rimbu/base");
|
|
516
|
+
function patch(value, patchItem) {
|
|
517
|
+
return patchEntry(value, value, value, patchItem);
|
|
518
|
+
}
|
|
519
|
+
function patchEntry(value, parent, root, patchItem) {
|
|
520
|
+
if (Object.is(value, patchItem)) {
|
|
521
|
+
return value;
|
|
522
|
+
}
|
|
523
|
+
if (typeof value === "function") {
|
|
524
|
+
return patchItem;
|
|
525
|
+
}
|
|
526
|
+
if (typeof patchItem === "function") {
|
|
527
|
+
const item = patchItem(value, parent, root);
|
|
528
|
+
return patchEntry(value, parent, root, item);
|
|
529
|
+
}
|
|
530
|
+
if ((0, import_base3.isPlainObj)(value)) {
|
|
531
|
+
return patchPlainObj(value, root, patchItem);
|
|
532
|
+
}
|
|
533
|
+
if (Array.isArray(value)) {
|
|
534
|
+
return patchArr(value, root, patchItem);
|
|
535
|
+
}
|
|
536
|
+
return patchItem;
|
|
537
|
+
}
|
|
538
|
+
function patchPlainObj(value, root, patchItem) {
|
|
539
|
+
if (!Array.isArray(patchItem)) {
|
|
540
|
+
return patchItem;
|
|
541
|
+
}
|
|
542
|
+
const result = { ...value };
|
|
543
|
+
let anyChange = false;
|
|
544
|
+
for (const entry of patchItem) {
|
|
545
|
+
const currentRoot = value === root ? { ...result } : root;
|
|
546
|
+
const parent = { ...result };
|
|
547
|
+
for (const key in entry) {
|
|
548
|
+
const currentValue = result[key];
|
|
549
|
+
const newValue = patchEntry(
|
|
550
|
+
currentValue,
|
|
551
|
+
parent,
|
|
552
|
+
currentRoot,
|
|
553
|
+
entry[key]
|
|
554
|
+
);
|
|
555
|
+
if (!Object.is(currentValue, newValue)) {
|
|
556
|
+
anyChange = true;
|
|
557
|
+
result[key] = newValue;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
if (anyChange) {
|
|
562
|
+
return result;
|
|
563
|
+
}
|
|
564
|
+
return value;
|
|
565
|
+
}
|
|
566
|
+
function patchArr(value, root, patchItem) {
|
|
567
|
+
if (Array.isArray(patchItem)) {
|
|
568
|
+
return patchItem;
|
|
569
|
+
}
|
|
570
|
+
const result = [...value];
|
|
571
|
+
let anyChange = false;
|
|
572
|
+
for (const index in patchItem) {
|
|
573
|
+
const numIndex = index;
|
|
574
|
+
const currentValue = result[numIndex];
|
|
575
|
+
const newValue = patchEntry(
|
|
576
|
+
currentValue,
|
|
577
|
+
value,
|
|
578
|
+
root,
|
|
579
|
+
patchItem[index]
|
|
580
|
+
);
|
|
581
|
+
if (!Object.is(newValue, currentValue)) {
|
|
582
|
+
anyChange = true;
|
|
583
|
+
result[numIndex] = newValue;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
if (anyChange) {
|
|
587
|
+
return result;
|
|
588
|
+
}
|
|
589
|
+
return value;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// src/selector.mts
|
|
593
|
+
function select(source, selector) {
|
|
594
|
+
if (typeof selector === "function") {
|
|
595
|
+
return selector(source);
|
|
596
|
+
} else if (typeof selector === "string") {
|
|
597
|
+
return deep_exports.getAt(source, selector);
|
|
598
|
+
} else if (Array.isArray(selector)) {
|
|
599
|
+
return selector.map((s) => select(source, s));
|
|
600
|
+
}
|
|
601
|
+
const result = {};
|
|
602
|
+
for (const key in selector) {
|
|
603
|
+
result[key] = select(source, selector[key]);
|
|
604
|
+
}
|
|
605
|
+
return result;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// src/deep.mts
|
|
609
|
+
function protect(source) {
|
|
610
|
+
return source;
|
|
611
|
+
}
|
|
612
|
+
function getAtWith(path) {
|
|
613
|
+
return (source) => deep_exports.getAt(source, path);
|
|
614
|
+
}
|
|
615
|
+
function patchWith(patchItem) {
|
|
616
|
+
return (source) => deep_exports.patch(source, patchItem);
|
|
617
|
+
}
|
|
618
|
+
function patchAtWith(path, patchItem) {
|
|
619
|
+
return (source) => deep_exports.patchAt(source, path, patchItem);
|
|
620
|
+
}
|
|
621
|
+
function matchWith(matcher) {
|
|
622
|
+
return (source) => deep_exports.match(source, matcher);
|
|
623
|
+
}
|
|
624
|
+
function matchAt(source, path, matcher) {
|
|
625
|
+
return deep_exports.match(deep_exports.getAt(source, path), matcher);
|
|
626
|
+
}
|
|
627
|
+
function matchAtWith(path, matcher) {
|
|
628
|
+
return (source) => deep_exports.matchAt(source, path, matcher);
|
|
629
|
+
}
|
|
630
|
+
function selectWith(selector) {
|
|
631
|
+
return (source) => deep_exports.select(source, selector);
|
|
632
|
+
}
|
|
633
|
+
function selectAt(source, path, selector) {
|
|
634
|
+
return deep_exports.select(deep_exports.getAt(source, path), selector);
|
|
635
|
+
}
|
|
636
|
+
function selectAtWith(path, selector) {
|
|
637
|
+
return (source) => deep_exports.selectAt(source, path, selector);
|
|
638
|
+
}
|
|
639
|
+
function withType() {
|
|
640
|
+
return deep_exports;
|
|
641
|
+
}
|
|
642
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
643
|
+
0 && (module.exports = {
|
|
644
|
+
Deep,
|
|
645
|
+
Path,
|
|
646
|
+
Tuple,
|
|
647
|
+
getAt,
|
|
648
|
+
getAtWith,
|
|
649
|
+
match,
|
|
650
|
+
matchAt,
|
|
651
|
+
matchAtWith,
|
|
652
|
+
matchWith,
|
|
653
|
+
patch,
|
|
654
|
+
patchAt,
|
|
655
|
+
patchAtWith,
|
|
656
|
+
patchWith,
|
|
657
|
+
protect,
|
|
658
|
+
select,
|
|
659
|
+
selectAt,
|
|
660
|
+
selectAtWith,
|
|
661
|
+
selectWith,
|
|
662
|
+
withType
|
|
663
|
+
});
|