Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
async remove (id, params) {
debug('Requesting remove() remote service on path ' + this.path, id, params)
try {
const result = await this.requester.send({ type: 'remove', id, params })
debug('Successfully remove() remote service on path ' + this.path)
return result
} catch (error) {
throw convert(error)
}
}
}
// This is the cote responder abstraction for a local Feathers service
class LocalService extends cote.Responder {
constructor (options) {
const app = options.app
const path = options.path
super({
name: path + ' responder',
namespace: path,
key: path,
respondsTo: ['find', 'get', 'create', 'update', 'patch', 'remove']
}, app.coteOptions)
debug('Responder created for local service on path ' + path)
const service = app.service(path)
// Answer requests from other nodes
this.on('find', async (req) => {
debug('Responding find() local service on path ' + path, req)
const result = await service.find(Object.assign({ fromRemote: true }, req.params))
var cote = require('cote'),
models = require('../models');
var userResponder = new cote.Responder({
name: 'user responder',
namespace: 'user',
respondsTo: ['create']
});
var userPublisher = new cote.Publisher({
name: 'user publisher',
namespace: 'user',
broadcasts: ['update']
});
userResponder.on('*', console.log);
userResponder.on('create', function(req, cb) {
models.User.create({}, cb);
const cote = require('cote')
const restaurantsResponder = new cote.Responder({ name: 'restaurants responder', key: 'restaurants' })
restaurantsResponder.on('*', req => req.type && console.log(req))
const restaurants = [{
id: 0,
name: 'Italian Restaurant',
menu: [{
id: 0,
name: 'Pizza',
price: 14
}, {
id: 1,
name: 'Pasta',
price: 12
}]
}, {
id: 1,
const cote = require('cote')
const deliveryResponder = new cote.Responder({ name: 'delivery responder', key: 'deliveries' })
deliveryResponder.on('*', req => req.type && console.log(req))
const deliveries = []
let idCounter = 0
deliveryResponder.on('create delivery', req => {
const delivery = { id: idCounter++, orderId: req.order.id, eta: 30, status: 'pending' }
deliveries.push(delivery)
return Promise.resolve(delivery)
})
var cote = require('cote');
var hostname = require('os').hostname();
var source = `time-service@${hostname}`;
var timeResponder = new cote.Responder({
name: 'Time Responder'
});
timeResponder.on('time', function(req, cb) {
var time = new Date();
var reply = {source, time, rand: Math.random()};
console.log(reply);
cb(reply);
});
var cote = require('cote'),
models = require('../models');
var paymentResponder = new cote.Responder({
name: 'payment responder',
key: 'payment'
});
paymentResponder.on('*', console.log);
paymentResponder.on('process', function(req, cb) {
models.User.get(req.userId, function(err, user) {
if (user.balance < req.price) return cb(true);
user.balance -= req.price;
user.save(cb);
});
});
const cote = require('cote')
const orderResponder = new cote.Responder({ name: 'order responder', key: 'orders' })
orderResponder.on('*', req => req.type && console.log(req))
const orders = []
let idCounter = 0
orderResponder.on('create order', req => {
const order = { id: idCounter++, ...req.order, status: 'preparing' }
orders.push(order)
return Promise.resolve(order)
})
var cote = require('cote'),
models = require('../models');
var productResponder = new cote.Responder({
name: 'product responder',
namespace: 'product',
respondsTo: ['list']
});
var productPublisher = new cote.Publisher({
name: 'product publisher',
namespace: 'product',
broadcasts: ['update']
});
productResponder.on('*', console.log);
productResponder.on('list', function(req, cb) {
var query = req.query || {};
models.Product.find(query, cb);
var cote = require('cote'),
models = require('../models');
var purchaseResponder = new cote.Responder({
name: 'purchase responder',
namespace: 'purchase',
respondsTo: ['buy']
});
var purchasePublisher = new cote.Publisher({
name: 'purchase publisher',
namespace: 'purchase',
broadcasts: ['update']
});
var paymentRequester = new cote.Requester({
name: 'payment requester',
key: 'payment'
});
(function () {
const cote = require('cote');
cote_resp = new cote.Responder({ name: 'bench-remote' });
cote_req = new cote.Requester({ name: 'bench-remote' });
cote_resp.on('add', (req, cb) => {
cb(req.a + req.b);
});
bench.add("Cote", done => {
cote_req.send({ type: 'add', a: 5, b: 3 }, res => done());
});
})();