@rkmodules/rules 0.0.154 → 0.0.155

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 CHANGED
@@ -2631,9 +2631,9 @@ var setField = {
2631
2631
  newObject = nAryOnTree([object, key, value], function (_a) {
2632
2632
  var _b = __read(_a, 3), o = _b[0], k = _b[1], v = _b[2];
2633
2633
  var newObj = __assign({}, o);
2634
- if (o[k] !== undefined && !overwrite) {
2634
+ if (newObj[k] !== undefined && !overwrite) {
2635
2635
  // If the key already exists and overwrite is false, return the original object
2636
- return o;
2636
+ return newObj;
2637
2637
  }
2638
2638
  if (k !== undefined) {
2639
2639
  newObj[k] = v;
@@ -2647,6 +2647,61 @@ var setField = {
2647
2647
  }); },
2648
2648
  };
2649
2649
 
2650
+ var destructureObject = {
2651
+ name: "destructureObject",
2652
+ label: "Destructure Object",
2653
+ description: "Separates an object into a part with the specified fields and the rest",
2654
+ inputs: {
2655
+ object: "any",
2656
+ fields: { type: "string" },
2657
+ },
2658
+ params: {
2659
+ all: { type: "boolean", default: true, label: "all fields" },
2660
+ },
2661
+ outputs: {
2662
+ object: "any",
2663
+ exclusion: "any",
2664
+ },
2665
+ impl: function (_a, params_1) { return __awaiter(void 0, [_a, params_1], void 0, function (_b, params) {
2666
+ var split;
2667
+ var _c = _b.object, object = _c === void 0 ? {} : _c, _d = _b.fields, fields = _d === void 0 ? {} : _d;
2668
+ return __generator(this, function (_e) {
2669
+ if (params.all) {
2670
+ fields = mapTreeBranch(fields, function (items) {
2671
+ return [items];
2672
+ });
2673
+ }
2674
+ split = nAryOnTree([object, fields], function (_a) {
2675
+ var _b = __read(_a, 2), obj = _b[0], _c = _b[1], flds = _c === void 0 ? [] : _c;
2676
+ var newObj = {};
2677
+ var exclusion = {};
2678
+ if (typeof obj !== "object" || obj === null)
2679
+ return DISCARD;
2680
+ Object.entries(obj).forEach(function (_a) {
2681
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
2682
+ if (flds.includes(key)) {
2683
+ newObj[key] = value;
2684
+ }
2685
+ else {
2686
+ exclusion[key] = value;
2687
+ }
2688
+ });
2689
+ return [[newObj, exclusion]];
2690
+ }, true);
2691
+ return [2 /*return*/, {
2692
+ object: mapTree(split, function (_a) {
2693
+ var _b = __read(_a, 2), o = _b[0]; _b[1];
2694
+ return o;
2695
+ }),
2696
+ exclusion: mapTree(split, function (_a) {
2697
+ var _b = __read(_a, 2); _b[0]; var e = _b[1];
2698
+ return e;
2699
+ }),
2700
+ }];
2701
+ });
2702
+ }); },
2703
+ };
2704
+
2650
2705
  var _a$1;
2651
2706
  var primitives$1 = (_a$1 = {},
2652
2707
  _a$1[object.name] = object,
@@ -2656,6 +2711,7 @@ var primitives$1 = (_a$1 = {},
2656
2711
  _a$1[mergeObject.name] = mergeObject,
2657
2712
  _a$1[objectEntries.name] = objectEntries,
2658
2713
  _a$1[explodeObject.name] = explodeObject,
2714
+ _a$1[destructureObject.name] = destructureObject,
2659
2715
  _a$1);
2660
2716
 
2661
2717
  var INFERRED = "inferred";