diff --git a/apps/nocapd/src/index.js b/apps/nocapd/src/index.js index 420f7f47..7af3ceba 100644 --- a/apps/nocapd/src/index.js +++ b/apps/nocapd/src/index.js @@ -62,12 +62,34 @@ const globalHandlers = ($daemon) => { $daemon.$q.queue.on('error', async (err) => { console.error('Queue Error: ', err); - gracefulShutdown(err) + if(err?.code === 'EAI_AGAIN' || JSON.stringify(err).includes('EAI_AGAIN')){ + const code = err?.code? err.code: '[code undefined!]' + gracefulShutdown(code) + } + }) + + $daemon.$q.events.on('error', async (err) => { + console.error('QueueEvents Error: ', err); + if(err?.code === 'EAI_AGAIN' || JSON.stringify(err).includes('EAI_AGAIN')){ + const code = err?.code? err.code: '[code undefined!]' + gracefulShutdown(code) + } }) $daemon.$q.queue.on('ioredis:close', async (err) => { console.error('Queue: ioredis:close: ', err); - gracefulShutdown(err) + if(err?.code === 'EAI_AGAIN' || JSON.stringify(err).includes('EAI_AGAIN')){ + const code = err?.code? err.code: '[code undefined!]' + gracefulShutdown(code) + } + }) + + $daemon.$q.worker.on('error', async (err) => { + console.error('Worker Error: ', err); + if(err?.code === 'EAI_AGAIN' || JSON.stringify(err).includes('EAI_AGAIN')){ + const code = err?.code? err.code: '[code undefined!]' + gracefulShutdown(code) + } }) } diff --git a/packages/publisher/src/Publisher.js b/packages/publisher/src/Publisher.js index eb5be938..9a832a5e 100644 --- a/packages/publisher/src/Publisher.js +++ b/packages/publisher/src/Publisher.js @@ -26,8 +26,8 @@ async function writeObjectToFile(obj) { export class Publisher { - constructor(){ - this.logger = new Logger('publisher[generic]') + constructor(key="generic"){ + this.logger = new Logger(`publisher[${key}]`) } tpl(){ diff --git a/packages/publisher/src/kinds/Kind0.js b/packages/publisher/src/kinds/Kind0.js index e9311ae5..c3d627c1 100644 --- a/packages/publisher/src/kinds/Kind0.js +++ b/packages/publisher/src/kinds/Kind0.js @@ -2,8 +2,9 @@ import { Publisher } from '../Publisher.js' export class Kind0 extends Publisher { constructor(){ - super() - this.kind = 0 + const KIND = 0 + super(KIND) + this.kind = KIND this.discoverable = { pubkey: true } this.human_readable = false this.machine_readable = true diff --git a/packages/publisher/src/kinds/Kind10002.js b/packages/publisher/src/kinds/Kind10002.js index dfaf6e3d..bda7d019 100644 --- a/packages/publisher/src/kinds/Kind10002.js +++ b/packages/publisher/src/kinds/Kind10002.js @@ -2,8 +2,9 @@ import { Publisher } from '../Publisher.js' export class Kind10002 extends Publisher { constructor(){ - super() - this.kind = 10002 + const KIND = 10002 + super(KIND) + this.kind = KIND this.discoverable = { pubkey: true } this.human_readable = false this.machine_readable = true @@ -30,5 +31,4 @@ export class Kind10002 extends Publisher { relays: event.tags.filter(tag => tag === 'r').map( tag => tag[1] ) } } - } \ No newline at end of file diff --git a/packages/publisher/src/kinds/Kind10166.js b/packages/publisher/src/kinds/Kind10166.js index a88ae78d..227937db 100644 --- a/packages/publisher/src/kinds/Kind10166.js +++ b/packages/publisher/src/kinds/Kind10166.js @@ -6,9 +6,9 @@ import ngeotags from 'nostr-geotags'; */ export class Kind10166 extends Publisher { constructor() { - super(); - /** @type {number} The kind identifier. */ - this.kind = 10166; + const KIND = 10166; + super(KIND); + this.kind = KIND; } /** diff --git a/packages/publisher/src/kinds/Kind1066.js b/packages/publisher/src/kinds/Kind1066.js index 9378a31a..4dde4945 100644 --- a/packages/publisher/src/kinds/Kind1066.js +++ b/packages/publisher/src/kinds/Kind1066.js @@ -2,6 +2,53 @@ import { Publisher } from '../Publisher.js' export class Kind1066 extends Publisher { constructor(){ + const KIND = 1066 super() + this.kind = KIND } +}import { Publisher } from '../Publisher.js' + +export class Kind1066 extends Publisher { + constructor(){ + const KIND = 1066 + super(KIND) + this.kind = KIND + this.discoverable = { pubkey: true } + this.human_readable = false + this.machine_readable = true + } + + generateEvent(data){ + let tags = Kind1066.generateTags(data) + const event = { + ...this.tpl(), + tags + } + return event + } + + static generateTags(data){ + if( !(relays instanceof Object) ) + throw new Error("Kind1066: generateTags(data): data should be an object") + let tags = [] + + tags.push(['r', data.url]) + + const aTag = ['a', `30066:${data.pubkey}:${data.url}`] + if(data?.relayHint) + aTag.push(data.relayHint) + tags.push(aTag) + + const deltas = data.deltas + .map( delta => [ ['D', delta.key], [delta.key, delta.value] ] ) + .reduce( (acc, val) => [...acc, ...val], [] ) + + tags = [ ...tags, ...deltas ] + } + + parse(event){ + return { + relays: event.tags.filter( tag => tag === 'r' ).map( tag => tag[1] ) + } + } } \ No newline at end of file diff --git a/packages/publisher/src/kinds/Kind30066.js b/packages/publisher/src/kinds/Kind30066.js index bbb0a09b..e3c6d9f6 100644 --- a/packages/publisher/src/kinds/Kind30066.js +++ b/packages/publisher/src/kinds/Kind30066.js @@ -1,13 +1,14 @@ import mapper from 'object-mapper' import ngeohash from 'ngeohash' -import { ParseEvent } from '@nostrwatch/parse' +// import { ParseEvent } from '@nostrwatch/parse' import { PublisherNocap } from '../Publisher.js' export class Kind30066 extends PublisherNocap { constructor(){ - super() - this.kind = 30066 + const KIND = 30066 + super(KIND) + this.kind = KIND this.discoverable = {tags: 'd'} this.human_readable = true this.machine_readable = true diff --git a/packages/publisher/src/kinds/Kind30166.js b/packages/publisher/src/kinds/Kind30166.js index c7589c67..3cdef172 100644 --- a/packages/publisher/src/kinds/Kind30166.js +++ b/packages/publisher/src/kinds/Kind30166.js @@ -5,8 +5,9 @@ import { PublisherNocap } from '../Publisher.js' export class Kind30166 extends PublisherNocap { constructor(){ - super() - this.kind = 30166 + const KIND =30166 + super(KIND) + this.kind = KIND this.discoverable = {tags: ['d', 'n', 'l', 'N', 's', 't', 'R']} this.human_readable = false this.machine_readable = true @@ -65,7 +66,7 @@ export class Kind30166 extends PublisherNocap { const current = data.ssl.data.valid_from < Date.now() && data.ssl.data.valid_to > Date.now() tags.push(['R', current ? 'ssl' : '!ssl']) } - else(protocol !== 'wss:') { + else if(protocol !== 'wss:') { tags.push(['R', '!ssl']) }