effect-inspect 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.
Files changed (38) hide show
  1. package/README.md +122 -0
  2. package/app/dist/client/assets/index-smV05cfr.js +25 -0
  3. package/app/dist/client/assets/rolldown-runtime-CbXtAM7H.js +1 -0
  4. package/app/dist/client/assets/routes-TKgeFdSW.js +5 -0
  5. package/app/dist/client/assets/styles-B3rAZGvS.css +2 -0
  6. package/app/dist/server/assets/_tanstack-start-manifest_v-Co953HeC.js +20 -0
  7. package/app/dist/server/assets/empty-plugin-adapters-D9UWiqvJ.js +5 -0
  8. package/app/dist/server/assets/router-CN98Ramo.js +491 -0
  9. package/app/dist/server/assets/routes-eZ4XqxE9.js +3999 -0
  10. package/app/dist/server/assets/start-5Z2QO8AU.js +4 -0
  11. package/app/dist/server/server.js +1812 -0
  12. package/dist/cli.d.ts +3 -0
  13. package/dist/cli.js +29 -0
  14. package/dist/client/Client.d.ts +52 -0
  15. package/dist/client/Client.js +224 -0
  16. package/dist/client/Edge.d.ts +31 -0
  17. package/dist/client/Edge.js +108 -0
  18. package/dist/client/Inspect.d.ts +49 -0
  19. package/dist/client/Inspect.js +55 -0
  20. package/dist/client/Tracer.d.ts +31 -0
  21. package/dist/client/Tracer.js +119 -0
  22. package/dist/collector/Config.d.ts +8 -0
  23. package/dist/collector/Config.js +9 -0
  24. package/dist/collector/Server.d.ts +24 -0
  25. package/dist/collector/Server.js +172 -0
  26. package/dist/collector/Store.d.ts +86 -0
  27. package/dist/collector/Store.js +119 -0
  28. package/dist/collector/WebApp.d.ts +3 -0
  29. package/dist/collector/WebApp.js +36 -0
  30. package/dist/collector/main.d.ts +1 -0
  31. package/dist/collector/main.js +22 -0
  32. package/dist/index.d.ts +3 -0
  33. package/dist/index.js +3 -0
  34. package/dist/protocol/Codec.d.ts +575 -0
  35. package/dist/protocol/Codec.js +50 -0
  36. package/dist/protocol/Schema.d.ts +1237 -0
  37. package/dist/protocol/Schema.js +327 -0
  38. package/package.json +85 -0
