@frondruntime/devtools 0.4.0 → 0.6.0-rc.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/dist/index.js CHANGED
@@ -1,43 +1,75 @@
1
1
  import {
2
- Attach,
3
- AttachmentInfo,
4
- EncodedEventRecord,
5
- EncodedGraphEdge,
6
- EncodedNodeSnapshot,
7
- FrondHubRpcs,
8
- GraphQuery,
9
- GraphSnapshot,
10
- HUB_ATTACH_PATH,
11
- HUB_DEFAULT_ATTACH_URL,
12
- HUB_DEFAULT_HOST,
13
- HUB_DEFAULT_PORT,
14
- HUB_PROTOCOL_VERSION,
15
- HubAttached,
16
- HubCommand,
17
- HubPing,
18
- HubQuery,
19
- HubRejection,
20
- Ingest,
21
- NodeQuery,
22
- QueryOutcome,
23
- Reply,
24
- RuntimeEventCategory,
25
- RuntimeEventSeverity,
26
- RuntimeEventTimeline,
27
- RuntimeWorkPriority,
28
- RuntimeWorkReason,
29
- RuntimeWorkSource,
30
- StateQuery,
31
- ValuePolicy
32
- } from "./chunk-71tmgh2e.js";
2
+ HUB_PROTOCOL_VERSION2,
3
+ HUB_DEFAULT_PORT2,
4
+ HUB_DEFAULT_HOST2,
5
+ HUB_ATTACH_PATH2,
6
+ HUB_DEFAULT_ATTACH_URL2,
7
+ ValuePolicy2,
8
+ RuntimeEventCategory2,
9
+ RuntimeEventSeverity2,
10
+ RuntimeEventTimeline2,
11
+ RuntimeWorkSource2,
12
+ RuntimeWorkReason2,
13
+ RuntimeWorkPriority2,
14
+ AttachmentInfo2,
15
+ EncodedEventRecord2,
16
+ EncodedNodeSnapshot2,
17
+ EncodedGraphEdge2,
18
+ GraphSnapshot2,
19
+ GraphQuery2,
20
+ NodeQuery2,
21
+ StateQuery2,
22
+ QueryOutcome2,
23
+ HubAttached2,
24
+ HubPing2,
25
+ HubQuery2,
26
+ HubCommand2,
27
+ HubRejection2,
28
+ Attach2,
29
+ Ingest2,
30
+ Reply2,
31
+ FrondHubRpcs2
32
+ } from "./chunk-tky04mfa.js";
33
33
 
34
34
  // src/attach.ts
35
- import { Clock, Effect, Layer, Stream } from "effect";
36
- import { RpcClient, RpcSerialization } from "effect/unstable/rpc";
37
- import { Socket } from "effect/unstable/socket";
35
+ import { Clock, Effect, Layer, Option, Schema, Stream } from "effect";
36
+ import { RpcClient, RpcSerialization } from "effect/rpc";
37
+ import { Socket } from "effect/socket";
38
38
 
39
39
  // src/cause.ts
40
40
  import { Diagnostics } from "@frondruntime/core";
41
+
42
+ // src/descriptors.ts
43
+ var WITHHELD = "withheld";
44
+ var UNREADABLE = { _: "opaque", type: "unreadable" };
45
+ var NOT_A_NUMBER = { _: "opaque", type: "number:NaN" };
46
+ var POSITIVE_INFINITY = { _: "opaque", type: "number:Infinity" };
47
+ var NEGATIVE_INFINITY = { _: "opaque", type: "number:-Infinity" };
48
+ function describeNonFiniteNumber(value) {
49
+ return value > 0 ? POSITIVE_INFINITY : value < 0 ? NEGATIVE_INFINITY : NOT_A_NUMBER;
50
+ }
51
+ function typeName(value) {
52
+ try {
53
+ const name = value.constructor?.name;
54
+ return typeof name === "string" ? name : "object";
55
+ } catch {
56
+ return "object";
57
+ }
58
+ }
59
+ function setField(record, key, value) {
60
+ if (key === "__proto__") {
61
+ Object.defineProperty(record, key, {
62
+ value,
63
+ enumerable: true,
64
+ writable: true,
65
+ configurable: true
66
+ });
67
+ } else {
68
+ record[key] = value;
69
+ }
70
+ }
71
+
72
+ // src/cause.ts
41
73
  var CAUSE_MAX_DEPTH = 8;
42
74
  var SHAPE_CAUSE_STRING_LENGTH = 256;
43
75
  var FULL_CAUSE_STRING_LENGTH = 1024;
@@ -57,57 +89,134 @@ function describeError(value, policy, full) {
57
89
  maxObjectKeys: disclose ? 20 : 8
58
90
  });
59
91
  if (full === undefined) {
60
- const shed = policy === "none" ? { path: undefined, valueKind: undefined } : {};
61
92
  return {
62
93
  _: "error",
63
94
  message: rootMessage(frames),
64
- causes: frames.map((frame) => compact({ ...frame, ...shed, stack: undefined, preview: undefined }))
95
+ causes: reduceChain(frames, policy)
65
96
  };
66
97
  }
