@stndrds/schema 0.1.0-alpha.66 → 1.0.0-alpha.100
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.
- package/dist/attributes-CH89Z_J-.d.mts +675 -0
- package/dist/attributes-dw-jLtYS.d.ts +675 -0
- package/dist/chunk-2LUHLHLE.mjs +8 -0
- package/dist/chunk-3RFFA4EV.mjs +14 -0
- package/dist/chunk-4DMDOSFN.js +10 -0
- package/dist/chunk-4IVCBFJA.mjs +12 -0
- package/dist/chunk-5CBTJS7J.js +22 -0
- package/dist/chunk-5SQEKHPW.js +78 -0
- package/dist/chunk-6IFD5732.js +10 -0
- package/dist/chunk-6MXQAQBB.mjs +18 -0
- package/dist/chunk-7FSIBNRH.mjs +25 -0
- package/dist/chunk-ALV6GETG.mjs +10 -0
- package/dist/chunk-ANP6HGMJ.js +64 -0
- package/dist/chunk-ATA4XHB4.js +20 -0
- package/dist/chunk-BEN6TE7Y.js +11 -0
- package/dist/chunk-BZTLI773.mjs +8 -0
- package/dist/chunk-C7KW4NAD.js +20 -0
- package/dist/chunk-CE25ADK5.js +212 -0
- package/dist/chunk-E6XO2STS.js +61 -0
- package/dist/chunk-EKG35CSO.mjs +1 -0
- package/dist/chunk-ERG77ADK.mjs +18 -0
- package/dist/chunk-FKETRWAF.js +10 -0
- package/dist/chunk-FKPYFM6G.mjs +14 -0
- package/dist/chunk-H3VBSMVW.js +105 -0
- package/dist/chunk-HJNLL34O.js +12 -0
- package/dist/chunk-IMEPIVTR.js +217 -0
- package/dist/chunk-JEDANRCG.mjs +74 -0
- package/dist/chunk-KC2FFNL4.js +16 -0
- package/dist/chunk-OO2LJ6GP.js +32 -0
- package/dist/chunk-P4NGPF5L.mjs +99 -0
- package/dist/chunk-PGHTIMRD.mjs +199 -0
- package/dist/chunk-PZT3CIHD.mjs +192 -0
- package/dist/chunk-QPDXDX7A.js +16 -0
- package/dist/chunk-R6JFUC32.js +2 -0
- package/dist/chunk-RDGBQM3N.mjs +20 -0
- package/dist/chunk-RDXQ4CYT.mjs +9 -0
- package/dist/chunk-STKN6A5M.js +14 -0
- package/dist/chunk-TV4G2KMD.mjs +8 -0
- package/dist/chunk-UPEQEX2D.js +10 -0
- package/dist/chunk-VC4E3OSZ.mjs +8 -0
- package/dist/{chunk-V2RPPE2Y.mjs → chunk-XAORXFAX.mjs} +20 -9
- package/dist/chunk-XPFWKISJ.mjs +60 -0
- package/dist/chunk-ZJNX6UXB.mjs +28 -0
- package/dist/chunk-ZWMMEQI7.js +28 -0
- package/dist/index-CftmKoRP.d.mts +2053 -0
- package/dist/index-Dh_XiNFt.d.ts +2053 -0
- package/dist/index.d.mts +4406 -490
- package/dist/index.d.ts +4406 -490
- package/dist/index.js +6598 -1729
- package/dist/index.mjs +5260 -938
- package/dist/types-D-0QbsA9.d.ts +39 -0
- package/dist/types-Ms3HtAmo.d.mts +39 -0
- package/dist/utils.d.mts +20 -1
- package/dist/utils.d.ts +20 -1
- package/dist/utils.js +38 -19
- package/dist/utils.mjs +1 -19
- package/dist/validation/all.d.mts +23 -0
- package/dist/validation/all.d.ts +23 -0
- package/dist/validation/all.js +265 -0
- package/dist/validation/all.mjs +20 -0
- package/dist/validation/complex/currency.d.mts +15 -0
- package/dist/validation/complex/currency.d.ts +15 -0
- package/dist/validation/complex/currency.js +12 -0
- package/dist/validation/complex/currency.mjs +3 -0
- package/dist/validation/complex/file.d.mts +13 -0
- package/dist/validation/complex/file.d.ts +13 -0
- package/dist/validation/complex/file.js +12 -0
- package/dist/validation/complex/file.mjs +3 -0
- package/dist/validation/complex/location.d.mts +22 -0
- package/dist/validation/complex/location.d.ts +22 -0
- package/dist/validation/complex/location.js +12 -0
- package/dist/validation/complex/location.mjs +3 -0
- package/dist/validation/complex/phone.d.mts +22 -0
- package/dist/validation/complex/phone.d.ts +22 -0
- package/dist/validation/complex/phone.js +12 -0
- package/dist/validation/complex/phone.mjs +3 -0
- package/dist/validation/complex/relation.d.mts +25 -0
- package/dist/validation/complex/relation.d.ts +25 -0
- package/dist/validation/complex/relation.js +20 -0
- package/dist/validation/complex/relation.mjs +3 -0
- package/dist/validation/complex/richtext.d.mts +13 -0
- package/dist/validation/complex/richtext.d.ts +13 -0
- package/dist/validation/complex/richtext.js +12 -0
- package/dist/validation/complex/richtext.mjs +3 -0
- package/dist/validation/complex/select.d.mts +20 -0
- package/dist/validation/complex/select.d.ts +20 -0
- package/dist/validation/complex/select.js +20 -0
- package/dist/validation/complex/select.mjs +3 -0
- package/dist/validation/complex/user.d.mts +13 -0
- package/dist/validation/complex/user.d.ts +13 -0
- package/dist/validation/complex/user.js +12 -0
- package/dist/validation/complex/user.mjs +3 -0
- package/dist/validation/computed/formula.d.mts +14 -0
- package/dist/validation/computed/formula.d.ts +14 -0
- package/dist/validation/computed/formula.js +12 -0
- package/dist/validation/computed/formula.mjs +3 -0
- package/dist/validation/computed/rollup.d.mts +14 -0
- package/dist/validation/computed/rollup.d.ts +14 -0
- package/dist/validation/computed/rollup.js +12 -0
- package/dist/validation/computed/rollup.mjs +3 -0
- package/dist/validation/config/index.d.mts +421 -0
- package/dist/validation/config/index.d.ts +421 -0
- package/dist/validation/config/index.js +103 -0
- package/dist/validation/config/index.mjs +2 -0
- package/dist/validation/core/index.d.mts +68 -0
- package/dist/validation/core/index.d.ts +68 -0
- package/dist/validation/core/index.js +23 -0
- package/dist/validation/core/index.mjs +2 -0
- package/dist/validation/object/index.d.mts +6 -0
- package/dist/validation/object/index.d.ts +6 -0
- package/dist/validation/object/index.js +71 -0
- package/dist/validation/object/index.mjs +18 -0
- package/dist/validation/primitives/checkbox.d.mts +12 -0
- package/dist/validation/primitives/checkbox.d.ts +12 -0
- package/dist/validation/primitives/checkbox.js +12 -0
- package/dist/validation/primitives/checkbox.mjs +3 -0
- package/dist/validation/primitives/date.d.mts +12 -0
- package/dist/validation/primitives/date.d.ts +12 -0
- package/dist/validation/primitives/date.js +12 -0
- package/dist/validation/primitives/date.mjs +3 -0
- package/dist/validation/primitives/number.d.mts +12 -0
- package/dist/validation/primitives/number.d.ts +12 -0
- package/dist/validation/primitives/number.js +12 -0
- package/dist/validation/primitives/number.mjs +3 -0
- package/dist/validation/primitives/rating.d.mts +12 -0
- package/dist/validation/primitives/rating.d.ts +12 -0
- package/dist/validation/primitives/rating.js +12 -0
- package/dist/validation/primitives/rating.mjs +3 -0
- package/dist/validation/primitives/text.d.mts +17 -0
- package/dist/validation/primitives/text.d.ts +17 -0
- package/dist/validation/primitives/text.js +16 -0
- package/dist/validation/primitives/text.mjs +3 -0
- package/dist/validation/validators.d.mts +21 -2
- package/dist/validation/validators.d.ts +21 -2
- package/dist/validation/validators.js +265 -121
- package/dist/validation/validators.mjs +20 -121
- package/package.json +109 -13
- package/dist/chunk-36UBIXJN.js +0 -82
- package/dist/chunk-3RG5ZIWI.js +0 -10
- package/dist/chunk-A6T4UUZ2.mjs +0 -18669
- package/dist/chunk-NEVERCM3.js +0 -41
- package/dist/chunk-SV4BCGQU.mjs +0 -617
- package/dist/chunk-TOTUS3YS.js +0 -18669
- package/dist/chunk-U4AB53AM.js +0 -617
- package/dist/chunk-V5QXU2OK.mjs +0 -82
- package/dist/chunk-Y6FXYEAI.mjs +0 -10
- package/dist/default-roles-42X3TJI5.mjs +0 -21
- package/dist/default-roles-C3FYDYMN.js +0 -21
- package/dist/runtime-BgtwoMx5.d.ts +0 -12759
- package/dist/runtime-DQlTgVZJ.d.mts +0 -12759
- package/dist/runtime.d.mts +0 -6
- package/dist/runtime.d.ts +0 -6
- package/dist/runtime.js +0 -323
- package/dist/runtime.mjs +0 -323
- package/dist/validators-BROsLGn4.d.mts +0 -1556
- package/dist/validators-CEzdvxEq.d.ts +0 -1556
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { createCheckboxValidator } from './chunk-2LUHLHLE.mjs';
|
|
2
|
+
import { createDateValidator } from './chunk-BZTLI773.mjs';
|
|
3
|
+
import { createNumberValidator } from './chunk-6MXQAQBB.mjs';
|
|
4
|
+
import { createRatingValidator } from './chunk-4IVCBFJA.mjs';
|
|
5
|
+
import { createTextAreaValidator, createTextValidator } from './chunk-7FSIBNRH.mjs';
|
|
6
|
+
import { createRelationValidator } from './chunk-XPFWKISJ.mjs';
|
|
7
|
+
import { createRichtextValidator } from './chunk-ALV6GETG.mjs';
|
|
8
|
+
import { createMultiselectValidator, createSelectValidator, createStatusValidator } from './chunk-ZJNX6UXB.mjs';
|
|
9
|
+
import { createUserValidator } from './chunk-3RFFA4EV.mjs';
|
|
10
|
+
import { createFormulaValidator } from './chunk-TV4G2KMD.mjs';
|
|
11
|
+
import { createRollupValidator } from './chunk-VC4E3OSZ.mjs';
|
|
12
|
+
import { createCurrencyValidator } from './chunk-FKPYFM6G.mjs';
|
|
13
|
+
import { createFileValidator } from './chunk-ERG77ADK.mjs';
|
|
14
|
+
import { createLocationValidator } from './chunk-RDGBQM3N.mjs';
|
|
15
|
+
import { createPhoneValidator } from './chunk-P4NGPF5L.mjs';
|
|
16
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-JEDANRCG.mjs';
|
|
17
|
+
import { formatZodErrors } from './chunk-RDXQ4CYT.mjs';
|
|
18
|
+
import { z } from 'zod';
|
|
19
|
+
|
|
20
|
+
function isEmptyValue(value) {
|
|
21
|
+
if (value === null || value === void 0) return true;
|
|
22
|
+
if (typeof value === "string" && value.trim() === "") return true;
|
|
23
|
+
if (value instanceof Date) return false;
|
|
24
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
25
|
+
return Object.values(value).every(
|
|
26
|
+
(v) => v === null || v === void 0 || typeof v === "string" && v.trim() === ""
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
function withEmptyToNull(validator) {
|
|
32
|
+
return z.preprocess((val) => isEmptyValue(val) ? null : val, validator.nullish());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/validation/object/attribute-factory.ts
|
|
36
|
+
function createAttributeValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
37
|
+
switch (attr.type) {
|
|
38
|
+
case "text":
|
|
39
|
+
return createTextValidator(attr, messages);
|
|
40
|
+
case "textarea":
|
|
41
|
+
return createTextAreaValidator(attr, messages);
|
|
42
|
+
case "richtext":
|
|
43
|
+
return createRichtextValidator(attr, messages);
|
|
44
|
+
case "number":
|
|
45
|
+
return createNumberValidator(attr, messages);
|
|
46
|
+
case "checkbox":
|
|
47
|
+
return createCheckboxValidator(attr, messages);
|
|
48
|
+
case "date":
|
|
49
|
+
return createDateValidator(attr, messages);
|
|
50
|
+
case "phone":
|
|
51
|
+
return createPhoneValidator(attr, messages);
|
|
52
|
+
case "currency":
|
|
53
|
+
return createCurrencyValidator(attr, messages);
|
|
54
|
+
case "status":
|
|
55
|
+
return createStatusValidator(attr, messages);
|
|
56
|
+
case "location":
|
|
57
|
+
return createLocationValidator(attr, messages);
|
|
58
|
+
case "select":
|
|
59
|
+
return createSelectValidator(attr, messages);
|
|
60
|
+
case "multiselect":
|
|
61
|
+
return createMultiselectValidator(attr, messages);
|
|
62
|
+
case "file":
|
|
63
|
+
return createFileValidator(attr, messages);
|
|
64
|
+
case "user":
|
|
65
|
+
return createUserValidator(attr, messages);
|
|
66
|
+
case "relation":
|
|
67
|
+
return createRelationValidator(attr, messages);
|
|
68
|
+
case "rating":
|
|
69
|
+
return createRatingValidator(attr, messages);
|
|
70
|
+
case "formula":
|
|
71
|
+
return createFormulaValidator(attr, messages);
|
|
72
|
+
case "rollup":
|
|
73
|
+
return createRollupValidator(attr, messages);
|
|
74
|
+
default:
|
|
75
|
+
return z.unknown();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function createFormAttributeValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
79
|
+
const validator = createAttributeValidator(attr, messages);
|
|
80
|
+
if (!attr.required) {
|
|
81
|
+
return withEmptyToNull(validator);
|
|
82
|
+
}
|
|
83
|
+
return validator;
|
|
84
|
+
}
|
|
85
|
+
function createObjectValidator(objectDef) {
|
|
86
|
+
const shape = {};
|
|
87
|
+
for (const attr of objectDef.attributes) {
|
|
88
|
+
const validator = createAttributeValidator(attr);
|
|
89
|
+
shape[attr.name] = attr.required ? validator : withEmptyToNull(validator);
|
|
90
|
+
}
|
|
91
|
+
return z.object(shape).passthrough();
|
|
92
|
+
}
|
|
93
|
+
function createDraftValidator(objectDef) {
|
|
94
|
+
const shape = {};
|
|
95
|
+
for (const attr of objectDef.attributes) {
|
|
96
|
+
const validator = createAttributeValidator(attr);
|
|
97
|
+
shape[attr.name] = withEmptyToNull(validator);
|
|
98
|
+
}
|
|
99
|
+
return z.object(shape).passthrough();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/validation/object/helpers.ts
|
|
103
|
+
function validateAttribute(attr, value) {
|
|
104
|
+
const validator = createAttributeValidator(attr);
|
|
105
|
+
if (!attr.required && (value === void 0 || value === null)) {
|
|
106
|
+
return { success: true, data: { [attr.name]: value } };
|
|
107
|
+
}
|
|
108
|
+
const result = validator.safeParse(value);
|
|
109
|
+
if (result.success) {
|
|
110
|
+
return {
|
|
111
|
+
success: true,
|
|
112
|
+
data: { [attr.name]: result.data }
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
success: false,
|
|
117
|
+
errors: formatZodErrors(result.error).map((err) => ({
|
|
118
|
+
path: [attr.name, ...err.path],
|
|
119
|
+
message: err.message
|
|
120
|
+
}))
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function validateObject(objectDef, data) {
|
|
124
|
+
const validator = createObjectValidator(objectDef);
|
|
125
|
+
const result = validator.safeParse(data);
|
|
126
|
+
if (result.success) {
|
|
127
|
+
return {
|
|
128
|
+
success: true,
|
|
129
|
+
data: result.data
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
success: false,
|
|
134
|
+
errors: formatZodErrors(result.error)
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function validateObjectOrThrow(objectDef, data) {
|
|
138
|
+
const result = validateObject(objectDef, data);
|
|
139
|
+
if (!result.success) {
|
|
140
|
+
const errorMessages = result.errors?.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
|
|
141
|
+
throw new Error(`Validation failed for ${objectDef.label}:
|
|
142
|
+
${errorMessages}`);
|
|
143
|
+
}
|
|
144
|
+
return result.data;
|
|
145
|
+
}
|
|
146
|
+
function validateDraft(objectDef, data) {
|
|
147
|
+
const validator = createDraftValidator(objectDef);
|
|
148
|
+
const result = validator.safeParse(data);
|
|
149
|
+
if (result.success) {
|
|
150
|
+
return {
|
|
151
|
+
success: true,
|
|
152
|
+
data: result.data
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
success: false,
|
|
157
|
+
errors: formatZodErrors(result.error)
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function validateDraftOrThrow(objectDef, data) {
|
|
161
|
+
const result = validateDraft(objectDef, data);
|
|
162
|
+
if (!result.success) {
|
|
163
|
+
const errorMessages = result.errors?.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
|
|
164
|
+
throw new Error(`Draft validation failed for ${objectDef.label}:
|
|
165
|
+
${errorMessages}`);
|
|
166
|
+
}
|
|
167
|
+
return result.data;
|
|
168
|
+
}
|
|
169
|
+
function isValuePresent(value) {
|
|
170
|
+
if (value === void 0 || value === null) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
if (typeof value === "string" && value.trim() === "") {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
function getMissingRequiredAttributes(objectDef, data) {
|
|
179
|
+
const missing = [];
|
|
180
|
+
for (const attr of objectDef.attributes) {
|
|
181
|
+
if (attr.required && !isValuePresent(data[attr.name])) {
|
|
182
|
+
missing.push(attr);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return missing;
|
|
186
|
+
}
|
|
187
|
+
function isRecordComplete(objectDef, data) {
|
|
188
|
+
const missing = getMissingRequiredAttributes(objectDef, data);
|
|
189
|
+
if (missing.length > 0) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
const validation = validateObject(objectDef, data);
|
|
193
|
+
return validation.success;
|
|
194
|
+
}
|
|
195
|
+
function computeRecordStatus(objectDef, data) {
|
|
196
|
+
return isRecordComplete(objectDef, data) ? "complete" : "draft";
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export { computeRecordStatus, createAttributeValidator, createDraftValidator, createFormAttributeValidator, createObjectValidator, getMissingRequiredAttributes, isRecordComplete, validateAttribute, validateDraft, validateDraftOrThrow, validateObject, validateObjectOrThrow };
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { formatZodErrors } from './chunk-RDXQ4CYT.mjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
var baseConfigSchema = z.object({
|
|
5
|
+
disabled: z.boolean().optional(),
|
|
6
|
+
placeholder: z.string().optional(),
|
|
7
|
+
description: z.string().optional(),
|
|
8
|
+
defaultValue: z.unknown().optional(),
|
|
9
|
+
icon: z.string().optional(),
|
|
10
|
+
order: z.number().int().optional(),
|
|
11
|
+
hidden: z.boolean().optional(),
|
|
12
|
+
archived: z.boolean().optional(),
|
|
13
|
+
deprecated: z.boolean().optional(),
|
|
14
|
+
metadata: z.record(z.string(), z.unknown()).optional()
|
|
15
|
+
});
|
|
16
|
+
var optionSchema = z.object({
|
|
17
|
+
id: z.string().min(1),
|
|
18
|
+
label: z.string().min(1),
|
|
19
|
+
value: z.string().min(1),
|
|
20
|
+
color: z.string().optional(),
|
|
21
|
+
icon: z.string().optional(),
|
|
22
|
+
description: z.string().optional(),
|
|
23
|
+
group: z.enum(["idle", "in_progress", "finished"]).optional(),
|
|
24
|
+
inverse: z.string().optional()
|
|
25
|
+
});
|
|
26
|
+
var optionsArraySchema = z.array(optionSchema).min(1).refine(
|
|
27
|
+
(options) => {
|
|
28
|
+
const values = options.map((o) => o.value);
|
|
29
|
+
return new Set(values).size === values.length;
|
|
30
|
+
},
|
|
31
|
+
{ message: "Duplicate option values are not allowed" }
|
|
32
|
+
);
|
|
33
|
+
var relationTargetSchema = z.object({
|
|
34
|
+
object: z.string().min(1),
|
|
35
|
+
displayTemplate: z.string().optional(),
|
|
36
|
+
filter: z.record(z.string(), z.unknown()).optional()
|
|
37
|
+
});
|
|
38
|
+
var textConfigSchema = baseConfigSchema.extend({
|
|
39
|
+
minLength: z.number().int().min(0).optional(),
|
|
40
|
+
maxLength: z.number().int().min(1).optional(),
|
|
41
|
+
pattern: z.string().optional()
|
|
42
|
+
});
|
|
43
|
+
var textareaConfigSchema = baseConfigSchema;
|
|
44
|
+
var richtextConfigSchema = baseConfigSchema.extend({
|
|
45
|
+
features: z.array(
|
|
46
|
+
z.enum(["headings", "bold", "italic", "lists", "links", "images", "codeBlocks", "tables"])
|
|
47
|
+
).optional()
|
|
48
|
+
});
|
|
49
|
+
var numberConfigSchema = baseConfigSchema.extend({
|
|
50
|
+
min: z.number().optional(),
|
|
51
|
+
max: z.number().optional(),
|
|
52
|
+
unit: z.enum(["integer", "decimal", "percentage"]).optional(),
|
|
53
|
+
decimals: z.number().int().min(0).optional()
|
|
54
|
+
});
|
|
55
|
+
var checkboxConfigSchema = baseConfigSchema;
|
|
56
|
+
var dateConfigSchema = baseConfigSchema.extend({
|
|
57
|
+
dateFormat: z.enum(["short", "long", "full", "relative"]).optional(),
|
|
58
|
+
minDate: z.string().optional(),
|
|
59
|
+
maxDate: z.string().optional()
|
|
60
|
+
});
|
|
61
|
+
var phoneConfigSchema = baseConfigSchema.extend({
|
|
62
|
+
defaultCountryCode: z.string().length(3).optional()
|
|
63
|
+
});
|
|
64
|
+
var currencyConfigSchema = baseConfigSchema.extend({
|
|
65
|
+
defaultCurrency: z.string().length(3).optional(),
|
|
66
|
+
allowedCurrencies: z.array(z.string().length(3)).optional()
|
|
67
|
+
});
|
|
68
|
+
var statusConfigSchema = baseConfigSchema.extend({
|
|
69
|
+
options: optionsArraySchema
|
|
70
|
+
});
|
|
71
|
+
var locationConfigSchema = baseConfigSchema.extend({
|
|
72
|
+
granularity: z.enum(["full", "address", "city", "state", "country", "coordinates"]),
|
|
73
|
+
enableAutocomplete: z.boolean().optional(),
|
|
74
|
+
enableMap: z.boolean().optional(),
|
|
75
|
+
defaultCountry: z.string().length(3).optional(),
|
|
76
|
+
allowedCountries: z.array(z.string().length(3)).optional(),
|
|
77
|
+
displayFormat: z.enum(["single_line", "multi_line", "compact"]).optional()
|
|
78
|
+
});
|
|
79
|
+
var selectConfigSchema = baseConfigSchema.extend({
|
|
80
|
+
options: optionsArraySchema
|
|
81
|
+
});
|
|
82
|
+
var multiselectConfigSchema = baseConfigSchema.extend({
|
|
83
|
+
options: optionsArraySchema
|
|
84
|
+
});
|
|
85
|
+
var fileConfigSchema = baseConfigSchema.extend({
|
|
86
|
+
maxFiles: z.number().int().min(1).optional(),
|
|
87
|
+
maxSize: z.number().int().min(1).optional(),
|
|
88
|
+
allowedTypes: z.array(z.string()).optional(),
|
|
89
|
+
multiple: z.boolean().optional()
|
|
90
|
+
});
|
|
91
|
+
var userConfigSchema = baseConfigSchema.extend({
|
|
92
|
+
allowedRoles: z.array(z.string()).optional(),
|
|
93
|
+
multiple: z.boolean().optional()
|
|
94
|
+
});
|
|
95
|
+
var relationConfigSchema = baseConfigSchema.extend({
|
|
96
|
+
targets: z.array(relationTargetSchema).min(1),
|
|
97
|
+
cardinality: z.enum(["one", "many"]),
|
|
98
|
+
minItems: z.number().int().min(0).optional(),
|
|
99
|
+
maxItems: z.number().int().min(1).optional()
|
|
100
|
+
});
|
|
101
|
+
var ratingConfigSchema = baseConfigSchema.extend({
|
|
102
|
+
max: z.number().int().min(1).optional(),
|
|
103
|
+
iconType: z.enum(["star", "heart", "thumbs", "number"]).optional()
|
|
104
|
+
});
|
|
105
|
+
var formulaConfigSchema = baseConfigSchema.extend({
|
|
106
|
+
expression: z.string().min(1),
|
|
107
|
+
returnType: z.enum(["text", "number", "boolean", "date"]),
|
|
108
|
+
decimals: z.number().int().min(0).max(10).optional(),
|
|
109
|
+
allowRelations: z.boolean().optional()
|
|
110
|
+
});
|
|
111
|
+
var rollupConfigSchema = baseConfigSchema.extend({
|
|
112
|
+
relationAttribute: z.string().min(1).optional(),
|
|
113
|
+
relationPath: z.string().optional(),
|
|
114
|
+
targetAttribute: z.string().min(1),
|
|
115
|
+
function: z.enum([
|
|
116
|
+
"sum",
|
|
117
|
+
"avg",
|
|
118
|
+
"earliest",
|
|
119
|
+
"latest",
|
|
120
|
+
"count",
|
|
121
|
+
"countValues",
|
|
122
|
+
"countUniqueValues",
|
|
123
|
+
"countEmpty",
|
|
124
|
+
"percentEmpty",
|
|
125
|
+
"percentNotEmpty",
|
|
126
|
+
"original"
|
|
127
|
+
]),
|
|
128
|
+
decimals: z.number().int().min(0).max(10).optional(),
|
|
129
|
+
targetAttributeType: z.string().optional(),
|
|
130
|
+
targetAttributeOptions: z.array(
|
|
131
|
+
z.object({
|
|
132
|
+
id: z.string(),
|
|
133
|
+
label: z.string(),
|
|
134
|
+
value: z.string(),
|
|
135
|
+
color: z.string().optional(),
|
|
136
|
+
icon: z.string().optional(),
|
|
137
|
+
description: z.string().optional(),
|
|
138
|
+
group: z.enum(["idle", "in_progress", "finished"]).optional()
|
|
139
|
+
})
|
|
140
|
+
).optional()
|
|
141
|
+
});
|
|
142
|
+
var documentConfigSchema = baseConfigSchema.extend({
|
|
143
|
+
multiple: z.boolean().optional(),
|
|
144
|
+
maxDocuments: z.number().int().min(1).optional(),
|
|
145
|
+
autoProcess: z.boolean().optional()
|
|
146
|
+
});
|
|
147
|
+
var attributeConfigSchemas = {
|
|
148
|
+
text: textConfigSchema,
|
|
149
|
+
textarea: textareaConfigSchema,
|
|
150
|
+
richtext: richtextConfigSchema,
|
|
151
|
+
number: numberConfigSchema,
|
|
152
|
+
checkbox: checkboxConfigSchema,
|
|
153
|
+
date: dateConfigSchema,
|
|
154
|
+
phone: phoneConfigSchema,
|
|
155
|
+
currency: currencyConfigSchema,
|
|
156
|
+
status: statusConfigSchema,
|
|
157
|
+
location: locationConfigSchema,
|
|
158
|
+
select: selectConfigSchema,
|
|
159
|
+
multiselect: multiselectConfigSchema,
|
|
160
|
+
file: fileConfigSchema,
|
|
161
|
+
user: userConfigSchema,
|
|
162
|
+
relation: relationConfigSchema,
|
|
163
|
+
rating: ratingConfigSchema,
|
|
164
|
+
formula: formulaConfigSchema,
|
|
165
|
+
rollup: rollupConfigSchema,
|
|
166
|
+
document: documentConfigSchema
|
|
167
|
+
};
|
|
168
|
+
function getAttributeConfigSchema(type) {
|
|
169
|
+
return attributeConfigSchemas[type];
|
|
170
|
+
}
|
|
171
|
+
function validateAttributeConfig(type, config) {
|
|
172
|
+
const schema = getAttributeConfigSchema(type);
|
|
173
|
+
const result = schema.safeParse(config);
|
|
174
|
+
if (result.success) {
|
|
175
|
+
return { success: true, data: result.data };
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
success: false,
|
|
179
|
+
errors: formatZodErrors(result.error).map((err) => `${err.path.join(".")}: ${err.message}`)
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function parseAttributeConfig(type, config) {
|
|
183
|
+
const schema = getAttributeConfigSchema(type);
|
|
184
|
+
return schema.strip().parse(config);
|
|
185
|
+
}
|
|
186
|
+
function safeParseAttributeConfig(type, config) {
|
|
187
|
+
const schema = getAttributeConfigSchema(type);
|
|
188
|
+
const result = schema.strip().safeParse(config);
|
|
189
|
+
return result.success ? result.data : void 0;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export { attributeConfigSchemas, checkboxConfigSchema, currencyConfigSchema, dateConfigSchema, documentConfigSchema, fileConfigSchema, formulaConfigSchema, getAttributeConfigSchema, locationConfigSchema, multiselectConfigSchema, numberConfigSchema, parseAttributeConfig, phoneConfigSchema, ratingConfigSchema, relationConfigSchema, richtextConfigSchema, rollupConfigSchema, safeParseAttributeConfig, selectConfigSchema, statusConfigSchema, textConfigSchema, textareaConfigSchema, userConfigSchema, validateAttributeConfig };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk5SQEKHPW_js = require('./chunk-5SQEKHPW.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createCurrencyValidator(attr, messages = chunk5SQEKHPW_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
return zod.z.object(
|
|
8
|
+
{
|
|
9
|
+
code: zod.z.string().length(3),
|
|
10
|
+
value: zod.z.number().min(0)
|
|
11
|
+
},
|
|
12
|
+
{ message: messages.invalidCurrency(attr) }
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.createCurrencyValidator = createCurrencyValidator;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-JEDANRCG.mjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
function createLocationValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
5
|
+
return z.object(
|
|
6
|
+
{
|
|
7
|
+
address: z.string().optional(),
|
|
8
|
+
address2: z.string().optional(),
|
|
9
|
+
city: z.string().optional(),
|
|
10
|
+
state: z.string().optional(),
|
|
11
|
+
postalCode: z.string().optional(),
|
|
12
|
+
country: z.string().length(3).optional(),
|
|
13
|
+
latitude: z.number().optional(),
|
|
14
|
+
longitude: z.number().optional()
|
|
15
|
+
},
|
|
16
|
+
{ message: messages.invalidLocation(attr) }
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { createLocationValidator };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk5SQEKHPW_js = require('./chunk-5SQEKHPW.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createRatingValidator(attr, messages = chunk5SQEKHPW_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
let schema = zod.z.number().min(0);
|
|
8
|
+
if (attr.max !== void 0) {
|
|
9
|
+
schema = schema.max(attr.max, messages.maxValue(attr, attr.max));
|
|
10
|
+
}
|
|
11
|
+
return schema;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.createRatingValidator = createRatingValidator;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk5SQEKHPW_js = require('./chunk-5SQEKHPW.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createFormulaValidator(_attr, _messages = chunk5SQEKHPW_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
return zod.z.unknown();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.createFormulaValidator = createFormulaValidator;
|
|
@@ -29,13 +29,24 @@ function generateTemplateName(label) {
|
|
|
29
29
|
function indexBy(items, keyFn) {
|
|
30
30
|
return new Map(items.map((item) => [keyFn(item), item]));
|
|
31
31
|
}
|
|
32
|
+
function deepEqual(a, b) {
|
|
33
|
+
if (a === b) return true;
|
|
34
|
+
if (a == null || b == null) return false;
|
|
35
|
+
if (typeof a !== typeof b) return false;
|
|
36
|
+
if (Array.isArray(a)) {
|
|
37
|
+
if (!Array.isArray(b)) return false;
|
|
38
|
+
if (a.length !== b.length) return false;
|
|
39
|
+
return a.every((item, index) => deepEqual(item, b[index]));
|
|
40
|
+
}
|
|
41
|
+
if (typeof a === "object" && typeof b === "object") {
|
|
42
|
+
const aObj = a;
|
|
43
|
+
const bObj = b;
|
|
44
|
+
const aKeys = Object.keys(aObj);
|
|
45
|
+
const bKeys = Object.keys(bObj);
|
|
46
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
47
|
+
return aKeys.every((key) => key in bObj && deepEqual(aObj[key], bObj[key]));
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
32
51
|
|
|
33
|
-
export {
|
|
34
|
-
asTenantId,
|
|
35
|
-
asUserId,
|
|
36
|
-
generateId,
|
|
37
|
-
generatePrefixedId,
|
|
38
|
-
slugify,
|
|
39
|
-
generateTemplateName,
|
|
40
|
-
indexBy
|
|
41
|
-
};
|
|
52
|
+
export { asTenantId, asUserId, deepEqual, generateId, generatePrefixedId, generateTemplateName, indexBy, slugify };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-JEDANRCG.mjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
function extractRelationId(item) {
|
|
5
|
+
if (typeof item === "object" && item !== null && "id" in item) {
|
|
6
|
+
return item.id;
|
|
7
|
+
}
|
|
8
|
+
return item;
|
|
9
|
+
}
|
|
10
|
+
function createSingleRelationValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
11
|
+
const uuidSchema = z.uuid({
|
|
12
|
+
message: messages.invalidId(attr)
|
|
13
|
+
});
|
|
14
|
+
const nullableUuidSchema = z.union([uuidSchema, z.null()]);
|
|
15
|
+
return z.union([
|
|
16
|
+
nullableUuidSchema,
|
|
17
|
+
z.object({
|
|
18
|
+
id: uuidSchema,
|
|
19
|
+
props: z.record(z.string(), z.unknown()).optional()
|
|
20
|
+
}).passthrough()
|
|
21
|
+
// Allow additional properties (bilateral relations may have extra metadata)
|
|
22
|
+
]);
|
|
23
|
+
}
|
|
24
|
+
function createMultiRelationValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
25
|
+
const uuidSchema = z.uuid({
|
|
26
|
+
message: messages.invalidId(attr)
|
|
27
|
+
});
|
|
28
|
+
const itemSchema = z.union([
|
|
29
|
+
uuidSchema,
|
|
30
|
+
z.object({
|
|
31
|
+
id: uuidSchema,
|
|
32
|
+
props: z.record(z.string(), z.unknown()).optional()
|
|
33
|
+
}).passthrough()
|
|
34
|
+
// Allow additional properties
|
|
35
|
+
]);
|
|
36
|
+
let arraySchema = z.array(itemSchema);
|
|
37
|
+
if (attr.minItems !== void 0) {
|
|
38
|
+
arraySchema = arraySchema.min(attr.minItems, messages.minItems(attr, attr.minItems));
|
|
39
|
+
}
|
|
40
|
+
if (attr.maxItems !== void 0) {
|
|
41
|
+
arraySchema = arraySchema.max(attr.maxItems, messages.maxItems(attr, attr.maxItems));
|
|
42
|
+
}
|
|
43
|
+
return arraySchema.refine(
|
|
44
|
+
(items) => {
|
|
45
|
+
return items.every((item) => {
|
|
46
|
+
const id = extractRelationId(item);
|
|
47
|
+
return typeof id === "string" && uuidSchema.safeParse(id).success;
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
{ message: messages.invalidId(attr) }
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
function createRelationValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
54
|
+
if (attr.cardinality === "many") {
|
|
55
|
+
return createMultiRelationValidator(attr, messages);
|
|
56
|
+
}
|
|
57
|
+
return createSingleRelationValidator(attr, messages);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { createMultiRelationValidator, createRelationValidator, createSingleRelationValidator };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-JEDANRCG.mjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
function createSelectValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
5
|
+
const validValues = attr.options.map((opt) => opt.value);
|
|
6
|
+
const validLabels = attr.options.map((opt) => opt.label);
|
|
7
|
+
return z.enum(validValues, {
|
|
8
|
+
message: messages.invalidOption(attr, validLabels)
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
function createMultiselectValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
12
|
+
const validValues = attr.options.map((opt) => opt.value);
|
|
13
|
+
const validLabels = attr.options.map((opt) => opt.label);
|
|
14
|
+
return z.array(
|
|
15
|
+
z.enum(validValues, {
|
|
16
|
+
message: messages.invalidOption(attr, validLabels)
|
|
17
|
+
})
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
function createStatusValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
21
|
+
const validValues = attr.options.map((opt) => opt.value);
|
|
22
|
+
const validLabels = attr.options.map((opt) => opt.label);
|
|
23
|
+
return z.enum(validValues, {
|
|
24
|
+
message: messages.invalidOption(attr, validLabels)
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { createMultiselectValidator, createSelectValidator, createStatusValidator };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk5SQEKHPW_js = require('./chunk-5SQEKHPW.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
var textRegexCache = chunk5SQEKHPW_js.createRegexCache();
|
|
7
|
+
function createTextValidator(attr, messages = chunk5SQEKHPW_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
8
|
+
let schema = zod.z.string();
|
|
9
|
+
if (attr.minLength !== void 0) {
|
|
10
|
+
schema = schema.min(attr.minLength, messages.minLength(attr, attr.minLength));
|
|
11
|
+
}
|
|
12
|
+
if (attr.maxLength !== void 0) {
|
|
13
|
+
schema = schema.max(attr.maxLength, messages.maxLength(attr, attr.maxLength));
|
|
14
|
+
}
|
|
15
|
+
if (attr.pattern) {
|
|
16
|
+
schema = schema.regex(
|
|
17
|
+
chunk5SQEKHPW_js.getCachedRegex(textRegexCache, attr.pattern),
|
|
18
|
+
messages.invalidPattern(attr)
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
return schema;
|
|
22
|
+
}
|
|
23
|
+
function createTextAreaValidator(_attr, _messages = chunk5SQEKHPW_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
24
|
+
return zod.z.string();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.createTextAreaValidator = createTextAreaValidator;
|
|
28
|
+
exports.createTextValidator = createTextValidator;
|