@ibgib/core-gib 0.0.107 → 0.0.108

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.
@@ -1,16 +1,34 @@
1
1
  import { FlatIbGibGraph } from "./graph-types.mjs";
2
+ export declare function serializeGraphToString(graph: FlatIbGibGraph): Promise<string>;
3
+ /**
4
+ * Takes an incoming jsonString created via {@link serializeGraphToString}
5
+ * and returns the original FlatIbGibGraph dto.
6
+ *
7
+ * @param jsonString
8
+ * @returns graph that was originally serialized
9
+ *
10
+ * ## notes
11
+ *
12
+ * This serialize/deserialize is used in the compress/decompress fns:
13
+ *
14
+ * @see {@link compressIbGibToBlob}
15
+ * @see {@link decompressIbGibFromBlob}
16
+ * @see {@link compressIbGibGraphToString}
17
+ * @see {@link decompressIbGibGraphFromString}
18
+ */
19
+ export declare function deserializeStringToGraph(jsonString: string): Promise<FlatIbGibGraph>;
2
20
  /**
3
21
  * Compresses an FlatIbGibGraph object into a Blob.
4
22
  * @param graph The FlatIbGibGraph object to compress.
5
23
  * @returns A Promise that resolves with the compressed Blob.
6
24
  */
7
- export declare function compressIbGib(graph: FlatIbGibGraph): Promise<Blob>;
25
+ export declare function compressIbGibToBlob(graph: FlatIbGibGraph): Promise<Blob>;
8
26
  /**
9
27
  * Decompresses a Blob back into an FlatIbGibGraph object.
10
28
  * @param compressedBlob The Blob containing the compressed graph data.
11
29
  * @returns A Promise that resolves with the original FlatIbGibGraph object.
12
30
  */
