@rimbu/deep 0.12.1 → 0.13.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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.match = void 0;
4
+ var tslib_1 = require("tslib");
4
5
  var base_1 = require("@rimbu/base");
5
6
  /**
6
7
  * Returns true if the given `value` object matches the given `matcher`, false otherwise.
@@ -8,7 +9,7 @@ var base_1 = require("@rimbu/base");
8
9
  * @typeparam C - utility type
9
10
  * @param source - the value to match (should be a plain object)
10
11
  * @param matcher - a matcher object or a function taking the matcher API and returning a match object
11
- * @param errorCollector - (optional) a string array that can be passed to collect reasons why the match failed
12
+ * @param failureLog - (optional) a string array that can be passed to collect reasons why the match failed
12
13
  * @example
13
14
  * ```ts
14
15
  * const input = { a: 1, b: { c: true, d: 'a' } }
@@ -21,15 +22,14 @@ var base_1 = require("@rimbu/base");
21
22
  * // => true
22
23
  * ```
23
24
  */
24
- function match(source, matcher, errorCollector) {
25
- if (errorCollector === void 0) { errorCollector = undefined; }
26
- return matchEntry(source, source, source, matcher, errorCollector);
25
+ function match(source, matcher, failureLog) {
26
+ return matchEntry(source, source, source, matcher, failureLog);
27
27
  }
28
28
  exports.match = match;
29
29
  /**
30
30
  * Match a generic match entry against the given source.
31
31
  */
32
- function matchEntry(source, parent, root, matcher, errorCollector) {
32
+ function matchEntry(source, parent, root, matcher, failureLog) {
33
33
  if (Object.is(source, matcher)) {
34
34
  // value and target are exactly the same, always will be true
35
35
  return true;
@@ -37,14 +37,14 @@ function matchEntry(source, parent, root, matcher, errorCollector) {
37
37
  if (matcher === null || matcher === undefined) {
38
38
  // these matchers can only be direct matches, and previously it was determined that
39
39
  // they are not equal
40
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push("value ".concat(JSON.stringify(source), " did not match matcher ").concat(matcher));
40
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("value ".concat(JSON.stringify(source), " did not match matcher ").concat(matcher));
41
41
  return false;
42
42
  }
43
43
  if (typeof source === 'function') {
44
44
  // function source values can only be directly matched
45
45
  var result = Object.is(source, matcher);
46
46
  if (!result) {
47
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push("both value and matcher are functions, but they do not have the same reference");
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
48
  }
49
49
  return result;
50
50
  }
@@ -54,62 +54,87 @@ function matchEntry(source, parent, root, matcher, errorCollector) {
54
54
  if (typeof matcherResult === 'boolean') {
55
55
  // function resulted in a direct match result
56
56
  if (!matcherResult) {
57
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push("function matcher returned false for value ".concat(JSON.stringify(source)));
57
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("function matcher returned false for value ".concat(JSON.stringify(source)));
58
58
  }
59
59
  return matcherResult;
60
60
  }
61
61
  // function resulted in a value that needs to be further matched
62
- return matchEntry(source, parent, root, matcherResult, errorCollector);
62
+ return matchEntry(source, parent, root, matcherResult, failureLog);
63
63
  }
64
64
  if ((0, base_1.isPlainObj)(source)) {
65
65
  // source ia a plain object, can be partially matched
66
- return matchPlainObj(source, parent, root, matcher, errorCollector);
66
+ return matchPlainObj(source, parent, root, matcher, failureLog);
67
67
  }
68
68
  if (Array.isArray(source)) {
69
69
  // source is an array
70
- return matchArr(source, root, matcher, errorCollector);
70
+ return matchArr(source, parent, root, matcher, failureLog);
71
71
  }
72
72
  // already determined above that the source and matcher are not equal
73
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push("value ".concat(JSON.stringify(source), " does not match given matcher ").concat(JSON.stringify(matcher)));
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
74
  return false;
75
75
  }
76
76
  /**
77
77
  * Match an array matcher against the given source.
78
78
  */
79
- function matchArr(source, root, matcher, errorCollector) {
79
+ function matchArr(source, parent, root, matcher, failureLog) {
80
80
  if (Array.isArray(matcher)) {
81
81
  // directly compare array contents
82
82
  var length_1 = source.length;
83
83
  if (length_1 !== matcher.length) {
84
84
  // if lengths not equal, arrays are not equal
85
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push("array lengths are not equal: value length ".concat(source.length, " !== matcher length ").concat(matcher.length));
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
86
  return false;
87
87
  }
88
88
  // loop over arrays, matching every value
89
89
  var index = -1;
90
90
  while (++index < length_1) {
91
- if (!Object.is(source[index], matcher[index])) {
91
+ if (!matchEntry(source[index], source, root, matcher[index], failureLog)) {
92
92
  // item did not match, return false
93
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push("index ".concat(index, " does not match with value ").concat(JSON.stringify(source[index]), " and matcher ").concat(matcher[index]));
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
94
  return false;
95
95
  }
96
96
  }
97
97
  // all items are equal
98
98
  return true;
99
99
  }
100
+ // matcher is plain object
101
+ if ("every" in matcher) {
102
+ return matchCompound(source, parent, root, tslib_1.__spreadArray(['every'], tslib_1.__read(matcher.every), false), failureLog);
103
+ }
104
+ if ("some" in matcher) {
105
+ return matchCompound(source, parent, root, tslib_1.__spreadArray(['some'], tslib_1.__read(matcher.some), false), failureLog);
106
+ }
107
+ if ("none" in matcher) {
108
+ return matchCompound(source, parent, root, tslib_1.__spreadArray(['none'], tslib_1.__read(matcher.none), false), failureLog);
109
+ }
110
+ if ("single" in matcher) {
111
+ return matchCompound(source, parent, root, tslib_1.__spreadArray(['single'], tslib_1.__read(matcher.single), false), failureLog);
112
+ }
113
+ if ("someItem" in matcher) {
114
+ return matchTraversal(source, root, 'someItem', matcher.someItem, failureLog);
115
+ }
116
+ if ("everyItem" in matcher) {
117
+ return matchTraversal(source, root, 'everyItem', matcher.everyItem, failureLog);
118
+ }
119
+ if ("noneItem" in matcher) {
120
+ return matchTraversal(source, root, 'noneItem', matcher.noneItem, failureLog);
121
+ }
122
+ if ("singleItem" in matcher) {
123
+ return matchTraversal(source, root, 'singleItem', matcher.singleItem, failureLog);
124
+ }
100
125
  // matcher is plain object with index keys
101
126
  for (var index in matcher) {
102
127
  var matcherAtIndex = matcher[index];
103
128
  if (!(index in source)) {
104
129
  // source does not have item at given index
105
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push("index ".concat(index, " does not exist in source ").concat(JSON.stringify(source), " but should match matcher ").concat(JSON.stringify(matcherAtIndex)));
130
+ 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)));
106
131
  return false;
107
132
  }
108
133
  // match the source item at the given index
109
- var result = matchEntry(source[index], source, root, matcherAtIndex, errorCollector);
134
+ var result = matchEntry(source[index], source, root, matcherAtIndex, failureLog);
110
135
  if (!result) {
111
136
  // item did not match
112
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push("index ".concat(index, " does not match with value ").concat(JSON.stringify(source[index]), " and matcher ").concat(JSON.stringify(matcherAtIndex)));
137
+ 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)));
113
138
  return false;
114
139
  }
115
140
  }
@@ -119,22 +144,22 @@ function matchArr(source, root, matcher, errorCollector) {
119
144
  /**
120
145
  * Match an object matcher against the given source.
121
146
  */
122
- function matchPlainObj(source, parent, root, matcher, errorCollector) {
147
+ function matchPlainObj(source, parent, root, matcher, failureLog) {
123
148
  if (Array.isArray(matcher)) {
124
149
  // the matcher is of compound type
125
- return matchCompound(source, parent, root, matcher, errorCollector);
150
+ return matchCompound(source, parent, root, matcher, failureLog);
126
151
  }
127
152
  // partial object props matcher
128
153
  for (var key in matcher) {
129
154
  if (!(key in source)) {
130
155
  // the source does not have the given key
131
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push("key ".concat(key, " is specified in matcher but not present in value ").concat(JSON.stringify(source)));
156
+ 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)));
132
157
  return false;
133
158
  }
134
159
  // match the source value at the given key with the matcher at given key
135
- var result = matchEntry(source[key], source, root, matcher[key], errorCollector);
160
+ var result = matchEntry(source[key], source, root, matcher[key], failureLog);
136
161
  if (!result) {
137
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push("key ".concat(key, " does not match in value ").concat(JSON.stringify(source[key]), " with matcher ").concat(JSON.stringify(matcher[key])));
162
+ 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])));
138
163
  return false;
