@bgord/tools 0.17.2 → 1.0.0

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.
Files changed (257) hide show
  1. package/dist/age-years.vo.d.ts +11 -0
  2. package/dist/age-years.vo.js +9 -0
  3. package/dist/age.vo.d.ts +11 -16
  4. package/dist/age.vo.js +20 -31
  5. package/dist/api-key.vo.d.ts +3 -1
  6. package/dist/api-key.vo.js +10 -5
  7. package/dist/basename.vo.d.ts +9 -9
  8. package/dist/basename.vo.js +22 -22
  9. package/dist/clock.vo.d.ts +10 -4
  10. package/dist/clock.vo.js +12 -14
  11. package/dist/date-calculator.service.d.ts +2 -1
  12. package/dist/date-formatter.service.d.ts +3 -4
  13. package/dist/date-range.vo.d.ts +7 -1
  14. package/dist/date-range.vo.js +5 -2
  15. package/dist/day-iso-id.vo.d.ts +5 -2
  16. package/dist/day-iso-id.vo.js +11 -7
  17. package/dist/day.vo.d.ts +4 -3
  18. package/dist/day.vo.js +18 -16
  19. package/dist/directory-path-absolute.vo.d.ts +10 -6
  20. package/dist/directory-path-absolute.vo.js +19 -17
  21. package/dist/directory-path-relative.vo.d.ts +10 -7
  22. package/dist/directory-path-relative.vo.js +18 -17
  23. package/dist/division-factor.vo.d.ts +7 -0
  24. package/dist/division-factor.vo.js +9 -0
  25. package/dist/duration-ms.vo.d.ts +6 -0
  26. package/dist/duration-ms.vo.js +3 -0
  27. package/dist/duration.service.d.ts +2 -14
  28. package/dist/duration.service.js +16 -35
  29. package/dist/email-mask.service.d.ts +1 -6
  30. package/dist/email-mask.service.js +6 -8
  31. package/dist/etags.vo.d.ts +4 -3
  32. package/dist/etags.vo.js +3 -3
  33. package/dist/extension.vo.d.ts +6 -4
  34. package/dist/extension.vo.js +15 -10
  35. package/dist/feature-flag-value.vo.d.ts +10 -0
  36. package/dist/feature-flag-value.vo.js +8 -0
  37. package/dist/feature-flag.vo.d.ts +1 -7
  38. package/dist/feature-flag.vo.js +1 -7
  39. package/dist/file-path-absolute-schema.vo.d.ts +10 -7
  40. package/dist/file-path-absolute-schema.vo.js +17 -17
  41. package/dist/file-path-relative-schema.vo.d.ts +10 -7
  42. package/dist/file-path-relative-schema.vo.js +14 -12
  43. package/dist/file-path.vo.d.ts +4 -4
  44. package/dist/file-path.vo.js +8 -8
  45. package/dist/filename-from-string.vo.d.ts +4 -2
  46. package/dist/filename-from-string.vo.js +10 -8
  47. package/dist/filename-suffix.vo.d.ts +7 -3
  48. package/dist/filename-suffix.vo.js +13 -7
  49. package/dist/filename.vo.d.ts +2 -0
  50. package/dist/filename.vo.js +8 -2
  51. package/dist/height-milimiters.vo.d.ts +6 -0
  52. package/dist/height-milimiters.vo.js +10 -0
  53. package/dist/height.vo.d.ts +3 -20
  54. package/dist/height.vo.js +11 -62
  55. package/dist/hour-format.service.js +1 -1
  56. package/dist/hour-schema.vo.d.ts +7 -0
  57. package/dist/hour-schema.vo.js +8 -0
  58. package/dist/hour.vo.d.ts +4 -3
  59. package/dist/hour.vo.js +8 -8
  60. package/dist/iban-mask.service.d.ts +1 -3
  61. package/dist/iban-mask.service.js +2 -2
  62. package/dist/iban-schema.vo.d.ts +7 -0
  63. package/dist/iban-schema.vo.js +10 -0
  64. package/dist/iban.vo.d.ts +4 -10
  65. package/dist/iban.vo.js +6 -13
  66. package/dist/image.vo.d.ts +6 -4
  67. package/dist/image.vo.js +13 -12
  68. package/dist/index.d.ts +24 -2
  69. package/dist/index.js +24 -2
  70. package/dist/language.vo.d.ts +2 -1
  71. package/dist/language.vo.js +6 -4
  72. package/dist/linear-regression.service.d.ts +27 -0
  73. package/dist/{simple-linear-regression.service.js → linear-regression.service.js} +17 -15
  74. package/dist/mean.service.d.ts +3 -1
  75. package/dist/mean.service.js +3 -4
  76. package/dist/mime-types.vo.d.ts +1 -2
  77. package/dist/mime-value.vo.d.ts +9 -0
  78. package/dist/mime-value.vo.js +9 -0
  79. package/dist/mime.vo.d.ts +11 -17
  80. package/dist/mime.vo.js +10 -27
  81. package/dist/min-max-scaler.service.d.ts +7 -5
  82. package/dist/min-max-scaler.service.js +12 -10
  83. package/dist/minute-schema.vo.d.ts +7 -0
  84. package/dist/minute-schema.vo.js +8 -0
  85. package/dist/minute.vo.d.ts +4 -3
  86. package/dist/minute.vo.js +8 -8
  87. package/dist/money-amount.vo.d.ts +7 -0
  88. package/dist/money-amount.vo.js +7 -0
  89. package/dist/money.vo.d.ts +9 -18
  90. package/dist/money.vo.js +14 -27
  91. package/dist/month-iso-id.vo.d.ts +4 -2
  92. package/dist/month-iso-id.vo.js +13 -7
  93. package/dist/month.vo.d.ts +4 -3
  94. package/dist/month.vo.js +21 -21
  95. package/dist/multiplication-factor.vo.d.ts +7 -0
  96. package/dist/multiplication-factor.vo.js +9 -0
  97. package/dist/object-key.vo.d.ts +9 -6
  98. package/dist/object-key.vo.js +20 -19
  99. package/dist/outlier-detector.service.d.ts +3 -1
  100. package/dist/outlier-detector.service.js +2 -2
  101. package/dist/package-version-schema.vo.d.ts +11 -0
  102. package/dist/package-version-schema.vo.js +15 -0
  103. package/dist/package-version.vo.d.ts +11 -20
  104. package/dist/package-version.vo.js +11 -20
  105. package/dist/pagination-page.vo.d.ts +6 -0
  106. package/dist/pagination-page.vo.js +7 -0
  107. package/dist/pagination-skip.vo.d.ts +7 -0
  108. package/dist/pagination-skip.vo.js +9 -0
  109. package/dist/pagination-take.vo.d.ts +7 -0
  110. package/dist/pagination-take.vo.js +9 -0
  111. package/dist/pagination.service.d.ts +3 -8
  112. package/dist/pagination.service.js +5 -12
  113. package/dist/percentage.service.d.ts +3 -1
  114. package/dist/percentage.service.js +2 -2
  115. package/dist/population-standard-deviation.service.d.ts +3 -1
  116. package/dist/population-standard-deviation.service.js +5 -4
  117. package/dist/quarter-iso-id.vo.d.ts +3 -2
  118. package/dist/quarter-iso-id.vo.js +7 -9
  119. package/dist/quarter.vo.d.ts +2 -1
  120. package/dist/quarter.vo.js +10 -7
  121. package/dist/random.service.d.ts +3 -4
  122. package/dist/random.service.js +5 -11
  123. package/dist/rate-limiter.service.d.ts +2 -2
  124. package/dist/rate-limiter.service.js +8 -8
  125. package/dist/reordering-item-position-value.vo.d.ts +6 -0
  126. package/dist/reordering-item-position-value.vo.js +6 -0
  127. package/dist/reordering.service.d.ts +7 -23
  128. package/dist/reordering.service.js +15 -24
  129. package/dist/revision-value.vo.d.ts +7 -0
  130. package/dist/revision-value.vo.js +6 -0
  131. package/dist/revision.vo.d.ts +6 -13
  132. package/dist/revision.vo.js +10 -22
  133. package/dist/rounding.adapter.d.ts +7 -2
  134. package/dist/rounding.adapter.js +13 -5
  135. package/dist/size-bytes.vo.d.ts +6 -0
  136. package/dist/size-bytes.vo.js +7 -0
  137. package/dist/size.vo.d.ts +15 -15
  138. package/dist/size.vo.js +41 -51
  139. package/dist/stopwatch.service.d.ts +3 -1
  140. package/dist/stopwatch.service.js +2 -2
  141. package/dist/sum.service.js +8 -8
  142. package/dist/thousands-separator.service.js +4 -1
  143. package/dist/time.service.d.ts +8 -0
  144. package/dist/time.service.js +13 -0
  145. package/dist/timestamp.vo.d.ts +1 -1
  146. package/dist/timestamp.vo.js +4 -5
  147. package/dist/timezone.vo.d.ts +4 -1
  148. package/dist/timezone.vo.js +12 -6
  149. package/dist/tsconfig.tsbuildinfo +1 -1
  150. package/dist/week-iso-id.vo.d.ts +4 -2
  151. package/dist/week-iso-id.vo.js +15 -9
  152. package/dist/week.vo.d.ts +4 -3
  153. package/dist/week.vo.js +21 -22
  154. package/dist/weekday.vo.d.ts +1 -1
  155. package/dist/weekday.vo.js +6 -8
  156. package/dist/weight-grams.vo.d.ts +7 -0
  157. package/dist/weight-grams.vo.js +7 -0
  158. package/dist/weight.vo.d.ts +12 -35
  159. package/dist/weight.vo.js +23 -72
  160. package/dist/year-iso-id.vo.d.ts +3 -2
  161. package/dist/year-iso-id.vo.js +6 -4
  162. package/dist/year.vo.d.ts +5 -6
  163. package/dist/year.vo.js +21 -26
  164. package/dist/z-score.service.d.ts +3 -1
  165. package/dist/z-score.service.js +2 -2
  166. package/package.json +4 -4
  167. package/readme.md +21 -2
  168. package/src/age-years.vo.ts +14 -0
  169. package/src/age.vo.ts +22 -35
  170. package/src/api-key.vo.ts +11 -5
  171. package/src/basename.vo.ts +24 -22
  172. package/src/clock.vo.ts +16 -17
  173. package/src/date-calculator.service.ts +2 -1
  174. package/src/date-formatter.service.ts +4 -5
  175. package/src/date-range.vo.ts +6 -2
  176. package/src/day-iso-id.vo.ts +12 -8
  177. package/src/day.vo.ts +27 -24
  178. package/src/directory-path-absolute.vo.ts +23 -18
  179. package/src/directory-path-relative.vo.ts +21 -18
  180. package/src/division-factor.vo.ts +13 -0
  181. package/src/duration-ms.vo.ts +7 -0
  182. package/src/duration.service.ts +16 -40
  183. package/src/email-mask.service.ts +7 -15
  184. package/src/etags.vo.ts +4 -5
  185. package/src/extension.vo.ts +17 -10
  186. package/src/feature-flag-value.vo.ts +12 -0
  187. package/src/feature-flag.vo.ts +1 -9
  188. package/src/file-path-absolute-schema.vo.ts +18 -17
  189. package/src/file-path-relative-schema.vo.ts +15 -12
  190. package/src/file-path.vo.ts +8 -8
  191. package/src/filename-from-string.vo.ts +12 -9
  192. package/src/filename-suffix.vo.ts +14 -7
  193. package/src/filename.vo.ts +11 -2
  194. package/src/height-milimiters.vo.ts +12 -0
  195. package/src/height.vo.ts +12 -83
  196. package/src/hour-format.service.ts +2 -1
  197. package/src/hour-schema.vo.ts +12 -0
  198. package/src/hour.vo.ts +12 -12
  199. package/src/iban-mask.service.ts +3 -5
  200. package/src/iban-schema.vo.ts +15 -0
  201. package/src/iban.vo.ts +9 -22
  202. package/src/image.vo.ts +14 -12
  203. package/src/index.ts +24 -2
  204. package/src/language.vo.ts +7 -4
  205. package/src/linear-regression.service.ts +71 -0
  206. package/src/mean.service.ts +3 -5
  207. package/src/mime-types.vo.ts +1 -3
  208. package/src/mime-value.vo.ts +12 -0
  209. package/src/mime.vo.ts +12 -33
  210. package/src/min-max-scaler.service.ts +13 -11
  211. package/src/minute-schema.vo.ts +12 -0
  212. package/src/minute.vo.ts +12 -12
  213. package/src/money-amount.vo.ts +11 -0
  214. package/src/money.vo.ts +20 -38
  215. package/src/month-iso-id.vo.ts +14 -7
  216. package/src/month.vo.ts +25 -24
  217. package/src/multiplication-factor.vo.ts +13 -0
  218. package/src/object-key.vo.ts +25 -21
  219. package/src/outlier-detector.service.ts +2 -2
  220. package/src/package-version-schema.vo.ts +21 -0
  221. package/src/package-version.vo.ts +17 -33
  222. package/src/pagination-page.vo.ts +11 -0
  223. package/src/pagination-skip.vo.ts +13 -0
  224. package/src/pagination-take.vo.ts +13 -0
  225. package/src/pagination.service.ts +5 -22
  226. package/src/percentage.service.ts +2 -2
  227. package/src/population-standard-deviation.service.ts +5 -4
  228. package/src/quarter-iso-id.vo.ts +7 -10
  229. package/src/quarter.vo.ts +14 -9
  230. package/src/random.service.ts +6 -9
  231. package/src/rate-limiter.service.ts +9 -8
  232. package/src/reordering-item-position-value.vo.ts +10 -0
  233. package/src/reordering.service.ts +19 -28
  234. package/src/revision-value.vo.ts +10 -0
  235. package/src/revision.vo.ts +10 -25
  236. package/src/rounding.adapter.ts +16 -3
  237. package/src/size-bytes.vo.ts +11 -0
  238. package/src/size.vo.ts +43 -54
  239. package/src/stopwatch.service.ts +3 -3
  240. package/src/sum.service.ts +8 -8
  241. package/src/thousands-separator.service.ts +4 -1
  242. package/src/time.service.ts +15 -0
  243. package/src/timestamp.vo.ts +4 -5
  244. package/src/timezone.vo.ts +12 -6
  245. package/src/week-iso-id.vo.ts +16 -12
  246. package/src/week.vo.ts +26 -28
  247. package/src/weekday.vo.ts +6 -9
  248. package/src/weight-grams.vo.ts +11 -0
  249. package/src/weight.vo.ts +28 -85
  250. package/src/year-iso-id.vo.ts +7 -4
  251. package/src/year.vo.ts +27 -33
  252. package/src/z-score.service.ts +2 -2
  253. package/dist/simple-linear-regression.service.d.ts +0 -25
  254. package/dist/streak-calculator.service.d.ts +0 -13
  255. package/dist/streak-calculator.service.js +0 -22
  256. package/src/simple-linear-regression.service.ts +0 -69
  257. package/src/streak-calculator.service.ts +0 -32
