This commit is contained in:
sinclair
2025-12-24 15:44:34 +09:00
commit 13d553220c
1047 changed files with 80931 additions and 0 deletions

38
changelog/0.17.4.md Normal file
View File

@@ -0,0 +1,38 @@
## [0.17.4](https://www.npmjs.com/package/@sinclair/typebox/v/0.17.4)
Changes:
- Added `Type.Box()` and `Type.Ref()` functions.
Notes:
This update provides the `Type.Box()` function to enable common related schemas to grouped under a common namespace; typically expressed as a `URI`. This functionality is primarily geared towards allowing one to define a common set of domain objects that may be shared across application domains running over a network. The `Type.Box()` is intended to be an analog to `XML` `xmlns` namespaces.
The `Type.Ref()` function is limited to referencing from boxes only. The following is an example.
```typescript
// Domain objects for the fruit service.
const Fruit = Type.Box('https://fruit.domain.com', {
Apple: Type.Object({ ... }),
Orange: Type.Object({ ... }),
})
// An order referencing types of the fruit service.
const Order = Type.Object({
id: Type.String(),
quantity: Type.Number(),
item: Type.Union([
Type.Ref(Fruit, 'Apple'),
Type.Ref(Fruit, 'Orange')
])
})
```
> Note: As of this release, the `Type.Omit()`, `Type.Pick()`, `Type.Partial()`, `Type.Readonly()` and `Type.Intersect()` functions do not work with Reference Types. This may change in later revisions.
For validation using `Ajv`, its possible to apply the `Box` directly as a schema.
```typescript
ajv.addSchema(Fruit) // makes all boxed types known to Ajv
```
This functionality is flagged as `EXPERIMENTAL` and awaits community feedback.