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

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 (175) hide show
  1. package/LICENSE +111 -0
  2. package/README.md +7 -0
  3. package/dist/{all-Cru_CaSY.d.mts → all-BekDmUP1.d.mts} +32 -32
  4. package/dist/{all-CDJSpI46.d.ts → all-Bl3DlCEn.d.ts} +32 -32
  5. package/dist/{attributes-CWPLbp7c.d.mts → attributes-CtS5Gf_i.d.mts} +1 -1
  6. package/dist/{attributes-CNYwg_Nr.d.ts → attributes-SIbTof03.d.ts} +1 -1
  7. package/dist/capabilities.js +2 -77
  8. package/dist/capabilities.mjs +2 -70
  9. package/dist/chunk-23KPS33D.js +2 -0
  10. package/dist/chunk-47EGJRW7.js +4 -0
  11. package/dist/chunk-47KVYDKG.js +2 -0
  12. package/dist/chunk-4OTKOCGB.mjs +2 -0
  13. package/dist/chunk-4VCADZK4.mjs +2 -0
  14. package/dist/chunk-5QAE5NPN.js +6 -0
  15. package/dist/chunk-72TQRSNX.js +12 -0
  16. package/dist/chunk-DPD6ZWL2.js +2 -0
  17. package/dist/chunk-GKXTXH4Y.mjs +2 -0
  18. package/dist/chunk-GWAHL4A2.mjs +2 -0
  19. package/dist/chunk-GXSNLYRR.js +2 -0
  20. package/dist/chunk-JCPAOH76.mjs +2 -0
  21. package/dist/chunk-JFSQ24XR.js +2 -0
  22. package/dist/chunk-JOS2XMXY.js +2 -0
  23. package/dist/chunk-JVLH3DVZ.js +2 -0
  24. package/dist/chunk-KG2ADZG6.mjs +2 -0
  25. package/dist/chunk-KLR22JMC.js +2 -0
  26. package/dist/chunk-KSPJP74K.mjs +2 -0
  27. package/dist/chunk-KYPEBOPW.mjs +2 -0
  28. package/dist/chunk-LB4TNMZU.mjs +2 -0
  29. package/dist/chunk-LQYUPOWB.js +2 -0
  30. package/dist/chunk-LSCBR4VS.js +2 -0
  31. package/dist/chunk-LWSOKXPF.js +2 -0
  32. package/dist/chunk-O34B5KOW.mjs +2 -0
  33. package/dist/chunk-PFO7NWQW.mjs +2 -0
  34. package/dist/chunk-PT25FZ62.mjs +12 -0
  35. package/dist/chunk-Q7TQCRSD.mjs +2 -0
  36. package/dist/chunk-RFKNNT2Q.mjs +4 -0
  37. package/dist/chunk-SDOYGWU4.js +2 -0
  38. package/dist/chunk-SLYRQ72J.js +2 -0
  39. package/dist/chunk-UXISKZ5Y.js +2 -0
  40. package/dist/chunk-V43RXKN2.mjs +6 -0
  41. package/dist/chunk-VKFLXFPP.mjs +2 -0
  42. package/dist/chunk-WMQRTFOP.mjs +2 -0
  43. package/dist/chunk-XHEBV2HE.js +2 -0
  44. package/dist/chunk-XMQV2WFY.mjs +2 -0
  45. package/dist/chunk-XRDP2Y4J.mjs +2 -0
  46. package/dist/chunk-XUAP7KWK.js +2 -0
  47. package/dist/chunk-XXTKNIBK.js +2 -0
  48. package/dist/chunk-YIXNAWH6.mjs +2 -0
  49. package/dist/exceptions.d.mts +8 -2
  50. package/dist/exceptions.d.ts +8 -2
  51. package/dist/exceptions.js +1 -158
  52. package/dist/exceptions.mjs +1 -1
  53. package/dist/{helpers-Dul_r9rJ.d.mts → helpers-BUsoR80N.d.mts} +3 -3
  54. package/dist/{helpers-CXkVwpsl.d.ts → helpers-DZFOorZt.d.ts} +3 -3
  55. package/dist/{index-CFhPHQaI.d.ts → index-DaY37pqb.d.ts} +2 -2
  56. package/dist/{index-BdVnHL3F.d.mts → index-EHhbbH-p.d.mts} +2 -2
  57. package/dist/index.d.mts +500 -146
  58. package/dist/index.d.ts +500 -146
  59. package/dist/index.js +30 -10514
  60. package/dist/index.mjs +30 -9626
  61. package/dist/{migrations-fRvadl6i.d.mts → migrations-DRBic-QO.d.mts} +1 -1
  62. package/dist/{migrations-DaFneOfx.d.ts → migrations-DhQ05TqN.d.ts} +1 -1
  63. package/dist/{objects-DJv6WrDE.d.ts → objects-DMOfJNYg.d.ts} +2 -2
  64. package/dist/{objects-CDwMSnqv.d.mts → objects-KU7alqZq.d.mts} +2 -2
  65. package/dist/{types-NGEww_ln.d.ts → types-BNaHEz_n.d.ts} +1 -1
  66. package/dist/{types-CVYiFc69.d.mts → types-ldo4nJxP.d.mts} +1 -1
  67. package/dist/utils.js +1 -31
  68. package/dist/utils.mjs +1 -2
  69. package/dist/validation/all.d.mts +7 -7
  70. package/dist/validation/all.d.ts +7 -7
  71. package/dist/validation/all.js +1 -131
  72. package/dist/validation/all.mjs +1 -18
  73. package/dist/validation/complex/currency.d.mts +2 -2
  74. package/dist/validation/complex/currency.d.ts +2 -2
  75. package/dist/validation/complex/currency.js +1 -11
  76. package/dist/validation/complex/currency.mjs +1 -2
  77. package/dist/validation/complex/location.d.mts +2 -2
  78. package/dist/validation/complex/location.d.ts +2 -2
  79. package/dist/validation/complex/location.js +1 -11
  80. package/dist/validation/complex/location.mjs +1 -2
  81. package/dist/validation/complex/phone.d.mts +2 -2
  82. package/dist/validation/complex/phone.d.ts +2 -2
  83. package/dist/validation/complex/phone.js +1 -11
  84. package/dist/validation/complex/phone.mjs +1 -2
  85. package/dist/validation/complex/relation.d.mts +2 -2
  86. package/dist/validation/complex/relation.d.ts +2 -2
  87. package/dist/validation/complex/relation.js +1 -19
  88. package/dist/validation/complex/relation.mjs +1 -2
  89. package/dist/validation/complex/richtext.d.mts +2 -2
  90. package/dist/validation/complex/richtext.d.ts +2 -2
  91. package/dist/validation/complex/richtext.js +1 -11
  92. package/dist/validation/complex/richtext.mjs +1 -2
  93. package/dist/validation/complex/select.d.mts +2 -2
  94. package/dist/validation/complex/select.d.ts +2 -2
  95. package/dist/validation/complex/select.js +1 -19
  96. package/dist/validation/complex/select.mjs +1 -2
  97. package/dist/validation/complex/user.d.mts +2 -2
  98. package/dist/validation/complex/user.d.ts +2 -2
  99. package/dist/validation/complex/user.js +1 -11
  100. package/dist/validation/complex/user.mjs +1 -2
  101. package/dist/validation/computed/formula.d.mts +2 -2
  102. package/dist/validation/computed/formula.d.ts +2 -2
  103. package/dist/validation/computed/formula.js +1 -11
  104. package/dist/validation/computed/formula.mjs +1 -2
  105. package/dist/validation/computed/rollup.d.mts +2 -2
  106. package/dist/validation/computed/rollup.d.ts +2 -2
  107. package/dist/validation/computed/rollup.js +1 -11
  108. package/dist/validation/computed/rollup.mjs +1 -2
  109. package/dist/validation/config/index.d.mts +4 -4
  110. package/dist/validation/config/index.d.ts +4 -4
  111. package/dist/validation/config/index.js +1 -52
  112. package/dist/validation/config/index.mjs +1 -7
  113. package/dist/validation/core/index.d.mts +3 -3
  114. package/dist/validation/core/index.d.ts +3 -3
  115. package/dist/validation/core/index.js +1 -14
  116. package/dist/validation/core/index.mjs +1 -1
  117. package/dist/validation/object/index.d.mts +5 -5
  118. package/dist/validation/object/index.d.ts +5 -5
  119. package/dist/validation/object/index.js +1 -69
  120. package/dist/validation/object/index.mjs +1 -16
  121. package/dist/validation/primitives/checkbox.d.mts +2 -2
  122. package/dist/validation/primitives/checkbox.d.ts +2 -2
  123. package/dist/validation/primitives/checkbox.js +1 -11
  124. package/dist/validation/primitives/checkbox.mjs +1 -2
  125. package/dist/validation/primitives/date.d.mts +2 -2
  126. package/dist/validation/primitives/date.d.ts +2 -2
  127. package/dist/validation/primitives/date.js +1 -11
  128. package/dist/validation/primitives/date.mjs +1 -2
  129. package/dist/validation/primitives/number.d.mts +2 -2
  130. package/dist/validation/primitives/number.d.ts +2 -2
  131. package/dist/validation/primitives/number.js +1 -11
  132. package/dist/validation/primitives/number.mjs +1 -2
  133. package/dist/validation/primitives/text.d.mts +2 -2
  134. package/dist/validation/primitives/text.d.ts +2 -2
  135. package/dist/validation/primitives/text.js +1 -11
  136. package/dist/validation/primitives/text.mjs +1 -2
  137. package/package.json +7 -5
  138. package/dist/chunk-2WWGHULM.mjs +0 -226
  139. package/dist/chunk-4KMUATDG.js +0 -609
  140. package/dist/chunk-5WATIVCA.js +0 -10
  141. package/dist/chunk-ACKMC6FL.js +0 -17
  142. package/dist/chunk-AYVHMVKQ.mjs +0 -15
  143. package/dist/chunk-CLZORRMS.mjs +0 -570
  144. package/dist/chunk-DVXGSTWJ.js +0 -81
  145. package/dist/chunk-E6JUYGJX.js +0 -22
  146. package/dist/chunk-EEH4XQ7W.js +0 -61
  147. package/dist/chunk-EW5XR2X3.js +0 -12
  148. package/dist/chunk-GO6LQADH.mjs +0 -57
  149. package/dist/chunk-HRQEZUAA.mjs +0 -29
  150. package/dist/chunk-HTSTPTNZ.js +0 -10
  151. package/dist/chunk-HURC6CW3.js +0 -241
  152. package/dist/chunk-JZNR4HKQ.mjs +0 -1432
  153. package/dist/chunk-KAWYU7TE.js +0 -657
  154. package/dist/chunk-KNGWHQLR.js +0 -16
  155. package/dist/chunk-LV3FEUKU.mjs +0 -14
  156. package/dist/chunk-NS63SPNN.mjs +0 -8
  157. package/dist/chunk-O73ROMWQ.mjs +0 -85
  158. package/dist/chunk-OSSGN43B.mjs +0 -8
  159. package/dist/chunk-Q44QKLN4.mjs +0 -43
  160. package/dist/chunk-Q4SZAMJT.js +0 -72
  161. package/dist/chunk-QT35SI3K.mjs +0 -641
  162. package/dist/chunk-QVLQPW3O.mjs +0 -10
  163. package/dist/chunk-QWKLQRBX.js +0 -35
  164. package/dist/chunk-R2DAEDRF.mjs +0 -74
  165. package/dist/chunk-R5LAJCBU.mjs +0 -67
  166. package/dist/chunk-SI34M4IC.js +0 -45
  167. package/dist/chunk-T5PM73EF.js +0 -1504
  168. package/dist/chunk-UANQJ2GH.mjs +0 -25
  169. package/dist/chunk-UXAHLSWC.mjs +0 -8
  170. package/dist/chunk-V2UA2D4E.js +0 -10
  171. package/dist/chunk-YIP5FJ5H.js +0 -27
  172. package/dist/chunk-YKWSHBT5.js +0 -32
  173. package/dist/chunk-YUFTHPOE.mjs +0 -20
  174. package/dist/chunk-ZDQ5AP26.mjs +0 -31
  175. package/dist/chunk-ZPFOKBIN.js +0 -89