139
164
  }
140
165
  }
@@ -144,7 +169,7 @@ function matchPlainObj(source, parent, root, matcher, errorCollector) {
144
169
  /**
145
170
  * Match a compound matcher against the given source.
146
171
  */
147
- function matchCompound(source, parent, root, compound, errorCollector) {
172
+ function matchCompound(source, parent, root, compound, failureLog) {
148
173
  // first item indicates compound match type
149
174
  var matchType = compound[0];
150
175
  var length = compound.length;
@@ -154,9 +179,9 @@ function matchCompound(source, parent, root, compound, errorCollector) {
154
179
  case 'every': {
155
180
  while (++index < length) {
156
181
  // if any item does not match, return false
157
- var result = matchEntry(source, parent, root, compound[index], errorCollector);
182
+ var result = matchEntry(source, parent, root, compound[index], failureLog);
158
183
  if (!result) {
159
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push("in compound \"every\": match at index ".concat(index, " failed"));
184
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in compound \"every\": match at index ".concat(index, " failed"));
160
185
  return false;
161
186
  }
162
187
  }
@@ -165,9 +190,9 @@ function matchCompound(source, parent, root, compound, errorCollector) {
165
190
  case 'none': {
166
191
  // if any item matches, return false
167
192
  while (++index < length) {
168
- var result = matchEntry(source, parent, root, compound[index], errorCollector);
193
+ var result = matchEntry(source, parent, root, compound[index], failureLog);
169
194
  if (result) {
170
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push("in compound \"none\": match at index ".concat(index, " succeeded"));
195
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in compound \"none\": match at index ".concat(index, " succeeded"));
171
196
  return false;
172
197
  }
173
198
  }
@@ -177,31 +202,81 @@ function matchCompound(source, parent, root, compound, errorCollector) {
177
202
  // if not exactly one item matches, return false
178
203
  var onePassed = false;
179
204
  while (++index < length) {
180
- var result = matchEntry(source, parent, root, compound[index], errorCollector);
205
+ var result = matchEntry(source, parent, root, compound[index], failureLog);
181
206
  if (result) {
182
207
  if (onePassed) {
183
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push("in compound \"single\": multiple matches succeeded");
208
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in compound \"single\": multiple matches succeeded");
184
209
  return false;
185
210
  }
186
211
  onePassed = true;
187
212
  }
188
213
  }
189
214
  if (!onePassed) {
190
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push("in compound \"single\": no matches succeeded");
215
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in compound \"single\": no matches succeeded");
191
216
  }
192
217
  return onePassed;
193
218
  }
194
219
  case 'some': {
195
220
  // if any item matches, return true
196
221
  while (++index < length) {
197
- var result = matchEntry(source, parent, root, compound[index], errorCollector);
222
+ var result = matchEntry(source, parent, root, compound[index], failureLog);
198
223
  if (result) {
199
224
  return true;
200
225
  }
201
226
  }
202
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push("in compound \"some\": no matches succeeded");
227
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in compound \"some\": no matches succeeded");
203
228
  return false;
204
229
  }
205
230
  }
206
231
  }
