@rkmodules/rules 0.0.60 → 0.0.62
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/index.cjs.js +82 -45
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +82 -46
- package/dist/index.esm.js.map +1 -1
- package/dist/lib/DataTree/index.d.ts +3 -0
- package/dist/lib/DataTree/util.d.ts +1 -1
- package/dist/lib/Engine/util.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -239,6 +239,9 @@ function isSingleTon(value) {
|
|
|
239
239
|
}
|
|
240
240
|
/**
|
|
241
241
|
* turns a value or array of values into a tree
|
|
242
|
+
* - a single value becomes a tree with one branch "0" and one item
|
|
243
|
+
* - an array of values becomes a tree with one branch "0" and the items in the array
|
|
244
|
+
* - a tree is returned as is
|
|
242
245
|
*/
|
|
243
246
|
function broadCast(value) {
|
|
244
247
|
if (Array.isArray(value)) {
|
|
@@ -259,14 +262,14 @@ function getBranch(tree, path) {
|
|
|
259
262
|
* @returns
|
|
260
263
|
*/
|
|
261
264
|
function mapTree(tree, fn) {
|
|
262
|
-
return nAryOnTree([tree], function (_a, _b, index) {
|
|
265
|
+
return nAryOnTree([tree], function mapTreeCallback(_a, _b, index) {
|
|
263
266
|
var _c = __read(_a, 1), item = _c[0];
|
|
264
267
|
var _d = __read(_b, 1), path = _d[0];
|
|
265
268
|
return fn(item, path, index);
|
|
266
269
|
});
|
|
267
270
|
}
|
|
268
271
|
function mapTreeBranch(tree, fn) {
|
|
269
|
-
return nAryOnTreeBranch([tree], function (_a, _b) {
|
|
272
|
+
return nAryOnTreeBranch([tree], function mapTreeBranchCallback(_a, _b) {
|
|
270
273
|
var _c = __read(_a, 1), branch = _c[0];
|
|
271
274
|
var _d = __read(_b, 1), path = _d[0];
|
|
272
275
|
return fn(branch, path);
|
|
@@ -319,7 +322,7 @@ function nAryOnTreeBranch(trees, fn) {
|
|
|
319
322
|
* @returns
|
|
320
323
|
*/
|
|
321
324
|
function nAryOnTree(trees, fn, fill) {
|
|
322
|
-
return nAryOnTreeBranch(trees, function (branches, paths) {
|
|
325
|
+
return nAryOnTreeBranch(trees, function nAryOnTreeCallback(branches, paths) {
|
|
323
326
|
var maxLength = Math.max.apply(Math, __spreadArray([], __read(branches.map(function (b) { return b.length; })), false));
|
|
324
327
|
if (maxLength === 0)
|
|
325
328
|
return; // Skip empty branches
|
|
@@ -356,7 +359,7 @@ function nAryOnTree(trees, fn, fill) {
|
|
|
356
359
|
* @returns
|
|
357
360
|
*/
|
|
358
361
|
function binaryOnTreeBranch(treeA, treeB, fn) {
|
|
359
|
-
return nAryOnTreeBranch([treeA, treeB], function (_a, _b) {
|
|
362
|
+
return nAryOnTreeBranch([treeA, treeB], function binaryOnTreeBranchCallback(_a, _b) {
|
|
360
363
|
var _c = __read(_a, 2), branchA = _c[0], branchB = _c[1];
|
|
361
364
|
var _d = __read(_b, 2), pathA = _d[0], pathB = _d[1];
|
|
362
365
|
return fn(branchA, branchB, pathA, pathB);
|
|
@@ -375,7 +378,7 @@ function binaryOnTreeBranch(treeA, treeB, fn) {
|
|
|
375
378
|
* @returns
|
|
376
379
|
*/
|
|
377
380
|
function binaryOnTree(treeA, treeB, fn, fill) {
|
|
378
|
-
return nAryOnTree([treeA, treeB], function (_a, _b, index) {
|
|
381
|
+
return nAryOnTree([treeA, treeB], function binaryOnTreeCallback(_a, _b, index) {
|
|
379
382
|
var _c = __read(_a, 2), itemA = _c[0], itemB = _c[1];
|
|
380
383
|
var _d = __read(_b, 2), pathA = _d[0], pathB = _d[1];
|
|
381
384
|
return fn(itemA, itemB, pathA, pathB, index);
|
|
@@ -403,30 +406,42 @@ function toArray(a) {
|
|
|
403
406
|
* @param b
|
|
404
407
|
* @returns
|
|
405
408
|
*/
|
|
406
|
-
function mergeTrees(
|
|
407
|
-
var
|
|
408
|
-
var
|
|
409
|
-
|
|
410
|
-
try {
|
|
411
|
-
for (var _c = __values(Object.entries(b)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
412
|
-
var _e = __read(_d.value, 2), k = _e[0], arr = _e[1];
|
|
413
|
-
out[k] = ((_b = out[k]) !== null && _b !== void 0 ? _b : []).concat(arr);
|
|
414
|
-
}
|
|
409
|
+
function mergeTrees() {
|
|
410
|
+
var others = [];
|
|
411
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
412
|
+
others[_i] = arguments[_i];
|
|
415
413
|
}
|
|
416
|
-
|
|
417
|
-
|
|
414
|
+
var a = others.shift() || { 0: [] };
|
|
415
|
+
var out = __assign({}, a);
|
|
416
|
+
others.forEach(function (b) {
|
|
417
|
+
var e_1, _a;
|
|
418
|
+
var _b;
|
|
418
419
|
try {
|
|
419
|
-
|
|
420
|
+
for (var _c = __values(Object.entries(b)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
421
|
+
var _e = __read(_d.value, 2), k = _e[0], arr = _e[1];
|
|
422
|
+
out[k] = ((_b = out[k]) !== null && _b !== void 0 ? _b : []).concat(arr);
|
|
423
|
+
}
|
|
420
424
|
}
|
|
421
|
-
|
|
422
|
-
|
|
425
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
426
|
+
finally {
|
|
427
|
+
try {
|
|
428
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
429
|
+
}
|
|
430
|
+
finally { if (e_1) throw e_1.error; }
|
|
431
|
+
}
|
|
432
|
+
});
|
|
423
433
|
return out;
|
|
424
434
|
}
|
|
425
435
|
|
|
426
436
|
function isReference(value) {
|
|
427
|
-
return (typeof value === "string" &&
|
|
428
|
-
|
|
429
|
-
|
|
437
|
+
return (typeof value === "string" && !!value.match(/^<([\w\.]+)>$/)
|
|
438
|
+
// value.startsWith("<") &&
|
|
439
|
+
// value.endsWith(">")
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
function hasReference(value) {
|
|
443
|
+
var _a;
|
|
444
|
+
return typeof value === "string" && !!((_a = value.match) === null || _a === void 0 ? void 0 : _a.call(value, /<(.*?)>/g));
|
|
430
445
|
}
|
|
431
446
|
function parseReference(ref) {
|
|
432
447
|
return ref.slice(1, -1);
|
|
@@ -446,29 +461,35 @@ function getValue$1(obj, path) {
|
|
|
446
461
|
return value;
|
|
447
462
|
}
|
|
448
463
|
function interpolateValue(value, scope) {
|
|
464
|
+
// interpolating arrays
|
|
449
465
|
if (Array.isArray(value)) {
|
|
450
466
|
if (!value.length)
|
|
451
|
-
return
|
|
452
|
-
if (
|
|
453
|
-
//
|
|
454
|
-
var
|
|
455
|
-
|
|
467
|
+
return [];
|
|
468
|
+
if (value.every(isTree)) {
|
|
469
|
+
// array of trees: merge the trees into one
|
|
470
|
+
var tree = mergeTrees.apply(void 0, __spreadArray([], __read(value), false));
|
|
471
|
+
// then interpolate each value in the tree in case there are references
|
|
472
|
+
return mapTree(tree, function (v) { return interpolateValue(v, scope); });
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
// array of other values: interpolate to an array of trees
|
|
476
|
+
var mappedValue = value.map(function (v) {
|
|
477
|
+
return broadCast(interpolateValue(v, scope));
|
|
478
|
+
});
|
|
479
|
+
if (!mappedValue.every(isTree)) {
|
|
456
480
|
// this is a bit of a hack when the values were all plain values
|
|
457
481
|
// in that case, just return them, which will result in a single tree
|
|
458
|
-
return
|
|
482
|
+
return mappedValue;
|
|
459
483
|
}
|
|
460
484
|
// then, for each value, combine the branches with the same index
|
|
461
|
-
return
|
|
462
|
-
}
|
|
463
|
-
else {
|
|
464
|
-
// combine the trees into one
|
|
465
|
-
var tree = value.reduce(function (acc, t) { return mergeTrees(acc, t); });
|
|
466
|
-
return mapTree(tree, function (v) { return interpolateValue(v, scope); });
|
|
485
|
+
return mergeTrees.apply(void 0, __spreadArray([], __read(mappedValue), false));
|
|
467
486
|
}
|
|
468
487
|
}
|
|
488
|
+
// a tree is mapped over each value
|
|
469
489
|
if (isTree(value)) {
|
|
470
490
|
return mapTree(value, function (v) { return interpolateValue(v, scope); });
|
|
471
491
|
}
|
|
492
|
+
// an object is interpolated recursively
|
|
472
493
|
if (typeof value === "object" && value !== null) {
|
|
473
494
|
if (Object.keys(value).length === 0) {
|
|
474
495
|
return {};
|
|
@@ -483,18 +504,33 @@ function interpolateValue(value, scope) {
|
|
|
483
504
|
}));
|
|
484
505
|
});
|
|
485
506
|
}
|
|
486
|
-
if (
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
507
|
+
if (hasReference(value)) {
|
|
508
|
+
if (isReference(value)) {
|
|
509
|
+
// it's a simple reference string
|
|
510
|
+
var parts_1 = parseReference(value).split(".");
|
|
511
|
+
var mappedValue = getValue$1(scope, parts_1.slice(0, 2).join("."));
|
|
512
|
+
if (parts_1.length > 2) {
|
|
513
|
+
// deep interpolate
|
|
514
|
+
mappedValue = mapTree(mappedValue, function (v) {
|
|
515
|
+
return getValue$1(v, parts_1.slice(2).join("."));
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
return mappedValue;
|
|
519
|
+
}
|
|
520
|
+
else {
|
|
521
|
+
// it's a template string, break up as an array of strings and references and interpolate each to a tree
|
|
522
|
+
var strings = value.split(/(<.*?>)/);
|
|
523
|
+
var trees = strings.map(function (str) {
|
|
524
|
+
return broadCast(interpolateValue(str, scope));
|
|
525
|
+
});
|
|
526
|
+
// create a combined string for each item, filling in missing items witht the last
|
|
527
|
+
var combined = nAryOnTree(trees, function (items) {
|
|
528
|
+
return items.join("");
|
|
529
|
+
}, true);
|
|
530
|
+
return combined;
|
|
531
|
+
}
|
|
496
532
|
}
|
|
497
|
-
return
|
|
533
|
+
return value;
|
|
498
534
|
}
|
|
499
535
|
function interpolate(inputs, scope) {
|
|
500
536
|
return Object.fromEntries(Object.entries(inputs).map(function (_a) {
|
|
@@ -5126,6 +5162,7 @@ exports.getBranch = getBranch;
|
|
|
5126
5162
|
exports.getReferences = getReferences;
|
|
5127
5163
|
exports.getValue = getValue$1;
|
|
5128
5164
|
exports.graftTree = graftTree;
|
|
5165
|
+
exports.hasReference = hasReference;
|
|
5129
5166
|
exports.interpolate = interpolate;
|
|
5130
5167
|
exports.isReference = isReference;
|
|
5131
5168
|
exports.isSingleTon = isSingleTon;
|