@stndrds/schema 1.0.0-alpha.293 → 1.0.0-alpha.68

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 (161) hide show
  1. package/dist/chunk-36UBIXJN.js +82 -0
  2. package/dist/chunk-3RG5ZIWI.js +10 -0
  3. package/dist/chunk-IXHWBBIY.mjs +721 -0
  4. package/dist/chunk-KG75T7MA.mjs +18664 -0
  5. package/dist/chunk-NEVERCM3.js +41 -0
  6. package/dist/chunk-V2RPPE2Y.mjs +41 -0
  7. package/dist/chunk-V32FQLWX.js +721 -0
  8. package/dist/chunk-V5QXU2OK.mjs +82 -0
  9. package/dist/chunk-XGFBT4K2.js +18664 -0
  10. package/dist/chunk-Y6FXYEAI.mjs +10 -0
  11. package/dist/default-roles-42X3TJI5.mjs +21 -0
  12. package/dist/default-roles-C3FYDYMN.js +21 -0
  13. package/dist/index.d.mts +3392 -10860
  14. package/dist/index.d.ts +3392 -10860
  15. package/dist/index.js +1705 -10255
  16. package/dist/index.mjs +1735 -9398
  17. package/dist/runtime-B0G6eBXO.d.ts +12810 -0
  18. package/dist/runtime-fj4EKCWH.d.mts +12810 -0
  19. package/dist/runtime.d.mts +6 -0
  20. package/dist/runtime.d.ts +6 -0
  21. package/dist/runtime.js +323 -0
  22. package/dist/runtime.mjs +323 -0
  23. package/dist/utils.d.mts +55 -35
  24. package/dist/utils.d.ts +55 -35
  25. package/dist/utils.js +19 -31
  26. package/dist/utils.mjs +19 -2
  27. package/dist/validation/validators.d.mts +4 -0
  28. package/dist/validation/validators.d.ts +4 -0
  29. package/dist/validation/validators.js +121 -0
  30. package/dist/validation/validators.mjs +121 -0
  31. package/dist/validators-B6L_hVBw.d.ts +1564 -0
  32. package/dist/validators-CgiGGhyH.d.mts +1564 -0
  33. package/package.json +16 -106
  34. package/dist/all-CDJSpI46.d.ts +0 -978
  35. package/dist/all-Cru_CaSY.d.mts +0 -978
  36. package/dist/attributes-CNYwg_Nr.d.ts +0 -584
  37. package/dist/attributes-CWPLbp7c.d.mts +0 -584
  38. package/dist/capabilities.d.mts +0 -146
  39. package/dist/capabilities.d.ts +0 -146
  40. package/dist/capabilities.js +0 -77
  41. package/dist/capabilities.mjs +0 -70
  42. package/dist/chunk-5N7OSHVX.js +0 -657
  43. package/dist/chunk-5WATIVCA.js +0 -10
  44. package/dist/chunk-ACKMC6FL.js +0 -17
  45. package/dist/chunk-APRL56F4.mjs +0 -226
  46. package/dist/chunk-AYVHMVKQ.mjs +0 -15
  47. package/dist/chunk-C32UUQ6D.js +0 -241
  48. package/dist/chunk-E6JUYGJX.js +0 -22
  49. package/dist/chunk-EEH4XQ7W.js +0 -61
  50. package/dist/chunk-EW5XR2X3.js +0 -12
  51. package/dist/chunk-GO6LQADH.mjs +0 -57
  52. package/dist/chunk-GRUSTQK3.mjs +0 -641
  53. package/dist/chunk-HRQEZUAA.mjs +0 -29
  54. package/dist/chunk-HTSTPTNZ.js +0 -10
  55. package/dist/chunk-KNGWHQLR.js +0 -16
  56. package/dist/chunk-LV3FEUKU.mjs +0 -14
  57. package/dist/chunk-NS63SPNN.mjs +0 -8
  58. package/dist/chunk-O73ROMWQ.mjs +0 -85
  59. package/dist/chunk-OASIPLEB.js +0 -1504
  60. package/dist/chunk-OSSGN43B.mjs +0 -8
  61. package/dist/chunk-P4VCAPJT.js +0 -81
  62. package/dist/chunk-Q44QKLN4.mjs +0 -43
  63. package/dist/chunk-Q4SZAMJT.js +0 -72
  64. package/dist/chunk-QVLQPW3O.mjs +0 -10
  65. package/dist/chunk-QWKLQRBX.js +0 -35
  66. package/dist/chunk-R5LAJCBU.mjs +0 -67
  67. package/dist/chunk-SI34M4IC.js +0 -45
  68. package/dist/chunk-UANQJ2GH.mjs +0 -25
  69. package/dist/chunk-ULM2BA5A.mjs +0 -1432
  70. package/dist/chunk-UXAHLSWC.mjs +0 -8
  71. package/dist/chunk-V2UA2D4E.js +0 -10
  72. package/dist/chunk-VGGGLTYJ.mjs +0 -74
  73. package/dist/chunk-Y3UPKP2B.js +0 -605
  74. package/dist/chunk-YIP5FJ5H.js +0 -27
  75. package/dist/chunk-YKWSHBT5.js +0 -32
  76. package/dist/chunk-YUFTHPOE.mjs +0 -20
  77. package/dist/chunk-Z5OPSBMQ.mjs +0 -566
  78. package/dist/chunk-ZDQ5AP26.mjs +0 -31
  79. package/dist/chunk-ZPFOKBIN.js +0 -89
  80. package/dist/exceptions.d.mts +0 -507
  81. package/dist/exceptions.d.ts +0 -507
  82. package/dist/exceptions.js +0 -158
  83. package/dist/exceptions.mjs +0 -1
  84. package/dist/helpers-CXkVwpsl.d.ts +0 -76
  85. package/dist/helpers-Dul_r9rJ.d.mts +0 -76
  86. package/dist/index-BdVnHL3F.d.mts +0 -853
  87. package/dist/index-CFhPHQaI.d.ts +0 -853
  88. package/dist/migrations-DaFneOfx.d.ts +0 -39
  89. package/dist/migrations-fRvadl6i.d.mts +0 -39
  90. package/dist/objects-CDwMSnqv.d.mts +0 -250
  91. package/dist/objects-DJv6WrDE.d.ts +0 -250
  92. package/dist/types-CVYiFc69.d.mts +0 -38
  93. package/dist/types-NGEww_ln.d.ts +0 -38
  94. package/dist/validation/all.d.mts +0 -11
  95. package/dist/validation/all.d.ts +0 -11
  96. package/dist/validation/all.js +0 -131
  97. package/dist/validation/all.mjs +0 -18
  98. package/dist/validation/complex/currency.d.mts +0 -15
  99. package/dist/validation/complex/currency.d.ts +0 -15
  100. package/dist/validation/complex/currency.js +0 -11
  101. package/dist/validation/complex/currency.mjs +0 -2
  102. package/dist/validation/complex/location.d.mts +0 -22
  103. package/dist/validation/complex/location.d.ts +0 -22
  104. package/dist/validation/complex/location.js +0 -11
  105. package/dist/validation/complex/location.mjs +0 -2
  106. package/dist/validation/complex/phone.d.mts +0 -22
  107. package/dist/validation/complex/phone.d.ts +0 -22
  108. package/dist/validation/complex/phone.js +0 -11
  109. package/dist/validation/complex/phone.mjs +0 -2
  110. package/dist/validation/complex/relation.d.mts +0 -25
  111. package/dist/validation/complex/relation.d.ts +0 -25
  112. package/dist/validation/complex/relation.js +0 -19
  113. package/dist/validation/complex/relation.mjs +0 -2
  114. package/dist/validation/complex/richtext.d.mts +0 -13
  115. package/dist/validation/complex/richtext.d.ts +0 -13
  116. package/dist/validation/complex/richtext.js +0 -11
  117. package/dist/validation/complex/richtext.mjs +0 -2
  118. package/dist/validation/complex/select.d.mts +0 -20
  119. package/dist/validation/complex/select.d.ts +0 -20
  120. package/dist/validation/complex/select.js +0 -19
  121. package/dist/validation/complex/select.mjs +0 -2
  122. package/dist/validation/complex/user.d.mts +0 -13
  123. package/dist/validation/complex/user.d.ts +0 -13
  124. package/dist/validation/complex/user.js +0 -11
  125. package/dist/validation/complex/user.mjs +0 -2
  126. package/dist/validation/computed/formula.d.mts +0 -14
  127. package/dist/validation/computed/formula.d.ts +0 -14
  128. package/dist/validation/computed/formula.js +0 -11
  129. package/dist/validation/computed/formula.mjs +0 -2
  130. package/dist/validation/computed/rollup.d.mts +0 -14
  131. package/dist/validation/computed/rollup.d.ts +0 -14
  132. package/dist/validation/computed/rollup.js +0 -11
  133. package/dist/validation/computed/rollup.mjs +0 -2
  134. package/dist/validation/config/index.d.mts +0 -7
  135. package/dist/validation/config/index.d.ts +0 -7
  136. package/dist/validation/config/index.js +0 -52
  137. package/dist/validation/config/index.mjs +0 -7
  138. package/dist/validation/core/index.d.mts +0 -19
  139. package/dist/validation/core/index.d.ts +0 -19
  140. package/dist/validation/core/index.js +0 -14
  141. package/dist/validation/core/index.mjs +0 -1
  142. package/dist/validation/object/index.d.mts +0 -32
  143. package/dist/validation/object/index.d.ts +0 -32
  144. package/dist/validation/object/index.js +0 -69
  145. package/dist/validation/object/index.mjs +0 -16
  146. package/dist/validation/primitives/checkbox.d.mts +0 -12
  147. package/dist/validation/primitives/checkbox.d.ts +0 -12
  148. package/dist/validation/primitives/checkbox.js +0 -11
  149. package/dist/validation/primitives/checkbox.mjs +0 -2
  150. package/dist/validation/primitives/date.d.mts +0 -25
  151. package/dist/validation/primitives/date.d.ts +0 -25
  152. package/dist/validation/primitives/date.js +0 -11
  153. package/dist/validation/primitives/date.mjs +0 -2
  154. package/dist/validation/primitives/number.d.mts +0 -12
  155. package/dist/validation/primitives/number.d.ts +0 -12
  156. package/dist/validation/primitives/number.js +0 -11
  157. package/dist/validation/primitives/number.mjs +0 -2
  158. package/dist/validation/primitives/text.d.mts +0 -12
  159. package/dist/validation/primitives/text.d.ts +0 -12
  160. package/dist/validation/primitives/text.js +0 -11
  161. package/dist/validation/primitives/text.mjs +0 -2
