@effect-atom-query/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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tjercus
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,26 @@
1
- # Temporary Holding Version
1
+ # @effect-atom-query/devtools
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ An in-app devtools panel for [effect-atom-query](https://github.com/tjercus/effect-atom-query).
4
+ It inspects the query and mutation caches (status, data, errors, timings) and
5
+ can refetch, invalidate, reset, cancel or remove a query.
6
+
7
+ ```sh
8
+ pnpm add -D @effect-atom-query/devtools
9
+ ```
10
+
11
+ ```tsx
12
+ import { QueryDevtools } from "@effect-atom-query/devtools";
13
+
14
+ <QueryClientProvider runtime={runtime}>
15
+ <App />
16
+ <QueryDevtools /> {/* floating toggle; QueryDevtoolsPanel embeds the panel */}
17
+ </QueryClientProvider>;
18
+ ```
19
+
20
+ Props: `initialIsOpen`, `position` (`"bottom-right"` etc.), `height`, and
21
+ `client`. Both components render nothing when `process.env.NODE_ENV` is
22
+ `"production"`, and bundlers drop the panel code.
23
+
24
+ Documentation: <https://tjercus.github.io/effect-atom-query/>
25
+
26
+ MIT © tjercus
@@ -0,0 +1,37 @@
1
+ import { QueryClient } from "@effect-atom-query/query";
2
+ import * as React from "react";
3
+ /**
4
+ * @since 0.1.0
5
+ * @category models
6
+ */
7
+ interface QueryDevtoolsPanelProps {
8
+ /** Defaults to the client of the nearest `QueryClientProvider`. */
9
+ readonly client?: QueryClient.Service | undefined;
10
+ readonly style?: React.CSSProperties | undefined;
11
+ readonly onClose?: (() => void) | undefined;
12
+ }
13
+ /**
14
+ * @since 0.1.0
15
+ * @category models
16
+ */
17
+ interface QueryDevtoolsProps extends Omit<QueryDevtoolsPanelProps, "onClose" | "style"> {
18
+ readonly initialIsOpen?: boolean | undefined;
19
+ readonly position?: "bottom-right" | "bottom-left" | "top-right" | "top-left" | undefined;
20
+ /** Panel height when open. Default `"40vh"`. */
21
+ readonly height?: string | undefined;
22
+ }
23
+ /**
24
+ * A floating button that opens the devtools panel.
25
+ *
26
+ * @since 0.1.0
27
+ * @category components
28
+ */
29
+ export declare const QueryDevtools: (props: QueryDevtoolsProps) => React.ReactNode;
30
+ /**
31
+ * The devtools panel on its own, for embedding.
32
+ *
33
+ * @since 0.1.0
34
+ * @category components
35
+ */
36
+ export declare const QueryDevtoolsPanel: (props: QueryDevtoolsPanelProps) => React.ReactNode;
37
+ export type { QueryDevtoolsPanelProps, QueryDevtoolsProps };
package/dist/index.mjs ADDED
@@ -0,0 +1,785 @@
1
+ import { QueryInspector } from "@effect-atom-query/query";
2
+ import { useQueryClient } from "@effect-atom-query/react";
3
+ import { Option } from "effect";
4
+ import * as React from "react";
5
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
+ // src/format.ts
7
+ const MAX_LENGTH = 5e4;
8
+ /**
9
+ * A JSON-safe copy of any value: Effect data uses its `toJSON`, and bigints,
10
+ * Maps, Sets, functions and cycles get readable placeholders. Only real
11
+ * cycles (an ancestor referenced again) are marked; shared references are
12
+ * printed in full.
13
+ */
14
+ const toJsonSafe = (value, ancestors, depth) => {
15
+ if (typeof value === "bigint") return `${value}n`;
16
+ if (typeof value === "function") return `[Function ${value.name || "anonymous"}]`;
17
+ if (typeof value === "symbol") return value.toString();
18
+ if (value === void 0) return "[undefined]";
19
+ if (typeof value !== "object" || value === null) return value;
20
+ if (ancestors.has(value)) return "[Circular]";
21
+ if (depth > 50) return "[…]";
22
+ ancestors.add(value);
23
+ try {
24
+ const next = (v) => toJsonSafe(v, ancestors, depth + 1);
25
+ if (value instanceof Map) return {
26
+ _id: "Map",
27
+ entries: Array.from(value.entries(), ([k, v]) => [next(k), next(v)])
28
+ };
29
+ if (value instanceof Set) return {
30
+ _id: "Set",
31
+ values: Array.from(value.values(), next)
32
+ };
33
+ if (Array.isArray(value)) return value.map(next);
34
+ const toJSON = value.toJSON;
35
+ if (typeof toJSON === "function") {
36
+ const json = toJSON.call(value);
37
+ return json === value ? "[object]" : next(json);
38
+ }
39
+ const out = {};
40
+ for (const [k, v] of Object.entries(value)) out[k] = next(v);
41
+ return out;
42
+ } finally {
43
+ ancestors.delete(value);
44
+ }
45
+ };
46
+ const truncate = (text) => text.length > MAX_LENGTH ? `${text.slice(0, MAX_LENGTH)}\n… (truncated)` : text;
47
+ /** Pretty JSON for any value; never throws. */
48
+ const formatValue = (value) => {
49
+ try {
50
+ return truncate(JSON.stringify(toJsonSafe(value, /* @__PURE__ */ new Set(), 0), null, 2) ?? String(value));
51
+ } catch (error) {
52
+ return `[unserialisable: ${error instanceof Error ? error.message : String(error)}]`;
53
+ }
54
+ };
55
+ /** Compact one-line form of a key; never throws. */
56
+ const formatKey = (key) => {
57
+ try {
58
+ return JSON.stringify(toJsonSafe(key, /* @__PURE__ */ new Set(), 0));
59
+ } catch {
60
+ return String(key);
61
+ }
62
+ };
63
+ /** "3s ago", "2m ago", … */
64
+ const formatAgo = (epochMillis, now) => {
65
+ const seconds = Math.max(0, Math.round((now - epochMillis) / 1e3));
66
+ if (seconds < 60) return `${seconds}s ago`;
67
+ const minutes = Math.round(seconds / 60);
68
+ if (minutes < 60) return `${minutes}m ago`;
69
+ return `${Math.round(minutes / 60)}h ago`;
70
+ };
71
+ const formatDuration = (millis) => {
72
+ if (millis === "static") return "static";
73
+ if (!Number.isFinite(millis)) return "Infinity";
74
+ if (millis < 1e3) return `${millis}ms`;
75
+ if (millis < 6e4) return `${millis / 1e3}s`;
76
+ return `${Math.round(millis / 6e3) / 10}m`;
77
+ };
78
+ const queryLabel = (q) => {
79
+ if (q.fetchStatus === "fetching") return "fetching";
80
+ if (q.fetchStatus === "paused") return "paused";
81
+ if (q.status === "error") return "error";
82
+ if (q.observers === 0) return "inactive";
83
+ if (q.isStale) return "stale";
84
+ return "fresh";
85
+ };
86
+ // src/QueryDevtools.tsx
87
+ const palette = {
88
+ fresh: "#16a34a",
89
+ fetching: "#2563eb",
90
+ paused: "#9333ea",
91
+ error: "#dc2626",
92
+ stale: "#ca8a04",
93
+ inactive: "#6b7280",
94
+ idle: "#6b7280",
95
+ pending: "#2563eb",
96
+ success: "#16a34a"
97
+ };
98
+ const font = "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
99
+ const styles = {
100
+ panel: {
101
+ display: "flex",
102
+ flexDirection: "column",
103
+ background: "#0f172a",
104
+ color: "#e2e8f0",
105
+ font: `12px/1.4 ${font}`,
106
+ boxSizing: "border-box",
107
+ minHeight: 0
108
+ },
109
+ header: {
110
+ display: "flex",
111
+ flexWrap: "wrap",
112
+ gap: 8,
113
+ alignItems: "center",
114
+ padding: "6px 8px",
115
+ borderBottom: "1px solid #1e293b"
116
+ },
117
+ body: {
118
+ display: "flex",
119
+ flex: 1,
120
+ minHeight: 0
121
+ },
122
+ list: {
123
+ flex: "1 1 50%",
124
+ overflow: "auto",
125
+ borderRight: "1px solid #1e293b",
126
+ minWidth: 0
127
+ },
128
+ detail: {
129
+ flex: "1 1 50%",
130
+ overflow: "auto",
131
+ padding: 8,
132
+ minWidth: 0
133
+ },
134
+ row: {
135
+ display: "flex",
136
+ gap: 8,
137
+ alignItems: "center",
138
+ width: "100%",
139
+ padding: "4px 8px",
140
+ background: "transparent",
141
+ color: "inherit",
142
+ border: 0,
143
+ borderBottom: "1px solid #1e293b",
144
+ font: "inherit",
145
+ textAlign: "left",
146
+ cursor: "pointer"
147
+ },
148
+ badge: {
149
+ display: "inline-block",
150
+ minWidth: 18,
151
+ padding: "0 4px",
152
+ borderRadius: 4,
153
+ color: "#fff",
154
+ textAlign: "center",
155
+ fontWeight: 600
156
+ },
157
+ button: {
158
+ background: "#1e293b",
159
+ color: "inherit",
160
+ border: "1px solid #334155",
161
+ borderRadius: 4,
162
+ padding: "2px 8px",
163
+ font: "inherit",
164
+ cursor: "pointer"
165
+ },
166
+ input: {
167
+ background: "#1e293b",
168
+ color: "inherit",
169
+ border: "1px solid #334155",
170
+ borderRadius: 4,
171
+ padding: "2px 6px",
172
+ font: "inherit",
173
+ minWidth: 0,
174
+ flex: "1 1 120px"
175
+ },
176
+ pre: {
177
+ margin: 0,
178
+ padding: 8,
179
+ background: "#020617",
180
+ borderRadius: 4,
181
+ whiteSpace: "pre-wrap",
182
+ wordBreak: "break-all"
183
+ },
184
+ dl: {
185
+ display: "grid",
186
+ gridTemplateColumns: "max-content 1fr",
187
+ gap: "2px 12px",
188
+ margin: "0 0 8px"
189
+ }
190
+ };
191
+ /** Cache snapshots, refreshed on cache changes and every second (for staleness). */
192
+ const useSnapshot = (client) => {
193
+ const store = React.useMemo(() => {
194
+ let current;
195
+ const read = () => {
196
+ current ??= {
197
+ queries: QueryInspector.queries(client),
198
+ mutations: QueryInspector.mutations(client),
199
+ now: Date.now()
200
+ };
201
+ return current;
202
+ };
203
+ return {
204
+ read,
205
+ subscribe: (onChange) => {
206
+ const refresh = () => {
207
+ current = void 0;
208
+ onChange();
209
+ };
210
+ const unsubscribe = QueryInspector.subscribe(client, refresh);
211
+ const timer = setInterval(refresh, 1e3);
212
+ return () => {
213
+ unsubscribe();
214
+ clearInterval(timer);
215
+ };
216
+ }
217
+ };
218
+ }, [client]);
219
+ return React.useSyncExternalStore(store.subscribe, store.read, store.read);
220
+ };
221
+ const Badge = ({ color, children }) => /* @__PURE__ */ jsx("span", {
222
+ style: {
223
+ ...styles.badge,
224
+ background: color
225
+ },
226
+ children
227
+ });
228
+ const Field = ({ label, children }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("dt", {
229
+ style: { color: "#94a3b8" },
230
+ children: label
231
+ }), /* @__PURE__ */ jsx("dd", {
232
+ style: { margin: 0 },
233
+ children
234
+ })] });
235
+ const QueryDetail = ({ client, query, now }) => {
236
+ const label = queryLabel(query);
237
+ const act = (action) => QueryInspector.run(client, QueryInspector.action(client, query.key, action));
238
+ return /* @__PURE__ */ jsxs("div", {
239
+ "aria-label": "query details",
240
+ children: [
241
+ /* @__PURE__ */ jsx("pre", {
242
+ style: {
243
+ ...styles.pre,
244
+ marginBottom: 8
245
+ },
246
+ children: query.hash
247
+ }),
248
+ /* @__PURE__ */ jsxs("dl", {
249
+ style: styles.dl,
250
+ children: [
251
+ /* @__PURE__ */ jsxs(Field, {
252
+ label: "status",
253
+ children: [
254
+ /* @__PURE__ */ jsx(Badge, {
255
+ color: palette[label],
256
+ children: label
257
+ }),
258
+ " ",
259
+ query.status,
260
+ " / ",
261
+ query.fetchStatus
262
+ ]
263
+ }),
264
+ /* @__PURE__ */ jsx(Field, {
265
+ label: "observers",
266
+ children: query.observers
267
+ }),
268
+ /* @__PURE__ */ jsxs(Field, {
269
+ label: "updated",
270
+ children: [
271
+ Option.match(query.dataUpdatedAt, {
272
+ onNone: () => "never",
273
+ onSome: (t) => formatAgo(t, now)
274
+ }),
275
+ " ",
276
+ "(",
277
+ query.dataUpdateCount,
278
+ "×)"
279
+ ]
280
+ }),
281
+ /* @__PURE__ */ jsx(Field, {
282
+ label: "staleTime",
283
+ children: formatDuration(query.staleTime)
284
+ }),
285
+ /* @__PURE__ */ jsx(Field, {
286
+ label: "gcTime",
287
+ children: formatDuration(query.gcTime)
288
+ }),
289
+ query.failureCount > 0 && /* @__PURE__ */ jsx(Field, {
290
+ label: "failures",
291
+ children: query.failureCount
292
+ }),
293
+ query.isDisabled && /* @__PURE__ */ jsx(Field, {
294
+ label: "disabled",
295
+ children: "yes"
296
+ }),
297
+ query.isInvalidated && /* @__PURE__ */ jsx(Field, {
298
+ label: "invalidated",
299
+ children: "yes"
300
+ }),
301
+ query.persisted && /* @__PURE__ */ jsx(Field, {
302
+ label: "persisted",
303
+ children: "yes"
304
+ })
305
+ ]
306
+ }),
307
+ /* @__PURE__ */ jsxs("div", {
308
+ style: {
309
+ display: "flex",
310
+ flexWrap: "wrap",
311
+ gap: 4,
312
+ marginBottom: 8
313
+ },
314
+ children: [
315
+ /* @__PURE__ */ jsx("button", {
316
+ style: styles.button,
317
+ onClick: () => act("refetch"),
318
+ children: "Refetch"
319
+ }),
320
+ /* @__PURE__ */ jsx("button", {
321
+ style: styles.button,
322
+ onClick: () => act("invalidate"),
323
+ children: "Invalidate"
324
+ }),
325
+ /* @__PURE__ */ jsx("button", {
326
+ style: styles.button,
327
+ onClick: () => act("reset"),
328
+ children: "Reset"
329
+ }),
330
+ query.fetchStatus !== "idle" && /* @__PURE__ */ jsx("button", {
331
+ style: styles.button,
332
+ onClick: () => act("cancel"),
333
+ children: "Cancel"
334
+ }),
335
+ /* @__PURE__ */ jsx("button", {
336
+ style: styles.button,
337
+ onClick: () => act("remove"),
338
+ children: "Remove"
339
+ })
340
+ ]
341
+ }),
342
+ Option.isSome(query.error) && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
343
+ style: {
344
+ color: palette.error,
345
+ margin: "4px 0"
346
+ },
347
+ children: "Error"
348
+ }), /* @__PURE__ */ jsx("pre", {
349
+ style: styles.pre,
350
+ children: query.error.value
351
+ })] }),
352
+ /* @__PURE__ */ jsx("div", {
353
+ style: {
354
+ color: "#94a3b8",
355
+ margin: "4px 0"
356
+ },
357
+ children: "Data"
358
+ }),
359
+ /* @__PURE__ */ jsx("pre", {
360
+ style: styles.pre,
361
+ "aria-label": "query data",
362
+ children: Option.match(query.data, {
363
+ onNone: () => "(none)",
364
+ onSome: formatValue
365
+ })
366
+ }),
367
+ Option.isSome(query.meta) && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
368
+ style: {
369
+ color: "#94a3b8",
370
+ margin: "4px 0"
371
+ },
372
+ children: "Meta"
373
+ }), /* @__PURE__ */ jsx("pre", {
374
+ style: styles.pre,
375
+ children: formatValue(query.meta.value)
376
+ })] })
377
+ ]
378
+ });
379
+ };
380
+ const MutationDetail = ({ mutation, now }) => /* @__PURE__ */ jsxs("div", {
381
+ "aria-label": "mutation details",
382
+ children: [
383
+ /* @__PURE__ */ jsxs("dl", {
384
+ style: styles.dl,
385
+ children: [
386
+ /* @__PURE__ */ jsx(Field, {
387
+ label: "key",
388
+ children: Option.match(mutation.key, {
389
+ onNone: () => "—",
390
+ onSome: formatValue
391
+ })
392
+ }),
393
+ /* @__PURE__ */ jsx(Field, {
394
+ label: "status",
395
+ children: /* @__PURE__ */ jsx(Badge, {
396
+ color: mutation.isPaused ? palette.paused : palette[mutation.status],
397
+ children: mutation.isPaused ? "paused" : mutation.status
398
+ })
399
+ }),
400
+ /* @__PURE__ */ jsx(Field, {
401
+ label: "submitted",
402
+ children: Option.match(mutation.submittedAt, {
403
+ onNone: () => "—",
404
+ onSome: (t) => formatAgo(t, now)
405
+ })
406
+ }),
407
+ mutation.failureCount > 0 && /* @__PURE__ */ jsx(Field, {
408
+ label: "failures",
409
+ children: mutation.failureCount
410
+ })
411
+ ]
412
+ }),
413
+ /* @__PURE__ */ jsx("div", {
414
+ style: {
415
+ color: "#94a3b8",
416
+ margin: "4px 0"
417
+ },
418
+ children: "Variables"
419
+ }),
420
+ /* @__PURE__ */ jsx("pre", {
421
+ style: styles.pre,
422
+ children: Option.match(mutation.variables, {
423
+ onNone: () => "(none)",
424
+ onSome: formatValue
425
+ })
426
+ }),
427
+ Option.isSome(mutation.error) && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
428
+ style: {
429
+ color: palette.error,
430
+ margin: "4px 0"
431
+ },
432
+ children: "Error"
433
+ }), /* @__PURE__ */ jsx("pre", {
434
+ style: styles.pre,
435
+ children: mutation.error.value
436
+ })] }),
437
+ /* @__PURE__ */ jsx("div", {
438
+ style: {
439
+ color: "#94a3b8",
440
+ margin: "4px 0"
441
+ },
442
+ children: "Data"
443
+ }),
444
+ /* @__PURE__ */ jsx("pre", {
445
+ style: styles.pre,
446
+ children: Option.match(mutation.data, {
447
+ onNone: () => "(none)",
448
+ onSome: formatValue
449
+ })
450
+ })
451
+ ]
452
+ });
453
+ const labelOrder = {
454
+ error: 0,
455
+ fetching: 1,
456
+ paused: 2,
457
+ stale: 3,
458
+ fresh: 4,
459
+ inactive: 5
460
+ };
461
+ /**
462
+ * The devtools panel, for embedding anywhere (e.g. in a resizable pane).
463
+ *
464
+ * @since 0.1.0
465
+ * @category components
466
+ */
467
+ const QueryDevtoolsPanelImpl = (props) => {
468
+ const contextClient = useOptionalQueryClient();
469
+ const client = props.client ?? contextClient;
470
+ if (client === void 0) throw new Error("QueryDevtools needs a `client` prop or a QueryClientProvider");
471
+ return /* @__PURE__ */ jsx(PanelBoundary, {
472
+ style: props.style,
473
+ onClose: props.onClose,
474
+ children: /* @__PURE__ */ jsx(Panel, {
475
+ ...props,
476
+ client
477
+ })
478
+ });
479
+ };
480
+ /** Keeps a devtools failure (e.g. unusual data) from unmounting the host app. */
481
+ var PanelBoundary = class extends React.Component {
482
+ state = { error: void 0 };
483
+ static getDerivedStateFromError(error) {
484
+ return { error };
485
+ }
486
+ render() {
487
+ if (this.state.error === void 0) return this.props.children;
488
+ return /* @__PURE__ */ jsxs("div", {
489
+ style: {
490
+ ...styles.panel,
491
+ ...this.props.style,
492
+ padding: 8
493
+ },
494
+ role: "alert",
495
+ children: [
496
+ /* @__PURE__ */ jsx("strong", { children: "effect-atom-query devtools crashed" }),
497
+ /* @__PURE__ */ jsx("pre", {
498
+ style: styles.pre,
499
+ children: this.state.error instanceof Error ? this.state.error.message : formatValue(this.state.error)
500
+ }),
501
+ /* @__PURE__ */ jsxs("div", {
502
+ style: {
503
+ display: "flex",
504
+ gap: 4,
505
+ marginTop: 8
506
+ },
507
+ children: [/* @__PURE__ */ jsx("button", {
508
+ style: styles.button,
509
+ onClick: () => this.setState({ error: void 0 }),
510
+ children: "Reload panel"
511
+ }), this.props.onClose && /* @__PURE__ */ jsx("button", {
512
+ style: styles.button,
513
+ onClick: this.props.onClose,
514
+ children: "Close"
515
+ })]
516
+ })
517
+ ]
518
+ });
519
+ }
520
+ };
521
+ const Panel = ({ client, style, onClose }) => {
522
+ const { queries, mutations, now } = useSnapshot(client);
523
+ const [tab, setTab] = React.useState("queries");
524
+ const [filter, setFilter] = React.useState("");
525
+ const [sort, setSort] = React.useState("status");
526
+ const [selected, setSelected] = React.useState(void 0);
527
+ const shownQueries = React.useMemo(() => {
528
+ const needle = filter.trim().toLowerCase();
529
+ return queries.filter((q) => needle === "" || q.hash.toLowerCase().includes(needle)).slice().sort((a, b) => {
530
+ if (sort === "key") return a.hash.localeCompare(b.hash);
531
+ if (sort === "updated") return Option.getOrElse(b.dataUpdatedAt, () => 0) - Option.getOrElse(a.dataUpdatedAt, () => 0);
532
+ return labelOrder[queryLabel(a)] - labelOrder[queryLabel(b)] || a.hash.localeCompare(b.hash);
533
+ });
534
+ }, [
535
+ queries,
536
+ filter,
537
+ sort
538
+ ]);
539
+ const shownMutations = React.useMemo(() => {
540
+ const needle = filter.trim().toLowerCase();
541
+ return mutations.filter((m) => needle === "" || Option.match(m.key, {
542
+ onNone: () => "",
543
+ onSome: formatKey
544
+ }).toLowerCase().includes(needle)).slice().reverse();
545
+ }, [mutations, filter]);
546
+ const counts = React.useMemo(() => {
547
+ const c = {
548
+ fresh: 0,
549
+ fetching: 0,
550
+ paused: 0,
551
+ error: 0,
552
+ stale: 0,
553
+ inactive: 0
554
+ };
555
+ for (const q of queries) c[queryLabel(q)]++;
556
+ return c;
557
+ }, [queries]);
558
+ const selectedQuery = tab === "queries" ? queries.find((q) => q.id === selected) : void 0;
559
+ const selectedMutation = tab === "mutations" ? mutations.find((m) => m.id === selected) : void 0;
560
+ return /* @__PURE__ */ jsxs("div", {
561
+ style: {
562
+ ...styles.panel,
563
+ ...style
564
+ },
565
+ role: "region",
566
+ "aria-label": "effect-atom-query devtools",
567
+ children: [/* @__PURE__ */ jsxs("div", {
568
+ style: styles.header,
569
+ children: [
570
+ /* @__PURE__ */ jsx("strong", { children: "effect-atom-query" }),
571
+ /* @__PURE__ */ jsx("div", {
572
+ role: "tablist",
573
+ style: {
574
+ display: "flex",
575
+ gap: 4
576
+ },
577
+ children: ["queries", "mutations"].map((t) => /* @__PURE__ */ jsxs("button", {
578
+ role: "tab",
579
+ "aria-selected": tab === t,
580
+ style: {
581
+ ...styles.button,
582
+ borderColor: tab === t ? "#60a5fa" : "#334155"
583
+ },
584
+ onClick: () => {
585
+ setTab(t);
586
+ setSelected(void 0);
587
+ },
588
+ children: [
589
+ t,
590
+ " (",
591
+ t === "queries" ? queries.length : mutations.length,
592
+ ")"
593
+ ]
594
+ }, t))
595
+ }),
596
+ tab === "queries" && /* @__PURE__ */ jsx("span", {
597
+ style: {
598
+ display: "flex",
599
+ gap: 4
600
+ },
601
+ children: Object.keys(counts).map((label) => /* @__PURE__ */ jsx("span", {
602
+ title: label,
603
+ children: /* @__PURE__ */ jsx(Badge, {
604
+ color: palette[label],
605
+ children: counts[label]
606
+ })
607
+ }, label))
608
+ }),
609
+ /* @__PURE__ */ jsx("input", {
610
+ style: styles.input,
611
+ placeholder: "Filter by key",
612
+ "aria-label": "filter",
613
+ value: filter,
614
+ onChange: (e) => setFilter(e.target.value)
615
+ }),
616
+ tab === "queries" && /* @__PURE__ */ jsxs("select", {
617
+ style: styles.button,
618
+ "aria-label": "sort",
619
+ value: sort,
620
+ onChange: (e) => setSort(e.target.value),
621
+ children: [
622
+ /* @__PURE__ */ jsx("option", {
623
+ value: "status",
624
+ children: "sort: status"
625
+ }),
626
+ /* @__PURE__ */ jsx("option", {
627
+ value: "key",
628
+ children: "sort: key"
629
+ }),
630
+ /* @__PURE__ */ jsx("option", {
631
+ value: "updated",
632
+ children: "sort: updated"
633
+ })
634
+ ]
635
+ }),
636
+ tab === "queries" ? /* @__PURE__ */ jsx("button", {
637
+ style: styles.button,
638
+ onClick: () => QueryInspector.run(client, client.clear),
639
+ title: "Remove every query and mutation",
640
+ children: "Clear"
641
+ }) : null,
642
+ onClose && /* @__PURE__ */ jsx("button", {
643
+ style: styles.button,
644
+ onClick: onClose,
645
+ "aria-label": "close devtools",
646
+ children: "✕"
647
+ })
648
+ ]
649
+ }), /* @__PURE__ */ jsxs("div", {
650
+ style: styles.body,
651
+ children: [/* @__PURE__ */ jsxs("div", {
652
+ style: styles.list,
653
+ role: "list",
654
+ children: [tab === "queries" ? shownQueries.map((q) => {
655
+ const label = queryLabel(q);
656
+ return /* @__PURE__ */ jsxs("button", {
657
+ role: "listitem",
658
+ style: {
659
+ ...styles.row,
660
+ background: q.id === selected ? "#1e293b" : "transparent"
661
+ },
662
+ onClick: () => setSelected(q.id),
663
+ title: label,
664
+ children: [/* @__PURE__ */ jsx(Badge, {
665
+ color: palette[label],
666
+ children: q.observers
667
+ }), /* @__PURE__ */ jsx("span", {
668
+ style: {
669
+ overflow: "hidden",
670
+ textOverflow: "ellipsis",
671
+ whiteSpace: "nowrap"
672
+ },
673
+ children: q.hash
674
+ })]
675
+ }, q.id);
676
+ }) : shownMutations.map((m) => /* @__PURE__ */ jsxs("button", {
677
+ role: "listitem",
678
+ style: {
679
+ ...styles.row,
680
+ background: m.id === selected ? "#1e293b" : "transparent"
681
+ },
682
+ onClick: () => setSelected(m.id),
683
+ children: [/* @__PURE__ */ jsx(Badge, {
684
+ color: m.isPaused ? palette.paused : palette[m.status],
685
+ children: m.isPaused ? "paused" : m.status
686
+ }), /* @__PURE__ */ jsx("span", { children: Option.match(m.key, {
687
+ onNone: () => `#${m.id}`,
688
+ onSome: formatKey
689
+ }) })]
690
+ }, m.id)), (tab === "queries" ? shownQueries.length : shownMutations.length) === 0 && /* @__PURE__ */ jsxs("div", {
691
+ style: {
692
+ padding: 8,
693
+ color: "#94a3b8"
694
+ },
695
+ children: ["No ", tab]
696
+ })]
697
+ }), /* @__PURE__ */ jsx("div", {
698
+ style: styles.detail,
699
+ children: selectedQuery ? /* @__PURE__ */ jsx(QueryDetail, {
700
+ client,
701
+ query: selectedQuery,
702
+ now
703
+ }) : selectedMutation ? /* @__PURE__ */ jsx(MutationDetail, {
704
+ mutation: selectedMutation,
705
+ now
706
+ }) : /* @__PURE__ */ jsxs("span", {
707
+ style: { color: "#94a3b8" },
708
+ children: ["Select a ", tab === "queries" ? "query" : "mutation"]
709
+ })
710
+ })]
711
+ })]
712
+ });
713
+ };
714
+ /** The provider's client, or `undefined` outside a provider. */
715
+ const useOptionalQueryClient = () => {
716
+ try {
717
+ return useQueryClient();
718
+ } catch {
719
+ return;
720
+ }
721
+ };
722
+ const corner = (position) => {
723
+ const [v, h] = position.split("-");
724
+ return {
725
+ [v]: 12,
726
+ [h]: 12
727
+ };
728
+ };
729
+ /**
730
+ * A floating toggle button that opens the devtools panel docked to the
731
+ * bottom (or top) of the viewport.
732
+ *
733
+ * @since 0.1.0
734
+ * @category components
735
+ */
736
+ const QueryDevtoolsImpl = ({ initialIsOpen = false, position = "bottom-right", height = "40vh", client }) => {
737
+ const [open, setOpen] = React.useState(initialIsOpen);
738
+ if (!open) return /* @__PURE__ */ jsx("button", {
739
+ onClick: () => setOpen(true),
740
+ "aria-label": "open devtools",
741
+ style: {
742
+ ...styles.button,
743
+ position: "fixed",
744
+ zIndex: 99999,
745
+ ...corner(position),
746
+ background: "#0f172a",
747
+ color: "#e2e8f0",
748
+ font: `12px ${font}`,
749
+ padding: "6px 10px",
750
+ boxShadow: "0 2px 8px rgba(0,0,0,.3)"
751
+ },
752
+ children: "⚡ queries"
753
+ });
754
+ return /* @__PURE__ */ jsx(QueryDevtoolsPanelImpl, {
755
+ client,
756
+ onClose: () => setOpen(false),
757
+ style: {
758
+ position: "fixed",
759
+ left: 0,
760
+ right: 0,
761
+ [position.startsWith("top") ? "top" : "bottom"]: 0,
762
+ height,
763
+ zIndex: 99999,
764
+ boxShadow: "0 -2px 12px rgba(0,0,0,.3)"
765
+ }
766
+ });
767
+ };
768
+ // src/index.ts
769
+ const isProduction = process.env.NODE_ENV === "production";
770
+ const Nothing = () => null;
771
+ /**
772
+ * A floating button that opens the devtools panel.
773
+ *
774
+ * @since 0.1.0
775
+ * @category components
776
+ */
777
+ const QueryDevtools = isProduction ? Nothing : QueryDevtoolsImpl;
778
+ /**
779
+ * The devtools panel on its own, for embedding.
780
+ *
781
+ * @since 0.1.0
782
+ * @category components
783
+ */
784
+ const QueryDevtoolsPanel = isProduction ? Nothing : QueryDevtoolsPanelImpl;
785
+ export { QueryDevtools, QueryDevtoolsPanel };
package/package.json CHANGED
@@ -1,6 +1,68 @@
1
1
  {
2
2
  "name": "@effect-atom-query/devtools",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0",
4
+ "description": "In-app devtools panel for @effect-atom-query (query and mutation cache inspector).",
5
+ "keywords": [
6
+ "devtools",
7
+ "effect",
8
+ "effect-ts",
9
+ "query",
10
+ "react"
11
+ ],
12
+ "homepage": "https://github.com/tjercus/effect-atom-query/tree/main/packages/devtools#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/tjercus/effect-atom-query/issues"
15
+ },
16
+ "license": "MIT",
17
+ "author": "tjercus",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/tjercus/effect-atom-query.git",
21
+ "directory": "packages/devtools"
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "type": "module",
27
+ "sideEffects": false,
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.mts",
31
+ "default": "./dist/index.mjs"
32
+ },
33
+ "./package.json": "./package.json"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public",
37
+ "registry": "https://registry.npmjs.org/"
38
+ },
39
+ "devDependencies": {
40
+ "@effect-atom-query/query": "^1.0.0",
41
+ "@effect-atom-query/react": "^1.0.0",
42
+ "@effect/atom-react": "^4.1.4",
43
+ "@effect/vitest": "^4.1.4",
44
+ "@testing-library/react": "^16.3.3",
45
+ "@types/react": "^19.3.0",
46
+ "@types/react-dom": "^19.3.0",
47
+ "effect": "^4.1.4",
48
+ "happy-dom": "^21.0.4",
49
+ "react": "^19.3.1",
50
+ "react-dom": "^19.3.1",
51
+ "scheduler": "^0.27.0",
52
+ "typescript": "^7.0.2",
53
+ "vite-plus": "1.6.0"
54
+ },
55
+ "peerDependencies": {
56
+ "@effect-atom-query/query": "^1.0.0",
57
+ "@effect-atom-query/react": "^1.0.0",
58
+ "@effect/atom-react": "^4.1.4",
59
+ "effect": "^4.1.4",
60
+ "react": "^19.3.1"
61
+ },
62
+ "scripts": {
63
+ "build": "vp pack",
64
+ "dev": "vp pack --watch",
65
+ "test": "vp test",
66
+ "check": "vp check"
67
+ }
6
68
  }