@player-ui/partial-match-registry 0.15.5--canary.888.37918 → 0.15.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Registry.native.js +124 -161
- package/dist/Registry.native.js.map +1 -1
- package/dist/cjs/index.cjs +12 -47
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +12 -47
- package/dist/index.mjs +12 -47
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/matcher.test.ts +0 -24
- package/src/__tests__/registry.test.ts +2 -67
- package/src/deep-partial-matcher.ts +1 -7
- package/src/index.ts +17 -61
- package/types/index.d.ts +3 -31
package/dist/Registry.native.js
CHANGED
|
@@ -81,23 +81,6 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
81
81
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
82
82
|
}
|
|
83
83
|
var Registry = function() {
|
|
84
|
-
var createNewSortInstance = function createNewSortInstance(opts) {
|
|
85
|
-
var comparer = castComparer(opts.comparer);
|
|
86
|
-
return function(arrayToSort) {
|
|
87
|
-
var ctx = Array.isArray(arrayToSort) && !opts.inPlaceSorting ? arrayToSort.slice() : arrayToSort;
|
|
88
|
-
return {
|
|
89
|
-
asc: function asc(sortBy) {
|
|
90
|
-
return sortArray(1, ctx, sortBy, comparer);
|
|
91
|
-
},
|
|
92
|
-
desc: function desc(sortBy) {
|
|
93
|
-
return sortArray(-1, ctx, sortBy, comparer);
|
|
94
|
-
},
|
|
95
|
-
by: function by(sortBy) {
|
|
96
|
-
return sortArray(1, ctx, sortBy, comparer);
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
84
|
var dlv_es_default = // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/dlv@1.1.3/node_modules/dlv/dist/dlv.es.js
|
|
102
85
|
function dlv_es_default(t, e, l, n, r) {
|
|
103
86
|
for(e = e.split ? e.split(".") : e, n = 0; n < e.length; n++)t = t ? t[e[n]] : r;
|
|
@@ -105,7 +88,7 @@ var Registry = function() {
|
|
|
105
88
|
};
|
|
106
89
|
var createObjectMatcher = function createObjectMatcher(partialObj) {
|
|
107
90
|
var pairs = traverseObj(partialObj);
|
|
108
|
-
var matchFunction = function(searchObj) {
|
|
91
|
+
var matchFunction = function matchFunction(searchObj) {
|
|
109
92
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
110
93
|
try {
|
|
111
94
|
for(var _iterator = Array.from(pairs)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
@@ -136,30 +119,39 @@ var Registry = function() {
|
|
|
136
119
|
};
|
|
137
120
|
var createBasicMatcher = // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/index.ts
|
|
138
121
|
function createBasicMatcher(seed) {
|
|
139
|
-
var matcher = function(match) {
|
|
122
|
+
var matcher = function matcher(match) {
|
|
140
123
|
return seed === match;
|
|
141
124
|
};
|
|
142
125
|
matcher.count = 1;
|
|
143
126
|
return matcher;
|
|
144
127
|
};
|
|
128
|
+
var __create = Object.create;
|
|
145
129
|
var __defProp = Object.defineProperty;
|
|
146
130
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
147
131
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
132
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
148
133
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
149
|
-
var
|
|
134
|
+
var __commonJS = function __commonJS(cb, mod) {
|
|
135
|
+
return function __require() {
|
|
136
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = {
|
|
137
|
+
exports: {}
|
|
138
|
+
}).exports, mod), mod.exports;
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
var __export = function __export(target, all) {
|
|
150
142
|
for(var name in all)__defProp(target, name, {
|
|
151
143
|
get: all[name],
|
|
152
144
|
enumerable: true
|
|
153
145
|
});
|
|
154
146
|
};
|
|
155
|
-
var __copyProps = function(to, from, except, desc) {
|
|
147
|
+
var __copyProps = function __copyProps(to, from, except, desc) {
|
|
156
148
|
if (from && (typeof from === "undefined" ? "undefined" : _type_of(from)) === "object" || typeof from === "function") {
|
|
157
149
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
158
150
|
try {
|
|
159
151
|
var _loop = function() {
|
|
160
152
|
var key = _step.value;
|
|
161
153
|
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
162
|
-
get: function() {
|
|
154
|
+
get: function get() {
|
|
163
155
|
return from[key];
|
|
164
156
|
},
|
|
165
157
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
@@ -183,117 +175,113 @@ var Registry = function() {
|
|
|
183
175
|
}
|
|
184
176
|
return to;
|
|
185
177
|
};
|
|
186
|
-
var
|
|
178
|
+
var __toESM = function __toESM(mod, isNodeMode, target) {
|
|
179
|
+
return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
|
|
180
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
181
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
182
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
183
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
184
|
+
value: mod,
|
|
185
|
+
enumerable: true
|
|
186
|
+
}) : target, mod);
|
|
187
|
+
};
|
|
188
|
+
var __toCommonJS = function __toCommonJS(mod) {
|
|
187
189
|
return __copyProps(__defProp({}, "__esModule", {
|
|
188
190
|
value: true
|
|
189
191
|
}), mod);
|
|
190
192
|
};
|
|
193
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/sorted-array@2.0.4/node_modules/sorted-array/sorted-array.js
|
|
194
|
+
var require_sorted_array = __commonJS({
|
|
195
|
+
"../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/sorted-array@2.0.4/node_modules/sorted-array/sorted-array.js": function(exports, module) {
|
|
196
|
+
"use strict";
|
|
197
|
+
var SortedArray2 = function() {
|
|
198
|
+
var SortedArray3 = defclass({
|
|
199
|
+
constructor: function constructor(array, compare) {
|
|
200
|
+
this.array = [];
|
|
201
|
+
this.compare = compare || compareDefault;
|
|
202
|
+
var length = array.length, index = 0;
|
|
203
|
+
while(index < length)this.insert(array[index++]);
|
|
204
|
+
},
|
|
205
|
+
insert: function insert(element) {
|
|
206
|
+
var array = this.array, compare = this.compare, high = array.length - 1, low = 0, pos = -1, index, ordering;
|
|
207
|
+
while(high >= low){
|
|
208
|
+
index = (high + low) / 2 >>> 0;
|
|
209
|
+
ordering = compare(array[index], element);
|
|
210
|
+
if (ordering < 0) low = index + 1;
|
|
211
|
+
else if (ordering > 0) high = index - 1;
|
|
212
|
+
else {
|
|
213
|
+
pos = index;
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
;
|
|
217
|
+
}
|
|
218
|
+
if (pos === -1) {
|
|
219
|
+
pos = high;
|
|
220
|
+
}
|
|
221
|
+
pos++;
|
|
222
|
+
high = array.length - 1;
|
|
223
|
+
while(pos < high && compare(element, array[pos]) === 0){
|
|
224
|
+
pos++;
|
|
225
|
+
}
|
|
226
|
+
index = array.length;
|
|
227
|
+
array.push(element);
|
|
228
|
+
while(index > pos){
|
|
229
|
+
array[index] = array[--index];
|
|
230
|
+
}
|
|
231
|
+
array[pos] = element;
|
|
232
|
+
return this;
|
|
233
|
+
},
|
|
234
|
+
search: function search(element) {
|
|
235
|
+
var array = this.array, compare = this.compare, high = array.length - 1, low = 0, index, ordering;
|
|
236
|
+
while(high >= low){
|
|
237
|
+
index = (high + low) / 2 >>> 0;
|
|
238
|
+
ordering = compare(array[index], element);
|
|
239
|
+
if (ordering < 0) low = index + 1;
|
|
240
|
+
else if (ordering > 0) high = index - 1;
|
|
241
|
+
else return index;
|
|
242
|
+
}
|
|
243
|
+
return -1;
|
|
244
|
+
},
|
|
245
|
+
remove: function remove(element) {
|
|
246
|
+
var index = this.search(element);
|
|
247
|
+
if (index >= 0) this.array.splice(index, 1);
|
|
248
|
+
return this;
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
SortedArray3.comparing = function(property, array) {
|
|
252
|
+
return new SortedArray3(array, function(a, b) {
|
|
253
|
+
return compareDefault(a[property], b[property]);
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
return SortedArray3;
|
|
257
|
+
function defclass(prototype) {
|
|
258
|
+
var constructor = prototype.constructor;
|
|
259
|
+
constructor.prototype = prototype;
|
|
260
|
+
return constructor;
|
|
261
|
+
}
|
|
262
|
+
function compareDefault(a, b) {
|
|
263
|
+
if (a < b) return -1;
|
|
264
|
+
else if (a > b) return 1;
|
|
265
|
+
else return 0;
|
|
266
|
+
}
|
|
267
|
+
}();
|
|
268
|
+
if ((typeof module === "undefined" ? "undefined" : _type_of(module)) === "object") module.exports = SortedArray2;
|
|
269
|
+
if (typeof define === "function" && define.amd) define(function() {
|
|
270
|
+
return SortedArray2;
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
});
|
|
191
274
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/index.ts
|
|
192
275
|
var src_exports = {};
|
|
193
276
|
__export(src_exports, {
|
|
194
|
-
Registry: function() {
|
|
277
|
+
Registry: function Registry1() {
|
|
195
278
|
return Registry;
|
|
196
279
|
},
|
|
197
|
-
createObjectMatcher: function() {
|
|
280
|
+
createObjectMatcher: function createObjectMatcher1() {
|
|
198
281
|
return createObjectMatcher;
|
|
199
282
|
}
|
|
200
283
|
});
|
|
201
|
-
|
|
202
|
-
var castComparer = function castComparer(comparer) {
|
|
203
|
-
return function(a, b, order) {
|
|
204
|
-
return comparer(a, b, order) * order;
|
|
205
|
-
};
|
|
206
|
-
};
|
|
207
|
-
var throwInvalidConfigErrorIfTrue = function throwInvalidConfigErrorIfTrue(condition, context) {
|
|
208
|
-
if (condition) throw Error("Invalid sort config: " + context);
|
|
209
|
-
};
|
|
210
|
-
var unpackObjectSorter = function unpackObjectSorter(sortByObj) {
|
|
211
|
-
var _a = sortByObj || {}, asc = _a.asc, desc = _a.desc;
|
|
212
|
-
var order = asc ? 1 : -1;
|
|
213
|
-
var sortBy = asc || desc;
|
|
214
|
-
throwInvalidConfigErrorIfTrue(!sortBy, "Expected `asc` or `desc` property");
|
|
215
|
-
throwInvalidConfigErrorIfTrue(asc && desc, "Ambiguous object with `asc` and `desc` config properties");
|
|
216
|
-
var comparer = sortByObj.comparer && castComparer(sortByObj.comparer);
|
|
217
|
-
return {
|
|
218
|
-
order: order,
|
|
219
|
-
sortBy: sortBy,
|
|
220
|
-
comparer: comparer
|
|
221
|
-
};
|
|
222
|
-
};
|
|
223
|
-
var multiPropertySorterProvider = function multiPropertySorterProvider(defaultComparer2) {
|
|
224
|
-
return function multiPropertySorter(sortBy, sortByArr, depth, order, comparer, a, b) {
|
|
225
|
-
var valA;
|
|
226
|
-
var valB;
|
|
227
|
-
if (typeof sortBy === "string") {
|
|
228
|
-
valA = a[sortBy];
|
|
229
|
-
valB = b[sortBy];
|
|
230
|
-
} else if (typeof sortBy === "function") {
|
|
231
|
-
valA = sortBy(a);
|
|
232
|
-
valB = sortBy(b);
|
|
233
|
-
} else {
|
|
234
|
-
var objectSorterConfig = unpackObjectSorter(sortBy);
|
|
235
|
-
return multiPropertySorter(objectSorterConfig.sortBy, sortByArr, depth, objectSorterConfig.order, objectSorterConfig.comparer || defaultComparer2, a, b);
|
|
236
|
-
}
|
|
237
|
-
var equality = comparer(valA, valB, order);
|
|
238
|
-
if ((equality === 0 || valA == null && valB == null) && sortByArr.length > depth) {
|
|
239
|
-
return multiPropertySorter(sortByArr[depth], sortByArr, depth + 1, order, comparer, a, b);
|
|
240
|
-
}
|
|
241
|
-
return equality;
|
|
242
|
-
};
|
|
243
|
-
};
|
|
244
|
-
function getSortStrategy(sortBy, comparer, order) {
|
|
245
|
-
if (sortBy === void 0 || sortBy === true) {
|
|
246
|
-
return function(a, b) {
|
|
247
|
-
return comparer(a, b, order);
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
if (typeof sortBy === "string") {
|
|
251
|
-
throwInvalidConfigErrorIfTrue(sortBy.includes("."), "String syntax not allowed for nested properties.");
|
|
252
|
-
return function(a, b) {
|
|
253
|
-
return comparer(a[sortBy], b[sortBy], order);
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
if (typeof sortBy === "function") {
|
|
257
|
-
return function(a, b) {
|
|
258
|
-
return comparer(sortBy(a), sortBy(b), order);
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
if (Array.isArray(sortBy)) {
|
|
262
|
-
var multiPropSorter_1 = multiPropertySorterProvider(comparer);
|
|
263
|
-
return function(a, b) {
|
|
264
|
-
return multiPropSorter_1(sortBy[0], sortBy, 1, order, comparer, a, b);
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
var objectSorterConfig = unpackObjectSorter(sortBy);
|
|
268
|
-
return getSortStrategy(objectSorterConfig.sortBy, objectSorterConfig.comparer || comparer, objectSorterConfig.order);
|
|
269
|
-
}
|
|
270
|
-
var sortArray = function sortArray(order, ctx, sortBy, comparer) {
|
|
271
|
-
var _a;
|
|
272
|
-
if (!Array.isArray(ctx)) {
|
|
273
|
-
return ctx;
|
|
274
|
-
}
|
|
275
|
-
if (Array.isArray(sortBy) && sortBy.length < 2) {
|
|
276
|
-
_a = sortBy, sortBy = _a[0];
|
|
277
|
-
}
|
|
278
|
-
return ctx.sort(getSortStrategy(sortBy, comparer, order));
|
|
279
|
-
};
|
|
280
|
-
var defaultComparer = function defaultComparer(a, b, order) {
|
|
281
|
-
if (a == null) return order;
|
|
282
|
-
if (b == null) return -order;
|
|
283
|
-
if ((typeof a === "undefined" ? "undefined" : _type_of(a)) !== (typeof b === "undefined" ? "undefined" : _type_of(b))) {
|
|
284
|
-
return (typeof a === "undefined" ? "undefined" : _type_of(a)) < (typeof b === "undefined" ? "undefined" : _type_of(b)) ? -1 : 1;
|
|
285
|
-
}
|
|
286
|
-
if (a < b) return -1;
|
|
287
|
-
if (a > b) return 1;
|
|
288
|
-
return 0;
|
|
289
|
-
};
|
|
290
|
-
var sort = createNewSortInstance({
|
|
291
|
-
comparer: defaultComparer
|
|
292
|
-
});
|
|
293
|
-
var inPlaceSort = createNewSortInstance({
|
|
294
|
-
comparer: defaultComparer,
|
|
295
|
-
inPlaceSorting: true
|
|
296
|
-
});
|
|
284
|
+
var import_sorted_array = __toESM(require_sorted_array());
|
|
297
285
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/deep-partial-matcher.ts
|
|
298
286
|
function traverseObj(object) {
|
|
299
287
|
var path = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [], pairs = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : /* @__PURE__ */ new Map();
|
|
@@ -305,7 +293,7 @@ var Registry = function() {
|
|
|
305
293
|
var nestedPath = _to_consumable_array(path).concat([
|
|
306
294
|
key
|
|
307
295
|
]);
|
|
308
|
-
if ((typeof val === "undefined" ? "undefined" : _type_of(val)) === "object"
|
|
296
|
+
if ((typeof val === "undefined" ? "undefined" : _type_of(val)) === "object") {
|
|
309
297
|
traverseObj(val, nestedPath, pairs);
|
|
310
298
|
} else {
|
|
311
299
|
pairs.set(nestedPath, val);
|
|
@@ -327,12 +315,16 @@ var Registry = function() {
|
|
|
327
315
|
}
|
|
328
316
|
return pairs;
|
|
329
317
|
}
|
|
318
|
+
var createSortedArray = function createSortedArray() {
|
|
319
|
+
return new import_sorted_array.default([], function(c) {
|
|
320
|
+
return c.matcher.count;
|
|
321
|
+
});
|
|
322
|
+
};
|
|
330
323
|
var Registry = /*#__PURE__*/ function() {
|
|
331
|
-
function Registry(initialSet
|
|
324
|
+
function Registry(initialSet) {
|
|
332
325
|
var _this = this;
|
|
333
326
|
_class_call_check(this, Registry);
|
|
334
|
-
this.store =
|
|
335
|
-
this.logger = logger;
|
|
327
|
+
this.store = createSortedArray();
|
|
336
328
|
initialSet === null || initialSet === void 0 ? void 0 : initialSet.forEach(function(param) {
|
|
337
329
|
var _param = _sliced_to_array(param, 2), match = _param[0], value = _param[1];
|
|
338
330
|
_this.set(match, value);
|
|
@@ -340,50 +332,22 @@ var Registry = function() {
|
|
|
340
332
|
}
|
|
341
333
|
_create_class(Registry, [
|
|
342
334
|
{
|
|
343
|
-
/**
|
|
344
|
-
* Add match -> value mapping to the registry
|
|
345
|
-
*
|
|
346
|
-
* If an entry with the same specificity and matching key already exists, it will be replaced
|
|
347
|
-
* and a debug log will be emitted (if a logger is configured).
|
|
348
|
-
*
|
|
349
|
-
* @param match - The key to match against (can be a primitive or object)
|
|
350
|
-
* @param value - The value to associate with this key
|
|
351
|
-
*/ key: "set",
|
|
335
|
+
/** Add match -> value mapping to the registry */ key: "set",
|
|
352
336
|
value: function set(match, value) {
|
|
353
337
|
var matcher = (typeof match === "undefined" ? "undefined" : _type_of(match)) === "object" ? createObjectMatcher(match) : createBasicMatcher(match);
|
|
354
|
-
|
|
355
|
-
return entry.matcher(match) && matcher(entry.key);
|
|
356
|
-
});
|
|
357
|
-
if (existingIndex !== -1) {
|
|
358
|
-
var _this_logger_debug, _this_logger;
|
|
359
|
-
this.store.splice(existingIndex, 1);
|
|
360
|
-
(_this_logger = this.logger) === null || _this_logger === void 0 ? void 0 : (_this_logger_debug = _this_logger.debug) === null || _this_logger_debug === void 0 ? void 0 : _this_logger_debug.call(_this_logger, "Registry: Replacing existing entry for key ", match);
|
|
361
|
-
}
|
|
362
|
-
this.store.push({
|
|
338
|
+
this.store.insert({
|
|
363
339
|
key: match,
|
|
364
340
|
value: value,
|
|
365
341
|
matcher: matcher
|
|
366
342
|
});
|
|
367
|
-
this.store = sort(this.store).desc(function(entry) {
|
|
368
|
-
return entry.matcher.count;
|
|
369
|
-
});
|
|
370
343
|
}
|
|
371
344
|
},
|
|
372
345
|
{
|
|
373
|
-
/**
|
|
374
|
-
* Fetch the best match in the registry
|
|
375
|
-
*
|
|
376
|
-
* Searches for the most specific entry that matches the given query.
|
|
377
|
-
* The registry is sorted by specificity (matcher.count) in descending order,
|
|
378
|
-
* so we iterate forward to find the highest specificity match first.
|
|
379
|
-
*
|
|
380
|
-
* @param query - The query object to match against registered keys
|
|
381
|
-
* @returns The value associated with the best matching key, or undefined if no match found
|
|
382
|
-
*/ key: "get",
|
|
346
|
+
/** Fetch the best match in the registry */ key: "get",
|
|
383
347
|
value: function get(query) {
|
|
384
348
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
385
349
|
try {
|
|
386
|
-
for(var _iterator = this.store[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
350
|
+
for(var _iterator = this.store.array[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
387
351
|
var entry = _step.value;
|
|
388
352
|
if (entry.matcher(query)) {
|
|
389
353
|
return entry.value;
|
|
@@ -403,7 +367,6 @@ var Registry = function() {
|
|
|
403
367
|
}
|
|
404
368
|
}
|
|
405
369
|
}
|
|
406
|
-
return void 0;
|
|
407
370
|
}
|
|
408
371
|
},
|
|
409
372
|
{
|
|
@@ -411,7 +374,7 @@ var Registry = function() {
|
|
|
411
374
|
value: function forEach(callbackfn) {
|
|
412
375
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
413
376
|
try {
|
|
414
|
-
for(var _iterator = this.store[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
377
|
+
for(var _iterator = this.store.array[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
415
378
|
var entry = _step.value;
|
|
416
379
|
callbackfn(entry);
|
|
417
380
|
}
|
|
@@ -434,13 +397,13 @@ var Registry = function() {
|
|
|
434
397
|
{
|
|
435
398
|
/** Reset the items in the registry */ key: "clear",
|
|
436
399
|
value: function clear() {
|
|
437
|
-
this.store =
|
|
400
|
+
this.store = createSortedArray();
|
|
438
401
|
}
|
|
439
402
|
},
|
|
440
403
|
{
|
|
441
404
|
/** Check if the registry is empty*/ key: "isRegistryEmpty",
|
|
442
405
|
value: function isRegistryEmpty() {
|
|
443
|
-
return this.store.length === 0;
|
|
406
|
+
return this.store.array.length === 0;
|
|
444
407
|
}
|
|
445
408
|
}
|
|
446
409
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2053/execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/dist/index.global.js","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/fast-sort@3.4.1/node_modules/fast-sort/dist/sort.mjs","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/dlv@1.1.3/node_modules/dlv/index.js","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/deep-partial-matcher.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/index.ts"],"names":["Registry","createNewSortInstance","opts","comparer","castComparer","arrayToSort","ctx","Array","isArray","inPlaceSorting","slice","asc","sortBy","sortArray","desc","by","dlv_es_default","obj","key","def","p","undef","split","length","createObjectMatcher","partialObj","pairs","traverseObj","matchFunction","searchObj","from","entry","path","value","count","size","createBasicMatcher","seed","matcher","match","__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","except","call","__toCommonJS","mod","src_exports","a","b","order","throwInvalidConfigErrorIfTrue","condition","context","Error","unpackObjectSorter","sortByObj","_a","multiPropertySorterProvider","defaultComparer","multiPropertySorter","sortByArr","depth","valA","valB","objectSorterConfig","equality","getSortStrategy","includes","multiPropSorter_1","sort","inPlaceSort","object","Map","keys","val","nestedPath","set","initialSet","logger","store","forEach","existingIndex","findIndex","splice","debug","push","query","callbackfn","clear","isRegistryEmpty"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAIA,WAAW,AAAC;QC2EPC,wBAAT,SAASA,sBAAsBC,IAAA;QAC3B,IAAIC,WAAWC,aAAaF,KAAKC,QAAQ;QACzC,OAAO,SAAUE,WAAA;YACb,IAAIC,MAAMC,MAAMC,OAAA,CAAQH,gBAAgB,CAACH,KAAKO,cAAA,GACxCJ,YAAYK,KAAA,KACZL;YACN,OAAO;gBACHM,KAAK,SAALA,IAAeC,MAAA;oBACX,OAAOC,UAAU,GAAGP,KAAKM,QAAQT;gBACrC;gBACAW,MAAM,SAANA,KAAgBF,MAAA;oBACZ,OAAOC,UAAU,CAAA,GAAIP,KAAKM,QAAQT;gBACtC;gBACAY,IAAI,SAAJA,GAAcH,MAAA;oBACV,OAAOC,UAAU,GAAGP,KAAKM,QAAQT;gBACrC;YACJ;QACJ;IACJ;QC9Fea,iBF8Ib,kJAAkJ;IE9IrI,SAAAA,eAAaC,CAAAA,EAAKC,CAAAA,EAAKC,CAAAA,EAAKC,CAAAA,EAAGC,CAAAA;QAAAA,IAC7CH,IAAMA,EAAII,KAAAA,GAAQJ,EAAII,KAAAA,CAAM,OAAOJ,GA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;;;gCAAA;sCAAA;;;;gBAGF;;;gBAAA,oCAAA,GAGAyE,KAAAA;uBAAAA,SAAAA;oBACE,IAAA,CAAKT,KAAA,GAAQ,EAAC;gBAChB;;;gBAAA,kCAAA,GAGAU,KAAAA;uBAAAA,SAAAA;oBACE,OAAO,IAAA,CAAKV,KAAA,CAAMxE,MAAA,KAAW;gBAC/B;;;;;IJqIA,OAAOqC,aAAaE;AACtB","sourcesContent":["\"use strict\";\nvar Registry = (() => {\n var __defProp = Object.defineProperty;\n var __getOwnPropDesc = Object.getOwnPropertyDescriptor;\n var __getOwnPropNames = Object.getOwnPropertyNames;\n var __hasOwnProp = Object.prototype.hasOwnProperty;\n var __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n };\n var __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n };\n var __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\n\n // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/index.ts\n var src_exports = {};\n __export(src_exports, {\n Registry: () => Registry,\n createObjectMatcher: () => createObjectMatcher\n });\n\n // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/fast-sort@3.4.1/node_modules/fast-sort/dist/sort.mjs\n var castComparer = function(comparer) {\n return function(a, b, order) {\n return comparer(a, b, order) * order;\n };\n };\n var throwInvalidConfigErrorIfTrue = function(condition, context) {\n if (condition)\n throw Error(\"Invalid sort config: \" + context);\n };\n var unpackObjectSorter = function(sortByObj) {\n var _a = sortByObj || {}, asc = _a.asc, desc = _a.desc;\n var order = asc ? 1 : -1;\n var sortBy = asc || desc;\n throwInvalidConfigErrorIfTrue(!sortBy, \"Expected `asc` or `desc` property\");\n throwInvalidConfigErrorIfTrue(asc && desc, \"Ambiguous object with `asc` and `desc` config properties\");\n var comparer = sortByObj.comparer && castComparer(sortByObj.comparer);\n return { order, sortBy, comparer };\n };\n var multiPropertySorterProvider = function(defaultComparer2) {\n return function multiPropertySorter(sortBy, sortByArr, depth, order, comparer, a, b) {\n var valA;\n var valB;\n if (typeof sortBy === \"string\") {\n valA = a[sortBy];\n valB = b[sortBy];\n } else if (typeof sortBy === \"function\") {\n valA = sortBy(a);\n valB = sortBy(b);\n } else {\n var objectSorterConfig = unpackObjectSorter(sortBy);\n return multiPropertySorter(objectSorterConfig.sortBy, sortByArr, depth, objectSorterConfig.order, objectSorterConfig.comparer || defaultComparer2, a, b);\n }\n var equality = comparer(valA, valB, order);\n if ((equality === 0 || valA == null && valB == null) && sortByArr.length > depth) {\n return multiPropertySorter(sortByArr[depth], sortByArr, depth + 1, order, comparer, a, b);\n }\n return equality;\n };\n };\n function getSortStrategy(sortBy, comparer, order) {\n if (sortBy === void 0 || sortBy === true) {\n return function(a, b) {\n return comparer(a, b, order);\n };\n }\n if (typeof sortBy === \"string\") {\n throwInvalidConfigErrorIfTrue(sortBy.includes(\".\"), \"String syntax not allowed for nested properties.\");\n return function(a, b) {\n return comparer(a[sortBy], b[sortBy], order);\n };\n }\n if (typeof sortBy === \"function\") {\n return function(a, b) {\n return comparer(sortBy(a), sortBy(b), order);\n };\n }\n if (Array.isArray(sortBy)) {\n var multiPropSorter_1 = multiPropertySorterProvider(comparer);\n return function(a, b) {\n return multiPropSorter_1(sortBy[0], sortBy, 1, order, comparer, a, b);\n };\n }\n var objectSorterConfig = unpackObjectSorter(sortBy);\n return getSortStrategy(objectSorterConfig.sortBy, objectSorterConfig.comparer || comparer, objectSorterConfig.order);\n }\n var sortArray = function(order, ctx, sortBy, comparer) {\n var _a;\n if (!Array.isArray(ctx)) {\n return ctx;\n }\n if (Array.isArray(sortBy) && sortBy.length < 2) {\n _a = sortBy, sortBy = _a[0];\n }\n return ctx.sort(getSortStrategy(sortBy, comparer, order));\n };\n function createNewSortInstance(opts) {\n var comparer = castComparer(opts.comparer);\n return function(arrayToSort) {\n var ctx = Array.isArray(arrayToSort) && !opts.inPlaceSorting ? arrayToSort.slice() : arrayToSort;\n return {\n asc: function(sortBy) {\n return sortArray(1, ctx, sortBy, comparer);\n },\n desc: function(sortBy) {\n return sortArray(-1, ctx, sortBy, comparer);\n },\n by: function(sortBy) {\n return sortArray(1, ctx, sortBy, comparer);\n }\n };\n };\n }\n var defaultComparer = function(a, b, order) {\n if (a == null)\n return order;\n if (b == null)\n return -order;\n if (typeof a !== typeof b) {\n return typeof a < typeof b ? -1 : 1;\n }\n if (a < b)\n return -1;\n if (a > b)\n return 1;\n return 0;\n };\n var sort = createNewSortInstance({\n comparer: defaultComparer\n });\n var inPlaceSort = createNewSortInstance({\n comparer: defaultComparer,\n inPlaceSorting: true\n });\n\n // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/dlv@1.1.3/node_modules/dlv/dist/dlv.es.js\n function dlv_es_default(t, e, l, n, r) {\n for (e = e.split ? e.split(\".\") : e, n = 0; n < e.length; n++)\n t = t ? t[e[n]] : r;\n return t === r ? l : t;\n }\n\n // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/deep-partial-matcher.ts\n function traverseObj(object, path = [], pairs = /* @__PURE__ */ new Map()) {\n for (const key of Object.keys(object)) {\n const val = object[key];\n const nestedPath = [...path, key];\n if (typeof val === \"object\" && val !== null) {\n traverseObj(val, nestedPath, pairs);\n } else {\n pairs.set(nestedPath, val);\n }\n }\n return pairs;\n }\n function createObjectMatcher(partialObj) {\n const pairs = traverseObj(partialObj);\n const matchFunction = (searchObj) => {\n for (const entry of Array.from(pairs)) {\n const [path, value] = entry;\n if (dlv_es_default(searchObj, path) !== value) {\n return false;\n }\n }\n return true;\n };\n matchFunction.count = pairs.size;\n return matchFunction;\n }\n\n // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/index.ts\n function createBasicMatcher(seed) {\n const matcher = (match) => seed === match;\n matcher.count = 1;\n return matcher;\n }\n var Registry = class {\n /**\n * Creates a new Registry instance\n *\n * @param initialSet - Optional array of [key, value] tuples to populate the registry\n * @param logger - Optional logger instance for debug logging (e.g., when entries are replaced)\n */\n constructor(initialSet, logger) {\n this.store = [];\n this.logger = logger;\n initialSet?.forEach(([match, value]) => {\n this.set(match, value);\n });\n }\n /**\n * Add match -> value mapping to the registry\n *\n * If an entry with the same specificity and matching key already exists, it will be replaced\n * and a debug log will be emitted (if a logger is configured).\n *\n * @param match - The key to match against (can be a primitive or object)\n * @param value - The value to associate with this key\n */\n set(match, value) {\n const matcher = typeof match === \"object\" ? createObjectMatcher(match) : createBasicMatcher(match);\n const existingIndex = this.store.findIndex(\n (entry) => entry.matcher(match) && matcher(entry.key)\n );\n if (existingIndex !== -1) {\n this.store.splice(existingIndex, 1);\n this.logger?.debug?.(\n \"Registry: Replacing existing entry for key \",\n match\n );\n }\n this.store.push({\n key: match,\n value,\n matcher\n });\n this.store = sort(this.store).desc((entry) => entry.matcher.count);\n }\n /**\n * Fetch the best match in the registry\n *\n * Searches for the most specific entry that matches the given query.\n * The registry is sorted by specificity (matcher.count) in descending order,\n * so we iterate forward to find the highest specificity match first.\n *\n * @param query - The query object to match against registered keys\n * @returns The value associated with the best matching key, or undefined if no match found\n */\n get(query) {\n for (const entry of this.store) {\n if (entry.matcher(query)) {\n return entry.value;\n }\n }\n return void 0;\n }\n /** Loop over all entries and run callback */\n forEach(callbackfn) {\n for (const entry of this.store) {\n callbackfn(entry);\n }\n }\n /** Reset the items in the registry */\n clear() {\n this.store = [];\n }\n /** Check if the registry is empty*/\n isRegistryEmpty() {\n return this.store.length === 0;\n }\n };\n return __toCommonJS(src_exports);\n})();\n","// >>> INTERFACES <<<\r\n// >>> HELPERS <<<\r\nvar castComparer = function (comparer) { return function (a, b, order) { return comparer(a, b, order) * order; }; };\r\nvar throwInvalidConfigErrorIfTrue = function (condition, context) {\r\n if (condition)\r\n throw Error(\"Invalid sort config: \" + context);\r\n};\r\nvar unpackObjectSorter = function (sortByObj) {\r\n var _a = sortByObj || {}, asc = _a.asc, desc = _a.desc;\r\n var order = asc ? 1 : -1;\r\n var sortBy = (asc || desc);\r\n // Validate object config\r\n throwInvalidConfigErrorIfTrue(!sortBy, 'Expected `asc` or `desc` property');\r\n throwInvalidConfigErrorIfTrue(asc && desc, 'Ambiguous object with `asc` and `desc` config properties');\r\n var comparer = sortByObj.comparer && castComparer(sortByObj.comparer);\r\n return { order: order, sortBy: sortBy, comparer: comparer };\r\n};\r\n// >>> SORTERS <<<\r\nvar multiPropertySorterProvider = function (defaultComparer) {\r\n return function multiPropertySorter(sortBy, sortByArr, depth, order, comparer, a, b) {\r\n var valA;\r\n var valB;\r\n if (typeof sortBy === 'string') {\r\n valA = a[sortBy];\r\n valB = b[sortBy];\r\n }\r\n else if (typeof sortBy === 'function') {\r\n valA = sortBy(a);\r\n valB = sortBy(b);\r\n }\r\n else {\r\n var objectSorterConfig = unpackObjectSorter(sortBy);\r\n return multiPropertySorter(objectSorterConfig.sortBy, sortByArr, depth, objectSorterConfig.order, objectSorterConfig.comparer || defaultComparer, a, b);\r\n }\r\n var equality = comparer(valA, valB, order);\r\n if ((equality === 0 || (valA == null && valB == null)) &&\r\n sortByArr.length > depth) {\r\n return multiPropertySorter(sortByArr[depth], sortByArr, depth + 1, order, comparer, a, b);\r\n }\r\n return equality;\r\n };\r\n};\r\nfunction getSortStrategy(sortBy, comparer, order) {\r\n // Flat array sorter\r\n if (sortBy === undefined || sortBy === true) {\r\n return function (a, b) { return comparer(a, b, order); };\r\n }\r\n // Sort list of objects by single object key\r\n if (typeof sortBy === 'string') {\r\n throwInvalidConfigErrorIfTrue(sortBy.includes('.'), 'String syntax not allowed for nested properties.');\r\n return function (a, b) { return comparer(a[sortBy], b[sortBy], order); };\r\n }\r\n // Sort list of objects by single function sorter\r\n if (typeof sortBy === 'function') {\r\n return function (a, b) { return comparer(sortBy(a), sortBy(b), order); };\r\n }\r\n // Sort by multiple properties\r\n if (Array.isArray(sortBy)) {\r\n var multiPropSorter_1 = multiPropertySorterProvider(comparer);\r\n return function (a, b) { return multiPropSorter_1(sortBy[0], sortBy, 1, order, comparer, a, b); };\r\n }\r\n // Unpack object config to get actual sorter strategy\r\n var objectSorterConfig = unpackObjectSorter(sortBy);\r\n return getSortStrategy(objectSorterConfig.sortBy, objectSorterConfig.comparer || comparer, objectSorterConfig.order);\r\n}\r\nvar sortArray = function (order, ctx, sortBy, comparer) {\r\n var _a;\r\n if (!Array.isArray(ctx)) {\r\n return ctx;\r\n }\r\n // Unwrap sortBy if array with only 1 value to get faster sort strategy\r\n if (Array.isArray(sortBy) && sortBy.length < 2) {\r\n _a = sortBy, sortBy = _a[0];\r\n }\r\n return ctx.sort(getSortStrategy(sortBy, comparer, order));\r\n};\r\nfunction createNewSortInstance(opts) {\r\n var comparer = castComparer(opts.comparer);\r\n return function (arrayToSort) {\r\n var ctx = Array.isArray(arrayToSort) && !opts.inPlaceSorting\r\n ? arrayToSort.slice()\r\n : arrayToSort;\r\n return {\r\n asc: function (sortBy) {\r\n return sortArray(1, ctx, sortBy, comparer);\r\n },\r\n desc: function (sortBy) {\r\n return sortArray(-1, ctx, sortBy, comparer);\r\n },\r\n by: function (sortBy) {\r\n return sortArray(1, ctx, sortBy, comparer);\r\n },\r\n };\r\n };\r\n}\r\nvar defaultComparer = function (a, b, order) {\r\n if (a == null)\r\n return order;\r\n if (b == null)\r\n return -order;\r\n if (typeof a !== typeof b) {\r\n return typeof a < typeof b ? -1 : 1;\r\n }\r\n if (a < b)\r\n return -1;\r\n if (a > b)\r\n return 1;\r\n return 0;\r\n};\r\nvar sort = createNewSortInstance({\r\n comparer: defaultComparer,\r\n});\r\nvar inPlaceSort = createNewSortInstance({\r\n comparer: defaultComparer,\r\n inPlaceSorting: true,\r\n});\n\nexport { createNewSortInstance, defaultComparer, inPlaceSort, sort };\n","export default function dlv(obj, key, def, p, undef) {\n\tkey = key.split ? key.split('.') : key;\n\tfor (p = 0; p < key.length; p++) {\n\t\tobj = obj ? obj[key[p]] : undef;\n\t}\n\treturn obj === undef ? def : obj;\n}\n","import dlv from \"dlv\";\n\n/** A function that checks overlapping properties against a reference value */\nexport type Matcher = ((searchObj: object) => boolean) & {\n /** The count represents the specificity of this matcher */\n count: number;\n};\n\n/** Traverse an object and collect any key/value pairs including nested keys */\nfunction traverseObj(\n object: Record<any, any>,\n path: string[] = [],\n pairs: Map<string[], any> = new Map(),\n): Map<string[], any> {\n for (const key of Object.keys(object)) {\n const val: any = object[key];\n const nestedPath = [...path, key];\n\n /* Explicitly avoid traversing null values.\n JavaScript's typeof null === \"object\" would otherwise cause the function to traverse null as an object\n and throw an error. \n \n Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#typeof_null\n */\n if (typeof val === \"object\" && val !== null) {\n traverseObj(val, nestedPath, pairs);\n } else {\n pairs.set(nestedPath, val);\n }\n }\n\n return pairs;\n}\n\n/**\n * Given a partial object, create a matcher function that checks if another object matches the specified properties\n * @param partialObj The partial object to match against\n * @returns A matcher function that checks if an object matches the partial object\n */\nexport function createObjectMatcher(partialObj: object): Matcher {\n // Convert the partial object into a list of [key, value] pairs;\n const pairs = traverseObj(partialObj);\n\n /** Generate a function to match against all of the properties we care about */\n const matchFunction = (searchObj: object) => {\n for (const entry of Array.from(pairs)) {\n const [path, value] = entry;\n\n if (dlv(searchObj, path) !== value) {\n return false;\n }\n }\n\n return true;\n };\n\n // Keep track of the specificity of the comparator\n matchFunction.count = pairs.size;\n\n return matchFunction;\n}\n","import { sort } from \"fast-sort\";\nimport type { Matcher } from \"./deep-partial-matcher\";\nimport { createObjectMatcher } from \"./deep-partial-matcher\";\n\nexport { createObjectMatcher } from \"./deep-partial-matcher\";\n\n/** Minimal logger interface for registry operations */\ninterface Logger {\n debug?: (...args: Array<any>) => void;\n}\n\n/** create a matcher function that matches exactly */\nfunction createBasicMatcher(seed: any): Matcher {\n /** a simple matcher function that only matches itself */\n const matcher = (match: any) => seed === match;\n matcher.count = 1;\n\n return matcher;\n}\n\ninterface RegistryIndex<V> {\n /** The original object we wanted to match on */\n key: object;\n\n /** The value to return */\n value: V;\n\n /** The matcher function for this entry */\n matcher: Matcher;\n}\n\n/**\n * A partial match registry is a map that uses an object to \"match\" against keys.\n * More specific matches take precedence over less specific ones.\n */\nexport class Registry<V> {\n private store: Array<RegistryIndex<V>> = [];\n private logger?: Logger;\n\n /**\n * Creates a new Registry instance\n *\n * @param initialSet - Optional array of [key, value] tuples to populate the registry\n * @param logger - Optional logger instance for debug logging (e.g., when entries are replaced)\n */\n constructor(initialSet?: Array<[any, V]>, logger?: Logger) {\n this.logger = logger;\n initialSet?.forEach(([match, value]) => {\n this.set(match, value);\n });\n }\n\n /**\n * Add match -> value mapping to the registry\n *\n * If an entry with the same specificity and matching key already exists, it will be replaced\n * and a debug log will be emitted (if a logger is configured).\n *\n * @param match - The key to match against (can be a primitive or object)\n * @param value - The value to associate with this key\n */\n set(match: any, value: V): void {\n const matcher =\n typeof match === \"object\"\n ? createObjectMatcher(match)\n : createBasicMatcher(match);\n\n // Find and remove any existing entry that matches this key\n // Use matcher to check for matching keys (handles deep equality)\n const existingIndex = this.store.findIndex(\n (entry) => entry.matcher(match) && matcher(entry.key),\n );\n if (existingIndex !== -1) {\n this.store.splice(existingIndex, 1);\n this.logger?.debug?.(\n \"Registry: Replacing existing entry for key \",\n match,\n );\n }\n\n this.store.push({\n key: match,\n value,\n matcher,\n });\n\n // Sort in descending order by matcher.count (highest specificity first)\n this.store = sort(this.store).desc((entry) => entry.matcher.count);\n }\n\n /**\n * Fetch the best match in the registry\n *\n * Searches for the most specific entry that matches the given query.\n * The registry is sorted by specificity (matcher.count) in descending order,\n * so we iterate forward to find the highest specificity match first.\n *\n * @param query - The query object to match against registered keys\n * @returns The value associated with the best matching key, or undefined if no match found\n */\n get(query: any): V | undefined {\n // Store is sorted by matcher.count (descending), so iterate forward\n for (const entry of this.store) {\n if (entry.matcher(query)) {\n return entry.value;\n }\n }\n return undefined;\n }\n\n /** Loop over all entries and run callback */\n forEach(callbackfn: (value: RegistryIndex<V>) => void): void {\n for (const entry of this.store) {\n callbackfn(entry);\n }\n }\n\n /** Reset the items in the registry */\n clear(): void {\n this.store = [];\n }\n\n /** Check if the registry is empty*/\n isRegistryEmpty(): boolean {\n return this.store.length === 0;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2303/execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/dist/index.global.js","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/dlv@1.1.3/node_modules/dlv/index.js","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/deep-partial-matcher.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/sorted-array@2.0.4/node_modules/sorted-array/sorted-array.js"],"names":["Registry","dlv_es_default","obj","key","def","p","undef","split","length","createObjectMatcher","partialObj","pairs","traverseObj","matchFunction","searchObj","Array","from","entry","path","value","count","size","createBasicMatcher","seed","matcher","match","__create","Object","create","__defProp","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__getProtoOf","getPrototypeOf","__hasOwnProp","prototype","hasOwnProperty","__commonJS","cb","mod","__require","exports","__export","target","all","name","get","enumerable","__copyProps","to","except","desc","call","__toESM","isNodeMode","__esModule","__toCommonJS","require_sorted_array","module","SortedArray","defclass","array","compare","compareDefault","index","insert","element","high","low","pos","ordering","push","search","remove","splice","comparing","property","a","b","constructor","define","amd","src_exports","import_sorted_array","object","Map","keys","val","nestedPath","set","createSortedArray","c","initialSet","store","forEach","query","callbackfn","clear","isRegistryEmpty"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAIA,WAAW,AAAC;QCDDC,iBDuIb,kJAAkJ;ICvIrI,SAAAA,eAAaC,CAAAA,EAAKC,CAAAA,EAAKC,CAAAA,EAAKC,CAAAA,EAAGC,CAAAA;QAAAA,IAC7CH,IAAMA,EAAII,KAAAA,GAAQJ,EAAII,KAAAA,CAAM,OAAOJ,GAC9BE,IAAI,GAAGA,IAAIF,EAAIK,MAAAA,EAAQH,IAC3BH,IAAMA,IAAMA,CAAAA,CAAIC,CAAAA,CAAIE,EAAAA,CAAAA,GAAMC;QAAAA,OAEpBJ,MAAQI,IAAQF,IAAMF;IAAAA;QC4BdO,sBAAT,SAASA,oBAAoBC,UAAA;QAElC,IAAMC,QAAQC,YAAYF;QAG1B,IAAMG,gBAAgB,uBAACC;gBACrB,kCAAA,2BAAA;;gBAAA,QAAA,YAAoBC,MAAMC,IAAA,CAAKL,2BAA/B,SAAA,6BAAA,QAAA,yBAAA,iCAAuC;oBAAvC,IAAWM,QAAX;oBACE,IAAsBA,0BAAAA,WAAfC,OAAeD,WAATE,QAASF;oBAEtB,IAAIhB,eAAIa,WAAWI,UAAUC,OAAO;wBAClC,OAAO;oBACT;gBACF;;gBANA;gBAAA;;;yBAAA,6BAAA;wBAAA;;;wBAAA;8BAAA;;;;YAQA,OAAO;QACT;QAGAN,cAAcO,KAAA,GAAQT,MAAMU,IAAA;QAE5B,OAAOR;IACT;QC/CSS,qBHmKP,mHAAmH;IGnKrH,SAASA,mBAAmBC,IAAA;QAE1B,IAAMC,UAAU,iBAACC;mBAAeF,SAASE;;QACzCD,QAAQJ,KAAA,GAAQ;QAEhB,OAAOI;IACT;IHXE,I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BACf;;;gBAAA,kCAAA,GAGAQ,KAAAA;uBAAAA,SAAAA;oBACE,OAAO,IAAA,CAAKL,KAAA,CAAMhC,KAAA,CAAMxD,MAAA,KAAW;gBACrC;;;;;IHuIA,OAAOmD,aAAa0B;AACtB","sourcesContent":["\"use strict\";\nvar Registry = (() => {\n var __create = Object.create;\n var __defProp = Object.defineProperty;\n var __getOwnPropDesc = Object.getOwnPropertyDescriptor;\n var __getOwnPropNames = Object.getOwnPropertyNames;\n var __getProtoOf = Object.getPrototypeOf;\n var __hasOwnProp = Object.prototype.hasOwnProperty;\n var __commonJS = (cb, mod) => function __require() {\n return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;\n };\n var __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n };\n var __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n };\n var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n ));\n var __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\n\n // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/sorted-array@2.0.4/node_modules/sorted-array/sorted-array.js\n var require_sorted_array = __commonJS({\n \"../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/sorted-array@2.0.4/node_modules/sorted-array/sorted-array.js\"(exports, module) {\n \"use strict\";\n var SortedArray2 = function() {\n var SortedArray3 = defclass({\n constructor: function(array, compare) {\n this.array = [];\n this.compare = compare || compareDefault;\n var length = array.length, index = 0;\n while (index < length)\n this.insert(array[index++]);\n },\n insert: function(element) {\n var array = this.array, compare = this.compare, high = array.length - 1, low = 0, pos = -1, index, ordering;\n while (high >= low) {\n index = (high + low) / 2 >>> 0;\n ordering = compare(array[index], element);\n if (ordering < 0)\n low = index + 1;\n else if (ordering > 0)\n high = index - 1;\n else {\n pos = index;\n break;\n }\n ;\n }\n if (pos === -1) {\n pos = high;\n }\n pos++;\n high = array.length - 1;\n while (pos < high && compare(element, array[pos]) === 0) {\n pos++;\n }\n index = array.length;\n array.push(element);\n while (index > pos) {\n array[index] = array[--index];\n }\n array[pos] = element;\n return this;\n },\n search: function(element) {\n var array = this.array, compare = this.compare, high = array.length - 1, low = 0, index, ordering;\n while (high >= low) {\n index = (high + low) / 2 >>> 0;\n ordering = compare(array[index], element);\n if (ordering < 0)\n low = index + 1;\n else if (ordering > 0)\n high = index - 1;\n else\n return index;\n }\n return -1;\n },\n remove: function(element) {\n var index = this.search(element);\n if (index >= 0)\n this.array.splice(index, 1);\n return this;\n }\n });\n SortedArray3.comparing = function(property, array) {\n return new SortedArray3(array, function(a, b) {\n return compareDefault(a[property], b[property]);\n });\n };\n return SortedArray3;\n function defclass(prototype) {\n var constructor = prototype.constructor;\n constructor.prototype = prototype;\n return constructor;\n }\n function compareDefault(a, b) {\n if (a < b)\n return -1;\n else if (a > b)\n return 1;\n else\n return 0;\n }\n }();\n if (typeof module === \"object\")\n module.exports = SortedArray2;\n if (typeof define === \"function\" && define.amd)\n define(function() {\n return SortedArray2;\n });\n }\n });\n\n // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/index.ts\n var src_exports = {};\n __export(src_exports, {\n Registry: () => Registry,\n createObjectMatcher: () => createObjectMatcher\n });\n var import_sorted_array = __toESM(require_sorted_array());\n\n // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/dlv@1.1.3/node_modules/dlv/dist/dlv.es.js\n function dlv_es_default(t, e, l, n, r) {\n for (e = e.split ? e.split(\".\") : e, n = 0; n < e.length; n++)\n t = t ? t[e[n]] : r;\n return t === r ? l : t;\n }\n\n // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/deep-partial-matcher.ts\n function traverseObj(object, path = [], pairs = /* @__PURE__ */ new Map()) {\n for (const key of Object.keys(object)) {\n const val = object[key];\n const nestedPath = [...path, key];\n if (typeof val === \"object\") {\n traverseObj(val, nestedPath, pairs);\n } else {\n pairs.set(nestedPath, val);\n }\n }\n return pairs;\n }\n function createObjectMatcher(partialObj) {\n const pairs = traverseObj(partialObj);\n const matchFunction = (searchObj) => {\n for (const entry of Array.from(pairs)) {\n const [path, value] = entry;\n if (dlv_es_default(searchObj, path) !== value) {\n return false;\n }\n }\n return true;\n };\n matchFunction.count = pairs.size;\n return matchFunction;\n }\n\n // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/index.ts\n function createBasicMatcher(seed) {\n const matcher = (match) => seed === match;\n matcher.count = 1;\n return matcher;\n }\n var createSortedArray = () => new import_sorted_array.default([], (c) => c.matcher.count);\n var Registry = class {\n constructor(initialSet) {\n this.store = createSortedArray();\n initialSet?.forEach(([match, value]) => {\n this.set(match, value);\n });\n }\n /** Add match -> value mapping to the registry */\n set(match, value) {\n const matcher = typeof match === \"object\" ? createObjectMatcher(match) : createBasicMatcher(match);\n this.store.insert({\n key: match,\n value,\n matcher\n });\n }\n /** Fetch the best match in the registry */\n get(query) {\n for (const entry of this.store.array) {\n if (entry.matcher(query)) {\n return entry.value;\n }\n }\n }\n /** Loop over all entries and run callback */\n forEach(callbackfn) {\n for (const entry of this.store.array) {\n callbackfn(entry);\n }\n }\n /** Reset the items in the registry */\n clear() {\n this.store = createSortedArray();\n }\n /** Check if the registry is empty*/\n isRegistryEmpty() {\n return this.store.array.length === 0;\n }\n };\n return __toCommonJS(src_exports);\n})();\n","export default function dlv(obj, key, def, p, undef) {\n\tkey = key.split ? key.split('.') : key;\n\tfor (p = 0; p < key.length; p++) {\n\t\tobj = obj ? obj[key[p]] : undef;\n\t}\n\treturn obj === undef ? def : obj;\n}\n","import dlv from \"dlv\";\n\n/** A function that checks overlapping properties against a reference value */\nexport type Matcher = ((searchObj: object) => boolean) & {\n /** The count represents the specificity of this matcher */\n count: number;\n};\n\n/** Traverse an object and collect any key/value pairs including nested keys */\nfunction traverseObj(\n object: Record<any, any>,\n path: string[] = [],\n pairs: Map<string[], any> = new Map(),\n): Map<string[], any> {\n for (const key of Object.keys(object)) {\n const val: any = object[key];\n const nestedPath = [...path, key];\n\n if (typeof val === \"object\") {\n traverseObj(val, nestedPath, pairs);\n } else {\n pairs.set(nestedPath, val);\n }\n }\n\n return pairs;\n}\n\n/**\n * Given a partial object, create a matcher function that checks if another object matches the specified properties\n * @param partialObj The partial object to match against\n * @returns A matcher function that checks if an object matches the partial object\n */\nexport function createObjectMatcher(partialObj: object): Matcher {\n // Convert the partial object into a list of [key, value] pairs;\n const pairs = traverseObj(partialObj);\n\n /** Generate a function to match against all of the properties we care about */\n const matchFunction = (searchObj: object) => {\n for (const entry of Array.from(pairs)) {\n const [path, value] = entry;\n\n if (dlv(searchObj, path) !== value) {\n return false;\n }\n }\n\n return true;\n };\n\n // Keep track of the specificity of the comparator\n matchFunction.count = pairs.size;\n\n return matchFunction;\n}\n","import SortedArray from \"sorted-array\";\nimport type { Matcher } from \"./deep-partial-matcher\";\nimport { createObjectMatcher } from \"./deep-partial-matcher\";\n\nexport { createObjectMatcher } from \"./deep-partial-matcher\";\n\n/** create a matcher function that matches exactly */\nfunction createBasicMatcher(seed: any): Matcher {\n /** a simple matcher function that only matches itself */\n const matcher = (match: any) => seed === match;\n matcher.count = 1;\n\n return matcher;\n}\n\ninterface RegistryIndex<V> {\n /** The original object we wanted to match on */\n key: object;\n\n /** The value to return */\n value: V;\n\n /** The matcher function for this entry */\n matcher: Matcher;\n}\n\n/** create an empty sorted array using the matcher count */\nconst createSortedArray = <V>() =>\n new SortedArray<RegistryIndex<V>>([], (c) => c.matcher.count);\n\n/**\n * A partial match registry is a map that uses an object to \"match\" against keys.\n * More specific matches take precedence over less specific ones.\n */\nexport class Registry<V> {\n private store = createSortedArray<V>();\n\n constructor(initialSet?: Array<[any, V]>) {\n initialSet?.forEach(([match, value]) => {\n this.set(match, value);\n });\n }\n\n /** Add match -> value mapping to the registry */\n set(match: any, value: V) {\n const matcher =\n typeof match === \"object\"\n ? createObjectMatcher(match)\n : createBasicMatcher(match);\n\n this.store.insert({\n key: match,\n value,\n matcher,\n });\n }\n\n /** Fetch the best match in the registry */\n get(query: any): V | undefined {\n for (const entry of this.store.array) {\n if (entry.matcher(query)) {\n return entry.value;\n }\n }\n }\n\n /** Loop over all entries and run callback */\n forEach(callbackfn: (value: RegistryIndex<V>) => void): void {\n for (const entry of this.store.array) {\n callbackfn(entry);\n }\n }\n\n /** Reset the items in the registry */\n clear() {\n this.store = createSortedArray<V>();\n }\n\n /** Check if the registry is empty*/\n isRegistryEmpty() {\n return this.store.array.length === 0;\n }\n}\n","var SortedArray = (function () {\n var SortedArray = defclass({\n\n constructor: function (array, compare) {\n this.array = [];\n this.compare = compare || compareDefault;\n var length = array.length,\n index = 0;\n while (index < length) this.insert(array[index++]);\n },\n insert: function (element) {\n var array = this.array,\n compare = this.compare,\n high = array.length-1,\n low = 0,\n pos = -1,\n index,\n ordering;\n\n // The array is sorted. You must find the position of new element in O(log(n)), not O(n).\n while (high >= low) {\n index = (high + low) / 2 >>> 0;\n ordering = compare(array[index], element); \n if (ordering < 0) low = index + 1;\n else if (ordering > 0) high = index - 1;\n else {\n pos = index;\n break;\n };\n }\n\n if (pos === -1) {\n // if element was not found, high < low.\n pos = high;\n }\n // This assures that equal elements inserted after will be in a higher position in array.\n // They can be equal for comparison purposes, but different objects with different data.\n // Respecting the chronological order can be important for many applications.\n pos++;\n high = array.length-1;\n while ((pos < high) && (compare(element, array[pos]) === 0)){\n pos++;\n }\n index = array.length;\n // Just to increase array size.\n array.push(element); \n // Much faster. No need to elements swap.\n while (index > pos) {\n array[index] = array[--index];\n }\n // Set the new element on its correct position.\n array[pos] = element;\n\n return this;\n },\n search: function (element) {\n var array = this.array,\n compare = this.compare,\n high = array.length-1,\n low = 0,\n // In most languages, inner variable declaration makes the code slower.\n index,\n ordering;\n\n while (high >= low) {\n index = (high + low) / 2 >>> 0;\n ordering = compare(array[index], element);\n\n if (ordering < 0) low = index + 1;\n else if (ordering > 0) high = index - 1;\n else return index;\n }\n\n return -1;\n },\n remove: function (element) {\n var index = this.search(element);\n if (index >= 0) this.array.splice(index, 1);\n return this;\n }\n });\n\n SortedArray.comparing = function (property, array) {\n return new SortedArray(array, function (a, b) {\n // This should be faster than calling functions.\n // Besides, this way it is not needed to create useless function to return property value.\n return compareDefault(a[property], b[property]);\n });\n };\n\n return SortedArray;\n\n function defclass(prototype) {\n var constructor = prototype.constructor;\n constructor.prototype = prototype;\n return constructor;\n }\n\n function compareDefault(a, b) {\n // Equality has a very low chance to happen. It should be the last option.\n if (a < b)\n return -1;\n else if (a > b)\n return 1;\n else\n return 0;\n }\n}());\n\nif (typeof module === \"object\") module.exports = SortedArray;\nif (typeof define === \"function\" && define.amd)\n define(function () { return SortedArray; });\n"]}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -34,7 +34,7 @@ __export(src_exports, {
|
|
|
34
34
|
createObjectMatcher: () => createObjectMatcher
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(src_exports);
|
|
37
|
-
var
|
|
37
|
+
var import_sorted_array = __toESM(require("sorted-array"));
|
|
38
38
|
|
|
39
39
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/deep-partial-matcher.ts
|
|
40
40
|
var import_dlv = __toESM(require("dlv"));
|
|
@@ -42,7 +42,7 @@ function traverseObj(object, path = [], pairs = /* @__PURE__ */ new Map()) {
|
|
|
42
42
|
for (const key of Object.keys(object)) {
|
|
43
43
|
const val = object[key];
|
|
44
44
|
const nestedPath = [...path, key];
|
|
45
|
-
if (typeof val === "object"
|
|
45
|
+
if (typeof val === "object") {
|
|
46
46
|
traverseObj(val, nestedPath, pairs);
|
|
47
47
|
} else {
|
|
48
48
|
pairs.set(nestedPath, val);
|
|
@@ -71,79 +71,44 @@ function createBasicMatcher(seed) {
|
|
|
71
71
|
matcher.count = 1;
|
|
72
72
|
return matcher;
|
|
73
73
|
}
|
|
74
|
+
var createSortedArray = () => new import_sorted_array.default([], (c) => c.matcher.count);
|
|
74
75
|
var Registry = class {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
*
|
|
78
|
-
* @param initialSet - Optional array of [key, value] tuples to populate the registry
|
|
79
|
-
* @param logger - Optional logger instance for debug logging (e.g., when entries are replaced)
|
|
80
|
-
*/
|
|
81
|
-
constructor(initialSet, logger) {
|
|
82
|
-
this.store = [];
|
|
83
|
-
this.logger = logger;
|
|
76
|
+
constructor(initialSet) {
|
|
77
|
+
this.store = createSortedArray();
|
|
84
78
|
initialSet?.forEach(([match, value]) => {
|
|
85
79
|
this.set(match, value);
|
|
86
80
|
});
|
|
87
81
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Add match -> value mapping to the registry
|
|
90
|
-
*
|
|
91
|
-
* If an entry with the same specificity and matching key already exists, it will be replaced
|
|
92
|
-
* and a debug log will be emitted (if a logger is configured).
|
|
93
|
-
*
|
|
94
|
-
* @param match - The key to match against (can be a primitive or object)
|
|
95
|
-
* @param value - The value to associate with this key
|
|
96
|
-
*/
|
|
82
|
+
/** Add match -> value mapping to the registry */
|
|
97
83
|
set(match, value) {
|
|
98
84
|
const matcher = typeof match === "object" ? createObjectMatcher(match) : createBasicMatcher(match);
|
|
99
|
-
|
|
100
|
-
(entry) => entry.matcher(match) && matcher(entry.key)
|
|
101
|
-
);
|
|
102
|
-
if (existingIndex !== -1) {
|
|
103
|
-
this.store.splice(existingIndex, 1);
|
|
104
|
-
this.logger?.debug?.(
|
|
105
|
-
"Registry: Replacing existing entry for key ",
|
|
106
|
-
match
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
this.store.push({
|
|
85
|
+
this.store.insert({
|
|
110
86
|
key: match,
|
|
111
87
|
value,
|
|
112
88
|
matcher
|
|
113
89
|
});
|
|
114
|
-
this.store = (0, import_fast_sort.sort)(this.store).desc((entry) => entry.matcher.count);
|
|
115
90
|
}
|
|
116
|
-
/**
|
|
117
|
-
* Fetch the best match in the registry
|
|
118
|
-
*
|
|
119
|
-
* Searches for the most specific entry that matches the given query.
|
|
120
|
-
* The registry is sorted by specificity (matcher.count) in descending order,
|
|
121
|
-
* so we iterate forward to find the highest specificity match first.
|
|
122
|
-
*
|
|
123
|
-
* @param query - The query object to match against registered keys
|
|
124
|
-
* @returns The value associated with the best matching key, or undefined if no match found
|
|
125
|
-
*/
|
|
91
|
+
/** Fetch the best match in the registry */
|
|
126
92
|
get(query) {
|
|
127
|
-
for (const entry of this.store) {
|
|
93
|
+
for (const entry of this.store.array) {
|
|
128
94
|
if (entry.matcher(query)) {
|
|
129
95
|
return entry.value;
|
|
130
96
|
}
|
|
131
97
|
}
|
|
132
|
-
return void 0;
|
|
133
98
|
}
|
|
134
99
|
/** Loop over all entries and run callback */
|
|
135
100
|
forEach(callbackfn) {
|
|
136
|
-
for (const entry of this.store) {
|
|
101
|
+
for (const entry of this.store.array) {
|
|
137
102
|
callbackfn(entry);
|
|
138
103
|
}
|
|
139
104
|
}
|
|
140
105
|
/** Reset the items in the registry */
|
|
141
106
|
clear() {
|
|
142
|
-
this.store =
|
|
107
|
+
this.store = createSortedArray();
|
|
143
108
|
}
|
|
144
109
|
/** Check if the registry is empty*/
|
|
145
110
|
isRegistryEmpty() {
|
|
146
|
-
return this.store.length === 0;
|
|
111
|
+
return this.store.array.length === 0;
|
|
147
112
|
}
|
|
148
113
|
};
|
|
149
114
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/index.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/deep-partial-matcher.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/index.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/deep-partial-matcher.ts"],"sourcesContent":["import SortedArray from \"sorted-array\";\nimport type { Matcher } from \"./deep-partial-matcher\";\nimport { createObjectMatcher } from \"./deep-partial-matcher\";\n\nexport { createObjectMatcher } from \"./deep-partial-matcher\";\n\n/** create a matcher function that matches exactly */\nfunction createBasicMatcher(seed: any): Matcher {\n /** a simple matcher function that only matches itself */\n const matcher = (match: any) => seed === match;\n matcher.count = 1;\n\n return matcher;\n}\n\ninterface RegistryIndex<V> {\n /** The original object we wanted to match on */\n key: object;\n\n /** The value to return */\n value: V;\n\n /** The matcher function for this entry */\n matcher: Matcher;\n}\n\n/** create an empty sorted array using the matcher count */\nconst createSortedArray = <V>() =>\n new SortedArray<RegistryIndex<V>>([], (c) => c.matcher.count);\n\n/**\n * A partial match registry is a map that uses an object to \"match\" against keys.\n * More specific matches take precedence over less specific ones.\n */\nexport class Registry<V> {\n private store = createSortedArray<V>();\n\n constructor(initialSet?: Array<[any, V]>) {\n initialSet?.forEach(([match, value]) => {\n this.set(match, value);\n });\n }\n\n /** Add match -> value mapping to the registry */\n set(match: any, value: V) {\n const matcher =\n typeof match === \"object\"\n ? createObjectMatcher(match)\n : createBasicMatcher(match);\n\n this.store.insert({\n key: match,\n value,\n matcher,\n });\n }\n\n /** Fetch the best match in the registry */\n get(query: any): V | undefined {\n for (const entry of this.store.array) {\n if (entry.matcher(query)) {\n return entry.value;\n }\n }\n }\n\n /** Loop over all entries and run callback */\n forEach(callbackfn: (value: RegistryIndex<V>) => void): void {\n for (const entry of this.store.array) {\n callbackfn(entry);\n }\n }\n\n /** Reset the items in the registry */\n clear() {\n this.store = createSortedArray<V>();\n }\n\n /** Check if the registry is empty*/\n isRegistryEmpty() {\n return this.store.array.length === 0;\n }\n}\n","import dlv from \"dlv\";\n\n/** A function that checks overlapping properties against a reference value */\nexport type Matcher = ((searchObj: object) => boolean) & {\n /** The count represents the specificity of this matcher */\n count: number;\n};\n\n/** Traverse an object and collect any key/value pairs including nested keys */\nfunction traverseObj(\n object: Record<any, any>,\n path: string[] = [],\n pairs: Map<string[], any> = new Map(),\n): Map<string[], any> {\n for (const key of Object.keys(object)) {\n const val: any = object[key];\n const nestedPath = [...path, key];\n\n if (typeof val === \"object\") {\n traverseObj(val, nestedPath, pairs);\n } else {\n pairs.set(nestedPath, val);\n }\n }\n\n return pairs;\n}\n\n/**\n * Given a partial object, create a matcher function that checks if another object matches the specified properties\n * @param partialObj The partial object to match against\n * @returns A matcher function that checks if an object matches the partial object\n */\nexport function createObjectMatcher(partialObj: object): Matcher {\n // Convert the partial object into a list of [key, value] pairs;\n const pairs = traverseObj(partialObj);\n\n /** Generate a function to match against all of the properties we care about */\n const matchFunction = (searchObj: object) => {\n for (const entry of Array.from(pairs)) {\n const [path, value] = entry;\n\n if (dlv(searchObj, path) !== value) {\n return false;\n }\n }\n\n return true;\n };\n\n // Keep track of the specificity of the comparator\n matchFunction.count = pairs.size;\n\n return matchFunction;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAwB;;;ACAxB,iBAAgB;AAShB,SAAS,YACP,QACA,OAAiB,CAAC,GAClB,QAA4B,oBAAI,IAAI,GAChB;AACpB,aAAW,OAAO,O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O;AACpC,UAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,eAAO,MAAM;AAAA,MACf;AAAA,IACF;AAAA,EACF;AAAA;AAAA,EAGA,QAAQ,YAAqD;AAC3D,eAAW,SAAS,KAAK,MAAM,OAAO;AACpC,iBAAW,KAAK;AAAA,IAClB;AAAA,EACF;AAAA;AAAA,EAGA,QAAQ;AACN,SAAK,QAAQ,kBAAqB;AAAA,EACpC;AAAA;AAAA,EAGA,kBAAkB;AAChB,WAAO,KAAK,MAAM,MAAM,WAAW;AAAA,EACrC;AACF;","names":["dlv","SortedArray"]}
|
package/dist/index.legacy-esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/index.ts
|
|
2
|
-
import
|
|
2
|
+
import SortedArray from "sorted-array";
|
|
3
3
|
|
|
4
4
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/deep-partial-matcher.ts
|
|
5
5
|
import dlv from "dlv";
|
|
@@ -7,7 +7,7 @@ function traverseObj(object, path = [], pairs = /* @__PURE__ */ new Map()) {
|
|
|
7
7
|
for (const key of Object.keys(object)) {
|
|
8
8
|
const val = object[key];
|
|
9
9
|
const nestedPath = [...path, key];
|
|
10
|
-
if (typeof val === "object"
|
|
10
|
+
if (typeof val === "object") {
|
|
11
11
|
traverseObj(val, nestedPath, pairs);
|
|
12
12
|
} else {
|
|
13
13
|
pairs.set(nestedPath, val);
|
|
@@ -36,79 +36,44 @@ function createBasicMatcher(seed) {
|
|
|
36
36
|
matcher.count = 1;
|
|
37
37
|
return matcher;
|
|
38
38
|
}
|
|
39
|
+
var createSortedArray = () => new SortedArray([], (c) => c.matcher.count);
|
|
39
40
|
var Registry = class {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
*
|
|
43
|
-
* @param initialSet - Optional array of [key, value] tuples to populate the registry
|
|
44
|
-
* @param logger - Optional logger instance for debug logging (e.g., when entries are replaced)
|
|
45
|
-
*/
|
|
46
|
-
constructor(initialSet, logger) {
|
|
47
|
-
this.store = [];
|
|
48
|
-
this.logger = logger;
|
|
41
|
+
constructor(initialSet) {
|
|
42
|
+
this.store = createSortedArray();
|
|
49
43
|
initialSet?.forEach(([match, value]) => {
|
|
50
44
|
this.set(match, value);
|
|
51
45
|
});
|
|
52
46
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Add match -> value mapping to the registry
|
|
55
|
-
*
|
|
56
|
-
* If an entry with the same specificity and matching key already exists, it will be replaced
|
|
57
|
-
* and a debug log will be emitted (if a logger is configured).
|
|
58
|
-
*
|
|
59
|
-
* @param match - The key to match against (can be a primitive or object)
|
|
60
|
-
* @param value - The value to associate with this key
|
|
61
|
-
*/
|
|
47
|
+
/** Add match -> value mapping to the registry */
|
|
62
48
|
set(match, value) {
|
|
63
49
|
const matcher = typeof match === "object" ? createObjectMatcher(match) : createBasicMatcher(match);
|
|
64
|
-
|
|
65
|
-
(entry) => entry.matcher(match) && matcher(entry.key)
|
|
66
|
-
);
|
|
67
|
-
if (existingIndex !== -1) {
|
|
68
|
-
this.store.splice(existingIndex, 1);
|
|
69
|
-
this.logger?.debug?.(
|
|
70
|
-
"Registry: Replacing existing entry for key ",
|
|
71
|
-
match
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
this.store.push({
|
|
50
|
+
this.store.insert({
|
|
75
51
|
key: match,
|
|
76
52
|
value,
|
|
77
53
|
matcher
|
|
78
54
|
});
|
|
79
|
-
this.store = sort(this.store).desc((entry) => entry.matcher.count);
|
|
80
55
|
}
|
|
81
|
-
/**
|
|
82
|
-
* Fetch the best match in the registry
|
|
83
|
-
*
|
|
84
|
-
* Searches for the most specific entry that matches the given query.
|
|
85
|
-
* The registry is sorted by specificity (matcher.count) in descending order,
|
|
86
|
-
* so we iterate forward to find the highest specificity match first.
|
|
87
|
-
*
|
|
88
|
-
* @param query - The query object to match against registered keys
|
|
89
|
-
* @returns The value associated with the best matching key, or undefined if no match found
|
|
90
|
-
*/
|
|
56
|
+
/** Fetch the best match in the registry */
|
|
91
57
|
get(query) {
|
|
92
|
-
for (const entry of this.store) {
|
|
58
|
+
for (const entry of this.store.array) {
|
|
93
59
|
if (entry.matcher(query)) {
|
|
94
60
|
return entry.value;
|
|
95
61
|
}
|
|
96
62
|
}
|
|
97
|
-
return void 0;
|
|
98
63
|
}
|
|
99
64
|
/** Loop over all entries and run callback */
|
|
100
65
|
forEach(callbackfn) {
|
|
101
|
-
for (const entry of this.store) {
|
|
66
|
+
for (const entry of this.store.array) {
|
|
102
67
|
callbackfn(entry);
|
|
103
68
|
}
|
|
104
69
|
}
|
|
105
70
|
/** Reset the items in the registry */
|
|
106
71
|
clear() {
|
|
107
|
-
this.store =
|
|
72
|
+
this.store = createSortedArray();
|
|
108
73
|
}
|
|
109
74
|
/** Check if the registry is empty*/
|
|
110
75
|
isRegistryEmpty() {
|
|
111
|
-
return this.store.length === 0;
|
|
76
|
+
return this.store.array.length === 0;
|
|
112
77
|
}
|
|
113
78
|
};
|
|
114
79
|
export {
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/index.ts
|
|
2
|
-
import
|
|
2
|
+
import SortedArray from "sorted-array";
|
|
3
3
|
|
|
4
4
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/deep-partial-matcher.ts
|
|
5
5
|
import dlv from "dlv";
|
|
@@ -7,7 +7,7 @@ function traverseObj(object, path = [], pairs = /* @__PURE__ */ new Map()) {
|
|
|
7
7
|
for (const key of Object.keys(object)) {
|
|
8
8
|
const val = object[key];
|
|
9
9
|
const nestedPath = [...path, key];
|
|
10
|
-
if (typeof val === "object"
|
|
10
|
+
if (typeof val === "object") {
|
|
11
11
|
traverseObj(val, nestedPath, pairs);
|
|
12
12
|
} else {
|
|
13
13
|
pairs.set(nestedPath, val);
|
|
@@ -36,79 +36,44 @@ function createBasicMatcher(seed) {
|
|
|
36
36
|
matcher.count = 1;
|
|
37
37
|
return matcher;
|
|
38
38
|
}
|
|
39
|
+
var createSortedArray = () => new SortedArray([], (c) => c.matcher.count);
|
|
39
40
|
var Registry = class {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
*
|
|
43
|
-
* @param initialSet - Optional array of [key, value] tuples to populate the registry
|
|
44
|
-
* @param logger - Optional logger instance for debug logging (e.g., when entries are replaced)
|
|
45
|
-
*/
|
|
46
|
-
constructor(initialSet, logger) {
|
|
47
|
-
this.store = [];
|
|
48
|
-
this.logger = logger;
|
|
41
|
+
constructor(initialSet) {
|
|
42
|
+
this.store = createSortedArray();
|
|
49
43
|
initialSet?.forEach(([match, value]) => {
|
|
50
44
|
this.set(match, value);
|
|
51
45
|
});
|
|
52
46
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Add match -> value mapping to the registry
|
|
55
|
-
*
|
|
56
|
-
* If an entry with the same specificity and matching key already exists, it will be replaced
|
|
57
|
-
* and a debug log will be emitted (if a logger is configured).
|
|
58
|
-
*
|
|
59
|
-
* @param match - The key to match against (can be a primitive or object)
|
|
60
|
-
* @param value - The value to associate with this key
|
|
61
|
-
*/
|
|
47
|
+
/** Add match -> value mapping to the registry */
|
|
62
48
|
set(match, value) {
|
|
63
49
|
const matcher = typeof match === "object" ? createObjectMatcher(match) : createBasicMatcher(match);
|
|
64
|
-
|
|
65
|
-
(entry) => entry.matcher(match) && matcher(entry.key)
|
|
66
|
-
);
|
|
67
|
-
if (existingIndex !== -1) {
|
|
68
|
-
this.store.splice(existingIndex, 1);
|
|
69
|
-
this.logger?.debug?.(
|
|
70
|
-
"Registry: Replacing existing entry for key ",
|
|
71
|
-
match
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
this.store.push({
|
|
50
|
+
this.store.insert({
|
|
75
51
|
key: match,
|
|
76
52
|
value,
|
|
77
53
|
matcher
|
|
78
54
|
});
|
|
79
|
-
this.store = sort(this.store).desc((entry) => entry.matcher.count);
|
|
80
55
|
}
|
|
81
|
-
/**
|
|
82
|
-
* Fetch the best match in the registry
|
|
83
|
-
*
|
|
84
|
-
* Searches for the most specific entry that matches the given query.
|
|
85
|
-
* The registry is sorted by specificity (matcher.count) in descending order,
|
|
86
|
-
* so we iterate forward to find the highest specificity match first.
|
|
87
|
-
*
|
|
88
|
-
* @param query - The query object to match against registered keys
|
|
89
|
-
* @returns The value associated with the best matching key, or undefined if no match found
|
|
90
|
-
*/
|
|
56
|
+
/** Fetch the best match in the registry */
|
|
91
57
|
get(query) {
|
|
92
|
-
for (const entry of this.store) {
|
|
58
|
+
for (const entry of this.store.array) {
|
|
93
59
|
if (entry.matcher(query)) {
|
|
94
60
|
return entry.value;
|
|
95
61
|
}
|
|
96
62
|
}
|
|
97
|
-
return void 0;
|
|
98
63
|
}
|
|
99
64
|
/** Loop over all entries and run callback */
|
|
100
65
|
forEach(callbackfn) {
|
|
101
|
-
for (const entry of this.store) {
|
|
66
|
+
for (const entry of this.store.array) {
|
|
102
67
|
callbackfn(entry);
|
|
103
68
|
}
|
|
104
69
|
}
|
|
105
70
|
/** Reset the items in the registry */
|
|
106
71
|
clear() {
|
|
107
|
-
this.store =
|
|
72
|
+
this.store = createSortedArray();
|
|
108
73
|
}
|
|
109
74
|
/** Check if the registry is empty*/
|
|
110
75
|
isRegistryEmpty() {
|
|
111
|
-
return this.store.length === 0;
|
|
76
|
+
return this.store.array.length === 0;
|
|
112
77
|
}
|
|
113
78
|
};
|
|
114
79
|
export {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/deep-partial-matcher.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/partial-match-registry/src/deep-partial-matcher.ts"],"sourcesContent":["import SortedArray from \"sorted-array\";\nimport type { Matcher } from \"./deep-partial-matcher\";\nimport { createObjectMatcher } from \"./deep-partial-matcher\";\n\nexport { createObjectMatcher } from \"./deep-partial-matcher\";\n\n/** create a matcher function that matches exactly */\nfunction createBasicMatcher(seed: any): Matcher {\n /** a simple matcher function that only matches itself */\n const matcher = (match: any) => seed === match;\n matcher.count = 1;\n\n return matcher;\n}\n\ninterface RegistryIndex<V> {\n /** The original object we wanted to match on */\n key: object;\n\n /** The value to return */\n value: V;\n\n /** The matcher function for this entry */\n matcher: Matcher;\n}\n\n/** create an empty sorted array using the matcher count */\nconst createSortedArray = <V>() =>\n new SortedArray<RegistryIndex<V>>([], (c) => c.matcher.count);\n\n/**\n * A partial match registry is a map that uses an object to \"match\" against keys.\n * More specific matches take precedence over less specific ones.\n */\nexport class Registry<V> {\n private store = createSortedArray<V>();\n\n constructor(initialSet?: Array<[any, V]>) {\n initialSet?.forEach(([match, value]) => {\n this.set(match, value);\n });\n }\n\n /** Add match -> value mapping to the registry */\n set(match: any, value: V) {\n const matcher =\n typeof match === \"object\"\n ? createObjectMatcher(match)\n : createBasicMatcher(match);\n\n this.store.insert({\n key: match,\n value,\n matcher,\n });\n }\n\n /** Fetch the best match in the registry */\n get(query: any): V | undefined {\n for (const entry of this.store.array) {\n if (entry.matcher(query)) {\n return entry.value;\n }\n }\n }\n\n /** Loop over all entries and run callback */\n forEach(callbackfn: (value: RegistryIndex<V>) => void): void {\n for (const entry of this.store.array) {\n callbackfn(entry);\n }\n }\n\n /** Reset the items in the registry */\n clear() {\n this.store = createSortedArray<V>();\n }\n\n /** Check if the registry is empty*/\n isRegistryEmpty() {\n return this.store.array.length === 0;\n }\n}\n","import dlv from \"dlv\";\n\n/** A function that checks overlapping properties against a reference value */\nexport type Matcher = ((searchObj: object) => boolean) & {\n /** The count represents the specificity of this matcher */\n count: number;\n};\n\n/** Traverse an object and collect any key/value pairs including nested keys */\nfunction traverseObj(\n object: Record<any, any>,\n path: string[] = [],\n pairs: Map<string[], any> = new Map(),\n): Map<string[], any> {\n for (const key of Object.keys(object)) {\n const val: any = object[key];\n const nestedPath = [...path, key];\n\n if (typeof val === \"object\") {\n traverseObj(val, nestedPath, pairs);\n } else {\n pairs.set(nestedPath, val);\n }\n }\n\n return pairs;\n}\n\n/**\n * Given a partial object, create a matcher function that checks if another object matches the specified properties\n * @param partialObj The partial object to match against\n * @returns A matcher function that checks if an object matches the partial object\n */\nexport function createObjectMatcher(partialObj: object): Matcher {\n // Convert the partial object into a list of [key, value] pairs;\n const pairs = traverseObj(partialObj);\n\n /** Generate a function to match against all of the properties we care about */\n const matchFunction = (searchObj: object) => {\n for (const entry of Array.from(pairs)) {\n const [path, value] = entry;\n\n if (dlv(searchObj, path) !== value) {\n return false;\n }\n }\n\n return true;\n };\n\n // Keep track of the specificity of the comparator\n matchFunction.count = pairs.size;\n\n return matchFunction;\n}\n"],"mappings":";AAAA,OAAO,iBAAiB;;;ACAxB,OAAO,SAAS;AAShB,SAAS,YACP,QACA,OAAiB,CAAC,GAClB,QAA4B,oBAAI,IAAI,GAChB;AACpB,aAAW,OAAO,OAAO,KAAK,MAAM,GAAG;AACrC,UAAM,MAAW,OAAO,GAAG;AAC3B,UAAM,aAAa,CAAC,GAAG,MAAM,GAAG;AAEhC,QAAI,OAAO,QAAQ,UAAU;AAC3B,kBAAY,KAAK,YAAY,KAAK;AAAA,IACpC,OAAO;AACL,YAAM,IAAI,YAAY,GAAG;AAAA,IAC3B;AAAA,EACF;AAEA,SAAO;AACT;AAOO,SAAS,oBAAoB,YAA6B;AAE/D,QAAM,QAAQ,YAAY,UAAU;AAGpC,QAAM,gBAAgB,CAAC,cAAsB;AAC3C,eAAW,SAAS,MAAM,KAAK,KAAK,GAAG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6
|
"types"
|
|
7
7
|
],
|
|
8
8
|
"name": "@player-ui/partial-match-registry",
|
|
9
|
-
"version": "0.15.5
|
|
9
|
+
"version": "0.15.5",
|
|
10
10
|
"main": "dist/cjs/index.cjs",
|
|
11
11
|
"module": "dist/index.legacy-esm.js",
|
|
12
12
|
"types": "types/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@types/dlv": "^1.1.4",
|
|
25
25
|
"dlv": "^1.1.3",
|
|
26
|
-
"
|
|
26
|
+
"sorted-array": "^2.0.4",
|
|
27
27
|
"tslib": "^2.6.2"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {}
|
|
@@ -7,27 +7,3 @@ test("works on basic objects", () => {
|
|
|
7
7
|
expect(matcher({ foo: "bar" })).toBe(true);
|
|
8
8
|
expect(matcher({ foo: "bar", bar: "baz" })).toBe(true);
|
|
9
9
|
});
|
|
10
|
-
|
|
11
|
-
test("handles null values correctly", () => {
|
|
12
|
-
// Test matching on null value
|
|
13
|
-
const matcherWithNull = createObjectMatcher({ foo: null });
|
|
14
|
-
expect(matcherWithNull({ foo: null })).toBe(true);
|
|
15
|
-
expect(matcherWithNull({ foo: "bar" })).toBe(false);
|
|
16
|
-
expect(matcherWithNull({})).toBe(false);
|
|
17
|
-
|
|
18
|
-
// Test matching on combination of null and non-null values
|
|
19
|
-
const matcherMixed = createObjectMatcher({ foo: null, bar: "baz" });
|
|
20
|
-
expect(matcherMixed({ foo: null, bar: "baz" })).toBe(true);
|
|
21
|
-
expect(matcherMixed({ foo: null, bar: "other" })).toBe(false);
|
|
22
|
-
expect(matcherMixed({ foo: "something", bar: "baz" })).toBe(false);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test("handles undefined values correctly", () => {
|
|
26
|
-
// Test matching on undefined value
|
|
27
|
-
// Note: dlv treats missing properties the same as undefined, so { foo: undefined } matches {}
|
|
28
|
-
const matcherWithUndefined = createObjectMatcher({ foo: undefined });
|
|
29
|
-
expect(matcherWithUndefined({ foo: undefined })).toBe(true);
|
|
30
|
-
expect(matcherWithUndefined({})).toBe(true); // Missing property is treated as undefined
|
|
31
|
-
expect(matcherWithUndefined({ foo: "bar" })).toBe(false);
|
|
32
|
-
expect(matcherWithUndefined({ foo: null })).toBe(false);
|
|
33
|
-
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { test, expect, beforeEach
|
|
1
|
+
import { test, expect, beforeEach } from "vitest";
|
|
2
2
|
|
|
3
3
|
import { Registry } from "..";
|
|
4
4
|
|
|
@@ -27,7 +27,7 @@ test("falls back to a partially matched object", () => {
|
|
|
27
27
|
expect(registry.get({ foo: "bar", bar: "baz" })).toBe("blah");
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
test("uses more specific match if one exists
|
|
30
|
+
test("uses more specific match if one exists", () => {
|
|
31
31
|
const query = { foo: "bar", metaData: { role: "baz" } };
|
|
32
32
|
registry.set({ foo: "bar" }, "blah");
|
|
33
33
|
expect(registry.get(query)).toBe("blah");
|
|
@@ -35,13 +35,6 @@ test("uses more specific match if one exists where more specific one is added la
|
|
|
35
35
|
expect(registry.get(query)).toBe("stuff");
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
-
test("uses more specific match if one exists where more specific one is added first", () => {
|
|
39
|
-
const query = { foo: "bar", metaData: { role: "baz" } };
|
|
40
|
-
registry.set({ foo: "bar", metaData: { role: "baz" } }, "stuff");
|
|
41
|
-
registry.set({ foo: "bar" }, "blah");
|
|
42
|
-
expect(registry.get(query)).toBe("stuff");
|
|
43
|
-
});
|
|
44
|
-
|
|
45
38
|
test("works with seed data", () => {
|
|
46
39
|
registry = new Registry([
|
|
47
40
|
[{ type: "foo" }, "foo-bar"],
|
|
@@ -74,61 +67,3 @@ test("check if registry is empty", () => {
|
|
|
74
67
|
expect(registry.isRegistryEmpty()).toBe(false);
|
|
75
68
|
expect(emptyRegistry.isRegistryEmpty()).toBe(true);
|
|
76
69
|
});
|
|
77
|
-
|
|
78
|
-
test("replacement only replaces exact matches, not fuzzy matches", () => {
|
|
79
|
-
registry.set({ foo: "bar" }, "exact-match");
|
|
80
|
-
registry.set({ foo: "bar", baz: "qux" }, "more-specific-match");
|
|
81
|
-
|
|
82
|
-
// Override the exact match - should only remove the exact match
|
|
83
|
-
registry.set({ foo: "bar" }, "new-exact-match");
|
|
84
|
-
|
|
85
|
-
// The exact match should be replaced
|
|
86
|
-
expect(registry.get({ foo: "bar" })).toBe("new-exact-match");
|
|
87
|
-
|
|
88
|
-
// The more specific match should still exist and be found by fuzzy matching
|
|
89
|
-
expect(registry.get({ foo: "bar", baz: "qux" })).toBe("more-specific-match");
|
|
90
|
-
|
|
91
|
-
// Now override the more specific match
|
|
92
|
-
registry.set({ foo: "bar", baz: "qux" }, "new-specific-match");
|
|
93
|
-
|
|
94
|
-
// The more specific match should be replaced
|
|
95
|
-
expect(registry.get({ foo: "bar", baz: "qux" })).toBe("new-specific-match");
|
|
96
|
-
|
|
97
|
-
// The exact match should still exist
|
|
98
|
-
expect(registry.get({ foo: "bar" })).toBe("new-exact-match");
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test("logs debug message when initialSet has duplicate keys", () => {
|
|
102
|
-
const mockDebug = vi.fn();
|
|
103
|
-
const logger = { debug: mockDebug };
|
|
104
|
-
|
|
105
|
-
// Create registry with duplicate keys in initialSet
|
|
106
|
-
const registryWithDuplicates = new Registry<string>(
|
|
107
|
-
[
|
|
108
|
-
[{ type: "action" }, "first-value"],
|
|
109
|
-
[{ type: "action" }, "second-value"], // Duplicate - should trigger log
|
|
110
|
-
[{ type: "other" }, "other-value"],
|
|
111
|
-
[{ type: "action" }, "third-value"], // Another duplicate - should trigger log again
|
|
112
|
-
],
|
|
113
|
-
logger,
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
// Should have logged twice for the two replacements
|
|
117
|
-
expect(mockDebug).toHaveBeenCalledTimes(2);
|
|
118
|
-
|
|
119
|
-
// Verify the log messages
|
|
120
|
-
expect(mockDebug).toHaveBeenNthCalledWith(
|
|
121
|
-
1,
|
|
122
|
-
"Registry: Replacing existing entry for key ",
|
|
123
|
-
{ type: "action" },
|
|
124
|
-
);
|
|
125
|
-
expect(mockDebug).toHaveBeenNthCalledWith(
|
|
126
|
-
2,
|
|
127
|
-
"Registry: Replacing existing entry for key ",
|
|
128
|
-
{ type: "action" },
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
// Verify the final value is the last one set
|
|
132
|
-
expect(registryWithDuplicates.get({ type: "action" })).toBe("third-value");
|
|
133
|
-
expect(registryWithDuplicates.get({ type: "other" })).toBe("other-value");
|
|
134
|
-
});
|
|
@@ -16,13 +16,7 @@ function traverseObj(
|
|
|
16
16
|
const val: any = object[key];
|
|
17
17
|
const nestedPath = [...path, key];
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
JavaScript's typeof null === "object" would otherwise cause the function to traverse null as an object
|
|
21
|
-
and throw an error.
|
|
22
|
-
|
|
23
|
-
Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#typeof_null
|
|
24
|
-
*/
|
|
25
|
-
if (typeof val === "object" && val !== null) {
|
|
19
|
+
if (typeof val === "object") {
|
|
26
20
|
traverseObj(val, nestedPath, pairs);
|
|
27
21
|
} else {
|
|
28
22
|
pairs.set(nestedPath, val);
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import SortedArray from "sorted-array";
|
|
2
2
|
import type { Matcher } from "./deep-partial-matcher";
|
|
3
3
|
import { createObjectMatcher } from "./deep-partial-matcher";
|
|
4
4
|
|
|
5
5
|
export { createObjectMatcher } from "./deep-partial-matcher";
|
|
6
6
|
|
|
7
|
-
/** Minimal logger interface for registry operations */
|
|
8
|
-
interface Logger {
|
|
9
|
-
debug?: (...args: Array<any>) => void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
7
|
/** create a matcher function that matches exactly */
|
|
13
8
|
function createBasicMatcher(seed: any): Matcher {
|
|
14
9
|
/** a simple matcher function that only matches itself */
|
|
@@ -29,99 +24,60 @@ interface RegistryIndex<V> {
|
|
|
29
24
|
matcher: Matcher;
|
|
30
25
|
}
|
|
31
26
|
|
|
27
|
+
/** create an empty sorted array using the matcher count */
|
|
28
|
+
const createSortedArray = <V>() =>
|
|
29
|
+
new SortedArray<RegistryIndex<V>>([], (c) => c.matcher.count);
|
|
30
|
+
|
|
32
31
|
/**
|
|
33
32
|
* A partial match registry is a map that uses an object to "match" against keys.
|
|
34
33
|
* More specific matches take precedence over less specific ones.
|
|
35
34
|
*/
|
|
36
35
|
export class Registry<V> {
|
|
37
|
-
private store
|
|
38
|
-
private logger?: Logger;
|
|
36
|
+
private store = createSortedArray<V>();
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
* Creates a new Registry instance
|
|
42
|
-
*
|
|
43
|
-
* @param initialSet - Optional array of [key, value] tuples to populate the registry
|
|
44
|
-
* @param logger - Optional logger instance for debug logging (e.g., when entries are replaced)
|
|
45
|
-
*/
|
|
46
|
-
constructor(initialSet?: Array<[any, V]>, logger?: Logger) {
|
|
47
|
-
this.logger = logger;
|
|
38
|
+
constructor(initialSet?: Array<[any, V]>) {
|
|
48
39
|
initialSet?.forEach(([match, value]) => {
|
|
49
40
|
this.set(match, value);
|
|
50
41
|
});
|
|
51
42
|
}
|
|
52
43
|
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
-
*
|
|
56
|
-
* If an entry with the same specificity and matching key already exists, it will be replaced
|
|
57
|
-
* and a debug log will be emitted (if a logger is configured).
|
|
58
|
-
*
|
|
59
|
-
* @param match - The key to match against (can be a primitive or object)
|
|
60
|
-
* @param value - The value to associate with this key
|
|
61
|
-
*/
|
|
62
|
-
set(match: any, value: V): void {
|
|
44
|
+
/** Add match -> value mapping to the registry */
|
|
45
|
+
set(match: any, value: V) {
|
|
63
46
|
const matcher =
|
|
64
47
|
typeof match === "object"
|
|
65
48
|
? createObjectMatcher(match)
|
|
66
49
|
: createBasicMatcher(match);
|
|
67
50
|
|
|
68
|
-
|
|
69
|
-
// Use matcher to check for matching keys (handles deep equality)
|
|
70
|
-
const existingIndex = this.store.findIndex(
|
|
71
|
-
(entry) => entry.matcher(match) && matcher(entry.key),
|
|
72
|
-
);
|
|
73
|
-
if (existingIndex !== -1) {
|
|
74
|
-
this.store.splice(existingIndex, 1);
|
|
75
|
-
this.logger?.debug?.(
|
|
76
|
-
"Registry: Replacing existing entry for key ",
|
|
77
|
-
match,
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
this.store.push({
|
|
51
|
+
this.store.insert({
|
|
82
52
|
key: match,
|
|
83
53
|
value,
|
|
84
54
|
matcher,
|
|
85
55
|
});
|
|
86
|
-
|
|
87
|
-
// Sort in descending order by matcher.count (highest specificity first)
|
|
88
|
-
this.store = sort(this.store).desc((entry) => entry.matcher.count);
|
|
89
56
|
}
|
|
90
57
|
|
|
91
|
-
/**
|
|
92
|
-
* Fetch the best match in the registry
|
|
93
|
-
*
|
|
94
|
-
* Searches for the most specific entry that matches the given query.
|
|
95
|
-
* The registry is sorted by specificity (matcher.count) in descending order,
|
|
96
|
-
* so we iterate forward to find the highest specificity match first.
|
|
97
|
-
*
|
|
98
|
-
* @param query - The query object to match against registered keys
|
|
99
|
-
* @returns The value associated with the best matching key, or undefined if no match found
|
|
100
|
-
*/
|
|
58
|
+
/** Fetch the best match in the registry */
|
|
101
59
|
get(query: any): V | undefined {
|
|
102
|
-
|
|
103
|
-
for (const entry of this.store) {
|
|
60
|
+
for (const entry of this.store.array) {
|
|
104
61
|
if (entry.matcher(query)) {
|
|
105
62
|
return entry.value;
|
|
106
63
|
}
|
|
107
64
|
}
|
|
108
|
-
return undefined;
|
|
109
65
|
}
|
|
110
66
|
|
|
111
67
|
/** Loop over all entries and run callback */
|
|
112
68
|
forEach(callbackfn: (value: RegistryIndex<V>) => void): void {
|
|
113
|
-
for (const entry of this.store) {
|
|
69
|
+
for (const entry of this.store.array) {
|
|
114
70
|
callbackfn(entry);
|
|
115
71
|
}
|
|
116
72
|
}
|
|
117
73
|
|
|
118
74
|
/** Reset the items in the registry */
|
|
119
|
-
clear()
|
|
120
|
-
this.store =
|
|
75
|
+
clear() {
|
|
76
|
+
this.store = createSortedArray<V>();
|
|
121
77
|
}
|
|
122
78
|
|
|
123
79
|
/** Check if the registry is empty*/
|
|
124
|
-
isRegistryEmpty()
|
|
125
|
-
return this.store.length === 0;
|
|
80
|
+
isRegistryEmpty() {
|
|
81
|
+
return this.store.array.length === 0;
|
|
126
82
|
}
|
|
127
83
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import type { Matcher } from "./deep-partial-matcher";
|
|
2
2
|
export { createObjectMatcher } from "./deep-partial-matcher";
|
|
3
|
-
/** Minimal logger interface for registry operations */
|
|
4
|
-
interface Logger {
|
|
5
|
-
debug?: (...args: Array<any>) => void;
|
|
6
|
-
}
|
|
7
3
|
interface RegistryIndex<V> {
|
|
8
4
|
/** The original object we wanted to match on */
|
|
9
5
|
key: object;
|
|
@@ -18,34 +14,10 @@ interface RegistryIndex<V> {
|
|
|
18
14
|
*/
|
|
19
15
|
export declare class Registry<V> {
|
|
20
16
|
private store;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Creates a new Registry instance
|
|
24
|
-
*
|
|
25
|
-
* @param initialSet - Optional array of [key, value] tuples to populate the registry
|
|
26
|
-
* @param logger - Optional logger instance for debug logging (e.g., when entries are replaced)
|
|
27
|
-
*/
|
|
28
|
-
constructor(initialSet?: Array<[any, V]>, logger?: Logger);
|
|
29
|
-
/**
|
|
30
|
-
* Add match -> value mapping to the registry
|
|
31
|
-
*
|
|
32
|
-
* If an entry with the same specificity and matching key already exists, it will be replaced
|
|
33
|
-
* and a debug log will be emitted (if a logger is configured).
|
|
34
|
-
*
|
|
35
|
-
* @param match - The key to match against (can be a primitive or object)
|
|
36
|
-
* @param value - The value to associate with this key
|
|
37
|
-
*/
|
|
17
|
+
constructor(initialSet?: Array<[any, V]>);
|
|
18
|
+
/** Add match -> value mapping to the registry */
|
|
38
19
|
set(match: any, value: V): void;
|
|
39
|
-
/**
|
|
40
|
-
* Fetch the best match in the registry
|
|
41
|
-
*
|
|
42
|
-
* Searches for the most specific entry that matches the given query.
|
|
43
|
-
* The registry is sorted by specificity (matcher.count) in descending order,
|
|
44
|
-
* so we iterate forward to find the highest specificity match first.
|
|
45
|
-
*
|
|
46
|
-
* @param query - The query object to match against registered keys
|
|
47
|
-
* @returns The value associated with the best matching key, or undefined if no match found
|
|
48
|
-
*/
|
|
20
|
+
/** Fetch the best match in the registry */
|
|
49
21
|
get(query: any): V | undefined;
|
|
50
22
|
/** Loop over all entries and run callback */
|
|
51
23
|
forEach(callbackfn: (value: RegistryIndex<V>) => void): void;
|