232
+ function matchTraversal(source, root, matchType, matcher, failureLog) {
233
+ var index = -1;
234
+ var length = source.length;
235
+ switch (matchType) {
236
+ case 'someItem': {
237
+ while (++index < length) {
238
+ if (matchEntry(source[index], source, root, matcher, failureLog)) {
239
+ return true;
240
+ }
241
+ }
242
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in array traversal \"someItem\": no items matched given matcher");
243
+ return false;
244
+ }
245
+ case 'everyItem': {
246
+ while (++index < length) {
247
+ if (!matchEntry(source[index], source, root, matcher, failureLog)) {
248
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in array traversal \"everyItem\": at least one item did not match given matcher");
249
+ return false;
250
+ }
251
+ }
252
+ return true;
253
+ }
254
+ case 'noneItem': {
255
+ while (++index < length) {
256
+ if (matchEntry(source[index], source, root, matcher, failureLog)) {
257
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in array traversal \"noneItem\": at least one item matched given matcher");
258
+ return false;
259
+ }
260
+ }
261
+ return true;
262
+ }
263
+ case 'singleItem': {
264
+ var singleMatched = false;
265
+ while (++index < length) {
266
+ if (matchEntry(source[index], source, root, matcher, failureLog)) {
267
+ if (singleMatched) {
268
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in array traversal \"singleItem\": more than one item matched given matcher");
269
+ return false;
270
+ }
271
+ singleMatched = true;
272
+ }
273
+ }
274
+ if (!singleMatched) {
275
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in array traversal \"singleItem\": no item matched given matcher");
276
+ return false;
277
+ }
278
+ return true;
279
+ }
280
+ }
281
+ }
207
282
  //# sourceMappingURL=match.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"match.js","sourceRoot":"","sources":["../../src/match.ts"],"names":[],"mappings":";;;AAAA,oCAMqB;AAkIrB;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,KAAK,CACnB,MAAS,EACT,OAAo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AAE,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"}
