jeremydaly / data-api-client

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

TypeScript Type Definitions #49

Open MarkHerhold opened 4 years ago

MarkHerhold commented 4 years ago

First pass at TS types from #2

jeremydaly commented 4 years ago

Thanks @MarkHerhold! Will review this soon.

MarkHerhold commented 4 years ago

Unfortunantly, the options object is completely wrong still. I'll have to take another look at it.

MarkHerhold commented 4 years ago

@jeremydaly Ok I figured out what you were doing with options and made some changes!

BTW, something I noticed - it's probably not a good idea to mutate global objects in this lib because you don't document the side effects and users don't expect it. IMO, it's best to leave that up to the user.

rraziel commented 4 years ago

Having typings support will be a nice improvement.

It would be interesting to have a generic parameter for iDataAPIQueryResult and use with query so you can do things like this without having to cast:

const result = await db.query<RecordType>('SELECT * from records');
const record = result.records[0];

Something like:


export interface iDataAPIClient {
  query<T>(sql: string, params?: [] | unknown): Promise<iDataAPIQueryResult<T>>;
  query<T>(obj: { sql: string; parameters: [] | unknown; database: string; hydrateColumnNames?: boolean }): Promise<iDataAPIQueryResult<T>>;
}

export interface iDataAPIQueryResult<T> {
  records: Array<T>;
}
MarkHerhold commented 4 years ago

@rraziel good idea, will give it a shot 👍

markpar commented 3 years ago

Anything I can do to help out on this one, @jeremydaly? The type definitions on DefinitelyTyped have what I think might be an errant type reference:

// This is added because aws-sdk depends on @types/node
/// <reference types="node" />

This is causing errors in our Reactive Native app because RN uses browser timers and referencing the node types redefines the timer functions, causing TSC errors b/c we're using number types when it now wants NodeJS.Timeout types.

padzikm commented 3 years ago

Hi, any chances that will be merged soon?