mike-north / jsonapi-typescript

TypeScript type information for JSON:API documents
52 stars 5 forks source link

Shouldn't DocWithData have `meta?: MetaObject` included? #36

Closed gnapse closed 5 years ago

gnapse commented 5 years ago

Is your feature request related to a problem? Please describe.

I regularly need to process jsonapi responses that may or may not include the top level meta key. However, DocWithData does not include the optional meta key.

Describe the solution you'd like

Add meta?: MetaObject to DocWithData. Or better yet, to DocBase.

I may be missing something if you intentionally did not include it in that way, and decided to provide DocWithMeta as a separate entity, but the more I read the specification, meta can be found in any valid jsonapi response, or at least in responses with data, as seen here.

Describe alternatives you've considered

I was thinking of declaring a type DocWithData & DocWithMeta, but that does not express that meta is optional. I'm left with declaring something like this:

type MyDocWithData = DocWithData & { meta?: MetaObject };

But then again I'd have to replicate the above for SingleResourceDoc and CollectionResourceDoc.

If this is accepted, I'm more than happy to work on a PR myself.

mike-north commented 5 years ago

Yep, this should definitely be in the types. I'll see if I can find time to address this in the next couple of weeks, unless you beat me to it!

gnapse commented 5 years ago

I can do it right now. I just have a couple of questions: do you agree the resolution should involve adding meta?: MetaObject to DocBase? And if so, then what's the point of DocWithMeta?