From b469f0266920b5538ade64c7d9b6731519568085 Mon Sep 17 00:00:00 2001 From: Ifiok Jr Date: Tue, 5 Feb 2019 11:15:36 +0000 Subject: [PATCH] feat: add wait-on types --- types/wait-on/index.d.ts | 94 ++++++++++++++++++++++++++++++++++ types/wait-on/tsconfig.json | 16 ++++++ types/wait-on/tslint.json | 1 + types/wait-on/wait-on-tests.ts | 75 +++++++++++++++++++++++++++ 4 files changed, 186 insertions(+) create mode 100644 types/wait-on/index.d.ts create mode 100644 types/wait-on/tsconfig.json create mode 100644 types/wait-on/tslint.json create mode 100644 types/wait-on/wait-on-tests.ts diff --git a/types/wait-on/index.d.ts b/types/wait-on/index.d.ts new file mode 100644 index 0000000000..55275a24e0 --- /dev/null +++ b/types/wait-on/index.d.ts @@ -0,0 +1,94 @@ +// Type definitions for wait-on 3.2 +// Project: https://github.com/jeffbski/wait-on#readme +// Definitions by: Ifiok Jr. +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +export = waitOn; + +declare function waitOn(options: waitOn.WaitOnOptions): Promise; +declare function waitOn( + options: waitOn.WaitOnOptions, + cb: (err: any) => void, +): void; + +declare namespace waitOn { + interface WaitOnOptions { + /** + * Array of string resources to wait for. prefix determines the type of resource with the default type of file: + */ + resources: string[]; + /** + * Initial delay in ms. + * @default 0 + */ + delay?: number; + /** + * Poll resource interval in ms, + * @default 250ms + */ + interval?: number; + /** + * Flag which outputs to stdout, remaining resources waited on and when complete or any error occurs. + */ + log?: boolean; + /** + * Flag to reverse operation so checks are for resources being NOT available. + * @default false + */ + reverse?: boolean; + /** + * Timeout in ms until it aborts with error. + * @default Infinity + */ + timeout?: number; + /** + * Tcp timeout in ms. + * @default 300 + */ + tcpTimeout?: number; + /** + * Flag which outputs debug output. + * @default false + */ + verbose?: boolean; + /** + * Stabilization time in ms + * Waits this amount of time for file sizes to stabilize or other resource availability to remain unchanged. + * @default 750ms. + */ + window?: number; + + /** + * Https specific option. + * see https:// github.com/request/request#readme for specific details + */ + auth?: WaitOnAuth; + httpSignature?: HttpSignature; + strictSSL?: boolean; + followAllRedirects?: boolean; + followRedirect?: boolean; + headers?: Record; + } + + interface HttpSignature { + keyId: string; + key: string; + } + + type WaitOnAuth = + | { + username: string; + password: string; + } + | { + /** + * Alias of username + */ + user: string; + /** + * Alias of password + */ + pass: string; + }; +} diff --git a/types/wait-on/tsconfig.json b/types/wait-on/tsconfig.json new file mode 100644 index 0000000000..c400fad2fe --- /dev/null +++ b/types/wait-on/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "wait-on-tests.ts"] +} diff --git a/types/wait-on/tslint.json b/types/wait-on/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/wait-on/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/wait-on/wait-on-tests.ts b/types/wait-on/wait-on-tests.ts new file mode 100644 index 0000000000..dea9a9c262 --- /dev/null +++ b/types/wait-on/wait-on-tests.ts @@ -0,0 +1,75 @@ +import waitOn = require('wait-on'); + +const opts = { + resources: [ + 'file1', + 'http://foo.com:8000/bar', + 'https://my.com/cat', + 'http-get://foo.com:8000/bar', + 'https-get://my.com/cat', + 'tcp:foo.com:8000', + 'socket:/my/sock', + 'http://unix:/my/sock:/my/url', + 'http-get://unix:/my/sock:/my/url', + ], + delay: 1000, // initial delay in ms, default 0 + interval: 100, // poll interval in ms, default 250ms + timeout: 30000, // timeout in ms, default Infinity + tcpTimeout: 1000, // tcp timeout in ms, default 300ms + window: 1000, // stabilization time in ms, default 750ms + + // http options + ca: [ + /* strings or binaries */ + ], + cert: [ + /* strings or binaries */ + ], + key: [ + /* strings or binaries */ + ], + passphrase: 'yourpassphrase', + auth: { + user: 'theuser', // or username + pass: 'thepassword', // or password + }, + httpSignature: { + keyId: 'yourKeyId', + key: 'yourKey', + }, + strictSSL: false, + followAllRedirects: true, + followRedirect: true, + headers: { + 'x-custom': 'headers', + }, +}; + +const handleError = (err: any) => undefined; + +// Usage with callback function +waitOn(opts, err => { + if (err) { + return handleError(err); + } + // once here, all resources are available +}); + +// Usage with promises +waitOn(opts) + .then(() => { + // once here, all resources are available + }) + .catch(err => { + handleError(err); + }); + +// Usage with async await +(async () => { + try { + await waitOn(opts); + // once here, all resources are available + } catch (err) { + handleError(err); + } +})();