@stndrds/schema 1.0.0-alpha.263 → 1.0.0-alpha.265
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-_6tvjbyl.d.ts → attributes-_b3Db8vT.d.ts} +1 -23
- package/dist/{attributes-Cmkc7UgJ.d.mts → attributes-lBLiOIY3.d.mts} +1 -23
- package/dist/chunk-NGGU6BSN.mjs +216 -0
- package/dist/chunk-NI3HCSYH.js +229 -0
- package/dist/{chunk-54WDPQ6R.mjs → chunk-QIWADKYA.mjs} +12 -216
- package/dist/{chunk-TS3PJOMZ.js → chunk-ZBQEMIAV.js} +11 -227
- package/dist/exceptions.d.mts +458 -0
- package/dist/exceptions.d.ts +458 -0
- package/dist/exceptions.js +154 -0
- package/dist/exceptions.mjs +1 -0
- package/dist/{helpers-BTC6TsKH.d.ts → helpers-eyrnPJEF.d.ts} +4 -39
- package/dist/{helpers-BO10yqih.d.mts → helpers-uKLet0kF.d.mts} +4 -39
- package/dist/index.d.mts +150 -476
- package/dist/index.d.ts +150 -476
- package/dist/index.js +238 -139
- package/dist/index.mjs +131 -35
- package/dist/migrations-BXd2ZGfM.d.mts +39 -0
- package/dist/migrations-DcuJZ8qO.d.ts +39 -0
- package/dist/{types-CVswgCx9.d.mts → types-DNz3ITS-.d.mts} +1 -1
- package/dist/{types-B_UZK_6m.d.ts → types-DqLi1tx1.d.ts} +1 -1
- package/dist/validation/all.d.mts +4 -3
- package/dist/validation/all.d.ts +4 -3
- package/dist/validation/all.js +10 -9
- package/dist/validation/all.mjs +4 -3
- 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/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 +1 -1
- package/dist/validation/config/index.d.ts +1 -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 +16 -15
- package/dist/validation/object/index.mjs +4 -3
- 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/package.json +7 -2
|
@@ -80,26 +80,6 @@ interface ComputedPlan {
|
|
|
80
80
|
ast?: ComputedFormulaAstNode;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
/**
|
|
84
|
-
* Configuration for AI autofill on an attribute or qualified property.
|
|
85
|
-
*/
|
|
86
|
-
interface AutofillConfig {
|
|
87
|
-
/**
|
|
88
|
-
* Source attribute names (same object) whose changes can trigger a
|
|
89
|
-
* contextual fill of this field. Empty array = document-only: the field
|
|
90
|
-
* is filled exclusively from attached document OCR content.
|
|
91
|
-
*/
|
|
92
|
-
from: string[];
|
|
93
|
-
/** Optional hint injected verbatim into the generation prompt for this field. */
|
|
94
|
-
instructions?: string;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Attribute types eligible for autofill.
|
|
98
|
-
* `location` is deferred: its value shape is too complex for v1 extraction.
|
|
99
|
-
*/
|
|
100
|
-
declare const AUTOFILL_ELIGIBLE_TYPES: readonly ["text", "number", "checkbox", "date", "phone", "currency", "status", "select", "multiselect"];
|
|
101
|
-
type AutofillEligibleType = (typeof AUTOFILL_ELIGIBLE_TYPES)[number];
|
|
102
|
-
|
|
103
83
|
/**
|
|
104
84
|
* Allowed attribute types in .qualifyWith()
|
|
105
85
|
*
|
|
@@ -211,8 +191,6 @@ interface BaseAttribute<DefaultValueType = unknown> {
|
|
|
211
191
|
system?: boolean;
|
|
212
192
|
unique?: boolean;
|
|
213
193
|
metadata?: Record<string, unknown>;
|
|
214
|
-
/** AI autofill configuration. Absent = field is never autofilled. */
|
|
215
|
-
autofill?: AutofillConfig;
|
|
216
194
|
}
|
|
217
195
|
interface TextAttribute extends BaseAttribute<string> {
|
|
218
196
|
type: "text";
|
|
@@ -602,4 +580,4 @@ declare function isAttributeSortable(attr: {
|
|
|
602
580
|
type: AttributeType;
|
|
603
581
|
}): boolean;
|
|
604
582
|
|
|
605
|
-
export { type
|
|
583
|
+
export { type OptionPropertyAttribute as $, type Attribute as A, type BilateralConfig as B, type CurrencyAttribute as C, type DateAttribute as D, type AttributeGroup as E, type FormulaAttribute as F, type BaseAttribute as G, type ComputedFieldKind as H, type ComputedFormulaBinaryNode as I, type ComputedFormulaBinaryOperator as J, type ComputedFormulaCallNode as K, type LocationAttribute as L, type MultiRelationAttribute as M, type NumberAttribute as N, type Option as O, type PhoneAttribute as P, type ComputedFormulaLiteralNode as Q, type RelationAttribute as R, type SingleRelationAttribute as S, type TextAttribute as T, type UserAttribute as U, ComputedFormulaParseError as V, type ComputedFormulaPathNode as W, type ComputedStateStatus as X, type DateFormat as Y, type DateValue as Z, type NumberUnit as _, type RichtextAttribute as a, type PropertyAttribute as a0, type PropertyType as a1, RELATION_TARGET_ANY as a2, type RichTextAttribute as a3, type StatusGroup as a4, hasOptions as a5, inferInverseCardinality as a6, isAttributeSortable as a7, isBilateralRelation as a8, isUniversalRelation as a9, parseComputedFormula as aa, resolvePropertyDefinitions as ab, type MultiselectAttribute as b, type SelectAttribute as c, type StatusAttribute as d, type RollupAttribute as e, type AttributeType as f, type CheckboxAttribute as g, type ComputedAttributeState as h, type ComputedValueType as i, type ComputedReturnType as j, type ComputedOptionsSource as k, type ComputedDependency as l, type ComputedPlan as m, type ComputedFormulaAstNode as n, type LocationGranularity as o, type Location as p, type DateRangeValue as q, type DocumentAttribute as r, type Phone as s, type Currency as t, type PropertySchema as u, type TimeFormat as v, type FormulaReturnType as w, type RelationTarget as x, type RollupFunction as y, type UserReferenceType as z };
|
|
@@ -80,26 +80,6 @@ interface ComputedPlan {
|
|
|
80
80
|
ast?: ComputedFormulaAstNode;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
/**
|
|
84
|
-
* Configuration for AI autofill on an attribute or qualified property.
|
|
85
|
-
*/
|
|
86
|
-
interface AutofillConfig {
|
|
87
|
-
/**
|
|
88
|
-
* Source attribute names (same object) whose changes can trigger a
|
|
89
|
-
* contextual fill of this field. Empty array = document-only: the field
|
|
90
|
-
* is filled exclusively from attached document OCR content.
|
|
91
|
-
*/
|
|
92
|
-
from: string[];
|
|
93
|
-
/** Optional hint injected verbatim into the generation prompt for this field. */
|
|
94
|
-
instructions?: string;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Attribute types eligible for autofill.
|
|
98
|
-
* `location` is deferred: its value shape is too complex for v1 extraction.
|
|
99
|
-
*/
|
|
100
|
-
declare const AUTOFILL_ELIGIBLE_TYPES: readonly ["text", "number", "checkbox", "date", "phone", "currency", "status", "select", "multiselect"];
|
|
101
|
-
type AutofillEligibleType = (typeof AUTOFILL_ELIGIBLE_TYPES)[number];
|
|
102
|
-
|
|
103
83
|
/**
|
|
104
84
|
* Allowed attribute types in .qualifyWith()
|
|
105
85
|
*
|
|
@@ -211,8 +191,6 @@ interface BaseAttribute<DefaultValueType = unknown> {
|
|
|
211
191
|
system?: boolean;
|
|
212
192
|
unique?: boolean;
|
|
213
193
|
metadata?: Record<string, unknown>;
|
|
214
|
-
/** AI autofill configuration. Absent = field is never autofilled. */
|
|
215
|
-
autofill?: AutofillConfig;
|
|
216
194
|
}
|
|
217
195
|
interface TextAttribute extends BaseAttribute<string> {
|
|
218
196
|
type: "text";
|
|
@@ -602,4 +580,4 @@ declare function isAttributeSortable(attr: {
|
|
|
602
580
|
type: AttributeType;
|
|
603
581
|
}): boolean;
|
|
604
582
|
|
|
605
|
-
export { type
|
|
583
|
+
export { type OptionPropertyAttribute as $, type Attribute as A, type BilateralConfig as B, type CurrencyAttribute as C, type DateAttribute as D, type AttributeGroup as E, type FormulaAttribute as F, type BaseAttribute as G, type ComputedFieldKind as H, type ComputedFormulaBinaryNode as I, type ComputedFormulaBinaryOperator as J, type ComputedFormulaCallNode as K, type LocationAttribute as L, type MultiRelationAttribute as M, type NumberAttribute as N, type Option as O, type PhoneAttribute as P, type ComputedFormulaLiteralNode as Q, type RelationAttribute as R, type SingleRelationAttribute as S, type TextAttribute as T, type UserAttribute as U, ComputedFormulaParseError as V, type ComputedFormulaPathNode as W, type ComputedStateStatus as X, type DateFormat as Y, type DateValue as Z, type NumberUnit as _, type RichtextAttribute as a, type PropertyAttribute as a0, type PropertyType as a1, RELATION_TARGET_ANY as a2, type RichTextAttribute as a3, type StatusGroup as a4, hasOptions as a5, inferInverseCardinality as a6, isAttributeSortable as a7, isBilateralRelation as a8, isUniversalRelation as a9, parseComputedFormula as aa, resolvePropertyDefinitions as ab, type MultiselectAttribute as b, type SelectAttribute as c, type StatusAttribute as d, type RollupAttribute as e, type AttributeType as f, type CheckboxAttribute as g, type ComputedAttributeState as h, type ComputedValueType as i, type ComputedReturnType as j, type ComputedOptionsSource as k, type ComputedDependency as l, type ComputedPlan as m, type ComputedFormulaAstNode as n, type LocationGranularity as o, type Location as p, type DateRangeValue as q, type DocumentAttribute as r, type Phone as s, type Currency as t, type PropertySchema as u, type TimeFormat as v, type FormulaReturnType as w, type RelationTarget as x, type RollupFunction as y, type UserReferenceType as z };
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { createCheckboxValidator } from './chunk-OSSGN43B.mjs';
|
|
2
|
+
import { createDateValidator } from './chunk-Q44QKLN4.mjs';
|
|
3
|
+
import { createNumberValidator } from './chunk-UANQJ2GH.mjs';
|
|
4
|
+
import { createTextValidator } from './chunk-U36ZIBEM.mjs';
|
|
5
|
+
import { createRichtextValidator } from './chunk-QVLQPW3O.mjs';
|
|
6
|
+
import { createMultiselectValidator, createSelectValidator, createStatusValidator } from './chunk-ZDQ5AP26.mjs';
|
|
7
|
+
import { createUserValidator } from './chunk-LV3FEUKU.mjs';
|
|
8
|
+
import { createFormulaValidator } from './chunk-UXAHLSWC.mjs';
|
|
9
|
+
import { createRollupValidator } from './chunk-NS63SPNN.mjs';
|
|
10
|
+
import { ValidationError } from './chunk-QIWADKYA.mjs';
|
|
11
|
+
import { createCurrencyValidator } from './chunk-AYVHMVKQ.mjs';
|
|
12
|
+
import { createLocationValidator } from './chunk-YUFTHPOE.mjs';
|
|
13
|
+
import { createPhoneValidator } from './chunk-JUKLL5RJ.mjs';
|
|
14
|
+
import { createRelationValidator } from './chunk-GO6LQADH.mjs';
|
|
15
|
+
import { DEFAULT_VALIDATION_MESSAGES, formatZodErrors } from './chunk-HRQEZUAA.mjs';
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
|
|
18
|
+
function isEmptyValue(value) {
|
|
19
|
+
if (value === null || value === void 0) return true;
|
|
20
|
+
if (typeof value === "string" && value.trim() === "") return true;
|
|
21
|
+
if (value instanceof Date) return false;
|
|
22
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
23
|
+
return Object.values(value).every(
|
|
24
|
+
(v) => v === null || v === void 0 || typeof v === "string" && v.trim() === ""
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
function withEmptyToNull(validator) {
|
|
30
|
+
return z.preprocess((val) => isEmptyValue(val) ? null : val, validator.nullish());
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/validation/object/attribute-factory.ts
|
|
34
|
+
function createAttributeValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
35
|
+
switch (attr.type) {
|
|
36
|
+
case "text":
|
|
37
|
+
return createTextValidator(attr, messages);
|
|
38
|
+
case "richtext":
|
|
39
|
+
return createRichtextValidator(attr, messages);
|
|
40
|
+
case "number":
|
|
41
|
+
return createNumberValidator(attr, messages);
|
|
42
|
+
case "checkbox":
|
|
43
|
+
return createCheckboxValidator(attr, messages);
|
|
44
|
+
case "date":
|
|
45
|
+
return createDateValidator(attr, messages);
|
|
46
|
+
case "phone":
|
|
47
|
+
return createPhoneValidator(attr, messages);
|
|
48
|
+
case "currency":
|
|
49
|
+
return createCurrencyValidator(attr, messages);
|
|
50
|
+
case "status":
|
|
51
|
+
return createStatusValidator(attr, messages);
|
|
52
|
+
case "location":
|
|
53
|
+
return createLocationValidator(attr, messages);
|
|
54
|
+
case "select":
|
|
55
|
+
return createSelectValidator(attr, messages);
|
|
56
|
+
case "multiselect":
|
|
57
|
+
return createMultiselectValidator(attr, messages);
|
|
58
|
+
case "user":
|
|
59
|
+
return createUserValidator(attr, messages);
|
|
60
|
+
case "relation":
|
|
61
|
+
return createRelationValidator(attr, messages);
|
|
62
|
+
case "formula":
|
|
63
|
+
return createFormulaValidator(attr, messages);
|
|
64
|
+
case "rollup":
|
|
65
|
+
return createRollupValidator(attr, messages);
|
|
66
|
+
default:
|
|
67
|
+
return z.unknown();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function createFormAttributeValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
71
|
+
const validator = createAttributeValidator(attr, messages);
|
|
72
|
+
if (!attr.required) {
|
|
73
|
+
return withEmptyToNull(validator);
|
|
74
|
+
}
|
|
75
|
+
return validator;
|
|
76
|
+
}
|
|
77
|
+
var objectValidatorCache = /* @__PURE__ */ new WeakMap();
|
|
78
|
+
var draftValidatorCache = /* @__PURE__ */ new WeakMap();
|
|
79
|
+
function createObjectValidator(objectDef) {
|
|
80
|
+
const cached = objectValidatorCache.get(objectDef);
|
|
81
|
+
if (cached) return cached;
|
|
82
|
+
const shape = {};
|
|
83
|
+
for (const attr of objectDef.attributes) {
|
|
84
|
+
const validator = createAttributeValidator(attr);
|
|
85
|
+
shape[attr.name] = attr.required ? validator : withEmptyToNull(validator);
|
|
86
|
+
}
|
|
87
|
+
const schema = z.object(shape).passthrough();
|
|
88
|
+
objectValidatorCache.set(objectDef, schema);
|
|
89
|
+
return schema;
|
|
90
|
+
}
|
|
91
|
+
function createDraftValidator(objectDef) {
|
|
92
|
+
const cached = draftValidatorCache.get(objectDef);
|
|
93
|
+
if (cached) return cached;
|
|
94
|
+
const shape = {};
|
|
95
|
+
for (const attr of objectDef.attributes) {
|
|
96
|
+
const validator = createAttributeValidator(attr);
|
|
97
|
+
shape[attr.name] = withEmptyToNull(validator);
|
|
98
|
+
}
|
|
99
|
+
const schema = z.object(shape).passthrough();
|
|
100
|
+
draftValidatorCache.set(objectDef, schema);
|
|
101
|
+
return schema;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/validation/object/helpers.ts
|
|
105
|
+
function validateAttribute(attr, value) {
|
|
106
|
+
const validator = createAttributeValidator(attr);
|
|
107
|
+
if (!attr.required && (value === void 0 || value === null)) {
|
|
108
|
+
return { success: true, data: { [attr.name]: value } };
|
|
109
|
+
}
|
|
110
|
+
const result = validator.safeParse(value);
|
|
111
|
+
if (result.success) {
|
|
112
|
+
return {
|
|
113
|
+
success: true,
|
|
114
|
+
data: { [attr.name]: result.data }
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
success: false,
|
|
119
|
+
errors: formatZodErrors(result.error).map((err) => ({
|
|
120
|
+
path: [attr.name, ...err.path],
|
|
121
|
+
message: err.message
|
|
122
|
+
}))
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function validateObject(objectDef, data) {
|
|
126
|
+
const validator = createObjectValidator(objectDef);
|
|
127
|
+
const result = validator.safeParse(data);
|
|
128
|
+
if (result.success) {
|
|
129
|
+
return {
|
|
130
|
+
success: true,
|
|
131
|
+
data: result.data
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
success: false,
|
|
136
|
+
errors: formatZodErrors(result.error)
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function validateObjectOrThrow(objectDef, data) {
|
|
140
|
+
const result = validateObject(objectDef, data);
|
|
141
|
+
if (!result.success) {
|
|
142
|
+
const errors = result.errors ?? [];
|
|
143
|
+
const detail = errors.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
|
|
144
|
+
throw new ValidationError(
|
|
145
|
+
`Validation failed for ${objectDef.label}:
|
|
146
|
+
${detail}`,
|
|
147
|
+
errors.map((err) => ({ path: err.path, message: err.message }))
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
return result.data;
|
|
151
|
+
}
|
|
152
|
+
function validateDraft(objectDef, data) {
|
|
153
|
+
const validator = createDraftValidator(objectDef);
|
|
154
|
+
const result = validator.safeParse(data);
|
|
155
|
+
if (result.success) {
|
|
156
|
+
return {
|
|
157
|
+
success: true,
|
|
158
|
+
data: result.data
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
success: false,
|
|
163
|
+
errors: formatZodErrors(result.error)
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function validateDraftOrThrow(objectDef, data) {
|
|
167
|
+
const result = validateDraft(objectDef, data);
|
|
168
|
+
if (!result.success) {
|
|
169
|
+
const errors = result.errors ?? [];
|
|
170
|
+
const detail = errors.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
|
|
171
|
+
throw new ValidationError(
|
|
172
|
+
`Draft validation failed for ${objectDef.label}:
|
|
173
|
+
${detail}`,
|
|
174
|
+
errors.map((err) => ({ path: err.path, message: err.message }))
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
return result.data;
|
|
178
|
+
}
|
|
179
|
+
function rejectUnknownAttributesOrThrow(objectDef, data) {
|
|
180
|
+
const knownNames = new Set(objectDef.attributes.map((a) => a.name));
|
|
181
|
+
const unknownKeys = Object.keys(data).filter((key) => !knownNames.has(key));
|
|
182
|
+
if (unknownKeys.length > 0) {
|
|
183
|
+
throw new ValidationError(
|
|
184
|
+
`Unknown attribute${unknownKeys.length > 1 ? "s" : ""} for ${objectDef.label}: ${unknownKeys.join(", ")}`,
|
|
185
|
+
unknownKeys.map((key) => ({ path: [key], message: "Unknown attribute" }))
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function isValuePresent(value) {
|
|
190
|
+
if (value === void 0 || value === null) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
if (typeof value === "string" && value.trim() === "") {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
function getMissingRequiredAttributes(objectDef, data) {
|
|
199
|
+
const missing = [];
|
|
200
|
+
for (const attr of objectDef.attributes) {
|
|
201
|
+
if (attr.required && !isValuePresent(data[attr.name])) {
|
|
202
|
+
missing.push(attr);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return missing;
|
|
206
|
+
}
|
|
207
|
+
function isRecordComplete(objectDef, data) {
|
|
208
|
+
const missing = getMissingRequiredAttributes(objectDef, data);
|
|
209
|
+
if (missing.length > 0) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
const validation = validateObject(objectDef, data);
|
|
213
|
+
return validation.success;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export { createAttributeValidator, createDraftValidator, createFormAttributeValidator, createObjectValidator, getMissingRequiredAttributes, isRecordComplete, rejectUnknownAttributesOrThrow, validateAttribute, validateDraft, validateDraftOrThrow, validateObject, validateObjectOrThrow };
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk5WATIVCA_js = require('./chunk-5WATIVCA.js');
|
|
4
|
+
var chunkSI34M4IC_js = require('./chunk-SI34M4IC.js');
|
|
5
|
+
var chunkYIP5FJ5H_js = require('./chunk-YIP5FJ5H.js');
|
|
6
|
+
var chunkQAF3HNKQ_js = require('./chunk-QAF3HNKQ.js');
|
|
7
|
+
var chunkEW5XR2X3_js = require('./chunk-EW5XR2X3.js');
|
|
8
|
+
var chunkQWKLQRBX_js = require('./chunk-QWKLQRBX.js');
|
|
9
|
+
var chunkKNGWHQLR_js = require('./chunk-KNGWHQLR.js');
|
|
10
|
+
var chunkHTSTPTNZ_js = require('./chunk-HTSTPTNZ.js');
|
|
11
|
+
var chunkV2UA2D4E_js = require('./chunk-V2UA2D4E.js');
|
|
12
|
+
var chunkZBQEMIAV_js = require('./chunk-ZBQEMIAV.js');
|
|
13
|
+
var chunkACKMC6FL_js = require('./chunk-ACKMC6FL.js');
|
|
14
|
+
var chunkE6JUYGJX_js = require('./chunk-E6JUYGJX.js');
|
|
15
|
+
var chunkEBGRZUIH_js = require('./chunk-EBGRZUIH.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 chunkQAF3HNKQ_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 chunkEBGRZUIH_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 chunkZBQEMIAV_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 chunkZBQEMIAV_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 chunkZBQEMIAV_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;
|