Skip to content

Commit

Permalink
Bumped version to v6 of nact
Browse files Browse the repository at this point in the history
  • Loading branch information
ncthbrt committed Apr 4, 2018
1 parent 918ae5e commit f456548
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 110 deletions.
26 changes: 14 additions & 12 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
const { AbstractPersistenceEngine, PersistedEvent, PersistedSnapshot } = require('nact/lib/persistence');
require('rxjs');
const pgp = require('pg-promise')();
const Rx = require('rxjs');
const { create } = require('./schema');
const assert = require('assert');

class Result {
constructor (promise) {
this.promise = promise;
}
then (...args) {
return this.promise.then(...args);
}
reduce (...args) {
return this.promise.then(result => result.reduce(...args));
}
}

class PostgresPersistenceEngine extends AbstractPersistenceEngine {
constructor (connectionString, { createIfNotExists = true, tablePrefix = '', ...settings } = {}) {
super();
Expand Down Expand Up @@ -52,16 +62,8 @@ class PostgresPersistenceEngine extends AbstractPersistenceEngine {
`;

const args = [persistenceKey, offset, limit, tags].filter(x => x !== undefined);

return Rx.Observable
.of([1])
// Perform query
.mergeMap((_) => this.db.any(query, args))
// Retry the query if it fails
.retry(5)
// Flatten array so that it is returned as a stream of events
.mergeMap(x => x)
.map(PostgresPersistenceEngine.mapDbModelToDomainModel);
const result = this.db.any(query, args).then(results => results.map(PostgresPersistenceEngine.mapDbModelToDomainModel));
return new Result(result);
}

persist (persistedEvent) {
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nact-persistence-postgres",
"version": "4.3.1",
"version": "6.0.0",
"description": "nact-persistence-postgres ⇒ nact + postresql = your services have never been so persistent",
"main": "lib/index.js",
"scripts": {
Expand Down Expand Up @@ -32,21 +32,20 @@
"url": "http://github.com/ncthbrt/nact-persistence-postgres/issues"
},
"dependencies": {
"pg-promise": "^7.3.2",
"rxjs": "^5.4.3"
"pg-promise": "^7.3.2"
},
"devDependencies": {
"devDependencies": {
"chai": "^4.1.1",
"chai-as-promised": "^7.1.1",
"coveralls": "^3.0.0",
"eslint": "^4.8.0",
"husky": "^0.14.3",
"mocha": "^4.0.0",
"nact": "^4.3.0",
"nact": "^6.0.0",
"nyc": "^11.2.1",
"semistandard": "^11.0.0"
},
"peerDependencies": {
"nact": "^4.3.0"
"nact": "^6.0.0"
}
}
}
53 changes: 0 additions & 53 deletions package.json.orig

This file was deleted.

23 changes: 4 additions & 19 deletions test/postgres-persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('PostgresPersistenceEngine', function () {
const engine = new PostgresPersistenceEngine(connectionString);
await retry(async () => {
const event1 = new PersistedEvent({ message: 'hello' }, 1, 'test', ['a', 'b', 'c']);
const event2 = new PersistedEvent([ 'message', 'goodbye' ], 2, 'test');
const event2 = new PersistedEvent(['message', 'goodbye'], 2, 'test');
const event3 = new PersistedEvent({ message: 'hello' }, 1, 'test2');
await engine.persist(event1);
await engine.persist(event2);
Expand Down Expand Up @@ -145,32 +145,17 @@ describe('PostgresPersistenceEngine', function () {
});

it('should be able to retrieve previously persisted events', async function () {
const result = await new Promise((resolve, reject) => {
engine.events('test3')
.reduce((prev, evt) => [...prev, evt], [])
.catch(e => { reject(e); return e; })
.subscribe(resolve);
});
const result = await engine.events('test3').reduce((prev, evt) => [...prev, evt], []);
result.should.deep.equal([event1, event2, event3]);
});

it('should be able to specify an offset of previously persisted events', async function () {
const result = await new Promise((resolve, reject) => {
engine.events('test3', 1)
.reduce((prev, evt) => [...prev, evt], [])
.catch(e => { reject(e); return e; })
.subscribe(resolve);
});
const result = await engine.events('test3', 1).reduce((prev, evt) => [...prev, evt], []);
result.should.deep.equal([event2, event3]);
});

it('should be able to filter by tag', async function () {
const result = await new Promise((resolve, reject) => {
engine.events('test3', undefined, undefined, ['b', 'c'])
.reduce((prev, evt) => [...prev, evt], [])
.catch(e => { reject(e); return e; })
.subscribe(resolve);
});
const result = await engine.events('test3', undefined, undefined, ['b', 'c']);
result.should.deep.equal([event1, event3]);
});
});
Expand Down
22 changes: 3 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,6 @@ deep-eql@^3.0.0:
dependencies:
type-detect "^4.0.0"

deep-freeze-node@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/deep-freeze-node/-/deep-freeze-node-1.1.3.tgz#ce9c14b3210e6f5607a578254f4b53fe01dd9467"

deep-is@~0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
Expand Down Expand Up @@ -1785,13 +1781,11 @@ [email protected]:
version "0.0.7"
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"

nact@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/nact/-/nact-4.3.0.tgz#e2856ad316d95d1cc33fcb6a19ab07e60568f0a4"
nact@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/nact/-/nact-6.0.0.tgz#e71f8da8fc11bef87fcd37a47d4ad1f5d34add83"
dependencies:
deep-freeze-node "^1.1.3"
denque "^1.2.2"
rxjs "^5.4.3"

natural-compare@^1.4.0:
version "1.4.0"
Expand Down Expand Up @@ -2346,12 +2340,6 @@ rx-lite@^3.1.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/rx-lite/-/rx-lite-3.1.2.tgz#19ce502ca572665f3b647b10939f97fd1615f102"

rxjs@^5.4.3:
version "5.5.3"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-5.5.3.tgz#b62227e74b84f4e77bdf440e50b5ee01a1bc7dcd"
dependencies:
symbol-observable "^1.0.1"

safe-buffer@^5.0.1, safe-buffer@^5.1.1, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853"
Expand Down Expand Up @@ -2582,10 +2570,6 @@ supports-color@^4.0.0:
dependencies:
has-flag "^2.0.0"

symbol-observable@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.1.0.tgz#5c68fd8d54115d9dfb72a84720549222e8db9b32"

table@^3.7.8:
version "3.8.3"
resolved "https://registry.yarnpkg.com/table/-/table-3.8.3.tgz#2bbc542f0fda9861a755d3947fefd8b3f513855f"
Expand Down

0 comments on commit f456548

Please sign in to comment.