From 813acb93dc3e0f77d078f98e5c8c35fcf4289d05 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Wed, 13 Dec 2023 17:30:43 +0100 Subject: [PATCH 1/7] feat: replace `JSONValue` with `unknown` --- .../components/controls/JSONPreview.svelte | 4 +- .../navigationBar/NavigationBar.svelte | 10 +-- src/lib/components/modals/SortModal.svelte | 4 +- .../components/modals/TransformModal.svelte | 7 +- .../components/modals/TransformWizard.svelte | 4 +- .../modes/tablemode/JSONValue.svelte | 3 +- .../modes/tablemode/TableMode.svelte | 21 +++--- .../modes/tablemode/TableModeWelcome.svelte | 4 +- .../contextmenu/TableContextMenu.svelte | 3 +- .../modes/tablemode/menu/TableMenu.svelte | 4 +- .../components/modes/treemode/JSONNode.svelte | 18 ++--- .../modes/treemode/JSONValue.svelte | 4 +- .../components/modes/treemode/TreeMode.svelte | 27 ++++---- .../contextmenu/TreeContextMenu.svelte | 3 +- .../modes/treemode/menu/TreeMenu.svelte | 4 +- src/lib/logic/actions.ts | 40 ++++++----- src/lib/logic/documentState.test.ts | 61 ++++++++--------- src/lib/logic/documentState.ts | 50 +++++++------- src/lib/logic/dragging.ts | 5 +- src/lib/logic/operations.ts | 67 +++++++------------ src/lib/logic/search.ts | 24 +++---- src/lib/logic/selection.test.ts | 9 +-- src/lib/logic/selection.ts | 39 ++++++----- src/lib/logic/sort.ts | 15 ++--- src/lib/logic/table.test.ts | 10 +-- src/lib/logic/table.ts | 24 +++---- src/lib/logic/validation.test.ts | 20 +++--- src/lib/logic/validation.ts | 3 +- .../query/javascriptQueryLanguage.test.ts | 5 +- .../plugins/query/javascriptQueryLanguage.ts | 6 +- .../query/jmespathQueryLanguage.test.ts | 6 +- .../plugins/query/jmespathQueryLanguage.ts | 6 +- .../plugins/query/lodashQueryLanguage.test.ts | 14 ++-- src/lib/plugins/query/lodashQueryLanguage.ts | 6 +- .../plugins/validator/createAjvValidator.ts | 12 +--- .../value/components/BooleanToggle.svelte | 4 +- .../value/components/EditableValue.svelte | 7 +- .../plugins/value/components/EnumValue.svelte | 10 +-- .../value/components/ReadonlyValue.svelte | 3 +- src/lib/types.ts | 63 +++++++---------- src/lib/utils/arrayUtils.ts | 13 ++-- src/lib/utils/jsonUtils.test.ts | 2 +- src/lib/utils/jsonUtils.ts | 10 ++- src/lib/utils/localStorageUtils.ts | 7 +- src/lib/utils/objectUtils.test.ts | 5 +- src/lib/utils/objectUtils.ts | 7 +- src/lib/utils/typeUtils.ts | 4 +- 47 files changed, 298 insertions(+), 379 deletions(-) diff --git a/src/lib/components/controls/JSONPreview.svelte b/src/lib/components/controls/JSONPreview.svelte index f65516ad..55a20437 100644 --- a/src/lib/components/controls/JSONPreview.svelte +++ b/src/lib/components/controls/JSONPreview.svelte @@ -1,11 +1,11 @@ diff --git a/src/lib/types.ts b/src/lib/types.ts index 7bd4780c..12a4eb91 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -244,16 +244,16 @@ export interface QueryLanguage { export interface QueryLanguageOptions { filter?: { - path?: string[] + path?: JSONPath relation?: '==' | '!=' | '<' | '<=' | '>' | '>=' value?: string } sort?: { - path?: string[] + path?: JSONPath direction?: 'asc' | 'desc' } projection?: { - paths?: string[][] + paths?: JSONPath[] } } From 217d6d5f286af334d2dfe7296e81b0fc56412d6b Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Thu, 14 Dec 2023 10:38:45 +0100 Subject: [PATCH 6/7] fix: refine the `JSONParser` type definition --- package-lock.json | 8 ++--- package.json | 2 +- src/lib/components/JSONEditor.svelte | 3 +- .../components/modals/TransformWizard.svelte | 8 ++--- .../modes/tablemode/tag/InlineValue.svelte | 6 ++-- .../modes/textmode/StatusBar.svelte | 8 ++--- .../components/modes/treemode/TreeMode.svelte | 30 +++++++++++-------- src/lib/logic/actions.ts | 2 +- src/lib/logic/operations.ts | 2 +- src/lib/logic/selection.ts | 6 ++-- src/lib/logic/validation.test.ts | 4 +-- src/lib/logic/validation.ts | 3 +- .../query/jmespathQueryLanguage.test.ts | 3 +- .../plugins/query/jmespathQueryLanguage.ts | 8 ++++- .../plugins/query/lodashQueryLanguage.test.ts | 3 +- src/lib/types.ts | 23 ++++++++++++-- src/lib/utils/jsonUtils.test.ts | 13 ++++---- src/lib/utils/jsonUtils.ts | 6 ++-- src/routes/development/+page.svelte | 14 ++++----- 19 files changed, 87 insertions(+), 65 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9d1bcde2..ad68cf84 100644 --- a/package-lock.json +++ b/package-lock.json @@ -69,7 +69,7 @@ "eslint-plugin-svelte": "2.35.1", "husky": "8.0.3", "jsdom": "23.0.1", - "lossless-json": "3.0.2", + "lossless-json": "4.0.1", "npm-run-all": "4.1.5", "prettier": "3.1.0", "prettier-plugin-svelte": "3.1.2", @@ -10681,9 +10681,9 @@ "dev": true }, "node_modules/lossless-json": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/lossless-json/-/lossless-json-3.0.2.tgz", - "integrity": "sha512-IbNz6s05hNuQjIC3DL15ahu3S5V7AQAjMnjNGfucqW+r17XQN6CwmAwU2LU2KAJkfaVu/4A7gmlCMrq/ch4wug==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lossless-json/-/lossless-json-4.0.1.tgz", + "integrity": "sha512-l0L+ppmgPDnb+JGxNLndPtJZGNf6+ZmVaQzoxQm3u6TXmhdnsA+YtdVR8DjzZd/em58686CQhOFDPewfJ4l7MA==", "dev": true }, "node_modules/loupe": { diff --git a/package.json b/package.json index 42ad4925..1cfac923 100644 --- a/package.json +++ b/package.json @@ -130,7 +130,7 @@ "eslint-plugin-svelte": "2.35.1", "husky": "8.0.3", "jsdom": "23.0.1", - "lossless-json": "3.0.2", + "lossless-json": "4.0.1", "npm-run-all": "4.1.5", "prettier": "3.1.0", "prettier-plugin-svelte": "3.1.2", diff --git a/src/lib/components/JSONEditor.svelte b/src/lib/components/JSONEditor.svelte index 090aa4f0..0f7063fe 100644 --- a/src/lib/components/JSONEditor.svelte +++ b/src/lib/components/JSONEditor.svelte @@ -132,8 +132,9 @@ debug('parser changed, recreate editor') if (isJSONContent(content)) { + const text = previousParser.stringify(content.json) content = { - json: parser.parse(previousParser.stringify(content.json)) + json: text !== undefined ? parser.parse(text) : undefined } } diff --git a/src/lib/components/modals/TransformWizard.svelte b/src/lib/components/modals/TransformWizard.svelte index 71b340ec..597f8403 100644 --- a/src/lib/components/modals/TransformWizard.svelte +++ b/src/lib/components/modals/TransformWizard.svelte @@ -46,9 +46,9 @@ $: projectionPaths = queryOptions?.projection?.paths && projectionOptions - ? queryOptions.projection.paths + ? (queryOptions.projection.paths .map((path) => projectionOptions.find((option) => isEqual(option.value, path))) - .filter((option) => !!option) as PathOption[] + .filter((option) => !!option) as PathOption[]) : null function changeFilterPath(path: JSONPath | undefined) { @@ -100,9 +100,9 @@ } $: changeFilterPath(filterPath?.value) - $: changeFilterRelation(filterRelation?.value ) + $: changeFilterRelation(filterRelation?.value) $: changeFilterValue(filterValue) - $: changeSortPath(sortPath?.value ) + $: changeSortPath(sortPath?.value) $: changeSortDirection(sortDirection?.value) $: changeProjectionPaths(projectionPaths ? projectionPaths.map((item) => item.value) : undefined) diff --git a/src/lib/components/modes/tablemode/tag/InlineValue.svelte b/src/lib/components/modes/tablemode/tag/InlineValue.svelte index 7fce5c36..c19c7b1f 100644 --- a/src/lib/components/modes/tablemode/tag/InlineValue.svelte +++ b/src/lib/components/modes/tablemode/tag/InlineValue.svelte @@ -1,13 +1,13 @@