@stndrds/schema 0.1.0-alpha.67 → 1.0.0-alpha.102
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-D7yQuTJK.d.mts +665 -0
- package/dist/attributes-DcbQC-4b.d.ts +665 -0
- package/dist/chunk-3JINFUN3.js +81 -0
- package/dist/chunk-4KRLCWJM.mjs +8 -0
- package/dist/chunk-4TC27SMF.mjs +18 -0
- package/dist/chunk-56QI6UTK.js +32 -0
- package/dist/chunk-5JVVPJJW.mjs +208 -0
- package/dist/chunk-5XL3JP73.mjs +83 -0
- package/dist/chunk-7HFZ7MVR.mjs +28 -0
- package/dist/chunk-ACQ3TUFK.js +10 -0
- package/dist/chunk-AYCSVKI2.mjs +14 -0
- package/dist/chunk-BLXQGQLK.mjs +10 -0
- package/dist/chunk-D7WFIGXW.js +14 -0
- package/dist/chunk-FRCDMQER.js +47 -0
- package/dist/chunk-GCRHSPZN.js +16 -0
- package/dist/chunk-IRTRJH37.mjs +8 -0
- package/dist/chunk-ITTQ4FGR.mjs +14 -0
- package/dist/chunk-J5HRK3WD.js +10 -0
- package/dist/chunk-KNYZH2WD.mjs +18 -0
- package/dist/chunk-KWVCGQ7N.mjs +78 -0
- package/dist/chunk-MAKSIK3P.js +10 -0
- package/dist/chunk-N7T66JVY.js +86 -0
- package/dist/chunk-OAQWRMTP.js +10 -0
- package/dist/chunk-OLJLCVNY.mjs +8 -0
- package/dist/chunk-P2BE2A2G.js +64 -0
- package/dist/chunk-PGERPYDR.js +2 -0
- package/dist/chunk-QWZHR2OO.js +12 -0
- package/dist/chunk-QY6QFRRV.mjs +41 -0
- package/dist/chunk-QYNPB37W.js +221 -0
- package/dist/chunk-R4CJHCC4.mjs +60 -0
- package/dist/chunk-RJ4LOX7P.js +22 -0
- package/dist/chunk-ROAZLZA2.js +20 -0
- package/dist/chunk-RUYUFXNW.mjs +12 -0
- package/dist/chunk-SP3PNHYF.mjs +1 -0
- package/dist/chunk-SS2NR6DH.mjs +176 -0
- package/dist/chunk-T225DB55.js +33 -0
- package/dist/chunk-TKN73433.js +20 -0
- package/dist/chunk-TMYBEXBT.mjs +8 -0
- package/dist/chunk-UQVW4KPP.mjs +30 -0
- package/dist/chunk-V6DE3MXC.js +180 -0
- package/dist/chunk-VXOTYFEW.js +16 -0
- package/dist/chunk-WV4V64D5.mjs +20 -0
- package/dist/helpers-DD6JzYfI.d.mts +860 -0
- package/dist/helpers-kMS5R7KX.d.ts +860 -0
- package/dist/index.d.mts +3597 -1768
- package/dist/index.d.ts +3597 -1768
- package/dist/index.js +4957 -1955
- package/dist/index.mjs +3920 -1116
- package/dist/types-BAPgWlpX.d.mts +39 -0
- package/dist/types-mZPUEZl0.d.ts +39 -0
- package/dist/utils.d.mts +20 -55
- package/dist/utils.d.ts +20 -55
- package/dist/utils.js +26 -19
- package/dist/utils.mjs +1 -19
- package/dist/validation/all.d.mts +8 -0
- package/dist/validation/all.d.ts +8 -0
- package/dist/validation/all.js +56 -0
- package/dist/validation/all.mjs +19 -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 +11 -0
- package/dist/validation/complex/currency.mjs +2 -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 +11 -0
- package/dist/validation/complex/file.mjs +2 -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 +11 -0
- package/dist/validation/complex/location.mjs +2 -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 +11 -0
- package/dist/validation/complex/phone.mjs +2 -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 +19 -0
- package/dist/validation/complex/relation.mjs +2 -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 +11 -0
- package/dist/validation/complex/richtext.mjs +2 -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 +19 -0
- package/dist/validation/complex/select.mjs +2 -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 +11 -0
- package/dist/validation/complex/user.mjs +2 -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 +11 -0
- package/dist/validation/computed/formula.mjs +2 -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 +11 -0
- package/dist/validation/computed/rollup.mjs +2 -0
- package/dist/validation/config/index.d.mts +20 -0
- package/dist/validation/config/index.d.ts +20 -0
- package/dist/validation/config/index.js +18 -0
- package/dist/validation/config/index.mjs +1 -0
- package/dist/validation/core/index.d.mts +19 -0
- package/dist/validation/core/index.d.ts +19 -0
- package/dist/validation/core/index.js +14 -0
- package/dist/validation/core/index.mjs +1 -0
- package/dist/validation/object/index.d.mts +31 -0
- package/dist/validation/object/index.d.ts +31 -0
- package/dist/validation/object/index.js +70 -0
- package/dist/validation/object/index.mjs +17 -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 +11 -0
- package/dist/validation/primitives/checkbox.mjs +2 -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 +11 -0
- package/dist/validation/primitives/date.mjs +2 -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 +11 -0
- package/dist/validation/primitives/number.mjs +2 -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 +11 -0
- package/dist/validation/primitives/rating.mjs +2 -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 +15 -0
- package/dist/validation/primitives/text.mjs +2 -0
- package/package.json +108 -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-V2RPPE2Y.mjs +0 -41
- 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/validation/validators.d.mts +0 -4
- package/dist/validation/validators.d.ts +0 -4
- package/dist/validation/validators.js +0 -121
- package/dist/validation/validators.mjs +0 -121
- package/dist/validators-BROsLGn4.d.mts +0 -1556
- package/dist/validators-CEzdvxEq.d.ts +0 -1556
package/dist/chunk-NEVERCM3.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils.ts
|
|
2
|
-
function asTenantId(id) {
|
|
3
|
-
return id;
|
|
4
|
-
}
|
|
5
|
-
function asUserId(id) {
|
|
6
|
-
return id;
|
|
7
|
-
}
|
|
8
|
-
function generateId() {
|
|
9
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
10
|
-
return crypto.randomUUID();
|
|
11
|
-
}
|
|
12
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
13
|
-
const r = Math.random() * 16 | 0;
|
|
14
|
-
const v = c === "x" ? r : r & 3 | 8;
|
|
15
|
-
return v.toString(16);
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
function generatePrefixedId(prefix) {
|
|
19
|
-
return `${prefix}_${generateId()}`;
|
|
20
|
-
}
|
|
21
|
-
function slugify(input) {
|
|
22
|
-
return input.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().replace(/[^a-z0-9\s_-]/g, "").trim().replace(/\s+/g, "-").replace(/-+/g, "-");
|
|
23
|
-
}
|
|
24
|
-
function generateTemplateName(label) {
|
|
25
|
-
const slug = slugify(label) || "template";
|
|
26
|
-
const suffix = generateId().slice(0, 8);
|
|
27
|
-
return `${slug}-${suffix}`;
|
|
28
|
-
}
|
|
29
|
-
function indexBy(items, keyFn) {
|
|
30
|
-
return new Map(items.map((item) => [keyFn(item), item]));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
exports.asTenantId = asTenantId; exports.asUserId = asUserId; exports.generateId = generateId; exports.generatePrefixedId = generatePrefixedId; exports.slugify = slugify; exports.generateTemplateName = generateTemplateName; exports.indexBy = indexBy;
|
package/dist/chunk-SV4BCGQU.mjs
DELETED
|
@@ -1,617 +0,0 @@
|
|
|
1
|
-
// src/validation/validators.ts
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
var regexPatternCache = /* @__PURE__ */ new Map();
|
|
4
|
-
function getCachedRegex(pattern) {
|
|
5
|
-
let cached = regexPatternCache.get(pattern);
|
|
6
|
-
if (!cached) {
|
|
7
|
-
cached = new RegExp(pattern);
|
|
8
|
-
regexPatternCache.set(pattern, cached);
|
|
9
|
-
}
|
|
10
|
-
return cached;
|
|
11
|
-
}
|
|
12
|
-
function formatZodErrors(error) {
|
|
13
|
-
return error.issues.map((err) => ({
|
|
14
|
-
path: err.path.map(String),
|
|
15
|
-
message: err.message
|
|
16
|
-
}));
|
|
17
|
-
}
|
|
18
|
-
var DEFAULT_VALIDATION_MESSAGES = {
|
|
19
|
-
required: (attr) => `${attr.label} is required`,
|
|
20
|
-
invalidType: (attr, expected) => `${attr.label} must be a ${expected}`,
|
|
21
|
-
minLength: (attr, min) => `${attr.label} must be at least ${min} characters`,
|
|
22
|
-
maxLength: (attr, max) => `${attr.label} must be at most ${max} characters`,
|
|
23
|
-
invalidPattern: (attr) => `${attr.label} format is invalid`,
|
|
24
|
-
minValue: (attr, min) => `${attr.label} must be at least ${min}`,
|
|
25
|
-
maxValue: (attr, max) => `${attr.label} must be at most ${max}`,
|
|
26
|
-
mustBeInteger: (attr) => `${attr.label} must be an integer`,
|
|
27
|
-
invalidDate: (attr) => `${attr.label} must be a valid date`,
|
|
28
|
-
invalidOption: (attr, options) => `${attr.label} must be one of: ${options.join(", ")}`,
|
|
29
|
-
invalidId: (attr) => `${attr.label} must be a valid ID`,
|
|
30
|
-
minItems: (attr, min) => `${attr.label} must have at least ${min} item${min > 1 ? "s" : ""}`,
|
|
31
|
-
maxItems: (attr, max) => `${attr.label} must have at most ${max} item${max > 1 ? "s" : ""}`,
|
|
32
|
-
invalidRichtext: (attr) => `${attr.label} must be valid rich text content`,
|
|
33
|
-
invalidPhone: (attr) => `${attr.label} must be a valid phone number`,
|
|
34
|
-
invalidCurrency: (attr) => `${attr.label} must be a valid currency value`,
|
|
35
|
-
invalidLocation: (attr) => `${attr.label} must be a valid location`
|
|
36
|
-
};
|
|
37
|
-
var baseConfigSchema = z.object({
|
|
38
|
-
disabled: z.boolean().optional(),
|
|
39
|
-
placeholder: z.string().optional(),
|
|
40
|
-
description: z.string().optional(),
|
|
41
|
-
defaultValue: z.unknown().optional(),
|
|
42
|
-
icon: z.string().optional(),
|
|
43
|
-
order: z.number().int().optional(),
|
|
44
|
-
hidden: z.boolean().optional(),
|
|
45
|
-
archived: z.boolean().optional(),
|
|
46
|
-
deprecated: z.boolean().optional(),
|
|
47
|
-
metadata: z.record(z.string(), z.unknown()).optional()
|
|
48
|
-
});
|
|
49
|
-
var optionSchema = z.object({
|
|
50
|
-
id: z.string().min(1),
|
|
51
|
-
label: z.string().min(1),
|
|
52
|
-
value: z.string().min(1),
|
|
53
|
-
color: z.string().optional(),
|
|
54
|
-
icon: z.string().optional(),
|
|
55
|
-
description: z.string().optional(),
|
|
56
|
-
group: z.enum(["idle", "in_progress", "finished"]).optional()
|
|
57
|
-
});
|
|
58
|
-
var optionsArraySchema = z.array(optionSchema).min(1).refine(
|
|
59
|
-
(options) => {
|
|
60
|
-
const values = options.map((o) => o.value);
|
|
61
|
-
return new Set(values).size === values.length;
|
|
62
|
-
},
|
|
63
|
-
{ message: "Duplicate option values are not allowed" }
|
|
64
|
-
);
|
|
65
|
-
var relationTargetSchema = z.object({
|
|
66
|
-
object: z.string().min(1),
|
|
67
|
-
displayTemplate: z.string().optional(),
|
|
68
|
-
filter: z.record(z.string(), z.unknown()).optional()
|
|
69
|
-
});
|
|
70
|
-
var textConfigSchema = baseConfigSchema.extend({
|
|
71
|
-
minLength: z.number().int().min(0).optional(),
|
|
72
|
-
maxLength: z.number().int().min(1).optional(),
|
|
73
|
-
pattern: z.string().optional()
|
|
74
|
-
});
|
|
75
|
-
var textareaConfigSchema = baseConfigSchema;
|
|
76
|
-
var richtextConfigSchema = baseConfigSchema.extend({
|
|
77
|
-
features: z.array(
|
|
78
|
-
z.enum(["headings", "bold", "italic", "lists", "links", "images", "codeBlocks", "tables"])
|
|
79
|
-
).optional()
|
|
80
|
-
});
|
|
81
|
-
var numberConfigSchema = baseConfigSchema.extend({
|
|
82
|
-
min: z.number().optional(),
|
|
83
|
-
max: z.number().optional(),
|
|
84
|
-
unit: z.enum(["integer", "decimal", "percentage"]).optional(),
|
|
85
|
-
decimals: z.number().int().min(0).optional()
|
|
86
|
-
});
|
|
87
|
-
var checkboxConfigSchema = baseConfigSchema;
|
|
88
|
-
var dateConfigSchema = baseConfigSchema.extend({
|
|
89
|
-
dateFormat: z.enum(["short", "long", "full", "relative"]).optional(),
|
|
90
|
-
minDate: z.string().optional(),
|
|
91
|
-
maxDate: z.string().optional()
|
|
92
|
-
});
|
|
93
|
-
var phoneConfigSchema = baseConfigSchema.extend({
|
|
94
|
-
defaultCountryCode: z.string().length(3).optional()
|
|
95
|
-
});
|
|
96
|
-
var currencyConfigSchema = baseConfigSchema.extend({
|
|
97
|
-
defaultCurrency: z.string().length(3).optional(),
|
|
98
|
-
allowedCurrencies: z.array(z.string().length(3)).optional()
|
|
99
|
-
});
|
|
100
|
-
var statusConfigSchema = baseConfigSchema.extend({
|
|
101
|
-
options: optionsArraySchema
|
|
102
|
-
});
|
|
103
|
-
var locationConfigSchema = baseConfigSchema.extend({
|
|
104
|
-
granularity: z.enum(["full", "address", "city", "state", "country", "coordinates"]),
|
|
105
|
-
enableAutocomplete: z.boolean().optional(),
|
|
106
|
-
enableMap: z.boolean().optional(),
|
|
107
|
-
defaultCountry: z.string().length(3).optional(),
|
|
108
|
-
allowedCountries: z.array(z.string().length(3)).optional(),
|
|
109
|
-
displayFormat: z.enum(["single_line", "multi_line", "compact"]).optional()
|
|
110
|
-
});
|
|
111
|
-
var selectConfigSchema = baseConfigSchema.extend({
|
|
112
|
-
options: optionsArraySchema
|
|
113
|
-
});
|
|
114
|
-
var multiselectConfigSchema = baseConfigSchema.extend({
|
|
115
|
-
options: optionsArraySchema
|
|
116
|
-
});
|
|
117
|
-
var fileConfigSchema = baseConfigSchema.extend({
|
|
118
|
-
maxFiles: z.number().int().min(1).optional(),
|
|
119
|
-
maxSize: z.number().int().min(1).optional(),
|
|
120
|
-
allowedTypes: z.array(z.string()).optional(),
|
|
121
|
-
multiple: z.boolean().optional()
|
|
122
|
-
});
|
|
123
|
-
var userConfigSchema = baseConfigSchema.extend({
|
|
124
|
-
allowedRoles: z.array(z.string()).optional(),
|
|
125
|
-
multiple: z.boolean().optional()
|
|
126
|
-
});
|
|
127
|
-
var relationConfigSchema = baseConfigSchema.extend({
|
|
128
|
-
targets: z.array(relationTargetSchema).min(1),
|
|
129
|
-
cardinality: z.enum(["one", "many"]),
|
|
130
|
-
minItems: z.number().int().min(0).optional(),
|
|
131
|
-
maxItems: z.number().int().min(1).optional()
|
|
132
|
-
});
|
|
133
|
-
var ratingConfigSchema = baseConfigSchema.extend({
|
|
134
|
-
max: z.number().int().min(1).optional(),
|
|
135
|
-
iconType: z.enum(["star", "heart", "thumbs", "number"]).optional()
|
|
136
|
-
});
|
|
137
|
-
var formulaConfigSchema = baseConfigSchema.extend({
|
|
138
|
-
expression: z.string().min(1),
|
|
139
|
-
returnType: z.enum(["text", "number", "boolean", "date"]),
|
|
140
|
-
decimals: z.number().int().min(0).max(10).optional(),
|
|
141
|
-
allowRelations: z.boolean().optional()
|
|
142
|
-
});
|
|
143
|
-
var rollupConfigSchema = baseConfigSchema.extend({
|
|
144
|
-
relationAttribute: z.string().min(1).optional(),
|
|
145
|
-
relationPath: z.string().optional(),
|
|
146
|
-
targetAttribute: z.string().min(1),
|
|
147
|
-
function: z.enum([
|
|
148
|
-
// Numeric aggregates
|
|
149
|
-
"sum",
|
|
150
|
-
"avg",
|
|
151
|
-
// Date aggregates
|
|
152
|
-
"earliest",
|
|
153
|
-
"latest",
|
|
154
|
-
// Count (universal)
|
|
155
|
-
"count",
|
|
156
|
-
"countValues",
|
|
157
|
-
"countUniqueValues",
|
|
158
|
-
"countEmpty",
|
|
159
|
-
// Percent (universal)
|
|
160
|
-
"percentEmpty",
|
|
161
|
-
"percentNotEmpty",
|
|
162
|
-
// Lookup (universal)
|
|
163
|
-
"original"
|
|
164
|
-
]),
|
|
165
|
-
decimals: z.number().int().min(0).max(10).optional(),
|
|
166
|
-
targetAttributeType: z.string().optional(),
|
|
167
|
-
targetAttributeOptions: z.array(
|
|
168
|
-
z.object({
|
|
169
|
-
id: z.string(),
|
|
170
|
-
label: z.string(),
|
|
171
|
-
value: z.string(),
|
|
172
|
-
color: z.string().optional(),
|
|
173
|
-
icon: z.string().optional(),
|
|
174
|
-
description: z.string().optional(),
|
|
175
|
-
group: z.enum(["idle", "in_progress", "finished"]).optional()
|
|
176
|
-
})
|
|
177
|
-
).optional()
|
|
178
|
-
});
|
|
179
|
-
var documentConfigSchema = baseConfigSchema.extend({
|
|
180
|
-
templateId: z.string().optional(),
|
|
181
|
-
allowedTemplates: z.array(z.string()).optional(),
|
|
182
|
-
multiple: z.boolean().optional(),
|
|
183
|
-
maxDocuments: z.number().int().min(1).optional(),
|
|
184
|
-
autoProcess: z.boolean().optional()
|
|
185
|
-
});
|
|
186
|
-
var attributeConfigSchemas = {
|
|
187
|
-
text: textConfigSchema,
|
|
188
|
-
textarea: textareaConfigSchema,
|
|
189
|
-
richtext: richtextConfigSchema,
|
|
190
|
-
number: numberConfigSchema,
|
|
191
|
-
checkbox: checkboxConfigSchema,
|
|
192
|
-
date: dateConfigSchema,
|
|
193
|
-
phone: phoneConfigSchema,
|
|
194
|
-
currency: currencyConfigSchema,
|
|
195
|
-
status: statusConfigSchema,
|
|
196
|
-
location: locationConfigSchema,
|
|
197
|
-
select: selectConfigSchema,
|
|
198
|
-
multiselect: multiselectConfigSchema,
|
|
199
|
-
file: fileConfigSchema,
|
|
200
|
-
user: userConfigSchema,
|
|
201
|
-
relation: relationConfigSchema,
|
|
202
|
-
rating: ratingConfigSchema,
|
|
203
|
-
formula: formulaConfigSchema,
|
|
204
|
-
rollup: rollupConfigSchema,
|
|
205
|
-
document: documentConfigSchema
|
|
206
|
-
};
|
|
207
|
-
function getAttributeConfigSchema(type) {
|
|
208
|
-
return attributeConfigSchemas[type];
|
|
209
|
-
}
|
|
210
|
-
function validateAttributeConfig(type, config) {
|
|
211
|
-
const schema = getAttributeConfigSchema(type);
|
|
212
|
-
const result = schema.safeParse(config);
|
|
213
|
-
if (result.success) {
|
|
214
|
-
return { success: true, data: result.data };
|
|
215
|
-
}
|
|
216
|
-
return {
|
|
217
|
-
success: false,
|
|
218
|
-
errors: formatZodErrors(result.error).map((err) => `${err.path.join(".")}: ${err.message}`)
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
function parseAttributeConfig(type, config) {
|
|
222
|
-
const schema = getAttributeConfigSchema(type);
|
|
223
|
-
return schema.strip().parse(config);
|
|
224
|
-
}
|
|
225
|
-
function safeParseAttributeConfig(type, config) {
|
|
226
|
-
const schema = getAttributeConfigSchema(type);
|
|
227
|
-
const result = schema.strip().safeParse(config);
|
|
228
|
-
return result.success ? result.data : void 0;
|
|
229
|
-
}
|
|
230
|
-
function createTextValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
231
|
-
let schema = z.string();
|
|
232
|
-
if (attr.minLength !== void 0) {
|
|
233
|
-
schema = schema.min(attr.minLength, messages.minLength(attr, attr.minLength));
|
|
234
|
-
}
|
|
235
|
-
if (attr.maxLength !== void 0) {
|
|
236
|
-
schema = schema.max(attr.maxLength, messages.maxLength(attr, attr.maxLength));
|
|
237
|
-
}
|
|
238
|
-
if (attr.pattern) {
|
|
239
|
-
schema = schema.regex(getCachedRegex(attr.pattern), messages.invalidPattern(attr));
|
|
240
|
-
}
|
|
241
|
-
return schema;
|
|
242
|
-
}
|
|
243
|
-
function createNumberValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
244
|
-
let schema = z.number();
|
|
245
|
-
if (attr.min !== void 0) {
|
|
246
|
-
schema = schema.min(attr.min, messages.minValue(attr, attr.min));
|
|
247
|
-
}
|
|
248
|
-
if (attr.max !== void 0) {
|
|
249
|
-
schema = schema.max(attr.max, messages.maxValue(attr, attr.max));
|
|
250
|
-
}
|
|
251
|
-
if (attr.unit === "integer") {
|
|
252
|
-
schema = schema.int(messages.mustBeInteger(attr));
|
|
253
|
-
}
|
|
254
|
-
return schema;
|
|
255
|
-
}
|
|
256
|
-
function createCheckboxValidator(_attr, _messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
257
|
-
return z.boolean();
|
|
258
|
-
}
|
|
259
|
-
function createDateValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
260
|
-
return z.coerce.date({ message: messages.invalidDate(attr) });
|
|
261
|
-
}
|
|
262
|
-
function createPhoneValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
263
|
-
return z.object(
|
|
264
|
-
{
|
|
265
|
-
countryCode: z.string().length(3),
|
|
266
|
-
phoneNumber: z.string().min(1)
|
|
267
|
-
},
|
|
268
|
-
{ message: messages.invalidPhone(attr) }
|
|
269
|
-
);
|
|
270
|
-
}
|
|
271
|
-
function createCurrencyValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
272
|
-
return z.object(
|
|
273
|
-
{
|
|
274
|
-
code: z.string().length(3),
|
|
275
|
-
value: z.number().min(0)
|
|
276
|
-
},
|
|
277
|
-
{ message: messages.invalidCurrency(attr) }
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
function createStatusValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
281
|
-
const validValues = attr.options.map((opt) => opt.value);
|
|
282
|
-
return z.enum(validValues, {
|
|
283
|
-
message: messages.invalidOption(attr, validValues)
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
function createSelectValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
287
|
-
const validValues = attr.options.map((opt) => opt.value);
|
|
288
|
-
return z.enum(validValues, {
|
|
289
|
-
message: messages.invalidOption(attr, validValues)
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
function createMultiselectValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
293
|
-
const validValues = attr.options.map((opt) => opt.value);
|
|
294
|
-
return z.array(
|
|
295
|
-
z.enum(validValues, {
|
|
296
|
-
message: messages.invalidOption(attr, validValues)
|
|
297
|
-
})
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
function createLocationValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
301
|
-
return z.object(
|
|
302
|
-
{
|
|
303
|
-
address: z.string().optional(),
|
|
304
|
-
address2: z.string().optional(),
|
|
305
|
-
city: z.string().optional(),
|
|
306
|
-
state: z.string().optional(),
|
|
307
|
-
postalCode: z.string().optional(),
|
|
308
|
-
country: z.string().length(3).optional(),
|
|
309
|
-
latitude: z.number().optional(),
|
|
310
|
-
longitude: z.number().optional()
|
|
311
|
-
},
|
|
312
|
-
{ message: messages.invalidLocation(attr) }
|
|
313
|
-
);
|
|
314
|
-
}
|
|
315
|
-
function createFileValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
316
|
-
const uuidSchema = z.uuid({
|
|
317
|
-
message: messages.invalidId(attr)
|
|
318
|
-
});
|
|
319
|
-
if (attr.multiple) {
|
|
320
|
-
let arraySchema = z.array(uuidSchema);
|
|
321
|
-
if (attr.maxFiles) {
|
|
322
|
-
arraySchema = arraySchema.max(attr.maxFiles, messages.maxItems(attr, attr.maxFiles));
|
|
323
|
-
}
|
|
324
|
-
return arraySchema;
|
|
325
|
-
}
|
|
326
|
-
return uuidSchema;
|
|
327
|
-
}
|
|
328
|
-
function createUserValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
329
|
-
const uuidSchema = z.uuid({
|
|
330
|
-
message: messages.invalidId(attr)
|
|
331
|
-
});
|
|
332
|
-
if (attr.multiple) {
|
|
333
|
-
return z.array(uuidSchema);
|
|
334
|
-
}
|
|
335
|
-
return uuidSchema;
|
|
336
|
-
}
|
|
337
|
-
function createSingleRelationValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
338
|
-
const uuidSchema = z.uuid({
|
|
339
|
-
message: messages.invalidId(attr)
|
|
340
|
-
});
|
|
341
|
-
return z.union([uuidSchema, z.null()]);
|
|
342
|
-
}
|
|
343
|
-
function createMultiRelationValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
344
|
-
const uuidSchema = z.uuid({
|
|
345
|
-
message: messages.invalidId(attr)
|
|
346
|
-
});
|
|
347
|
-
let arraySchema = z.array(uuidSchema);
|
|
348
|
-
if (attr.minItems !== void 0) {
|
|
349
|
-
arraySchema = arraySchema.min(attr.minItems, messages.minItems(attr, attr.minItems));
|
|
350
|
-
}
|
|
351
|
-
if (attr.maxItems !== void 0) {
|
|
352
|
-
arraySchema = arraySchema.max(attr.maxItems, messages.maxItems(attr, attr.maxItems));
|
|
353
|
-
}
|
|
354
|
-
return arraySchema;
|
|
355
|
-
}
|
|
356
|
-
function createRelationValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
357
|
-
if (attr.cardinality === "many") {
|
|
358
|
-
return createMultiRelationValidator(attr, messages);
|
|
359
|
-
}
|
|
360
|
-
return createSingleRelationValidator(attr, messages);
|
|
361
|
-
}
|
|
362
|
-
function createRatingValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
363
|
-
let schema = z.number().min(0);
|
|
364
|
-
if (attr.max !== void 0) {
|
|
365
|
-
schema = schema.max(attr.max, messages.maxValue(attr, attr.max));
|
|
366
|
-
}
|
|
367
|
-
return schema;
|
|
368
|
-
}
|
|
369
|
-
function createFormulaValidator(_attr, _messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
370
|
-
return z.unknown();
|
|
371
|
-
}
|
|
372
|
-
function createRollupValidator(_attr, _messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
373
|
-
return z.unknown();
|
|
374
|
-
}
|
|
375
|
-
function createTextAreaValidator(_attr, _messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
376
|
-
return z.string();
|
|
377
|
-
}
|
|
378
|
-
function createRichtextValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
379
|
-
return z.string({
|
|
380
|
-
message: messages.invalidRichtext(attr)
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
function createAttributeValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
384
|
-
switch (attr.type) {
|
|
385
|
-
case "text":
|
|
386
|
-
return createTextValidator(attr, messages);
|
|
387
|
-
case "textarea":
|
|
388
|
-
return createTextAreaValidator(attr, messages);
|
|
389
|
-
case "richtext":
|
|
390
|
-
return createRichtextValidator(attr, messages);
|
|
391
|
-
case "number":
|
|
392
|
-
return createNumberValidator(attr, messages);
|
|
393
|
-
case "checkbox":
|
|
394
|
-
return createCheckboxValidator(attr, messages);
|
|
395
|
-
case "date":
|
|
396
|
-
return createDateValidator(attr, messages);
|
|
397
|
-
case "phone":
|
|
398
|
-
return createPhoneValidator(attr, messages);
|
|
399
|
-
case "currency":
|
|
400
|
-
return createCurrencyValidator(attr, messages);
|
|
401
|
-
case "status":
|
|
402
|
-
return createStatusValidator(attr, messages);
|
|
403
|
-
case "location":
|
|
404
|
-
return createLocationValidator(attr, messages);
|
|
405
|
-
case "select":
|
|
406
|
-
return createSelectValidator(attr, messages);
|
|
407
|
-
case "multiselect":
|
|
408
|
-
return createMultiselectValidator(attr, messages);
|
|
409
|
-
case "file":
|
|
410
|
-
return createFileValidator(attr, messages);
|
|
411
|
-
case "user":
|
|
412
|
-
return createUserValidator(attr, messages);
|
|
413
|
-
case "relation":
|
|
414
|
-
return createRelationValidator(attr, messages);
|
|
415
|
-
case "rating":
|
|
416
|
-
return createRatingValidator(attr, messages);
|
|
417
|
-
case "formula":
|
|
418
|
-
return createFormulaValidator(attr, messages);
|
|
419
|
-
case "rollup":
|
|
420
|
-
return createRollupValidator(attr, messages);
|
|
421
|
-
default:
|
|
422
|
-
return z.unknown();
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
function isEmptyValue(value) {
|
|
426
|
-
if (value === null || value === void 0) return true;
|
|
427
|
-
if (typeof value === "string" && value.trim() === "") return true;
|
|
428
|
-
if (value instanceof Date) return false;
|
|
429
|
-
if (typeof value === "object" && !Array.isArray(value)) {
|
|
430
|
-
return Object.values(value).every(
|
|
431
|
-
(v) => v === null || v === void 0 || typeof v === "string" && v.trim() === ""
|
|
432
|
-
);
|
|
433
|
-
}
|
|
434
|
-
return false;
|
|
435
|
-
}
|
|
436
|
-
function withEmptyToNull(validator) {
|
|
437
|
-
return z.preprocess((val) => isEmptyValue(val) ? null : val, validator.nullish());
|
|
438
|
-
}
|
|
439
|
-
function createFormAttributeValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
440
|
-
const validator = createAttributeValidator(attr, messages);
|
|
441
|
-
if (!attr.required) {
|
|
442
|
-
return withEmptyToNull(validator);
|
|
443
|
-
}
|
|
444
|
-
return validator;
|
|
445
|
-
}
|
|
446
|
-
function createObjectValidator(objectDef) {
|
|
447
|
-
const shape = {};
|
|
448
|
-
for (const attr of objectDef.attributes) {
|
|
449
|
-
const validator = createAttributeValidator(attr);
|
|
450
|
-
shape[attr.name] = attr.required ? validator : withEmptyToNull(validator);
|
|
451
|
-
}
|
|
452
|
-
return z.object(shape).passthrough();
|
|
453
|
-
}
|
|
454
|
-
function validateAttribute(attr, value) {
|
|
455
|
-
const validator = createAttributeValidator(attr);
|
|
456
|
-
if (!attr.required && (value === void 0 || value === null)) {
|
|
457
|
-
return { success: true, data: { [attr.name]: value } };
|
|
458
|
-
}
|
|
459
|
-
const result = validator.safeParse(value);
|
|
460
|
-
if (result.success) {
|
|
461
|
-
return {
|
|
462
|
-
success: true,
|
|
463
|
-
data: { [attr.name]: result.data }
|
|
464
|
-
};
|
|
465
|
-
}
|
|
466
|
-
return {
|
|
467
|
-
success: false,
|
|
468
|
-
errors: formatZodErrors(result.error).map((err) => ({
|
|
469
|
-
path: [attr.name, ...err.path],
|
|
470
|
-
message: err.message
|
|
471
|
-
}))
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
function validateObject(objectDef, data) {
|
|
475
|
-
const validator = createObjectValidator(objectDef);
|
|
476
|
-
const result = validator.safeParse(data);
|
|
477
|
-
if (result.success) {
|
|
478
|
-
return {
|
|
479
|
-
success: true,
|
|
480
|
-
data: result.data
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
return {
|
|
484
|
-
success: false,
|
|
485
|
-
errors: formatZodErrors(result.error)
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
function validateObjectOrThrow(objectDef, data) {
|
|
489
|
-
const result = validateObject(objectDef, data);
|
|
490
|
-
if (!result.success) {
|
|
491
|
-
const errorMessages = result.errors?.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
|
|
492
|
-
throw new Error(`Validation failed for ${objectDef.label}:
|
|
493
|
-
${errorMessages}`);
|
|
494
|
-
}
|
|
495
|
-
return result.data;
|
|
496
|
-
}
|
|
497
|
-
function createDraftValidator(objectDef) {
|
|
498
|
-
const shape = {};
|
|
499
|
-
for (const attr of objectDef.attributes) {
|
|
500
|
-
const validator = createAttributeValidator(attr);
|
|
501
|
-
shape[attr.name] = withEmptyToNull(validator);
|
|
502
|
-
}
|
|
503
|
-
return z.object(shape).passthrough();
|
|
504
|
-
}
|
|
505
|
-
function validateDraft(objectDef, data) {
|
|
506
|
-
const validator = createDraftValidator(objectDef);
|
|
507
|
-
const result = validator.safeParse(data);
|
|
508
|
-
if (result.success) {
|
|
509
|
-
return {
|
|
510
|
-
success: true,
|
|
511
|
-
data: result.data
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
return {
|
|
515
|
-
success: false,
|
|
516
|
-
errors: formatZodErrors(result.error)
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
function validateDraftOrThrow(objectDef, data) {
|
|
520
|
-
const result = validateDraft(objectDef, data);
|
|
521
|
-
if (!result.success) {
|
|
522
|
-
const errorMessages = result.errors?.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
|
|
523
|
-
throw new Error(`Draft validation failed for ${objectDef.label}:
|
|
524
|
-
${errorMessages}`);
|
|
525
|
-
}
|
|
526
|
-
return result.data;
|
|
527
|
-
}
|
|
528
|
-
function isValuePresent(value) {
|
|
529
|
-
if (value === void 0 || value === null) {
|
|
530
|
-
return false;
|
|
531
|
-
}
|
|
532
|
-
if (typeof value === "string" && value.trim() === "") {
|
|
533
|
-
return false;
|
|
534
|
-
}
|
|
535
|
-
return true;
|
|
536
|
-
}
|
|
537
|
-
function getMissingRequiredAttributes(objectDef, data) {
|
|
538
|
-
const missing = [];
|
|
539
|
-
for (const attr of objectDef.attributes) {
|
|
540
|
-
if (attr.required && !isValuePresent(data[attr.name])) {
|
|
541
|
-
missing.push(attr);
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
return missing;
|
|
545
|
-
}
|
|
546
|
-
function isRecordComplete(objectDef, data) {
|
|
547
|
-
const missing = getMissingRequiredAttributes(objectDef, data);
|
|
548
|
-
if (missing.length > 0) {
|
|
549
|
-
return false;
|
|
550
|
-
}
|
|
551
|
-
const validation = validateObject(objectDef, data);
|
|
552
|
-
return validation.success;
|
|
553
|
-
}
|
|
554
|
-
function computeRecordStatus(objectDef, data) {
|
|
555
|
-
return isRecordComplete(objectDef, data) ? "complete" : "draft";
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
export {
|
|
559
|
-
formatZodErrors,
|
|
560
|
-
DEFAULT_VALIDATION_MESSAGES,
|
|
561
|
-
textConfigSchema,
|
|
562
|
-
textareaConfigSchema,
|
|
563
|
-
richtextConfigSchema,
|
|
564
|
-
numberConfigSchema,
|
|
565
|
-
checkboxConfigSchema,
|
|
566
|
-
dateConfigSchema,
|
|
567
|
-
phoneConfigSchema,
|
|
568
|
-
currencyConfigSchema,
|
|
569
|
-
statusConfigSchema,
|
|
570
|
-
locationConfigSchema,
|
|
571
|
-
selectConfigSchema,
|
|
572
|
-
multiselectConfigSchema,
|
|
573
|
-
fileConfigSchema,
|
|
574
|
-
userConfigSchema,
|
|
575
|
-
relationConfigSchema,
|
|
576
|
-
ratingConfigSchema,
|
|
577
|
-
formulaConfigSchema,
|
|
578
|
-
rollupConfigSchema,
|
|
579
|
-
documentConfigSchema,
|
|
580
|
-
attributeConfigSchemas,
|
|
581
|
-
getAttributeConfigSchema,
|
|
582
|
-
validateAttributeConfig,
|
|
583
|
-
parseAttributeConfig,
|
|
584
|
-
safeParseAttributeConfig,
|
|
585
|
-
createTextValidator,
|
|
586
|
-
createNumberValidator,
|
|
587
|
-
createCheckboxValidator,
|
|
588
|
-
createDateValidator,
|
|
589
|
-
createPhoneValidator,
|
|
590
|
-
createCurrencyValidator,
|
|
591
|
-
createStatusValidator,
|
|
592
|
-
createSelectValidator,
|
|
593
|
-
createMultiselectValidator,
|
|
594
|
-
createLocationValidator,
|
|
595
|
-
createFileValidator,
|
|
596
|
-
createUserValidator,
|
|
597
|
-
createSingleRelationValidator,
|
|
598
|
-
createMultiRelationValidator,
|
|
599
|
-
createRelationValidator,
|
|
600
|
-
createRatingValidator,
|
|
601
|
-
createFormulaValidator,
|
|
602
|
-
createRollupValidator,
|
|
603
|
-
createTextAreaValidator,
|
|
604
|
-
createRichtextValidator,
|
|
605
|
-
createAttributeValidator,
|
|
606
|
-
createFormAttributeValidator,
|
|
607
|
-
createObjectValidator,
|
|
608
|
-
validateAttribute,
|
|
609
|
-
validateObject,
|
|
610
|
-
validateObjectOrThrow,
|
|
611
|
-
createDraftValidator,
|
|
612
|
-
validateDraft,
|
|
613
|
-
validateDraftOrThrow,
|
|
614
|
-
getMissingRequiredAttributes,
|
|
615
|
-
isRecordComplete,
|
|
616
|
-
computeRecordStatus
|
|
617
|
-
};
|