Skip to content

ref: use Registry instead of TypeSystem#977

Merged
SaltyAom merged 3 commits intoelysiajs:mainfrom
bogeychan:bogey/914
Feb 16, 2025
Merged

ref: use Registry instead of TypeSystem#977
SaltyAom merged 3 commits intoelysiajs:mainfrom
bogeychan:bogey/914

Conversation

@bogeychan
Copy link
Copy Markdown
Contributor

Fixes #914

) => TUnsafe<File>

const File: ElysiaFile =
(TypeRegistry.Get('Files') as unknown as ElysiaFile) ??
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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


t.UnionEnum = ElysiaType.UnionEnum

function getOrSetType<TSchema = unknown, TReturn = unknown>(
Copy link
Copy Markdown
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.

TypeSystemDuplicateFormat,
TypeSystemDuplicateTypeKind
} from '@sinclair/typebox/system'
export { TypeRegistry, FormatRegistry } from '@sinclair/typebox'
Copy link
Copy Markdown
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..

@SaltyAom
Copy link
Copy Markdown
Member

B2ADE125-536D-44A1-A536-D4E3A36C8338

@SaltyAom SaltyAom merged commit 7578faa into elysiajs:main Feb 16, 2025
1 check passed
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

2 participants