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

Add support for typed arrays #4418

Closed
makuko opened this issue Jun 3, 2023 · 1 comment · Fixed by #4419
Closed

Add support for typed arrays #4418

makuko opened this issue Jun 3, 2023 · 1 comment · Fixed by #4419
Labels
enhancement New feature or request

Comments

@makuko
Copy link
Contributor

makuko commented Jun 3, 2023

Is your feature request related to a problem? Please describe.
Currently MikroORM works fine with Node.js Buffer. They are handled correctly in the EntityDTO type returned by the toObject method. Also BlobType can store them as expected in the database.

So far so good. But unfortunetely in browser applications we can only work with typed arrays. I'm working with a binary format (CBOR) in my API and data is transferred as Uint8Array since that is supported in both Node.js and browsers.

Describe the solution you'd like
I propose to support at least Uint8Array in BlobType and EntityDTO. Since Node.js Buffer basically is a Uint8Array and it usually is the drop-in replacement when browsers are involved.

Describe alternatives you've considered
Right now two extra conversion steps (incoming and outgoing) are necessary to make things run smoothly. The database side is not that bad actually. I created a custom type that is based on BlobType. The ougoign data on the other hand requires more boilerplate code if I don't want to do without type safety - which is one reason I picked MikroORM in the first place.

Additional context
I already made the rather trivial changes locally and can provide the necessary PR if that is helpful.

@makuko makuko added the enhancement New feature or request label Jun 3, 2023
@B4nan
Copy link
Member

B4nan commented Jun 3, 2023

I am not entirely sure what you mean, PR welcome for sure.

B4nan pushed a commit that referenced this issue Jun 10, 2023
The goal is to work properly with entities that have properties of type
Uint8Array. Those properties should automatically be stored as binary
data and converted back to Uint8Array without specifying a type
(analogous to Buffer).

Also when converting entities to DTOs Uint8Array types should be kept
unchanged.

Closes #4418
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants