ruru-components 2.0.0-0.5

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 (69) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE.md +20 -0
  3. package/README.md +26 -0
  4. package/dist/components/Copy.d.ts +6 -0
  5. package/dist/components/Copy.d.ts.map +1 -0
  6. package/dist/components/Copy.js +23 -0
  7. package/dist/components/Copy.js.map +1 -0
  8. package/dist/components/ErrorPopup.d.ts +6 -0
  9. package/dist/components/ErrorPopup.d.ts.map +1 -0
  10. package/dist/components/ErrorPopup.js +8 -0
  11. package/dist/components/ErrorPopup.js.map +1 -0
  12. package/dist/components/Explain.d.ts +14 -0
  13. package/dist/components/Explain.d.ts.map +1 -0
  14. package/dist/components/Explain.js +59 -0
  15. package/dist/components/Explain.js.map +1 -0
  16. package/dist/components/Footer.d.ts +3 -0
  17. package/dist/components/Footer.d.ts.map +1 -0
  18. package/dist/components/Footer.js +7 -0
  19. package/dist/components/Footer.js.map +1 -0
  20. package/dist/components/Mermaid.d.ts +5 -0
  21. package/dist/components/Mermaid.d.ts.map +1 -0
  22. package/dist/components/Mermaid.js +21 -0
  23. package/dist/components/Mermaid.js.map +1 -0
  24. package/dist/defaultQuery.d.ts +2 -0
  25. package/dist/defaultQuery.d.ts.map +1 -0
  26. package/dist/defaultQuery.js +37 -0
  27. package/dist/defaultQuery.js.map +1 -0
  28. package/dist/hooks/useExplain.d.ts +19 -0
  29. package/dist/hooks/useExplain.d.ts.map +1 -0
  30. package/dist/hooks/useExplain.js +47 -0
  31. package/dist/hooks/useExplain.js.map +1 -0
  32. package/dist/hooks/useFetcher.d.ts +28 -0
  33. package/dist/hooks/useFetcher.d.ts.map +1 -0
  34. package/dist/hooks/useFetcher.js +179 -0
  35. package/dist/hooks/useFetcher.js.map +1 -0
  36. package/dist/hooks/useGraphQLChangeStream.d.ts +5 -0
  37. package/dist/hooks/useGraphQLChangeStream.d.ts.map +1 -0
  38. package/dist/hooks/useGraphQLChangeStream.js +55 -0
  39. package/dist/hooks/useGraphQLChangeStream.js.map +1 -0
  40. package/dist/hooks/usePrettify.d.ts +12 -0
  41. package/dist/hooks/usePrettify.d.ts.map +1 -0
  42. package/dist/hooks/usePrettify.js +33 -0
  43. package/dist/hooks/usePrettify.js.map +1 -0
  44. package/dist/hooks/useSchema.d.ts +8 -0
  45. package/dist/hooks/useSchema.d.ts.map +1 -0
  46. package/dist/hooks/useSchema.js +74 -0
  47. package/dist/hooks/useSchema.js.map +1 -0
  48. package/dist/hooks/useStorage.d.ts +18 -0
  49. package/dist/hooks/useStorage.d.ts.map +1 -0
  50. package/dist/hooks/useStorage.js +63 -0
  51. package/dist/hooks/useStorage.js.map +1 -0
  52. package/dist/index.d.ts +3 -0
  53. package/dist/index.d.ts.map +1 -0
  54. package/dist/index.js +6 -0
  55. package/dist/index.js.map +1 -0
  56. package/dist/interfaces.d.ts +27 -0
  57. package/dist/interfaces.d.ts.map +1 -0
  58. package/dist/interfaces.js +3 -0
  59. package/dist/interfaces.js.map +1 -0
  60. package/dist/plugins/explain.d.ts +3 -0
  61. package/dist/plugins/explain.d.ts.map +1 -0
  62. package/dist/plugins/explain.js +18 -0
  63. package/dist/plugins/explain.js.map +1 -0
  64. package/dist/ruru.d.ts +13 -0
  65. package/dist/ruru.d.ts.map +1 -0
  66. package/dist/ruru.js +72 -0
  67. package/dist/ruru.js.map +1 -0
  68. package/package.json +73 -0
  69. package/ruru.css +72 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # ruru-components
