@shadow-js/devtools 0.0.0-stage → 1.0.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 (112) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +21 -0
  3. package/README.md +576 -2
  4. package/dist/dev/agent.d.ts +239 -0
  5. package/dist/dev/agent.js +626 -0
  6. package/dist/dev/agent.js.map +1 -0
  7. package/dist/dev/backend.d.ts +53 -0
  8. package/dist/dev/backend.js +53 -0
  9. package/dist/dev/backend.js.map +1 -0
  10. package/dist/dev/hook.d.ts +83 -0
  11. package/dist/dev/hook.js +136 -0
  12. package/dist/dev/hook.js.map +1 -0
  13. package/dist/dev/index.d.ts +17 -0
  14. package/dist/dev/index.js +17 -0
  15. package/dist/dev/inspection.d.ts +226 -0
  16. package/dist/dev/inspection.js +263 -0
  17. package/dist/dev/inspection.js.map +1 -0
  18. package/dist/dev/inspector.d.ts +331 -0
  19. package/dist/dev/inspector.js +429 -0
  20. package/dist/dev/inspector.js.map +1 -0
  21. package/dist/dev/model.d.ts +418 -0
  22. package/dist/dev/model.js +559 -0
  23. package/dist/dev/model.js.map +1 -0
  24. package/dist/dev/mount.d.ts +207 -0
  25. package/dist/dev/mount.js +256 -0
  26. package/dist/dev/mount.js.map +1 -0
  27. package/dist/dev/overlay.d.ts +102 -0
  28. package/dist/dev/overlay.js +176 -0
  29. package/dist/dev/overlay.js.map +1 -0
  30. package/dist/dev/preview.d.ts +74 -0
  31. package/dist/dev/preview.js +122 -0
  32. package/dist/dev/preview.js.map +1 -0
  33. package/dist/dev/protocol.d.ts +288 -0
  34. package/dist/dev/protocol.js +109 -0
  35. package/dist/dev/protocol.js.map +1 -0
  36. package/dist/dev/ring.d.ts +50 -0
  37. package/dist/dev/ring.js +94 -0
  38. package/dist/dev/ring.js.map +1 -0
  39. package/dist/dev/transport.d.ts +347 -0
  40. package/dist/dev/transport.js +394 -0
  41. package/dist/dev/transport.js.map +1 -0
  42. package/dist/dev/ui/details.js +294 -0
  43. package/dist/dev/ui/details.js.map +1 -0
  44. package/dist/dev/ui/inspection-state.d.ts +43 -0
  45. package/dist/dev/ui/inspection-state.js +62 -0
  46. package/dist/dev/ui/inspection-state.js.map +1 -0
  47. package/dist/dev/ui/issues.js +85 -0
  48. package/dist/dev/ui/issues.js.map +1 -0
  49. package/dist/dev/ui/panel.d.ts +55 -0
  50. package/dist/dev/ui/panel.js +160 -0
  51. package/dist/dev/ui/panel.js.map +1 -0
  52. package/dist/dev/ui/rows.d.ts +44 -0
  53. package/dist/dev/ui/rows.js +132 -0
  54. package/dist/dev/ui/rows.js.map +1 -0
  55. package/dist/dev/ui/state-tab.js +88 -0
  56. package/dist/dev/ui/state-tab.js.map +1 -0
  57. package/dist/dev/ui/state.d.ts +192 -0
  58. package/dist/dev/ui/state.js +147 -0
  59. package/dist/dev/ui/state.js.map +1 -0
  60. package/dist/dev/ui/styles.d.ts +31 -0
  61. package/dist/dev/ui/styles.js +113 -0
  62. package/dist/dev/ui/styles.js.map +1 -0
  63. package/dist/dev/ui/timeline.js +135 -0
  64. package/dist/dev/ui/timeline.js.map +1 -0
  65. package/dist/dev/ui/tree.js +186 -0
  66. package/dist/dev/ui/tree.js.map +1 -0
  67. package/dist/prod/agent.js +2 -0
  68. package/dist/prod/agent.js.map +1 -0
  69. package/dist/prod/backend.js +2 -0
  70. package/dist/prod/backend.js.map +1 -0
  71. package/dist/prod/hook.js +2 -0
  72. package/dist/prod/hook.js.map +1 -0
  73. package/dist/prod/index.js +1 -0
  74. package/dist/prod/inspection.js +2 -0
  75. package/dist/prod/inspection.js.map +1 -0
  76. package/dist/prod/inspector.js +2 -0
  77. package/dist/prod/inspector.js.map +1 -0
  78. package/dist/prod/model.js +2 -0
  79. package/dist/prod/model.js.map +1 -0
  80. package/dist/prod/mount.js +2 -0
  81. package/dist/prod/mount.js.map +1 -0
  82. package/dist/prod/overlay.js +11 -0
  83. package/dist/prod/overlay.js.map +1 -0
  84. package/dist/prod/preview.js +2 -0
  85. package/dist/prod/preview.js.map +1 -0
  86. package/dist/prod/protocol.js +2 -0
  87. package/dist/prod/protocol.js.map +1 -0
  88. package/dist/prod/ring.js +2 -0
  89. package/dist/prod/ring.js.map +1 -0
  90. package/dist/prod/transport.js +2 -0
  91. package/dist/prod/transport.js.map +1 -0
  92. package/dist/prod/ui/details.js +2 -0
  93. package/dist/prod/ui/details.js.map +1 -0
  94. package/dist/prod/ui/inspection-state.js +2 -0
  95. package/dist/prod/ui/inspection-state.js.map +1 -0
  96. package/dist/prod/ui/issues.js +2 -0
  97. package/dist/prod/ui/issues.js.map +1 -0
  98. package/dist/prod/ui/panel.js +2 -0
  99. package/dist/prod/ui/panel.js.map +1 -0
  100. package/dist/prod/ui/rows.js +2 -0
  101. package/dist/prod/ui/rows.js.map +1 -0
  102. package/dist/prod/ui/state-tab.js +2 -0
  103. package/dist/prod/ui/state-tab.js.map +1 -0
  104. package/dist/prod/ui/state.js +2 -0
  105. package/dist/prod/ui/state.js.map +1 -0
  106. package/dist/prod/ui/styles.js +82 -0
  107. package/dist/prod/ui/styles.js.map +1 -0
  108. package/dist/prod/ui/timeline.js +2 -0
  109. package/dist/prod/ui/timeline.js.map +1 -0
  110. package/dist/prod/ui/tree.js +2 -0
  111. package/dist/prod/ui/tree.js.map +1 -0
  112. package/package.json +69 -4
