@bgord/tools 1.3.24 → 1.4.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 +3 -3
- package/dist/age-years.vo.js +4 -9
- package/dist/age.vo.js +2 -1
- package/dist/api-key.vo.d.ts +3 -4
- package/dist/api-key.vo.js +5 -9
- package/dist/basename.vo.d.ts +3 -3
- package/dist/basename.vo.js +10 -15
- package/dist/day-iso-id.vo.d.ts +3 -3
- package/dist/day-iso-id.vo.js +4 -8
- package/dist/day.vo.d.ts +1 -1
- package/dist/day.vo.js +7 -6
- package/dist/directory-path-absolute.vo.d.ts +3 -3
- package/dist/directory-path-absolute.vo.js +5 -12
- package/dist/directory-path-relative.vo.d.ts +3 -3
- package/dist/directory-path-relative.vo.js +5 -12
- package/dist/distance-value.vo.d.ts +3 -3
- package/dist/distance-value.vo.js +4 -8
- package/dist/distance.vo.js +7 -6
- package/dist/division-factor.vo.d.ts +3 -3
- package/dist/division-factor.vo.js +4 -7
- package/dist/duration-ms.vo.d.ts +3 -3
- package/dist/duration-ms.vo.js +4 -3
- package/dist/duration.service.js +2 -1
- package/dist/email.vo.d.ts +3 -3
- package/dist/email.vo.js +3 -3
- package/dist/etags.vo.js +3 -2
- package/dist/extension.vo.d.ts +3 -3
- package/dist/extension.vo.js +6 -12
- package/dist/feature-flag-value.vo.d.ts +3 -3
- package/dist/feature-flag-value.vo.js +2 -2
- package/dist/file-path-absolute-schema.vo.d.ts +8 -5
- package/dist/file-path-absolute-schema.vo.js +6 -13
- package/dist/file-path-relative-schema.vo.d.ts +8 -5
- package/dist/file-path-relative-schema.vo.js +6 -13
- package/dist/file-path.vo.js +5 -4
- package/dist/filename-affix.vo.d.ts +3 -3
- package/dist/filename-affix.vo.js +4 -9
- package/dist/filename-from-string.vo.d.ts +6 -6
- package/dist/filename-from-string.vo.js +5 -8
- package/dist/filename.vo.js +8 -7
- package/dist/height-milimiters.vo.d.ts +3 -3
- package/dist/height-milimiters.vo.js +4 -8
- package/dist/height.vo.js +4 -3
- package/dist/hour-value.vo.d.ts +3 -3
- package/dist/hour-value.vo.js +4 -9
- package/dist/hour.vo.js +3 -2
- package/dist/iban-schema.vo.d.ts +3 -3
- package/dist/iban-schema.vo.js +4 -9
- package/dist/iban.vo.js +2 -1
- package/dist/image.vo.d.ts +5 -5
- package/dist/image.vo.js +7 -17
- package/dist/integer-non-negative.vo.d.ts +3 -3
- package/dist/integer-non-negative.vo.js +4 -8
- package/dist/integer-positive.vo.d.ts +3 -3
- package/dist/integer-positive.vo.js +4 -8
- package/dist/integer.vo.d.ts +3 -3
- package/dist/integer.vo.js +3 -3
- package/dist/language.vo.d.ts +3 -3
- package/dist/language.vo.js +2 -2
- package/dist/mime-value.vo.d.ts +3 -2
- package/dist/mime-value.vo.js +4 -7
- package/dist/mime.vo.js +2 -1
- package/dist/mimes.js +12 -11
- package/dist/minute-value.vo.d.ts +3 -3
- package/dist/minute-value.vo.js +4 -9
- package/dist/minute.vo.js +3 -2
- package/dist/money-amount.vo.d.ts +3 -3
- package/dist/money-amount.vo.js +4 -8
- package/dist/money.vo.js +7 -6
- package/dist/month-iso-id.vo.d.ts +3 -3
- package/dist/month-iso-id.vo.js +5 -9
- package/dist/month.vo.js +5 -4
- package/dist/multiplication-factor.vo.d.ts +3 -3
- package/dist/multiplication-factor.vo.js +4 -7
- package/dist/object-key.vo.d.ts +3 -3
- package/dist/object-key.vo.js +8 -13
- package/dist/package-version-schema.vo.d.ts +3 -3
- package/dist/package-version-schema.vo.js +4 -7
- package/dist/package-version.vo.js +3 -4
- package/dist/pagination-page.vo.d.ts +3 -3
- package/dist/pagination-page.vo.js +2 -6
- package/dist/pagination-skip.vo.d.ts +3 -3
- package/dist/pagination-skip.vo.js +2 -5
- package/dist/pagination-take.vo.d.ts +3 -3
- package/dist/pagination-take.vo.js +2 -5
- package/dist/pagination.service.js +8 -7
- package/dist/quarter-iso-id.vo.d.ts +4 -3
- package/dist/quarter-iso-id.vo.js +7 -11
- package/dist/quarter.vo.js +3 -2
- package/dist/reordering-item-position-value.vo.d.ts +3 -3
- package/dist/reordering-item-position-value.vo.js +2 -5
- package/dist/reordering.service.d.ts +9 -9
- package/dist/reordering.service.js +7 -7
- package/dist/revision-value.vo.d.ts +3 -3
- package/dist/revision-value.vo.js +2 -5
- package/dist/revision.vo.js +3 -2
- package/dist/rounding-decimal.strategy.d.ts +2 -2
- package/dist/rounding-decimal.strategy.js +5 -10
- package/dist/size-bytes.vo.d.ts +3 -3
- package/dist/size-bytes.vo.js +4 -8
- package/dist/size.vo.js +5 -4
- package/dist/time-zone-offset-value.vo.d.ts +3 -3
- package/dist/time-zone-offset-value.vo.js +8 -12
- package/dist/timestamp-value.vo.d.ts +3 -3
- package/dist/timestamp-value.vo.js +4 -8
- package/dist/timestamp.vo.js +2 -1
- package/dist/timezone.vo.d.ts +3 -3
- package/dist/timezone.vo.js +7 -10
- package/dist/url-with-slash.vo.d.ts +3 -3
- package/dist/url-with-slash.vo.js +4 -7
- package/dist/url-without-slash.vo.d.ts +3 -3
- package/dist/url-without-slash.vo.js +4 -7
- package/dist/week-iso-id.vo.d.ts +3 -3
- package/dist/week-iso-id.vo.js +5 -9
- package/dist/week.vo.js +5 -4
- package/dist/weekday-iso-id.vo.d.ts +3 -3
- package/dist/weekday-iso-id.vo.js +4 -9
- package/dist/weekday.vo.js +9 -8
- package/dist/weight-grams.vo.d.ts +3 -3
- package/dist/weight-grams.vo.js +4 -8
- package/dist/weight.vo.js +8 -7
- package/dist/year-iso-id.vo.d.ts +3 -3
- package/dist/year-iso-id.vo.js +4 -7
- package/dist/year.vo.js +6 -5
- package/package.json +9 -12
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const MoneyAmountError: {
|
|
3
3
|
Type: string;
|
|
4
4
|
Invalid: string;
|
|
5
5
|
};
|
|
6
|
-
export declare const MoneyAmount:
|
|
7
|
-
export type MoneyAmountType =
|
|
6
|
+
export declare const MoneyAmount: v.SchemaWithPipe<readonly [v.NumberSchema<string>, v.IntegerAction<number, string>, v.MinValueAction<number, 0, string>, v.BrandAction<number, "MoneyAmount">]>;
|
|
7
|
+
export type MoneyAmountType = v.InferOutput<typeof MoneyAmount>;
|
package/dist/money-amount.vo.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const MoneyAmountError = { Type: "money.amount.type", Invalid: "money.amount.invalid" };
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
.number(MoneyAmountError.Type)
|
|
7
|
-
.int(MoneyAmountError.Type)
|
|
8
|
-
.min(0, MoneyAmountError.Invalid)
|
|
9
|
-
.brand("MoneyAmount");
|
|
3
|
+
export const MoneyAmount = v.pipe(v.number(MoneyAmountError.Type), v.integer(MoneyAmountError.Type), v.minValue(0, MoneyAmountError.Invalid),
|
|
4
|
+
// Stryker disable next-line StringLiteral
|
|
5
|
+
v.brand("MoneyAmount"));
|
package/dist/money.vo.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
1
2
|
import { MoneyAmount } from "./money-amount.vo";
|
|
2
3
|
import { RoundingToNearestStrategy } from "./rounding-to-nearest.strategy";
|
|
3
4
|
export const MoneyError = { SubtractResultLessThanZero: "money.subtract.result.less.than.zero" };
|
|
4
5
|
export class Money {
|
|
5
6
|
amount;
|
|
6
|
-
static ZERO =
|
|
7
|
+
static ZERO = v.parse(MoneyAmount, 0);
|
|
7
8
|
constructor(amount) {
|
|
8
9
|
this.amount = amount;
|
|
9
10
|
}
|
|
10
11
|
static fromAmount(candidate) {
|
|
11
|
-
return new Money(
|
|
12
|
+
return new Money(v.parse(MoneyAmount, candidate));
|
|
12
13
|
}
|
|
13
14
|
static fromAmountSafe(candidate) {
|
|
14
15
|
return new Money(candidate);
|
|
@@ -20,19 +21,19 @@ export class Money {
|
|
|
20
21
|
return this.amount;
|
|
21
22
|
}
|
|
22
23
|
add(money) {
|
|
23
|
-
return new Money(
|
|
24
|
+
return new Money(v.parse(MoneyAmount, this.amount + money.getAmount()));
|
|
24
25
|
}
|
|
25
26
|
multiply(factor, rounding = new RoundingToNearestStrategy()) {
|
|
26
|
-
return new Money(
|
|
27
|
+
return new Money(v.parse(MoneyAmount, rounding.round(this.amount * factor)));
|
|
27
28
|
}
|
|
28
29
|
subtract(money) {
|
|
29
30
|
const result = this.amount - money.getAmount();
|
|
30
31
|
if (result < Money.ZERO)
|
|
31
32
|
throw new Error(MoneyError.SubtractResultLessThanZero);
|
|
32
|
-
return new Money(
|
|
33
|
+
return new Money(v.parse(MoneyAmount, result));
|
|
33
34
|
}
|
|
34
35
|
divide(factor, rounding = new RoundingToNearestStrategy()) {
|
|
35
|
-
return new Money(
|
|
36
|
+
return new Money(v.parse(MoneyAmount, rounding.round(this.amount / factor)));
|
|
36
37
|
}
|
|
37
38
|
equals(another) {
|
|
38
39
|
return this.amount === another.getAmount();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const MonthIsoIdError: {
|
|
3
3
|
Type: string;
|
|
4
4
|
BadChars: string;
|
|
5
5
|
Invalid: string;
|
|
6
6
|
};
|
|
7
|
-
export declare const MonthIsoId:
|
|
8
|
-
export type MonthIsoIdType =
|
|
7
|
+
export declare const MonthIsoId: v.SchemaWithPipe<readonly [v.StringSchema<string>, v.RegexAction<string, string>, v.CheckAction<string, string>, v.BrandAction<string, "MonthIsoId">]>;
|
|
8
|
+
export type MonthIsoIdType = v.InferOutput<typeof MonthIsoId>;
|
package/dist/month-iso-id.vo.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const MonthIsoIdError = {
|
|
3
3
|
Type: "month.iso.id.type",
|
|
4
4
|
BadChars: "month.iso.id.bad.chars",
|
|
@@ -6,13 +6,9 @@ export const MonthIsoIdError = {
|
|
|
6
6
|
};
|
|
7
7
|
// Four digits, hyphen, two digits
|
|
8
8
|
const MONTH_ISO_ID_CHARS_WHITELIST = /^\d{4}-\d{2}$/;
|
|
9
|
-
|
|
10
|
-
export const MonthIsoId = z
|
|
11
|
-
// Stryker restore all
|
|
12
|
-
.string(MonthIsoIdError.Type)
|
|
13
|
-
.regex(MONTH_ISO_ID_CHARS_WHITELIST, MonthIsoIdError.BadChars)
|
|
14
|
-
.refine((value) => {
|
|
9
|
+
export const MonthIsoId = v.pipe(v.string(MonthIsoIdError.Type), v.regex(MONTH_ISO_ID_CHARS_WHITELIST, MonthIsoIdError.BadChars), v.check((value) => {
|
|
15
10
|
const month = value.split("-").map(Number)[1];
|
|
16
11
|
return month >= 1 && month <= 12;
|
|
17
|
-
}, MonthIsoIdError.Invalid)
|
|
18
|
-
|
|
12
|
+
}, MonthIsoIdError.Invalid),
|
|
13
|
+
// Stryker disable next-line StringLiteral
|
|
14
|
+
v.brand("MonthIsoId"));
|
package/dist/month.vo.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { endOfMonth, format, startOfMonth } from "date-fns";
|
|
2
|
+
import * as v from "valibot";
|
|
2
3
|
import { DateRange } from "./date-range.vo";
|
|
3
4
|
import { Integer } from "./integer.vo";
|
|
4
5
|
import { MonthIsoId } from "./month-iso-id.vo";
|
|
@@ -16,18 +17,18 @@ export class Month extends DateRange {
|
|
|
16
17
|
return Month.fromTimestamp(now);
|
|
17
18
|
}
|
|
18
19
|
static fromIsoId(iso) {
|
|
19
|
-
const [year, month] =
|
|
20
|
+
const [year, month] = v.parse(MonthIsoId, iso).split("-").map(Number);
|
|
20
21
|
const reference = Timestamp.fromNumber(Date.UTC(year, month - 1, 1));
|
|
21
22
|
return Month.fromTimestamp(reference);
|
|
22
23
|
}
|
|
23
24
|
toIsoId() {
|
|
24
|
-
return
|
|
25
|
+
return v.parse(MonthIsoId, format(this.getStart().ms, "yyyy-MM"));
|
|
25
26
|
}
|
|
26
27
|
previous() {
|
|
27
|
-
return this.shift(
|
|
28
|
+
return this.shift(v.parse(Integer, -1));
|
|
28
29
|
}
|
|
29
30
|
next() {
|
|
30
|
-
return this.shift(
|
|
31
|
+
return this.shift(v.parse(Integer, 1));
|
|
31
32
|
}
|
|
32
33
|
shift(count) {
|
|
33
34
|
const start = new Date(this.getStart().ms);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const MultiplicationFactorError: {
|
|
3
3
|
Type: string;
|
|
4
4
|
Invalid: string;
|
|
5
5
|
};
|
|
6
|
-
export declare const MultiplicationFactor:
|
|
7
|
-
export type MultiplicationFactorType =
|
|
6
|
+
export declare const MultiplicationFactor: v.SchemaWithPipe<readonly [v.NumberSchema<string>, v.MinValueAction<number, 0, string>, v.BrandAction<number, "MultiplicationFactor">]>;
|
|
7
|
+
export type MultiplicationFactorType = v.InferOutput<typeof MultiplicationFactor>;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const MultiplicationFactorError = {
|
|
3
3
|
Type: "multiplication.factor.type",
|
|
4
4
|
Invalid: "multiplication.factor.invalid",
|
|
5
5
|
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
.number(MultiplicationFactorError.Type)
|
|
10
|
-
.min(0, MultiplicationFactorError.Invalid)
|
|
11
|
-
.brand("MultiplicationFactor");
|
|
6
|
+
export const MultiplicationFactor = v.pipe(v.number(MultiplicationFactorError.Type), v.minValue(0, MultiplicationFactorError.Invalid),
|
|
7
|
+
// Stryker disable next-line StringLiteral
|
|
8
|
+
v.brand("MultiplicationFactor"));
|
package/dist/object-key.vo.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const ObjectKeyError: {
|
|
3
3
|
Type: string;
|
|
4
4
|
LeadingSlash: string;
|
|
@@ -7,5 +7,5 @@ export declare const ObjectKeyError: {
|
|
|
7
7
|
BadChars: string;
|
|
8
8
|
DotSegments: string;
|
|
9
9
|
};
|
|
10
|
-
export declare const ObjectKey:
|
|
11
|
-
export type ObjectKeyType =
|
|
10
|
+
export declare const ObjectKey: v.SchemaWithPipe<readonly [v.StringSchema<string>, v.MinLengthAction<string, 1, string>, v.MaxLengthAction<string, 256, string>, v.CheckAction<string, string>, v.CheckAction<string, string>, v.CheckAction<string, string>, v.BrandAction<string, "ObjectKey">]>;
|
|
11
|
+
export type ObjectKeyType = v.InferOutput<typeof ObjectKey>;
|
package/dist/object-key.vo.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const ObjectKeyError = {
|
|
3
3
|
Type: "object.key.type",
|
|
4
4
|
LeadingSlash: "object.key.leading.slash",
|
|
@@ -10,15 +10,10 @@ export const ObjectKeyError = {
|
|
|
10
10
|
// Lowercase letters, digits, dots, underscores, and hyphens
|
|
11
11
|
const OBJECT_KEY_SEGMENT_CHARS_WHITELIST = /^[a-z0-9._-]+$/;
|
|
12
12
|
const DOT_SEGMENTS = [".", ".."];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// Allow only known characters for users/avatars/1234567890/avatar.png segments
|
|
21
|
-
.refine((value) => value.split("/").every((segment) => OBJECT_KEY_SEGMENT_CHARS_WHITELIST.test(segment)), ObjectKeyError.BadChars)
|
|
22
|
-
// Reject object keys like users/./avatar.png or users/../avatar.png
|
|
23
|
-
.refine((value) => value.split("/").every((segment) => !DOT_SEGMENTS.includes(segment)), ObjectKeyError.DotSegments)
|
|
24
|
-
.brand("ObjectKey");
|
|
13
|
+
export const ObjectKey = v.pipe(v.string(ObjectKeyError.Type), v.minLength(1, ObjectKeyError.Empty), v.maxLength(256, ObjectKeyError.TooLong), v.check((value) => !value.startsWith("/"), ObjectKeyError.LeadingSlash),
|
|
14
|
+
// Allow only known characters for users/avatars/1234567890/avatar.png segments
|
|
15
|
+
v.check((value) => value.split("/").every((segment) => OBJECT_KEY_SEGMENT_CHARS_WHITELIST.test(segment)), ObjectKeyError.BadChars),
|
|
16
|
+
// Reject object keys like users/./avatar.png or users/../avatar.png
|
|
17
|
+
v.check((value) => value.split("/").every((segment) => !DOT_SEGMENTS.includes(segment)), ObjectKeyError.DotSegments),
|
|
18
|
+
// Stryker disable next-line StringLiteral
|
|
19
|
+
v.brand("ObjectKey"));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const PackageVersionSchemaError: {
|
|
3
3
|
Type: string;
|
|
4
4
|
BadChars: string;
|
|
5
5
|
};
|
|
6
6
|
export declare const PACKAGE_VERSIONS_CHARS_WHITELIST: RegExp;
|
|
7
|
-
export declare const PackageVersionSchema:
|
|
8
|
-
export type PackageVersionSchemaType =
|
|
7
|
+
export declare const PackageVersionSchema: v.SchemaWithPipe<readonly [v.StringSchema<string>, v.RegexAction<string, string>, v.BrandAction<string, "PackageVersionSchema">]>;
|
|
8
|
+
export type PackageVersionSchemaType = v.InferOutput<typeof PackageVersionSchema>;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const PackageVersionSchemaError = {
|
|
3
3
|
Type: "package.version.schema.error",
|
|
4
4
|
BadChars: "package.version.schema.bad.chars",
|
|
5
5
|
};
|
|
6
6
|
// v, 1-4 digits, dot, 1-4 digits, dot, 1-4 digits - () for capturing groups
|
|
7
7
|
export const PACKAGE_VERSIONS_CHARS_WHITELIST = /^v([0-9]{1,4})\.([0-9]{1,4})\.([0-9]{1,4})$/;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
.string(PackageVersionSchemaError.Type)
|
|
12
|
-
.regex(PACKAGE_VERSIONS_CHARS_WHITELIST, PackageVersionSchemaError.BadChars)
|
|
13
|
-
.brand("PackageVersionSchema");
|
|
8
|
+
export const PackageVersionSchema = v.pipe(v.string(PackageVersionSchemaError.Type), v.regex(PACKAGE_VERSIONS_CHARS_WHITELIST, PackageVersionSchemaError.BadChars),
|
|
9
|
+
// Stryker disable next-line StringLiteral
|
|
10
|
+
v.brand("PackageVersionSchema"));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
1
2
|
import { PACKAGE_VERSIONS_CHARS_WHITELIST, PackageVersionSchema, } from "./package-version-schema.vo";
|
|
2
3
|
export class PackageVersion {
|
|
3
4
|
major;
|
|
@@ -9,16 +10,14 @@ export class PackageVersion {
|
|
|
9
10
|
this.patch = patch;
|
|
10
11
|
}
|
|
11
12
|
static fromVersionString(candidate) {
|
|
12
|
-
|
|
13
|
-
return PackageVersion.fromVersionStringSafe(version);
|
|
13
|
+
return PackageVersion.fromVersionStringSafe(v.parse(PackageVersionSchema, candidate));
|
|
14
14
|
}
|
|
15
15
|
static fromVersionStringSafe(candidate) {
|
|
16
16
|
const [, major, minor, patch] = PACKAGE_VERSIONS_CHARS_WHITELIST.exec(candidate).map(Number);
|
|
17
17
|
return new PackageVersion(major, minor, patch);
|
|
18
18
|
}
|
|
19
19
|
static fromString(candidate) {
|
|
20
|
-
|
|
21
|
-
return PackageVersion.fromVersionStringSafe(version);
|
|
20
|
+
return PackageVersion.fromVersionStringSafe(v.parse(PackageVersionSchema, `v${candidate}`));
|
|
22
21
|
}
|
|
23
22
|
compareTo(another) {
|
|
24
23
|
if (this.major > another.major)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const PaginationPageError: {
|
|
3
3
|
Type: string;
|
|
4
4
|
};
|
|
5
|
-
export declare const Page:
|
|
6
|
-
export type PageType =
|
|
5
|
+
export declare const Page: v.SchemaWithPipe<readonly [v.UnknownSchema, v.TransformAction<unknown, number>, v.NumberSchema<string>, v.IntegerAction<number, string>, v.TransformAction<number, number>]>;
|
|
6
|
+
export type PageType = v.InferOutput<typeof Page>;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const PaginationPageError = { Type: "pagination.page.type" };
|
|
3
|
-
export const Page =
|
|
4
|
-
.number(PaginationPageError.Type)
|
|
5
|
-
.int(PaginationPageError.Type)
|
|
6
|
-
.transform((value) => (value <= 0 ? 1 : value))
|
|
7
|
-
.default(1);
|
|
3
|
+
export const Page = v.pipe(v.unknown(), v.transform((value) => (value === undefined ? 1 : Number(value))), v.number(PaginationPageError.Type), v.integer(PaginationPageError.Type), v.transform((value) => (value <= 0 ? 1 : value)));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const PaginationSkipError: {
|
|
3
3
|
Type: string;
|
|
4
4
|
Invalid: string;
|
|
5
5
|
};
|
|
6
|
-
export declare const Skip:
|
|
7
|
-
export type SkipType =
|
|
6
|
+
export declare const Skip: v.SchemaWithPipe<readonly [v.NumberSchema<string>, v.IntegerAction<number, string>, v.MinValueAction<number, 0, string>]>;
|
|
7
|
+
export type SkipType = v.InferOutput<typeof Skip>;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const PaginationSkipError = { Type: "pagination.skip.type", Invalid: "pagination.skip.invalid" };
|
|
3
|
-
export const Skip =
|
|
4
|
-
.number(PaginationSkipError.Type)
|
|
5
|
-
.int(PaginationSkipError.Type)
|
|
6
|
-
.gte(0, PaginationSkipError.Invalid);
|
|
3
|
+
export const Skip = v.pipe(v.number(PaginationSkipError.Type), v.integer(PaginationSkipError.Type), v.minValue(0, PaginationSkipError.Invalid));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const PaginationTakeError: {
|
|
3
3
|
Type: string;
|
|
4
4
|
Invalid: string;
|
|
5
5
|
};
|
|
6
|
-
export declare const Take:
|
|
7
|
-
export type TakeType =
|
|
6
|
+
export declare const Take: v.SchemaWithPipe<readonly [v.NumberSchema<string>, v.IntegerAction<number, string>, v.MinValueAction<number, 1, string>]>;
|
|
7
|
+
export type TakeType = v.InferOutput<typeof Take>;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const PaginationTakeError = { Type: "pagination.take.type", Invalid: "pagination.take.invalid" };
|
|
3
|
-
export const Take =
|
|
4
|
-
.number(PaginationTakeError.Type)
|
|
5
|
-
.int(PaginationTakeError.Type)
|
|
6
|
-
.gte(1, PaginationTakeError.Invalid);
|
|
3
|
+
export const Take = v.pipe(v.number(PaginationTakeError.Type), v.integer(PaginationTakeError.Type), v.minValue(1, PaginationTakeError.Invalid));
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
1
2
|
import { Page } from "./pagination-page.vo";
|
|
2
3
|
import { Skip } from "./pagination-skip.vo";
|
|
3
4
|
import { Take } from "./pagination-take.vo";
|
|
4
5
|
import { RoundingUpStrategy } from "./rounding-up.strategy";
|
|
5
6
|
export class Pagination {
|
|
6
7
|
static parse(values, _take) {
|
|
7
|
-
const page =
|
|
8
|
-
const take =
|
|
9
|
-
const skip =
|
|
8
|
+
const page = v.parse(Page, values.page);
|
|
9
|
+
const take = v.parse(Take, _take);
|
|
10
|
+
const skip = v.parse(Skip, (page - 1) * take);
|
|
10
11
|
return { values: { take, skip }, page };
|
|
11
12
|
}
|
|
12
13
|
static prepare(config) {
|
|
13
14
|
const exhausted = Pagination.isExhausted(config);
|
|
14
15
|
const currentPage = config.pagination.page;
|
|
15
16
|
const lastPage = Pagination.getLastPage(config);
|
|
16
|
-
const previousPage = currentPage > 1 ?
|
|
17
|
-
const nextPage = currentPage < lastPage ?
|
|
17
|
+
const previousPage = currentPage > 1 ? v.parse(Page, currentPage - 1) : undefined;
|
|
18
|
+
const nextPage = currentPage < lastPage ? v.parse(Page, currentPage + 1) : undefined;
|
|
18
19
|
return {
|
|
19
20
|
result: config.result,
|
|
20
21
|
meta: { exhausted, currentPage, previousPage, nextPage, lastPage, total: config.total },
|
|
@@ -24,7 +25,7 @@ export class Pagination {
|
|
|
24
25
|
return Pagination.getLastPage(config) <= config.pagination.page;
|
|
25
26
|
}
|
|
26
27
|
static getLastPage(config) {
|
|
27
|
-
return
|
|
28
|
+
return v.parse(Page, new RoundingUpStrategy().round(config.total / config.pagination.values.take));
|
|
28
29
|
}
|
|
29
30
|
static empty = {
|
|
30
31
|
result: [],
|
|
@@ -38,6 +39,6 @@ export class Pagination {
|
|
|
38
39
|
},
|
|
39
40
|
};
|
|
40
41
|
static getFirstPage(input) {
|
|
41
|
-
return { values: { take:
|
|
42
|
+
return { values: { take: v.parse(Take, input.take), skip: v.parse(Skip, 0) }, page: v.parse(Page, 1) };
|
|
42
43
|
}
|
|
43
44
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const QuarterIsoIdError: {
|
|
3
3
|
Type: string;
|
|
4
4
|
BadChars: string;
|
|
5
5
|
};
|
|
6
|
-
export declare const
|
|
7
|
-
export
|
|
6
|
+
export declare const QUARTER_ISO_ID_CHARS_WHITELIST: RegExp;
|
|
7
|
+
export declare const QuarterIsoId: v.SchemaWithPipe<readonly [v.StringSchema<string>, v.RegexAction<string, string>, v.BrandAction<string, "QuarterIsoId">]>;
|
|
8
|
+
export type QuarterIsoIdType = v.InferOutput<typeof QuarterIsoId>;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
export const QuarterIsoIdError = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// Stryker disable
|
|
7
|
-
|
|
8
|
-
// Stryker restore all
|
|
9
|
-
.string(QuarterIsoIdError.Type)
|
|
10
|
-
.regex(/^\d{4}-Q[1-4]$/, QuarterIsoIdError.BadChars)
|
|
11
|
-
.brand("QuarterIsoId");
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
export const QuarterIsoIdError = { Type: "quarter.iso.id.type", BadChars: "quarter.iso.id.bad.chars" };
|
|
3
|
+
// 4 digits, hyphen, Q, digits from 1 to 4
|
|
4
|
+
export const QUARTER_ISO_ID_CHARS_WHITELIST = /^\d{4}-Q[1-4]$/;
|
|
5
|
+
export const QuarterIsoId = v.pipe(v.string(QuarterIsoIdError.Type), v.regex(QUARTER_ISO_ID_CHARS_WHITELIST, QuarterIsoIdError.BadChars),
|
|
6
|
+
// Stryker disable next-line StringLiteral
|
|
7
|
+
v.brand("QuarterIsoId"));
|
package/dist/quarter.vo.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { endOfQuarter, getQuarter, getYear, startOfQuarter } from "date-fns";
|
|
2
|
+
import * as v from "valibot";
|
|
2
3
|
import { DateRange } from "./date-range.vo";
|
|
3
4
|
import { QuarterIsoId } from "./quarter-iso-id.vo";
|
|
4
5
|
import { Timestamp } from "./timestamp.vo";
|
|
@@ -15,13 +16,13 @@ export class Quarter extends DateRange {
|
|
|
15
16
|
return Quarter.fromTimestamp(now);
|
|
16
17
|
}
|
|
17
18
|
static fromIsoId(isoId) {
|
|
18
|
-
const [year, quarter] =
|
|
19
|
+
const [year, quarter] = v.parse(QuarterIsoId, isoId).split("-Q").map(Number);
|
|
19
20
|
return Quarter.fromTimestamp(Timestamp.fromNumber(Date.UTC(year, (quarter - 1) * 3, 1)));
|
|
20
21
|
}
|
|
21
22
|
toIsoId() {
|
|
22
23
|
const year = getYear(this.getStart().ms);
|
|
23
24
|
const quarter = getQuarter(this.getStart().ms);
|
|
24
|
-
return
|
|
25
|
+
return v.parse(QuarterIsoId, `${year}-Q${quarter}`);
|
|
25
26
|
}
|
|
26
27
|
toString() {
|
|
27
28
|
return this.toIsoId();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const ReorderingItemPositionValueError: {
|
|
3
3
|
Invalid: string;
|
|
4
4
|
};
|
|
5
|
-
export declare const ReorderingItemPositionValue:
|
|
6
|
-
export type ReorderingItemPositionValueType =
|
|
5
|
+
export declare const ReorderingItemPositionValue: v.SchemaWithPipe<readonly [v.NumberSchema<string>, v.IntegerAction<number, string>, v.MinValueAction<number, 0, string>]>;
|
|
6
|
+
export type ReorderingItemPositionValueType = v.InferOutput<typeof ReorderingItemPositionValue>;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const ReorderingItemPositionValueError = { Invalid: "reordering.position.type" };
|
|
3
|
-
export const ReorderingItemPositionValue =
|
|
4
|
-
.number(ReorderingItemPositionValueError.Invalid)
|
|
5
|
-
.int(ReorderingItemPositionValueError.Invalid)
|
|
6
|
-
.min(0, ReorderingItemPositionValueError.Invalid);
|
|
3
|
+
export const ReorderingItemPositionValue = v.pipe(v.number(ReorderingItemPositionValueError.Invalid), v.integer(ReorderingItemPositionValueError.Invalid), v.minValue(0, ReorderingItemPositionValueError.Invalid));
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
import { type ReorderingItemPositionValueType } from "./reordering-item-position-value.vo";
|
|
3
3
|
export declare const ReorderingError: {
|
|
4
4
|
CannotFindItem: string;
|
|
5
5
|
CannotFindCurrent: string;
|
|
6
6
|
CannotFindTarget: string;
|
|
7
7
|
};
|
|
8
|
-
export declare const ReorderingId:
|
|
9
|
-
export type ReorderingItemIdType =
|
|
10
|
-
export declare const Reordering:
|
|
11
|
-
correlationId:
|
|
12
|
-
id:
|
|
13
|
-
position:
|
|
14
|
-
},
|
|
15
|
-
export type ReorderingType =
|
|
8
|
+
export declare const ReorderingId: v.SchemaWithPipe<readonly [v.StringSchema<string>, v.MinLengthAction<string, 1, string>]>;
|
|
9
|
+
export type ReorderingItemIdType = v.InferOutput<typeof ReorderingId>;
|
|
10
|
+
export declare const Reordering: v.ObjectSchema<{
|
|
11
|
+
readonly correlationId: v.SchemaWithPipe<readonly [v.StringSchema<string>, v.MinLengthAction<string, 1, string>]>;
|
|
12
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<string>, v.MinLengthAction<string, 1, string>]>;
|
|
13
|
+
readonly position: v.SchemaWithPipe<readonly [v.NumberSchema<string>, v.IntegerAction<number, string>, v.MinValueAction<number, 0, string>]>;
|
|
14
|
+
}, undefined>;
|
|
15
|
+
export type ReorderingType = v.InferOutput<typeof Reordering>;
|
|
16
16
|
export type WithReorderingPositionValue<T> = T & {
|
|
17
17
|
position: ReorderingItemPositionValueType;
|
|
18
18
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Stryker disable all
|
|
2
|
-
import * as
|
|
2
|
+
import * as v from "valibot";
|
|
3
3
|
import { DoublyLinkedList, Node } from "./dll.service";
|
|
4
4
|
import { ReorderingItemPositionValue, } from "./reordering-item-position-value.vo";
|
|
5
5
|
export const ReorderingError = {
|
|
@@ -8,8 +8,8 @@ export const ReorderingError = {
|
|
|
8
8
|
CannotFindTarget: "reordering.cannot.find.target",
|
|
9
9
|
};
|
|
10
10
|
const ReorderingIdError = { Type: "reordering.id.type" };
|
|
11
|
-
export const ReorderingId =
|
|
12
|
-
export const Reordering =
|
|
11
|
+
export const ReorderingId = v.pipe(v.string(ReorderingIdError.Type), v.minLength(1, ReorderingIdError.Type));
|
|
12
|
+
export const Reordering = v.object({
|
|
13
13
|
correlationId: ReorderingId,
|
|
14
14
|
id: ReorderingId,
|
|
15
15
|
position: ReorderingItemPositionValue,
|
|
@@ -17,7 +17,7 @@ export const Reordering = z.object({
|
|
|
17
17
|
export class ReorderingPosition {
|
|
18
18
|
value;
|
|
19
19
|
constructor(value) {
|
|
20
|
-
this.value =
|
|
20
|
+
this.value = v.parse(ReorderingItemPositionValue, value);
|
|
21
21
|
}
|
|
22
22
|
eq(another) {
|
|
23
23
|
return this.value === another.value;
|
|
@@ -71,7 +71,7 @@ export class ReorderingCalculator {
|
|
|
71
71
|
}
|
|
72
72
|
add(id) {
|
|
73
73
|
const size = this.dll.getSize();
|
|
74
|
-
const position = new ReorderingPosition(
|
|
74
|
+
const position = new ReorderingPosition(v.parse(ReorderingItemPositionValue, size));
|
|
75
75
|
const item = new ReorderingItem(id, position);
|
|
76
76
|
const node = new Node(item);
|
|
77
77
|
this.dll.append(node);
|
|
@@ -114,7 +114,7 @@ export class ReorderingCalculator {
|
|
|
114
114
|
let index = 0;
|
|
115
115
|
for (const node of this.dll) {
|
|
116
116
|
const id = node.data.id;
|
|
117
|
-
const position = new ReorderingPosition(
|
|
117
|
+
const position = new ReorderingPosition(v.parse(ReorderingItemPositionValue, index));
|
|
118
118
|
node.data = new ReorderingItem(id, position);
|
|
119
119
|
index += 1;
|
|
120
120
|
}
|
|
@@ -124,7 +124,7 @@ export class ReorderingIntegrator {
|
|
|
124
124
|
static appendPosition(reordering) {
|
|
125
125
|
return function (item) {
|
|
126
126
|
const found = reordering.find((x) => x.id === item.id);
|
|
127
|
-
const positionValue =
|
|
127
|
+
const positionValue = v.parse(ReorderingItemPositionValue, found?.position ?? 0);
|
|
128
128
|
return { ...item, position: positionValue };
|
|
129
129
|
};
|
|
130
130
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const RevisionValueError: {
|
|
3
3
|
Type: string;
|
|
4
4
|
Invalid: string;
|
|
5
5
|
};
|
|
6
|
-
export declare const RevisionValue:
|
|
7
|
-
export type RevisionValueType =
|
|
6
|
+
export declare const RevisionValue: v.SchemaWithPipe<readonly [v.NumberSchema<string>, v.IntegerAction<number, string>, v.MinValueAction<number, 0, string>]>;
|
|
7
|
+
export type RevisionValueType = v.InferOutput<typeof RevisionValue>;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const RevisionValueError = { Type: "revision.value.type", Invalid: "revision.value.invalid" };
|
|
3
|
-
export const RevisionValue =
|
|
4
|
-
.number(RevisionValueError.Type)
|
|
5
|
-
.int(RevisionValueError.Type)
|
|
6
|
-
.min(0, RevisionValueError.Invalid);
|
|
3
|
+
export const RevisionValue = v.pipe(v.number(RevisionValueError.Type), v.integer(RevisionValueError.Type), v.minValue(0, RevisionValueError.Invalid));
|
package/dist/revision.vo.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
1
2
|
import { RevisionValue } from "./revision-value.vo";
|
|
2
3
|
export const RevisionError = { Missing: "revision.missing", Mismatch: "revision.mismatch" };
|
|
3
4
|
export class Revision {
|
|
4
|
-
static INITIAL =
|
|
5
|
+
static INITIAL = v.parse(RevisionValue, 0);
|
|
5
6
|
value;
|
|
6
7
|
constructor(value) {
|
|
7
|
-
this.value =
|
|
8
|
+
this.value = v.parse(RevisionValue, value);
|
|
8
9
|
}
|
|
9
10
|
equals(another) {
|
|
10
11
|
return this.value === another;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
import type { RoundingStrategy } from "./rounding.strategy";
|
|
3
3
|
export declare const RoundingDecimalError: {
|
|
4
4
|
Type: string;
|
|
5
5
|
Invalid: string;
|
|
6
6
|
};
|
|
7
|
-
export declare const RoundingDecimal:
|
|
7
|
+
export declare const RoundingDecimal: v.SchemaWithPipe<readonly [v.NumberSchema<string>, v.IntegerAction<number, string>, v.MinValueAction<number, 1, string>, v.MaxValueAction<number, 100, string>, v.BrandAction<number, "RoundingDecimal">]>;
|
|
8
8
|
export declare class RoundingDecimalStrategy implements RoundingStrategy {
|
|
9
9
|
private readonly decimals;
|
|
10
10
|
constructor(candidate: number);
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const RoundingDecimalError = { Type: "rounding.decimal.type", Invalid: "rounding.decimal.invalid" };
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
.number(RoundingDecimalError.Type)
|
|
7
|
-
.int(RoundingDecimalError.Invalid)
|
|
8
|
-
.min(1, RoundingDecimalError.Invalid)
|
|
9
|
-
.max(100, RoundingDecimalError.Invalid)
|
|
10
|
-
.brand("RoundingDecimal");
|
|
3
|
+
export const RoundingDecimal = v.pipe(v.number(RoundingDecimalError.Type), v.integer(RoundingDecimalError.Invalid), v.minValue(1, RoundingDecimalError.Invalid), v.maxValue(100, RoundingDecimalError.Invalid),
|
|
4
|
+
// Stryker disable next-line StringLiteral
|
|
5
|
+
v.brand("RoundingDecimal"));
|
|
11
6
|
export class RoundingDecimalStrategy {
|
|
12
7
|
decimals;
|
|
13
8
|
constructor(candidate) {
|
|
14
|
-
this.decimals =
|
|
9
|
+
this.decimals = v.parse(RoundingDecimal, candidate);
|
|
15
10
|
}
|
|
16
11
|
round(value) {
|
|
17
12
|
return Number.parseFloat(value.toFixed(this.decimals));
|