2
+
3
+ ## 2.0.0-0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [`9b296ba54`](undefined) - More secure, more compatible, and lots of fixes
8
+ across the monorepo
package/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ # The MIT License (MIT)
2
+
3
+ Copyright © `2023` Benjie Gillam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the “Software”), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # ruru-components
2
+
3
+ The React components behind [ruru][], in case you want to embed Ruru into an
4
+ existing React project.
5
+
6
+ **PRERELEASE**: this is pre-release software; use at your own risk and do not
7
+ embed into public-facing projects. This will likely change a lot before it's
8
+ ultimately released. The pre-release nature also explains the shocking lack of
9
+ documentation.
10
+
11
+ ## Usage
12
+
13
+ For other usage patterns, please see the main [ruru][] package.
14
+
15
+ ```js
16
+ import { Ruru } from "ruru-components";
17
+ import "graphiql/graphiql.css";
18
+ import "@graphiql/plugin-explorer/dist/style.css";
19
+ import "ruru-components/ruru.css";
20
+
21
+ React.render(<Ruru endpoint="/graphql" />);
22
+ ```
23
+
24
+ [GNU Terry Pratchett](http://www.gnuterrypratchett.com/)
25
+
26
+ [ruru]: https://www.npmjs.com/package/ruru
@@ -0,0 +1,6 @@
1
+ import type { FC } from "react";
2
+ export declare const Copy: FC<{
3
+ text: string;
4
+ children: string | JSX.Element | JSX.Element[];
5
+ }>;
6
+ //# sourceMappingURL=Copy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Copy.d.ts","sourceRoot":"","sources":["../../src/components/Copy.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAGhC,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;CAChD,CA0BA,CAAC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Copy = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const Copy = ({ text, children }) => {
7
+ const ref = (0, react_1.useRef)(null);
8
+ const copy = (0, react_1.useCallback)(() => {
9
+ const el = ref.current;
10
+ if (el) {
11
+ /* Select the text field */
12
+ el.select();
13
+ el.setSelectionRange(0, 99999); /* For mobile devices */
14
+ /* Copy the text inside the text field */
15
+ navigator.clipboard.writeText(el.value);
16
+ }
17
+ }, []);
18
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("textarea", { ref: (el) => {
19
+ ref.current = el;
20
+ }, value: text, readOnly: true, style: { display: "none" } }), (0, jsx_runtime_1.jsx)("button", { onClick: copy, children: children })] }));
21
+ };
22
+ exports.Copy = Copy;
23
+ //# sourceMappingURL=Copy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Copy.js","sourceRoot":"","sources":["../../src/components/Copy.tsx"],"names":[],"mappings":";;;;AACA,iCAA4C;AAErC,MAAM,IAAI,GAGZ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC1B,MAAM,GAAG,GAAG,IAAA,cAAM,EAA6B,IAAI,CAAC,CAAC;IACrD,MAAM,IAAI,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QAC5B,MAAM,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC;QACvB,IAAI,EAAE,EAAE;YACN,2BAA2B;YAC3B,EAAE,CAAC,MAAM,EAAE,CAAC;YACZ,EAAE,CAAC,iBAAiB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,wBAAwB;YAExD,yCAAyC;YACzC,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;SACzC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,CACL,6DACE,qCACE,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE;oBACV,GAAG,CAAC,OAAO,GAAG,EAAE,CAAC;gBACnB,CAAC,EACD,KAAK,EAAE,IAAI,EACX,QAAQ,QACR,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAC1B,EACF,mCAAQ,OAAO,EAAE,IAAI,YAAG,QAAQ,GAAU,IACzC,CACJ,CAAC;AACJ,CAAC,CAAC;AA7BW,QAAA,IAAI,QA6Bf"}
@@ -0,0 +1,6 @@
1
+ import type { FC } from "react";
2
+ export declare const ErrorPopup: FC<{
3
+ error: Error;
4
+ onClose: () => void;
5
+ }>;
6
+ //# sourceMappingURL=ErrorPopup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorPopup.d.ts","sourceRoot":"","sources":["../../src/components/ErrorPopup.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAIhC,eAAO,MAAM,UAAU,EAAE,EAAE,CAAC;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,CAUhE,CAAC"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorPopup = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ // TODO: this needs proper design and accessibility considerations
6
+ const ErrorPopup = ({ error, onClose, }) => ((0, jsx_runtime_1.jsxs)("div", { className: "errorPopup", children: [(0, jsx_runtime_1.jsx)("button", { className: "errorPopupClose", onClick: onClose, children: "\uD83D\uDDD9" }), (0, jsx_runtime_1.jsx)("div", { className: "errorPopupError", children: String(error) })] }));
7
+ exports.ErrorPopup = ErrorPopup;
8
+ //# sourceMappingURL=ErrorPopup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorPopup.js","sourceRoot":"","sources":["../../src/components/ErrorPopup.tsx"],"names":[],"mappings":";;;;AAEA,kEAAkE;AAE3D,MAAM,UAAU,GAA8C,CAAC,EACpE,KAAK,EACL,OAAO,GACR,EAAE,EAAE,CAAC,CACJ,iCAAK,SAAS,EAAC,YAAY,aACzB,mCAAQ,SAAS,EAAC,iBAAiB,EAAC,OAAO,EAAE,OAAO,6BAE3C,EACT,gCAAK,SAAS,EAAC,iBAAiB,YAAE,MAAM,CAAC,KAAK,CAAC,GAAO,IAClD,CACP,CAAC;AAVW,QAAA,UAAU,cAUrB"}
@@ -0,0 +1,14 @@
1
+ import type { FC } from "react";
2
+ import type { ExplainHelpers } from "../hooks/useExplain.js";
3
+ import type { ExplainResults } from "../hooks/useFetcher.js";
4
+ export declare const Explain: FC<{
5
+ explain: boolean;
6
+ setExplain: (newExplain: boolean) => void;
7
+ helpers: ExplainHelpers;
8
+ results: ExplainResults | null;
9
+ }>;
10
+ export declare const ExplainMain: FC<{
11
+ helpers: ExplainHelpers;
12
+ results: ExplainResults;
13
+ }>;
14
+ //# sourceMappingURL=Explain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Explain.d.ts","sourceRoot":"","sources":["../../src/components/Explain.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAIhC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAI7D,eAAO,MAAM,OAAO,EAAE,EAAE,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;IAC1C,OAAO,EAAE,cAAc,CAAC;IACxB,OAAO,EAAE,cAAc,GAAG,IAAI,CAAC;CAChC,CA6BA,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,EAAE,CAAC;IAC3B,OAAO,EAAE,cAAc,CAAC;IACxB,OAAO,EAAE,cAAc,CAAC;CACzB,CA6HA,CAAC"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExplainMain = exports.Explain = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const react_dom_1 = require("react-dom");
7
+ const Copy_js_1 = require("./Copy.js");
8
+ const Mermaid_js_1 = require("./Mermaid.js");
9
+ const Explain = ({ explain, setExplain, helpers, results }) => {
10
+ return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: !results ? (!explain ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("p", { children: "WARNING: you've not enabled the 'explain' functionality" }), (0, jsx_runtime_1.jsx)("p", { children: (0, jsx_runtime_1.jsx)("button", { onClick: () => setExplain(true), children: "Enable explain" }) })] })) : ((0, jsx_runtime_1.jsx)("p", { children: "There are no explain results to display - perhaps you have not yet ran an operation against a server that supports this feature?" }))) : results.operations.length === 0 ? ((0, jsx_runtime_1.jsx)("p", { children: "Empty explain results" })) : ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(exports.ExplainMain, { helpers: helpers, results: results }) })) }));
11
+ };
12
+ exports.Explain = Explain;
13
+ const ExplainMain = ({ results }) => {
14
+ const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(0);
15
+ (0, react_1.useEffect)(() => {
16
+ setSelectedIndex(0);
17
+ }, [results]);
18
+ const selectedResult = results.operations[selectedIndex];
19
+ const [expanded, setExpanded] = (0, react_1.useState)(false);
20
+ const expand = (0, react_1.useCallback)(() => {
21
+ setExpanded(true);
22
+ }, []);
23
+ const nodeRef = (0, react_1.useRef)();
24
+ if (!nodeRef.current) {
25
+ nodeRef.current = document.createElement("div");
26
+ }
27
+ const node = nodeRef.current;
28
+ (0, react_1.useEffect)(() => {
29
+ document.body.appendChild(node);
30
+ return () => {
31
+ document.body.removeChild(node);
32
+ };
33
+ }, [node]);
34
+ const component = (() => {
35
+ switch (selectedResult?.type) {
36
+ case "sql": {
37
+ return ((0, jsx_runtime_1.jsxs)("div", { children: [selectedResult.explain ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("h4", { children: ["Result from SQL", " ", (0, jsx_runtime_1.jsx)("a", { href: "https://www.postgresql.org/docs/current/sql-explain.html", children: "EXPLAIN" }), " ", "on executed query:"] }), (0, jsx_runtime_1.jsx)("pre", { className: "explain-plan", children: (0, jsx_runtime_1.jsx)("code", { children: selectedResult.explain }) })] })) : null, (0, jsx_runtime_1.jsx)("h4", { children: "Executed SQL query:" }), (0, jsx_runtime_1.jsx)("pre", { className: "explain-sql", style: { fontSize: "0.75rem", whiteSpace: "pre-wrap" }, children: selectedResult.query.split("\n").map((line, i) => ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)("code", { style: {
38
+ display: "block",
39
+ marginLeft: "1.8rem",
40
+ textIndent: "-1.8rem",
41
+ }, children: line }, i) }))) })] }));
42
+ }
43
+ case "mermaid-js": {
44
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Copy_js_1.Copy, { text: selectedResult.diagram, children: "Copy Mermaid.js Definition" }), (0, jsx_runtime_1.jsx)("div", { onClick: expand, children: (0, jsx_runtime_1.jsx)(Mermaid_js_1.Mermaid, { diagram: selectedResult.diagram }) }), expanded
45
+ ? (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsxs)("div", { className: "explainExpandedContainer", children: [(0, jsx_runtime_1.jsx)("div", { className: "explainExpandedTitle", children: "Operation Plan" }), (0, jsx_runtime_1.jsx)("div", { className: "explainExpandedCloseContainer", children: (0, jsx_runtime_1.jsx)("button", { className: "explainExpandedCloseButton", onClick: () => setExpanded(false), children: "\u00D7" }) }), (0, jsx_runtime_1.jsx)("div", { className: "explainExpandedMain", children: (0, jsx_runtime_1.jsx)(Mermaid_js_1.Mermaid, { diagram: selectedResult.diagram }) })] }), node)
46
+ : null] }));
47
+ }
48
+ case undefined: {
49
+ return ((0, jsx_runtime_1.jsxs)("div", { children: ["Explain result type '$", selectedResult.type, "' not yet supported."] }));
50
+ }
51
+ default: {
52
+ return (0, jsx_runtime_1.jsx)("div", {});
53
+ }
54
+ }
55
+ })();
56
+ return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("select", { value: String(selectedIndex), onChange: (e) => setSelectedIndex(parseInt(e.target.value, 10)), children: results.operations.map((o, i) => ((0, jsx_runtime_1.jsx)("option", { value: String(i), children: o.title }, i))) }), component] }));
57
+ };
58
+ exports.ExplainMain = ExplainMain;
59
+ //# sourceMappingURL=Explain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Explain.js","sourceRoot":"","sources":["../../src/components/Explain.tsx"],"names":[],"mappings":";;;;AACA,iCAAiE;AACjE,yCAAyC;AAIzC,uCAAiC;AACjC,6CAAuC;AAEhC,MAAM,OAAO,GAKf,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE;IACjD,OAAO,CACL,2DACG,CAAC,OAAO,CAAC,CAAC,CAAC,CACV,CAAC,OAAO,CAAC,CAAC,CAAC,CACT,6DACE,oGAGI,EACJ,wCACE,mCAAQ,OAAO,E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C,0BAA0B,aACvC,gCAAK,SAAS,EAAC,sBAAsB,+BAAqB,EAC1D,gCAAK,SAAS,EAAC,+BAA+B,YAC5C,mCACE,SAAS,EAAC,4BAA4B,EACtC,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,uBAG1B,GACL,EACN,gCAAK,SAAS,EAAC,qBAAqB,YAClC,uBAAC,oBAAO,IAAC,OAAO,EAAE,cAAc,CAAC,OAAO,GAAI,GACxC,IACF,EAEN,IAAI,CACL;4BACH,CAAC,CAAC,IAAI,IACP,CACJ,CAAC;aACH;YACD,KAAK,SAAS,CAAC,CAAC;gBACd,OAAO,CACL,sEAC+B,cAAsB,CAAC,IAAI,4BAEpD,CACP,CAAC;aACH;YACD,OAAO,CAAC,CAAC;gBACP,OAAO,iCAAW,CAAC;aACpB;SACF;IACH,CAAC,CAAC,EAAE,CAAC;IACL,OAAO,CACL,4CACE,mCACE,KAAK,EAAE,MAAM,CAAC,aAAa,CAAC,EAC5B,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,YAE9D,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAChC,mCAAQ,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,YACrB,CAAC,CAAC,KAAK,IADqB,CAAC,CAEvB,CACV,CAAC,GACK,EACR,SAAS,IACN,CACP,CAAC;AACJ,CAAC,CAAC;AAhIW,QAAA,WAAW,eAgItB"}
@@ -0,0 +1,3 @@
1
+ import type { FC } from "react";
2
+ export declare const RuruFooter: FC;
3
+ //# sourceMappingURL=Footer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Footer.d.ts","sourceRoot":"","sources":["../../src/components/Footer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAEhC,eAAO,MAAM,UAAU,EAAE,EAYxB,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RuruFooter = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const RuruFooter = () => ((0, jsx_runtime_1.jsxs)("div", { style: { padding: 7 }, children: ["Community-funded OSS \uD83D\uDE4F", " ", (0, jsx_runtime_1.jsx)("a", { title: "All our projects are supported by the community, please sponsor ongoing development", href: "https://graphile.org/sponsor/", target: "new", children: "please sponsor" }), " ", "\uD83D\uDC96"] }));
6
+ exports.RuruFooter = RuruFooter;
7
+ //# sourceMappingURL=Footer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Footer.js","sourceRoot":"","sources":["../../src/components/Footer.tsx"],"names":[],"mappings":";;;;AAEO,MAAM,UAAU,GAAO,GAAG,EAAE,CAAC,CAClC,iCAAK,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,kDACA,GAAG,EAC3B,8BACE,KAAK,EAAC,qFAAqF,EAC3F,IAAI,EAAC,+BAA+B,EACpC,MAAM,EAAC,KAAK,+BAGV,EAAC,GAAG,oBAEJ,CACP,CAAC;AAZW,QAAA,UAAU,cAYrB"}
@@ -0,0 +1,5 @@
1
+ import type { FC } from "react";
2
+ export declare const Mermaid: FC<{
3
+ diagram: string;
4
+ }>;
5
+ //# sourceMappingURL=Mermaid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Mermaid.d.ts","sourceRoot":"","sources":["../../src/components/Mermaid.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAQhC,eAAO,MAAM,OAAO,EAAE,EAAE,CAAC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAW3C,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Mermaid = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const mermaid_1 = tslib_1.__importDefault(require("mermaid"));
7
+ const react_1 = require("react");
8
+ mermaid_1.default.initialize({
9
+ startOnLoad: true,
10
+ maxTextSize: 1000000,
11
+ });
12
+ const Mermaid = ({ diagram }) => {
13
+ (0, react_1.useEffect)(() => {
14
+ if (diagram) {
15
+ mermaid_1.default.contentLoaded();
16
+ }
17
+ }, [diagram]);
18
+ return ((0, jsx_runtime_1.jsx)("div", { className: "mermaid", children: diagram }, diagram));
19
+ };
20
+ exports.Mermaid = Mermaid;
21
+ //# sourceMappingURL=Mermaid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Mermaid.js","sourceRoot":"","sources":["../../src/components/Mermaid.tsx"],"names":[],"mappings":";;;;;AAAA,8DAA8B;AAE9B,iCAAkC;AAEjC,iBAAe,CAAC,UAAU,CAAC;IAC1B,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,OAAO;CACrB,CAAC,CAAC;AAEI,MAAM,OAAO,GAA4B,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;IAC9D,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,OAAO,EAAE;YACV,iBAAe,CAAC,aAAa,EAAE,CAAC;SAClC;IACH,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IACd,OAAO,CACL,gCAAK,SAAS,EAAC,SAAS,YACrB,OAAO,IADoB,OAAO,CAE/B,CACP,CAAC;AACJ,CAAC,CAAC;AAXW,QAAA,OAAO,WAWlB"}
@@ -0,0 +1,2 @@
1
+ export declare const defaultQuery = "# Welcome to Ruru, our distribution of GraphiQL and related tooling to\n# inspect your GraphQL API.\n#\n# GraphiQL is an in-browser tool for writing, validating, and\n# testing GraphQL queries.\n#\n# Type queries into this side of the screen, and you will see intelligent\n# typeaheads aware of the current GraphQL type schema and live syntax and\n# validation errors highlighted within the text.\n#\n# GraphQL queries typically start with a \"{\" character. Lines that starts\n# with a # are ignored.\n#\n# An example GraphQL query might look like:\n#\n# {\n# field(arg: \"value\") {\n# subField\n# }\n# }\n#\n# Keyboard shortcuts:\n#\n# Prettify Query: Shift-Ctrl-P (or press the prettify button above)\n#\n# Merge Query: Shift-Ctrl-M (or press the merge button above)\n#\n# Run Query: Ctrl-Enter (or press the play button above)\n#\n# Auto Complete: Ctrl-Space (or just start typing)\n#\n";
2
+ //# sourceMappingURL=defaultQuery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaultQuery.d.ts","sourceRoot":"","sources":["../src/defaultQuery.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,66BAgCxB,CAAC"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultQuery = void 0;
4
+ exports.defaultQuery = `\
5
+ # Welcome to Ruru, our distribution of GraphiQL and related tooling to
6
+ # inspect your GraphQL API.
7
+ #
8
+ # GraphiQL is an in-browser tool for writing, validating, and
9
+ # testing GraphQL queries.
10
+ #
11
+ # Type queries into this side of the screen, and you will see intelligent
12
+ # typeaheads aware of the current GraphQL type schema and live syntax and
13
+ # validation errors highlighted within the text.
14
+ #
15
+ # GraphQL queries typically start with a "{" character. Lines that starts
16
+ # with a # are ignored.
17
+ #
18
+ # An example GraphQL query might look like:
19
+ #
20
+ # {
21
+ # field(arg: "value") {
22
+ # subField
23
+ # }
24
+ # }
25
+ #
26
+ # Keyboard shortcuts:
27
+ #
28
+ # Prettify Query: Shift-Ctrl-P (or press the prettify button above)
29
+ #
30
+ # Merge Query: Shift-Ctrl-M (or press the merge button above)
31
+ #
32
+ # Run Query: Ctrl-Enter (or press the play button above)
33
+ #
34
+ # Auto Complete: Ctrl-Space (or just start typing)
35
+ #
36
+ `;
37
+ //# sourceMappingURL=defaultQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaultQuery.js","sourceRoot":"","sources":["../src/defaultQuery.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgC3B,CAAC"}
@@ -0,0 +1,19 @@
1
+ /// <reference types="react" />
2
+ import type { ExplainResults } from "./useFetcher.js";
3
+ import type { RuruStorage } from "./useStorage.js";
4
+ export interface ExplainHelpers {
5
+ showExplain: boolean;
6
+ explainSize: number;
7
+ explainAtBottom: boolean;
8
+ setExplainSize: (newSize: number) => void;
9
+ setExplainAtBottom: (atBottom: boolean) => void;
10
+ setShowExplain: (newShow: boolean) => void;
11
+ }
12
+ export declare const ExplainContext: import("react").Context<{
13
+ explainHelpers: ExplainHelpers;
14
+ explain: boolean;
15
+ setExplain: (newExplain: boolean) => void;
16
+ explainResults: ExplainResults | null;
17
+ }>;
18
+ export declare const useExplain: (storage: RuruStorage) => ExplainHelpers;
19
+ //# sourceMappingURL=useExplain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useExplain.d.ts","sourceRoot":"","sources":["../../src/hooks/useExplain.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,OAAO,CAAC;IACzB,cAAc,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,kBAAkB,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IAChD,cAAc,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CAC5C;AAED,eAAO,MAAM,cAAc;oBACT,cAAc;aACrB,OAAO;6BACS,OAAO,KAAK,IAAI;oBACzB,cAAc,GAAG,IAAI;EAarC,CAAC;AAEH,eAAO,MAAM,UAAU,YAAa,WAAW,KAAG,cA0CjD,CAAC"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useExplain = exports.ExplainContext = void 0;
4
+ const react_1 = require("react");
5
+ exports.ExplainContext = (0, react_1.createContext)({
6
+ explainHelpers: {
7
+ showExplain: false,
8
+ explainSize: 0,
9
+ explainAtBottom: true,
10
+ setExplainSize: () => { },
11
+ setExplainAtBottom: () => { },
12
+ setShowExplain: () => { },
13
+ },
14
+ explain: false,
15
+ setExplain: () => { },
16
+ explainResults: null,
17
+ });
18
+ const useExplain = (storage) => {
19
+ const [showExplain, _setShowExplain] = (0, react_1.useState)(storage.get("explainIsOpen") === "true");
20
+ const [explainSize, _setExplainSize] = (0, react_1.useState)(parseInt(storage.get("explainSize") ?? "", 10) || 300);
21
+ const [explainAtBottom, _setExplainAtBottom] = (0, react_1.useState)([null, "true"].includes(storage.get("explainAtBottom")));
22
+ const setShowExplain = (0, react_1.useCallback)((nextShowExplain) => {
23
+ _setShowExplain(nextShowExplain);
24
+ if (nextShowExplain) {
25
+ storage.set("explain", "true");
26
+ }
27
+ storage.set("explainIsOpen", nextShowExplain ? "true" : "");
28
+ }, [storage]);
29
+ const setExplainAtBottom = (0, react_1.useCallback)((nextAtBottom) => {
30
+ _setExplainAtBottom(nextAtBottom);
31
+ storage.set("explainAtBottom", nextAtBottom ? "true" : "");
32
+ }, [storage]);
33
+ const setExplainSize = (0, react_1.useCallback)((nextSize) => {
34
+ _setExplainSize(nextSize);
35
+ storage.set("explainSize", String(nextSize));
36
+ }, [storage]);
37
+ return {
38
+ showExplain,
39
+ explainSize,
40
+ explainAtBottom,
41
+ setExplainSize,
42
+ setExplainAtBottom,
43
+ setShowExplain,
44
+ };
45
+ };
46
+ exports.useExplain = useExplain;
47
+ //# sourceMappingURL=useExplain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useExplain.js","sourceRoot":"","sources":["../../src/hooks/useExplain.ts"],"names":[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9D,CAAC,EACD,CAAC,OAAO,CAAC,CACV,CAAC;IACF,MAAM,kBAAkB,GAAG,IAAA,mBAAW,EACpC,CAAC,YAAqB,EAAE,EAAE;QACxB,mBAAmB,CAAC,YAAY,CAAC,CAAC;QAClC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC7D,CAAC,EACD,CAAC,OAAO,CAAC,CACV,CAAC;IACF,MAAM,cAAc,GAAG,IAAA,mBAAW,EAChC,CAAC,QAAgB,EAAE,EAAE;QACnB,eAAe,CAAC,QAAQ,CAAC,CAAC;QAC1B,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC/C,CAAC,EACD,CAAC,OAAO,CAAC,CACV,CAAC;IACF,OAAO;QACL,WAAW;QACX,WAAW;QACX,eAAe;QACf,cAAc;QACd,kBAAkB;QAClB,cAAc;KACf,CAAC;AACJ,CAAC,CAAC;AA1CW,QAAA,UAAU,cA0CrB"}
@@ -0,0 +1,28 @@
1
+ import type { FetcherParams, FetcherReturnType } from "@graphiql/toolkit";
2
+ import type { RuruProps } from "../interfaces.js";
3
+ export interface IExplainedOperation {
4
+ type: string;
5
+ title: string;
6
+ }
7
+ export interface ExplainedSQLOperation extends IExplainedOperation {
8
+ type: "sql";
9
+ query: string;
10
+ explain?: string;
11
+ }
12
+ export interface ExplainedMermaidJsOperation extends IExplainedOperation {
13
+ type: "mermaid-js";
14
+ diagram: string;
15
+ }
16
+ export declare type ExplainedOperation = ExplainedSQLOperation | ExplainedMermaidJsOperation;
17
+ export interface ExplainResults {
18
+ operations: Array<ExplainedOperation>;
19
+ }
20
+ export declare const useFetcher: (props: RuruProps, options?: {
21
+ explain?: boolean;
22
+ verbose?: boolean;
23
+ }) => {
24
+ fetcher: (graphQLParams: FetcherParams, opts?: import("@graphiql/toolkit").FetcherOpts | undefined) => Promise<FetcherReturnType>;
25
+ explainResults: ExplainResults | null;
26
+ streamEndpoint: string | null;
27
+ };
28
+ //# sourceMappingURL=useFetcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFetcher.d.ts","sourceRoot":"","sources":["../../src/hooks/useFetcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,aAAa,EACb,iBAAiB,EAClB,MAAM,mBAAmB,CAAC;AAM3B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,qBAAsB,SAAQ,mBAAmB;IAChE,IAAI,EAAE,KAAK,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,2BAA4B,SAAQ,mBAAmB;IACtE,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,oBAAY,kBAAkB,GAC1B,qBAAqB,GACrB,2BAA2B,CAAC;AAEhC,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,KAAK,CAAC,kBAAkB,CAAC,CAAC;CACvC;AAsDD,eAAO,MAAM,UAAU,UACd,SAAS,YACP;IAAE,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE;2GAqH5C,QAAQ,iBAAiB,CAAC;;;CAuChC,CAAC"}
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useFetcher = void 0;
4
+ const toolkit_1 = require("@graphiql/toolkit");
5
+ const graphql_1 = require("graphql");
6
+ const react_1 = require("react");
7
+ const isExplainOperationLike = (op) => {
8
+ return (typeof op === "object" &&
9
+ op &&
10
+ typeof op.type === "string" &&
11
+ typeof op.title === "string");
12
+ };
13
+ const isExplainResultsLike = (explain) => {
14
+ return (explain &&
15
+ Array.isArray(explain.operations) &&
16
+ explain.operations.every(isExplainOperationLike));
17
+ };
18
+ const isIntrospectionQuery = (params) => {
19
+ try {
20
+ if (params.operationName === "IntrospectionQuery") {
21
+ return true;
22
+ }
23
+ if (params.operationName) {
24
+ return false;
25
+ }
26
+ const ast = (0, graphql_1.parse)(params.query);
27
+ const def = (0, graphql_1.getOperationAST)(ast, params.operationName);
28
+ if (def?.name?.value === "IntrospectionQuery") {
29
+ return true;
30
+ }
31
+ return false;
32
+ }
33
+ catch (e) {
34
+ return false;
35
+ }
36
+ };
37
+ function makeWsUrl(url) {
38
+ if (url.startsWith("/")) {
39
+ return `ws${window.location.protocol === "https:" ? "s" : ""}://${window.location.host}${url}`;
40
+ }
41
+ else {
42
+ return url;
43
+ }
44
+ }
45
+ function hideProperty(obj, property) {
46
+ const value = obj[property];
47
+ delete obj[property];
48
+ Object.defineProperty(obj, property, { value, enumerable: false });
49
+ }
50
+ const useFetcher = (props, options = {}) => {
51
+ const [streamEndpoint, setStreamEndpoint] = (0, react_1.useState)(null);
52
+ const endpoint = props.endpoint ?? "/graphql";
53
+ const url = endpoint.startsWith("/")
54
+ ? (typeof window !== "undefined" ? window.location.origin : "") + endpoint
55
+ : endpoint;
56
+ const subscriptionUrl = props.subscriptionEndpoint
57
+ ? makeWsUrl(props.subscriptionEndpoint)
58
+ : undefined;
59
+ const [explainResults, setExplainResults] = (0, react_1.useState)(null);
60
+ // Reset the stream endpoint every time the URL changes.
61
+ (0, react_1.useEffect)(() => {
62
+ if (url) {
63
+ setStreamEndpoint(null);
64
+ }
65
+ }, [url]);
66
+ const explain = options.explain &&
67
+ (!props.debugTools || props.debugTools.includes("explain"));
68
+ const verbose = !!options.verbose;
69
+ const ourFetch = (0, react_1.useMemo)(() => {
70
+ return (...args) => {
71
+ const result = fetch(...args);
72
+ result.then((response) => {
73
+ const stream = response.headers.get("X-GraphQL-Event-Stream");
74
+ if (typeof stream === "string") {
75
+ const streamUrl = new URL(stream, url);
76
+ setStreamEndpoint(streamUrl.toString());
77
+ }
78
+ }, () => { });
79
+ return result;
80
+ };
81
+ }, [url]);
82
+ const fetcherOptions = (0, react_1.useMemo)(() => ({
83
+ url,
84
+ subscriptionUrl,
85
+ headers: {
86
+ ...(explain
87
+ ? {
88
+ "X-PostGraphile-Explain": "on",
89
+ "X-GraphQL-Explain": "mermaid-js,sql",
90
+ }
91
+ : null),
92
+ },
93
+ fetch: ourFetch,
94
+ }), [explain, url, subscriptionUrl, ourFetch]);
95
+ const fetcher = (0, react_1.useMemo)(() => props.fetcher ?? (0, toolkit_1.createGraphiQLFetcher)(fetcherOptions), [fetcherOptions, props.fetcher]);
96
+ const wrappedFetcher = (0, react_1.useMemo)(() => {
97
+ const processPayload = (result) => {
98
+ if (!result) {
99
+ return;
100
+ }
101
+ if (Array.isArray(result)) {
102
+ return result.forEach(processPayload);
103
+ }
104
+ // Legacy PostGraphile v4 support
105
+ const legacy = result.explain;
106
+ if (result.extensions?.explain) {
107
+ const explain = result.extensions.explain;
108
+ if (typeof explain === "object" && isExplainResultsLike(explain)) {
109
+ setTimeout(() => {
110
+ setExplainResults(explain);
111
+ }, 100);
112
+ }
113
+ else {
114
+ console.warn("The response had `extensions.explain` set, but in an incompatible format.");
115
+ }
116
+ // Hide it if not verbose
117
+ if (!verbose) {
118
+ if (Object.keys(result.extensions).length === 1) {
119
+ hideProperty(result, "extensions");
120
+ }
121
+ else {
122
+ hideProperty(result.extensions, "explain");
123
+ }
124
+ }
125
+ }
126
+ else if (legacy) {
127
+ setTimeout(() => {
128
+ setExplainResults({
129
+ operations: legacy.map((l, i) => ({
130
+ type: "sql",
131
+ title: `Legacy explain ${i + 1}`,
132
+ query: l.query,
133
+ explain: l.plan,
134
+ })),
135
+ });
136
+ }, 100);
137
+ }
138
+ };
139
+ return async function (...args) {
140
+ const result = await fetcher(...args);
141
+ // Short circuit the introspection query so as to not confuse people
142
+ if (isIntrospectionQuery(args[0])) {
143
+ return result;
144
+ }
145
+ setTimeout(() => {
146
+ setExplainResults(null);
147
+ }, 100);
148
+ if ("subscribe" in result) {
149
+ // TODO: support wrapping subscriptions
150
+ }
151
+ else if ("next" in result && typeof result.next === "function") {
152
+ // Return a new iterator, equivalent to the old, but that calls 'processPayload'
153
+ return {
154
+ throw: result.throw?.bind(result),
155
+ return: result.return?.bind(result),
156
+ next(...args) {
157
+ const n = result.next(...args);
158
+ Promise.resolve(n).then(({ done: _done, value }) => {
159
+ if (value) {
160
+ processPayload(value);
161
+ }
162
+ });
163
+ return n;
164
+ },
165
+ [Symbol.asyncIterator]() {
166
+ return this;
167
+ },
168
+ };
169
+ }
170
+ else {
171
+ processPayload(result);
172
+ }
173
+ return result;
174
+ };
175
+ }, [fetcher, verbose]);
176
+ return { fetcher: wrappedFetcher, explainResults, streamEndpoint };
177
+ };
178
+ exports.useFetcher = useFetcher;
179
+ //# sourceMappingURL=useFetcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFetcher.js","sourceRoot":"","sources":["../../src/hooks/useFetcher.ts"],"names":[],"mappings":";;;AAMA,+CAA0D;AAE1D,qCAAiD;AACjD,iCAAqD;AA4BrD,MAAM,sBAAsB,GAAG,CAAC,EAAO,EAA6B,EAAE;IACpE,OAAO,CACL,OAAO,EAAE,KAAK,QAAQ;QACtB,EAAE;QACF,OAAO,EAAE,CAAC,IAAI,KAAK,QAAQ;QAC3B,OAAO,EAAE,CAAC,KAAK,KAAK,QAAQ,CAC7B,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,oBAAoB,GAAG,CAAC,OAAY,EAA6B,EAAE;IACvE,OAAO,CACL,OAAO;QACP,KAAK,CAAC,OAAO,CAAE,OAAe,CAAC,UAAU,CAAC;QACzC,OAAe,CAAC,UAAU,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAC1D,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,oBAAoB,GAAG,CAAC,MAAqB,EAAE,EAAE;IACrD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AAC;YAC1B,CAAC,EAAE,GAAG,CAAC,CAAC;YACR,IAAI,WAAW,IAAI,MAAM,EAAE;gBACzB,uCAAuC;aACxC;iBAAM,IAAI,MAAM,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU,EAAE;gBAChE,gFAAgF;gBAChF,OAAO;oBACL,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC;oBACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;oBACnC,IAAI,CAAC,GAAG,IAAI;wBACV,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;wBAC/B,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE;4BACjD,IAAI,KAAK,EAAE;gCACT,cAAc,CAAC,KAAK,CAAC,CAAC;6BACvB;wBACH,CAAC,CAAC,CAAC;wBACH,OAAO,CAAC,CAAC;oBACX,CAAC;oBACD,CAAC,MAAM,CAAC,aAAa,CAAC;wBACpB,OAAO,IAAI,CAAC;oBACd,CAAC;iBAC4B,CAAC;aACjC;iBAAM;gBACL,cAAc,CAAC,MAAM,CAAC,CAAC;aACxB;YACD,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAEvB,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC;AACrE,CAAC,CAAC;AA9JW,QAAA,UAAU,cA8JrB"}
@@ -0,0 +1,5 @@
1
+ import type { RuruProps } from "../interfaces.js";
2
+ export declare const useGraphQLChangeStream: (props: RuruProps, refetch: () => void, streamEndpoint: string | null) => {
3
+ error: Error | null;
4
+ };
5
+ //# sourceMappingURL=useGraphQLChangeStream.d.ts.map