import { ConnectedPosition } from '@angular/cdk/overlay'; import { DatePipe, DecimalPipe, JsonPipe, KeyValuePipe, SlicePipe } from '@angular/common'; import { ChangeDetectionStrategy, Component, OnInit, Signal, computed, effect, signal } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { humanBytes } from '@deepkit/core'; import { ButtonGroupComponent, CheckboxComponent, DropdownComponent, IconComponent, InputComponent, LabelComponent, LabelGridComponent, OpenDropdownDirective, OptionDirective, SelectBoxComponent, TabButtonComponent, TableCellDirective, TableColumnDirective, TableComponent, } from '@deepkit/desktop-ui'; import { CodeHighlightComponent, DeepkitBoxComponent } from '@deepkit/ui-library'; import { Client, RpcAction, clearClient, clients } from '../collector'; @Component({ styles: ` :host { display: flex; flex-direction: column; height: 100%; overflow: hidden; } .client { display: flex; flex-direction: row; height: 100%; flex: 1; .stats { width: 300px; padding: 10px; } } .filter { height: 28px; display: flex; align-items: center; } .stats { .block { margin: 5px 0; } } .summary-actions { table-layout: fixed; width: 100%; .action { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .value { width: 40px; text-align: right; padding-left: 10px; padding-right: 5px; } } .data { flex: 1; display: flex; flex-direction: column; height: 100%; overflow: hidden; } code-highlight { margin-left: 5px; } table.pretty { table-layout: fixed; width: 100%; td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 5px; } } `, template: `
@if (action(); as message) {

{{ message.action }}

{{ message.timestamp | date: 'HH:mm:ss.SSS' }}
{{ message.timestamp | date: 'medium' }}
{{ message.status }}
Took: @if (message.took) { {{ message.took | number: '0.0-3' }} ms } @else { @if (message.mode !== 'static') { @if (message.completed) { {{ message.completed - message.timestamp | number: '0.0-3' }} ms } @else { active } } }
Total size: {{ humanBytes(message.size) }}
Sent size: {{ humanBytes(message.sizeSent) }}
Received size: {{ humanBytes(message.sizeReceived) }}
@if (message.mode === 'static') { } @else { @for (emit of latest(message.emits, 20); track emit.timestamp) { } } }
@if (selected()?.(); as client) {
@for (client of clients(); track client().id) { {{ client().closed ? '🔴' : '🟢' }} {{ client().url | slice: 0 : 50 }} #{{ client().id }} }
Created: {{ client.createdAt | date: 'medium' }} ({{ client.closed ? 'closed' : 'open' }})
@if (client.closed) {
Closed: {{ client.closedAt | date: 'medium' }}
}
@if (client.summary(); as summary) {
Messages received: {{ summary.received }} ({{ humanBytes(summary.receivedBytes) }})
Messages sent: {{ summary.sent }} ({{ humanBytes(summary.sentBytes) }})
Actions executed: {{ summary.actionsTotal }}
@if (client.type === 'deepkit') {
Observables: {{ summary.total.observables }} ({{ summary.active.observables }} active)
Subscriptions: {{ summary.total.subscriptions }} ({{ summary.active.subscriptions }} active)
Subjects: {{ summary.total.subjects }} ({{ summary.active.subjects }} active)
BehaviorSubjects: {{ summary.total.behaviorSubjects }} ({{ summary.active.behaviorSubjects }} active)
ProgressTracker: {{ summary.total.progressTrackers }} ({{ summary.active.progressTrackers }} active)
@for (action of summary.actions | keyvalue; track action.key) { }
{{ action.key }} {{ action.value }}
} }
@if (client.type === 'deepkit') {
Actions Messages @if (tableView() === 'actions') { All Types Static ({{ types().static || 0 }}) Observable ({{ types().observable || 0 }}) Subject ({{ types().subject || 0 }}) BehaviorSubject ({{ types().behaviorSubject || 0 }}) ProgressTracker ({{ types().progressTracker || 0 }}) Active Observables }
} @if (tableView() === 'messages' || client.type !== 'deepkit') { {{ message.type }} {{ message.timestamp | date: 'HH:mm:ss.SSS' }} {{ humanBytes(message.size) }} {{ message.data | slice: 0 : 500 }} } @else { {{ message.action }} {{ message.timestamp | date: 'HH:mm:ss.SSS' }} @if (message.took) { {{ message.took | number: '0.0-3' }} ms } @else { @if (message.mode !== 'static') { @if (message.completed) { {{ message.completed - message.timestamp | number: '0.0-3' }} ms } @else { active } } } {{ humanBytes(message.size) }} {{ humanBytes(message.sizeSent) }} {{ humanBytes(message.sizeReceived) }} {{ message.returnType }} {{ message.args | json }} {{ message.response | json | slice: 0 : 500 }} }
}
`, changeDetection: ChangeDetectionStrategy.Eager, imports: [ SlicePipe, JsonPipe, KeyValuePipe, FormsModule, DatePipe, DecimalPipe, CodeHighlightComponent, DeepkitBoxComponent, DropdownComponent, LabelGridComponent, LabelComponent, SelectBoxComponent, OptionDirective, IconComponent, ButtonGroupComponent, TabButtonComponent, InputComponent, CheckboxComponent, TableComponent, TableColumnDirective, TableCellDirective, OpenDropdownDirective, ], }) export class RpcViewComponent implements OnInit { clients = clients; tableView = signal('actions'); selected = signal | undefined>(undefined); filterText = signal(''); filterType = signal(''); filterErrors = signal(false); filterActiveObservables = signal(false); actions = computed(() => { const selected = this.selected()?.(); if (!selected) return []; const text = this.filterText().toLowerCase(); const type = this.filterType(); const activeObservables = this.filterActiveObservables(); const filterErrors = this.filterErrors(); let actions = selected.actions(); if (text) { actions = actions.filter(action => action.action.toLowerCase().includes(text)); } if (type) { actions = actions.filter(action => action.mode === type); } if (activeObservables) { actions = actions.filter( action => action.active.subscriptions > 0 || action.active.observables > 0 || action.active.subjects > 0 || action.active.behaviorSubjects > 0 || action.active.progressTrackers > 0, ); } if (filterErrors) { actions = actions.filter(action => action.errors > 0); } return actions; }); types = computed<{ [name: string]: number }>(() => { const selected = this.selected()?.(); if (!selected) return {}; const types: { [name: string]: number } = {}; for (const action of selected.actions()) { if (!types[action.mode]) types[action.mode] = 0; types[action.mode]++; } return types; }); action = signal(undefined); messages = computed(() => { const selected = this.selected()?.(); if (!selected) return []; return selected.messages(); }); clearMessages() { const selected = this.selected()?.(); if (!selected) return; clearClient(selected); } connectedPositions: ConnectedPosition[] = [ { originX: 'end', originY: 'top', overlayX: 'start', overlayY: 'top', }, ]; constructor() { effect(() => { const selected = this.selected(); const _clients = clients(); if (_clients.length === 0) { this.selected.set(undefined); return; } if (selected) return; const first = _clients[0]; if (first) this.selected.set(first); }); } latest(items: T[], count: number): T[] { const next = items.slice(-count); next.reverse(); return next; } ngOnInit() {} protected readonly humanBytes = humanBytes; }