| 46 | * @public |
| 47 | */ |
| 48 | export class AggregationMiddleware extends BasePresentationMiddleware implements PresentationMiddleware { |
| 49 | mgrs: Map<Ref<Class<Doc>>, IAggregationManager<any>> = new Map<Ref<Class<Doc>>, IAggregationManager<any>>() |
| 50 | docs: Doc[] | undefined |
| 51 | |
| 52 | subscribers: Map<string, DocSubScriber> = new Map<string, DocSubScriber>() |
| 53 | private constructor (client: Client, next?: PresentationMiddleware) { |
| 54 | super(client, next) |
| 55 | } |
| 56 | |
| 57 | static create (client: Client, next?: PresentationMiddleware): AggregationMiddleware { |
| 58 | return new AggregationMiddleware(client, next) |
| 59 | } |
| 60 | |
| 61 | async notifyTx (...tx: Tx[]): Promise<void> { |
| 62 | const promises: Array<Promise<void>> = [] |
| 63 | for (const [, value] of this.mgrs) { |
| 64 | promises.push(value.notifyTx(...tx)) |
| 65 | } |
| 66 | await Promise.all(promises) |
| 67 | await this.provideNotifyTx(...tx) |
| 68 | } |
| 69 | |
| 70 | async close (): Promise<void> { |
| 71 | this.mgrs.forEach((mgr) => { |
| 72 | mgr.close() |
| 73 | }) |
| 74 | await this.provideClose() |
| 75 | } |
| 76 | |
| 77 | async tx (tx: Tx): Promise<TxResult> { |
| 78 | return await this.provideTx(tx) |
| 79 | } |
| 80 | |
| 81 | private refreshSubscribers (): void { |
| 82 | for (const s of this.subscribers.values()) { |
| 83 | // TODO: Do something more smart and track if used component field is changed. |
| 84 | s.refresh() |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | async subscribe<T extends Doc>( |
| 89 | _class: Ref<Class<T>>, |
| 90 | query: DocumentQuery<T>, |
| 91 | options: FindOptions<T> | undefined, |
| 92 | refresh: () => void |
| 93 | ): Promise<{ |
| 94 | unsubscribe: () => void |
| 95 | query?: DocumentQuery<T> |
| 96 | options?: FindOptions<T> |
| 97 | }> { |
| 98 | const ret = await this.provideSubscribe(_class, query, options, refresh) |
| 99 | const h = this.client.getHierarchy() |
| 100 | |
| 101 | const id = generateId() |
| 102 | const s: DocSubScriber<T> = { |
| 103 | _class, |
| 104 | query, |
| 105 | refresh, |
nothing calls this directly
no outgoing calls
no test coverage detected