Skip to content

Commit

Permalink
fix: remove any-observable
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jamesfer committed Sep 17, 2020
1 parent a08828a commit 8328434
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 30 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -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",
Expand Down
17 changes: 6 additions & 11 deletions 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';
Expand All @@ -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[] = [];

Expand Down Expand Up @@ -257,7 +256,7 @@ export class Connection extends Builder<Query> {
* 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.
Expand Down Expand Up @@ -292,11 +291,6 @@ export class Connection extends Builder<Query> {
* 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<R>`.
*
Expand All @@ -323,18 +317,19 @@ export class Connection extends Builder<Query> {
stream<R = any>(query: Query): Observable<Dictionary<R>> {
return new Observable((subscriber: Observer<Dictionary<R>>): 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
Expand Down
3 changes: 1 addition & 2 deletions src/query.spec.ts
@@ -1,12 +1,11 @@
// 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';
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', () => {
Expand Down
8 changes: 3 additions & 5 deletions 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';
Expand Down Expand Up @@ -86,7 +84,7 @@ export class Query extends Builder<Query> {
* 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.
Expand Down Expand Up @@ -127,7 +125,7 @@ export class Query extends Builder<Query> {
* Throws an exception if this query does not have a connection or has no
* clauses.
*/
stream<R = any>(): RxObservable<Dictionary<R>> {
stream<R = any>(): Observable<Dictionary<R>> {
if (!this.connection) {
return new Observable((subscriber: Observer<Dictionary<R>>): void => {
subscriber.error(new Error('Cannot run query; no connection object available.'));
Expand Down
3 changes: 1 addition & 2 deletions 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';
Expand Down
4 changes: 0 additions & 4 deletions typings/any-observable/index.d.ts

This file was deleted.

5 changes: 0 additions & 5 deletions yarn.lock
Expand Up @@ -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"
Expand Down

0 comments on commit 8328434

Please sign in to comment.