13
- export declare function decompressIbGib(compressedBlob: Blob): Promise<FlatIbGibGraph>;
31
+ export declare function decompressIbGibFromBlob(compressedBlob: Blob): Promise<FlatIbGibGraph>;
14
32
  /**
15
33
  * Compresses an FlatIbGibGraph object and returns a Base64 string representation.
16
34
  * @param graph The FlatIbGibGraph object to compress.
@@ -1 +1 @@
1
- {"version":3,"file":"other-helper.web.d.mts","sourceRoot":"","sources":["../../../src/common/other/other-helper.web.mts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAyCnD;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAmCxE;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,cAAc,EAAE,IAAI,GAAG,OAAO,CAAC,cAAc,CAAC,CA8BnF;AAED;;;;GAIG;AACH,wBAAsB,0BAA0B,CAAC,EAC7C,KAAK,EACR,EAAE;IACC,KAAK,EAAE,cAAc,CAAA;CACxB,GAAG,OAAO,CAAC,MAAM,CAAC,CAoBlB;AAED;;;;GAIG;AACH,wBAAsB,8BAA8B,CAAC,EACjD,gBAAgB,GACnB,EAAE;IACC,gBAAgB,EAAE,MAAM,CAAC;CAC5B,GAAG,OAAO,CAAC,cAAc,CAAC,CAoB1B"}
1
+ {"version":3,"file":"other-helper.web.d.mts","sourceRoot":"","sources":["../../../src/common/other/other-helper.web.mts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAyCnD,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAuCnF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CA+B1F;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAuB9E;AAED;;;;GAIG;AACH,wBAAsB,uBAAuB,CAAC,cAAc,EAAE,IAAI,GAAG,OAAO,CAAC,cAAc,CAAC,CAY3F;AAED;;;;GAIG;AACH,wBAAsB,0BAA0B,CAAC,EAC7C,KAAK,EACR,EAAE;IACC,KAAK,EAAE,cAAc,CAAA;CACxB,GAAG,OAAO,CAAC,MAAM,CAAC,CAoBlB;AAED;;;;GAIG;AACH,wBAAsB,8BAA8B,CAAC,EACjD,gBAAgB,GACnB,EAAE;IACC,gBAAgB,EAAE,MAAM,CAAC;CAC5B,GAAG,OAAO,CAAC,cAAc,CAAC,CAoB1B"}
@@ -35,69 +35,142 @@ async function base64ToUint8Array(base64String) {
35
35
  const buffer = await blob.arrayBuffer();
36
36
  return new Uint8Array(buffer);
37
37
  }
38
+ export async function serializeGraphToString(graph) {
39
+ const lc = `[${serializeGraphToString.name}]`;
40
+ try {
41
+ if (logalot) {
42
+ console.log(`${lc} starting... (I: 4ddb8803cf68e1d3d35f60680cb69825)`);
43
+ }
44
+ // 1. Serialize: Create a JSON-safe representation of the graph
45
+ // We use a custom replacer to handle Uint8Array
46
+ // const replacer = (key: string, value: any) => {
47
+ // if (value instanceof Uint8Array) {
48
+ // // This part is async, so we can't use it directly in JSON.stringify.
49
+ // // We must pre-process the object first.
50
+ // throw new Error("Cannot use async replacer. Pre-process the object first.");
51
+ // }
52
+ // return value;
53
+ // };
54
+ // Pre-process the graph to handle async Base64 conversion
55
+ const serializableGraph = JSON.parse(JSON.stringify(graph)); // Deep clone to avoid mutation
56
+ for (const key in serializableGraph) {
57
+ if (graph[key].data instanceof Uint8Array) {
58
+ serializableGraph[key].data = {
59
+ _dataType: 'Uint8Array_Base64',
60
+ value: await uint8ArrayToBase64(graph[key].data)
61
+ };
62
+ }
63
+ }
64
+ // 2. Stringify: Convert the serializable object to a JSON string
65
+ const jsonString = JSON.stringify(serializableGraph);
66
+ if (logalot) {
67
+ console.log(`${lc} jsonString.length: ${jsonString.length} (I: 56dec8ad0931ab8ba9b5ca3d4e66be25)`);
68
+ }
69
+ return jsonString;
70
+ }
71
+ catch (error) {
72
+ console.error(`${lc} ${extractErrorMsg(error)}`);
73
+ throw error;
74
+ }
75
+ finally {
76
+ if (logalot) {
77
+ console.log(`${lc} complete.`);
78
+ }
79
+ }
80
+ }
81
+ /**
82
+ * Takes an incoming jsonString created via {@link serializeGraphToString}
83
+ * and returns the original FlatIbGibGraph dto.
84
+ *
85
+ * @param jsonString
86
+ * @returns graph that was originally serialized
87
+ *
88
+ * ## notes
89
+ *
90
+ * This serialize/deserialize is used in the compress/decompress fns:
91
+ *
92
+ * @see {@link compressIbGibToBlob}
93
+ * @see {@link decompressIbGibFromBlob}
94
+ * @see {@link compressIbGibGraphToString}
95
+ * @see {@link decompressIbGibGraphFromString}
96
+ */
97
+ export async function deserializeStringToGraph(jsonString) {
98
+ const lc = `[${deserializeStringToGraph.name}]`;
99
+ try {
100
+ if (logalot) {
101
+ console.log(`${lc} starting... (I: 52e1a1fb1adcc75168fbc6d819868825)`);
102
+ }
103
+ const reviver = (key, value) => {
104
+ if (value && value._dataType === 'Uint8Array_Base64') {
105
+ // Converting base64 to Uint8Array is async, so we can't use it
106
+ // in JSON.parse. We will post-process the object.
107
+ return value; // Return the placeholder for now
108
+ }
109
+ return value;
110
+ };
111
+ const parsedGraph = JSON.parse(jsonString, reviver);
112
+ // Post-process to convert Base64 back to Uint8Array
113
+ for (const key in parsedGraph) {
114
+ const data = parsedGraph[key].data;
115
+ if (data && data._dataType === 'Uint8Array_Base64') {
116
+ parsedGraph[key].data = await base64ToUint8Array(data.value);
117
+ }
118
+ }
119
+ return parsedGraph;
120
+ }
121
+ catch (error) {
122
+ console.error(`${lc} ${extractErrorMsg(error)}`);
123
+ throw error;
124
+ }
125
+ finally {
126
+ if (logalot) {
127
+ console.log(`${lc} complete.`);
128
+ }
129
+ }
130
+ }
38
131
  /**
39
132
  * Compresses an FlatIbGibGraph object into a Blob.
40
133
  * @param graph The FlatIbGibGraph object to compress.
41
134
  * @returns A Promise that resolves with the compressed Blob.
42
135
  */
