@stndrds/schema 1.0.0-alpha.294 → 1.0.0-alpha.295

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 (127) hide show
  1. package/LICENSE +111 -0
  2. package/README.md +7 -0
  3. package/dist/capabilities.js +2 -77
  4. package/dist/capabilities.mjs +2 -70
  5. package/dist/chunk-23KPS33D.js +2 -0
  6. package/dist/chunk-257HAQVV.mjs +6 -0
  7. package/dist/chunk-47KVYDKG.js +2 -0
  8. package/dist/chunk-4OTKOCGB.mjs +2 -0
  9. package/dist/chunk-4VCADZK4.mjs +2 -0
  10. package/dist/chunk-7SDHYJX4.mjs +2 -0
  11. package/dist/chunk-DPD6ZWL2.js +2 -0
  12. package/dist/chunk-EREGHAGI.js +2 -0
  13. package/dist/chunk-GKXTXH4Y.mjs +2 -0
  14. package/dist/chunk-GXSNLYRR.js +2 -0
  15. package/dist/chunk-HTY3NECU.mjs +2 -0
  16. package/dist/chunk-JFSQ24XR.js +2 -0
  17. package/dist/chunk-JOJ4LF2I.js +2 -0
  18. package/dist/chunk-JOS2XMXY.js +2 -0
  19. package/dist/chunk-JVLH3DVZ.js +2 -0
  20. package/dist/chunk-KG2ADZG6.mjs +2 -0
  21. package/dist/chunk-KLR22JMC.js +2 -0
  22. package/dist/chunk-KSPJP74K.mjs +2 -0
  23. package/dist/chunk-KYPEBOPW.mjs +2 -0
  24. package/dist/chunk-LB4TNMZU.mjs +2 -0
  25. package/dist/chunk-LSCBR4VS.js +2 -0
  26. package/dist/chunk-LWSOKXPF.js +2 -0
  27. package/dist/chunk-O34B5KOW.mjs +2 -0
  28. package/dist/chunk-OCAMDRO3.mjs +4 -0
  29. package/dist/chunk-PFO7NWQW.mjs +2 -0
  30. package/dist/chunk-Q7TQCRSD.mjs +2 -0
  31. package/dist/chunk-SLYRQ72J.js +2 -0
  32. package/dist/chunk-TKABCIEO.js +12 -0
  33. package/dist/chunk-TP63U7PL.js +4 -0
  34. package/dist/chunk-UXISKZ5Y.js +2 -0
  35. package/dist/chunk-VKFLXFPP.mjs +2 -0
  36. package/dist/chunk-WMQRTFOP.mjs +2 -0
  37. package/dist/chunk-XHEBV2HE.js +2 -0
  38. package/dist/chunk-XMQV2WFY.mjs +2 -0
  39. package/dist/chunk-XPF6CGAW.js +6 -0
  40. package/dist/chunk-XRDP2Y4J.mjs +2 -0
  41. package/dist/chunk-XUAP7KWK.js +2 -0
  42. package/dist/chunk-XXTKNIBK.js +2 -0
  43. package/dist/chunk-YBDR5ZMH.mjs +12 -0
  44. package/dist/chunk-YIXNAWH6.mjs +2 -0
  45. package/dist/exceptions.d.mts +5 -0
  46. package/dist/exceptions.d.ts +5 -0
  47. package/dist/exceptions.js +1 -158
  48. package/dist/exceptions.mjs +1 -1
  49. package/dist/index.d.mts +415 -116
  50. package/dist/index.d.ts +415 -116
  51. package/dist/index.js +30 -10514
  52. package/dist/index.mjs +30 -9626
  53. package/dist/utils.js +1 -31
  54. package/dist/utils.mjs +1 -2
  55. package/dist/validation/all.js +1 -131
  56. package/dist/validation/all.mjs +1 -18
  57. package/dist/validation/complex/currency.js +1 -11
  58. package/dist/validation/complex/currency.mjs +1 -2
  59. package/dist/validation/complex/location.js +1 -11
  60. package/dist/validation/complex/location.mjs +1 -2
  61. package/dist/validation/complex/phone.js +1 -11
  62. package/dist/validation/complex/phone.mjs +1 -2
  63. package/dist/validation/complex/relation.js +1 -19
  64. package/dist/validation/complex/relation.mjs +1 -2
  65. package/dist/validation/complex/richtext.js +1 -11
  66. package/dist/validation/complex/richtext.mjs +1 -2
  67. package/dist/validation/complex/select.js +1 -19
  68. package/dist/validation/complex/select.mjs +1 -2
  69. package/dist/validation/complex/user.js +1 -11
  70. package/dist/validation/complex/user.mjs +1 -2
  71. package/dist/validation/computed/formula.js +1 -11
  72. package/dist/validation/computed/formula.mjs +1 -2
  73. package/dist/validation/computed/rollup.js +1 -11
  74. package/dist/validation/computed/rollup.mjs +1 -2
  75. package/dist/validation/config/index.js +1 -52
  76. package/dist/validation/config/index.mjs +1 -7
  77. package/dist/validation/core/index.js +1 -14
  78. package/dist/validation/core/index.mjs +1 -1
  79. package/dist/validation/object/index.js +1 -69
  80. package/dist/validation/object/index.mjs +1 -16
  81. package/dist/validation/primitives/checkbox.js +1 -11
  82. package/dist/validation/primitives/checkbox.mjs +1 -2
  83. package/dist/validation/primitives/date.js +1 -11
  84. package/dist/validation/primitives/date.mjs +1 -2
  85. package/dist/validation/primitives/number.js +1 -11
  86. package/dist/validation/primitives/number.mjs +1 -2
  87. package/dist/validation/primitives/text.js +1 -11
  88. package/dist/validation/primitives/text.mjs +1 -2
  89. package/package.json +7 -5
  90. package/dist/chunk-2WWGHULM.mjs +0 -226
  91. package/dist/chunk-4KMUATDG.js +0 -609
  92. package/dist/chunk-5WATIVCA.js +0 -10
  93. package/dist/chunk-ACKMC6FL.js +0 -17
  94. package/dist/chunk-AYVHMVKQ.mjs +0 -15
  95. package/dist/chunk-CLZORRMS.mjs +0 -570
  96. package/dist/chunk-DVXGSTWJ.js +0 -81
  97. package/dist/chunk-E6JUYGJX.js +0 -22
  98. package/dist/chunk-EEH4XQ7W.js +0 -61
  99. package/dist/chunk-EW5XR2X3.js +0 -12
  100. package/dist/chunk-GO6LQADH.mjs +0 -57
  101. package/dist/chunk-HRQEZUAA.mjs +0 -29
  102. package/dist/chunk-HTSTPTNZ.js +0 -10
  103. package/dist/chunk-HURC6CW3.js +0 -241
  104. package/dist/chunk-JZNR4HKQ.mjs +0 -1432
  105. package/dist/chunk-KAWYU7TE.js +0 -657
  106. package/dist/chunk-KNGWHQLR.js +0 -16
  107. package/dist/chunk-LV3FEUKU.mjs +0 -14
  108. package/dist/chunk-NS63SPNN.mjs +0 -8
  109. package/dist/chunk-O73ROMWQ.mjs +0 -85
  110. package/dist/chunk-OSSGN43B.mjs +0 -8
  111. package/dist/chunk-Q44QKLN4.mjs +0 -43
  112. package/dist/chunk-Q4SZAMJT.js +0 -72
  113. package/dist/chunk-QT35SI3K.mjs +0 -641
  114. package/dist/chunk-QVLQPW3O.mjs +0 -10
  115. package/dist/chunk-QWKLQRBX.js +0 -35
  116. package/dist/chunk-R2DAEDRF.mjs +0 -74
  117. package/dist/chunk-R5LAJCBU.mjs +0 -67
  118. package/dist/chunk-SI34M4IC.js +0 -45
  119. package/dist/chunk-T5PM73EF.js +0 -1504
  120. package/dist/chunk-UANQJ2GH.mjs +0 -25
  121. package/dist/chunk-UXAHLSWC.mjs +0 -8
  122. package/dist/chunk-V2UA2D4E.js +0 -10
  123. package/dist/chunk-YIP5FJ5H.js +0 -27
  124. package/dist/chunk-YKWSHBT5.js +0 -32
  125. package/dist/chunk-YUFTHPOE.mjs +0 -20
  126. package/dist/chunk-ZDQ5AP26.mjs +0 -31
  127. package/dist/chunk-ZPFOKBIN.js +0 -89
