Comments (2)
Hey @sinclairzx81, I was able to figure it out later on. The issue was, that the UUID from Scylla was getting passed on as int array buffer, but in the error message of typebox, it was coming as a string value, which led to the confusion.
Even in the logs it was coming up at us string value since I was using Pino logger. Until I checked with console.log, I wasn't able to figure it out.
it's working as expected now.
from typebox.
@Dhruv-Garg79 Hi, That's a strange error.
I don't seem to be able to replicate the issue locally... here's the code I'm using (you can run this locally to repro)
import { TypeCompiler } from '@sinclair/typebox/compiler'
import { Type, FormatRegistry } from '@sinclair/typebox'
import { Value } from '@sinclair/typebox/value'
FormatRegistry.Set('uuid', value => IsUuid(value))
const Uuid = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i
export function IsUuid(value: string): boolean {
return Uuid.test(value)
}
// ...Test
const T = Type.Object({ id: Type.String({ format: 'uuid' }) })
const A = TypeCompiler.Compile(T).Check({ id: 'f00b12d9-b2af-48ab-8b00-25070afbe307' })
const B = Value.Check(T, { id: String('f00b12d9-b2af-48ab-8b00-25070afbe307') })
const C = [...Value.Errors(T, { id: String('f00b12d9-b2af-48ab-8b00-25070afbe307') })]
console.log(A, B, C) // true, true, [] - ok
So the above is fine, however the error you've posted is somewhat puzzling as the /id
value passed on the error certainly appears to be a string. I'm not sure how this could happen...breakdown of the error below...
[{
"type":54, // ok: error type string
"schema": { "format":"uuid", "type":"string" }, // ok: a string with format
"path": "/id", // ok: path looks correct
"value": "f00b12d9-b2af-48ab-8b00-25070afbe307", // puzzle: but the value is string?
"message": "Expected string" // ok:
}]
Could you run a quick test on the id
value to see what type it is....
console.log(typeof value.id === 'string') // should print true
... the only thing I can think of is that id
somehow isn't a string....
const A = String('hello world')
const B = Object.assign(A, {}) // is it possible the id might be assigned things?
console.log(typeof A) // string - ok
console.log(typeof B) // object - not a string - but still string-like
Outside of the above guess, there's not too much else to go on. Just check there's nothing unusual about the id
(i.e. some database drivers may create specialized string values for identifiers). It's a curious error, but need more information to provide additional help.
Let me know how you go.
Cheers
S
from typebox.
Related Issues (20)
- Reduce unnecessary cloning in `Value.Convert` HOT 2
- [typebox-codegen] Option to emit types wrapped in arrow function? HOT 1
- Type.Mapped does not handle optional properties the same as Typescript HOT 2
- Add changelog or create a new release for each tag HOT 3
- TypeCheck.Decode return type inferred incorrectly? HOT 12
- Feature request: functions as defaults HOT 3
- Composite doesn't check additionalProperties HOT 2
- Custom TypeRegistry and TypeFormat HOT 1
- [feat] describe a object with pattern key, and literal key at the same time HOT 1
- Easier/general way to implement Typescript's "key remapping via `as`" approach HOT 1
- Overriding Schema Title HOT 1
- Cannot find module "./assert/index.mjs" HOT 1
- Encode is called twice on Type.Transform when inner type is Type.Intersection HOT 1
- StaticDecode cannot handle union of literals, while Static can HOT 1
- How to validate raw json schema HOT 2
- Why is Nullable not a first class Type? HOT 4
- Value.Convert does not seem to convert sometimes HOT 3
- `Value.Default` corrupts data in unions
- Is there a way to coerce when creating a schema? HOT 2
- Avoid losing precision when converting to bigints HOT 6
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.