@effect-atom-query/devtools 1.3.0 → 1.4.0-next.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 (2) hide show
  1. package/dist/index.mjs +16 -20
  2. package/package.json +5 -5
package/dist/index.mjs CHANGED
@@ -1,9 +1,10 @@
1
1
  import { QueryInspector } from "@effect-atom-query/query";
2
- import { useQueryClient } from "@effect-atom-query/react";
3
- import { Option } from "effect";
2
+ import { useQueryClientOption } from "@effect-atom-query/react";
3
+ import { Option, Result } from "effect";
4
4
  import * as React from "react";
5
5
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
6
  // src/format.ts
7
+ /** Value formatting for the devtools explorer. */
7
8
  const MAX_LENGTH = 5e4;
8
9
  /**
9
10
  * A JSON-safe copy of any value: Effect data uses its `toJSON`, and bigints,
@@ -53,13 +54,7 @@ const formatValue = (value) => {
53
54
  }
54
55
  };
55
56
  /** 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
- };
57
+ const formatKey = (key) => Result.getOrElse(Result.try(() => JSON.stringify(toJsonSafe(key, /* @__PURE__ */ new Set(), 0))), () => String(key));
63
58
  /** "3s ago", "2m ago", … */
64
59
  const formatAgo = (epochMillis, now) => {
65
60
  const seconds = Math.max(0, Math.round((now - epochMillis) / 1e3));
@@ -196,7 +191,7 @@ const useSnapshot = (client) => {
196
191
  current ??= {
197
192
  queries: QueryInspector.queries(client),
198
193
  mutations: QueryInspector.mutations(client),
199
- now: Date.now()
194
+ now: client.runtime.now()
200
195
  };
201
196
  return current;
202
197
  };
@@ -458,16 +453,25 @@ const labelOrder = {
458
453
  fresh: 4,
459
454
  inactive: 5
460
455
  };
456
+ /** Thrown when the panel has neither a `client` prop nor a provider. */
457
+ var MissingDevtoolsClientError = class extends Error {
458
+ constructor() {
459
+ super("QueryDevtools needs a `client` prop or a QueryClientProvider");
460
+ this.name = "MissingDevtoolsClientError";
461
+ }
462
+ };
461
463
  /**
462
464
  * The devtools panel, for embedding anywhere (e.g. in a resizable pane).
465
+ * Throws (to the nearest error boundary) when it has neither a `client` prop
466
+ * nor a `QueryClientProvider` above it.
463
467
  *
464
468
  * @since 0.1.0
465
469
  * @category components
466
470
  */
467
471
  const QueryDevtoolsPanelImpl = (props) => {
468
- const contextClient = useOptionalQueryClient();
472
+ const contextClient = Option.getOrUndefined(useQueryClientOption());
469
473
  const client = props.client ?? contextClient;
470
- if (client === void 0) throw new Error("QueryDevtools needs a `client` prop or a QueryClientProvider");
474
+ if (client === void 0) throw new MissingDevtoolsClientError();
471
475
  return /* @__PURE__ */ jsx(PanelBoundary, {
472
476
  style: props.style,
473
477
  onClose: props.onClose,
@@ -711,14 +715,6 @@ const Panel = ({ client, style, onClose }) => {
711
715
  })]
712
716
  });
713
717
  };
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
718
  const corner = (position) => {
723
719
  const [v, h] = position.split("-");
724
720
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-atom-query/devtools",
3
- "version": "1.3.0",
3
+ "version": "1.4.0-next.0",
4
4
  "description": "In-app devtools panel for @effect-atom-query (query and mutation cache inspector).",
5
5
  "keywords": [
6
6
  "devtools",
@@ -37,8 +37,8 @@
37
37
  "registry": "https://registry.npmjs.org/"
38
38
  },
39
39
  "devDependencies": {
40
- "@effect-atom-query/query": "^1.3.0",
41
- "@effect-atom-query/react": "^1.3.0",
40
+ "@effect-atom-query/query": "^1.4.0-next.0",
41
+ "@effect-atom-query/react": "^1.4.0-next.0",
42
42
  "@effect/atom-react": "^4.1.4",
43
43
  "@effect/vitest": "^4.1.4",
44
44
  "@testing-library/react": "^16.3.3",
@@ -54,8 +54,8 @@
54
54
  "vite-plus": "1.6.0"
55
55
  },
56
56
  "peerDependencies": {
57
- "@effect-atom-query/query": "^1.3.0",
58
- "@effect-atom-query/react": "^1.3.0",
57
+ "@effect-atom-query/query": "^1.4.0-next.0",
58
+ "@effect-atom-query/react": "^1.4.0-next.0",
59
59
  "@effect/atom-react": "^4.1.4",
60
60
  "effect": "^4.1.4",
61
61
  "react": "^19.0.0"