@parsrun/core 0.1.29 → 0.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/decimal.d.ts +176 -46
- package/dist/decimal.js +123 -40
- package/dist/decimal.js.map +1 -1
- package/dist/errors.d.ts +39 -3
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +184 -15
- package/dist/index.js +155 -40
- package/dist/index.js.map +1 -1
- package/dist/{logger-3oVznpFY.d.ts → logger-DrxxwI7C.d.ts} +136 -11
- package/dist/logger.d.ts +1 -1
- package/dist/logger.js +32 -0
- package/dist/logger.js.map +1 -1
- package/dist/transports/index.d.ts +58 -7
- package/dist/transports/index.js.map +1 -1
- package/dist/types.d.ts +176 -0
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -390,23 +390,55 @@ var Logger = class _Logger {
|
|
|
390
390
|
transport.log(entry);
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
|
+
/**
|
|
394
|
+
* Log a trace message (most verbose level).
|
|
395
|
+
* @param message - Log message
|
|
396
|
+
* @param context - Optional context data
|
|
397
|
+
*/
|
|
393
398
|
trace(message, context) {
|
|
394
399
|
this.log("TRACE", message, context);
|
|
395
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* Log a debug message.
|
|
403
|
+
* @param message - Log message
|
|
404
|
+
* @param context - Optional context data
|
|
405
|
+
*/
|
|
396
406
|
debug(message, context) {
|
|
397
407
|
this.log("DEBUG", message, context);
|
|
398
408
|
}
|
|
409
|
+
/**
|
|
410
|
+
* Log an informational message.
|
|
411
|
+
* @param message - Log message
|
|
412
|
+
* @param context - Optional context data
|
|
413
|
+
*/
|
|
399
414
|
info(message, context) {
|
|
400
415
|
this.log("INFO", message, context);
|
|
401
416
|
}
|
|
417
|
+
/**
|
|
418
|
+
* Log a warning message.
|
|
419
|
+
* @param message - Log message
|
|
420
|
+
* @param context - Optional context data
|
|
421
|
+
*/
|
|
402
422
|
warn(message, context) {
|
|
403
423
|
this.log("WARN", message, context);
|
|
404
424
|
}
|
|
425
|
+
/**
|
|
426
|
+
* Log an error message with optional Error object.
|
|
427
|
+
* @param message - Log message
|
|
428
|
+
* @param error - Optional Error object or context
|
|
429
|
+
* @param context - Optional additional context
|
|
430
|
+
*/
|
|
405
431
|
error(message, error, context) {
|
|
406
432
|
const err2 = error instanceof Error ? error : void 0;
|
|
407
433
|
const ctx = error instanceof Error ? context : error;
|
|
408
434
|
this.log("ERROR", message, ctx, err2);
|
|
409
435
|
}
|
|
436
|
+
/**
|
|
437
|
+
* Log a fatal error message (most severe level).
|
|
438
|
+
* @param message - Log message
|
|
439
|
+
* @param error - Optional Error object or context
|
|
440
|
+
* @param context - Optional additional context
|
|
441
|
+
*/
|
|
410
442
|
fatal(message, error, context) {
|
|
411
443
|
const err2 = error instanceof Error ? error : void 0;
|
|
412
444
|
const ctx = error instanceof Error ? context : error;
|
|
@@ -475,7 +507,9 @@ var Decimal = class _Decimal {
|
|
|
475
507
|
return trimmed.replace(/^(-?)0+(?=\d)/, "$1").replace(/\.?0+$/, "") || "0";
|
|
476
508
|
}
|
|
477
509
|
/**
|
|
478
|
-
* Add
|
|
510
|
+
* Add another value to this decimal.
|
|
511
|
+
* @param other - Value to add
|
|
512
|
+
* @returns A new Decimal with the result
|
|
479
513
|
*/
|
|
480
514
|
add(other) {
|
|
481
515
|
const a = parseFloat(this.value);
|
|
@@ -483,7 +517,9 @@ var Decimal = class _Decimal {
|
|
|
483
517
|
return new _Decimal(a + b);
|
|
484
518
|
}
|
|
485
519
|
/**
|
|
486
|
-
* Subtract
|
|
520
|
+
* Subtract a value from this decimal.
|
|
521
|
+
* @param other - Value to subtract
|
|
522
|
+
* @returns A new Decimal with the result
|
|
487
523
|
*/
|
|
488
524
|
sub(other) {
|
|
489
525
|
const a = parseFloat(this.value);
|
|
@@ -491,7 +527,9 @@ var Decimal = class _Decimal {
|
|
|
491
527
|
return new _Decimal(a - b);
|
|
492
528
|
}
|
|
493
529
|
/**
|
|
494
|
-
* Multiply
|
|
530
|
+
* Multiply this decimal by another value.
|
|
531
|
+
* @param other - Value to multiply by
|
|
532
|
+
* @returns A new Decimal with the result
|
|
495
533
|
*/
|
|
496
534
|
mul(other) {
|
|
497
535
|
const a = parseFloat(this.value);
|
|
@@ -499,7 +537,10 @@ var Decimal = class _Decimal {
|
|
|
499
537
|
return new _Decimal(a * b);
|
|
500
538
|
}
|
|
501
539
|
/**
|
|
502
|
-
* Divide
|
|
540
|
+
* Divide this decimal by another value.
|
|
541
|
+
* @param other - Value to divide by
|
|
542
|
+
* @returns A new Decimal with the result
|
|
543
|
+
* @throws Error if dividing by zero
|
|
503
544
|
*/
|
|
504
545
|
div(other) {
|
|
505
546
|
const a = parseFloat(this.value);
|
|
@@ -510,7 +551,9 @@ var Decimal = class _Decimal {
|
|
|
510
551
|
return new _Decimal(a / b);
|
|
511
552
|
}
|
|
512
553
|
/**
|
|
513
|
-
*
|
|
554
|
+
* Get the modulo (remainder) of dividing this decimal by another value.
|
|
555
|
+
* @param other - Value to divide by
|
|
556
|
+
* @returns A new Decimal with the remainder
|
|
514
557
|
*/
|
|
515
558
|
mod(other) {
|
|
516
559
|
const a = parseFloat(this.value);
|
|
@@ -518,14 +561,18 @@ var Decimal = class _Decimal {
|
|
|
518
561
|
return new _Decimal(a % b);
|
|
519
562
|
}
|
|
520
563
|
/**
|
|
521
|
-
*
|
|
564
|
+
* Raise this decimal to a power.
|
|
565
|
+
* @param exp - The exponent
|
|
566
|
+
* @returns A new Decimal with the result
|
|
522
567
|
*/
|
|
523
568
|
pow(exp) {
|
|
524
569
|
const a = parseFloat(this.value);
|
|
525
570
|
return new _Decimal(Math.pow(a, exp));
|
|
526
571
|
}
|
|
527
572
|
/**
|
|
528
|
-
*
|
|
573
|
+
* Calculate the square root of this decimal.
|
|
574
|
+
* @returns A new Decimal with the square root
|
|
575
|
+
* @throws Error if the value is negative
|
|
529
576
|
*/
|
|
530
577
|
sqrt() {
|
|
531
578
|
const a = parseFloat(this.value);
|
|
@@ -535,21 +582,25 @@ var Decimal = class _Decimal {
|
|
|
535
582
|
return new _Decimal(Math.sqrt(a));
|
|
536
583
|
}
|
|
537
584
|
/**
|
|
538
|
-
*
|
|
585
|
+
* Get the absolute value of this decimal.
|
|
586
|
+
* @returns A new Decimal with the absolute value
|
|
539
587
|
*/
|
|
540
588
|
abs() {
|
|
541
589
|
const a = parseFloat(this.value);
|
|
542
590
|
return new _Decimal(Math.abs(a));
|
|
543
591
|
}
|
|
544
592
|
/**
|
|
545
|
-
* Negate
|
|
593
|
+
* Negate this decimal (multiply by -1).
|
|
594
|
+
* @returns A new Decimal with the negated value
|
|
546
595
|
*/
|
|
547
596
|
neg() {
|
|
548
597
|
const a = parseFloat(this.value);
|
|
549
598
|
return new _Decimal(-a);
|
|
550
599
|
}
|
|
551
600
|
/**
|
|
552
|
-
* Round to decimal places
|
|
601
|
+
* Round to the specified number of decimal places using standard rounding.
|
|
602
|
+
* @param decimals - Number of decimal places (default: 0)
|
|
603
|
+
* @returns A new Decimal with the rounded value
|
|
553
604
|
*/
|
|
554
605
|
round(decimals = 0) {
|
|
555
606
|
const a = parseFloat(this.value);
|
|
@@ -557,7 +608,9 @@ var Decimal = class _Decimal {
|
|
|
557
608
|
return new _Decimal(Math.round(a * factor) / factor);
|
|
558
609
|
}
|
|
559
610
|
/**
|
|
560
|
-
*
|
|
611
|
+
* Round down to the specified number of decimal places.
|
|
612
|
+
* @param decimals - Number of decimal places (default: 0)
|
|
613
|
+
* @returns A new Decimal with the floored value
|
|
561
614
|
*/
|
|
562
615
|
floor(decimals = 0) {
|
|
563
616
|
const a = parseFloat(this.value);
|
|
@@ -565,7 +618,9 @@ var Decimal = class _Decimal {
|
|
|
565
618
|
return new _Decimal(Math.floor(a * factor) / factor);
|
|
566
619
|
}
|
|
567
620
|
/**
|
|
568
|
-
*
|
|
621
|
+
* Round up to the specified number of decimal places.
|
|
622
|
+
* @param decimals - Number of decimal places (default: 0)
|
|
623
|
+
* @returns A new Decimal with the ceiled value
|
|
569
624
|
*/
|
|
570
625
|
ceil(decimals = 0) {
|
|
571
626
|
const a = parseFloat(this.value);
|
|
@@ -573,7 +628,9 @@ var Decimal = class _Decimal {
|
|
|
573
628
|
return new _Decimal(Math.ceil(a * factor) / factor);
|
|
574
629
|
}
|
|
575
630
|
/**
|
|
576
|
-
* Compare
|
|
631
|
+
* Compare this decimal to another value.
|
|
632
|
+
* @param other - Value to compare against
|
|
633
|
+
* @returns -1 if less, 0 if equal, 1 if greater
|
|
577
634
|
*/
|
|
578
635
|
cmp(other) {
|
|
579
636
|
const a = parseFloat(this.value);
|
|
@@ -583,85 +640,107 @@ var Decimal = class _Decimal {
|
|
|
583
640
|
return 0;
|
|
584
641
|
}
|
|
585
642
|
/**
|
|
586
|
-
*
|
|
643
|
+
* Check if this decimal equals another value.
|
|
644
|
+
* @param other - Value to compare against
|
|
645
|
+
* @returns True if values are equal
|
|
587
646
|
*/
|
|
588
647
|
eq(other) {
|
|
589
648
|
return this.cmp(other) === 0;
|
|
590
649
|
}
|
|
591
650
|
/**
|
|
592
|
-
*
|
|
651
|
+
* Check if this decimal is greater than another value.
|
|
652
|
+
* @param other - Value to compare against
|
|
653
|
+
* @returns True if this is greater
|
|
593
654
|
*/
|
|
594
655
|
gt(other) {
|
|
595
656
|
return this.cmp(other) === 1;
|
|
596
657
|
}
|
|
597
658
|
/**
|
|
598
|
-
*
|
|
659
|
+
* Check if this decimal is greater than or equal to another value.
|
|
660
|
+
* @param other - Value to compare against
|
|
661
|
+
* @returns True if this is greater or equal
|
|
599
662
|
*/
|
|
600
663
|
gte(other) {
|
|
601
664
|
return this.cmp(other) >= 0;
|
|
602
665
|
}
|
|
603
666
|
/**
|
|
604
|
-
*
|
|
667
|
+
* Check if this decimal is less than another value.
|
|
668
|
+
* @param other - Value to compare against
|
|
669
|
+
* @returns True if this is less
|
|
605
670
|
*/
|
|
606
671
|
lt(other) {
|
|
607
672
|
return this.cmp(other) === -1;
|
|
608
673
|
}
|
|
609
674
|
/**
|
|
610
|
-
*
|
|
675
|
+
* Check if this decimal is less than or equal to another value.
|
|
676
|
+
* @param other - Value to compare against
|
|
677
|
+
* @returns True if this is less or equal
|
|
611
678
|
*/
|
|
612
679
|
lte(other) {
|
|
613
680
|
return this.cmp(other) <= 0;
|
|
614
681
|
}
|
|
615
682
|
/**
|
|
616
|
-
* Check if zero
|
|
683
|
+
* Check if this decimal is exactly zero.
|
|
684
|
+
* @returns True if value is zero
|
|
617
685
|
*/
|
|
618
686
|
isZero() {
|
|
619
687
|
return parseFloat(this.value) === 0;
|
|
620
688
|
}
|
|
621
689
|
/**
|
|
622
|
-
* Check if positive
|
|
690
|
+
* Check if this decimal is positive (greater than zero).
|
|
691
|
+
* @returns True if value is positive
|
|
623
692
|
*/
|
|
624
693
|
isPositive() {
|
|
625
694
|
return parseFloat(this.value) > 0;
|
|
626
695
|
}
|
|
627
696
|
/**
|
|
628
|
-
* Check if negative
|
|
697
|
+
* Check if this decimal is negative (less than zero).
|
|
698
|
+
* @returns True if value is negative
|
|
629
699
|
*/
|
|
630
700
|
isNegative() {
|
|
631
701
|
return parseFloat(this.value) < 0;
|
|
632
702
|
}
|
|
633
703
|
/**
|
|
634
|
-
* Convert to number
|
|
704
|
+
* Convert this decimal to a JavaScript number.
|
|
705
|
+
* @returns The numeric value
|
|
635
706
|
*/
|
|
636
707
|
toNumber() {
|
|
637
708
|
return parseFloat(this.value);
|
|
638
709
|
}
|
|
639
710
|
/**
|
|
640
|
-
* Convert to string
|
|
711
|
+
* Convert this decimal to its string representation.
|
|
712
|
+
* @returns The string value
|
|
641
713
|
*/
|
|
642
714
|
toString() {
|
|
643
715
|
return this.value;
|
|
644
716
|
}
|
|
645
717
|
/**
|
|
646
|
-
* Format with fixed decimal places
|
|
718
|
+
* Format this decimal with a fixed number of decimal places.
|
|
719
|
+
* @param decimals - Number of decimal places (default: 2)
|
|
720
|
+
* @returns Formatted string
|
|
647
721
|
*/
|
|
648
722
|
toFixed(decimals = 2) {
|
|
649
723
|
return parseFloat(this.value).toFixed(decimals);
|
|
650
724
|
}
|
|
651
725
|
/**
|
|
652
|
-
* Convert to JSON (string representation)
|
|
726
|
+
* Convert to JSON (returns string representation for serialization).
|
|
727
|
+
* @returns The string value for JSON serialization
|
|
653
728
|
*/
|
|
654
729
|
toJSON() {
|
|
655
730
|
return this.value;
|
|
656
731
|
}
|
|
657
732
|
/**
|
|
658
|
-
*
|
|
733
|
+
* Create a Decimal from a value (alias for constructor).
|
|
734
|
+
* @param value - The value to convert
|
|
735
|
+
* @returns A new Decimal instance
|
|
659
736
|
*/
|
|
660
737
|
static from(value) {
|
|
661
738
|
return new _Decimal(value);
|
|
662
739
|
}
|
|
663
740
|
/**
|
|
664
|
-
*
|
|
741
|
+
* Calculate the sum of an array of values.
|
|
742
|
+
* @param values - Array of values to sum
|
|
743
|
+
* @returns A new Decimal with the sum
|
|
665
744
|
*/
|
|
666
745
|
static sum(values) {
|
|
667
746
|
return values.reduce(
|
|
@@ -670,14 +749,19 @@ var Decimal = class _Decimal {
|
|
|
670
749
|
);
|
|
671
750
|
}
|
|
672
751
|
/**
|
|
673
|
-
*
|
|
752
|
+
* Calculate the average of an array of values.
|
|
753
|
+
* @param values - Array of values to average
|
|
754
|
+
* @returns A new Decimal with the average (0 if empty array)
|
|
674
755
|
*/
|
|
675
756
|
static avg(values) {
|
|
676
757
|
if (values.length === 0) return new _Decimal(0);
|
|
677
758
|
return _Decimal.sum(values).div(values.length);
|
|
678
759
|
}
|
|
679
760
|
/**
|
|
680
|
-
*
|
|
761
|
+
* Find the minimum value from the provided values.
|
|
762
|
+
* @param values - Values to compare
|
|
763
|
+
* @returns A new Decimal with the minimum value
|
|
764
|
+
* @throws Error if no values provided
|
|
681
765
|
*/
|
|
682
766
|
static min(...values) {
|
|
683
767
|
if (values.length === 0) throw new Error("No values provided");
|
|
@@ -687,7 +771,10 @@ var Decimal = class _Decimal {
|
|
|
687
771
|
}, new _Decimal(values[0]));
|
|
688
772
|
}
|
|
689
773
|
/**
|
|
690
|
-
*
|
|
774
|
+
* Find the maximum value from the provided values.
|
|
775
|
+
* @param values - Values to compare
|
|
776
|
+
* @returns A new Decimal with the maximum value
|
|
777
|
+
* @throws Error if no values provided
|
|
691
778
|
*/
|
|
692
779
|
static max(...values) {
|
|
693
780
|
if (values.length === 0) throw new Error("No values provided");
|
|
@@ -699,51 +786,73 @@ var Decimal = class _Decimal {
|
|
|
699
786
|
};
|
|
700
787
|
var DecimalUtils = {
|
|
701
788
|
/**
|
|
702
|
-
* Convert number to database decimal string
|
|
789
|
+
* Convert a number to a database-safe decimal string.
|
|
790
|
+
* @param value - The value to convert
|
|
791
|
+
* @returns The decimal string or null if value is null/undefined
|
|
703
792
|
*/
|
|
704
793
|
toDecimalString(value) {
|
|
705
794
|
if (value === null || value === void 0) return null;
|
|
706
795
|
return new Decimal(value).toString();
|
|
707
796
|
},
|
|
708
797
|
/**
|
|
709
|
-
* Convert database decimal string to number
|
|
798
|
+
* Convert a database decimal string to a JavaScript number.
|
|
799
|
+
* @param value - The decimal string from database
|
|
800
|
+
* @returns The numeric value (0 if null/undefined/empty)
|
|
710
801
|
*/
|
|
711
802
|
fromDecimalString(value) {
|
|
712
803
|
if (!value) return 0;
|
|
713
804
|
return new Decimal(value).toNumber();
|
|
714
805
|
},
|
|
715
806
|
/**
|
|
716
|
-
*
|
|
807
|
+
* Multiply two values with precise decimal arithmetic.
|
|
808
|
+
* @param a - First value
|
|
809
|
+
* @param b - Second value
|
|
810
|
+
* @returns The product as a string
|
|
717
811
|
*/
|
|
718
812
|
multiply(a, b) {
|
|
719
813
|
return new Decimal(a).mul(b).toString();
|
|
720
814
|
},
|
|
721
815
|
/**
|
|
722
|
-
*
|
|
816
|
+
* Add two values with precise decimal arithmetic.
|
|
817
|
+
* @param a - First value
|
|
818
|
+
* @param b - Second value
|
|
819
|
+
* @returns The sum as a string
|
|
723
820
|
*/
|
|
724
821
|
add(a, b) {
|
|
725
822
|
return new Decimal(a).add(b).toString();
|
|
726
823
|
},
|
|
727
824
|
/**
|
|
728
|
-
*
|
|
825
|
+
* Subtract two values with precise decimal arithmetic.
|
|
826
|
+
* @param a - Value to subtract from
|
|
827
|
+
* @param b - Value to subtract
|
|
828
|
+
* @returns The difference as a string
|
|
729
829
|
*/
|
|
730
830
|
subtract(a, b) {
|
|
731
831
|
return new Decimal(a).sub(b).toString();
|
|
732
832
|
},
|
|
733
833
|
/**
|
|
734
|
-
*
|
|
834
|
+
* Divide two values with precise decimal arithmetic.
|
|
835
|
+
* @param a - Dividend
|
|
836
|
+
* @param b - Divisor
|
|
837
|
+
* @returns The quotient as a string
|
|
735
838
|
*/
|
|
736
839
|
divide(a, b) {
|
|
737
840
|
return new Decimal(a).div(b).toString();
|
|
738
841
|
},
|
|
739
842
|
/**
|
|
740
|
-
* Format decimal for display
|
|
843
|
+
* Format a decimal value for display with fixed decimal places.
|
|
844
|
+
* @param value - The value to format
|
|
845
|
+
* @param decimalPlaces - Number of decimal places (default: 2)
|
|
846
|
+
* @returns Formatted string
|
|
741
847
|
*/
|
|
742
848
|
format(value, decimalPlaces = 2) {
|
|
743
849
|
return new Decimal(value).toFixed(decimalPlaces);
|
|
744
850
|
},
|
|
745
851
|
/**
|
|
746
|
-
* Format as currency
|
|
852
|
+
* Format a value as currency using Intl.NumberFormat.
|
|
853
|
+
* @param value - The value to format
|
|
854
|
+
* @param options - Currency formatting options
|
|
855
|
+
* @returns Formatted currency string
|
|
747
856
|
*/
|
|
748
857
|
formatCurrency(value, options = {}) {
|
|
749
858
|
const { currency = "USD", locale = "en-US", decimals = 2 } = options;
|
|
@@ -756,7 +865,10 @@ var DecimalUtils = {
|
|
|
756
865
|
}).format(num);
|
|
757
866
|
},
|
|
758
867
|
/**
|
|
759
|
-
*
|
|
868
|
+
* Prepare an object for database insert/update by converting numeric fields to decimal strings.
|
|
869
|
+
* @param data - The object to prepare
|
|
870
|
+
* @param decimalFields - Array of field names that should be converted to decimal strings
|
|
871
|
+
* @returns A new object with specified fields converted to decimal strings
|
|
760
872
|
*/
|
|
761
873
|
prepareForDatabase(data, decimalFields) {
|
|
762
874
|
const result = { ...data };
|
|
@@ -771,7 +883,10 @@ var DecimalUtils = {
|
|
|
771
883
|
return result;
|
|
772
884
|
},
|
|
773
885
|
/**
|
|
774
|
-
*
|
|
886
|
+
* Parse an object from database by converting decimal string fields to JavaScript numbers.
|
|
887
|
+
* @param data - The object from database
|
|
888
|
+
* @param decimalFields - Array of field names that should be converted from decimal strings
|
|
889
|
+
* @returns A new object with specified fields converted to numbers
|
|
775
890
|
*/
|
|
776
891
|
parseFromDatabase(data, decimalFields) {
|
|
777
892
|
const result = { ...data };
|