@stndrds/schema 1.0.0-alpha.95 → 1.0.0-alpha.96
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/attributes-Btn-GLvC.d.ts +674 -0
- package/dist/attributes-CeDp1IMp.d.mts +674 -0
- package/dist/chunk-2TEWGEUI.js +212 -0
- package/dist/chunk-4RGFTMQR.mjs +8 -0
- package/dist/chunk-5TLM4QXO.mjs +8 -0
- package/dist/chunk-67PQMHQA.mjs +199 -0
- package/dist/chunk-6HHSX6LP.js +64 -0
- package/dist/chunk-AHPXNPJC.js +105 -0
- package/dist/chunk-BEN6TE7Y.js +11 -0
- package/dist/chunk-BH3RPSC5.js +22 -0
- package/dist/chunk-BIQ35DLC.mjs +78 -0
- package/dist/chunk-CKZHFJQT.js +16 -0
- package/dist/chunk-E6XO2STS.js +11 -11
- package/dist/chunk-EIWGW2ML.mjs +99 -0
- package/dist/chunk-EKG35CSO.mjs +1 -0
- package/dist/chunk-IMEPIVTR.js +217 -0
- package/dist/chunk-J4ORNCAH.js +10 -0
- package/dist/chunk-KC4F3HB7.js +32 -0
- package/dist/chunk-LHXE7LLD.js +28 -0
- package/dist/chunk-MD6XGXTU.mjs +18 -0
- package/dist/chunk-N47XKY4R.js +14 -0
- package/dist/chunk-NXXSNUDI.mjs +8 -0
- package/dist/chunk-PKG3E5MW.mjs +18 -0
- package/dist/chunk-PZT3CIHD.mjs +192 -0
- package/dist/chunk-QL3UGPUG.mjs +60 -0
- package/dist/chunk-QY65ZSBL.js +16 -0
- package/dist/chunk-R6JFUC32.js +2 -0
- package/dist/chunk-RDXQ4CYT.mjs +9 -0
- package/dist/chunk-S5VJ2FZE.js +12 -0
- package/dist/chunk-SVII65W7.mjs +14 -0
- package/dist/chunk-U7VN3RUE.mjs +25 -0
- package/dist/chunk-VCPYYLCS.js +83 -0
- package/dist/chunk-VD3P2A6Q.js +10 -0
- package/dist/chunk-VPEV3W34.mjs +10 -0
- package/dist/chunk-WGFQMQMV.mjs +14 -0
- package/dist/chunk-X6VDDXG7.mjs +12 -0
- package/dist/chunk-XAORXFAX.mjs +1 -10
- package/dist/chunk-XEOG24K6.mjs +8 -0
- package/dist/chunk-XK6XC3V4.js +10 -0
- package/dist/chunk-XZ5B5MTG.js +20 -0
- package/dist/chunk-YKHC2AW6.js +10 -0
- package/dist/chunk-Z2T7ONKU.js +20 -0
- package/dist/chunk-ZFL7DXAE.mjs +28 -0
- package/dist/chunk-ZM7W2ZCF.mjs +20 -0
- package/dist/{validators-BCw4Sn01.d.mts → index-CvXnHxD2.d.mts} +12 -1359
- package/dist/{validators-5XMwJOlV.d.ts → index-telccAkt.d.ts} +12 -1359
- package/dist/index.d.mts +1281 -461
- package/dist/index.d.ts +1281 -461
- package/dist/index.js +1400 -831
- package/dist/index.mjs +583 -571
- package/dist/types-B5Zhhoev.d.ts +39 -0
- package/dist/types-C6naks1H.d.mts +39 -0
- package/dist/utils.js +38 -20
- package/dist/utils.mjs +1 -20
- 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 +85 -0
- package/dist/validation/core/index.d.ts +85 -0
- package/dist/validation/core/index.js +27 -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 -120
- package/dist/validation/validators.mjs +20 -120
- package/package.json +108 -5
- package/dist/chunk-4362R5F2.mjs +0 -780
- package/dist/chunk-7QUI6TSO.js +0 -780
|
@@ -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,60 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-BIQ35DLC.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,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVCPYYLCS_js = require('./chunk-VCPYYLCS.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createCurrencyValidator(attr, messages = chunkVCPYYLCS_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,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVCPYYLCS_js = require('./chunk-VCPYYLCS.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createRichtextValidator(attr, messages = chunkVCPYYLCS_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
return zod.z.string({
|
|
8
|
+
message: messages.invalidRichtext(attr)
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
exports.createRichtextValidator = createRichtextValidator;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-BIQ35DLC.mjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
function createCurrencyValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
5
|
+
return z.object(
|
|
6
|
+
{
|
|
7
|
+
code: z.string().length(3),
|
|
8
|
+
value: z.number().min(0)
|
|
9
|
+
},
|
|
10
|
+
{ message: messages.invalidCurrency(attr) }
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { createCurrencyValidator };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createRegexCache, DEFAULT_VALIDATION_MESSAGES, getCachedRegex } from './chunk-BIQ35DLC.mjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
var textRegexCache = createRegexCache();
|
|
5
|
+
function createTextValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
6
|
+
let schema = z.string();
|
|
7
|
+
if (attr.minLength !== void 0) {
|
|
8
|
+
schema = schema.min(attr.minLength, messages.minLength(attr, attr.minLength));
|
|
9
|
+
}
|
|
10
|
+
if (attr.maxLength !== void 0) {
|
|
11
|
+
schema = schema.max(attr.maxLength, messages.maxLength(attr, attr.maxLength));
|
|
12
|
+
}
|
|
13
|
+
if (attr.pattern) {
|
|
14
|
+
schema = schema.regex(
|
|
15
|
+
getCachedRegex(textRegexCache, attr.pattern),
|
|
16
|
+
messages.invalidPattern(attr)
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
return schema;
|
|
20
|
+
}
|
|
21
|
+
function createTextAreaValidator(_attr, _messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
22
|
+
return z.string();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { createTextAreaValidator, createTextValidator };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/validation/core/messages.ts
|
|
4
|
+
var DEFAULT_VALIDATION_MESSAGES = {
|
|
5
|
+
required: (attr) => `${attr.label} is required`,
|
|
6
|
+
invalidType: (attr, expected) => `${attr.label} must be a ${expected}`,
|
|
7
|
+
minLength: (attr, min) => `${attr.label} must be at least ${min} characters`,
|
|
8
|
+
maxLength: (attr, max) => `${attr.label} must be at most ${max} characters`,
|
|
9
|
+
invalidPattern: (attr) => `${attr.label} format is invalid`,
|
|
10
|
+
minValue: (attr, min) => `${attr.label} must be at least ${min}`,
|
|
11
|
+
maxValue: (attr, max) => `${attr.label} must be at most ${max}`,
|
|
12
|
+
mustBeInteger: (attr) => `${attr.label} must be an integer`,
|
|
13
|
+
invalidDate: (attr) => `${attr.label} must be a valid date`,
|
|
14
|
+
invalidOption: (attr, options) => `${attr.label} must be one of: ${options.join(", ")}`,
|
|
15
|
+
invalidId: (attr) => `${attr.label} must be a valid ID`,
|
|
16
|
+
minItems: (attr, min) => `${attr.label} must have at least ${min} item${min > 1 ? "s" : ""}`,
|
|
17
|
+
maxItems: (attr, max) => `${attr.label} must have at most ${max} item${max > 1 ? "s" : ""}`,
|
|
18
|
+
invalidRichtext: (attr) => `${attr.label} must be valid rich text content`,
|
|
19
|
+
invalidPhone: (attr) => `${attr.label} must be a valid phone number`,
|
|
20
|
+
invalidCurrency: (attr) => `${attr.label} must be a valid currency value`,
|
|
21
|
+
invalidLocation: (attr) => `${attr.label} must be a valid location`
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/lib/lru-cache.ts
|
|
25
|
+
var LRUCache = class {
|
|
26
|
+
constructor(capacity) {
|
|
27
|
+
if (capacity <= 0) {
|
|
28
|
+
throw new Error("LRU cache capacity must be greater than 0");
|
|
29
|
+
}
|
|
30
|
+
this.capacity = capacity;
|
|
31
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
32
|
+
}
|
|
33
|
+
get(key) {
|
|
34
|
+
const value = this.cache.get(key);
|
|
35
|
+
if (value !== void 0) {
|
|
36
|
+
this.cache.delete(key);
|
|
37
|
+
this.cache.set(key, value);
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
set(key, value) {
|
|
42
|
+
if (this.cache.has(key)) {
|
|
43
|
+
this.cache.delete(key);
|
|
44
|
+
} else if (this.cache.size >= this.capacity) {
|
|
45
|
+
const firstKey = this.cache.keys().next().value;
|
|
46
|
+
if (firstKey !== void 0) {
|
|
47
|
+
this.cache.delete(firstKey);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
this.cache.set(key, value);
|
|
51
|
+
}
|
|
52
|
+
has(key) {
|
|
53
|
+
return this.cache.has(key);
|
|
54
|
+
}
|
|
55
|
+
clear() {
|
|
56
|
+
this.cache.clear();
|
|
57
|
+
}
|
|
58
|
+
get size() {
|
|
59
|
+
return this.cache.size;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// src/validation/core/regex-cache.ts
|
|
64
|
+
function createRegexCache(capacity = 100) {
|
|
65
|
+
return new LRUCache(capacity);
|
|
66
|
+
}
|
|
67
|
+
function getCachedRegex(cache, pattern) {
|
|
68
|
+
let cached = cache.get(pattern);
|
|
69
|
+
if (!cached) {
|
|
70
|
+
cached = new RegExp(pattern);
|
|
71
|
+
cache.set(pattern, cached);
|
|
72
|
+
}
|
|
73
|
+
return cached;
|
|
74
|
+
}
|
|
75
|
+
var defaultRegexCache = createRegexCache();
|
|
76
|
+
function getRegex(pattern) {
|
|
77
|
+
return getCachedRegex(defaultRegexCache, pattern);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
exports.DEFAULT_VALIDATION_MESSAGES = DEFAULT_VALIDATION_MESSAGES;
|
|
81
|
+
exports.createRegexCache = createRegexCache;
|
|
82
|
+
exports.getCachedRegex = getCachedRegex;
|
|
83
|
+
exports.getRegex = getRegex;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVCPYYLCS_js = require('./chunk-VCPYYLCS.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createDateValidator(attr, messages = chunkVCPYYLCS_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
return zod.z.coerce.date({ message: messages.invalidDate(attr) });
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.createDateValidator = createDateValidator;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-BIQ35DLC.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 };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-BIQ35DLC.mjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
function createUserValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
5
|
+
const uuidSchema = z.uuid({
|
|
6
|
+
message: messages.invalidId(attr)
|
|
7
|
+
});
|
|
8
|
+
if (attr.multiple) {
|
|
9
|
+
return z.array(uuidSchema);
|
|
10
|
+
}
|
|
11
|
+
return uuidSchema;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { createUserValidator };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-BIQ35DLC.mjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
function createRatingValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
5
|
+
let schema = z.number().min(0);
|
|
6
|
+
if (attr.max !== void 0) {
|
|
7
|
+
schema = schema.max(attr.max, messages.maxValue(attr, attr.max));
|
|
8
|
+
}
|
|
9
|
+
return schema;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { createRatingValidator };
|
package/dist/chunk-XAORXFAX.mjs
CHANGED
|
@@ -49,13 +49,4 @@ function deepEqual(a, b) {
|
|
|
49
49
|
return false;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
export {
|
|
53
|
-
asTenantId,
|
|
54
|
-
asUserId,
|
|
55
|
-
generateId,
|
|
56
|
-
generatePrefixedId,
|
|
57
|
-
slugify,
|
|
58
|
-
generateTemplateName,
|
|
59
|
-
indexBy,
|
|
60
|
-
deepEqual
|
|
61
|
-
};
|
|
52
|
+
export { asTenantId, asUserId, deepEqual, generateId, generatePrefixedId, generateTemplateName, indexBy, slugify };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-BIQ35DLC.mjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
function createDateValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
5
|
+
return z.coerce.date({ message: messages.invalidDate(attr) });
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export { createDateValidator };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVCPYYLCS_js = require('./chunk-VCPYYLCS.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createCheckboxValidator(_attr, _messages = chunkVCPYYLCS_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
return zod.z.boolean();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.createCheckboxValidator = createCheckboxValidator;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVCPYYLCS_js = require('./chunk-VCPYYLCS.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createNumberValidator(attr, messages = chunkVCPYYLCS_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
let schema = zod.z.number();
|
|
8
|
+
if (attr.min !== void 0) {
|
|
9
|
+
schema = schema.min(attr.min, messages.minValue(attr, attr.min));
|
|
10
|
+
}
|
|
11
|
+
if (attr.max !== void 0) {
|
|
12
|
+
schema = schema.max(attr.max, messages.maxValue(attr, attr.max));
|
|
13
|
+
}
|
|
14
|
+
if (attr.unit === "integer") {
|
|
15
|
+
schema = schema.int(messages.mustBeInteger(attr));
|
|
16
|
+
}
|
|
17
|
+
return schema;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
exports.createNumberValidator = createNumberValidator;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVCPYYLCS_js = require('./chunk-VCPYYLCS.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createRollupValidator(_attr, _messages = chunkVCPYYLCS_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
return zod.z.unknown();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.createRollupValidator = createRollupValidator;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVCPYYLCS_js = require('./chunk-VCPYYLCS.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createFileValidator(attr, messages = chunkVCPYYLCS_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
const uuidSchema = zod.z.uuid({
|
|
8
|
+
message: messages.invalidId(attr)
|
|
9
|
+
});
|
|
10
|
+
if (attr.multiple) {
|
|
11
|
+
let arraySchema = zod.z.array(uuidSchema);
|
|
12
|
+
if (attr.maxFiles) {
|
|
13
|
+
arraySchema = arraySchema.max(attr.maxFiles, messages.maxItems(attr, attr.maxFiles));
|
|
14
|
+
}
|
|
15
|
+
return arraySchema;
|
|
16
|
+
}
|
|
17
|
+
return uuidSchema;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
exports.createFileValidator = createFileValidator;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-BIQ35DLC.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,20 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-BIQ35DLC.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 };
|