@bgord/tools 0.8.0 → 0.9.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/api-key.vo.d.ts +1 -1
- package/dist/api-key.vo.js +1 -1
- package/dist/build-version.vo.d.ts +1 -1
- package/dist/build-version.vo.js +1 -1
- package/dist/clock.vo.js +3 -0
- package/dist/dll.service.js +7 -8
- package/dist/email-mask.service.d.ts +4 -2
- package/dist/email-mask.service.js +1 -1
- package/dist/etags.vo.d.ts +1 -1
- package/dist/etags.vo.js +11 -7
- package/dist/filter.vo.js +1 -0
- package/dist/hour.vo.js +4 -2
- package/dist/iban.vo.d.ts +13 -0
- package/dist/iban.vo.js +27 -0
- package/dist/image.vo.d.ts +2 -2
- package/dist/image.vo.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/language.vo.d.ts +1 -1
- package/dist/language.vo.js +2 -1
- package/dist/mime.vo.js +4 -0
- package/dist/min-max-scaler.service.js +5 -0
- package/dist/minute.vo.js +3 -2
- package/dist/money.vo.d.ts +3 -3
- package/dist/money.vo.js +9 -4
- package/dist/outlier-detector.service.js +2 -0
- package/dist/package-version.vo.d.ts +2 -2
- package/dist/package-version.vo.js +5 -1
- package/dist/pagination.service.d.ts +3 -3
- package/dist/pagination.service.js +21 -19
- package/dist/rate-limiter.service.d.ts +1 -1
- package/dist/rate-limiter.service.js +4 -2
- package/dist/reordering.service.d.ts +7 -7
- package/dist/reordering.service.js +12 -8
- package/dist/revision.vo.d.ts +1 -1
- package/dist/revision.vo.js +3 -2
- package/dist/rounding.service.js +1 -0
- package/dist/simple-linear-regression.service.js +2 -1
- package/dist/size.vo.d.ts +1 -1
- package/dist/size.vo.js +11 -8
- package/dist/stepper.service.js +3 -2
- package/dist/stopwatch.service.d.ts +1 -1
- package/dist/stopwatch.service.js +6 -6
- package/dist/streak-calculator.service.js +1 -0
- package/dist/thousands-separator.service.js +1 -1
- package/dist/time-zone-offset-value.vo.d.ts +1 -1
- package/dist/time-zone-offset-value.vo.js +2 -1
- package/dist/time.service.js +5 -0
- package/dist/timestamp.vo.d.ts +1 -1
- package/dist/timestamp.vo.js +2 -1
- package/dist/timezone.vo.d.ts +1 -1
- package/dist/timezone.vo.js +2 -1
- package/dist/visually-unambiguous-characters-generator.service.js +24 -24
- package/dist/z-score.service.js +3 -0
- package/package.json +4 -4
- package/src/api-key.vo.ts +1 -1
- package/src/build-version.vo.ts +1 -1
- package/src/email-mask.service.ts +4 -2
- package/src/etags.vo.ts +3 -3
- package/src/iban.vo.ts +39 -0
- package/src/image.vo.ts +2 -2
- package/src/index.ts +1 -0
- package/src/language.vo.ts +2 -1
- package/src/money.vo.ts +6 -3
- package/src/package-version.vo.ts +2 -1
- package/src/pagination.service.ts +11 -8
- package/src/rate-limiter.service.ts +2 -2
- package/src/reordering.service.ts +9 -8
- package/src/revision.vo.ts +2 -2
- package/src/size.vo.ts +4 -4
- package/src/stopwatch.service.ts +4 -4
- package/src/time-zone-offset-value.vo.ts +2 -1
- package/src/timestamp.vo.ts +2 -1
- package/src/timezone.vo.ts +2 -1
package/dist/api-key.vo.d.ts
CHANGED
package/dist/api-key.vo.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
export const ApiKey = z.string().trim().length(64);
|
|
2
|
+
export const ApiKey = z.string().trim().length(64).brand("ApiKey");
|
package/dist/build-version.vo.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
export const BuildVersion = z.string().min(1).max(8);
|
|
2
|
+
export const BuildVersion = z.string().min(1).max(8).brand("BuildVersion");
|
package/dist/clock.vo.js
CHANGED
|
@@ -9,6 +9,9 @@ export const ClockFormatters = {
|
|
|
9
9
|
TWELVE_HOURS: (hour, minute) => `${hour.get(HourFormatters.TWELVE_HOURS).formatted}:${minute.get().formatted}`,
|
|
10
10
|
};
|
|
11
11
|
export class Clock {
|
|
12
|
+
hour;
|
|
13
|
+
minute;
|
|
14
|
+
formatter;
|
|
12
15
|
constructor(hour, minute, formatter) {
|
|
13
16
|
this.hour = hour;
|
|
14
17
|
this.minute = minute;
|
package/dist/dll.service.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export class Node {
|
|
2
|
+
data;
|
|
3
|
+
prev = null;
|
|
4
|
+
next = null;
|
|
2
5
|
constructor(data) {
|
|
3
|
-
this.prev = null;
|
|
4
|
-
this.next = null;
|
|
5
6
|
this.data = data;
|
|
6
7
|
}
|
|
7
8
|
forward(n) {
|
|
@@ -26,11 +27,10 @@ export class Node {
|
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
export class DoublyLinkedList {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
30
|
+
static EMPTY_SIZE = 0;
|
|
31
|
+
size = DoublyLinkedList.EMPTY_SIZE;
|
|
32
|
+
head = null;
|
|
33
|
+
tail = null;
|
|
34
34
|
getSize() {
|
|
35
35
|
return this.size;
|
|
36
36
|
}
|
|
@@ -145,4 +145,3 @@ export class DoublyLinkedList {
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
DoublyLinkedList.EMPTY_SIZE = 0;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
export declare const Email: z.ZodEmail
|
|
2
|
+
export declare const Email: z.core.$ZodBranded<z.ZodEmail, "Email">;
|
|
3
3
|
export type EmailType = z.infer<typeof Email>;
|
|
4
|
+
type EmailMaskedType = string;
|
|
4
5
|
export declare class EmailMask {
|
|
5
|
-
static censor(email: EmailType):
|
|
6
|
+
static censor(email: EmailType): EmailMaskedType;
|
|
6
7
|
}
|
|
8
|
+
export {};
|
package/dist/etags.vo.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
declare const RevisionValue: z.ZodNumber
|
|
2
|
+
declare const RevisionValue: z.core.$ZodBranded<z.ZodNumber, "RevisionValue">;
|
|
3
3
|
type RevisionValueType = z.infer<typeof RevisionValue>;
|
|
4
4
|
type ETagValueType = string;
|
|
5
5
|
export declare class ETag {
|
package/dist/etags.vo.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
const RevisionValue = z.number().int().min(0);
|
|
2
|
+
const RevisionValue = z.number().int().min(0).brand("RevisionValue");
|
|
3
3
|
export class ETag {
|
|
4
|
+
revision;
|
|
5
|
+
static HEADER_NAME = "ETag";
|
|
6
|
+
static IF_MATCH_HEADER_NAME = "if-match";
|
|
7
|
+
value;
|
|
4
8
|
constructor(revision) {
|
|
5
9
|
this.revision = revision;
|
|
6
10
|
this.value = revision.toString();
|
|
@@ -11,12 +15,14 @@ export class ETag {
|
|
|
11
15
|
const candidate = Number(value);
|
|
12
16
|
if (Number.isNaN(candidate))
|
|
13
17
|
return null;
|
|
14
|
-
return new ETag(candidate);
|
|
18
|
+
return new ETag(RevisionValue.parse(candidate));
|
|
15
19
|
}
|
|
16
20
|
}
|
|
17
|
-
ETag.HEADER_NAME = "ETag";
|
|
18
|
-
ETag.IF_MATCH_HEADER_NAME = "if-match";
|
|
19
21
|
export class WeakETag {
|
|
22
|
+
revision;
|
|
23
|
+
static HEADER_NAME = "ETag";
|
|
24
|
+
static IF_MATCH_HEADER_NAME = "if-match";
|
|
25
|
+
value;
|
|
20
26
|
constructor(revision) {
|
|
21
27
|
this.revision = revision;
|
|
22
28
|
this.value = `W/${revision.toString()}`;
|
|
@@ -27,8 +33,6 @@ export class WeakETag {
|
|
|
27
33
|
const candidate = Number(value.split("W/")[1]);
|
|
28
34
|
if (Number.isNaN(candidate))
|
|
29
35
|
return null;
|
|
30
|
-
return new WeakETag(candidate);
|
|
36
|
+
return new WeakETag(RevisionValue.parse(candidate));
|
|
31
37
|
}
|
|
32
38
|
}
|
|
33
|
-
WeakETag.HEADER_NAME = "ETag";
|
|
34
|
-
WeakETag.IF_MATCH_HEADER_NAME = "if-match";
|
package/dist/filter.vo.js
CHANGED
package/dist/hour.vo.js
CHANGED
|
@@ -18,6 +18,10 @@ export const HourFormatters = {
|
|
|
18
18
|
TWELVE_HOURS_WO_PADDING: (value) => (value % 12).toString(),
|
|
19
19
|
};
|
|
20
20
|
export class Hour {
|
|
21
|
+
value;
|
|
22
|
+
formatter;
|
|
23
|
+
static ZERO = new Hour(0);
|
|
24
|
+
static MAX = new Hour(23);
|
|
21
25
|
constructor(candidate, formatter) {
|
|
22
26
|
if (!Number.isInteger(candidate)) {
|
|
23
27
|
throw new Error("Invalid hour");
|
|
@@ -48,5 +52,3 @@ export class Hour {
|
|
|
48
52
|
return Array.from({ length: 24 }).map((_, index) => new Hour(index, formatter));
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
|
-
Hour.ZERO = new Hour(0);
|
|
52
|
-
Hour.MAX = new Hour(23);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
declare const IBANValueSchema: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
3
|
+
type IBANValueType = z.infer<typeof IBANValueSchema>;
|
|
4
|
+
type IBANCountryCode = string;
|
|
5
|
+
export declare class IBAN {
|
|
6
|
+
private readonly value;
|
|
7
|
+
constructor(value: string);
|
|
8
|
+
toString(): IBANValueType;
|
|
9
|
+
format(): string;
|
|
10
|
+
get countryCode(): IBANCountryCode;
|
|
11
|
+
equals(other: IBAN): boolean;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
package/dist/iban.vo.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
// Basic IBAN format regex (2-letter country code + 2 digits + 11–30 alphanumerics)
|
|
3
|
+
const IBAN_REGEX = /^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$/;
|
|
4
|
+
const IBANValueSchema = z
|
|
5
|
+
.string()
|
|
6
|
+
.transform((val) => val.replace(/\s+/g, "").toUpperCase())
|
|
7
|
+
.refine((iban) => IBAN_REGEX.test(iban), {
|
|
8
|
+
message: "invalid.iban.format",
|
|
9
|
+
});
|
|
10
|
+
export class IBAN {
|
|
11
|
+
value;
|
|
12
|
+
constructor(value) {
|
|
13
|
+
this.value = IBANValueSchema.parse(value);
|
|
14
|
+
}
|
|
15
|
+
toString() {
|
|
16
|
+
return this.value;
|
|
17
|
+
}
|
|
18
|
+
format() {
|
|
19
|
+
return this.value.replace(/(.{4})(?=.)/g, "$1 ");
|
|
20
|
+
}
|
|
21
|
+
get countryCode() {
|
|
22
|
+
return this.value.slice(0, 2);
|
|
23
|
+
}
|
|
24
|
+
equals(other) {
|
|
25
|
+
return this.value === other.value;
|
|
26
|
+
}
|
|
27
|
+
}
|
package/dist/image.vo.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
export declare const Width: z.ZodNumber
|
|
2
|
+
export declare const Width: z.core.$ZodBranded<z.ZodNumber, "Width">;
|
|
3
3
|
export type WidthType = z.infer<typeof Width>;
|
|
4
|
-
export declare const Height: z.ZodNumber
|
|
4
|
+
export declare const Height: z.core.$ZodBranded<z.ZodNumber, "Height">;
|
|
5
5
|
export type HeightType = z.infer<typeof Height>;
|
package/dist/image.vo.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
export const Width = z.number().int().positive().max(10000);
|
|
3
|
-
export const Height = z.number().int().positive().max(10000);
|
|
2
|
+
export const Width = z.number().int().positive().max(10000).brand("Width");
|
|
3
|
+
export const Height = z.number().int().positive().max(10000).brand("Height");
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./etags.vo";
|
|
|
10
10
|
export * from "./feature-flag.vo";
|
|
11
11
|
export * from "./filter.vo";
|
|
12
12
|
export * from "./hour.vo";
|
|
13
|
+
export * from "./iban.vo";
|
|
13
14
|
export * from "./image.vo";
|
|
14
15
|
export * from "./language.vo";
|
|
15
16
|
export * from "./leap-year-checker.service";
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./etags.vo";
|
|
|
10
10
|
export * from "./feature-flag.vo";
|
|
11
11
|
export * from "./filter.vo";
|
|
12
12
|
export * from "./hour.vo";
|
|
13
|
+
export * from "./iban.vo";
|
|
13
14
|
export * from "./image.vo";
|
|
14
15
|
export * from "./language.vo";
|
|
15
16
|
export * from "./leap-year-checker.service";
|
package/dist/language.vo.d.ts
CHANGED
package/dist/language.vo.js
CHANGED
package/dist/mime.vo.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export class Mime {
|
|
2
|
+
raw;
|
|
3
|
+
type;
|
|
4
|
+
subtype;
|
|
2
5
|
constructor(value) {
|
|
3
6
|
const [type, subtype] = value.split("/");
|
|
4
7
|
if (typeof type !== "string" || type.length === 0) {
|
|
@@ -27,6 +30,7 @@ export class InvalidMimeError extends Error {
|
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
32
|
export class NotAcceptedMimeError extends Error {
|
|
33
|
+
mime;
|
|
30
34
|
constructor(mime) {
|
|
31
35
|
super();
|
|
32
36
|
Object.setPrototypeOf(this, NotAcceptedMimeError.prototype);
|
package/dist/minute.vo.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export class Minute {
|
|
2
|
+
value;
|
|
3
|
+
static ZERO = new Minute(0);
|
|
4
|
+
static MAX = new Minute(59);
|
|
2
5
|
constructor(candidate) {
|
|
3
6
|
if (!Number.isInteger(candidate)) {
|
|
4
7
|
throw new Error("Invalid minute");
|
|
@@ -30,5 +33,3 @@ export class Minute {
|
|
|
30
33
|
return Array.from({ length: 60 }).map((_, index) => new Minute(index));
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
|
-
Minute.ZERO = new Minute(0);
|
|
34
|
-
Minute.MAX = new Minute(59);
|
package/dist/money.vo.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
2
|
import { RoundingStrategy } from "./rounding.service";
|
|
3
|
-
export declare const MoneyAmount: z.ZodNumber
|
|
3
|
+
export declare const MoneyAmount: z.core.$ZodBranded<z.ZodNumber, "MoneyAmount">;
|
|
4
4
|
export type MoneyAmountType = z.infer<typeof MoneyAmount>;
|
|
5
|
-
export declare const MoneyMultiplicationFactor: z.ZodNumber
|
|
5
|
+
export declare const MoneyMultiplicationFactor: z.core.$ZodBranded<z.ZodNumber, "MoneyMultiplicationFactor">;
|
|
6
6
|
export type MoneyMultiplicationFactorType = z.infer<typeof MoneyMultiplicationFactor>;
|
|
7
|
-
export declare const MoneyDivisionFactor: z.ZodNumber
|
|
7
|
+
export declare const MoneyDivisionFactor: z.core.$ZodBranded<z.ZodNumber, "MoneyDivisionFactor">;
|
|
8
8
|
export type MoneyDivisionFactorType = z.infer<typeof MoneyDivisionFactor>;
|
|
9
9
|
export declare class Money {
|
|
10
10
|
private static readonly ZERO;
|
package/dist/money.vo.js
CHANGED
|
@@ -3,15 +3,21 @@ import { RoundToNearest } from "./rounding.service";
|
|
|
3
3
|
export const MoneyAmount = z
|
|
4
4
|
.number()
|
|
5
5
|
.int({ message: "money.amount.invalid " })
|
|
6
|
-
.min(0, { message: "money.amount.invalid " })
|
|
6
|
+
.min(0, { message: "money.amount.invalid " })
|
|
7
|
+
.brand("MoneyAmount");
|
|
7
8
|
export const MoneyMultiplicationFactor = z
|
|
8
9
|
.number()
|
|
9
|
-
.min(0, { message: "money.multiplication-factor.invalid" })
|
|
10
|
+
.min(0, { message: "money.multiplication-factor.invalid" })
|
|
11
|
+
.brand("MoneyMultiplicationFactor");
|
|
10
12
|
export const MoneyDivisionFactor = z
|
|
11
13
|
.number()
|
|
12
14
|
.min(0, { message: "money.division-factor.invalid" })
|
|
13
|
-
.refine((value) => value !== 0, { message: "money.division-factor.invalid" })
|
|
15
|
+
.refine((value) => value !== 0, { message: "money.division-factor.invalid" })
|
|
16
|
+
.brand("MoneyDivisionFactor");
|
|
14
17
|
export class Money {
|
|
18
|
+
static ZERO = 0;
|
|
19
|
+
amount;
|
|
20
|
+
rounding;
|
|
15
21
|
constructor(value = Money.ZERO, rounding) {
|
|
16
22
|
this.amount = MoneyAmount.parse(value);
|
|
17
23
|
this.rounding = rounding ?? new RoundToNearest();
|
|
@@ -61,4 +67,3 @@ export class Money {
|
|
|
61
67
|
return `${whole}.${fractionFormatted}`;
|
|
62
68
|
}
|
|
63
69
|
}
|
|
64
|
-
Money.ZERO = 0;
|
|
@@ -2,11 +2,11 @@ import { z } from "zod/v4";
|
|
|
2
2
|
type MajorType = number;
|
|
3
3
|
type MinorType = number;
|
|
4
4
|
type PatchType = number;
|
|
5
|
-
export declare const PackageVersionValue: z.ZodPipe<z.ZodString, z.ZodTransform<{
|
|
5
|
+
export declare const PackageVersionValue: z.core.$ZodBranded<z.ZodPipe<z.ZodString, z.ZodTransform<{
|
|
6
6
|
major: number;
|
|
7
7
|
minor: number;
|
|
8
8
|
patch: number;
|
|
9
|
-
}, string
|
|
9
|
+
}, string>>, "PackageVersionValue">;
|
|
10
10
|
export type PackageVersionValueType = z.infer<typeof PackageVersionValue>;
|
|
11
11
|
export declare class PackageVersion {
|
|
12
12
|
readonly major: MajorType;
|
|
@@ -36,8 +36,12 @@ export const PackageVersionValue = z
|
|
|
36
36
|
minor: Number(minor),
|
|
37
37
|
patch: Number(patch),
|
|
38
38
|
};
|
|
39
|
-
})
|
|
39
|
+
})
|
|
40
|
+
.brand("PackageVersionValue");
|
|
40
41
|
export class PackageVersion {
|
|
42
|
+
major;
|
|
43
|
+
minor;
|
|
44
|
+
patch;
|
|
41
45
|
constructor(major, minor, patch) {
|
|
42
46
|
this.major = major;
|
|
43
47
|
this.minor = minor;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
declare const Take: z.ZodNumber
|
|
2
|
+
declare const Take: z.core.$ZodBranded<z.ZodNumber, "Take">;
|
|
3
3
|
type TakeType = z.infer<typeof Take>;
|
|
4
|
-
declare const Skip: z.ZodNumber
|
|
4
|
+
declare const Skip: z.core.$ZodBranded<z.ZodNumber, "Skip">;
|
|
5
5
|
type SkipType = z.infer<typeof Skip>;
|
|
6
|
-
declare const Page: z.ZodDefault<z.ZodPipe<z.ZodCoercedNumber<unknown>, z.ZodTransform<number, number
|
|
6
|
+
declare const Page: z.core.$ZodBranded<z.ZodDefault<z.ZodPipe<z.ZodCoercedNumber<unknown>, z.ZodTransform<number, number>>>, "Page">;
|
|
7
7
|
export type PageType = z.infer<typeof Page>;
|
|
8
8
|
export type PaginationType = {
|
|
9
9
|
values: {
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
const Take = z.number().int().
|
|
3
|
-
const Skip = z.number().int().
|
|
2
|
+
const Take = z.number().int().gte(0).brand("Take");
|
|
3
|
+
const Skip = z.number().int().gte(0).brand("Skip");
|
|
4
4
|
const Page = z.coerce
|
|
5
5
|
.number()
|
|
6
6
|
.int()
|
|
7
7
|
.transform((value) => (value <= 0 ? 1 : value))
|
|
8
|
-
.default(1)
|
|
8
|
+
.default(1)
|
|
9
|
+
.brand("Page");
|
|
9
10
|
export class Pagination {
|
|
10
11
|
static parse(values, _take) {
|
|
11
12
|
const page = Page.parse(values.page);
|
|
12
13
|
const take = Take.parse(_take);
|
|
13
|
-
const skip = (page - 1) * take;
|
|
14
|
+
const skip = Skip.parse((page - 1) * take);
|
|
14
15
|
return { values: { take, skip }, page };
|
|
15
16
|
}
|
|
16
17
|
static prepare(config) {
|
|
17
18
|
const exhausted = Pagination.isExhausted(config);
|
|
18
19
|
const currentPage = config.pagination.page;
|
|
19
20
|
const lastPage = Pagination.getLastPage(config);
|
|
20
|
-
const previousPage = currentPage > 1 ? currentPage - 1 : undefined;
|
|
21
|
-
const nextPage = currentPage < lastPage ? currentPage + 1 : undefined;
|
|
21
|
+
const previousPage = currentPage > 1 ? Page.parse(currentPage - 1) : undefined;
|
|
22
|
+
const nextPage = currentPage < lastPage ? Page.parse(currentPage + 1) : undefined;
|
|
22
23
|
return {
|
|
23
24
|
result: config.result,
|
|
24
25
|
meta: {
|
|
@@ -37,20 +38,21 @@ export class Pagination {
|
|
|
37
38
|
return lastPage <= currentPage;
|
|
38
39
|
}
|
|
39
40
|
static getLastPage(config) {
|
|
40
|
-
|
|
41
|
+
const lastPage = Math.ceil(config.total / config.pagination.values.take);
|
|
42
|
+
return Page.parse(lastPage);
|
|
41
43
|
}
|
|
44
|
+
static empty = {
|
|
45
|
+
result: [],
|
|
46
|
+
meta: {
|
|
47
|
+
exhausted: true,
|
|
48
|
+
currentPage: 1,
|
|
49
|
+
previousPage: undefined,
|
|
50
|
+
nextPage: undefined,
|
|
51
|
+
lastPage: 1,
|
|
52
|
+
total: 0,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
42
55
|
static getFirstPage({ take }) {
|
|
43
|
-
return { values: { take, skip: 0 }, page: 1 };
|
|
56
|
+
return { values: { take, skip: Skip.parse(0) }, page: Page.parse(1) };
|
|
44
57
|
}
|
|
45
58
|
}
|
|
46
|
-
Pagination.empty = {
|
|
47
|
-
result: [],
|
|
48
|
-
meta: {
|
|
49
|
-
exhausted: true,
|
|
50
|
-
currentPage: 1,
|
|
51
|
-
previousPage: undefined,
|
|
52
|
-
nextPage: undefined,
|
|
53
|
-
lastPage: 1,
|
|
54
|
-
total: 0,
|
|
55
|
-
},
|
|
56
|
-
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { Timestamp } from "./timestamp.vo";
|
|
1
2
|
export class RateLimiter {
|
|
3
|
+
options;
|
|
4
|
+
lastInvocationTimestampMs = null;
|
|
2
5
|
constructor(options) {
|
|
3
6
|
this.options = options;
|
|
4
|
-
this.lastInvocationTimestampMs = null;
|
|
5
7
|
}
|
|
6
8
|
verify(currentTimestampMs) {
|
|
7
9
|
if (this.lastInvocationTimestampMs === null || this.lastInvocationTimestampMs === undefined) {
|
|
@@ -15,7 +17,7 @@ export class RateLimiter {
|
|
|
15
17
|
}
|
|
16
18
|
return {
|
|
17
19
|
allowed: false,
|
|
18
|
-
remainingMs: nextAllowedTimestampMs - currentTimestampMs,
|
|
20
|
+
remainingMs: Timestamp.parse(nextAllowedTimestampMs - currentTimestampMs),
|
|
19
21
|
};
|
|
20
22
|
}
|
|
21
23
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
export declare const ReorderingItemPositionValue: z.ZodNumber
|
|
2
|
+
export declare const ReorderingItemPositionValue: z.core.$ZodBranded<z.ZodNumber, "ReorderingItemPositionValue">;
|
|
3
3
|
export type ReorderingItemPositionValueType = z.infer<typeof ReorderingItemPositionValue>;
|
|
4
|
-
export declare const ReorderingCorrelationId: z.ZodString
|
|
4
|
+
export declare const ReorderingCorrelationId: z.core.$ZodBranded<z.ZodString, "ReorderingCorrelationId">;
|
|
5
5
|
export type ReorderingCorrelationIdType = z.infer<typeof ReorderingCorrelationId>;
|
|
6
|
-
export declare const ReorderingItemId: z.ZodUUID
|
|
6
|
+
export declare const ReorderingItemId: z.core.$ZodBranded<z.ZodUUID, "ReorderingItemId">;
|
|
7
7
|
export type ReorderingItemIdType = z.infer<typeof ReorderingItemId>;
|
|
8
8
|
export declare const Reordering: z.ZodObject<{
|
|
9
|
-
correlationId: z.ZodString
|
|
10
|
-
id: z.ZodUUID
|
|
11
|
-
position: z.ZodNumber
|
|
9
|
+
correlationId: z.core.$ZodBranded<z.ZodString, "ReorderingCorrelationId">;
|
|
10
|
+
id: z.core.$ZodBranded<z.ZodUUID, "ReorderingItemId">;
|
|
11
|
+
position: z.core.$ZodBranded<z.ZodNumber, "ReorderingItemPositionValue">;
|
|
12
12
|
}, z.core.$strip>;
|
|
13
13
|
export type ReorderingType = z.infer<typeof Reordering>;
|
|
14
14
|
export type WithReorderingPositionValue<T> = T & {
|
|
@@ -47,7 +47,7 @@ export declare class ReorderingCalculator {
|
|
|
47
47
|
delete(id: ReorderingItem["id"]): void;
|
|
48
48
|
transfer(transfer: ReorderingTransfer): ReturnType<ReorderingCalculator["read"]>;
|
|
49
49
|
read(): {
|
|
50
|
-
ids: string[];
|
|
50
|
+
ids: (string & z.core.$brand<"ReorderingItemId">)[];
|
|
51
51
|
items: ReorderingItem[];
|
|
52
52
|
};
|
|
53
53
|
private recalculate;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
2
|
import { DoublyLinkedList, Node } from "./dll.service";
|
|
3
|
-
export const ReorderingItemPositionValue = z.number().int().min(0);
|
|
4
|
-
export const ReorderingCorrelationId = z.string().min(1);
|
|
5
|
-
export const ReorderingItemId = z.uuid();
|
|
3
|
+
export const ReorderingItemPositionValue = z.number().int().min(0).brand("ReorderingItemPositionValue");
|
|
4
|
+
export const ReorderingCorrelationId = z.string().min(1).brand("ReorderingCorrelationId");
|
|
5
|
+
export const ReorderingItemId = z.uuid().brand("ReorderingItemId");
|
|
6
6
|
export const Reordering = z.object({
|
|
7
7
|
correlationId: ReorderingCorrelationId,
|
|
8
8
|
id: ReorderingItemId,
|
|
9
9
|
position: ReorderingItemPositionValue,
|
|
10
10
|
});
|
|
11
11
|
export class ReorderingPosition {
|
|
12
|
+
value;
|
|
12
13
|
constructor(value) {
|
|
13
14
|
if (!ReorderingItemPositionValue.safeParse(value).success) {
|
|
14
15
|
throw new Error("Position is not a positive integer");
|
|
@@ -20,6 +21,8 @@ export class ReorderingPosition {
|
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
class ReorderingItem {
|
|
24
|
+
id;
|
|
25
|
+
position;
|
|
23
26
|
constructor(id, position) {
|
|
24
27
|
this.id = id;
|
|
25
28
|
this.position = position;
|
|
@@ -35,6 +38,8 @@ var ReorderingTransferDirection;
|
|
|
35
38
|
ReorderingTransferDirection["noop"] = "noop";
|
|
36
39
|
})(ReorderingTransferDirection || (ReorderingTransferDirection = {}));
|
|
37
40
|
export class ReorderingTransfer {
|
|
41
|
+
id;
|
|
42
|
+
to;
|
|
38
43
|
constructor(config) {
|
|
39
44
|
this.id = config.id;
|
|
40
45
|
this.to = new ReorderingPosition(config.to);
|
|
@@ -49,6 +54,7 @@ export class ReorderingTransfer {
|
|
|
49
54
|
}
|
|
50
55
|
}
|
|
51
56
|
export class ReorderingCalculator {
|
|
57
|
+
dll;
|
|
52
58
|
constructor() {
|
|
53
59
|
this.dll = DoublyLinkedList.fromArray([]);
|
|
54
60
|
}
|
|
@@ -60,7 +66,7 @@ export class ReorderingCalculator {
|
|
|
60
66
|
return reordering;
|
|
61
67
|
}
|
|
62
68
|
add(id) {
|
|
63
|
-
const position = new ReorderingPosition(this.dll.getSize());
|
|
69
|
+
const position = new ReorderingPosition(ReorderingItemPositionValue.parse(this.dll.getSize()));
|
|
64
70
|
const item = new ReorderingItem(id, position);
|
|
65
71
|
this.dll.append(new Node(item));
|
|
66
72
|
return item;
|
|
@@ -109,10 +115,8 @@ export class ReorderingCalculator {
|
|
|
109
115
|
export class ReorderingIntegrator {
|
|
110
116
|
static appendPosition(reordering) {
|
|
111
117
|
return function (item) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
position: reordering.find((x) => x.id === item.id)?.position ?? 0,
|
|
115
|
-
};
|
|
118
|
+
const position = ReorderingItemPositionValue.parse(reordering.find((x) => x.id === item.id)?.position ?? 0);
|
|
119
|
+
return { ...item, position };
|
|
116
120
|
};
|
|
117
121
|
}
|
|
118
122
|
static sortByPosition() {
|
package/dist/revision.vo.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
2
|
import { ETag, WeakETag } from "./etags.vo";
|
|
3
|
-
export declare const RevisionValue: z.ZodNumber
|
|
3
|
+
export declare const RevisionValue: z.core.$ZodBranded<z.ZodNumber, "RevisionValue">;
|
|
4
4
|
export type RevisionValueType = z.infer<typeof RevisionValue>;
|
|
5
5
|
export declare class Revision {
|
|
6
6
|
readonly value: RevisionValueType;
|
package/dist/revision.vo.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
export const RevisionValue = z.number().int().min(0);
|
|
2
|
+
export const RevisionValue = z.number().int().min(0).brand("RevisionValue");
|
|
3
3
|
export class Revision {
|
|
4
|
+
value;
|
|
5
|
+
static initial = RevisionValue.parse(0);
|
|
4
6
|
constructor(value) {
|
|
5
7
|
const result = RevisionValue.safeParse(value);
|
|
6
8
|
if (!result.success)
|
|
@@ -30,7 +32,6 @@ export class Revision {
|
|
|
30
32
|
return new Revision(weakEtag.revision);
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
|
-
Revision.initial = 0;
|
|
34
35
|
export class RevisionMismatchError extends Error {
|
|
35
36
|
constructor() {
|
|
36
37
|
super();
|
package/dist/rounding.service.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { RoundToNearest } from "./rounding.service";
|
|
2
2
|
import { Sum } from "./sum.service";
|
|
3
3
|
export class SimpleLinearRegression {
|
|
4
|
+
params;
|
|
5
|
+
rounding = new RoundToNearest();
|
|
4
6
|
constructor(params, rounding) {
|
|
5
7
|
this.params = params;
|
|
6
|
-
this.rounding = new RoundToNearest();
|
|
7
8
|
this.rounding = rounding ?? this.rounding;
|
|
8
9
|
}
|
|
9
10
|
static fromPairs(pairs, rounding) {
|
package/dist/size.vo.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare enum SizeUnit {
|
|
|
5
5
|
MB = "MB",
|
|
6
6
|
GB = "GB"
|
|
7
7
|
}
|
|
8
|
-
declare const SizeValue: z.ZodNumber
|
|
8
|
+
declare const SizeValue: z.core.$ZodBranded<z.ZodNumber, "SizeValue">;
|
|
9
9
|
export type SizeValueType = z.infer<typeof SizeValue>;
|
|
10
10
|
type SizeConfigType = {
|
|
11
11
|
unit: SizeUnit;
|