@@ -0,0 +1,575 @@
1
+ /**
2
+ * NDJSON codec for the protocol unions.
3
+ *
4
+ * The whole encoding lives behind {@link Codec}: one line of JSON per message,
5
+ * `\n`-terminated. Swapping in a compact binary format later means another
6
+ * `make`-shaped factory, not touching callers.
7
+ */
8
+ import { Result } from 'effect';
9
+ declare const EncodeError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
10
+ readonly _tag: "EncodeError";
11
+ } & Readonly<A>;
12
+ /** Raised when a message cannot be encoded — an out-of-domain field value. */
13
+ export declare class EncodeError extends EncodeError_base<{
14
+ readonly reason: string;
15
+ }> {
16
+ get message(): string;
17
+ }
18
+ declare const DecodeError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
19
+ readonly _tag: "DecodeError";
20
+ } & Readonly<A>;
21
+ /** Raised when a line is not valid JSON, or not a valid message. */
22
+ export declare class DecodeError extends DecodeError_base<{
23
+ readonly line: string;
24
+ readonly reason: string;
25
+ }> {
26
+ get message(): string;
27
+ }
28
+ /** An encode/decode pair for one protocol union. */
29
+ export interface Codec<A> {
30
+ /**
31
+ * Encodes one message as a single `\n`-terminated NDJSON line.
32
+ *
33
+ * Throws {@link EncodeError} if a field is out of its schema's domain (a
34
+ * `NaN` attribute, a negative count). That is a producer bug, not a runtime
35
+ * condition, so callers that would only rethrow need no branch; use
36
+ * {@link Codec.encodeResult} where the value came from outside.
37
+ */
38
+ readonly encode: (message: A) => string;
39
+ /** {@link Codec.encode} as a `Result`, for values from an untrusted source. */
40
+ readonly encodeResult: (message: A) => Result.Result<string, EncodeError>;
41
+ /** Decodes one NDJSON line. Surrounding whitespace is tolerated. */
42
+ readonly decode: (line: string) => Result.Result<A, DecodeError>;
43
+ /**
44
+ * Decodes every non-empty line of an NDJSON chunk.
45
+ *
46
+ * Fails on the first bad line rather than skipping it: a malformed line means
47
+ * the stream is out of sync, and silently dropping telemetry is worse than
48
+ * surfacing it.
49
+ */
50
+ readonly decodeAll: (chunk: string) => Result.Result<ReadonlyArray<A>, DecodeError>;
51
+ }
52
+ /** Instrumented program → collector. */
53
+ export declare const clientCodec: Codec<{
54
+ readonly sessionId: string;
55
+ readonly _tag: "Hello";
56
+ readonly program: string;
57
+ readonly pid: number;
58
+ readonly runtime: string;
59
+ readonly protocolVersion: number;
60
+ readonly clock: {
61
+ readonly startTime: bigint;
62
+ readonly wallClockEpochMillis: number;
63
+ };
64
+ } | {
65
+ readonly sessionId: string;
66
+ readonly _tag: "SpanStart";
67
+ readonly spanId: string;
68
+ readonly traceId: string;
69
+ readonly parent?: {
70
+ readonly _tag: "LocalParent";
71
+ readonly spanId: string;
72
+ } | {
73
+ readonly _tag: "ExternalParent";
74
+ readonly spanId: string;
75
+ readonly traceId: string;
76
+ readonly sampled: boolean;
77
+ } | undefined;
78
+ readonly name: string;
79
+ readonly kind: "client" | "consumer" | "internal" | "producer" | "server";
80
+ readonly startTime: bigint;
81
+ readonly attributes: {
82
+ readonly [x: string]: import("./Schema.ts").Json;
83
+ };
84
+ readonly sampled: boolean;
85
+ readonly fiberId?: number | undefined;
86
+ } | {
87
+ readonly sessionId: string;
88
+ readonly _tag: "SpanEnd";
89
+ readonly spanId: string;
90
+ readonly endTime: bigint;
91
+ readonly outcome: {
92
+ readonly _tag: "Success";
93
+ } | {
94
+ readonly _tag: "Failure";
95
+ readonly kind: "Die" | "Fail" | "Interrupt";
96
+ readonly error: string;
97
+ readonly stack?: string | undefined;
98
+ };
99
+ readonly attributes: {
100
+ readonly [x: string]: import("./Schema.ts").Json;
101
+ };
102
+ } | {
103
+ readonly sessionId: string;
104
+ readonly _tag: "SpanEvent";
105
+ readonly spanId: string;
106
+ readonly name: string;
107
+ readonly time: bigint;
108
+ readonly attributes: {
109
+ readonly [x: string]: import("./Schema.ts").Json;
110
+ };
111
+ } | {
112
+ readonly sessionId: string;
113
+ readonly _tag: "Log";
114
+ readonly time: bigint;
115
+ readonly level: "All" | "Debug" | "Error" | "Fatal" | "Info" | "None" | "Trace" | "Warn";
116
+ readonly message: import("./Schema.ts").Json;
117
+ readonly spanId?: string | undefined;
118
+ readonly fiberId?: number | undefined;
119
+ readonly annotations: {
120
+ readonly [x: string]: import("./Schema.ts").Json;
121
+ };
122
+ } | {
123
+ readonly sessionId: string;
124
+ readonly _tag: "Metrics";
125
+ readonly time: bigint;
126
+ readonly metrics: readonly ({
127
+ readonly type: "Counter";
128
+ readonly name: string;
129
+ readonly description?: string | undefined;
130
+ readonly attributes: {
131
+ readonly [x: string]: string;
132
+ };
133
+ readonly state: {
134
+ readonly count: number;
135
+ readonly incremental: boolean;
136
+ };
137
+ } | {
138
+ readonly type: "Gauge";
139
+ readonly name: string;
140
+ readonly description?: string | undefined;
141
+ readonly attributes: {
142
+ readonly [x: string]: string;
143
+ };
144
+ readonly state: {
145
+ readonly value: number;
146
+ };
147
+ } | {
148
+ readonly type: "Histogram";
149
+ readonly name: string;
150
+ readonly description?: string | undefined;
151
+ readonly attributes: {
152
+ readonly [x: string]: string;
153
+ };
154
+ readonly state: {
155
+ readonly buckets: readonly (readonly [number, number])[];
156
+ readonly count: number;
157
+ readonly min: number;
158
+ readonly max: number;
159
+ readonly sum: number;
160
+ };
161
+ } | {
162
+ readonly type: "Frequency";
163
+ readonly name: string;
164
+ readonly description?: string | undefined;
165
+ readonly attributes: {
166
+ readonly [x: string]: string;
167
+ };
168
+ readonly state: {
169
+ readonly occurrences: {
170
+ readonly [x: string]: number;
171
+ };
172
+ };
173
+ } | {
174
+ readonly type: "Summary";
175
+ readonly name: string;
176
+ readonly description?: string | undefined;
177
+ readonly attributes: {
178
+ readonly [x: string]: string;
179
+ };
180
+ readonly state: {
181
+ readonly quantiles: readonly (readonly [number, number | null])[];
182
+ readonly count: number;
183
+ readonly min: number;
184
+ readonly max: number;
185
+ readonly sum: number;
186
+ };
187
+ })[];
188
+ } | {
189
+ readonly sessionId: string;
190
+ readonly _tag: "FiberEvent";
191
+ readonly fiberId: number;
192
+ readonly event: "End" | "Resume" | "Start" | "Suspend";
193
+ readonly parentFiberId?: number | undefined;
194
+ readonly time: bigint;
195
+ } | {
196
+ readonly sessionId: string;
197
+ readonly _tag: "MemorySample";
198
+ readonly time: bigint;
199
+ readonly heapUsed: number;
200
+ readonly heapTotal: number;
201
+ readonly rss: number;
202
+ readonly external: number;
203
+ } | {
204
+ readonly sessionId: string;
205
+ readonly _tag: "Ping";
206
+ }>;
207
+ /** Collector → instrumented program. */
208
+ export declare const collectorCodec: Codec<{
209
+ readonly sessionId: string;
210
+ readonly _tag: "Pong";
211
+ } | {
212
+ readonly _tag: "MetricsRequest";
213
+ }>;
214
+ /** Collector → webapp. */
215
+ export declare const webappCodec: Codec<{
216
+ readonly _tag: "SessionList";
217
+ readonly sessions: readonly {
218
+ readonly sessionId: string;
219
+ readonly program: string;
220
+ readonly pid: number;
221
+ readonly runtime: string;
222
+ readonly clock: {
223
+ readonly startTime: bigint;
224
+ readonly wallClockEpochMillis: number;
225
+ };
226
+ readonly active: boolean;
227
+ readonly endedAtEpochMillis?: number | undefined;
228
+ }[];
229
+ } | {
230
+ readonly sessionId: string;
231
+ readonly _tag: "Backlog";
232
+ readonly messages: readonly ({
233
+ readonly sessionId: string;
234
+ readonly _tag: "Hello";
235
+ readonly program: string;
236
+ readonly pid: number;
237
+ readonly runtime: string;
238
+ readonly protocolVersion: number;
239
+ readonly clock: {
240
+ readonly startTime: bigint;
241
+ readonly wallClockEpochMillis: number;
242
+ };
243
+ } | {
244
+ readonly sessionId: string;
245
+ readonly _tag: "SpanStart";
246
+ readonly spanId: string;
247
+ readonly traceId: string;
248
+ readonly parent?: {
249
+ readonly _tag: "LocalParent";
250
+ readonly spanId: string;
251
+ } | {
252
+ readonly _tag: "ExternalParent";
253
+ readonly spanId: string;
254
+ readonly traceId: string;
255
+ readonly sampled: boolean;
256
+ } | undefined;
257
+ readonly name: string;
258
+ readonly kind: "client" | "consumer" | "internal" | "producer" | "server";
259
+ readonly startTime: bigint;
260
+ readonly attributes: {
261
+ readonly [x: string]: import("./Schema.ts").Json;
262
+ };
263
+ readonly sampled: boolean;
264
+ readonly fiberId?: number | undefined;
265
+ } | {
266
+ readonly sessionId: string;
267
+ readonly _tag: "SpanEnd";
268
+ readonly spanId: string;
269
+ readonly endTime: bigint;
270
+ readonly outcome: {
271
+ readonly _tag: "Success";
272
+ } | {
273
+ readonly _tag: "Failure";
274
+ readonly kind: "Die" | "Fail" | "Interrupt";
275
+ readonly error: string;
276
+ readonly stack?: string | undefined;
277
+ };
278
+ readonly attributes: {
279
+ readonly [x: string]: import("./Schema.ts").Json;
280
+ };
281
+ } | {
282
+ readonly sessionId: string;
283
+ readonly _tag: "SpanEvent";
284
+ readonly spanId: string;
285
+ readonly name: string;
286
+ readonly time: bigint;
287
+ readonly attributes: {
288
+ readonly [x: string]: import("./Schema.ts").Json;
289
+ };
290
+ } | {
291
+ readonly sessionId: string;
292
+ readonly _tag: "Log";
293
+ readonly time: bigint;
294
+ readonly level: "All" | "Debug" | "Error" | "Fatal" | "Info" | "None" | "Trace" | "Warn";
295
+ readonly message: import("./Schema.ts").Json;
296
+ readonly spanId?: string | undefined;
297
+ readonly fiberId?: number | undefined;
298
+ readonly annotations: {
299
+ readonly [x: string]: import("./Schema.ts").Json;
300
+ };
301
+ } | {
302
+ readonly sessionId: string;
303
+ readonly _tag: "Metrics";
304
+ readonly time: bigint;
305
+ readonly metrics: readonly ({
306
+ readonly type: "Counter";
307
+ readonly name: string;
308
+ readonly description?: string | undefined;
309
+ readonly attributes: {
310
+ readonly [x: string]: string;
311
+ };
312
+ readonly state: {
313
+ readonly count: number;
314
+ readonly incremental: boolean;
315
+ };
316
+ } | {
317
+ readonly type: "Gauge";
318
+ readonly name: string;
319
+ readonly description?: string | undefined;
320
+ readonly attributes: {
321
+ readonly [x: string]: string;
322
+ };
323
+ readonly state: {
324
+ readonly value: number;
325
+ };
326
+ } | {
327
+ readonly type: "Histogram";
328
+ readonly name: string;
329
+ readonly description?: string | undefined;
330
+ readonly attributes: {
331
+ readonly [x: string]: string;
332
+ };
333
+ readonly state: {
334
+ readonly buckets: readonly (readonly [number, number])[];
335
+ readonly count: number;
336
+ readonly min: number;
337
+ readonly max: number;
338
+ readonly sum: number;
339
+ };
340
+ } | {
341
+ readonly type: "Frequency";
342
+ readonly name: string;
343
+ readonly description?: string | undefined;
344
+ readonly attributes: {
345
+ readonly [x: string]: string;
346
+ };
347
+ readonly state: {
348
+ readonly occurrences: {
349
+ readonly [x: string]: number;
350
+ };
351
+ };
352
+ } | {
353
+ readonly type: "Summary";
354
+ readonly name: string;
355
+ readonly description?: string | undefined;
356
+ readonly attributes: {
357
+ readonly [x: string]: string;
358
+ };
359
+ readonly state: {
360
+ readonly quantiles: readonly (readonly [number, number | null])[];
361
+ readonly count: number;
362
+ readonly min: number;
363
+ readonly max: number;
364
+ readonly sum: number;
365
+ };
366
+ })[];
367
+ } | {
368
+ readonly sessionId: string;
369
+ readonly _tag: "FiberEvent";
370
+ readonly fiberId: number;
371
+ readonly event: "End" | "Resume" | "Start" | "Suspend";
372
+ readonly parentFiberId?: number | undefined;
373
+ readonly time: bigint;
374
+ } | {
375
+ readonly sessionId: string;
376
+ readonly _tag: "MemorySample";
377
+ readonly time: bigint;
378
+ readonly heapUsed: number;
379
+ readonly heapTotal: number;
380
+ readonly rss: number;
381
+ readonly external: number;
382
+ } | {
383
+ readonly sessionId: string;
384
+ readonly _tag: "Ping";
385
+ })[];
386
+ readonly complete: boolean;
387
+ } | {
388
+ readonly _tag: "Live";
389
+ readonly message: {
390
+ readonly sessionId: string;
391
+ readonly _tag: "Hello";
392
+ readonly program: string;
393
+ readonly pid: number;
394
+ readonly runtime: string;
395
+ readonly protocolVersion: number;
396
+ readonly clock: {
397
+ readonly startTime: bigint;
398
+ readonly wallClockEpochMillis: number;
399
+ };
400
+ } | {
401
+ readonly sessionId: string;
402
+ readonly _tag: "SpanStart";
403
+ readonly spanId: string;
404
+ readonly traceId: string;
405
+ readonly parent?: {
406
+ readonly _tag: "LocalParent";
407
+ readonly spanId: string;
408
+ } | {
409
+ readonly _tag: "ExternalParent";
410
+ readonly spanId: string;
411
+ readonly traceId: string;
412
+ readonly sampled: boolean;
413
+ } | undefined;
414
+ readonly name: string;
415
+ readonly kind: "client" | "consumer" | "internal" | "producer" | "server";
416
+ readonly startTime: bigint;
417
+ readonly attributes: {
418
+ readonly [x: string]: import("./Schema.ts").Json;
419
+ };
420
+ readonly sampled: boolean;
421
+ readonly fiberId?: number | undefined;
422
+ } | {
423
+ readonly sessionId: string;
424
+ readonly _tag: "SpanEnd";
425
+ readonly spanId: string;
426
+ readonly endTime: bigint;
427
+ readonly outcome: {
428
+ readonly _tag: "Success";
429
+ } | {
430
+ readonly _tag: "Failure";
431
+ readonly kind: "Die" | "Fail" | "Interrupt";
432
+ readonly error: string;
433
+ readonly stack?: string | undefined;
434
+ };
435
+ readonly attributes: {
436
+ readonly [x: string]: import("./Schema.ts").Json;
437
+ };
438
+ } | {
439
+ readonly sessionId: string;
440
+ readonly _tag: "SpanEvent";
441
+ readonly spanId: string;
442
+ readonly name: string;
443
+ readonly time: bigint;
444
+ readonly attributes: {
445
+ readonly [x: string]: import("./Schema.ts").Json;
446
+ };
447
+ } | {
448
+ readonly sessionId: string;
449
+ readonly _tag: "Log";
450
+ readonly time: bigint;
451
+ readonly level: "All" | "Debug" | "Error" | "Fatal" | "Info" | "None" | "Trace" | "Warn";
452
+ readonly message: import("./Schema.ts").Json;
453
+ readonly spanId?: string | undefined;
454
+ readonly fiberId?: number | undefined;
455
+ readonly annotations: {
456
+ readonly [x: string]: import("./Schema.ts").Json;
457
+ };
458
+ } | {
459
+ readonly sessionId: string;
460
+ readonly _tag: "Metrics";
461
+ readonly time: bigint;
462
+ readonly metrics: readonly ({
463
+ readonly type: "Counter";
464
+ readonly name: string;
465
+ readonly description?: string | undefined;
466
+ readonly attributes: {
467
+ readonly [x: string]: string;
468
+ };
469
+ readonly state: {
470
+ readonly count: number;
471
+ readonly incremental: boolean;
472
+ };
473
+ } | {
474
+ readonly type: "Gauge";
475
+ readonly name: string;
476
+ readonly description?: string | undefined;
477
+ readonly attributes: {
478
+ readonly [x: string]: string;
479
+ };
480
+ readonly state: {
481
+ readonly value: number;
482
+ };
483
+ } | {
484
+ readonly type: "Histogram";
485
+ readonly name: string;
486
+ readonly description?: string | undefined;
487
+ readonly attributes: {
488
+ readonly [x: string]: string;
489
+ };
490
+ readonly state: {
491
+ readonly buckets: readonly (readonly [number, number])[];
492
+ readonly count: number;
493
+ readonly min: number;
494
+ readonly max: number;
495
+ readonly sum: number;
496
+ };
497
+ } | {
498
+ readonly type: "Frequency";
499
+ readonly name: string;
500
+ readonly description?: string | undefined;
501
+ readonly attributes: {
502
+ readonly [x: string]: string;
503
+ };
504
+ readonly state: {
505
+ readonly occurrences: {
506
+ readonly [x: string]: number;
507
+ };
508
+ };
509
+ } | {
510
+ readonly type: "Summary";
511
+ readonly name: string;
512
+ readonly description?: string | undefined;
513
+ readonly attributes: {
514
+ readonly [x: string]: string;
515
+ };
516
+ readonly state: {
517
+ readonly quantiles: readonly (readonly [number, number | null])[];
518
+ readonly count: number;
519
+ readonly min: number;
520
+ readonly max: number;
521
+ readonly sum: number;
522
+ };
523
+ })[];
524
+ } | {
525
+ readonly sessionId: string;
526
+ readonly _tag: "FiberEvent";
527
+ readonly fiberId: number;
528
+ readonly event: "End" | "Resume" | "Start" | "Suspend";
529
+ readonly parentFiberId?: number | undefined;
530
+ readonly time: bigint;
531
+ } | {
532
+ readonly sessionId: string;
533
+ readonly _tag: "MemorySample";
534
+ readonly time: bigint;
535
+ readonly heapUsed: number;
536
+ readonly heapTotal: number;
537
+ readonly rss: number;
538
+ readonly external: number;
539
+ } | {
540
+ readonly sessionId: string;
541
+ readonly _tag: "Ping";
542
+ };
543
+ } | {
544
+ readonly sessionId: string;
545
+ readonly _tag: "SessionEnded";
546
+ readonly endedAtEpochMillis: number;
547
+ }>;
548
+ /** Webapp → collector. */
549
+ export declare const webappRequestCodec: Codec<{
550
+ readonly sessionId: string;
551
+ readonly _tag: "Subscribe";
552
+ } | {
553
+ readonly sessionId: string;
554
+ readonly _tag: "Unsubscribe";
555
+ }>;
556
+ /** Line 1 of a saved trace file; the rest of the file is {@link clientCodec} lines. */
557
+ export declare const traceFileHeaderCodec: Codec<{
558
+ readonly _tag: "TraceFileHeader";
559
+ readonly formatVersion: number;
560
+ readonly protocolVersion: number;
561
+ readonly session: {
562
+ readonly sessionId: string;
563
+ readonly program: string;
564
+ readonly pid: number;
565
+ readonly runtime: string;
566
+ readonly clock: {
567
+ readonly startTime: bigint;
568
+ readonly wallClockEpochMillis: number;
569
+ };
570
+ readonly active: boolean;
571
+ readonly endedAtEpochMillis?: number | undefined;
572
+ };
573
+ readonly savedAtEpochMillis: number;
574
+ }>;
575
+ export {};
@@ -0,0 +1,50 @@
1
+ /**
2
+ * NDJSON codec for the protocol unions.
3
+ *
4
+ * The whole encoding lives behind {@link Codec}: one line of JSON per message,
5
+ * `\n`-terminated. Swapping in a compact binary format later means another
6
+ * `make`-shaped factory, not touching callers.
7
+ */
8
+ import { Data, Result, Schema } from 'effect';
9
+ import { ClientMessage, CollectorMessage, TraceFileHeader, WebappMessage, WebappRequest, } from './Schema.js';
10
+ /** Raised when a message cannot be encoded — an out-of-domain field value. */
11
+ export class EncodeError extends Data.TaggedError('EncodeError') {
12
+ get message() {
13
+ return `Unencodable protocol message: ${this.reason}`;
14
+ }
15
+ }
16
+ /** Raised when a line is not valid JSON, or not a valid message. */
17
+ export class DecodeError extends Data.TaggedError('DecodeError') {
18
+ get message() {
19
+ return `Invalid protocol message: ${this.reason}`;
20
+ }
21
+ }
22
+ const make = (schema) => {
23
+ const json = Schema.fromJsonString(schema);
24
+ const encodeJson = Schema.encodeResult(json);
25
+ const decodeJson = Schema.decodeUnknownResult(json);
26
+ const encodeResult = (message) => Result.match(encodeJson(message), {
27
+ onSuccess: (line) => Result.succeed(`${line}\n`),
28
+ onFailure: (error) => Result.fail(new EncodeError({ reason: error.message })),
29
+ });
30
+ const decode = (line) => Result.mapError(decodeJson(line.trim()), (error) => new DecodeError({ line, reason: error.message }));
31
+ return {
32
+ encode: (message) => Result.getOrThrow(encodeResult(message)),
33
+ encodeResult,
34
+ decode,
35
+ decodeAll: (chunk) => Result.all(chunk
36
+ .split('\n')
37
+ .filter((line) => line.trim() !== '')
38
+ .map(decode)),
39
+ };
40
+ };
41
+ /** Instrumented program → collector. */
42
+ export const clientCodec = make(ClientMessage);
43
+ /** Collector → instrumented program. */
44
+ export const collectorCodec = make(CollectorMessage);
45
+ /** Collector → webapp. */
46
+ export const webappCodec = make(WebappMessage);
47
+ /** Webapp → collector. */
48
+ export const webappRequestCodec = make(WebappRequest);
49
+ /** Line 1 of a saved trace file; the rest of the file is {@link clientCodec} lines. */
50
+ export const traceFileHeaderCodec = make(TraceFileHeader);