jsf.js_next_gen 1.0.0-beta-14 → 1.0.0-beta-17

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.
@@ -504,8 +504,12 @@ var DomQuery = /** @class */ (function () {
504
504
  Object.defineProperty(DomQuery.prototype, "asArray", {
505
505
  get: function () {
506
506
  //filter not supported by IE11
507
- return [].concat(Stream_1.LazyStream.of.apply(Stream_1.LazyStream, this.rootNode).filter(function (item) { return item != null; })
508
- .map(function (item) { return DomQuery.byId(item); }).collect(new SourcesCollectors_1.ArrayCollector()));
507
+ return [].concat(Stream_1.LazyStream.of.apply(Stream_1.LazyStream, this.rootNode).filter(function (item) {
508
+ return item != null;
509
+ })
510
+ .map(function (item) {
511
+ return DomQuery.byId(item);
512
+ }).collect(new SourcesCollectors_1.ArrayCollector()));
509
513
  },
510
514
  enumerable: false,
511
515
  configurable: true
@@ -896,7 +900,8 @@ var DomQuery = /** @class */ (function () {
896
900
  //code snippet license: https://creativecommons.org/licenses/by-sa/2.5/
897
901
  DomQuery.prototype._mozMatchesSelector = function (toMatch, selector) {
898
902
  var prot = toMatch;
899
- var matchesSelector = prot.matchesSelector ||
903
+ var matchesSelector = prot.matches ||
904
+ prot.matchesSelector ||
900
905
  prot.mozMatchesSelector ||
901
906
  prot.msMatchesSelector ||
902
907
  prot.oMatchesSelector ||
@@ -925,14 +930,19 @@ var DomQuery = /** @class */ (function () {
925
930
  });
926
931
  return new (DomQuery.bind.apply(DomQuery, __spreadArray([void 0], matched, false)))();
927
932
  };
933
+ /**
934
+ * checks whether any item in this domQuery level matches the selector
935
+ * if there is one element only attached, as root the match is only
936
+ * performed on this element.
937
+ * @param selector
938
+ */
928
939
  DomQuery.prototype.matchesSelector = function (selector) {
929
940
  var _this = this;
930
- this.eachElem(function (item) {
931
- if (!_this._mozMatchesSelector(item, selector)) {
932
- return false;
933
- }
934
- });
935
- return true;
941
+ var ret = this.lazyStream
942
+ .map(function (item) { return _this._mozMatchesSelector(item.getAsElem(0).value, selector); })
943
+ .filter(function (match) { return match; })
944
+ .first();
945
+ return ret.isPresent();
936
946
  };
937
947
  /**
938
948
  * easy node traversal, you can pass
@@ -1618,6 +1628,19 @@ var DomQuery = /** @class */ (function () {
1618
1628
  this.pos++;
1619
1629
  return new DomQuery(this.values[this.pos]);
1620
1630
  };
1631
+ DomQuery.prototype.lookAhead = function (cnt) {
1632
+ if (cnt === void 0) { cnt = 1; }
1633
+ if ((this.values.length - 1) < (this.pos + cnt)) {
1634
+ return SourcesCollectors_1.ITERATION_STATUS.EO_STRM;
1635
+ }
1636
+ return new DomQuery(this.values[this.pos + cnt]);
1637
+ };
1638
+ DomQuery.prototype.current = function () {
1639
+ if (this.pos == -1) {
1640
+ return SourcesCollectors_1.ITERATION_STATUS.BEF_STRM;
1641
+ }
1642
+ return new DomQuery(this.values[this.pos]);
1643
+ };
1621
1644
  DomQuery.prototype.reset = function () {
1622
1645
  this.pos = -1;
1623
1646
  };
@@ -1740,6 +1763,24 @@ var DomQuery = /** @class */ (function () {
1740
1763
  }
1741
1764
  };
1742
1765
  };
1766
+ /**
1767
+ * concats the elements of two Dom Queries into a single one
1768
+ * @param toAttach
1769
+ */
1770
+ DomQuery.prototype.concat = function (toAttach, filterDoubles) {
1771
+ if (filterDoubles === void 0) { filterDoubles = true; }
1772
+ var ret = this.lazyStream.concat(toAttach.lazyStream).collect(new DomQueryCollector());
1773
+ //we now filter the doubles out
1774
+ if (!filterDoubles) {
1775
+ return ret;
1776
+ }
1777
+ var idx = {}; //ie11 does not support sets, we have to fake it
1778
+ return ret.lazyStream.filter(function (node) {
1779
+ var notFound = !(idx === null || idx === void 0 ? void 0 : idx[node.value.value.outerHTML]);
1780
+ idx[node.value.value.outerHTML] = true;
1781
+ return notFound;
1782
+ }).collect(new DomQueryCollector());
1783
+ };
1743
1784
  DomQuery.absent = new DomQuery();
1744
1785
  return DomQuery;
1745
1786
  }());
@@ -2385,6 +2426,10 @@ var Config = /** @class */ (function (_super) {
2385
2426
  return _super.call(this, root) || this;
2386
2427
  }
2387
2428
  Object.defineProperty(Config.prototype, "shallowCopy", {
2429
+ /**
2430
+ * shallow copy getter, copies only the first level, references the deeper nodes
2431
+ * in a shared manner
2432
+ */
2388
2433
  get: function () {
2389
2434
  return new Config(Stream_1.Stream.ofAssoc(this.value).collect(new SourcesCollectors_1.AssocArrayCollector()));
2390
2435
  },
@@ -2392,12 +2437,19 @@ var Config = /** @class */ (function (_super) {
2392
2437
  configurable: true
2393
2438
  });
2394
2439
  Object.defineProperty(Config.prototype, "deepCopy", {
2440
+ /**
2441
+ * deep copy, copies all config nodes
2442
+ */
2395
2443
  get: function () {
2396
2444
  return new Config(objAssign({}, this.value));
2397
2445
  },
2398
2446
  enumerable: false,
2399
2447
  configurable: true
2400
2448
  });
2449
+ /**
2450
+ * creates a config from an initial value or null
2451
+ * @param value
2452
+ */
2401
2453
  Config.fromNullable = function (value) {
2402
2454
  return new Config(value);
2403
2455
  };
@@ -2438,74 +2490,99 @@ var Config = /** @class */ (function (_super) {
2438
2490
  *
2439
2491
  * resulting in myConfig.foobaz == ["newValue, newValue2"]
2440
2492
  *
2441
- * @param keys
2493
+ * @param {string[]} accessPath
2442
2494
  */
2443
2495
  Config.prototype.append = function () {
2444
- var keys = [];
2496
+ var accessPath = [];
2445
2497
  for (var _i = 0; _i < arguments.length; _i++) {
2446
- keys[_i] = arguments[_i];
2498
+ accessPath[_i] = arguments[_i];
2447
2499
  }
2448
- var noKeys = keys.length < 1;
2500
+ var noKeys = accessPath.length < 1;
2449
2501
  if (noKeys) {
2450
2502
  return;
2451
2503
  }
2452
- var lastKey = keys[keys.length - 1];
2504
+ var lastKey = accessPath[accessPath.length - 1];
2453
2505
  var currKey, finalKey = this.keyVal(lastKey);
2454
- var pathExists = this.getIf.apply(this, keys).isPresent();
2455
- this.buildPath(keys);
2506
+ var pathExists = this.getIf.apply(this, accessPath).isPresent();
2507
+ this.buildPath(accessPath);
2456
2508
  var finalKeyArrPos = this.arrayIndex(lastKey);
2457
2509
  if (finalKeyArrPos > -1) {
2458
2510
  throw Error("Append only possible on non array properties, use assign on indexed data");
2459
2511
  }
2460
- var value = this.getIf.apply(this, keys).value;
2512
+ var value = this.getIf.apply(this, accessPath).value;
2461
2513
  if (!Array.isArray(value)) {
2462
- value = this.assign.apply(this, keys).value = [value];
2514
+ value = this.assign.apply(this, accessPath).value = [value];
2463
2515
  }
2464
2516
  if (pathExists) {
2465
2517
  value.push({});
2466
2518
  }
2467
2519
  finalKeyArrPos = value.length - 1;
2468
- var retVal = new ConfigEntry(keys.length == 1 ? this.value : this.getIf.apply(this, keys.slice(0, keys.length - 1)).value, lastKey, finalKeyArrPos);
2520
+ var retVal = new ConfigEntry(accessPath.length == 1 ? this.value : this.getIf.apply(this, accessPath.slice(0, accessPath.length - 1)).value, lastKey, finalKeyArrPos);
2469
2521
  return retVal;
2470
2522
  };
2523
+ /**
2524
+ * appends to an existing entry (or extends into an array and appends)
2525
+ * if the condition is met
2526
+ * @param {boolean} condition
2527
+ * @param {string[]} accessPath
2528
+ */
2471
2529
  Config.prototype.appendIf = function (condition) {
2472
- var keys = [];
2530
+ var accessPath = [];
2473
2531
  for (var _i = 1; _i < arguments.length; _i++) {
2474
- keys[_i - 1] = arguments[_i];
2532
+ accessPath[_i - 1] = arguments[_i];
2475
2533
  }
2476
2534
  if (!condition) {
2477
2535
  return { value: null };
2478
2536
  }
2479
- return this.append.apply(this, keys);
2537
+ return this.append.apply(this, accessPath);
2480
2538
  };
2539
+ /**
2540
+ * assings an new value on the given access path
2541
+ * @param accessPath
2542
+ */
2481
2543
  Config.prototype.assign = function () {
2482
- var keys = [];
2544
+ var accessPath = [];
2483
2545
  for (var _i = 0; _i < arguments.length; _i++) {
2484
- keys[_i] = arguments[_i];
2546
+ accessPath[_i] = arguments[_i];
2485
2547
  }
2486
- if (keys.length < 1) {
2548
+ if (accessPath.length < 1) {
2487
2549
  return;
2488
2550
  }
2489
- this.buildPath(keys);
2490
- var currKey = this.keyVal(keys[keys.length - 1]);
2491
- var arrPos = this.arrayIndex(keys[keys.length - 1]);
2492
- var retVal = new ConfigEntry(keys.length == 1 ? this.value : this.getIf.apply(this, keys.slice(0, keys.length - 1)).value, currKey, arrPos);
2551
+ this.buildPath(accessPath);
2552
+ var currKey = this.keyVal(accessPath[accessPath.length - 1]);
2553
+ var arrPos = this.arrayIndex(accessPath[accessPath.length - 1]);
2554
+ var retVal = new ConfigEntry(accessPath.length == 1 ? this.value : this.getIf.apply(this, accessPath.slice(0, accessPath.length - 1)).value, currKey, arrPos);
2493
2555
  return retVal;
2494
2556
  };
2557
+ /**
2558
+ * assign a value if the condition is set to true, otherwise skip it
2559
+ *
2560
+ * @param condition the condition, the access accessPath into the config
2561
+ * @param accessPath
2562
+ */
2495
2563
  Config.prototype.assignIf = function (condition) {
2496
- var keys = [];
2564
+ var accessPath = [];
2497
2565
  for (var _i = 1; _i < arguments.length; _i++) {
2498
- keys[_i - 1] = arguments[_i];
2566
+ accessPath[_i - 1] = arguments[_i];
2499
2567
  }
2500
- return condition ? this.assign.apply(this, keys) : { value: null };
2568
+ return condition ? this.assign.apply(this, accessPath) : { value: null };
2501
2569
  };
2570
+ /**
2571
+ * get if the access path is present (get is reserved as getter with a default, on the current path)
2572
+ * TODO will be renamed to something more meaningful and deprecated, the name is ambigous
2573
+ * @param accessPath the access path
2574
+ */
2502
2575
  Config.prototype.getIf = function () {
2503
- var keys = [];
2576
+ var accessPath = [];
2504
2577
  for (var _i = 0; _i < arguments.length; _i++) {
2505
- keys[_i] = arguments[_i];
2578
+ accessPath[_i] = arguments[_i];
2506
2579
  }
2507
- return this.getClass().fromNullable(_super.prototype.getIf.apply(this, keys).value);
2580
+ return this.getClass().fromNullable(_super.prototype.getIf.apply(this, accessPath).value);
2508
2581
  };
2582
+ /**
2583
+ * gets the current node and if none is present returns a config with a default value
2584
+ * @param defaultVal
2585
+ */
2509
2586
  Config.prototype.get = function (defaultVal) {
2510
2587
  return this.getClass().fromNullable(_super.prototype.get.call(this, defaultVal).value);
2511
2588
  };
@@ -2516,6 +2593,9 @@ var Config = /** @class */ (function (_super) {
2516
2593
  }
2517
2594
  return this;
2518
2595
  };
2596
+ /**
2597
+ * converts the entire config into a json object
2598
+ */
2519
2599
  Config.prototype.toJson = function () {
2520
2600
  return JSON.stringify(this.value);
2521
2601
  };
@@ -2528,9 +2608,9 @@ var Config = /** @class */ (function (_super) {
2528
2608
  /**
2529
2609
  * builds the config path
2530
2610
  *
2531
- * @param keys a sequential array of keys containing either a key name or an array reference name[<index>]
2611
+ * @param accessPath a sequential array of accessPath containing either a key name or an array reference name[<index>]
2532
2612
  */
2533
- Config.prototype.buildPath = function (keys) {
2613
+ Config.prototype.buildPath = function (accessPath) {
2534
2614
  var val = this;
2535
2615
  var parentVal = this.getClass().fromNullable(null);
2536
2616
  var parentPos = -1;
@@ -2541,9 +2621,9 @@ var Config = /** @class */ (function (_super) {
2541
2621
  arr.push({});
2542
2622
  }
2543
2623
  };
2544
- for (var cnt = 0; cnt < keys.length; cnt++) {
2545
- var currKey = this.keyVal(keys[cnt]);
2546
- var arrPos = this.arrayIndex(keys[cnt]);
2624
+ for (var cnt = 0; cnt < accessPath.length; cnt++) {
2625
+ var currKey = this.keyVal(accessPath[cnt]);
2626
+ var arrPos = this.arrayIndex(accessPath[cnt]);
2547
2627
  if (currKey === "" && arrPos >= 0) {
2548
2628
  val.setVal((val.value instanceof Array) ? val.value : []);
2549
2629
  alloc(val.value, arrPos + 1);
@@ -2615,8 +2695,24 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2615
2695
  return to.concat(ar || Array.prototype.slice.call(from));
2616
2696
  };
2617
2697
  Object.defineProperty(exports, "__esModule", ({ value: true }));
2618
- exports.QueryFormStringCollector = exports.QueryFormDataCollector = exports.FormDataCollector = exports.AssocArrayCollector = exports.Run = exports.ArrayAssocArrayCollector = exports.ArrayCollector = exports.FlatMapStreamDataSource = exports.MappedStreamDataSource = exports.FilteredStreamDatasource = exports.ArrayStreamDataSource = exports.SequenceDataSource = void 0;
2698
+ exports.QueryFormStringCollector = exports.QueryFormDataCollector = exports.FormDataCollector = exports.AssocArrayCollector = exports.Run = exports.ArrayAssocArrayCollector = exports.ArrayCollector = exports.FlatMapStreamDataSource = exports.MappedStreamDataSource = exports.FilteredStreamDatasource = exports.ArrayStreamDataSource = exports.SequenceDataSource = exports.ITERATION_STATUS = void 0;
2619
2699
  var Stream_1 = __webpack_require__(/*! ./Stream */ "./node_modules/mona-dish/src/main/typescript/Stream.ts");
2700
+ /**
2701
+ * special status of the datasource location pointer
2702
+ * if an access, outside of the possible data boundaries is happening
2703
+ * (example for instance current without a first next call, or next
2704
+ * which goes over the last possible dataset), an iteration status return
2705
+ * value is returned marking this boundary instead of a classical element
2706
+ *
2707
+ * Note this is only internally used but must be implemented to fullfill
2708
+ * internal contracts, the end user will never see those values if he uses
2709
+ * streams!
2710
+ */
2711
+ var ITERATION_STATUS;
2712
+ (function (ITERATION_STATUS) {
2713
+ ITERATION_STATUS["EO_STRM"] = "__EO_STRM__";
2714
+ ITERATION_STATUS["BEF_STRM"] = "___BEF_STRM__";
2715
+ })(ITERATION_STATUS = exports.ITERATION_STATUS || (exports.ITERATION_STATUS = {}));
2620
2716
  /**
2621
2717
  * defines a sequence of numbers for our stream input
2622
2718
  */
@@ -2624,16 +2720,30 @@ var SequenceDataSource = /** @class */ (function () {
2624
2720
  function SequenceDataSource(start, total) {
2625
2721
  this.total = total;
2626
2722
  this.start = start;
2627
- this.value = start;
2723
+ this.value = start - 1;
2628
2724
  }
2629
2725
  SequenceDataSource.prototype.hasNext = function () {
2630
- return this.value < this.total;
2726
+ return this.value < (this.total - 1);
2631
2727
  };
2632
2728
  SequenceDataSource.prototype.next = function () {
2633
- return Math.min(this.value++, this.total - 1);
2729
+ this.value++;
2730
+ return this.value <= (this.total - 1) ? this.value : ITERATION_STATUS.EO_STRM;
2731
+ };
2732
+ SequenceDataSource.prototype.lookAhead = function (cnt) {
2733
+ if (cnt === void 0) { cnt = 1; }
2734
+ if ((this.value + cnt) > this.total - 1) {
2735
+ return ITERATION_STATUS.EO_STRM;
2736
+ }
2737
+ else {
2738
+ return this.value + cnt;
2739
+ }
2634
2740
  };
2635
2741
  SequenceDataSource.prototype.reset = function () {
2636
- this.value = 0;
2742
+ this.value = this.start - 1;
2743
+ };
2744
+ SequenceDataSource.prototype.current = function () {
2745
+ //first condition current without initial call for next
2746
+ return (this.start - 1) ? ITERATION_STATUS.BEF_STRM : this.value;
2637
2747
  };
2638
2748
  return SequenceDataSource;
2639
2749
  }());
@@ -2650,16 +2760,27 @@ var ArrayStreamDataSource = /** @class */ (function () {
2650
2760
  this.dataPos = -1;
2651
2761
  this.value = value;
2652
2762
  }
2763
+ ArrayStreamDataSource.prototype.lookAhead = function (cnt) {
2764
+ if (cnt === void 0) { cnt = 1; }
2765
+ if ((this.dataPos + cnt) > this.value.length - 1) {
2766
+ return ITERATION_STATUS.EO_STRM;
2767
+ }
2768
+ return this.value[this.dataPos + cnt];
2769
+ };
2653
2770
  ArrayStreamDataSource.prototype.hasNext = function () {
2654
2771
  return this.value.length - 1 > this.dataPos;
2655
2772
  };
2656
2773
  ArrayStreamDataSource.prototype.next = function () {
2774
+ var _a;
2657
2775
  this.dataPos++;
2658
- return this.value[this.dataPos];
2776
+ return (_a = this === null || this === void 0 ? void 0 : this.value[this.dataPos]) !== null && _a !== void 0 ? _a : ITERATION_STATUS.EO_STRM;
2659
2777
  };
2660
2778
  ArrayStreamDataSource.prototype.reset = function () {
2661
2779
  this.dataPos = -1;
2662
2780
  };
2781
+ ArrayStreamDataSource.prototype.current = function () {
2782
+ return this.value[Math.max(0, this.dataPos)];
2783
+ };
2663
2784
  return ArrayStreamDataSource;
2664
2785
  }());
2665
2786
  exports.ArrayStreamDataSource = ArrayStreamDataSource;
@@ -2671,7 +2792,11 @@ exports.ArrayStreamDataSource = ArrayStreamDataSource;
2671
2792
  */
2672
2793
  var FilteredStreamDatasource = /** @class */ (function () {
2673
2794
  function FilteredStreamDatasource(filterFunc, parent) {
2674
- this.filteredNext = null;
2795
+ this._current = ITERATION_STATUS.BEF_STRM;
2796
+ // we have to add a filter idx because the external filter values might change over time, so
2797
+ // we cannot reset the state properly unless we do it from a snapshot
2798
+ this._filterIdx = {};
2799
+ this._unfilteredPos = 0;
2675
2800
  this.filterFunc = filterFunc;
2676
2801
  this.inputDataSource = parent;
2677
2802
  }
@@ -2682,32 +2807,61 @@ var FilteredStreamDatasource = /** @class */ (function () {
2682
2807
  * serve it via next
2683
2808
  */
2684
2809
  FilteredStreamDatasource.prototype.hasNext = function () {
2685
- while (this.filteredNext == null && this.inputDataSource.hasNext()) {
2686
- var next = this.inputDataSource.next();
2810
+ var steps = 1;
2811
+ var found = false;
2812
+ var next;
2813
+ while (!found && (next = this.inputDataSource.lookAhead(steps)) != ITERATION_STATUS.EO_STRM) {
2687
2814
  if (this.filterFunc(next)) {
2688
- this.filteredNext = next;
2689
- return true;
2815
+ this._filterIdx[this._unfilteredPos + steps] = true;
2816
+ found = true;
2690
2817
  }
2691
2818
  else {
2692
- this.filteredNext = null;
2819
+ steps++;
2693
2820
  }
2694
2821
  }
2695
- return this.filteredNext != null;
2822
+ return found;
2696
2823
  };
2697
2824
  /**
2698
2825
  * serve the next element
2699
2826
  */
2700
2827
  FilteredStreamDatasource.prototype.next = function () {
2701
- var ret = this.filteredNext;
2702
- this.filteredNext = null;
2703
- //We have to call hasNext, to roll another
2704
- //prefetch in case someone runs next
2705
- //sequentially without calling hasNext
2706
- this.hasNext();
2707
- return ret;
2828
+ var _a, _b;
2829
+ var found = ITERATION_STATUS.EO_STRM;
2830
+ while (this.inputDataSource.hasNext()) {
2831
+ this._unfilteredPos++;
2832
+ var next = this.inputDataSource.next();
2833
+ //again here we cannot call the filter function twice, because its state might change, so if indexed, we have a decent snapshot, either has next or next can trigger
2834
+ //the snapshot
2835
+ if (next != ITERATION_STATUS.EO_STRM &&
2836
+ (((_b = (_a = this._filterIdx) === null || _a === void 0 ? void 0 : _a[this._unfilteredPos]) !== null && _b !== void 0 ? _b : false) || this.filterFunc(next))) {
2837
+ this._filterIdx[this._unfilteredPos] = true;
2838
+ found = next;
2839
+ break;
2840
+ }
2841
+ }
2842
+ this._current = found;
2843
+ return found;
2844
+ };
2845
+ FilteredStreamDatasource.prototype.lookAhead = function (cnt) {
2846
+ var _a;
2847
+ if (cnt === void 0) { cnt = 1; }
2848
+ var lookupVal;
2849
+ for (var loop = 1; cnt > 0 && (lookupVal = this.inputDataSource.lookAhead(loop)) != ITERATION_STATUS.EO_STRM; loop++) {
2850
+ var inCache = (_a = this._filterIdx) === null || _a === void 0 ? void 0 : _a[this._unfilteredPos + loop];
2851
+ if (inCache || this.filterFunc(lookupVal)) {
2852
+ cnt--;
2853
+ this._filterIdx[this._unfilteredPos + loop] = true;
2854
+ }
2855
+ }
2856
+ return lookupVal;
2857
+ };
2858
+ FilteredStreamDatasource.prototype.current = function () {
2859
+ return this._current;
2708
2860
  };
2709
2861
  FilteredStreamDatasource.prototype.reset = function () {
2710
- this.filteredNext = null;
2862
+ this._current = ITERATION_STATUS.BEF_STRM;
2863
+ this._filterIdx = {};
2864
+ this._unfilteredPos = 0;
2711
2865
  this.inputDataSource.reset();
2712
2866
  };
2713
2867
  return FilteredStreamDatasource;
@@ -2731,6 +2885,14 @@ var MappedStreamDataSource = /** @class */ (function () {
2731
2885
  MappedStreamDataSource.prototype.reset = function () {
2732
2886
  this.inputDataSource.reset();
2733
2887
  };
2888
+ MappedStreamDataSource.prototype.current = function () {
2889
+ return this.mapFunc(this.inputDataSource.current());
2890
+ };
2891
+ MappedStreamDataSource.prototype.lookAhead = function (cnt) {
2892
+ if (cnt === void 0) { cnt = 1; }
2893
+ var lookAheadVal = this.inputDataSource.lookAhead(cnt);
2894
+ return (lookAheadVal == ITERATION_STATUS.EO_STRM) ? lookAheadVal : this.mapFunc(lookAheadVal);
2895
+ };
2734
2896
  return MappedStreamDataSource;
2735
2897
  }());
2736
2898
  exports.MappedStreamDataSource = MappedStreamDataSource;
@@ -2739,38 +2901,101 @@ exports.MappedStreamDataSource = MappedStreamDataSource;
2739
2901
  */
2740
2902
  var FlatMapStreamDataSource = /** @class */ (function () {
2741
2903
  function FlatMapStreamDataSource(func, parent) {
2904
+ this.walkedDataSources = [];
2905
+ this._currPos = 0;
2742
2906
  this.mapFunc = func;
2743
2907
  this.inputDataSource = parent;
2744
2908
  }
2745
2909
  FlatMapStreamDataSource.prototype.hasNext = function () {
2746
- return this.resolveCurrentNext() || this.resolveNextNext();
2910
+ return this.resolveActiveHasNext() || this.resolveNextHasNext();
2747
2911
  };
2748
- FlatMapStreamDataSource.prototype.resolveCurrentNext = function () {
2912
+ FlatMapStreamDataSource.prototype.resolveActiveHasNext = function () {
2749
2913
  var next = false;
2750
2914
  if (this.activeDataSource) {
2751
2915
  next = this.activeDataSource.hasNext();
2752
2916
  }
2753
2917
  return next;
2754
2918
  };
2755
- FlatMapStreamDataSource.prototype.resolveNextNext = function () {
2919
+ FlatMapStreamDataSource.prototype.lookAhead = function (cnt) {
2920
+ var _a;
2921
+ if (cnt === void 0) { cnt = 1; }
2922
+ //easy access trial
2923
+ if ((this === null || this === void 0 ? void 0 : this.activeDataSource) && ((_a = this === null || this === void 0 ? void 0 : this.activeDataSource) === null || _a === void 0 ? void 0 : _a.lookAhead(cnt)) != ITERATION_STATUS.EO_STRM) {
2924
+ //this should coverr 95% of all accesses
2925
+ return this === null || this === void 0 ? void 0 : this.activeDataSource.lookAhead(cnt);
2926
+ }
2927
+ /**
2928
+ * we only can determine how many elems datasource has by going up
2929
+ * (for now this suffices, however not ideal, we might have to introduce a numElements or so)
2930
+ * @param datasource
2931
+ */
2932
+ function howManyElems(datasource) {
2933
+ var cnt = 1;
2934
+ while (datasource.lookAhead(cnt) !== ITERATION_STATUS.EO_STRM) {
2935
+ cnt++;
2936
+ }
2937
+ return cnt - 1;
2938
+ }
2939
+ function readjustSkip(dataSource) {
2940
+ var skippedElems = (dataSource) ? howManyElems(dataSource) : 0;
2941
+ cnt = cnt - skippedElems;
2942
+ }
2943
+ if (this.activeDataSource) {
2944
+ readjustSkip(this.activeDataSource);
2945
+ }
2946
+ //the idea is basically to look into the streams subsequentially for a match
2947
+ //after each stream we have to take into consideration that the skipCnt is
2948
+ //reduced by the number of datasets we already have looked into in the previous stream/datasource
2949
+ //unfortunately for now we have to loop into them so we introduce a small o2 here
2950
+ for (var dsLoop = 1; true; dsLoop++) {
2951
+ var currDatasource = this.inputDataSource.lookAhead(dsLoop);
2952
+ //we have looped out
2953
+ if (currDatasource === ITERATION_STATUS.EO_STRM) {
2954
+ return ITERATION_STATUS.EO_STRM;
2955
+ }
2956
+ var mapped = this.mapFunc(currDatasource);
2957
+ //it either comes in as datasource or as array
2958
+ var currentDataSource = this.toDatasource(mapped);
2959
+ var ret = currentDataSource.lookAhead(cnt);
2960
+ if (ret != ITERATION_STATUS.EO_STRM) {
2961
+ return ret;
2962
+ }
2963
+ readjustSkip(currDatasource);
2964
+ }
2965
+ };
2966
+ FlatMapStreamDataSource.prototype.toDatasource = function (mapped) {
2967
+ var ds = Array.isArray(mapped) ? new (ArrayStreamDataSource.bind.apply(ArrayStreamDataSource, __spreadArray([void 0], mapped, false)))() : mapped;
2968
+ this.walkedDataSources.push(ds);
2969
+ return ds;
2970
+ };
2971
+ FlatMapStreamDataSource.prototype.resolveNextHasNext = function () {
2756
2972
  var next = false;
2757
2973
  while (!next && this.inputDataSource.hasNext()) {
2758
2974
  var mapped = this.mapFunc(this.inputDataSource.next());
2759
- if (Array.isArray(mapped)) {
2760
- this.activeDataSource = new (ArrayStreamDataSource.bind.apply(ArrayStreamDataSource, __spreadArray([void 0], mapped, false)))();
2761
- }
2762
- else {
2763
- this.activeDataSource = mapped;
2764
- }
2975
+ this.activeDataSource = this.toDatasource(mapped);
2976
+ ;
2765
2977
  next = this.activeDataSource.hasNext();
2766
2978
  }
2767
2979
  return next;
2768
2980
  };
2769
2981
  FlatMapStreamDataSource.prototype.next = function () {
2770
- return this.activeDataSource.next();
2982
+ if (this.hasNext()) {
2983
+ this._currPos++;
2984
+ return this.activeDataSource.next();
2985
+ }
2771
2986
  };
2772
2987
  FlatMapStreamDataSource.prototype.reset = function () {
2773
2988
  this.inputDataSource.reset();
2989
+ this.walkedDataSources.forEach(function (ds) { return ds.reset(); });
2990
+ this.walkedDataSources = [];
2991
+ this._currPos = 0;
2992
+ this.activeDataSource = null;
2993
+ };
2994
+ FlatMapStreamDataSource.prototype.current = function () {
2995
+ if (!this.activeDataSource) {
2996
+ this.hasNext();
2997
+ }
2998
+ return this.activeDataSource.current();
2774
2999
  };
2775
3000
  return FlatMapStreamDataSource;
2776
3001
  }());
@@ -3005,13 +3230,14 @@ var Stream = /** @class */ (function () {
3005
3230
  };
3006
3231
  Stream.prototype.each = function (fn) {
3007
3232
  this.onElem(fn);
3233
+ this.reset();
3008
3234
  };
3009
3235
  Stream.prototype.map = function (fn) {
3010
3236
  if (!fn) {
3011
3237
  fn = function (inval) { return inval; };
3012
3238
  }
3013
3239
  var res = [];
3014
- this.each(function (item, cnt) {
3240
+ this.each(function (item) {
3015
3241
  res.push(fn(item));
3016
3242
  });
3017
3243
  return new (Stream.bind.apply(Stream, __spreadArray([void 0], res, false)))();
@@ -3044,14 +3270,17 @@ var Stream = /** @class */ (function () {
3044
3270
  for (var cnt = offset; cnt < this.value.length && (this._limits == -1 || cnt < this._limits); cnt++) {
3045
3271
  val1 = fn(val1, this.value[cnt]);
3046
3272
  }
3273
+ this.reset();
3047
3274
  return Monad_1.Optional.fromNullable(val1);
3048
3275
  };
3049
3276
  Stream.prototype.first = function () {
3277
+ this.reset();
3050
3278
  return this.value && this.value.length ? Monad_1.Optional.fromNullable(this.value[0]) : Monad_1.Optional.absent;
3051
3279
  };
3052
3280
  Stream.prototype.last = function () {
3053
3281
  //could be done via reduce, but is faster this way
3054
3282
  var length = this._limits > 0 ? Math.min(this._limits, this.value.length) : this.value.length;
3283
+ this.reset();
3055
3284
  return Monad_1.Optional.fromNullable(length ? this.value[length - 1] : null);
3056
3285
  };
3057
3286
  Stream.prototype.anyMatch = function (fn) {
@@ -3060,6 +3289,7 @@ var Stream = /** @class */ (function () {
3060
3289
  return true;
3061
3290
  }
3062
3291
  }
3292
+ this.reset();
3063
3293
  return false;
3064
3294
  };
3065
3295
  Stream.prototype.allMatch = function (fn) {
@@ -3072,6 +3302,7 @@ var Stream = /** @class */ (function () {
3072
3302
  matches++;
3073
3303
  }
3074
3304
  }
3305
+ this.reset();
3075
3306
  return matches == this.value.length;
3076
3307
  };
3077
3308
  Stream.prototype.noneMatch = function (fn) {
@@ -3081,6 +3312,7 @@ var Stream = /** @class */ (function () {
3081
3312
  matches++;
3082
3313
  }
3083
3314
  }
3315
+ this.reset();
3084
3316
  return matches == this.value.length;
3085
3317
  };
3086
3318
  Stream.prototype.sort = function (comparator) {
@@ -3089,6 +3321,7 @@ var Stream = /** @class */ (function () {
3089
3321
  };
3090
3322
  Stream.prototype.collect = function (collector) {
3091
3323
  this.each(function (data) { return collector.collect(data); });
3324
+ this.reset();
3092
3325
  return collector.finalValue;
3093
3326
  };
3094
3327
  //-- internally exposed methods needed for the interconnectivity
@@ -3104,6 +3337,13 @@ var Stream = /** @class */ (function () {
3104
3337
  this.pos++;
3105
3338
  return this.value[this.pos];
3106
3339
  };
3340
+ Stream.prototype.lookAhead = function (cnt) {
3341
+ if (cnt === void 0) { cnt = 1; }
3342
+ if ((this.pos + cnt) >= this.value.length) {
3343
+ return SourcesCollectors_1.ITERATION_STATUS.EO_STRM;
3344
+ }
3345
+ return this.value[this.pos + cnt];
3346
+ };
3107
3347
  Stream.prototype[Symbol.iterator] = function () {
3108
3348
  var _this = this;
3109
3349
  return {
@@ -3190,9 +3430,16 @@ var LazyStream = /** @class */ (function () {
3190
3430
  this.pos++;
3191
3431
  return next;
3192
3432
  };
3433
+ LazyStream.prototype.lookAhead = function (cnt) {
3434
+ if (cnt === void 0) { cnt = 1; }
3435
+ return this.dataSource.lookAhead(cnt);
3436
+ };
3437
+ LazyStream.prototype.current = function () {
3438
+ return this.dataSource.current();
3439
+ };
3193
3440
  LazyStream.prototype.reset = function () {
3194
3441
  this.dataSource.reset();
3195
- this.pos = 0;
3442
+ this.pos = -1;
3196
3443
  this._limits = -1;
3197
3444
  };
3198
3445
  /**
@@ -3228,6 +3475,7 @@ var LazyStream = /** @class */ (function () {
3228
3475
  var t = this.next();
3229
3476
  collector.collect(t);
3230
3477
  }
3478
+ this.reset();
3231
3479
  return collector.finalValue;
3232
3480
  };
3233
3481
  LazyStream.prototype.onElem = function (fn) {
@@ -3255,13 +3503,14 @@ var LazyStream = /** @class */ (function () {
3255
3503
  this.stop();
3256
3504
  }
3257
3505
  }
3506
+ this.reset();
3258
3507
  };
3259
3508
  LazyStream.prototype.reduce = function (fn, startVal) {
3260
3509
  if (startVal === void 0) { startVal = null; }
3261
3510
  if (!this.hasNext()) {
3262
3511
  return Monad_1.Optional.absent;
3263
3512
  }
3264
- var value1 = null;
3513
+ var value1;
3265
3514
  var value2 = null;
3266
3515
  if (startVal != null) {
3267
3516
  value1 = startVal;
@@ -3279,6 +3528,7 @@ var LazyStream = /** @class */ (function () {
3279
3528
  value2 = this.next();
3280
3529
  value1 = fn(value1, value2);
3281
3530
  }
3531
+ this.reset();
3282
3532
  return Monad_1.Optional.fromNullable(value1);
3283
3533
  };
3284
3534
  LazyStream.prototype.last = function () {
@@ -3348,6 +3598,7 @@ var LazyStream = /** @class */ (function () {
3348
3598
  }*/
3349
3599
  LazyStream.prototype.stop = function () {
3350
3600
  this.pos = this._limits + 1000000000;
3601
+ this._limits = 0;
3351
3602
  };
3352
3603
  LazyStream.prototype.isOverLimits = function () {
3353
3604
  return this._limits != -1 && this.pos >= this._limits - 1;
@@ -3549,6 +3800,7 @@ exports.myfaces = exports.jsf = void 0;
3549
3800
  ///<reference types='../../types/typedefs'/>
3550
3801
  var AjaxImpl_1 = __webpack_require__(/*! ../impl/AjaxImpl */ "./src/main/typescript/impl/AjaxImpl.ts");
3551
3802
  var PushImpl_1 = __webpack_require__(/*! ../impl/PushImpl */ "./src/main/typescript/impl/PushImpl.ts");
3803
+ //declare const Implementation: any;
3552
3804
  var jsf;
3553
3805
  (function (jsf) {
3554
3806
  "use strict";
@@ -3864,7 +4116,7 @@ var Implementation;
3864
4116
  /**
3865
4117
  * fetches the separator char from the given script tags
3866
4118
  *
3867
- * @return {char} the separator char for the given script tags
4119
+ * @return {string} the separator char for the given script tags
3868
4120
  */
3869
4121
  function getSeparatorChar() {
3870
4122
  var _a, _b, _c;
@@ -3911,30 +4163,17 @@ var Implementation;
3911
4163
  * @param funcs
3912
4164
  */
3913
4165
  function chain(source, event) {
4166
+ // we can use our lazy stream each functionality to run our chain here..
4167
+ // by passing a boolean as return value into the onElem call
4168
+ // we can stop early at the first false, just like the spec requests
3914
4169
  var funcs = [];
3915
4170
  for (var _i = 2; _i < arguments.length; _i++) {
3916
4171
  funcs[_i - 2] = arguments[_i];
3917
4172
  }
3918
- var ret = true;
3919
- var resolveAndExecute = function (func) {
3920
- if ("string" != typeof func) {
3921
- //function is passed down as chain parameter, can be executed as is
3922
- return (ret = ret && (func.call(source, event) !== false));
3923
- }
3924
- else {
3925
- //either a function or a string can be passed in case of a string we have to wrap it into another function
3926
- //it it is not a plain executable code but a definition
3927
- var sourceCode = trim(func);
3928
- if (sourceCode.indexOf("function ") == 0) {
3929
- sourceCode = "return ".concat(sourceCode, " (event)");
3930
- }
3931
- return (ret = ret && (new Function("event", sourceCode).call(source, event) !== false));
3932
- }
3933
- };
3934
- //we can use our stream each functionality to run our chain here..
3935
- //the no return value == false stop stream functionality is handled by our resolveAndExecute
3936
- mona_dish_1.Stream.of.apply(mona_dish_1.Stream, funcs).each(function (func) { return resolveAndExecute(func); });
3937
- return ret;
4173
+ return mona_dish_1.LazyStream.of.apply(mona_dish_1.LazyStream, funcs).map(function (func) { return resolveAndExecute(source, event, func); })
4174
+ // we use the return false == stop as an early stop
4175
+ .onElem(function (opResult) { return opResult; })
4176
+ .last().value;
3938
4177
  }
3939
4178
  Implementation.chain = chain;
3940
4179
  /**
@@ -4353,6 +4592,30 @@ var Implementation;
4353
4592
  var _a, _b;
4354
4593
  return (_b = (_a = window === null || window === void 0 ? void 0 : window[Const_1.MYFACES]) === null || _a === void 0 ? void 0 : _a.config) !== null && _b !== void 0 ? _b : {};
4355
4594
  }
4595
+ /**
4596
+ * Private helper to execute a function or code fragment
4597
+ * @param source the source of the caller passed into the function as this
4598
+ * @param event an event which needs to be passed down into the function
4599
+ * @param func either a function or code fragment
4600
+ * @return a boolean value, if the passed function returns false, then the
4601
+ * caller is basically notified that the execution can now stop (JSF requirement for chain)
4602
+ * @private
4603
+ */
4604
+ function resolveAndExecute(source, event, func) {
4605
+ if ("string" != typeof func) {
4606
+ //function is passed down as chain parameter, can be executed as is
4607
+ return func.call(source, event) !== false;
4608
+ }
4609
+ else {
4610
+ //either a function or a string can be passed in case of a string we have to wrap it into another function
4611
+ //it it is not a plain executable code but a definition
4612
+ var sourceCode = trim(func);
4613
+ if (sourceCode.indexOf("function ") == 0) {
4614
+ sourceCode = "return ".concat(sourceCode, " (event)");
4615
+ }
4616
+ return new Function("event", sourceCode).call(source, event) !== false;
4617
+ }
4618
+ }
4356
4619
  })(Implementation = exports.Implementation || (exports.Implementation = {}));
4357
4620
 
4358
4621
 
@@ -5163,6 +5426,7 @@ var IS_JSF_SOURCE = function (source) {
5163
5426
  var IS_INTERNAL_SOURCE = function (source) {
5164
5427
  return source.search(/\/jsf[^\.]\.js.*ln\=myfaces.testscripts.*/gi) != -1;
5165
5428
  };
5429
+ var ATTR_SRC = 'src';
5166
5430
  /**
5167
5431
  * Extension which adds implementation specific
5168
5432
  * meta data to our dom query
@@ -5241,8 +5505,8 @@ var ExtDomquery = /** @class */ (function (_super) {
5241
5505
  var nonceScript = mona_dish_1.DQ
5242
5506
  .querySelectorAll("script[src], link[src]")
5243
5507
  .lazyStream
5244
- .filter(function (item) { return item.attr("nonce").value != null && item.attr("src") != null; })
5245
- .map(function (item) { return IS_JSF_SOURCE(item.attr('src').value); })
5508
+ .filter(function (item) { return item.attr("nonce").value != null && item.attr(ATTR_SRC) != null; })
5509
+ .map(function (item) { return IS_JSF_SOURCE(item.attr(ATTR_SRC).value); })
5246
5510
  .first();
5247
5511
  if (nonceScript.isPresent()) {
5248
5512
  nonce.value = mona_dish_1.DomQuery.byId(nonceScript.value, true).attr("nonce").value;
@@ -5263,8 +5527,8 @@ var ExtDomquery = /** @class */ (function (_super) {
5263
5527
  ExtDomquery.prototype.searchJsfJsFor = function (rexp) {
5264
5528
  //perfect application for lazy stream
5265
5529
  return mona_dish_1.DQ.querySelectorAll("script[src], link[src]").lazyStream
5266
- .filter(function (item) { return IS_JSF_SOURCE(item.attr('src').value); })
5267
- .map(function (item) { return item.attr("src").value.match(rexp); })
5530
+ .filter(function (item) { return IS_JSF_SOURCE(item.attr(ATTR_SRC).value); })
5531
+ .map(function (item) { return item.attr(ATTR_SRC).value.match(rexp); })
5268
5532
  .filter(function (item) { return item != null && item.length > 1; })
5269
5533
  .map(function (result) {
5270
5534
  return decodeURIComponent(result[1]);
@@ -6567,12 +6831,10 @@ var XhrFormData = /** @class */ (function (_super) {
6567
6831
  * @param dataSource either a form as DomQuery object or an encoded url string
6568
6832
  * @param partialIdsArray partial ids to collect, to reduce the data sent down
6569
6833
  */
6570
- function XhrFormData(dataSource, partialIdsArray, encode) {
6571
- if (encode === void 0) { encode = true; }
6834
+ function XhrFormData(dataSource, partialIdsArray) {
6572
6835
  var _this = _super.call(this, {}) || this;
6573
6836
  _this.dataSource = dataSource;
6574
6837
  _this.partialIdsArray = partialIdsArray;
6575
- _this.encode = encode;
6576
6838
  _this.fileInputs = {};
6577
6839
  //a call to getViewState before must pass the encoded line
6578
6840
  //a call from getViewState passes the form element as datasource
@@ -6608,7 +6870,7 @@ var XhrFormData = /** @class */ (function (_super) {
6608
6870
  }
6609
6871
  };
6610
6872
  var inputExists = function (item) {
6611
- return !!item.length;
6873
+ return item.isPresent();
6612
6874
  };
6613
6875
  var applyInput = function (item) {
6614
6876
  _this.fileInputs[_this.resolveSubmitIdentifier(item.getAsElem(0).value)] = true;
@@ -6618,25 +6880,11 @@ var XhrFormData = /** @class */ (function (_super) {
6618
6880
  .each(applyInput);
6619
6881
  };
6620
6882
  XhrFormData.prototype.getFileInputs = function (rootElment) {
6621
- var _this = this;
6622
- var resolveFileInputs = function (item) {
6623
- var _a;
6624
- if (item.length == 1) {
6625
- if (item.tagName.get("booga").value.toLowerCase() == "input" &&
6626
- (((_a = item.attr("type")) === null || _a === void 0 ? void 0 : _a.value) || '').toLowerCase() == "file") {
6627
- return item;
6628
- }
6629
- return rootElment.querySelectorAllDeep("input[type='file']");
6630
- }
6631
- return _this.getFileInputs(item);
6632
- };
6633
- var itemExists = function (item) {
6634
- return !!(item === null || item === void 0 ? void 0 : item.length);
6635
- };
6636
- var ret = rootElment.lazyStream
6637
- .map(resolveFileInputs)
6638
- .filter(itemExists)
6639
- .collect(new mona_dish_1.DomQueryCollector());
6883
+ var rootFileInputs = rootElment
6884
+ .filter(function (elem) { return elem.matchesSelector("input[type='file']"); });
6885
+ var childFileInputs = rootElment
6886
+ .querySelectorAll("input[type='file']");
6887
+ var ret = rootFileInputs.concat(childFileInputs);
6640
6888
  return ret;
6641
6889
  };
6642
6890
  XhrFormData.prototype.handleFormSource = function () {
@@ -6669,15 +6917,25 @@ var XhrFormData = /** @class */ (function (_super) {
6669
6917
  * @param encoded
6670
6918
  */
6671
6919
  XhrFormData.prototype.assignEncodedString = function (encoded) {
6920
+ //TODO reevaluate this method
6672
6921
  //this code filters out empty strings as key value pairs
6673
- var keyValueEntries = decodeURIComponent(encoded).split(/&/gi).filter(function (item) { return !!(item || '').replace(/\s+/g, ''); });
6922
+ var keyValueEntries = decodeURIComponent(encoded).split(/&/gi)
6923
+ .filter(function (item) { return !!(item || '')
6924
+ .replace(/\s+/g, ''); });
6674
6925
  this.assignString(keyValueEntries);
6675
6926
  };
6676
6927
  XhrFormData.prototype.assignString = function (keyValueEntries) {
6677
6928
  var toMerge = new mona_dish_1.Config({});
6678
- mona_dish_2.Stream.of.apply(mona_dish_2.Stream, keyValueEntries).map(function (line) { return line.split(/=(.*)/gi); })
6929
+ function splitToKeyVal(line) {
6930
+ return line.split(/=(.*)/gi);
6931
+ }
6932
+ function fixKeyWithoutVal(keyVal) {
6933
+ var _a, _b;
6934
+ return keyVal.length < 3 ? [(_a = keyVal === null || keyVal === void 0 ? void 0 : keyVal[0]) !== null && _a !== void 0 ? _a : [], (_b = keyVal === null || keyVal === void 0 ? void 0 : keyVal[1]) !== null && _b !== void 0 ? _b : []] : keyVal;
6935
+ }
6936
+ mona_dish_2.Stream.of.apply(mona_dish_2.Stream, keyValueEntries).map(function (line) { return splitToKeyVal(line); })
6679
6937
  //special case of having keys without values
6680
- .map(function (keyVal) { var _a, _b; return keyVal.length < 3 ? [(_a = keyVal === null || keyVal === void 0 ? void 0 : keyVal[0]) !== null && _a !== void 0 ? _a : [], (_b = keyVal === null || keyVal === void 0 ? void 0 : keyVal[1]) !== null && _b !== void 0 ? _b : []] : keyVal; })
6938
+ .map(function (keyVal) { return fixKeyWithoutVal(keyVal); })
6681
6939
  .each(function (keyVal) {
6682
6940
  var _a, _b;
6683
6941
  toMerge.append(keyVal[0]).value = (_b = (_a = keyVal === null || keyVal === void 0 ? void 0 : keyVal.splice(1)) === null || _a === void 0 ? void 0 : _a.join("")) !== null && _b !== void 0 ? _b : "";