@moqtap/trace 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +108 -0
- package/SPEC.md +228 -0
- package/dist/index.cjs +493 -0
- package/dist/index.d.cts +146 -0
- package/dist/index.d.ts +146 -0
- package/dist/index.js +493 -0
- package/package.json +61 -0
- package/src/binary.ts +351 -0
- package/src/index.ts +33 -0
- package/src/json.ts +21 -0
- package/src/recorder.ts +247 -0
- package/src/types.ts +106 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
export type DetailLevel = 'control' | 'headers' | 'headers+sizes' | 'headers+data' | 'full';
|
|
2
|
+
export type Perspective = 'client' | 'server' | 'observer';
|
|
3
|
+
|
|
4
|
+
export interface TraceHeader {
|
|
5
|
+
readonly protocol: string;
|
|
6
|
+
readonly perspective: Perspective;
|
|
7
|
+
readonly detail: DetailLevel;
|
|
8
|
+
readonly startTime: number;
|
|
9
|
+
readonly endTime?: number;
|
|
10
|
+
readonly transport?: string;
|
|
11
|
+
readonly source?: string;
|
|
12
|
+
readonly endpoint?: string;
|
|
13
|
+
readonly sessionId?: string;
|
|
14
|
+
readonly custom?: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface BaseEvent {
|
|
18
|
+
readonly seq: number;
|
|
19
|
+
readonly timestamp: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ControlMessageEvent extends BaseEvent {
|
|
23
|
+
readonly type: 'control';
|
|
24
|
+
readonly direction: 0 | 1;
|
|
25
|
+
readonly messageType: number;
|
|
26
|
+
readonly message: Record<string, unknown>;
|
|
27
|
+
readonly raw?: Uint8Array;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface StreamOpenedEvent extends BaseEvent {
|
|
31
|
+
readonly type: 'stream-opened';
|
|
32
|
+
readonly streamId: bigint;
|
|
33
|
+
readonly direction: 0 | 1;
|
|
34
|
+
readonly streamType: 0 | 1 | 2;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface StreamClosedEvent extends BaseEvent {
|
|
38
|
+
readonly type: 'stream-closed';
|
|
39
|
+
readonly streamId: bigint;
|
|
40
|
+
readonly errorCode: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface ObjectHeaderEvent extends BaseEvent {
|
|
44
|
+
readonly type: 'object-header';
|
|
45
|
+
readonly streamId: bigint;
|
|
46
|
+
readonly groupId: bigint;
|
|
47
|
+
readonly objectId: bigint;
|
|
48
|
+
readonly publisherPriority: number;
|
|
49
|
+
readonly objectStatus: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface ObjectPayloadEvent extends BaseEvent {
|
|
53
|
+
readonly type: 'object-payload';
|
|
54
|
+
readonly streamId: bigint;
|
|
55
|
+
readonly groupId: bigint;
|
|
56
|
+
readonly objectId: bigint;
|
|
57
|
+
readonly size: number;
|
|
58
|
+
readonly payload?: Uint8Array;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface StateChangeEvent extends BaseEvent {
|
|
62
|
+
readonly type: 'state-change';
|
|
63
|
+
readonly from: string;
|
|
64
|
+
readonly to: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface TraceErrorEvent extends BaseEvent {
|
|
68
|
+
readonly type: 'error';
|
|
69
|
+
readonly errorCode: number;
|
|
70
|
+
readonly reason: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface AnnotationEvent extends BaseEvent {
|
|
74
|
+
readonly type: 'annotation';
|
|
75
|
+
readonly label: string;
|
|
76
|
+
readonly data: unknown;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type TraceEvent =
|
|
80
|
+
| ControlMessageEvent
|
|
81
|
+
| StreamOpenedEvent
|
|
82
|
+
| StreamClosedEvent
|
|
83
|
+
| ObjectHeaderEvent
|
|
84
|
+
| ObjectPayloadEvent
|
|
85
|
+
| StateChangeEvent
|
|
86
|
+
| TraceErrorEvent
|
|
87
|
+
| AnnotationEvent;
|
|
88
|
+
|
|
89
|
+
export interface Trace {
|
|
90
|
+
readonly header: TraceHeader;
|
|
91
|
+
readonly events: TraceEvent[];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface RecorderOptions {
|
|
95
|
+
readonly detail: DetailLevel;
|
|
96
|
+
readonly protocol: string;
|
|
97
|
+
readonly perspective: Perspective;
|
|
98
|
+
readonly transport?: string;
|
|
99
|
+
readonly source?: string;
|
|
100
|
+
readonly endpoint?: string;
|
|
101
|
+
readonly sessionId?: string;
|
|
102
|
+
readonly maxEvents?: number;
|
|
103
|
+
readonly clock?: () => number;
|
|
104
|
+
/** Map message type name (e.g. 'subscribe') to wire ID (e.g. 0x03). Required for session-layer recording. */
|
|
105
|
+
readonly messageTypeId?: (name: string) => number;
|
|
106
|
+
}
|