@databricks/sql 1.2.0 → 1.3.0

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 (174) hide show
  1. package/README.md +2 -2
  2. package/dist/DBSQLClient.d.ts +9 -9
  3. package/dist/DBSQLClient.js +94 -63
  4. package/dist/DBSQLClient.js.map +1 -1
  5. package/dist/DBSQLOperation/CompleteOperationHelper.d.ts +3 -3
  6. package/dist/DBSQLOperation/CompleteOperationHelper.js +12 -17
  7. package/dist/DBSQLOperation/CompleteOperationHelper.js.map +1 -1
  8. package/dist/DBSQLOperation/FetchResultsHelper.d.ts +4 -5
  9. package/dist/DBSQLOperation/FetchResultsHelper.js +16 -12
  10. package/dist/DBSQLOperation/FetchResultsHelper.js.map +1 -1
  11. package/dist/DBSQLOperation/OperationStatusHelper.d.ts +2 -3
  12. package/dist/DBSQLOperation/OperationStatusHelper.js +12 -12
  13. package/dist/DBSQLOperation/OperationStatusHelper.js.map +1 -1
  14. package/dist/DBSQLOperation/SchemaHelper.d.ts +2 -3
  15. package/dist/DBSQLOperation/SchemaHelper.js +2 -3
  16. package/dist/DBSQLOperation/SchemaHelper.js.map +1 -1
  17. package/dist/DBSQLOperation/index.d.ts +7 -7
  18. package/dist/DBSQLOperation/index.js +18 -11
  19. package/dist/DBSQLOperation/index.js.map +1 -1
  20. package/dist/DBSQLSession.d.ts +3 -5
  21. package/dist/DBSQLSession.js +63 -49
  22. package/dist/DBSQLSession.js.map +1 -1
  23. package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.d.ts +24 -0
  24. package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.js +165 -0
  25. package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.js.map +1 -0
  26. package/dist/connection/auth/DatabricksOAuth/OAuthManager.d.ts +47 -0
  27. package/dist/connection/auth/DatabricksOAuth/OAuthManager.js +169 -0
  28. package/dist/connection/auth/DatabricksOAuth/OAuthManager.js.map +1 -0
  29. package/dist/connection/auth/DatabricksOAuth/OAuthPersistence.d.ts +10 -0
  30. package/dist/connection/auth/DatabricksOAuth/OAuthPersistence.js +29 -0
  31. package/dist/connection/auth/DatabricksOAuth/OAuthPersistence.js.map +1 -0
  32. package/dist/connection/auth/DatabricksOAuth/OAuthScope.d.ts +7 -0
  33. package/dist/connection/auth/DatabricksOAuth/OAuthScope.js +11 -0
  34. package/dist/connection/auth/DatabricksOAuth/OAuthScope.js.map +1 -0
  35. package/dist/connection/auth/DatabricksOAuth/OAuthToken.d.ts +10 -0
  36. package/dist/connection/auth/DatabricksOAuth/OAuthToken.js +32 -0
  37. package/dist/connection/auth/DatabricksOAuth/OAuthToken.js.map +1 -0
  38. package/dist/connection/auth/DatabricksOAuth/index.d.ts +21 -0
  39. package/dist/connection/auth/DatabricksOAuth/index.js +41 -0
  40. package/dist/connection/auth/DatabricksOAuth/index.js.map +1 -0
  41. package/dist/connection/auth/PlainHttpAuthentication.d.ts +11 -11
  42. package/dist/connection/auth/PlainHttpAuthentication.js +15 -7
  43. package/dist/connection/auth/PlainHttpAuthentication.js.map +1 -1
  44. package/dist/connection/connections/HttpConnection.d.ts +1 -2
  45. package/dist/connection/connections/HttpConnection.js +24 -14
  46. package/dist/connection/connections/HttpConnection.js.map +1 -1
  47. package/dist/connection/contracts/IAuthentication.d.ts +2 -2
  48. package/dist/connection/contracts/IConnectionOptions.d.ts +3 -1
  49. package/dist/connection/contracts/IConnectionProvider.d.ts +1 -2
  50. package/dist/contracts/IDBSQLClient.d.ts +17 -3
  51. package/dist/dto/Status.d.ts +9 -13
  52. package/dist/dto/Status.js +31 -10
  53. package/dist/dto/Status.js.map +1 -1
  54. package/dist/globalConfig.d.ts +5 -0
  55. package/dist/globalConfig.js +5 -0
  56. package/dist/globalConfig.js.map +1 -1
  57. package/dist/hive/Commands/BaseCommand.d.ts +3 -1
  58. package/dist/hive/Commands/BaseCommand.js +66 -4
  59. package/dist/hive/Commands/BaseCommand.js.map +1 -1
  60. package/dist/hive/HiveDriver.d.ts +3 -2
  61. package/dist/hive/HiveDriver.js +116 -44
  62. package/dist/hive/HiveDriver.js.map +1 -1
  63. package/dist/index.d.ts +0 -2
  64. package/dist/index.js +0 -2
  65. package/dist/index.js.map +1 -1
  66. package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/http_connection.js +10 -0
  67. package/dist/result/ArrowResult.js +3 -0
  68. package/dist/result/ArrowResult.js.map +1 -1
  69. package/dist/result/JsonResult.js +3 -0
  70. package/dist/result/JsonResult.js.map +1 -1
  71. package/dist/utils/areHeadersEqual.d.ts +2 -0
  72. package/dist/utils/areHeadersEqual.js +49 -0
  73. package/dist/utils/areHeadersEqual.js.map +1 -0
  74. package/dist/utils/index.d.ts +2 -1
  75. package/dist/utils/index.js +3 -1
  76. package/dist/utils/index.js.map +1 -1
  77. package/dist/version.d.ts +1 -1
  78. package/dist/version.js +1 -1
  79. package/package.json +6 -6
  80. package/thrift/TCLIService.d.ts +17 -0
  81. package/thrift/TCLIService_types.d.ts +185 -13
  82. package/thrift/TCLIService_types.js +2013 -279
  83. package/dist/connection/auth/NoSaslAuthentication.d.ts +0 -5
  84. package/dist/connection/auth/NoSaslAuthentication.js +0 -15
  85. package/dist/connection/auth/NoSaslAuthentication.js.map +0 -1
  86. package/dist/connection/auth/helpers/SaslPackageFactory.d.ts +0 -11
  87. package/dist/connection/auth/helpers/SaslPackageFactory.js +0 -20
  88. package/dist/connection/auth/helpers/SaslPackageFactory.js.map +0 -1
  89. package/dist/connection/contracts/ITransport.d.ts +0 -13
  90. package/dist/connection/contracts/ITransport.js +0 -3
  91. package/dist/connection/contracts/ITransport.js.map +0 -1
  92. package/dist/connection/transports/HttpTransport.d.ts +0 -14
  93. package/dist/connection/transports/HttpTransport.js +0 -24
  94. package/dist/connection/transports/HttpTransport.js.map +0 -1
  95. package/dist/connection/types/AuthOptions.d.ts +0 -4
  96. package/dist/connection/types/AuthOptions.js +0 -3
  97. package/dist/connection/types/AuthOptions.js.map +0 -1
  98. package/dist/factory/StatusFactory.d.ts +0 -12
  99. package/dist/factory/StatusFactory.js +0 -35
  100. package/dist/factory/StatusFactory.js.map +0 -1
  101. package/node_modules/async-limiter/.eslintignore +0 -2
  102. package/node_modules/async-limiter/.nycrc +0 -10
  103. package/node_modules/async-limiter/.travis.yml +0 -9
  104. package/node_modules/async-limiter/LICENSE +0 -8
  105. package/node_modules/async-limiter/index.js +0 -67
  106. package/node_modules/async-limiter/package.json +0 -35
  107. package/node_modules/async-limiter/readme.md +0 -132
  108. package/node_modules/browser-or-node/LICENSE +0 -21
  109. package/node_modules/browser-or-node/README.md +0 -63
  110. package/node_modules/browser-or-node/lib/index.js +0 -31
  111. package/node_modules/browser-or-node/package.json +0 -60
  112. package/node_modules/browser-or-node/src/index.js +0 -26
  113. package/node_modules/isomorphic-ws/LICENSE +0 -21
  114. package/node_modules/isomorphic-ws/README.md +0 -58
  115. package/node_modules/isomorphic-ws/browser.js +0 -17
  116. package/node_modules/isomorphic-ws/index.d.ts +0 -8
  117. package/node_modules/isomorphic-ws/node.js +0 -3
  118. package/node_modules/isomorphic-ws/package.json +0 -34
  119. package/node_modules/node-int64/.npmignore +0 -3
  120. package/node_modules/node-int64/Int64.js +0 -268
  121. package/node_modules/node-int64/LICENSE +0 -19
  122. package/node_modules/node-int64/README.md +0 -78
  123. package/node_modules/node-int64/package.json +0 -27
  124. package/node_modules/node-int64/test.js +0 -120
  125. package/node_modules/q/CHANGES.md +0 -800
  126. package/node_modules/q/LICENSE +0 -18
  127. package/node_modules/q/README.md +0 -874
  128. package/node_modules/q/package.json +0 -76
  129. package/node_modules/q/q.js +0 -2076
  130. package/node_modules/q/queue.js +0 -35
  131. package/node_modules/ws/LICENSE +0 -21
  132. package/node_modules/ws/README.md +0 -417
  133. package/node_modules/ws/index.js +0 -9
  134. package/node_modules/ws/lib/buffer-util.js +0 -72
  135. package/node_modules/ws/lib/constants.js +0 -10
  136. package/node_modules/ws/lib/event-target.js +0 -170
  137. package/node_modules/ws/lib/extension.js +0 -211
  138. package/node_modules/ws/lib/permessage-deflate.js +0 -516
  139. package/node_modules/ws/lib/receiver.js +0 -513
  140. package/node_modules/ws/lib/sender.js +0 -401
  141. package/node_modules/ws/lib/validation.js +0 -29
  142. package/node_modules/ws/lib/websocket-server.js +0 -369
  143. package/node_modules/ws/lib/websocket.js +0 -828
  144. package/node_modules/ws/package.json +0 -44
  145. /package/{node_modules → dist/node_modules}/thrift/LICENSE +0 -0
  146. /package/{node_modules → dist/node_modules}/thrift/README.md +0 -0
  147. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/README.md +0 -0
  148. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/binary.js +0 -0
  149. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/binary_protocol.js +0 -0
  150. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/browser.js +0 -0
  151. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/buffered_transport.js +0 -0
  152. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/compact_protocol.js +0 -0
  153. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/connection.js +0 -0
  154. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/create_client.js +0 -0
  155. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/framed_transport.js +0 -0
  156. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/header_protocol.js +0 -0
  157. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/header_transport.js +0 -0
  158. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/index.js +0 -0
  159. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/input_buffer_underrun_error.js +0 -0
  160. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/int64_util.js +0 -0
  161. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/json_parse.js +0 -0
  162. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/json_protocol.js +0 -0
  163. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/log.js +0 -0
  164. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/multiplexed_processor.js +0 -0
  165. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/multiplexed_protocol.js +0 -0
  166. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/protocol.js +0 -0
  167. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/server.js +0 -0
  168. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/thrift.js +0 -0
  169. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/transport.js +0 -0
  170. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/web_server.js +0 -0
  171. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/ws_connection.js +0 -0
  172. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/ws_transport.js +0 -0
  173. /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/xhr_connection.js +0 -0
  174. /package/{node_modules → dist/node_modules}/thrift/package.json +0 -0
