@databricks/sql 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -1
- package/dist/DBSQLClient.d.ts +1 -1
- package/dist/DBSQLClient.js +18 -4
- package/dist/DBSQLClient.js.map +1 -1
- package/dist/DBSQLOperation/SchemaHelper.d.ts +4 -1
- package/dist/DBSQLOperation/SchemaHelper.js +25 -4
- package/dist/DBSQLOperation/SchemaHelper.js.map +1 -1
- package/dist/DBSQLOperation/index.js +2 -3
- package/dist/DBSQLOperation/index.js.map +1 -1
- package/dist/connection/connections/HttpConnection.js +2 -2
- package/dist/connection/connections/HttpConnection.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/result/IOperationResult.d.ts +2 -1
- package/dist/result/JsonResult.d.ts +3 -5
- package/dist/result/JsonResult.js +6 -11
- package/dist/result/JsonResult.js.map +1 -1
- package/dist/utils/buildUserAgentString.js +2 -7
- package/dist/utils/buildUserAgentString.js.map +1 -1
- package/dist/version.d.ts +2 -0
- package/dist/version.js +4 -0
- package/dist/version.js.map +1 -0
- package/node_modules/async-limiter/.eslintignore +2 -0
- package/node_modules/async-limiter/.nycrc +10 -0
- package/node_modules/async-limiter/.travis.yml +9 -0
- package/node_modules/async-limiter/LICENSE +8 -0
- package/node_modules/async-limiter/index.js +67 -0
- package/node_modules/async-limiter/package.json +39 -0
- package/node_modules/async-limiter/readme.md +132 -0
- package/node_modules/browser-or-node/LICENSE +21 -0
- package/node_modules/browser-or-node/README.md +63 -0
- package/node_modules/browser-or-node/lib/index.js +31 -0
- package/node_modules/browser-or-node/package.json +64 -0
- package/node_modules/browser-or-node/src/index.js +26 -0
- package/node_modules/isomorphic-ws/LICENSE +21 -0
- package/node_modules/isomorphic-ws/README.md +58 -0
- package/node_modules/isomorphic-ws/browser.js +17 -0
- package/node_modules/isomorphic-ws/index.d.ts +8 -0
- package/node_modules/isomorphic-ws/node.js +3 -0
- package/node_modules/isomorphic-ws/package.json +38 -0
- package/node_modules/node-int64/.npmignore +3 -0
- package/node_modules/node-int64/Int64.js +268 -0
- package/node_modules/node-int64/LICENSE +19 -0
- package/node_modules/node-int64/README.md +78 -0
- package/node_modules/node-int64/package.json +31 -0
- package/node_modules/node-int64/test.js +120 -0
- package/node_modules/q/CHANGES.md +800 -0
- package/node_modules/q/LICENSE +18 -0
- package/node_modules/q/README.md +874 -0
- package/node_modules/q/package.json +80 -0
- package/node_modules/q/q.js +2076 -0
- package/node_modules/q/queue.js +35 -0
- package/node_modules/thrift/LICENSE +306 -0
- package/node_modules/thrift/README.md +210 -0
- package/node_modules/thrift/lib/nodejs/README.md +142 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/binary.js +168 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/binary_protocol.js +367 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/browser.js +49 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/buffered_transport.js +186 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/compact_protocol.js +915 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/connection.js +396 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/create_client.js +54 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/framed_transport.js +185 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/header_protocol.js +258 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/header_transport.js +341 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/http_connection.js +282 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/index.js +76 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/input_buffer_underrun_error.js +32 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/int64_util.js +91 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/json_parse.js +299 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/json_protocol.js +799 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/log.js +87 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/multiplexed_processor.js +63 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/multiplexed_protocol.js +73 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/protocol.js +22 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/server.js +123 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/thrift.js +241 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/transport.js +22 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/web_server.js +567 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/ws_connection.js +286 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/ws_transport.js +206 -0
- package/node_modules/thrift/lib/nodejs/lib/thrift/xhr_connection.js +280 -0
- package/node_modules/thrift/package.json +76 -0
- package/node_modules/ws/LICENSE +21 -0
- package/node_modules/ws/README.md +417 -0
- package/node_modules/ws/index.js +9 -0
- package/node_modules/ws/lib/buffer-util.js +72 -0
- package/node_modules/ws/lib/constants.js +10 -0
- package/node_modules/ws/lib/event-target.js +170 -0
- package/node_modules/ws/lib/extension.js +211 -0
- package/node_modules/ws/lib/permessage-deflate.js +516 -0
- package/node_modules/ws/lib/receiver.js +513 -0
- package/node_modules/ws/lib/sender.js +401 -0
- package/node_modules/ws/lib/validation.js +29 -0
- package/node_modules/ws/lib/websocket-server.js +369 -0
- package/node_modules/ws/lib/websocket.js +828 -0
- package/node_modules/ws/package.json +48 -0
- package/package.json +9 -3
- package/dist/DBSQLOperation/getResult.d.ts +0 -2
- package/dist/DBSQLOperation/getResult.js +0 -19
- package/dist/DBSQLOperation/getResult.js.map +0 -1
- package/dist/result/NullResult.d.ts +0 -4
- package/dist/result/NullResult.js +0 -9
- package/dist/result/NullResult.js.map +0 -1
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Async-Limiter
|
|
2
|
+
|
|
3
|
+
A module for limiting concurrent asynchronous actions in flight. Forked from [queue](https://github.com/jessetane/queue).
|
|
4
|
+
|
|
5
|
+
[](http://www.npmjs.org/async-limiter)
|
|
6
|
+
[](https://travis-ci.org/STRML/async-limiter)
|
|
7
|
+
[](https://coveralls.io/r/STRML/async-limiter)
|
|
8
|
+
|
|
9
|
+
This module exports a class `Limiter` that implements some of the `Array` API.
|
|
10
|
+
Pass async functions (ones that accept a callback or return a promise) to an instance's additive array methods.
|
|
11
|
+
|
|
12
|
+
## Motivation
|
|
13
|
+
|
|
14
|
+
Certain functions, like `zlib`, have [undesirable behavior](https://github.com/nodejs/node/issues/8871#issuecomment-250915913) when
|
|
15
|
+
run at infinite concurrency.
|
|
16
|
+
|
|
17
|
+
In this case, it is actually faster, and takes far less memory, to limit concurrency.
|
|
18
|
+
|
|
19
|
+
This module should do the absolute minimum work necessary to queue up functions. PRs are welcome that would
|
|
20
|
+
make this module faster or lighter, but new functionality is not desired.
|
|
21
|
+
|
|
22
|
+
Style should confirm to nodejs/node style.
|
|
23
|
+
|
|
24
|
+
## Example
|
|
25
|
+
|
|
26
|
+
``` javascript
|
|
27
|
+
var Limiter = require('async-limiter')
|
|
28
|
+
|
|
29
|
+
var t = new Limiter({concurrency: 2});
|
|
30
|
+
var results = []
|
|
31
|
+
|
|
32
|
+
// add jobs using the familiar Array API
|
|
33
|
+
t.push(function (cb) {
|
|
34
|
+
results.push('two')
|
|
35
|
+
cb()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
t.push(
|
|
39
|
+
function (cb) {
|
|
40
|
+
results.push('four')
|
|
41
|
+
cb()
|
|
42
|
+
},
|
|
43
|
+
function (cb) {
|
|
44
|
+
results.push('five')
|
|
45
|
+
cb()
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
t.unshift(function (cb) {
|
|
50
|
+
results.push('one')
|
|
51
|
+
cb()
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
t.splice(2, 0, function (cb) {
|
|
55
|
+
results.push('three')
|
|
56
|
+
cb()
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
// Jobs run automatically. If you want a callback when all are done,
|
|
60
|
+
// call 'onDone()'.
|
|
61
|
+
t.onDone(function () {
|
|
62
|
+
console.log('all done:', results)
|
|
63
|
+
})
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Zlib Example
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
const zlib = require('zlib');
|
|
70
|
+
const Limiter = require('async-limiter');
|
|
71
|
+
|
|
72
|
+
const message = {some: "data"};
|
|
73
|
+
const payload = new Buffer(JSON.stringify(message));
|
|
74
|
+
|
|
75
|
+
// Try with different concurrency values to see how this actually
|
|
76
|
+
// slows significantly with higher concurrency!
|
|
77
|
+
//
|
|
78
|
+
// 5: 1398.607ms
|
|
79
|
+
// 10: 1375.668ms
|
|
80
|
+
// Infinity: 4423.300ms
|
|
81
|
+
//
|
|
82
|
+
const t = new Limiter({concurrency: 5});
|
|
83
|
+
function deflate(payload, cb) {
|
|
84
|
+
t.push(function(done) {
|
|
85
|
+
zlib.deflate(payload, function(err, buffer) {
|
|
86
|
+
done();
|
|
87
|
+
cb(err, buffer);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
console.time('deflate');
|
|
93
|
+
for(let i = 0; i < 30000; ++i) {
|
|
94
|
+
deflate(payload, function (err, buffer) {});
|
|
95
|
+
}
|
|
96
|
+
t.onDone(function() {
|
|
97
|
+
console.timeEnd('deflate');
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Install
|
|
102
|
+
|
|
103
|
+
`npm install async-limiter`
|
|
104
|
+
|
|
105
|
+
## Test
|
|
106
|
+
|
|
107
|
+
`npm test`
|
|
108
|
+
|
|
109
|
+
## API
|
|
110
|
+
|
|
111
|
+
### `var t = new Limiter([opts])`
|
|
112
|
+
Constructor. `opts` may contain inital values for:
|
|
113
|
+
* `t.concurrency`
|
|
114
|
+
|
|
115
|
+
## Instance methods
|
|
116
|
+
|
|
117
|
+
### `t.onDone(fn)`
|
|
118
|
+
`fn` will be called once and only once, when the queue is empty.
|
|
119
|
+
|
|
120
|
+
## Instance methods mixed in from `Array`
|
|
121
|
+
Mozilla has docs on how these methods work [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).
|
|
122
|
+
### `t.push(element1, ..., elementN)`
|
|
123
|
+
### `t.unshift(element1, ..., elementN)`
|
|
124
|
+
### `t.splice(index , howMany[, element1[, ...[, elementN]]])`
|
|
125
|
+
|
|
126
|
+
## Properties
|
|
127
|
+
### `t.concurrency`
|
|
128
|
+
Max number of jobs the queue should process concurrently, defaults to `Infinity`.
|
|
129
|
+
|
|
130
|
+
### `t.length`
|
|
131
|
+
Jobs pending + jobs to process (readonly).
|
|
132
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Dineshkumar Pandiyan <flexdinesh@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Browser or Node.js
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/flexdinesh/browser-or-node)
|
|
4
|
+
[](https://www.npmjs.com/package/browser-or-node)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
Check whether the code is running in the browser or node.js runtime.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
$ npm install --save browser-or-node
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
ES6 style import
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import { isBrowser, isNode, isWebWorker, isJsDom } from "browser-or-node";
|
|
21
|
+
|
|
22
|
+
if (isBrowser) {
|
|
23
|
+
// do browser only stuff
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (isNode) {
|
|
27
|
+
// do node.js only stuff
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (isWebWorker) {
|
|
31
|
+
// do web worker only stuff
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (isJsDom) {
|
|
35
|
+
// do jsdom only stuff
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
ES5 style import
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
var jsEnv = require("browser-or-node");
|
|
43
|
+
|
|
44
|
+
if (jsEnv.isBrowser) {
|
|
45
|
+
// do browser only stuff
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (jsEnv.isNode) {
|
|
49
|
+
// do node.js only stuff
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (jsEnv.isWebWorker) {
|
|
53
|
+
// do web worker only stuff
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (jsEnv.isJsDom) {
|
|
57
|
+
// do jsdom only stuff
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## License
|
|
62
|
+
|
|
63
|
+
MIT © Dineshkumar Pandiyan
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
|
8
|
+
|
|
9
|
+
/* global window self */
|
|
10
|
+
|
|
11
|
+
var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
12
|
+
|
|
13
|
+
/* eslint-disable no-restricted-globals */
|
|
14
|
+
var isWebWorker = (typeof self === 'undefined' ? 'undefined' : _typeof(self)) === 'object' && self.constructor && self.constructor.name === 'DedicatedWorkerGlobalScope';
|
|
15
|
+
/* eslint-enable no-restricted-globals */
|
|
16
|
+
|
|
17
|
+
var isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @see https://github.com/jsdom/jsdom/releases/tag/12.0.0
|
|
21
|
+
* @see https://github.com/jsdom/jsdom/issues/1537
|
|
22
|
+
*/
|
|
23
|
+
/* eslint-disable no-undef */
|
|
24
|
+
var isJsDom = function isJsDom() {
|
|
25
|
+
return typeof window !== 'undefined' && window.name === 'nodejs' || navigator.userAgent.includes('Node.js') || navigator.userAgent.includes('jsdom');
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
exports.isBrowser = isBrowser;
|
|
29
|
+
exports.isWebWorker = isWebWorker;
|
|
30
|
+
exports.isNode = isNode;
|
|
31
|
+
exports.isJsDom = isJsDom;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "browser-or-node",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "Check where the code is running in the browser or node.js",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"clean": "rimraf lib",
|
|
8
|
+
"test": "npm run cover",
|
|
9
|
+
"test:only": "cross-env BABEL_ENV=commonjs mocha --require babel-core/register --recursive",
|
|
10
|
+
"test:watch": "npm test -- --watch",
|
|
11
|
+
"test:examples": "node examples/",
|
|
12
|
+
"cover": "cross-env BABEL_ENV=commonjs istanbul cover node_modules/mocha/bin/_mocha -- --require babel-core/register --recursive",
|
|
13
|
+
"lint": "eslint src",
|
|
14
|
+
"build": "cross-env BABEL_ENV=commonjs babel src --out-dir lib",
|
|
15
|
+
"prepublish": "npm run clean && npm run lint && npm run test && npm run build"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"lib",
|
|
19
|
+
"src"
|
|
20
|
+
],
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/flexdinesh/browser-or-node.git"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"npm",
|
|
27
|
+
"browser",
|
|
28
|
+
"node",
|
|
29
|
+
"is browser",
|
|
30
|
+
"is node",
|
|
31
|
+
"is browser node"
|
|
32
|
+
],
|
|
33
|
+
"author": "Dineshkumar Pandiyan <flexdinesh@gmail.com>",
|
|
34
|
+
"contributors": [
|
|
35
|
+
"Daniel Wang <daniel.liberated@gmail.com> (https://github.com/dan1wang/)"
|
|
36
|
+
],
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/flexdinesh/browser-or-node/issues"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/flexdinesh/browser-or-node#readme",
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"babel": "^6.23.0",
|
|
44
|
+
"babel-cli": "^6.26.0",
|
|
45
|
+
"babel-eslint": "^10.1.0",
|
|
46
|
+
"babel-plugin-add-module-exports": "^1.0.2",
|
|
47
|
+
"babel-preset-es2015": "^6.24.1",
|
|
48
|
+
"babel-preset-stage-2": "^6.24.1",
|
|
49
|
+
"chai": "^4.2.0",
|
|
50
|
+
"cross-env": "^7.0.2",
|
|
51
|
+
"eslint": "^7.3.1",
|
|
52
|
+
"eslint-config-airbnb": "^18.2.0",
|
|
53
|
+
"eslint-plugin-import": "^2.21.2",
|
|
54
|
+
"eslint-plugin-jsx-a11y": "^6.3.1",
|
|
55
|
+
"eslint-plugin-react": "^7.20.0",
|
|
56
|
+
"istanbul": "^1.0.0-alpha",
|
|
57
|
+
"mocha": "^8.0.1",
|
|
58
|
+
"rimraf": "^3.0.2"
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
,"_resolved": "https://registry.npmjs.org/browser-or-node/-/browser-or-node-1.3.0.tgz"
|
|
62
|
+
,"_integrity": "sha512-0F2z/VSnLbmEeBcUrSuDH5l0HxTXdQQzLjkmBR4cYfvg1zJrKSlmIZFqyFR8oX0NrwPhy3c3HQ6i3OxMbew4Tg=="
|
|
63
|
+
,"_from": "browser-or-node@1.3.0"
|
|
64
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* global window self */
|
|
2
|
+
|
|
3
|
+
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
4
|
+
|
|
5
|
+
/* eslint-disable no-restricted-globals */
|
|
6
|
+
const isWebWorker = typeof self === 'object'
|
|
7
|
+
&& self.constructor
|
|
8
|
+
&& self.constructor.name === 'DedicatedWorkerGlobalScope';
|
|
9
|
+
/* eslint-enable no-restricted-globals */
|
|
10
|
+
|
|
11
|
+
const isNode = typeof process !== 'undefined'
|
|
12
|
+
&& process.versions != null
|
|
13
|
+
&& process.versions.node != null;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @see https://github.com/jsdom/jsdom/releases/tag/12.0.0
|
|
17
|
+
* @see https://github.com/jsdom/jsdom/issues/1537
|
|
18
|
+
*/
|
|
19
|
+
/* eslint-disable no-undef */
|
|
20
|
+
const isJsDom = () => (typeof window !== 'undefined' && window.name === 'nodejs')
|
|
21
|
+
|| navigator.userAgent.includes('Node.js')
|
|
22
|
+
|| navigator.userAgent.includes('jsdom');
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
isBrowser, isWebWorker, isNode, isJsDom
|
|
26
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Zejin Zhuang <heineiuo@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# isomorphic-ws
|
|
2
|
+
|
|
3
|
+
Isomorphic implementation of WebSocket.
|
|
4
|
+
|
|
5
|
+
It uses:
|
|
6
|
+
- [ws](https://github.com/websockets/ws) on Node
|
|
7
|
+
- [global.WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) in browsers
|
|
8
|
+
|
|
9
|
+
## Limitations
|
|
10
|
+
|
|
11
|
+
Before using this module you should know that
|
|
12
|
+
[`ws`](https://github.com/websockets/ws/blob/master/doc/ws.md#class-websocket)
|
|
13
|
+
is not perfectly API compatible with
|
|
14
|
+
[WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket),
|
|
15
|
+
you should always test your code against both Node and browsers.
|
|
16
|
+
|
|
17
|
+
Some major differences:
|
|
18
|
+
|
|
19
|
+
- no `Server` implementation in browsers
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
You need to install both this package and [ws](https://github.com/websockets/ws):
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
> npm i isomorphic-ws ws
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Then just require this package:
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
const WebSocket = require('isomorphic-ws')
|
|
33
|
+
|
|
34
|
+
const ws = new WebSocket('wss://echo.websocket.org/', {
|
|
35
|
+
origin: 'https://websocket.org'
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
ws.onopen = function open() {
|
|
39
|
+
console.log('connected');
|
|
40
|
+
ws.send(Date.now());
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
ws.onclose = function close() {
|
|
44
|
+
console.log('disconnected');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
ws.onmessage = function incoming(data) {
|
|
48
|
+
console.log(`Roundtrip time: ${Date.now() - data} ms`);
|
|
49
|
+
|
|
50
|
+
setTimeout(function timeout() {
|
|
51
|
+
ws.send(Date.now());
|
|
52
|
+
}, 500);
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// https://github.com/maxogden/websocket-stream/blob/48dc3ddf943e5ada668c31ccd94e9186f02fafbd/ws-fallback.js
|
|
2
|
+
|
|
3
|
+
var ws = null
|
|
4
|
+
|
|
5
|
+
if (typeof WebSocket !== 'undefined') {
|
|
6
|
+
ws = WebSocket
|
|
7
|
+
} else if (typeof MozWebSocket !== 'undefined') {
|
|
8
|
+
ws = MozWebSocket
|
|
9
|
+
} else if (typeof global !== 'undefined') {
|
|
10
|
+
ws = global.WebSocket || global.MozWebSocket
|
|
11
|
+
} else if (typeof window !== 'undefined') {
|
|
12
|
+
ws = window.WebSocket || window.MozWebSocket
|
|
13
|
+
} else if (typeof self !== 'undefined') {
|
|
14
|
+
ws = self.WebSocket || self.MozWebSocket
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = ws
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Type definitions for isomorphic-ws
|
|
2
|
+
// Run `npm install @types/ws` before using this.
|
|
3
|
+
// Fix for https://github.com/heineiuo/isomorphic-ws/issues/8
|
|
4
|
+
// If there is still something wrong, welcome issue.
|
|
5
|
+
|
|
6
|
+
import WebSocket = require('ws')
|
|
7
|
+
|
|
8
|
+
export = WebSocket
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "isomorphic-ws",
|
|
3
|
+
"version": "4.0.1",
|
|
4
|
+
"description": "Isomorphic implementation of WebSocket",
|
|
5
|
+
"main": "node.js",
|
|
6
|
+
"browser": "browser.js",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/heineiuo/isomorphic-ws.git"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"browser",
|
|
13
|
+
"browsers",
|
|
14
|
+
"isomorphic",
|
|
15
|
+
"node",
|
|
16
|
+
"websocket",
|
|
17
|
+
"ws"
|
|
18
|
+
],
|
|
19
|
+
"author": "@heineiuo",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/heineiuo/isomorphic-ws/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/heineiuo/isomorphic-ws#readme",
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"ws": "*"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"index.d.ts",
|
|
30
|
+
"node.js",
|
|
31
|
+
"browser.js",
|
|
32
|
+
"README.md"
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
,"_resolved": "https://registry.npmjs.org/isomorphic-ws/-/isomorphic-ws-4.0.1.tgz"
|
|
36
|
+
,"_integrity": "sha512-BhBvN2MBpWTaSHdWRb/bwdZJ1WaehQ2L1KngkCkfLUGF0mAWAT1sQUQacEmQ0jXkFw/czDXPNQSL5u2/Krsz1w=="
|
|
37
|
+
,"_from": "isomorphic-ws@4.0.1"
|
|
38
|
+
}
|