json-crdt-server
Version:
JSON CRDT server and syncing local-first browser client
21 lines (20 loc) • 892 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.listen = void 0;
const rxjs_1 = require("rxjs");
const listen = ({ t, services }) => (r) => {
const Request = t.Object(t.prop('channel', t.str).options({
title: 'Channel name',
description: 'The name of the channel to subscribe to.',
}));
const Response = t.Object(t.prop('message', t.any).options({
title: 'Subscription message',
description: 'A message received from the channel. Emitted every time a message is published to the channel.',
}));
const Func = t.Function$(Request, Response);
return r.prop('pubsub.listen', Func, (req) => {
const response = req.pipe((0, rxjs_1.switchMap)((req) => services.pubsub.listen$(req.channel)), (0, rxjs_1.map)((message) => ({ message })));
return response;
});
};
exports.listen = listen;
;