Skip to content

Add Bytes type to Parse.Schema #1503

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

Closed
4 tasks done
MrMartinR opened this issue Jun 25, 2022 · 18 comments · Fixed by #2001
Closed
4 tasks done

Add Bytes type to Parse.Schema #1503

MrMartinR opened this issue Jun 25, 2022 · 18 comments · Fixed by #2001
Labels
type:feature New feature or improvement of existing feature

Comments

@MrMartinR
Copy link

New Issue Checklist

Issue Description

Is not possible to add a field using Bytes filetype.
VS Code throws an error on the 'Bytes' parameter
Argument of type '"Bytes"' is not assignable to parameter of type 'TYPE | undefined'.ts(2345)

Steps to reproduce

  const schema = new Parse.Schema('Contact')
  schema.addField('bytesField', 'Bytes')
  schema.update().then((result) => {
    console.log(result)
  })

I guess we need something like Parse-Swift feature.

Actual Outcome

On console.log Uncaught (in promise) Error: Bytes is not a valid type.

Expected Outcome

Not get the error and return the object

Environment

Local environment, using parse-server from the npm

Server

  • Parse Server version: latest
  • Operating system: macOS Monterrey
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): Local

Database

  • System (MongoDB or Postgres): Postgres
  • Database version: 14
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): local

Client

  • Parse JS SDK version: latest

Logs

https://community.parseplatform.org/t/saving-byte-data-to-parseobject/1804/4
parse-community/Parse-Swift#190

it('works with bytes type', done => {
const object = new TestObject();
object.set('bytes', { __type: 'Bytes', base64: 'ZnJveW8=' });
object
.save()
.then(() => {
const query = new Parse.Query(TestObject);
return query.get(object.id);
})
.then(o => {
assert.equal(o.get('bytes').__type, 'Bytes');
assert.equal(o.get('bytes').base64, 'ZnJveW8=');
done();
});
});

@parse-github-assistant
Copy link

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

@mtrezza
Copy link
Member

mtrezza commented Jun 25, 2022

Where is the Bytes field type documented, I think that documentation is still missing? Parse Dashboard doesn't even seem to support that field type?

@MrMartinR
Copy link
Author

MrMartinR commented Jun 25, 2022

mmm I assumed that Parse-server supports that, Baker did some implementation in Swift parse-community/Parse-Swift#190 and the test sample creates an object type Bytes object.set('bytes', { __type: 'Bytes', base64: 'ZnJveW8=' });
and this guy did something too https://community.parseplatform.org/t/saving-byte-data-to-parseobject/1804/8

