From 7a3b17879620bb4785e7711f615993555ecb568c Mon Sep 17 00:00:00 2001 From: Konrad Mattheis Date: Sun, 3 Dec 2017 22:39:42 +0100 Subject: [PATCH 1/2] * add README.md * fix close -> closed * add better typing's for mixins and interceptors Signed-off-by: Konrad Mattheis --- types/enigma.js/README.md | 35 +++++++++++++++++++++++++++++ types/enigma.js/index.d.ts | 46 +++++++++++++++++++++++++++++++++----- 2 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 types/enigma.js/README.md diff --git a/types/enigma.js/README.md b/types/enigma.js/README.md new file mode 100644 index 0000000000..bafa016369 --- /dev/null +++ b/types/enigma.js/README.md @@ -0,0 +1,35 @@ +# Installation +> `npm install --save @types/enigma.js` + +# Summary +This package contains type definitions for enigma.js (https://github.com/qlik-oss/enigma.js). + +# Example + +`npm install --save enigma.js` +`npm install --save bluebird` + +```js +import * as enigma from "enigma.js"; +import * as blubird from "bluebird"; + +let qixSchema = require("./node_modules/enigma.js/schemas/12.20.0.json"); + +let enigmaConfig: enigmaJS.IConfig = { + Promise: blubird, + schema: qixSchema, + url: "ws://localhost:4848/" +}; + +let session = enigma.create(enigmaConfig); + +session.on("traffic:sent", data => console.log("sent:", data)); + +session.open() + .then((global: EngineAPI.IGlobal) => { + return global.EngineVersion() + }) + .then((version) => { + console.log(version); + }); +``` diff --git a/types/enigma.js/index.d.ts b/types/enigma.js/index.d.ts index 38fc18da16..f691e69b2b 100644 --- a/types/enigma.js/index.d.ts +++ b/types/enigma.js/index.d.ts @@ -38,7 +38,7 @@ declare namespace enigmaJS { /** * mixin.extend is an object containing methods to extend the generated API with. These method names cannot already exist or enigma.js will throw an error. */ - extend?: [any]; + extend?: any; /** * mixin.override is an object containing methods that overrides existing API methods. @@ -46,7 +46,35 @@ declare namespace enigmaJS { * Be careful when overriding, you may break expected behaviors in other mixins or your application. * base is a reference to the previous mixin method, can be used to invoke the mixin chain before this mixin method. */ - override?: [any]; + override?: any; + } + + interface IResponseInterceptors { + /** + * This method is invoked when a previous interceptor has rejected the promise, use this to handle for example errors before they are sent into mixins. + * @param session refers to the session executing the interceptor. + * @param request is the JSON-RPC request resulting in this error. You may use .retry() to retry sending it to QIX Engine. + * @param error is whatever the previous interceptor rejected with. + */ + onRejected?(session: ISession, request: any, error: any): Promise; + + /** + * This method is invoked when a promise has been successfully resolved, use this to modify the result or reject the promise chain before it is sent to mixins. + * @param session refers to the session executing the interceptor. + * @param request is the JSON-RPC request resulting in this error. You may use .retry() to retry sending it to QIX Engine. + * @param error is whatever the previous interceptor resolved with. + */ + onFulfilled?(session: ISession, request: any, result: any): Promise; + } + + interface IRequestInterceptors { + /** + * This method is invoked when a request is about to be sent to QIX Engine. + * @param session refers to the session executing the interceptor. + * @param request is the JSON-RPC request resulting in this error. You may use .retry() to retry sending it to QIX Engine. + * @returns request the new request + */ + onFulfilled?(session: ISession, request: any, result: any): any; } interface IProtocol { @@ -83,13 +111,19 @@ declare namespace enigmaJS { * See Mixins section for more information how each entry in this array should look like. * Mixins are applied in the array order. */ - mixins?: [any]; + mixins?: IMixin[]; /** - * Interceptors for augmenting responses before they are passed into mixins and end-users. + * Interceptors for augmenting requests before they are sent to QIX Engine. * See Interceptors section for more information how each entry in this array should look like. * Interceptors are applied in the array order. */ - interceptors?: [any]; + requestInterceptors?: IRequestInterceptors[]; + /** + * Interceptors for augmenting responses before they are sent to QIX Engine. + * See Interceptors section for more information how each entry in this array should look like. + * Interceptors are applied in the array order. + */ + responseInterceptors?: IResponseInterceptors[]; /** * An object containing additional JSON-RPC request parameters. * protocol.delta : Set to false to disable the use of the bandwidth-reducing delta protocol. @@ -148,7 +182,7 @@ declare namespace enigmaJS { * @param event - Event that triggers the function * @param func - Called function */ - on(event: "opened" | "close" | "suspended" | "resumed" | string, func: any): void; + on(event: "opened" | "closed" | "suspended" | "resumed" | string, func: any): void; } interface IGeneratedAPI { From 8770bd18c7f66ba10acdbbeeeff1d5db2310c7e0 Mon Sep 17 00:00:00 2001 From: Konrad Mattheis Date: Sun, 3 Dec 2017 22:41:26 +0100 Subject: [PATCH 2/2] fix README.md Signed-off-by: Konrad Mattheis --- types/enigma.js/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/types/enigma.js/README.md b/types/enigma.js/README.md index bafa016369..4370bff4cb 100644 --- a/types/enigma.js/README.md +++ b/types/enigma.js/README.md @@ -1,5 +1,5 @@ # Installation -> `npm install --save @types/enigma.js` +`npm install --save @types/enigma.js` # Summary This package contains type definitions for enigma.js (https://github.com/qlik-oss/enigma.js). @@ -7,6 +7,7 @@ This package contains type definitions for enigma.js (https://github.com/qlik-os # Example `npm install --save enigma.js` + `npm install --save bluebird` ```js @@ -27,7 +28,7 @@ session.on("traffic:sent", data => console.log("sent:", data)); session.open() .then((global: EngineAPI.IGlobal) => { - return global.EngineVersion() + return global.EngineVersion(); }) .then((version) => { console.log(version);