@nesso-how/formats 0.1.0-alpha.19

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.
@@ -0,0 +1,10 @@
1
+ import type { Node, Edge } from '@xyflow/react';
2
+ import type { ConceptNodeData, GraphDisplaySettings } from '@nesso-how/types';
3
+ export interface NessoGraphFile {
4
+ name: string;
5
+ nodes: Node<ConceptNodeData>[];
6
+ edges: Edge[];
7
+ display?: Partial<GraphDisplaySettings>;
8
+ }
9
+ export declare function serializeGraph(file: NessoGraphFile): string;
10
+ export declare function deserializeGraph(json: string): NessoGraphFile;
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ export function serializeGraph(file) {
2
+ return JSON.stringify(file, null, 2);
3
+ }
4
+ export function deserializeGraph(json) {
5
+ const data = JSON.parse(json);
6
+ if (typeof data !== 'object' ||
7
+ data === null ||
8
+ !Array.isArray(data.nodes) ||
9
+ !Array.isArray(data.edges)) {
10
+ throw new Error('Invalid Nesso graph file: missing nodes or edges array');
11
+ }
12
+ return data;
13
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@nesso-how/formats",
3
+ "version": "0.1.0-alpha.19",
4
+ "description": "Nesso graph serialization formats — JSON serialize/deserialize",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ }
15
+ },
16
+ "scripts": {
17
+ "build": "tsc",
18
+ "prepublishOnly": "pnpm build",
19
+ "dev": "tsc --watch"
20
+ },
21
+ "dependencies": {
22
+ "@nesso-how/types": "workspace:*",
23
+ "@xyflow/react": "^12.6.4"
24
+ },
25
+ "devDependencies": {
26
+ "typescript": "~5.8.3"
27
+ }
28
+ }
package/src/index.ts ADDED
@@ -0,0 +1,27 @@
1
+ // SPDX-License-Identifier: MIT
2
+ import type { Node, Edge } from '@xyflow/react'
3
+ import type { ConceptNodeData, GraphDisplaySettings } from '@nesso-how/types'
4
+
5
+ export interface NessoGraphFile {
6
+ name: string
7
+ nodes: Node<ConceptNodeData>[]
8
+ edges: Edge[]
9
+ display?: Partial<GraphDisplaySettings>
10
+ }
11
+
12
+ export function serializeGraph(file: NessoGraphFile): string {
13
+ return JSON.stringify(file, null, 2)
14
+ }
15
+
16
+ export function deserializeGraph(json: string): NessoGraphFile {
17
+ const data: unknown = JSON.parse(json)
18
+ if (
19
+ typeof data !== 'object' ||
20
+ data === null ||
21
+ !Array.isArray((data as Record<string, unknown>).nodes) ||
22
+ !Array.isArray((data as Record<string, unknown>).edges)
23
+ ) {
24
+ throw new Error('Invalid Nesso graph file: missing nodes or edges array')
25
+ }
26
+ return data as NessoGraphFile
27
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "outDir": "dist",
7
+ "rootDir": "src",
8
+ "strict": true,
9
+ "declaration": true,
10
+ "skipLibCheck": true
11
+ },
12
+ "include": ["src"]
13
+ }