@rainbow-o23/n1 1.0.50 → 1.0.51
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/index.cjs +10 -579
- package/index.js +9 -539
- package/lib/envs.d.ts +1 -1
- package/lib/pipeline/index.d.ts +0 -2
- package/lib/pipeline/step-helpers-utils.d.ts +1 -1
- package/package.json +2 -1
- package/rollup.config.base.js +4 -1
- package/src/lib/envs.ts +2 -20
- package/src/lib/pipeline/index.ts +0 -2
- package/src/lib/pipeline/step-helpers-utils.ts +7 -11
- package/lib/pipeline/step-helpers-value-operator.d.ts +0 -34
- package/lib/pipeline/value-operators/action-types.d.ts +0 -18
- package/lib/pipeline/value-operators/index.d.ts +0 -8
- package/lib/pipeline/value-operators/test-any-actions.d.ts +0 -10
- package/lib/pipeline/value-operators/test-decimal-actions.d.ts +0 -25
- package/lib/pipeline/value-operators/test-string-actions.d.ts +0 -2
- package/lib/pipeline/value-operators/testers.d.ts +0 -36
- package/lib/pipeline/value-operators/transform-decimal-actions.d.ts +0 -21
- package/lib/pipeline/value-operators/transform-string-actions.d.ts +0 -10
- package/lib/pipeline/value-operators/transformers.d.ts +0 -31
- package/src/lib/pipeline/step-helpers-value-operator.ts +0 -307
- package/src/lib/pipeline/value-operators/action-types.ts +0 -8
- package/src/lib/pipeline/value-operators/index.ts +0 -10
- package/src/lib/pipeline/value-operators/test-any-actions.ts +0 -58
- package/src/lib/pipeline/value-operators/test-decimal-actions.ts +0 -85
- package/src/lib/pipeline/value-operators/test-string-actions.ts +0 -15
- package/src/lib/pipeline/value-operators/testers.ts +0 -59
- package/src/lib/pipeline/value-operators/transform-decimal-actions.ts +0 -88
- package/src/lib/pipeline/value-operators/transform-string-actions.ts +0 -49
- package/src/lib/pipeline/value-operators/transformers.ts +0 -34
package/index.js
CHANGED
|
@@ -1,27 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import ArraySupport from 'dayjs/plugin/arraySupport.js';
|
|
3
|
-
import CustomParseFormat from 'dayjs/plugin/customParseFormat.js';
|
|
4
|
-
import Duration from 'dayjs/plugin/duration.js';
|
|
5
|
-
import IsToday from 'dayjs/plugin/isToday.js';
|
|
6
|
-
import ObjectSupport from 'dayjs/plugin/objectSupport.js';
|
|
7
|
-
import QuarterOfYear from 'dayjs/plugin/quarterOfYear.js';
|
|
8
|
-
import RelativeTime from 'dayjs/plugin/relativeTime.js';
|
|
9
|
-
import UTC from 'dayjs/plugin/utc.js';
|
|
10
|
-
import WeekOfYear from 'dayjs/plugin/weekOfYear.js';
|
|
1
|
+
import { isPrototype, isLength, isArrayLike, ValueOperator } from '@rainbow-n19/n1';
|
|
11
2
|
import { customAlphabet, nanoid } from 'nanoid';
|
|
3
|
+
import dayjs from 'dayjs';
|
|
12
4
|
import Decimal from 'decimal.js';
|
|
13
5
|
import { create, all } from 'mathjs';
|
|
14
6
|
|
|
15
|
-
dayjs.extend(WeekOfYear);
|
|
16
|
-
dayjs.extend(QuarterOfYear);
|
|
17
|
-
dayjs.extend(Duration);
|
|
18
|
-
dayjs.extend(IsToday);
|
|
19
|
-
dayjs.extend(RelativeTime);
|
|
20
|
-
dayjs.extend(ArraySupport);
|
|
21
|
-
dayjs.extend(ObjectSupport);
|
|
22
|
-
dayjs.extend(CustomParseFormat);
|
|
23
|
-
dayjs.extend(UTC);
|
|
24
|
-
|
|
25
7
|
const ERR_PIPELINE_NOT_FOUND = 'O01-00001';
|
|
26
8
|
const ERR_TRIM_NON_STRING = 'O01-00002';
|
|
27
9
|
const ERR_DUPLICATED_ERROR_CODE = 'O01-00002';
|
|
@@ -434,516 +416,6 @@ const StaticImplements = () => {
|
|
|
434
416
|
};
|
|
435
417
|
};
|
|
436
418
|
|
|
437
|
-
const OBJECT_PROTOTYPE = Object.prototype;
|
|
438
|
-
|
|
439
|
-
const isLength = (value) => {
|
|
440
|
-
return typeof value === 'number' && value > -1 && value % 1 === 0 && value <= Number.MAX_SAFE_INTEGER;
|
|
441
|
-
};
|
|
442
|
-
const isArrayLike = (value) => {
|
|
443
|
-
return value != null && typeof value !== 'function' && isLength(value.length);
|
|
444
|
-
};
|
|
445
|
-
const isPrototype = (value) => {
|
|
446
|
-
const Ctor = value && value.constructor;
|
|
447
|
-
const proto = (typeof Ctor === 'function' && Ctor.prototype) || OBJECT_PROTOTYPE;
|
|
448
|
-
return value === proto;
|
|
449
|
-
};
|
|
450
|
-
const isNull = (value) => {
|
|
451
|
-
return value == null
|
|
452
|
-
? { test: true, value: value }
|
|
453
|
-
: { test: false, value };
|
|
454
|
-
};
|
|
455
|
-
const isNotNull = (value) => ({ test: !isNull(value).test, value });
|
|
456
|
-
const isEmpty = (value) => {
|
|
457
|
-
if (value == null) {
|
|
458
|
-
return { test: true, value: value };
|
|
459
|
-
}
|
|
460
|
-
let length = null;
|
|
461
|
-
if (isArrayLike(value) && (Array.isArray(value) || typeof value === 'string')) {
|
|
462
|
-
length = value.length;
|
|
463
|
-
}
|
|
464
|
-
else if (value instanceof Map) {
|
|
465
|
-
length = value.size;
|
|
466
|
-
}
|
|
467
|
-
else if (value instanceof Set) {
|
|
468
|
-
length = value.size;
|
|
469
|
-
}
|
|
470
|
-
else if (isPrototype(value)) {
|
|
471
|
-
length = Object.keys(value).length;
|
|
472
|
-
}
|
|
473
|
-
return { test: length === 0, value };
|
|
474
|
-
};
|
|
475
|
-
const isNotEmpty = (value) => ({ test: !isEmpty(value).test, value });
|
|
476
|
-
const isBlank = (value) => {
|
|
477
|
-
switch (true) {
|
|
478
|
-
case (value == null):
|
|
479
|
-
return { test: true, value: value };
|
|
480
|
-
case (typeof value === 'string' && value.trim().length === 0):
|
|
481
|
-
return { test: true, value: value };
|
|
482
|
-
default:
|
|
483
|
-
return { test: false, value };
|
|
484
|
-
}
|
|
485
|
-
};
|
|
486
|
-
const isNotBlank = (value) => ({ test: !isBlank(value).test, value });
|
|
487
|
-
|
|
488
|
-
const regexp = (regexp) => {
|
|
489
|
-
return (value) => {
|
|
490
|
-
if (value == null) {
|
|
491
|
-
return { test: false, value };
|
|
492
|
-
}
|
|
493
|
-
const type = typeof value;
|
|
494
|
-
if (['string', 'number', 'bigint'].includes(type)) {
|
|
495
|
-
return { test: regexp.test(value), value };
|
|
496
|
-
}
|
|
497
|
-
return { test: false, value };
|
|
498
|
-
};
|
|
499
|
-
};
|
|
500
|
-
|
|
501
|
-
var Rounding;
|
|
502
|
-
(function (Rounding) {
|
|
503
|
-
Rounding["ROUND_UP"] = "up";
|
|
504
|
-
Rounding["ROUND_DOWN"] = "down";
|
|
505
|
-
Rounding["ROUND_CEIL"] = "ceil";
|
|
506
|
-
Rounding["ROUND_FLOOR"] = "floor";
|
|
507
|
-
Rounding["ROUND_HALF_UP"] = "half-up";
|
|
508
|
-
Rounding["ROUND_HALF_DOWN"] = "half-down";
|
|
509
|
-
Rounding["ROUND_HALF_EVEN"] = "half-even";
|
|
510
|
-
Rounding["ROUND_HALF_CEIL"] = "half-ceil";
|
|
511
|
-
Rounding["ROUND_HALF_FLOOR"] = "half-floor";
|
|
512
|
-
})(Rounding || (Rounding = {}));
|
|
513
|
-
const ToDecimalJsRounding = {
|
|
514
|
-
[Rounding.ROUND_UP]: Decimal.ROUND_UP,
|
|
515
|
-
[Rounding.ROUND_DOWN]: Decimal.ROUND_DOWN,
|
|
516
|
-
[Rounding.ROUND_CEIL]: Decimal.ROUND_CEIL,
|
|
517
|
-
[Rounding.ROUND_FLOOR]: Decimal.ROUND_FLOOR,
|
|
518
|
-
[Rounding.ROUND_HALF_UP]: Decimal.ROUND_HALF_UP,
|
|
519
|
-
[Rounding.ROUND_HALF_DOWN]: Decimal.ROUND_HALF_DOWN,
|
|
520
|
-
[Rounding.ROUND_HALF_EVEN]: Decimal.ROUND_HALF_EVEN,
|
|
521
|
-
[Rounding.ROUND_HALF_CEIL]: Decimal.ROUND_HALF_CEIL,
|
|
522
|
-
[Rounding.ROUND_HALF_FLOOR]: Decimal.ROUND_HALF_FLOOR
|
|
523
|
-
};
|
|
524
|
-
const toDecimal = (value) => {
|
|
525
|
-
if (value == null) {
|
|
526
|
-
return { test: false, value };
|
|
527
|
-
}
|
|
528
|
-
else if (value instanceof Decimal) {
|
|
529
|
-
return { test: true, value };
|
|
530
|
-
}
|
|
531
|
-
else if (['string', 'number'].includes(typeof value)) {
|
|
532
|
-
try {
|
|
533
|
-
return { test: true, value: new Decimal(value) };
|
|
534
|
-
}
|
|
535
|
-
catch {
|
|
536
|
-
return { test: false, value };
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
else {
|
|
540
|
-
return { test: false, value };
|
|
541
|
-
}
|
|
542
|
-
};
|
|
543
|
-
const toNumber = (value) => {
|
|
544
|
-
const { test, value: parsed } = toDecimal(value);
|
|
545
|
-
if (!test) {
|
|
546
|
-
return { test: false, value };
|
|
547
|
-
}
|
|
548
|
-
return { test: true, value: parsed.toNumber() };
|
|
549
|
-
};
|
|
550
|
-
const toFixed = (fractionDigits, rounding = Rounding.ROUND_HALF_UP) => {
|
|
551
|
-
return (value) => {
|
|
552
|
-
const { test, value: parsed } = toDecimal(value);
|
|
553
|
-
if (!test) {
|
|
554
|
-
return { test: false, value };
|
|
555
|
-
}
|
|
556
|
-
return { test: true, value: parsed.toFixed(fractionDigits, ToDecimalJsRounding[rounding]) };
|
|
557
|
-
};
|
|
558
|
-
};
|
|
559
|
-
const baseRound = (rounding = Rounding.ROUND_HALF_UP) => {
|
|
560
|
-
return (fractionDigits) => {
|
|
561
|
-
return (value) => {
|
|
562
|
-
const { test, value: parsed } = toDecimal(value);
|
|
563
|
-
if (!test) {
|
|
564
|
-
return { test: false, value };
|
|
565
|
-
}
|
|
566
|
-
return { test: true, value: parsed.toDecimalPlaces(fractionDigits, ToDecimalJsRounding[rounding]) };
|
|
567
|
-
};
|
|
568
|
-
};
|
|
569
|
-
};
|
|
570
|
-
const roundUp = baseRound(Rounding.ROUND_HALF_UP);
|
|
571
|
-
const roundDown = baseRound(Rounding.ROUND_HALF_DOWN);
|
|
572
|
-
const floor = baseRound(Rounding.ROUND_FLOOR);
|
|
573
|
-
const ceil = baseRound(Rounding.ROUND_CEIL);
|
|
574
|
-
const roundBy = (fractionDigits, rounding = Rounding.ROUND_HALF_UP) => {
|
|
575
|
-
return baseRound(rounding)(fractionDigits);
|
|
576
|
-
};
|
|
577
|
-
|
|
578
|
-
const isDecimal = (value) => {
|
|
579
|
-
const { test, value: decimal } = toDecimal(value);
|
|
580
|
-
return { test, value: test ? decimal : value };
|
|
581
|
-
};
|
|
582
|
-
const isInteger = (value) => {
|
|
583
|
-
const { test, value: decimal } = toDecimal(value);
|
|
584
|
-
return (test && decimal.isInteger()) ? { test: true, value: decimal } : { test: false, value };
|
|
585
|
-
};
|
|
586
|
-
const isInRange = (options) => {
|
|
587
|
-
const { min, max, interval = 'closed' } = options;
|
|
588
|
-
return (value) => {
|
|
589
|
-
const { test, value: decimal } = toDecimal(value);
|
|
590
|
-
if (!test) {
|
|
591
|
-
return { test: false, value };
|
|
592
|
-
}
|
|
593
|
-
let pass = false;
|
|
594
|
-
switch (interval) {
|
|
595
|
-
case 'open':
|
|
596
|
-
case 'o':
|
|
597
|
-
pass = (min == null || decimal.gt(min)) && (max == null || decimal.lt(max));
|
|
598
|
-
break;
|
|
599
|
-
case 'left-open':
|
|
600
|
-
case 'lo':
|
|
601
|
-
pass = (min == null || decimal.gt(min)) && (max == null || decimal.lte(max));
|
|
602
|
-
break;
|
|
603
|
-
case 'right-open':
|
|
604
|
-
case 'ro':
|
|
605
|
-
pass = (min == null || decimal.gte(min)) && (max == null || decimal.lt(max));
|
|
606
|
-
break;
|
|
607
|
-
case 'closed':
|
|
608
|
-
case 'c':
|
|
609
|
-
default:
|
|
610
|
-
pass = (min == null || decimal.gte(min)) && (max == null || decimal.lte(max));
|
|
611
|
-
break;
|
|
612
|
-
}
|
|
613
|
-
return pass ? { test: true, value: decimal } : { test: false, value };
|
|
614
|
-
};
|
|
615
|
-
};
|
|
616
|
-
const isPositive = isInRange({ min: 0, interval: 'left-open' });
|
|
617
|
-
const isNotPositive = isInRange({ max: 0 });
|
|
618
|
-
const isNegative = isInRange({ max: 0, interval: 'right-open' });
|
|
619
|
-
const isNotNegative = isInRange({ min: 0 });
|
|
620
|
-
const isZero = (value) => {
|
|
621
|
-
const { test, value: decimal } = toDecimal(value);
|
|
622
|
-
return (test && decimal.isZero()) ? { test: true, value: decimal } : { test: false, value };
|
|
623
|
-
};
|
|
624
|
-
const isNotZero = (value) => {
|
|
625
|
-
const { test, value: decimal } = toDecimal(value);
|
|
626
|
-
return (test && !decimal.isZero()) ? { test: true, value: decimal } : { test: false, value };
|
|
627
|
-
};
|
|
628
|
-
const isGreaterThan = (compare) => {
|
|
629
|
-
return isInRange({ min: compare, interval: 'left-open' });
|
|
630
|
-
};
|
|
631
|
-
const isGreaterThanOrEqual = (compare) => {
|
|
632
|
-
return isInRange({ min: compare });
|
|
633
|
-
};
|
|
634
|
-
const isLessThan = (compare) => {
|
|
635
|
-
return isInRange({ max: compare, interval: 'right-open' });
|
|
636
|
-
};
|
|
637
|
-
const isLessThanOrEqual = (compare) => {
|
|
638
|
-
return isInRange({ max: compare });
|
|
639
|
-
};
|
|
640
|
-
|
|
641
|
-
const testers = {
|
|
642
|
-
isNull: { type: 'func', func: isNull },
|
|
643
|
-
isNotNull: { type: 'func', func: isNotNull },
|
|
644
|
-
isEmpty: { type: 'func', func: isEmpty },
|
|
645
|
-
isNotEmpty: { type: 'func', func: isNotEmpty },
|
|
646
|
-
isBlank: { type: 'func', func: isBlank },
|
|
647
|
-
isNotBlank: { type: 'func', func: isNotBlank },
|
|
648
|
-
regexp: { type: 'param', func: regexp },
|
|
649
|
-
regex: { type: 'param', func: regexp },
|
|
650
|
-
matches: { type: 'param', func: regexp },
|
|
651
|
-
isNumber: { type: 'func', func: isDecimal },
|
|
652
|
-
isDecimal: { type: 'func', func: isDecimal },
|
|
653
|
-
isInteger: { type: 'func', func: isInteger },
|
|
654
|
-
isInt: { type: 'func', func: isInteger },
|
|
655
|
-
isPositive: { type: 'func', func: isPositive },
|
|
656
|
-
isNotPositive: { type: 'func', func: isNotPositive },
|
|
657
|
-
isNegative: { type: 'func', func: isNegative },
|
|
658
|
-
isNotNegative: { type: 'func', func: isNotNegative },
|
|
659
|
-
isZero: { type: 'func', func: isZero },
|
|
660
|
-
isNotZero: { type: 'func', func: isNotZero },
|
|
661
|
-
isGreaterThan: { type: 'param', func: isGreaterThan },
|
|
662
|
-
gt: { type: 'param', func: isGreaterThan },
|
|
663
|
-
isGreaterThanOrEqual: {
|
|
664
|
-
type: 'param', func: isGreaterThanOrEqual
|
|
665
|
-
},
|
|
666
|
-
gte: { type: 'param', func: isGreaterThanOrEqual },
|
|
667
|
-
isLessThan: { type: 'param', func: isLessThan },
|
|
668
|
-
lt: { type: 'param', func: isLessThan },
|
|
669
|
-
isLessThanOrEqual: {
|
|
670
|
-
type: 'param', func: isLessThanOrEqual
|
|
671
|
-
},
|
|
672
|
-
lte: { type: 'param', func: isLessThanOrEqual },
|
|
673
|
-
isInRange: { type: 'param', func: isInRange },
|
|
674
|
-
within: { type: 'param', func: isInRange }
|
|
675
|
-
};
|
|
676
|
-
const AllTesters = testers;
|
|
677
|
-
|
|
678
|
-
const trim = (value) => {
|
|
679
|
-
if (value == null) {
|
|
680
|
-
return { test: true, value };
|
|
681
|
-
}
|
|
682
|
-
else if (typeof value === 'string') {
|
|
683
|
-
return { test: true, value: value.trim() };
|
|
684
|
-
}
|
|
685
|
-
else {
|
|
686
|
-
return { test: true, value };
|
|
687
|
-
}
|
|
688
|
-
};
|
|
689
|
-
const pad = (options) => {
|
|
690
|
-
const { length, char = ' ', direction = 'right' } = options;
|
|
691
|
-
return (value) => {
|
|
692
|
-
if (value == null) {
|
|
693
|
-
return { test: false, value };
|
|
694
|
-
}
|
|
695
|
-
const type = typeof value;
|
|
696
|
-
if (['string', 'number', 'bigint', 'boolean'].includes(type)) {
|
|
697
|
-
const stringified = `${value}`;
|
|
698
|
-
const len = stringified.length;
|
|
699
|
-
if (len >= length) {
|
|
700
|
-
return { test: true, value: stringified };
|
|
701
|
-
}
|
|
702
|
-
return {
|
|
703
|
-
test: true,
|
|
704
|
-
value: direction === 'left' ? stringified.padStart(length, char) : stringified.padEnd(length, char)
|
|
705
|
-
};
|
|
706
|
-
}
|
|
707
|
-
else {
|
|
708
|
-
return { test: false, value };
|
|
709
|
-
}
|
|
710
|
-
};
|
|
711
|
-
};
|
|
712
|
-
const padStart = (options) => pad({ ...options, direction: 'left' });
|
|
713
|
-
const padEnd = (options) => pad({ ...options, direction: 'right' });
|
|
714
|
-
|
|
715
|
-
const transformers = {
|
|
716
|
-
trim: { type: 'func', func: trim },
|
|
717
|
-
pad: { type: 'param', func: pad },
|
|
718
|
-
padStart: { type: 'param', func: padStart },
|
|
719
|
-
padLeft: { type: 'param', func: padStart },
|
|
720
|
-
lpad: { type: 'param', func: padStart },
|
|
721
|
-
padEnd: { type: 'param', func: padEnd },
|
|
722
|
-
padRight: { type: 'param', func: padEnd },
|
|
723
|
-
rpad: { type: 'param', func: padEnd },
|
|
724
|
-
toDecimal: { type: 'func', func: toDecimal },
|
|
725
|
-
toNumber: { type: 'func', func: toNumber },
|
|
726
|
-
toFixed0: { type: 'func', func: toFixed(0) },
|
|
727
|
-
toFixed1: { type: 'func', func: toFixed(1) },
|
|
728
|
-
toFixed2: { type: 'func', func: toFixed(2) },
|
|
729
|
-
toFixed3: { type: 'func', func: toFixed(3) },
|
|
730
|
-
toFixed4: { type: 'func', func: toFixed(4) },
|
|
731
|
-
toFixed5: { type: 'func', func: toFixed(5) },
|
|
732
|
-
toFixed6: { type: 'func', func: toFixed(6) },
|
|
733
|
-
toFixed: { type: 'param', func: toFixed },
|
|
734
|
-
round: { type: 'param', func: roundUp },
|
|
735
|
-
roundUp: { type: 'param', func: roundUp },
|
|
736
|
-
roundDown: { type: 'param', func: roundDown },
|
|
737
|
-
floor: { type: 'param', func: floor },
|
|
738
|
-
ceil: { type: 'param', func: ceil },
|
|
739
|
-
roundBy: { type: 'param', func: roundBy }
|
|
740
|
-
};
|
|
741
|
-
const AllTransformers = transformers;
|
|
742
|
-
|
|
743
|
-
var ValueOperatorBootstrap_1;
|
|
744
|
-
const applyOperator = (operator, base) => {
|
|
745
|
-
if (base.$allowNoParamFuncCall) {
|
|
746
|
-
base.$allowNoParamFuncCall = false;
|
|
747
|
-
return operator;
|
|
748
|
-
}
|
|
749
|
-
else {
|
|
750
|
-
throw new Error(`Function call is not allowed from: ${operator}.`);
|
|
751
|
-
}
|
|
752
|
-
};
|
|
753
|
-
const NOT_FOUND = Symbol('not found');
|
|
754
|
-
const findValueAction = (actions) => {
|
|
755
|
-
return (operator, base, prop) => {
|
|
756
|
-
const tester = actions[prop];
|
|
757
|
-
if (tester == null) {
|
|
758
|
-
return NOT_FOUND;
|
|
759
|
-
}
|
|
760
|
-
base.$allowUseDefault = true;
|
|
761
|
-
if (base.$actions == null) {
|
|
762
|
-
base.$actions = [];
|
|
763
|
-
}
|
|
764
|
-
if (tester.type === 'func') {
|
|
765
|
-
base.$actions.push(tester.func);
|
|
766
|
-
base.$allowNoParamFuncCall = true;
|
|
767
|
-
return operator;
|
|
768
|
-
}
|
|
769
|
-
else if (tester.type === 'param') {
|
|
770
|
-
return (...args) => {
|
|
771
|
-
base.$actions.push(tester.func(...args));
|
|
772
|
-
return operator;
|
|
773
|
-
};
|
|
774
|
-
}
|
|
775
|
-
else {
|
|
776
|
-
throw new Error(`Unknown tester type: ${tester}.`);
|
|
777
|
-
}
|
|
778
|
-
};
|
|
779
|
-
};
|
|
780
|
-
const findTester = findValueAction(AllTesters);
|
|
781
|
-
const findTransformer = findValueAction(AllTransformers);
|
|
782
|
-
const findUseDefault = (operator, base, prop) => {
|
|
783
|
-
if (!base.$allowUseDefault || !['orUseDefault', 'useDefault', 'withDefault', 'orElse', 'else'].includes(prop)) {
|
|
784
|
-
return NOT_FOUND;
|
|
785
|
-
}
|
|
786
|
-
if ((base.$actions == null || base.$actions.length === 0)) {
|
|
787
|
-
return (void 0);
|
|
788
|
-
}
|
|
789
|
-
base.$allowMoreAction = false;
|
|
790
|
-
base.$allowUseDefault = false;
|
|
791
|
-
return (defaultValue) => {
|
|
792
|
-
base.$defaultUsed = true;
|
|
793
|
-
base.$defaultValue = defaultValue;
|
|
794
|
-
return operator;
|
|
795
|
-
};
|
|
796
|
-
};
|
|
797
|
-
const createValueRetrieveFunc = (base) => {
|
|
798
|
-
return () => {
|
|
799
|
-
const tested = { test: true, value: base.$value };
|
|
800
|
-
for (const action of (base.$actions ?? [])) {
|
|
801
|
-
const result = action(tested.value);
|
|
802
|
-
if (!result.test) {
|
|
803
|
-
tested.test = false;
|
|
804
|
-
tested.value = base.$value;
|
|
805
|
-
break;
|
|
806
|
-
}
|
|
807
|
-
else {
|
|
808
|
-
tested.value = result.value;
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
if (tested.test) ;
|
|
812
|
-
else if (base.$defaultUsed) {
|
|
813
|
-
tested.test = true;
|
|
814
|
-
tested.value = base.$defaultValue;
|
|
815
|
-
}
|
|
816
|
-
else {
|
|
817
|
-
tested.value = base.$value;
|
|
818
|
-
}
|
|
819
|
-
return tested;
|
|
820
|
-
};
|
|
821
|
-
};
|
|
822
|
-
const findValue = (_operator, base, prop) => {
|
|
823
|
-
if (prop !== 'value') {
|
|
824
|
-
return NOT_FOUND;
|
|
825
|
-
}
|
|
826
|
-
if ((base.$actions == null || base.$actions.length === 0)) {
|
|
827
|
-
return (void 0);
|
|
828
|
-
}
|
|
829
|
-
return () => createValueRetrieveFunc(base)().value;
|
|
830
|
-
};
|
|
831
|
-
const findSuccessOrFailureCallback = (_operator, base, prop) => {
|
|
832
|
-
if (prop !== 'success' && prop !== 'failure') {
|
|
833
|
-
return NOT_FOUND;
|
|
834
|
-
}
|
|
835
|
-
if ((base.$actions == null || base.$actions.length === 0)) {
|
|
836
|
-
return (void 0);
|
|
837
|
-
}
|
|
838
|
-
switch (prop) {
|
|
839
|
-
case 'success':
|
|
840
|
-
return (callback) => {
|
|
841
|
-
const tested = createValueRetrieveFunc(base)();
|
|
842
|
-
if (tested.test) {
|
|
843
|
-
callback(tested.value);
|
|
844
|
-
}
|
|
845
|
-
return {
|
|
846
|
-
failure: (callback) => {
|
|
847
|
-
if (!tested.test) {
|
|
848
|
-
callback(tested.value);
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
};
|
|
852
|
-
};
|
|
853
|
-
case 'failure':
|
|
854
|
-
return (callback) => {
|
|
855
|
-
const tested = createValueRetrieveFunc(base)();
|
|
856
|
-
if (!tested.test) {
|
|
857
|
-
callback(tested.value);
|
|
858
|
-
}
|
|
859
|
-
return {
|
|
860
|
-
success: (callback) => {
|
|
861
|
-
if (tested.test) {
|
|
862
|
-
callback(tested.value);
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
};
|
|
866
|
-
};
|
|
867
|
-
default:
|
|
868
|
-
throw new Error(`Unknown callback type: ${prop}.`);
|
|
869
|
-
}
|
|
870
|
-
};
|
|
871
|
-
const findOK = (operator, base, prop) => {
|
|
872
|
-
if (prop !== 'ok') {
|
|
873
|
-
return NOT_FOUND;
|
|
874
|
-
}
|
|
875
|
-
if ((base.$actions == null || base.$actions.length === 0)) {
|
|
876
|
-
return (void 0);
|
|
877
|
-
}
|
|
878
|
-
return () => createValueRetrieveFunc(base)().test;
|
|
879
|
-
};
|
|
880
|
-
const findPromise = (_operator, base, prop) => {
|
|
881
|
-
if (prop !== 'promise') {
|
|
882
|
-
return NOT_FOUND;
|
|
883
|
-
}
|
|
884
|
-
if ((base.$actions == null || base.$actions.length === 0)) {
|
|
885
|
-
return (void 0);
|
|
886
|
-
}
|
|
887
|
-
return async () => {
|
|
888
|
-
const tested = createValueRetrieveFunc(base)();
|
|
889
|
-
if (tested.test) {
|
|
890
|
-
return Promise.resolve(tested.value);
|
|
891
|
-
}
|
|
892
|
-
else {
|
|
893
|
-
return Promise.reject(tested.value);
|
|
894
|
-
}
|
|
895
|
-
};
|
|
896
|
-
};
|
|
897
|
-
const getFromOperator = (operator, base, prop) => {
|
|
898
|
-
base.$allowNoParamFuncCall = false;
|
|
899
|
-
const finds = [
|
|
900
|
-
findTester, findTransformer, findUseDefault,
|
|
901
|
-
findValue, findSuccessOrFailureCallback, findOK, findPromise
|
|
902
|
-
];
|
|
903
|
-
for (const find of finds) {
|
|
904
|
-
const result = find(operator, base, prop);
|
|
905
|
-
if (result !== NOT_FOUND) {
|
|
906
|
-
return result;
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
return (void 0);
|
|
910
|
-
};
|
|
911
|
-
const createOperator = (base) => {
|
|
912
|
-
const operatorBase = () => {
|
|
913
|
-
};
|
|
914
|
-
operatorBase.$base = base;
|
|
915
|
-
const operator = new Proxy(operatorBase, {
|
|
916
|
-
apply(base, _thisArg, _argArray) {
|
|
917
|
-
return applyOperator(operator, base.$base);
|
|
918
|
-
},
|
|
919
|
-
get(base, p, _receiver) {
|
|
920
|
-
return getFromOperator(operator, base.$base, p);
|
|
921
|
-
}
|
|
922
|
-
});
|
|
923
|
-
return operator;
|
|
924
|
-
};
|
|
925
|
-
let ValueOperatorBootstrap = ValueOperatorBootstrap_1 = class ValueOperatorBootstrap {
|
|
926
|
-
constructor() {
|
|
927
|
-
}
|
|
928
|
-
static of(value) {
|
|
929
|
-
return createOperator({
|
|
930
|
-
$value: value,
|
|
931
|
-
$allowMoreAction: true, $allowUseDefault: false, $defaultUsed: false,
|
|
932
|
-
$allowNoParamFuncCall: false
|
|
933
|
-
});
|
|
934
|
-
}
|
|
935
|
-
static from(value) {
|
|
936
|
-
return ValueOperatorBootstrap_1.of(value);
|
|
937
|
-
}
|
|
938
|
-
static with(value) {
|
|
939
|
-
return ValueOperatorBootstrap_1.of(value);
|
|
940
|
-
}
|
|
941
|
-
};
|
|
942
|
-
ValueOperatorBootstrap = ValueOperatorBootstrap_1 = __decorate([
|
|
943
|
-
StaticImplements()
|
|
944
|
-
], ValueOperatorBootstrap);
|
|
945
|
-
const ValueOperator = ValueOperatorBootstrap;
|
|
946
|
-
|
|
947
419
|
var StepHelpersUtils_1;
|
|
948
420
|
const PIPELINE_STEP_FILE_SYMBOL = Symbol();
|
|
949
421
|
const PIPELINE_STEP_RETURN_NULL = Symbol();
|
|
@@ -995,9 +467,7 @@ let StepHelpersUtils = class StepHelpersUtils {
|
|
|
995
467
|
return PIPELINE_STEP_RETURN_NULL;
|
|
996
468
|
}
|
|
997
469
|
static isPrototype(value) {
|
|
998
|
-
|
|
999
|
-
const proto = (typeof Ctor === 'function' && Ctor.prototype) || OBJECT_PROTOTYPE;
|
|
1000
|
-
return value === proto;
|
|
470
|
+
return isPrototype(value);
|
|
1001
471
|
}
|
|
1002
472
|
static isLength(value) {
|
|
1003
473
|
return isLength(value);
|
|
@@ -1006,16 +476,16 @@ let StepHelpersUtils = class StepHelpersUtils {
|
|
|
1006
476
|
return isArrayLike(value);
|
|
1007
477
|
}
|
|
1008
478
|
static isEmpty(value) {
|
|
1009
|
-
return
|
|
479
|
+
return ValueOperator.of(value).isEmpty().ok();
|
|
1010
480
|
}
|
|
1011
481
|
static isNotEmpty(value) {
|
|
1012
|
-
return
|
|
482
|
+
return ValueOperator.of(value).isNotEmpty().ok();
|
|
1013
483
|
}
|
|
1014
484
|
static isBlank(value) {
|
|
1015
|
-
return
|
|
485
|
+
return ValueOperator.of(value).isBlank().ok();
|
|
1016
486
|
}
|
|
1017
487
|
static isNotBlank(value) {
|
|
1018
|
-
return
|
|
488
|
+
return ValueOperator.of(value).isNotBlank().ok();
|
|
1019
489
|
}
|
|
1020
490
|
static trim(value) {
|
|
1021
491
|
if (value == null) {
|
|
@@ -1027,7 +497,7 @@ let StepHelpersUtils = class StepHelpersUtils {
|
|
|
1027
497
|
throw new UncatchableError(ERR_TRIM_NON_STRING, `Cannot apply trim to non-string object[type=${typeof value}, value=${value}].`);
|
|
1028
498
|
}
|
|
1029
499
|
static touch(value) {
|
|
1030
|
-
return ValueOperator.
|
|
500
|
+
return ValueOperator.of(value);
|
|
1031
501
|
}
|
|
1032
502
|
static noop() {
|
|
1033
503
|
}
|
|
@@ -1311,4 +781,4 @@ class PipelineRepository {
|
|
|
1311
781
|
}
|
|
1312
782
|
}
|
|
1313
783
|
|
|
1314
|
-
export { AbstractPipeline, AbstractPipelineExecution, AbstractPipelineStep, AbstractStaticPipeline,
|
|
784
|
+
export { AbstractPipeline, AbstractPipelineExecution, AbstractPipelineStep, AbstractStaticPipeline, CatchableError, Config, ConsoleLogger, DefaultPipelineBuilder, DefaultPipelineStepBuilder, ERR_DUPLICATED_ERROR_CODE, ERR_PIPELINE_NOT_FOUND, ERR_TRIM_NON_STRING, ERR_UNKNOWN, EnhancedLogger, ErrorCodes, ExposedUncatchableError, LoggerPerformanceSaver, LoggerUtils, PIPELINE_STEP_FILE_SYMBOL, PIPELINE_STEP_RETURN_NULL, PerformanceExecution, PipelineRepository, PipelineStepDateHelper, StepHelpersUtils, UncatchableError, createConfig, createLogger, createStepHelpers, registerToStepHelpers, saveLoggerPerformance };
|
package/lib/envs.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import '@rainbow-n19/n1';
|
package/lib/pipeline/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { IValueOperator } from '@rainbow-n19/n1';
|
|
1
2
|
import { CatchableError, ExposedUncatchableError, UncatchableError } from '../utils';
|
|
2
3
|
import { PipelineStepHelpers } from './step-helpers';
|
|
3
|
-
import { IValueOperator } from './step-helpers-value-operator';
|
|
4
4
|
export interface PipelineStepErrorOptions {
|
|
5
5
|
status: number;
|
|
6
6
|
code: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rainbow-o23/n1",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.51",
|
|
4
4
|
"description": "o23 interfaces",
|
|
5
5
|
"main": "index.cjs",
|
|
6
6
|
"module": "index.js",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"url": "https://github.com/InsureMO/rainbow-o23/issues"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
+
"@rainbow-n19/n1": "latest",
|
|
24
25
|
"dayjs": "^1.11.13",
|
|
25
26
|
"decimal.js": "^10.4.3",
|
|
26
27
|
"mathjs": "^13.2.1",
|
package/rollup.config.base.js
CHANGED
|
@@ -23,7 +23,10 @@ export const buildConfig = (lint) => {
|
|
|
23
23
|
].filter(x => x != null),
|
|
24
24
|
external(id) {
|
|
25
25
|
return ["dayjs/plugin/"].some(scope => id.startsWith(scope))
|
|
26
|
-
|| [
|
|
26
|
+
|| [
|
|
27
|
+
'@rainbow-n19/n1',
|
|
28
|
+
'nanoid', 'dayjs', 'mathjs', 'decimal.js'
|
|
29
|
+
].includes(id);
|
|
27
30
|
}
|
|
28
31
|
};
|
|
29
32
|
};
|
package/src/lib/envs.ts
CHANGED
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import CustomParseFormat from 'dayjs/plugin/customParseFormat.js';
|
|
4
|
-
import Duration from 'dayjs/plugin/duration.js';
|
|
5
|
-
import IsToday from 'dayjs/plugin/isToday.js';
|
|
6
|
-
import ObjectSupport from 'dayjs/plugin/objectSupport.js';
|
|
7
|
-
import QuarterOfYear from 'dayjs/plugin/quarterOfYear.js';
|
|
8
|
-
import RelativeTime from 'dayjs/plugin/relativeTime.js';
|
|
9
|
-
import UTC from 'dayjs/plugin/utc.js';
|
|
10
|
-
import WeekOfYear from 'dayjs/plugin/weekOfYear.js';
|
|
11
|
-
|
|
12
|
-
dayjs.extend(WeekOfYear);
|
|
13
|
-
dayjs.extend(QuarterOfYear);
|
|
14
|
-
dayjs.extend(Duration);
|
|
15
|
-
dayjs.extend(IsToday);
|
|
16
|
-
dayjs.extend(RelativeTime);
|
|
17
|
-
dayjs.extend(ArraySupport);
|
|
18
|
-
dayjs.extend(ObjectSupport);
|
|
19
|
-
dayjs.extend(CustomParseFormat);
|
|
20
|
-
dayjs.extend(UTC);
|
|
1
|
+
// initial dayjs and decimal.js
|
|
2
|
+
import '@rainbow-n19/n1';
|