/* * Deepkit Framework * Copyright (C) 2021 Deepkit UG, Marc J. Schmidt * * This program is free software: you can redistribute it and/or modify * it under the terms of the MIT License. * * You should have received a copy of the MIT License along with this program. */ import { BrokerKernel } from '@deepkit/broker'; import { RpcTcpServer } from '@deepkit/rpc-tcp'; import { BrokerConfig } from '../module.config.js'; // export enum EntityChannelMessageType { // remove, // patch, // add, // } // // interface EntityChannelMessageAdd { // type: EntityChannelMessageType.add, // id: string | number, // item: T, // } // // interface EntityChannelMessageRemove { // type: EntityChannelMessageType.remove, // ids: (string | number | UUID | MongoId)[], // } // // export interface EntityPatches { // $set?: { [path: string]: any }; // $unset?: { [path: string]: number }; // $inc?: { [path: string]: number }; // } // // interface EntityChannelMessagePatch { // type: EntityChannelMessageType.patch, // id: string | number, // version: number, // item: Partial, // patch: EntityPatches, // } // // type EntityChannelMessage = EntityChannelMessageAdd // | EntityChannelMessageRemove // | EntityChannelMessagePatch; // // export class EntityBrokerChannel extends BrokerBus> { // publishAdd(item: T) { // return this.publish({ type: EntityChannelMessageType.add, id: item.id, item }); // } // // publishRemove(ids: (string | number)[]) { // return this.publish({ type: EntityChannelMessageType.remove, ids }); // } // // publishPatch(id: string | number, version: number, patch: EntityPatches, item: Partial) { // return this.publish({ type: EntityChannelMessageType.patch, id, version, patch, item }); // } // } // // export class BaseBroker extends Broker { // protected getEntityChannelMessageType(schema: ReflectionClass): Type { // const jit = schema.getJitContainer(); // if (!jit.entityChannelMessage) { // jit.entityChannelMessage = typeOf>([schema.type]); // } // return jit.entityChannelMessage; // } // // public entityChannel(schemaOrType: ClassType): EntityBrokerChannel { // const schema = ReflectionClass.from(schemaOrType); // const channelName = 'dk/e/' + schema.getName(); // let channel = this.activeChannels.get(channelName); // if (channel) return channel as EntityBrokerChannel; // // const type = this.getEntityChannelMessageType(schema); // channel = new EntityBrokerChannel(channelName, type, this); // this.activeChannels.set(channel.channel, channel); // // return channel as EntityBrokerChannel; // } // } export class BrokerServer extends RpcTcpServer { protected kernel: BrokerKernel = new BrokerKernel; constructor(protected listen: BrokerConfig['listen']) { super(new BrokerKernel, listen); } }