openvibers/openvibe.live Commits
Channel search documents go out with priority low (the envelope allows critical, important or low; 'normal' made Events refuse them with 422); the test's stub Events now validates envelopes as Events does
Changes
@@@ -86,8 +86,8 @@ function publish(userId, { now = Date.now() } = {}) {const id = String(userId);d.transaction(() => {streamEvents.enqueue(doc.deleted-- ? { event_type: 'live.index_document.deleted', actor: { type: 'service', id: 'live' }, subject: { type: 'channel', id, revision }, visibility: 'internal', priority: 'normal', payload: { type: 'channel', id, revision } }-- : { event_type: 'live.index_document.upserted', actor: { type: 'service', id: 'live' }, subject: { type: 'channel', id, revision }, visibility: 'internal', priority: 'normal',++ ? { event_type: 'live.index_document.deleted', actor: { type: 'service', id: 'live' }, subject: { type: 'channel', id, revision }, visibility: 'internal', priority: 'low', payload: { type: 'channel', id, revision } }++ : { event_type: 'live.index_document.upserted', actor: { type: 'service', id: 'live' }, subject: { type: 'channel', id, revision }, visibility: 'internal', priority: 'low',payload: { ...doc, revision, updated_at: new Date(now).toISOString() } });d.prepare(`INSERT INTO search_doc_pushes (user_id, hash, revision, deleted, pushed_at) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP)ON CONFLICT(user_id) DO UPDATE SET hash = excluded.hash, revision = excluded.revision, deleted = excluded.deleted, pushed_at = excluded.pushed_at`)@@@ -25,6 +25,9 @@ const stub = http.createServer((req, res) => {if (req.url === '/api/v1/events' && req.method === 'POST') {const parsed = JSON.parse(body);const list = parsed.events || [parsed];++ const { validate } = require('openvibe-contracts');++ const bad = list.find((e) => !validate('events.event-envelope@1', e).valid);++ if (bad) { res.statusCode = 422; return res.end(JSON.stringify({ code: 'events.invalid_envelope', errors: validate('events.event-envelope@1', bad).errors })); } // as Events doesconst results = list.map((e) => { published.push(e); return { event_id: e.event_id, seq: published.length, duplicate: false }; });return res.end(JSON.stringify(parsed.events ? { results } : results[0]));}
@@ -86,8 +86,8 @@ function publish(userId, { now = Date.now() } = {}) {
@@ -86,8 +86,8 @@ function publish(userId, { now = Date.now() } = {}) {
const id = String(userId);
const id = String(userId);
d.transaction(() => {
d.transaction(() => {
streamEvents.enqueue(doc.deleted
streamEvents.enqueue(doc.deleted
- ? { event_type: 'live.index_document.deleted', actor: { type: 'service', id: 'live' }, subject: { type: 'channel', id, revision }, visibility: 'internal', priority: 'normal', payload: { type: 'channel', id, revision } }
- : { event_type: 'live.index_document.upserted', actor: { type: 'service', id: 'live' }, subject: { type: 'channel', id, revision }, visibility: 'internal', priority: 'normal',
+ ? { event_type: 'live.index_document.deleted', actor: { type: 'service', id: 'live' }, subject: { type: 'channel', id, revision }, visibility: 'internal', priority: 'low', payload: { type: 'channel', id, revision } }
+ : { event_type: 'live.index_document.upserted', actor: { type: 'service', id: 'live' }, subject: { type: 'channel', id, revision }, visibility: 'internal', priority: 'low',
payload: { ...doc, revision, updated_at: new Date(now).toISOString() } });
payload: { ...doc, revision, updated_at: new Date(now).toISOString() } });
d.prepare(`INSERT INTO search_doc_pushes (user_id, hash, revision, deleted, pushed_at) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP)
d.prepare(`INSERT INTO search_doc_pushes (user_id, hash, revision, deleted, pushed_at) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP)
ON CONFLICT(user_id) DO UPDATE SET hash = excluded.hash, revision = excluded.revision, deleted = excluded.deleted, pushed_at = excluded.pushed_at`)
ON CONFLICT(user_id) DO UPDATE SET hash = excluded.hash, revision = excluded.revision, deleted = excluded.deleted, pushed_at = excluded.pushed_at`)
@@ -25,6 +25,9 @@ const stub = http.createServer((req, res) => {
@@ -25,6 +25,9 @@ const stub = http.createServer((req, res) => {
if (req.url === '/api/v1/events' && req.method === 'POST') {
if (req.url === '/api/v1/events' && req.method === 'POST') {
const parsed = JSON.parse(body);
const parsed = JSON.parse(body);
const list = parsed.events || [parsed];
const list = parsed.events || [parsed];
+ const { validate } = require('openvibe-contracts');
+ const bad = list.find((e) => !validate('events.event-envelope@1', e).valid);
+ if (bad) { res.statusCode = 422; return res.end(JSON.stringify({ code: 'events.invalid_envelope', errors: validate('events.event-envelope@1', bad).errors })); } // as Events does
const results = list.map((e) => { published.push(e); return { event_id: e.event_id, seq: published.length, duplicate: false }; });
const results = list.map((e) => { published.push(e); return { event_id: e.event_id, seq: published.length, duplicate: false }; });
return res.end(JSON.stringify(parsed.events ? { results } : results[0]));
return res.end(JSON.stringify(parsed.events ? { results } : results[0]));
}
}