@@ -1,8 +1,11 @@
1
1
  import { z } from "zod/v4";
2
- export declare const ObjectKeyMustNotStartWithSlashError: "obj_key_must_not_start_with_slash";
3
- export declare const ObjectKeyBackslashForbiddenError: "obj_key_backslash_forbidden";
4
- export declare const ObjectKeyControlCharsForbiddenError: "obj_key_control_chars_forbidden";
5
- export declare const ObjectKeyEmptyError: "obj_key_empty";
6
- export declare const ObjectKeyBadSegmentsError: "obj_key_bad_segments";
7
- export declare const ObjectKey: z.core.$ZodBranded<z.ZodString, "object_key">;
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>;
@@ -1,21 +1,22 @@
1
1
  import { z } from "zod/v4";
2
- export const ObjectKeyMustNotStartWithSlashError = "obj_key_must_not_start_with_slash";
3
- export const ObjectKeyBackslashForbiddenError = "obj_key_backslash_forbidden";
4
- export const ObjectKeyControlCharsForbiddenError = "obj_key_control_chars_forbidden";
5
- export const ObjectKeyEmptyError = "obj_key_empty";
6
- export const ObjectKeyBadSegmentsError = "obj_key_bad_segments";
7
- // biome-ignore lint: lint/suspicious/noControlCharactersInRegex
8
- const CONTROL_CHARS_REGEX = /[\u0000-\u001F\u007F]/;
9
- const SEGMENT_ALLOWED_REGEX = /^[a-z0-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
- .trim()
13
- // fastest early exits first:
14
- .refine((value) => value.length > 0, ObjectKeyEmptyError)
15
- .refine((value) => !value.startsWith("/"), ObjectKeyMustNotStartWithSlashError)
16
- .refine((value) => !value.includes("\\"), ObjectKeyBackslashForbiddenError)
17
- .refine((value) => !CONTROL_CHARS_REGEX.test(value), ObjectKeyControlCharsForbiddenError)
18
- .refine((value) => value
19
- .split("/")
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 OutlierDetectorMinValuesError: "outlier.detector.min.values";
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 OutlierDetectorMinValuesError = "outlier.detector.min.values";
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(OutlierDetectorMinValuesError);
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: MajorType;
16
- readonly minor: MinorType;
17
- readonly patch: PatchType;
18
- constructor(major: MajorType, minor: MinorType, patch: PatchType);
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
- static fromStringWithV(value: string): PackageVersion;
22
- static fromString(value: string): PackageVersion;
10
+ toJSON(): {
11
+ major: number;
12
+ minor: number;
13
+ patch: number;
14
+ };
23
15
  }
24
- export {};
@@ -1,16 +1,4 @@
1
- import { z } from "zod/v4";
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
- static fromStringWithV(value) {
42
- const parsed = PackageVersionValue.parse(value);
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,7 @@
1
+ import { z } from "zod/v4";
2
+ export const PaginationPageError = { Type: "pagination.page.Type" };
3
+ export const Page = z.coerce
4
+ .number(PaginationPageError.Type)
5
+ .int(PaginationPageError.Type)
6
+ .transform((value) => (value <= 0 ? 1 : value))
7
+ .default(1);
@@ -0,0 +1,7 @@
1
+ import { z } from "zod/v4";
2
+ export declare const PaginationSkipError: {
3
+ readonly Type: "pagination.skip.type";
4
+ readonly Invalid: "pagination.skip.invalid";
5
+ };
6
+ export declare const Skip: z.ZodNumber;
7
+ export type SkipType = z.infer<typeof Skip>;
@@ -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,7 @@
1
+ import { z } from "zod/v4";
2
+ export declare const PaginationTakeError: {
3
+ readonly Type: "pagination.take.type";
4
+ readonly Invalid: "pagination.take.invalid";
5
+ };
6
+ export declare const Take: z.ZodNumber;
7
+ export type TakeType = z.infer<typeof Take>;
@@ -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 { z } from "zod/v4";
2
- declare const Take: z.ZodNumber;
3
- type TakeType = z.infer<typeof Take>;
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 { z } from "zod/v4";
2
- const PaginationTakeError = { error: "pagination.take.invalid" };
3
- const PaginationSkipError = { error: "pagination.skip.invalid" };
4
- const PaginationPageError = { error: "pagination.page.invalid" };
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(Math.ceil(config.total / config.pagination.values.take));
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 PercentageInvalidDenominatorError: "percentage.invalid.denominator";
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 PercentageInvalidDenominatorError = "percentage.invalid.denominator";
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(PercentageInvalidDenominatorError);
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 PopulationStandardDeviationMinValuesError: "population.standard.deviation.min.values";
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 PopulationStandardDeviationMinValuesError = "population.standard.deviation.min.values";
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(PopulationStandardDeviationMinValuesError);
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 sumOfSquaredDifferences = Sum.of(squaredDifferences);
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 error: "quarter-iso-id.invalid";
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 = { error: "quarter-iso-id.invalid" };
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
- .refine((value) => {
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");
@@ -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
  }
@@ -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(new Date(Date.UTC(year, 0, 1)), quarter);
22
- return Quarter.fromTimestamp(Timestamp.parse(reference.getTime()));
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
  }
@@ -2,10 +2,9 @@ type RandomGenerateConfigType = {
2
2
  min: number;
3
3
  max: number;
4
4
  };
5
- export declare const RandomMinNotIntegerError: "random.min.not.integer";
6
- export declare const RandomMaxNotIntegerError: "random.max.not.integer";
7
- export declare const RandomMinEqualsMaxError: "random.min.equals.max";
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;
@@ -1,21 +1,15 @@
1
- export const RandomMinNotIntegerError = "random.min.not.integer";
2
- export const RandomMaxNotIntegerError = "random.max.not.integer";
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(RandomMinEqualsMaxError);
10
+ throw new Error(RandomError.MinMax);
17
11
  if (min > max)
18
- throw new Error(RandomMinGreaterThanMaxError);
19
- return Math.floor(Math.random() * (max - min + 1)) + min;
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 lastInvocationTimestampMs;
13
+ private lastInvocation;
14
14
  constructor(duration: Duration);
15
- verify(currentTimestampMs: TimestampType): RateLimiterResultType;
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
- lastInvocationTimestampMs = null;
4
+ lastInvocation = null;
5
5
  constructor(duration) {
6
6
  this.duration = duration;
7
7
  }
8
- verify(currentTimestampMs) {
9
- if (this.lastInvocationTimestampMs == null) {
10
- this.lastInvocationTimestampMs = currentTimestampMs;
8
+ verify(now) {
9
+ if (this.lastInvocation == null) {
10
+ this.lastInvocation = now;
11
11
  return { allowed: true };
12
12
  }
13
- const nextAllowedTimestampMs = this.lastInvocationTimestampMs + this.duration.ms;
14
- if (nextAllowedTimestampMs <= currentTimestampMs) {
15
- this.lastInvocationTimestampMs = currentTimestampMs;
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 = nextAllowedTimestampMs - currentTimestampMs;
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
- export declare const ReorderingPositionError: {
3
- readonly error: "reordering.position.invalid";
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 ReorderingCannotFindItemError: {
6
- readonly error: "reordering.item.not_found";
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;