yury-dymov / json-api-normalizer

Normalize JSON API data for redux applications
MIT License
576 stars 40 forks source link

What about type annotations? #8

Open apsavin opened 7 years ago

apsavin commented 7 years ago

Hi, Yury!

Thanks for the useful lib!

A lot of programmers in JS community use flow and Typescript. My company uses flow, so I'm interested in flow mostly. Do you want to add annotations so the users of typed languges would benefit from it?

Here's the docs for flow and typescript for reference.

yury-dymov commented 7 years ago

Hi @apsavin,

I am using flow in my projects as well, and I considered to add it here. I am a bit busy nowadays, so this might be shipped in a month from now or so. PRs are welcome of course :)

emp823 commented 5 years ago

Made a simple definition. Does not cover the actual transformations, that could probably be covered with generics.

declare module "json-api-normalizer" {
  export interface IJsonApiResponse {
    data: IJsonApiObject[]
    included?: IJsonApiObject[]
    links?: { [key: string]: string }
    meta?: { [key: string]: any }
  }

  export interface IJsonApiObject {
    attributes: { [key: string]: any }
    id: string
    links?: { [key: string]: string }
    meta?: {}
    relationships: {
      [key: string]: {
        data: IJsonApiReference | IJsonApiReference[]
        links?: { [key: string]: string }
        meta?: {}
      }
    }
    type: string
  }

  interface IJsonApiReference {
    id: string
    type: string
  }

  interface IOpts {
    camelizeKeys?: boolean
    camelizeTypeValues?: boolean
    endpoint?: boolean
    filterEndpoint?: boolean
  }

  function normalize(json: IJsonApiResponse, opts?: IOpts): {}
  export default normalize
}
yury-dymov commented 5 years ago

@emp823 looks great! Would be more than happy to accept a good PR, once ready