43
- export async function compressIbGib(graph) {
44
- // 1. Serialize: Create a JSON-safe representation of the graph
45
- // We use a custom replacer to handle Uint8Array
46
- // const replacer = (key: string, value: any) => {
47
- // if (value instanceof Uint8Array) {
48
- // // This part is async, so we can't use it directly in JSON.stringify.
49
- // // We must pre-process the object first.
50
- // throw new Error("Cannot use async replacer. Pre-process the object first.");
51
- // }
52
- // return value;
53
- // };
54
- // Pre-process the graph to handle async Base64 conversion
55
- const serializableGraph = JSON.parse(JSON.stringify(graph)); // Deep clone to avoid mutation
56
- for (const key in serializableGraph) {
57
- if (graph[key].data instanceof Uint8Array) {
58
- serializableGraph[key].data = {
59
- _dataType: 'Uint8Array_Base64',
60
- value: await uint8ArrayToBase64(graph[key].data)
61
- };
136
+ export async function compressIbGibToBlob(graph) {
137
+ const lc = `[${compressIbGibToBlob.name}]`;
138
+ try {
139
+ if (logalot) {
140
+ console.log(`${lc} starting... (I: 8d306868b718596fe8f562bd5118d825)`);
141
+ }
142
+ // 1. Serialize: Create a JSON-safe representation of the graph and stringify
143
+ const jsonString = await serializeGraphToString(graph);
144
+ // 2. Encode: Convert the string to a Uint8Array (UTF-8)
145
+ const dataToCompress = new TextEncoder().encode(jsonString);
146
+ // 3. Compress: Use the Compression Streams API
147
+ const stream = new Response(dataToCompress).body;
148
+ const compressedStream = stream.pipeThrough(new CompressionStream('gzip'));
149
+ // Return the compressed data as a Blob
150
+ return await new Response(compressedStream).blob();
151
+ }
152
+ catch (error) {
153
+ console.error(`${lc} ${extractErrorMsg(error)}`);
154
+ throw error;
155
+ }
156
+ finally {
157
+ if (logalot) {
158
+ console.log(`${lc} complete.`);
62
159
  }
63
160
  }
64
- // 2. Stringify: Convert the serializable object to a JSON string
65
- const jsonString = JSON.stringify(serializableGraph);
66
- // 3. Encode: Convert the string to a Uint8Array (UTF-8)
67
- const dataToCompress = new TextEncoder().encode(jsonString);
68
- // 4. Compress: Use the Compression Streams API
69
- const stream = new Response(dataToCompress).body;
70
- const compressedStream = stream.pipeThrough(new CompressionStream('gzip'));
71
- // Return the compressed data as a Blob
72
- return await new Response(compressedStream).blob();
73
161
  }
74
162
  /**
75
163
  * Decompresses a Blob back into an FlatIbGibGraph object.
76
164
  * @param compressedBlob The Blob containing the compressed graph data.
77
165
  * @returns A Promise that resolves with the original FlatIbGibGraph object.
78
166
  */
79
- export async function decompressIbGib(compressedBlob) {
167
+ export async function decompressIbGibFromBlob(compressedBlob) {
80
168
  // 1. Decompress: Use the Decompression Streams API
81
169
  const decompressedStream = compressedBlob.stream().pipeThrough(new DecompressionStream('gzip'));
82
170
  // 2. Decode: Convert the decompressed stream back to a string
83
171
  const jsonString = await new Response(decompressedStream).text();
84
172
  // 3. Deserialize: Parse the JSON with a reviver to restore Uint8Arrays
85
- const reviver = (key, value) => {
86
- if (value && value._dataType === 'Uint8Array_Base64') {
87
- // This part is async, so we can't use it in JSON.parse.
88
- // We must post-process the object.
89
- return value; // Return the placeholder for now
90
- }
91
- return value;
92
- };
93
- const parsedGraph = JSON.parse(jsonString, reviver);
94
- // Post-process to convert Base64 back to Uint8Array
95
- for (const key in parsedGraph) {
96
- const data = parsedGraph[key].data;
97
- if (data && data._dataType === 'Uint8Array_Base64') {
98
- parsedGraph[key].data = await base64ToUint8Array(data.value);
99
- }
100
- }
173
+ const parsedGraph = await deserializeStringToGraph(jsonString);
101
174
  return parsedGraph;
102
175
  }
103
176
  /**
@@ -112,7 +185,7 @@ export async function compressIbGibGraphToString({ graph }) {
112
185
  console.log(`${lc} starting... (I: 1352f8540c08f0b725952df8f18c4825)`);
113
186
  }
114
187
  // 1. Get the compressed data as a Blob first.
115
- const compressedBlob = await compressIbGib(graph);
188
+ const compressedBlob = await compressIbGibToBlob(graph);
116
189
  // 2. Convert the Blob's binary data to a Uint8Array.
117
190
  const buffer = await compressedBlob.arrayBuffer();
118
191
  const uint8Array = new Uint8Array(buffer);
@@ -146,7 +219,7 @@ export async function decompressIbGibGraphFromString({ compressedBase64, }) {
146
219
  // The MIME type isn't strictly necessary for DecompressionStream but is good practice.
147
220
  const compressedBlob = new Blob([compressedUint8Array], { type: 'application/gzip' });
148
221
  // 3. Use our existing function to decompress the Blob.
149
- return await decompressIbGib(compressedBlob);
222
+ return await decompressIbGibFromBlob(compressedBlob);
150
223
  }
151
224
  catch (error) {
152
225
  console.error(`${lc} ${extractErrorMsg(error)}`);
@@ -1 +1 @@
1
- {"version":3,"file":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AoB,GAAG,MAAM,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;QAExE,wCAAwC;QACxC,uFAAuF;QACvF,MAAM,cAAc,GAAG,IAAI,IAAI,CAAC,CAAC,oBAAoB,CAAC,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC,CAAC;QAEtF,uDAAuD;QACvD,OAAO,MAAM,uBAAuB,CAAC,cAAc,CAAC,CAAC;KACxD;IAAC,OAAO,KAAK,EAAE;QACZ,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACjD,MAAM,KAAK,CAAC;KACf;YAAS;QACN,IAAI,OAAO,EAAE;YAAE,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;SAAE;KACnD;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibgib/core-gib",
3
- "version": "0.0.107",
3
+ "version": "0.0.108",
4
4
  "description": "ibgib core functionality, including base architecture for witnesses, spaces, apps, robbots, etc., as well as shared utility functions. Node v19+ needed for heavily-used isomorphic webcrypto hashing consumed in both node and browsers.",
5
5
  "funding": {
6
6
  "type": "individual",
@@ -42,46 +42,124 @@ async function base64ToUint8Array(base64String: string): Promise<Uint8Array> {
42
42
  return new Uint8Array(buffer);
43
43
  }
44
44
 
45
+ export async function serializeGraphToString(graph: FlatIbGibGraph): Promise<string> {
46
+ const lc = `[${serializeGraphToString.name}]`;
47
+ try {
48
+ if (logalot) { console.log(`${lc} starting... (I: 4ddb8803cf68e1d3d35f60680cb69825)`); }
49
+
50
+ // 1. Serialize: Create a JSON-safe representation of the graph
51
+ // We use a custom replacer to handle Uint8Array
52
+ // const replacer = (key: string, value: any) => {
53
+ // if (value instanceof Uint8Array) {
54
+ // // This part is async, so we can't use it directly in JSON.stringify.
55
+ // // We must pre-process the object first.
56
+ // throw new Error("Cannot use async replacer. Pre-process the object first.");
57
+ // }
58
+ // return value;
59
+ // };
60
+
61
+ // Pre-process the graph to handle async Base64 conversion
62
+ const serializableGraph = JSON.parse(JSON.stringify(graph)); // Deep clone to avoid mutation
63
+ for (const key in serializableGraph) {
64
+ if (graph[key].data instanceof Uint8Array) {
65
+ serializableGraph[key].data = {
66
+ _dataType: 'Uint8Array_Base64',
67
+ value: await uint8ArrayToBase64(graph[key].data as Uint8Array)
68
+ } as SerializedUint8Array;
69
+ }
70
+ }
71
+
72
+ // 2. Stringify: Convert the serializable object to a JSON string
73
+ const jsonString = JSON.stringify(serializableGraph);
74
+
75
+ if (logalot) { console.log(`${lc} jsonString.length: ${jsonString.length} (I: 56dec8ad0931ab8ba9b5ca3d4e66be25)`); }
76
+
77
+ return jsonString;
78
+ } catch (error) {
79
+ console.error(`${lc} ${extractErrorMsg(error)}`);
80
+ throw error;
81
+ } finally {
82
+ if (logalot) { console.log(`${lc} complete.`); }
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Takes an incoming jsonString created via {@link serializeGraphToString}
88
+ * and returns the original FlatIbGibGraph dto.
89
+ *
90
+ * @param jsonString
91
+ * @returns graph that was originally serialized
92
+ *
93
+ * ## notes
94
+ *
95
+ * This serialize/deserialize is used in the compress/decompress fns:
96
+ *
97
+ * @see {@link compressIbGibToBlob}
98
+ * @see {@link decompressIbGibFromBlob}
99
+ * @see {@link compressIbGibGraphToString}
100
+ * @see {@link decompressIbGibGraphFromString}
101
+ */
102
+ export async function deserializeStringToGraph(jsonString: string): Promise<FlatIbGibGraph> {
103
+ const lc = `[${deserializeStringToGraph.name}]`;
104
+ try {
105
+ if (logalot) { console.log(`${lc} starting... (I: 52e1a1fb1adcc75168fbc6d819868825)`); }
106
+
107
+ const reviver = (key: string, value: any) => {
108
+ if (value && value._dataType === 'Uint8Array_Base64') {
109
+ // Converting base64 to Uint8Array is async, so we can't use it
110
+ // in JSON.parse. We will post-process the object.
111
+ return value; // Return the placeholder for now
112
+ }
113
+ return value;
114
+ };
115
+
116
+ const parsedGraph = JSON.parse(jsonString, reviver);
117
+
118
+ // Post-process to convert Base64 back to Uint8Array
119
+ for (const key in parsedGraph) {
120
+ const data = parsedGraph[key].data;
121
+ if (data && data._dataType === 'Uint8Array_Base64') {
122
+ parsedGraph[key].data = await base64ToUint8Array(data.value);
123
+ }
124
+ }
125
+
126
+ return parsedGraph as FlatIbGibGraph;
127
+ } catch (error) {
128
+ console.error(`${lc} ${extractErrorMsg(error)}`);
129
+ throw error;
130
+ } finally {
131
+ if (logalot) { console.log(`${lc} complete.`); }
132
+ }
133
+ }
134
+
45
135
  /**
46
136
  * Compresses an FlatIbGibGraph object into a Blob.
47
137
  * @param graph The FlatIbGibGraph object to compress.
48
138
  * @returns A Promise that resolves with the compressed Blob.
49
139
  */
50
- export async function compressIbGib(graph: FlatIbGibGraph): Promise<Blob> {
51
- // 1. Serialize: Create a JSON-safe representation of the graph
52
- // We use a custom replacer to handle Uint8Array
53
- // const replacer = (key: string, value: any) => {
54
- // if (value instanceof Uint8Array) {
55
- // // This part is async, so we can't use it directly in JSON.stringify.
56
- // // We must pre-process the object first.
57
- // throw new Error("Cannot use async replacer. Pre-process the object first.");
58
- // }
59
- // return value;
60
- // };
61
-
62
- // Pre-process the graph to handle async Base64 conversion
63
- const serializableGraph = JSON.parse(JSON.stringify(graph)); // Deep clone to avoid mutation
64
- for (const key in serializableGraph) {
65
- if (graph[key].data instanceof Uint8Array) {
66
- serializableGraph[key].data = {
67
- _dataType: 'Uint8Array_Base64',
68
- value: await uint8ArrayToBase64(graph[key].data as Uint8Array)
69
- } as SerializedUint8Array;
70
- }
71
- }
140
+ export async function compressIbGibToBlob(graph: FlatIbGibGraph): Promise<Blob> {
141
+ const lc = `[${compressIbGibToBlob.name}]`;
142
+ try {
143
+ if (logalot) { console.log(`${lc} starting... (I: 8d306868b718596fe8f562bd5118d825)`); }
72
144
 
73
- // 2. Stringify: Convert the serializable object to a JSON string
74
- const jsonString = JSON.stringify(serializableGraph);
145
+ // 1. Serialize: Create a JSON-safe representation of the graph and stringify
146
+ const jsonString = await serializeGraphToString(graph);
75
147
 
76
- // 3. Encode: Convert the string to a Uint8Array (UTF-8)
77
- const dataToCompress = new TextEncoder().encode(jsonString);
148
+ // 2. Encode: Convert the string to a Uint8Array (UTF-8)
149
+ const dataToCompress = new TextEncoder().encode(jsonString);
78
150
 
79
- // 4. Compress: Use the Compression Streams API
80
- const stream = new Response(dataToCompress).body!;
81
- const compressedStream = stream.pipeThrough(new CompressionStream('gzip'));
151
+ // 3. Compress: Use the Compression Streams API
152
+ const stream = new Response(dataToCompress).body!;
153
+ const compressedStream = stream.pipeThrough(new CompressionStream('gzip'));
82
154
 
83
- // Return the compressed data as a Blob
84
- return await new Response(compressedStream).blob();
155
+ // Return the compressed data as a Blob
156
+ return await new Response(compressedStream).blob();
157
+ } catch (error) {
158
+ console.error(`${lc} ${extractErrorMsg(error)}`);
159
+ throw error;
160
+ } finally {
161
+ if (logalot) { console.log(`${lc} complete.`); }
162
+ }
85
163
  }
86
164
 
87
165
  /**
@@ -89,7 +167,7 @@ export async function compressIbGib(graph: FlatIbGibGraph): Promise<Blob> {
89
167
  * @param compressedBlob The Blob containing the compressed graph data.
90
168
  * @returns A Promise that resolves with the original FlatIbGibGraph object.
91
169
  */
92
- export async function decompressIbGib(compressedBlob: Blob): Promise<FlatIbGibGraph> {
170
+ export async function decompressIbGibFromBlob(compressedBlob: Blob): Promise<FlatIbGibGraph> {
93
171
  // 1. Decompress: Use the Decompression Streams API
94
172
  const decompressedStream = compressedBlob.stream().pipeThrough(
95
173
  new DecompressionStream('gzip')
@@ -99,26 +177,8 @@ export async function decompressIbGib(compressedBlob: Blob): Promise<FlatIbGibGr
99
177
  const jsonString = await new Response(decompressedStream).text();
100
178
 
101
179
  // 3. Deserialize: Parse the JSON with a reviver to restore Uint8Arrays
102
- const reviver = (key: string, value: any) => {
103
- if (value && value._dataType === 'Uint8Array_Base64') {
104
- // This part is async, so we can't use it in JSON.parse.
105
- // We must post-process the object.
106
- return value; // Return the placeholder for now
107
- }
108
- return value;
109
- };
110
-
111
- const parsedGraph = JSON.parse(jsonString, reviver);
112
-
113
- // Post-process to convert Base64 back to Uint8Array
114
- for (const key in parsedGraph) {
115
- const data = parsedGraph[key].data;
116
- if (data && data._dataType === 'Uint8Array_Base64') {
117
- parsedGraph[key].data = await base64ToUint8Array(data.value);
118
- }
119
- }
120
-
121
- return parsedGraph as FlatIbGibGraph;
180
+ const parsedGraph = await deserializeStringToGraph(jsonString);
181
+ return parsedGraph;
122
182
  }
123
183
 
124
184
  /**
@@ -136,7 +196,7 @@ export async function compressIbGibGraphToString({
136
196
  if (logalot) { console.log(`${lc} starting... (I: 1352f8540c08f0b725952df8f18c4825)`); }
137
197
 
138
198
  // 1. Get the compressed data as a Blob first.
139
- const compressedBlob = await compressIbGib(graph);
199
+ const compressedBlob = await compressIbGibToBlob(graph);
140
200
 
141
201
  // 2. Convert the Blob's binary data to a Uint8Array.
142
202
  const buffer = await compressedBlob.arrayBuffer();
@@ -174,7 +234,7 @@ export async function decompressIbGibGraphFromString({
174
234
  const compressedBlob = new Blob([compressedUint8Array], { type: 'application/gzip' });
175
235
 
176
236
  // 3. Use our existing function to decompress the Blob.
177
- return await decompressIbGib(compressedBlob);
237
+ return await decompressIbGibFromBlob(compressedBlob);
178
238
  } catch (error) {
179
239
  console.error(`${lc} ${extractErrorMsg(error)}`);
180
240
  throw error;