@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.
Files changed (105) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/dist/DBSQLClient.d.ts +1 -1
  3. package/dist/DBSQLClient.js +18 -4
  4. package/dist/DBSQLClient.js.map +1 -1
  5. package/dist/DBSQLOperation/SchemaHelper.d.ts +4 -1
  6. package/dist/DBSQLOperation/SchemaHelper.js +25 -4
  7. package/dist/DBSQLOperation/SchemaHelper.js.map +1 -1
  8. package/dist/DBSQLOperation/index.js +2 -3
  9. package/dist/DBSQLOperation/index.js.map +1 -1
  10. package/dist/connection/connections/HttpConnection.js +2 -2
  11. package/dist/connection/connections/HttpConnection.js.map +1 -1
  12. package/dist/index.d.ts +3 -0
  13. package/dist/index.js +8 -1
  14. package/dist/index.js.map +1 -1
  15. package/dist/result/IOperationResult.d.ts +2 -1
  16. package/dist/result/JsonResult.d.ts +3 -5
  17. package/dist/result/JsonResult.js +6 -11
  18. package/dist/result/JsonResult.js.map +1 -1
  19. package/dist/utils/buildUserAgentString.js +2 -7
  20. package/dist/utils/buildUserAgentString.js.map +1 -1
  21. package/dist/version.d.ts +2 -0
  22. package/dist/version.js +4 -0
  23. package/dist/version.js.map +1 -0
  24. package/node_modules/async-limiter/.eslintignore +2 -0
  25. package/node_modules/async-limiter/.nycrc +10 -0
  26. package/node_modules/async-limiter/.travis.yml +9 -0
  27. package/node_modules/async-limiter/LICENSE +8 -0
  28. package/node_modules/async-limiter/index.js +67 -0
  29. package/node_modules/async-limiter/package.json +39 -0
  30. package/node_modules/async-limiter/readme.md +132 -0
  31. package/node_modules/browser-or-node/LICENSE +21 -0
  32. package/node_modules/browser-or-node/README.md +63 -0
  33. package/node_modules/browser-or-node/lib/index.js +31 -0
  34. package/node_modules/browser-or-node/package.json +64 -0
  35. package/node_modules/browser-or-node/src/index.js +26 -0
  36. package/node_modules/isomorphic-ws/LICENSE +21 -0
  37. package/node_modules/isomorphic-ws/README.md +58 -0
  38. package/node_modules/isomorphic-ws/browser.js +17 -0
  39. package/node_modules/isomorphic-ws/index.d.ts +8 -0
  40. package/node_modules/isomorphic-ws/node.js +3 -0
  41. package/node_modules/isomorphic-ws/package.json +38 -0
  42. package/node_modules/node-int64/.npmignore +3 -0
  43. package/node_modules/node-int64/Int64.js +268 -0
  44. package/node_modules/node-int64/LICENSE +19 -0
  45. package/node_modules/node-int64/README.md +78 -0
  46. package/node_modules/node-int64/package.json +31 -0
  47. package/node_modules/node-int64/test.js +120 -0
  48. package/node_modules/q/CHANGES.md +800 -0
  49. package/node_modules/q/LICENSE +18 -0
  50. package/node_modules/q/README.md +874 -0
  51. package/node_modules/q/package.json +80 -0
  52. package/node_modules/q/q.js +2076 -0
  53. package/node_modules/q/queue.js +35 -0
  54. package/node_modules/thrift/LICENSE +306 -0
  55. package/node_modules/thrift/README.md +210 -0
  56. package/node_modules/thrift/lib/nodejs/README.md +142 -0
  57. package/node_modules/thrift/lib/nodejs/lib/thrift/binary.js +168 -0
  58. package/node_modules/thrift/lib/nodejs/lib/thrift/binary_protocol.js +367 -0
  59. package/node_modules/thrift/lib/nodejs/lib/thrift/browser.js +49 -0
  60. package/node_modules/thrift/lib/nodejs/lib/thrift/buffered_transport.js +186 -0
  61. package/node_modules/thrift/lib/nodejs/lib/thrift/compact_protocol.js +915 -0
  62. package/node_modules/thrift/lib/nodejs/lib/thrift/connection.js +396 -0
  63. package/node_modules/thrift/lib/nodejs/lib/thrift/create_client.js +54 -0
  64. package/node_modules/thrift/lib/nodejs/lib/thrift/framed_transport.js +185 -0
  65. package/node_modules/thrift/lib/nodejs/lib/thrift/header_protocol.js +258 -0
  66. package/node_modules/thrift/lib/nodejs/lib/thrift/header_transport.js +341 -0
  67. package/node_modules/thrift/lib/nodejs/lib/thrift/http_connection.js +282 -0
  68. package/node_modules/thrift/lib/nodejs/lib/thrift/index.js +76 -0
  69. package/node_modules/thrift/lib/nodejs/lib/thrift/input_buffer_underrun_error.js +32 -0
  70. package/node_modules/thrift/lib/nodejs/lib/thrift/int64_util.js +91 -0
  71. package/node_modules/thrift/lib/nodejs/lib/thrift/json_parse.js +299 -0
  72. package/node_modules/thrift/lib/nodejs/lib/thrift/json_protocol.js +799 -0
  73. package/node_modules/thrift/lib/nodejs/lib/thrift/log.js +87 -0
  74. package/node_modules/thrift/lib/nodejs/lib/thrift/multiplexed_processor.js +63 -0
  75. package/node_modules/thrift/lib/nodejs/lib/thrift/multiplexed_protocol.js +73 -0
  76. package/node_modules/thrift/lib/nodejs/lib/thrift/protocol.js +22 -0
  77. package/node_modules/thrift/lib/nodejs/lib/thrift/server.js +123 -0
  78. package/node_modules/thrift/lib/nodejs/lib/thrift/thrift.js +241 -0
  79. package/node_modules/thrift/lib/nodejs/lib/thrift/transport.js +22 -0
  80. package/node_modules/thrift/lib/nodejs/lib/thrift/web_server.js +567 -0
  81. package/node_modules/thrift/lib/nodejs/lib/thrift/ws_connection.js +286 -0
  82. package/node_modules/thrift/lib/nodejs/lib/thrift/ws_transport.js +206 -0
  83. package/node_modules/thrift/lib/nodejs/lib/thrift/xhr_connection.js +280 -0
  84. package/node_modules/thrift/package.json +76 -0
  85. package/node_modules/ws/LICENSE +21 -0
  86. package/node_modules/ws/README.md +417 -0
  87. package/node_modules/ws/index.js +9 -0
  88. package/node_modules/ws/lib/buffer-util.js +72 -0
  89. package/node_modules/ws/lib/constants.js +10 -0
  90. package/node_modules/ws/lib/event-target.js +170 -0
  91. package/node_modules/ws/lib/extension.js +211 -0
  92. package/node_modules/ws/lib/permessage-deflate.js +516 -0
  93. package/node_modules/ws/lib/receiver.js +513 -0
  94. package/node_modules/ws/lib/sender.js +401 -0
  95. package/node_modules/ws/lib/validation.js +29 -0
  96. package/node_modules/ws/lib/websocket-server.js +369 -0
  97. package/node_modules/ws/lib/websocket.js +828 -0
  98. package/node_modules/ws/package.json +48 -0
  99. package/package.json +9 -3
  100. package/dist/DBSQLOperation/getResult.d.ts +0 -2
  101. package/dist/DBSQLOperation/getResult.js +0 -19
  102. package/dist/DBSQLOperation/getResult.js.map +0 -1
  103. package/dist/result/NullResult.d.ts +0 -4
  104. package/dist/result/NullResult.js +0 -9
  105. package/dist/result/NullResult.js.map +0 -1
