@nesso-how/formats 0.1.0-alpha.20 → 0.1.0-alpha.22

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/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # @nesso-how/formats
2
+
3
+ JSON serialize/deserialize for [Nesso](https://nesso.how) graph files.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @nesso-how/formats
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { serializeGraph, deserializeGraph } from "@nesso-how/formats";
15
+
16
+ const json = serializeGraph({ name: "My graph", nodes, edges });
17
+ const file = deserializeGraph(json);
18
+ ```
19
+
20
+ ## License
21
+
22
+ MIT
package/dist/index.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import type { Node, Edge } from '@xyflow/react';
2
2
  import type { ConceptNodeData, GraphDisplaySettings } from '@nesso-how/types';
3
3
  export interface NessoGraphFile {
4
+ /** Internal graph id (desktop sync); omitted in manual exports. */
5
+ id?: string;
6
+ /** Last save time (Unix ms); desktop sync metadata. */
7
+ updatedAt?: number;
4
8
  name: string;
5
9
  nodes: Node<ConceptNodeData>[];
6
10
  edges: Edge[];
@@ -8,3 +12,7 @@ export interface NessoGraphFile {
8
12
  }
9
13
  export declare function serializeGraph(file: NessoGraphFile): string;
10
14
  export declare function deserializeGraph(json: string): NessoGraphFile;
15
+ /** Strip personal FSRS / review history for shareable graph export. Keeps text, elaboration, layout. */
16
+ export declare function nodesForGraphShareExport(nodes: Node<ConceptNodeData>[]): Node<ConceptNodeData>[];
17
+ /** Reset review fields on import so shared files never restore someone else's scheduling. */
18
+ export declare function nodesFromGraphShareImport(nodes: Node<ConceptNodeData>[]): Node<ConceptNodeData>[];
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { defaultConceptReviewFields } from '@nesso-how/types';
1
2
  export function serializeGraph(file) {
2
3
  return JSON.stringify(file, null, 2);
3
4
  }
@@ -11,3 +12,22 @@ export function deserializeGraph(json) {
11
12
  }
12
13
  return data;
13
14
  }
15
+ /** Strip personal FSRS / review history for shareable graph export. Keeps text, elaboration, layout. */
16
+ export function nodesForGraphShareExport(nodes) {
17
+ const review = defaultConceptReviewFields();
18
+ return nodes.map(node => {
19
+ const { text, elaboration } = node.data ?? { text: '' };
20
+ return {
21
+ ...node,
22
+ data: {
23
+ text: text ?? '',
24
+ ...(elaboration ? { elaboration } : {}),
25
+ ...review,
26
+ },
27
+ };
28
+ });
29
+ }
30
+ /** Reset review fields on import so shared files never restore someone else's scheduling. */
31
+ export function nodesFromGraphShareImport(nodes) {
32
+ return nodesForGraphShareExport(nodes);
33
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nesso-how/formats",
3
- "version": "0.1.0-alpha.20",
3
+ "version": "0.1.0-alpha.22",
4
4
  "description": "Nesso graph serialization formats — JSON serialize/deserialize",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@xyflow/react": "^12.6.4",
18
- "@nesso-how/types": "0.1.0-alpha.20"
18
+ "@nesso-how/types": "0.1.0-alpha.22"
19
19
  },
20
20
  "devDependencies": {
21
21
  "typescript": "~5.8.3"
package/src/index.ts CHANGED
@@ -1,8 +1,13 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  import type { Node, Edge } from '@xyflow/react'
3
3
  import type { ConceptNodeData, GraphDisplaySettings } from '@nesso-how/types'
4
+ import { defaultConceptReviewFields } from '@nesso-how/types'
4
5
 
5
6
  export interface NessoGraphFile {
7
+ /** Internal graph id (desktop sync); omitted in manual exports. */
8
+ id?: string
9
+ /** Last save time (Unix ms); desktop sync metadata. */
10
+ updatedAt?: number
6
11
  name: string
7
12
  nodes: Node<ConceptNodeData>[]
8
13
  edges: Edge[]
@@ -25,3 +30,28 @@ export function deserializeGraph(json: string): NessoGraphFile {
25
30
  }
26
31
  return data as NessoGraphFile
27
32
  }
33
+
34
+ /** Strip personal FSRS / review history for shareable graph export. Keeps text, elaboration, layout. */
35
+ export function nodesForGraphShareExport(
36
+ nodes: Node<ConceptNodeData>[],
37
+ ): Node<ConceptNodeData>[] {
38
+ const review = defaultConceptReviewFields()
39
+ return nodes.map(node => {
40
+ const { text, elaboration } = node.data ?? { text: '' }
41
+ return {
42
+ ...node,
43
+ data: {
44
+ text: text ?? '',
45
+ ...(elaboration ? { elaboration } : {}),
46
+ ...review,
47
+ },
48
+ }
49
+ })
50
+ }
51
+
52
+ /** Reset review fields on import so shared files never restore someone else's scheduling. */
53
+ export function nodesFromGraphShareImport(
54
+ nodes: Node<ConceptNodeData>[],
55
+ ): Node<ConceptNodeData>[] {
56
+ return nodesForGraphShareExport(nodes)
57
+ }