@databricks/sql 1.5.0 → 1.6.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 (104) hide show
  1. package/dist/DBSQLClient.d.ts +17 -8
  2. package/dist/DBSQLClient.js +82 -82
  3. package/dist/DBSQLClient.js.map +1 -1
  4. package/dist/DBSQLOperation/FetchResultsHelper.d.ts +3 -3
  5. package/dist/DBSQLOperation/FetchResultsHelper.js +4 -3
  6. package/dist/DBSQLOperation/FetchResultsHelper.js.map +1 -1
  7. package/dist/DBSQLOperation/index.d.ts +10 -7
  8. package/dist/DBSQLOperation/index.js +110 -41
  9. package/dist/DBSQLOperation/index.js.map +1 -1
  10. package/dist/DBSQLParameter.d.ts +6 -2
  11. package/dist/DBSQLParameter.js +15 -1
  12. package/dist/DBSQLParameter.js.map +1 -1
  13. package/dist/DBSQLSession.d.ts +5 -6
  14. package/dist/DBSQLSession.js +66 -36
  15. package/dist/DBSQLSession.js.map +1 -1
  16. package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.d.ts +3 -3
  17. package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.js +3 -4
  18. package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.js.map +1 -1
  19. package/dist/connection/auth/DatabricksOAuth/OAuthManager.d.ts +6 -3
  20. package/dist/connection/auth/DatabricksOAuth/OAuthManager.js +27 -8
  21. package/dist/connection/auth/DatabricksOAuth/OAuthManager.js.map +1 -1
  22. package/dist/connection/auth/DatabricksOAuth/index.d.ts +4 -6
  23. package/dist/connection/auth/DatabricksOAuth/index.js +1 -1
  24. package/dist/connection/auth/DatabricksOAuth/index.js.map +1 -1
  25. package/dist/connection/auth/PlainHttpAuthentication.d.ts +6 -3
  26. package/dist/connection/auth/PlainHttpAuthentication.js +1 -0
  27. package/dist/connection/auth/PlainHttpAuthentication.js.map +1 -1
  28. package/dist/connection/connections/HttpConnection.d.ts +16 -9
  29. package/dist/connection/connections/HttpConnection.js +60 -51
  30. package/dist/connection/connections/HttpConnection.js.map +1 -1
  31. package/dist/connection/connections/ThriftHttpConnection.d.ts +38 -0
  32. package/dist/connection/connections/ThriftHttpConnection.js +134 -0
  33. package/dist/connection/connections/ThriftHttpConnection.js.map +1 -0
  34. package/dist/connection/contracts/IAuthentication.d.ts +2 -2
  35. package/dist/connection/contracts/IConnectionOptions.d.ts +17 -19
  36. package/dist/connection/contracts/IConnectionProvider.d.ts +6 -3
  37. package/dist/contracts/IClientContext.d.ts +10 -0
  38. package/dist/{connection/contracts/IThriftConnection.js → contracts/IClientContext.js} +1 -1
  39. package/dist/contracts/IClientContext.js.map +1 -0
  40. package/dist/contracts/IDBSQLClient.d.ts +2 -0
  41. package/dist/contracts/IDBSQLSession.d.ts +1 -0
  42. package/dist/contracts/IDriver.d.ts +24 -0
  43. package/dist/contracts/IDriver.js +3 -0
  44. package/dist/contracts/IDriver.js.map +1 -0
  45. package/dist/errors/ParameterError.d.ts +2 -0
  46. package/dist/errors/ParameterError.js +6 -0
  47. package/dist/errors/ParameterError.js.map +1 -0
  48. package/dist/hive/HiveDriver.d.ts +8 -5
  49. package/dist/hive/HiveDriver.js +23 -23
  50. package/dist/hive/HiveDriver.js.map +1 -1
  51. package/dist/result/ArrowResult.d.ts +3 -1
  52. package/dist/result/ArrowResult.js +4 -2
  53. package/dist/result/ArrowResult.js.map +1 -1
  54. package/dist/result/CloudFetchResult.d.ts +2 -1
  55. package/dist/result/CloudFetchResult.js +5 -3
  56. package/dist/result/CloudFetchResult.js.map +1 -1
  57. package/dist/result/JsonResult.d.ts +3 -1
  58. package/dist/result/JsonResult.js +2 -1
  59. package/dist/result/JsonResult.js.map +1 -1
  60. package/dist/utils/index.d.ts +1 -2
  61. package/dist/utils/index.js +1 -3
  62. package/dist/utils/index.js.map +1 -1
  63. package/dist/version.d.ts +1 -1
  64. package/dist/version.js +1 -1
  65. package/package.json +2 -4
  66. package/dist/DBSQLOperation/OperationStatusHelper.d.ts +0 -16
  67. package/dist/DBSQLOperation/OperationStatusHelper.js +0 -138
  68. package/dist/DBSQLOperation/OperationStatusHelper.js.map +0 -1
  69. package/dist/connection/contracts/IThriftConnection.d.ts +0 -4
  70. package/dist/connection/contracts/IThriftConnection.js.map +0 -1
  71. package/dist/node_modules/thrift/LICENSE +0 -306
  72. package/dist/node_modules/thrift/README.md +0 -210
  73. package/dist/node_modules/thrift/lib/nodejs/README.md +0 -142
  74. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/binary.js +0 -168
  75. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/binary_protocol.js +0 -367
  76. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/browser.js +0 -49
  77. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/buffered_transport.js +0 -186
  78. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/compact_protocol.js +0 -915
  79. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/connection.js +0 -396
  80. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/create_client.js +0 -54
  81. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/framed_transport.js +0 -185
  82. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/header_protocol.js +0 -258
  83. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/header_transport.js +0 -341
  84. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/http_connection.js +0 -292
  85. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/index.js +0 -76
  86. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/input_buffer_underrun_error.js +0 -32
  87. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/int64_util.js +0 -91
  88. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/json_parse.js +0 -299
  89. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/json_protocol.js +0 -799
  90. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/log.js +0 -87
  91. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/multiplexed_processor.js +0 -63
  92. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/multiplexed_protocol.js +0 -73
  93. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/protocol.js +0 -22
  94. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/server.js +0 -123
  95. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/thrift.js +0 -241
  96. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/transport.js +0 -22
  97. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/web_server.js +0 -567
  98. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/ws_connection.js +0 -286
  99. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/ws_transport.js +0 -206
  100. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/xhr_connection.js +0 -280
  101. package/dist/node_modules/thrift/package.json +0 -72
  102. package/dist/utils/areHeadersEqual.d.ts +0 -2
  103. package/dist/utils/areHeadersEqual.js +0 -49
  104. package/dist/utils/areHeadersEqual.js.map +0 -1
