diff --git a/types/data-api-client/data-api-client-tests.ts b/types/data-api-client/data-api-client-tests.ts index b078259a767004..a1fd83e142fa74 100644 --- a/types/data-api-client/data-api-client-tests.ts +++ b/types/data-api-client/data-api-client-tests.ts @@ -1,6 +1,6 @@ import Client = require('data-api-client'); -const client = Client({ +const client: Client.iDataAPIClient = Client({ resourceArn: '', secretArn: '', database: '', @@ -24,15 +24,13 @@ client.query({ sql: 'SELECT * FROM Users;', parameters: {}, transactionId: '' }) } }); -client - .query<{ id: string; name: string }>('SELECT * FROM Users WHERE id = :id;', { id: 'id' }) - .then(res => { - if (res.records?.length) { - const user = res.records[0]; - user.id; - user.name; - } - }); +client.query<{ id: string; name: string }>('SELECT * FROM Users WHERE id = :id;', { id: 'id' }).then(res => { + if (res.records?.length) { + const user = res.records[0]; + user.id; + user.name; + } +}); client .transaction() diff --git a/types/data-api-client/index.d.ts b/types/data-api-client/index.d.ts index b37b443d128297..c0626e041013fa 100644 --- a/types/data-api-client/index.d.ts +++ b/types/data-api-client/index.d.ts @@ -9,66 +9,67 @@ /// import type { ClientConfiguration, Types } from 'aws-sdk/clients/rdsdataservice'; +declare namespace Client { + type OmittedValues = 'database' | 'resourceArn' | 'secretArn' | 'schema'; -type OmittedValues = 'database' | 'resourceArn' | 'secretArn' | 'schema'; - -interface iParams { - secretArn: string; - resourceArn: string; - database?: string | undefined; - keepAlive?: boolean | undefined; - hydrateColumnNames?: boolean | undefined; - sslEnabled?: boolean | undefined; - options?: ClientConfiguration | undefined; - region?: string | undefined; - engine?: 'mysql' | 'pg' | undefined; - formatOptions?: { - deserializeDate?: boolean | undefined; - treatAsLocalDate?: boolean | undefined; - } | undefined; -} - -interface Transaction { - query(sql: string, params?: [] | unknown): Transaction; // params can be [] or {}; - query( - obj: + interface iParams { + secretArn: string; + resourceArn: string; + database?: string | undefined; + keepAlive?: boolean | undefined; + hydrateColumnNames?: boolean | undefined; + sslEnabled?: boolean | undefined; + options?: ClientConfiguration | undefined; + region?: string | undefined; + engine?: 'mysql' | 'pg' | undefined; + formatOptions?: | { - sql: string; - parameters: [] | unknown; - database?: string | undefined; - hydrateColumnNames?: boolean | undefined; + deserializeDate?: boolean | undefined; + treatAsLocalDate?: boolean | undefined; } - | ((prevResult: { insertId?: any }) => any), - ): Transaction; - - rollback: (error: Error, status: any) => void; - commit: () => Promise; -} + | undefined; + } -interface iDataAPIClient { - /* tslint:disable:no-unnecessary-generics */ - query(sql: string, params?: [] | unknown): Promise>; // params can be [] or {}; - query(obj: { - sql: string; - parameters?: [] | unknown | undefined; - transactionId?: string | undefined; - database?: string | undefined; - hydrateColumnNames?: boolean | undefined; - }): Promise>; - transaction(): Transaction; // needs to return an interface with + interface Transaction { + query(sql: string, params?: [] | unknown): Transaction; // params can be [] or {}; + query( + obj: + | { + sql: string; + parameters: [] | unknown; + database?: string | undefined; + hydrateColumnNames?: boolean | undefined; + } + | ((prevResult: { insertId?: any }) => any), + ): Transaction; - // promisified versions of the RDSDataService methods - batchExecuteStatement: (params: Omit) => Promise; - beginTransaction: () => Promise; - commitTransaction: (params: Omit) => Promise; - executeStatement: (params: Omit) => Promise; - rollbackTransaction: (params: Omit) => Promise; -} + rollback: (error: Error, status: any) => void; + commit: () => Promise; + } -interface iDataAPIQueryResult { - records: T[]; -} + interface iDataAPIClient { + /* tslint:disable:no-unnecessary-generics */ + query(sql: string, params?: [] | unknown): Promise>; // params can be [] or {}; + query(obj: { + sql: string; + parameters?: [] | unknown | undefined; + transactionId?: string | undefined; + database?: string | undefined; + hydrateColumnNames?: boolean | undefined; + }): Promise>; + transaction(): Transaction; // needs to return an interface with -declare function Client(params: iParams): iDataAPIClient; + // promisified versions of the RDSDataService methods + batchExecuteStatement: (params: Omit) => Promise; + beginTransaction: () => Promise; + commitTransaction: (params: Omit) => Promise; + executeStatement: (params: Omit) => Promise; + rollbackTransaction: (params: Omit) => Promise; + } + interface iDataAPIQueryResult { + records: T[]; + } +} +declare function Client(params: Client.iParams): Client.iDataAPIClient; export = Client;