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

Unhandled type: Bytes #16

Open
platform-kit opened this issue Jul 14, 2022 · 2 comments
Open

Unhandled type: Bytes #16

platform-kit opened this issue Jul 14, 2022 · 2 comments

Comments

@platform-kit
Copy link

It seems that the prisma adapter does not support the "bytes" type:
https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#bytes

Console output simply says: Unhandled type: Bytes

@styrken
Copy link

styrken commented Aug 29, 2022

I get the same. Any idea how it should behave in the case of Bytes?

@VSKut
Copy link

VSKut commented Sep 7, 2023

Faced with the same problem, but was able to find the temporary solution:

First of all, I i've got such (dot notation) Payload:

{
.....
'password.type': 'Buffer',
'password.data.0': '123',
'password.data.1': '21',
'password.data.2': '146',
'password.data.3': '168',
'password.data.4': '174',
.....
}

Into a normal object:

....
{
 type: 'Buffer',
 data: [
    '123', '21',  '146', '168', '174',
    '142', '68',  '50',  '105', '91',
    '154', '143', '96',  '108', '201',
    '236', '4',   '73',  '76',  '161',
    '109', '120', '172', '212', '161',
    '172', '152', '115', '2',   '146',
    '122', '53'
  ]
}
....

After that, we take Data from this object and turn it into a Buffer

Buffer.from(payload.password.data)

And after that I reassign this Buffer to the password value in the payload.
And yes - it works!

Full code:

  options: {
    actions: {
      edit: {
        before: async (request) => {
          if (isGETMethod(request)) {
            return request;
          }

          // convert "dot notation" to regular object
          let payload: any = {};
          for (const key in request.payload) {
            _.set(payload, key,  _.get(request.payload, key));
          }

          // convert "password object" to Buffer & assign to payload
          _.set(payload, 'password', Buffer.from(payload.password.data));

          request.payload = payload;

          // return request.payload.password with Buffer type
          return request
        },
      }
  }
}

It's my first day using AdminJS and I don't know all the mechanics - if someone can write some more convenient handler for Bytes data based on this, it will be cool.

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

No branches or pull requests

3 participants