Skip to content

AsyncIterator API for Result consumption #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,7 @@ var driver = neo4j.driver(
## Building

```
./buildDependencies.sh
npm install
npm ci
npm run build
```

Expand Down
8 changes: 0 additions & 8 deletions buildDependencies.sh

This file was deleted.

6 changes: 6 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"packages": [
"packages/*"
],
"version": "4.4.0-dev"
}
18,105 changes: 4,641 additions & 13,464 deletions package-lock.json

Large diffs are not rendered by default.

121 changes: 13 additions & 108 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,113 +1,18 @@
{
"name": "neo4j-driver",
"version": "4.3.0-dev",
"description": "Connect to Neo4j 3.5.0 and up from JavaScript",
"author": "Neo4j",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "git://github.com/neo4j/neo4j-javascript-driver.git"
},
"scripts": {
"lint": "eslint --fix --ext .js ./",
"format": "prettier-eslint '**/*.js' '**/*.json' '**/*.md' '**/*.ts' '**/*.html' --write",
"test": "gulp test",
"build": "gulp all",
"start-neo4j": "gulp start-neo4j",
"stop-neo4j": "gulp stop-neo4j",
"run-stress-tests": "gulp run-stress-tests-without-jasmine",
"run-ts-declaration-tests": "gulp run-ts-declaration-tests",
"predocs": "cd core && npm run docs",
"docs": "esdoc -c esdoc.json",
"versionRelease": "gulp set --x $VERSION && npm version $VERSION --no-git-tag-version",
"browser": "gulp browser && gulp test-browser"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,json,ts,md,html}": [
"prettier-eslint --write",
"git add"
]
},
"main": "lib/index.js",
"browser": {
"./lib/internal/node/index.js": "./lib/internal/browser/index.js"
},
"unpkg": "lib/browser/neo4j-web.js",
"jsdelivr": "lib/browser/neo4j-web.js",
"types": "types/index.d.ts",
"name": "root",
"private": true,
"devDependencies": {
"@babel/core": "^7.5.5",
"@babel/plugin-transform-runtime": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/register": "^7.5.5",
"@istanbuljs/nyc-config-babel": "^2.1.1",
"async": "^3.2.0",
"babel-eslint": "^10.0.3",
"babel-plugin-istanbul": "^5.2.0",
"babelify": "^10.0.0",
"browserify": "^16.5.0",
"browserify-transform-tools": "^1.7.0",
"esdoc": "^1.1.0",
"esdoc-importpath-plugin": "^1.0.2",
"esdoc-standard-plugin": "^1.0.0",
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.23.3",
"eslint-plugin-jasmine": "^2.10.1",
"eslint-plugin-node": "^9.2.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"fancy-log": "^1.3.3",
"fs-extra": "^8.1.0",
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"gulp-batch": "^1.0.5",
"gulp-decompress": "^2.0.3",
"gulp-download": "^0.0.1",
"gulp-file": "^0.4.0",
"gulp-install": "^1.1.0",
"gulp-jasmine": "^4.0.0",
"gulp-replace": "^1.1.3",
"gulp-typescript": "^5.0.1",
"gulp-uglify": "^3.0.2",
"gulp-watch": "^5.0.1",
"husky": "^3.1.0",
"istanbul": "^0.4.5",
"jasmine-spec-reporter": "^4.2.1",
"karma": "^4.4.1",
"karma-browserify": "^6.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-edge-launcher": "^0.4.2",
"karma-firefox-launcher": "^1.3.0",
"karma-ie-launcher": "^1.0.0",
"karma-jasmine": "^2.0.1",
"karma-source-map-support": "^1.4.0",
"karma-spec-reporter": "^0.0.32",
"lint-staged": "^9.5.0",
"lodash": "^4.17.20",
"lolex": "^4.2.0",
"minimist": "^1.2.5",
"mustache": "^3.2.1",
"nyc": "^14.1.1",
"prettier-eslint": "^9.0.2",
"prettier-eslint-cli": "^5.0.0",
"run-sequence": "^2.2.1",
"semver": "^6.3.0",
"tmp": "0.1.0",
"typescript": "^3.9.7",
"vinyl-buffer": "^1.0.1",
"vinyl-source-stream": "^2.0.0",
"webpack": "^4.44.2"
"lerna": "^4.0.0"
},
"dependencies": {
"@babel/runtime": "^7.5.5",
"neo4j-driver-bolt-connection": "file:./bolt-connection",
"neo4j-driver-core": "file:./core",
"rxjs": "^6.6.3"
"scripts": {
"clean": "lerna clean -y && lerna run clean",
"build": "lerna bootstrap --ci",
"test::unit": "lerna run test::unit --stream",
"test::integration": "lerna run test::integration --stream",
"test::stress": "lerna run test::stress --stream",
"test": "lerna run test --stream",
"start-neo4j": "lerna run start-neo4j --scope neo4j-driver",
"stop-neo4j": "lerna run stop-neo4j --scope neo4j-driver",
"lerna": "lerna"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 13 additions & 3 deletions bolt-connection/README.md → packages/bolt-connection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@ This is an internal package shared by the [neo4j-driver](https://www.npmjs.com/p

## Building

It's required to first build the `neo4j-driver-core` under the `../core` (see instruction on its folder). Then,
The build of this package is handled by the root package of this repository.

First it is needed to install the mono-repo dependencies by running `npm ci` in the root of the repository. Then:

* Build all could be performed with


```
npm install
npm run build
```
* Build only the Core could be performed with
Builind only Core:
```
npm run build -- --scope=neo4j-driver-bolt-connection

```

This produces a Node.js module version under `lib/`.

## Testing

The tests can be executed by running `npm test`. For development, you can have the build tool rerun the tests each time you change the source code:
The tests could be executed by running `npm test` in this package folder. For development, you can have the build tool rerun the tests each time you change the source code:

```
npm run test::watch
Expand Down
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"name": "neo4j-driver-bolt-connection",
"version": "4.3.0-dev",
"version": "4.4.0-dev",
"description": "Implements the connection with the Neo4j Database using the Bolt Protocol",
"main": "lib/index.js",
"types": "types/index.d.ts",
"scripts": {
"build": "tsc",
"test": "jest --passWithNoTests",
"test::watch": "jest --watch"
"test::watch": "jest --watch",
"test::unit": "npm run test",
"prepare": "npm run build",
"clean": "rm -fr node_modules lib"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -35,7 +38,7 @@
"typescript": "^4.1.3"
},
"dependencies": {
"neo4j-driver-core": "file:../core",
"neo4j-driver-core": "^4.4.0-dev",
"text-encoding-utf-8": "^1.0.2"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 14 additions & 2 deletions core/README.md → packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,28 @@ This is a internal package shared by the [neo4j-driver](https://www.npmjs.com/pa

## Building

The build of this package is handled by the root package of this repository.

First it is needed to install the mono-repo dependencies by running `npm ci` in the root of the repository. Then:

* Build all could be performed with


```
npm install
npm run build
```
* Build only the Core could be performed with
Builind only Core:
```
npm run build -- --scope=neo4j-driver-core

```

This produces a Node.js module version under `lib/`.

## Testing

The tests could be executed by running `npm test`. For development, you can have the build tool rerun the tests each time you change the source code:
The tests could be executed by running `npm test` in this package folder. For development, you can have the build tool rerun the tests each time you change the source code:

```
npm run test::watch
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion core/package-lock.json → packages/core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions core/package.json → packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "neo4j-driver-core",
"version": "4.3.0-dev",
"version": "4.4.0-dev",
"description": "Internals of neo4j-driver",
"main": "lib/index.js",
"types": "types/index.d.ts",
Expand All @@ -9,8 +9,11 @@
"build::es6": "tsc --target ES6 --outdir lib6",
"test": "jest",
"test::watch": "jest --watch",
"test::unit": "npm run test",
"predocs": "npm run build && npm run build::es6",
"docs": "esdoc -c esdoc.json"
"docs": "esdoc -c esdoc.json",
"prepare": "npm run build",
"clean": "rm -fr node_modules lib types"
},
"repository": {
"type": "git",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
52 changes: 52 additions & 0 deletions core/src/result.ts → packages/core/src/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,58 @@ class Result implements Promise<QueryResult> {
return this._p
}

async* [Symbol.asyncIterator](): AsyncIterator<Record, ResultSummary> {
interface ConsumedValue {
done: boolean
record?: Record
summary?: ResultSummary
}

interface ResolvablePromise<T> {
promise: Promise<T>
resolve: (arg: T) => any | undefined
reject: (arg: Error) => any | undefined
}

function createResolvablePromise (): ResolvablePromise<ConsumedValue> {
const resolvablePromise: any = {}
resolvablePromise.promise = new Promise((resolve, reject) => {
resolvablePromise.resolve = resolve
resolvablePromise.reject = reject
});
return resolvablePromise;
}

const observer = {
_buffer: [createResolvablePromise()],
onNext: (record: Record) => {
observer._buffer[observer._buffer.length - 1].resolve({ record, done: false });
observer._buffer.push(createResolvablePromise());
},
onCompleted: (summary: ResultSummary) => {
observer._buffer[observer._buffer.length - 1].resolve({ summary, done: true });
},
onError: (error: Error) => {
observer._buffer[observer._buffer.length - 1].reject(error);
},
consume: async () => {
const value = await observer._buffer[0].promise
observer._buffer.shift();
return value
}
}

this.subscribe(observer)

while(true) {
const value = await observer.consume()
if (value.done) {
return value.summary!
}
yield value.record!
}
}

/**
* Waits for all results and calls the passed in function with the results.
*
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,20 @@ var driver = neo4j.driver(

## Building

The build of this package is handled by the root package of this repository.

First it is needed to install the mono-repo dependencies by running `npm ci` in the root of the repository. Then:

* Build all could be performed with

```
./buildDependencies.sh
npm install
npm run build
npn rub build:browser
```
* Build only the Core could be performed with
Builind only Core:
```
npm run build -- --scope=neo4j-driver-lite

```

This produces browser-compatible standalone files under `lib/browser` and a Node.js module version under `lib/`.
Expand Down Expand Up @@ -399,14 +408,12 @@ python3 main.py

More details about how to use Teskit could be found on [its repository](https://github.com/neo4j-drivers/testkit/tree/4.3)

Simple `npm test` can also be used if you want to run only the unit tests.
Runing `npm test` in this package directory can also be used if you want to run only the unit tests.

For development, you can have the build tool rerun the tests each time you change the source code:

```
npm run test:watch
```

The guides about how to test the driver internal dependencies should be found on it own Readme files.

See `../core` and `../bolt-connection`
The command `npm run test::unit` could be used in the root package for running the unit tests for all the packages in this project.
File renamed without changes.
Loading