@@ -0,0 +1,239 @@
1
+ import { DevtoolsHook, HookSink, WireEvent } from "./protocol.js";
2
+ import { RingBuffer } from "./ring.js";
3
+ import { InspectorModel, ModelLimits, ModelState } from "./model.js";
4
+ import { GraphSnapshot } from "./inspector.js";
5
+ //#region src/agent.d.ts
6
+ /**
7
+ * Options of {@link createAgent}. Every field is optional.
8
+ *
9
+ * @since 1.0.0
10
+ */
11
+ export interface AgentOptions {
12
+ /** Capacities of the model's buffers. The values left out take the defaults of `DEFAULT_LIMITS`. */
13
+ limits?: Partial<ModelLimits>;
14
+ /**
15
+ * Raw events kept for the events log. The newest are kept; older ones are overwritten and counted
16
+ * in `dropped`.
17
+ *
18
+ * @default 10000
19
+ */
20
+ events?: number;
21
+ /**
22
+ * Most events waiting for subscribers. When this many are pending they are delivered at once,
23
+ * instead of at the end of the current microtask.
24
+ *
25
+ * @default 10000
26
+ */
27
+ maxPending?: number;
28
+ /**
29
+ * Maximum length of a value preview, in characters.
30
+ *
31
+ * @default 80
32
+ */
33
+ previewLength?: number;
34
+ /**
35
+ * The clock, in milliseconds. Defaults to `performance.now` (or `Date.now` where it is missing).
36
+ */
37
+ now?: () => number;
38
+ /**
39
+ * Writes a signal node for the value editor. Pass `writeSignal` from `@shadow-js/core/extend`.
40
+ * Without it signals are shown but not editable: a write is refused with "Editing is not enabled.".
41
+ */
42
+ writeSignal?: (node: never, value: never) => unknown;
43
+ }
44
+ /**
45
+ * Counters of what the agent saw. They keep growing while the agent runs; {@link Agent.clear} does not
46
+ * reset them.
47
+ *
48
+ * @since 1.0.0
49
+ */
50
+ export interface AgentStats {
51
+ /** Events the agent was offered while it was not paused. */
52
+ received: number;
53
+ /** Events turned into wire events. */
54
+ recorded: number;
55
+ /**
56
+ * Events the agent skipped on purpose: objects created inside {@link Agent.quiet} (the tools' own
57
+ * UI), dispose and unmount events for objects it never named, malformed store handles, and event
58
+ * kinds from a newer runtime.
59
+ */
60
+ ignored: number;
61
+ /**
62
+ * Writes, runs and mounts about objects the agent never saw created (reported before it attached,
63
+ * when the hook's replay buffer had been released).
64
+ */
65
+ unknown: number;
66
+ }
67
+ /**
68
+ * A command a panel sends to the agent, answered by {@link Agent.handle}. All fields are plain data,
69
+ * so a command can cross a message channel:
70
+ *
71
+ * - `snapshot`: the model's state.
72
+ * - `value` and `write`: read a signal as editable text, or write it.
73
+ * - `store` and `store-set`: read a store as editable text, or write one path of it.
74
+ * - `highlight`: the agent acknowledges it; the page draws the highlight (see `createLocalBackend`).
75
+ * - `pause`, `resume`, `clear`: control recording. `stats`: the counters.
76
+ * - `inspect`: every inspection source registered with `registerInspection`, read now.
77
+ *
78
+ * @since 1.0.0
79
+ */
80
+ export type AgentRequest = {
81
+ type: "snapshot";
82
+ } | {
83
+ type: "value";
84
+ id: number;
85
+ } | {
86
+ type: "write";
87
+ id: number;
88
+ text: string;
89
+ } | {
90
+ type: "store";
91
+ id: number;
92
+ } | {
93
+ type: "store-set";
94
+ id: number;
95
+ path: Array<string | number>;
96
+ text: string;
97
+ } | {
98
+ type: "highlight";
99
+ id: number | null;
100
+ } | {
101
+ type: "pause";
102
+ } | {
103
+ type: "resume";
104
+ } | {
105
+ type: "clear";
106
+ } | {
107
+ type: "stats";
108
+ } | {
109
+ type: "inspect";
110
+ };
111
+ /**
112
+ * The answer to an {@link AgentRequest}: the result, or an error message to show the user.
113
+ *
114
+ * @since 1.0.0
115
+ */
116
+ export type AgentResponse = {
117
+ ok: true;
118
+ result: unknown;
119
+ } | {
120
+ ok: false;
121
+ error: string;
122
+ };
123
+ /**
124
+ * The value of a node, as text, for the value editor.
125
+ *
126
+ * @since 1.0.0
127
+ */
128
+ export interface ValueResult {
129
+ /** The node that was asked for. */
130
+ id: number;
131
+ /** `signal` for a signal, `store` for a store. */
132
+ kind: "signal" | "store";
133
+ /** The value as editable text (see {@link toEditableText}). */
134
+ text: string;
135
+ /** True when the panel may write it: a store always, a signal only when `writeSignal` is set. */
136
+ editable: boolean;
137
+ }
138
+ /**
139
+ * The agent. It receives the runtime's own objects from the hook, turns them into id-based
140
+ * {@link WireEvent}s and folds them into an {@link InspectorModel}. Recording is O(1) per event and
141
+ * every buffer is bounded: the raw event ring, the model's run, write and flush rings, the disposed-node
142
+ * graveyard and the live node count.
143
+ *
144
+ * A development tool: the hook it attaches to is installed only in development builds (see
145
+ * `installHook`).
146
+ *
147
+ * @since 1.0.0
148
+ */
149
+ export interface Agent extends HookSink {
150
+ /** The model the events are folded into. */
151
+ readonly model: InspectorModel;
152
+ /** The newest raw events, as many as the `events` option holds (default 10000). */
153
+ readonly events: RingBuffer<WireEvent>;
154
+ /** Counters of what the agent saw. */
155
+ readonly stats: Readonly<AgentStats>;
156
+ /** True while the agent drops the events the runtime reports (see {@link Agent.pause}). */
157
+ readonly paused: boolean;
158
+ /**
159
+ * Attaches the agent to `hook`, so that the hook delivers its events to the agent. Pass the hook
160
+ * from `installHook` or `getHook`.
161
+ *
162
+ * @param hook The hook to listen to.
163
+ * @returns A function that detaches the agent from the hook.
164
+ */
165
+ attach(hook: DevtoolsHook): () => void;
166
+ /**
167
+ * Calls `listener` with batches of new events: once per microtask, or sooner when `maxPending`
168
+ * events are waiting. Only events recorded after the call are delivered.
169
+ *
170
+ * @param listener Receives each batch, oldest first.
171
+ * @returns A function that unsubscribes the listener.
172
+ */
173
+ subscribe(listener: (events: readonly WireEvent[]) => void): () => void;
174
+ /** Delivers the pending events to the subscribers now, instead of at the end of the microtask. */
175
+ flush(): void;
176
+ /**
177
+ * Runs `fn` while the agent ignores everything the runtime creates, and everything created under
178
+ * those nodes. Use it to mount the tools' own UI, so that the tools never inspect themselves. An error
179
+ * thrown by `fn` propagates.
180
+ *
181
+ * @param fn The work to run.
182
+ * @returns What `fn` returns.
183
+ */
184
+ quiet<T>(fn: () => T): T;
185
+ /** Stops recording: events the runtime reports are dropped until {@link Agent.resume}. */
186
+ pause(): void;
187
+ /** Resumes recording after {@link Agent.pause}. */
188
+ resume(): void;
189
+ /**
190
+ * Forgets everything recorded so far: the model's nodes and records, the event ring, and the
191
+ * references to live nodes. Nodes created later are tracked; live ones are not, and later events about
192
+ * them count as unknown. {@link AgentStats} are not reset.
193
+ */
194
+ clear(): void;
195
+ /** The graph snapshot of the model (see `snapshotOf`). Each call builds a new object. */
196
+ snapshot(): GraphSnapshot;
197
+ /** The model state, for sending to a remote panel. */
198
+ state(): ModelState;
199
+ /**
200
+ * Answers a panel command. Never throws: a failure, such as an error from writing user state, comes
201
+ * back as `ok: false`, and so does an unknown command.
202
+ *
203
+ * @param request The command.
204
+ * @returns The answer.
205
+ */
206
+ handle(request: AgentRequest): AgentResponse;
207
+ /**
208
+ * The connected DOM nodes that the component `id` rendered, for highlighting. Empty when the
209
+ * component is unknown or its nodes left the page. The agent holds the nodes weakly.
210
+ *
211
+ * @param id The component's node id.
212
+ * @returns The nodes.
213
+ */
214
+ nodesOf(id: number): Node[];
215
+ /**
216
+ * Detaches from every hook it was attached to, and drops the listeners and the references to live
217
+ * signals, components and stores. The model and the event ring keep what they recorded.
218
+ */
219
+ dispose(): void;
220
+ }
221
+ /**
222
+ * Creates an agent that records the runtime's events. Attach it to a hook with `agent.attach(hook)`.
223
+ * A development tool: the events come only from development builds, where the hook is installed.
224
+ *
225
+ * @param options Buffer sizes, clock and the signal writer. Every field is optional.
226
+ * @returns The agent.
227
+ * @example
228
+ * import { createAgent, installHook } from "@shadow-js/devtools";
229
+ * import { writeSignal } from "@shadow-js/core/extend";
230
+ *
231
+ * const hook = installHook();
232
+ * const agent = createAgent({ writeSignal });
233
+ * if (hook !== undefined) agent.attach(hook);
234
+ * agent.snapshot().counts.nodes;
235
+ * @since 1.0.0
236
+ */
237
+ export declare function createAgent(options?: AgentOptions): Agent;
238
+ //#endregion
239
+ //# sourceMappingURL=agent.d.ts.map