Skip to content

Commit 7b9cd09

Browse files
authored
Preparing the preview release of Deno driver (neo4j#1149)
* Add preview alert when init the driver * Add README.md * Set version * Alpha 01 * Add fix driver name * Add script for bump deno version * Add missing file * Set correct version
1 parent e26619c commit 7b9cd09

File tree

10 files changed

+321
-50
lines changed

10 files changed

+321
-50
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"scripts": {
4141
"clean": "lerna clean -y && lerna run clean",
4242
"build": "lerna bootstrap --ci",
43-
"build::deno": "cd ./packages/neo4j-driver-deno && deno run --allow-read --allow-write --allow-net ./generate.ts --version=5.0.0-dev",
43+
"set_version::deno": "cd ./packages/neo4j-driver-deno && deno run --allow-read --allow-write ./versioning.ts --output=. --filename=current.version.ts",
44+
"build::deno": "cd ./packages/neo4j-driver-deno && deno run --allow-read --allow-write --allow-net ./generate.ts",
4445
"build::notci": "lerna bootstrap",
4546
"docs": "lerna run docs --stream --concurrency 1",
4647
"test::unit": "lerna run test::unit --stream",

packages/core/src/internal/bolt-agent/deno/bolt-agent.ts

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export function fromVersion (
5656
const DENO_VERSION = `Deno/${systemInfo.denoVersion}`
5757
const OS_NAME_VERSION = `${systemInfo.osVersion} ${systemInfo.osRelease}`.trim()
5858

59+
console.warn("WARNING! neo4j-driver-deno stills in preview.")
60+
5961
return {
6062
product: `neo4j-javascript/${version}`,
6163
platform: `${OS_NAME_VERSION}; ${systemInfo.hostArch}`,

packages/core/test/deno/internal/bolt-agent/deno/bolt-agent.test.ts

+25
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,29 @@ Deno.test('Test full bolt agent for mocked values', () => {
5959
languageDetails: `Deno/1.19.1 (v8 8.1.39)`
6060
})
6161
});
62+
63+
// @ts-ignore
64+
Deno.test('Test full bolt agent for mocked values', () => {
65+
const originalConsoleWarn = console.warn
66+
const consoleWarnCalls = [] as any[][]
67+
const myConsoleWarn = (...args: any[]) => consoleWarnCalls.push(args)
68+
69+
try {
70+
console.warn = myConsoleWarn;
71+
72+
fromVersion('5.3')
73+
74+
assertEquals(consoleWarnCalls.length, 1)
75+
assertEquals(consoleWarnCalls[0].length, 1)
76+
77+
const [[message]] = consoleWarnCalls
78+
79+
assertEquals(message, "WARNING! neo4j-driver-deno stills in preview.")
80+
} finally {
81+
console.warn = originalConsoleWarn
82+
}
83+
84+
});
85+
86+
6287
/* eslint-enable */

packages/neo4j-driver-deno/README.md

+105-37
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,131 @@
1-
# Neo4j Driver for Deno (Experimental)
1+
# Neo4j Lite Driver for Deno (Preview)
22

3-
This folder contains a script which can auto-generate a version of
4-
`neo4j-driver-lite` that is fully compatible with Deno, including complete type
5-
information.
3+
> :warning: **This package stills a PREVIEW version.**
64
7-
The resulting driver does not use any dependencies outside of the Deno standard
8-
library.
5+
This is the Deno version of the official Neo4j driver for JavaScript.
96

10-
## Development instructions
7+
This version of driver is based in the `neo4j-driver-lite`.
8+
So, this version has the same capabilities as the Neo4j Driver except for the support of reactive sessions.
9+
This means it doesn't have the `RxJS` dependency and the `Driver#rxSession` api.
1110

12-
To generate the driver, open a shell in this folder and run this command,
13-
specifying what version number you want the driver to identify as:
11+
Starting with 5.0, the Neo4j Drivers will be moving to a monthly release cadence. A minor version will be released on the last Friday of each month so as to maintain versioning consistency with the core product (Neo4j DBMS) which has also moved to a monthly cadence.
1412

15-
```
16-
deno run --allow-read --allow-write --allow-net ./generate.ts --version=4.4.0
13+
As a policy, patch versions will not be released except on rare occasions. Bug fixes and updates will go into the latest minor version and users should upgrade to that. Driver upgrades within a major version will never contain breaking API changes.
14+
15+
See also: https://neo4j.com/developer/kb/neo4j-supported-versions/
16+
17+
Resources to get you started:
18+
19+
- [API Documentation](https://neo4j.com/docs/api/javascript-driver/current/)
20+
- [Neo4j Manual](https://neo4j.com/docs/)
21+
- [Neo4j Refcard](https://neo4j.com/docs/cypher-refcard/current/)
22+
- [TLS](#tls)
23+
24+
## What's New in 5.x
25+
26+
- [Changelog](https://github.com/neo4j/neo4j-javascript-driver/wiki/5.0-changelog)
27+
28+
## Usage
29+
30+
Importing the driver:
31+
32+
```typescript
33+
import neo4j from "https://deno.land/x/neo4j_driver_lite@VERSION/mod.ts";
1734
```
1835

19-
The script will:
36+
Driver instance should be closed when application exits:
2037

21-
1. Copy `neo4j-driver-lite` and the Neo4j packages it uses into a subfolder here
22-
called `lib`.
23-
1. Rewrite all imports to Deno-compatible versions
24-
1. Replace the "node channel" with the "deno channel"
25-
1. Test that the resulting driver can be imported by Deno and passes type checks
38+
```javascript
39+
await driver.close()
40+
```
41+
otherwise the application shutdown might hang or exit with a non-zero exit code.
2642

27-
It is not necessary to do any other setup first; in particular, you don't need
28-
to install any of the Node packages or run any of the driver monorepo's other
29-
scripts. However, you do need to have Deno installed.
43+
Application which uses the should use `--allow-net --allow-sys...` for running.
44+
For Deno versions bellow `1.27.1`, you should use the flag `--allow-env` instead of `--allow-sys`.
3045

31-
## Usage instructions
46+
### TLS
3247

33-
Once the driver is generated in the `lib` directory, you can import it and use
34-
it as you would use `neo4j-driver-lite` (refer to its documentation).
48+
For using system certificates, the `DENO_TLS_CA_STORE` should be set to `"system"`.
49+
`TRUST_ALL_CERTIFICATES` should be handle by `--unsafely-ignore-certificate-errors` and not by driver configuration. See, https://deno.com/blog/v1.13#disable-tls-verification;
3550

36-
Here is an example:
51+
### Basic Example
3752

3853
```typescript
39-
import neo4j from "./lib/mod.ts";
4054
const URI = "bolt://localhost:7687";
4155
const driver = neo4j.driver(URI, neo4j.auth.basic("neo4j", "driverdemo"));
42-
const session = driver.session();
4356

44-
const results = await session.run("MATCH (n) RETURN n LIMIT 25");
45-
console.log(results.records);
57+
const { records } = await driver.executeQuery("MATCH (n) RETURN n LIMIT 25");
58+
console.log(records);
4659

47-
await session.close();
4860
await driver.close();
61+
4962
```
5063

51-
You can use `deno run --allow-net --allow-sys...` or `deno repl` to run this example.
64+
### Numbers and the Integer type
5265

53-
For Deno versions bellow `1.27.1`, you should use the flag `--allow-env` instead of `--allow-sys`.
66+
The Neo4j type system uses 64-bit signed integer values. The range of values is between `-(2`<sup>`64`</sup>`- 1)` and `(2`<sup>`63`</sup>`- 1)`.
5467

55-
If you don't have a running Neo4j instance, you can use
56-
`docker run --rm -p 7687:7687 -e NEO4J_AUTH=neo4j/driverdemo neo4j:4.4` to
57-
quickly spin one up.
68+
However, JavaScript can only safely represent integers between `Number.MIN_SAFE_INTEGER` `-(2`<sup>`53`</sup>`- 1)` and `Number.MAX_SAFE_INTEGER` `(2`<sup>`53`</sup>`- 1)`.
5869

59-
## TLS
70+
In order to support the full Neo4j type system, the driver will not automatically convert to javascript integers.
71+
Any time the driver receives an integer value from Neo4j, it will be represented with an internal integer type by the driver.
6072

61-
For using system certificates, the `DENO_TLS_CA_STORE` should be set to `"system"`.
62-
`TRUST_ALL_CERTIFICATES` should be handle by `--unsafely-ignore-certificate-errors` and not by driver configuration. See, https://deno.com/blog/v1.13#disable-tls-verification;
73+
_**Any javascript number value passed as a parameter will be recognized as `Float` type.**_
74+
75+
#### Writing integers
76+
77+
Numbers written directly e.g. `session.run("CREATE (n:Node {age: $age})", {age: 22})` will be of type `Float` in Neo4j.
78+
79+
To write the `age` as an integer the `neo4j.int` method should be used:
80+
81+
```javascript
82+
session.run('CREATE (n {age: $myIntParam})', { myIntParam: neo4j.int(22) })
83+
```
84+
85+
To write an integer value that are not within the range of `Number.MIN_SAFE_INTEGER` `-(2`<sup>`53`</sup>`- 1)` and `Number.MAX_SAFE_INTEGER` `(2`<sup>`53`</sup>`- 1)`, use a string argument to `neo4j.int`:
86+
87+
```javascript
88+
session.run('CREATE (n {age: $myIntParam})', {
89+
myIntParam: neo4j.int('9223372036854775807')
90+
})
91+
```
92+
93+
#### Reading integers
94+
95+
In Neo4j, the type Integer can be larger what can be represented safely as an integer with JavaScript Number.
96+
97+
It is only safe to convert to a JavaScript Number if you know that the number will be in the range `Number.MIN_SAFE_INTEGER` `-(2`<sup>`53`</sup>`- 1)` and `Number.MAX_SAFE_INTEGER` `(2`<sup>`53`</sup>`- 1)`.
98+
99+
In order to facilitate working with integers the driver include `neo4j.isInt`, `neo4j.integer.inSafeRange`, `neo4j.integer.toNumber`, and `neo4j.integer.toString`.
100+
101+
```javascript
102+
var smallInteger = neo4j.int(123)
103+
if (neo4j.integer.inSafeRange(smallInteger)) {
104+
var aNumber = smallInteger.toNumber()
105+
}
106+
```
107+
108+
If you will be handling integers that is not within the JavaScript safe range of integers, you should convert the value to a string:
109+
110+
```javascript
111+
var largeInteger = neo4j.int('9223372036854775807')
112+
if (!neo4j.integer.inSafeRange(largeInteger)) {
113+
var integerAsString = largeInteger.toString()
114+
}
115+
```
116+
117+
#### Enabling native numbers
118+
119+
Starting from 1.6 version of the driver it is possible to configure it to only return native numbers instead of custom `Integer` objects.
120+
The configuration option affects all integers returned by the driver. **Enabling this option can result in a loss of precision and incorrect numeric
121+
values being returned if the database contains integer numbers outside of the range** `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`.
122+
To enable potentially lossy integer values use the driver's configuration object:
123+
124+
```javascript
125+
var driver = neo4j.driver(
126+
'neo4j://localhost',
127+
neo4j.auth.basic('neo4j', 'password'),
128+
{ disableLosslessIntegers: true }
129+
)
130+
```
63131

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
export default "5.14.0-alpha01" // Specified using --version when running generate.ts

packages/neo4j-driver-deno/generate.ts

+7-11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as log from "https://deno.land/[email protected]/log/mod.ts";
1414
import { parse } from "https://deno.land/[email protected]/flags/mod.ts";
1515
import { ensureDir } from "https://deno.land/[email protected]/fs/mod.ts";
1616
import { join, relative } from "https://deno.land/[email protected]/path/mod.ts";
17+
import { setVersion } from "./versioning.ts"
1718

1819
const isDir = (path: string) => {
1920
try {
@@ -45,7 +46,7 @@ const parsedArgs = parse(Deno.args, {
4546
// Should we rewrite imports or simply copy the files unmodified?
4647
// Copying without changes can be useful to later generate a diff of the transforms
4748
const doTransform = parsedArgs["transform"];
48-
const version = parsedArgs.version ?? "0.0.0dev";
49+
const version = parsedArgs.version;
4950

5051
////////////////////////////////////////////////////////////////////////////////
5152
// Clear out the destination folder
@@ -174,22 +175,17 @@ await copyAndTransform(
174175
await copyAndTransform("../neo4j-driver-lite/src", rootOutDir);
175176
// Deno convention is to use "mod.ts" not "index.ts", so let's do that at least for the main/root import:
176177
await Deno.rename(join(rootOutDir, "index.ts"), join(rootOutDir, "mod.ts"))
177-
const copyright = await Deno.readTextFile("./copyright.txt");
178-
await Deno.writeTextFile(
179-
join(rootOutDir, "version.ts"),
180-
[copyright, `export default "${version}" // Specified using --version when running generate.ts\n`].join('\n'),
181-
);
178+
await setVersion(rootOutDir, version)
179+
180+
// Copy README.md
181+
const readmeFileName = "README.md"
182+
await Deno.copyFile(join(`./`, readmeFileName), join(rootOutDir, readmeFileName))
182183

183184
////////////////////////////////////////////////////////////////////////////////
184185
// Warnings show up at the end
185186
if (!doTransform) {
186187
log.warning("Transform step was skipped.");
187188
}
188-
if (!parsedArgs.version) {
189-
log.warning(
190-
"No version specified. Specify a version like this: --version=4.4.0",
191-
);
192-
}
193189

194190
////////////////////////////////////////////////////////////////////////////////
195191
// Now test the driver

0 commit comments

Comments
 (0)