data-api-client icon indicating copy to clipboard operation
data-api-client copied to clipboard

Typescript Support

Open MattNguyen opened this issue 5 years ago • 13 comments

It would be great to include a type declaration file.

I'm currently using this for now, but I'm seeing TypeError: config.RDS.executeStatement is not a function when executing query().

declare module 'data-api-client' {
  import RDSDataService from 'aws-sdk/clients/rdsdataservice';
  import {ConfigBase as Config} from 'aws-sdk/lib/config';

  export interface iParams {
    secretArn: string;
    resourceArn: string;
    database: string;
    keepAlive?: boolean;
    hydrateColumnNames?: boolean;
    options?: Config & RDSDataService.Types.ClientConfiguration;
  }

  export interface iDataAPIClient {
    query(...x: any[]): iDataAPIQueryResult;
  }

  export interface iDataAPIQueryResult {
    records: Array<any>;
  }

  export default function (params: iParams): iDataAPIClient
}

MattNguyen avatar Jun 05 '19 16:06 MattNguyen

Hi Matt,

A TypeScript declaration file is on my list of TODOs. The typing will need to be a bit more complex than what you've got. The config object stores a reference to the RDSDataService methods, but also promisifies them under the hood. I'll need to do a bit more research to figure this out. Any help would be greatly appreciated.

Thanks, Jeremy

jeremydaly avatar Jun 05 '19 16:06 jeremydaly

@MattNguyen - I am going implement this lib in TS as well did you get anywhere with it by chance?

@jeremydaly - nice work on this; starting to pull it into a serverless(.com) based project that I have in TypeScript so checking to see if any work has been done in TS yet.

cbschuld avatar Nov 02 '19 00:11 cbschuld

@MattNguyen I had to adjust your type definitions to fix settings (likely still incorrect) and make query return a promise. See PR #49.

@cbschuld How is your implementation going?

MarkHerhold avatar Jun 13 '20 20:06 MarkHerhold

@MarkHerhold my solution is here (https://github.com/cbschuld/rds-data). (https://www.npmjs.com/package/rds-data). Jeremy's library is so good just missing that Typescript ❤️ . I am not sold my adoption is great either, related specifically to how I am typing the return values, but it has been nice to have in a few of my TS projects.

cbschuld avatar Jun 13 '20 22:06 cbschuld

@cbschuld Neat! Are you running it in prod? I could give it a try!

MarkHerhold avatar Jun 14 '20 14:06 MarkHerhold

@MarkHerhold - yes, on a few different apps. So far so good!

cbschuld avatar Jun 14 '20 15:06 cbschuld

Would be great to see this come through as this library seems to return data a nicer format than "rds-data" package mentioned above.

miketeix avatar Aug 26 '20 02:08 miketeix

Hey @miketeix there is an open PR to change the way the data is returned from rds-data. Interested in your feedback if you want to toss it over there.

cbschuld avatar Aug 26 '20 05:08 cbschuld

Is there an update on this? Could be extremely useful having TypeScript, this seems like a very good library with good potential, because using aws-sdk is a pain with the Data API

idanlo avatar Jan 07 '21 10:01 idanlo

@ffxsam, any interest in working on this?

jeremydaly avatar Jan 07 '21 15:01 jeremydaly

@jeremydaly I don't have the bandwidth right now, unfortunately! I wish I did because I've been wanting TS support myself. 😄

ffxsam avatar Jan 09 '21 02:01 ffxsam

@jeremydaly Because the PR hasn't been updated in a while I took some of the code there and modified it a bit, it's pretty basic but it does the job, I have created a PR at DefinitelyTyped - https://github.com/DefinitelyTyped/DefinitelyTyped/pull/50495, If you could take a look there and offer improvements that would be great. Having no types for this is pretty annoying for me because I will need to use multiple instances of this library in lambda functions, so I would like it to have types without me needing to modify node_modules every time. Thank you!

By the way: I noticed that you are using legacy export syntax (module.exports) which means that the TypeScript types cannot export stuff other than the default exported member, which is not ideal, also TypeScript would have to require this module like this import Client = require('data-api-client'), if you could change to ES6 syntax exports I think that is the ideal solution.

idanlo avatar Jan 09 '21 11:01 idanlo

@jeremydaly ping

shellscape avatar Jun 09 '21 13:06 shellscape