@stndrds/schema 1.0.0-alpha.94 → 1.0.0-alpha.96

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 (137) hide show
  1. package/dist/attributes-Btn-GLvC.d.ts +674 -0
  2. package/dist/attributes-CeDp1IMp.d.mts +674 -0
  3. package/dist/chunk-2TEWGEUI.js +212 -0
  4. package/dist/chunk-4RGFTMQR.mjs +8 -0
  5. package/dist/chunk-5TLM4QXO.mjs +8 -0
  6. package/dist/chunk-67PQMHQA.mjs +199 -0
  7. package/dist/chunk-6HHSX6LP.js +64 -0
  8. package/dist/chunk-AHPXNPJC.js +105 -0
  9. package/dist/chunk-BEN6TE7Y.js +11 -0
  10. package/dist/chunk-BH3RPSC5.js +22 -0
  11. package/dist/chunk-BIQ35DLC.mjs +78 -0
  12. package/dist/chunk-CKZHFJQT.js +16 -0
  13. package/dist/chunk-E6XO2STS.js +11 -11
  14. package/dist/chunk-EIWGW2ML.mjs +99 -0
  15. package/dist/chunk-EKG35CSO.mjs +1 -0
  16. package/dist/chunk-IMEPIVTR.js +217 -0
  17. package/dist/chunk-J4ORNCAH.js +10 -0
  18. package/dist/chunk-KC4F3HB7.js +32 -0
  19. package/dist/chunk-LHXE7LLD.js +28 -0
  20. package/dist/chunk-MD6XGXTU.mjs +18 -0
  21. package/dist/chunk-N47XKY4R.js +14 -0
  22. package/dist/chunk-NXXSNUDI.mjs +8 -0
  23. package/dist/chunk-PKG3E5MW.mjs +18 -0
  24. package/dist/chunk-PZT3CIHD.mjs +192 -0
  25. package/dist/chunk-QL3UGPUG.mjs +60 -0
  26. package/dist/chunk-QY65ZSBL.js +16 -0
  27. package/dist/chunk-R6JFUC32.js +2 -0
  28. package/dist/chunk-RDXQ4CYT.mjs +9 -0
  29. package/dist/chunk-S5VJ2FZE.js +12 -0
  30. package/dist/chunk-SVII65W7.mjs +14 -0
  31. package/dist/chunk-U7VN3RUE.mjs +25 -0
  32. package/dist/chunk-VCPYYLCS.js +83 -0
  33. package/dist/chunk-VD3P2A6Q.js +10 -0
  34. package/dist/chunk-VPEV3W34.mjs +10 -0
  35. package/dist/chunk-WGFQMQMV.mjs +14 -0
  36. package/dist/chunk-X6VDDXG7.mjs +12 -0
  37. package/dist/chunk-XAORXFAX.mjs +1 -10
  38. package/dist/chunk-XEOG24K6.mjs +8 -0
  39. package/dist/chunk-XK6XC3V4.js +10 -0
  40. package/dist/chunk-XZ5B5MTG.js +20 -0
  41. package/dist/chunk-YKHC2AW6.js +10 -0
  42. package/dist/chunk-Z2T7ONKU.js +20 -0
  43. package/dist/chunk-ZFL7DXAE.mjs +28 -0
  44. package/dist/chunk-ZM7W2ZCF.mjs +20 -0
  45. package/dist/{validators-BCw4Sn01.d.mts → index-CvXnHxD2.d.mts} +12 -1359
  46. package/dist/{validators-5XMwJOlV.d.ts → index-telccAkt.d.ts} +12 -1359
  47. package/dist/index.d.mts +1295 -474
  48. package/dist/index.d.ts +1295 -474
  49. package/dist/index.js +1400 -831
  50. package/dist/index.mjs +583 -571
  51. package/dist/types-B5Zhhoev.d.ts +39 -0
  52. package/dist/types-C6naks1H.d.mts +39 -0
  53. package/dist/utils.js +38 -20
  54. package/dist/utils.mjs +1 -20
  55. package/dist/validation/all.d.mts +23 -0
  56. package/dist/validation/all.d.ts +23 -0
  57. package/dist/validation/all.js +265 -0
  58. package/dist/validation/all.mjs +20 -0
  59. package/dist/validation/complex/currency.d.mts +15 -0
  60. package/dist/validation/complex/currency.d.ts +15 -0
  61. package/dist/validation/complex/currency.js +12 -0
  62. package/dist/validation/complex/currency.mjs +3 -0
  63. package/dist/validation/complex/file.d.mts +13 -0
  64. package/dist/validation/complex/file.d.ts +13 -0
  65. package/dist/validation/complex/file.js +12 -0
  66. package/dist/validation/complex/file.mjs +3 -0
  67. package/dist/validation/complex/location.d.mts +22 -0
  68. package/dist/validation/complex/location.d.ts +22 -0
  69. package/dist/validation/complex/location.js +12 -0
  70. package/dist/validation/complex/location.mjs +3 -0
  71. package/dist/validation/complex/phone.d.mts +22 -0
  72. package/dist/validation/complex/phone.d.ts +22 -0
  73. package/dist/validation/complex/phone.js +12 -0
  74. package/dist/validation/complex/phone.mjs +3 -0
  75. package/dist/validation/complex/relation.d.mts +25 -0
  76. package/dist/validation/complex/relation.d.ts +25 -0
  77. package/dist/validation/complex/relation.js +20 -0
  78. package/dist/validation/complex/relation.mjs +3 -0
  79. package/dist/validation/complex/richtext.d.mts +13 -0
  80. package/dist/validation/complex/richtext.d.ts +13 -0
  81. package/dist/validation/complex/richtext.js +12 -0
  82. package/dist/validation/complex/richtext.mjs +3 -0
  83. package/dist/validation/complex/select.d.mts +20 -0
  84. package/dist/validation/complex/select.d.ts +20 -0
  85. package/dist/validation/complex/select.js +20 -0
  86. package/dist/validation/complex/select.mjs +3 -0
  87. package/dist/validation/complex/user.d.mts +13 -0
  88. package/dist/validation/complex/user.d.ts +13 -0
  89. package/dist/validation/complex/user.js +12 -0
  90. package/dist/validation/complex/user.mjs +3 -0
  91. package/dist/validation/computed/formula.d.mts +14 -0
  92. package/dist/validation/computed/formula.d.ts +14 -0
  93. package/dist/validation/computed/formula.js +12 -0
  94. package/dist/validation/computed/formula.mjs +3 -0
  95. package/dist/validation/computed/rollup.d.mts +14 -0
  96. package/dist/validation/computed/rollup.d.ts +14 -0
  97. package/dist/validation/computed/rollup.js +12 -0
  98. package/dist/validation/computed/rollup.mjs +3 -0
  99. package/dist/validation/config/index.d.mts +421 -0
  100. package/dist/validation/config/index.d.ts +421 -0
  101. package/dist/validation/config/index.js +103 -0
  102. package/dist/validation/config/index.mjs +2 -0
  103. package/dist/validation/core/index.d.mts +85 -0
  104. package/dist/validation/core/index.d.ts +85 -0
  105. package/dist/validation/core/index.js +27 -0
  106. package/dist/validation/core/index.mjs +2 -0
  107. package/dist/validation/object/index.d.mts +6 -0
  108. package/dist/validation/object/index.d.ts +6 -0
  109. package/dist/validation/object/index.js +71 -0
  110. package/dist/validation/object/index.mjs +18 -0
  111. package/dist/validation/primitives/checkbox.d.mts +12 -0
  112. package/dist/validation/primitives/checkbox.d.ts +12 -0
  113. package/dist/validation/primitives/checkbox.js +12 -0
  114. package/dist/validation/primitives/checkbox.mjs +3 -0
  115. package/dist/validation/primitives/date.d.mts +12 -0
  116. package/dist/validation/primitives/date.d.ts +12 -0
  117. package/dist/validation/primitives/date.js +12 -0
  118. package/dist/validation/primitives/date.mjs +3 -0
  119. package/dist/validation/primitives/number.d.mts +12 -0
  120. package/dist/validation/primitives/number.d.ts +12 -0
  121. package/dist/validation/primitives/number.js +12 -0
  122. package/dist/validation/primitives/number.mjs +3 -0
  123. package/dist/validation/primitives/rating.d.mts +12 -0
  124. package/dist/validation/primitives/rating.d.ts +12 -0
  125. package/dist/validation/primitives/rating.js +12 -0
  126. package/dist/validation/primitives/rating.mjs +3 -0
  127. package/dist/validation/primitives/text.d.mts +17 -0
  128. package/dist/validation/primitives/text.d.ts +17 -0
  129. package/dist/validation/primitives/text.js +16 -0
  130. package/dist/validation/primitives/text.mjs +3 -0
  131. package/dist/validation/validators.d.mts +21 -2
  132. package/dist/validation/validators.d.ts +21 -2
  133. package/dist/validation/validators.js +265 -120
  134. package/dist/validation/validators.mjs +20 -120
  135. package/package.json +108 -5
  136. package/dist/chunk-4362R5F2.mjs +0 -780
  137. package/dist/chunk-7QUI6TSO.js +0 -780