@@ -0,0 +1,369 @@
1
+ 'use strict';
2
+
3
+ const EventEmitter = require('events');
4
+ const crypto = require('crypto');
5
+ const http = require('http');
6
+ const url = require('url');
7
+
8
+ const PerMessageDeflate = require('./permessage-deflate');
9
+ const extension = require('./extension');
10
+ const constants = require('./constants');
11
+ const WebSocket = require('./websocket');
12
+
13
+ /**
14
+ * Class representing a WebSocket server.
15
+ *
16
+ * @extends EventEmitter
17
+ */
18
+ class WebSocketServer extends EventEmitter {
19
+ /**
20
+ * Create a `WebSocketServer` instance.
21
+ *
22
+ * @param {Object} options Configuration options
23
+ * @param {String} options.host The hostname where to bind the server
24
+ * @param {Number} options.port The port where to bind the server
25
+ * @param {http.Server} options.server A pre-created HTTP/S server to use
26
+ * @param {Function} options.verifyClient An hook to reject connections
27
+ * @param {Function} options.handleProtocols An hook to handle protocols
28
+ * @param {String} options.path Accept only connections matching this path
29
+ * @param {Boolean} options.noServer Enable no server mode
30
+ * @param {Boolean} options.clientTracking Specifies whether or not to track clients
31
+ * @param {(Boolean|Object)} options.perMessageDeflate Enable/disable permessage-deflate
32
+ * @param {Number} options.maxPayload The maximum allowed message size
33
+ * @param {Function} callback A listener for the `listening` event
34
+ */
35
+ constructor (options, callback) {
36
+ super();
37
+
38
+ options = Object.assign({
39
+ maxPayload: 100 * 1024 * 1024,
40
+ perMessageDeflate: false,
41
+ handleProtocols: null,
42
+ clientTracking: true,
43
+ verifyClient: null,
44
+ noServer: false,
45
+ backlog: null, // use default (511 as implemented in net.js)
46
+ server: null,
47
+ host: null,
48
+ path: null,
49
+ port: null
50
+ }, options);
51
+
52
+ if (options.port == null && !options.server && !options.noServer) {
53
+ throw new TypeError(
54
+ 'One of the "port", "server", or "noServer" options must be specified'
55
+ );
56
+ }
57
+
58
+ if (options.port != null) {
59
+ this._server = http.createServer((req, res) => {
60
+ const body = http.STATUS_CODES[426];
61
+
62
+ res.writeHead(426, {
63
+ 'Content-Length': body.length,
64
+ 'Content-Type': 'text/plain'
65
+ });
66
+ res.end(body);
67
+ });
68
+ this._server.listen(options.port, options.host, options.backlog, callback);
69
+ } else if (options.server) {
70
+ this._server = options.server;
71
+ }
72
+
73
+ if (this._server) {
74
+ this._removeListeners = addListeners(this._server, {
75
+ listening: this.emit.bind(this, 'listening'),
76
+ error: this.emit.bind(this, 'error'),
77
+ upgrade: (req, socket, head) => {
78
+ this.handleUpgrade(req, socket, head, (ws) => {
79
+ this.emit('connection', ws, req);
80
+ });
81
+ }
82
+ });
83
+ }
84
+
85
+ if (options.perMessageDeflate === true) options.perMessageDeflate = {};
86
+ if (options.clientTracking) this.clients = new Set();
87
+ this.options = options;
88
+ }
89
+
90
+ /**
91
+ * Returns the bound address, the address family name, and port of the server
92
+ * as reported by the operating system if listening on an IP socket.
93
+ * If the server is listening on a pipe or UNIX domain socket, the name is
94
+ * returned as a string.
95
+ *
96
+ * @return {(Object|String|null)} The address of the server
97
+ * @public
98
+ */
99
+ address () {
100
+ if (this.options.noServer) {
101
+ throw new Error('The server is operating in "noServer" mode');
102
+ }
103
+
104
+ if (!this._server) return null;
105
+ return this._server.address();
106
+ }
107
+
108
+ /**
109
+ * Close the server.
110
+ *
111
+ * @param {Function} cb Callback
112
+ * @public
113
+ */
114
+ close (cb) {
115
+ //
116
+ // Terminate all associated clients.
117
+ //
118
+ if (this.clients) {
119
+ for (const client of this.clients) client.terminate();
120
+ }
121
+
122
+ const server = this._server;
123
+
124
+ if (server) {
125
+ this._removeListeners();
126
+ this._removeListeners = this._server = null;
127
+
128
+ //
129
+ // Close the http server if it was internally created.
130
+ //
131
+ if (this.options.port != null) return server.close(cb);
132
+ }
133
+
134
+ if (cb) cb();
135
+ }
136
+
137
+ /**
138
+ * See if a given request should be handled by this server instance.
139
+ *
140
+ * @param {http.IncomingMessage} req Request object to inspect
141
+ * @return {Boolean} `true` if the request is valid, else `false`
142
+ * @public
143
+ */
144
+ shouldHandle (req) {
145
+ if (this.options.path && url.parse(req.url).pathname !== this.options.path) {
146
+ return false;
147
+ }
148
+
149
+ return true;
150
+ }
151
+
152
+ /**
153
+ * Handle a HTTP Upgrade request.
154
+ *
155
+ * @param {http.IncomingMessage} req The request object
156
+ * @param {net.Socket} socket The network socket between the server and client
157
+ * @param {Buffer} head The first packet of the upgraded stream
158
+ * @param {Function} cb Callback
159
+ * @public
160
+ */
161
+ handleUpgrade (req, socket, head, cb) {
162
+ socket.on('error', socketOnError);
163
+
164
+ const version = +req.headers['sec-websocket-version'];
165
+ const extensions = {};
166
+
167
+ if (
168
+ req.method !== 'GET' || req.headers.upgrade.toLowerCase() !== 'websocket' ||
169
+ !req.headers['sec-websocket-key'] || (version !== 8 && version !== 13) ||
170
+ !this.shouldHandle(req)
171
+ ) {
172
+ return abortHandshake(socket, 400);
173
+ }
174
+
175
+ if (this.options.perMessageDeflate) {
176
+ const perMessageDeflate = new PerMessageDeflate(
177
+ this.options.perMessageDeflate,
178
+ true,
179
+ this.options.maxPayload
180
+ );
181
+
182
+ try {
183
+ const offers = extension.parse(
184
+ req.headers['sec-websocket-extensions']
185
+ );
186
+
187
+ if (offers[PerMessageDeflate.extensionName]) {
188
+ perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
189
+ extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
190
+ }
191
+ } catch (err) {
192
+ return abortHandshake(socket, 400);
193
+ }
194
+ }
195
+
196
+ //
197
+ // Optionally call external client verification handler.
198
+ //
199
+ if (this.options.verifyClient) {
200
+ const info = {
201
+ origin: req.headers[`${version === 8 ? 'sec-websocket-origin' : 'origin'}`],
202
+ secure: !!(req.connection.authorized || req.connection.encrypted),
203
+ req
204
+ };
205
+
206
+ if (this.options.verifyClient.length === 2) {
207
+ this.options.verifyClient(info, (verified, code, message, headers) => {
208
+ if (!verified) {
209
+ return abortHandshake(socket, code || 401, message, headers);
210
+ }
211
+
212
+ this.completeUpgrade(extensions, req, socket, head, cb);
213
+ });
214
+ return;
215
+ }
216
+
217
+ if (!this.options.verifyClient(info)) return abortHandshake(socket, 401);
218
+ }
219
+
220
+ this.completeUpgrade(extensions, req, socket, head, cb);
221
+ }
222
+
223
+ /**
224
+ * Upgrade the connection to WebSocket.
225
+ *
226
+ * @param {Object} extensions The accepted extensions
227
+ * @param {http.IncomingMessage} req The request object
228
+ * @param {net.Socket} socket The network socket between the server and client
229
+ * @param {Buffer} head The first packet of the upgraded stream
230
+ * @param {Function} cb Callback
231
+ * @private
232
+ */
233
+ completeUpgrade (extensions, req, socket, head, cb) {
234
+ //
235
+ // Destroy the socket if the client has already sent a FIN packet.
236
+ //
237
+ if (!socket.readable || !socket.writable) return socket.destroy();
238
+
239
+ const key = crypto.createHash('sha1')
240
+ .update(req.headers['sec-websocket-key'] + constants.GUID, 'binary')
241
+ .digest('base64');
242
+
243
+ const headers = [
244
+ 'HTTP/1.1 101 Switching Protocols',
245
+ 'Upgrade: websocket',
246
+ 'Connection: Upgrade',
247
+ `Sec-WebSocket-Accept: ${key}`
248
+ ];
249
+
250
+ const ws = new WebSocket(null);
251
+ var protocol = req.headers['sec-websocket-protocol'];
252
+
253
+ if (protocol) {
254
+ protocol = protocol.split(',').map(trim);
255
+
256
+ //
257
+ // Optionally call external protocol selection handler.
258
+ //
259
+ if (this.options.handleProtocols) {
260
+ protocol = this.options.handleProtocols(protocol, req);
261
+ } else {
262
+ protocol = protocol[0];
263
+ }
264
+
265
+ if (protocol) {
266
+ headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
267
+ ws.protocol = protocol;
268
+ }
269
+ }
270
+
271
+ if (extensions[PerMessageDeflate.extensionName]) {
272
+ const params = extensions[PerMessageDeflate.extensionName].params;
273
+ const value = extension.format({
274
+ [PerMessageDeflate.extensionName]: [params]
275
+ });
276
+ headers.push(`Sec-WebSocket-Extensions: ${value}`);
277
+ ws._extensions = extensions;
278
+ }
279
+
280
+ //
281
+ // Allow external modification/inspection of handshake headers.
282
+ //
283
+ this.emit('headers', headers, req);
284
+
285
+ socket.write(headers.concat('\r\n').join('\r\n'));
286
+ socket.removeListener('error', socketOnError);
287
+
288
+ ws.setSocket(socket, head, this.options.maxPayload);
289
+
290
+ if (this.clients) {
291
+ this.clients.add(ws);
292
+ ws.on('close', () => this.clients.delete(ws));
293
+ }
294
+
295
+ cb(ws);
296
+ }
297
+ }
298
+
299
+ module.exports = WebSocketServer;
300
+
301
+ /**
302
+ * Add event listeners on an `EventEmitter` using a map of <event, listener>
303
+ * pairs.
304
+ *
305
+ * @param {EventEmitter} server The event emitter
306
+ * @param {Object.<String, Function>} map The listeners to add
307
+ * @return {Function} A function that will remove the added listeners when called
308
+ * @private
309
+ */
310
+ function addListeners (server, map) {
311
+ for (const event of Object.keys(map)) server.on(event, map[event]);
312
+
313
+ return function removeListeners () {
314
+ for (const event of Object.keys(map)) {
315
+ server.removeListener(event, map[event]);
316
+ }
317
+ };
318
+ }
319
+
320
+ /**
321
+ * Handle premature socket errors.
322
+ *
323
+ * @private
324
+ */
325
+ function socketOnError () {
326
+ this.destroy();
327
+ }
328
+
329
+ /**
330
+ * Close the connection when preconditions are not fulfilled.
331
+ *
332
+ * @param {net.Socket} socket The socket of the upgrade request
333
+ * @param {Number} code The HTTP response status code
334
+ * @param {String} [message] The HTTP response body
335
+ * @param {Object} [headers] Additional HTTP response headers
336
+ * @private
337
+ */
338
+ function abortHandshake (socket, code, message, headers) {
339
+ if (socket.writable) {
340
+ message = message || http.STATUS_CODES[code];
341
+ headers = Object.assign({
342
+ 'Connection': 'close',
343
+ 'Content-type': 'text/html',
344
+ 'Content-Length': Buffer.byteLength(message)
345
+ }, headers);
346
+
347
+ socket.write(
348
+ `HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r\n` +
349
+ Object.keys(headers).map(h => `${h}: ${headers[h]}`).join('\r\n') +
350
+ '\r\n\r\n' +
351
+ message
352
+ );
353
+ }
354
+
355
+ socket.removeListener('error', socketOnError);
356
+ socket.destroy();
357
+ }
358
+
359
+ /**
360
+ * Remove whitespace characters from both ends of a string.
361
+ *
362
+ * @param {String} str The string
363
+ * @return {String} A new string representing `str` stripped of whitespace
364
+ * characters from both its beginning and end
365
+ * @private
366
+ */
367
+ function trim(str) {
368
+ return str.trim();
369
+ }