From 8328434717f392372292369539484d318b36dbd8 Mon Sep 17 00:00:00 2001 From: James Ferguson Date: Sun, 22 Dec 2019 18:27:59 +1100 Subject: [PATCH] fix: remove any-observable Removes the any-observable package. Maintaining support for it proved too much of a hassle for the value it presented. The RxJS library is quite obviously the defacto Observable library and the new Neo4j driver also uses RxJS observables. BREAKING CHANGE: Removes the any-observable package --- package.json | 1 - src/connection.ts | 17 ++++++----------- src/query.spec.ts | 3 +-- src/query.ts | 8 +++----- tests/connection.test.ts | 3 +-- typings/any-observable/index.d.ts | 4 ---- yarn.lock | 5 ----- 7 files changed, 11 insertions(+), 30 deletions(-) delete mode 100644 typings/any-observable/index.d.ts diff --git a/package.json b/package.json index bd51544f..5d91cd79 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,6 @@ "dependencies": { "@types/lodash": "^4.14.136", "@types/node": "^12.6.1", - "any-observable": "^0.5.0", "lodash": "^4.17.15", "neo4j-driver": "^4.0.1", "node-cleanup": "^2.1.2", diff --git a/src/connection.ts b/src/connection.ts index 591b2afd..70679bae 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -1,5 +1,3 @@ -// tslint:disable-next-line import-name -import Observable from 'any-observable'; import { Dictionary, isFunction } from 'lodash'; import nodeCleanup from 'node-cleanup'; import { AuthToken, Config, Driver, Session } from 'neo4j-driver/types'; @@ -8,6 +6,7 @@ import { Transformer } from './transformer'; import { Query } from './query'; import { Builder } from './builder'; import { Clause } from './clause'; +import { Observable } from 'rxjs'; let connections: Connection[] = []; @@ -257,7 +256,7 @@ export class Connection extends Builder { * Runs the provided query on this connection, regardless of which connection * the query was created from. Each query is run on it's own session. * - * Returns an observable that emits each record as it is received from the + * Returns an RxJS observable that emits each record as it is received from the * database. This is the most efficient way of working with very large * datasets. Each record is an object where each key is the name of a variable * that you specified in your return clause. @@ -292,11 +291,6 @@ export class Connection extends Builder { * const friends$ = results$.map(row => row.friends); * ``` * - * The observable class that is used is imported from - * [any-observable](https://github.com/sindresorhus/any-observable) by default - * it uses rxjs for the observables, but you can pick a different implementation - * by registering it with any-observable before importing this module. - * * If you use typescript you can use the type parameter to hint at the type of * the return value which is `Dictionary`. * @@ -323,18 +317,19 @@ export class Connection extends Builder { stream(query: Query): Observable> { return new Observable((subscriber: Observer>): void => { if (!this.open) { - subscriber.error(new Error('Cannot run query; connection is not open.')); + subscriber.error(new Error('Cannot run query: connection is not open.')); return; } if (query.getClauses().length === 0) { - subscriber.error(Error('Cannot run query: no clauses attached to the query.')); + subscriber.error(new Error('Cannot run query: no clauses attached to the query.')); return; } const session = this.session(); if (!session) { - throw Error('Cannot run query: connection is not open.'); + subscriber.error(new Error('Cannot run query: connection is not open.')); + return; } // Run the query diff --git a/src/query.spec.ts b/src/query.spec.ts index 81ef0307..89f89e43 100644 --- a/src/query.spec.ts +++ b/src/query.spec.ts @@ -1,5 +1,3 @@ -// tslint:disable-next-line import-name -import Observable from 'any-observable'; import { Dictionary, each } from 'lodash'; import { spy, stub } from 'sinon'; import { expect } from '../test-setup'; @@ -7,6 +5,7 @@ import { mockConnection } from '../tests/connection.mock'; import { ClauseCollection } from './clause-collection'; import { node, NodePattern } from './clauses'; import { Query } from './query'; +import { Observable } from 'rxjs'; describe('Query', () => { describe('query methods', () => { diff --git a/src/query.ts b/src/query.ts index 8f152756..f4c49fde 100644 --- a/src/query.ts +++ b/src/query.ts @@ -1,6 +1,4 @@ -// tslint:disable-next-line import-name -import Observable from 'any-observable'; -import { Observable as RxObservable } from 'rxjs'; +import { Observable } from 'rxjs'; import { Dictionary } from 'lodash'; import { Connection, Observer } from './connection'; import { Builder } from './builder'; @@ -86,7 +84,7 @@ export class Query extends Builder { * chainable method of a connection, then its connection was automatically * set. * - * Returns an observable that emits each record as it is received from the + * Returns an RxJS observable that emits each record as it is received from the * database. This is the most efficient way of working with very large * datasets. Each record is an object where each key is the name of a variable * that you specified in your return clause. @@ -127,7 +125,7 @@ export class Query extends Builder { * Throws an exception if this query does not have a connection or has no * clauses. */ - stream(): RxObservable> { + stream(): Observable> { if (!this.connection) { return new Observable((subscriber: Observer>): void => { subscriber.error(new Error('Cannot run query; no connection object available.')); diff --git a/tests/connection.test.ts b/tests/connection.test.ts index bc305a2d..475c8734 100644 --- a/tests/connection.test.ts +++ b/tests/connection.test.ts @@ -1,9 +1,8 @@ -// tslint:disable-next-line import-name -import Observable from 'any-observable'; import { Dictionary, each } from 'lodash'; import * as neo4j from 'neo4j-driver'; import { Driver, Session } from 'neo4j-driver/types'; import { AuthToken, Config } from 'neo4j-driver/types/driver'; +import { Observable } from 'rxjs'; import { tap } from 'rxjs/operators'; import { SinonSpy, SinonStub, spy, stub } from 'sinon'; import { Connection, Node, Query } from '../src'; diff --git a/typings/any-observable/index.d.ts b/typings/any-observable/index.d.ts deleted file mode 100644 index 0c8777c3..00000000 --- a/typings/any-observable/index.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -declare module 'any-observable' { - import { Observable } from 'rxjs'; - export = Observable; -} diff --git a/yarn.lock b/yarn.lock index 0e2c2110..fb75c618 100644 --- a/yarn.lock +++ b/yarn.lock @@ -656,11 +656,6 @@ ansistyles@~0.1.3: resolved "https://registry.yarnpkg.com/ansistyles/-/ansistyles-0.1.3.tgz#5de60415bda071bb37127854c864f41b23254539" integrity sha1-XeYEFb2gcbs3EnhUyGT0GyMlRTk= -any-observable@^0.5.0: - version "0.5.0" - resolved "https://registry.yarnpkg.com/any-observable/-/any-observable-0.5.0.tgz#2dc6af0382b67cfd1a49e1f65e515196d4e32d38" - integrity sha512-GnS7zaS5yBufhXeqfROuyt//AlqrN6dNHTN0Ex6vy22cIyUdeJY46rll8WLVmbV2yV2DEEl3HjspPLVLS79YZw== - append-transform@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/append-transform/-/append-transform-1.0.0.tgz#046a52ae582a228bd72f58acfbe2967c678759ab"