Skip to content

✨ Innovative and open-source visualization application that transforms various data formats, such as JSON, YAML, XML and CSV into interactive graphs.

feat: support more types

AykutSarac7f37df42de2e
diff --git a/next.config.js b/next.config.js
index 2fe158e3..afca1c61 100644
--- a/next.config.js
+++ b/next.config.js
@@ -15,6 +15,8 @@ const config = {
},
webpack: config => {
config.resolve.fallback = { fs: false };
+ config.output.webassemblyModuleFilename = "static/wasm/[modulehash].wasm";
+ config.experiments = { asyncWebAssembly: true };
return config;
},
diff --git a/package.json b/package.json
index ed5a9814..35097b70 100644
--- a/package.json
+++ b/package.json
@@ -32,7 +32,7 @@
"jq-web": "^0.5.1",
"js-yaml": "^4.1.0",
"json-2-csv": "^5.0.1",
- "json-to-ts": "^1.7.0",
+ "json_typegen_wasm": "^0.7.0",
"jsonc-parser": "^3.2.0",
"jsonwebtoken": "^9.0.2",
"jxon": "^2.0.0-beta.5",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 12c5fcf6..df104316 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -59,9 +59,9 @@ dependencies:
json-2-csv:
specifier: ^5.0.1
version: 5.0.1
- json-to-ts:
- specifier: ^1.7.0
- version: 1.7.0
+ json_typegen_wasm:
+ specifier: ^0.7.0
+ version: 0.7.0
jsonc-parser:
specifier: ^3.2.0
version: 3.2.0
@@ -1321,6 +1321,7 @@ packages:
es-abstract: 1.22.3
get-intrinsic: 1.2.2
is-string: 1.0.7
+ dev: true
resolution: {integrity: sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==}
@@ -1358,17 +1359,6 @@ packages:
es-shim-unscopables: 1.0.2
dev: true
- resolution: {integrity: sha512-UW+Mz8LG/sPSU8jRDCjVr6J/ZKAGpHfwrZ6kWTG5qCxIEiXdVshqGnu5vEZA8S1y6X4aCSbQZ0/EEsfvEvBiSg==}
- engines: {node: '>= 0.4'}
- dependencies:
- call-bind: 1.0.5
- define-properties: 1.2.1
- es-abstract: 1.22.3
- es-array-method-boxes-properly: 1.0.0
- is-string: 1.0.7
- dev: false
-
resolution: {integrity: sha512-HuQCHOlk1Weat5jzStICBCd83NxiIMwqDg/dHEsoefabn/hJRj5pVdWcPUSpRrwhwxZOsQassMpgN/xRYFBMIg==}
dependencies:
@@ -1909,10 +1899,6 @@ packages:
unbox-primitive: 1.0.2
which-typed-array: 1.1.13
- resolution: {integrity: sha512-wd6JXUmyHmt8T5a2xreUwKcGPq6f1f+WwIJkijUqiGcJz1qqnZgP6XIK+QyIWU5lT7imeNxUll48bziG+TSYcA==}
- dev: false
-
resolution: {integrity: sha512-GhoY8uYqd6iwUl2kgjTm4CZAf6oo5mHK7BPqx3rKgx893YSsy0LGHV6gfqqQvZt/8xM8xeOnfXBCfqclMKkJ5g==}
dependencies:
@@ -1954,21 +1940,6 @@ packages:
is-date-object: 1.0.5
is-symbol: 1.0.4
- resolution: {integrity: sha512-aiQ/QyJBVJbabtsSediM1S4qI+P3p8F5J5YR5o/bH003BCnnclzxK9pi5Qd2Hg01ktAtZCaQBdejHrkOBGwf5Q==}
- engines: {node: '>=0.4.0'}
- dependencies:
- array-includes: 3.1.7
- object.entries: 1.1.7
- object.getownpropertydescriptors: 2.1.7
- object.values: 1.1.7
- string-at: 1.1.0
- string.prototype.padend: 3.1.5
- string.prototype.padstart: 3.1.5
- string.prototype.trimleft: 2.1.3
- string.prototype.trimright: 2.1.3
- dev: false
-
resolution: {integrity: sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==}
engines: {node: '>=0.8.0'}
@@ -2676,13 +2647,6 @@ packages:
engines: {node: '>= 0.4.0'}
dev: false
- resolution: {integrity: sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA==}
- dependencies:
- inherits: 2.0.4
- minimalistic-assert: 1.0.1
- dev: false
-
resolution: {integrity: sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA==}
engines: {node: '>= 0.4'}
@@ -3055,14 +3019,6 @@ packages:
resolution: {integrity: sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==}
dev: true
- resolution: {integrity: sha512-uVhcw4SLnf9ucMwFpom/G1/IT+lnoILOyHbFE6xqxvw67oCvHl6iDZzmjyn2lPCRPsAOMSQgG/ZxvbCPySMi1Q==}
- dependencies:
- es7-shim: 6.0.0
- hash.js: 1.1.7
- pluralize: 3.1.0
- dev: false
-
resolution: {integrity: sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==}
hasBin: true
@@ -3070,6 +3026,10 @@ packages:
minimist: 1.2.8
dev: true
+ resolution: {integrity: sha512-xTDD7jlMpXB8S/6lD00aqOmHPuVszG4vtrJTaED8Mb6ziryGtXmtkREWpuvJbWWj45aVFGO3O/WjwxRBLw8dUQ==}
+ dev: false
+
resolution: {integrity: sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==}
dev: false
@@ -3336,10 +3296,6 @@ packages:
engines: {node: '>=12'}
dev: true
- resolution: {integrity: sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==}
- dev: false
-
resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==}
dependencies:
@@ -3521,6 +3477,7 @@ packages:
call-bind: 1.0.5
define-properties: 1.2.1
es-abstract: 1.22.3
+ dev: true
resolution: {integrity: sha512-UPbPHML6sL8PI/mOqPwsH4G6iyXcCGzLin8KvEPenOZN5lpCNBZZQ+V62vdjB1mQHrmqGQt5/OJzemUA+KJmEA==}
@@ -3531,17 +3488,6 @@ packages:
es-abstract: 1.22.3
dev: true
- resolution: {integrity: sha512-PrJz0C2xJ58FNn11XV2lr4Jt5Gzl94qpy9Lu0JlfEj14z88sqbSBJCBEzdlNUCzY2gburhbrwOZ5BHCmuNUy0g==}
- engines: {node: '>= 0.8'}
- dependencies:
- array.prototype.reduce: 1.0.6
- call-bind: 1.0.5
- define-properties: 1.2.1
- es-abstract: 1.22.3
- safe-array-concat: 1.0.1
- dev: false
-
resolution: {integrity: sha512-HqaQtqLnp/8Bn4GL16cj+CUYbnpe1bh0TtEaWvybszDG4tgxCJuRpV8VGuvNaI1fAnI4lUJzDG55MXcOH4JZcQ==}
dependencies:
@@ -3565,6 +3511,7 @@ packages:
call-bind: 1.0.5
define-properties: 1.2.1
es-abstract: 1.22.3
+ dev: true
resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==}
@@ -3719,10 +3666,6 @@ packages:
engines: {node: '>=0.10.0'}
dev: false
- resolution: {integrity: sha512-2wcybwjwXOzGI1rlxWtlcs0/nSYK0OzNPqsg35TKxJFQlGhFu3cZ1x7EHS4r4bubQlhzyF4YxxlJqQnIhkUQCw==}
- dev: false
-
resolution: {integrity: sha512-Wb4p1J4zyFTbM+u6WuO4XstYx4Ky9Cewe4DWrel7B0w6VVICvPwdOpotjzcf6eD8TsckVnIMNONQyPIUFOUbCQ==}
deprecated: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1
@@ -4304,15 +4247,6 @@ packages:
engines: {node: '>=10.0.0'}
dev: false
- resolution: {integrity: sha512-jCpPowWKBn0NFdvtmK2qxK40Ol4jPcgCt8qYnKpPx6B5eDwHMDhRvq9MCsDEgsOTNtbXY6beAMHMRT2qPJXllA==}
- engines: {node: '>= 0.4'}
- deprecated: The original `String.prototype.at` proposal has been replaced by a new one; please use v1 or later of `string.prototype.at` instead
- dependencies:
- define-properties: 1.2.1
- es-abstract: 1.22.3
- dev: false
-
resolution: {integrity: sha512-0XsVpQLnVCXHJfyEs8tC0zpTVIr5PKKsQtkT29IwupnPTjtPmQ3xT/4yCREF9hYkV/3M3kzcUTSAZT6a6h81tw==}
engines: {node: '>=0.10.0'}
@@ -4336,24 +4270,6 @@ packages:
side-channel: 1.0.4
dev: true
- resolution: {integrity: sha512-DOB27b/2UTTD+4myKUFh+/fXWcu/UDyASIXfg+7VzoCNNGOfWvoyU/x5pvVHr++ztyt/oSYI1BcWBBG/hmlNjA==}
- engines: {node: '>= 0.4'}
- dependencies:
- call-bind: 1.0.5
- define-properties: 1.2.1
- es-abstract: 1.22.3
- dev: false
-
- resolution: {integrity: sha512-R57IsE3JIfModQWrVXYZ8ZHWMBNDpIoniDwhYCR1nx+iHwDkjjk26a8xM9BYgf7SAXJO7sdNPng5J+0ccr5LFQ==}
- engines: {node: '>= 0.4'}
- dependencies:
- call-bind: 1.0.5
- define-properties: 1.2.1
- es-abstract: 1.22.3
- dev: false
-
resolution: {integrity: sha512-lfjY4HcixfQXOfaqCvcBuOIapyaroTXhbkfJN3gcB1OtyupngWK4sEET9Knd0cXd28kTUqu/kHoV4HKSJdnjiQ==}
engines: {node: '>= 0.4'}
@@ -4369,24 +4285,6 @@ packages:
define-properties: 1.2.1
es-abstract: 1.22.3
- resolution: {integrity: sha512-699Ibssmj/awVzvdNk4g83/Iu8U9vDohzmA/ly2BrQWGhamuY4Tlvs5XKmKliDt3ky6SKbE1bzPhASKCFlx9Sg==}
- engines: {node: '>= 0.4'}
- dependencies:
- call-bind: 1.0.5
- define-properties: 1.2.1
- string.prototype.trimstart: 1.0.7
- dev: false
-
- resolution: {integrity: sha512-hoOq56oRFnnfDuXNy2lGHiwT77MehHv9d0zGfRZ8QdC+4zjrkFB9vd5i/zYTd/ymFBd4YxtbdgHt3U6ksGeuBw==}
- engines: {node: '>= 0.4'}
- dependencies:
- call-bind: 1.0.5
- define-properties: 1.2.1
- string.prototype.trimend: 1.0.7
- dev: false
-
resolution: {integrity: sha512-NGhtDFu3jCEm7B4Fy0DpLewdJQOZcQ0rGbwQ/+stjnrp2i+rlKeCvos9hOIeCmqwratM47OBxY7uFZzjxHXmrg==}
dependencies:
diff --git a/src/components/PromptInput/index.tsx b/src/components/PromptInput/index.tsx
index d16bdeb8..c9147d3d 100644
--- a/src/components/PromptInput/index.tsx
+++ b/src/components/PromptInput/index.tsx
@@ -9,12 +9,6 @@ import useJsonQuery from "src/hooks/useJsonQuery";
import { supabase } from "src/lib/api/supabase";
import useUser from "src/store/useUser";
-function removeWhitespaces(inputString: string) {
- // Remove extra whitespaces and newlines
- const compactString = inputString.replace(/\s+/g, "").replaceAll("interface", "interface ");
- return compactString;
-}
-
const StyledPromptInput = styled(TextInput)`
.mantine-Input-input {
font-weight: 500;
@@ -47,12 +41,10 @@ export const PromptInput = () => {
const onSubmit = async () => {
try {
setCompleting(true);
+ const jsonModel = await getJsonType();
const resp = await supabase.functions.invoke("jq", {
- body: {
- query: prompt,
- jsonModel: removeWhitespaces(getJsonType()),
- },
+ body: { query: prompt, jsonModel },
});
// extract jq command
diff --git a/src/containers/Modals/JQModal/index.tsx b/src/containers/Modals/JQModal/index.tsx
index f0459d5d..66603823 100644
--- a/src/containers/Modals/JQModal/index.tsx
+++ b/src/containers/Modals/JQModal/index.tsx
@@ -17,10 +17,6 @@ export const JQModal: React.FC<ModalProps> = ({ opened, onClose }) => {
const { updateJson } = useJsonQuery();
const [query, setQuery] = React.useState("");
- const onApply = () => {
- updateJson(query);
- };
-
return (
<Modal title="JSON Query" size="lg" opened={opened} onClose={onClose} centered>
<Stack py="sm">
@@ -40,7 +36,7 @@ export const JQModal: React.FC<ModalProps> = ({ opened, onClose }) => {
/>
<Divider my="xs" />
<Group justify="right">
- <Button onClick={onApply}>Display on Graph</Button>
+ <Button onClick={() => updateJson(query, onClose)}>Display on Graph</Button>
</Group>
</Stack>
</Modal>
diff --git a/src/containers/Modals/TypeModal/index.tsx b/src/containers/Modals/TypeModal/index.tsx
index 421e096d..8f055533 100644
--- a/src/containers/Modals/TypeModal/index.tsx
+++ b/src/containers/Modals/TypeModal/index.tsx
@@ -5,17 +5,43 @@ import useJson from "src/store/useJson";
enum Language {
TypeScript = "typescript",
+ TypeScript_Combined = "typescript/typealias",
Go = "go",
+ JSON_SCHEMA = "json_schema",
+ Kotlin = "kotlin",
+ Rust = "rust",
}
const typeOptions = [
{
label: "TypeScript",
value: Language.TypeScript,
+ lang: "typescript",
+ },
+ {
+ label: "TypeScript (combined)",
+ value: Language.TypeScript_Combined,
+ lang: "typescript",
},
{
label: "Go",
value: Language.Go,
+ lang: "go",
+ },
+ {
+ label: "JSON Schema",
+ value: Language.JSON_SCHEMA,
+ lang: "json",
+ },
+ {
+ label: "Kotlin",
+ value: Language.Kotlin,
+ lang: "kotlin",
+ },
+ {
+ label: "Rust",
+ value: Language.Rust,
+ lang: "rust",
},
];
@@ -24,23 +50,38 @@ export const TypeModal: React.FC<ModalProps> = ({ opened, onClose }) => {
const [type, setType] = React.useState("");
const [selectedType, setSelectedType] = React.useState<Language>(Language.TypeScript);
+ const editorLanguage = React.useMemo(() => {
+ return typeOptions[typeOptions.findIndex(o => o.value === selectedType)]?.lang;
+ }, [selectedType]);
+
+ const transformer = React.useCallback(
+ async ({ value }) => {
+ const { run } = await import("json_typegen_wasm");
+ return run(
+ "Root",
+ value,
+ JSON.stringify({
+ output_mode: selectedType,
+ })
+ );
+ },
+ [selectedType]
+ );
+
React.useEffect(() => {
if (opened) {
- if (selectedType === Language.TypeScript) {
- import("json-to-ts").then(jts => {
- const types = jts.default(JSON.parse(getJson()));
- setType(types.flat().join("\n\n"));
- });
- } else if (selectedType === Language.Go) {
+ if (selectedType === Language.Go) {
import("src/lib/utils/json2go").then(jtg => {
import("gofmt.js").then(gofmt => {
const types = jtg.default(getJson());
setType(gofmt.default(types.go));
});
});
+ } else {
+ transformer({ value: getJson() }).then(setType);
}
}
- }, [getJson, opened, selectedType]);
+ }, [getJson, opened, selectedType, transformer]);
return (
<Modal title="Generate Types" size="auto" opened={opened} onClose={onClose} centered>
@@ -54,7 +95,7 @@ export const TypeModal: React.FC<ModalProps> = ({ opened, onClose }) => {
<CodeHighlight
miw={350}
mah={600}
- language={selectedType}
+ language={editorLanguage}
copyLabel="Copy to clipboard"
copiedLabel="Copied to clipboard"
code={type}
diff --git a/src/hooks/useJsonQuery.ts b/src/hooks/useJsonQuery.ts
index 01e5963b..dbebb31d 100644
--- a/src/hooks/useJsonQuery.ts
+++ b/src/hooks/useJsonQuery.ts
@@ -1,5 +1,4 @@
import jq from "jq-web";
-import jts from "json-to-ts";
import toast from "react-hot-toast";
import useFile from "src/store/useFile";
import useJson from "src/store/useJson";
@@ -8,19 +7,25 @@ const useJsonQuery = () => {
const getJson = useJson(state => state.getJson);
const setContents = useFile(state => state.setContents);
- const updateJson = (query: string) => {
+ const transformer = async ({ value }) => {
+ const { run } = await import("json_typegen_wasm");
+ return run("Root", value, JSON.stringify({ output_mode: "typescript/typealias" }));
+ };
+
+ const updateJson = (query: string, cb?: () => void) => {
try {
const res = jq.json(JSON.parse(getJson()), query);
setContents({ contents: JSON.stringify(res, null, 2) });
+ cb?.();
} catch (error) {
console.error(error);
toast.error("Unable to process the request.");
}
};
- const getJsonType = () => {
- const types = jts(JSON.parse(getJson()));
- return types.flat().join("\n\n");
+ const getJsonType = async () => {
+ const types = await transformer({ value: getJson() });
+ return types;
};
return { updateJson, getJsonType };