@akanjs/ui 0.9.55 → 0.9.57
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/Data/CardList.d.ts +3 -3
- package/Data/TableList.d.ts +4 -4
- package/Field.d.ts +11 -12
- package/Model/Remove.d.ts +3 -1
- package/Select.d.ts +2 -2
- package/Signal/Arg.d.ts +14 -11
- package/Signal/Doc.d.ts +8 -1
- package/Signal/GraphQL.d.ts +13 -16
- package/Signal/Message.d.ts +12 -15
- package/Signal/PubSub.d.ts +13 -15
- package/Signal/Response.d.ts +3 -5
- package/Signal/RestApi.d.ts +17 -20
- package/Signal/WebSocket.d.ts +1 -1
- package/System/CSR.d.ts +2 -2
- package/System/Common.d.ts +2 -25
- package/System/SSR.d.ts +2 -2
- package/Table.d.ts +2 -2
- package/cjs/Data/Insight.js +1 -1
- package/cjs/Data/Item.js +1 -1
- package/cjs/Data/ListContainer.js +5 -5
- package/cjs/Data/TableList.js +2 -5
- package/cjs/Field.js +11 -9
- package/cjs/Model/EditModal.js +1 -1
- package/cjs/Model/Remove.js +6 -11
- package/cjs/Model/ViewEditModal.js +14 -1
- package/cjs/Select.js +1 -1
- package/cjs/Signal/Arg.js +22 -22
- package/cjs/Signal/Doc.js +18 -27
- package/cjs/Signal/GraphQL.js +37 -52
- package/cjs/Signal/Message.js +25 -53
- package/cjs/Signal/Object.js +4 -12
- package/cjs/Signal/PubSub.js +20 -54
- package/cjs/Signal/Response.js +2 -2
- package/cjs/Signal/RestApi.js +63 -79
- package/cjs/Signal/WebSocket.js +14 -15
- package/cjs/System/CSR.js +5 -10
- package/cjs/System/Common.js +6 -6
- package/cjs/System/SSR.js +5 -10
- package/esm/Data/Insight.js +1 -1
- package/esm/Data/Item.js +1 -1
- package/esm/Data/ListContainer.js +5 -5
- package/esm/Data/TableList.js +2 -5
- package/esm/Field.js +12 -10
- package/esm/Model/EditModal.js +1 -1
- package/esm/Model/Remove.js +7 -12
- package/esm/Model/ViewEditModal.js +15 -2
- package/esm/Select.js +2 -2
- package/esm/Signal/Arg.js +24 -24
- package/esm/Signal/Doc.js +17 -26
- package/esm/Signal/GraphQL.js +39 -62
- package/esm/Signal/Message.js +27 -55
- package/esm/Signal/Object.js +4 -12
- package/esm/Signal/PubSub.js +22 -56
- package/esm/Signal/Response.js +2 -2
- package/esm/Signal/RestApi.js +66 -90
- package/esm/Signal/WebSocket.js +14 -15
- package/esm/System/CSR.js +5 -10
- package/esm/System/Common.js +6 -6
- package/esm/System/SSR.js +5 -10
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ import { usePage } from "@akanjs/client";
|
|
|
4
4
|
import { capitalize } from "@akanjs/common";
|
|
5
5
|
import { st } from "@akanjs/store";
|
|
6
6
|
import { AiOutlineEdit, AiOutlineSave } from "react-icons/ai";
|
|
7
|
-
import { BiDotsVertical } from "react-icons/bi";
|
|
7
|
+
import { BiDotsVertical, BiTrash } from "react-icons/bi";
|
|
8
8
|
import { Modal } from "../Modal";
|
|
9
9
|
import Remove from "./Remove";
|
|
10
10
|
import View from "./View";
|
|
@@ -62,7 +62,20 @@ function ViewEditModal({
|
|
|
62
62
|
/* @__PURE__ */ jsx(Title, {}),
|
|
63
63
|
/* @__PURE__ */ jsxs("div", { className: "dropdown dropdown-end", children: [
|
|
64
64
|
/* @__PURE__ */ jsx("label", { tabIndex: 0, className: "btn btn-square m-1", children: /* @__PURE__ */ jsx(BiDotsVertical, {}) }),
|
|
65
|
-
/* @__PURE__ */ jsx("ul", { tabIndex: 0, className: "dropdown-content menu bg-base-100 rounded-box z-[1] p-2 shadow-sm", children: model ? /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(
|
|
65
|
+
/* @__PURE__ */ jsx("ul", { tabIndex: 0, className: "dropdown-content menu bg-base-100 rounded-box z-[1] p-2 shadow-sm", children: model ? /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("a", { children: /* @__PURE__ */ jsxs(
|
|
66
|
+
Remove,
|
|
67
|
+
{
|
|
68
|
+
className: "text-error flex items-center gap-2",
|
|
69
|
+
sliceName,
|
|
70
|
+
modelId: model.id,
|
|
71
|
+
modal: null,
|
|
72
|
+
children: [
|
|
73
|
+
/* @__PURE__ */ jsx(BiTrash, {}),
|
|
74
|
+
" ",
|
|
75
|
+
l("base.remove")
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
) }) }) : null })
|
|
66
79
|
] })
|
|
67
80
|
] }),
|
|
68
81
|
action: modelModal === "view" ? /* @__PURE__ */ jsxs(
|
package/esm/Select.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { isEnum } from "@akanjs/base";
|
|
4
4
|
import { clsx, usePage } from "@akanjs/client";
|
|
5
5
|
import { useDebounce } from "@akanjs/next";
|
|
6
6
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
@@ -31,7 +31,7 @@ const Select = ({
|
|
|
31
31
|
const { l } = usePage();
|
|
32
32
|
const [isOpen, setIsOpen] = useState(false);
|
|
33
33
|
const labeledOptions = useMemo(
|
|
34
|
-
() => options
|
|
34
|
+
() => isEnum(options) ? options.values.map((v) => ({
|
|
35
35
|
label: typeof v === "string" ? v : typeof v === "object" ? JSON.stringify(v) : String(v),
|
|
36
36
|
value: v
|
|
37
37
|
})) : options[0]?.label && options[0]?.value ? options : options.map((v) => ({ label: v, value: v })),
|
package/esm/Signal/Arg.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { isGqlScalar } from "@akanjs/base";
|
|
4
4
|
import { usePage } from "@akanjs/client";
|
|
5
|
-
import { getGqlTypeStr, getScalarExample } from "@akanjs/constant";
|
|
5
|
+
import { constantInfo, getGqlTypeStr, getScalarExample } from "@akanjs/constant";
|
|
6
6
|
import { st } from "@akanjs/store";
|
|
7
7
|
import { AiOutlineDelete } from "react-icons/ai";
|
|
8
8
|
import { DatePicker } from "../DatePicker";
|
|
@@ -11,7 +11,7 @@ import Object from "./Object";
|
|
|
11
11
|
function Arg({ argType, value, onChange }) {
|
|
12
12
|
return argType === "ID" ? /* @__PURE__ */ jsx(Arg.ID, { value, onChange }) : argType === "Int" ? /* @__PURE__ */ jsx(Arg.Int, { value, onChange }) : argType === "Float" ? /* @__PURE__ */ jsx(Arg.Float, { value, onChange }) : argType === "String" ? /* @__PURE__ */ jsx(Arg.String, { value, onChange }) : argType === "Boolean" ? /* @__PURE__ */ jsx(Arg.Boolean, { value, onChange }) : argType === "Date" ? /* @__PURE__ */ jsx(Arg.Date, { value, onChange }) : argType === "JSON" ? /* @__PURE__ */ jsx(Arg.Json, { value, onChange }) : argType === "Upload" ? /* @__PURE__ */ jsx(Arg.Upload, { value, onChange }) : /* @__PURE__ */ jsx(Fragment, {});
|
|
13
13
|
}
|
|
14
|
-
const ArgTable = ({
|
|
14
|
+
const ArgTable = ({ refName, gqlKey, argMetas }) => {
|
|
15
15
|
const { l } = usePage();
|
|
16
16
|
const onCopy = (text) => {
|
|
17
17
|
void navigator.clipboard.writeText(text);
|
|
@@ -26,14 +26,14 @@ const ArgTable = ({ sigMeta, gqlMeta, argMetas }) => {
|
|
|
26
26
|
/* @__PURE__ */ jsx("th", { className: "text-center", children: "Description" })
|
|
27
27
|
] }) }),
|
|
28
28
|
argMetas.map((argMeta, idx) => {
|
|
29
|
-
const
|
|
29
|
+
const argRef = constantInfo.getModelRef(argMeta.refName, argMeta.modelType);
|
|
30
30
|
return /* @__PURE__ */ jsx("tbody", { className: "font-normal", children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
31
31
|
/* @__PURE__ */ jsx("td", { children: argMeta.name }),
|
|
32
|
-
/* @__PURE__ */ jsx("td", { className: "text-center", children: /* @__PURE__ */ jsx(Object.Type, { objRef: argRef, arrDepth:
|
|
32
|
+
/* @__PURE__ */ jsx("td", { className: "text-center", children: /* @__PURE__ */ jsx(Object.Type, { objRef: argRef, arrDepth: argMeta.arrDepth }) }),
|
|
33
33
|
/* @__PURE__ */ jsx("td", { width: argMeta.argsOption.enum ? "20%" : "10%", className: "text-center", children: argMeta.argsOption.enum ? /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: argMeta.argsOption.enum.map((opt, idx2) => /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
|
|
34
34
|
"button",
|
|
35
35
|
{
|
|
36
|
-
"data-tip": l.
|
|
36
|
+
"data-tip": l._(`${argMeta.argsOption.enum?.refName}.${opt}`),
|
|
37
37
|
onClick: () => {
|
|
38
38
|
onCopy(opt);
|
|
39
39
|
},
|
|
@@ -42,19 +42,19 @@ const ArgTable = ({ sigMeta, gqlMeta, argMetas }) => {
|
|
|
42
42
|
},
|
|
43
43
|
idx2
|
|
44
44
|
) }, idx2)) }) : "-" }),
|
|
45
|
-
/* @__PURE__ */ jsx("td", { className: "text-center", children: l.
|
|
46
|
-
/* @__PURE__ */ jsx("td", { className: "text-center", children: l.
|
|
45
|
+
/* @__PURE__ */ jsx("td", { className: "text-center", children: l._(`${refName}.signal.${gqlKey}.arg.${argMeta.name}`) }),
|
|
46
|
+
/* @__PURE__ */ jsx("td", { className: "text-center", children: l._(`${refName}.signal.${gqlKey}.arg.${argMeta.name}.desc`) })
|
|
47
47
|
] }) }, idx);
|
|
48
48
|
})
|
|
49
49
|
] });
|
|
50
50
|
};
|
|
51
51
|
Arg.Table = ArgTable;
|
|
52
|
-
const ArgParam = ({ argMeta, value, onChange }) => {
|
|
53
|
-
const
|
|
52
|
+
const ArgParam = ({ gqlKey, argMeta, value, onChange }) => {
|
|
53
|
+
const argRef = constantInfo.getModelRef(argMeta.refName, argMeta.modelType);
|
|
54
54
|
if (!isGqlScalar(argRef))
|
|
55
|
-
throw new Error(`Param arg - ${
|
|
56
|
-
else if (
|
|
57
|
-
throw new Error(`Param arg - ${
|
|
55
|
+
throw new Error(`Param arg - ${gqlKey}/${argMeta.name} must be scalar`);
|
|
56
|
+
else if (argMeta.arrDepth > 0)
|
|
57
|
+
throw new Error(`Param arg - ${gqlKey}/${argMeta.name} must not be array`);
|
|
58
58
|
const argType = getGqlTypeStr(argRef);
|
|
59
59
|
return /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-2", children: [
|
|
60
60
|
/* @__PURE__ */ jsxs("div", { className: "w-36 pl-2", children: [
|
|
@@ -65,19 +65,19 @@ const ArgParam = ({ argMeta, value, onChange }) => {
|
|
|
65
65
|
] });
|
|
66
66
|
};
|
|
67
67
|
Arg.Param = ArgParam;
|
|
68
|
-
const ArgQuery = ({ argMeta, value, onChange }) => {
|
|
69
|
-
const
|
|
68
|
+
const ArgQuery = ({ gqlKey, argMeta, value, onChange }) => {
|
|
69
|
+
const argRef = constantInfo.getModelRef(argMeta.refName, argMeta.modelType);
|
|
70
70
|
if (!isGqlScalar(argRef))
|
|
71
|
-
throw new Error(`Query arg - ${
|
|
72
|
-
else if (
|
|
73
|
-
throw new Error(`Query arg - ${
|
|
71
|
+
throw new Error(`Query arg - ${gqlKey}/${argMeta.name} must be scalar`);
|
|
72
|
+
else if (argMeta.arrDepth > 1)
|
|
73
|
+
throw new Error(`Query arg - ${gqlKey}/${argMeta.name} must not be more than 2D array`);
|
|
74
74
|
const argType = getGqlTypeStr(argRef);
|
|
75
75
|
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
76
76
|
/* @__PURE__ */ jsxs("div", { className: "w-36 pl-2", children: [
|
|
77
77
|
"- ",
|
|
78
78
|
argMeta.name
|
|
79
79
|
] }),
|
|
80
|
-
/* @__PURE__ */ jsx("div", { className: "w-full", children:
|
|
80
|
+
/* @__PURE__ */ jsx("div", { className: "w-full", children: argMeta.arrDepth > 0 && Array.isArray(value) ? /* @__PURE__ */ jsxs("div", { children: [
|
|
81
81
|
value.map((val, idx) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
82
82
|
/* @__PURE__ */ jsx(
|
|
83
83
|
Arg,
|
|
@@ -114,12 +114,12 @@ const ArgQuery = ({ argMeta, value, onChange }) => {
|
|
|
114
114
|
] });
|
|
115
115
|
};
|
|
116
116
|
Arg.Query = ArgQuery;
|
|
117
|
-
const ArgFormData = ({ argMeta, value, onChange }) => {
|
|
118
|
-
const
|
|
117
|
+
const ArgFormData = ({ gqlKey, argMeta, value, onChange }) => {
|
|
118
|
+
const argRef = constantInfo.getModelRef(argMeta.refName, argMeta.modelType);
|
|
119
119
|
if (getGqlTypeStr(argRef) !== "Upload")
|
|
120
|
-
throw new Error(`FormData arg - ${
|
|
121
|
-
else if (
|
|
122
|
-
throw new Error(`FormData arg - ${
|
|
120
|
+
throw new Error(`FormData arg - ${gqlKey}/${argMeta.name} must be Upload`);
|
|
121
|
+
else if (argMeta.arrDepth < 1)
|
|
122
|
+
throw new Error(`FormData arg - ${gqlKey}/${argMeta.name} must be array`);
|
|
123
123
|
return /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-2", children: [
|
|
124
124
|
/* @__PURE__ */ jsxs("div", { className: "w-36 pl-2", children: [
|
|
125
125
|
"- ",
|
package/esm/Signal/Doc.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { usePage } from "@akanjs/client";
|
|
4
4
|
import { lowerlize } from "@akanjs/common";
|
|
5
|
-
import { client, defaultAccount
|
|
5
|
+
import { client, defaultAccount } from "@akanjs/signal";
|
|
6
6
|
import { st } from "@akanjs/store";
|
|
7
7
|
import decode from "jsonwebtoken/decode";
|
|
8
|
-
import { useState } from "react";
|
|
8
|
+
import { useEffect, useState } from "react";
|
|
9
9
|
import { AiOutlineApi, AiOutlineCopy } from "react-icons/ai";
|
|
10
10
|
import { BiLock, BiLogoGraphql } from "react-icons/bi";
|
|
11
11
|
import { Copy } from "../Copy";
|
|
@@ -17,12 +17,20 @@ import WebSocket from "./WebSocket";
|
|
|
17
17
|
function Doc() {
|
|
18
18
|
return /* @__PURE__ */ jsx("div", {});
|
|
19
19
|
}
|
|
20
|
-
const DocSetting = (
|
|
20
|
+
const DocSetting = ({
|
|
21
|
+
guardNames = ["Public"],
|
|
22
|
+
roleTypes = ["Public", "User", "Admin", "SuperAdmin"],
|
|
23
|
+
roleKeys = { me: "Admin", self: "User" }
|
|
24
|
+
}) => {
|
|
21
25
|
const trySignalType = st.use.trySignalType();
|
|
22
26
|
const tryRoles = st.use.tryRoles();
|
|
23
27
|
const tryAccount = st.use.tryAccount();
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
st.set({ tryRoles: [...roleTypes] });
|
|
30
|
+
}, []);
|
|
24
31
|
const tryRoleForAll = roleTypes.every((roleType) => tryRoles.includes(roleType));
|
|
25
32
|
const baseUrl = trySignalType === "graphql" ? client.uri : client.uri.replace("/graphql", "");
|
|
33
|
+
const currentRoles = Object.entries(roleKeys).filter(([key, roleType]) => !!tryAccount[key]).map(([key, roleType]) => roleType);
|
|
26
34
|
return /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-wrap items-center justify-between gap-4", children: [
|
|
27
35
|
/* @__PURE__ */ jsxs("div", { className: "flex flex-1 items-center gap-1", children: [
|
|
28
36
|
"BaseURL:",
|
|
@@ -93,14 +101,10 @@ const DocSetting = () => {
|
|
|
93
101
|
] }),
|
|
94
102
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
95
103
|
"Auth:",
|
|
96
|
-
/* @__PURE__ */ jsx(DocAuthModal, { children: /* @__PURE__ */ jsxs("button", { className: `btn btn-sm ${
|
|
104
|
+
/* @__PURE__ */ jsx(DocAuthModal, { children: /* @__PURE__ */ jsxs("button", { className: `btn btn-sm ${currentRoles.length > 0 ? "btn-warning" : "btn-neutral"} `, children: [
|
|
97
105
|
/* @__PURE__ */ jsx(BiLock, {}),
|
|
98
106
|
" ",
|
|
99
|
-
|
|
100
|
-
tryAccount.me ? "Admin" : null,
|
|
101
|
-
tryAccount.self ? "User" : null,
|
|
102
|
-
!tryAccount.me && !tryAccount.self ? "Public" : null
|
|
103
|
-
].filter((roleType) => !!roleType).join(",")
|
|
107
|
+
currentRoles.length > 0 ? currentRoles.join(", ") : "Public"
|
|
104
108
|
] }) })
|
|
105
109
|
] })
|
|
106
110
|
] });
|
|
@@ -154,18 +158,7 @@ const DocAuthModal = ({ children }) => {
|
|
|
154
158
|
/* @__PURE__ */ jsx(Input, { inputClassName: "w-full", value: jwt ?? "", onChange: setJwt, validate: () => true })
|
|
155
159
|
] }),
|
|
156
160
|
/* @__PURE__ */ jsxs("div", { className: "w-full", children: [
|
|
157
|
-
/* @__PURE__ */
|
|
158
|
-
"Account Decoded",
|
|
159
|
-
!decodedAccount?.me && !decodedAccount?.self ? /* @__PURE__ */ jsx("div", { className: "badge badge-primary", children: "Public" }) : null,
|
|
160
|
-
decodedAccount?.me?.roles.map((role) => /* @__PURE__ */ jsxs("div", { className: "badge badge-warning", children: [
|
|
161
|
-
"Admin-",
|
|
162
|
-
role
|
|
163
|
-
] }, role)),
|
|
164
|
-
decodedAccount?.self?.roles.map((role) => /* @__PURE__ */ jsxs("div", { className: "badge badge-neutral", children: [
|
|
165
|
-
"User-",
|
|
166
|
-
role
|
|
167
|
-
] }, role))
|
|
168
|
-
] }),
|
|
161
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center gap-2", children: "Account Decoded" }),
|
|
169
162
|
/* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
170
163
|
/* @__PURE__ */ jsx(
|
|
171
164
|
Input.TextArea,
|
|
@@ -190,10 +183,8 @@ const DocAuthModal = ({ children }) => {
|
|
|
190
183
|
};
|
|
191
184
|
Doc.AuthModal = DocAuthModal;
|
|
192
185
|
const DocSignals = () => {
|
|
193
|
-
const
|
|
194
|
-
const refNames =
|
|
195
|
-
(a, b) => lowerlize(a) > lowerlize(b) ? 1 : -1
|
|
196
|
-
);
|
|
186
|
+
const signals = global.signals;
|
|
187
|
+
const refNames = signals.map((signal) => signal.refName).sort((a, b) => lowerlize(a) > lowerlize(b) ? 1 : -1);
|
|
197
188
|
return /* @__PURE__ */ jsx("div", { children: refNames.map((refName, idx) => {
|
|
198
189
|
return /* @__PURE__ */ jsx("div", { className: "px-5 pb-5 text-3xl font-bold", children: /* @__PURE__ */ jsx(DocSignal, { refName }) }, idx);
|
|
199
190
|
}) });
|
|
@@ -214,7 +205,7 @@ const Zone = ({ refName, openAll }) => {
|
|
|
214
205
|
/* @__PURE__ */ jsx("div", { className: "text-3xl font-bold", children: refName }),
|
|
215
206
|
/* @__PURE__ */ jsxs("div", { className: "mb-5", children: [
|
|
216
207
|
" - ",
|
|
217
|
-
l.
|
|
208
|
+
l._(`${refName}.modelDesc`)
|
|
218
209
|
] }),
|
|
219
210
|
/* @__PURE__ */ jsx("div", { className: "text-2xl font-bold", children: "APIs" }),
|
|
220
211
|
/* @__PURE__ */ jsx(DocSetting, {}),
|
package/esm/Signal/GraphQL.js
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { isGqlScalar } from "@akanjs/base";
|
|
4
4
|
import { usePage } from "@akanjs/client";
|
|
5
5
|
import { constantInfo } from "@akanjs/constant";
|
|
6
|
-
import {
|
|
7
|
-
fetch,
|
|
8
|
-
getArgMetas,
|
|
9
|
-
getGqlMetas,
|
|
10
|
-
getGqlStr,
|
|
11
|
-
getSigMeta,
|
|
12
|
-
getSignalRefsOnStorage,
|
|
13
|
-
makeRequestExample
|
|
14
|
-
} from "@akanjs/signal";
|
|
6
|
+
import { fetch, getGqlStr, makeRequestExample } from "@akanjs/signal";
|
|
15
7
|
import { st } from "@akanjs/store";
|
|
16
8
|
import { useMemo, useState } from "react";
|
|
17
9
|
import { AiOutlineFileWord, AiOutlineSend } from "react-icons/ai";
|
|
@@ -24,43 +16,39 @@ function GraphQL() {
|
|
|
24
16
|
return /* @__PURE__ */ jsx("div", {});
|
|
25
17
|
}
|
|
26
18
|
const GraphQLEndpoints = ({ refName, openAll }) => {
|
|
27
|
-
const
|
|
19
|
+
const signals = global.signals;
|
|
20
|
+
const signal = signals.find((signal2) => signal2.refName === refName);
|
|
28
21
|
const tryRoles = st.use.tryRoles();
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (gqlMeta.type === "Pubsub" || gqlMeta.type === "Message")
|
|
22
|
+
if (!signal)
|
|
23
|
+
return null;
|
|
24
|
+
const gqlInfos = global.Object.entries(signal.endpoint).sort(([keyA], [keyB]) => keyA > keyB ? 1 : -1).filter(([key, gqlMeta]) => gqlMeta.signalOption?.onlyFor !== "restapi").filter(([key, gqlMeta]) => {
|
|
25
|
+
if (gqlMeta.type !== "query" && gqlMeta.type !== "mutation")
|
|
34
26
|
return false;
|
|
35
|
-
if (gqlMeta.guards
|
|
27
|
+
if (gqlMeta.signalOption?.guards?.includes("Public") && tryRoles.includes("Public"))
|
|
36
28
|
return true;
|
|
37
|
-
if ((gqlMeta.guards
|
|
29
|
+
if ((gqlMeta.signalOption?.guards?.includes("User") || gqlMeta.signalOption?.guards?.includes("Every")) && tryRoles.includes("User"))
|
|
38
30
|
return true;
|
|
39
|
-
if ((gqlMeta.guards
|
|
31
|
+
if ((gqlMeta.signalOption?.guards?.includes("Admin") || gqlMeta.signalOption?.guards?.includes("Every")) && tryRoles.includes("Admin"))
|
|
40
32
|
return true;
|
|
41
|
-
if (gqlMeta.guards
|
|
33
|
+
if ((gqlMeta.signalOption?.guards?.includes("SuperAdmin") || gqlMeta.signalOption?.guards?.includes("Every")) && tryRoles.includes("SuperAdmin"))
|
|
42
34
|
return true;
|
|
43
35
|
return false;
|
|
44
36
|
});
|
|
45
|
-
return /* @__PURE__ */ jsx("div", { children: gqlInfos.map((
|
|
37
|
+
return /* @__PURE__ */ jsx("div", { children: gqlInfos.map(([gqlKey, gqlMeta], idx) => /* @__PURE__ */ jsx(GraphQLEndpoint, { refName, gqlKey, gqlMeta, open: openAll }, idx)) });
|
|
46
38
|
};
|
|
47
39
|
GraphQL.Endpoints = GraphQLEndpoints;
|
|
48
|
-
const GraphQLEndpoint = ({
|
|
40
|
+
const GraphQLEndpoint = ({ refName, gqlKey, gqlMeta, open }) => {
|
|
49
41
|
const { l } = usePage();
|
|
50
|
-
const sigMeta = getSigMeta(sigRef);
|
|
51
42
|
const [viewStatus, setViewStatus] = useState("doc");
|
|
52
|
-
const [argMetas] = getArgMetas(sigRef, gqlMeta.key);
|
|
53
|
-
const gqlArgMetas = argMetas.filter((argMeta) => argMeta.type !== "Upload");
|
|
54
|
-
const uploadArgMetas = argMetas.filter((argMeta) => argMeta.type === "Upload");
|
|
55
43
|
return /* @__PURE__ */ jsxs("div", { className: "collapse-arrow bg-base-300 collapse my-1", children: [
|
|
56
44
|
/* @__PURE__ */ jsx("input", { type: "checkbox", checked: open }),
|
|
57
45
|
/* @__PURE__ */ jsx("div", { className: "collapse-title text-xl", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
58
|
-
/* @__PURE__ */ jsx("div", { className: `btn btn-xs w-16 ${gqlMeta.type === "
|
|
59
|
-
|
|
46
|
+
/* @__PURE__ */ jsx("div", { className: `btn btn-xs w-16 ${gqlMeta.type === "query" ? "btn-success" : "btn-accent"}`, children: gqlMeta.type }),
|
|
47
|
+
gqlKey,
|
|
60
48
|
" ",
|
|
61
49
|
/* @__PURE__ */ jsxs("span", { className: "text-sm", children: [
|
|
62
50
|
"(",
|
|
63
|
-
l.
|
|
51
|
+
l._(`${refName}.signal.${gqlKey}`),
|
|
64
52
|
")"
|
|
65
53
|
] })
|
|
66
54
|
] }) }),
|
|
@@ -68,9 +56,9 @@ const GraphQLEndpoint = ({ sigRef, gqlMeta, open }) => {
|
|
|
68
56
|
/* @__PURE__ */ jsxs("div", { className: "mt-4 text-lg", children: [
|
|
69
57
|
"Description",
|
|
70
58
|
/* @__PURE__ */ jsx("hr", { className: "my-2 border-[0.1px] border-gray-400" }),
|
|
71
|
-
gqlMeta.guards
|
|
59
|
+
gqlMeta.signalOption?.guards?.some((guard) => guard !== "None") ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 pb-3 pl-3 text-base font-normal", children: [
|
|
72
60
|
"- Guards:",
|
|
73
|
-
gqlMeta.guards.map((guard) => /* @__PURE__ */ jsx(
|
|
61
|
+
gqlMeta.signalOption.guards.map((guard) => /* @__PURE__ */ jsx(
|
|
74
62
|
"span",
|
|
75
63
|
{
|
|
76
64
|
className: `badge ${guard === "Public" ? "badge-success" : guard === "SuperAdmin" ? "badge-error" : guard === "Admin" ? "badge-error" : guard === "User" ? "badge-accent" : guard === "Owner" ? "badge-accent" : guard === "Every" ? "badge-warning" : ""}`,
|
|
@@ -81,7 +69,7 @@ const GraphQLEndpoint = ({ sigRef, gqlMeta, open }) => {
|
|
|
81
69
|
] }) : null,
|
|
82
70
|
/* @__PURE__ */ jsxs("div", { className: "pb-3 pl-3 text-base font-normal", children: [
|
|
83
71
|
"- ",
|
|
84
|
-
l.
|
|
72
|
+
l._(`${refName}.signal.${gqlKey}.desc`)
|
|
85
73
|
] })
|
|
86
74
|
] }),
|
|
87
75
|
/* @__PURE__ */ jsxs("div", { className: "my-4 flex w-full gap-5 px-5", children: [
|
|
@@ -112,31 +100,25 @@ const GraphQLEndpoint = ({ sigRef, gqlMeta, open }) => {
|
|
|
112
100
|
}
|
|
113
101
|
)
|
|
114
102
|
] }),
|
|
115
|
-
viewStatus === "doc" ? /* @__PURE__ */ jsx(
|
|
116
|
-
GraphQLInterface,
|
|
117
|
-
{
|
|
118
|
-
sigRef,
|
|
119
|
-
gqlMeta,
|
|
120
|
-
gqlArgMetas,
|
|
121
|
-
uploadArgMetas
|
|
122
|
-
}
|
|
123
|
-
) : /* @__PURE__ */ jsx(GraphQLTry, { sigRef, gqlMeta, gqlArgMetas, uploadArgMetas })
|
|
103
|
+
viewStatus === "doc" ? /* @__PURE__ */ jsx(GraphQLInterface, { refName, gqlKey, gqlMeta }) : /* @__PURE__ */ jsx(GraphQLTry, { gqlKey, gqlMeta })
|
|
124
104
|
] })
|
|
125
105
|
] });
|
|
126
106
|
};
|
|
127
107
|
GraphQL.Endpoint = GraphQLEndpoint;
|
|
128
|
-
const GraphQLInterface = ({
|
|
129
|
-
const
|
|
130
|
-
const
|
|
108
|
+
const GraphQLInterface = ({ refName, gqlKey, gqlMeta }) => {
|
|
109
|
+
const returnRef = constantInfo.getModelRef(gqlMeta.returns.refName, gqlMeta.returns.modelType);
|
|
110
|
+
const arrDepth = gqlMeta.returns.arrDepth;
|
|
131
111
|
const isReturnModelType = !isGqlScalar(returnRef);
|
|
112
|
+
const uploadArgMetas = gqlMeta.args.filter((argMeta) => argMeta.type === "Upload");
|
|
113
|
+
const gqlArgMetas = gqlMeta.args.filter((argMeta) => argMeta.type !== "Upload");
|
|
132
114
|
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
133
115
|
uploadArgMetas.length ? /* @__PURE__ */ jsxs("div", { children: [
|
|
134
116
|
/* @__PURE__ */ jsx("div", { className: "text-lg", children: "Form data upload" }),
|
|
135
|
-
/* @__PURE__ */ jsx("div", { className: "bg-base-100 overflow-x-auto rounded-md p-3", children: /* @__PURE__ */ jsx(Arg.Table, {
|
|
117
|
+
/* @__PURE__ */ jsx("div", { className: "bg-base-100 overflow-x-auto rounded-md p-3", children: /* @__PURE__ */ jsx(Arg.Table, { refName, gqlKey, argMetas: uploadArgMetas }) })
|
|
136
118
|
] }) : null,
|
|
137
119
|
gqlArgMetas.length ? /* @__PURE__ */ jsxs("div", { className: "text-start", children: [
|
|
138
120
|
/* @__PURE__ */ jsx("span", { className: "text-start text-xl font-bold", children: "Variables" }),
|
|
139
|
-
/* @__PURE__ */ jsx("div", { className: "bg-base-100 mt-3 overflow-x-auto rounded-md p-3", children: /* @__PURE__ */ jsx(Arg.Table, {
|
|
121
|
+
/* @__PURE__ */ jsx("div", { className: "bg-base-100 mt-3 overflow-x-auto rounded-md p-3", children: /* @__PURE__ */ jsx(Arg.Table, { refName, gqlKey, argMetas: gqlArgMetas }) })
|
|
140
122
|
] }) : null,
|
|
141
123
|
/* @__PURE__ */ jsx("div", { className: "text-lg font-bold", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-col gap-2 rounded-md font-normal md:flex-col", children: [
|
|
142
124
|
/* @__PURE__ */ jsxs("div", { className: "w-full text-start md:w-full", children: [
|
|
@@ -149,27 +131,21 @@ const GraphQLInterface = ({ sigRef, gqlMeta, gqlArgMetas, uploadArgMetas }) => {
|
|
|
149
131
|
] }),
|
|
150
132
|
/* @__PURE__ */ jsxs("div", { className: "w-full text-start md:w-full", children: [
|
|
151
133
|
/* @__PURE__ */ jsx("span", { className: "text-xl font-bold", children: "Response Example" }),
|
|
152
|
-
/* @__PURE__ */ jsx("div", { className: "mt-3", children: /* @__PURE__ */ jsx(Response.Example, {
|
|
134
|
+
/* @__PURE__ */ jsx("div", { className: "mt-3", children: /* @__PURE__ */ jsx(Response.Example, { gqlMeta }) })
|
|
153
135
|
] })
|
|
154
136
|
] }) })
|
|
155
137
|
] });
|
|
156
138
|
};
|
|
157
139
|
GraphQL.Interface = GraphQLInterface;
|
|
158
|
-
const GraphQLTry = ({
|
|
140
|
+
const GraphQLTry = ({ gqlKey, gqlMeta }) => {
|
|
159
141
|
const tryJwt = st.use.tryJwt();
|
|
160
|
-
const
|
|
142
|
+
const modelRef = constantInfo.getModelRef(gqlMeta.returns.refName, gqlMeta.returns.modelType);
|
|
143
|
+
const uploadArgMetas = gqlMeta.args.filter((argMeta) => argMeta.type === "Upload");
|
|
144
|
+
const gqlArgMetas = gqlMeta.args.filter((argMeta) => argMeta.type !== "Upload");
|
|
161
145
|
const isScalar = isGqlScalar(modelRef);
|
|
162
|
-
const returnRef = isScalar || arrDepth === 0 ? modelRef : constantInfo.isFull(modelRef) ? constantInfo.getDatabase(constantInfo.getRefName(modelRef)).light : modelRef;
|
|
163
|
-
const gqlStr = useMemo(
|
|
164
|
-
|
|
165
|
-
modelRef,
|
|
166
|
-
gqlMeta.key,
|
|
167
|
-
[...gqlArgMetas, ...uploadArgMetas].sort((a, b) => a.idx - b.idx),
|
|
168
|
-
returnRef
|
|
169
|
-
),
|
|
170
|
-
[]
|
|
171
|
-
);
|
|
172
|
-
const requestExample = useMemo(() => JSON.stringify(makeRequestExample(sigRef, gqlMeta.key), null, 2), []);
|
|
146
|
+
const returnRef = isScalar || gqlMeta.returns.arrDepth === 0 ? modelRef : constantInfo.isFull(modelRef) ? constantInfo.getDatabase(constantInfo.getRefName(modelRef)).light : modelRef;
|
|
147
|
+
const gqlStr = useMemo(() => getGqlStr(modelRef, gqlKey, gqlMeta, returnRef), []);
|
|
148
|
+
const requestExample = useMemo(() => JSON.stringify(makeRequestExample(gqlMeta), null, 2), []);
|
|
173
149
|
const [gqlRequest, setGqlRequest] = useState(requestExample);
|
|
174
150
|
const [uploadRequest, setUploadRequest] = useState({});
|
|
175
151
|
const [response, setResponse] = useState({
|
|
@@ -179,8 +155,8 @@ const GraphQLTry = ({ sigRef, gqlMeta, gqlArgMetas, uploadArgMetas }) => {
|
|
|
179
155
|
const onSend = async () => {
|
|
180
156
|
setResponse({ status: "loading", data: null });
|
|
181
157
|
const request = { ...JSON.parse(gqlRequest), ...uploadRequest };
|
|
182
|
-
const argData =
|
|
183
|
-
const fetchFn = fetch[
|
|
158
|
+
const argData = gqlMeta.args.map((argMeta) => request[argMeta.name]);
|
|
159
|
+
const fetchFn = fetch[gqlKey].bind(fetch);
|
|
184
160
|
const data = await fetchFn(...argData, {
|
|
185
161
|
token: tryJwt,
|
|
186
162
|
onError: (data2) => {
|
|
@@ -195,6 +171,7 @@ const GraphQLTry = ({ sigRef, gqlMeta, gqlArgMetas, uploadArgMetas }) => {
|
|
|
195
171
|
uploadArgMetas.map((argMeta) => /* @__PURE__ */ jsx(
|
|
196
172
|
Arg.FormData,
|
|
197
173
|
{
|
|
174
|
+
gqlKey,
|
|
198
175
|
argMeta,
|
|
199
176
|
value: uploadRequest[argMeta.name],
|
|
200
177
|
onChange: (fileList) => {
|
package/esm/Signal/Message.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { isGqlScalar } from "@akanjs/base";
|
|
4
4
|
import { usePage } from "@akanjs/client";
|
|
5
5
|
import { capitalize } from "@akanjs/common";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { constantInfo } from "@akanjs/constant";
|
|
7
|
+
import { fetch, makeRequestExample } from "@akanjs/signal";
|
|
8
8
|
import { useEffect, useMemo, useState } from "react";
|
|
9
9
|
import { AiOutlineDisconnect, AiOutlineFileWord, AiOutlineSend, AiOutlineSwap } from "react-icons/ai";
|
|
10
10
|
import { BiSolidNetworkChart } from "react-icons/bi";
|
|
@@ -15,22 +15,20 @@ import Response from "./Response";
|
|
|
15
15
|
function Message() {
|
|
16
16
|
return /* @__PURE__ */ jsx("div", {});
|
|
17
17
|
}
|
|
18
|
-
const MessageEndpoint = ({
|
|
18
|
+
const MessageEndpoint = ({ refName, gqlKey, gqlMeta, open }) => {
|
|
19
19
|
const { l } = usePage();
|
|
20
|
-
const sigMeta = getSigMeta(sigRef);
|
|
21
20
|
const [viewStatus, setViewStatus] = useState("doc");
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const uploadArgMetas = argMetas.filter((argMeta) => argMeta.type === "Upload");
|
|
21
|
+
const gqlArgMetas = gqlMeta.args.filter((argMeta) => argMeta.type !== "Upload");
|
|
22
|
+
const uploadArgMetas = gqlMeta.args.filter((argMeta) => argMeta.type === "Upload");
|
|
25
23
|
return /* @__PURE__ */ jsxs("div", { className: "collapse-arrow bg-base-300 collapse my-1", children: [
|
|
26
24
|
/* @__PURE__ */ jsx("input", { type: "checkbox", checked: open }),
|
|
27
25
|
/* @__PURE__ */ jsx("div", { className: "collapse-title text-xl", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
28
|
-
/* @__PURE__ */ jsx("div", { className: `btn btn-xs w-16 ${gqlMeta.type === "
|
|
29
|
-
|
|
26
|
+
/* @__PURE__ */ jsx("div", { className: `btn btn-xs w-16 ${gqlMeta.type === "pubsub" ? "btn-info" : "btn-warning"}`, children: gqlMeta.type }),
|
|
27
|
+
gqlKey,
|
|
30
28
|
" ",
|
|
31
29
|
/* @__PURE__ */ jsxs("span", { className: "text-sm", children: [
|
|
32
30
|
"(",
|
|
33
|
-
l.
|
|
31
|
+
l._(`${refName}.signal.${gqlKey}`),
|
|
34
32
|
")"
|
|
35
33
|
] })
|
|
36
34
|
] }) }),
|
|
@@ -38,9 +36,9 @@ const MessageEndpoint = ({ sigRef, gqlMeta, open }) => {
|
|
|
38
36
|
/* @__PURE__ */ jsxs("div", { className: "mt-4 text-lg", children: [
|
|
39
37
|
"Description",
|
|
40
38
|
/* @__PURE__ */ jsx("hr", { className: "my-2 border-[0.1px] border-gray-400" }),
|
|
41
|
-
gqlMeta.guards
|
|
39
|
+
gqlMeta.signalOption?.guards?.some((guard) => guard !== "None") ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 pb-3 pl-3 text-base font-normal", children: [
|
|
42
40
|
"- Guards:",
|
|
43
|
-
gqlMeta.guards.map((guard) => /* @__PURE__ */ jsx(
|
|
41
|
+
gqlMeta.signalOption.guards.map((guard) => /* @__PURE__ */ jsx(
|
|
44
42
|
"span",
|
|
45
43
|
{
|
|
46
44
|
className: `badge ${guard === "Public" ? "badge-success" : guard === "SuperAdmin" ? "badge-error" : guard === "Admin" ? "badge-error" : guard === "User" ? "badge-accent" : guard === "Owner" ? "badge-accent" : guard === "Every" ? "badge-warning" : ""}`,
|
|
@@ -51,7 +49,7 @@ const MessageEndpoint = ({ sigRef, gqlMeta, open }) => {
|
|
|
51
49
|
] }) : null,
|
|
52
50
|
/* @__PURE__ */ jsxs("div", { className: "pb-3 pl-3 text-base font-normal", children: [
|
|
53
51
|
"- ",
|
|
54
|
-
l.
|
|
52
|
+
l._(`${refName}.signal.${gqlKey}.desc`)
|
|
55
53
|
] })
|
|
56
54
|
] }),
|
|
57
55
|
/* @__PURE__ */ jsxs("div", { className: "my-4 flex w-full gap-5 px-5", children: [
|
|
@@ -82,69 +80,57 @@ const MessageEndpoint = ({ sigRef, gqlMeta, open }) => {
|
|
|
82
80
|
}
|
|
83
81
|
)
|
|
84
82
|
] }),
|
|
85
|
-
viewStatus === "doc" ? /* @__PURE__ */ jsx(
|
|
86
|
-
MessageInterface,
|
|
87
|
-
{
|
|
88
|
-
sigRef,
|
|
89
|
-
gqlMeta,
|
|
90
|
-
gqlArgMetas,
|
|
91
|
-
uploadArgMetas
|
|
92
|
-
}
|
|
93
|
-
) : /* @__PURE__ */ jsx(MessageTry, { sigRef, gqlMeta, gqlArgMetas, uploadArgMetas })
|
|
83
|
+
viewStatus === "doc" ? /* @__PURE__ */ jsx(MessageInterface, { refName, gqlKey, gqlMeta }) : /* @__PURE__ */ jsx(MessageTry, { gqlKey, gqlMeta })
|
|
94
84
|
] })
|
|
95
85
|
] });
|
|
96
86
|
};
|
|
97
87
|
Message.Endpoint = MessageEndpoint;
|
|
98
|
-
const MessageInterface = ({
|
|
99
|
-
const
|
|
100
|
-
const
|
|
88
|
+
const MessageInterface = ({ refName, gqlKey, gqlMeta }) => {
|
|
89
|
+
const returnRef = constantInfo.getModelRef(gqlMeta.returns.refName, gqlMeta.returns.modelType);
|
|
90
|
+
const uploadArgMetas = gqlMeta.args.filter((argMeta) => argMeta.type === "Upload");
|
|
91
|
+
const gqlArgMetas = gqlMeta.args.filter((argMeta) => argMeta.type !== "Upload");
|
|
101
92
|
const isReturnModelType = !isGqlScalar(returnRef);
|
|
102
93
|
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
103
94
|
uploadArgMetas.length ? /* @__PURE__ */ jsxs("div", { children: [
|
|
104
95
|
/* @__PURE__ */ jsx("div", { className: "text-lg", children: "Form data upload" }),
|
|
105
|
-
/* @__PURE__ */ jsx("div", { className: "bg-base-100 overflow-x-auto rounded-md p-3", children: /* @__PURE__ */ jsx(Arg.Table, {
|
|
96
|
+
/* @__PURE__ */ jsx("div", { className: "bg-base-100 overflow-x-auto rounded-md p-3", children: /* @__PURE__ */ jsx(Arg.Table, { refName, gqlKey, argMetas: uploadArgMetas }) })
|
|
106
97
|
] }) : null,
|
|
107
98
|
gqlArgMetas.length ? /* @__PURE__ */ jsxs("div", { children: [
|
|
108
99
|
/* @__PURE__ */ jsx("div", { className: "text-lg", children: "Variables" }),
|
|
109
|
-
/* @__PURE__ */ jsx("div", { className: "bg-base-100 overflow-x-auto rounded-md p-3", children: /* @__PURE__ */ jsx(Arg.Table, {
|
|
100
|
+
/* @__PURE__ */ jsx("div", { className: "bg-base-100 overflow-x-auto rounded-md p-3", children: /* @__PURE__ */ jsx(Arg.Table, { refName, gqlKey, argMetas: gqlArgMetas }) })
|
|
110
101
|
] }) : null,
|
|
111
102
|
/* @__PURE__ */ jsx("div", { className: "text-lg font-bold", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-col gap-2 rounded-md font-normal md:flex-row", children: [
|
|
112
103
|
/* @__PURE__ */ jsxs("div", { className: "w-full md:w-1/2", children: [
|
|
113
104
|
"Response Type",
|
|
114
105
|
/* @__PURE__ */ jsxs("div", { className: "bg-base-100 max-h-[500px] overflow-auto rounded-md p-4 md:h-[500px]", children: [
|
|
115
106
|
"Returns: ",
|
|
116
|
-
/* @__PURE__ */ jsx(Object.Type, { objRef: returnRef, arrDepth }),
|
|
107
|
+
/* @__PURE__ */ jsx(Object.Type, { objRef: returnRef, arrDepth: gqlMeta.returns.arrDepth }),
|
|
117
108
|
isReturnModelType ? /* @__PURE__ */ jsx(Object.Detail, { objRef: returnRef }) : null
|
|
118
109
|
] })
|
|
119
110
|
] }),
|
|
120
111
|
/* @__PURE__ */ jsxs("div", { className: "w-full md:w-1/2", children: [
|
|
121
112
|
"Response Example",
|
|
122
|
-
/* @__PURE__ */ jsx(Response.Example, {
|
|
113
|
+
/* @__PURE__ */ jsx(Response.Example, { gqlMeta })
|
|
123
114
|
] })
|
|
124
115
|
] }) })
|
|
125
116
|
] });
|
|
126
117
|
};
|
|
127
118
|
Message.Interface = MessageInterface;
|
|
128
|
-
const MessageTry = ({
|
|
129
|
-
const
|
|
130
|
-
const [modelRef, arrDepth] = getNonArrayModel(gqlMeta.returns());
|
|
131
|
-
const isScalar = isGqlScalar(modelRef);
|
|
132
|
-
const requestExample = useMemo(() => JSON.stringify(makeRequestExample(sigRef, gqlMeta.key), null, 2), []);
|
|
119
|
+
const MessageTry = ({ gqlKey, gqlMeta }) => {
|
|
120
|
+
const requestExample = useMemo(() => JSON.stringify(makeRequestExample(gqlMeta), null, 2), []);
|
|
133
121
|
const [gqlRequest, setGqlRequest] = useState(requestExample);
|
|
134
|
-
const [uploadRequest, setUploadRequest] = useState({});
|
|
135
122
|
const [stopListen, setStopListen] = useState(null);
|
|
136
123
|
const [messages, setMessages] = useState("");
|
|
137
124
|
const [response, setResponse] = useState({ status: "ready", data: "" });
|
|
138
125
|
const onSend = async () => {
|
|
139
|
-
const request =
|
|
140
|
-
const argData =
|
|
141
|
-
const fetchFn = fetch[
|
|
126
|
+
const request = JSON.parse(gqlRequest);
|
|
127
|
+
const argData = gqlMeta.args.map((argMeta) => request[argMeta.name]);
|
|
128
|
+
const fetchFn = fetch[gqlKey].bind(fetch);
|
|
142
129
|
await fetchFn(...argData);
|
|
143
130
|
};
|
|
144
131
|
const onListen = () => {
|
|
145
132
|
setResponse({ status: "loading", data: null });
|
|
146
|
-
const
|
|
147
|
-
const fetchFn = fetch[`listen${capitalize(gqlMeta.key)}`].bind(fetch);
|
|
133
|
+
const fetchFn = fetch[`listen${capitalize(gqlKey)}`].bind(fetch);
|
|
148
134
|
setResponse({ status: "loading", data: messages });
|
|
149
135
|
const stopListen2 = fetchFn((data) => {
|
|
150
136
|
setMessages(
|
|
@@ -171,20 +157,6 @@ ${data}` : typeof data === "object" ? [...prev && prev.length ? [...prev] : [],
|
|
|
171
157
|
};
|
|
172
158
|
}, [stopListen]);
|
|
173
159
|
return /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-col gap-4", children: [
|
|
174
|
-
uploadArgMetas.length ? /* @__PURE__ */ jsxs("div", { children: [
|
|
175
|
-
/* @__PURE__ */ jsx("div", { className: "text-lg", children: "Form data uplaod" }),
|
|
176
|
-
uploadArgMetas.map((argMeta) => /* @__PURE__ */ jsx(
|
|
177
|
-
Arg.FormData,
|
|
178
|
-
{
|
|
179
|
-
argMeta,
|
|
180
|
-
value: uploadRequest[argMeta.name],
|
|
181
|
-
onChange: (fileList) => {
|
|
182
|
-
setUploadRequest({ ...uploadRequest, [argMeta.name]: fileList });
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
argMeta.name
|
|
186
|
-
))
|
|
187
|
-
] }) : null,
|
|
188
160
|
/* @__PURE__ */ jsxs("div", { children: [
|
|
189
161
|
/* @__PURE__ */ jsx("div", { className: "grid gap-2 lg:grid-cols-2", children: /* @__PURE__ */ jsxs("div", { children: [
|
|
190
162
|
/* @__PURE__ */ jsx("div", { className: "text-lg", children: "Variables" }),
|