67
98
  const links = causeValues(value, frames.length);
68
- const marked = links.filter((link) => typeof link === "object" && link !== null && !full.seen.has(link));
69
- for (const link of marked) {
70
- full.seen.add(link);
99
+ let marked = 0;
100
+ for (let index = 0;index < links.length; index++) {
101
+ const link = links[index];
102
+ if (typeof link === "object" && link !== null && !full.seen.has(link)) {
103
+ full.seen.add(link);
104
+ marked |= 1 << index;
105
+ }
71
106
  }
72
107
  try {
73
- return {
74
- _: "error",
75
- message: rootMessage(frames),
76
- causes: frames.map((frame, index) => compact({
77
- ...frame,
78
- preview: undefined,
79
- stack: frame.stack === undefined ? undefined : abridgeStack(frame.stack),
80
- fields: errorFields(links[index], full.encodeValue)
81
- }))
82
- };
108
+ const causes = reduceChain(frames, policy);
109
+ for (let index = 0;index < causes.length; index++) {
110
+ const fields = errorFields(links[index], full.encodeValue);
111
+ if (fields !== undefined) {
112
+ causes[index]["fields"] = fields;
113
+ }
114
+ }
115
+ return { _: "error", message: rootMessage(frames), causes };
83
116
  } finally {
84
- for (const link of marked) {
85
- full.seen.delete(link);
117
+ for (let index = 0;index < links.length; index++) {
118
+ if ((marked & 1 << index) !== 0) {
119
+ full.seen.delete(links[index]);
120
+ }
86
121
  }
87
122
  }
88
123
  }
124
+ function reduceChain(chain, policy) {
125
+ const reduced = [];
126
+ for (let index = 0;index < chain.length; index++) {
127
+ reduced.push(reduceFrame(chain[index], policy));
128
+ }
129
+ return reduced;
130
+ }
131
+ function reduceFrame(frame, policy) {
132
+ const out = {};
133
+ for (const key in frame) {
134
+ if (!Object.prototype.hasOwnProperty.call(frame, key)) {
135
+ continue;
136
+ }
137
+ const value = frame[key];
138
+ if (value === undefined || key === "preview") {
139
+ continue;
140
+ }
141
+ if (key === "stack") {
142
+ if (policy === "full" && typeof value === "string") {
143
+ out[key] = abridgeStack(value);
144
+ }
145
+ } else if (key === "path") {
146
+ if (policy !== "none") {
147
+ out[key] = Array.isArray(value) ? pathOf(value) : value;
148
+ }
149
+ } else if (key === "valueKind") {
150
+ if (policy !== "none") {
151
+ out[key] = value;
152
+ }
153
+ } else if (key === "failures" && Array.isArray(value)) {
154
+ const chains = value;
155
+ const reduced = [];
156
+ for (let index = 0;index < chains.length; index++) {
157
+ reduced.push(reduceChain(chains[index], policy));
158
+ }
159
+ out[key] = reduced;
160
+ } else if (key === "cancellation" && typeof value === "object" && value !== null) {
161
+ out[key] = compact(value);
162
+ } else if (typeof value === "number") {
163
+ out[key] = value - value === 0 ? value : describeNonFiniteNumber(value);
164
+ } else {
165
+ out[key] = value;
166
+ }
167
+ }
168
+ return out;
169
+ }
170
+ function pathOf(path) {
171
+ const out = [];
172
+ for (let index = 0;index < path.length; index++) {
173
+ const entry = path[index];
174
+ out.push(entry === undefined ? "undefined" : entry);
175
+ }
176
+ return out;
177
+ }
89
178
  function abridgeStack(stack) {
90
179
  const lines = stack.split(`
91
180
  `);
92
- const first = lines.findIndex(isStackFrame);
181
+ let first = -1;
182
+ for (let index = 0;index < lines.length; index++) {
183
+ if (isStackFrame(lines[index])) {
184
+ first = index;
185
+ break;
186
+ }
187
+ }
93
188
  if (first === -1) {
94
189
  return stack.length <= FULL_CAUSE_STACK_LENGTH ? stack : `${stack.slice(0, FULL_CAUSE_STACK_LENGTH)}…`;
95
190
  }
96
- const header = lines.slice(0, first);
97
- const body = lines.slice(first).filter((line) => line.trim() !== "");
98
- const frames = body.filter(isStackFrame);
99
- const own = frames.filter((line) => !LIBRARY_STACK_FRAME.test(line));
100
- const kept = (own.length === 0 ? frames.slice(0, LIBRARY_ONLY_STACK_FRAMES) : own).slice(0, KEPT_STACK_FRAMES);
101
- const dropped = body.length - kept.length;
102
- if (dropped === 0) {
103
- return [...header, ...kept].join(`
104
- `);
191
+ let body = 0;
192
+ const leading = [];
193
+ const own = [];
194
+ for (let index = first;index < lines.length; index++) {
195
+ const line = lines[index];
196
+ if (line.trim() === "") {
197
+ continue;
198
+ }
199
+ body++;
200
+ if (!isStackFrame(line)) {
201
+ continue;
202
+ }
203
+ if (leading.length < LIBRARY_ONLY_STACK_FRAMES) {
204
+ leading.push(line);
205
+ }
206
+ if (own.length < KEPT_STACK_FRAMES && !LIBRARY_STACK_FRAME.test(line)) {
207
+ own.push(line);
208
+ }
209
+ }
210
+ const kept = own.length === 0 ? leading : own;
211
+ const out = lines.slice(0, first);
212
+ for (let index = 0;index < kept.length; index++) {
213
+ out.push(kept[index]);
105
214
  }
106
- return [
107
- ...header,
108
- ...kept,
109
- ` … ${dropped} frame${dropped === 1 ? "" : "s"} dropped: library internals, unrecognized lines, and any past the first ${KEPT_STACK_FRAMES}`
110
- ].join(`
215
+ const dropped = body - kept.length;
216
+ if (dropped !== 0) {
217
+ out.push(` … ${dropped} frame${dropped === 1 ? "" : "s"} dropped: library internals, unrecognized lines, and any past the first ${KEPT_STACK_FRAMES}`);
218
+ }
219
+ return out.join(`
111
220
  `);
112
221
  }
113
222
  function isStackFrame(line) {
@@ -150,17 +259,29 @@ function errorFields(value, encodeValue) {
150
259
  if (typeof value !== "object" || value === null) {
151
260
  return encodeValue(value);
152
261
  }
153
- const own = {};
262
+ let keys;
154
263
  try {
155
- for (const key of Object.keys(value)) {
156
- if (!NAMED_ERROR_KEYS.has(key)) {
157
- own[key] = value[key];
158
- }
159
- }
264
+ keys = Object.keys(value);
160
265
  } catch {
161
266
  return;
162
267
  }
163
- return Object.keys(own).length === 0 ? undefined : encodeValue(own);
268
+ const own = {};
269
+ let copied = 0;
270
+ for (let index = 0;index < keys.length; index++) {
271
+ const key = keys[index];
272
+ if (NAMED_ERROR_KEYS.has(key)) {
273
+ continue;
274
+ }
275
+ let field;
276
+ try {
277
+ field = value[key];
278
+ } catch {
279
+ field = UNREADABLE;
280
+ }
281
+ setField(own, key, field);
282
+ copied++;
283
+ }
284
+ return copied === 0 ? undefined : encodeValue(own);
164
285
  }
165
286
  function rootMessage(frames) {
166
287
  for (let index = frames.length - 1;index >= 0; index -= 1) {
@@ -172,9 +293,13 @@ function rootMessage(frames) {
172
293
  }
173
294
  return frames[0]?.tag ?? frames[0]?.name ?? "";
174
295
  }
175
- function compact(frame) {
296
+ function compact(record) {
176
297
  const out = {};
177
- for (const [key, value] of Object.entries(frame)) {
298
+ for (const key in record) {
299
+ if (!Object.prototype.hasOwnProperty.call(record, key)) {
300
+ continue;
301
+ }
302
+ const value = record[key];
178
303
  if (value !== undefined) {
179
304
  out[key] = value;
180
305
  }
@@ -182,10 +307,6 @@ function compact(frame) {
182
307
  return out;
183
308
  }
184
309
 
185
- // src/descriptors.ts
186
- var WITHHELD = "withheld";
187
- var UNREADABLE = { _: "opaque", type: "unreadable" };
188
-
189
310
  // src/full.ts
190
311
  var FULL_MAX_DEPTH = 24;
191
312
  var FULL_MAX_STRING_LENGTH = 65536;
@@ -200,17 +321,19 @@ function describeFull(value, depth, seen, budget) {
200
321
  return value ?? null;
201
322
  }
202
323
  switch (typeof value) {
203
- case "boolean":
204
- case "number": {
324
+ case "boolean": {
205
325
  return value;
206
326
  }
327
+ case "number": {
328
+ return value - value === 0 ? value : describeNonFiniteNumber(value);
329
+ }
207
330
  case "bigint": {
208
331
  return { _: "opaque", type: `bigint:${value.toString()}` };
209
332
  }
210
333
  case "function": {
211
334
  return {
212
335
  _: "opaque",
213
- type: `function:${value.name || "anonymous"}`
336
+ type: `function:${functionName(value)}`
214
337
  };
215
338
  }
216
339
  case "symbol": {
@@ -248,7 +371,8 @@ function describeFullStructureUnguarded(value, depth, seen, budget) {
248
371
  return described;
249
372
  }
250
373
  if (value instanceof Date) {
251
- return value.toISOString();
374
+ const iso = value.toISOString();
375
+ return typeof iso === "string" ? iso : UNREADABLE;
252
376
  }
253
377
  if (depth >= FULL_MAX_DEPTH) {
254
378
  return { _: "elided", by: "depth" };
@@ -256,39 +380,86 @@ function describeFullStructureUnguarded(value, depth, seen, budget) {
256
380
  seen.add(value);
257
381
  try {
258
382
  if (Array.isArray(value)) {
259
- const kept = value.slice(0, FULL_MAX_ENTRIES);
260
- const encoded = kept.map((entry) => describeFull(entry, depth + 1, seen, budget));
261
- if (value.length > FULL_MAX_ENTRIES) {
262
- encoded.push({
263
- _: "elided",
264
- by: "entries",
265
- length: value.length
266
- });
383
+ const length = arrayLength(value);
384
+ const count = typeof length === "number" && length > 0 ? Math.min(Math.floor(length), FULL_MAX_ENTRIES) : 0;
385
+ const encoded = [];
386
+ for (let index = 0;index < count; index++) {
387
+ let entry;
388
+ try {
389
+ entry = value[index];
390
+ } catch {
391
+ encoded.push(UNREADABLE);
392
+ continue;
393
+ }
394
+ encoded.push(describeFull(entry, depth + 1, seen, budget));
395
+ }
396
+ if (typeof length === "number" && length > FULL_MAX_ENTRIES) {
397
+ encoded.push(entriesCut(finiteNumber(length)));
267
398
  }
268
399
  return encoded;
269
400
  }
270
401
  if (value instanceof Map) {
271
- return {
272
- _: "map",
273
- entries: [...value.entries()].slice(0, FULL_MAX_ENTRIES).map(([key, entry]) => [
274
- describeFull(key, depth + 1, seen, budget),
275
- describeFull(entry, depth + 1, seen, budget)
276
- ]),
277
- size: value.size
278
- };
402
+ const walk = readSteps(value.entries());
403
+ const entries = [];
404
+ for (let index = 0;index < walk.values.length; index++) {
405
+ const pair = walk.values[index];
406
+ entries.push([
407
+ describeStepValue(halfOf(pair, 0), depth, seen, budget),
408
+ describeStepValue(halfOf(pair, 1), depth, seen, budget)
409
+ ]);
410
+ }
411
+ const reported = collectionSize(value);
412
+ const size = reported ?? entries.length;
413
+ switch (walk.end) {
414
+ case "broken": {
415
+ entries.push([UNREADABLE, UNREADABLE]);
416
+ break;
417
+ }
418
+ case "cut": {
419
+ const marker = entriesCut(reported);
420
+ entries.push([marker, marker]);
421
+ break;
422
+ }
423
+ case "done": {
424
+ break;
425
+ }
426
+ }
427
+ return { _: "map", entries, size };
279
428
  }
280
429
  if (value instanceof Set) {
281
- return {
282
- _: "set",
283
- values: [...value.values()].slice(0, FULL_MAX_ENTRIES).map((entry) => describeFull(entry, depth + 1, seen, budget)),
284
- size: value.size
285
- };
430
+ const walk = readSteps(value.values());
431
+ const values = [];
432
+ for (let index = 0;index < walk.values.length; index++) {
433
+ values.push(describeStepValue(walk.values[index], depth, seen, budget));
434
+ }
435
+ const reported = collectionSize(value);
436
+ const size = reported ?? values.length;
437
+ switch (walk.end) {
438
+ case "broken": {
439
+ values.push(UNREADABLE);
440
+ break;
441
+ }
442
+ case "cut": {
443
+ values.push(entriesCut(reported));
444
+ break;
445
+ }
446
+ case "done": {
447
+ break;
448
+ }
449
+ }
450
+ return { _: "set", values, size };
286
451
  }
287
452
  const out = {};
288
453
  const allKeys = Object.keys(value);
289
454
  const keys = allKeys.slice(0, FULL_MAX_ENTRIES);
290
455
  for (const key of keys) {
291
- out[key] = describeFull(value[key], depth + 1, seen, budget);
456
+ let encoded;
457
+ try {
458
+ encoded = describeFull(value[key], depth + 1, seen, budget);
459
+ } catch {
460
+ encoded = UNREADABLE;
461
+ }
462
+ setField(out, key, encoded);
292
463
  }
293
464
  if (allKeys.length > keys.length) {
294
465
  out["_elided"] = {
@@ -299,13 +470,98 @@ function describeFullStructureUnguarded(value, depth, seen, budget) {
299
470
  }
300
471
  const prototype = Object.getPrototypeOf(value);
301
472
  if (prototype !== null && prototype !== Object.prototype) {
302
- out["_type"] = value.constructor?.name ?? "object";
473
+ out["_type"] = typeName(value);
303
474
  }
304
475
  return out;
305
476
  } finally {
306
477
  seen.delete(value);
307
478
  }
308
479
  }
480
+ var UNREADABLE_STEP = Symbol("unreadable step");
481
+ var NO_ARGUMENTS = [];
482
+ function readSteps(source) {
483
+ const method = source[Symbol.iterator];
484
+ const iterator = typeof method === "function" ? Reflect.apply(method, source, NO_ARGUMENTS) : source;
485
+ const next = iterator.next;
486
+ const values = [];
487
+ for (;; ) {
488
+ let step;
489
+ let done;
490
+ try {
491
+ step = Reflect.apply(next, iterator, NO_ARGUMENTS);
492
+ if (step === null || typeof step !== "object" && typeof step !== "function") {
493
+ return { values, end: "broken" };
494
+ }
495
+ done = step.done;
496
+ } catch {
497
+ return { values, end: "broken" };
498
+ }
499
+ if (done) {
500
+ return { values, end: "done" };
501
+ }
502
+ if (values.length === FULL_MAX_ENTRIES) {
503
+ return { values, end: "cut" };
504
+ }
505
+ let entry;
506
+ try {
507
+ entry = step.value;
508
+ } catch {
509
+ entry = UNREADABLE_STEP;
510
+ }
511
+ values.push(entry);
512
+ }
513
+ }
514
+ function halfOf(pair, index) {
515
+ if (pair === UNREADABLE_STEP) {
516
+ return UNREADABLE_STEP;
517
+ }
518
+ try {
519
+ return pair[index];
520
+ } catch {
521
+ return UNREADABLE_STEP;
522
+ }
523
+ }
524
+ function describeStepValue(read, depth, seen, budget) {
525
+ return read === UNREADABLE_STEP ? UNREADABLE : describeFull(read, depth + 1, seen, budget);
526
+ }
527
+ var MAX_ARRAY_INDEX = 2 ** 32 - 2;
528
+ function arrayLength(value) {
529
+ try {
530
+ return value.length;
531
+ } catch {
532
+ const keys = Object.getOwnPropertyNames(value);
533
+ let length = 0;
534
+ for (let index = 0;index < keys.length; index++) {
535
+ const key = keys[index];
536
+ const position = Number(key);
537
+ if (position >= length && position <= MAX_ARRAY_INDEX && String(position) === key && Number.isInteger(position)) {
538
+ length = position + 1;
539
+ }
540
+ }
541
+ return length;
542
+ }
543
+ }
544
+ function functionName(value) {
545
+ try {
546
+ const name = value.name;
547
+ return typeof name === "string" && name !== "" ? name : "anonymous";
548
+ } catch {
549
+ return "anonymous";
550
+ }
551
+ }
552
+ function collectionSize(value) {
553
+ try {
554
+ return finiteNumber(value.size);
555
+ } catch {
556
+ return;
557
+ }
558
+ }
559
+ function entriesCut(length) {
560
+ return length === undefined ? { _: "elided", by: "entries" } : { _: "elided", by: "entries", length };
561
+ }
562
+ function finiteNumber(reported) {
563
+ return typeof reported === "number" && reported - reported === 0 ? reported : undefined;
564
+ }
309
565
 
310
566
  // src/shape.ts
311
567
  var MAX_STRING_LENGTH = 256;
@@ -316,10 +572,12 @@ function describeShape(value, depth) {
316
572
  return value ?? null;
317
573
  }
318
574
  switch (typeof value) {
319
- case "boolean":
320
- case "number": {
575
+ case "boolean": {
321
576
  return value;
322
577
  }
578
+ case "number": {
579
+ return value - value === 0 ? value : describeNonFiniteNumber(value);
580
+ }
323
581
  case "bigint":
324
582
  case "function":
325
583
  case "symbol": {
@@ -352,8 +610,7 @@ function describeStructureUnguarded(value, depth) {
352
610
  return Array.isArray(value) ? "[…]" : "{…}";
353
611
  }
354
612
  if (Array.isArray(value)) {
355
- const first = value[0];
356
- return `${first === undefined ? "unknown" : shapeName(first, depth + 1)}[${value.length}]`;
613
+ return `${firstElementName(value, depth + 1)}[${lengthLabel(value)}]`;
357
614
  }
358
615
  if (value instanceof Map) {
359
616
  return `Map(${value.size})`;
@@ -363,12 +620,36 @@ function describeStructureUnguarded(value, depth) {
363
620
  }
364
621
  const prototype = Object.getPrototypeOf(value);
365
622
  if (prototype !== null && prototype !== Object.prototype) {
366
- return `${value.constructor?.name ?? "object"}{?}`;
623
+ return `${typeName(value)}{?}`;
367
624
  }
368
625
  const keys = Object.keys(value);
369
- const shown = keys.length > MAX_KEYS ? [...keys.slice(0, MAX_KEYS), "…"] : keys;
370
- const tag = value._tag;
371
- return `${typeof tag === "string" ? tag : ""}{${shown.join(",")}}`;
626
+ if (keys.length > MAX_KEYS) {
627
+ keys.length = MAX_KEYS;
628
+ keys.push("…");
629
+ }
630
+ let tag;
631
+ try {
632
+ tag = value._tag;
633
+ } catch {
634
+ tag = undefined;
635
+ }
636
+ return `${typeof tag === "string" ? tag : ""}{${keys.join(",")}}`;
637
+ }
638
+ function firstElementName(value, depth) {
639
+ let first;
640
+ try {
641
+ first = value[0];
642
+ } catch {
643
+ return "unreadable";
644
+ }
645
+ return first === undefined ? "unknown" : shapeName(first, depth);
646
+ }
647
+ function lengthLabel(value) {
648
+ try {
649
+ return `${value.length}`;
650
+ } catch {
651
+ return "?";
652
+ }
372
653
  }
373
654
  function shapeName(value, depth) {
374
655
  if (value === null) {
@@ -378,43 +659,80 @@ function shapeName(value, depth) {
378
659
  return typeof value;
379
660
  }
380
661
  const described = describeStructure(value, depth);
381
- return typeof described === "string" ? described : "error";
662
+ if (typeof described === "string") {
663
+ return described;
664
+ }
665
+ return described === UNREADABLE ? "unreadable" : "error";
382
666
  }
383
667
 
384
668
  // src/encode.ts
385
669
  function createValueEncoder(policy) {
386
670
  if (policy === "none") {
387
- return {
388
- value: () => WITHHELD,
389
- failure: (value) => describeError(value, policy)
390
- };
671
+ return { value: withheldValue, failure: noneFailure };
391
672
  }
392
673
  if (policy === "shape") {
393
- return {
394
- value: (value) => describeShape(value, 0),
395
- failure: (value) => describeError(value, policy)
396
- };
674
+ return { value: shapeValue, failure: shapeFailure };
397
675
  }
398
676
  const budget = { remaining: FULL_MAX_NODES };
399
677
  return {
400
- value: (value) => describeFull(value, 0, new Set, budget),
401
- failure: (value) => {
402
- const seen = new Set;
403
- return describeError(value, policy, {
404
- seen,
405
- encodeValue: (own) => describeFull(own, 1, seen, budget)
406
- });
407
- }
678
+ value: (value) => fullValue(value, budget),
679
+ failure: (value) => fullFailure(value, budget)
408
680
  };
409
681
  }
682
+ function withheldValue() {
683
+ return WITHHELD;
684
+ }
685
+ function noneFailure(value) {
686
+ return describeError(value, "none");
687
+ }
688
+ function shapeValue(value) {
689
+ return describeShape(value, 0);
690
+ }
691
+ function shapeFailure(value) {
692
+ return describeError(value, "shape");
693
+ }
694
+ function fullValue(value, budget) {
695
+ return describeFull(value, 0, new Set, budget);
696
+ }
697
+ function fullFailure(value, budget) {
698
+ const seen = new Set;
699
+ return describeError(value, "full", {
700
+ seen,
701
+ encodeValue: (own) => describeFull(own, 1, seen, budget)
702
+ });
703
+ }
704
+ function encodeValueAt(policy, value, budget) {
705
+ switch (policy) {
706
+ case "none": {
707
+ return WITHHELD;
708
+ }
709
+ case "shape": {
710
+ return describeShape(value, 0);
711
+ }
712
+ case "full": {
713
+ return fullValue(value, budget);
714
+ }
715
+ }
716
+ }
717
+ function encodeFailureAt(policy, value, budget) {
718
+ switch (policy) {
719
+ case "none":
720
+ case "shape": {
721
+ return describeError(value, policy);
722
+ }
723
+ case "full": {
724
+ return fullFailure(value, budget);
725
+ }
726
+ }
727
+ }
728
+ var UNSPENT = Object.freeze({ remaining: FULL_MAX_NODES });
410
729
  function encodeRecord(record, policy) {
411
- const encoder = createValueEncoder(policy);
412
- const known = new Set(record.failures.filter((failure) => typeof failure === "object" && failure !== null));
413
- const encodeField = (value) => typeof value === "object" && value !== null && known.has(value) ? encoder.failure(value) : encoder.value(value);
414
- return {
730
+ const budget = policy === "full" ? { remaining: FULL_MAX_NODES } : UNSPENT;
731
+ const event = record.event;
732
+ const encoded = {
415
733
  sequence: record.sequence,
416
734
  recordedAt: record.recordedAt,
417
- tag: record.event._tag,
735
+ tag: event._tag,
418
736
  category: record.classification.category,
419
737
  severity: record.classification.severity,
420
738
  timeline: record.classification.timeline,
@@ -424,23 +742,72 @@ function encodeRecord(record, policy) {
424
742
  source: record.work.source,
425
743
  reason: record.work.reason,
426
744
  priority: record.work.priority,
427
- nodeIds: record.nodeIds,
428
- ...signalIdentity(record.event),
429
- fields: policy === "none" ? {} : describeFields(record.event, encodeField),
430
- failures: record.failures.map(encoder.failure)
745
+ nodeIds: record.nodeIds
431
746
  };
747
+ writeSignalIdentity(encoded, event);
748
+ encoded.fields = policy === "none" ? {} : describeFields(event, policy, budget, record.failures);
749
+ const source = record.failures;
750
+ const length = source.length;
751
+ const failures = new Array(length);
752
+ for (let index = 0;index < length; index++) {
753
+ if (index in source) {
754
+ failures[index] = encodeFailureAt(policy, source[index], budget);
755
+ }
756
+ }
757
+ encoded.failures = failures;
758
+ return encoded;
759
+ }
760
+ function writeSignalIdentity(encoded, event) {
761
+ switch (event._tag) {
762
+ case "RuntimeSignalPublished": {
763
+ writeIdentityOf(encoded, readGuarded(readGuarded(event, "record"), "signal"));
764
+ return;
765
+ }
766
+ case "RuntimeSignalSubscriberFailureObserved": {
767
+ writeIdentityOf(encoded, readGuarded(readGuarded(event, "signal"), "signal"));
768
+ return;
769
+ }
770
+ default: {
771
+ return;
772
+ }
773
+ }
774
+ }
775
+ function writeIdentityOf(encoded, signal) {
776
+ const channel = readGuarded(signal, "channel");
777
+ const name = readGuarded(signal, "name");
778
+ if (typeof channel === "string") {
779
+ encoded.channel = channel;
780
+ }
781
+ if (typeof name === "string") {
782
+ encoded.name = name;
783
+ }
432
784
  }
433
- function signalIdentity(event) {
434
- const signal = event._tag === "RuntimeSignalPublished" ? event.record.signal : event._tag === "RuntimeSignalSubscriberFailureObserved" ? event.signal.signal : undefined;
435
- return signal === undefined ? {} : { channel: signal.channel, name: signal.name };
785
+ function readGuarded(target, key) {
786
+ if (typeof target !== "object" || target === null) {
787
+ return;
788
+ }
789
+ try {
790
+ return target[key];
791
+ } catch {
792
+ return;
793
+ }
436
794
  }
437
- function describeFields(event, encodeValue) {
795
+ function describeFields(event, policy, budget, failures) {
438
796
  const fields = {};
439
- for (const [key, value] of Object.entries(event)) {
797
+ const keys = Object.keys(event);
798
+ for (let index = 0;index < keys.length; index++) {
799
+ const key = keys[index];
440
800
  if (key === "_tag") {
441
801
  continue;
442
802
  }
443
- fields[key] = encodeValue(value);
803
+ let value;
804
+ try {
805
+ value = event[key];
806
+ } catch {
807
+ setField(fields, key, UNREADABLE);
808
+ continue;
809
+ }
810
+ setField(fields, key, typeof value === "object" && value !== null && failures.includes(value) ? encodeFailureAt(policy, value, budget) : encodeValueAt(policy, value, budget));
444
811
  }
445
812
  return fields;
446
813
  }
@@ -537,7 +904,10 @@ function attachLayer(attachUrl) {
537
904
  return RpcClient.layerProtocolSocket().pipe(Layer.provide(Socket.layerWebSocket(attachUrl)), Layer.provide(Socket.layerWebSocketConstructorGlobal), Layer.provide(RpcSerialization.layerNdjson));
538
905
  }
539
906
  var attachRuntime = Effect.fnUntraced(function* (options) {
540
- const client = yield* RpcClient.make(FrondHubRpcs);
907
+ const client = yield* RpcClient.make(FrondHubRpcs2);
908
+ const { codecFor } = yield* RpcClient.Protocol;
909
+ const encodeForWire = Schema.encodeUnknownOption(codecFor(EncodedEventRecord2));
910
+ const crossesTheWire = (record) => Option.isSome(encodeForWire(record));
541
911
  const ceiling = options.values ?? "shape";
542
912
  let buffer = [];
543
913
  let dropped = 0;
@@ -555,7 +925,7 @@ var attachRuntime = Effect.fnUntraced(function* (options) {
555
925
  });
556
926
  yield* Effect.addFinalizer(() => Effect.sync(() => subscription.unsubscribe()));
557
927
  const info = {
558
- protocolVersion: HUB_PROTOCOL_VERSION,
928
+ protocolVersion: HUB_PROTOCOL_VERSION2,
559
929
  instanceId: options.instanceId ?? newInstanceId(),
560
930
  runtimeId: options.runtime.getSnapshotSync().runtimeId,
561
931
  generation: options.generation ?? 0,
@@ -574,9 +944,15 @@ var attachRuntime = Effect.fnUntraced(function* (options) {
574
944
  const droppedSince = dropped;
575
945
  buffer = [];
576
946
  dropped = 0;
577
- yield* client["Frond.Ingest"]({ attachmentId: id, records, droppedSince });
947
+ yield* Effect.catchCause(client["Frond.Ingest"]({ attachmentId: id, records, droppedSince }), (cause) => {
948
+ const sendable = records.filter(crossesTheWire);
949
+ return sendable.length === records.length ? Effect.failCause(cause) : client["Frond.Ingest"]({
950
+ attachmentId: id,
951
+ records: sendable,
952
+ droppedSince: droppedSince + records.length - sendable.length
953
+ });
954
+ });
578
955
  });
579
- yield* Effect.forkScoped(Effect.forever(flushOnce));
580
956
  const answer = (command) => Effect.gen(function* () {
581
957
  const id = attachmentId;
582
958
  if (id === undefined) {
@@ -593,7 +969,7 @@ var attachRuntime = Effect.fnUntraced(function* (options) {
593
969
  })), (exit) => exit._tag === "Success" ? { _tag: "Snapshot", snapshot: exit.value } : { _tag: "Failed", reason: failureReason(exit.cause) });
594
970
  yield* Effect.ignore(client["Frond.Reply"]({ attachmentId: id, requestId: command.requestId, outcome }));
595
971
  });
596
- yield* Stream.runForEach(client["Frond.Attach"]({ info }), (command) => {
972
+ const commands = Stream.runForEach(client["Frond.Attach"]({ info }), (command) => {
597
973
  if (command._tag === "Attached") {
598
974
  return Effect.sync(() => {
599
975
  attachmentId = command.attachmentId;
@@ -606,6 +982,7 @@ var attachRuntime = Effect.fnUntraced(function* (options) {
606
982
  }
607
983
  return Effect.void;
608
984
  });
985
+ yield* Effect.raceFirst(commands, Effect.forever(flushOnce));
609
986
  });
610
987
  function failureReason(cause) {
611
988
  if (cause instanceof Error) {
@@ -621,14 +998,14 @@ class AttachRefused extends Data.TaggedError("AttachRefused") {
621
998
  }
622
999
  function refusal(cause) {
623
1000
  for (const reason of cause.reasons) {
624
- if (Cause.isFailReason(reason) && reason.error instanceof HubRejection) {
1001
+ if (Cause.isFailReason(reason) && reason.error instanceof HubRejection2) {
625
1002
  return reason.error;
626
1003
  }
627
1004
  }
628
1005
  return;
629
1006
  }
630
1007
  function attachDevtools(options) {
631
- const url = options.url ?? HUB_DEFAULT_ATTACH_URL;
1008
+ const url = options.url ?? HUB_DEFAULT_ATTACH_URL2;
632
1009
  const instanceId = options.instanceId ?? newInstanceId();
633
1010
  let generation = 0;
634
1011
  const session = Effect2.suspend(() => attachRuntime({
@@ -671,43 +1048,43 @@ function detectPlatform() {
671
1048
  return "unknown";
672
1049
  }
673
1050
  export {
674
- resolvePolicy,
675
- encodeRecord,
676
- encodeGraphSnapshot,
677
- createValueEncoder,
678
- attachRuntime,
679
- attachLayer,
1051
+ Attach2 as Attach,
1052
+ AttachmentInfo2 as AttachmentInfo,
1053
+ EncodedEventRecord2 as EncodedEventRecord,
1054
+ EncodedGraphEdge2 as EncodedGraphEdge,
1055
+ EncodedNodeSnapshot2 as EncodedNodeSnapshot,
1056
+ FrondHubRpcs2 as FrondHubRpcs,
1057
+ GraphQuery2 as GraphQuery,
1058
+ GraphSnapshot2 as GraphSnapshot,
1059
+ HUB_ATTACH_PATH2 as HUB_ATTACH_PATH,
1060
+ HUB_DEFAULT_ATTACH_URL2 as HUB_DEFAULT_ATTACH_URL,
1061
+ HUB_DEFAULT_HOST2 as HUB_DEFAULT_HOST,
1062
+ HUB_DEFAULT_PORT2 as HUB_DEFAULT_PORT,
1063
+ HUB_PROTOCOL_VERSION2 as HUB_PROTOCOL_VERSION,
1064
+ HubAttached2 as HubAttached,
1065
+ HubCommand2 as HubCommand,
1066
+ HubPing2 as HubPing,
1067
+ HubQuery2 as HubQuery,
1068
+ HubRejection2 as HubRejection,
1069
+ Ingest2 as Ingest,
1070
+ NodeQuery2 as NodeQuery,
1071
+ QueryOutcome2 as QueryOutcome,
1072
+ Reply2 as Reply,
1073
+ RuntimeEventCategory2 as RuntimeEventCategory,
1074
+ RuntimeEventSeverity2 as RuntimeEventSeverity,
1075
+ RuntimeEventTimeline2 as RuntimeEventTimeline,
1076
+ RuntimeWorkPriority2 as RuntimeWorkPriority,
1077
+ RuntimeWorkReason2 as RuntimeWorkReason,
1078
+ RuntimeWorkSource2 as RuntimeWorkSource,
1079
+ StateQuery2 as StateQuery,
1080
+ ValuePolicy2 as ValuePolicy,
680
1081
  attachDevtools,
681
- ValuePolicy,
682
- StateQuery,
683
- RuntimeWorkSource,
684
- RuntimeWorkReason,
685
- RuntimeWorkPriority,
686
- RuntimeEventTimeline,
687
- RuntimeEventSeverity,
688
- RuntimeEventCategory,
689
- Reply,
690
- QueryOutcome,
691
- NodeQuery,
692
- Ingest,
693
- HubRejection,
694
- HubQuery,
695
- HubPing,
696
- HubCommand,
697
- HubAttached,
698
- HUB_PROTOCOL_VERSION,
699
- HUB_DEFAULT_PORT,
700
- HUB_DEFAULT_HOST,
701
- HUB_DEFAULT_ATTACH_URL,
702
- HUB_ATTACH_PATH,
703
- GraphSnapshot,
704
- GraphQuery,
705
- FrondHubRpcs,
706
- EncodedNodeSnapshot,
707
- EncodedGraphEdge,
708
- EncodedEventRecord,
709
- AttachmentInfo,
710
- Attach
1082
+ attachLayer,
1083
+ attachRuntime,
1084
+ createValueEncoder,
1085
+ encodeGraphSnapshot,
1086
+ encodeRecord,
1087
+ resolvePolicy
711
1088
  };
712
1089
 
713
- //# debugId=2D4EEFF071D4325764756E2164756E21
1090
+ //# debugId=A1F31E6F36A07D0A64756E2164756E21