From 2f03cffc48c550dbf5eac90e5fd7c1ddbaf9434f Mon Sep 17 00:00:00 2001 From: Claude Ciocan Date: Mon, 18 Jun 2018 14:26:14 -0700 Subject: [PATCH 1/2] Added declaration files for gramps rest-helpers Why did you do this? The package doesn't have it's own so I'm adding them. I don't use all of the methods in the GraphQLConnector class, so I haven't validated that all of these methods work, but based on the comments in the source code it appears to be the correct types. --- .../gramps__rest-helpers-tests.ts | 16 ++++++++++++ types/gramps__rest-helpers/index.d.ts | 26 +++++++++++++++++++ types/gramps__rest-helpers/tsconfig.json | 24 +++++++++++++++++ types/gramps__rest-helpers/tslint.json | 3 +++ 4 files changed, 69 insertions(+) create mode 100644 types/gramps__rest-helpers/gramps__rest-helpers-tests.ts create mode 100644 types/gramps__rest-helpers/index.d.ts create mode 100644 types/gramps__rest-helpers/tsconfig.json create mode 100644 types/gramps__rest-helpers/tslint.json diff --git a/types/gramps__rest-helpers/gramps__rest-helpers-tests.ts b/types/gramps__rest-helpers/gramps__rest-helpers-tests.ts new file mode 100644 index 0000000000..cbb74725ca --- /dev/null +++ b/types/gramps__rest-helpers/gramps__rest-helpers-tests.ts @@ -0,0 +1,16 @@ +import { GraphQLConnector, GraphQLModel } from '@gramps/rest-helpers'; + +const myConnector = new GraphQLConnector(); + +myConnector.apiBaseUri = "some uri"; +myConnector.headers = {}; +myConnector.cacheExpiry = 300; +myConnector.enableCache = true; +myConnector.redis = false; + +myConnector.get("someurl"); +myConnector.post("someendpoint", {}, {}).then(() => {}); +myConnector.put("someendpoint", {}, {}).then(() => {}); +myConnector.delete("someendpoint", {}).then(() => {}); + +const myModel = new GraphQLModel(myConnector); diff --git a/types/gramps__rest-helpers/index.d.ts b/types/gramps__rest-helpers/index.d.ts new file mode 100644 index 0000000000..4fb7e32a27 --- /dev/null +++ b/types/gramps__rest-helpers/index.d.ts @@ -0,0 +1,26 @@ +// Type definitions for @gramps/rest-helpers 1.1 +// Project: https://github.com/gramps-graphql/rest-helpers +// Definitions by: Claude Ciocan +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +export class GraphQLConnector { + constructor(); + + apiBaseUri: string; + headers: object; + request: any; + cacheExpiry: number; + enableCache: boolean; + redis: boolean; + get(endpoint: string): Promise; + post(endpoint: string, body: object, options: object): Promise; + put(endpoint: string, body: object, options: object): Promise; + delete(endpoint: string, options: object): Promise; +} + +export class GraphQLModel { + connector: GraphQLConnector; + + constructor({}); +} diff --git a/types/gramps__rest-helpers/tsconfig.json b/types/gramps__rest-helpers/tsconfig.json new file mode 100644 index 0000000000..07c3832ff5 --- /dev/null +++ b/types/gramps__rest-helpers/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "paths": { + "@gramps/rest-helpers": [ + "gramps__rest-helpers" + ] + } + } +} \ No newline at end of file diff --git a/types/gramps__rest-helpers/tslint.json b/types/gramps__rest-helpers/tslint.json new file mode 100644 index 0000000000..e60c15844f --- /dev/null +++ b/types/gramps__rest-helpers/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file From fc819241de6d3258ba046e7d840d5d475e0bda37 Mon Sep 17 00:00:00 2001 From: Claude Ciocan Date: Mon, 18 Jun 2018 20:42:11 -0700 Subject: [PATCH 2/2] Added files to tsconfig --- types/gramps__rest-helpers/tsconfig.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/types/gramps__rest-helpers/tsconfig.json b/types/gramps__rest-helpers/tsconfig.json index 07c3832ff5..03402cad31 100644 --- a/types/gramps__rest-helpers/tsconfig.json +++ b/types/gramps__rest-helpers/tsconfig.json @@ -20,5 +20,9 @@ "gramps__rest-helpers" ] } - } + }, + "files": [ + "index.d.ts", + "gramps__rest-helpers-tests.ts" + ] } \ No newline at end of file