Skip to content

Commit a414253

Browse files
committed
Deprecate exposing Integer
It does not make sense to expose the `Integer` type to users. Users should use a framework of their liking instead and we only expose `inSafeRange`, `toNumber` and `toString` functions.
1 parent 77e0689 commit a414253

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ While there is no need to grab admin right if you are running tests against an e
138138
## A note on numbers and the Integer type
139139
The Neo4j type system includes 64-bit integer values.
140140
However, Javascript can only safely represent integers between `-(2`<sup>`53`</sup>` - 1)` and `(2`<sup>`53`</sup>` - 1)`.
141-
In order to support the full Neo4j type system, the driver includes an explicit Integer types.
142-
Any time the driver recieves an Integer value from Neo4j, it will be represented with the Integer type by the driver.
141+
In order to support the full Neo4j type system, the driver will not automatically convert to javascript integers.
142+
Any time the driver receives an integer value from Neo4j, it will be represented with an internal integer type by the driver.
143143

144144
### Write integers
145145
Number written directly e.g. `session.run("CREATE (n:Node {age: {age}})", {age: 22})` will be of type `Float` in Neo4j.
@@ -158,19 +158,22 @@ session.run("CREATE (n {age: {myIntParam}})", {myIntParam: neo4j.int("9223372036
158158
```
159159

160160
### Read integers
161-
Since Integers can be larger than can be represented as JavaScript numbers, it is only safe to convert Integer instances to JavaScript numbers if you know that they will not exceed `(2`<sup>`53`</sup>` - 1)` in size:
161+
Since Integers can be larger than can be represented as JavaScript numbers, it is only safe to convert to JavaScript numbers if you know that they will not exceed `(2`<sup>`53`</sup>` - 1)` in size.
162+
In order to facilitate working with integers the driver include `neo4j.isInt`, `neo4j.integer.inSafeRange`, `neo4j.integer.toNumber`, and `neo4j.integer.toString`.
162163

163164
```javascript
164165
var aSmallInteger = neo4j.int(123);
165-
var aNumber = aSmallInteger.toNumber();
166+
if (neo4j.integer.inSafeRange(aSmallInteger)) {
167+
var aNumber = aSmallInteger.toNumber();
168+
}
166169
```
167170

168-
If you will be handling integers larger than that, you can use the Integer instances directly, or convert them to strings:
171+
If you will be handling integers larger than that, you can should convert them to strings:
169172

170173
```javascript
171174
var aLargerInteger = neo4j.int("9223372036854775807");
172-
var integerAsString = aLargerInteger.toString();
175+
if (!neo4j.integer.inSafeRange(aSmallInteger)) {
176+
var integerAsString = aLargerInteger.toString();
177+
}
173178
```
174179

175-
To help you work with Integers, the Integer class exposes a large set of arithmetic methods.
176-
Refer to the [Integer API docs](http://neo4j.com/docs/api/javascript-driver/current/class/src/v1/integer.js~Integer.html) for details.

src/v1/integer.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import {newError} from "./error";
3232
* @param {number} low The low (signed) 32 bits of the long
3333
* @param {number} high The high (signed) 32 bits of the long
3434
* @constructor
35+
*
36+
* @deprecated This class will be removed or made internal in a future version of the driver.
3537
*/
3638
class Integer {
3739
constructor(low, high) {
@@ -841,16 +843,16 @@ Integer.MIN_VALUE = Integer.fromBits(0, 0x80000000|0, false);
841843
/**
842844
* Minimum safe value.
843845
* @type {!Integer}
844-
* @private
846+
* @expose
845847
*/
846-
Integer.MIN_SAFE_VALUE = Integer.fromNumber(Number.MIN_SAFE_INTEGER);
848+
Integer.MIN_SAFE_VALUE = Integer.fromBits(0x1|0, 0xFFFFFFFFFFE00000|0);
847849

848850
/**
849851
* Maximum safe value.
850852
* @type {!Integer}
851-
* @private
853+
* @expose
852854
*/
853-
Integer.MAX_SAFE_VALUE = Integer.fromNumber(Number.MAX_SAFE_INTEGER);
855+
Integer.MAX_SAFE_VALUE = Integer.fromBits(0xFFFFFFFF|0,0x1FFFFF|0);
854856

855857
/**
856858
* Cast value to Integer type.

test/v1/integer.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,4 @@ describe('Pool', function() {
4040
expect(integer.toString(int("-9007199254740991"))).toEqual("-9007199254740991");
4141
expect(integer.toString(int("-9007199254740992"))).toEqual("-9007199254740992");
4242
});
43-
4443
});

0 commit comments

Comments
 (0)