@@ -1,258 +0,0 @@
1
- /*
2
- * Licensed to the Apache Software Foundation (ASF) under one
3
- * or more contributor license agreements. See the NOTICE file
4
- * distributed with this work for additional information
5
- * regarding copyright ownership. The ASF licenses this file
6
- * to you under the Apache License, Version 2.0 (the
7
- * "License"); you may not use this file except in compliance
8
- * with the License. You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing,
13
- * software distributed under the License is distributed on an
14
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
- * KIND, either express or implied. See the License for the
16
- * specific language governing permissions and limitations
17
- * under the License.
18
- */
19
- var util = require('util');
20
- var TBinaryProtocol = require('./binary_protocol');
21
- var TCompactProtocol = require('./compact_protocol');
22
- var THeaderTransport = require('./header_transport');
23
-
24
- var ProtocolMap = {};
25
- ProtocolMap[THeaderTransport.SubprotocolId.BINARY] = TBinaryProtocol;
26
- ProtocolMap[THeaderTransport.SubprotocolId.COMPACT] = TCompactProtocol;
27
-
28
- module.exports = THeaderProtocol;
29
-
30
- function THeaderProtocolError(message) {
31
- Error.call(this);
32
- if (Error.captureStackTrace !== undefined) {
33
- Error.captureStackTrace(this, this.constructor);
34
- }
35
- this.name = this.constructor.name;
36
- this.message = message;
37
- }
38
-
39
- util.inherits(THeaderProtocolError, Error);
40
-
41
- /**
42
- * A framed protocol with headers.
43
- *
44
- * THeaderProtocol frames other Thrift protocols and adds support for
45
- * optional out-of-band headers. The currently supported subprotocols are
46
- * TBinaryProtocol and TCompactProtocol. It can currently only be used with
47
- * transports that inherit THeaderTransport.
48
- *
49
- * THeaderProtocol does not currently support THTTPServer, TNonblockingServer,
50
- * or TProcessPoolServer.
51
- *
52
- * See doc/specs/HeaderFormat.md for details of the wire format.
53
- */
54
- function THeaderProtocol(trans) {
55
- if (!(trans instanceof THeaderTransport)) {
56
- throw new THeaderProtocolError(
57
- 'Only transports that inherit THeaderTransport can be' +
58
- ' used with THeaderProtocol'
59
- );
60
- }
61
- this.trans = trans;
62
- this.setProtocol();
63
- };
64
-
65
- THeaderProtocol.prototype.flush = function() {
66
- // Headers must be written prior to flushing because because
67
- // you need to calculate the length of the payload for the length
68
- // field of the header
69
- this.trans.writeHeaders();
70
- return this.trans.flush();
71
- };
72
-
73
- THeaderProtocol.prototype.writeMessageBegin = function(name, type, seqid) {
74
- return this.protocol.writeMessageBegin(name, type, seqid);
75
- };
76
-
77
- THeaderProtocol.prototype.writeMessageEnd = function() {
78
- return this.protocol.writeMessageEnd();
79
- };
80
-
81
- THeaderProtocol.prototype.writeStructBegin = function(name) {
82
- return this.protocol.writeStructBegin(name);
83
- };
84
-
85
- THeaderProtocol.prototype.writeStructEnd = function() {
86
- return this.protocol.writeStructEnd();
87
- };
88
-
89
- THeaderProtocol.prototype.writeFieldBegin = function(name, type, id) {
90
- return this.protocol.writeFieldBegin(name, type, id);
91
- }
92
-
93
- THeaderProtocol.prototype.writeFieldEnd = function() {
94
- return this.protocol.writeFieldEnd();
95
- };
96
-
97
- THeaderProtocol.prototype.writeFieldStop = function() {
98
- return this.protocol.writeFieldStop();
99
- };
100
-
101
- THeaderProtocol.prototype.writeMapBegin = function(ktype, vtype, size) {
102
- return this.protocol.writeMapBegin(ktype, vtype, size);
103
- };
104
-
105
- THeaderProtocol.prototype.writeMapEnd = function() {
106
- return this.protocol.writeMapEnd();
107
- };
108
-
109
- THeaderProtocol.prototype.writeListBegin = function(etype, size) {
110
- return this.protocol.writeListBegin(etype, size);
111
- };
112
-
113
- THeaderProtocol.prototype.writeListEnd = function() {
114
- return this.protocol.writeListEnd();
115
- };
116
-
117
- THeaderProtocol.prototype.writeSetBegin = function(etype, size) {
118
- return this.protocol.writeSetBegin(etype, size);
119
- };
120
-
121
- THeaderProtocol.prototype.writeSetEnd = function() {
122
- return this.protocol.writeSetEnd();
123
- };
124
-
125
- THeaderProtocol.prototype.writeBool = function(b) {
126
- return this.protocol.writeBool(b);
127
- };
128
-
129
- THeaderProtocol.prototype.writeByte = function(b) {
130
- return this.protocol.writeByte(b);
131
- };
132
-
133
- THeaderProtocol.prototype.writeI16 = function(i16) {
134
- return this.protocol.writeI16(i16);
135
- };
136
-
137
- THeaderProtocol.prototype.writeI32 = function(i32) {
138
- return this.protocol.writeI32(i32);
139
- };
140
-
141
- THeaderProtocol.prototype.writeI64 = function(i64) {
142
- return this.protocol.writeI64(i64);
143
- };
144
-
145
- THeaderProtocol.prototype.writeDouble = function(dub) {
146
- return this.protocol.writeDouble(dub);
147
- };
148
-
149
- THeaderProtocol.prototype.writeStringOrBinary = function(name, encoding, arg) {
150
- return this.protocol.writeStringOrBinary(name, encoding, arg);
151
- };
152
-
153
- THeaderProtocol.prototype.writeString = function(arg) {
154
- return this.protocol.writeString(arg);
155
- };
156
-
157
- THeaderProtocol.prototype.writeBinary = function(arg) {
158
- return this.protocol.writeBinary(arg);
159
- };
160
-
161
- THeaderProtocol.prototype.readMessageBegin = function() {
162
- this.trans.readHeaders();
163
- this.setProtocol();
164
- return this.protocol.readMessageBegin();
165
- };
166
-
167
- THeaderProtocol.prototype.readMessageEnd = function() {
168
- return this.protocol.readMessageEnd();
169
- };
170
-
171
- THeaderProtocol.prototype.readStructBegin = function() {
172
- return this.protocol.readStructBegin();
173
- };
174
-
175
- THeaderProtocol.prototype.readStructEnd = function() {
176
- return this.protocol.readStructEnd();
177
- };
178
-
179
- THeaderProtocol.prototype.readFieldBegin = function() {
180
- return this.protocol.readFieldBegin();
181
- };
182
-
183
- THeaderProtocol.prototype.readFieldEnd = function() {
184
- return this.protocol.readFieldEnd();
185
- };
186
-
187
- THeaderProtocol.prototype.readMapBegin = function() {
188
- return this.protocol.readMapBegin();
189
- };
190
-
191
- THeaderProtocol.prototype.readMapEnd = function() {
192
- return this.protocol.readMapEnd();
193
- };
194
-
195
- THeaderProtocol.prototype.readListBegin = function() {
196
- return this.protocol.readListBegin();
197
- };
198
-
199
- THeaderProtocol.prototype.readListEnd = function() {
200
- return this.protocol.readListEnd();
201
- };
202
-
203
- THeaderProtocol.prototype.readSetBegin = function() {
204
- return this.protocol.readSetBegin();
205
- };
206
-
207
- THeaderProtocol.prototype.readSetEnd = function() {
208
- return this.protocol.readSetEnd();
209
- };
210
-
211
- THeaderProtocol.prototype.readBool = function() {
212
- return this.protocol.readBool();
213
- };
214
-
215
- THeaderProtocol.prototype.readByte = function() {
216
- return this.protocol.readByte();
217
- };
218
-
219
- THeaderProtocol.prototype.readI16 = function() {
220
- return this.protocol.readI16();
221
- };
222
-
223
- THeaderProtocol.prototype.readI32 = function() {
224
- return this.protocol.readI32();
225
- };
226
-
227
- THeaderProtocol.prototype.readI64 = function() {
228
- return this.protocol.readI64();
229
- };
230
-
231
- THeaderProtocol.prototype.readDouble = function() {
232
- return this.protocol.readDouble();
233
- };
234
-
235
- THeaderProtocol.prototype.readBinary = function() {
236
- return this.protocol.readBinary();
237
- };
238
-
239
- THeaderProtocol.prototype.readString = function() {
240
- return this.protocol.readString();
241
- };
242
-
243
- THeaderProtocol.prototype.getTransport = function() {
244
- return this.trans;
245
- };
246
-
247
- THeaderProtocol.prototype.skip = function(type) {
248
- return this.protocol.skip(type);
249
- };
250
-
251
- THeaderProtocol.prototype.setProtocol = function(subProtocolId) {
252
- var subProtocolId = this.trans.getProtocolId();
253
- if (!ProtocolMap[subProtocolId]) {
254
- throw new THeaderProtocolError('Headers not supported for protocol ' + subProtocolId);
255
- }
256
-
257
- this.protocol = new ProtocolMap[subProtocolId](this.trans);
258
- };
@@ -1,341 +0,0 @@
1
- /*
2
- * Licensed to the Apache Software Foundation (ASF) under one
3
- * or more contributor license agreements. See the NOTICE file
4
- * distributed with this work for additional information
5
- * regarding copyright ownership. The ASF licenses this file
6
- * to you under the Apache License, Version 2.0 (the
7
- * "License"); you may not use this file except in compliance
8
- * with the License. You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing,
13
- * software distributed under the License is distributed on an
14
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
- * KIND, either express or implied. See the License for the
16
- * specific language governing permissions and limitations
17
- * under the License.
18
- */
19
-
20
- var util = require('util');
21
- var TCompactProtocol = require('./compact_protocol');
22
- var TBinaryProtocol = require('./binary_protocol');
23
- var InputBufferUnderrunError = require('./input_buffer_underrun_error');
24
-
25
- function THeaderTransportError(message) {
26
- Error.call(this);
27
- if (Error.captureStackTrace !== undefined) {
28
- Error.captureStackTrace(this, this.constructor);
29
- }
30
- this.name = this.constructor.name;
31
- this.message = message;
32
- }
33
-
34
- util.inherits(THeaderTransportError, Error);
35
-
36
- module.exports = THeaderTransport;
37
-
38
- // from HeaderFormat.md
39
- var COMPACT_PROTOCOL_OFFSET = 0;
40
- var COMPACT_PROTOCOL_VERSION_OFFSET = 1;
41
- var FRAME_SIZE_OFFSET = 0;
42
- var HEADER_MAGIC_OFFSET = 32 / 8;
43
- var FLAGS_OFFSET = 48 / 8;
44
- var SEQID_OFFSET = 64 / 8;
45
- var HEADER_SIZE_OFFSET = 96 / 8;
46
- var HEADER_START_OFFSET = 112 / 8;
47
-
48
- var HEADER_MAGIC = 0x0FFF;
49
-
50
- var TINFO_HEADER_KEY_VALUE_TYPE = 0x01;
51
- var MAX_FRAME_SIZE = 0x3FFFFFFF;
52
-
53
- // A helper class for reading/writing varints. Uses
54
- // TCompactProtocol under the hood
55
- function VarintHelper(readBuffer) {
56
- var TBufferedTransport = require('./buffered_transport');
57
- this.outputBuffer = null;
58
- var _this = this;
59
- this.transport = new TBufferedTransport(null, function(output) {
60
- _this.outputBuffer = output;
61
- });
62
-
63
- this.transport.inBuf = readBuffer || Buffer.alloc(0);
64
- this.transport.writeCursor = this.transport.inBuf.length;
65
- this.protocol = new TCompactProtocol(this.transport);
66
- };
67
-
68
- VarintHelper.prototype.readVarint32 = function() {
69
- return this.protocol.readVarint32();
70
- };
71
-
72
- VarintHelper.prototype.writeVarint32 = function(i) {
73
- this.protocol.writeVarint32(i);
74
- };
75
-
76
- VarintHelper.prototype.readString = function() {
77
- return this.protocol.readString();
78
- };
79
-
80
- VarintHelper.prototype.writeString = function(str) {
81
- this.protocol.writeString(str);
82
- }
83
-
84
- VarintHelper.prototype.getOutCount = function() {
85
- return this.transport.outCount;
86
- };
87
-
88
- VarintHelper.prototype.write = function(str) {
89
- this.transport.write(str);
90
- };
91
-
92
- VarintHelper.prototype.toBuffer = function() {
93
- this.transport.flush();
94
- return this.outputBuffer;
95
- };
96
-
97
- // from lib/cpp/src/thrift/protocol/TProtocolTypes.h
98
- THeaderTransport.SubprotocolId = {
99
- BINARY: 0,
100
- JSON: 1,
101
- COMPACT: 2,
102
- };
103
-
104
- /**
105
- An abstract transport used as a prototype for other transports
106
- to enable reading/writing theaders. This should NOT be used as a standalone transport
107
- The methods in this transport are called by THeaderProtocol, which will call readHeaders/writeHeaders
108
- in the read/writeMessageBegin methods and parse/write headers to/from a request
109
- prior to reading/writing.
110
-
111
- The reason this is not a standalone transport type is because different transport types
112
- have their own individual static receiver methods that are called prior to instantiation.
113
- There doesn't seem to be a way for THeaderTransport to know which receiver method to use
114
- without reworking the server API.
115
-
116
- For reading headers from a request, the parsed headers can be retrieved via
117
- getReadHeader. Similarly, you can set headers to be written on the client via
118
- setWriteHeader.
119
- */
120
- function THeaderTransport() {
121
- this.maxFrameSize = MAX_FRAME_SIZE;
122
- this.protocolId = THeaderTransport.SubprotocolId.BINARY;
123
- this.rheaders = {};
124
- this.wheaders = {};
125
- this.inBuf = Buffer.alloc(0);
126
- this.outCount = 0;
127
- this.flags = null;
128
- this.seqid = 0;
129
- this.shouldWriteHeaders = true;
130
- };
131
-
132
- var validateHeaders = function(key, value) {
133
- if (typeof key !== 'string' || typeof value !== 'string') {
134
- throw new THeaderTransportError('Header key and values must be strings');
135
- }
136
- };
137
-
138
- var validateProtocolId = function(protocolId) {
139
- var protocols = Object.keys(THeaderTransport.SubprotocolId);
140
- for (var i = 0; i < protocols.length; i++) {
141
- if (protocolId === THeaderTransport.SubprotocolId[protocols[i]]) return true;
142
- }
143
-
144
- throw new Error(protocolId + ' is not a valid protocol id');
145
- };
146
-
147
- THeaderTransport.prototype.setSeqId = function(seqid) {
148
- this.seqid = seqid;
149
- };
150
-
151
- THeaderTransport.prototype.getSeqId = function(seqid) {
152
- return this.seqid;
153
- };
154
-
155
- THeaderTransport.prototype.setFlags = function(flags) {
156
- this.flags = flags;
157
- };
158
-
159
- THeaderTransport.prototype.getReadHeaders = function() {
160
- return this.rheaders;
161
- };
162
-
163
- THeaderTransport.prototype.setReadHeader = function(key, value) {
164
- validateHeaders(key, value);
165
- this.rheaders[key] = value;
166
- };
167
-
168
- THeaderTransport.prototype.clearReadHeaders = function() {
169
- this.rheaders = {};
170
- };
171
-
172
- THeaderTransport.prototype.getWriteHeaders = function() {
173
- return this.wheaders;
174
- };
175
-
176
- THeaderTransport.prototype.setWriteHeader = function(key, value) {
177
- validateHeaders(key, value);
178
- this.wheaders[key] = value;
179
- };
180
-
181
- THeaderTransport.prototype.clearWriteHeaders = function() {
182
- this.wheaders = {};
183
- };
184
-
185
- THeaderTransport.prototype.setMaxFrameSize = function(frameSize) {
186
- this.maxFrameSize = frameSize;
187
- };
188
-
189
- THeaderTransport.prototype.setProtocolId = function(protocolId) {
190
- validateProtocolId(protocolId);
191
- this.protocolId = protocolId;
192
- };
193
-
194
- THeaderTransport.prototype.getProtocolId = function() {
195
- return this.protocolId;
196
- };
197
-
198
- var isUnframedBinary = function(readBuffer) {
199
- var version = readBuffer.readInt32BE();
200
- return (version & TBinaryProtocol.VERSION_MASK) === TBinaryProtocol.VERSION_1;
201
- }
202
-
203
- var isUnframedCompact = function(readBuffer) {
204
- var protocolId = readBuffer.readInt8(COMPACT_PROTOCOL_OFFSET);
205
- var version = readBuffer.readInt8(COMPACT_PROTOCOL_VERSION_OFFSET);
206
- return protocolId === TCompactProtocol.PROTOCOL_ID &&
207
- (version & TCompactProtocol.VERSION_MASK) === TCompactProtocol.VERSION_N;
208
- }
209
-
210
- THeaderTransport.prototype.readHeaders = function() {
211
- var readBuffer = this.inBuf;
212
-
213
- var isUnframed = false;
214
- if (isUnframedBinary(readBuffer)) {
215
- this.setProtocolId(THeaderTransport.SubprotocolId.BINARY);
216
- isUnframed = true;
217
- }
218
-
219
- if (isUnframedCompact(readBuffer)) {
220
- this.setProtocolId(THeaderTransport.SubprotocolId.COMPACT);
221
- isUnframed = true;
222
- }
223
-
224
- if (isUnframed) {
225
- this.shouldWriteHeaders = false;
226
- return;
227
- }
228
-
229
- var frameSize = readBuffer.readInt32BE(FRAME_SIZE_OFFSET);
230
- if (frameSize > this.maxFrameSize) {
231
- throw new THeaderTransportError('Frame exceeds maximum frame size');
232
- }
233
-
234
- var headerMagic = readBuffer.readInt16BE(HEADER_MAGIC_OFFSET);
235
- this.shouldWriteHeaders = headerMagic === HEADER_MAGIC;
236
- if (!this.shouldWriteHeaders) {
237
- return;
238
- }
239
-
240
- this.setFlags(readBuffer.readInt16BE(FLAGS_OFFSET));
241
- this.setSeqId(readBuffer.readInt32BE(SEQID_OFFSET));
242
- var headerSize = readBuffer.readInt16BE(HEADER_SIZE_OFFSET) * 4;
243
- var endOfHeaders = HEADER_START_OFFSET + headerSize;
244
- if (endOfHeaders > readBuffer.length) {
245
- throw new THeaderTransportError('Header size is greater than frame size');
246
- }
247
-
248
- var headerBuffer = Buffer.alloc(headerSize);
249
- readBuffer.copy(headerBuffer, 0, HEADER_START_OFFSET, endOfHeaders);
250
-
251
- var varintHelper = new VarintHelper(headerBuffer);
252
- this.setProtocolId(varintHelper.readVarint32());
253
- var transformCount = varintHelper.readVarint32();
254
- if (transformCount > 0) {
255
- throw new THeaderTransportError('Transforms are not yet supported');
256
- }
257
-
258
- while (true) {
259
- try {
260
- var headerType = varintHelper.readVarint32();
261
- if (headerType !== TINFO_HEADER_KEY_VALUE_TYPE) {
262
- break;
263
- }
264
-
265
- var numberOfHeaders = varintHelper.readVarint32();
266
- for (var i = 0; i < numberOfHeaders; i++) {
267
- var key = varintHelper.readString();
268
- var value = varintHelper.readString();
269
- this.setReadHeader(key, value);
270
- }
271
- } catch (e) {
272
- if (e instanceof InputBufferUnderrunError) {
273
- break;
274
- }
275
- throw e;
276
- }
277
- }
278
-
279
- // moves the read cursor past the headers
280
- this.read(endOfHeaders);
281
- return this.getReadHeaders();
282
- };
283
-
284
- THeaderTransport.prototype.writeHeaders = function() {
285
- // only write headers on the server if the client contained headers
286
- if (!this.shouldWriteHeaders) {
287
- return;
288
- }
289
- var headers = this.getWriteHeaders();
290
-
291
- var varintWriter = new VarintHelper();
292
- varintWriter.writeVarint32(this.protocolId);
293
- varintWriter.writeVarint32(0); // transforms not supported
294
-
295
- // writing info header key values
296
- var headerKeys = Object.keys(headers);
297
- if (headerKeys.length > 0) {
298
- varintWriter.writeVarint32(TINFO_HEADER_KEY_VALUE_TYPE);
299
- varintWriter.writeVarint32(headerKeys.length);
300
- for (var i = 0; i < headerKeys.length; i++) {
301
- var key = headerKeys[i];
302
- var value = headers[key];
303
-
304
- varintWriter.writeString(key);
305
- varintWriter.writeString(value);
306
- }
307
- }
308
- var headerSizeWithoutPadding = varintWriter.getOutCount();
309
- var paddingNeeded = (4 - (headerSizeWithoutPadding % 4)) % 4;
310
-
311
- var headerSize = Buffer.alloc(2);
312
- headerSize.writeInt16BE(Math.floor((headerSizeWithoutPadding + paddingNeeded) / 4));
313
-
314
- var paddingBuffer = Buffer.alloc(paddingNeeded);
315
- paddingBuffer.fill(0x00);
316
- varintWriter.write(paddingBuffer);
317
- var headerContentBuffer = varintWriter.toBuffer();
318
- var frameSize = Buffer.alloc(4);
319
- frameSize.writeInt32BE(10 + this.outCount + headerContentBuffer.length);
320
- var headerMagic = Buffer.alloc(2);
321
- headerMagic.writeInt16BE(HEADER_MAGIC);
322
-
323
- // flags are not yet supported, so write a zero
324
- var flags = Buffer.alloc(2);
325
- flags.writeInt16BE(0);
326
-
327
- var seqid = Buffer.alloc(4);
328
- seqid.writeInt32BE(this.getSeqId());
329
-
330
- var headerBuffer = Buffer.concat([
331
- frameSize,
332
- headerMagic,
333
- flags,
334
- seqid,
335
- headerSize,
336
- headerContentBuffer,
337
- ]);
338
-
339
- this.outBuffers.unshift(headerBuffer);
340
- this.outCount += headerBuffer.length;
341
- };