@bgord/tools 0.17.2 → 1.0.1
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/age-years.vo.d.ts +11 -0
- package/dist/age-years.vo.js +9 -0
- package/dist/age.vo.d.ts +11 -16
- package/dist/age.vo.js +20 -31
- package/dist/api-key.vo.d.ts +3 -1
- package/dist/api-key.vo.js +10 -5
- package/dist/basename.vo.d.ts +9 -9
- package/dist/basename.vo.js +22 -22
- package/dist/clock.vo.d.ts +10 -4
- package/dist/clock.vo.js +12 -14
- package/dist/date-calculator.service.d.ts +2 -1
- package/dist/date-formatter.service.d.ts +3 -4
- package/dist/date-range.vo.d.ts +7 -1
- package/dist/date-range.vo.js +5 -2
- package/dist/day-iso-id.vo.d.ts +5 -2
- package/dist/day-iso-id.vo.js +11 -7
- package/dist/day.vo.d.ts +4 -3
- package/dist/day.vo.js +18 -16
- package/dist/directory-path-absolute.vo.d.ts +10 -6
- package/dist/directory-path-absolute.vo.js +19 -17
- package/dist/directory-path-relative.vo.d.ts +10 -7
- package/dist/directory-path-relative.vo.js +18 -17
- package/dist/division-factor.vo.d.ts +7 -0
- package/dist/division-factor.vo.js +9 -0
- package/dist/duration-ms.vo.d.ts +6 -0
- package/dist/duration-ms.vo.js +3 -0
- package/dist/duration.service.d.ts +2 -14
- package/dist/duration.service.js +16 -35
- package/dist/email-mask.service.d.ts +1 -6
- package/dist/email-mask.service.js +6 -8
- package/dist/etags.vo.d.ts +4 -3
- package/dist/etags.vo.js +3 -3
- package/dist/extension.vo.d.ts +6 -4
- package/dist/extension.vo.js +15 -10
- package/dist/feature-flag-value.vo.d.ts +10 -0
- package/dist/feature-flag-value.vo.js +8 -0
- package/dist/feature-flag.vo.d.ts +1 -7
- package/dist/feature-flag.vo.js +1 -7
- package/dist/file-path-absolute-schema.vo.d.ts +10 -7
- package/dist/file-path-absolute-schema.vo.js +17 -17
- package/dist/file-path-relative-schema.vo.d.ts +10 -7
- package/dist/file-path-relative-schema.vo.js +14 -12
- package/dist/file-path.vo.d.ts +4 -4
- package/dist/file-path.vo.js +8 -8
- package/dist/filename-from-string.vo.d.ts +4 -2
- package/dist/filename-from-string.vo.js +10 -8
- package/dist/filename-suffix.vo.d.ts +7 -3
- package/dist/filename-suffix.vo.js +13 -7
- package/dist/filename.vo.d.ts +2 -0
- package/dist/filename.vo.js +8 -2
- package/dist/height-milimiters.vo.d.ts +6 -0
- package/dist/height-milimiters.vo.js +10 -0
- package/dist/height.vo.d.ts +3 -20
- package/dist/height.vo.js +11 -62
- package/dist/hour-format.service.js +1 -1
- package/dist/hour-schema.vo.d.ts +7 -0
- package/dist/hour-schema.vo.js +8 -0
- package/dist/hour.vo.d.ts +4 -3
- package/dist/hour.vo.js +8 -8
- package/dist/iban-mask.service.d.ts +1 -3
- package/dist/iban-mask.service.js +2 -2
- package/dist/iban-schema.vo.d.ts +7 -0
- package/dist/iban-schema.vo.js +10 -0
- package/dist/iban.vo.d.ts +4 -10
- package/dist/iban.vo.js +6 -13
- package/dist/image.vo.d.ts +6 -4
- package/dist/image.vo.js +13 -12
- package/dist/index.d.ts +24 -2
- package/dist/index.js +24 -2
- package/dist/language.vo.d.ts +2 -1
- package/dist/language.vo.js +6 -4
- package/dist/linear-regression.service.d.ts +27 -0
- package/dist/{simple-linear-regression.service.js → linear-regression.service.js} +17 -15
- package/dist/mean.service.d.ts +3 -1
- package/dist/mean.service.js +3 -4
- package/dist/mime-types.vo.d.ts +1 -2
- package/dist/mime-value.vo.d.ts +9 -0
- package/dist/mime-value.vo.js +9 -0
- package/dist/mime.vo.d.ts +11 -17
- package/dist/mime.vo.js +10 -27
- package/dist/min-max-scaler.service.d.ts +7 -5
- package/dist/min-max-scaler.service.js +12 -10
- package/dist/minute-schema.vo.d.ts +7 -0
- package/dist/minute-schema.vo.js +8 -0
- package/dist/minute.vo.d.ts +4 -3
- package/dist/minute.vo.js +8 -8
- package/dist/money-amount.vo.d.ts +7 -0
- package/dist/money-amount.vo.js +7 -0
- package/dist/money.vo.d.ts +9 -18
- package/dist/money.vo.js +14 -27
- package/dist/month-iso-id.vo.d.ts +4 -2
- package/dist/month-iso-id.vo.js +13 -7
- package/dist/month.vo.d.ts +4 -3
- package/dist/month.vo.js +21 -21
- package/dist/multiplication-factor.vo.d.ts +7 -0
- package/dist/multiplication-factor.vo.js +9 -0
- package/dist/object-key.vo.d.ts +9 -6
- package/dist/object-key.vo.js +20 -19
- package/dist/outlier-detector.service.d.ts +3 -1
- package/dist/outlier-detector.service.js +2 -2
- package/dist/package-version-schema.vo.d.ts +11 -0
- package/dist/package-version-schema.vo.js +15 -0
- package/dist/package-version.vo.d.ts +11 -20
- package/dist/package-version.vo.js +11 -20
- package/dist/pagination-page.vo.d.ts +6 -0
- package/dist/pagination-page.vo.js +7 -0
- package/dist/pagination-skip.vo.d.ts +7 -0
- package/dist/pagination-skip.vo.js +9 -0
- package/dist/pagination-take.vo.d.ts +7 -0
- package/dist/pagination-take.vo.js +9 -0
- package/dist/pagination.service.d.ts +3 -8
- package/dist/pagination.service.js +5 -12
- package/dist/percentage.service.d.ts +3 -1
- package/dist/percentage.service.js +2 -2
- package/dist/population-standard-deviation.service.d.ts +3 -1
- package/dist/population-standard-deviation.service.js +5 -4
- package/dist/quarter-iso-id.vo.d.ts +3 -2
- package/dist/quarter-iso-id.vo.js +7 -9
- package/dist/quarter.vo.d.ts +2 -1
- package/dist/quarter.vo.js +10 -7
- package/dist/random.service.d.ts +3 -4
- package/dist/random.service.js +5 -11
- package/dist/rate-limiter.service.d.ts +2 -2
- package/dist/rate-limiter.service.js +8 -8
- package/dist/reordering-item-position-value.vo.d.ts +6 -0
- package/dist/reordering-item-position-value.vo.js +6 -0
- package/dist/reordering.service.d.ts +7 -23
- package/dist/reordering.service.js +15 -24
- package/dist/revision-value.vo.d.ts +7 -0
- package/dist/revision-value.vo.js +6 -0
- package/dist/revision.vo.d.ts +6 -13
- package/dist/revision.vo.js +10 -22
- package/dist/rounding.adapter.d.ts +7 -2
- package/dist/rounding.adapter.js +13 -5
- package/dist/size-bytes.vo.d.ts +6 -0
- package/dist/size-bytes.vo.js +7 -0
- package/dist/size.vo.d.ts +15 -15
- package/dist/size.vo.js +41 -51
- package/dist/stopwatch.service.d.ts +3 -1
- package/dist/stopwatch.service.js +2 -2
- package/dist/sum.service.js +8 -8
- package/dist/thousands-separator.service.js +4 -1
- package/dist/time.service.d.ts +8 -0
- package/dist/time.service.js +13 -0
- package/dist/timestamp.vo.d.ts +1 -1
- package/dist/timestamp.vo.js +4 -5
- package/dist/timezone.vo.d.ts +4 -1
- package/dist/timezone.vo.js +12 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/week-iso-id.vo.d.ts +4 -2
- package/dist/week-iso-id.vo.js +15 -9
- package/dist/week.vo.d.ts +4 -3
- package/dist/week.vo.js +21 -22
- package/dist/weekday.vo.d.ts +1 -1
- package/dist/weekday.vo.js +6 -8
- package/dist/weight-grams.vo.d.ts +7 -0
- package/dist/weight-grams.vo.js +7 -0
- package/dist/weight.vo.d.ts +12 -35
- package/dist/weight.vo.js +23 -72
- package/dist/year-iso-id.vo.d.ts +3 -2
- package/dist/year-iso-id.vo.js +6 -4
- package/dist/year.vo.d.ts +5 -6
- package/dist/year.vo.js +21 -26
- package/dist/z-score.service.d.ts +3 -1
- package/dist/z-score.service.js +2 -2
- package/package.json +4 -4
- package/readme.md +21 -2
- package/src/age-years.vo.ts +14 -0
- package/src/age.vo.ts +22 -35
- package/src/api-key.vo.ts +11 -5
- package/src/basename.vo.ts +24 -22
- package/src/clock.vo.ts +16 -17
- package/src/date-calculator.service.ts +2 -1
- package/src/date-formatter.service.ts +4 -5
- package/src/date-range.vo.ts +6 -2
- package/src/day-iso-id.vo.ts +12 -8
- package/src/day.vo.ts +27 -24
- package/src/directory-path-absolute.vo.ts +23 -18
- package/src/directory-path-relative.vo.ts +21 -18
- package/src/division-factor.vo.ts +13 -0
- package/src/duration-ms.vo.ts +7 -0
- package/src/duration.service.ts +16 -40
- package/src/email-mask.service.ts +7 -15
- package/src/etags.vo.ts +4 -5
- package/src/extension.vo.ts +17 -10
- package/src/feature-flag-value.vo.ts +12 -0
- package/src/feature-flag.vo.ts +1 -9
- package/src/file-path-absolute-schema.vo.ts +18 -17
- package/src/file-path-relative-schema.vo.ts +15 -12
- package/src/file-path.vo.ts +8 -8
- package/src/filename-from-string.vo.ts +12 -9
- package/src/filename-suffix.vo.ts +14 -7
- package/src/filename.vo.ts +11 -2
- package/src/height-milimiters.vo.ts +12 -0
- package/src/height.vo.ts +12 -83
- package/src/hour-format.service.ts +2 -1
- package/src/hour-schema.vo.ts +12 -0
- package/src/hour.vo.ts +12 -12
- package/src/iban-mask.service.ts +3 -5
- package/src/iban-schema.vo.ts +15 -0
- package/src/iban.vo.ts +9 -22
- package/src/image.vo.ts +14 -12
- package/src/index.ts +24 -2
- package/src/language.vo.ts +7 -4
- package/src/linear-regression.service.ts +71 -0
- package/src/mean.service.ts +3 -5
- package/src/mime-types.vo.ts +1 -3
- package/src/mime-value.vo.ts +12 -0
- package/src/mime.vo.ts +12 -33
- package/src/min-max-scaler.service.ts +13 -11
- package/src/minute-schema.vo.ts +12 -0
- package/src/minute.vo.ts +12 -12
- package/src/money-amount.vo.ts +11 -0
- package/src/money.vo.ts +20 -38
- package/src/month-iso-id.vo.ts +14 -7
- package/src/month.vo.ts +25 -24
- package/src/multiplication-factor.vo.ts +13 -0
- package/src/object-key.vo.ts +25 -21
- package/src/outlier-detector.service.ts +2 -2
- package/src/package-version-schema.vo.ts +21 -0
- package/src/package-version.vo.ts +17 -33
- package/src/pagination-page.vo.ts +11 -0
- package/src/pagination-skip.vo.ts +13 -0
- package/src/pagination-take.vo.ts +13 -0
- package/src/pagination.service.ts +5 -22
- package/src/percentage.service.ts +2 -2
- package/src/population-standard-deviation.service.ts +5 -4
- package/src/quarter-iso-id.vo.ts +7 -10
- package/src/quarter.vo.ts +14 -9
- package/src/random.service.ts +6 -9
- package/src/rate-limiter.service.ts +9 -8
- package/src/reordering-item-position-value.vo.ts +10 -0
- package/src/reordering.service.ts +19 -28
- package/src/revision-value.vo.ts +10 -0
- package/src/revision.vo.ts +10 -25
- package/src/rounding.adapter.ts +16 -3
- package/src/size-bytes.vo.ts +11 -0
- package/src/size.vo.ts +43 -54
- package/src/stopwatch.service.ts +3 -3
- package/src/sum.service.ts +8 -8
- package/src/thousands-separator.service.ts +4 -1
- package/src/time.service.ts +15 -0
- package/src/timestamp.vo.ts +4 -5
- package/src/timezone.vo.ts +12 -6
- package/src/week-iso-id.vo.ts +16 -12
- package/src/week.vo.ts +26 -28
- package/src/weekday.vo.ts +6 -9
- package/src/weight-grams.vo.ts +11 -0
- package/src/weight.vo.ts +28 -85
- package/src/year-iso-id.vo.ts +7 -4
- package/src/year.vo.ts +27 -33
- package/src/z-score.service.ts +2 -2
- package/dist/simple-linear-regression.service.d.ts +0 -25
- package/dist/streak-calculator.service.d.ts +0 -13
- package/dist/streak-calculator.service.js +0 -22
- package/src/simple-linear-regression.service.ts +0 -69
- package/src/streak-calculator.service.ts +0 -32
package/dist/object-key.vo.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
export declare const ObjectKeyError: {
|
|
3
|
+
readonly Type: "object.key.type";
|
|
4
|
+
readonly LeadingSlash: "object.key.leading.slash";
|
|
5
|
+
readonly Empty: "object.key.empty";
|
|
6
|
+
readonly TooLong: "object.key.too.long";
|
|
7
|
+
readonly BadChars: "object.key.bad.chars";
|
|
8
|
+
readonly DotSegments: "object.key.dot.segments";
|
|
9
|
+
};
|
|
10
|
+
export declare const ObjectKey: z.core.$ZodBranded<z.ZodString, "ObjectKey">;
|
|
8
11
|
export type ObjectKeyType = z.infer<typeof ObjectKey>;
|
package/dist/object-key.vo.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
export const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
export const ObjectKeyError = {
|
|
3
|
+
Type: "object.key.type",
|
|
4
|
+
LeadingSlash: "object.key.leading.slash",
|
|
5
|
+
Empty: "object.key.empty",
|
|
6
|
+
TooLong: "object.key.too.long",
|
|
7
|
+
BadChars: "object.key.bad.chars",
|
|
8
|
+
DotSegments: "object.key.dot.segments",
|
|
9
|
+
};
|
|
10
|
+
// Lowercase letters, digits, dots, underscores, and hyphens
|
|
11
|
+
const OBJECT_KEY_SEGMENT_CHARS_WHITELIST = /^[a-z0-9._-]+$/;
|
|
12
|
+
const DOT_SEGMENTS = [".", ".."];
|
|
10
13
|
export const ObjectKey = z
|
|
11
|
-
.string()
|
|
12
|
-
.
|
|
13
|
-
|
|
14
|
-
.refine((value) => value.
|
|
15
|
-
|
|
16
|
-
.refine((value) =>
|
|
17
|
-
.
|
|
18
|
-
.refine((value) => value
|
|
19
|
-
.
|
|
20
|
-
.every((segment) => SEGMENT_ALLOWED_REGEX.test(segment) && segment !== "." && segment !== ".."), ObjectKeyBadSegmentsError)
|
|
21
|
-
.brand("object_key");
|
|
14
|
+
.string(ObjectKeyError.Type)
|
|
15
|
+
.min(1, ObjectKeyError.Empty)
|
|
16
|
+
.max(256, ObjectKeyError.TooLong)
|
|
17
|
+
.refine((value) => !value.startsWith("/"), ObjectKeyError.LeadingSlash)
|
|
18
|
+
// Allow only known characters for users/avatars/1234567890/avatar.png segments
|
|
19
|
+
.refine((value) => value.split("/").every((segment) => OBJECT_KEY_SEGMENT_CHARS_WHITELIST.test(segment)), ObjectKeyError.BadChars)
|
|
20
|
+
// Reject object keys like users/./avatar.png or users/../avatar.png
|
|
21
|
+
.refine((value) => value.split("/").every((segment) => !DOT_SEGMENTS.includes(segment)), ObjectKeyError.DotSegments)
|
|
22
|
+
.brand("ObjectKey");
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const OutlierDetectorError: {
|
|
2
|
+
readonly NotEnoughValues: "outlier.detector.not.enough.values";
|
|
3
|
+
};
|
|
2
4
|
export declare class OutlierDetector {
|
|
3
5
|
private readonly zScore;
|
|
4
6
|
private readonly threshold;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ZScore } from "./z-score.service";
|
|
2
|
-
export const
|
|
2
|
+
export const OutlierDetectorError = { NotEnoughValues: "outlier.detector.not.enough.values" };
|
|
3
3
|
export class OutlierDetector {
|
|
4
4
|
zScore;
|
|
5
5
|
threshold;
|
|
6
6
|
constructor(values, threshold) {
|
|
7
7
|
if (values.length < 2)
|
|
8
|
-
throw new Error(
|
|
8
|
+
throw new Error(OutlierDetectorError.NotEnoughValues);
|
|
9
9
|
this.zScore = new ZScore(values);
|
|
10
10
|
this.threshold = Math.abs(threshold);
|
|
11
11
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
export declare const PackageVersionSchemaError: {
|
|
3
|
+
readonly Type: "package.version.schema.error";
|
|
4
|
+
readonly BadChars: "package.version.schema.bad.chars";
|
|
5
|
+
};
|
|
6
|
+
export declare const PackageVersionSchema: z.core.$ZodBranded<z.ZodPipe<z.ZodString, z.ZodTransform<{
|
|
7
|
+
major: number;
|
|
8
|
+
minor: number;
|
|
9
|
+
patch: number;
|
|
10
|
+
}, string>>, "PackageVersionSchema">;
|
|
11
|
+
export type PackageVersionSchemaType = z.infer<typeof PackageVersionSchema>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
export const PackageVersionSchemaError = {
|
|
3
|
+
Type: "package.version.schema.error",
|
|
4
|
+
BadChars: "package.version.schema.bad.chars",
|
|
5
|
+
};
|
|
6
|
+
// v, 1-4 digits, dot, 1-4 digits, dot, 1-4 digits - () for capturing groups
|
|
7
|
+
const PACKAGE_VERSIONS_CHARS_WHITELIST = /^v([0-9]{1,4})\.([0-9]{1,4})\.([0-9]{1,4})$/;
|
|
8
|
+
export const PackageVersionSchema = z
|
|
9
|
+
.string(PackageVersionSchemaError.Type)
|
|
10
|
+
.regex(PACKAGE_VERSIONS_CHARS_WHITELIST, PackageVersionSchemaError.BadChars)
|
|
11
|
+
.transform((value) => {
|
|
12
|
+
const match = PACKAGE_VERSIONS_CHARS_WHITELIST.exec(value);
|
|
13
|
+
return { major: Number(match[1]), minor: Number(match[2]), patch: Number(match[3]) };
|
|
14
|
+
})
|
|
15
|
+
.brand("PackageVersionSchema");
|
|
@@ -1,24 +1,15 @@
|
|
|
1
|
-
import { z } from "zod/v4";
|
|
2
|
-
type MajorType = number;
|
|
3
|
-
type MinorType = number;
|
|
4
|
-
type PatchType = number;
|
|
5
|
-
export declare const PackageVersionError: {
|
|
6
|
-
readonly error: "package.version.error";
|
|
7
|
-
};
|
|
8
|
-
export declare const PackageVersionValue: z.core.$ZodBranded<z.ZodPipe<z.ZodString, z.ZodTransform<{
|
|
9
|
-
major: number;
|
|
10
|
-
minor: number;
|
|
11
|
-
patch: number;
|
|
12
|
-
}, string>>, "PackageVersionValue">;
|
|
13
|
-
export type PackageVersionValueType = z.infer<typeof PackageVersionValue>;
|
|
14
1
|
export declare class PackageVersion {
|
|
15
|
-
readonly major
|
|
16
|
-
readonly minor
|
|
17
|
-
readonly patch
|
|
18
|
-
constructor(major:
|
|
2
|
+
private readonly major;
|
|
3
|
+
private readonly minor;
|
|
4
|
+
private readonly patch;
|
|
5
|
+
constructor(major: number, minor: number, patch: number);
|
|
6
|
+
static fromStringWithV(candidate: string): PackageVersion;
|
|
7
|
+
static fromString(candidate: string): PackageVersion;
|
|
19
8
|
isGreaterThanOrEqual(another: PackageVersion): boolean;
|
|
20
9
|
toString(): string;
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
toJSON(): {
|
|
11
|
+
major: number;
|
|
12
|
+
minor: number;
|
|
13
|
+
patch: number;
|
|
14
|
+
};
|
|
23
15
|
}
|
|
24
|
-
export {};
|
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export const PackageVersionError = { error: "package.version.error" };
|
|
3
|
-
export const PackageVersionValue = z
|
|
4
|
-
.string(PackageVersionError)
|
|
5
|
-
.regex(/^v(\d+)\.(\d+)\.(\d+)$/, PackageVersionError)
|
|
6
|
-
.transform((value) => {
|
|
7
|
-
const match = /^v(\d+)\.(\d+)\.(\d+)$/.exec(value);
|
|
8
|
-
const major = Number(match[1]);
|
|
9
|
-
const minor = Number(match[2]);
|
|
10
|
-
const patch = Number(match[3]);
|
|
11
|
-
return { major, minor, patch };
|
|
12
|
-
})
|
|
13
|
-
.brand("PackageVersionValue");
|
|
1
|
+
import { PackageVersionSchema } from "./package-version-schema.vo";
|
|
14
2
|
export class PackageVersion {
|
|
15
3
|
major;
|
|
16
4
|
minor;
|
|
@@ -20,6 +8,14 @@ export class PackageVersion {
|
|
|
20
8
|
this.minor = minor;
|
|
21
9
|
this.patch = patch;
|
|
22
10
|
}
|
|
11
|
+
static fromStringWithV(candidate) {
|
|
12
|
+
const version = PackageVersionSchema.parse(candidate);
|
|
13
|
+
return new PackageVersion(version.major, version.minor, version.patch);
|
|
14
|
+
}
|
|
15
|
+
static fromString(candidate) {
|
|
16
|
+
const version = PackageVersionSchema.parse(`v${candidate}`);
|
|
17
|
+
return new PackageVersion(version.major, version.minor, version.patch);
|
|
18
|
+
}
|
|
23
19
|
isGreaterThanOrEqual(another) {
|
|
24
20
|
if (this.major > another.major)
|
|
25
21
|
return true;
|
|
@@ -38,12 +34,7 @@ export class PackageVersion {
|
|
|
38
34
|
toString() {
|
|
39
35
|
return `${this.major}.${this.minor}.${this.patch}`;
|
|
40
36
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return new PackageVersion(parsed.major, parsed.minor, parsed.patch);
|
|
44
|
-
}
|
|
45
|
-
static fromString(value) {
|
|
46
|
-
const parsed = PackageVersionValue.parse(`v${value}`);
|
|
47
|
-
return new PackageVersion(parsed.major, parsed.minor, parsed.patch);
|
|
37
|
+
toJSON() {
|
|
38
|
+
return { major: this.major, minor: this.minor, patch: this.patch };
|
|
48
39
|
}
|
|
49
40
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
export declare const PaginationPageError: {
|
|
3
|
+
readonly Type: "pagination.page.Type";
|
|
4
|
+
};
|
|
5
|
+
export declare const Page: z.ZodDefault<z.ZodPipe<z.ZodCoercedNumber<unknown>, z.ZodTransform<number, number>>>;
|
|
6
|
+
export type PageType = z.infer<typeof Page>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
export const PaginationSkipError = {
|
|
3
|
+
Type: "pagination.skip.type",
|
|
4
|
+
Invalid: "pagination.skip.invalid",
|
|
5
|
+
};
|
|
6
|
+
export const Skip = z
|
|
7
|
+
.number(PaginationSkipError.Type)
|
|
8
|
+
.int(PaginationSkipError.Type)
|
|
9
|
+
.gte(0, PaginationSkipError.Invalid);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
export const PaginationTakeError = {
|
|
3
|
+
Type: "pagination.take.type",
|
|
4
|
+
Invalid: "pagination.take.invalid",
|
|
5
|
+
};
|
|
6
|
+
export const Take = z
|
|
7
|
+
.number(PaginationTakeError.Type)
|
|
8
|
+
.int(PaginationTakeError.Type)
|
|
9
|
+
.gte(1, PaginationTakeError.Invalid);
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
type TakeType
|
|
4
|
-
declare const Skip: z.ZodNumber;
|
|
5
|
-
type SkipType = z.infer<typeof Skip>;
|
|
6
|
-
declare const Page: z.ZodDefault<z.ZodPipe<z.ZodCoercedNumber<unknown>, z.ZodTransform<number, number>>>;
|
|
7
|
-
export type PageType = z.infer<typeof Page>;
|
|
1
|
+
import { type PageType } from "./pagination-page.vo";
|
|
2
|
+
import { type SkipType } from "./pagination-skip.vo";
|
|
3
|
+
import { type TakeType } from "./pagination-take.vo";
|
|
8
4
|
export type PaginationType = {
|
|
9
5
|
values: {
|
|
10
6
|
take: TakeType;
|
|
@@ -55,4 +51,3 @@ export type Paged<T> = {
|
|
|
55
51
|
total: TotalType;
|
|
56
52
|
};
|
|
57
53
|
};
|
|
58
|
-
export {};
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const Take = z.number(PaginationTakeError).int(PaginationTakeError).gte(1, PaginationTakeError);
|
|
6
|
-
const Skip = z.number(PaginationSkipError).int(PaginationSkipError).gte(0, PaginationSkipError);
|
|
7
|
-
const Page = z.coerce
|
|
8
|
-
.number(PaginationPageError)
|
|
9
|
-
.int(PaginationPageError)
|
|
10
|
-
.transform((value) => (value <= 0 ? 1 : value))
|
|
11
|
-
.default(1);
|
|
1
|
+
import { Page } from "./pagination-page.vo";
|
|
2
|
+
import { Skip } from "./pagination-skip.vo";
|
|
3
|
+
import { Take } from "./pagination-take.vo";
|
|
4
|
+
import { RoundUp } from "./rounding.adapter";
|
|
12
5
|
export class Pagination {
|
|
13
6
|
static parse(values, _take) {
|
|
14
7
|
const page = Page.parse(values.page);
|
|
@@ -31,7 +24,7 @@ export class Pagination {
|
|
|
31
24
|
return Pagination.getLastPage(config) <= config.pagination.page;
|
|
32
25
|
}
|
|
33
26
|
static getLastPage(config) {
|
|
34
|
-
return Page.parse(
|
|
27
|
+
return Page.parse(new RoundUp().round(config.total / config.pagination.values.take));
|
|
35
28
|
}
|
|
36
29
|
static empty = {
|
|
37
30
|
result: [],
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { RoundingPort } from "./rounding.port";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const PercentageError: {
|
|
3
|
+
readonly InvalidDenominator: "percentage.invalid.denominator";
|
|
4
|
+
};
|
|
3
5
|
export declare class Percentage {
|
|
4
6
|
static of(numerator: number, denominator: number, rounding?: RoundingPort): number;
|
|
5
7
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { RoundToNearest } from "./rounding.adapter";
|
|
2
|
-
export const
|
|
2
|
+
export const PercentageError = { InvalidDenominator: "percentage.invalid.denominator" };
|
|
3
3
|
export class Percentage {
|
|
4
4
|
static of(numerator, denominator, rounding = new RoundToNearest()) {
|
|
5
5
|
if (denominator === 0)
|
|
6
|
-
throw new Error(
|
|
6
|
+
throw new Error(PercentageError.InvalidDenominator);
|
|
7
7
|
if (numerator === 0)
|
|
8
8
|
return 0;
|
|
9
9
|
return rounding.round((numerator / denominator) * 100);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { RoundingPort } from "./rounding.port";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const PopulationStandardDeviationError: {
|
|
3
|
+
readonly NotEnoughValues: "population.standard.deviation.not.enough.values";
|
|
4
|
+
};
|
|
3
5
|
export declare class PopulationStandardDeviation {
|
|
4
6
|
static calculate(values: number[], rounding?: RoundingPort): number;
|
|
5
7
|
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { Mean } from "./mean.service";
|
|
2
2
|
import { RoundToDecimal } from "./rounding.adapter";
|
|
3
3
|
import { Sum } from "./sum.service";
|
|
4
|
-
export const
|
|
4
|
+
export const PopulationStandardDeviationError = {
|
|
5
|
+
NotEnoughValues: "population.standard.deviation.not.enough.values",
|
|
6
|
+
};
|
|
5
7
|
export class PopulationStandardDeviation {
|
|
6
8
|
static calculate(values, rounding = new RoundToDecimal(2)) {
|
|
7
9
|
if (values.length < 2)
|
|
8
|
-
throw new Error(
|
|
10
|
+
throw new Error(PopulationStandardDeviationError.NotEnoughValues);
|
|
9
11
|
const mean = Mean.calculate(values);
|
|
10
12
|
const count = values.length;
|
|
11
13
|
const squaredDifferences = values.map((value) => (value - mean) ** 2);
|
|
12
|
-
const
|
|
13
|
-
const variance = sumOfSquaredDifferences / count;
|
|
14
|
+
const variance = Sum.of(squaredDifferences) / count;
|
|
14
15
|
return rounding.round(Math.sqrt(variance));
|
|
15
16
|
}
|
|
16
17
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
2
|
export declare const QuarterIsoIdError: {
|
|
3
|
-
readonly
|
|
3
|
+
readonly Type: "quarter.iso.id.type";
|
|
4
|
+
readonly BadChars: "quarter.iso.id.bad.chars";
|
|
4
5
|
};
|
|
5
|
-
export declare const QuarterIsoId: z.ZodString
|
|
6
|
+
export declare const QuarterIsoId: z.core.$ZodBranded<z.ZodString, "QuarterIsoId">;
|
|
6
7
|
export type QuarterIsoIdType = z.infer<typeof QuarterIsoId>;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
export const QuarterIsoIdError = {
|
|
2
|
+
export const QuarterIsoIdError = {
|
|
3
|
+
Type: "quarter.iso.id.type",
|
|
4
|
+
BadChars: "quarter.iso.id.bad.chars",
|
|
5
|
+
};
|
|
3
6
|
export const QuarterIsoId = z
|
|
4
|
-
.string(QuarterIsoIdError)
|
|
5
|
-
.regex(/^\d{4}-Q[1-4]$/, QuarterIsoIdError)
|
|
6
|
-
.
|
|
7
|
-
const [yearPart, quarterPart] = value.split("-Q");
|
|
8
|
-
const year = Number(yearPart);
|
|
9
|
-
const quarter = Number(quarterPart);
|
|
10
|
-
return Number.isInteger(year) && Number.isInteger(quarter) && quarter >= 1 && quarter <= 4;
|
|
11
|
-
}, QuarterIsoIdError);
|
|
7
|
+
.string(QuarterIsoIdError.Type)
|
|
8
|
+
.regex(/^\d{4}-Q[1-4]$/, QuarterIsoIdError.BadChars)
|
|
9
|
+
.brand("QuarterIsoId");
|
package/dist/quarter.vo.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ import { DateRange } from "./date-range.vo";
|
|
|
2
2
|
import { type QuarterIsoIdType } from "./quarter-iso-id.vo";
|
|
3
3
|
import { type TimestampType } from "./timestamp.vo";
|
|
4
4
|
export declare class Quarter extends DateRange {
|
|
5
|
-
toIsoId(): QuarterIsoIdType;
|
|
6
5
|
static fromTimestamp(timestamp: TimestampType): Quarter;
|
|
7
6
|
static fromNow(now: TimestampType): Quarter;
|
|
8
7
|
static fromIsoId(isoId: QuarterIsoIdType): Quarter;
|
|
8
|
+
toIsoId(): QuarterIsoIdType;
|
|
9
|
+
toString(): string;
|
|
9
10
|
}
|
package/dist/quarter.vo.js
CHANGED
|
@@ -3,11 +3,6 @@ import { DateRange } from "./date-range.vo";
|
|
|
3
3
|
import { QuarterIsoId } from "./quarter-iso-id.vo";
|
|
4
4
|
import { Timestamp } from "./timestamp.vo";
|
|
5
5
|
export class Quarter extends DateRange {
|
|
6
|
-
toIsoId() {
|
|
7
|
-
const year = getYear(this.getStart());
|
|
8
|
-
const quarter = getQuarter(this.getStart());
|
|
9
|
-
return `${year}-Q${quarter}`;
|
|
10
|
-
}
|
|
11
6
|
static fromTimestamp(timestamp) {
|
|
12
7
|
const start = Timestamp.parse(startOfQuarter(timestamp).getTime());
|
|
13
8
|
const end = Timestamp.parse(endOfQuarter(timestamp).getTime());
|
|
@@ -18,7 +13,15 @@ export class Quarter extends DateRange {
|
|
|
18
13
|
}
|
|
19
14
|
static fromIsoId(isoId) {
|
|
20
15
|
const [year, quarter] = QuarterIsoId.parse(isoId).split("-Q").map(Number);
|
|
21
|
-
const reference = setQuarter(
|
|
22
|
-
return Quarter.fromTimestamp(Timestamp.parse(reference
|
|
16
|
+
const reference = setQuarter(Date.UTC(year), quarter).getTime();
|
|
17
|
+
return Quarter.fromTimestamp(Timestamp.parse(reference));
|
|
18
|
+
}
|
|
19
|
+
toIsoId() {
|
|
20
|
+
const year = getYear(this.getStart());
|
|
21
|
+
const quarter = getQuarter(this.getStart());
|
|
22
|
+
return QuarterIsoId.parse(`${year}-Q${quarter}`);
|
|
23
|
+
}
|
|
24
|
+
toString() {
|
|
25
|
+
return this.toIsoId();
|
|
23
26
|
}
|
|
24
27
|
}
|
package/dist/random.service.d.ts
CHANGED
|
@@ -2,10 +2,9 @@ type RandomGenerateConfigType = {
|
|
|
2
2
|
min: number;
|
|
3
3
|
max: number;
|
|
4
4
|
};
|
|
5
|
-
export declare const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export declare const RandomMinGreaterThanMaxError: "random.min.greater.than.max";
|
|
5
|
+
export declare const RandomError: {
|
|
6
|
+
readonly MinMax: "random.min.max";
|
|
7
|
+
};
|
|
9
8
|
export declare class Random {
|
|
10
9
|
private static readonly DEFAULT_MIN;
|
|
11
10
|
private static readonly DEFAULT_MAX;
|
package/dist/random.service.js
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
export const
|
|
3
|
-
export const RandomMinEqualsMaxError = "random.min.equals.max";
|
|
4
|
-
export const RandomMinGreaterThanMaxError = "random.min.greater.than.max";
|
|
1
|
+
import { RoundDown } from "./rounding.adapter";
|
|
2
|
+
export const RandomError = { MinMax: "random.min.max" };
|
|
5
3
|
export class Random {
|
|
6
4
|
static DEFAULT_MIN = 0;
|
|
7
5
|
static DEFAULT_MAX = 1;
|
|
8
6
|
static generate(config) {
|
|
9
7
|
const min = config ? config.min : Random.DEFAULT_MIN;
|
|
10
8
|
const max = config ? config.max : Random.DEFAULT_MAX;
|
|
11
|
-
if (!Number.isInteger(min))
|
|
12
|
-
throw new Error(RandomMinNotIntegerError);
|
|
13
|
-
if (!Number.isInteger(max))
|
|
14
|
-
throw new Error(RandomMaxNotIntegerError);
|
|
15
9
|
if (min === max)
|
|
16
|
-
throw new Error(
|
|
10
|
+
throw new Error(RandomError.MinMax);
|
|
17
11
|
if (min > max)
|
|
18
|
-
throw new Error(
|
|
19
|
-
return
|
|
12
|
+
throw new Error(RandomError.MinMax);
|
|
13
|
+
return new RoundDown().round(Math.random() * (max - min + 1)) + min;
|
|
20
14
|
}
|
|
21
15
|
}
|
|
@@ -10,8 +10,8 @@ type RateLimiterResultErrorType = {
|
|
|
10
10
|
type RateLimiterResultType = RateLimiterResultSuccessType | RateLimiterResultErrorType;
|
|
11
11
|
export declare class RateLimiter {
|
|
12
12
|
private readonly duration;
|
|
13
|
-
private
|
|
13
|
+
private lastInvocation;
|
|
14
14
|
constructor(duration: Duration);
|
|
15
|
-
verify(
|
|
15
|
+
verify(now: TimestampType): RateLimiterResultType;
|
|
16
16
|
}
|
|
17
17
|
export {};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { Duration } from "./duration.service";
|
|
2
2
|
export class RateLimiter {
|
|
3
3
|
duration;
|
|
4
|
-
|
|
4
|
+
lastInvocation = null;
|
|
5
5
|
constructor(duration) {
|
|
6
6
|
this.duration = duration;
|
|
7
7
|
}
|
|
8
|
-
verify(
|
|
9
|
-
if (this.
|
|
10
|
-
this.
|
|
8
|
+
verify(now) {
|
|
9
|
+
if (this.lastInvocation == null) {
|
|
10
|
+
this.lastInvocation = now;
|
|
11
11
|
return { allowed: true };
|
|
12
12
|
}
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
15
|
-
this.
|
|
13
|
+
const nextAllowedTimestamp = this.lastInvocation + this.duration.ms;
|
|
14
|
+
if (nextAllowedTimestamp <= now) {
|
|
15
|
+
this.lastInvocation = now;
|
|
16
16
|
return { allowed: true };
|
|
17
17
|
}
|
|
18
|
-
const remainingDelta =
|
|
18
|
+
const remainingDelta = nextAllowedTimestamp - now;
|
|
19
19
|
return { allowed: false, remaining: Duration.Ms(remainingDelta) };
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
export declare const ReorderingItemPositionValueError: {
|
|
3
|
+
readonly Invalid: "reordering.position.type";
|
|
4
|
+
};
|
|
5
|
+
export declare const ReorderingItemPositionValue: z.ZodNumber;
|
|
6
|
+
export type ReorderingItemPositionValueType = z.infer<typeof ReorderingItemPositionValue>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
export const ReorderingItemPositionValueError = { Invalid: "reordering.position.type" };
|
|
3
|
+
export const ReorderingItemPositionValue = z
|
|
4
|
+
.number(ReorderingItemPositionValueError.Invalid)
|
|
5
|
+
.int(ReorderingItemPositionValueError.Invalid)
|
|
6
|
+
.min(0, ReorderingItemPositionValueError.Invalid);
|
|
@@ -1,28 +1,12 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { type ReorderingItemPositionValueType } from "./reordering-item-position-value.vo";
|
|
3
|
+
export declare const ReorderingError: {
|
|
4
|
+
CannotFindItem: string;
|
|
5
|
+
CannotFindCurrent: string;
|
|
6
|
+
CannotFindTarget: string;
|
|
4
7
|
};
|
|
5
|
-
export declare const
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
export declare const ReorderingCannotFindCurrentError: {
|
|
9
|
-
readonly error: "reordering.current_item.not_found";
|
|
10
|
-
};
|
|
11
|
-
export declare const ReorderingCannotFindTargetError: {
|
|
12
|
-
readonly error: "reordering.target_item.not_found";
|
|
13
|
-
};
|
|
14
|
-
export declare const ReorderingCorrelationIdError: {
|
|
15
|
-
readonly error: "reordering.correlation_id.invalid";
|
|
16
|
-
};
|
|
17
|
-
export declare const ReorderingItemIdError: {
|
|
18
|
-
readonly error: "reordering.item_id.invalid";
|
|
19
|
-
};
|
|
20
|
-
export declare const ReorderingItemPositionValue: z.ZodNumber;
|
|
21
|
-
export type ReorderingItemPositionValueType = z.infer<typeof ReorderingItemPositionValue>;
|
|
22
|
-
export declare const ReorderingCorrelationId: z.ZodString;
|
|
23
|
-
export type ReorderingCorrelationIdType = z.infer<typeof ReorderingCorrelationId>;
|
|
24
|
-
export declare const ReorderingItemId: z.ZodString;
|
|
25
|
-
export type ReorderingItemIdType = z.infer<typeof ReorderingItemId>;
|
|
8
|
+
export declare const ReorderingId: z.ZodString;
|
|
9
|
+
export type ReorderingItemIdType = z.infer<typeof ReorderingId>;
|
|
26
10
|
export declare const Reordering: z.ZodObject<{
|
|
27
11
|
correlationId: z.ZodString;
|
|
28
12
|
id: z.ZodString;
|