@@ -1,780 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/validation/validators.ts
2
- var _constants = require('@stndrds/constants');
3
- var _zod = require('zod');
4
-
5
- // src/lib/lru-cache.ts
6
- var LRUCache = class {
7
- constructor(capacity) {
8
- if (capacity <= 0) {
9
- throw new Error("LRU cache capacity must be greater than 0");
10
- }
11
- this.capacity = capacity;
12
- this.cache = /* @__PURE__ */ new Map();
13
- }
14
- get(key) {
15
- const value = this.cache.get(key);
16
- if (value !== void 0) {
17
- this.cache.delete(key);
18
- this.cache.set(key, value);
19
- }
20
- return value;
21
- }
22
- set(key, value) {
23
- if (this.cache.has(key)) {
24
- this.cache.delete(key);
25
- } else if (this.cache.size >= this.capacity) {
26
- const firstKey = this.cache.keys().next().value;
27
- if (firstKey !== void 0) {
28
- this.cache.delete(firstKey);
29
- }
30
- }
31
- this.cache.set(key, value);
32
- }
33
- has(key) {
34
- return this.cache.has(key);
35
- }
36
- clear() {
37
- this.cache.clear();
38
- }
39
- get size() {
40
- return this.cache.size;
41
- }
42
- };
43
-
44
- // src/phone-utils.ts
45
-
46
- var _libphonenumberjs = require('libphonenumber-js');
47
- function digitsOnly(input) {
48
- return input.replace(/\D/g, "");
49
- }
50
- function getIso2(iso3) {
51
- const country = _constants.getCountryByIso3.call(void 0, iso3);
52
- return _optionalChain([country, 'optionalAccess', _ => _.iso2]);
53
- }
54
- function normalizePhoneNumber(phoneNumber, countryIso3) {
55
- if (!phoneNumber) return "";
56
- const iso2 = getIso2(countryIso3);
57
- if (!iso2) {
58
- return digitsOnly(phoneNumber);
59
- }
60
- const parsed = _libphonenumberjs.parsePhoneNumberFromString.call(void 0, phoneNumber, iso2);
61
- if (parsed) {
62
- return parsed.nationalNumber;
63
- }
64
- const country = _constants.getCountryByIso3.call(void 0, countryIso3);
65
- const digits = digitsOnly(phoneNumber);
66
- if (country) {
67
- const callingCode = country.phoneCode.replace("+", "");
68
- const withoutCC = digits.startsWith(callingCode) ? digits.slice(callingCode.length) : digits;
69
- return _constants.stripTrunkPrefix.call(void 0, withoutCC, _nullishCoalesce(country.phoneTrunkPrefix, () => ( "")));
70
- }
71
- return digits;
72
- }
73
- function validatePhoneNumber(phoneNumber, countryIso3) {
74
- if (!phoneNumber) return false;
75
- const iso2 = getIso2(countryIso3);
76
- if (!iso2) return false;
77
- const country = _constants.getCountryByIso3.call(void 0, countryIso3);
78
- if (!country) return false;
79
- const trunkPrefix = _nullishCoalesce(country.phoneTrunkPrefix, () => ( ""));
80
- const digits = digitsOnly(phoneNumber);
81
- const withTrunk = trunkPrefix + digits;
82
- const parsed = _libphonenumberjs.parsePhoneNumberFromString.call(void 0, withTrunk, iso2);
83
- if (_optionalChain([parsed, 'optionalAccess', _2 => _2.isValid, 'call', _3 => _3()])) return true;
84
- const parsedDirect = _libphonenumberjs.parsePhoneNumberFromString.call(void 0, phoneNumber, iso2);
85
- if (_optionalChain([parsedDirect, 'optionalAccess', _4 => _4.isValid, 'call', _5 => _5()])) return true;
86
- const maxDigits = _nullishCoalesce(country.phoneMaxDigits, () => ( 15));
87
- const expectedWithoutTrunk = maxDigits - trunkPrefix.length;
88
- return digits.length === expectedWithoutTrunk || digits.length === maxDigits;
89
- }
90
- function formatPhoneForDisplay(phone) {
91
- if (!phone.phoneNumber) return "";
92
- const iso2 = getIso2(phone.countryCode);
93
- const country = _constants.getCountryByIso3.call(void 0, phone.countryCode);
94
- const dial = _nullishCoalesce(_optionalChain([country, 'optionalAccess', _6 => _6.phoneCode]), () => ( ""));
95
- if (!iso2) {
96
- return `${dial} ${phone.phoneNumber}`.trim();
97
- }
98
- const e164 = `${dial}${digitsOnly(phone.phoneNumber)}`;
99
- const parsed = _libphonenumberjs.parsePhoneNumberFromString.call(void 0, e164);
100
- if (parsed) {
101
- return parsed.formatInternational();
102
- }
103
- return `${dial} ${phone.phoneNumber}`.trim();
104
- }
105
- function parseRawPhoneInput(rawInput, countryIso3) {
106
- if (!rawInput || rawInput.trim() === "") {
107
- return { success: false, error: "Phone number is empty" };
108
- }
109
- const normalized = normalizePhoneNumber(rawInput, countryIso3);
110
- if (!normalized) {
111
- return { success: false, error: "Could not extract digits from input" };
112
- }
113
- if (!validatePhoneNumber(normalized, countryIso3)) {
114
- return { success: false, error: "Invalid phone number for country" };
115
- }
116
- return {
117
- success: true,
118
- phone: { countryCode: countryIso3, phoneNumber: normalized }
119
- };
120
- }
121
-
122
- // src/validation/validators.ts
123
- var regexPatternCache = new LRUCache(100);
124
- function getCachedRegex(pattern) {
125
- let cached = regexPatternCache.get(pattern);
126
- if (!cached) {
127
- cached = new RegExp(pattern);
128
- regexPatternCache.set(pattern, cached);
129
- }
130
- return cached;
131
- }
132
- function formatZodErrors(error) {
133
- return error.issues.map((err) => ({
134
- path: err.path.map(String),
135
- message: err.message
136
- }));
137
- }
138
- var DEFAULT_VALIDATION_MESSAGES = {
139
- required: (attr) => `${attr.label} is required`,
140
- invalidType: (attr, expected) => `${attr.label} must be a ${expected}`,
141
- minLength: (attr, min) => `${attr.label} must be at least ${min} characters`,
142
- maxLength: (attr, max) => `${attr.label} must be at most ${max} characters`,
143
- invalidPattern: (attr) => `${attr.label} format is invalid`,
144
- minValue: (attr, min) => `${attr.label} must be at least ${min}`,
145
- maxValue: (attr, max) => `${attr.label} must be at most ${max}`,
146
- mustBeInteger: (attr) => `${attr.label} must be an integer`,
147
- invalidDate: (attr) => `${attr.label} must be a valid date`,
148
- invalidOption: (attr, options) => `${attr.label} must be one of: ${options.join(", ")}`,
149
- invalidId: (attr) => `${attr.label} must be a valid ID`,
150
- minItems: (attr, min) => `${attr.label} must have at least ${min} item${min > 1 ? "s" : ""}`,
151
- maxItems: (attr, max) => `${attr.label} must have at most ${max} item${max > 1 ? "s" : ""}`,
152
- invalidRichtext: (attr) => `${attr.label} must be valid rich text content`,
153
- invalidPhone: (attr) => `${attr.label} must be a valid phone number`,
154
- invalidCurrency: (attr) => `${attr.label} must be a valid currency value`,
155
- invalidLocation: (attr) => `${attr.label} must be a valid location`
156
- };
157
- var baseConfigSchema = _zod.z.object({
158
- disabled: _zod.z.boolean().optional(),
159
- placeholder: _zod.z.string().optional(),
160
- description: _zod.z.string().optional(),
161
- defaultValue: _zod.z.unknown().optional(),
162
- icon: _zod.z.string().optional(),
163
- order: _zod.z.number().int().optional(),
164
- hidden: _zod.z.boolean().optional(),
165
- archived: _zod.z.boolean().optional(),
166
- deprecated: _zod.z.boolean().optional(),
167
- metadata: _zod.z.record(_zod.z.string(), _zod.z.unknown()).optional()
168
- });
169
- var optionSchema = _zod.z.object({
170
- id: _zod.z.string().min(1),
171
- label: _zod.z.string().min(1),
172
- value: _zod.z.string().min(1),
173
- color: _zod.z.string().optional(),
174
- icon: _zod.z.string().optional(),
175
- description: _zod.z.string().optional(),
176
- group: _zod.z.enum(["idle", "in_progress", "finished"]).optional(),
177
- inverse: _zod.z.string().optional()
178
- });
179
- var optionsArraySchema = _zod.z.array(optionSchema).min(1).refine(
180
- (options) => {
181
- const values = options.map((o) => o.value);
182
- return new Set(values).size === values.length;
183
- },
184
- { message: "Duplicate option values are not allowed" }
185
- );
186
- var relationTargetSchema = _zod.z.object({
187
- object: _zod.z.string().min(1),
188
- displayTemplate: _zod.z.string().optional(),
189
- filter: _zod.z.record(_zod.z.string(), _zod.z.unknown()).optional()
190
- });
191
- var textConfigSchema = baseConfigSchema.extend({
192
- minLength: _zod.z.number().int().min(0).optional(),
193
- maxLength: _zod.z.number().int().min(1).optional(),
194
- pattern: _zod.z.string().optional()
195
- });
196
- var textareaConfigSchema = baseConfigSchema;
197
- var richtextConfigSchema = baseConfigSchema.extend({
198
- features: _zod.z.array(
199
- _zod.z.enum(["headings", "bold", "italic", "lists", "links", "images", "codeBlocks", "tables"])
200
- ).optional()
201
- });
202
- var numberConfigSchema = baseConfigSchema.extend({
203
- min: _zod.z.number().optional(),
204
- max: _zod.z.number().optional(),
205
- unit: _zod.z.enum(["integer", "decimal", "percentage"]).optional(),
206
- decimals: _zod.z.number().int().min(0).optional()
207
- });
208
- var checkboxConfigSchema = baseConfigSchema;
209
- var dateConfigSchema = baseConfigSchema.extend({
210
- dateFormat: _zod.z.enum(["short", "long", "full", "relative"]).optional(),
211
- minDate: _zod.z.string().optional(),
212
- maxDate: _zod.z.string().optional()
213
- });
214
- var phoneConfigSchema = baseConfigSchema.extend({
215
- defaultCountryCode: _zod.z.string().length(3).optional()
216
- });
217
- var currencyConfigSchema = baseConfigSchema.extend({
218
- defaultCurrency: _zod.z.string().length(3).optional(),
219
- allowedCurrencies: _zod.z.array(_zod.z.string().length(3)).optional()
220
- });
221
- var statusConfigSchema = baseConfigSchema.extend({
222
- options: optionsArraySchema
223
- });
224
- var locationConfigSchema = baseConfigSchema.extend({
225
- granularity: _zod.z.enum(["full", "address", "city", "state", "country", "coordinates"]),
226
- enableAutocomplete: _zod.z.boolean().optional(),
227
- enableMap: _zod.z.boolean().optional(),
228
- defaultCountry: _zod.z.string().length(3).optional(),
229
- allowedCountries: _zod.z.array(_zod.z.string().length(3)).optional(),
230
- displayFormat: _zod.z.enum(["single_line", "multi_line", "compact"]).optional()
231
- });
232
- var selectConfigSchema = baseConfigSchema.extend({
233
- options: optionsArraySchema
234
- });
235
- var multiselectConfigSchema = baseConfigSchema.extend({
236
- options: optionsArraySchema
237
- });
238
- var fileConfigSchema = baseConfigSchema.extend({
239
- maxFiles: _zod.z.number().int().min(1).optional(),
240
- maxSize: _zod.z.number().int().min(1).optional(),
241
- allowedTypes: _zod.z.array(_zod.z.string()).optional(),
242
- multiple: _zod.z.boolean().optional()
243
- });
244
- var userConfigSchema = baseConfigSchema.extend({
245
- allowedRoles: _zod.z.array(_zod.z.string()).optional(),
246
- multiple: _zod.z.boolean().optional()
247
- });
248
- var relationConfigSchema = baseConfigSchema.extend({
249
- targets: _zod.z.array(relationTargetSchema).min(1),
250
- cardinality: _zod.z.enum(["one", "many"]),
251
- minItems: _zod.z.number().int().min(0).optional(),
252
- maxItems: _zod.z.number().int().min(1).optional()
253
- });
254
- var ratingConfigSchema = baseConfigSchema.extend({
255
- max: _zod.z.number().int().min(1).optional(),
256
- iconType: _zod.z.enum(["star", "heart", "thumbs", "number"]).optional()
257
- });
258
- var formulaConfigSchema = baseConfigSchema.extend({
259
- expression: _zod.z.string().min(1),
260
- returnType: _zod.z.enum(["text", "number", "boolean", "date"]),
261
- decimals: _zod.z.number().int().min(0).max(10).optional(),
262
- allowRelations: _zod.z.boolean().optional()
263
- });
264
- var rollupConfigSchema = baseConfigSchema.extend({
265
- relationAttribute: _zod.z.string().min(1).optional(),
266
- relationPath: _zod.z.string().optional(),
267
- targetAttribute: _zod.z.string().min(1),
268
- function: _zod.z.enum([
269
- // Numeric aggregates
270
- "sum",
271
- "avg",
272
- // Date aggregates
273
- "earliest",
274
- "latest",
275
- // Count (universal)
276
- "count",
277
- "countValues",
278
- "countUniqueValues",
279
- "countEmpty",
280
- // Percent (universal)
281
- "percentEmpty",
282
- "percentNotEmpty",
283
- // Lookup (universal)
284
- "original"
285
- ]),
286
- decimals: _zod.z.number().int().min(0).max(10).optional(),
287
- targetAttributeType: _zod.z.string().optional(),
288
- targetAttributeOptions: _zod.z.array(
289
- _zod.z.object({
290
- id: _zod.z.string(),
291
- label: _zod.z.string(),
292
- value: _zod.z.string(),
293
- color: _zod.z.string().optional(),
294
- icon: _zod.z.string().optional(),
295
- description: _zod.z.string().optional(),
296
- group: _zod.z.enum(["idle", "in_progress", "finished"]).optional()
297
- })
298
- ).optional()
299
- });
300
- var documentConfigSchema = baseConfigSchema.extend({
301
- multiple: _zod.z.boolean().optional(),
302
- maxDocuments: _zod.z.number().int().min(1).optional(),
303
- autoProcess: _zod.z.boolean().optional()
304
- });
305
- var attributeConfigSchemas = {
306
- text: textConfigSchema,
307
- textarea: textareaConfigSchema,
308
- richtext: richtextConfigSchema,
309
- number: numberConfigSchema,
310
- checkbox: checkboxConfigSchema,
311
- date: dateConfigSchema,
312
- phone: phoneConfigSchema,
313
- currency: currencyConfigSchema,
314
- status: statusConfigSchema,
315
- location: locationConfigSchema,
316
- select: selectConfigSchema,
317
- multiselect: multiselectConfigSchema,
318
- file: fileConfigSchema,
319
- user: userConfigSchema,
320
- relation: relationConfigSchema,
321
- rating: ratingConfigSchema,
322
- formula: formulaConfigSchema,
323
- rollup: rollupConfigSchema,
324
- document: documentConfigSchema
325
- };
326
- function getAttributeConfigSchema(type) {
327
- return attributeConfigSchemas[type];
328
- }
329
- function validateAttributeConfig(type, config) {
330
- const schema = getAttributeConfigSchema(type);
331
- const result = schema.safeParse(config);
332
- if (result.success) {
333
- return { success: true, data: result.data };
334
- }
335
- return {
336
- success: false,
337
- errors: formatZodErrors(result.error).map((err) => `${err.path.join(".")}: ${err.message}`)
338
- };
339
- }
340
- function parseAttributeConfig(type, config) {
341
- const schema = getAttributeConfigSchema(type);
342
- return schema.strip().parse(config);
343
- }
344
- function safeParseAttributeConfig(type, config) {
345
- const schema = getAttributeConfigSchema(type);
346
- const result = schema.strip().safeParse(config);
347
- return result.success ? result.data : void 0;
348
- }
349
- function createTextValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
350
- let schema = _zod.z.string();
351
- if (attr.minLength !== void 0) {
352
- schema = schema.min(attr.minLength, messages.minLength(attr, attr.minLength));
353
- }
354
- if (attr.maxLength !== void 0) {
355
- schema = schema.max(attr.maxLength, messages.maxLength(attr, attr.maxLength));
356
- }
357
- if (attr.pattern) {
358
- schema = schema.regex(getCachedRegex(attr.pattern), messages.invalidPattern(attr));
359
- }
360
- return schema;
361
- }
362
- function createNumberValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
363
- let schema = _zod.z.number();
364
- if (attr.min !== void 0) {
365
- schema = schema.min(attr.min, messages.minValue(attr, attr.min));
366
- }
367
- if (attr.max !== void 0) {
368
- schema = schema.max(attr.max, messages.maxValue(attr, attr.max));
369
- }
370
- if (attr.unit === "integer") {
371
- schema = schema.int(messages.mustBeInteger(attr));
372
- }
373
- return schema;
374
- }
375
- function createCheckboxValidator(_attr, _messages = DEFAULT_VALIDATION_MESSAGES) {
376
- return _zod.z.boolean();
377
- }
378
- function createDateValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
379
- return _zod.z.coerce.date({ message: messages.invalidDate(attr) });
380
- }
381
- function createPhoneValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
382
- return _zod.z.object(
383
- {
384
- countryCode: _zod.z.string().length(3),
385
- phoneNumber: _zod.z.string().min(1)
386
- },
387
- { message: messages.invalidPhone(attr) }
388
- ).refine((val) => _constants.isValidIso3.call(void 0, val.countryCode), {
389
- message: "Invalid country code"
390
- }).transform((val) => ({
391
- countryCode: val.countryCode,
392
- phoneNumber: normalizePhoneNumber(val.phoneNumber, val.countryCode)
393
- })).refine((val) => validatePhoneNumber(val.phoneNumber, val.countryCode), {
394
- message: messages.invalidPhone(attr)
395
- });
396
- }
397
- function createCurrencyValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
398
- return _zod.z.object(
399
- {
400
- code: _zod.z.string().length(3),
401
- value: _zod.z.number().min(0)
402
- },
403
- { message: messages.invalidCurrency(attr) }
404
- );
405
- }
406
- function createStatusValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
407
- const validValues = attr.options.map((opt) => opt.value);
408
- const validLabels = attr.options.map((opt) => opt.label);
409
- return _zod.z.enum(validValues, {
410
- message: messages.invalidOption(attr, validLabels)
411
- });
412
- }
413
- function createSelectValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
414
- const validValues = attr.options.map((opt) => opt.value);
415
- const validLabels = attr.options.map((opt) => opt.label);
416
- return _zod.z.enum(validValues, {
417
- message: messages.invalidOption(attr, validLabels)
418
- });
419
- }
420
- function createMultiselectValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
421
- const validValues = attr.options.map((opt) => opt.value);
422
- const validLabels = attr.options.map((opt) => opt.label);
423
- return _zod.z.array(
424
- _zod.z.enum(validValues, {
425
- message: messages.invalidOption(attr, validLabels)
426
- })
427
- );
428
- }
429
- function createLocationValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
430
- return _zod.z.object(
431
- {
432
- address: _zod.z.string().optional(),
433
- address2: _zod.z.string().optional(),
434
- city: _zod.z.string().optional(),
435
- state: _zod.z.string().optional(),
436
- postalCode: _zod.z.string().optional(),
437
- country: _zod.z.string().length(3).optional(),
438
- latitude: _zod.z.number().optional(),
439
- longitude: _zod.z.number().optional()
440
- },
441
- { message: messages.invalidLocation(attr) }
442
- );
443
- }
444
- function createFileValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
445
- const uuidSchema = _zod.z.uuid({
446
- message: messages.invalidId(attr)
447
- });
448
- if (attr.multiple) {
449
- let arraySchema = _zod.z.array(uuidSchema);
450
- if (attr.maxFiles) {
451
- arraySchema = arraySchema.max(attr.maxFiles, messages.maxItems(attr, attr.maxFiles));
452
- }
453
- return arraySchema;
454
- }
455
- return uuidSchema;
456
- }
457
- function createUserValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
458
- const uuidSchema = _zod.z.uuid({
459
- message: messages.invalidId(attr)
460
- });
461
- if (attr.multiple) {
462
- return _zod.z.array(uuidSchema);
463
- }
464
- return uuidSchema;
465
- }
466
- function extractRelationId(item) {
467
- if (typeof item === "object" && item !== null && "id" in item) {
468
- return item.id;
469
- }
470
- return item;
471
- }
472
- function createSingleRelationValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
473
- const uuidSchema = _zod.z.uuid({
474
- message: messages.invalidId(attr)
475
- });
476
- const nullableUuidSchema = _zod.z.union([uuidSchema, _zod.z.null()]);
477
- return _zod.z.union([
478
- nullableUuidSchema,
479
- _zod.z.object({
480
- id: uuidSchema,
481
- props: _zod.z.record(_zod.z.string(), _zod.z.unknown()).optional()
482
- }).passthrough()
483
- // Allow additional properties (bilateral relations may have extra metadata)
484
- ]);
485
- }
486
- function createMultiRelationValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
487
- const uuidSchema = _zod.z.uuid({
488
- message: messages.invalidId(attr)
489
- });
490
- const itemSchema = _zod.z.union([
491
- uuidSchema,
492
- _zod.z.object({
493
- id: uuidSchema,
494
- props: _zod.z.record(_zod.z.string(), _zod.z.unknown()).optional()
495
- }).passthrough()
496
- // Allow additional properties
497
- ]);
498
- let arraySchema = _zod.z.array(itemSchema);
499
- if (attr.minItems !== void 0) {
500
- arraySchema = arraySchema.min(attr.minItems, messages.minItems(attr, attr.minItems));
501
- }
502
- if (attr.maxItems !== void 0) {
503
- arraySchema = arraySchema.max(attr.maxItems, messages.maxItems(attr, attr.maxItems));
504
- }
505
- return arraySchema.refine(
506
- (items) => {
507
- return items.every((item) => {
508
- const id = extractRelationId(item);
509
- return typeof id === "string" && uuidSchema.safeParse(id).success;
510
- });
511
- },
512
- { message: messages.invalidId(attr) }
513
- );
514
- }
515
- function createRelationValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
516
- if (attr.cardinality === "many") {
517
- return createMultiRelationValidator(attr, messages);
518
- }
519
- return createSingleRelationValidator(attr, messages);
520
- }
521
- function createRatingValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
522
- let schema = _zod.z.number().min(0);
523
- if (attr.max !== void 0) {
524
- schema = schema.max(attr.max, messages.maxValue(attr, attr.max));
525
- }
526
- return schema;
527
- }
528
- function createFormulaValidator(_attr, _messages = DEFAULT_VALIDATION_MESSAGES) {
529
- return _zod.z.unknown();
530
- }
531
- function createRollupValidator(_attr, _messages = DEFAULT_VALIDATION_MESSAGES) {
532
- return _zod.z.unknown();
533
- }
534
- function createTextAreaValidator(_attr, _messages = DEFAULT_VALIDATION_MESSAGES) {
535
- return _zod.z.string();
536
- }
537
- function createRichtextValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
538
- return _zod.z.string({
539
- message: messages.invalidRichtext(attr)
540
- });
541
- }
542
- function createAttributeValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
543
- switch (attr.type) {
544
- case "text":
545
- return createTextValidator(attr, messages);
546
- case "textarea":
547
- return createTextAreaValidator(attr, messages);
548
- case "richtext":
549
- return createRichtextValidator(attr, messages);
550
- case "number":
551
- return createNumberValidator(attr, messages);
552
- case "checkbox":
553
- return createCheckboxValidator(attr, messages);
554
- case "date":
555
- return createDateValidator(attr, messages);
556
- case "phone":
557
- return createPhoneValidator(attr, messages);
558
- case "currency":
559
- return createCurrencyValidator(attr, messages);
560
- case "status":
561
- return createStatusValidator(attr, messages);
562
- case "location":
563
- return createLocationValidator(attr, messages);
564
- case "select":
565
- return createSelectValidator(attr, messages);
566
- case "multiselect":
567
- return createMultiselectValidator(attr, messages);
568
- case "file":
569
- return createFileValidator(attr, messages);
570
- case "user":
571
- return createUserValidator(attr, messages);
572
- case "relation":
573
- return createRelationValidator(attr, messages);
574
- case "rating":
575
- return createRatingValidator(attr, messages);
576
- case "formula":
577
- return createFormulaValidator(attr, messages);
578
- case "rollup":
579
- return createRollupValidator(attr, messages);
580
- default:
581
- return _zod.z.unknown();
582
- }
583
- }
584
- function isEmptyValue(value) {
585
- if (value === null || value === void 0) return true;
586
- if (typeof value === "string" && value.trim() === "") return true;
587
- if (value instanceof Date) return false;
588
- if (typeof value === "object" && !Array.isArray(value)) {
589
- return Object.values(value).every(
590
- (v) => v === null || v === void 0 || typeof v === "string" && v.trim() === ""
591
- );
592
- }
593
- return false;
594
- }
595
- function withEmptyToNull(validator) {
596
- return _zod.z.preprocess((val) => isEmptyValue(val) ? null : val, validator.nullish());
597
- }
598
- function createFormAttributeValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
599
- const validator = createAttributeValidator(attr, messages);
600
- if (!attr.required) {
601
- return withEmptyToNull(validator);
602
- }
603
- return validator;
604
- }
605
- function createObjectValidator(objectDef) {
606
- const shape = {};
607
- for (const attr of objectDef.attributes) {
608
- const validator = createAttributeValidator(attr);
609
- shape[attr.name] = attr.required ? validator : withEmptyToNull(validator);
610
- }
611
- return _zod.z.object(shape).passthrough();
612
- }
613
- function validateAttribute(attr, value) {
614
- const validator = createAttributeValidator(attr);
615
- if (!attr.required && (value === void 0 || value === null)) {
616
- return { success: true, data: { [attr.name]: value } };
617
- }
618
- const result = validator.safeParse(value);
619
- if (result.success) {
620
- return {
621
- success: true,
622
- data: { [attr.name]: result.data }
623
- };
624
- }
625
- return {
626
- success: false,
627
- errors: formatZodErrors(result.error).map((err) => ({
628
- path: [attr.name, ...err.path],
629
- message: err.message
630
- }))
631
- };
632
- }
633
- function validateObject(objectDef, data) {
634
- const validator = createObjectValidator(objectDef);
635
- const result = validator.safeParse(data);
636
- if (result.success) {
637
- return {
638
- success: true,
639
- data: result.data
640
- };
641
- }
642
- return {
643
- success: false,
644
- errors: formatZodErrors(result.error)
645
- };
646
- }
647
- function validateObjectOrThrow(objectDef, data) {
648
- const result = validateObject(objectDef, data);
649
- if (!result.success) {
650
- const errorMessages = _optionalChain([result, 'access', _7 => _7.errors, 'optionalAccess', _8 => _8.map, 'call', _9 => _9((err) => `${err.path.join(".")}: ${err.message}`), 'access', _10 => _10.join, 'call', _11 => _11("\n")]) || "Unknown validation error";
651
- throw new Error(`Validation failed for ${objectDef.label}:
652
- ${errorMessages}`);
653
- }
654
- return result.data;
655
- }
656
- function createDraftValidator(objectDef) {
657
- const shape = {};
658
- for (const attr of objectDef.attributes) {
659
- const validator = createAttributeValidator(attr);
660
- shape[attr.name] = withEmptyToNull(validator);
661
- }
662
- return _zod.z.object(shape).passthrough();
663
- }
664
- function validateDraft(objectDef, data) {
665
- const validator = createDraftValidator(objectDef);
666
- const result = validator.safeParse(data);
667
- if (result.success) {
668
- return {
669
- success: true,
670
- data: result.data
671
- };
672
- }
673
- return {
674
- success: false,
675
- errors: formatZodErrors(result.error)
676
- };
677
- }
678
- function validateDraftOrThrow(objectDef, data) {
679
- const result = validateDraft(objectDef, data);
680
- if (!result.success) {
681
- const errorMessages = _optionalChain([result, 'access', _12 => _12.errors, 'optionalAccess', _13 => _13.map, 'call', _14 => _14((err) => `${err.path.join(".")}: ${err.message}`), 'access', _15 => _15.join, 'call', _16 => _16("\n")]) || "Unknown validation error";
682
- throw new Error(`Draft validation failed for ${objectDef.label}:
683
- ${errorMessages}`);
684
- }
685
- return result.data;
686
- }
687
- function isValuePresent(value) {
688
- if (value === void 0 || value === null) {
689
- return false;
690
- }
691
- if (typeof value === "string" && value.trim() === "") {
692
- return false;
693
- }
694
- return true;
695
- }
696
- function getMissingRequiredAttributes(objectDef, data) {
697
- const missing = [];
698
- for (const attr of objectDef.attributes) {
699
- if (attr.required && !isValuePresent(data[attr.name])) {
700
- missing.push(attr);
701
- }
702
- }
703
- return missing;
704
- }
705
- function isRecordComplete(objectDef, data) {
706
- const missing = getMissingRequiredAttributes(objectDef, data);
707
- if (missing.length > 0) {
708
- return false;
709
- }
710
- const validation = validateObject(objectDef, data);
711
- return validation.success;
712
- }
713
- function computeRecordStatus(objectDef, data) {
714
- return isRecordComplete(objectDef, data) ? "complete" : "draft";
715
- }
716
-
717
-
718
-
719
-
720
-
721
-
722
-
723
-
724
-
725
-
726
-
727
-
728
-
729
-
730
-
731
-
732
-
733
-
734
-
735
-
736
-
737
-
738
-
739
-
740
-
741
-
742
-
743
-
744
-
745
-
746
-
747
-
748
-
749
-
750
-
751
-
752
-
753
-
754
-
755
-
756
-
757
-
758
-
759
-
760
-
761
-
762
-
763
-
764
-
765
-
766
-
767
-
768
-
769
-
770
-
771
-
772
-
773
-
774
-
775
-
776
-
777
-
778
-
779
-
780
- exports.normalizePhoneNumber = normalizePhoneNumber; exports.validatePhoneNumber = validatePhoneNumber; exports.formatPhoneForDisplay = formatPhoneForDisplay; exports.parseRawPhoneInput = parseRawPhoneInput; exports.formatZodErrors = formatZodErrors; exports.DEFAULT_VALIDATION_MESSAGES = DEFAULT_VALIDATION_MESSAGES; exports.textConfigSchema = textConfigSchema; exports.textareaConfigSchema = textareaConfigSchema; exports.richtextConfigSchema = richtextConfigSchema; exports.numberConfigSchema = numberConfigSchema; exports.checkboxConfigSchema = checkboxConfigSchema; exports.dateConfigSchema = dateConfigSchema; exports.phoneConfigSchema = phoneConfigSchema; exports.currencyConfigSchema = currencyConfigSchema; exports.statusConfigSchema = statusConfigSchema; exports.locationConfigSchema = locationConfigSchema; exports.selectConfigSchema = selectConfigSchema; exports.multiselectConfigSchema = multiselectConfigSchema; exports.fileConfigSchema = fileConfigSchema; exports.userConfigSchema = userConfigSchema; exports.relationConfigSchema = relationConfigSchema; exports.ratingConfigSchema = ratingConfigSchema; exports.formulaConfigSchema = formulaConfigSchema; exports.rollupConfigSchema = rollupConfigSchema; exports.documentConfigSchema = documentConfigSchema; exports.attributeConfigSchemas = attributeConfigSchemas; exports.getAttributeConfigSchema = getAttributeConfigSchema; exports.validateAttributeConfig = validateAttributeConfig; exports.parseAttributeConfig = parseAttributeConfig; exports.safeParseAttributeConfig = safeParseAttributeConfig; exports.createTextValidator = createTextValidator; exports.createNumberValidator = createNumberValidator; exports.createCheckboxValidator = createCheckboxValidator; exports.createDateValidator = createDateValidator; exports.createPhoneValidator = createPhoneValidator; exports.createCurrencyValidator = createCurrencyValidator; exports.createStatusValidator = createStatusValidator; exports.createSelectValidator = createSelectValidator; exports.createMultiselectValidator = createMultiselectValidator; exports.createLocationValidator = createLocationValidator; exports.createFileValidator = createFileValidator; exports.createUserValidator = createUserValidator; exports.createSingleRelationValidator = createSingleRelationValidator; exports.createMultiRelationValidator = createMultiRelationValidator; exports.createRelationValidator = createRelationValidator; exports.createRatingValidator = createRatingValidator; exports.createFormulaValidator = createFormulaValidator; exports.createRollupValidator = createRollupValidator; exports.createTextAreaValidator = createTextAreaValidator; exports.createRichtextValidator = createRichtextValidator; exports.createAttributeValidator = createAttributeValidator; exports.createFormAttributeValidator = createFormAttributeValidator; exports.createObjectValidator = createObjectValidator; exports.validateAttribute = validateAttribute; exports.validateObject = validateObject; exports.validateObjectOrThrow = validateObjectOrThrow; exports.createDraftValidator = createDraftValidator; exports.validateDraft = validateDraft; exports.validateDraftOrThrow = validateDraftOrThrow; exports.getMissingRequiredAttributes = getMissingRequiredAttributes; exports.isRecordComplete = isRecordComplete; exports.computeRecordStatus = computeRecordStatus;