SeyZ / jsonapi-serializer

A Node.js framework agnostic library for (de)serializing your data to JSON API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feat: On deserialization it would be nice if the meta, links, etc, are available as a Symbol in the data

diosney opened this issue · comments

Right now after deserialization, we don't have access to the meta data like meta, links and so on, only to the data itself.

This has a caveat, that if we pass or return that data to another method, we lose access to that meta data and forces us now to destructure it before deserialization to pass it as an extra param.

This could be easily solved if that meta data is returned as a non enumerable, non writable, non configurable property keyed with a Symbol, to avoid clashes, so we can have access to it at any time if we have a reference to the deserialized data itself.

For instance:

let deserializedData: any = new JsonApiSerializer
          .Deserializer(JSON_DESERIALIZER_DEFAULT_OPTIONS)
          .deserialize(jsonApiResponse);

console.log(deserializedData[JsonApiSerializer.EXTRAS_SYMBOL]); 

// Example output could be:
{
   extras: {
     links: {...},
     meta: {...}
   }
}

// Extras Symbol could be something like:
JsonApiSerializer.EXTRAS_SYMBOL = new Symbol('json-api-serializer-extras-symbol');