@agentuity/schema 0.0.110 → 0.0.112
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/complex/object.d.ts
CHANGED
|
@@ -13,6 +13,12 @@ type InferObjectShape<T extends ObjectShape> = {
|
|
|
13
13
|
} & {
|
|
14
14
|
[K in OptionalKeys<T>]?: Infer<T[K]>;
|
|
15
15
|
};
|
|
16
|
+
type PartialShape<T extends ObjectShape> = {
|
|
17
|
+
[K in keyof T]: OptionalSchema<T[K]>;
|
|
18
|
+
};
|
|
19
|
+
type PickShape<T extends ObjectShape, K extends keyof T> = Pick<T, K>;
|
|
20
|
+
type OmitShape<T extends ObjectShape, K extends keyof T> = Omit<T, K>;
|
|
21
|
+
type ExtendShape<T extends ObjectShape, U extends ObjectShape> = Omit<T, keyof U> & U;
|
|
16
22
|
/**
|
|
17
23
|
* Schema for validating objects with typed properties.
|
|
18
24
|
* Validates each property according to its schema and collects all validation errors.
|
|
@@ -51,6 +57,61 @@ export declare class ObjectSchema<T extends ObjectShape> implements Schema<Infer
|
|
|
51
57
|
describe(description: string): this;
|
|
52
58
|
optional(): OptionalSchema<this>;
|
|
53
59
|
nullable(): import("..").NullableSchema<this>;
|
|
60
|
+
/**
|
|
61
|
+
* Create a new object schema with only the specified keys.
|
|
62
|
+
* Similar to TypeScript's Pick<T, K> utility type.
|
|
63
|
+
*
|
|
64
|
+
* @param keys - Array of keys to pick from the schema
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const userSchema = s.object({ name: s.string(), age: s.number(), email: s.string() });
|
|
69
|
+
* const nameOnlySchema = userSchema.pick(['name']);
|
|
70
|
+
* // { name: string }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
pick<K extends keyof T & string>(keys: readonly K[]): ObjectSchema<PickShape<T, K>>;
|
|
74
|
+
/**
|
|
75
|
+
* Create a new object schema without the specified keys.
|
|
76
|
+
* Similar to TypeScript's Omit<T, K> utility type.
|
|
77
|
+
*
|
|
78
|
+
* @param keys - Array of keys to omit from the schema
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const userSchema = s.object({ name: s.string(), age: s.number(), password: s.string() });
|
|
83
|
+
* const publicUserSchema = userSchema.omit(['password']);
|
|
84
|
+
* // { name: string; age: number }
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
omit<K extends keyof T & string>(keys: readonly K[]): ObjectSchema<OmitShape<T, K>>;
|
|
88
|
+
/**
|
|
89
|
+
* Create a new object schema where all properties are optional.
|
|
90
|
+
* Similar to TypeScript's Partial<T> utility type.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const userSchema = s.object({ name: s.string(), age: s.number() });
|
|
95
|
+
* const partialUserSchema = userSchema.partial();
|
|
96
|
+
* // { name?: string; age?: number }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
partial(): ObjectSchema<PartialShape<T>>;
|
|
100
|
+
/**
|
|
101
|
+
* Create a new object schema by extending this schema with additional properties.
|
|
102
|
+
* Properties in the extension override properties in the base schema.
|
|
103
|
+
* Similar to TypeScript's intersection types with override semantics.
|
|
104
|
+
*
|
|
105
|
+
* @param extension - Object shape to extend with
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const userSchema = s.object({ name: s.string(), age: s.number() });
|
|
110
|
+
* const adminSchema = userSchema.extend({ role: s.literal('admin'), permissions: s.array(s.string()) });
|
|
111
|
+
* // { name: string; age: number; role: 'admin'; permissions: string[] }
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
extend<U extends ObjectShape>(extension: U): ObjectSchema<ExtendShape<T, U>>;
|
|
54
115
|
parse: (this: Schema<any, InferObjectShape<T>>, value: unknown) => InferObjectShape<T>;
|
|
55
116
|
safeParse: (this: Schema<any, InferObjectShape<T>>, value: unknown) => import("..").SafeParseResult<InferObjectShape<T>>;
|
|
56
117
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/complex/object.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,EAAY,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAI7D,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAIpD,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,cAAc,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;AAGlE,KAAK,YAAY,CAAC,CAAC,SAAS,WAAW,IAAI;KACzC,CAAC,IAAI,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,CAAC;CACzD,CAAC,MAAM,CAAC,CAAC,CAAC;AAEX,KAAK,YAAY,CAAC,CAAC,SAAS,WAAW,IAAI;KACzC,CAAC,IAAI,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GAAG,CAAC,GAAG,KAAK;CACzD,CAAC,MAAM,CAAC,CAAC,CAAC;AAGX,KAAK,gBAAgB,CAAC,CAAC,SAAS,WAAW,IAAI;KAC7C,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACnC,GAAG;KACF,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACpC,CAAC;
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/complex/object.ts"],"names":[],"mappings":"AAAA,OA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;;;;;;;;OAaG;IACH,MAAM,CAAC,CAAC,SAAS,WAAW,EAAE,SAAS,EAAE,CAAC,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAK5E,KAAK,kFAA2B;IAChC,SAAS,gHAA+B;CACxC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,WAAW,EAAE,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAEvE"}
|
package/dist/complex/object.js
CHANGED
|
@@ -78,6 +78,87 @@ export class ObjectSchema {
|
|
|
78
78
|
nullable() {
|
|
79
79
|
return nullable(this);
|
|
80
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Create a new object schema with only the specified keys.
|
|
83
|
+
* Similar to TypeScript's Pick<T, K> utility type.
|
|
84
|
+
*
|
|
85
|
+
* @param keys - Array of keys to pick from the schema
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const userSchema = s.object({ name: s.string(), age: s.number(), email: s.string() });
|
|
90
|
+
* const nameOnlySchema = userSchema.pick(['name']);
|
|
91
|
+
* // { name: string }
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
pick(keys) {
|
|
95
|
+
const newShape = {};
|
|
96
|
+
for (const key of keys) {
|
|
97
|
+
if (key in this.shape) {
|
|
98
|
+
newShape[key] = this.shape[key];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return new ObjectSchema(newShape);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Create a new object schema without the specified keys.
|
|
105
|
+
* Similar to TypeScript's Omit<T, K> utility type.
|
|
106
|
+
*
|
|
107
|
+
* @param keys - Array of keys to omit from the schema
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const userSchema = s.object({ name: s.string(), age: s.number(), password: s.string() });
|
|
112
|
+
* const publicUserSchema = userSchema.omit(['password']);
|
|
113
|
+
* // { name: string; age: number }
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
omit(keys) {
|
|
117
|
+
const keysSet = new Set(keys);
|
|
118
|
+
const newShape = {};
|
|
119
|
+
for (const [key, schema] of Object.entries(this.shape)) {
|
|
120
|
+
if (!keysSet.has(key)) {
|
|
121
|
+
newShape[key] = schema;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return new ObjectSchema(newShape);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Create a new object schema where all properties are optional.
|
|
128
|
+
* Similar to TypeScript's Partial<T> utility type.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const userSchema = s.object({ name: s.string(), age: s.number() });
|
|
133
|
+
* const partialUserSchema = userSchema.partial();
|
|
134
|
+
* // { name?: string; age?: number }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
partial() {
|
|
138
|
+
const newShape = {};
|
|
139
|
+
for (const [key, schema] of Object.entries(this.shape)) {
|
|
140
|
+
newShape[key] = optional(schema);
|
|
141
|
+
}
|
|
142
|
+
return new ObjectSchema(newShape);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Create a new object schema by extending this schema with additional properties.
|
|
146
|
+
* Properties in the extension override properties in the base schema.
|
|
147
|
+
* Similar to TypeScript's intersection types with override semantics.
|
|
148
|
+
*
|
|
149
|
+
* @param extension - Object shape to extend with
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* const userSchema = s.object({ name: s.string(), age: s.number() });
|
|
154
|
+
* const adminSchema = userSchema.extend({ role: s.literal('admin'), permissions: s.array(s.string()) });
|
|
155
|
+
* // { name: string; age: number; role: 'admin'; permissions: string[] }
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
extend(extension) {
|
|
159
|
+
const newShape = { ...this.shape, ...extension };
|
|
160
|
+
return new ObjectSchema(newShape);
|
|
161
|
+
}
|
|
81
162
|
parse = this.parseMethods.parse;
|
|
82
163
|
safeParse = this.parseMethods.safeParse;
|
|
83
164
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/complex/object.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAkB,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/complex/object.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAkB,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAuC7C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,YAAY;IAMJ;IAHpB,WAAW,CAAU;IACb,YAAY,GAAG,kBAAkB,EAAuB,CAAC;IAEjE,YAAoB,KAAQ;QAAR,UAAK,GAAL,KAAK,CAAG;IAAG,CAAC;IAEvB,WAAW,GAAG;QACtB,OAAO,EAAE,CAAU;QACnB,MAAM,EAAE,WAAW;QACnB,QAAQ,EAAE,CAAC,KAAc,EAAE,EAAE;YAC5B,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACpB,OAAO,OAAO,CAAC,CAAC,WAAW,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC;YAC5D,CAAC;YACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC1B,OAAO,OAAO,CAAC,CAAC,WAAW,CAAC,4BAA4B,CAAC,C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C,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACvD,QAAwB,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;QACnD,CAAC;QACD,OAAO,IAAI,YAAY,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAwB,SAAY;QACzC,MAAM,QAAQ,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,SAAS,EAAuB,CAAC;QACtE,OAAO,IAAI,YAAY,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;IAChC,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC;CACxC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,MAAM,CAAwB,KAAQ;IACrD,OAAO,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentuity/schema",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.112",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"author": "Agentuity employees and contributors",
|
|
6
6
|
"type": "module",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"prepublishOnly": "bun run clean && bun run build"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@agentuity/core": "0.0.
|
|
29
|
+
"@agentuity/core": "0.0.112"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@agentuity/test-utils": "0.0.
|
|
32
|
+
"@agentuity/test-utils": "0.0.112",
|
|
33
33
|
"@types/bun": "latest",
|
|
34
34
|
"bun-types": "latest",
|
|
35
35
|
"typescript": "^5.9.0"
|
package/src/complex/object.ts
CHANGED
|
@@ -26,6 +26,20 @@ type InferObjectShape<T extends ObjectShape> = {
|
|
|
26
26
|
[K in OptionalKeys<T>]?: Infer<T[K]>;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
+
// Helper type to make all properties optional schemas
|
|
30
|
+
type PartialShape<T extends ObjectShape> = {
|
|
31
|
+
[K in keyof T]: OptionalSchema<T[K]>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Helper type for picking keys from an object shape
|
|
35
|
+
type PickShape<T extends ObjectShape, K extends keyof T> = Pick<T, K>;
|
|
36
|
+
|
|
37
|
+
// Helper type for omitting keys from an object shape
|
|
38
|
+
type OmitShape<T extends ObjectShape, K extends keyof T> = Omit<T, K>;
|
|
39
|
+
|
|
40
|
+
// Helper type for extending an object shape
|
|
41
|
+
type ExtendShape<T extends ObjectShape, U extends ObjectShape> = Omit<T, keyof U> & U;
|
|
42
|
+
|
|
29
43
|
/**
|
|
30
44
|
* Schema for validating objects with typed properties.
|
|
31
45
|
* Validates each property according to its schema and collects all validation errors.
|
|
@@ -115,6 +129,91 @@ export class ObjectSchema<T extends ObjectShape>
|
|
|
115
129
|
return nullable(this);
|
|
116
130
|
}
|
|
117
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Create a new object schema with only the specified keys.
|
|
134
|
+
* Similar to TypeScript's Pick<T, K> utility type.
|
|
135
|
+
*
|
|
136
|
+
* @param keys - Array of keys to pick from the schema
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* const userSchema = s.object({ name: s.string(), age: s.number(), email: s.string() });
|
|
141
|
+
* const nameOnlySchema = userSchema.pick(['name']);
|
|
142
|
+
* // { name: string }
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
pick<K extends keyof T & string>(keys: readonly K[]): ObjectSchema<PickShape<T, K>> {
|
|
146
|
+
const newShape = {} as PickShape<T, K>;
|
|
147
|
+
for (const key of keys) {
|
|
148
|
+
if (key in this.shape) {
|
|
149
|
+
newShape[key] = this.shape[key];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return new ObjectSchema(newShape);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Create a new object schema without the specified keys.
|
|
157
|
+
* Similar to TypeScript's Omit<T, K> utility type.
|
|
158
|
+
*
|
|
159
|
+
* @param keys - Array of keys to omit from the schema
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* const userSchema = s.object({ name: s.string(), age: s.number(), password: s.string() });
|
|
164
|
+
* const publicUserSchema = userSchema.omit(['password']);
|
|
165
|
+
* // { name: string; age: number }
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
omit<K extends keyof T & string>(keys: readonly K[]): ObjectSchema<OmitShape<T, K>> {
|
|
169
|
+
const keysSet = new Set(keys);
|
|
170
|
+
const newShape = {} as OmitShape<T, K>;
|
|
171
|
+
for (const [key, schema] of Object.entries(this.shape)) {
|
|
172
|
+
if (!keysSet.has(key as K)) {
|
|
173
|
+
(newShape as ObjectShape)[key] = schema;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return new ObjectSchema(newShape);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Create a new object schema where all properties are optional.
|
|
181
|
+
* Similar to TypeScript's Partial<T> utility type.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* const userSchema = s.object({ name: s.string(), age: s.number() });
|
|
186
|
+
* const partialUserSchema = userSchema.partial();
|
|
187
|
+
* // { name?: string; age?: number }
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
partial(): ObjectSchema<PartialShape<T>> {
|
|
191
|
+
const newShape = {} as PartialShape<T>;
|
|
192
|
+
for (const [key, schema] of Object.entries(this.shape)) {
|
|
193
|
+
(newShape as ObjectShape)[key] = optional(schema);
|
|
194
|
+
}
|
|
195
|
+
return new ObjectSchema(newShape);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Create a new object schema by extending this schema with additional properties.
|
|
200
|
+
* Properties in the extension override properties in the base schema.
|
|
201
|
+
* Similar to TypeScript's intersection types with override semantics.
|
|
202
|
+
*
|
|
203
|
+
* @param extension - Object shape to extend with
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* const userSchema = s.object({ name: s.string(), age: s.number() });
|
|
208
|
+
* const adminSchema = userSchema.extend({ role: s.literal('admin'), permissions: s.array(s.string()) });
|
|
209
|
+
* // { name: string; age: number; role: 'admin'; permissions: string[] }
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
extend<U extends ObjectShape>(extension: U): ObjectSchema<ExtendShape<T, U>> {
|
|
213
|
+
const newShape = { ...this.shape, ...extension } as ExtendShape<T, U>;
|
|
214
|
+
return new ObjectSchema(newShape);
|
|
215
|
+
}
|
|
216
|
+
|
|
118
217
|
parse = this.parseMethods.parse;
|
|
119
218
|
safeParse = this.parseMethods.safeParse;
|
|
120
219
|
}
|