From 61fe35677ab6aa9c0a9f0af374a0612d25f61220 Mon Sep 17 00:00:00 2001 From: Tom Richards Date: Tue, 25 Aug 2020 10:19:03 -0400 Subject: [PATCH 1/3] Add type definitions, es modules usage Signed-off-by: Tom Richards --- README.md | 14 +++++++++++++- cometd-nodejs-client.d.ts | 12 ++++++++++++ package.json | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 cometd-nodejs-client.d.ts diff --git a/README.md b/README.md index 48adfdb..3a7a61d 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Therefore, you need to install the CometD JavaScript Client, version 3.1.2 or gr npm install cometd ``` -### Usage +### Usage (CommonJS) ```javascript // Run the adapter code that implements XMLHttpRequest. @@ -38,4 +38,16 @@ var cometd = new lib.CometD(); ... ``` +### Usage (ES Modules) + +```javascript +import { CometD } from 'cometd'; +import { adapt } from 'cometd-nodejs-client'; +// Shim XMLHTTPRequest for Node.js (required by CometD). +adapt(); + +// Your normal CometD client application here. +const client = new CometD(); +``` + See [here](https://github.com/cometd/cometd-javascript/blob/master/README.md) for an example CometD client application. diff --git a/cometd-nodejs-client.d.ts b/cometd-nodejs-client.d.ts new file mode 100644 index 0000000..458e56c --- /dev/null +++ b/cometd-nodejs-client.d.ts @@ -0,0 +1,12 @@ +export interface Proxy { + uri?: string; + includes?: string[]; + excludes?: string[]; +} + +export interface Options { + logLevel?: "debug" | "info"; + httpProxy: Proxy; +} + +export function adapt(options?: Options): void; diff --git a/package.json b/package.json index f12d787..4c26028 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ }, "license": "Apache-2.0", "main": "cometd-nodejs-client.js", + "types": "cometd-nodejs-client.d.ts", "repository": { "type": "git", "url": "https://github.com/cometd/cometd-nodejs-client.git" From c0121d944fdd8dfb2548e3fbb49e1a697ec27f7e Mon Sep 17 00:00:00 2001 From: Tom Richards Date: Tue, 25 Aug 2020 10:30:31 -0400 Subject: [PATCH 2/3] Make http proxy optional Signed-off-by: Tom Richards --- cometd-nodejs-client.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cometd-nodejs-client.d.ts b/cometd-nodejs-client.d.ts index 458e56c..08465ff 100644 --- a/cometd-nodejs-client.d.ts +++ b/cometd-nodejs-client.d.ts @@ -6,7 +6,7 @@ export interface Proxy { export interface Options { logLevel?: "debug" | "info"; - httpProxy: Proxy; + httpProxy?: Proxy; } export function adapt(options?: Options): void; From e3e98cfb73a1324ca5260bada914baed5cff2039 Mon Sep 17 00:00:00 2001 From: Tom Richards Date: Fri, 4 Sep 2020 14:39:36 -0400 Subject: [PATCH 3/3] Rename Proxy -> HttpProxy, add copyright header Signed-off-by: Tom Richards --- .gitignore | 1 + cometd-nodejs-client.d.ts | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 1d57ba1..77dcfc5 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ .idea/ node_modules/ +package-lock.json diff --git a/cometd-nodejs-client.d.ts b/cometd-nodejs-client.d.ts index 08465ff..e172e03 100644 --- a/cometd-nodejs-client.d.ts +++ b/cometd-nodejs-client.d.ts @@ -1,4 +1,19 @@ -export interface Proxy { +/* + * Copyright (c) 2017-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export interface HttpProxy { uri?: string; includes?: string[]; excludes?: string[]; @@ -6,7 +21,7 @@ export interface Proxy { export interface Options { logLevel?: "debug" | "info"; - httpProxy?: Proxy; + httpProxy?: HttpProxy; } export function adapt(options?: Options): void;