@vim3d/core 0.2.4 → 0.2.5
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/esm/storage.js +14 -10
- package/package.json +1 -1
- package/storage.d.ts +8 -2
- package/storage.js +14 -10
package/esm/storage.js
CHANGED
|
@@ -545,28 +545,32 @@ function json(value) {
|
|
|
545
545
|
return invalid('Expected finite JSON scene data');
|
|
546
546
|
}
|
|
547
547
|
function sorted(values, key) {
|
|
548
|
-
return values && [...values].sort((a, b) => comparePaths(key(a), key(b)));
|
|
548
|
+
return values && [...values].sort((a, b) => (key && comparePaths(key(a), key(b))) || comparePaths(json(a), json(b)));
|
|
549
549
|
}
|
|
550
550
|
function sortedNodes(nodes) {
|
|
551
|
-
return sorted(nodes
|
|
551
|
+
return sorted(nodes?.map(node => ({
|
|
552
552
|
...node,
|
|
553
553
|
props: sorted(node.props, prop => prop.name),
|
|
554
554
|
nodes: sortedNodes(node.nodes),
|
|
555
|
-
edges: sorted(node.edges
|
|
556
|
-
}));
|
|
555
|
+
edges: sorted(node.edges),
|
|
556
|
+
})), node => node.name);
|
|
557
557
|
}
|
|
558
|
-
|
|
559
|
-
return
|
|
558
|
+
function sortedGraph(graph) {
|
|
559
|
+
return {
|
|
560
560
|
...graph,
|
|
561
561
|
nodes: sortedNodes(graph.nodes),
|
|
562
|
-
edges: sorted(graph.edges
|
|
563
|
-
definitions: sorted(graph.definitions
|
|
562
|
+
edges: sorted(graph.edges),
|
|
563
|
+
definitions: sorted(graph.definitions?.map(def => ({
|
|
564
564
|
...def,
|
|
565
565
|
props: sorted(def.props, prop => prop.name),
|
|
566
566
|
inputs: sorted(def.inputs, port => port.name),
|
|
567
567
|
outputs: sorted(def.outputs, port => port.name),
|
|
568
|
-
|
|
569
|
-
|
|
568
|
+
graph: def.graph && sortedGraph(def.graph),
|
|
569
|
+
})), def => json([def.context, def.category ?? '', def.name, def.category !== undefined])),
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
export function serializeStorageGraph(graph) {
|
|
573
|
+
return json(sortedGraph(graph));
|
|
570
574
|
}
|
|
571
575
|
export async function hashStorageGraph(graph) {
|
|
572
576
|
const bytes = new TextEncoder().encode(serializeStorageGraph(graph));
|
package/package.json
CHANGED
package/storage.d.ts
CHANGED
|
@@ -22,11 +22,17 @@ export interface StorageDefinition {
|
|
|
22
22
|
readonly inputs?: readonly Declaration[];
|
|
23
23
|
readonly outputs?: readonly Declaration[];
|
|
24
24
|
readonly props?: readonly Omit<Declaration, 'multi'>[];
|
|
25
|
+
readonly graph?: StorageSubgraph;
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
-
readonly
|
|
27
|
+
interface StorageSubgraph {
|
|
28
|
+
readonly name?: string;
|
|
29
|
+
readonly context?: string;
|
|
28
30
|
readonly nodes: readonly StorageNode[];
|
|
29
31
|
readonly edges: readonly GraphEdge[];
|
|
32
|
+
readonly definitions?: readonly StorageDefinition[];
|
|
33
|
+
}
|
|
34
|
+
export interface StorageGraph extends StorageSubgraph {
|
|
35
|
+
readonly context: 'vim3d';
|
|
30
36
|
readonly definitions: readonly StorageDefinition[];
|
|
31
37
|
}
|
|
32
38
|
export declare function toStorageGraph(scene: CompiledScene): StorageGraph;
|
package/storage.js
CHANGED
|
@@ -551,28 +551,32 @@ function json(value) {
|
|
|
551
551
|
return invalid('Expected finite JSON scene data');
|
|
552
552
|
}
|
|
553
553
|
function sorted(values, key) {
|
|
554
|
-
return values && [...values].sort((a, b) => (0, graph_js_1.comparePaths)(key(a), key(b)));
|
|
554
|
+
return values && [...values].sort((a, b) => (key && (0, graph_js_1.comparePaths)(key(a), key(b))) || (0, graph_js_1.comparePaths)(json(a), json(b)));
|
|
555
555
|
}
|
|
556
556
|
function sortedNodes(nodes) {
|
|
557
|
-
return sorted(nodes
|
|
557
|
+
return sorted(nodes?.map(node => ({
|
|
558
558
|
...node,
|
|
559
559
|
props: sorted(node.props, prop => prop.name),
|
|
560
560
|
nodes: sortedNodes(node.nodes),
|
|
561
|
-
edges: sorted(node.edges
|
|
562
|
-
}));
|
|
561
|
+
edges: sorted(node.edges),
|
|
562
|
+
})), node => node.name);
|
|
563
563
|
}
|
|
564
|
-
function
|
|
565
|
-
return
|
|
564
|
+
function sortedGraph(graph) {
|
|
565
|
+
return {
|
|
566
566
|
...graph,
|
|
567
567
|
nodes: sortedNodes(graph.nodes),
|
|
568
|
-
edges: sorted(graph.edges
|
|
569
|
-
definitions: sorted(graph.definitions
|
|
568
|
+
edges: sorted(graph.edges),
|
|
569
|
+
definitions: sorted(graph.definitions?.map(def => ({
|
|
570
570
|
...def,
|
|
571
571
|
props: sorted(def.props, prop => prop.name),
|
|
572
572
|
inputs: sorted(def.inputs, port => port.name),
|
|
573
573
|
outputs: sorted(def.outputs, port => port.name),
|
|
574
|
-
|
|
575
|
-
|
|
574
|
+
graph: def.graph && sortedGraph(def.graph),
|
|
575
|
+
})), def => json([def.context, def.category ?? '', def.name, def.category !== undefined])),
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
function serializeStorageGraph(graph) {
|
|
579
|
+
return json(sortedGraph(graph));
|
|
576
580
|
}
|
|
577
581
|
async function hashStorageGraph(graph) {
|
|
578
582
|
const bytes = new TextEncoder().encode(serializeStorageGraph(graph));
|