@@ -1,641 +0,0 @@
1
- import { ValidationError } from './chunk-CLZORRMS.mjs';
2
- import { z } from 'zod';
3
- import { ICONS, COLORS } from '@stndrds/constants';
4
-
5
- // src/computed/parser.ts
6
- var ComputedFormulaParseError = class extends Error {
7
- constructor(message) {
8
- super(message);
9
- this.name = "ComputedFormulaParseError";
10
- }
11
- };
12
- function parseComputedFormula(expression) {
13
- const parser = new Parser(tokenize(expression));
14
- const ast = parser.parseExpression();
15
- parser.expectEnd();
16
- return ast;
17
- }
18
- function tokenize(expression) {
19
- const tokens = [];
20
- let index = 0;
21
- while (index < expression.length) {
22
- const char = expression[index];
23
- if (char === " " || char === " " || char === "\n" || char === "\r") {
24
- index += 1;
25
- continue;
26
- }
27
- if (char === '"' || char === "'") {
28
- const result = scanString(expression, index, char);
29
- tokens.push({ kind: "string", value: result.value, position: index });
30
- index = result.nextIndex;
31
- continue;
32
- }
33
- if (isDigit(char)) {
34
- const result = scanNumber(expression, index);
35
- tokens.push({ kind: "number", value: result.value, position: index });
36
- index = result.nextIndex;
37
- continue;
38
- }
39
- if (isIdentifierStart(char)) {
40
- const result = scanIdentifier(expression, index);
41
- const canonical = result.value.toLowerCase();
42
- if (canonical === "true") {
43
- tokens.push({ kind: "boolean", value: true, position: index });
44
- } else if (canonical === "false") {
45
- tokens.push({ kind: "boolean", value: false, position: index });
46
- } else if (canonical === "null") {
47
- tokens.push({ kind: "null", position: index });
48
- } else {
49
- tokens.push({ kind: "identifier", value: result.value, position: index });
50
- }
51
- index = result.nextIndex;
52
- continue;
53
- }
54
- const twoChar = expression.slice(index, index + 2);
55
- if (twoChar === ">=" || twoChar === "<=" || twoChar === "==" || twoChar === "!=") {
56
- tokens.push({ kind: "operator", value: twoChar, position: index });
57
- index += 2;
58
- continue;
59
- }
60
- if (char === ">" || char === "<" || char === "+" || char === "-" || char === "*" || char === "/") {
61
- tokens.push({ kind: "operator", value: char, position: index });
62
- index += 1;
63
- continue;
64
- }
65
- if (char === "(" || char === ")" || char === "," || char === ".") {
66
- tokens.push({ kind: "punctuation", value: char, position: index });
67
- index += 1;
68
- continue;
69
- }
70
- throw new ComputedFormulaParseError(`Unexpected character "${char}" at position ${index}`);
71
- }
72
- return tokens;
73
- }
74
- function scanString(expression, startIndex, delimiter = '"') {
75
- let value = "";
76
- let index = startIndex + 1;
77
- while (index < expression.length) {
78
- const char = expression[index];
79
- if (char === delimiter) {
80
- return { value, nextIndex: index + 1 };
81
- }
82
- if (char === "\\") {
83
- const escaped = expression[index + 1];
84
- if (escaped === void 0) {
85
- throw new ComputedFormulaParseError(`Unterminated string literal at position ${index}`);
86
- }
87
- value += decodeEscape(escaped, index);
88
- index += 2;
89
- continue;
90
- }
91
- value += char;
92
- index += 1;
93
- }
94
- throw new ComputedFormulaParseError(`Unterminated string literal at position ${startIndex}`);
95
- }
96
- function decodeEscape(char, position) {
97
- switch (char) {
98
- case '"':
99
- case "\\":
100
- return char;
101
- case "n":
102
- return "\n";
103
- case "r":
104
- return "\r";
105
- case "t":
106
- return " ";
107
- default:
108
- throw new ComputedFormulaParseError(
109
- `Unknown escape sequence "\\${char}" at position ${position}`
110
- );
111
- }
112
- }
113
- function scanNumber(expression, startIndex) {
114
- let index = startIndex;
115
- while (index < expression.length && isDigit(expression[index])) {
116
- index += 1;
117
- }
118
- if (expression[index] === ".") {
119
- const decimalStart = index;
120
- index += 1;
121
- if (!isDigit(expression[index])) {
122
- throw new ComputedFormulaParseError(`Invalid number literal at position ${decimalStart}`);
123
- }
124
- while (index < expression.length && isDigit(expression[index])) {
125
- index += 1;
126
- }
127
- }
128
- const raw = expression.slice(startIndex, index);
129
- const value = Number(raw);
130
- if (!Number.isFinite(value)) {
131
- throw new ComputedFormulaParseError(`Invalid number literal "${raw}"`);
132
- }
133
- return { value, nextIndex: index };
134
- }
135
- function scanIdentifier(expression, startIndex) {
136
- let index = startIndex + 1;
137
- while (index < expression.length && isIdentifierPart(expression[index])) {
138
- index += 1;
139
- }
140
- return { value: expression.slice(startIndex, index), nextIndex: index };
141
- }
142
- function isDigit(char) {
143
- return char !== void 0 && char >= "0" && char <= "9";
144
- }
145
- function isIdentifierStart(char) {
146
- return char !== void 0 && /[A-Za-z_]/.test(char);
147
- }
148
- function isIdentifierPart(char) {
149
- return char !== void 0 && /[A-Za-z0-9_]/.test(char);
150
- }
151
- var Parser = class {
152
- constructor(tokens) {
153
- this.tokens = tokens;
154
- this.position = 0;
155
- }
156
- parseExpression() {
157
- return this.parseBinaryExpression(0);
158
- }
159
- expectEnd() {
160
- const token = this.peek();
161
- if (token !== void 0) {
162
- throw new ComputedFormulaParseError(
163
- `Unexpected token ${describeToken(token)} at position ${token.position}`
164
- );
165
- }
166
- }
167
- parseBinaryExpression(minPrecedence) {
168
- let left = this.parsePrimary();
169
- while (true) {
170
- const token = this.peek();
171
- if (token?.kind !== "operator") {
172
- return left;
173
- }
174
- const precedence = getOperatorPrecedence(token.value);
175
- if (precedence < minPrecedence) {
176
- return left;
177
- }
178
- const operator = token.value;
179
- this.consume();
180
- const right = this.parseBinaryExpression(precedence + 1);
181
- left = { kind: "binary", operator, left, right };
182
- }
183
- }
184
- parsePrimary() {
185
- const token = this.consume();
186
- if (token === void 0) {
187
- throw new ComputedFormulaParseError("Unexpected end of expression");
188
- }
189
- switch (token.kind) {
190
- case "string":
191
- case "number":
192
- case "boolean":
193
- return { kind: "literal", value: token.value };
194
- case "null":
195
- return { kind: "literal", value: null };
196
- case "identifier":
197
- return this.parseIdentifier(token.value);
198
- case "punctuation":
199
- if (token.value === "(") {
200
- const expression = this.parseExpression();
201
- this.expectPunctuation(")");
202
- return expression;
203
- }
204
- break;
205
- case "operator":
206
- if (token.value === "-") {
207
- const next = this.consume();
208
- if (next?.kind === "number") {
209
- return { kind: "literal", value: -next.value };
210
- }
211
- }
212
- break;
213
- }
214
- throw new ComputedFormulaParseError(
215
- `Expected literal, path, call, or parenthesized expression at position ${token.position}`
216
- );
217
- }
218
- parseIdentifier(identifier) {
219
- if (this.matchPunctuation("(")) {
220
- const args = [];
221
- if (!this.matchPunctuation(")")) {
222
- do {
223
- args.push(this.parseExpression());
224
- } while (this.matchPunctuation(","));
225
- this.expectPunctuation(")");
226
- }
227
- return { kind: "call", functionName: identifier.toLowerCase(), args };
228
- }
229
- const parts = [identifier];
230
- while (this.matchPunctuation(".")) {
231
- const next = this.consume();
232
- if (next?.kind !== "identifier") {
233
- const position = next?.position ?? this.previousPosition();
234
- throw new ComputedFormulaParseError(
235
- `Expected attribute name after path separator at position ${position}`
236
- );
237
- }
238
- parts.push(next.value);
239
- }
240
- return { kind: "path", parts };
241
- }
242
- expectPunctuation(value) {
243
- if (!this.matchPunctuation(value)) {
244
- const token = this.peek();
245
- const position = token?.position ?? this.previousPosition();
246
- throw new ComputedFormulaParseError(`Expected "${value}" at position ${position}`);
247
- }
248
- }
249
- matchPunctuation(value) {
250
- const token = this.peek();
251
- if (token?.kind === "punctuation" && token.value === value) {
252
- this.consume();
253
- return true;
254
- }
255
- return false;
256
- }
257
- peek() {
258
- return this.tokens[this.position];
259
- }
260
- consume() {
261
- const token = this.tokens[this.position];
262
- this.position += 1;
263
- return token;
264
- }
265
- previousPosition() {
266
- const previous = this.tokens[this.position - 1];
267
- return previous?.position ?? 0;
268
- }
269
- };
270
- function describeToken(token) {
271
- switch (token.kind) {
272
- case "identifier":
273
- case "number":
274
- case "string":
275
- case "boolean":
276
- case "operator":
277
- case "punctuation":
278
- return `"${String(token.value)}"`;
279
- case "null":
280
- return '"null"';
281
- default: {
282
- const exhaustive = token;
283
- return exhaustive;
284
- }
285
- }
286
- }
287
- function getOperatorPrecedence(operator) {
288
- switch (operator) {
289
- case "*":
290
- case "/":
291
- return 3;
292
- case "+":
293
- case "-":
294
- return 2;
295
- case ">":
296
- case "<":
297
- case ">=":
298
- case "<=":
299
- case "==":
300
- case "!=":
301
- return 1;
302
- default: {
303
- const exhaustive = operator;
304
- return exhaustive;
305
- }
306
- }
307
- }
308
-
309
- // src/validation/limits.ts
310
- var SCHEMA_LIMITS = {
311
- attributesPerObject: 300,
312
- tabsPerView: 24,
313
- groupsPerFormTab: 12,
314
- fieldsPerGroup: 60,
315
- fieldsPerFormTab: 150,
316
- columnsPerTab: 50,
317
- optionsPerAttribute: 200,
318
- sidePanelAttributes: 100,
319
- sidePanelPanes: 20,
320
- filterRulesPerTab: 50,
321
- sortsPerTab: 20,
322
- emailAttributesPerTab: 30,
323
- objectsPerPlan: 20,
324
- mutationsPerPlan: 500,
325
- planBytes: 512 * 1024,
326
- historyDefault: 20,
327
- historyMax: 50,
328
- iconQueries: 5,
329
- iconResults: 20
330
- };
331
- var COLOR_IDS = Object.keys(COLORS);
332
- var ICON_NAMES = new Set(ICONS);
333
- var colorIdSchema = z.enum(COLOR_IDS);
334
- var iconNameSchema = z.string().superRefine((value, ctx) => {
335
- if (!ICON_NAMES.has(value)) {
336
- ctx.addIssue({
337
- code: "custom",
338
- message: "Invalid icon name"
339
- });
340
- }
341
- }).transform((value) => value);
342
-
343
- // src/validation/config/schemas.ts
344
- var baseConfigSchema = z.object({
345
- placeholder: z.string().optional(),
346
- description: z.string().optional(),
347
- defaultValue: z.unknown().optional(),
348
- icon: z.string().optional(),
349
- order: z.number().int().optional(),
350
- hidden: z.boolean().optional(),
351
- archived: z.boolean().optional(),
352
- deprecated: z.boolean().optional(),
353
- metadata: z.record(z.string(), z.unknown()).optional()
354
- });
355
- var optionBaseSchema = z.object({
356
- value: z.string().min(1),
357
- label: z.string().min(1),
358
- description: z.string().optional(),
359
- inverse: z.string().optional(),
360
- archived: z.boolean().optional()
361
- });
362
- var statusGroupSchema = z.enum(["idle", "in_progress", "finished"]);
363
- var selectOptionWriteSchema = optionBaseSchema.extend({
364
- color: colorIdSchema
365
- }).strict();
366
- var multiselectOptionWriteSchema = selectOptionWriteSchema;
367
- var statusOptionWriteSchema = optionBaseSchema.extend({
368
- color: colorIdSchema,
369
- group: statusGroupSchema
370
- }).strict();
371
- var optionSchema = optionBaseSchema.extend({
372
- color: z.string().optional(),
373
- group: statusGroupSchema.optional()
374
- }).strict();
375
- var optionsArraySchema = z.array(optionSchema).min(1).refine(
376
- (options) => {
377
- const values = options.map((o) => o.value);
378
- return new Set(values).size === values.length;
379
- },
380
- { message: "Duplicate option values are not allowed" }
381
- );
382
- function writeOptionsArraySchema(option) {
383
- return z.array(option).min(1).max(SCHEMA_LIMITS.optionsPerAttribute).refine(
384
- (options) => {
385
- const values = options.map((candidate) => candidate.value);
386
- return new Set(values).size === values.length;
387
- },
388
- { message: "Duplicate option values are not allowed" }
389
- );
390
- }
391
- var selectOptionsWriteSchema = writeOptionsArraySchema(selectOptionWriteSchema);
392
- var multiselectOptionsWriteSchema = writeOptionsArraySchema(multiselectOptionWriteSchema);
393
- var statusOptionsWriteSchema = writeOptionsArraySchema(statusOptionWriteSchema);
394
- var relationTargetSchema = z.object({
395
- object: z.string().min(1),
396
- displayTemplate: z.string().optional(),
397
- filter: z.record(z.string(), z.unknown()).optional()
398
- });
399
- var bilateralConfigSchema = z.object({
400
- object: z.string().min(1),
401
- attribute: z.string().min(1),
402
- cardinality: z.enum(["one", "many"]).optional(),
403
- storageOwner: z.boolean().optional()
404
- });
405
- var computedOptionsSourceSchema = z.object({
406
- objectName: z.string().min(1),
407
- attributeName: z.string().min(1),
408
- attributeId: z.string().optional()
409
- });
410
- var textConfigSchema = baseConfigSchema.extend({
411
- multiline: z.boolean().optional(),
412
- minLength: z.number().int().min(0).optional(),
413
- maxLength: z.number().int().min(1).optional(),
414
- pattern: z.string().optional(),
415
- format: z.enum(["email", "url", "slug"]).optional()
416
- });
417
- var richtextConfigSchema = baseConfigSchema;
418
- var numberConfigSchema = baseConfigSchema.extend({
419
- renderAs: z.enum(["number", "rating"]).optional(),
420
- min: z.number().optional(),
421
- max: z.number().optional(),
422
- unit: z.enum(["integer", "decimal", "percentage"]).optional(),
423
- decimals: z.number().int().min(0).max(10).optional()
424
- });
425
- var checkboxConfigSchema = baseConfigSchema;
426
- var dateConfigSchema = baseConfigSchema.extend({
427
- dateFormat: z.enum(["short", "long", "full", "relative"]).optional(),
428
- minDate: z.string().optional(),
429
- maxDate: z.string().optional(),
430
- includeTime: z.boolean().optional(),
431
- endDate: z.boolean().optional(),
432
- timeFormat: z.enum(["12h", "24h"]).optional()
433
- });
434
- var phoneConfigSchema = baseConfigSchema.extend({
435
- defaultCountryCode: z.string().length(3).optional()
436
- });
437
- var currencyConfigSchema = baseConfigSchema.extend({
438
- defaultCurrency: z.string().length(3).optional(),
439
- allowedCurrencies: z.array(z.string().length(3)).optional(),
440
- allowNegative: z.boolean().optional()
441
- });
442
- var statusConfigSchema = baseConfigSchema.extend({
443
- options: optionsArraySchema
444
- });
445
- var locationConfigSchema = baseConfigSchema.extend({
446
- granularity: z.enum(["full", "address", "city", "state", "country", "coordinates"]).optional(),
447
- defaultCountry: z.string().length(3).optional(),
448
- allowedCountries: z.array(z.string().length(3)).optional()
449
- });
450
- var selectConfigSchema = baseConfigSchema.extend({
451
- options: optionsArraySchema,
452
- renderAs: z.literal("badges").optional()
453
- });
454
- var multiselectConfigSchema = baseConfigSchema.extend({
455
- options: optionsArraySchema,
456
- renderAs: z.literal("badges").optional()
457
- });
458
- var userConfigSchema = baseConfigSchema.extend({
459
- types: z.array(z.enum(["user", "agent"])).min(1).optional(),
460
- multiple: z.boolean().optional()
461
- });
462
- var relationConfigSchema = baseConfigSchema.extend({
463
- targets: z.array(relationTargetSchema).min(1),
464
- cardinality: z.enum(["one", "many"]),
465
- maxItems: z.number().int().min(1).optional(),
466
- bilateral: bilateralConfigSchema.optional(),
467
- /**
468
- * PropertySchema declared via `.qualifyWith()`. Pass-through; structural
469
- * validation happens at the builder level — see `propertySchemaPassthrough`
470
- * comment further below for the rationale.
471
- */
472
- properties: z.object({ definitions: z.array(z.record(z.string(), z.unknown())) }).passthrough().optional()
473
- });
474
- var formulaConfigSchema = baseConfigSchema.extend({
475
- // Validate the expression grammar up-front so an assignment-style "=" (or any
476
- // other malformed syntax) is rejected at save time instead of crashing the
477
- // computed write-path later. Type/attribute coherence is still checked
478
- // downstream by compileComputedFormula, which needs the full schema.
479
- expression: z.string().min(1).superRefine((value, ctx) => {
480
- try {
481
- parseComputedFormula(value);
482
- } catch (error) {
483
- ctx.addIssue({
484
- code: z.ZodIssueCode.custom,
485
- message: error instanceof Error ? error.message : "Invalid formula expression"
486
- });
487
- }
488
- }),
489
- returnType: z.enum(["text", "number", "boolean", "date", "select", "multiselect"]),
490
- decimals: z.number().int().min(0).max(10).optional(),
491
- allowRelations: z.boolean().optional(),
492
- optionsSource: computedOptionsSourceSchema.optional()
493
- });
494
- var rollupConfigSchema = baseConfigSchema.extend({
495
- relationAttribute: z.string().min(1).optional(),
496
- relationPath: z.string().optional(),
497
- targetAttribute: z.string().min(1),
498
- function: z.enum([
499
- "sum",
500
- "avg",
501
- "earliest",
502
- "latest",
503
- "count",
504
- "countValues",
505
- "countUniqueValues",
506
- "countEmpty",
507
- "percentEmpty",
508
- "percentNotEmpty",
509
- "original"
510
- ]),
511
- decimals: z.number().int().min(0).max(10).optional(),
512
- targetAttributeType: z.string().optional(),
513
- targetAttributeOptions: z.array(optionSchema).optional(),
514
- // The sum's symbol (#2644) — declared here or `.strip()` eats it before
515
- // storage, exactly the fate this schema spares its two siblings above.
516
- targetCurrencyCode: z.string().length(3).optional(),
517
- optionsSource: computedOptionsSourceSchema.optional()
518
- });
519
- var propertySchemaPassthrough = z.object({ definitions: z.array(z.record(z.string(), z.unknown())) }).passthrough();
520
- var documentConfigSchema = baseConfigSchema.extend({
521
- /**
522
- * PropertySchema declared via `.qualifyWith()` on a document attribute.
523
- * Drives hydration into `[{id, props}]` shape and write-time validation.
524
- */
525
- properties: propertySchemaPassthrough.optional(),
526
- /** MIME prefixes/globs declared via `.accepts(...)`, applied to every file of the pack. */
527
- accepts: z.array(z.string().min(1)).optional(),
528
- /** Hard ceiling in bytes declared via `.maxFileSize(...)`, applied to every file of the pack. */
529
- maxFileSize: z.number().int().min(1).optional()
530
- });
531
- var attributeConfigSchemas = {
532
- text: textConfigSchema,
533
- richtext: richtextConfigSchema,
534
- number: numberConfigSchema,
535
- checkbox: checkboxConfigSchema,
536
- date: dateConfigSchema,
537
- phone: phoneConfigSchema,
538
- currency: currencyConfigSchema,
539
- status: statusConfigSchema,
540
- location: locationConfigSchema,
541
- select: selectConfigSchema,
542
- multiselect: multiselectConfigSchema,
543
- user: userConfigSchema,
544
- relation: relationConfigSchema,
545
- formula: formulaConfigSchema,
546
- rollup: rollupConfigSchema,
547
- document: documentConfigSchema
548
- };
549
- function getAttributeConfigSchema(type) {
550
- const schema = attributeConfigSchemas[type];
551
- if (!schema) {
552
- throw new ValidationError(`Unsupported attribute type: ${type}`, []);
553
- }
554
- return schema;
555
- }
556
- function parseAttributeConfig(type, config) {
557
- const schema = getAttributeConfigSchema(type);
558
- return schema.strip().parse(config);
559
- }
560
- function getAttributeConfigWriteSchema(type) {
561
- const schema = getAttributeConfigSchema(type).extend({
562
- icon: iconNameSchema.optional()
563
- });
564
- switch (type) {
565
- case "select":
566
- return schema.extend({ options: selectOptionsWriteSchema });
567
- case "multiselect":
568
- return schema.extend({ options: multiselectOptionsWriteSchema });
569
- case "status":
570
- return schema.extend({ options: statusOptionsWriteSchema });
571
- default:
572
- return schema;
573
- }
574
- }
575
- function validationErrorFromIssues(issues) {
576
- return ValidationError.fromZodErrors(
577
- issues.map((issue) => ({
578
- path: issue.path.map((segment) => typeof segment === "symbol" ? String(segment) : segment),
579
- message: issue.message
580
- }))
581
- );
582
- }
583
- function parseWriteSchema(type, input) {
584
- const result = getAttributeConfigWriteSchema(type).strip().safeParse(input);
585
- if (!result.success) {
586
- throw validationErrorFromIssues(result.error.issues);
587
- }
588
- return result.data;
589
- }
590
- function parseAttributeConfigForCreate(type, input) {
591
- return parseWriteSchema(type, input);
592
- }
593
- function validatePatchedIcon(patch) {
594
- if (!Object.prototype.hasOwnProperty.call(patch, "icon")) {
595
- return;
596
- }
597
- const result = iconNameSchema.optional().safeParse(patch.icon);
598
- if (!result.success) {
599
- throw ValidationError.fromZodErrors(
600
- result.error.issues.map((issue) => ({
601
- path: [
602
- "icon",
603
- ...issue.path.map((segment) => typeof segment === "symbol" ? String(segment) : segment)
604
- ],
605
- message: issue.message
606
- }))
607
- );
608
- }
609
- }
610
- function isSelectLike(type) {
611
- return type === "select" || type === "multiselect" || type === "status";
612
- }
613
- function parseAttributeConfigForUpdate(stored, patch) {
614
- const ownsOptions = Object.prototype.hasOwnProperty.call(patch, "options");
615
- const ownsIcon = Object.prototype.hasOwnProperty.call(patch, "icon");
616
- const input = { ...stored, ...patch };
617
- validatePatchedIcon(patch);
618
- if (ownsOptions) {
619
- const { icon: storedIcon, ...inputWithoutStoredIcon } = input;
620
- const parsed2 = parseWriteSchema(stored.type, ownsIcon ? input : inputWithoutStoredIcon);
621
- if (!ownsIcon && storedIcon !== void 0) {
622
- parsed2.icon = storedIcon;
623
- }
624
- return parsed2;
625
- }
626
- const storedOptions = stored.options;
627
- if (isSelectLike(stored.type)) {
628
- input.options = [{ value: "__legacy__", label: "__legacy__" }];
629
- }
630
- const result = getAttributeConfigSchema(stored.type).strip().safeParse(input);
631
- if (!result.success) {
632
- throw validationErrorFromIssues(result.error.issues);
633
- }
634
- const parsed = result.data;
635
- if (isSelectLike(stored.type)) {
636
- parsed.options = storedOptions;
637
- }
638
- return parsed;
639
- }
640
-
641
- export { ComputedFormulaParseError, SCHEMA_LIMITS, attributeConfigSchemas, colorIdSchema, getAttributeConfigSchema, getAttributeConfigWriteSchema, iconNameSchema, multiselectOptionWriteSchema, parseAttributeConfig, parseAttributeConfigForCreate, parseAttributeConfigForUpdate, parseComputedFormula, selectOptionWriteSchema, statusGroupSchema, statusOptionWriteSchema };
@@ -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;