Skip to content

Commit

Permalink
Add compatibility for v5 and update dependencies (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Jul 5, 2021
1 parent f3183a3 commit 491558a
Show file tree
Hide file tree
Showing 10 changed files with 3,822 additions and 3,834 deletions.
2 changes: 1 addition & 1 deletion lib/adapters/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = config => {
if (!redisClient && typeof db !== 'undefined') {
debug(`Setting up Redis client for db: ${db}`);
}

const pub = redisClient || redis.createClient(db, config.redisOptions);
const sub = pub.duplicate();

Expand Down
21 changes: 17 additions & 4 deletions lib/core.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
const debug = require('debug')('feathers-sync');
const { hooks, _ } = require('@feathersjs/commons');
const feathers = require('@feathersjs/feathers');
const { _ } = require('@feathersjs/commons');
const SYNC = Symbol('feathers-sync/enabled');

const defaultEvents = ['created', 'updated', 'removed', 'patched'];
const getServiceOptions = service => {
if (typeof feathers.getServiceOptions === 'function') {
return feathers.getServiceOptions(service);
}

return {};
};

module.exports = app => {
if (app[SYNC]) {
return;
Expand Down Expand Up @@ -30,17 +40,20 @@ module.exports = app => {

app.mixins.push((service, path) => {
if (typeof service._emit !== 'function') {
const { events: customEvents = service.events } = getServiceOptions(service);
const events = defaultEvents.concat(customEvents);

service._emit = service.emit;
service.emit = function (event, data, ctx) {
const disabled = ctx && ctx[SYNC] === false;

if (!service._serviceEvents.includes(event) || disabled) {
if (!events.includes(event) || disabled) {
debug(`Passing through non-service event '${path} ${event}'`);
return this._emit(event, data, ctx);
}

const context = hooks.isHookObject(ctx)
? _.omit(ctx, 'app', 'service')
const context = ctx && (ctx.app === app || ctx.service === service)
? _.omit(ctx, 'app', 'service', 'self')
: ctx;

debug(`Sending sync-out event '${path} ${event}'`);
Expand Down
7,571 changes: 3,770 additions & 3,801 deletions package-lock.json

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,27 @@
"src": "src"
},
"dependencies": {
"amqp-connection-manager": "^3.2.1",
"amqplib": "^0.6.0",
"amqp-connection-manager": "^3.2.2",
"amqplib": "^0.8.0",
"debug": "^4.3.1",
"lodash": "^4.17.20",
"lodash": "^4.17.21",
"nats": "^1.4.12",
"redis": "^3.0.2"
"redis": "^3.1.2"
},
"devDependencies": {
"@feathersjs/feathers": "^4.5.11",
"@feathersjs/feathers": "^5.0.0-pre.5",
"@semantic-release/commit-analyzer": "^8.0.1",
"@semantic-release/npm": "^7.0.10",
"@semantic-release/release-notes-generator": "^9.0.1",
"@types/node": "^14.14.22",
"bson": "^4.2.2",
"dtslint": "^4.0.6",
"mocha": "^8.2.1",
"@semantic-release/npm": "^7.1.3",
"@semantic-release/release-notes-generator": "^9.0.3",
"@types/node": "^15.12.5",
"bson": "^4.4.0",
"dtslint": "^4.1.0",
"mocha": "^9.0.1",
"npm-check-updates": "^11.7.1",
"nyc": "^15.1.0",
"semantic-release": "^17.3.7",
"semistandard": "^16.0.0",
"typescript": "^4.1.3"
"semantic-release": "^17.4.4",
"semistandard": "^16.0.1",
"typescript": "^4.3.4"
},
"mocha": {
"timeout": 30000,
Expand Down
4 changes: 2 additions & 2 deletions test/adapters/amqp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('feathers-sync AMQP tests', () => {
before(async () => {
app1 = createApp();
await app1.sync.ready;

app2 = createApp();
await app2.sync.ready;

Expand All @@ -36,7 +36,7 @@ describe('feathers-sync AMQP tests', () => {
assert.ok(context);
assert.deepStrictEqual(context.result, data);
assert.strictEqual(context.method, 'create');
assert.strictEqual(context.type, 'after');
assert.strictEqual(context.type, null);
assert.strictEqual(context.service, app.service('todo'));
assert.strictEqual(context.app, app);

Expand Down
4 changes: 2 additions & 2 deletions test/adapters/nats.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('feathers-sync NATS tests', () => {
before(async () => {
app1 = createApp();
await app1.sync.ready;

app2 = createApp();
await app2.sync.ready;

Expand All @@ -34,7 +34,7 @@ describe('feathers-sync NATS tests', () => {
assert.ok(context);
assert.deepStrictEqual(context.result, data);
assert.strictEqual(context.method, 'create');
assert.strictEqual(context.type, 'after');
assert.strictEqual(context.type, null);
assert.strictEqual(context.service, app.service('todo'));
assert.strictEqual(context.app, app);

Expand Down
2 changes: 1 addition & 1 deletion test/adapters/redis.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('feathers-sync Redis tests', () => {
assert.ok(context);
assert.deepStrictEqual(context.result, data);
assert.strictEqual(context.method, 'create');
assert.strictEqual(context.type, 'after');
assert.strictEqual(context.type, null);
assert.strictEqual(context.service, app.service('todo'));
assert.strictEqual(context.app, app);

Expand Down
19 changes: 12 additions & 7 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ describe('feathers-sync core tests', () => {
path: 'todo',
data: message,
context: {
arguments: [message],
arguments: [message, {}],
data: message,
params: {},
type: 'after',
type: null,
method: 'create',
event: 'created',
path: 'todo',
result: message
}
Expand Down Expand Up @@ -126,10 +127,14 @@ describe('feathers-sync core tests', () => {
});
});

it('sync-in does nothing for invalid event (path)', () => {
app.emit('sync-in', {
event: 'something',
path: 'todos'
});
it('sync-in fails for invalid event (path)', () => {
try {
app.emit('sync-in', {
event: 'something',
path: 'todos'
});
} catch (error) {
assert.strictEqual(error.message, 'Can not find service \'todos\'');
}
});
});
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Application } from "@feathersjs/feathers";

// TypeScript Version: 3.0
// TypeScript Version: 4.0
export interface SyncOptions {
key?: string;
uri: string;
Expand Down
2 changes: 1 addition & 1 deletion types/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import feathers from '@feathersjs/feathers';
import { feathers } from '@feathersjs/feathers';
import sync, { redis } from 'feathers-sync';

const app = feathers();
Expand Down

0 comments on commit 491558a

Please sign in to comment.