From f26121d6163fc60a11e8fb96b21ced1c8da35d7d Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 11 Feb 2020 02:16:14 +0100 Subject: [PATCH] add T2 --- src/backend/Components/Eventbus.ts | 98 ---------------------- src/backend/Components/PubSub/Interface.ts | 2 +- src/backend/Types/Items.ts | 58 ++++++++++++- 3 files changed, 58 insertions(+), 100 deletions(-) delete mode 100644 src/backend/Components/Eventbus.ts diff --git a/src/backend/Components/Eventbus.ts b/src/backend/Components/Eventbus.ts deleted file mode 100644 index 6d33315..0000000 --- a/src/backend/Components/Eventbus.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { RPCExporter, SubscriptionResponse, ErrorResponse, SuccessResponse } from "rpclibrary"; -import { FrontworkAdmin } from "../Admin/Admin"; -import { TableDefinitionExporter } from "../Types/Interfaces"; -import { getLogger } from 'frontblock-generic/Types'; - -import * as uuid from 'uuid/v4' -import { TableDefiniton } from "../Types/Types"; - -export type NotificationSeverity = 'Info' | 'Important' | 'Error' - -export type Notification = { - ID?:number, - severity: NotificationSeverity, - topic: string, - message:string, - time?: number -} - -export type EventbusIfc = { - Eventbus: { - getNotificationLog: () => Promise - pushNotification: (notification:Notification) => Promise - subscribeNotifications: (callback:Function) => Promise - } -} - -const logger = getLogger("Eventbus", 'debug') - -export class FrontworkEventBus -implements RPCExporter, TableDefinitionExporter { - name = "Eventbus" as "Eventbus" - private subscriptions : { [uid in string]:Function } = {} - - constructor(private admin: FrontworkAdmin){ - } - - async subscribeNotifications(callback) : Promise{ - const uid = uuid() - this.subscriptions[uid] = callback - return { result: 'Success', uuid: uid } - } - - async getNotificationLog() : Promise{ - try{ - return await this.admin.knex.select('*').from('notifications') - }catch(e){ - logger.error(e) - throw e - } - } - - async unsubscribeNotifications(uid:string) : Promise{ - if(!this.subscriptions[uid]) return { result: 'Error', message: "Unknown subscription" } - delete this.subscriptions[uid] - return { result: 'Success' } - } - - async pushNotification(notification: Notification){ - if(!notification.time) notification.time = Date.now() - logger.debug("inserting into notifications", notification) - try{ - await this.admin.knex('notifications').insert(notification) - }catch(e){ - logger.error(e) - throw e - } - - Object.values(this.subscriptions).forEach(callback => { - callback(notification) - }) - } - - exportRPCs(){ - return [{ - name: 'getNotificationLog' as 'getNotificationLog', - call: this.getNotificationLog - },{ - name: 'pushNotification' as 'pushNotification', - call: this.pushNotification - },{ - name: 'subscribeNotificaitons' as 'subscribeNotifications', - hook: async (callback: Function) => await this.subscribeNotifications(callback) - }] - } - - getTableDefinitions(): TableDefiniton[]{ - return [{ - name: 'notifications', - tableBuilder: (table) => { - table.increments('ID').primary(); - table.string('severity'); - table.string('topic'); - table.string('message'); - table.timestamp('time'); - } - }] - } -} \ No newline at end of file diff --git a/src/backend/Components/PubSub/Interface.ts b/src/backend/Components/PubSub/Interface.ts index 68967ec..7b6da86 100644 --- a/src/backend/Components/PubSub/Interface.ts +++ b/src/backend/Components/PubSub/Interface.ts @@ -1,7 +1,7 @@ import { SubscriptionResponse } from "rpclibrary" export class IPubSub{ - publish: (topic: string, p: UpdateType) => void + publish: (topic: string, p: UpdateType) => Promise subscribe: (topic:string, callback: (p:UpdateType)=>any) => Promise unsubscribe: (uuid: string) => Promise } diff --git a/src/backend/Types/Items.ts b/src/backend/Types/Items.ts index 1a40b6b..f9d4169 100644 --- a/src/backend/Types/Items.ts +++ b/src/backend/Types/Items.ts @@ -135,7 +135,63 @@ export const T2:string[] = [ "Band of Dark Dominion", "Draconic Avenger", "Interlaced Shadow Jerkin", -"Ringo's Blizzard Boots" +"Ringo's Blizzard Boots", +"Scrolls of Blinding Light", +"Rune of Metamorphosis", +"Natural Alignment Crystal", +"Mind Quickening Gem", +"Lifegiving Gem", +"Arcane Infused Gem", +"The Black Book", +"Venomous Totem", +"Nemesis Spaulders", +"Nemesis Robes", +"Nemesis Bracers", +"Nemesis Gloves", +"Nemesis Belt", +"Nemesis Boots", +"Netherwind Mantle", +"Netherwind Robes", +"Netherwind Bindings", +"Netherwind Gloves", +"Netherwind Belt", +"Netherwind Boots", +"Bloodfang Spaulders", +"Bloodfang Chestpiece", +"Bloodfang Bracers", +"Bloodfang Gloves", +"Bloodfang Belt", +"Bloodfang Boots", +"Stormrage Pauldrons", +"Stormrage Chestguard", +"Stormrage Bracers", +"Stormrage Handguards", +"Stormrage Belt", +"Stormrage Boots", +"Dragonstalker's Spaulders", +"Dragonstalker's Breastplate", +"Dragonstalker's Bracers", +"Dragonstalker's Guantlets", +"Dragonstalker's Belt", +"Dragonstalker's Greaves", +"Judgement Spaulders", +"Judgement Breastplate", +"Judgement Bindings", +"Judgement Guantlets", +"Judgement Belt", +"Judgement Sabatons", +"Pauldrons of Transcendence", +"Robes of Transcendence", +"Bindings of Transcendence", +"Handguards of Transcendence", +"Belt of Transcendence", +"Boots of Transcendence", +"Pauldrons of Wrath", +"Breastplate of Wrath", +"Bracelets of Wrath", +"Guantlets of Wrath", +"Waistband of Wrath", +"Sabatons of Wrath" ] export type AllItems = {