-
-
Notifications
You must be signed in to change notification settings - Fork 245
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
ref: use Registry instead of TypeSystem #977
base: main
Are you sure you want to change the base?
Conversation
@@ -232,33 +232,30 @@ type ElysiaFile = ( | |||
options?: Partial<ElysiaTypeOptions.Files> | undefined | |||
) => TUnsafe<File> | |||
|
|||
const File: ElysiaFile = | |||
(TypeRegistry.Get('Files') as unknown as ElysiaFile) ?? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here was "Files" instead of "File"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Furthermore, TypeRegistry.Get('...')
didn't work as expected because it returns the validation function instead of the schema-function with options, which means it breaks if someone overwrites it nowadays or when type-system.ts
gets executed twice.
schema.enum.includes(value as never) | ||
) | ||
}) | ||
if (!TypeRegistry.Has('UnionEnum')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here was no "Has"-check.. In case a user wanna override it
@@ -744,6 +745,18 @@ t.Date = ElysiaType.Date | |||
|
|||
t.UnionEnum = ElysiaType.UnionEnum | |||
|
|||
function getOrSetType<TSchema = unknown, TReturn = unknown>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function implementation is based on sinclare docs and TypeSystem.Type.
It's not recommendet anymore to use TypeSystem
and instead switch to TypeRegistry
and FormatRegistry
.
This approach doesn't throw any TypeSystemDuplicateTypeKind
-Error.
@@ -752,6 +765,7 @@ export { | |||
TypeSystemDuplicateFormat, | |||
TypeSystemDuplicateTypeKind | |||
} from '@sinclair/typebox/system' | |||
export { TypeRegistry, FormatRegistry } from '@sinclair/typebox' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added registry exports to simplify providing additional type/format logic without bun add @sinclair/typebox@<exact-elysia-version>
.
Maybe we could export this getOrSetType
in the future as well or we wait until typebox
comes up with something similar..
Fixes #914