@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,107 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var chunkSI34M4IC_js = require('./chunk-SI34M4IC.js');
|
|
4
|
-
var chunkYIP5FJ5H_js = require('./chunk-YIP5FJ5H.js');
|
|
5
|
-
var chunkQAF3HNKQ_js = require('./chunk-QAF3HNKQ.js');
|
|
6
|
-
var chunkQWKLQRBX_js = require('./chunk-QWKLQRBX.js');
|
|
7
|
-
var chunkKNGWHQLR_js = require('./chunk-KNGWHQLR.js');
|
|
8
|
-
var chunkHTSTPTNZ_js = require('./chunk-HTSTPTNZ.js');
|
|
9
|
-
var chunkV2UA2D4E_js = require('./chunk-V2UA2D4E.js');
|
|
10
|
-
var chunk5WATIVCA_js = require('./chunk-5WATIVCA.js');
|
|
11
|
-
var chunkACKMC6FL_js = require('./chunk-ACKMC6FL.js');
|
|
12
|
-
var chunkE6JUYGJX_js = require('./chunk-E6JUYGJX.js');
|
|
13
|
-
var chunkEBGRZUIH_js = require('./chunk-EBGRZUIH.js');
|
|
14
|
-
var chunkEEH4XQ7W_js = require('./chunk-EEH4XQ7W.js');
|
|
15
|
-
var chunkEW5XR2X3_js = require('./chunk-EW5XR2X3.js');
|
|
16
|
-
var chunkYKWSHBT5_js = require('./chunk-YKWSHBT5.js');
|
|
17
|
-
var zod = require('zod');
|
|
18
|
-
|
|
19
|
-
function isEmptyValue(value) {
|
|
20
|
-
if (value === null || value === void 0) return true;
|
|
21
|
-
if (typeof value === "string" && value.trim() === "") return true;
|
|
22
|
-
if (value instanceof Date) return false;
|
|
23
|
-
if (typeof value === "object" && !Array.isArray(value)) {
|
|
24
|
-
return Object.values(value).every(
|
|
25
|
-
(v) => v === null || v === void 0 || typeof v === "string" && v.trim() === ""
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
function withEmptyToNull(validator) {
|
|
31
|
-
return zod.z.preprocess((val) => isEmptyValue(val) ? null : val, validator.nullish());
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// src/validation/object/attribute-factory.ts
|
|
35
|
-
function createAttributeValidator(attr, messages = chunkYKWSHBT5_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
36
|
-
switch (attr.type) {
|
|
37
|
-
case "text":
|
|
38
|
-
return chunkQAF3HNKQ_js.createTextValidator(attr, messages);
|
|
39
|
-
case "richtext":
|
|
40
|
-
return chunkEW5XR2X3_js.createRichtextValidator(attr, messages);
|
|
41
|
-
case "number":
|
|
42
|
-
return chunkYIP5FJ5H_js.createNumberValidator(attr, messages);
|
|
43
|
-
case "checkbox":
|
|
44
|
-
return chunk5WATIVCA_js.createCheckboxValidator(attr, messages);
|
|
45
|
-
case "date":
|
|
46
|
-
return chunkSI34M4IC_js.createDateValidator(attr, messages);
|
|
47
|
-
case "phone":
|
|
48
|
-
return chunkEBGRZUIH_js.createPhoneValidator(attr, messages);
|
|
49
|
-
case "currency":
|
|
50
|
-
return chunkACKMC6FL_js.createCurrencyValidator(attr, messages);
|
|
51
|
-
case "status":
|
|
52
|
-
return chunkQWKLQRBX_js.createStatusValidator(attr, messages);
|
|
53
|
-
case "location":
|
|
54
|
-
return chunkE6JUYGJX_js.createLocationValidator(attr, messages);
|
|
55
|
-
case "select":
|
|
56
|
-
return chunkQWKLQRBX_js.createSelectValidator(attr, messages);
|
|
57
|
-
case "multiselect":
|
|
58
|
-
return chunkQWKLQRBX_js.createMultiselectValidator(attr, messages);
|
|
59
|
-
case "user":
|
|
60
|
-
return chunkKNGWHQLR_js.createUserValidator(attr, messages);
|
|
61
|
-
case "relation":
|
|
62
|
-
return chunkEEH4XQ7W_js.createRelationValidator(attr, messages);
|
|
63
|
-
case "formula":
|
|
64
|
-
return chunkHTSTPTNZ_js.createFormulaValidator(attr, messages);
|
|
65
|
-
case "rollup":
|
|
66
|
-
return chunkV2UA2D4E_js.createRollupValidator(attr, messages);
|
|
67
|
-
default:
|
|
68
|
-
return zod.z.unknown();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
function createFormAttributeValidator(attr, messages = chunkYKWSHBT5_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
72
|
-
const validator = createAttributeValidator(attr, messages);
|
|
73
|
-
if (!attr.required) {
|
|
74
|
-
return withEmptyToNull(validator);
|
|
75
|
-
}
|
|
76
|
-
return validator;
|
|
77
|
-
}
|
|
78
|
-
var objectValidatorCache = /* @__PURE__ */ new WeakMap();
|
|
79
|
-
var draftValidatorCache = /* @__PURE__ */ new WeakMap();
|
|
80
|
-
function createObjectValidator(objectDef) {
|
|
81
|
-
const cached = objectValidatorCache.get(objectDef);
|
|
82
|
-
if (cached) return cached;
|
|
83
|
-
const shape = {};
|
|
84
|
-
for (const attr of objectDef.attributes) {
|
|
85
|
-
const validator = createAttributeValidator(attr);
|
|
86
|
-
shape[attr.name] = attr.required ? validator : withEmptyToNull(validator);
|
|
87
|
-
}
|
|
88
|
-
const schema = zod.z.object(shape).passthrough();
|
|
89
|
-
objectValidatorCache.set(objectDef, schema);
|
|
90
|
-
return schema;
|
|
91
|
-
}
|
|
92
|
-
function createDraftValidator(objectDef) {
|
|
93
|
-
const cached = draftValidatorCache.get(objectDef);
|
|
94
|
-
if (cached) return cached;
|
|
95
|
-
const shape = {};
|
|
96
|
-
for (const attr of objectDef.attributes) {
|
|
97
|
-
const validator = createAttributeValidator(attr);
|
|
98
|
-
shape[attr.name] = withEmptyToNull(validator);
|
|
99
|
-
}
|
|
100
|
-
const schema = zod.z.object(shape).passthrough();
|
|
101
|
-
draftValidatorCache.set(objectDef, schema);
|
|
102
|
-
return schema;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
3
|
// src/exceptions.ts
|
|
106
4
|
var SchemaErrorCode = {
|
|
107
5
|
// Generic
|
|
@@ -112,6 +10,7 @@ var SchemaErrorCode = {
|
|
|
112
10
|
RECORD_NOT_FOUND: "SCHEMA_RECORD_NOT_FOUND",
|
|
113
11
|
ROLE_NOT_FOUND: "SCHEMA_ROLE_NOT_FOUND",
|
|
114
12
|
MEMORY_NOT_FOUND: "SCHEMA_MEMORY_NOT_FOUND",
|
|
13
|
+
SCHEMA_PLAN_NOT_FOUND: "SCHEMA_PLAN_NOT_FOUND",
|
|
115
14
|
// Validation
|
|
116
15
|
VALIDATION_FAILED: "SCHEMA_VALIDATION_FAILED",
|
|
117
16
|
INVALID_ATTRIBUTE_NAME: "SCHEMA_INVALID_ATTRIBUTE_NAME",
|
|
@@ -224,7 +123,17 @@ var SchemaErrorCode = {
|
|
|
224
123
|
EMAIL_IMAGE_PROXY_UPSTREAM_FAILED: "EMAIL_IMAGE_PROXY_UPSTREAM_FAILED",
|
|
225
124
|
// Email provider sync — transport failures from Gmail / Microsoft Graph
|
|
226
125
|
EMAIL_PROVIDER_API_FAILED: "EMAIL_PROVIDER_API_FAILED",
|
|
227
|
-
EMAIL_BATCH_ITEM_FAILED: "EMAIL_BATCH_ITEM_FAILED"
|
|
126
|
+
EMAIL_BATCH_ITEM_FAILED: "EMAIL_BATCH_ITEM_FAILED",
|
|
127
|
+
// Reflexes — agent-authored deterministic automations
|
|
128
|
+
REFLEX_INVALID_TRANSITION: "REFLEX_INVALID_TRANSITION",
|
|
129
|
+
REFLEX_INVALID_TOKEN: "REFLEX_INVALID_TOKEN",
|
|
130
|
+
REFLEX_CAPABILITY_DENIED: "REFLEX_CAPABILITY_DENIED",
|
|
131
|
+
REFLEX_GATEWAY_UNAVAILABLE: "REFLEX_GATEWAY_UNAVAILABLE",
|
|
132
|
+
REFLEX_BUNDLE_FAILED: "REFLEX_BUNDLE_FAILED",
|
|
133
|
+
REFLEX_EGRESS_DENIED: "REFLEX_EGRESS_DENIED",
|
|
134
|
+
REFLEX_PROTOCOL_VIOLATION: "REFLEX_PROTOCOL_VIOLATION",
|
|
135
|
+
REFLEX_RUN_FAILED: "REFLEX_RUN_FAILED",
|
|
136
|
+
REFLEX_RUN_TIMEOUT: "REFLEX_RUN_TIMEOUT"
|
|
228
137
|
};
|
|
229
138
|
var SchemaError = class extends Error {
|
|
230
139
|
constructor(message, code = SchemaErrorCode.UNKNOWN, details) {
|
|
@@ -272,6 +181,12 @@ var RecordNotFoundError = class extends NotFoundError {
|
|
|
272
181
|
this.name = "RecordNotFoundError";
|
|
273
182
|
}
|
|
274
183
|
};
|
|
184
|
+
var SchemaPlanNotFoundError = class extends NotFoundError {
|
|
185
|
+
constructor(planId) {
|
|
186
|
+
super("Schema plan", planId, SchemaErrorCode.SCHEMA_PLAN_NOT_FOUND);
|
|
187
|
+
this.name = "SchemaPlanNotFoundError";
|
|
188
|
+
}
|
|
189
|
+
};
|
|
275
190
|
var ValidationError = class _ValidationError extends SchemaError {
|
|
276
191
|
constructor(message, errors) {
|
|
277
192
|
super(message, SchemaErrorCode.VALIDATION_FAILED, { errors });
|
|
@@ -372,19 +287,14 @@ var OrphanSystemAttributeError = class extends SchemaError {
|
|
|
372
287
|
var DestructiveSyncNotAllowedError = class extends SchemaError {
|
|
373
288
|
constructor(operations) {
|
|
374
289
|
const summary = operations.map((op) => {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
}
|
|
378
|
-
if (op.type === "remove_object") {
|
|
379
|
-
return "- remove_object";
|
|
380
|
-
}
|
|
381
|
-
return `- ${op.type}`;
|
|
290
|
+
const named = op;
|
|
291
|
+
return named.name ? `- ${op.type} "${named.name}"` : `- ${op.type}`;
|
|
382
292
|
}).join("\n");
|
|
383
293
|
super(
|
|
384
294
|
`Destructive schema operations detected (data will be lost):
|
|
385
295
|
${summary}
|
|
386
296
|
|
|
387
|
-
To
|
|
297
|
+
These are applied only under an explicit opt-in; without it boot demotes the object to runtime and keeps its rows. To let Standards apply them automatically, set the environment variable:
|
|
388
298
|
STANDARDS_ALLOW_DESTRUCTIVE_SYNC=1
|
|
389
299
|
|
|
390
300
|
Otherwise, revert your code changes or back up the data first.`,
|
|
@@ -600,118 +510,6 @@ function isObjectReferencedError(error) {
|
|
|
600
510
|
return error instanceof ObjectReferencedError;
|
|
601
511
|
}
|
|
602
512
|
|
|
603
|
-
// src/validation/object/helpers.ts
|
|
604
|
-
function validateAttribute(attr, value) {
|
|
605
|
-
const validator = createAttributeValidator(attr);
|
|
606
|
-
if (!attr.required && (value === void 0 || value === null)) {
|
|
607
|
-
return { success: true, data: { [attr.name]: value } };
|
|
608
|
-
}
|
|
609
|
-
const result = validator.safeParse(value);
|
|
610
|
-
if (result.success) {
|
|
611
|
-
return {
|
|
612
|
-
success: true,
|
|
613
|
-
data: { [attr.name]: result.data }
|
|
614
|
-
};
|
|
615
|
-
}
|
|
616
|
-
return {
|
|
617
|
-
success: false,
|
|
618
|
-
errors: chunkYKWSHBT5_js.formatZodErrors(result.error).map((err) => ({
|
|
619
|
-
path: [attr.name, ...err.path],
|
|
620
|
-
message: err.message
|
|
621
|
-
}))
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
function validateObject(objectDef, data) {
|
|
625
|
-
const validator = createObjectValidator(objectDef);
|
|
626
|
-
const result = validator.safeParse(data);
|
|
627
|
-
if (result.success) {
|
|
628
|
-
return {
|
|
629
|
-
success: true,
|
|
630
|
-
data: result.data
|
|
631
|
-
};
|
|
632
|
-
}
|
|
633
|
-
return {
|
|
634
|
-
success: false,
|
|
635
|
-
errors: chunkYKWSHBT5_js.formatZodErrors(result.error)
|
|
636
|
-
};
|
|
637
|
-
}
|
|
638
|
-
function validateObjectOrThrow(objectDef, data) {
|
|
639
|
-
const result = validateObject(objectDef, data);
|
|
640
|
-
if (!result.success) {
|
|
641
|
-
const errors = result.errors ?? [];
|
|
642
|
-
const detail = errors.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
|
|
643
|
-
throw new ValidationError(
|
|
644
|
-
`Validation failed for ${objectDef.label}:
|
|
645
|
-
${detail}`,
|
|
646
|
-
errors.map((err) => ({ path: err.path, message: err.message }))
|
|
647
|
-
);
|
|
648
|
-
}
|
|
649
|
-
return result.data;
|
|
650
|
-
}
|
|
651
|
-
function validateDraft(objectDef, data) {
|
|
652
|
-
const validator = createDraftValidator(objectDef);
|
|
653
|
-
const result = validator.safeParse(data);
|
|
654
|
-
if (result.success) {
|
|
655
|
-
return {
|
|
656
|
-
success: true,
|
|
657
|
-
data: result.data
|
|
658
|
-
};
|
|
659
|
-
}
|
|
660
|
-
return {
|
|
661
|
-
success: false,
|
|
662
|
-
errors: chunkYKWSHBT5_js.formatZodErrors(result.error)
|
|
663
|
-
};
|
|
664
|
-
}
|
|
665
|
-
function validateDraftOrThrow(objectDef, data) {
|
|
666
|
-
const result = validateDraft(objectDef, data);
|
|
667
|
-
if (!result.success) {
|
|
668
|
-
const errors = result.errors ?? [];
|
|
669
|
-
const detail = errors.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
|
|
670
|
-
throw new ValidationError(
|
|
671
|
-
`Draft validation failed for ${objectDef.label}:
|
|
672
|
-
${detail}`,
|
|
673
|
-
errors.map((err) => ({ path: err.path, message: err.message }))
|
|
674
|
-
);
|
|
675
|
-
}
|
|
676
|
-
return result.data;
|
|
677
|
-
}
|
|
678
|
-
function rejectUnknownAttributesOrThrow(objectDef, data) {
|
|
679
|
-
const knownNames = new Set(objectDef.attributes.map((a) => a.name));
|
|
680
|
-
const unknownKeys = Object.keys(data).filter((key) => !knownNames.has(key));
|
|
681
|
-
if (unknownKeys.length > 0) {
|
|
682
|
-
throw new ValidationError(
|
|
683
|
-
`Unknown attribute${unknownKeys.length > 1 ? "s" : ""} for ${objectDef.label}: ${unknownKeys.join(", ")}`,
|
|
684
|
-
unknownKeys.map((key) => ({ path: [key], message: "Unknown attribute" }))
|
|
685
|
-
);
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
function isValuePresent(value) {
|
|
689
|
-
if (value === void 0 || value === null) {
|
|
690
|
-
return false;
|
|
691
|
-
}
|
|
692
|
-
if (typeof value === "string" && value.trim() === "") {
|
|
693
|
-
return false;
|
|
694
|
-
}
|
|
695
|
-
return true;
|
|
696
|
-
}
|
|
697
|
-
function getMissingRequiredAttributes(objectDef, data) {
|
|
698
|
-
const missing = [];
|
|
699
|
-
for (const attr of objectDef.attributes) {
|
|
700
|
-
if (attr.required && !isValuePresent(data[attr.name])) {
|
|
701
|
-
missing.push(attr);
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
return missing;
|
|
705
|
-
}
|
|
706
|
-
function isRecordComplete(objectDef, data) {
|
|
707
|
-
const missing = getMissingRequiredAttributes(objectDef, data);
|
|
708
|
-
if (missing.length > 0) {
|
|
709
|
-
return false;
|
|
710
|
-
}
|
|
711
|
-
const validation = validateObject(objectDef, data);
|
|
712
|
-
return validation.success;
|
|
713
|
-
}
|
|
714
|
-
|
|
715
513
|
exports.AccessDeniedError = AccessDeniedError;
|
|
716
514
|
exports.AttributeInUseError = AttributeInUseError;
|
|
717
515
|
exports.AttributeNotFoundError = AttributeNotFoundError;
|
|
@@ -735,6 +533,7 @@ exports.RepositoryError = RepositoryError;
|
|
|
735
533
|
exports.RoleNotFoundError = RoleNotFoundError;
|
|
736
534
|
exports.SchemaError = SchemaError;
|
|
737
535
|
exports.SchemaErrorCode = SchemaErrorCode;
|
|
536
|
+
exports.SchemaPlanNotFoundError = SchemaPlanNotFoundError;
|
|
738
537
|
exports.SearchBackendError = SearchBackendError;
|
|
739
538
|
exports.StorageError = StorageError;
|
|
740
539
|
exports.SyncCascadeError = SyncCascadeError;
|
|
@@ -742,22 +541,10 @@ exports.SyncConflictError = SyncConflictError;
|
|
|
742
541
|
exports.SyncError = SyncError;
|
|
743
542
|
exports.SystemEntityImmutableError = SystemEntityImmutableError;
|
|
744
543
|
exports.ValidationError = ValidationError;
|
|
745
|
-
exports.createAttributeValidator = createAttributeValidator;
|
|
746
|
-
exports.createDraftValidator = createDraftValidator;
|
|
747
|
-
exports.createFormAttributeValidator = createFormAttributeValidator;
|
|
748
|
-
exports.createObjectValidator = createObjectValidator;
|
|
749
|
-
exports.getMissingRequiredAttributes = getMissingRequiredAttributes;
|
|
750
544
|
exports.isAttributeInUseError = isAttributeInUseError;
|
|
751
545
|
exports.isNotFoundError = isNotFoundError;
|
|
752
546
|
exports.isObjectReferencedError = isObjectReferencedError;
|
|
753
547
|
exports.isProtectedResourceError = isProtectedResourceError;
|
|
754
|
-
exports.isRecordComplete = isRecordComplete;
|
|
755
548
|
exports.isRecordReferencedError = isRecordReferencedError;
|
|
756
549
|
exports.isSchemaError = isSchemaError;
|
|
757
550
|
exports.isValidationError = isValidationError;
|
|
758
|
-
exports.rejectUnknownAttributesOrThrow = rejectUnknownAttributesOrThrow;
|
|
759
|
-
exports.validateAttribute = validateAttribute;
|
|
760
|
-
exports.validateDraft = validateDraft;
|
|
761
|
-
exports.validateDraftOrThrow = validateDraftOrThrow;
|
|
762
|
-
exports.validateObject = validateObject;
|
|
763
|
-
exports.validateObjectOrThrow = validateObjectOrThrow;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { ValidationError } from './chunk-POULKEJM.mjs';
|
|
1
2
|
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
// src/validation/config/schemas.ts
|
|
3
|
+
import { ICONS, COLORS } from '@stndrds/constants';
|
|
4
4
|
|
|
5
5
|
// src/computed/parser.ts
|
|
6
6
|
var ComputedFormulaParseError = class extends Error {
|
|
@@ -306,6 +306,39 @@ function getOperatorPrecedence(operator) {
|
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
308
|
|
|
309
|
+
// src/validation/limits.ts
|
|
310
|
+
var SCHEMA_LIMITS = {
|
|
311
|
+
attributesPerObject: 300,
|
|
312
|
+
tabsPerView: 24,
|
|
313
|
+
groupsPerFormTab: 12,
|
|
314
|
+
fieldsPerGroup: 60,
|
|
315
|
+
fieldsPerFormTab: 150,
|
|
316
|
+
columnsPerTab: 50,
|
|
317
|
+
optionsPerAttribute: 200,
|
|
318
|
+
sidePanelAttributes: 100,
|
|
319
|
+
filterRulesPerTab: 50,
|
|
320
|
+
sortsPerTab: 20,
|
|
321
|
+
emailAttributesPerTab: 30,
|
|
322
|
+
objectsPerPlan: 20,
|
|
323
|
+
mutationsPerPlan: 500,
|
|
324
|
+
planBytes: 512 * 1024,
|
|
325
|
+
historyDefault: 20,
|
|
326
|
+
historyMax: 50,
|
|
327
|
+
iconQueries: 5,
|
|
328
|
+
iconResults: 20
|
|
329
|
+
};
|
|
330
|
+
var COLOR_IDS = Object.keys(COLORS);
|
|
331
|
+
var ICON_NAMES = new Set(ICONS);
|
|
332
|
+
var colorIdSchema = z.enum(COLOR_IDS);
|
|
333
|
+
var iconNameSchema = z.string().superRefine((value, ctx) => {
|
|
334
|
+
if (!ICON_NAMES.has(value)) {
|
|
335
|
+
ctx.addIssue({
|
|
336
|
+
code: "custom",
|
|
337
|
+
message: "Invalid icon name"
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
}).transform((value) => value);
|
|
341
|
+
|
|
309
342
|
// src/validation/config/schemas.ts
|
|
310
343
|
var baseConfigSchema = z.object({
|
|
311
344
|
placeholder: z.string().optional(),
|
|
@@ -318,14 +351,25 @@ var baseConfigSchema = z.object({
|
|
|
318
351
|
deprecated: z.boolean().optional(),
|
|
319
352
|
metadata: z.record(z.string(), z.unknown()).optional()
|
|
320
353
|
});
|
|
321
|
-
var
|
|
354
|
+
var optionBaseSchema = z.object({
|
|
322
355
|
value: z.string().min(1),
|
|
323
356
|
label: z.string().min(1),
|
|
324
|
-
color: z.string().optional(),
|
|
325
357
|
description: z.string().optional(),
|
|
326
|
-
group: z.enum(["idle", "in_progress", "finished"]).optional(),
|
|
327
358
|
inverse: z.string().optional(),
|
|
328
359
|
archived: z.boolean().optional()
|
|
360
|
+
});
|
|
361
|
+
var statusGroupSchema = z.enum(["idle", "in_progress", "finished"]);
|
|
362
|
+
var selectOptionWriteSchema = optionBaseSchema.extend({
|
|
363
|
+
color: colorIdSchema
|
|
364
|
+
}).strict();
|
|
365
|
+
var multiselectOptionWriteSchema = selectOptionWriteSchema;
|
|
366
|
+
var statusOptionWriteSchema = optionBaseSchema.extend({
|
|
367
|
+
color: colorIdSchema,
|
|
368
|
+
group: statusGroupSchema
|
|
369
|
+
}).strict();
|
|
370
|
+
var optionSchema = optionBaseSchema.extend({
|
|
371
|
+
color: z.string().optional(),
|
|
372
|
+
group: statusGroupSchema.optional()
|
|
329
373
|
}).strict();
|
|
330
374
|
var optionsArraySchema = z.array(optionSchema).min(1).refine(
|
|
331
375
|
(options) => {
|
|
@@ -334,6 +378,18 @@ var optionsArraySchema = z.array(optionSchema).min(1).refine(
|
|
|
334
378
|
},
|
|
335
379
|
{ message: "Duplicate option values are not allowed" }
|
|
336
380
|
);
|
|
381
|
+
function writeOptionsArraySchema(option) {
|
|
382
|
+
return z.array(option).min(1).max(SCHEMA_LIMITS.optionsPerAttribute).refine(
|
|
383
|
+
(options) => {
|
|
384
|
+
const values = options.map((candidate) => candidate.value);
|
|
385
|
+
return new Set(values).size === values.length;
|
|
386
|
+
},
|
|
387
|
+
{ message: "Duplicate option values are not allowed" }
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
var selectOptionsWriteSchema = writeOptionsArraySchema(selectOptionWriteSchema);
|
|
391
|
+
var multiselectOptionsWriteSchema = writeOptionsArraySchema(multiselectOptionWriteSchema);
|
|
392
|
+
var statusOptionsWriteSchema = writeOptionsArraySchema(statusOptionWriteSchema);
|
|
337
393
|
var relationTargetSchema = z.object({
|
|
338
394
|
object: z.string().min(1),
|
|
339
395
|
displayTemplate: z.string().optional(),
|
|
@@ -369,7 +425,10 @@ var checkboxConfigSchema = baseConfigSchema;
|
|
|
369
425
|
var dateConfigSchema = baseConfigSchema.extend({
|
|
370
426
|
dateFormat: z.enum(["short", "long", "full", "relative"]).optional(),
|
|
371
427
|
minDate: z.string().optional(),
|
|
372
|
-
maxDate: z.string().optional()
|
|
428
|
+
maxDate: z.string().optional(),
|
|
429
|
+
includeTime: z.boolean().optional(),
|
|
430
|
+
endDate: z.boolean().optional(),
|
|
431
|
+
timeFormat: z.enum(["12h", "24h"]).optional()
|
|
373
432
|
});
|
|
374
433
|
var phoneConfigSchema = baseConfigSchema.extend({
|
|
375
434
|
defaultCountryCode: z.string().length(3).optional()
|
|
@@ -388,10 +447,12 @@ var locationConfigSchema = baseConfigSchema.extend({
|
|
|
388
447
|
allowedCountries: z.array(z.string().length(3)).optional()
|
|
389
448
|
});
|
|
390
449
|
var selectConfigSchema = baseConfigSchema.extend({
|
|
391
|
-
options: optionsArraySchema
|
|
450
|
+
options: optionsArraySchema,
|
|
451
|
+
renderAs: z.literal("badges").optional()
|
|
392
452
|
});
|
|
393
453
|
var multiselectConfigSchema = baseConfigSchema.extend({
|
|
394
|
-
options: optionsArraySchema
|
|
454
|
+
options: optionsArraySchema,
|
|
455
|
+
renderAs: z.literal("badges").optional()
|
|
395
456
|
});
|
|
396
457
|
var userConfigSchema = baseConfigSchema.extend({
|
|
397
458
|
types: z.array(z.enum(["user", "agent"])).min(1).optional(),
|
|
@@ -492,5 +553,85 @@ function parseAttributeConfig(type, config) {
|
|
|
492
553
|
const schema = getAttributeConfigSchema(type);
|
|
493
554
|
return schema.strip().parse(config);
|
|
494
555
|
}
|
|
556
|
+
function getAttributeConfigWriteSchema(type) {
|
|
557
|
+
const schema = getAttributeConfigSchema(type).extend({
|
|
558
|
+
icon: iconNameSchema.optional()
|
|
559
|
+
});
|
|
560
|
+
switch (type) {
|
|
561
|
+
case "select":
|
|
562
|
+
return schema.extend({ options: selectOptionsWriteSchema });
|
|
563
|
+
case "multiselect":
|
|
564
|
+
return schema.extend({ options: multiselectOptionsWriteSchema });
|
|
565
|
+
case "status":
|
|
566
|
+
return schema.extend({ options: statusOptionsWriteSchema });
|
|
567
|
+
default:
|
|
568
|
+
return schema;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
function validationErrorFromIssues(issues) {
|
|
572
|
+
return ValidationError.fromZodErrors(
|
|
573
|
+
issues.map((issue) => ({
|
|
574
|
+
path: issue.path.map((segment) => typeof segment === "symbol" ? String(segment) : segment),
|
|
575
|
+
message: issue.message
|
|
576
|
+
}))
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
function parseWriteSchema(type, input) {
|
|
580
|
+
const result = getAttributeConfigWriteSchema(type).strip().safeParse(input);
|
|
581
|
+
if (!result.success) {
|
|
582
|
+
throw validationErrorFromIssues(result.error.issues);
|
|
583
|
+
}
|
|
584
|
+
return result.data;
|
|
585
|
+
}
|
|
586
|
+
function parseAttributeConfigForCreate(type, input) {
|
|
587
|
+
return parseWriteSchema(type, input);
|
|
588
|
+
}
|
|
589
|
+
function validatePatchedIcon(patch) {
|
|
590
|
+
if (!Object.prototype.hasOwnProperty.call(patch, "icon")) {
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
const result = iconNameSchema.optional().safeParse(patch.icon);
|
|
594
|
+
if (!result.success) {
|
|
595
|
+
throw ValidationError.fromZodErrors(
|
|
596
|
+
result.error.issues.map((issue) => ({
|
|
597
|
+
path: [
|
|
598
|
+
"icon",
|
|
599
|
+
...issue.path.map((segment) => typeof segment === "symbol" ? String(segment) : segment)
|
|
600
|
+
],
|
|
601
|
+
message: issue.message
|
|
602
|
+
}))
|
|
603
|
+
);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
function isSelectLike(type) {
|
|
607
|
+
return type === "select" || type === "multiselect" || type === "status";
|
|
608
|
+
}
|
|
609
|
+
function parseAttributeConfigForUpdate(stored, patch) {
|
|
610
|
+
const ownsOptions = Object.prototype.hasOwnProperty.call(patch, "options");
|
|
611
|
+
const ownsIcon = Object.prototype.hasOwnProperty.call(patch, "icon");
|
|
612
|
+
const input = { ...stored, ...patch };
|
|
613
|
+
validatePatchedIcon(patch);
|
|
614
|
+
if (ownsOptions) {
|
|
615
|
+
const { icon: storedIcon, ...inputWithoutStoredIcon } = input;
|
|
616
|
+
const parsed2 = parseWriteSchema(stored.type, ownsIcon ? input : inputWithoutStoredIcon);
|
|
617
|
+
if (!ownsIcon && storedIcon !== void 0) {
|
|
618
|
+
parsed2.icon = storedIcon;
|
|
619
|
+
}
|
|
620
|
+
return parsed2;
|
|
621
|
+
}
|
|
622
|
+
const storedOptions = stored.options;
|
|
623
|
+
if (isSelectLike(stored.type)) {
|
|
624
|
+
input.options = [{ value: "__legacy__", label: "__legacy__" }];
|
|
625
|
+
}
|
|
626
|
+
const result = getAttributeConfigSchema(stored.type).strip().safeParse(input);
|
|
627
|
+
if (!result.success) {
|
|
628
|
+
throw validationErrorFromIssues(result.error.issues);
|
|
629
|
+
}
|
|
630
|
+
const parsed = result.data;
|
|
631
|
+
if (isSelectLike(stored.type)) {
|
|
632
|
+
parsed.options = storedOptions;
|
|
633
|
+
}
|
|
634
|
+
return parsed;
|
|
635
|
+
}
|
|
495
636
|
|
|
496
|
-
export { ComputedFormulaParseError, attributeConfigSchemas, getAttributeConfigSchema, parseAttributeConfig, parseComputedFormula };
|
|
637
|
+
export { ComputedFormulaParseError, SCHEMA_LIMITS, attributeConfigSchemas, colorIdSchema, getAttributeConfigSchema, iconNameSchema, multiselectOptionWriteSchema, parseAttributeConfig, parseAttributeConfigForCreate, parseAttributeConfigForUpdate, parseComputedFormula, selectOptionWriteSchema, statusGroupSchema, statusOptionWriteSchema };
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-HRQEZUAA.mjs';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
|
+
// src/lib/text-format.ts
|
|
5
|
+
var TEXT_FORMAT_PATTERNS = {
|
|
6
|
+
email: "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",
|
|
7
|
+
url: "^https?:\\/\\/[\\w\\-]+(\\.[\\w\\-]+)+[/#?]?.*$",
|
|
8
|
+
slug: "^[a-z0-9]+(?:-[a-z0-9]+)*$"
|
|
9
|
+
};
|
|
10
|
+
function resolveTextPattern(attr) {
|
|
11
|
+
if (attr.pattern) return attr.pattern;
|
|
12
|
+
return attr.format ? TEXT_FORMAT_PATTERNS[attr.format] : void 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
4
15
|
// src/lib/lru-cache.ts
|
|
5
16
|
var LRUCache = class {
|
|
6
17
|
constructor(capacity) {
|
|
@@ -64,13 +75,11 @@ function createTextValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
|
64
75
|
if (attr.maxLength !== void 0) {
|
|
65
76
|
schema = schema.max(attr.maxLength, messages.maxLength(attr, attr.maxLength));
|
|
66
77
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
messages.invalidPattern(attr)
|
|
71
|
-
);
|
|
78
|
+
const pattern = resolveTextPattern(attr);
|
|
79
|
+
if (pattern) {
|
|
80
|
+
schema = schema.regex(getCachedRegex(textRegexCache, pattern), messages.invalidPattern(attr));
|
|
72
81
|
}
|
|
73
82
|
return schema;
|
|
74
83
|
}
|
|
75
84
|
|
|
76
|
-
export { createTextValidator };
|
|
85
|
+
export { TEXT_FORMAT_PATTERNS, createTextValidator, resolveTextPattern };
|