Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bogeychan
Copy link
Contributor

Fixes #914

@@ -232,33 +232,30 @@ type ElysiaFile = (
options?: Partial<ElysiaTypeOptions.Files> | undefined
) => TUnsafe<File>

const File: ElysiaFile =
(TypeRegistry.Get('Files') as unknown as ElysiaFile) ??
Copy link
Contributor Author

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"

Copy link
Contributor Author

@bogeychan bogeychan Dec 25, 2024

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'))
Copy link
Contributor Author

@bogeychan bogeychan Dec 25, 2024

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>(
Copy link
Contributor Author

@bogeychan bogeychan Dec 25, 2024

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'
Copy link
Contributor Author

@bogeychan bogeychan Dec 25, 2024

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..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Old usage of Typebox breaks Hermes
1 participant