@agentuity/schema 0.0.69
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/AGENTS.md +86 -0
- package/README.md +323 -0
- package/dist/base.d.ts +111 -0
- package/dist/base.d.ts.map +1 -0
- package/dist/base.js +93 -0
- package/dist/base.js.map +1 -0
- package/dist/coerce/boolean.d.ts +37 -0
- package/dist/coerce/boolean.d.ts.map +1 -0
- package/dist/coerce/boolean.js +49 -0
- package/dist/coerce/boolean.js.map +1 -0
- package/dist/coerce/date.d.ts +36 -0
- package/dist/coerce/date.d.ts.map +1 -0
- package/dist/coerce/date.js +60 -0
- package/dist/coerce/date.js.map +1 -0
- package/dist/coerce/number.d.ts +36 -0
- package/dist/coerce/number.d.ts.map +1 -0
- package/dist/coerce/number.js +59 -0
- package/dist/coerce/number.js.map +1 -0
- package/dist/coerce/string.d.ts +35 -0
- package/dist/coerce/string.d.ts.map +1 -0
- package/dist/coerce/string.js +47 -0
- package/dist/coerce/string.js.map +1 -0
- package/dist/complex/array.d.ts +56 -0
- package/dist/complex/array.d.ts.map +1 -0
- package/dist/complex/array.js +96 -0
- package/dist/complex/array.js.map +1 -0
- package/dist/complex/object.d.ts +76 -0
- package/dist/complex/object.d.ts.map +1 -0
- package/dist/complex/object.js +104 -0
- package/dist/complex/object.js.map +1 -0
- package/dist/complex/record.d.ts +53 -0
- package/dist/complex/record.d.ts.map +1 -0
- package/dist/complex/record.js +109 -0
- package/dist/complex/record.js.map +1 -0
- package/dist/index.d.ts +151 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +128 -0
- package/dist/index.js.map +1 -0
- package/dist/json-schema.d.ts +60 -0
- package/dist/json-schema.d.ts.map +1 -0
- package/dist/json-schema.js +280 -0
- package/dist/json-schema.js.map +1 -0
- package/dist/primitives/any.d.ts +44 -0
- package/dist/primitives/any.d.ts.map +1 -0
- package/dist/primitives/any.js +57 -0
- package/dist/primitives/any.js.map +1 -0
- package/dist/primitives/boolean.d.ts +39 -0
- package/dist/primitives/boolean.d.ts.map +1 -0
- package/dist/primitives/boolean.js +53 -0
- package/dist/primitives/boolean.js.map +1 -0
- package/dist/primitives/null.d.ts +26 -0
- package/dist/primitives/null.d.ts.map +1 -0
- package/dist/primitives/null.js +40 -0
- package/dist/primitives/null.js.map +1 -0
- package/dist/primitives/number.d.ts +87 -0
- package/dist/primitives/number.d.ts.map +1 -0
- package/dist/primitives/number.js +129 -0
- package/dist/primitives/number.js.map +1 -0
- package/dist/primitives/string.d.ts +64 -0
- package/dist/primitives/string.d.ts.map +1 -0
- package/dist/primitives/string.js +102 -0
- package/dist/primitives/string.js.map +1 -0
- package/dist/primitives/undefined.d.ts +26 -0
- package/dist/primitives/undefined.d.ts.map +1 -0
- package/dist/primitives/undefined.js +40 -0
- package/dist/primitives/undefined.js.map +1 -0
- package/dist/primitives/unknown.d.ts +47 -0
- package/dist/primitives/unknown.d.ts.map +1 -0
- package/dist/primitives/unknown.js +56 -0
- package/dist/primitives/unknown.js.map +1 -0
- package/dist/utils/literal.d.ts +47 -0
- package/dist/utils/literal.d.ts.map +1 -0
- package/dist/utils/literal.js +64 -0
- package/dist/utils/literal.js.map +1 -0
- package/dist/utils/nullable.d.ts +50 -0
- package/dist/utils/nullable.d.ts.map +1 -0
- package/dist/utils/nullable.js +69 -0
- package/dist/utils/nullable.js.map +1 -0
- package/dist/utils/optional.d.ts +50 -0
- package/dist/utils/optional.d.ts.map +1 -0
- package/dist/utils/optional.js +69 -0
- package/dist/utils/optional.js.map +1 -0
- package/dist/utils/union.d.ts +60 -0
- package/dist/utils/union.d.ts.map +1 -0
- package/dist/utils/union.js +87 -0
- package/dist/utils/union.js.map +1 -0
- package/package.json +39 -0
- package/src/__tests__/coerce.test.ts +88 -0
- package/src/__tests__/complex.test.ts +124 -0
- package/src/__tests__/errors.test.ts +129 -0
- package/src/__tests__/json-schema.test.ts +138 -0
- package/src/__tests__/primitives.test.ts +184 -0
- package/src/__tests__/type-inference.test.ts +68 -0
- package/src/__tests__/utils.test.ts +100 -0
- package/src/base.ts +185 -0
- package/src/coerce/boolean.ts +56 -0
- package/src/coerce/date.ts +68 -0
- package/src/coerce/number.ts +67 -0
- package/src/coerce/string.ts +54 -0
- package/src/complex/array.ts +108 -0
- package/src/complex/object.ts +141 -0
- package/src/complex/record.ts +129 -0
- package/src/index.ts +177 -0
- package/src/json-schema.ts +331 -0
- package/src/primitives/any.ts +64 -0
- package/src/primitives/boolean.ts +60 -0
- package/src/primitives/null.ts +47 -0
- package/src/primitives/number.ts +141 -0
- package/src/primitives/string.ts +113 -0
- package/src/primitives/undefined.ts +47 -0
- package/src/primitives/unknown.ts +63 -0
- package/src/utils/literal.ts +71 -0
- package/src/utils/nullable.ts +80 -0
- package/src/utils/optional.ts +80 -0
- package/src/utils/union.ts +103 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { StringSchema, string } from './primitives/string';
|
|
2
|
+
import { NumberSchema, number } from './primitives/number';
|
|
3
|
+
import { BooleanSchema, boolean } from './primitives/boolean';
|
|
4
|
+
import { NullSchema, null_ } from './primitives/null';
|
|
5
|
+
import { UndefinedSchema } from './primitives/undefined';
|
|
6
|
+
import { ObjectSchema, object } from './complex/object';
|
|
7
|
+
import { ArraySchema, array } from './complex/array';
|
|
8
|
+
import { LiteralSchema, literal } from './utils/literal';
|
|
9
|
+
import { OptionalSchema, optional } from './utils/optional';
|
|
10
|
+
import { NullableSchema, nullable } from './utils/nullable';
|
|
11
|
+
import { UnionSchema, union } from './utils/union';
|
|
12
|
+
/**
|
|
13
|
+
* Convert a schema to JSON Schema format.
|
|
14
|
+
* Supports primitives, objects, arrays, unions, literals, optional, and nullable types.
|
|
15
|
+
*
|
|
16
|
+
* @param schema - The schema to convert
|
|
17
|
+
* @returns JSON Schema object
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const userSchema = s.object({
|
|
22
|
+
* name: s.string().describe('User name'),
|
|
23
|
+
* age: s.number().describe('User age')
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* const jsonSchema = s.toJSONSchema(userSchema);
|
|
27
|
+
* // { type: 'object', properties: {...}, required: [...] }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function toJSONSchema(schema) {
|
|
31
|
+
const result = {};
|
|
32
|
+
// Add description if available
|
|
33
|
+
if (schema.description) {
|
|
34
|
+
result.description = schema.description;
|
|
35
|
+
}
|
|
36
|
+
// Primitive types
|
|
37
|
+
if (schema instanceof StringSchema) {
|
|
38
|
+
result.type = 'string';
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
if (schema instanceof NumberSchema) {
|
|
42
|
+
result.type = 'number';
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
if (schema instanceof BooleanSchema) {
|
|
46
|
+
result.type = 'boolean';
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
if (schema instanceof NullSchema) {
|
|
50
|
+
result.type = 'null';
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
if (schema instanceof UndefinedSchema) {
|
|
54
|
+
// JSON Schema doesn't have a direct "undefined" type
|
|
55
|
+
// We can represent it as an empty schema or omit the field
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
// Literal types
|
|
59
|
+
if (schema instanceof LiteralSchema) {
|
|
60
|
+
const value = schema.value;
|
|
61
|
+
result.const = value;
|
|
62
|
+
if (typeof value === 'string') {
|
|
63
|
+
result.type = 'string';
|
|
64
|
+
}
|
|
65
|
+
else if (typeof value === 'number') {
|
|
66
|
+
result.type = 'number';
|
|
67
|
+
}
|
|
68
|
+
else if (typeof value === 'boolean') {
|
|
69
|
+
result.type = 'boolean';
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
// Object types
|
|
74
|
+
if (schema instanceof ObjectSchema) {
|
|
75
|
+
result.type = 'object';
|
|
76
|
+
const shape = schema.shape;
|
|
77
|
+
result.properties = {};
|
|
78
|
+
result.required = [];
|
|
79
|
+
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
80
|
+
result.properties[key] = toJSONSchema(fieldSchema);
|
|
81
|
+
// If the field is not optional, add it to required
|
|
82
|
+
if (!(fieldSchema instanceof OptionalSchema)) {
|
|
83
|
+
result.required.push(key);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Remove required if empty
|
|
87
|
+
if (result.required.length === 0) {
|
|
88
|
+
delete result.required;
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
// Array types
|
|
93
|
+
if (schema instanceof ArraySchema) {
|
|
94
|
+
result.type = 'array';
|
|
95
|
+
const itemSchema = schema.itemSchema;
|
|
96
|
+
result.items = toJSONSchema(itemSchema);
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
// Optional types
|
|
100
|
+
if (schema instanceof OptionalSchema) {
|
|
101
|
+
const innerSchema = schema.schema;
|
|
102
|
+
const innerJSON = toJSONSchema(innerSchema);
|
|
103
|
+
// Optional is typically handled at the object level via required array
|
|
104
|
+
return innerJSON;
|
|
105
|
+
}
|
|
106
|
+
// Nullable types
|
|
107
|
+
if (schema instanceof NullableSchema) {
|
|
108
|
+
const innerSchema = schema.schema;
|
|
109
|
+
const innerJSON = toJSONSchema(innerSchema);
|
|
110
|
+
// Nullable can be represented as anyOf with null
|
|
111
|
+
return {
|
|
112
|
+
anyOf: [innerJSON, { type: 'null' }],
|
|
113
|
+
...(schema.description && { description: schema.description }),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
// Union types
|
|
117
|
+
if (schema instanceof UnionSchema) {
|
|
118
|
+
const schemas = schema.schemas;
|
|
119
|
+
result.anyOf = schemas.map((schema) => toJSONSchema(schema));
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
// Fallback for unknown schema types
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Convert a JSON Schema object to a schema.
|
|
127
|
+
* Supports round-trip conversion with toJSONSchema.
|
|
128
|
+
*
|
|
129
|
+
* @param jsonSchema - The JSON Schema object to convert
|
|
130
|
+
* @returns Schema instance
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const jsonSchema = {
|
|
135
|
+
* type: 'object',
|
|
136
|
+
* properties: {
|
|
137
|
+
* name: { type: 'string' },
|
|
138
|
+
* age: { type: 'number' }
|
|
139
|
+
* },
|
|
140
|
+
* required: ['name', 'age']
|
|
141
|
+
* };
|
|
142
|
+
*
|
|
143
|
+
* const schema = s.fromJSONSchema(jsonSchema);
|
|
144
|
+
* const user = schema.parse({ name: 'John', age: 30 });
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
export function fromJSONSchema(jsonSchema) {
|
|
148
|
+
// Handle const (literal values)
|
|
149
|
+
if (jsonSchema.const !== undefined) {
|
|
150
|
+
const schema = literal(jsonSchema.const);
|
|
151
|
+
if (jsonSchema.description) {
|
|
152
|
+
schema.describe(jsonSchema.description);
|
|
153
|
+
}
|
|
154
|
+
return schema;
|
|
155
|
+
}
|
|
156
|
+
// Handle anyOf (union or nullable)
|
|
157
|
+
if (jsonSchema.anyOf && Array.isArray(jsonSchema.anyOf)) {
|
|
158
|
+
// Check if it's a nullable pattern (anyOf with one schema and one null)
|
|
159
|
+
if (jsonSchema.anyOf.length === 2) {
|
|
160
|
+
const nullIndex = jsonSchema.anyOf.findIndex((s) => s.type === 'null');
|
|
161
|
+
if (nullIndex !== -1) {
|
|
162
|
+
const otherIndex = nullIndex === 0 ? 1 : 0;
|
|
163
|
+
const innerSchema = fromJSONSchema(jsonSchema.anyOf[otherIndex]);
|
|
164
|
+
const schema = nullable(innerSchema);
|
|
165
|
+
if (jsonSchema.description) {
|
|
166
|
+
schema.describe(jsonSchema.description);
|
|
167
|
+
}
|
|
168
|
+
return schema;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// Otherwise treat as union
|
|
172
|
+
const schemas = jsonSchema.anyOf.map((s) => fromJSONSchema(s));
|
|
173
|
+
const schema = union(...schemas);
|
|
174
|
+
if (jsonSchema.description) {
|
|
175
|
+
schema.describe(jsonSchema.description);
|
|
176
|
+
}
|
|
177
|
+
return schema;
|
|
178
|
+
}
|
|
179
|
+
// Handle oneOf (union)
|
|
180
|
+
if (jsonSchema.oneOf && Array.isArray(jsonSchema.oneOf)) {
|
|
181
|
+
const schemas = jsonSchema.oneOf.map((s) => fromJSONSchema(s));
|
|
182
|
+
const schema = union(...schemas);
|
|
183
|
+
if (jsonSchema.description) {
|
|
184
|
+
schema.describe(jsonSchema.description);
|
|
185
|
+
}
|
|
186
|
+
return schema;
|
|
187
|
+
}
|
|
188
|
+
// Handle enum (union of literals)
|
|
189
|
+
if (jsonSchema.enum && Array.isArray(jsonSchema.enum)) {
|
|
190
|
+
const schemas = jsonSchema.enum.map((value) => literal(value));
|
|
191
|
+
const schema = union(...schemas);
|
|
192
|
+
if (jsonSchema.description) {
|
|
193
|
+
schema.describe(jsonSchema.description);
|
|
194
|
+
}
|
|
195
|
+
return schema;
|
|
196
|
+
}
|
|
197
|
+
// Handle primitive types
|
|
198
|
+
switch (jsonSchema.type) {
|
|
199
|
+
case 'string': {
|
|
200
|
+
const schema = string();
|
|
201
|
+
if (jsonSchema.description) {
|
|
202
|
+
schema.describe(jsonSchema.description);
|
|
203
|
+
}
|
|
204
|
+
return schema;
|
|
205
|
+
}
|
|
206
|
+
case 'number':
|
|
207
|
+
case 'integer': {
|
|
208
|
+
const schema = number();
|
|
209
|
+
if (jsonSchema.description) {
|
|
210
|
+
schema.describe(jsonSchema.description);
|
|
211
|
+
}
|
|
212
|
+
return schema;
|
|
213
|
+
}
|
|
214
|
+
case 'boolean': {
|
|
215
|
+
const schema = boolean();
|
|
216
|
+
if (jsonSchema.description) {
|
|
217
|
+
schema.describe(jsonSchema.description);
|
|
218
|
+
}
|
|
219
|
+
return schema;
|
|
220
|
+
}
|
|
221
|
+
case 'null': {
|
|
222
|
+
const schema = null_();
|
|
223
|
+
if (jsonSchema.description) {
|
|
224
|
+
schema.describe(jsonSchema.description);
|
|
225
|
+
}
|
|
226
|
+
return schema;
|
|
227
|
+
}
|
|
228
|
+
case 'array': {
|
|
229
|
+
if (!jsonSchema.items) {
|
|
230
|
+
throw new Error('Array type must have items property');
|
|
231
|
+
}
|
|
232
|
+
const itemSchema = fromJSONSchema(jsonSchema.items);
|
|
233
|
+
const schema = array(itemSchema);
|
|
234
|
+
if (jsonSchema.description) {
|
|
235
|
+
schema.describe(jsonSchema.description);
|
|
236
|
+
}
|
|
237
|
+
return schema;
|
|
238
|
+
}
|
|
239
|
+
case 'object': {
|
|
240
|
+
if (!jsonSchema.properties) {
|
|
241
|
+
// Empty object schema
|
|
242
|
+
const schema = object({});
|
|
243
|
+
if (jsonSchema.description) {
|
|
244
|
+
schema.describe(jsonSchema.description);
|
|
245
|
+
}
|
|
246
|
+
return schema;
|
|
247
|
+
}
|
|
248
|
+
const shape = {};
|
|
249
|
+
const requiredFields = new Set(jsonSchema.required || []);
|
|
250
|
+
for (const [key, propSchema] of Object.entries(jsonSchema.properties)) {
|
|
251
|
+
let fieldSchema = fromJSONSchema(propSchema);
|
|
252
|
+
// If field is not in required array, make it optional
|
|
253
|
+
if (!requiredFields.has(key)) {
|
|
254
|
+
fieldSchema = optional(fieldSchema);
|
|
255
|
+
}
|
|
256
|
+
shape[key] = fieldSchema;
|
|
257
|
+
}
|
|
258
|
+
const schema = object(shape);
|
|
259
|
+
if (jsonSchema.description) {
|
|
260
|
+
schema.describe(jsonSchema.description);
|
|
261
|
+
}
|
|
262
|
+
return schema;
|
|
263
|
+
}
|
|
264
|
+
default: {
|
|
265
|
+
// If no type is specified, try to infer from other properties
|
|
266
|
+
if (jsonSchema.properties) {
|
|
267
|
+
// Treat as object
|
|
268
|
+
return fromJSONSchema({ ...jsonSchema, type: 'object' });
|
|
269
|
+
}
|
|
270
|
+
if (jsonSchema.items) {
|
|
271
|
+
// Treat as array
|
|
272
|
+
return fromJSONSchema({ ...jsonSchema, type: 'array' });
|
|
273
|
+
}
|
|
274
|
+
// Fallback to string schema for unrecognized/untyped JSON Schema
|
|
275
|
+
// This provides a permissive default but may mask schema issues
|
|
276
|
+
return string();
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
//# sourceMappingURL=json-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.js","sourceRoot":"","sources":["../src/json-schema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAmBnD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,YAAY,CAAC,MAAwB;IACpD,MAAM,MAAM,GAAe,EAAE,CAAC;IAE9B,+BAA+B;IAC/B,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACxB,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C,UAAU,CAAC,CAAC;gBAE7C,sDAAsD;gBACtD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;oBAC9B,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC;gBACrC,CAAC;gBAED,KAAK,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC;YAC1B,CAAC;YAED,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YAC7B,IAAI,UAAU,CAAC,WAAW,EAAE,CAAC;gBAC5B,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;YACzC,CAAC;YACD,OAAO,MAAM,CAAC;QACf,CAAC;QAED,OAAO,CAAC,CAAC,CAAC;YACT,8DAA8D;YAC9D,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;gBAC3B,kBAAkB;gBAClB,OAAO,cAAc,CAAC,EAAE,GAAG,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;YAC1D,CAAC;YACD,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC;gBACtB,iBAAiB;gBACjB,OAAO,cAAc,CAAC,EAAE,GAAG,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;YACzD,CAAC;YACD,iEAAiE;YACjE,gEAAgE;YAChE,OAAO,MAAM,EAAE,CAAC;QACjB,CAAC;IACF,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Schema } from '../base';
|
|
2
|
+
/**
|
|
3
|
+
* Schema that accepts any value with 'any' type.
|
|
4
|
+
* Returns the value as-is without validation or type safety.
|
|
5
|
+
* Use this sparingly - prefer unknown() for better type safety.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const schema = s.any();
|
|
10
|
+
* const value = schema.parse(123); // any
|
|
11
|
+
* const value2 = schema.parse('hello'); // any
|
|
12
|
+
*
|
|
13
|
+
* // No type checking required
|
|
14
|
+
* value.toUpperCase(); // No error, but may fail at runtime
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class AnySchema implements Schema<any, any> {
|
|
18
|
+
description?: string;
|
|
19
|
+
readonly '~standard': {
|
|
20
|
+
version: 1;
|
|
21
|
+
vendor: string;
|
|
22
|
+
validate: (value: unknown) => import("@agentuity/core").StandardSchemaV1.SuccessResult<any>;
|
|
23
|
+
types: {
|
|
24
|
+
input: any;
|
|
25
|
+
output: any;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
describe(description: string): this;
|
|
29
|
+
optional(): import("..").OptionalSchema<this>;
|
|
30
|
+
nullable(): import("..").NullableSchema<this>;
|
|
31
|
+
parse: (this: Schema<any, any>, value: unknown) => any;
|
|
32
|
+
safeParse: (this: Schema<any, any>, value: unknown) => import("..").SafeParseResult<any>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create an any schema that accepts any value.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const schema = s.any();
|
|
40
|
+
* const value = schema.parse(anything); // Type is any
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function any(): AnySchema;
|
|
44
|
+
//# sourceMappingURL=any.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"any.d.ts","sourceRoot":"","sources":["../../src/primitives/any.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAQtC;;;;;;;;;;;;;;GAcG;AAEH,qBAAa,SAAU,YAAW,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,QAAQ,CAAC,WAAW;;;0BAID,OAAO;eAEM;YAAE,KAAK,EAAE,GAAG,CAAC;YAAC,MAAM,EAAE,GAAG,CAAA;SAAE;MACzD;IAEF,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAKnC,QAAQ;IAIR,QAAQ;IAGR,KAAK,kDAAsB;IAC3B,SAAS,gFAA0B;CACnC;AAED;;;;;;;;GAQG;AACH,wBAAgB,GAAG,IAAI,SAAS,CAE/B"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { success, createParseMethods } from '../base';
|
|
2
|
+
import { optional } from '../utils/optional';
|
|
3
|
+
import { nullable } from '../utils/nullable';
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
+
const parseMethods = createParseMethods();
|
|
6
|
+
/**
|
|
7
|
+
* Schema that accepts any value with 'any' type.
|
|
8
|
+
* Returns the value as-is without validation or type safety.
|
|
9
|
+
* Use this sparingly - prefer unknown() for better type safety.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const schema = s.any();
|
|
14
|
+
* const value = schema.parse(123); // any
|
|
15
|
+
* const value2 = schema.parse('hello'); // any
|
|
16
|
+
*
|
|
17
|
+
* // No type checking required
|
|
18
|
+
* value.toUpperCase(); // No error, but may fail at runtime
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
export class AnySchema {
|
|
23
|
+
description;
|
|
24
|
+
'~standard' = {
|
|
25
|
+
version: 1,
|
|
26
|
+
vendor: 'agentuity',
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
validate: (value) => success(value),
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
types: undefined,
|
|
31
|
+
};
|
|
32
|
+
describe(description) {
|
|
33
|
+
this.description = description;
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
optional() {
|
|
37
|
+
return optional(this);
|
|
38
|
+
}
|
|
39
|
+
nullable() {
|
|
40
|
+
return nullable(this);
|
|
41
|
+
}
|
|
42
|
+
parse = parseMethods.parse;
|
|
43
|
+
safeParse = parseMethods.safeParse;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create an any schema that accepts any value.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const schema = s.any();
|
|
51
|
+
* const value = schema.parse(anything); // Type is any
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export function any() {
|
|
55
|
+
return new AnySchema();
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=any.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"any.js","sourceRoot":"","sources":["../../src/primitives/any.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,8DAA8D;AAC9D,MAAM,YAAY,GAAG,kBAAkB,EAAO,CAAC;AAE/C;;;;;;;;;;;;;;GAcG;AACH,8DAA8D;AAC9D,MAAM,OAAO,SAAS;IACrB,WAAW,CAAU;IAEZ,WAAW,GAAG;QACtB,OAAO,EAAE,CAAU;QACnB,MAAM,EAAE,WAAW;QACnB,8DAA8D;QAC9D,QAAQ,EAAE,CAAC,KAAc,EAAE,EAAE,CAAC,OAAO,CAAC,KAAY,CAAC;QACnD,8DAA8D;QAC9D,KAAK,EAAE,SAAmD;KAC1D,CAAC;IAEF,QAAQ,CAAC,WAAmB;QAC3B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,OAAO,IAAI,CAAC;IACb,CAAC;IAED,QAAQ;QACP,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,QAAQ;QACP,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IACD,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC;IAC3B,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC;CACnC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,GAAG;IAClB,OAAO,IAAI,SAAS,EAAE,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Schema } from '../base';
|
|
2
|
+
/**
|
|
3
|
+
* Schema for validating boolean values.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* const schema = s.boolean();
|
|
8
|
+
* const active = schema.parse(true); // true
|
|
9
|
+
* schema.parse('true'); // throws ValidationError
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare class BooleanSchema implements Schema<boolean, boolean> {
|
|
13
|
+
description?: string;
|
|
14
|
+
readonly '~standard': {
|
|
15
|
+
version: 1;
|
|
16
|
+
vendor: string;
|
|
17
|
+
validate: (value: unknown) => import("@agentuity/core").StandardSchemaV1.FailureResult | import("@agentuity/core").StandardSchemaV1.SuccessResult<boolean>;
|
|
18
|
+
types: {
|
|
19
|
+
input: boolean;
|
|
20
|
+
output: boolean;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
describe(description: string): this;
|
|
24
|
+
optional(): import("..").OptionalSchema<this>;
|
|
25
|
+
nullable(): import("..").NullableSchema<this>;
|
|
26
|
+
parse: (this: Schema<any, boolean>, value: unknown) => boolean;
|
|
27
|
+
safeParse: (this: Schema<any, boolean>, value: unknown) => import("..").SafeParseResult<boolean>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Create a boolean schema.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const activeSchema = s.boolean().describe('Account status');
|
|
35
|
+
* const active = activeSchema.parse(true);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function boolean(): BooleanSchema;
|
|
39
|
+
//# sourceMappingURL=boolean.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean.d.ts","sourceRoot":"","sources":["../../src/primitives/boolean.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAOtC;;;;;;;;;GASG;AACH,qBAAa,aAAc,YAAW,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IAC7D,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,QAAQ,CAAC,WAAW;;;0BAGD,OAAO;eAMM;YAAE,KAAK,EAAE,OAAO,CAAC;YAAC,MAAM,EAAE,OAAO,CAAA;SAAE;MACjE;IAEF,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAKnC,QAAQ;IAIR,QAAQ;IAGR,KAAK,0DAAsB;IAC3B,SAAS,wFAA0B;CACnC;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,IAAI,aAAa,CAEvC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createIssue, failure, success, createParseMethods } from '../base';
|
|
2
|
+
import { optional } from '../utils/optional';
|
|
3
|
+
import { nullable } from '../utils/nullable';
|
|
4
|
+
const parseMethods = createParseMethods();
|
|
5
|
+
/**
|
|
6
|
+
* Schema for validating boolean values.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const schema = s.boolean();
|
|
11
|
+
* const active = schema.parse(true); // true
|
|
12
|
+
* schema.parse('true'); // throws ValidationError
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export class BooleanSchema {
|
|
16
|
+
description;
|
|
17
|
+
'~standard' = {
|
|
18
|
+
version: 1,
|
|
19
|
+
vendor: 'agentuity',
|
|
20
|
+
validate: (value) => {
|
|
21
|
+
if (typeof value !== 'boolean') {
|
|
22
|
+
return failure([createIssue(`Expected boolean, got ${typeof value}`)]);
|
|
23
|
+
}
|
|
24
|
+
return success(value);
|
|
25
|
+
},
|
|
26
|
+
types: undefined,
|
|
27
|
+
};
|
|
28
|
+
describe(description) {
|
|
29
|
+
this.description = description;
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
optional() {
|
|
33
|
+
return optional(this);
|
|
34
|
+
}
|
|
35
|
+
nullable() {
|
|
36
|
+
return nullable(this);
|
|
37
|
+
}
|
|
38
|
+
parse = parseMethods.parse;
|
|
39
|
+
safeParse = parseMethods.safeParse;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a boolean schema.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const activeSchema = s.boolean().describe('Account status');
|
|
47
|
+
* const active = activeSchema.parse(true);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export function boolean() {
|
|
51
|
+
return new BooleanSchema();
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=boolean.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../src/primitives/boolean.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,MAAM,YAAY,GAAG,kBAAkB,EAAW,CAAC;AAEnD;;;;;;;;;GASG;AACH,MAAM,OAAO,aAAa;IACzB,WAAW,CAAU;IAEZ,WAAW,GAAG;QACtB,OAAO,EAAE,CAAU;QACnB,MAAM,EAAE,WAAW;QACnB,QAAQ,EAAE,CAAC,KAAc,EAAE,EAAE;YAC5B,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;gBAChC,OAAO,OAAO,CAAC,CAAC,WAAW,CAAC,yBAAyB,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;YACxE,CAAC;YACD,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;QACD,KAAK,EAAE,SAA2D;KAClE,CAAC;IAEF,QAAQ,CAAC,WAAmB;QAC3B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,OAAO,IAAI,CAAC;IACb,CAAC;IAED,QAAQ;QACP,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,QAAQ;QACP,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IACD,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC;IAC3B,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC;CACnC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,OAAO;IACtB,OAAO,IAAI,aAAa,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Schema } from '../base';
|
|
2
|
+
/**
|
|
3
|
+
* Schema for validating null values.
|
|
4
|
+
*/
|
|
5
|
+
export declare class NullSchema implements Schema<null, null> {
|
|
6
|
+
description?: string;
|
|
7
|
+
readonly '~standard': {
|
|
8
|
+
version: 1;
|
|
9
|
+
vendor: string;
|
|
10
|
+
validate: (value: unknown) => import("@agentuity/core").StandardSchemaV1.FailureResult | import("@agentuity/core").StandardSchemaV1.SuccessResult<null>;
|
|
11
|
+
types: {
|
|
12
|
+
input: null;
|
|
13
|
+
output: null;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
describe(description: string): this;
|
|
17
|
+
optional(): import("..").OptionalSchema<this>;
|
|
18
|
+
nullable(): import("..").NullableSchema<this>;
|
|
19
|
+
parse: (this: Schema<any, null>, value: unknown) => null;
|
|
20
|
+
safeParse: (this: Schema<any, null>, value: unknown) => import("..").SafeParseResult<null>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a null schema.
|
|
24
|
+
*/
|
|
25
|
+
export declare function null_(): NullSchema;
|
|
26
|
+
//# sourceMappingURL=null.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"null.d.ts","sourceRoot":"","sources":["../../src/primitives/null.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAOtC;;GAEG;AACH,qBAAa,UAAW,YAAW,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC;IACpD,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,QAAQ,CAAC,WAAW;;;0BAGD,OAAO;eAMM;YAAE,KAAK,EAAE,IAAI,CAAC;YAAC,MAAM,EAAE,IAAI,CAAA;SAAE;MAC3D;IAEF,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAKnC,QAAQ;IAIR,QAAQ;IAGR,KAAK,oDAAsB;IAC3B,SAAS,kFAA0B;CACnC;AAED;;GAEG;AACH,wBAAgB,KAAK,IAAI,UAAU,CAElC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createIssue, failure, success, createParseMethods } from '../base';
|
|
2
|
+
import { optional } from '../utils/optional';
|
|
3
|
+
import { nullable } from '../utils/nullable';
|
|
4
|
+
const parseMethods = createParseMethods();
|
|
5
|
+
/**
|
|
6
|
+
* Schema for validating null values.
|
|
7
|
+
*/
|
|
8
|
+
export class NullSchema {
|
|
9
|
+
description;
|
|
10
|
+
'~standard' = {
|
|
11
|
+
version: 1,
|
|
12
|
+
vendor: 'agentuity',
|
|
13
|
+
validate: (value) => {
|
|
14
|
+
if (value !== null) {
|
|
15
|
+
return failure([createIssue(`Expected null, got ${typeof value}`)]);
|
|
16
|
+
}
|
|
17
|
+
return success(value);
|
|
18
|
+
},
|
|
19
|
+
types: undefined,
|
|
20
|
+
};
|
|
21
|
+
describe(description) {
|
|
22
|
+
this.description = description;
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
optional() {
|
|
26
|
+
return optional(this);
|
|
27
|
+
}
|
|
28
|
+
nullable() {
|
|
29
|
+
return nullable(this);
|
|
30
|
+
}
|
|
31
|
+
parse = parseMethods.parse;
|
|
32
|
+
safeParse = parseMethods.safeParse;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create a null schema.
|
|
36
|
+
*/
|
|
37
|
+
export function null_() {
|
|
38
|
+
return new NullSchema();
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=null.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"null.js","sourceRoot":"","sources":["../../src/primitives/null.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,MAAM,YAAY,GAAG,kBAAkB,EAAQ,CAAC;AAEhD;;GAEG;AACH,MAAM,OAAO,UAAU;IACtB,WAAW,CAAU;IAEZ,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,sBAAsB,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;YACrE,CAAC;YACD,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;QACD,KAAK,EAAE,SAAqD;KAC5D,CAAC;IAEF,QAAQ,CAAC,WAAmB;QAC3B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,OAAO,IAAI,CAAC;IACb,CAAC;IAED,QAAQ;QACP,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,QAAQ;QACP,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IACD,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC;IAC3B,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,UAAU,KAAK;IACpB,OAAO,IAAI,UAAU,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { Schema } from '../base';
|
|
2
|
+
/**
|
|
3
|
+
* Schema for validating number values.
|
|
4
|
+
* Rejects NaN values.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const schema = s.number();
|
|
9
|
+
* const age = schema.parse(30); // 30
|
|
10
|
+
* schema.parse('30'); // throws ValidationError
|
|
11
|
+
* schema.parse(NaN); // throws ValidationError
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare class NumberSchema implements Schema<number, number> {
|
|
15
|
+
description?: string;
|
|
16
|
+
private _finite;
|
|
17
|
+
private _min?;
|
|
18
|
+
private _max?;
|
|
19
|
+
readonly '~standard': {
|
|
20
|
+
version: 1;
|
|
21
|
+
vendor: string;
|
|
22
|
+
validate: (value: unknown) => import("@agentuity/core").StandardSchemaV1.FailureResult | import("@agentuity/core").StandardSchemaV1.SuccessResult<number>;
|
|
23
|
+
types: {
|
|
24
|
+
input: number;
|
|
25
|
+
output: number;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
describe(description: string): this;
|
|
29
|
+
/**
|
|
30
|
+
* Require the number to be finite (not Infinity, -Infinity, or NaN).
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const schema = s.number().finite();
|
|
35
|
+
* schema.parse(123); // 123
|
|
36
|
+
* schema.parse(Infinity); // throws ValidationError
|
|
37
|
+
* schema.parse(-Infinity); // throws ValidationError
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
finite(): NumberSchema;
|
|
41
|
+
/**
|
|
42
|
+
* Set minimum value (inclusive).
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const schema = s.number().min(0);
|
|
47
|
+
* schema.parse(5); // 5
|
|
48
|
+
* schema.parse(-1); // throws ValidationError
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
min(value: number): NumberSchema;
|
|
52
|
+
/**
|
|
53
|
+
* Set maximum value (inclusive).
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const schema = s.number().max(100);
|
|
58
|
+
* schema.parse(50); // 50
|
|
59
|
+
* schema.parse(101); // throws ValidationError
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
max(value: number): NumberSchema;
|
|
63
|
+
optional(): import("..").OptionalSchema<this>;
|
|
64
|
+
nullable(): import("..").NullableSchema<this>;
|
|
65
|
+
private _clone;
|
|
66
|
+
parse: (this: Schema<any, number>, value: unknown) => number;
|
|
67
|
+
safeParse: (this: Schema<any, number>, value: unknown) => import("..").SafeParseResult<number>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Create a number schema.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const ageSchema = s.number().describe('User age');
|
|
75
|
+
* const age = ageSchema.parse(30);
|
|
76
|
+
*
|
|
77
|
+
* const finiteSchema = s.number().finite();
|
|
78
|
+
* finiteSchema.parse(123); // OK
|
|
79
|
+
* finiteSchema.parse(Infinity); // throws
|
|
80
|
+
*
|
|
81
|
+
* const rangeSchema = s.number().min(0).max(100);
|
|
82
|
+
* rangeSchema.parse(50); // OK
|
|
83
|
+
* rangeSchema.parse(101); // throws
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare function number(): NumberSchema;
|
|
87
|
+
//# sourceMappingURL=number.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../src/primitives/number.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAOtC;;;;;;;;;;;GAWG;AACH,qBAAa,YAAa,YAAW,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAC1D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,IAAI,CAAC,CAAS;IACtB,OAAO,CAAC,IAAI,CAAC,CAAS;IAEtB,QAAQ,CAAC,WAAW;;;0BAGD,OAAO;eAeM;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE;MAC/D;IAEF,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAKnC;;;;;;;;;;OAUG;IACH,MAAM,IAAI,YAAY;IAMtB;;;;;;;;;OASG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY;IAMhC;;;;;;;;;OASG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY;IAMhC,QAAQ;IAIR,QAAQ;IAIR,OAAO,CAAC,MAAM;IASd,KAAK,wDAAsB;IAC3B,SAAS,sFAA0B;CACnC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,IAAI,YAAY,CAErC"}
|