From 5885e10dbb0a0be0a84221ae04f78b594b519ee5 Mon Sep 17 00:00:00 2001 From: Mark Herhold Date: Sat, 13 Jun 2020 16:03:23 -0400 Subject: [PATCH 1/5] adding TS types --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 4e086fa..8feeb6e 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.0.1", "description": "A lightweight wrapper that simplifies working with the Amazon Aurora Serverless Data API", "main": "index.js", + "types": "index.d.ts", "scripts": { "test": "jest", "test-ci": "eslint . && jest", From 45a4b9551a2fd7e935d31ba84e2e385dd677a39c Mon Sep 17 00:00:00 2001 From: Mark Herhold Date: Sat, 13 Jun 2020 16:04:21 -0400 Subject: [PATCH 2/5] adding TS types --- index.d.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..ea7e48c --- /dev/null +++ b/index.d.ts @@ -0,0 +1,23 @@ +declare module 'data-api-client' { + import type RDSDataService from 'aws-sdk/clients/rdsdataservice'; + import type { ConfigBase as Config } from 'aws-sdk/lib/config'; + export interface iParams extends RDSDataService.Types.ClientConfiguration { + secretArn: string; + resourceArn: string; + database: string; + keepAlive?: boolean; + hydrateColumnNames?: boolean; + options?: Config & RDSDataService.Types.ClientConfiguration; + } + + export interface iDataAPIClient { + query(...x: any[]): Promise; + } + + export interface iDataAPIQueryResult { + records: Array; + } + + export default function (params: iParams): iDataAPIClient; +} + From bdc74ab68ebf3b067c730ab3bb5e354149bf70dd Mon Sep 17 00:00:00 2001 From: Mark Herhold Date: Tue, 16 Jun 2020 17:31:29 -0400 Subject: [PATCH 3/5] fixing type issues --- README.md | 6 +++--- index.d.ts | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index de7e9d0..94e618d 100644 --- a/README.md +++ b/README.md @@ -133,9 +133,9 @@ Below is a table containing all of the possible configuration options for the `d | resourceArn | `string` | The ARN of your Aurora Serverless Cluster. This value is *required*, but can be overridden when querying. | | | secretArn | `string` | The ARN of the secret associated with your database credentials. This is *required*, but can be overridden when querying. | | | database | `string` | *Optional* default database to use with queries. Can be overridden when querying. | | -| hydrateColumnNames | `boolean` | When `true`, results will be returned as objects with column names as keys. If `false`, results will be returned as an array of values. | `true` | -| keepAlive | `boolean` | Enables HTTP Keep-Alive for calls to the AWS SDK. This dramatically decreases the latency of subsequent calls. | `true` | -| sslEnabled | `boolean` | *Optional* Enables SSL HTTP endpoint. Can be disable for local development. | `true` | +| hydrateColumnNames | `boolean` | *Optional* When `true`, results will be returned as objects with column names as keys. If `false`, results will be returned as an array of values. | `true` | +| keepAlive | `boolean` | *Optional* Enables HTTP Keep-Alive for calls to the AWS SDK. This dramatically decreases the latency of subsequent calls. | `true` | +| sslEnabled | `boolean` | *Optional* Enables SSL HTTP endpoint. Can be disabled for local development. | `true` | | options | `object` | An *optional* configuration object that is passed directly into the RDSDataService constructor. See [here](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/RDSDataService.html#constructor-property) for available options. | `{}` | | region | `string` | *Optional* AWS region to use. | `aws-sdk default` | diff --git a/index.d.ts b/index.d.ts index ea7e48c..8221c3c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,13 +1,16 @@ declare module 'data-api-client' { import type RDSDataService from 'aws-sdk/clients/rdsdataservice'; - import type { ConfigBase as Config } from 'aws-sdk/lib/config'; - export interface iParams extends RDSDataService.Types.ClientConfiguration { + import type { ClientConfiguration } from 'aws-sdk/clients/rdsdataservice'; + + export interface iParams { secretArn: string; resourceArn: string; database: string; keepAlive?: boolean; hydrateColumnNames?: boolean; - options?: Config & RDSDataService.Types.ClientConfiguration; + sslEnabled?: boolean; + options?: ClientConfiguration; + region?: string; } export interface iDataAPIClient { From 02ef0d3d608376c0046b7ea8cd9ee334327ee0c8 Mon Sep 17 00:00:00 2001 From: Mark Herhold Date: Thu, 18 Jun 2020 20:13:14 -0400 Subject: [PATCH 4/5] adding the transaction interface --- index.d.ts | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index 8221c3c..f161abd 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,11 +1,10 @@ declare module 'data-api-client' { - import type RDSDataService from 'aws-sdk/clients/rdsdataservice'; import type { ClientConfiguration } from 'aws-sdk/clients/rdsdataservice'; export interface iParams { secretArn: string; resourceArn: string; - database: string; + database?: string; keepAlive?: boolean; hydrateColumnNames?: boolean; sslEnabled?: boolean; @@ -13,8 +12,28 @@ declare module 'data-api-client' { region?: string; } + interface iTransaction { + query: iQuery; + rollback: (error: Error, status: any) => void; + commit: () => Promise; + } + + interface iQuery { + (sql: string, params?: [] | unknown): Promise; // params can be [] or {} + (obj: { sql: string; parameters: [] | unknown; database: string; hydrateColumnNames?: boolean }): Promise; + } + export interface iDataAPIClient { - query(...x: any[]): Promise; + query: iQuery; + transaction(): iTransaction; // needs to return an interface with + + // promisified versions of the RDSDataService methods + // TODO add actual return types + batchExecuteStatement: (...args) => Promise; + beginTransaction: (...args) => Promise; + commitTransaction: (...args) => Promise; + executeStatement: (...args) => Promise; + rollbackTransaction: (...args) => Promise; } export interface iDataAPIQueryResult { @@ -23,4 +42,3 @@ declare module 'data-api-client' { export default function (params: iParams): iDataAPIClient; } - From 0698e71b7a86d7b6ee1369b358640550a3834779 Mon Sep 17 00:00:00 2001 From: Mark Herhold Date: Fri, 19 Jun 2020 08:24:22 -0400 Subject: [PATCH 5/5] optional database --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index f161abd..c3c4719 100644 --- a/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ declare module 'data-api-client' { interface iQuery { (sql: string, params?: [] | unknown): Promise; // params can be [] or {} - (obj: { sql: string; parameters: [] | unknown; database: string; hydrateColumnNames?: boolean }): Promise; + (obj: { sql: string; parameters: [] | unknown; database?: string; hydrateColumnNames?: boolean }): Promise; } export interface iDataAPIClient {