From b96abd137d926f8cc2fb91a9f57b4cf60572b613 Mon Sep 17 00:00:00 2001 From: sinclair Date: Mon, 20 Nov 2023 21:21:00 +0900 Subject: [PATCH] Update Intersect Transform Logic --- examples/index.ts | 7 ++----- readme.md | 10 +++++----- src/value/transform.ts | 10 ---------- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/examples/index.ts b/examples/index.ts index 244fde67c..40a1ceff2 100644 --- a/examples/index.ts +++ b/examples/index.ts @@ -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 }) @@ -25,7 +25,6 @@ const TBIntersect = Type.Intersect([ }), ]) - const aencoded = Value.Encode(TBIntersect, { model: 'Prius', features: [ @@ -39,5 +38,3 @@ const aencoded = Value.Encode(TBIntersect, { }) console.log(aencoded) - - diff --git a/readme.md b/readme.md index d4868e0d7..8ba350169 100644 --- a/readme.md +++ b/readme.md @@ -1719,11 +1719,11 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m ┌──────────────────────┬────────────┬────────────┬─────────────┐ │ (index) │ Compiled │ Minified │ Compression │ ├──────────────────────┼────────────┼────────────┼─────────────┤ -│ 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' │ └──────────────────────┴────────────┴────────────┴─────────────┘ ``` diff --git a/src/value/transform.ts b/src/value/transform.ts index 626d21986..bb377f9a1 100644 --- a/src/value/transform.ts +++ b/src/value/transform.ts @@ -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`)