@stndrds/schema 1.0.0-alpha.294 → 1.0.0-alpha.68
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/chunk-36UBIXJN.js +82 -0
- package/dist/chunk-3RG5ZIWI.js +10 -0
- package/dist/chunk-IXHWBBIY.mjs +721 -0
- package/dist/chunk-KG75T7MA.mjs +18664 -0
- package/dist/chunk-NEVERCM3.js +41 -0
- package/dist/chunk-V2RPPE2Y.mjs +41 -0
- package/dist/chunk-V32FQLWX.js +721 -0
- package/dist/chunk-V5QXU2OK.mjs +82 -0
- package/dist/chunk-XGFBT4K2.js +18664 -0
- package/dist/chunk-Y6FXYEAI.mjs +10 -0
- package/dist/default-roles-42X3TJI5.mjs +21 -0
- package/dist/default-roles-C3FYDYMN.js +21 -0
- package/dist/index.d.mts +3392 -10868
- package/dist/index.d.ts +3392 -10868
- package/dist/index.js +1705 -10256
- package/dist/index.mjs +1735 -9398
- package/dist/runtime-B0G6eBXO.d.ts +12810 -0
- package/dist/runtime-fj4EKCWH.d.mts +12810 -0
- package/dist/runtime.d.mts +6 -0
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.js +323 -0
- package/dist/runtime.mjs +323 -0
- package/dist/utils.d.mts +55 -35
- package/dist/utils.d.ts +55 -35
- package/dist/utils.js +19 -31
- package/dist/utils.mjs +19 -2
- package/dist/validation/validators.d.mts +4 -0
- package/dist/validation/validators.d.ts +4 -0
- package/dist/validation/validators.js +121 -0
- package/dist/validation/validators.mjs +121 -0
- package/dist/validators-B6L_hVBw.d.ts +1564 -0
- package/dist/validators-CgiGGhyH.d.mts +1564 -0
- package/package.json +16 -106
- package/dist/all-CDJSpI46.d.ts +0 -978
- package/dist/all-Cru_CaSY.d.mts +0 -978
- package/dist/attributes-CNYwg_Nr.d.ts +0 -584
- package/dist/attributes-CWPLbp7c.d.mts +0 -584
- package/dist/capabilities.d.mts +0 -146
- package/dist/capabilities.d.ts +0 -146
- package/dist/capabilities.js +0 -77
- package/dist/capabilities.mjs +0 -70
- package/dist/chunk-2WWGHULM.mjs +0 -226
- package/dist/chunk-4KMUATDG.js +0 -609
- package/dist/chunk-5WATIVCA.js +0 -10
- package/dist/chunk-ACKMC6FL.js +0 -17
- package/dist/chunk-AYVHMVKQ.mjs +0 -15
- package/dist/chunk-CLZORRMS.mjs +0 -570
- package/dist/chunk-DVXGSTWJ.js +0 -81
- package/dist/chunk-E6JUYGJX.js +0 -22
- package/dist/chunk-EEH4XQ7W.js +0 -61
- package/dist/chunk-EW5XR2X3.js +0 -12
- package/dist/chunk-GO6LQADH.mjs +0 -57
- package/dist/chunk-HRQEZUAA.mjs +0 -29
- package/dist/chunk-HTSTPTNZ.js +0 -10
- package/dist/chunk-HURC6CW3.js +0 -241
- package/dist/chunk-JZNR4HKQ.mjs +0 -1432
- package/dist/chunk-KAWYU7TE.js +0 -657
- package/dist/chunk-KNGWHQLR.js +0 -16
- package/dist/chunk-LV3FEUKU.mjs +0 -14
- package/dist/chunk-NS63SPNN.mjs +0 -8
- package/dist/chunk-O73ROMWQ.mjs +0 -85
- package/dist/chunk-OSSGN43B.mjs +0 -8
- package/dist/chunk-Q44QKLN4.mjs +0 -43
- package/dist/chunk-Q4SZAMJT.js +0 -72
- package/dist/chunk-QT35SI3K.mjs +0 -641
- package/dist/chunk-QVLQPW3O.mjs +0 -10
- package/dist/chunk-QWKLQRBX.js +0 -35
- package/dist/chunk-R2DAEDRF.mjs +0 -74
- package/dist/chunk-R5LAJCBU.mjs +0 -67
- package/dist/chunk-SI34M4IC.js +0 -45
- package/dist/chunk-T5PM73EF.js +0 -1504
- package/dist/chunk-UANQJ2GH.mjs +0 -25
- package/dist/chunk-UXAHLSWC.mjs +0 -8
- package/dist/chunk-V2UA2D4E.js +0 -10
- package/dist/chunk-YIP5FJ5H.js +0 -27
- package/dist/chunk-YKWSHBT5.js +0 -32
- package/dist/chunk-YUFTHPOE.mjs +0 -20
- package/dist/chunk-ZDQ5AP26.mjs +0 -31
- package/dist/chunk-ZPFOKBIN.js +0 -89
- package/dist/exceptions.d.mts +0 -511
- package/dist/exceptions.d.ts +0 -511
- package/dist/exceptions.js +0 -158
- package/dist/exceptions.mjs +0 -1
- package/dist/helpers-CXkVwpsl.d.ts +0 -76
- package/dist/helpers-Dul_r9rJ.d.mts +0 -76
- package/dist/index-BdVnHL3F.d.mts +0 -853
- package/dist/index-CFhPHQaI.d.ts +0 -853
- package/dist/migrations-DaFneOfx.d.ts +0 -39
- package/dist/migrations-fRvadl6i.d.mts +0 -39
- package/dist/objects-CDwMSnqv.d.mts +0 -250
- package/dist/objects-DJv6WrDE.d.ts +0 -250
- package/dist/types-CVYiFc69.d.mts +0 -38
- package/dist/types-NGEww_ln.d.ts +0 -38
- package/dist/validation/all.d.mts +0 -11
- package/dist/validation/all.d.ts +0 -11
- package/dist/validation/all.js +0 -131
- package/dist/validation/all.mjs +0 -18
- package/dist/validation/complex/currency.d.mts +0 -15
- package/dist/validation/complex/currency.d.ts +0 -15
- package/dist/validation/complex/currency.js +0 -11
- package/dist/validation/complex/currency.mjs +0 -2
- package/dist/validation/complex/location.d.mts +0 -22
- package/dist/validation/complex/location.d.ts +0 -22
- package/dist/validation/complex/location.js +0 -11
- package/dist/validation/complex/location.mjs +0 -2
- package/dist/validation/complex/phone.d.mts +0 -22
- package/dist/validation/complex/phone.d.ts +0 -22
- package/dist/validation/complex/phone.js +0 -11
- package/dist/validation/complex/phone.mjs +0 -2
- package/dist/validation/complex/relation.d.mts +0 -25
- package/dist/validation/complex/relation.d.ts +0 -25
- package/dist/validation/complex/relation.js +0 -19
- package/dist/validation/complex/relation.mjs +0 -2
- package/dist/validation/complex/richtext.d.mts +0 -13
- package/dist/validation/complex/richtext.d.ts +0 -13
- package/dist/validation/complex/richtext.js +0 -11
- package/dist/validation/complex/richtext.mjs +0 -2
- package/dist/validation/complex/select.d.mts +0 -20
- package/dist/validation/complex/select.d.ts +0 -20
- package/dist/validation/complex/select.js +0 -19
- package/dist/validation/complex/select.mjs +0 -2
- package/dist/validation/complex/user.d.mts +0 -13
- package/dist/validation/complex/user.d.ts +0 -13
- package/dist/validation/complex/user.js +0 -11
- package/dist/validation/complex/user.mjs +0 -2
- package/dist/validation/computed/formula.d.mts +0 -14
- package/dist/validation/computed/formula.d.ts +0 -14
- package/dist/validation/computed/formula.js +0 -11
- package/dist/validation/computed/formula.mjs +0 -2
- package/dist/validation/computed/rollup.d.mts +0 -14
- package/dist/validation/computed/rollup.d.ts +0 -14
- package/dist/validation/computed/rollup.js +0 -11
- package/dist/validation/computed/rollup.mjs +0 -2
- package/dist/validation/config/index.d.mts +0 -7
- package/dist/validation/config/index.d.ts +0 -7
- package/dist/validation/config/index.js +0 -52
- package/dist/validation/config/index.mjs +0 -7
- package/dist/validation/core/index.d.mts +0 -19
- package/dist/validation/core/index.d.ts +0 -19
- package/dist/validation/core/index.js +0 -14
- package/dist/validation/core/index.mjs +0 -1
- package/dist/validation/object/index.d.mts +0 -32
- package/dist/validation/object/index.d.ts +0 -32
- package/dist/validation/object/index.js +0 -69
- package/dist/validation/object/index.mjs +0 -16
- package/dist/validation/primitives/checkbox.d.mts +0 -12
- package/dist/validation/primitives/checkbox.d.ts +0 -12
- package/dist/validation/primitives/checkbox.js +0 -11
- package/dist/validation/primitives/checkbox.mjs +0 -2
- package/dist/validation/primitives/date.d.mts +0 -25
- package/dist/validation/primitives/date.d.ts +0 -25
- package/dist/validation/primitives/date.js +0 -11
- package/dist/validation/primitives/date.mjs +0 -2
- package/dist/validation/primitives/number.d.mts +0 -12
- package/dist/validation/primitives/number.d.ts +0 -12
- package/dist/validation/primitives/number.js +0 -11
- package/dist/validation/primitives/number.mjs +0 -2
- package/dist/validation/primitives/text.d.mts +0 -12
- package/dist/validation/primitives/text.d.ts +0 -12
- package/dist/validation/primitives/text.js +0 -11
- package/dist/validation/primitives/text.mjs +0 -2
package/dist/capabilities.d.mts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
/** Accepted forms of the object identifier every object-scoped capability takes. */
|
|
4
|
-
declare const OBJECT_ID_DESCRIPTION = "Object UUID, kebab-case name (e.g., 'contacts'), or display label (e.g., 'Personne physique'). All three are accepted; UUID is most precise.";
|
|
5
|
-
/** Shared suffix for record `data` inputs that accept `$fromSandboxFile` references for large content. */
|
|
6
|
-
declare const SANDBOX_FILE_DATA_HINT = " For large text content (> a few KB), write it to a sandbox file first and pass {\"$fromSandboxFile\": \"/workspace/<file>\"} as the attribute value \u2014 the server substitutes the file content.";
|
|
7
|
-
/**
|
|
8
|
-
* The LLM-facing filter shape, deliberately looser than its two siblings:
|
|
9
|
-
* `types/filters.ts` (`FilterState`, the canonical TS model — its `quantifier`
|
|
10
|
-
* is omitted here on purpose, agents don't set edge quantifiers) and
|
|
11
|
-
* `validators/view-config.schema.ts` (`filterStateSchema`, the strict capped
|
|
12
|
-
* variant for stored view config). The operator list in the describe text
|
|
13
|
-
* restates `filters/operators.ts` (`OPERATOR_SPECS`) and
|
|
14
|
-
* `filters/normalize-operator.ts` (`SYNONYM_ALIASES`) — those are the source
|
|
15
|
-
* of truth; keep the prose in sync when adding an operator.
|
|
16
|
-
*/
|
|
17
|
-
declare const filtersSchema: z.ZodObject<{
|
|
18
|
-
combinator: z.ZodDefault<z.ZodEnum<{
|
|
19
|
-
and: "and";
|
|
20
|
-
or: "or";
|
|
21
|
-
}>>;
|
|
22
|
-
rules: z.ZodArray<z.ZodObject<{
|
|
23
|
-
attribute: z.ZodString;
|
|
24
|
-
property: z.ZodOptional<z.ZodString>;
|
|
25
|
-
operator: z.ZodString;
|
|
26
|
-
value: z.ZodNullable<z.ZodUnknown>;
|
|
27
|
-
}, z.core.$strip>>;
|
|
28
|
-
}, z.core.$strip>;
|
|
29
|
-
declare const sortsSchema: z.ZodArray<z.ZodObject<{
|
|
30
|
-
attribute: z.ZodString;
|
|
31
|
-
direction: z.ZodEnum<{
|
|
32
|
-
asc: "asc";
|
|
33
|
-
desc: "desc";
|
|
34
|
-
}>;
|
|
35
|
-
}, z.core.$strip>>;
|
|
36
|
-
/**
|
|
37
|
-
* Filter shapes derived from {@link filtersSchema} so the capability schema stays
|
|
38
|
-
* the single source of truth.
|
|
39
|
-
*
|
|
40
|
-
* The *parsed* shape (`z.infer`), deliberately: the runtime holds these after
|
|
41
|
-
* validation, when `combinator` has already been defaulted. What a caller may
|
|
42
|
-
* omit is `z.input`, and that is what {@link CapabilityInput} exposes.
|
|
43
|
-
*/
|
|
44
|
-
type FilterStateInput = z.infer<typeof filtersSchema>;
|
|
45
|
-
type FilterRuleInput = FilterStateInput["rules"][number];
|
|
46
|
-
/** How a capability mutates data, which decides whether a rehearsal captures it. */
|
|
47
|
-
type CapabilityKind = "read" | "create" | "update" | "delete";
|
|
48
|
-
/**
|
|
49
|
-
* Every capability a Reflex may call, defined once.
|
|
50
|
-
*
|
|
51
|
-
* Deliberately five entries — the single-record tools whose input the gateway can
|
|
52
|
-
* turn into a faithful `RunEffect`. Excluded on purpose: `get_schema`,
|
|
53
|
-
* `global_search` and `bulk_search`, which are not scoped to one object and so
|
|
54
|
-
* yield no object to grant a permission on; and the `bulk_*` record tools, where
|
|
55
|
-
* one call mutates many records and would be recorded as a single effect, making
|
|
56
|
-
* an effects report understate what happened.
|
|
57
|
-
*
|
|
58
|
-
* `description` is NOT here: the tools compute it per call from their config
|
|
59
|
-
* (`schemaInContext` changes the wording), and `schema-tools-descriptions.test.ts`
|
|
60
|
-
* pins both variants. The name, the kind and the input schema are what must exist
|
|
61
|
-
* exactly once, and they do.
|
|
62
|
-
*/
|
|
63
|
-
declare const RECORD_CAPABILITIES: {
|
|
64
|
-
readonly get_record: {
|
|
65
|
-
readonly name: "get_record";
|
|
66
|
-
readonly kind: "read";
|
|
67
|
-
readonly input: z.ZodObject<{
|
|
68
|
-
recordId: z.ZodString;
|
|
69
|
-
fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
70
|
-
}, z.core.$strip>;
|
|
71
|
-
};
|
|
72
|
-
readonly search_records: {
|
|
73
|
-
readonly name: "search_records";
|
|
74
|
-
readonly kind: "read";
|
|
75
|
-
readonly input: z.ZodObject<{
|
|
76
|
-
objectId: z.ZodString;
|
|
77
|
-
_displayLabel: z.ZodOptional<z.ZodString>;
|
|
78
|
-
query: z.ZodOptional<z.ZodString>;
|
|
79
|
-
limit: z.ZodOptional<z.ZodNumber>;
|
|
80
|
-
offset: z.ZodOptional<z.ZodNumber>;
|
|
81
|
-
fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
82
|
-
filters: z.ZodOptional<z.ZodObject<{
|
|
83
|
-
combinator: z.ZodDefault<z.ZodEnum<{
|
|
84
|
-
and: "and";
|
|
85
|
-
or: "or";
|
|
86
|
-
}>>;
|
|
87
|
-
rules: z.ZodArray<z.ZodObject<{
|
|
88
|
-
attribute: z.ZodString;
|
|
89
|
-
property: z.ZodOptional<z.ZodString>;
|
|
90
|
-
operator: z.ZodString;
|
|
91
|
-
value: z.ZodNullable<z.ZodUnknown>;
|
|
92
|
-
}, z.core.$strip>>;
|
|
93
|
-
}, z.core.$strip>>;
|
|
94
|
-
sorts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
95
|
-
attribute: z.ZodString;
|
|
96
|
-
direction: z.ZodEnum<{
|
|
97
|
-
asc: "asc";
|
|
98
|
-
desc: "desc";
|
|
99
|
-
}>;
|
|
100
|
-
}, z.core.$strip>>>;
|
|
101
|
-
}, z.core.$strip>;
|
|
102
|
-
};
|
|
103
|
-
readonly create_record: {
|
|
104
|
-
readonly name: "create_record";
|
|
105
|
-
readonly kind: "create";
|
|
106
|
-
readonly input: z.ZodObject<{
|
|
107
|
-
objectId: z.ZodString;
|
|
108
|
-
_displayLabel: z.ZodOptional<z.ZodString>;
|
|
109
|
-
data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
110
|
-
}, z.core.$strip>;
|
|
111
|
-
};
|
|
112
|
-
readonly update_record: {
|
|
113
|
-
readonly name: "update_record";
|
|
114
|
-
readonly kind: "update";
|
|
115
|
-
readonly input: z.ZodObject<{
|
|
116
|
-
recordId: z.ZodString;
|
|
117
|
-
data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
118
|
-
}, z.core.$strip>;
|
|
119
|
-
};
|
|
120
|
-
readonly delete_record: {
|
|
121
|
-
readonly name: "delete_record";
|
|
122
|
-
readonly kind: "delete";
|
|
123
|
-
readonly input: z.ZodObject<{
|
|
124
|
-
recordId: z.ZodString;
|
|
125
|
-
}, z.core.$strip>;
|
|
126
|
-
};
|
|
127
|
-
};
|
|
128
|
-
type RecordCapabilityName = keyof typeof RECORD_CAPABILITIES;
|
|
129
|
-
/**
|
|
130
|
-
* A capability's argument type, inferred from the very schema the runtime
|
|
131
|
-
* validates against.
|
|
132
|
-
*
|
|
133
|
-
* `z.input`, not `z.infer`: these are the arguments a caller supplies, and the
|
|
134
|
-
* two sides differ wherever a field has a `.default()` — `filtersSchema`'s
|
|
135
|
-
* `combinator` is required on the output and optional on the input. Typing
|
|
136
|
-
* arguments with the output side made the SDK demand a `combinator` the runtime
|
|
137
|
-
* would have filled in anyway.
|
|
138
|
-
*/
|
|
139
|
-
type CapabilityInput<N extends RecordCapabilityName> = z.input<(typeof RECORD_CAPABILITIES)[N]["input"]>;
|
|
140
|
-
/**
|
|
141
|
-
* The capability → kind projection, derived rather than restated. The reflexes
|
|
142
|
-
* module reads this instead of maintaining its own table (D26/D28).
|
|
143
|
-
*/
|
|
144
|
-
declare const RECORD_CAPABILITY_KINDS: Readonly<Record<RecordCapabilityName, CapabilityKind>>;
|
|
145
|
-
|
|
146
|
-
export { type CapabilityInput, type CapabilityKind, type FilterRuleInput, type FilterStateInput, OBJECT_ID_DESCRIPTION, RECORD_CAPABILITIES, RECORD_CAPABILITY_KINDS, type RecordCapabilityName, SANDBOX_FILE_DATA_HINT, filtersSchema, sortsSchema };
|
package/dist/capabilities.d.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
/** Accepted forms of the object identifier every object-scoped capability takes. */
|
|
4
|
-
declare const OBJECT_ID_DESCRIPTION = "Object UUID, kebab-case name (e.g., 'contacts'), or display label (e.g., 'Personne physique'). All three are accepted; UUID is most precise.";
|
|
5
|
-
/** Shared suffix for record `data` inputs that accept `$fromSandboxFile` references for large content. */
|
|
6
|
-
declare const SANDBOX_FILE_DATA_HINT = " For large text content (> a few KB), write it to a sandbox file first and pass {\"$fromSandboxFile\": \"/workspace/<file>\"} as the attribute value \u2014 the server substitutes the file content.";
|
|
7
|
-
/**
|
|
8
|
-
* The LLM-facing filter shape, deliberately looser than its two siblings:
|
|
9
|
-
* `types/filters.ts` (`FilterState`, the canonical TS model — its `quantifier`
|
|
10
|
-
* is omitted here on purpose, agents don't set edge quantifiers) and
|
|
11
|
-
* `validators/view-config.schema.ts` (`filterStateSchema`, the strict capped
|
|
12
|
-
* variant for stored view config). The operator list in the describe text
|
|
13
|
-
* restates `filters/operators.ts` (`OPERATOR_SPECS`) and
|
|
14
|
-
* `filters/normalize-operator.ts` (`SYNONYM_ALIASES`) — those are the source
|
|
15
|
-
* of truth; keep the prose in sync when adding an operator.
|
|
16
|
-
*/
|
|
17
|
-
declare const filtersSchema: z.ZodObject<{
|
|
18
|
-
combinator: z.ZodDefault<z.ZodEnum<{
|
|
19
|
-
and: "and";
|
|
20
|
-
or: "or";
|
|
21
|
-
}>>;
|
|
22
|
-
rules: z.ZodArray<z.ZodObject<{
|
|
23
|
-
attribute: z.ZodString;
|
|
24
|
-
property: z.ZodOptional<z.ZodString>;
|
|
25
|
-
operator: z.ZodString;
|
|
26
|
-
value: z.ZodNullable<z.ZodUnknown>;
|
|
27
|
-
}, z.core.$strip>>;
|
|
28
|
-
}, z.core.$strip>;
|
|
29
|
-
declare const sortsSchema: z.ZodArray<z.ZodObject<{
|
|
30
|
-
attribute: z.ZodString;
|
|
31
|
-
direction: z.ZodEnum<{
|
|
32
|
-
asc: "asc";
|
|
33
|
-
desc: "desc";
|
|
34
|
-
}>;
|
|
35
|
-
}, z.core.$strip>>;
|
|
36
|
-
/**
|
|
37
|
-
* Filter shapes derived from {@link filtersSchema} so the capability schema stays
|
|
38
|
-
* the single source of truth.
|
|
39
|
-
*
|
|
40
|
-
* The *parsed* shape (`z.infer`), deliberately: the runtime holds these after
|
|
41
|
-
* validation, when `combinator` has already been defaulted. What a caller may
|
|
42
|
-
* omit is `z.input`, and that is what {@link CapabilityInput} exposes.
|
|
43
|
-
*/
|
|
44
|
-
type FilterStateInput = z.infer<typeof filtersSchema>;
|
|
45
|
-
type FilterRuleInput = FilterStateInput["rules"][number];
|
|
46
|
-
/** How a capability mutates data, which decides whether a rehearsal captures it. */
|
|
47
|
-
type CapabilityKind = "read" | "create" | "update" | "delete";
|
|
48
|
-
/**
|
|
49
|
-
* Every capability a Reflex may call, defined once.
|
|
50
|
-
*
|
|
51
|
-
* Deliberately five entries — the single-record tools whose input the gateway can
|
|
52
|
-
* turn into a faithful `RunEffect`. Excluded on purpose: `get_schema`,
|
|
53
|
-
* `global_search` and `bulk_search`, which are not scoped to one object and so
|
|
54
|
-
* yield no object to grant a permission on; and the `bulk_*` record tools, where
|
|
55
|
-
* one call mutates many records and would be recorded as a single effect, making
|
|
56
|
-
* an effects report understate what happened.
|
|
57
|
-
*
|
|
58
|
-
* `description` is NOT here: the tools compute it per call from their config
|
|
59
|
-
* (`schemaInContext` changes the wording), and `schema-tools-descriptions.test.ts`
|
|
60
|
-
* pins both variants. The name, the kind and the input schema are what must exist
|
|
61
|
-
* exactly once, and they do.
|
|
62
|
-
*/
|
|
63
|
-
declare const RECORD_CAPABILITIES: {
|
|
64
|
-
readonly get_record: {
|
|
65
|
-
readonly name: "get_record";
|
|
66
|
-
readonly kind: "read";
|
|
67
|
-
readonly input: z.ZodObject<{
|
|
68
|
-
recordId: z.ZodString;
|
|
69
|
-
fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
70
|
-
}, z.core.$strip>;
|
|
71
|
-
};
|
|
72
|
-
readonly search_records: {
|
|
73
|
-
readonly name: "search_records";
|
|
74
|
-
readonly kind: "read";
|
|
75
|
-
readonly input: z.ZodObject<{
|
|
76
|
-
objectId: z.ZodString;
|
|
77
|
-
_displayLabel: z.ZodOptional<z.ZodString>;
|
|
78
|
-
query: z.ZodOptional<z.ZodString>;
|
|
79
|
-
limit: z.ZodOptional<z.ZodNumber>;
|
|
80
|
-
offset: z.ZodOptional<z.ZodNumber>;
|
|
81
|
-
fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
82
|
-
filters: z.ZodOptional<z.ZodObject<{
|
|
83
|
-
combinator: z.ZodDefault<z.ZodEnum<{
|
|
84
|
-
and: "and";
|
|
85
|
-
or: "or";
|
|
86
|
-
}>>;
|
|
87
|
-
rules: z.ZodArray<z.ZodObject<{
|
|
88
|
-
attribute: z.ZodString;
|
|
89
|
-
property: z.ZodOptional<z.ZodString>;
|
|
90
|
-
operator: z.ZodString;
|
|
91
|
-
value: z.ZodNullable<z.ZodUnknown>;
|
|
92
|
-
}, z.core.$strip>>;
|
|
93
|
-
}, z.core.$strip>>;
|
|
94
|
-
sorts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
95
|
-
attribute: z.ZodString;
|
|
96
|
-
direction: z.ZodEnum<{
|
|
97
|
-
asc: "asc";
|
|
98
|
-
desc: "desc";
|
|
99
|
-
}>;
|
|
100
|
-
}, z.core.$strip>>>;
|
|
101
|
-
}, z.core.$strip>;
|
|
102
|
-
};
|
|
103
|
-
readonly create_record: {
|
|
104
|
-
readonly name: "create_record";
|
|
105
|
-
readonly kind: "create";
|
|
106
|
-
readonly input: z.ZodObject<{
|
|
107
|
-
objectId: z.ZodString;
|
|
108
|
-
_displayLabel: z.ZodOptional<z.ZodString>;
|
|
109
|
-
data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
110
|
-
}, z.core.$strip>;
|
|
111
|
-
};
|
|
112
|
-
readonly update_record: {
|
|
113
|
-
readonly name: "update_record";
|
|
114
|
-
readonly kind: "update";
|
|
115
|
-
readonly input: z.ZodObject<{
|
|
116
|
-
recordId: z.ZodString;
|
|
117
|
-
data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
118
|
-
}, z.core.$strip>;
|
|
119
|
-
};
|
|
120
|
-
readonly delete_record: {
|
|
121
|
-
readonly name: "delete_record";
|
|
122
|
-
readonly kind: "delete";
|
|
123
|
-
readonly input: z.ZodObject<{
|
|
124
|
-
recordId: z.ZodString;
|
|
125
|
-
}, z.core.$strip>;
|
|
126
|
-
};
|
|
127
|
-
};
|
|
128
|
-
type RecordCapabilityName = keyof typeof RECORD_CAPABILITIES;
|
|
129
|
-
/**
|
|
130
|
-
* A capability's argument type, inferred from the very schema the runtime
|
|
131
|
-
* validates against.
|
|
132
|
-
*
|
|
133
|
-
* `z.input`, not `z.infer`: these are the arguments a caller supplies, and the
|
|
134
|
-
* two sides differ wherever a field has a `.default()` — `filtersSchema`'s
|
|
135
|
-
* `combinator` is required on the output and optional on the input. Typing
|
|
136
|
-
* arguments with the output side made the SDK demand a `combinator` the runtime
|
|
137
|
-
* would have filled in anyway.
|
|
138
|
-
*/
|
|
139
|
-
type CapabilityInput<N extends RecordCapabilityName> = z.input<(typeof RECORD_CAPABILITIES)[N]["input"]>;
|
|
140
|
-
/**
|
|
141
|
-
* The capability → kind projection, derived rather than restated. The reflexes
|
|
142
|
-
* module reads this instead of maintaining its own table (D26/D28).
|
|
143
|
-
*/
|
|
144
|
-
declare const RECORD_CAPABILITY_KINDS: Readonly<Record<RecordCapabilityName, CapabilityKind>>;
|
|
145
|
-
|
|
146
|
-
export { type CapabilityInput, type CapabilityKind, type FilterRuleInput, type FilterStateInput, OBJECT_ID_DESCRIPTION, RECORD_CAPABILITIES, RECORD_CAPABILITY_KINDS, type RecordCapabilityName, SANDBOX_FILE_DATA_HINT, filtersSchema, sortsSchema };
|
package/dist/capabilities.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var zod = require('zod');
|
|
4
|
-
|
|
5
|
-
// src/capabilities.ts
|
|
6
|
-
var OBJECT_ID_DESCRIPTION = "Object UUID, kebab-case name (e.g., 'contacts'), or display label (e.g., 'Personne physique'). All three are accepted; UUID is most precise.";
|
|
7
|
-
var SANDBOX_FILE_DATA_HINT = ' For large text content (> a few KB), write it to a sandbox file first and pass {"$fromSandboxFile": "/workspace/<file>"} as the attribute value \u2014 the server substitutes the file content.';
|
|
8
|
-
var filtersSchema = zod.z.object({
|
|
9
|
-
combinator: zod.z.enum(["and", "or"]).default("and"),
|
|
10
|
-
rules: zod.z.array(
|
|
11
|
-
zod.z.object({
|
|
12
|
-
attribute: zod.z.string().describe("Attribute name on the object being searched"),
|
|
13
|
-
property: zod.z.string().optional().describe(
|
|
14
|
-
"Optional. Only valid when 'attribute' is a relation / document / user attribute declared with .qualifyWith({...}). When set, the rule filters on the named EDGE property (not the linked record) and the operator must be valid for that property's type. See <filter_operators>."
|
|
15
|
-
),
|
|
16
|
-
operator: zod.z.string().describe(
|
|
17
|
-
"Filter operator (canonical: is, is_not, contains, not_contains, starts_with, ends_with, less_than, greater_than, less_or_equal, greater_or_equal, is_within, on_day_month, any_of, none_of, is_empty, is_not_empty). Short codes (lt, gt, lte, gte, eq, neq, in) are accepted as input and auto-normalized to the canonical names. The valid set depends on the attribute type (or property type when 'property' is set) \u2014 see <filter_operators>."
|
|
18
|
-
),
|
|
19
|
-
value: zod.z.unknown().nullable().describe(
|
|
20
|
-
"Value matching the attribute (or property) type: scalar for is/contains/less_than/etc (checkbox is: true|false); array (string[]) for any_of/none_of; null for is_empty/is_not_empty; { amount, unit, direction } for is_within; { day, month } for on_day_month."
|
|
21
|
-
)
|
|
22
|
-
})
|
|
23
|
-
)
|
|
24
|
-
});
|
|
25
|
-
var sortsSchema = zod.z.array(
|
|
26
|
-
zod.z.object({
|
|
27
|
-
attribute: zod.z.string().describe("Attribute name"),
|
|
28
|
-
direction: zod.z.enum(["asc", "desc"])
|
|
29
|
-
})
|
|
30
|
-
);
|
|
31
|
-
var getRecordInput = zod.z.object({
|
|
32
|
-
recordId: zod.z.string().describe("Record UUID"),
|
|
33
|
-
fields: zod.z.array(zod.z.string()).optional().describe("Attribute names to return")
|
|
34
|
-
});
|
|
35
|
-
var searchRecordsInput = zod.z.object({
|
|
36
|
-
objectId: zod.z.string().describe(OBJECT_ID_DESCRIPTION),
|
|
37
|
-
_displayLabel: zod.z.string().optional().describe("Display label"),
|
|
38
|
-
query: zod.z.string().optional().describe("Full-text search query (omit to browse/list)"),
|
|
39
|
-
limit: zod.z.number().optional().describe("Max results per call: 1-1000 (default 20). Paginate via offset for more."),
|
|
40
|
-
offset: zod.z.number().optional().describe("Skip N records (default 0)"),
|
|
41
|
-
fields: zod.z.array(zod.z.string()).optional().describe("Attribute names to include in values"),
|
|
42
|
-
filters: filtersSchema.optional().describe(
|
|
43
|
-
"Structured filter: { combinator: 'and'|'or', rules: [{attribute, operator, value, property?}] }. Operators are constrained per attribute type \u2014 see <filter_operators>. Use 'property' on a rule to filter on a qualified edge property."
|
|
44
|
-
),
|
|
45
|
-
sorts: sortsSchema.optional().describe("Sorts: [{ attribute, direction: 'asc'|'desc' }]")
|
|
46
|
-
});
|
|
47
|
-
var createRecordInput = zod.z.object({
|
|
48
|
-
objectId: zod.z.string().describe(OBJECT_ID_DESCRIPTION),
|
|
49
|
-
_displayLabel: zod.z.string().optional().describe("Display label"),
|
|
50
|
-
data: zod.z.record(zod.z.string(), zod.z.unknown()).describe(`Record data.${SANDBOX_FILE_DATA_HINT}`)
|
|
51
|
-
});
|
|
52
|
-
var updateRecordInput = zod.z.object({
|
|
53
|
-
recordId: zod.z.string().describe("Record UUID"),
|
|
54
|
-
data: zod.z.record(zod.z.string(), zod.z.unknown()).describe(`Fields to update.${SANDBOX_FILE_DATA_HINT}`)
|
|
55
|
-
});
|
|
56
|
-
var deleteRecordInput = zod.z.object({
|
|
57
|
-
recordId: zod.z.string().describe("Record UUID")
|
|
58
|
-
});
|
|
59
|
-
var RECORD_CAPABILITIES = {
|
|
60
|
-
get_record: { name: "get_record", kind: "read", input: getRecordInput },
|
|
61
|
-
search_records: { name: "search_records", kind: "read", input: searchRecordsInput },
|
|
62
|
-
create_record: { name: "create_record", kind: "create", input: createRecordInput },
|
|
63
|
-
update_record: { name: "update_record", kind: "update", input: updateRecordInput },
|
|
64
|
-
delete_record: { name: "delete_record", kind: "delete", input: deleteRecordInput }
|
|
65
|
-
};
|
|
66
|
-
var RECORD_CAPABILITY_KINDS = Object.freeze(
|
|
67
|
-
Object.fromEntries(
|
|
68
|
-
Object.values(RECORD_CAPABILITIES).map((capability) => [capability.name, capability.kind])
|
|
69
|
-
)
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
exports.OBJECT_ID_DESCRIPTION = OBJECT_ID_DESCRIPTION;
|
|
73
|
-
exports.RECORD_CAPABILITIES = RECORD_CAPABILITIES;
|
|
74
|
-
exports.RECORD_CAPABILITY_KINDS = RECORD_CAPABILITY_KINDS;
|
|
75
|
-
exports.SANDBOX_FILE_DATA_HINT = SANDBOX_FILE_DATA_HINT;
|
|
76
|
-
exports.filtersSchema = filtersSchema;
|
|
77
|
-
exports.sortsSchema = sortsSchema;
|
package/dist/capabilities.mjs
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
// src/capabilities.ts
|
|
4
|
-
var OBJECT_ID_DESCRIPTION = "Object UUID, kebab-case name (e.g., 'contacts'), or display label (e.g., 'Personne physique'). All three are accepted; UUID is most precise.";
|
|
5
|
-
var SANDBOX_FILE_DATA_HINT = ' For large text content (> a few KB), write it to a sandbox file first and pass {"$fromSandboxFile": "/workspace/<file>"} as the attribute value \u2014 the server substitutes the file content.';
|
|
6
|
-
var filtersSchema = z.object({
|
|
7
|
-
combinator: z.enum(["and", "or"]).default("and"),
|
|
8
|
-
rules: z.array(
|
|
9
|
-
z.object({
|
|
10
|
-
attribute: z.string().describe("Attribute name on the object being searched"),
|
|
11
|
-
property: z.string().optional().describe(
|
|
12
|
-
"Optional. Only valid when 'attribute' is a relation / document / user attribute declared with .qualifyWith({...}). When set, the rule filters on the named EDGE property (not the linked record) and the operator must be valid for that property's type. See <filter_operators>."
|
|
13
|
-
),
|
|
14
|
-
operator: z.string().describe(
|
|
15
|
-
"Filter operator (canonical: is, is_not, contains, not_contains, starts_with, ends_with, less_than, greater_than, less_or_equal, greater_or_equal, is_within, on_day_month, any_of, none_of, is_empty, is_not_empty). Short codes (lt, gt, lte, gte, eq, neq, in) are accepted as input and auto-normalized to the canonical names. The valid set depends on the attribute type (or property type when 'property' is set) \u2014 see <filter_operators>."
|
|
16
|
-
),
|
|
17
|
-
value: z.unknown().nullable().describe(
|
|
18
|
-
"Value matching the attribute (or property) type: scalar for is/contains/less_than/etc (checkbox is: true|false); array (string[]) for any_of/none_of; null for is_empty/is_not_empty; { amount, unit, direction } for is_within; { day, month } for on_day_month."
|
|
19
|
-
)
|
|
20
|
-
})
|
|
21
|
-
)
|
|
22
|
-
});
|
|
23
|
-
var sortsSchema = z.array(
|
|
24
|
-
z.object({
|
|
25
|
-
attribute: z.string().describe("Attribute name"),
|
|
26
|
-
direction: z.enum(["asc", "desc"])
|
|
27
|
-
})
|
|
28
|
-
);
|
|
29
|
-
var getRecordInput = z.object({
|
|
30
|
-
recordId: z.string().describe("Record UUID"),
|
|
31
|
-
fields: z.array(z.string()).optional().describe("Attribute names to return")
|
|
32
|
-
});
|
|
33
|
-
var searchRecordsInput = z.object({
|
|
34
|
-
objectId: z.string().describe(OBJECT_ID_DESCRIPTION),
|
|
35
|
-
_displayLabel: z.string().optional().describe("Display label"),
|
|
36
|
-
query: z.string().optional().describe("Full-text search query (omit to browse/list)"),
|
|
37
|
-
limit: z.number().optional().describe("Max results per call: 1-1000 (default 20). Paginate via offset for more."),
|
|
38
|
-
offset: z.number().optional().describe("Skip N records (default 0)"),
|
|
39
|
-
fields: z.array(z.string()).optional().describe("Attribute names to include in values"),
|
|
40
|
-
filters: filtersSchema.optional().describe(
|
|
41
|
-
"Structured filter: { combinator: 'and'|'or', rules: [{attribute, operator, value, property?}] }. Operators are constrained per attribute type \u2014 see <filter_operators>. Use 'property' on a rule to filter on a qualified edge property."
|
|
42
|
-
),
|
|
43
|
-
sorts: sortsSchema.optional().describe("Sorts: [{ attribute, direction: 'asc'|'desc' }]")
|
|
44
|
-
});
|
|
45
|
-
var createRecordInput = z.object({
|
|
46
|
-
objectId: z.string().describe(OBJECT_ID_DESCRIPTION),
|
|
47
|
-
_displayLabel: z.string().optional().describe("Display label"),
|
|
48
|
-
data: z.record(z.string(), z.unknown()).describe(`Record data.${SANDBOX_FILE_DATA_HINT}`)
|
|
49
|
-
});
|
|
50
|
-
var updateRecordInput = z.object({
|
|
51
|
-
recordId: z.string().describe("Record UUID"),
|
|
52
|
-
data: z.record(z.string(), z.unknown()).describe(`Fields to update.${SANDBOX_FILE_DATA_HINT}`)
|
|
53
|
-
});
|
|
54
|
-
var deleteRecordInput = z.object({
|
|
55
|
-
recordId: z.string().describe("Record UUID")
|
|
56
|
-
});
|
|
57
|
-
var RECORD_CAPABILITIES = {
|
|
58
|
-
get_record: { name: "get_record", kind: "read", input: getRecordInput },
|
|
59
|
-
search_records: { name: "search_records", kind: "read", input: searchRecordsInput },
|
|
60
|
-
create_record: { name: "create_record", kind: "create", input: createRecordInput },
|
|
61
|
-
update_record: { name: "update_record", kind: "update", input: updateRecordInput },
|
|
62
|
-
delete_record: { name: "delete_record", kind: "delete", input: deleteRecordInput }
|
|
63
|
-
};
|
|
64
|
-
var RECORD_CAPABILITY_KINDS = Object.freeze(
|
|
65
|
-
Object.fromEntries(
|
|
66
|
-
Object.values(RECORD_CAPABILITIES).map((capability) => [capability.name, capability.kind])
|
|
67
|
-
)
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
export { OBJECT_ID_DESCRIPTION, RECORD_CAPABILITIES, RECORD_CAPABILITY_KINDS, SANDBOX_FILE_DATA_HINT, filtersSchema, sortsSchema };
|
package/dist/chunk-2WWGHULM.mjs
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { createRelationValidator } from './chunk-GO6LQADH.mjs';
|
|
2
|
-
import { createRichtextValidator } from './chunk-QVLQPW3O.mjs';
|
|
3
|
-
import { createMultiselectValidator, createSelectValidator, createStatusValidator } from './chunk-ZDQ5AP26.mjs';
|
|
4
|
-
import { createUserValidator } from './chunk-LV3FEUKU.mjs';
|
|
5
|
-
import { createFormulaValidator } from './chunk-UXAHLSWC.mjs';
|
|
6
|
-
import { createRollupValidator } from './chunk-NS63SPNN.mjs';
|
|
7
|
-
import { createCheckboxValidator } from './chunk-OSSGN43B.mjs';
|
|
8
|
-
import { createDateValidator } from './chunk-Q44QKLN4.mjs';
|
|
9
|
-
import { createNumberValidator } from './chunk-UANQJ2GH.mjs';
|
|
10
|
-
import { createTextValidator } from './chunk-O73ROMWQ.mjs';
|
|
11
|
-
import { ValidationError } from './chunk-CLZORRMS.mjs';
|
|
12
|
-
import { createCurrencyValidator } from './chunk-AYVHMVKQ.mjs';
|
|
13
|
-
import { createLocationValidator } from './chunk-YUFTHPOE.mjs';
|
|
14
|
-
import { createPhoneValidator } from './chunk-R5LAJCBU.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
|
-
|
|
78
|
-
// src/lib/empty.ts
|
|
79
|
-
function isNullishOrEmptyString(value) {
|
|
80
|
-
return value === null || value === void 0 || value === "";
|
|
81
|
-
}
|
|
82
|
-
function isValuePresent(value) {
|
|
83
|
-
if (value === null || value === void 0) return false;
|
|
84
|
-
if (typeof value === "string") return value.trim() !== "";
|
|
85
|
-
if (Array.isArray(value)) return value.length > 0;
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// src/validation/object/object-validator.ts
|
|
90
|
-
var objectValidatorCache = /* @__PURE__ */ new WeakMap();
|
|
91
|
-
var draftValidatorCache = /* @__PURE__ */ new WeakMap();
|
|
92
|
-
function createObjectValidator(objectDef) {
|
|
93
|
-
const cached = objectValidatorCache.get(objectDef);
|
|
94
|
-
if (cached) return cached;
|
|
95
|
-
const shape = {};
|
|
96
|
-
for (const attr of objectDef.attributes) {
|
|
97
|
-
const validator = createAttributeValidator(attr);
|
|
98
|
-
if (attr.required) {
|
|
99
|
-
shape[attr.name] = validator.refine(isValuePresent, {
|
|
100
|
-
message: DEFAULT_VALIDATION_MESSAGES.required(attr)
|
|
101
|
-
});
|
|
102
|
-
} else {
|
|
103
|
-
shape[attr.name] = withEmptyToNull(validator);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
const schema = z.object(shape).passthrough();
|
|
107
|
-
objectValidatorCache.set(objectDef, schema);
|
|
108
|
-
return schema;
|
|
109
|
-
}
|
|
110
|
-
function createDraftValidator(objectDef) {
|
|
111
|
-
const cached = draftValidatorCache.get(objectDef);
|
|
112
|
-
if (cached) return cached;
|
|
113
|
-
const shape = {};
|
|
114
|
-
for (const attr of objectDef.attributes) {
|
|
115
|
-
const validator = createAttributeValidator(attr);
|
|
116
|
-
shape[attr.name] = withEmptyToNull(validator);
|
|
117
|
-
}
|
|
118
|
-
const schema = z.object(shape).passthrough();
|
|
119
|
-
draftValidatorCache.set(objectDef, schema);
|
|
120
|
-
return schema;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// src/validation/object/helpers.ts
|
|
124
|
-
function validateAttribute(attr, value) {
|
|
125
|
-
const validator = createAttributeValidator(attr);
|
|
126
|
-
if (!attr.required && (value === void 0 || value === null)) {
|
|
127
|
-
return { success: true, data: { [attr.name]: value } };
|
|
128
|
-
}
|
|
129
|
-
const result = validator.safeParse(value);
|
|
130
|
-
if (result.success) {
|
|
131
|
-
return {
|
|
132
|
-
success: true,
|
|
133
|
-
data: { [attr.name]: result.data }
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
return {
|
|
137
|
-
success: false,
|
|
138
|
-
errors: formatZodErrors(result.error).map((err) => ({
|
|
139
|
-
path: [attr.name, ...err.path],
|
|
140
|
-
message: err.message
|
|
141
|
-
}))
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
function validateObject(objectDef, data) {
|
|
145
|
-
const validator = createObjectValidator(objectDef);
|
|
146
|
-
const result = validator.safeParse(data);
|
|
147
|
-
if (result.success) {
|
|
148
|
-
return {
|
|
149
|
-
success: true,
|
|
150
|
-
data: result.data
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
return {
|
|
154
|
-
success: false,
|
|
155
|
-
errors: formatZodErrors(result.error)
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
function validateObjectOrThrow(objectDef, data) {
|
|
159
|
-
const result = validateObject(objectDef, data);
|
|
160
|
-
if (!result.success) {
|
|
161
|
-
const errors = result.errors ?? [];
|
|
162
|
-
const detail = errors.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
|
|
163
|
-
throw new ValidationError(
|
|
164
|
-
`Validation failed for ${objectDef.label}:
|
|
165
|
-
${detail}`,
|
|
166
|
-
errors.map((err) => ({ path: err.path, message: err.message }))
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
return result.data;
|
|
170
|
-
}
|
|
171
|
-
function validateDraft(objectDef, data) {
|
|
172
|
-
const validator = createDraftValidator(objectDef);
|
|
173
|
-
const result = validator.safeParse(data);
|
|
174
|
-
if (result.success) {
|
|
175
|
-
return {
|
|
176
|
-
success: true,
|
|
177
|
-
data: result.data
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
return {
|
|
181
|
-
success: false,
|
|
182
|
-
errors: formatZodErrors(result.error)
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
function validateDraftOrThrow(objectDef, data) {
|
|
186
|
-
const result = validateDraft(objectDef, data);
|
|
187
|
-
if (!result.success) {
|
|
188
|
-
const errors = result.errors ?? [];
|
|
189
|
-
const detail = errors.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
|
|
190
|
-
throw new ValidationError(
|
|
191
|
-
`Draft validation failed for ${objectDef.label}:
|
|
192
|
-
${detail}`,
|
|
193
|
-
errors.map((err) => ({ path: err.path, message: err.message }))
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
return result.data;
|
|
197
|
-
}
|
|
198
|
-
function rejectUnknownAttributesOrThrow(objectDef, data) {
|
|
199
|
-
const knownNames = new Set(objectDef.attributes.map((a) => a.name));
|
|
200
|
-
const unknownKeys = Object.keys(data).filter((key) => !knownNames.has(key));
|
|
201
|
-
if (unknownKeys.length > 0) {
|
|
202
|
-
throw new ValidationError(
|
|
203
|
-
`Unknown attribute${unknownKeys.length > 1 ? "s" : ""} for ${objectDef.label}: ${unknownKeys.join(", ")}`,
|
|
204
|
-
unknownKeys.map((key) => ({ path: [key], message: "Unknown attribute" }))
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
function getMissingRequiredAttributes(objectDef, data) {
|
|
209
|
-
const missing = [];
|
|
210
|
-
for (const attr of objectDef.attributes) {
|
|
211
|
-
if (attr.required && !isValuePresent(data[attr.name])) {
|
|
212
|
-
missing.push(attr);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return missing;
|
|
216
|
-
}
|
|
217
|
-
function isRecordComplete(objectDef, data) {
|
|
218
|
-
const missing = getMissingRequiredAttributes(objectDef, data);
|
|
219
|
-
if (missing.length > 0) {
|
|
220
|
-
return false;
|
|
221
|
-
}
|
|
222
|
-
const validation = validateObject(objectDef, data);
|
|
223
|
-
return validation.success;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
export { createAttributeValidator, createDraftValidator, createFormAttributeValidator, createObjectValidator, getMissingRequiredAttributes, isNullishOrEmptyString, isRecordComplete, isValuePresent, rejectUnknownAttributesOrThrow, validateAttribute, validateDraft, validateDraftOrThrow, validateObject, validateObjectOrThrow };
|