@rainbow-o23/n1 1.0.48 → 1.0.50
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/README.md +44 -6
- package/index.cjs +641 -78
- package/index.d.ts +1 -0
- package/index.js +598 -54
- package/lib/pipeline/index.d.ts +2 -1
- package/lib/pipeline/step-helpers-utils.d.ts +28 -3
- package/lib/pipeline/step-helpers-value-operator.d.ts +34 -0
- package/lib/pipeline/step-helpers.d.ts +9 -23
- package/lib/pipeline/types.d.ts +1 -0
- package/lib/pipeline/value-operators/action-types.d.ts +18 -0
- package/lib/pipeline/value-operators/index.d.ts +8 -0
- package/lib/pipeline/value-operators/test-any-actions.d.ts +10 -0
- package/lib/pipeline/value-operators/test-decimal-actions.d.ts +25 -0
- package/lib/pipeline/value-operators/test-string-actions.d.ts +2 -0
- package/lib/pipeline/value-operators/testers.d.ts +36 -0
- package/lib/pipeline/value-operators/transform-decimal-actions.d.ts +21 -0
- package/lib/pipeline/value-operators/transform-string-actions.d.ts +10 -0
- package/lib/pipeline/value-operators/transformers.d.ts +31 -0
- package/package.json +25 -3
- package/rollup.config.base.js +1 -2
- package/src/index.ts +3 -0
- package/src/lib/pipeline/index.ts +2 -1
- package/src/lib/pipeline/step-helpers-utils.ts +105 -29
- package/src/lib/pipeline/step-helpers-value-operator.ts +307 -0
- package/src/lib/pipeline/step-helpers.ts +24 -50
- package/src/lib/pipeline/types.ts +7 -0
- package/src/lib/pipeline/value-operators/action-types.ts +8 -0
- package/src/lib/pipeline/value-operators/index.ts +10 -0
- package/src/lib/pipeline/value-operators/test-any-actions.ts +58 -0
- package/src/lib/pipeline/value-operators/test-decimal-actions.ts +85 -0
- package/src/lib/pipeline/value-operators/test-string-actions.ts +15 -0
- package/src/lib/pipeline/value-operators/testers.ts +59 -0
- package/src/lib/pipeline/value-operators/transform-decimal-actions.ts +88 -0
- package/src/lib/pipeline/value-operators/transform-string-actions.ts +49 -0
- package/src/lib/pipeline/value-operators/transformers.ts +34 -0
- package/test/value-test.test.ts +55 -0
- /package/lib/{pipeline/envs.d.ts → envs.d.ts} +0 -0
- /package/src/lib/{pipeline/envs.ts → envs.ts} +0 -0
package/index.cjs
CHANGED
|
@@ -11,26 +11,18 @@ var RelativeTime = require('dayjs/plugin/relativeTime.js');
|
|
|
11
11
|
var UTC = require('dayjs/plugin/utc.js');
|
|
12
12
|
var WeekOfYear = require('dayjs/plugin/weekOfYear.js');
|
|
13
13
|
var nanoid = require('nanoid');
|
|
14
|
-
var
|
|
14
|
+
var Decimal = require('decimal.js');
|
|
15
|
+
var mathjs$1 = require('mathjs');
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
n.default = e;
|
|
30
|
-
return Object.freeze(n);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
var math__namespace = /*#__PURE__*/_interopNamespaceDefault(math);
|
|
17
|
+
dayjs.extend(WeekOfYear);
|
|
18
|
+
dayjs.extend(QuarterOfYear);
|
|
19
|
+
dayjs.extend(Duration);
|
|
20
|
+
dayjs.extend(IsToday);
|
|
21
|
+
dayjs.extend(RelativeTime);
|
|
22
|
+
dayjs.extend(ArraySupport);
|
|
23
|
+
dayjs.extend(ObjectSupport);
|
|
24
|
+
dayjs.extend(CustomParseFormat);
|
|
25
|
+
dayjs.extend(UTC);
|
|
34
26
|
|
|
35
27
|
const ERR_PIPELINE_NOT_FOUND = 'O01-00001';
|
|
36
28
|
const ERR_TRIM_NON_STRING = 'O01-00002';
|
|
@@ -410,28 +402,563 @@ const createConfig = (logger) => {
|
|
|
410
402
|
return new Config(logger ?? createLogger());
|
|
411
403
|
};
|
|
412
404
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
405
|
+
/******************************************************************************
|
|
406
|
+
Copyright (c) Microsoft Corporation.
|
|
407
|
+
|
|
408
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
409
|
+
purpose with or without fee is hereby granted.
|
|
410
|
+
|
|
411
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
412
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
413
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
414
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
415
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
416
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
417
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
418
|
+
***************************************************************************** */
|
|
419
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
function __decorate(decorators, target, key, desc) {
|
|
423
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
424
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
425
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
426
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
430
|
+
var e = new Error(message);
|
|
431
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
const StaticImplements = () => {
|
|
435
|
+
return (_constructor) => {
|
|
436
|
+
};
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
const OBJECT_PROTOTYPE = Object.prototype;
|
|
440
|
+
|
|
441
|
+
const isLength = (value) => {
|
|
442
|
+
return typeof value === 'number' && value > -1 && value % 1 === 0 && value <= Number.MAX_SAFE_INTEGER;
|
|
443
|
+
};
|
|
444
|
+
const isArrayLike = (value) => {
|
|
445
|
+
return value != null && typeof value !== 'function' && isLength(value.length);
|
|
446
|
+
};
|
|
447
|
+
const isPrototype = (value) => {
|
|
448
|
+
const Ctor = value && value.constructor;
|
|
449
|
+
const proto = (typeof Ctor === 'function' && Ctor.prototype) || OBJECT_PROTOTYPE;
|
|
450
|
+
return value === proto;
|
|
451
|
+
};
|
|
452
|
+
const isNull = (value) => {
|
|
453
|
+
return value == null
|
|
454
|
+
? { test: true, value: value }
|
|
455
|
+
: { test: false, value };
|
|
456
|
+
};
|
|
457
|
+
const isNotNull = (value) => ({ test: !isNull(value).test, value });
|
|
458
|
+
const isEmpty = (value) => {
|
|
459
|
+
if (value == null) {
|
|
460
|
+
return { test: true, value: value };
|
|
461
|
+
}
|
|
462
|
+
let length = null;
|
|
463
|
+
if (isArrayLike(value) && (Array.isArray(value) || typeof value === 'string')) {
|
|
464
|
+
length = value.length;
|
|
465
|
+
}
|
|
466
|
+
else if (value instanceof Map) {
|
|
467
|
+
length = value.size;
|
|
468
|
+
}
|
|
469
|
+
else if (value instanceof Set) {
|
|
470
|
+
length = value.size;
|
|
471
|
+
}
|
|
472
|
+
else if (isPrototype(value)) {
|
|
473
|
+
length = Object.keys(value).length;
|
|
474
|
+
}
|
|
475
|
+
return { test: length === 0, value };
|
|
476
|
+
};
|
|
477
|
+
const isNotEmpty = (value) => ({ test: !isEmpty(value).test, value });
|
|
478
|
+
const isBlank = (value) => {
|
|
479
|
+
switch (true) {
|
|
480
|
+
case (value == null):
|
|
481
|
+
return { test: true, value: value };
|
|
482
|
+
case (typeof value === 'string' && value.trim().length === 0):
|
|
483
|
+
return { test: true, value: value };
|
|
484
|
+
default:
|
|
485
|
+
return { test: false, value };
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
const isNotBlank = (value) => ({ test: !isBlank(value).test, value });
|
|
489
|
+
|
|
490
|
+
const regexp = (regexp) => {
|
|
491
|
+
return (value) => {
|
|
492
|
+
if (value == null) {
|
|
493
|
+
return { test: false, value };
|
|
494
|
+
}
|
|
495
|
+
const type = typeof value;
|
|
496
|
+
if (['string', 'number', 'bigint'].includes(type)) {
|
|
497
|
+
return { test: regexp.test(value), value };
|
|
498
|
+
}
|
|
499
|
+
return { test: false, value };
|
|
500
|
+
};
|
|
501
|
+
};
|
|
422
502
|
|
|
503
|
+
exports.Rounding = void 0;
|
|
504
|
+
(function (Rounding) {
|
|
505
|
+
Rounding["ROUND_UP"] = "up";
|
|
506
|
+
Rounding["ROUND_DOWN"] = "down";
|
|
507
|
+
Rounding["ROUND_CEIL"] = "ceil";
|
|
508
|
+
Rounding["ROUND_FLOOR"] = "floor";
|
|
509
|
+
Rounding["ROUND_HALF_UP"] = "half-up";
|
|
510
|
+
Rounding["ROUND_HALF_DOWN"] = "half-down";
|
|
511
|
+
Rounding["ROUND_HALF_EVEN"] = "half-even";
|
|
512
|
+
Rounding["ROUND_HALF_CEIL"] = "half-ceil";
|
|
513
|
+
Rounding["ROUND_HALF_FLOOR"] = "half-floor";
|
|
514
|
+
})(exports.Rounding || (exports.Rounding = {}));
|
|
515
|
+
const ToDecimalJsRounding = {
|
|
516
|
+
[exports.Rounding.ROUND_UP]: Decimal.ROUND_UP,
|
|
517
|
+
[exports.Rounding.ROUND_DOWN]: Decimal.ROUND_DOWN,
|
|
518
|
+
[exports.Rounding.ROUND_CEIL]: Decimal.ROUND_CEIL,
|
|
519
|
+
[exports.Rounding.ROUND_FLOOR]: Decimal.ROUND_FLOOR,
|
|
520
|
+
[exports.Rounding.ROUND_HALF_UP]: Decimal.ROUND_HALF_UP,
|
|
521
|
+
[exports.Rounding.ROUND_HALF_DOWN]: Decimal.ROUND_HALF_DOWN,
|
|
522
|
+
[exports.Rounding.ROUND_HALF_EVEN]: Decimal.ROUND_HALF_EVEN,
|
|
523
|
+
[exports.Rounding.ROUND_HALF_CEIL]: Decimal.ROUND_HALF_CEIL,
|
|
524
|
+
[exports.Rounding.ROUND_HALF_FLOOR]: Decimal.ROUND_HALF_FLOOR
|
|
525
|
+
};
|
|
526
|
+
const toDecimal = (value) => {
|
|
527
|
+
if (value == null) {
|
|
528
|
+
return { test: false, value };
|
|
529
|
+
}
|
|
530
|
+
else if (value instanceof Decimal) {
|
|
531
|
+
return { test: true, value };
|
|
532
|
+
}
|
|
533
|
+
else if (['string', 'number'].includes(typeof value)) {
|
|
534
|
+
try {
|
|
535
|
+
return { test: true, value: new Decimal(value) };
|
|
536
|
+
}
|
|
537
|
+
catch {
|
|
538
|
+
return { test: false, value };
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
return { test: false, value };
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
const toNumber = (value) => {
|
|
546
|
+
const { test, value: parsed } = toDecimal(value);
|
|
547
|
+
if (!test) {
|
|
548
|
+
return { test: false, value };
|
|
549
|
+
}
|
|
550
|
+
return { test: true, value: parsed.toNumber() };
|
|
551
|
+
};
|
|
552
|
+
const toFixed = (fractionDigits, rounding = exports.Rounding.ROUND_HALF_UP) => {
|
|
553
|
+
return (value) => {
|
|
554
|
+
const { test, value: parsed } = toDecimal(value);
|
|
555
|
+
if (!test) {
|
|
556
|
+
return { test: false, value };
|
|
557
|
+
}
|
|
558
|
+
return { test: true, value: parsed.toFixed(fractionDigits, ToDecimalJsRounding[rounding]) };
|
|
559
|
+
};
|
|
560
|
+
};
|
|
561
|
+
const baseRound = (rounding = exports.Rounding.ROUND_HALF_UP) => {
|
|
562
|
+
return (fractionDigits) => {
|
|
563
|
+
return (value) => {
|
|
564
|
+
const { test, value: parsed } = toDecimal(value);
|
|
565
|
+
if (!test) {
|
|
566
|
+
return { test: false, value };
|
|
567
|
+
}
|
|
568
|
+
return { test: true, value: parsed.toDecimalPlaces(fractionDigits, ToDecimalJsRounding[rounding]) };
|
|
569
|
+
};
|
|
570
|
+
};
|
|
571
|
+
};
|
|
572
|
+
const roundUp = baseRound(exports.Rounding.ROUND_HALF_UP);
|
|
573
|
+
const roundDown = baseRound(exports.Rounding.ROUND_HALF_DOWN);
|
|
574
|
+
const floor = baseRound(exports.Rounding.ROUND_FLOOR);
|
|
575
|
+
const ceil = baseRound(exports.Rounding.ROUND_CEIL);
|
|
576
|
+
const roundBy = (fractionDigits, rounding = exports.Rounding.ROUND_HALF_UP) => {
|
|
577
|
+
return baseRound(rounding)(fractionDigits);
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
const isDecimal = (value) => {
|
|
581
|
+
const { test, value: decimal } = toDecimal(value);
|
|
582
|
+
return { test, value: test ? decimal : value };
|
|
583
|
+
};
|
|
584
|
+
const isInteger = (value) => {
|
|
585
|
+
const { test, value: decimal } = toDecimal(value);
|
|
586
|
+
return (test && decimal.isInteger()) ? { test: true, value: decimal } : { test: false, value };
|
|
587
|
+
};
|
|
588
|
+
const isInRange = (options) => {
|
|
589
|
+
const { min, max, interval = 'closed' } = options;
|
|
590
|
+
return (value) => {
|
|
591
|
+
const { test, value: decimal } = toDecimal(value);
|
|
592
|
+
if (!test) {
|
|
593
|
+
return { test: false, value };
|
|
594
|
+
}
|
|
595
|
+
let pass = false;
|
|
596
|
+
switch (interval) {
|
|
597
|
+
case 'open':
|
|
598
|
+
case 'o':
|
|
599
|
+
pass = (min == null || decimal.gt(min)) && (max == null || decimal.lt(max));
|
|
600
|
+
break;
|
|
601
|
+
case 'left-open':
|
|
602
|
+
case 'lo':
|
|
603
|
+
pass = (min == null || decimal.gt(min)) && (max == null || decimal.lte(max));
|
|
604
|
+
break;
|
|
605
|
+
case 'right-open':
|
|
606
|
+
case 'ro':
|
|
607
|
+
pass = (min == null || decimal.gte(min)) && (max == null || decimal.lt(max));
|
|
608
|
+
break;
|
|
609
|
+
case 'closed':
|
|
610
|
+
case 'c':
|
|
611
|
+
default:
|
|
612
|
+
pass = (min == null || decimal.gte(min)) && (max == null || decimal.lte(max));
|
|
613
|
+
break;
|
|
614
|
+
}
|
|
615
|
+
return pass ? { test: true, value: decimal } : { test: false, value };
|
|
616
|
+
};
|
|
617
|
+
};
|
|
618
|
+
const isPositive = isInRange({ min: 0, interval: 'left-open' });
|
|
619
|
+
const isNotPositive = isInRange({ max: 0 });
|
|
620
|
+
const isNegative = isInRange({ max: 0, interval: 'right-open' });
|
|
621
|
+
const isNotNegative = isInRange({ min: 0 });
|
|
622
|
+
const isZero = (value) => {
|
|
623
|
+
const { test, value: decimal } = toDecimal(value);
|
|
624
|
+
return (test && decimal.isZero()) ? { test: true, value: decimal } : { test: false, value };
|
|
625
|
+
};
|
|
626
|
+
const isNotZero = (value) => {
|
|
627
|
+
const { test, value: decimal } = toDecimal(value);
|
|
628
|
+
return (test && !decimal.isZero()) ? { test: true, value: decimal } : { test: false, value };
|
|
629
|
+
};
|
|
630
|
+
const isGreaterThan = (compare) => {
|
|
631
|
+
return isInRange({ min: compare, interval: 'left-open' });
|
|
632
|
+
};
|
|
633
|
+
const isGreaterThanOrEqual = (compare) => {
|
|
634
|
+
return isInRange({ min: compare });
|
|
635
|
+
};
|
|
636
|
+
const isLessThan = (compare) => {
|
|
637
|
+
return isInRange({ max: compare, interval: 'right-open' });
|
|
638
|
+
};
|
|
639
|
+
const isLessThanOrEqual = (compare) => {
|
|
640
|
+
return isInRange({ max: compare });
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
const testers = {
|
|
644
|
+
isNull: { type: 'func', func: isNull },
|
|
645
|
+
isNotNull: { type: 'func', func: isNotNull },
|
|
646
|
+
isEmpty: { type: 'func', func: isEmpty },
|
|
647
|
+
isNotEmpty: { type: 'func', func: isNotEmpty },
|
|
648
|
+
isBlank: { type: 'func', func: isBlank },
|
|
649
|
+
isNotBlank: { type: 'func', func: isNotBlank },
|
|
650
|
+
regexp: { type: 'param', func: regexp },
|
|
651
|
+
regex: { type: 'param', func: regexp },
|
|
652
|
+
matches: { type: 'param', func: regexp },
|
|
653
|
+
isNumber: { type: 'func', func: isDecimal },
|
|
654
|
+
isDecimal: { type: 'func', func: isDecimal },
|
|
655
|
+
isInteger: { type: 'func', func: isInteger },
|
|
656
|
+
isInt: { type: 'func', func: isInteger },
|
|
657
|
+
isPositive: { type: 'func', func: isPositive },
|
|
658
|
+
isNotPositive: { type: 'func', func: isNotPositive },
|
|
659
|
+
isNegative: { type: 'func', func: isNegative },
|
|
660
|
+
isNotNegative: { type: 'func', func: isNotNegative },
|
|
661
|
+
isZero: { type: 'func', func: isZero },
|
|
662
|
+
isNotZero: { type: 'func', func: isNotZero },
|
|
663
|
+
isGreaterThan: { type: 'param', func: isGreaterThan },
|
|
664
|
+
gt: { type: 'param', func: isGreaterThan },
|
|
665
|
+
isGreaterThanOrEqual: {
|
|
666
|
+
type: 'param', func: isGreaterThanOrEqual
|
|
667
|
+
},
|
|
668
|
+
gte: { type: 'param', func: isGreaterThanOrEqual },
|
|
669
|
+
isLessThan: { type: 'param', func: isLessThan },
|
|
670
|
+
lt: { type: 'param', func: isLessThan },
|
|
671
|
+
isLessThanOrEqual: {
|
|
672
|
+
type: 'param', func: isLessThanOrEqual
|
|
673
|
+
},
|
|
674
|
+
lte: { type: 'param', func: isLessThanOrEqual },
|
|
675
|
+
isInRange: { type: 'param', func: isInRange },
|
|
676
|
+
within: { type: 'param', func: isInRange }
|
|
677
|
+
};
|
|
678
|
+
const AllTesters = testers;
|
|
679
|
+
|
|
680
|
+
const trim = (value) => {
|
|
681
|
+
if (value == null) {
|
|
682
|
+
return { test: true, value };
|
|
683
|
+
}
|
|
684
|
+
else if (typeof value === 'string') {
|
|
685
|
+
return { test: true, value: value.trim() };
|
|
686
|
+
}
|
|
687
|
+
else {
|
|
688
|
+
return { test: true, value };
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
const pad = (options) => {
|
|
692
|
+
const { length, char = ' ', direction = 'right' } = options;
|
|
693
|
+
return (value) => {
|
|
694
|
+
if (value == null) {
|
|
695
|
+
return { test: false, value };
|
|
696
|
+
}
|
|
697
|
+
const type = typeof value;
|
|
698
|
+
if (['string', 'number', 'bigint', 'boolean'].includes(type)) {
|
|
699
|
+
const stringified = `${value}`;
|
|
700
|
+
const len = stringified.length;
|
|
701
|
+
if (len >= length) {
|
|
702
|
+
return { test: true, value: stringified };
|
|
703
|
+
}
|
|
704
|
+
return {
|
|
705
|
+
test: true,
|
|
706
|
+
value: direction === 'left' ? stringified.padStart(length, char) : stringified.padEnd(length, char)
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
else {
|
|
710
|
+
return { test: false, value };
|
|
711
|
+
}
|
|
712
|
+
};
|
|
713
|
+
};
|
|
714
|
+
const padStart = (options) => pad({ ...options, direction: 'left' });
|
|
715
|
+
const padEnd = (options) => pad({ ...options, direction: 'right' });
|
|
716
|
+
|
|
717
|
+
const transformers = {
|
|
718
|
+
trim: { type: 'func', func: trim },
|
|
719
|
+
pad: { type: 'param', func: pad },
|
|
720
|
+
padStart: { type: 'param', func: padStart },
|
|
721
|
+
padLeft: { type: 'param', func: padStart },
|
|
722
|
+
lpad: { type: 'param', func: padStart },
|
|
723
|
+
padEnd: { type: 'param', func: padEnd },
|
|
724
|
+
padRight: { type: 'param', func: padEnd },
|
|
725
|
+
rpad: { type: 'param', func: padEnd },
|
|
726
|
+
toDecimal: { type: 'func', func: toDecimal },
|
|
727
|
+
toNumber: { type: 'func', func: toNumber },
|
|
728
|
+
toFixed0: { type: 'func', func: toFixed(0) },
|
|
729
|
+
toFixed1: { type: 'func', func: toFixed(1) },
|
|
730
|
+
toFixed2: { type: 'func', func: toFixed(2) },
|
|
731
|
+
toFixed3: { type: 'func', func: toFixed(3) },
|
|
732
|
+
toFixed4: { type: 'func', func: toFixed(4) },
|
|
733
|
+
toFixed5: { type: 'func', func: toFixed(5) },
|
|
734
|
+
toFixed6: { type: 'func', func: toFixed(6) },
|
|
735
|
+
toFixed: { type: 'param', func: toFixed },
|
|
736
|
+
round: { type: 'param', func: roundUp },
|
|
737
|
+
roundUp: { type: 'param', func: roundUp },
|
|
738
|
+
roundDown: { type: 'param', func: roundDown },
|
|
739
|
+
floor: { type: 'param', func: floor },
|
|
740
|
+
ceil: { type: 'param', func: ceil },
|
|
741
|
+
roundBy: { type: 'param', func: roundBy }
|
|
742
|
+
};
|
|
743
|
+
const AllTransformers = transformers;
|
|
744
|
+
|
|
745
|
+
var ValueOperatorBootstrap_1;
|
|
746
|
+
const applyOperator = (operator, base) => {
|
|
747
|
+
if (base.$allowNoParamFuncCall) {
|
|
748
|
+
base.$allowNoParamFuncCall = false;
|
|
749
|
+
return operator;
|
|
750
|
+
}
|
|
751
|
+
else {
|
|
752
|
+
throw new Error(`Function call is not allowed from: ${operator}.`);
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
const NOT_FOUND = Symbol('not found');
|
|
756
|
+
const findValueAction = (actions) => {
|
|
757
|
+
return (operator, base, prop) => {
|
|
758
|
+
const tester = actions[prop];
|
|
759
|
+
if (tester == null) {
|
|
760
|
+
return NOT_FOUND;
|
|
761
|
+
}
|
|
762
|
+
base.$allowUseDefault = true;
|
|
763
|
+
if (base.$actions == null) {
|
|
764
|
+
base.$actions = [];
|
|
765
|
+
}
|
|
766
|
+
if (tester.type === 'func') {
|
|
767
|
+
base.$actions.push(tester.func);
|
|
768
|
+
base.$allowNoParamFuncCall = true;
|
|
769
|
+
return operator;
|
|
770
|
+
}
|
|
771
|
+
else if (tester.type === 'param') {
|
|
772
|
+
return (...args) => {
|
|
773
|
+
base.$actions.push(tester.func(...args));
|
|
774
|
+
return operator;
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
else {
|
|
778
|
+
throw new Error(`Unknown tester type: ${tester}.`);
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
};
|
|
782
|
+
const findTester = findValueAction(AllTesters);
|
|
783
|
+
const findTransformer = findValueAction(AllTransformers);
|
|
784
|
+
const findUseDefault = (operator, base, prop) => {
|
|
785
|
+
if (!base.$allowUseDefault || !['orUseDefault', 'useDefault', 'withDefault', 'orElse', 'else'].includes(prop)) {
|
|
786
|
+
return NOT_FOUND;
|
|
787
|
+
}
|
|
788
|
+
if ((base.$actions == null || base.$actions.length === 0)) {
|
|
789
|
+
return (void 0);
|
|
790
|
+
}
|
|
791
|
+
base.$allowMoreAction = false;
|
|
792
|
+
base.$allowUseDefault = false;
|
|
793
|
+
return (defaultValue) => {
|
|
794
|
+
base.$defaultUsed = true;
|
|
795
|
+
base.$defaultValue = defaultValue;
|
|
796
|
+
return operator;
|
|
797
|
+
};
|
|
798
|
+
};
|
|
799
|
+
const createValueRetrieveFunc = (base) => {
|
|
800
|
+
return () => {
|
|
801
|
+
const tested = { test: true, value: base.$value };
|
|
802
|
+
for (const action of (base.$actions ?? [])) {
|
|
803
|
+
const result = action(tested.value);
|
|
804
|
+
if (!result.test) {
|
|
805
|
+
tested.test = false;
|
|
806
|
+
tested.value = base.$value;
|
|
807
|
+
break;
|
|
808
|
+
}
|
|
809
|
+
else {
|
|
810
|
+
tested.value = result.value;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
if (tested.test) ;
|
|
814
|
+
else if (base.$defaultUsed) {
|
|
815
|
+
tested.test = true;
|
|
816
|
+
tested.value = base.$defaultValue;
|
|
817
|
+
}
|
|
818
|
+
else {
|
|
819
|
+
tested.value = base.$value;
|
|
820
|
+
}
|
|
821
|
+
return tested;
|
|
822
|
+
};
|
|
823
|
+
};
|
|
824
|
+
const findValue = (_operator, base, prop) => {
|
|
825
|
+
if (prop !== 'value') {
|
|
826
|
+
return NOT_FOUND;
|
|
827
|
+
}
|
|
828
|
+
if ((base.$actions == null || base.$actions.length === 0)) {
|
|
829
|
+
return (void 0);
|
|
830
|
+
}
|
|
831
|
+
return () => createValueRetrieveFunc(base)().value;
|
|
832
|
+
};
|
|
833
|
+
const findSuccessOrFailureCallback = (_operator, base, prop) => {
|
|
834
|
+
if (prop !== 'success' && prop !== 'failure') {
|
|
835
|
+
return NOT_FOUND;
|
|
836
|
+
}
|
|
837
|
+
if ((base.$actions == null || base.$actions.length === 0)) {
|
|
838
|
+
return (void 0);
|
|
839
|
+
}
|
|
840
|
+
switch (prop) {
|
|
841
|
+
case 'success':
|
|
842
|
+
return (callback) => {
|
|
843
|
+
const tested = createValueRetrieveFunc(base)();
|
|
844
|
+
if (tested.test) {
|
|
845
|
+
callback(tested.value);
|
|
846
|
+
}
|
|
847
|
+
return {
|
|
848
|
+
failure: (callback) => {
|
|
849
|
+
if (!tested.test) {
|
|
850
|
+
callback(tested.value);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
};
|
|
854
|
+
};
|
|
855
|
+
case 'failure':
|
|
856
|
+
return (callback) => {
|
|
857
|
+
const tested = createValueRetrieveFunc(base)();
|
|
858
|
+
if (!tested.test) {
|
|
859
|
+
callback(tested.value);
|
|
860
|
+
}
|
|
861
|
+
return {
|
|
862
|
+
success: (callback) => {
|
|
863
|
+
if (tested.test) {
|
|
864
|
+
callback(tested.value);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
};
|
|
868
|
+
};
|
|
869
|
+
default:
|
|
870
|
+
throw new Error(`Unknown callback type: ${prop}.`);
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
const findOK = (operator, base, prop) => {
|
|
874
|
+
if (prop !== 'ok') {
|
|
875
|
+
return NOT_FOUND;
|
|
876
|
+
}
|
|
877
|
+
if ((base.$actions == null || base.$actions.length === 0)) {
|
|
878
|
+
return (void 0);
|
|
879
|
+
}
|
|
880
|
+
return () => createValueRetrieveFunc(base)().test;
|
|
881
|
+
};
|
|
882
|
+
const findPromise = (_operator, base, prop) => {
|
|
883
|
+
if (prop !== 'promise') {
|
|
884
|
+
return NOT_FOUND;
|
|
885
|
+
}
|
|
886
|
+
if ((base.$actions == null || base.$actions.length === 0)) {
|
|
887
|
+
return (void 0);
|
|
888
|
+
}
|
|
889
|
+
return async () => {
|
|
890
|
+
const tested = createValueRetrieveFunc(base)();
|
|
891
|
+
if (tested.test) {
|
|
892
|
+
return Promise.resolve(tested.value);
|
|
893
|
+
}
|
|
894
|
+
else {
|
|
895
|
+
return Promise.reject(tested.value);
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
};
|
|
899
|
+
const getFromOperator = (operator, base, prop) => {
|
|
900
|
+
base.$allowNoParamFuncCall = false;
|
|
901
|
+
const finds = [
|
|
902
|
+
findTester, findTransformer, findUseDefault,
|
|
903
|
+
findValue, findSuccessOrFailureCallback, findOK, findPromise
|
|
904
|
+
];
|
|
905
|
+
for (const find of finds) {
|
|
906
|
+
const result = find(operator, base, prop);
|
|
907
|
+
if (result !== NOT_FOUND) {
|
|
908
|
+
return result;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
return (void 0);
|
|
912
|
+
};
|
|
913
|
+
const createOperator = (base) => {
|
|
914
|
+
const operatorBase = () => {
|
|
915
|
+
};
|
|
916
|
+
operatorBase.$base = base;
|
|
917
|
+
const operator = new Proxy(operatorBase, {
|
|
918
|
+
apply(base, _thisArg, _argArray) {
|
|
919
|
+
return applyOperator(operator, base.$base);
|
|
920
|
+
},
|
|
921
|
+
get(base, p, _receiver) {
|
|
922
|
+
return getFromOperator(operator, base.$base, p);
|
|
923
|
+
}
|
|
924
|
+
});
|
|
925
|
+
return operator;
|
|
926
|
+
};
|
|
927
|
+
let ValueOperatorBootstrap = ValueOperatorBootstrap_1 = class ValueOperatorBootstrap {
|
|
928
|
+
constructor() {
|
|
929
|
+
}
|
|
930
|
+
static of(value) {
|
|
931
|
+
return createOperator({
|
|
932
|
+
$value: value,
|
|
933
|
+
$allowMoreAction: true, $allowUseDefault: false, $defaultUsed: false,
|
|
934
|
+
$allowNoParamFuncCall: false
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
static from(value) {
|
|
938
|
+
return ValueOperatorBootstrap_1.of(value);
|
|
939
|
+
}
|
|
940
|
+
static with(value) {
|
|
941
|
+
return ValueOperatorBootstrap_1.of(value);
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
ValueOperatorBootstrap = ValueOperatorBootstrap_1 = __decorate([
|
|
945
|
+
StaticImplements()
|
|
946
|
+
], ValueOperatorBootstrap);
|
|
947
|
+
const ValueOperator = ValueOperatorBootstrap;
|
|
948
|
+
|
|
949
|
+
var StepHelpersUtils_1;
|
|
423
950
|
const PIPELINE_STEP_FILE_SYMBOL = Symbol();
|
|
424
951
|
const PIPELINE_STEP_RETURN_NULL = Symbol();
|
|
425
|
-
class StepHelpersUtils {
|
|
952
|
+
exports.StepHelpersUtils = class StepHelpersUtils {
|
|
953
|
+
static { StepHelpersUtils_1 = this; }
|
|
426
954
|
static asciiNanoId = nanoid.customAlphabet('1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_', 32);
|
|
427
|
-
static OBJECT_PROTOTYPE = Object.prototype;
|
|
428
955
|
constructor() {
|
|
429
956
|
}
|
|
430
957
|
static $nano(size) {
|
|
431
958
|
return nanoid.nanoid(size);
|
|
432
959
|
}
|
|
433
960
|
static $ascii(size) {
|
|
434
|
-
return
|
|
961
|
+
return StepHelpersUtils_1.asciiNanoId(size);
|
|
435
962
|
}
|
|
436
963
|
static createCatchableError = (options) => {
|
|
437
964
|
throw new CatchableError(options.code, options.reason);
|
|
@@ -452,14 +979,14 @@ class StepHelpersUtils {
|
|
|
452
979
|
return e != null && e instanceof UncatchableError;
|
|
453
980
|
};
|
|
454
981
|
static $errors = {
|
|
455
|
-
catchable:
|
|
456
|
-
isCatchable:
|
|
457
|
-
exposed:
|
|
458
|
-
isExposed:
|
|
459
|
-
uncatchable:
|
|
460
|
-
isUncatchable:
|
|
982
|
+
catchable: StepHelpersUtils_1.createCatchableError,
|
|
983
|
+
isCatchable: StepHelpersUtils_1.isCatchableError,
|
|
984
|
+
exposed: StepHelpersUtils_1.createExposedUncatchableError,
|
|
985
|
+
isExposed: StepHelpersUtils_1.isExposedUncatchableError,
|
|
986
|
+
uncatchable: StepHelpersUtils_1.createUncatchableError,
|
|
987
|
+
isUncatchable: StepHelpersUtils_1.isUncatchableError
|
|
461
988
|
};
|
|
462
|
-
static
|
|
989
|
+
static $file(options) {
|
|
463
990
|
return {
|
|
464
991
|
$file: PIPELINE_STEP_FILE_SYMBOL,
|
|
465
992
|
name: options.name, type: options.type,
|
|
@@ -471,47 +998,26 @@ class StepHelpersUtils {
|
|
|
471
998
|
}
|
|
472
999
|
static isPrototype(value) {
|
|
473
1000
|
const Ctor = value && value.constructor;
|
|
474
|
-
const proto = (typeof Ctor === 'function' && Ctor.prototype) ||
|
|
1001
|
+
const proto = (typeof Ctor === 'function' && Ctor.prototype) || OBJECT_PROTOTYPE;
|
|
475
1002
|
return value === proto;
|
|
476
1003
|
}
|
|
477
1004
|
static isLength(value) {
|
|
478
|
-
return
|
|
1005
|
+
return isLength(value);
|
|
479
1006
|
}
|
|
480
1007
|
static isArrayLike(value) {
|
|
481
|
-
return
|
|
1008
|
+
return isArrayLike(value);
|
|
482
1009
|
}
|
|
483
1010
|
static isEmpty(value) {
|
|
484
|
-
|
|
485
|
-
return true;
|
|
486
|
-
}
|
|
487
|
-
if (StepHelpersUtils.isArrayLike(value) && (Array.isArray(value) || typeof value === 'string')) {
|
|
488
|
-
return value.length === 0;
|
|
489
|
-
}
|
|
490
|
-
else if (value instanceof Map) {
|
|
491
|
-
return value.size === 0;
|
|
492
|
-
}
|
|
493
|
-
else if (value instanceof Set) {
|
|
494
|
-
return value.size === 0;
|
|
495
|
-
}
|
|
496
|
-
else if (StepHelpersUtils.isPrototype(value)) {
|
|
497
|
-
return Object.keys(value).length === 0;
|
|
498
|
-
}
|
|
499
|
-
return false;
|
|
1011
|
+
return isEmpty(value).test;
|
|
500
1012
|
}
|
|
501
1013
|
static isNotEmpty(value) {
|
|
502
|
-
return
|
|
1014
|
+
return isNotEmpty(value).test;
|
|
503
1015
|
}
|
|
504
1016
|
static isBlank(value) {
|
|
505
|
-
|
|
506
|
-
return true;
|
|
507
|
-
}
|
|
508
|
-
if (typeof value !== 'string') {
|
|
509
|
-
return false;
|
|
510
|
-
}
|
|
511
|
-
return value.trim().length === 0;
|
|
1017
|
+
return isBlank(value).test;
|
|
512
1018
|
}
|
|
513
1019
|
static isNotBlank(value) {
|
|
514
|
-
return
|
|
1020
|
+
return isNotBlank(value).test;
|
|
515
1021
|
}
|
|
516
1022
|
static trim(value) {
|
|
517
1023
|
if (value == null) {
|
|
@@ -522,7 +1028,17 @@ class StepHelpersUtils {
|
|
|
522
1028
|
}
|
|
523
1029
|
throw new UncatchableError(ERR_TRIM_NON_STRING, `Cannot apply trim to non-string object[type=${typeof value}, value=${value}].`);
|
|
524
1030
|
}
|
|
525
|
-
|
|
1031
|
+
static touch(value) {
|
|
1032
|
+
return ValueOperator.from(value);
|
|
1033
|
+
}
|
|
1034
|
+
static noop() {
|
|
1035
|
+
}
|
|
1036
|
+
static async asyncNoop() {
|
|
1037
|
+
}
|
|
1038
|
+
};
|
|
1039
|
+
exports.StepHelpersUtils = StepHelpersUtils_1 = __decorate([
|
|
1040
|
+
StaticImplements()
|
|
1041
|
+
], exports.StepHelpersUtils);
|
|
526
1042
|
|
|
527
1043
|
class PerformanceExecution {
|
|
528
1044
|
options;
|
|
@@ -636,22 +1152,31 @@ const RegisteredHelpers = { helpers: {} };
|
|
|
636
1152
|
const registerToStepHelpers = (helpers) => {
|
|
637
1153
|
RegisteredHelpers.helpers = helpers ?? {};
|
|
638
1154
|
};
|
|
1155
|
+
const mathjs = mathjs$1.create(mathjs$1.all, { number: 'BigNumber', precision: 32 });
|
|
639
1156
|
const createStepHelpers = (config, logger) => {
|
|
640
|
-
|
|
1157
|
+
const helpers = {
|
|
641
1158
|
...RegisteredHelpers.helpers,
|
|
642
1159
|
$config: config, $logger: logger,
|
|
643
1160
|
$date: new PipelineStepDateHelper(config),
|
|
644
|
-
$math:
|
|
645
|
-
$
|
|
646
|
-
$
|
|
1161
|
+
$math: mathjs,
|
|
1162
|
+
$decimal: (value) => new Decimal(value),
|
|
1163
|
+
$nano: exports.StepHelpersUtils.$nano, $ascii: exports.StepHelpersUtils.$ascii,
|
|
1164
|
+
$error: exports.StepHelpersUtils.createExposedUncatchableError,
|
|
647
1165
|
$errorCodes: ErrorCodes,
|
|
648
|
-
$errors: StepHelpersUtils.$errors,
|
|
649
|
-
$file: StepHelpersUtils
|
|
650
|
-
$clearContextData: StepHelpersUtils.$clearContextData,
|
|
651
|
-
isEmpty: StepHelpersUtils.isEmpty, isNotEmpty: StepHelpersUtils.isNotEmpty,
|
|
652
|
-
isBlank: StepHelpersUtils.isBlank, isNotBlank: StepHelpersUtils.isNotBlank,
|
|
653
|
-
trim: StepHelpersUtils.trim
|
|
1166
|
+
$errors: exports.StepHelpersUtils.$errors,
|
|
1167
|
+
$file: exports.StepHelpersUtils.$file,
|
|
1168
|
+
$clearContextData: exports.StepHelpersUtils.$clearContextData,
|
|
1169
|
+
isEmpty: exports.StepHelpersUtils.isEmpty, isNotEmpty: exports.StepHelpersUtils.isNotEmpty,
|
|
1170
|
+
isBlank: exports.StepHelpersUtils.isBlank, isNotBlank: exports.StepHelpersUtils.isNotBlank,
|
|
1171
|
+
trim: exports.StepHelpersUtils.trim,
|
|
1172
|
+
touch: exports.StepHelpersUtils.touch,
|
|
1173
|
+
noop: exports.StepHelpersUtils.noop, asyncNoop: exports.StepHelpersUtils.asyncNoop
|
|
654
1174
|
};
|
|
1175
|
+
return new Proxy(helpers, {
|
|
1176
|
+
set(_target, _p, _value, _receiver) {
|
|
1177
|
+
return false;
|
|
1178
|
+
}
|
|
1179
|
+
});
|
|
655
1180
|
};
|
|
656
1181
|
|
|
657
1182
|
class AbstractPipelineStep extends AbstractPipelineExecution {
|
|
@@ -792,6 +1317,8 @@ exports.AbstractPipeline = AbstractPipeline;
|
|
|
792
1317
|
exports.AbstractPipelineExecution = AbstractPipelineExecution;
|
|
793
1318
|
exports.AbstractPipelineStep = AbstractPipelineStep;
|
|
794
1319
|
exports.AbstractStaticPipeline = AbstractStaticPipeline;
|
|
1320
|
+
exports.AllTesters = AllTesters;
|
|
1321
|
+
exports.AllTransformers = AllTransformers;
|
|
795
1322
|
exports.CatchableError = CatchableError;
|
|
796
1323
|
exports.Config = Config;
|
|
797
1324
|
exports.ConsoleLogger = ConsoleLogger;
|
|
@@ -806,15 +1333,51 @@ exports.ErrorCodes = ErrorCodes;
|
|
|
806
1333
|
exports.ExposedUncatchableError = ExposedUncatchableError;
|
|
807
1334
|
exports.LoggerPerformanceSaver = LoggerPerformanceSaver;
|
|
808
1335
|
exports.LoggerUtils = LoggerUtils;
|
|
1336
|
+
exports.OBJECT_PROTOTYPE = OBJECT_PROTOTYPE;
|
|
809
1337
|
exports.PIPELINE_STEP_FILE_SYMBOL = PIPELINE_STEP_FILE_SYMBOL;
|
|
810
1338
|
exports.PIPELINE_STEP_RETURN_NULL = PIPELINE_STEP_RETURN_NULL;
|
|
811
1339
|
exports.PerformanceExecution = PerformanceExecution;
|
|
812
1340
|
exports.PipelineRepository = PipelineRepository;
|
|
813
1341
|
exports.PipelineStepDateHelper = PipelineStepDateHelper;
|
|
814
|
-
exports.StepHelpersUtils = StepHelpersUtils;
|
|
815
1342
|
exports.UncatchableError = UncatchableError;
|
|
1343
|
+
exports.ValueOperator = ValueOperator;
|
|
1344
|
+
exports.ceil = ceil;
|
|
816
1345
|
exports.createConfig = createConfig;
|
|
817
1346
|
exports.createLogger = createLogger;
|
|
818
1347
|
exports.createStepHelpers = createStepHelpers;
|
|
1348
|
+
exports.floor = floor;
|
|
1349
|
+
exports.isArrayLike = isArrayLike;
|
|
1350
|
+
exports.isBlank = isBlank;
|
|
1351
|
+
exports.isDecimal = isDecimal;
|
|
1352
|
+
exports.isEmpty = isEmpty;
|
|
1353
|
+
exports.isGreaterThan = isGreaterThan;
|
|
1354
|
+
exports.isGreaterThanOrEqual = isGreaterThanOrEqual;
|
|
1355
|
+
exports.isInRange = isInRange;
|
|
1356
|
+
exports.isInteger = isInteger;
|
|
1357
|
+
exports.isLength = isLength;
|
|
1358
|
+
exports.isLessThan = isLessThan;
|
|
1359
|
+
exports.isLessThanOrEqual = isLessThanOrEqual;
|
|
1360
|
+
exports.isNegative = isNegative;
|
|
1361
|
+
exports.isNotBlank = isNotBlank;
|
|
1362
|
+
exports.isNotEmpty = isNotEmpty;
|
|
1363
|
+
exports.isNotNegative = isNotNegative;
|
|
1364
|
+
exports.isNotNull = isNotNull;
|
|
1365
|
+
exports.isNotPositive = isNotPositive;
|
|
1366
|
+
exports.isNotZero = isNotZero;
|
|
1367
|
+
exports.isNull = isNull;
|
|
1368
|
+
exports.isPositive = isPositive;
|
|
1369
|
+
exports.isPrototype = isPrototype;
|
|
1370
|
+
exports.isZero = isZero;
|
|
1371
|
+
exports.pad = pad;
|
|
1372
|
+
exports.padEnd = padEnd;
|
|
1373
|
+
exports.padStart = padStart;
|
|
1374
|
+
exports.regexp = regexp;
|
|
819
1375
|
exports.registerToStepHelpers = registerToStepHelpers;
|
|
1376
|
+
exports.roundBy = roundBy;
|
|
1377
|
+
exports.roundDown = roundDown;
|
|
1378
|
+
exports.roundUp = roundUp;
|
|
820
1379
|
exports.saveLoggerPerformance = saveLoggerPerformance;
|
|
1380
|
+
exports.toDecimal = toDecimal;
|
|
1381
|
+
exports.toFixed = toFixed;
|
|
1382
|
+
exports.toNumber = toNumber;
|
|
1383
|
+
exports.trim = trim;
|