jeremydaly / data-api-client

A "DocumentClient" for the Amazon Aurora Serverless Data API
MIT License
446 stars 63 forks source link

Typescript Support #2

Open MattNguyen opened 5 years ago

MattNguyen commented 5 years ago

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
}
jeremydaly commented 5 years ago

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

cbschuld commented 5 years ago

@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.

MarkHerhold commented 4 years ago

@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?

cbschuld commented 4 years ago

@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.

MarkHerhold commented 4 years ago

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

cbschuld commented 4 years ago

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

miketeix commented 4 years ago

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

cbschuld commented 4 years ago

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.

idanlo commented 3 years ago

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

jeremydaly commented 3 years ago

@ffxsam, any interest in working on this?

ffxsam commented 3 years ago

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

idanlo commented 3 years ago

@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.

shellscape commented 3 years ago

@jeremydaly ping