@@ -1,74 +0,0 @@
1
- import { ValidationError } from './chunk-CLZORRMS.mjs';
2
-
3
- // src/utils/canonical-json.ts
4
- function canonicalStringify(value) {
5
- const seen = /* @__PURE__ */ new Set();
6
- function encode(v) {
7
- if (v === null) return "null";
8
- switch (typeof v) {
9
- case "string":
10
- case "number":
11
- case "boolean":
12
- return JSON.stringify(v);
13
- case "undefined":
14
- return void 0;
15
- case "object":
16
- break;
17
- default:
18
- throw new ValidationError(`Cannot canonicalize value of type ${typeof v}`, []);
19
- }
20
- const obj = v;
21
- if (seen.has(obj)) throw new ValidationError("Cannot canonicalize circular structure", []);
22
- seen.add(obj);
23
- try {
24
- if (Array.isArray(obj)) return `[${obj.map((e) => encode(e) ?? "null").join(",")}]`;
25
- const entries = Object.entries(obj).map(([k, val]) => [k, encode(val)]).filter((pair) => pair[1] !== void 0).sort(([a], [b]) => a < b ? -1 : 1);
26
- return `{${entries.map(([k, val]) => `${JSON.stringify(k)}:${val}`).join(",")}}`;
27
- } finally {
28
- seen.delete(obj);
29
- }
30
- }
31
- return encode(value) ?? "null";
32
- }
33
-
34
- // src/utils.ts
35
- function asTenantId(id) {
36
- return id;
37
- }
38
- function asUserId(id) {
39
- return id;
40
- }
41
- function generateId() {
42
- if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
43
- return crypto.randomUUID();
44
- }
45
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
46
- const r = Math.random() * 16 | 0;
47
- const v = c === "x" ? r : r & 3 | 8;
48
- return v.toString(16);
49
- });
50
- }
51
- function indexBy(items, keyFn) {
52
- return new Map(items.map((item) => [keyFn(item), item]));
53
- }
54
- function deepEqual(a, b) {
55
- if (a === b) return true;
56
- if (a == null || b == null) return false;
57
- if (typeof a !== typeof b) return false;
58
- if (Array.isArray(a)) {
59
- if (!Array.isArray(b)) return false;
60
- if (a.length !== b.length) return false;
61
- return a.every((item, index) => deepEqual(item, b[index]));
62
- }
63
- if (typeof a === "object" && typeof b === "object") {
64
- const aObj = a;
65
- const bObj = b;
66
- const aKeys = Object.keys(aObj);
67
- const bKeys = Object.keys(bObj);
68
- if (aKeys.length !== bKeys.length) return false;
69
- return aKeys.every((key) => key in bObj && deepEqual(aObj[key], bObj[key]));
70
- }
71
- return false;
72
- }
73
-
74
- export { asTenantId, asUserId, canonicalStringify, deepEqual, generateId, indexBy };
@@ -1,67 +0,0 @@
1
- import { DEFAULT_VALIDATION_MESSAGES } from './chunk-HRQEZUAA.mjs';
2
- import { getCountryByIso3, stripTrunkPrefix, isValidIso3 } from '@stndrds/constants';
3
- import { z } from 'zod';
4
- import { parsePhoneNumberFromString } from 'libphonenumber-js';
5
-
6
- function digitsOnly(input) {
7
- return input.replace(/\D/g, "");
8
- }
9
- function normalizeCountrylessPhoneNumber(phoneNumber) {
10
- return digitsOnly(phoneNumber);
11
- }
12
- function getIso2(iso3) {
13
- const country = getCountryByIso3(iso3);
14
- return country?.iso2;
15
- }
16
- function normalizePhoneNumber(phoneNumber, countryIso3) {
17
- if (!phoneNumber) return "";
18
- const iso2 = getIso2(countryIso3);
19
- if (!iso2) {
20
- return digitsOnly(phoneNumber);
21
- }
22
- const parsed = parsePhoneNumberFromString(phoneNumber, iso2);
23
- if (parsed) {
24
- return parsed.nationalNumber;
25
- }
26
- const country = getCountryByIso3(countryIso3);
27
- const digits = digitsOnly(phoneNumber);
28
- if (country) {
29
- const callingCode = country.phoneCode.replace("+", "");
30
- const withoutCC = digits.startsWith(callingCode) ? digits.slice(callingCode.length) : digits;
31
- return stripTrunkPrefix(withoutCC, country.phoneTrunkPrefix ?? "");
32
- }
33
- return digits;
34
- }
35
- function formatPhoneForDisplay(phone) {
36
- if (!phone.phoneNumber) return "";
37
- const iso2 = getIso2(phone.countryCode);
38
- const country = getCountryByIso3(phone.countryCode);
39
- const dial = country?.phoneCode ?? "";
40
- if (!iso2) {
41
- return `${dial} ${phone.phoneNumber}`.trim();
42
- }
43
- const e164 = `${dial}${digitsOnly(phone.phoneNumber)}`;
44
- const parsed = parsePhoneNumberFromString(e164);
45
- if (parsed) {
46
- return parsed.formatInternational();
47
- }
48
- return `${dial} ${phone.phoneNumber}`.trim();
49
- }
50
-
51
- // src/validation/complex/phone.ts
52
- function createPhoneValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
53
- return z.object(
54
- {
55
- countryCode: z.string().length(3),
56
- phoneNumber: z.string().min(1)
57
- },
58
- { message: messages.invalidPhone(attr) }
59
- ).refine((val) => isValidIso3(val.countryCode), {
60
- message: "Invalid country code"
61
- }).transform((val) => ({
62
- countryCode: val.countryCode,
63
- phoneNumber: normalizePhoneNumber(val.phoneNumber, val.countryCode)
64
- }));
65
- }
66
-
67
- export { createPhoneValidator, formatPhoneForDisplay, normalizeCountrylessPhoneNumber, normalizePhoneNumber };
@@ -1,45 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkYKWSHBT5_js = require('./chunk-YKWSHBT5.js');
4
- var zod = require('zod');
5
-
6
- function resolveBound(bound) {
7
- if (!bound) return null;
8
- const raw = bound === "today" ? (/* @__PURE__ */ new Date()).toISOString().slice(0, 10) : bound;
9
- const parsed = new Date(raw);
10
- return Number.isNaN(parsed.getTime()) ? null : parsed;
11
- }
12
- function createDateValidator(attr, messages = chunkYKWSHBT5_js.DEFAULT_VALIDATION_MESSAGES) {
13
- const message = messages.invalidDate(attr);
14
- const min = resolveBound(attr.minDate);
15
- const max = resolveBound(attr.maxDate);
16
- const bound = zod.z.any().superRefine((raw, ctx) => {
17
- const coerced = new Date(raw);
18
- if (Number.isNaN(coerced.getTime())) {
19
- ctx.addIssue({ code: "custom", message });
20
- return;
21
- }
22
- if (min && coerced < min) {
23
- ctx.addIssue({ code: "custom", message });
24
- }
25
- if (max && coerced > max) {
26
- ctx.addIssue({ code: "custom", message });
27
- }
28
- });
29
- if (!attr.endDate) return bound;
30
- const range = zod.z.object({ start: bound, end: bound.nullable() }).superRefine((value, ctx) => {
31
- if (value.end === null) return;
32
- const start = new Date(value.start);
33
- const end = new Date(value.end);
34
- const bothValid = !(Number.isNaN(start.getTime()) || Number.isNaN(end.getTime()));
35
- if (bothValid && end < start) {
36
- ctx.addIssue({ code: "custom", message, path: ["end"] });
37
- }
38
- });
39
- return zod.z.preprocess(
40
- (value) => typeof value === "string" ? { start: value, end: null } : value,
41
- range
42
- );
43
- }
44
-
45
- exports.createDateValidator = createDateValidator;