Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revision 0.34.28 #1187

Merged
merged 3 commits into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog/0.34.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
---

### Revision Updates
- [Revision 0.34.28](https://github.com/sinclairzx81/typebox/pull/1187)
- Add Cast to Configurable Parse Pipeline
- [Revision 0.34.27](https://github.com/sinclairzx81/typebox/pull/1182)
- [1178](https://github.com/sinclairzx81/typebox/issues/1178) Support Deep Referential Transform Inference Inside Modules
- [Revision 0.34.26](https://github.com/sinclairzx81/typebox/pull/1181)
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sinclair/typebox",
"version": "0.34.27",
"version": "0.34.28",
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
"keywords": [
"typescript",
Expand Down
16 changes: 9 additions & 7 deletions src/value/parse/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ import { TransformDecode, TransformEncode, HasTransform } from '../transform/ind
import { TSchema } from '../../type/schema/index'
import { StaticDecode } from '../../type/static/index'
import { Assert } from '../assert/index'
import { Default } from '../default/index'
import { Convert } from '../convert/index'
import { Cast } from '../cast/index'
import { Clean } from '../clean/index'
import { Clone } from '../clone/index'
import { Convert } from '../convert/index'
import { Default } from '../default/index'

// ------------------------------------------------------------------
// Guards
Expand All @@ -53,18 +54,19 @@ export class ParseError extends TypeBoxError {
// ------------------------------------------------------------------
// ParseRegistry
// ------------------------------------------------------------------
export type TParseOperation = 'Clone' | 'Clean' | 'Default' | 'Convert' | 'Assert' | 'Decode' | 'Encode' | ({} & string)
export type TParseOperation = 'Assert' | 'Cast' | 'Clean' | 'Clone' | 'Convert' | 'Decode' | 'Default' | 'Encode' | ({} & string)
export type TParseFunction = (type: TSchema, references: TSchema[], value: unknown) => unknown

// prettier-ignore
export namespace ParseRegistry {
const registry = new Map<string, TParseFunction>([
['Clone', (_type, _references, value: unknown) => Clone(value)],
['Assert', (type, references, value: unknown) => { Assert(type, references, value); return value }],
['Cast', (type, references, value: unknown) => Cast(type, references, value)],
['Clean', (type, references, value: unknown) => Clean(type, references, value)],
['Default', (type, references, value: unknown) => Default(type, references, value)],
['Clone', (_type, _references, value: unknown) => Clone(value)],
['Convert', (type, references, value: unknown) => Convert(type, references, value)],
['Assert', (type, references, value: unknown) => { Assert(type, references, value); return value }],
['Decode', (type, references, value: unknown) => (HasTransform(type, references) ? TransformDecode(type, references, value) : value)],
['Default', (type, references, value: unknown) => Default(type, references, value)],
['Encode', (type, references, value: unknown) => (HasTransform(type, references) ? TransformEncode(type, references, value) : value)],
])
// Deletes an entry from the registry
Expand All @@ -81,7 +83,7 @@ export namespace ParseRegistry {
}
}
// ------------------------------------------------------------------
// Default Parse Sequence
// Default Parse Pipeline
// ------------------------------------------------------------------
// prettier-ignore
export const ParseDefault = [
Expand Down