Skip to content

Commit

Permalink
Update Intersect Transform Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 committed Nov 20, 2023
1 parent 6be0231 commit b96abd1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
7 changes: 2 additions & 5 deletions examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const TBItem = Type.Transform(
isHybrid: Type.Boolean(),
}),
)
.Decode((value) => ({ isHybrid: value.isHybrid ? 1 : 0 }))
.Encode((value) => ({ isHybrid: value.isHybrid === 1 ? true : false }))
.Decode((value) => ({ isHybrid: value.isHybrid ? 1 : 0 }))
.Encode((value) => ({ isHybrid: value.isHybrid === 1 ? true : false }))

let decoded = Value.Decode(TBItem, { isHybrid: true })
let encoded = Value.Encode(TBItem, { isHybrid: 1 })
Expand All @@ -25,7 +25,6 @@ const TBIntersect = Type.Intersect([
}),
])


const aencoded = Value.Encode(TBIntersect, {
model: 'Prius',
features: [
Expand All @@ -39,5 +38,3 @@ const aencoded = Value.Encode(TBIntersect, {
})

console.log(aencoded)


10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -1719,11 +1719,11 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m
┌──────────────────────┬────────────┬────────────┬─────────────┐
│ (index) │ CompiledMinifiedCompression
├──────────────────────┼────────────┼────────────┼─────────────┤
typebox/compiler'148.9 kb'' 65.8 kb''2.26 x'
typebox/errors'111.5 kb'' 49.1 kb''2.27 x'
typebox/system' 82.6 kb'' 36.8 kb''2.24 x'
typebox/value'190.5 kb'' 82.4 kb''2.31 x'
typebox' 72.4 kb'' 31.6 kb''2.29 x'
typebox/compiler'163.6 kb'' 71.6 kb''2.28 x'
typebox/errors'113.3 kb'' 50.1 kb''2.26 x'
typebox/system' 83.9 kb'' 37.5 kb''2.24 x'
typebox/value'191.1 kb'' 82.3 kb''2.32 x'
typebox' 73.8 kb'' 32.3 kb''2.29 x'
└──────────────────────┴────────────┴────────────┴─────────────┘
```
Expand Down
10 changes: 0 additions & 10 deletions src/value/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,9 @@ import { Deref } from './deref'
import { Check } from './check'
import * as Types from '../typebox'

// -------------------------------------------------------------------------
// CheckFunction
// -------------------------------------------------------------------------
export type CheckFunction = (schema: Types.TSchema, references: Types.TSchema[], value: unknown) => boolean

// -------------------------------------------------------------------------
// Errors
// -------------------------------------------------------------------------
export class TransformUnknownTypeError extends Types.TypeBoxError {
constructor(public readonly schema: Types.TRef | Types.TThis) {
super(`Unknown type`)
}
}
export class TransformDecodeCheckError extends Types.TypeBoxError {
constructor(public readonly schema: Types.TSchema, public readonly value: unknown, public readonly error: ValueError) {
super(`Unable to decode due to invalid value`)
Expand Down

0 comments on commit b96abd1

Please sign in to comment.