@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,26 +0,0 @@
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
- };
@@ -1,21 +0,0 @@
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.
@@ -1,58 +0,0 @@
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)
@@ -1,17 +0,0 @@
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
@@ -1,8 +0,0 @@
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
@@ -1,3 +0,0 @@
1
- "use strict";
2
-
3
- module.exports = require('ws');
@@ -1,34 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- node_modules
2
- .DS_Store
3
- npm-debug.log
@@ -1,268 +0,0 @@
1
- // Int64.js
2
- //
3
- // Copyright (c) 2012 Robert Kieffer
4
- // MIT License - http://opensource.org/licenses/mit-license.php
5
-
6
- /**
7
- * Support for handling 64-bit int numbers in Javascript (node.js)
8
- *
9
- * JS Numbers are IEEE-754 binary double-precision floats, which limits the
10
- * range of values that can be represented with integer precision to:
11
- *
12
- * 2^^53 <= N <= 2^53
13
- *
14
- * Int64 objects wrap a node Buffer that holds the 8-bytes of int64 data. These
15
- * objects operate directly on the buffer which means that if they are created
16
- * using an existing buffer then setting the value will modify the Buffer, and
17
- * vice-versa.
18
- *
19
- * Internal Representation
20
- *
21
- * The internal buffer format is Big Endian. I.e. the most-significant byte is
22
- * at buffer[0], the least-significant at buffer[7]. For the purposes of
23
- * converting to/from JS native numbers, the value is assumed to be a signed
24
- * integer stored in 2's complement form.
25
- *
26
- * For details about IEEE-754 see:
27
- * http://en.wikipedia.org/wiki/Double_precision_floating-point_format
28
- */
29
-
30
- // Useful masks and values for bit twiddling
31
- var MASK31 = 0x7fffffff, VAL31 = 0x80000000;
32
- var MASK32 = 0xffffffff, VAL32 = 0x100000000;
33
-
34
- // Map for converting hex octets to strings
35
- var _HEX = [];
36
- for (var i = 0; i < 256; i++) {
37
- _HEX[i] = (i > 0xF ? '' : '0') + i.toString(16);
38
- }
39
-
40
- //
41
- // Int64
42
- //
43
-
44
- /**
45
- * Constructor accepts any of the following argument types:
46
- *
47
- * new Int64(buffer[, offset=0]) - Existing Buffer with byte offset
48
- * new Int64(Uint8Array[, offset=0]) - Existing Uint8Array with a byte offset
49
- * new Int64(string) - Hex string (throws if n is outside int64 range)
50
- * new Int64(number) - Number (throws if n is outside int64 range)
51
- * new Int64(hi, lo) - Raw bits as two 32-bit values
52
- */
53
- var Int64 = module.exports = function(a1, a2) {
54
- if (a1 instanceof Buffer) {
55
- this.buffer = a1;
56
- this.offset = a2 || 0;
57
- } else if (Object.prototype.toString.call(a1) == '[object Uint8Array]') {
58
- // Under Browserify, Buffers can extend Uint8Arrays rather than an
59
- // instance of Buffer. We could assume the passed in Uint8Array is actually
60
- // a buffer but that won't handle the case where a raw Uint8Array is passed
61
- // in. We construct a new Buffer just in case.
62
- this.buffer = new Buffer(a1);
63
- this.offset = a2 || 0;
64
- } else {
65
- this.buffer = this.buffer || new Buffer(8);
66
- this.offset = 0;
67
- this.setValue.apply(this, arguments);
68
- }
69
- };
70
-
71
-
72
- // Max integer value that JS can accurately represent
73
- Int64.MAX_INT = Math.pow(2, 53);
74
-
75
- // Min integer value that JS can accurately represent
76
- Int64.MIN_INT = -Math.pow(2, 53);
77
-
78
- Int64.prototype = {
79
-
80
- constructor: Int64,
81
-
82
- /**
83
- * Do in-place 2's compliment. See
84
- * http://en.wikipedia.org/wiki/Two's_complement
85
- */
86
- _2scomp: function() {
87
- var b = this.buffer, o = this.offset, carry = 1;
88
- for (var i = o + 7; i >= o; i--) {
89
- var v = (b[i] ^ 0xff) + carry;
90
- b[i] = v & 0xff;
91
- carry = v >> 8;
92
- }
93
- },
94
-
95
- /**
96
- * Set the value. Takes any of the following arguments:
97
- *
98
- * setValue(string) - A hexidecimal string
99
- * setValue(number) - Number (throws if n is outside int64 range)
100
- * setValue(hi, lo) - Raw bits as two 32-bit values
101
- */
102
- setValue: function(hi, lo) {
103
- var negate = false;
104
- if (arguments.length == 1) {
105
- if (typeof(hi) == 'number') {
106
- // Simplify bitfield retrieval by using abs() value. We restore sign
107
- // later
108
- negate = hi < 0;
109
- hi = Math.abs(hi);
110
- lo = hi % VAL32;
111
- hi = hi / VAL32;
112
- if (hi > VAL32) throw new RangeError(hi + ' is outside Int64 range');
113
- hi = hi | 0;
114
- } else if (typeof(hi) == 'string') {
115
- hi = (hi + '').replace(/^0x/, '');
116
- lo = hi.substr(-8);
117
- hi = hi.length > 8 ? hi.substr(0, hi.length - 8) : '';
118
- hi = parseInt(hi, 16);
119
- lo = parseInt(lo, 16);
120
- } else {
121
- throw new Error(hi + ' must be a Number or String');
122
- }
123
- }
124
-
125
- // Technically we should throw if hi or lo is outside int32 range here, but
126
- // it's not worth the effort. Anything past the 32'nd bit is ignored.
127
-
128
- // Copy bytes to buffer
129
- var b = this.buffer, o = this.offset;
130
- for (var i = 7; i >= 0; i--) {
131
- b[o+i] = lo & 0xff;
132
- lo = i == 4 ? hi : lo >>> 8;
133
- }
134
-
135
- // Restore sign of passed argument
136
- if (negate) this._2scomp();
137
- },
138
-
139
- /**
140
- * Convert to a native JS number.
141
- *
142
- * WARNING: Do not expect this value to be accurate to integer precision for
143
- * large (positive or negative) numbers!
144
- *
145
- * @param allowImprecise If true, no check is performed to verify the
146
- * returned value is accurate to integer precision. If false, imprecise
147
- * numbers (very large positive or negative numbers) will be forced to +/-
148
- * Infinity.
149
- */
150
- toNumber: function(allowImprecise) {
151
- var b = this.buffer, o = this.offset;
152
-
153
- // Running sum of octets, doing a 2's complement
154
- var negate = b[o] & 0x80, x = 0, carry = 1;
155
- for (var i = 7, m = 1; i >= 0; i--, m *= 256) {
156
- var v = b[o+i];
157
-
158
- // 2's complement for negative numbers
159
- if (negate) {
160
- v = (v ^ 0xff) + carry;
161
- carry = v >> 8;
162
- v = v & 0xff;
163
- }
164
-
165
- x += v * m;
166
- }
167
-
168
- // Return Infinity if we've lost integer precision
169
- if (!allowImprecise && x >= Int64.MAX_INT) {
170
- return negate ? -Infinity : Infinity;
171
- }
172
-
173
- return negate ? -x : x;
174
- },
175
-
176
- /**
177
- * Convert to a JS Number. Returns +/-Infinity for values that can't be
178
- * represented to integer precision.
179
- */
180
- valueOf: function() {
181
- return this.toNumber(false);
182
- },
183
-
184
- /**
185
- * Return string value
186
- *
187
- * @param radix Just like Number#toString()'s radix
188
- */
189
- toString: function(radix) {
190
- return this.valueOf().toString(radix || 10);
191
- },
192
-
193
- /**
194
- * Return a string showing the buffer octets, with MSB on the left.
195
- *
196
- * @param sep separator string. default is '' (empty string)
197
- */
198
- toOctetString: function(sep) {
199
- var out = new Array(8);
200
- var b = this.buffer, o = this.offset;
201
- for (var i = 0; i < 8; i++) {
202
- out[i] = _HEX[b[o+i]];
203
- }
204
- return out.join(sep || '');
205
- },
206
-
207
- /**
208
- * Returns the int64's 8 bytes in a buffer.
209
- *
210
- * @param {bool} [rawBuffer=false] If no offset and this is true, return the internal buffer. Should only be used if
211
- * you're discarding the Int64 afterwards, as it breaks encapsulation.
212
- */
213
- toBuffer: function(rawBuffer) {
214
- if (rawBuffer && this.offset === 0) return this.buffer;
215
-
216
- var out = new Buffer(8);
217
- this.buffer.copy(out, 0, this.offset, this.offset + 8);
218
- return out;
219
- },
220
-
221
- /**
222
- * Copy 8 bytes of int64 into target buffer at target offset.
223
- *
224
- * @param {Buffer} targetBuffer Buffer to copy into.
225
- * @param {number} [targetOffset=0] Offset into target buffer.
226
- */
227
- copy: function(targetBuffer, targetOffset) {
228
- this.buffer.copy(targetBuffer, targetOffset || 0, this.offset, this.offset + 8);
229
- },
230
-
231
- /**
232
- * Returns a number indicating whether this comes before or after or is the
233
- * same as the other in sort order.
234
- *
235
- * @param {Int64} other Other Int64 to compare.
236
- */
237
- compare: function(other) {
238
-
239
- // If sign bits differ ...
240
- if ((this.buffer[this.offset] & 0x80) != (other.buffer[other.offset] & 0x80)) {
241
- return other.buffer[other.offset] - this.buffer[this.offset];
242
- }
243
-
244
- // otherwise, compare bytes lexicographically
245
- for (var i = 0; i < 8; i++) {
246
- if (this.buffer[this.offset+i] !== other.buffer[other.offset+i]) {
247
- return this.buffer[this.offset+i] - other.buffer[other.offset+i];
248
- }
249
- }
250
- return 0;
251
- },
252
-
253
- /**
254
- * Returns a boolean indicating if this integer is equal to other.
255
- *
256
- * @param {Int64} other Other Int64 to compare.
257
- */
258
- equals: function(other) {
259
- return this.compare(other) === 0;
260
- },
261
-
262
- /**
263
- * Pretty output in console.log
264
- */
265
- inspect: function() {
266
- return '[Int64 value:' + this + ' octets:' + this.toOctetString(' ') + ']';
267
- }
268
- };
@@ -1,19 +0,0 @@
1
- Copyright (c) 2014 Robert Kieffer
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
@@ -1,78 +0,0 @@
1
- JavaScript Numbers are represented as [IEEE 754 double-precision floats](http://steve.hollasch.net/cgindex/coding/ieeefloat.html). Unfortunately, this means they lose integer precision for values beyond +/- 2^^53. For projects that need to accurately handle 64-bit ints, such as [node-thrift](https://github.com/wadey/node-thrift), a performant, Number-like class is needed. Int64 is that class.
2
-
3
- Int64 instances look and feel much like JS-native Numbers. By way of example ...
4
- ```js
5
- // First, let's illustrate the problem ...
6
- > (0x123456789).toString(16)
7
- '123456789' // <- what we expect.
8
- > (0x123456789abcdef0).toString(16)
9
- '123456789abcdf00' // <- Ugh! JS doesn't do big ints. :(
10
-
11
- // So let's create a couple Int64s using the above values ...
12
-
13
- // Require, of course
14
- > Int64 = require('node-int64')
15
-
16
- // x's value is what we expect (the decimal value of 0x123456789)
17
- > x = new Int64(0x123456789)
18
- [Int64 value:4886718345 octets:00 00 00 01 23 45 67 89]
19
-
20
- // y's value is Infinity because it's outside the range of integer
21
- // precision. But that's okay - it's still useful because it's internal
22
- // representation (octets) is what we passed in
23
- > y = new Int64('123456789abcdef0')
24
- [Int64 value:Infinity octets:12 34 56 78 9a bc de f0]
25
-
26
- // Let's do some math. Int64's behave like Numbers. (Sorry, Int64 isn't
27
- // for doing 64-bit integer arithmetic (yet) - it's just for carrying
28
- // around int64 values
29
- > x + 1
30
- 4886718346
31
- > y + 1
32
- Infinity
33
-
34
- // Int64 string operations ...
35
- > 'value: ' + x
36
- 'value: 4886718345'
37
- > 'value: ' + y
38
- 'value: Infinity'
39
- > x.toString(2)
40
- '100100011010001010110011110001001'
41
- > y.toString(2)
42
- 'Infinity'
43
-
44
- // Use JS's isFinite() method to see if the Int64 value is in the
45
- // integer-precise range of JS values
46
- > isFinite(x)
47
- true
48
- > isFinite(y)
49
- false
50
-
51
- // Get an octet string representation. (Yay, y is what we put in!)
52
- > x.toOctetString()
53
- '0000000123456789'
54
- > y.toOctetString()
55
- '123456789abcdef0'
56
-
57
- // Finally, some other ways to create Int64s ...
58
-
59
- // Pass hi/lo words
60
- > new Int64(0x12345678, 0x9abcdef0)
61
- [Int64 value:Infinity octets:12 34 56 78 9a bc de f0]
62
-
63
- // Pass a Buffer
64
- > new Int64(new Buffer([0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0]))
65
- [Int64 value:Infinity octets:12 34 56 78 9a bc de f0]
66
-
67
- // Pass a Buffer and offset
68
- > new Int64(new Buffer([0,0,0,0,0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0]), 4)
69
- [Int64 value:Infinity octets:12 34 56 78 9a bc de f0]
70
-
71
- // Pull out into a buffer
72
- > new Int64(new Buffer([0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0])).toBuffer()
73
- <Buffer 12 34 56 78 9a bc de f0>
74
-
75
- // Or copy into an existing one (at an offset)
76
- > var buf = new Buffer(1024);
77
- > new Int64(new Buffer([0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0])).copy(buf, 512);
78
- ```
@@ -1,27 +0,0 @@
1
- {
2
- "name": "node-int64",
3
- "description": "Support for representing 64-bit integers in JavaScript",
4
- "url": "http://github.com/broofa/node-int64",
5
- "keywords": [
6
- "math",
7
- "integer",
8
- "int64"
9
- ],
10
- "author": "Robert Kieffer <robert@broofa.com>",
11
- "contributors": [],
12
- "dependencies": {},
13
- "license": "MIT",
14
- "lib": ".",
15
- "main": "./Int64.js",
16
- "version": "0.4.0",
17
- "scripts": {
18
- "test": "nodeunit test.js"
19
- },
20
- "repository": {
21
- "type": "git",
22
- "url": "https://github.com/broofa/node-int64"
23
- },
24
- "devDependencies": {
25
- "nodeunit": "^0.9.0"
26
- }
27
- }