@standards/schema 0.0.0-stage → 1.0.0-alpha.382
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/LICENSE +111 -0
- package/README.md +8 -2
- package/dist/all-BgYwavNm.d.mts +2956 -0
- package/dist/all-DjdKldjX.d.ts +2956 -0
- package/dist/api/index.d.mts +11838 -0
- package/dist/api/index.d.ts +11838 -0
- package/dist/api/index.js +2 -0
- package/dist/api/index.mjs +2 -0
- package/dist/attribute-validators-DRqhAt2t.mjs +11 -0
- package/dist/attribute-validators-WAoJbap5.js +11 -0
- package/dist/attributes-aTeqx6cK.d.mts +557 -0
- package/dist/attributes-kAhQzg8-.d.ts +557 -0
- package/dist/checkbox-BZvZOraX.d.mts +11 -0
- package/dist/checkbox-n0YV1O13.d.ts +11 -0
- package/dist/config-BIxnbUN8.mjs +2 -0
- package/dist/config-DdjlHdPg.js +2 -0
- package/dist/core-397tQy5q.js +2 -0
- package/dist/core-BLHhNykL.mjs +2 -0
- package/dist/date-CxqDOhA0.d.mts +24 -0
- package/dist/date-D007KyTI.d.ts +24 -0
- package/dist/exceptions-DjPVyS-Q.d.mts +761 -0
- package/dist/exceptions-DjPVyS-Q.d.ts +761 -0
- package/dist/exceptions.d.mts +3 -0
- package/dist/exceptions.d.ts +3 -0
- package/dist/exceptions.js +2 -0
- package/dist/exceptions.mjs +2 -0
- package/dist/index-3HZjBOpj.d.mts +53 -0
- package/dist/index-BmNMneu3.d.mts +278 -0
- package/dist/index-Bu9xF5Nq.d.ts +278 -0
- package/dist/index-CiTBL4gH.d.ts +101 -0
- package/dist/index-D7TEaPqX.d.ts +16519 -0
- package/dist/index-DLO8JpnY.d.ts +53 -0
- package/dist/index-DPO5w-fC.d.mts +101 -0
- package/dist/index-DwQWBzYJ.d.mts +16519 -0
- package/dist/index.d.mts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +2 -0
- package/dist/index.mjs +2 -0
- package/dist/number-CgBxEbjI.d.mts +11 -0
- package/dist/number-DncH-WRO.d.ts +11 -0
- package/dist/object-DcgxLvip.js +4 -0
- package/dist/object-Dzl7sfq8.mjs +4 -0
- package/dist/objects-B4DgFZ82.d.ts +398 -0
- package/dist/objects-C9f6hFW_.d.mts +398 -0
- package/dist/phone-BB-tzcSr.js +2 -0
- package/dist/phone-Bca_xiOX.mjs +2 -0
- package/dist/record-aggregates-CzG86pUS.mjs +2 -0
- package/dist/record-aggregates-DwpIJ2Dv.js +2 -0
- package/dist/record-operation-BSXczk7v.js +2 -0
- package/dist/record-operation-C9oXHmfF.mjs +2 -0
- package/dist/text-A9AJ1wUO.js +2 -0
- package/dist/text-C8Lb-NFo.mjs +2 -0
- package/dist/text-DDoY_LcQ.d.ts +11 -0
- package/dist/text-DeUqCFp9.d.mts +11 -0
- package/dist/utils-B7Dlrtnx.d.ts +163 -0
- package/dist/utils-DbRMK8NI.d.mts +163 -0
- package/dist/utils-fXIvFFl6.mjs +2 -0
- package/dist/utils-gY3d9Dwp.js +2 -0
- package/dist/utils.d.mts +3 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +2 -0
- package/dist/utils.mjs +2 -0
- package/dist/validation/all.d.mts +6 -0
- package/dist/validation/all.d.ts +6 -0
- package/dist/validation/all.js +2 -0
- package/dist/validation/all.mjs +2 -0
- package/dist/validation/complex/currency.d.mts +13 -0
- package/dist/validation/complex/currency.d.ts +13 -0
- package/dist/validation/complex/currency.js +2 -0
- package/dist/validation/complex/currency.mjs +2 -0
- package/dist/validation/complex/location.d.mts +20 -0
- package/dist/validation/complex/location.d.ts +20 -0
- package/dist/validation/complex/location.js +2 -0
- package/dist/validation/complex/location.mjs +2 -0
- package/dist/validation/complex/phone.d.mts +20 -0
- package/dist/validation/complex/phone.d.ts +20 -0
- package/dist/validation/complex/phone.js +2 -0
- package/dist/validation/complex/phone.mjs +2 -0
- package/dist/validation/complex/relation.d.mts +23 -0
- package/dist/validation/complex/relation.d.ts +23 -0
- package/dist/validation/complex/relation.js +2 -0
- package/dist/validation/complex/relation.mjs +2 -0
- package/dist/validation/complex/richtext.d.mts +11 -0
- package/dist/validation/complex/richtext.d.ts +11 -0
- package/dist/validation/complex/richtext.js +2 -0
- package/dist/validation/complex/richtext.mjs +2 -0
- package/dist/validation/complex/select.d.mts +18 -0
- package/dist/validation/complex/select.d.ts +18 -0
- package/dist/validation/complex/select.js +2 -0
- package/dist/validation/complex/select.mjs +2 -0
- package/dist/validation/complex/user.d.mts +11 -0
- package/dist/validation/complex/user.d.ts +11 -0
- package/dist/validation/complex/user.js +2 -0
- package/dist/validation/complex/user.mjs +2 -0
- package/dist/validation/computed/formula.d.mts +12 -0
- package/dist/validation/computed/formula.d.ts +12 -0
- package/dist/validation/computed/formula.js +2 -0
- package/dist/validation/computed/formula.mjs +2 -0
- package/dist/validation/computed/rollup.d.mts +12 -0
- package/dist/validation/computed/rollup.d.ts +12 -0
- package/dist/validation/computed/rollup.js +2 -0
- package/dist/validation/computed/rollup.mjs +2 -0
- package/dist/validation/config/index.d.mts +3 -0
- package/dist/validation/config/index.d.ts +3 -0
- package/dist/validation/config/index.js +2 -0
- package/dist/validation/config/index.mjs +2 -0
- package/dist/validation/core/index.d.mts +3 -0
- package/dist/validation/core/index.d.ts +3 -0
- package/dist/validation/core/index.js +2 -0
- package/dist/validation/core/index.mjs +2 -0
- package/dist/validation/object/index.d.mts +3 -0
- package/dist/validation/object/index.d.ts +3 -0
- package/dist/validation/object/index.js +2 -0
- package/dist/validation/object/index.mjs +2 -0
- package/dist/validation/primitives/checkbox.d.mts +3 -0
- package/dist/validation/primitives/checkbox.d.ts +3 -0
- package/dist/validation/primitives/checkbox.js +2 -0
- package/dist/validation/primitives/checkbox.mjs +2 -0
- package/dist/validation/primitives/date.d.mts +3 -0
- package/dist/validation/primitives/date.d.ts +3 -0
- package/dist/validation/primitives/date.js +2 -0
- package/dist/validation/primitives/date.mjs +2 -0
- package/dist/validation/primitives/number.d.mts +3 -0
- package/dist/validation/primitives/number.d.ts +3 -0
- package/dist/validation/primitives/number.js +2 -0
- package/dist/validation/primitives/number.mjs +2 -0
- package/dist/validation/primitives/text.d.mts +3 -0
- package/dist/validation/primitives/text.d.ts +3 -0
- package/dist/validation/primitives/text.js +2 -0
- package/dist/validation/primitives/text.mjs +2 -0
- package/dist/view-config.schema-BQ9tU_9G.js +2 -0
- package/dist/view-config.schema-BmjCQJ51.mjs +2 -0
- package/package.json +279 -3
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
|
|
2
|
+
import { n as Attribute } from "./attributes-kAhQzg8-.js";
|
|
3
|
+
import { z as z$1 } from "zod";
|
|
4
|
+
//#region src/validation/core/types.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Validation messages for Zod validators.
|
|
7
|
+
* All functions receive the full Attribute to access label, type, etc.
|
|
8
|
+
* Can be customized for i18n support.
|
|
9
|
+
*/
|
|
10
|
+
interface ValidationMessages {
|
|
11
|
+
required: (attr: Attribute) => string;
|
|
12
|
+
invalidType: (attr: Attribute, expected: string) => string;
|
|
13
|
+
minLength: (attr: Attribute, min: number) => string;
|
|
14
|
+
maxLength: (attr: Attribute, max: number) => string;
|
|
15
|
+
invalidPattern: (attr: Attribute) => string;
|
|
16
|
+
minValue: (attr: Attribute, min: number) => string;
|
|
17
|
+
maxValue: (attr: Attribute, max: number) => string;
|
|
18
|
+
mustBeInteger: (attr: Attribute) => string;
|
|
19
|
+
invalidDate: (attr: Attribute) => string;
|
|
20
|
+
invalidOption: (attr: Attribute, options: string[]) => string;
|
|
21
|
+
invalidId: (attr: Attribute) => string;
|
|
22
|
+
maxItems: (attr: Attribute, max: number) => string;
|
|
23
|
+
invalidRichtext: (attr: Attribute) => string;
|
|
24
|
+
invalidPhone: (attr: Attribute) => string;
|
|
25
|
+
invalidCurrency: (attr: Attribute) => string;
|
|
26
|
+
invalidLocation: (attr: Attribute) => string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Validation result
|
|
30
|
+
*/
|
|
31
|
+
interface ValidationResult {
|
|
32
|
+
success: boolean;
|
|
33
|
+
data?: Record<string, unknown>;
|
|
34
|
+
errors?: Array<{
|
|
35
|
+
path: string[];
|
|
36
|
+
message: string;
|
|
37
|
+
}>;
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/validation/core/messages.d.ts
|
|
41
|
+
declare const DEFAULT_VALIDATION_MESSAGES: ValidationMessages;
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/validation/core/errors.d.ts
|
|
44
|
+
/**
|
|
45
|
+
* Format Zod validation errors into a consistent structure.
|
|
46
|
+
* This eliminates code duplication across multiple validation functions.
|
|
47
|
+
*/
|
|
48
|
+
declare function formatZodErrors(error: z$1.ZodError): Array<{
|
|
49
|
+
path: string[];
|
|
50
|
+
message: string;
|
|
51
|
+
}>;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { ValidationResult as i, DEFAULT_VALIDATION_MESSAGES as n, ValidationMessages as r, formatZodErrors as t };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
|
|
2
|
+
import { i as ObjectDefinition } from "./objects-C9f6hFW_.mjs";
|
|
3
|
+
import { n as Attribute } from "./attributes-aTeqx6cK.mjs";
|
|
4
|
+
import { i as ValidationResult, r as ValidationMessages } from "./index-3HZjBOpj.mjs";
|
|
5
|
+
import { z as z$1 } from "zod";
|
|
6
|
+
//#region src/validation/object/attribute-factory.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Create a Zod schema for any attribute type.
|
|
9
|
+
* Returns a strict validator that does NOT handle optional fields.
|
|
10
|
+
* Use createFormAttributeValidator for form validation with optional support.
|
|
11
|
+
*
|
|
12
|
+
* @param attr - The attribute to create a validator for
|
|
13
|
+
* @param messages - Custom validation messages for i18n support
|
|
14
|
+
*/
|
|
15
|
+
declare function createAttributeValidator(attr: Attribute, messages?: ValidationMessages): z$1.ZodTypeAny;
|
|
16
|
+
/**
|
|
17
|
+
* Create a Zod schema for form validation.
|
|
18
|
+
* - Normalizes empty values (empty strings, empty objects) to null for optional fields
|
|
19
|
+
* - Accepts custom messages for i18n support
|
|
20
|
+
*
|
|
21
|
+
* Use this in UI forms where optional fields may have null/undefined values.
|
|
22
|
+
*
|
|
23
|
+
* @param attr - The attribute to create a validator for
|
|
24
|
+
* @param messages - Custom validation messages for i18n support
|
|
25
|
+
*/
|
|
26
|
+
declare function createFormAttributeValidator(attr: Attribute, messages?: ValidationMessages): z$1.ZodTypeAny;
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/validation/object/object-validator.d.ts
|
|
29
|
+
/**
|
|
30
|
+
* Create a Zod schema for an entire object
|
|
31
|
+
*
|
|
32
|
+
* Uses passthrough mode to allow computed fields (formula, rollup) that may be
|
|
33
|
+
* present in record data but are not part of the mutable schema.
|
|
34
|
+
*
|
|
35
|
+
* Result is cached per ObjectDefinition instance — safe because ObjectDefinitions
|
|
36
|
+
* are stable after module load and never mutated at runtime.
|
|
37
|
+
*/
|
|
38
|
+
declare function createObjectValidator(objectDef: ObjectDefinition): z$1.ZodType<Record<string, unknown>>;
|
|
39
|
+
/**
|
|
40
|
+
* Create a Zod schema for draft validation.
|
|
41
|
+
* All attributes become optional, but provided values are still validated.
|
|
42
|
+
*
|
|
43
|
+
* Uses passthrough mode to allow computed fields (formula, rollup) that may be
|
|
44
|
+
* present in record data but are not part of the mutable schema.
|
|
45
|
+
*
|
|
46
|
+
* Result is cached per ObjectDefinition instance — safe because ObjectDefinitions
|
|
47
|
+
* are stable after module load and never mutated at runtime.
|
|
48
|
+
*/
|
|
49
|
+
declare function createDraftValidator(objectDef: ObjectDefinition): z$1.ZodType<Record<string, unknown>>;
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/validation/object/helpers.d.ts
|
|
52
|
+
/**
|
|
53
|
+
* Validate data against an attribute schema
|
|
54
|
+
*/
|
|
55
|
+
declare function validateAttribute(attr: Attribute, value: unknown): ValidationResult;
|
|
56
|
+
/**
|
|
57
|
+
* Validate data against an object schema
|
|
58
|
+
*/
|
|
59
|
+
declare function validateObject(objectDef: ObjectDefinition, data: Record<string, unknown>): ValidationResult;
|
|
60
|
+
/**
|
|
61
|
+
* Validate and throw if invalid.
|
|
62
|
+
*
|
|
63
|
+
* Throws `ValidationError` (code `SCHEMA_VALIDATION_FAILED`) on failure so HTTP
|
|
64
|
+
* adapters can map it to 400. Generic `Error` would bubble up to a 500.
|
|
65
|
+
*/
|
|
66
|
+
declare function validateObjectOrThrow(objectDef: ObjectDefinition, data: Record<string, unknown>): Record<string, unknown>;
|
|
67
|
+
/**
|
|
68
|
+
* Validate data in draft mode.
|
|
69
|
+
* - All attributes are treated as optional (no required validation)
|
|
70
|
+
* - Provided values are still validated for format/type correctness
|
|
71
|
+
*/
|
|
72
|
+
declare function validateDraft(objectDef: ObjectDefinition, data: Record<string, unknown>): ValidationResult;
|
|
73
|
+
/**
|
|
74
|
+
* Validate draft data and throw if format validation fails.
|
|
75
|
+
*
|
|
76
|
+
* Same contract as `validateObjectOrThrow` but skips `required()` checks.
|
|
77
|
+
* Throws `ValidationError` so HTTP adapters map it to 400.
|
|
78
|
+
*/
|
|
79
|
+
declare function validateDraftOrThrow(objectDef: ObjectDefinition, data: Record<string, unknown>): Record<string, unknown>;
|
|
80
|
+
/**
|
|
81
|
+
* Throw a `ValidationError` when `data` contains keys that do not correspond
|
|
82
|
+
* to any attribute declared on `objectDef`.
|
|
83
|
+
*
|
|
84
|
+
* Call this on **client-supplied input** before Zod validation so the error
|
|
85
|
+
* message clearly names every offending key. Do NOT call on merged data that
|
|
86
|
+
* includes existing record values — older records may legitimately carry stale
|
|
87
|
+
* keys that predate this guard (see issue #658).
|
|
88
|
+
*
|
|
89
|
+
* Maps to HTTP 400 via `SchemaExceptionFilter` (code SCHEMA_VALIDATION_FAILED).
|
|
90
|
+
*/
|
|
91
|
+
declare function rejectUnknownAttributesOrThrow(objectDef: ObjectDefinition, data: Record<string, unknown>): void;
|
|
92
|
+
/**
|
|
93
|
+
* Get the list of required attributes that are missing values.
|
|
94
|
+
*/
|
|
95
|
+
declare function getMissingRequiredAttributes(objectDef: ObjectDefinition, data: Record<string, unknown>): Attribute[];
|
|
96
|
+
/**
|
|
97
|
+
* Check if a record is complete (all required attributes have valid values).
|
|
98
|
+
*/
|
|
99
|
+
declare function isRecordComplete(objectDef: ObjectDefinition, data: Record<string, unknown>): boolean;
|
|
100
|
+
//#endregion
|
|
101
|
+
export { validateDraft as a, validateObjectOrThrow as c, createAttributeValidator as d, createFormAttributeValidator as f, validateAttribute as i, createDraftValidator as l, isRecordComplete as n, validateDraftOrThrow as o, rejectUnknownAttributesOrThrow as r, validateObject as s, getMissingRequiredAttributes as t, createObjectValidator as u };
|