@stndrds/schema 1.0.0-alpha.264 → 1.0.0-alpha.266
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/all--B2_3ksI.d.ts +465 -0
- package/dist/all-D5zeUllO.d.mts +465 -0
- package/dist/{attributes-DUuaECJI.d.ts → attributes-_b3Db8vT.d.ts} +1 -1
- package/dist/{attributes-DCgZhISp.d.mts → attributes-lBLiOIY3.d.mts} +1 -1
- package/dist/chunk-6ZDH3EJA.js +1261 -0
- package/dist/chunk-F6ATLCIR.mjs +1214 -0
- package/dist/{chunk-TS3PJOMZ.js → chunk-FDIAOFHS.js} +22 -235
- package/dist/{chunk-UXCJ3NI4.mjs → chunk-KDHDC7E6.mjs} +150 -9
- package/dist/{chunk-U36ZIBEM.mjs → chunk-O73ROMWQ.mjs} +15 -6
- package/dist/{chunk-54WDPQ6R.mjs → chunk-POULKEJM.mjs} +22 -224
- package/dist/{chunk-EBGRZUIH.js → chunk-Q4SZAMJT.js} +5 -0
- package/dist/chunk-QMLO7V5E.mjs +216 -0
- package/dist/{chunk-L4U5QEQL.js → chunk-QN2N3IJZ.js} +158 -8
- package/dist/{chunk-JUKLL5RJ.mjs → chunk-R5LAJCBU.mjs} +5 -2
- package/dist/chunk-V6Q7HCA7.js +229 -0
- package/dist/{chunk-QAF3HNKQ.js → chunk-ZPFOKBIN.js} +16 -5
- package/dist/exceptions.d.mts +471 -0
- package/dist/exceptions.d.ts +471 -0
- package/dist/exceptions.js +158 -0
- package/dist/exceptions.mjs +1 -0
- package/dist/helpers-C1VVEAOO.d.mts +76 -0
- package/dist/helpers-vQ6kp8ET.d.ts +76 -0
- package/dist/index-Bq1KrQkR.d.ts +2413 -0
- package/dist/index-DtxtOBYT.d.mts +2413 -0
- package/dist/index.d.mts +1580 -2652
- package/dist/index.d.ts +1580 -2652
- package/dist/index.js +1297 -1045
- package/dist/index.mjs +913 -907
- package/dist/migrations-BXd2ZGfM.d.mts +39 -0
- package/dist/migrations-DcuJZ8qO.d.ts +39 -0
- package/dist/{helpers-B4qBjTd0.d.ts → objects-A1ED9af-.d.ts} +33 -113
- package/dist/{helpers-B_NlMAm2.d.mts → objects-BCaBw2ef.d.mts} +33 -113
- package/dist/{types-15lGDPlN.d.mts → types-DNz3ITS-.d.mts} +1 -1
- package/dist/{types-CqZZxm_V.d.ts → types-DqLi1tx1.d.ts} +1 -1
- package/dist/validation/all.d.mts +7 -4
- package/dist/validation/all.d.ts +7 -4
- package/dist/validation/all.js +88 -15
- package/dist/validation/all.mjs +9 -8
- package/dist/validation/complex/currency.d.mts +2 -2
- package/dist/validation/complex/currency.d.ts +2 -2
- package/dist/validation/complex/location.d.mts +2 -2
- package/dist/validation/complex/location.d.ts +2 -2
- package/dist/validation/complex/phone.d.mts +2 -2
- package/dist/validation/complex/phone.d.ts +2 -2
- package/dist/validation/complex/phone.js +2 -2
- package/dist/validation/complex/phone.mjs +1 -1
- package/dist/validation/complex/relation.d.mts +2 -2
- package/dist/validation/complex/relation.d.ts +2 -2
- package/dist/validation/complex/richtext.d.mts +2 -2
- package/dist/validation/complex/richtext.d.ts +2 -2
- package/dist/validation/complex/select.d.mts +2 -2
- package/dist/validation/complex/select.d.ts +2 -2
- package/dist/validation/complex/user.d.mts +2 -2
- package/dist/validation/complex/user.d.ts +2 -2
- package/dist/validation/computed/formula.d.mts +2 -2
- package/dist/validation/computed/formula.d.ts +2 -2
- package/dist/validation/computed/rollup.d.mts +2 -2
- package/dist/validation/computed/rollup.d.ts +2 -2
- package/dist/validation/config/index.d.mts +5 -18
- package/dist/validation/config/index.d.ts +5 -18
- package/dist/validation/config/index.js +34 -4
- package/dist/validation/config/index.mjs +7 -1
- package/dist/validation/core/index.d.mts +3 -3
- package/dist/validation/core/index.d.ts +3 -3
- package/dist/validation/object/index.d.mts +5 -4
- package/dist/validation/object/index.d.ts +5 -4
- package/dist/validation/object/index.js +19 -18
- package/dist/validation/object/index.mjs +7 -6
- package/dist/validation/primitives/checkbox.d.mts +2 -2
- package/dist/validation/primitives/checkbox.d.ts +2 -2
- package/dist/validation/primitives/date.d.mts +2 -2
- package/dist/validation/primitives/date.d.ts +2 -2
- package/dist/validation/primitives/number.d.mts +2 -2
- package/dist/validation/primitives/number.d.ts +2 -2
- package/dist/validation/primitives/text.d.mts +2 -2
- package/dist/validation/primitives/text.d.ts +2 -2
- package/dist/validation/primitives/text.js +2 -2
- package/dist/validation/primitives/text.mjs +1 -1
- package/package.json +7 -2
- package/dist/chunk-PGERPYDR.js +0 -2
- package/dist/chunk-SP3PNHYF.mjs +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunkFDIAOFHS_js = require('./chunk-FDIAOFHS.js');
|
|
3
4
|
var zod = require('zod');
|
|
4
|
-
|
|
5
|
-
// src/validation/config/schemas.ts
|
|
5
|
+
var constants = require('@stndrds/constants');
|
|
6
6
|
|
|
7
7
|
// src/computed/parser.ts
|
|
8
8
|
var ComputedFormulaParseError = class extends Error {
|
|
@@ -308,6 +308,39 @@ function getOperatorPrecedence(operator) {
|
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
310
|
|
|
311
|
+
// src/validation/limits.ts
|
|
312
|
+
var SCHEMA_LIMITS = {
|
|
313
|
+
attributesPerObject: 300,
|
|
314
|
+
tabsPerView: 24,
|
|
315
|
+
groupsPerFormTab: 12,
|
|
316
|
+
fieldsPerGroup: 60,
|
|
317
|
+
fieldsPerFormTab: 150,
|
|
318
|
+
columnsPerTab: 50,
|
|
319
|
+
optionsPerAttribute: 200,
|
|
320
|
+
sidePanelAttributes: 100,
|
|
321
|
+
filterRulesPerTab: 50,
|
|
322
|
+
sortsPerTab: 20,
|
|
323
|
+
emailAttributesPerTab: 30,
|
|
324
|
+
objectsPerPlan: 20,
|
|
325
|
+
mutationsPerPlan: 500,
|
|
326
|
+
planBytes: 512 * 1024,
|
|
327
|
+
historyDefault: 20,
|
|
328
|
+
historyMax: 50,
|
|
329
|
+
iconQueries: 5,
|
|
330
|
+
iconResults: 20
|
|
331
|
+
};
|
|
332
|
+
var COLOR_IDS = Object.keys(constants.COLORS);
|
|
333
|
+
var ICON_NAMES = new Set(constants.ICONS);
|
|
334
|
+
var colorIdSchema = zod.z.enum(COLOR_IDS);
|
|
335
|
+
var iconNameSchema = zod.z.string().superRefine((value, ctx) => {
|
|
336
|
+
if (!ICON_NAMES.has(value)) {
|
|
337
|
+
ctx.addIssue({
|
|
338
|
+
code: "custom",
|
|
339
|
+
message: "Invalid icon name"
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
}).transform((value) => value);
|
|
343
|
+
|
|
311
344
|
// src/validation/config/schemas.ts
|
|
312
345
|
var baseConfigSchema = zod.z.object({
|
|
313
346
|
placeholder: zod.z.string().optional(),
|
|
@@ -320,14 +353,25 @@ var baseConfigSchema = zod.z.object({
|
|
|
320
353
|
deprecated: zod.z.boolean().optional(),
|
|
321
354
|
metadata: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
|
|
322
355
|
});
|
|
323
|
-
var
|
|
356
|
+
var optionBaseSchema = zod.z.object({
|
|
324
357
|
value: zod.z.string().min(1),
|
|
325
358
|
label: zod.z.string().min(1),
|
|
326
|
-
color: zod.z.string().optional(),
|
|
327
359
|
description: zod.z.string().optional(),
|
|
328
|
-
group: zod.z.enum(["idle", "in_progress", "finished"]).optional(),
|
|
329
360
|
inverse: zod.z.string().optional(),
|
|
330
361
|
archived: zod.z.boolean().optional()
|
|
362
|
+
});
|
|
363
|
+
var statusGroupSchema = zod.z.enum(["idle", "in_progress", "finished"]);
|
|
364
|
+
var selectOptionWriteSchema = optionBaseSchema.extend({
|
|
365
|
+
color: colorIdSchema
|
|
366
|
+
}).strict();
|
|
367
|
+
var multiselectOptionWriteSchema = selectOptionWriteSchema;
|
|
368
|
+
var statusOptionWriteSchema = optionBaseSchema.extend({
|
|
369
|
+
color: colorIdSchema,
|
|
370
|
+
group: statusGroupSchema
|
|
371
|
+
}).strict();
|
|
372
|
+
var optionSchema = optionBaseSchema.extend({
|
|
373
|
+
color: zod.z.string().optional(),
|
|
374
|
+
group: statusGroupSchema.optional()
|
|
331
375
|
}).strict();
|
|
332
376
|
var optionsArraySchema = zod.z.array(optionSchema).min(1).refine(
|
|
333
377
|
(options) => {
|
|
@@ -336,6 +380,18 @@ var optionsArraySchema = zod.z.array(optionSchema).min(1).refine(
|
|
|
336
380
|
},
|
|
337
381
|
{ message: "Duplicate option values are not allowed" }
|
|
338
382
|
);
|
|
383
|
+
function writeOptionsArraySchema(option) {
|
|
384
|
+
return zod.z.array(option).min(1).max(SCHEMA_LIMITS.optionsPerAttribute).refine(
|
|
385
|
+
(options) => {
|
|
386
|
+
const values = options.map((candidate) => candidate.value);
|
|
387
|
+
return new Set(values).size === values.length;
|
|
388
|
+
},
|
|
389
|
+
{ message: "Duplicate option values are not allowed" }
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
var selectOptionsWriteSchema = writeOptionsArraySchema(selectOptionWriteSchema);
|
|
393
|
+
var multiselectOptionsWriteSchema = writeOptionsArraySchema(multiselectOptionWriteSchema);
|
|
394
|
+
var statusOptionsWriteSchema = writeOptionsArraySchema(statusOptionWriteSchema);
|
|
339
395
|
var relationTargetSchema = zod.z.object({
|
|
340
396
|
object: zod.z.string().min(1),
|
|
341
397
|
displayTemplate: zod.z.string().optional(),
|
|
@@ -371,7 +427,10 @@ var checkboxConfigSchema = baseConfigSchema;
|
|
|
371
427
|
var dateConfigSchema = baseConfigSchema.extend({
|
|
372
428
|
dateFormat: zod.z.enum(["short", "long", "full", "relative"]).optional(),
|
|
373
429
|
minDate: zod.z.string().optional(),
|
|
374
|
-
maxDate: zod.z.string().optional()
|
|
430
|
+
maxDate: zod.z.string().optional(),
|
|
431
|
+
includeTime: zod.z.boolean().optional(),
|
|
432
|
+
endDate: zod.z.boolean().optional(),
|
|
433
|
+
timeFormat: zod.z.enum(["12h", "24h"]).optional()
|
|
375
434
|
});
|
|
376
435
|
var phoneConfigSchema = baseConfigSchema.extend({
|
|
377
436
|
defaultCountryCode: zod.z.string().length(3).optional()
|
|
@@ -390,10 +449,12 @@ var locationConfigSchema = baseConfigSchema.extend({
|
|
|
390
449
|
allowedCountries: zod.z.array(zod.z.string().length(3)).optional()
|
|
391
450
|
});
|
|
392
451
|
var selectConfigSchema = baseConfigSchema.extend({
|
|
393
|
-
options: optionsArraySchema
|
|
452
|
+
options: optionsArraySchema,
|
|
453
|
+
renderAs: zod.z.literal("badges").optional()
|
|
394
454
|
});
|
|
395
455
|
var multiselectConfigSchema = baseConfigSchema.extend({
|
|
396
|
-
options: optionsArraySchema
|
|
456
|
+
options: optionsArraySchema,
|
|
457
|
+
renderAs: zod.z.literal("badges").optional()
|
|
397
458
|
});
|
|
398
459
|
var userConfigSchema = baseConfigSchema.extend({
|
|
399
460
|
types: zod.z.array(zod.z.enum(["user", "agent"])).min(1).optional(),
|
|
@@ -494,9 +555,98 @@ function parseAttributeConfig(type, config) {
|
|
|
494
555
|
const schema = getAttributeConfigSchema(type);
|
|
495
556
|
return schema.strip().parse(config);
|
|
496
557
|
}
|
|
558
|
+
function getAttributeConfigWriteSchema(type) {
|
|
559
|
+
const schema = getAttributeConfigSchema(type).extend({
|
|
560
|
+
icon: iconNameSchema.optional()
|
|
561
|
+
});
|
|
562
|
+
switch (type) {
|
|
563
|
+
case "select":
|
|
564
|
+
return schema.extend({ options: selectOptionsWriteSchema });
|
|
565
|
+
case "multiselect":
|
|
566
|
+
return schema.extend({ options: multiselectOptionsWriteSchema });
|
|
567
|
+
case "status":
|
|
568
|
+
return schema.extend({ options: statusOptionsWriteSchema });
|
|
569
|
+
default:
|
|
570
|
+
return schema;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
function validationErrorFromIssues(issues) {
|
|
574
|
+
return chunkFDIAOFHS_js.ValidationError.fromZodErrors(
|
|
575
|
+
issues.map((issue) => ({
|
|
576
|
+
path: issue.path.map((segment) => typeof segment === "symbol" ? String(segment) : segment),
|
|
577
|
+
message: issue.message
|
|
578
|
+
}))
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
function parseWriteSchema(type, input) {
|
|
582
|
+
const result = getAttributeConfigWriteSchema(type).strip().safeParse(input);
|
|
583
|
+
if (!result.success) {
|
|
584
|
+
throw validationErrorFromIssues(result.error.issues);
|
|
585
|
+
}
|
|
586
|
+
return result.data;
|
|
587
|
+
}
|
|
588
|
+
function parseAttributeConfigForCreate(type, input) {
|
|
589
|
+
return parseWriteSchema(type, input);
|
|
590
|
+
}
|
|
591
|
+
function validatePatchedIcon(patch) {
|
|
592
|
+
if (!Object.prototype.hasOwnProperty.call(patch, "icon")) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
const result = iconNameSchema.optional().safeParse(patch.icon);
|
|
596
|
+
if (!result.success) {
|
|
597
|
+
throw chunkFDIAOFHS_js.ValidationError.fromZodErrors(
|
|
598
|
+
result.error.issues.map((issue) => ({
|
|
599
|
+
path: [
|
|
600
|
+
"icon",
|
|
601
|
+
...issue.path.map((segment) => typeof segment === "symbol" ? String(segment) : segment)
|
|
602
|
+
],
|
|
603
|
+
message: issue.message
|
|
604
|
+
}))
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
function isSelectLike(type) {
|
|
609
|
+
return type === "select" || type === "multiselect" || type === "status";
|
|
610
|
+
}
|
|
611
|
+
function parseAttributeConfigForUpdate(stored, patch) {
|
|
612
|
+
const ownsOptions = Object.prototype.hasOwnProperty.call(patch, "options");
|
|
613
|
+
const ownsIcon = Object.prototype.hasOwnProperty.call(patch, "icon");
|
|
614
|
+
const input = { ...stored, ...patch };
|
|
615
|
+
validatePatchedIcon(patch);
|
|
616
|
+
if (ownsOptions) {
|
|
617
|
+
const { icon: storedIcon, ...inputWithoutStoredIcon } = input;
|
|
618
|
+
const parsed2 = parseWriteSchema(stored.type, ownsIcon ? input : inputWithoutStoredIcon);
|
|
619
|
+
if (!ownsIcon && storedIcon !== void 0) {
|
|
620
|
+
parsed2.icon = storedIcon;
|
|
621
|
+
}
|
|
622
|
+
return parsed2;
|
|
623
|
+
}
|
|
624
|
+
const storedOptions = stored.options;
|
|
625
|
+
if (isSelectLike(stored.type)) {
|
|
626
|
+
input.options = [{ value: "__legacy__", label: "__legacy__" }];
|
|
627
|
+
}
|
|
628
|
+
const result = getAttributeConfigSchema(stored.type).strip().safeParse(input);
|
|
629
|
+
if (!result.success) {
|
|
630
|
+
throw validationErrorFromIssues(result.error.issues);
|
|
631
|
+
}
|
|
632
|
+
const parsed = result.data;
|
|
633
|
+
if (isSelectLike(stored.type)) {
|
|
634
|
+
parsed.options = storedOptions;
|
|
635
|
+
}
|
|
636
|
+
return parsed;
|
|
637
|
+
}
|
|
497
638
|
|
|
498
639
|
exports.ComputedFormulaParseError = ComputedFormulaParseError;
|
|
640
|
+
exports.SCHEMA_LIMITS = SCHEMA_LIMITS;
|
|
499
641
|
exports.attributeConfigSchemas = attributeConfigSchemas;
|
|
642
|
+
exports.colorIdSchema = colorIdSchema;
|
|
500
643
|
exports.getAttributeConfigSchema = getAttributeConfigSchema;
|
|
644
|
+
exports.iconNameSchema = iconNameSchema;
|
|
645
|
+
exports.multiselectOptionWriteSchema = multiselectOptionWriteSchema;
|
|
501
646
|
exports.parseAttributeConfig = parseAttributeConfig;
|
|
647
|
+
exports.parseAttributeConfigForCreate = parseAttributeConfigForCreate;
|
|
648
|
+
exports.parseAttributeConfigForUpdate = parseAttributeConfigForUpdate;
|
|
502
649
|
exports.parseComputedFormula = parseComputedFormula;
|
|
650
|
+
exports.selectOptionWriteSchema = selectOptionWriteSchema;
|
|
651
|
+
exports.statusGroupSchema = statusGroupSchema;
|
|
652
|
+
exports.statusOptionWriteSchema = statusOptionWriteSchema;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-HRQEZUAA.mjs';
|
|
2
|
-
import { getCountryByIso3,
|
|
2
|
+
import { getCountryByIso3, stripTrunkPrefix, isValidIso3 } from '@stndrds/constants';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { parsePhoneNumberFromString } from 'libphonenumber-js';
|
|
5
5
|
|
|
6
6
|
function digitsOnly(input) {
|
|
7
7
|
return input.replace(/\D/g, "");
|
|
8
8
|
}
|
|
9
|
+
function normalizeCountrylessPhoneNumber(phoneNumber) {
|
|
10
|
+
return digitsOnly(phoneNumber);
|
|
11
|
+
}
|
|
9
12
|
function getIso2(iso3) {
|
|
10
13
|
const country = getCountryByIso3(iso3);
|
|
11
14
|
return country?.iso2;
|
|
@@ -61,4 +64,4 @@ function createPhoneValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
|
61
64
|
}));
|
|
62
65
|
}
|
|
63
66
|
|
|
64
|
-
export { createPhoneValidator, formatPhoneForDisplay };
|
|
67
|
+
export { createPhoneValidator, formatPhoneForDisplay, normalizeCountrylessPhoneNumber, normalizePhoneNumber };
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkEW5XR2X3_js = require('./chunk-EW5XR2X3.js');
|
|
4
|
+
var chunkQWKLQRBX_js = require('./chunk-QWKLQRBX.js');
|
|
5
|
+
var chunkKNGWHQLR_js = require('./chunk-KNGWHQLR.js');
|
|
6
|
+
var chunkHTSTPTNZ_js = require('./chunk-HTSTPTNZ.js');
|
|
7
|
+
var chunkV2UA2D4E_js = require('./chunk-V2UA2D4E.js');
|
|
8
|
+
var chunk5WATIVCA_js = require('./chunk-5WATIVCA.js');
|
|
9
|
+
var chunkSI34M4IC_js = require('./chunk-SI34M4IC.js');
|
|
10
|
+
var chunkYIP5FJ5H_js = require('./chunk-YIP5FJ5H.js');
|
|
11
|
+
var chunkZPFOKBIN_js = require('./chunk-ZPFOKBIN.js');
|
|
12
|
+
var chunkFDIAOFHS_js = require('./chunk-FDIAOFHS.js');
|
|
13
|
+
var chunkACKMC6FL_js = require('./chunk-ACKMC6FL.js');
|
|
14
|
+
var chunkE6JUYGJX_js = require('./chunk-E6JUYGJX.js');
|
|
15
|
+
var chunkQ4SZAMJT_js = require('./chunk-Q4SZAMJT.js');
|
|
16
|
+
var chunkEEH4XQ7W_js = require('./chunk-EEH4XQ7W.js');
|
|
17
|
+
var chunkYKWSHBT5_js = require('./chunk-YKWSHBT5.js');
|
|
18
|
+
var zod = require('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 zod.z.preprocess((val) => isEmptyValue(val) ? null : val, validator.nullish());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/validation/object/attribute-factory.ts
|
|
36
|
+
function createAttributeValidator(attr, messages = chunkYKWSHBT5_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
37
|
+
switch (attr.type) {
|
|
38
|
+
case "text":
|
|
39
|
+
return chunkZPFOKBIN_js.createTextValidator(attr, messages);
|
|
40
|
+
case "richtext":
|
|
41
|
+
return chunkEW5XR2X3_js.createRichtextValidator(attr, messages);
|
|
42
|
+
case "number":
|
|
43
|
+
return chunkYIP5FJ5H_js.createNumberValidator(attr, messages);
|
|
44
|
+
case "checkbox":
|
|
45
|
+
return chunk5WATIVCA_js.createCheckboxValidator(attr, messages);
|
|
46
|
+
case "date":
|
|
47
|
+
return chunkSI34M4IC_js.createDateValidator(attr, messages);
|
|
48
|
+
case "phone":
|
|
49
|
+
return chunkQ4SZAMJT_js.createPhoneValidator(attr, messages);
|
|
50
|
+
case "currency":
|
|
51
|
+
return chunkACKMC6FL_js.createCurrencyValidator(attr, messages);
|
|
52
|
+
case "status":
|
|
53
|
+
return chunkQWKLQRBX_js.createStatusValidator(attr, messages);
|
|
54
|
+
case "location":
|
|
55
|
+
return chunkE6JUYGJX_js.createLocationValidator(attr, messages);
|
|
56
|
+
case "select":
|
|
57
|
+
return chunkQWKLQRBX_js.createSelectValidator(attr, messages);
|
|
58
|
+
case "multiselect":
|
|
59
|
+
return chunkQWKLQRBX_js.createMultiselectValidator(attr, messages);
|
|
60
|
+
case "user":
|
|
61
|
+
return chunkKNGWHQLR_js.createUserValidator(attr, messages);
|
|
62
|
+
case "relation":
|
|
63
|
+
return chunkEEH4XQ7W_js.createRelationValidator(attr, messages);
|
|
64
|
+
case "formula":
|
|
65
|
+
return chunkHTSTPTNZ_js.createFormulaValidator(attr, messages);
|
|
66
|
+
case "rollup":
|
|
67
|
+
return chunkV2UA2D4E_js.createRollupValidator(attr, messages);
|
|
68
|
+
default:
|
|
69
|
+
return zod.z.unknown();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function createFormAttributeValidator(attr, messages = chunkYKWSHBT5_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
73
|
+
const validator = createAttributeValidator(attr, messages);
|
|
74
|
+
if (!attr.required) {
|
|
75
|
+
return withEmptyToNull(validator);
|
|
76
|
+
}
|
|
77
|
+
return validator;
|
|
78
|
+
}
|
|
79
|
+
var objectValidatorCache = /* @__PURE__ */ new WeakMap();
|
|
80
|
+
var draftValidatorCache = /* @__PURE__ */ new WeakMap();
|
|
81
|
+
function createObjectValidator(objectDef) {
|
|
82
|
+
const cached = objectValidatorCache.get(objectDef);
|
|
83
|
+
if (cached) return cached;
|
|
84
|
+
const shape = {};
|
|
85
|
+
for (const attr of objectDef.attributes) {
|
|
86
|
+
const validator = createAttributeValidator(attr);
|
|
87
|
+
shape[attr.name] = attr.required ? validator : withEmptyToNull(validator);
|
|
88
|
+
}
|
|
89
|
+
const schema = zod.z.object(shape).passthrough();
|
|
90
|
+
objectValidatorCache.set(objectDef, schema);
|
|
91
|
+
return schema;
|
|
92
|
+
}
|
|
93
|
+
function createDraftValidator(objectDef) {
|
|
94
|
+
const cached = draftValidatorCache.get(objectDef);
|
|
95
|
+
if (cached) return cached;
|
|
96
|
+
const shape = {};
|
|
97
|
+
for (const attr of objectDef.attributes) {
|
|
98
|
+
const validator = createAttributeValidator(attr);
|
|
99
|
+
shape[attr.name] = withEmptyToNull(validator);
|
|
100
|
+
}
|
|
101
|
+
const schema = zod.z.object(shape).passthrough();
|
|
102
|
+
draftValidatorCache.set(objectDef, schema);
|
|
103
|
+
return schema;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/validation/object/helpers.ts
|
|
107
|
+
function validateAttribute(attr, value) {
|
|
108
|
+
const validator = createAttributeValidator(attr);
|
|
109
|
+
if (!attr.required && (value === void 0 || value === null)) {
|
|
110
|
+
return { success: true, data: { [attr.name]: value } };
|
|
111
|
+
}
|
|
112
|
+
const result = validator.safeParse(value);
|
|
113
|
+
if (result.success) {
|
|
114
|
+
return {
|
|
115
|
+
success: true,
|
|
116
|
+
data: { [attr.name]: result.data }
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
success: false,
|
|
121
|
+
errors: chunkYKWSHBT5_js.formatZodErrors(result.error).map((err) => ({
|
|
122
|
+
path: [attr.name, ...err.path],
|
|
123
|
+
message: err.message
|
|
124
|
+
}))
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function validateObject(objectDef, data) {
|
|
128
|
+
const validator = createObjectValidator(objectDef);
|
|
129
|
+
const result = validator.safeParse(data);
|
|
130
|
+
if (result.success) {
|
|
131
|
+
return {
|
|
132
|
+
success: true,
|
|
133
|
+
data: result.data
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
success: false,
|
|
138
|
+
errors: chunkYKWSHBT5_js.formatZodErrors(result.error)
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function validateObjectOrThrow(objectDef, data) {
|
|
142
|
+
const result = validateObject(objectDef, data);
|
|
143
|
+
if (!result.success) {
|
|
144
|
+
const errors = result.errors ?? [];
|
|
145
|
+
const detail = errors.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
|
|
146
|
+
throw new chunkFDIAOFHS_js.ValidationError(
|
|
147
|
+
`Validation failed for ${objectDef.label}:
|
|
148
|
+
${detail}`,
|
|
149
|
+
errors.map((err) => ({ path: err.path, message: err.message }))
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
return result.data;
|
|
153
|
+
}
|
|
154
|
+
function validateDraft(objectDef, data) {
|
|
155
|
+
const validator = createDraftValidator(objectDef);
|
|
156
|
+
const result = validator.safeParse(data);
|
|
157
|
+
if (result.success) {
|
|
158
|
+
return {
|
|
159
|
+
success: true,
|
|
160
|
+
data: result.data
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
success: false,
|
|
165
|
+
errors: chunkYKWSHBT5_js.formatZodErrors(result.error)
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function validateDraftOrThrow(objectDef, data) {
|
|
169
|
+
const result = validateDraft(objectDef, data);
|
|
170
|
+
if (!result.success) {
|
|
171
|
+
const errors = result.errors ?? [];
|
|
172
|
+
const detail = errors.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
|
|
173
|
+
throw new chunkFDIAOFHS_js.ValidationError(
|
|
174
|
+
`Draft validation failed for ${objectDef.label}:
|
|
175
|
+
${detail}`,
|
|
176
|
+
errors.map((err) => ({ path: err.path, message: err.message }))
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
return result.data;
|
|
180
|
+
}
|
|
181
|
+
function rejectUnknownAttributesOrThrow(objectDef, data) {
|
|
182
|
+
const knownNames = new Set(objectDef.attributes.map((a) => a.name));
|
|
183
|
+
const unknownKeys = Object.keys(data).filter((key) => !knownNames.has(key));
|
|
184
|
+
if (unknownKeys.length > 0) {
|
|
185
|
+
throw new chunkFDIAOFHS_js.ValidationError(
|
|
186
|
+
`Unknown attribute${unknownKeys.length > 1 ? "s" : ""} for ${objectDef.label}: ${unknownKeys.join(", ")}`,
|
|
187
|
+
unknownKeys.map((key) => ({ path: [key], message: "Unknown attribute" }))
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function isValuePresent(value) {
|
|
192
|
+
if (value === void 0 || value === null) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
if (typeof value === "string" && value.trim() === "") {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
function getMissingRequiredAttributes(objectDef, data) {
|
|
201
|
+
const missing = [];
|
|
202
|
+
for (const attr of objectDef.attributes) {
|
|
203
|
+
if (attr.required && !isValuePresent(data[attr.name])) {
|
|
204
|
+
missing.push(attr);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return missing;
|
|
208
|
+
}
|
|
209
|
+
function isRecordComplete(objectDef, data) {
|
|
210
|
+
const missing = getMissingRequiredAttributes(objectDef, data);
|
|
211
|
+
if (missing.length > 0) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
const validation = validateObject(objectDef, data);
|
|
215
|
+
return validation.success;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
exports.createAttributeValidator = createAttributeValidator;
|
|
219
|
+
exports.createDraftValidator = createDraftValidator;
|
|
220
|
+
exports.createFormAttributeValidator = createFormAttributeValidator;
|
|
221
|
+
exports.createObjectValidator = createObjectValidator;
|
|
222
|
+
exports.getMissingRequiredAttributes = getMissingRequiredAttributes;
|
|
223
|
+
exports.isRecordComplete = isRecordComplete;
|
|
224
|
+
exports.rejectUnknownAttributesOrThrow = rejectUnknownAttributesOrThrow;
|
|
225
|
+
exports.validateAttribute = validateAttribute;
|
|
226
|
+
exports.validateDraft = validateDraft;
|
|
227
|
+
exports.validateDraftOrThrow = validateDraftOrThrow;
|
|
228
|
+
exports.validateObject = validateObject;
|
|
229
|
+
exports.validateObjectOrThrow = validateObjectOrThrow;
|
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
var chunkYKWSHBT5_js = require('./chunk-YKWSHBT5.js');
|
|
4
4
|
var zod = require('zod');
|
|
5
5
|
|
|
6
|
+
// src/lib/text-format.ts
|
|
7
|
+
var TEXT_FORMAT_PATTERNS = {
|
|
8
|
+
email: "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",
|
|
9
|
+
url: "^https?:\\/\\/[\\w\\-]+(\\.[\\w\\-]+)+[/#?]?.*$",
|
|
10
|
+
slug: "^[a-z0-9]+(?:-[a-z0-9]+)*$"
|
|
11
|
+
};
|
|
12
|
+
function resolveTextPattern(attr) {
|
|
13
|
+
if (attr.pattern) return attr.pattern;
|
|
14
|
+
return attr.format ? TEXT_FORMAT_PATTERNS[attr.format] : void 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
6
17
|
// src/lib/lru-cache.ts
|
|
7
18
|
var LRUCache = class {
|
|
8
19
|
constructor(capacity) {
|
|
@@ -66,13 +77,13 @@ function createTextValidator(attr, messages = chunkYKWSHBT5_js.DEFAULT_VALIDATIO
|
|
|
66
77
|
if (attr.maxLength !== void 0) {
|
|
67
78
|
schema = schema.max(attr.maxLength, messages.maxLength(attr, attr.maxLength));
|
|
68
79
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
messages.invalidPattern(attr)
|
|
73
|
-
);
|
|
80
|
+
const pattern = resolveTextPattern(attr);
|
|
81
|
+
if (pattern) {
|
|
82
|
+
schema = schema.regex(getCachedRegex(textRegexCache, pattern), messages.invalidPattern(attr));
|
|
74
83
|
}
|
|
75
84
|
return schema;
|
|
76
85
|
}
|
|
77
86
|
|
|
87
|
+
exports.TEXT_FORMAT_PATTERNS = TEXT_FORMAT_PATTERNS;
|
|
78
88
|
exports.createTextValidator = createTextValidator;
|
|
89
|
+
exports.resolveTextPattern = resolveTextPattern;
|