@@ -1,170 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * Class representing an event.
5
- *
6
- * @private
7
- */
8
- class Event {
9
- /**
10
- * Create a new `Event`.
11
- *
12
- * @param {String} type The name of the event
13
- * @param {Object} target A reference to the target to which the event was dispatched
14
- */
15
- constructor (type, target) {
16
- this.target = target;
17
- this.type = type;
18
- }
19
- }
20
-
21
- /**
22
- * Class representing a message event.
23
- *
24
- * @extends Event
25
- * @private
26
- */
27
- class MessageEvent extends Event {
28
- /**
29
- * Create a new `MessageEvent`.
30
- *
31
- * @param {(String|Buffer|ArrayBuffer|Buffer[])} data The received data
32
- * @param {WebSocket} target A reference to the target to which the event was dispatched
33
- */
34
- constructor (data, target) {
35
- super('message', target);
36
-
37
- this.data = data;
38
- }
39
- }
40
-
41
- /**
42
- * Class representing a close event.
43
- *
44
- * @extends Event
45
- * @private
46
- */
47
- class CloseEvent extends Event {
48
- /**
49
- * Create a new `CloseEvent`.
50
- *
51
- * @param {Number} code The status code explaining why the connection is being closed
52
- * @param {String} reason A human-readable string explaining why the connection is closing
53
- * @param {WebSocket} target A reference to the target to which the event was dispatched
54
- */
55
- constructor (code, reason, target) {
56
- super('close', target);
57
-
58
- this.wasClean = target._closeFrameReceived && target._closeFrameSent;
59
- this.reason = reason;
60
- this.code = code;
61
- }
62
- }
63
-
64
- /**
65
- * Class representing an open event.
66
- *
67
- * @extends Event
68
- * @private
69
- */
70
- class OpenEvent extends Event {
71
- /**
72
- * Create a new `OpenEvent`.
73
- *
74
- * @param {WebSocket} target A reference to the target to which the event was dispatched
75
- */
76
- constructor (target) {
77
- super('open', target);
78
- }
79
- }
80
-
81
- /**
82
- * Class representing an error event.
83
- *
84
- * @extends Event
85
- * @private
86
- */
87
- class ErrorEvent extends Event {
88
- /**
89
- * Create a new `ErrorEvent`.
90
- *
91
- * @param {Object} error The error that generated this event
92
- * @param {WebSocket} target A reference to the target to which the event was dispatched
93
- */
94
- constructor (error, target) {
95
- super('error', target);
96
-
97
- this.message = error.message;
98
- this.error = error;
99
- }
100
- }
101
-
102
- /**
103
- * This provides methods for emulating the `EventTarget` interface. It's not
104
- * meant to be used directly.
105
- *
106
- * @mixin
107
- */
108
- const EventTarget = {
109
- /**
110
- * Register an event listener.
111
- *
112
- * @param {String} method A string representing the event type to listen for
113
- * @param {Function} listener The listener to add
114
- * @public
115
- */
116
- addEventListener (method, listener) {
117
- if (typeof listener !== 'function') return;
118
-
119
- function onMessage (data) {
120
- listener.call(this, new MessageEvent(data, this));
121
- }
122
-
123
- function onClose (code, message) {
124
- listener.call(this, new CloseEvent(code, message, this));
125
- }
126
-
127
- function onError (error) {
128
- listener.call(this, new ErrorEvent(error, this));
129
- }
130
-
131
- function onOpen () {
132
- listener.call(this, new OpenEvent(this));
133
- }
134
-
135
- if (method === 'message') {
136
- onMessage._listener = listener;
137
- this.on(method, onMessage);
138
- } else if (method === 'close') {
139
- onClose._listener = listener;
140
- this.on(method, onClose);
141
- } else if (method === 'error') {
142
- onError._listener = listener;
143
- this.on(method, onError);
144
- } else if (method === 'open') {
145
- onOpen._listener = listener;
146
- this.on(method, onOpen);
147
- } else {
148
- this.on(method, listener);
149
- }
150
- },
151
-
152
- /**
153
- * Remove an event listener.
154
- *
155
- * @param {String} method A string representing the event type to remove
156
- * @param {Function} listener The listener to remove
157
- * @public
158
- */
159
- removeEventListener (method, listener) {
160
- const listeners = this.listeners(method);
161
-
162
- for (var i = 0; i < listeners.length; i++) {
163
- if (listeners[i] === listener || listeners[i]._listener === listener) {
164
- this.removeListener(method, listeners[i]);
165
- }
166
- }
167
- }
168
- };
169
-
170
- module.exports = EventTarget;
@@ -1,211 +0,0 @@
1
- 'use strict';
2
-
3
- //
4
- // Allowed token characters:
5
- //
6
- // '!', '#', '$', '%', '&', ''', '*', '+', '-',
7
- // '.', 0-9, A-Z, '^', '_', '`', a-z, '|', '~'
8
- //
9
- // tokenChars[32] === 0 // ' '
10
- // tokenChars[33] === 1 // '!'
11
- // tokenChars[34] === 0 // '"'
12
- // ...
13
- //
14
- const tokenChars = [
15
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 15
16
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 31
17
- 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, // 32 - 47
18
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // 48 - 63
19
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 64 - 79
20
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, // 80 - 95
21
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 96 - 111
22
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0 // 112 - 127
23
- ];
24
-
25
- /**
26
- * Adds an offer to the map of extension offers or a parameter to the map of
27
- * parameters.
28
- *
29
- * @param {Object} dest The map of extension offers or parameters
30
- * @param {String} name The extension or parameter name
31
- * @param {(Object|Boolean|String)} elem The extension parameters or the
32
- * parameter value
33
- * @private
34
- */
35
- function push (dest, name, elem) {
36
- if (Object.prototype.hasOwnProperty.call(dest, name)) dest[name].push(elem);
37
- else dest[name] = [elem];
38
- }
39
-
40
- /**
41
- * Parses the `Sec-WebSocket-Extensions` header into an object.
42
- *
43
- * @param {String} header The field value of the header
44
- * @return {Object} The parsed object
45
- * @public
46
- */
47
- function parse (header) {
48
- const offers = {};
49
-
50
- if (header === undefined || header === '') return offers;
51
-
52
- var params = {};
53
- var mustUnescape = false;
54
- var isEscaping = false;
55
- var inQuotes = false;
56
- var extensionName;
57
- var paramName;
58
- var start = -1;
59
- var end = -1;
60
-
61
- for (var i = 0; i < header.length; i++) {
62
- const code = header.charCodeAt(i);
63
-
64
- if (extensionName === undefined) {
65
- if (end === -1 && tokenChars[code] === 1) {
66
- if (start === -1) start = i;
67
- } else if (code === 0x20/* ' ' */|| code === 0x09/* '\t' */) {
68
- if (end === -1 && start !== -1) end = i;
69
- } else if (code === 0x3b/* ';' */ || code === 0x2c/* ',' */) {
70
- if (start === -1) {
71
- throw new SyntaxError(`Unexpected character at index ${i}`);
72
- }
73
-
74
- if (end === -1) end = i;
75
- const name = header.slice(start, end);
76
- if (code === 0x2c) {
77
- push(offers, name, params);
78
- params = {};
79
- } else {
80
- extensionName = name;
81
- }
82
-
83
- start = end = -1;
84
- } else {
85
- throw new SyntaxError(`Unexpected character at index ${i}`);
86
- }
87
- } else if (paramName === undefined) {
88
- if (end === -1 && tokenChars[code] === 1) {
89
- if (start === -1) start = i;
90
- } else if (code === 0x20 || code === 0x09) {
91
- if (end === -1 && start !== -1) end = i;
92
- } else if (code === 0x3b || code === 0x2c) {
93
- if (start === -1) {
94
- throw new SyntaxError(`Unexpected character at index ${i}`);
95
- }
96
-
97
- if (end === -1) end = i;
98
- push(params, header.slice(start, end), true);
99
- if (code === 0x2c) {
100
- push(offers, extensionName, params);
101
- params = {};
102
- extensionName = undefined;
103
- }
104
-
105
- start = end = -1;
106
- } else if (code === 0x3d/* '=' */&& start !== -1 && end === -1) {
107
- paramName = header.slice(start, i);
108
- start = end = -1;
109
- } else {
110
- throw new SyntaxError(`Unexpected character at index ${i}`);
111
- }
112
- } else {
113
- //
114
- // The value of a quoted-string after unescaping must conform to the
115
- // token ABNF, so only token characters are valid.
116
- // Ref: https://tools.ietf.org/html/rfc6455#section-9.1
117
- //
118
- if (isEscaping) {
119
- if (tokenChars[code] !== 1) {
120
- throw new SyntaxError(`Unexpected character at index ${i}`);
121
- }
122
- if (start === -1) start = i;
123
- else if (!mustUnescape) mustUnescape = true;
124
- isEscaping = false;
125
- } else if (inQuotes) {
126
- if (tokenChars[code] === 1) {
127
- if (start === -1) start = i;
128
- } else if (code === 0x22/* '"' */ && start !== -1) {
129
- inQuotes = false;
130
- end = i;
131
- } else if (code === 0x5c/* '\' */) {
132
- isEscaping = true;
133
- } else {
134
- throw new SyntaxError(`Unexpected character at index ${i}`);
135
- }
136
- } else if (code === 0x22 && header.charCodeAt(i - 1) === 0x3d) {
137
- inQuotes = true;
138
- } else if (end === -1 && tokenChars[code] === 1) {
139
- if (start === -1) start = i;
140
- } else if (start !== -1 && (code === 0x20 || code === 0x09)) {
141
- if (end === -1) end = i;
142
- } else if (code === 0x3b || code === 0x2c) {
143
- if (start === -1) {
144
- throw new SyntaxError(`Unexpected character at index ${i}`);
145
- }
146
-
147
- if (end === -1) end = i;
148
- var value = header.slice(start, end);
149
- if (mustUnescape) {
150
- value = value.replace(/\\/g, '');
151
- mustUnescape = false;
152
- }
153
- push(params, paramName, value);
154
- if (code === 0x2c) {
155
- push(offers, extensionName, params);
156
- params = {};
157
- extensionName = undefined;
158
- }
159
-
160
- paramName = undefined;
161
- start = end = -1;
162
- } else {
163
- throw new SyntaxError(`Unexpected character at index ${i}`);
164
- }
165
- }
166
- }
167
-
168
- if (start === -1 || inQuotes) {
169
- throw new SyntaxError('Unexpected end of input');
170
- }
171
-
172
- if (end === -1) end = i;
173
- const token = header.slice(start, end);
174
- if (extensionName === undefined) {
175
- push(offers, token, {});
176
- } else {
177
- if (paramName === undefined) {
178
- push(params, token, true);
179
- } else if (mustUnescape) {
180
- push(params, paramName, token.replace(/\\/g, ''));
181
- } else {
182
- push(params, paramName, token);
183
- }
184
- push(offers, extensionName, params);
185
- }
186
-
187
- return offers;
188
- }
189
-
190
- /**
191
- * Builds the `Sec-WebSocket-Extensions` header field value.
192
- *
193
- * @param {Object} extensions The map of extensions and parameters to format
194
- * @return {String} A string representing the given object
195
- * @public
196
- */
197
- function format (extensions) {
198
- return Object.keys(extensions).map((extension) => {
199
- var configurations = extensions[extension];
200
- if (!Array.isArray(configurations)) configurations = [configurations];
201
- return configurations.map((params) => {
202
- return [extension].concat(Object.keys(params).map((k) => {
203
- var values = params[k];
204
- if (!Array.isArray(values)) values = [values];
205
- return values.map((v) => v === true ? k : `${k}=${v}`).join('; ');
206
- })).join('; ');
207
- }).join(', ');
208
- }).join(', ');
209
- }
210
-
211
- module.exports = { format, parse };