@@ -5,7 +5,7 @@ import { isPlainObj, } from '@rimbu/base';
5
5
  * @typeparam C - utility type
6
6
  * @param source - the value to match (should be a plain object)
7
7
  * @param matcher - a matcher object or a function taking the matcher API and returning a match object
8
- * @param errorCollector - (optional) a string array that can be passed to collect reasons why the match failed
8
+ * @param failureLog - (optional) a string array that can be passed to collect reasons why the match failed
9
9
  * @example
10
10
  * ```ts
11
11
  * const input = { a: 1, b: { c: true, d: 'a' } }
@@ -18,13 +18,13 @@ import { isPlainObj, } from '@rimbu/base';
18
18
  * // => true
19
19
  * ```
20
20
  */
21
- export function match(source, matcher, errorCollector = undefined) {
22
- return matchEntry(source, source, source, matcher, errorCollector);
21
+ export function match(source, matcher, failureLog) {
22
+ return matchEntry(source, source, source, matcher, failureLog);
23
23
  }
24
24
  /**
25
25
  * Match a generic match entry against the given source.
26
26
  */
27
- function matchEntry(source, parent, root, matcher, errorCollector) {
27
+ function matchEntry(source, parent, root, matcher, failureLog) {
28
28
  if (Object.is(source, matcher)) {
29
29
  // value and target are exactly the same, always will be true
30
30
  return true;
@@ -32,14 +32,14 @@ function matchEntry(source, parent, root, matcher, errorCollector) {
32
32
  if (matcher === null || matcher === undefined) {
33
33
  // these matchers can only be direct matches, and previously it was determined that
34
34
  // they are not equal
35
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push(`value ${JSON.stringify(source)} did not match matcher ${matcher}`);
35
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push(`value ${JSON.stringify(source)} did not match matcher ${matcher}`);
36
36
  return false;
37
37
  }
38
38
  if (typeof source === 'function') {
39
39
  // function source values can only be directly matched
40
40
  const result = Object.is(source, matcher);
41
41
  if (!result) {
42
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push(`both value and matcher are functions, but they do not have the same reference`);
42
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push(`both value and matcher are functions, but they do not have the same reference`);
43
43
  }
44
44
  return result;
45
45
  }
@@ -49,62 +49,87 @@ function matchEntry(source, parent, root, matcher, errorCollector) {
49
49
  if (typeof matcherResult === 'boolean') {
50
50
  // function resulted in a direct match result
51
51
  if (!matcherResult) {
52
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push(`function matcher returned false for value ${JSON.stringify(source)}`);
52
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push(`function matcher returned false for value ${JSON.stringify(source)}`);
53
53
  }
54
54
  return matcherResult;
55
55
  }
56
56
  // function resulted in a value that needs to be further matched
57
- return matchEntry(source, parent, root, matcherResult, errorCollector);
57
+ return matchEntry(source, parent, root, matcherResult, failureLog);
58
58
  }
59
59
  if (isPlainObj(source)) {
60
60
  // source ia a plain object, can be partially matched
61
- return matchPlainObj(source, parent, root, matcher, errorCollector);
61
+ return matchPlainObj(source, parent, root, matcher, failureLog);
62
62
  }
63
63
  if (Array.isArray(source)) {
64
64
  // source is an array
65
- return matchArr(source, root, matcher, errorCollector);
65
+ return matchArr(source, parent, root, matcher, failureLog);
66
66
  }
67
67
  // already determined above that the source and matcher are not equal
68
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push(`value ${JSON.stringify(source)} does not match given matcher ${JSON.stringify(matcher)}`);
68
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push(`value ${JSON.stringify(source)} does not match given matcher ${JSON.stringify(matcher)}`);
69
69
  return false;
70
70
  }
71
71
  /**
72
72
  * Match an array matcher against the given source.
73
73
  */
74
- function matchArr(source, root, matcher, errorCollector) {
74
+ function matchArr(source, parent, root, matcher, failureLog) {
75
75
  if (Array.isArray(matcher)) {
76
76
  // directly compare array contents
77
77
  const length = source.length;
78
78
  if (length !== matcher.length) {
79
79
  // if lengths not equal, arrays are not equal
80
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push(`array lengths are not equal: value length ${source.length} !== matcher length ${matcher.length}`);
80
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push(`array lengths are not equal: value length ${source.length} !== matcher length ${matcher.length}`);
81
81
  return false;
82
82
  }
83
83
  // loop over arrays, matching every value
84
84
  let index = -1;
85
85
  while (++index < length) {
86
- if (!Object.is(source[index], matcher[index])) {
86
+ if (!matchEntry(source[index], source, root, matcher[index], failureLog)) {
87
87
  // item did not match, return false
88
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push(`index ${index} does not match with value ${JSON.stringify(source[index])} and matcher ${matcher[index]}`);
88
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push(`index ${index} does not match with value ${JSON.stringify(source[index])} and matcher ${matcher[index]}`);
89
89
  return false;
90
90
  }
91
91
  }
92
92
  // all items are equal
93
93
  return true;
94
94
  }
95
+ // matcher is plain object
96
+ if (`every` in matcher) {
97
+ return matchCompound(source, parent, root, ['every', ...matcher.every], failureLog);
98
+ }
99
+ if (`some` in matcher) {
100
+ return matchCompound(source, parent, root, ['some', ...matcher.some], failureLog);
101
+ }
102
+ if (`none` in matcher) {
103
+ return matchCompound(source, parent, root, ['none', ...matcher.none], failureLog);
104
+ }
105
+ if (`single` in matcher) {
106
+ return matchCompound(source, parent, root, ['single', ...matcher.single], failureLog);
107
+ }
108
+ if (`someItem` in matcher) {
109
+ return matchTraversal(source, root, 'someItem', matcher.someItem, failureLog);
110
+ }
111
+ if (`everyItem` in matcher) {
112
+ return matchTraversal(source, root, 'everyItem', matcher.everyItem, failureLog);
113
+ }
114
+ if (`noneItem` in matcher) {
115
+ return matchTraversal(source, root, 'noneItem', matcher.noneItem, failureLog);
116
+ }
117
+ if (`singleItem` in matcher) {
118
+ return matchTraversal(source, root, 'singleItem', matcher.singleItem, failureLog);
119
+ }
95
120
  // matcher is plain object with index keys
96
121
  for (const index in matcher) {
97
122
  const matcherAtIndex = matcher[index];
98
123
  if (!(index in source)) {
99
124
  // source does not have item at given index
100
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push(`index ${index} does not exist in source ${JSON.stringify(source)} but should match matcher ${JSON.stringify(matcherAtIndex)}`);
125
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push(`index ${index} does not exist in source ${JSON.stringify(source)} but should match matcher ${JSON.stringify(matcherAtIndex)}`);
101
126
  return false;
102
127
  }
103
128
  // match the source item at the given index
104
- const result = matchEntry(source[index], source, root, matcherAtIndex, errorCollector);
129
+ const result = matchEntry(source[index], source, root, matcherAtIndex, failureLog);
105
130
  if (!result) {
106
131
  // item did not match
107
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push(`index ${index} does not match with value ${JSON.stringify(source[index])} and matcher ${JSON.stringify(matcherAtIndex)}`);
132
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push(`index ${index} does not match with value ${JSON.stringify(source[index])} and matcher ${JSON.stringify(matcherAtIndex)}`);
108
133
  return false;
109
134
  }
110
135
  }
@@ -114,22 +139,22 @@ function matchArr(source, root, matcher, errorCollector) {
114
139
  /**
115
140
  * Match an object matcher against the given source.
116
141
  */
117
- function matchPlainObj(source, parent, root, matcher, errorCollector) {
142
+ function matchPlainObj(source, parent, root, matcher, failureLog) {
118
143
  if (Array.isArray(matcher)) {
119
144
  // the matcher is of compound type
120
- return matchCompound(source, parent, root, matcher, errorCollector);
145
+ return matchCompound(source, parent, root, matcher, failureLog);
121
146
  }
122
147
  // partial object props matcher
123
148
  for (const key in matcher) {
124
149
  if (!(key in source)) {
125
150
  // the source does not have the given key
126
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push(`key ${key} is specified in matcher but not present in value ${JSON.stringify(source)}`);
151
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push(`key ${key} is specified in matcher but not present in value ${JSON.stringify(source)}`);
127
152
  return false;
128
153
  }
129
154
  // match the source value at the given key with the matcher at given key
130
- const result = matchEntry(source[key], source, root, matcher[key], errorCollector);
155
+ const result = matchEntry(source[key], source, root, matcher[key], failureLog);
131
156
  if (!result) {
132
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push(`key ${key} does not match in value ${JSON.stringify(source[key])} with matcher ${JSON.stringify(matcher[key])}`);
157
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push(`key ${key} does not match in value ${JSON.stringify(source[key])} with matcher ${JSON.stringify(matcher[key])}`);
133
158
  return false;
134
159
  }
135
160
  }
@@ -139,7 +164,7 @@ function matchPlainObj(source, parent, root, matcher, errorCollector) {
139
164
  /**
140
165
  * Match a compound matcher against the given source.
141
166
  */
142
- function matchCompound(source, parent, root, compound, errorCollector) {
167
+ function matchCompound(source, parent, root, compound, failureLog) {
143
168
  // first item indicates compound match type
144
169
  const matchType = compound[0];
145
170
  const length = compound.length;
@@ -149,9 +174,9 @@ function matchCompound(source, parent, root, compound, errorCollector) {
149
174
  case 'every': {
150
175
  while (++index < length) {
151
176
  // if any item does not match, return false
152
- const result = matchEntry(source, parent, root, compound[index], errorCollector);
177
+ const result = matchEntry(source, parent, root, compound[index], failureLog);
153
178
  if (!result) {
154
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push(`in compound "every": match at index ${index} failed`);
179
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push(`in compound "every": match at index ${index} failed`);
155
180
  return false;
156
181
  }
157
182
  }
@@ -160,9 +185,9 @@ function matchCompound(source, parent, root, compound, errorCollector) {
160
185
  case 'none': {
161
186
  // if any item matches, return false
162
187
  while (++index < length) {
163
- const result = matchEntry(source, parent, root, compound[index], errorCollector);
188
+ const result = matchEntry(source, parent, root, compound[index], failureLog);
164
189
  if (result) {
165
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push(`in compound "none": match at index ${index} succeeded`);
190
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push(`in compound "none": match at index ${index} succeeded`);
166
191
  return false;
167
192
  }
168
193
  }
@@ -172,31 +197,81 @@ function matchCompound(source, parent, root, compound, errorCollector) {
172
197
  // if not exactly one item matches, return false
173
198
  let onePassed = false;
174
199
  while (++index < length) {
175
- const result = matchEntry(source, parent, root, compound[index], errorCollector);
200
+ const result = matchEntry(source, parent, root, compound[index], failureLog);
176
201
  if (result) {
177
202
  if (onePassed) {
178
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push(`in compound "single": multiple matches succeeded`);
203
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push(`in compound "single": multiple matches succeeded`);
179
204
  return false;
180
205
  }
181
206
  onePassed = true;
182
207
  }
183
208
  }
184
209
  if (!onePassed) {
185
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push(`in compound "single": no matches succeeded`);
210
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push(`in compound "single": no matches succeeded`);
186
211
  }
187
212
  return onePassed;
188
213
  }
189
214
  case 'some': {
190
215
  // if any item matches, return true
191
216
  while (++index < length) {
192
- const result = matchEntry(source, parent, root, compound[index], errorCollector);
217
+ const result = matchEntry(source, parent, root, compound[index], failureLog);
193
218
  if (result) {
194
219
  return true;
195
220
  }
196
221
  }
197
- errorCollector === null || errorCollector === void 0 ? void 0 : errorCollector.push(`in compound "some": no matches succeeded`);
222
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push(`in compound "some": no matches succeeded`);
198
223
  return false;
199
224
  }
200
225
  }
201
226
  }
227
+ function matchTraversal(source, root, matchType, matcher, failureLog) {
228
+ let index = -1;
229
+ const length = source.length;
230
+ switch (matchType) {
231
+ case 'someItem': {
232
+ while (++index < length) {
233
+ if (matchEntry(source[index], source, root, matcher, failureLog)) {
234
+ return true;
235
+ }
236
+ }
237
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push(`in array traversal "someItem": no items matched given matcher`);
238
+ return false;
239
+ }
240
+ case 'everyItem': {
241
+ while (++index < length) {
242
+ if (!matchEntry(source[index], source, root, matcher, failureLog)) {
243
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push(`in array traversal "everyItem": at least one item did not match given matcher`);
244
+ return false;
245
+ }
246
+ }
247
+ return true;
248
+ }
249
+ case 'noneItem': {
250
+ while (++index < length) {
251
+ if (matchEntry(source[index], source, root, matcher, failureLog)) {
252
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push(`in array traversal "noneItem": at least one item matched given matcher`);
253
+ return false;
254
+ }
255
+ }
256
+ return true;
257
+ }
258
+ case 'singleItem': {
259
+ let singleMatched = false;
260
+ while (++index < length) {
261
+ if (matchEntry(source[index], source, root, matcher, failureLog)) {
262
+ if (singleMatched) {
263
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push(`in array traversal "singleItem": more than one item matched given matcher`);
264
+ return false;
265
+ }
266
+ singleMatched = true;
267
+ }
268
+ }
269
+ if (!singleMatched) {
270
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push(`in array traversal "singleItem": no item matched given matcher`);
271
+ return false;
272
+ }
273
+ return true;
274
+ }
275
+ }
276
+ }
202
277
  //# sourceMappingURL=match.js.map