@@ -1,8 +0,0 @@
1
- import { DEFAULT_VALIDATION_MESSAGES } from './chunk-HRQEZUAA.mjs';
2
- import { z } from 'zod';
3
-
4
- function createCheckboxValidator(_attr, _messages = DEFAULT_VALIDATION_MESSAGES) {
5
- return z.boolean();
6
- }
7
-
8
- export { createCheckboxValidator };
@@ -1,81 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkY3UPKP2B_js = require('./chunk-Y3UPKP2B.js');
4
-
5
- // src/utils/canonical-json.ts
6
- function canonicalStringify(value) {
7
- const seen = /* @__PURE__ */ new Set();
8
- function encode(v) {
9
- if (v === null) return "null";
10
- switch (typeof v) {
11
- case "string":
12
- case "number":
13
- case "boolean":
14
- return JSON.stringify(v);
15
- case "undefined":
16
- return void 0;
17
- case "object":
18
- break;
19
- default:
20
- throw new chunkY3UPKP2B_js.ValidationError(`Cannot canonicalize value of type ${typeof v}`, []);
21
- }
22
- const obj = v;
23
- if (seen.has(obj)) throw new chunkY3UPKP2B_js.ValidationError("Cannot canonicalize circular structure", []);
24
- seen.add(obj);
25
- try {
26
- if (Array.isArray(obj)) return `[${obj.map((e) => encode(e) ?? "null").join(",")}]`;
27
- const entries = Object.entries(obj).map(([k, val]) => [k, encode(val)]).filter((pair) => pair[1] !== void 0).sort(([a], [b]) => a < b ? -1 : 1);
28
- return `{${entries.map(([k, val]) => `${JSON.stringify(k)}:${val}`).join(",")}}`;
29
- } finally {
30
- seen.delete(obj);
31
- }
32
- }
33
- return encode(value) ?? "null";
34
- }
35
-
36
- // src/utils.ts
37
- function asTenantId(id) {
38
- return id;
39
- }
40
- function asUserId(id) {
41
- return id;
42
- }
43
- function generateId() {
44
- if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
45
- return crypto.randomUUID();
46
- }
47
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
48
- const r = Math.random() * 16 | 0;
49
- const v = c === "x" ? r : r & 3 | 8;
50
- return v.toString(16);
51
- });
52
- }
53
- function indexBy(items, keyFn) {
54
- return new Map(items.map((item) => [keyFn(item), item]));
55
- }
56
- function deepEqual(a, b) {
57
- if (a === b) return true;
58
- if (a == null || b == null) return false;
59
- if (typeof a !== typeof b) return false;
60
- if (Array.isArray(a)) {
61
- if (!Array.isArray(b)) return false;
62
- if (a.length !== b.length) return false;
63
- return a.every((item, index) => deepEqual(item, b[index]));
64
- }
65
- if (typeof a === "object" && typeof b === "object") {
66
- const aObj = a;
67
- const bObj = b;
68
- const aKeys = Object.keys(aObj);
69
- const bKeys = Object.keys(bObj);
70
- if (aKeys.length !== bKeys.length) return false;
71
- return aKeys.every((key) => key in bObj && deepEqual(aObj[key], bObj[key]));
72
- }
73
- return false;
74
- }
75
-
76
- exports.asTenantId = asTenantId;
77
- exports.asUserId = asUserId;
78
- exports.canonicalStringify = canonicalStringify;
79
- exports.deepEqual = deepEqual;
80
- exports.generateId = generateId;
81
- exports.indexBy = indexBy;
@@ -1,43 +0,0 @@
1
- import { DEFAULT_VALIDATION_MESSAGES } from './chunk-HRQEZUAA.mjs';
2
- import { z } from 'zod';
3
-
4
- function resolveBound(bound) {
5
- if (!bound) return null;
6
- const raw = bound === "today" ? (/* @__PURE__ */ new Date()).toISOString().slice(0, 10) : bound;
7
- const parsed = new Date(raw);
8
- return Number.isNaN(parsed.getTime()) ? null : parsed;
9
- }
10
- function createDateValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
11
- const message = messages.invalidDate(attr);
12
- const min = resolveBound(attr.minDate);
13
- const max = resolveBound(attr.maxDate);
14
- const bound = z.any().superRefine((raw, ctx) => {
15
- const coerced = new Date(raw);
16
- if (Number.isNaN(coerced.getTime())) {
17
- ctx.addIssue({ code: "custom", message });
18
- return;
19
- }
20
- if (min && coerced < min) {
21
- ctx.addIssue({ code: "custom", message });
22
- }
23
- if (max && coerced > max) {
24
- ctx.addIssue({ code: "custom", message });
25
- }
26
- });
27
- if (!attr.endDate) return bound;
28
- const range = z.object({ start: bound, end: bound.nullable() }).superRefine((value, ctx) => {
29
- if (value.end === null) return;
30
- const start = new Date(value.start);
31
- const end = new Date(value.end);
32
- const bothValid = !(Number.isNaN(start.getTime()) || Number.isNaN(end.getTime()));
33
- if (bothValid && end < start) {
34
- ctx.addIssue({ code: "custom", message, path: ["end"] });
35
- }
36
- });
37
- return z.preprocess(
38
- (value) => typeof value === "string" ? { start: value, end: null } : value,
39
- range
40
- );
41
- }
42
-
43
- export { createDateValidator };
@@ -1,72 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkYKWSHBT5_js = require('./chunk-YKWSHBT5.js');
4
- var constants = require('@stndrds/constants');
5
- var zod = require('zod');
6
- var libphonenumberJs = require('libphonenumber-js');
7
-
8
- function digitsOnly(input) {
9
- return input.replace(/\D/g, "");
10
- }
11
- function normalizeCountrylessPhoneNumber(phoneNumber) {
12
- return digitsOnly(phoneNumber);
13
- }
14
- function getIso2(iso3) {
15
- const country = constants.getCountryByIso3(iso3);
16
- return country?.iso2;
17
- }
18
- function normalizePhoneNumber(phoneNumber, countryIso3) {
19
- if (!phoneNumber) return "";
20
- const iso2 = getIso2(countryIso3);
21
- if (!iso2) {
22
- return digitsOnly(phoneNumber);
23
- }
24
- const parsed = libphonenumberJs.parsePhoneNumberFromString(phoneNumber, iso2);
25
- if (parsed) {
26
- return parsed.nationalNumber;
27
- }
28
- const country = constants.getCountryByIso3(countryIso3);
29
- const digits = digitsOnly(phoneNumber);
30
- if (country) {
31
- const callingCode = country.phoneCode.replace("+", "");
32
- const withoutCC = digits.startsWith(callingCode) ? digits.slice(callingCode.length) : digits;
33
- return constants.stripTrunkPrefix(withoutCC, country.phoneTrunkPrefix ?? "");
34
- }
35
- return digits;
36
- }
37
- function formatPhoneForDisplay(phone) {
38
- if (!phone.phoneNumber) return "";
39
- const iso2 = getIso2(phone.countryCode);
40
- const country = constants.getCountryByIso3(phone.countryCode);
41
- const dial = country?.phoneCode ?? "";
42
- if (!iso2) {
43
- return `${dial} ${phone.phoneNumber}`.trim();
44
- }
45
- const e164 = `${dial}${digitsOnly(phone.phoneNumber)}`;
46
- const parsed = libphonenumberJs.parsePhoneNumberFromString(e164);
47
- if (parsed) {
48
- return parsed.formatInternational();
49
- }
50
- return `${dial} ${phone.phoneNumber}`.trim();
51
- }
52
-
53
- // src/validation/complex/phone.ts
54
- function createPhoneValidator(attr, messages = chunkYKWSHBT5_js.DEFAULT_VALIDATION_MESSAGES) {
55
- return zod.z.object(
56
- {
57
- countryCode: zod.z.string().length(3),
58
- phoneNumber: zod.z.string().min(1)
59
- },
60
- { message: messages.invalidPhone(attr) }
61
- ).refine((val) => constants.isValidIso3(val.countryCode), {
62
- message: "Invalid country code"
63
- }).transform((val) => ({
64
- countryCode: val.countryCode,
65
- phoneNumber: normalizePhoneNumber(val.phoneNumber, val.countryCode)
66
- }));
67
- }
68
-
69
- exports.createPhoneValidator = createPhoneValidator;
70
- exports.formatPhoneForDisplay = formatPhoneForDisplay;
71
- exports.normalizeCountrylessPhoneNumber = normalizeCountrylessPhoneNumber;
72
- exports.normalizePhoneNumber = normalizePhoneNumber;
@@ -1,10 +0,0 @@
1
- import { DEFAULT_VALIDATION_MESSAGES } from './chunk-HRQEZUAA.mjs';
2
- import { z } from 'zod';
3
-
4
- function createRichtextValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
5
- return z.string({
6
- message: messages.invalidRichtext(attr)
7
- });
8
- }
9
-
10
- export { createRichtextValidator };
@@ -1,35 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkYKWSHBT5_js = require('./chunk-YKWSHBT5.js');
4
- var zod = require('zod');
5
-
6
- function createSelectValidator(attr, messages = chunkYKWSHBT5_js.DEFAULT_VALIDATION_MESSAGES) {
7
- const validValues = attr.options.map((opt) => opt.value);
8
- if (validValues.length === 0) return zod.z.never();
9
- const validLabels = attr.options.map((opt) => opt.label);
10
- return zod.z.enum(validValues, {
11
- message: messages.invalidOption(attr, validLabels)
12
- });
13
- }
14
- function createMultiselectValidator(attr, messages = chunkYKWSHBT5_js.DEFAULT_VALIDATION_MESSAGES) {
15
- const validValues = attr.options.map((opt) => opt.value);
16
- if (validValues.length === 0) return zod.z.never();
17
- const validLabels = attr.options.map((opt) => opt.label);
18
- return zod.z.array(
19
- zod.z.enum(validValues, {
20
- message: messages.invalidOption(attr, validLabels)
21
- })
22
- );
23
- }
24
- function createStatusValidator(attr, messages = chunkYKWSHBT5_js.DEFAULT_VALIDATION_MESSAGES) {
25
- const validValues = attr.options.map((opt) => opt.value);
26
- if (validValues.length === 0) return zod.z.never();
27
- const validLabels = attr.options.map((opt) => opt.label);
28
- return zod.z.enum(validValues, {
29
- message: messages.invalidOption(attr, validLabels)
30
- });
31
- }
32
-
33
- exports.createMultiselectValidator = createMultiselectValidator;
34
- exports.createSelectValidator = createSelectValidator;
35
- exports.createStatusValidator = createStatusValidator;
@@ -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;
@@ -1,25 +0,0 @@
1
- import { DEFAULT_VALIDATION_MESSAGES } from './chunk-HRQEZUAA.mjs';
2
- import { z } from 'zod';
3
-
4
- function createNumberValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
5
- let schema = z.number();
6
- if (attr.min !== void 0) {
7
- schema = schema.min(attr.min, messages.minValue(attr, attr.min));
8
- }
9
- if (attr.max !== void 0) {
10
- schema = schema.max(attr.max, messages.maxValue(attr, attr.max));
11
- }
12
- if (attr.renderAs === "rating") {
13
- schema = schema.min(attr.min ?? 0);
14
- schema = schema.max(attr.max ?? 5);
15
- }
16
- if (attr.unit === "percentage") {
17
- schema = schema.min(attr.min ?? 0).max(attr.max ?? 100);
18
- }
19
- if (attr.unit === "integer") {
20
- schema = schema.int(messages.mustBeInteger(attr));
21
- }
22
- return schema;
23
- }
24
-
25
- export { createNumberValidator };