the parse js sdk schema shows the addField('newField', 'ANewDataType') (which I think is redundant if we have the rest of the add() methods...
https://docs.parseplatform.org/js/guide/#schema

mySchema
  .addString('stringField')
  .addNumber('numberField')
  .addBoolean('booleanField')
  .addDate('dateField')
  .addFile('fileField')
  .addGeoPoint('geoPointField')
  .addPolygon('polygonField')
  .addArray('arrayField')
  .addObject('objectField')
  .addPointer('pointerField', '_User')
  .addRelation('relationField', '_User');

// new types can be added as they are available
mySchema.addField('newField', 'ANewDataType')

@mtrezza
Copy link
Member

mtrezza commented Jun 25, 2022

Yes, the type is there, but I don't know how widely it is supported; it doesn't seem to be documented and how would Parse Dashboard even display that field if the field type does not seem to exist there? These are more general questions, not necessarily related to your new issue.

@MrMartinR
Copy link
Author

MrMartinR commented Jun 25, 2022

the guy who was played with it, explained that parse-dashboard shows it as encoded base64 but is stored in Bytes, the type of the field shows as Bytes

image from the post in the forum

@mtrezza
Copy link
Member

mtrezza commented Jun 25, 2022

I see, so it shows just the raw JSON data, like a custom data type - neat.

@MrMartinR
Copy link
Author

I personally not sure if I need/will ever use Bytes, I just saw something that "was missing" and I wanted to report it, just in case someone had free time to implemented it..

@mtrezza
Copy link
Member

mtrezza commented Jun 26, 2022

You'd need to look into Parse Server if there is a Bytes data type at all. It's not in the docs, so I'm not sure there is something missing in the docs or it's supposed to be handled in a special way.

@MrMartinR
Copy link
Author

Not even know how to check that?
I did find "something" here and here
So I guess is supported? I am gonna try to summon @cbaker6 here to see if he can throw some light...

@cbaker6
Copy link

cbaker6 commented Jun 26, 2022

I think the benefits of ParseBytes are highlighted in the link you already shared: https://community.parseplatform.org/t/saving-byte-data-to-parseobject/1804

My guess would be Bytes was simply overlooked by the other SDKs, Dashboard, and docs when open-sourcing. I wasn’t aware of it until @davimacedo mentioned it in the linked thread. It was an easy implementation in the Swift SDK, so I suspect the same for other SDKs.

It definitely works as I tested it when adding it to the Swift SDK.

@cbaker6
Copy link

cbaker6 commented Jun 26, 2022

I see, so it shows just the raw JSON data, like a custom data type - neat.

@mtrezza I believe there are additional benefits as the data is stored in the DB as bytes. See here: https://community.parseplatform.org/t/saving-byte-data-to-parseobject/1804/8?u=cbaker6

@mtrezza
Copy link
Member

mtrezza commented Jun 26, 2022

I think you are right with it being overlooked, it's been there for a long time, presumably since open-sourcing looking at git blame.

We need some care when expanding / building upon this half-implemented feature. At least Parse Dashboard seems to be able to handle this field type, but an SDK may crash if the data type is unknown and not properly handled.

Something we could do immediately is adding this type to the docs with a note that it's not fully implemented across client SDKs and Parse Dashboard (can only display but not set field type), use at own risk.

So the fact that Parse.Schema doesn't support it is an actual issue. Well uncovered, @MrMartinR! Would you want to open a docs PR to add a note about this data type? This could bring some clarity for people who are researching this.

@cbaker6
Copy link

cbaker6 commented Jun 26, 2022

Implementing this into Schema for the JS SDK would require looking here:

const FIELD_TYPES = [
'String',
'Number',
'Boolean',
'Date',
'File',
'GeoPoint',
'Polygon',
'Array',
'Object',
'Pointer',
'Relation',
];

The Swift SDK counterpart is here:

/// Field types available in `ParseSchema`.
    public enum FieldType: String, Codable {
        /// A string type.
        case string = "String"
        /// A number type.
        case number = "Number"
        /// A boolean type.
        case boolean = "Boolean"
        /// A date type.
        case date = "Date"
        /// A file type.
        case file = "File"
        /// A geoPoint type.
        case geoPoint = "GeoPoint"
        /// A polygon type.
        case polygon = "Polygon"
        /// An array type.
        case array = "Array"
        /// An object type.
        case object = "Object"
        /// A pointer type.
        case pointer = "Pointer"
        /// A relation type.
        case relation = "Relation"
        /// A bytes type.
        case bytes = "Bytes"
        /// A acl type.
        case acl = "ACL"
    }

Of course tests will be needed in the JS SDK side. You should be able to copy/modify this test for Bytes:

it('can create schema pointer and relation with addFields', () => {
const schema = new ParseSchema('SchemaTest');
schema
.addField('newPointer', 'Pointer', { targetClass: '_User' })
.addField('newRelation', 'Relation', { targetClass: '_User' });
expect(schema._fields.newPointer.type).toEqual('Pointer');
expect(schema._fields.newRelation.type).toEqual('Relation');
expect(schema._fields.newPointer.targetClass).toEqual('_User');
expect(schema._fields.newRelation.targetClass).toEqual('_User');
});

@mtrezza
Copy link
Member

mtrezza commented Jun 26, 2022

So I'll label this as a feature request if we assume that Bytes is simply not supported everywhere yet.

@mtrezza mtrezza added the type:feature New feature or improvement of existing feature label Jun 26, 2022
@cbaker6
Copy link

cbaker6 commented Aug 18, 2022

Bytes has been in the Objective-C SDK for years. The SDK can encode and decode Bytes.

@mtrezza
Copy link
Member

mtrezza commented Aug 18, 2022

Even more interesting that it's not in the JS SDK, which is usually the most complete one.

@cbaker6
Copy link

cbaker6 commented Aug 18, 2022

If my memory serves me correct, the JS SDK has only been more complete than the Objective-C and Android SDK's in recent years due to open-source maintainers beefing it up and limited contributions to the others. Before that, the other SDKs were more complete than JS.

@dplewis
Copy link
Member

dplewis commented Aug 25, 2023

I can open a PR for this.

Should we all so add support for ParseBytes like in the PHP SDK in the future?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or improvement of existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants