@amazon/vinyl-validation 1.2.0 → 2.0.4
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/README.md +42 -0
- package/dist/index.cjs +334 -171
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +322 -159
- package/dist/index.js.map +4 -4
- package/dist/types/current/index.d.ts +15 -14
- package/dist/types/current/index.d.ts.map +1 -1
- package/dist/types/current/index.js +15 -14
- package/dist/types/current/tsconfig.tsbuildinfo +1 -1
- package/dist/types/current/validation/ArraySchema.d.ts.map +1 -1
- package/dist/types/current/validation/ArraySchema.js +11 -4
- package/dist/types/current/validation/JsonSchema.d.ts +63 -0
- package/dist/types/current/validation/JsonSchema.d.ts.map +1 -0
- package/dist/types/current/validation/JsonSchema.js +59 -0
- package/dist/types/current/validation/NumberSchema.d.ts.map +1 -1
- package/dist/types/current/validation/NumberSchema.js +6 -6
- package/dist/types/current/validation/ObjectSchema.d.ts.map +1 -1
- package/dist/types/current/validation/ObjectSchema.js +12 -1
- package/dist/types/current/validation/RecordSchema.d.ts.map +1 -1
- package/dist/types/current/validation/RecordSchema.js +4 -0
- package/dist/types/current/validation/SchemaBase.d.ts +23 -1
- package/dist/types/current/validation/SchemaBase.d.ts.map +1 -1
- package/dist/types/current/validation/SchemaBase.js +36 -0
- package/dist/types/current/validation/SetSchema.d.ts.map +1 -1
- package/dist/types/current/validation/SetSchema.js +6 -1
- package/dist/types/current/validation/StringSchema.d.ts.map +1 -1
- package/dist/types/current/validation/StringSchema.js +4 -4
- package/dist/types/current/validation/Validator.d.ts +14 -2
- package/dist/types/current/validation/Validator.d.ts.map +1 -1
- package/dist/types/current/validation/Validator.js +6 -2
- package/dist/types/current/validation/ValueSchema.d.ts +1 -0
- package/dist/types/current/validation/ValueSchema.d.ts.map +1 -1
- package/dist/types/current/validation/ValueSchema.js +7 -2
- package/dist/types/current/validation/andValidators.d.ts.map +1 -1
- package/dist/types/current/validation/andValidators.js +2 -1
- package/dist/types/current/validation/orValidators.d.ts.map +1 -1
- package/dist/types/current/validation/orValidators.js +18 -1
- package/dist/types/current/validation/typeOfValidators.d.ts.map +1 -1
- package/dist/types/current/validation/typeOfValidators.js +13 -1
- package/dist/types/current/validation/validators.d.ts.map +1 -1
- package/dist/types/current/validation/validators.js +1 -1
- package/dist/types/ts3.7/index.d.ts +15 -14
- package/dist/types/ts3.7/validation/JsonSchema.d.ts +63 -0
- package/dist/types/ts3.7/validation/SchemaBase.d.ts +18 -1
- package/dist/types/ts3.7/validation/Validator.d.ts +14 -2
- package/dist/types/ts3.7/validation/ValueSchema.d.ts +1 -0
- package/dist/types/ts4.1/index.d.ts +15 -14
- package/dist/types/ts4.1/validation/JsonSchema.d.ts +63 -0
- package/dist/types/ts4.1/validation/SchemaBase.d.ts +18 -1
- package/dist/types/ts4.1/validation/Validator.d.ts +14 -2
- package/dist/types/ts4.1/validation/ValueSchema.d.ts +1 -0
- package/dist/types/ts4.7/index.d.ts +15 -14
- package/dist/types/ts4.7/validation/JsonSchema.d.ts +63 -0
- package/dist/types/ts4.7/validation/SchemaBase.d.ts +23 -1
- package/dist/types/ts4.7/validation/Validator.d.ts +14 -2
- package/dist/types/ts4.7/validation/ValueSchema.d.ts +1 -0
- package/dist/unit/types/current/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -12
package/README.md
CHANGED
|
@@ -298,6 +298,48 @@ function processUser(data: unknown) {
|
|
|
298
298
|
}
|
|
299
299
|
```
|
|
300
300
|
|
|
301
|
+
## Descriptions and JSON Schema Export
|
|
302
|
+
|
|
303
|
+
Any schema node can carry a human-readable description, and any schema can be
|
|
304
|
+
exported as a [JSON Schema](https://json-schema.org/) definition. This is useful
|
|
305
|
+
for describing a shape to an LLM or another consumer, and works similarly to
|
|
306
|
+
zod's `describe` and `zod-to-json-schema`.
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
import {
|
|
310
|
+
object,
|
|
311
|
+
string,
|
|
312
|
+
number,
|
|
313
|
+
isOneOf,
|
|
314
|
+
toJsonSchema,
|
|
315
|
+
} from '@amazon/vinyl-validation'
|
|
316
|
+
|
|
317
|
+
const userSchema = object({
|
|
318
|
+
name: string().notEmpty().describe('The user full name'),
|
|
319
|
+
age: number().gte(0).lte(120),
|
|
320
|
+
role: isOneOf('admin', 'user').describe('Access level'),
|
|
321
|
+
nickname: string().optional(),
|
|
322
|
+
}).describe('A user record')
|
|
323
|
+
|
|
324
|
+
toJsonSchema(userSchema)
|
|
325
|
+
// {
|
|
326
|
+
// type: 'object',
|
|
327
|
+
// properties: {
|
|
328
|
+
// name: { type: 'string', minLength: 1, description: 'The user full name' },
|
|
329
|
+
// age: { type: 'number', minimum: 0, maximum: 120 },
|
|
330
|
+
// role: { enum: ['admin', 'user'], description: 'Access level' },
|
|
331
|
+
// nickname: { type: 'string' },
|
|
332
|
+
// },
|
|
333
|
+
// required: ['name', 'age', 'role'],
|
|
334
|
+
// description: 'A user record',
|
|
335
|
+
// }
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
`describe` is metadata only; it does not affect validation. Optional properties
|
|
339
|
+
are omitted from the `required` list. Unions (`or`, `maybe`) export as `anyOf`,
|
|
340
|
+
arrays as `items`, tuples as positional `items`, sets as unique-item arrays, and
|
|
341
|
+
records as objects with typed `additionalProperties`.
|
|
342
|
+
|
|
301
343
|
## License
|
|
302
344
|
|
|
303
345
|
Apache-2.0
|