Comments (2)
@tzezar Hi,
When using Fastify, you shouldn't use Type.Date. TypeBox added this type as an extended type, but the schema it produces is unknown to Ajv (which is the validator Fastify uses internally). The issue stems from Json Schema (and Json) being unable to encode JavaScript Date objects, and that dates need to be encoded as either number
or string
(iso8601). For this reason, you should define the schema as either Type.Number (timestamp) or Type.String (iso8601)
Transforms
If you're using https://github.com/fastify/fastify-type-provider-typebox, unfortunately you won't be able to use Type.Transform as this is only applicable to TypeBox's validators (specifically the Encode / Decode functions). There are ways to integrate Encode/Decode into the Fastify validation pipeline, but as of today, the Encode/Decode hasn't been integrated into the Fastify type provider project (so if you want to use these Transform types, you will need to implement them manually).
From memory, you will need to override via the setValidationCompiler
and preValidationHook
handler. It looks like I've drafted an experimental implementation of Encode/Decode which is noted at the following issue comment.
fastify/fastify-type-provider-typebox#128 (comment)
I may take a look at providing the Type Provider project a more fleshed out implementation later in the year, but if you do try out the implementation noted on this comment thread and it works good for you, feel free to submit a PR to the provider project, ill be able to help review the PR.
Hope this helps.
S
from typebox.
@tzezar Hey, might close off this issue as it's generally related to Fastify (and Drizzle) integration.
I can only really speak for Fastify integrations (as that project I've had experience with). But as a general rule, when working with projects that are based on the Json Schema specification, only use the [Json]
types and avoid the [JavaScript]
types (as the latter will only work with TypeBox validators). The types listed for either category can be found here.
https://github.com/sinclairzx81/typebox?tab=readme-ov-file#types-json
https://github.com/sinclairzx81/typebox?tab=readme-ov-file#javascript-types
If you have any follow up questions, feel free to ping on this thread.
Cheers
S
from typebox.
Related Issues (20)
- `TypeSystem.Type` returning `any` after updating to `0.32.16` HOT 1
- Type.Schema HOT 2
- Preflight validation check failed to guard for the given schema when using `structuredClone` HOT 2
- `Value.Convert` to a `Union` no longer checks destination type validity HOT 2
- Error when trying to use TSchema as a generic HOT 2
- How to use `Value.Check` with raw json schemas? HOT 4
- Regression bug 0.32.19 HOT 2
- TypeGuard.IsEnum HOT 2
- Better pre-validation errors for invalid TypeBox schema HOT 2
- Static resolution is not working as expected when using a generic function to generate a schema HOT 3
- tsconfig "strict": true - ignore modifiers HOT 2
- `Static` types cannot be used to enforce types from a generic parameter HOT 3
- Applying refinements + general advice on my implementation HOT 11
- Unable to create value of custom class type HOT 2
- Migrate to regexp vs string type in pattern HOT 4
- feedback on Refinement API HOT 2
- Should coerce type to array HOT 2
- Interconnected interfaces, missing type annotations and maximum length exceeded. HOT 2
- Optimisations to inference in 0.32 seems to cause `ts(2589)` with composite types. HOT 16
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typebox.