graphiti-api/spraypaint.js

Model to json payload

Opened this issue · 2 comments

Is there a way to generate json payload from a model's instance? Right now I have this in my code which seems to work, but curious if an alternative exists

import { WritePayload } from 'spraypaint/lib-esm/util/write-payload';

@Model()
class Model extends SpraypaintBase {
  toJsonPayload = () => {
    return new WritePayload(this).asJSON();
  };
}

I think this is easier for read operations, but what you have is probably the only way to go for writes. I'd accept a PR for it if you'd like to add it with some tests!

I'll try to find some time to send a pr, thanks @richmolj !