@workglow/util 0.0.122 → 0.0.123
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/dist/browser.js +1 -954
- package/dist/browser.js.map +3 -17
- package/dist/bun.js +1 -938
- package/dist/bun.js.map +3 -17
- package/dist/common.d.ts +0 -10
- package/dist/common.d.ts.map +1 -1
- package/dist/compress-browser.d.ts +7 -0
- package/dist/compress-browser.d.ts.map +1 -0
- package/dist/compress-browser.js +18 -0
- package/dist/compress-browser.js.map +10 -0
- package/dist/compress-node.d.ts +7 -0
- package/dist/compress-node.d.ts.map +1 -0
- package/dist/compress-node.js +25 -0
- package/dist/compress-node.js.map +10 -0
- package/dist/graph-entry.d.ts +7 -0
- package/dist/graph-entry.d.ts.map +1 -0
- package/dist/graph-entry.js +539 -0
- package/dist/graph-entry.js.map +15 -0
- package/dist/json-schema/SchemaUtils.d.ts +58 -0
- package/dist/json-schema/SchemaUtils.d.ts.map +1 -0
- package/dist/json-schema/SchemaValidation.d.ts +8 -0
- package/dist/json-schema/SchemaValidation.d.ts.map +1 -0
- package/dist/media-browser.d.ts +8 -0
- package/dist/media-browser.d.ts.map +1 -0
- package/dist/media-browser.js +73 -0
- package/dist/media-browser.js.map +11 -0
- package/dist/media-node.d.ts +8 -0
- package/dist/media-node.d.ts.map +1 -0
- package/dist/media-node.js +50 -0
- package/dist/media-node.js.map +11 -0
- package/dist/node.js +1 -938
- package/dist/node.js.map +3 -17
- package/dist/schema-entry.d.ts +17 -0
- package/dist/schema-entry.d.ts.map +1 -0
- package/dist/schema-entry.js +774 -0
- package/dist/schema-entry.js.map +18 -0
- package/dist/types.d.ts +0 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +41 -4
package/dist/node.js
CHANGED
|
@@ -430,624 +430,6 @@ class BaseError {
|
|
|
430
430
|
return `${this.name}: ${this.message}`;
|
|
431
431
|
}
|
|
432
432
|
}
|
|
433
|
-
|
|
434
|
-
// src/graph/errors.ts
|
|
435
|
-
class NodeAlreadyExistsError extends BaseError {
|
|
436
|
-
static type = "NodeAlreadyExistsError";
|
|
437
|
-
newNode;
|
|
438
|
-
oldNode;
|
|
439
|
-
identity;
|
|
440
|
-
constructor(newNode, oldNode, identity) {
|
|
441
|
-
super(`${JSON.stringify(newNode)} shares an identity (${String(identity)}) with ${JSON.stringify(oldNode)}`);
|
|
442
|
-
this.newNode = newNode;
|
|
443
|
-
this.oldNode = oldNode;
|
|
444
|
-
this.identity = identity;
|
|
445
|
-
this.name = "NodeAlreadyExistsError";
|
|
446
|
-
Object.setPrototypeOf(this, NodeAlreadyExistsError.prototype);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
class NodeDoesntExistError extends BaseError {
|
|
451
|
-
static type = "NodeDoesntExistError";
|
|
452
|
-
identity;
|
|
453
|
-
constructor(identity) {
|
|
454
|
-
super(`A node with identity ${String(identity)} doesn't exist in the graph`);
|
|
455
|
-
this.identity = identity;
|
|
456
|
-
this.name = "NodeDoesntExistError";
|
|
457
|
-
Object.setPrototypeOf(this, NodeDoesntExistError.prototype);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
class CycleError extends BaseError {
|
|
462
|
-
static type = "CycleError";
|
|
463
|
-
constructor(message) {
|
|
464
|
-
super(message);
|
|
465
|
-
this.name = "CycleError";
|
|
466
|
-
Object.setPrototypeOf(this, CycleError.prototype);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
// src/graph/graph.ts
|
|
471
|
-
class Graph {
|
|
472
|
-
nodes;
|
|
473
|
-
adjacency;
|
|
474
|
-
nodeIdentity;
|
|
475
|
-
edgeIdentity;
|
|
476
|
-
constructor(nodeIdentity, edgeIdentity) {
|
|
477
|
-
this.nodes = new Map;
|
|
478
|
-
this.adjacency = [];
|
|
479
|
-
this.nodeIdentity = nodeIdentity;
|
|
480
|
-
this.edgeIdentity = edgeIdentity;
|
|
481
|
-
}
|
|
482
|
-
events = new EventEmitter;
|
|
483
|
-
on(name, fn) {
|
|
484
|
-
this.events.on.call(this.events, name, fn);
|
|
485
|
-
}
|
|
486
|
-
off(name, fn) {
|
|
487
|
-
this.events.off.call(this.events, name, fn);
|
|
488
|
-
}
|
|
489
|
-
emit(name, ...args) {
|
|
490
|
-
this.events.emit(name, ...args);
|
|
491
|
-
}
|
|
492
|
-
insert(node) {
|
|
493
|
-
const id = this.nodeIdentity(node);
|
|
494
|
-
const isOverwrite = this.nodes.has(id);
|
|
495
|
-
if (isOverwrite) {
|
|
496
|
-
throw new NodeAlreadyExistsError(node, this.nodes.get(id), id);
|
|
497
|
-
}
|
|
498
|
-
this.nodes.set(id, node);
|
|
499
|
-
this.adjacency.map((adj) => adj.push(null));
|
|
500
|
-
this.adjacency.push(new Array(this.adjacency.length + 1).fill(null));
|
|
501
|
-
this.emit("node-added", id);
|
|
502
|
-
return id;
|
|
503
|
-
}
|
|
504
|
-
replace(node) {
|
|
505
|
-
const id = this.nodeIdentity(node);
|
|
506
|
-
const isOverwrite = this.nodes.has(id);
|
|
507
|
-
if (!isOverwrite) {
|
|
508
|
-
throw new NodeDoesntExistError(id);
|
|
509
|
-
}
|
|
510
|
-
this.nodes.set(id, node);
|
|
511
|
-
this.emit("node-replaced", id);
|
|
512
|
-
}
|
|
513
|
-
upsert(node) {
|
|
514
|
-
const id = this.nodeIdentity(node);
|
|
515
|
-
const isOverwrite = this.nodes.has(id);
|
|
516
|
-
this.nodes.set(id, node);
|
|
517
|
-
if (!isOverwrite) {
|
|
518
|
-
this.adjacency.map((adj) => adj.push(null));
|
|
519
|
-
this.adjacency.push(new Array(this.adjacency.length + 1).fill(null));
|
|
520
|
-
this.emit("node-added", id);
|
|
521
|
-
} else {
|
|
522
|
-
this.emit("node-replaced", id);
|
|
523
|
-
}
|
|
524
|
-
return id;
|
|
525
|
-
}
|
|
526
|
-
addEdge(node1Identity, node2Identity, edge) {
|
|
527
|
-
if (edge === undefined) {
|
|
528
|
-
edge = true;
|
|
529
|
-
}
|
|
530
|
-
const node1Exists = this.nodes.has(node1Identity);
|
|
531
|
-
const node2Exists = this.nodes.has(node2Identity);
|
|
532
|
-
if (!node1Exists) {
|
|
533
|
-
throw new NodeDoesntExistError(node1Identity);
|
|
534
|
-
}
|
|
535
|
-
if (!node2Exists) {
|
|
536
|
-
throw new NodeDoesntExistError(node2Identity);
|
|
537
|
-
}
|
|
538
|
-
const node1Index = Array.from(this.nodes.keys()).indexOf(node1Identity);
|
|
539
|
-
const node2Index = Array.from(this.nodes.keys()).indexOf(node2Identity);
|
|
540
|
-
if (this.adjacency[node1Index][node2Index] === null) {
|
|
541
|
-
this.adjacency[node1Index][node2Index] = [edge];
|
|
542
|
-
} else {
|
|
543
|
-
if (!this.adjacency[node1Index][node2Index].includes(edge)) {
|
|
544
|
-
this.adjacency[node1Index][node2Index].push(edge);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
const id = this.edgeIdentity(edge, node1Identity, node2Identity);
|
|
548
|
-
this.emit("edge-added", id);
|
|
549
|
-
return id;
|
|
550
|
-
}
|
|
551
|
-
getNodes(compareFunc) {
|
|
552
|
-
const temp = Array.from(this.nodes.values());
|
|
553
|
-
if (compareFunc !== undefined) {
|
|
554
|
-
return temp.sort(compareFunc);
|
|
555
|
-
}
|
|
556
|
-
return temp;
|
|
557
|
-
}
|
|
558
|
-
getNode(nodeIdentity) {
|
|
559
|
-
return this.nodes.get(nodeIdentity);
|
|
560
|
-
}
|
|
561
|
-
hasNode(nodeIdentity) {
|
|
562
|
-
return this.nodes.has(nodeIdentity);
|
|
563
|
-
}
|
|
564
|
-
getEdges() {
|
|
565
|
-
const toReturn = [];
|
|
566
|
-
const nodeKeys = Array.from(this.nodes.keys());
|
|
567
|
-
this.adjacency.forEach((row, rowIndex) => {
|
|
568
|
-
const node1Identity = nodeKeys[rowIndex];
|
|
569
|
-
if (node1Identity != null) {
|
|
570
|
-
row.forEach((edges, colIndex) => {
|
|
571
|
-
if (edges !== null) {
|
|
572
|
-
const node2Identity = nodeKeys[colIndex];
|
|
573
|
-
if (node2Identity != null) {
|
|
574
|
-
for (const edge of edges) {
|
|
575
|
-
toReturn.push([node1Identity, node2Identity, edge]);
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
});
|
|
580
|
-
}
|
|
581
|
-
});
|
|
582
|
-
return toReturn;
|
|
583
|
-
}
|
|
584
|
-
outEdges(node1Identity) {
|
|
585
|
-
const nodeKeys = Array.from(this.nodes.keys());
|
|
586
|
-
const nodeIndex = nodeKeys.indexOf(node1Identity);
|
|
587
|
-
const toReturn = [];
|
|
588
|
-
this.adjacency[nodeIndex].forEach((edges, colIndex) => {
|
|
589
|
-
if (edges !== null) {
|
|
590
|
-
const node2Identity = nodeKeys[colIndex];
|
|
591
|
-
if (node2Identity != null) {
|
|
592
|
-
for (const edge of edges) {
|
|
593
|
-
toReturn.push([node1Identity, node2Identity, edge]);
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
});
|
|
598
|
-
return toReturn;
|
|
599
|
-
}
|
|
600
|
-
inEdges(node2Identity) {
|
|
601
|
-
const nodeKeys = Array.from(this.nodes.keys());
|
|
602
|
-
const node2Index = nodeKeys.indexOf(node2Identity);
|
|
603
|
-
const toReturn = [];
|
|
604
|
-
this.adjacency.forEach((row, rowIndex) => {
|
|
605
|
-
const node1Identity = nodeKeys[rowIndex];
|
|
606
|
-
const edges = row[node2Index];
|
|
607
|
-
if (edges !== null) {
|
|
608
|
-
for (const edge of edges) {
|
|
609
|
-
toReturn.push([node1Identity, node2Identity, edge]);
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
});
|
|
613
|
-
return toReturn;
|
|
614
|
-
}
|
|
615
|
-
nodeEdges(nodeIdentity) {
|
|
616
|
-
return [...this.outEdges(nodeIdentity), ...this.inEdges(nodeIdentity)];
|
|
617
|
-
}
|
|
618
|
-
removeEdge(node1Identity, node2Identity, edgeIdentity) {
|
|
619
|
-
const node1Exists = this.nodes.has(node1Identity);
|
|
620
|
-
const node2Exists = this.nodes.has(node2Identity);
|
|
621
|
-
if (!node1Exists) {
|
|
622
|
-
throw new NodeDoesntExistError(node1Identity);
|
|
623
|
-
}
|
|
624
|
-
if (!node2Exists) {
|
|
625
|
-
throw new NodeDoesntExistError(node2Identity);
|
|
626
|
-
}
|
|
627
|
-
const node1Index = Array.from(this.nodes.keys()).indexOf(node1Identity);
|
|
628
|
-
const node2Index = Array.from(this.nodes.keys()).indexOf(node2Identity);
|
|
629
|
-
if (edgeIdentity === undefined) {
|
|
630
|
-
this.adjacency[node1Index][node2Index] = null;
|
|
631
|
-
} else {
|
|
632
|
-
for (const row of this.adjacency) {
|
|
633
|
-
for (const edgelist of row) {
|
|
634
|
-
if (edgelist !== null) {
|
|
635
|
-
for (let edgeIndex = 0;edgeIndex < edgelist.length; edgeIndex++) {
|
|
636
|
-
if (this.edgeIdentity(edgelist[edgeIndex], node1Identity, node2Identity) === edgeIdentity) {
|
|
637
|
-
edgelist.splice(edgeIndex, 1);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
this.emit("edge-removed", edgeIdentity);
|
|
645
|
-
}
|
|
646
|
-
remove(nodeIdentity) {
|
|
647
|
-
if (!this.nodes.has(nodeIdentity)) {
|
|
648
|
-
throw new NodeDoesntExistError(nodeIdentity);
|
|
649
|
-
}
|
|
650
|
-
this.nodes.delete(nodeIdentity);
|
|
651
|
-
const nodeIndex = Array.from(this.nodes.keys()).indexOf(nodeIdentity);
|
|
652
|
-
this.adjacency.splice(nodeIndex, 1);
|
|
653
|
-
this.adjacency.forEach((row) => row.splice(nodeIndex, 1));
|
|
654
|
-
this.emit("node-removed", nodeIdentity);
|
|
655
|
-
}
|
|
656
|
-
removeNode(nodeIdentity) {
|
|
657
|
-
return this.remove(nodeIdentity);
|
|
658
|
-
}
|
|
659
|
-
addNode(node) {
|
|
660
|
-
return this.insert(node);
|
|
661
|
-
}
|
|
662
|
-
addNodes(nodes) {
|
|
663
|
-
return nodes.map((node) => this.insert(node));
|
|
664
|
-
}
|
|
665
|
-
addEdges(edges) {
|
|
666
|
-
return edges.map(([node1Identity, node2Identity, edge]) => this.addEdge(node1Identity, node2Identity, edge));
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
// src/graph/directedGraph.ts
|
|
671
|
-
class DirectedGraph extends Graph {
|
|
672
|
-
hasCycle = false;
|
|
673
|
-
isAcyclic() {
|
|
674
|
-
if (this.hasCycle !== undefined) {
|
|
675
|
-
return !this.hasCycle;
|
|
676
|
-
}
|
|
677
|
-
const nodeIndices = Array.from(this.nodes.keys());
|
|
678
|
-
const nodeInDegrees = new Map(Array.from(this.nodes.keys()).map((n) => [n, this.indegreeOfNode(n)]));
|
|
679
|
-
const toSearch = Array.from(nodeInDegrees).filter((pair) => pair[1] === 0);
|
|
680
|
-
let visitedNodes = 0;
|
|
681
|
-
while (toSearch.length > 0) {
|
|
682
|
-
const cur = toSearch.pop();
|
|
683
|
-
if (cur === undefined) {
|
|
684
|
-
continue;
|
|
685
|
-
}
|
|
686
|
-
const nodeIndex = nodeIndices.indexOf(cur[0]);
|
|
687
|
-
this.adjacency[nodeIndex].forEach((hasAdj, index) => {
|
|
688
|
-
if (hasAdj !== null) {
|
|
689
|
-
const currentInDegree = nodeInDegrees.get(nodeIndices[index]);
|
|
690
|
-
if (currentInDegree !== undefined) {
|
|
691
|
-
nodeInDegrees.set(nodeIndices[index], currentInDegree - 1);
|
|
692
|
-
if (currentInDegree - 1 === 0) {
|
|
693
|
-
toSearch.push([nodeIndices[index], currentInDegree - 1]);
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
});
|
|
698
|
-
visitedNodes++;
|
|
699
|
-
}
|
|
700
|
-
this.hasCycle = !(visitedNodes === this.nodes.size);
|
|
701
|
-
return visitedNodes === this.nodes.size;
|
|
702
|
-
}
|
|
703
|
-
indegreeOfNode(nodeID) {
|
|
704
|
-
const nodeIdentities = Array.from(this.nodes.keys());
|
|
705
|
-
const indexOfNode = nodeIdentities.indexOf(nodeID);
|
|
706
|
-
if (indexOfNode === -1) {
|
|
707
|
-
throw new NodeDoesntExistError(nodeID);
|
|
708
|
-
}
|
|
709
|
-
return this.adjacency.reduce((carry, row) => {
|
|
710
|
-
return carry + (row[indexOfNode] == null ? 0 : 1);
|
|
711
|
-
}, 0);
|
|
712
|
-
}
|
|
713
|
-
addEdge(sourceNodeIdentity, targetNodeIdentity, edge, skipUpdatingCyclicality = false) {
|
|
714
|
-
if (edge === undefined) {
|
|
715
|
-
edge = true;
|
|
716
|
-
}
|
|
717
|
-
if (this.hasCycle === false && !skipUpdatingCyclicality) {
|
|
718
|
-
this.hasCycle = this.wouldAddingEdgeCreateCycle(sourceNodeIdentity, targetNodeIdentity);
|
|
719
|
-
} else if (skipUpdatingCyclicality) {
|
|
720
|
-
this.hasCycle = undefined;
|
|
721
|
-
}
|
|
722
|
-
return super.addEdge(sourceNodeIdentity, targetNodeIdentity, edge);
|
|
723
|
-
}
|
|
724
|
-
canReachFrom(startNode, endNode) {
|
|
725
|
-
const nodeIdentities = Array.from(this.nodes.keys());
|
|
726
|
-
const startNodeIndex = nodeIdentities.indexOf(startNode);
|
|
727
|
-
const endNodeIndex = nodeIdentities.indexOf(endNode);
|
|
728
|
-
if (this.adjacency[startNodeIndex][endNodeIndex] != null) {
|
|
729
|
-
return true;
|
|
730
|
-
}
|
|
731
|
-
return this.adjacency[startNodeIndex].reduce((carry, edge, index) => {
|
|
732
|
-
if (carry || edge === null) {
|
|
733
|
-
return carry;
|
|
734
|
-
}
|
|
735
|
-
return this.canReachFrom(nodeIdentities[index], endNode);
|
|
736
|
-
}, false);
|
|
737
|
-
}
|
|
738
|
-
wouldAddingEdgeCreateCycle(sourceNodeIdentity, targetNodeIdentity) {
|
|
739
|
-
return this.hasCycle || sourceNodeIdentity === targetNodeIdentity || this.canReachFrom(targetNodeIdentity, sourceNodeIdentity);
|
|
740
|
-
}
|
|
741
|
-
getSubGraphStartingFrom(startNodeIdentity) {
|
|
742
|
-
const nodeIndices = Array.from(this.nodes.keys());
|
|
743
|
-
const initalNode = this.nodes.get(startNodeIdentity);
|
|
744
|
-
if (initalNode == null) {
|
|
745
|
-
throw new NodeDoesntExistError(startNodeIdentity);
|
|
746
|
-
}
|
|
747
|
-
const recur = (startNodeIdentity2, nodesToInclude) => {
|
|
748
|
-
let toReturn = [...nodesToInclude];
|
|
749
|
-
const nodeIndex = nodeIndices.indexOf(startNodeIdentity2);
|
|
750
|
-
this.adjacency[nodeIndex].forEach((hasAdj, index) => {
|
|
751
|
-
if (hasAdj !== null && nodesToInclude.find((n) => this.nodeIdentity(n) === nodeIndices[index]) == null) {
|
|
752
|
-
const newNode = this.nodes.get(nodeIndices[index]);
|
|
753
|
-
if (newNode != null) {
|
|
754
|
-
toReturn = [...recur(nodeIndices[index], toReturn), newNode];
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
});
|
|
758
|
-
return toReturn;
|
|
759
|
-
};
|
|
760
|
-
const newGraph = new DirectedGraph(this.nodeIdentity, this.edgeIdentity);
|
|
761
|
-
const nodeList = recur(startNodeIdentity, [initalNode]);
|
|
762
|
-
const includeIdents = nodeList.map((t) => this.nodeIdentity(t));
|
|
763
|
-
Array.from(this.nodes.values()).forEach((n) => {
|
|
764
|
-
if (includeIdents.includes(this.nodeIdentity(n))) {
|
|
765
|
-
newGraph.insert(n);
|
|
766
|
-
}
|
|
767
|
-
});
|
|
768
|
-
newGraph.adjacency = this.subAdj(nodeList);
|
|
769
|
-
return newGraph;
|
|
770
|
-
}
|
|
771
|
-
subAdj(include) {
|
|
772
|
-
const includeIdents = include.map((t) => this.nodeIdentity(t));
|
|
773
|
-
const nodeIndices = Array.from(this.nodes.keys());
|
|
774
|
-
return this.adjacency.reduce((carry, cur, index) => {
|
|
775
|
-
if (includeIdents.includes(nodeIndices[index])) {
|
|
776
|
-
return [...carry, cur.filter((_, index2) => includeIdents.includes(nodeIndices[index2]))];
|
|
777
|
-
} else {
|
|
778
|
-
return carry;
|
|
779
|
-
}
|
|
780
|
-
}, []);
|
|
781
|
-
}
|
|
782
|
-
getEdges() {
|
|
783
|
-
return super.getEdges();
|
|
784
|
-
}
|
|
785
|
-
removeEdge(sourceNodeIdentity, targetNodeIdentity, edgeIdentity) {
|
|
786
|
-
super.removeEdge(sourceNodeIdentity, targetNodeIdentity, edgeIdentity);
|
|
787
|
-
this.hasCycle = undefined;
|
|
788
|
-
}
|
|
789
|
-
remove(nodeIdentity) {
|
|
790
|
-
super.remove(nodeIdentity);
|
|
791
|
-
this.hasCycle = undefined;
|
|
792
|
-
}
|
|
793
|
-
addEdges(edges) {
|
|
794
|
-
return super.addEdges(edges);
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
// src/graph/directedAcyclicGraph.ts
|
|
799
|
-
class DirectedAcyclicGraph extends DirectedGraph {
|
|
800
|
-
_topologicallySortedNodes;
|
|
801
|
-
static fromDirectedGraph(graph) {
|
|
802
|
-
if (!graph.isAcyclic()) {
|
|
803
|
-
throw new CycleError("Can't convert that graph to a DAG because it contains a cycle");
|
|
804
|
-
}
|
|
805
|
-
const toRet = new DirectedAcyclicGraph(graph.nodeIdentity, graph.edgeIdentity);
|
|
806
|
-
toRet.nodes = graph.nodes;
|
|
807
|
-
toRet.adjacency = graph.adjacency;
|
|
808
|
-
return toRet;
|
|
809
|
-
}
|
|
810
|
-
addEdge(sourceNodeIdentity, targetNodeIdentity, edge) {
|
|
811
|
-
if (edge === undefined) {
|
|
812
|
-
edge = true;
|
|
813
|
-
}
|
|
814
|
-
if (this.wouldAddingEdgeCreateCycle(sourceNodeIdentity, targetNodeIdentity)) {
|
|
815
|
-
throw new CycleError(`Can't add edge from ${String(sourceNodeIdentity)} to ${String(targetNodeIdentity)} it would create a cycle`);
|
|
816
|
-
}
|
|
817
|
-
this._topologicallySortedNodes = undefined;
|
|
818
|
-
return super.addEdge(sourceNodeIdentity, targetNodeIdentity, edge, true);
|
|
819
|
-
}
|
|
820
|
-
insert(node) {
|
|
821
|
-
if (this._topologicallySortedNodes !== undefined) {
|
|
822
|
-
this._topologicallySortedNodes = [node, ...this._topologicallySortedNodes];
|
|
823
|
-
}
|
|
824
|
-
return super.insert(node);
|
|
825
|
-
}
|
|
826
|
-
topologicallySortedNodes() {
|
|
827
|
-
if (this._topologicallySortedNodes !== undefined) {
|
|
828
|
-
return this._topologicallySortedNodes;
|
|
829
|
-
}
|
|
830
|
-
const nodeIndices = Array.from(this.nodes.keys());
|
|
831
|
-
const nodeInDegrees = new Map(Array.from(this.nodes.keys()).map((n) => [n, this.indegreeOfNode(n)]));
|
|
832
|
-
const adjCopy = this.adjacency.map((a) => [...a]);
|
|
833
|
-
const toSearch = Array.from(nodeInDegrees).filter((pair) => pair[1] === 0);
|
|
834
|
-
if (toSearch.length === this.nodes.size) {
|
|
835
|
-
const arrayOfNodes = Array.from(this.nodes.values());
|
|
836
|
-
this._topologicallySortedNodes = arrayOfNodes;
|
|
837
|
-
return arrayOfNodes;
|
|
838
|
-
}
|
|
839
|
-
const toReturn = [];
|
|
840
|
-
while (toSearch.length > 0) {
|
|
841
|
-
const n = toSearch.pop();
|
|
842
|
-
if (n === undefined) {
|
|
843
|
-
throw new Error("Unexpected empty array");
|
|
844
|
-
}
|
|
845
|
-
const curNode = this.nodes.get(n[0]);
|
|
846
|
-
if (curNode == null) {
|
|
847
|
-
throw new Error("This should never happen");
|
|
848
|
-
}
|
|
849
|
-
toReturn.push(curNode);
|
|
850
|
-
adjCopy[nodeIndices.indexOf(n[0])]?.forEach((edge, index) => {
|
|
851
|
-
if (edge !== null) {
|
|
852
|
-
adjCopy[nodeIndices.indexOf(n[0])][index] = null;
|
|
853
|
-
const target = nodeInDegrees.get(nodeIndices[index]);
|
|
854
|
-
if (target !== undefined) {
|
|
855
|
-
nodeInDegrees.set(nodeIndices[index], target - 1);
|
|
856
|
-
if (target - 1 === 0) {
|
|
857
|
-
toSearch.push([nodeIndices[index], 0]);
|
|
858
|
-
}
|
|
859
|
-
} else {
|
|
860
|
-
throw new Error("This should never happen");
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
});
|
|
864
|
-
}
|
|
865
|
-
this._topologicallySortedNodes = toReturn;
|
|
866
|
-
return toReturn;
|
|
867
|
-
}
|
|
868
|
-
getSubGraphStartingFrom(startNodeIdentity) {
|
|
869
|
-
return DirectedAcyclicGraph.fromDirectedGraph(super.getSubGraphStartingFrom(startNodeIdentity));
|
|
870
|
-
}
|
|
871
|
-
removeEdge(sourceNodeIdentity, targetNodeIdentity, edgeIdentity) {
|
|
872
|
-
super.removeEdge(sourceNodeIdentity, targetNodeIdentity, edgeIdentity);
|
|
873
|
-
this._topologicallySortedNodes = undefined;
|
|
874
|
-
}
|
|
875
|
-
remove(nodeIdentity) {
|
|
876
|
-
super.remove(nodeIdentity);
|
|
877
|
-
this._topologicallySortedNodes = undefined;
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
// src/json-schema/FromSchema.ts
|
|
881
|
-
var FromSchemaDefaultOptions = {
|
|
882
|
-
parseNotKeyword: true,
|
|
883
|
-
parseIfThenElseKeywords: true,
|
|
884
|
-
keepDefaultedPropertiesOptional: true,
|
|
885
|
-
references: false,
|
|
886
|
-
deserialize: false
|
|
887
|
-
};
|
|
888
|
-
// src/json-schema/parsePartialJson.ts
|
|
889
|
-
function parsePartialJson(text) {
|
|
890
|
-
const trimmed = text.trim();
|
|
891
|
-
if (!trimmed)
|
|
892
|
-
return;
|
|
893
|
-
try {
|
|
894
|
-
const result = JSON.parse(trimmed);
|
|
895
|
-
if (typeof result === "object" && result !== null && !Array.isArray(result)) {
|
|
896
|
-
return result;
|
|
897
|
-
}
|
|
898
|
-
return;
|
|
899
|
-
} catch {}
|
|
900
|
-
if (trimmed[0] !== "{")
|
|
901
|
-
return;
|
|
902
|
-
const repaired = repairJson(trimmed);
|
|
903
|
-
if (repaired === undefined)
|
|
904
|
-
return;
|
|
905
|
-
try {
|
|
906
|
-
const result = JSON.parse(repaired);
|
|
907
|
-
if (typeof result === "object" && result !== null && !Array.isArray(result)) {
|
|
908
|
-
return result;
|
|
909
|
-
}
|
|
910
|
-
return;
|
|
911
|
-
} catch {
|
|
912
|
-
return;
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
function repairJson(text) {
|
|
916
|
-
let result = "";
|
|
917
|
-
let i = 0;
|
|
918
|
-
const len = text.length;
|
|
919
|
-
const stack = [];
|
|
920
|
-
let inString = false;
|
|
921
|
-
let escaped = false;
|
|
922
|
-
let lastSafeEnd = 0;
|
|
923
|
-
while (i < len) {
|
|
924
|
-
const ch = text[i];
|
|
925
|
-
if (escaped) {
|
|
926
|
-
escaped = false;
|
|
927
|
-
result += ch;
|
|
928
|
-
i++;
|
|
929
|
-
continue;
|
|
930
|
-
}
|
|
931
|
-
if (ch === "\\") {
|
|
932
|
-
escaped = true;
|
|
933
|
-
result += ch;
|
|
934
|
-
i++;
|
|
935
|
-
continue;
|
|
936
|
-
}
|
|
937
|
-
if (inString) {
|
|
938
|
-
if (ch === '"') {
|
|
939
|
-
inString = false;
|
|
940
|
-
result += ch;
|
|
941
|
-
i++;
|
|
942
|
-
lastSafeEnd = result.length;
|
|
943
|
-
continue;
|
|
944
|
-
}
|
|
945
|
-
result += ch;
|
|
946
|
-
i++;
|
|
947
|
-
continue;
|
|
948
|
-
}
|
|
949
|
-
switch (ch) {
|
|
950
|
-
case '"':
|
|
951
|
-
inString = true;
|
|
952
|
-
result += ch;
|
|
953
|
-
i++;
|
|
954
|
-
break;
|
|
955
|
-
case "{":
|
|
956
|
-
stack.push("}");
|
|
957
|
-
result += ch;
|
|
958
|
-
i++;
|
|
959
|
-
break;
|
|
960
|
-
case "[":
|
|
961
|
-
stack.push("]");
|
|
962
|
-
result += ch;
|
|
963
|
-
i++;
|
|
964
|
-
break;
|
|
965
|
-
case "}":
|
|
966
|
-
if (stack.length > 0 && stack[stack.length - 1] === "}") {
|
|
967
|
-
stack.pop();
|
|
968
|
-
result += ch;
|
|
969
|
-
i++;
|
|
970
|
-
lastSafeEnd = result.length;
|
|
971
|
-
} else {
|
|
972
|
-
return closeStack(result, stack);
|
|
973
|
-
}
|
|
974
|
-
break;
|
|
975
|
-
case "]":
|
|
976
|
-
if (stack.length > 0 && stack[stack.length - 1] === "]") {
|
|
977
|
-
stack.pop();
|
|
978
|
-
result += ch;
|
|
979
|
-
i++;
|
|
980
|
-
lastSafeEnd = result.length;
|
|
981
|
-
} else {
|
|
982
|
-
return closeStack(result, stack);
|
|
983
|
-
}
|
|
984
|
-
break;
|
|
985
|
-
default:
|
|
986
|
-
result += ch;
|
|
987
|
-
i++;
|
|
988
|
-
break;
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
if (inString) {
|
|
992
|
-
result += '"';
|
|
993
|
-
}
|
|
994
|
-
if (stack.length === 0) {
|
|
995
|
-
return result;
|
|
996
|
-
}
|
|
997
|
-
return closeStack(cleanTrailing(result), stack);
|
|
998
|
-
}
|
|
999
|
-
function cleanTrailing(text) {
|
|
1000
|
-
let s = text.trimEnd();
|
|
1001
|
-
let changed = true;
|
|
1002
|
-
while (changed) {
|
|
1003
|
-
changed = false;
|
|
1004
|
-
const trimmed = s.trimEnd();
|
|
1005
|
-
if (trimmed.endsWith(",")) {
|
|
1006
|
-
s = trimmed.slice(0, -1);
|
|
1007
|
-
changed = true;
|
|
1008
|
-
continue;
|
|
1009
|
-
}
|
|
1010
|
-
if (trimmed.endsWith(":")) {
|
|
1011
|
-
const withoutColon = trimmed.slice(0, -1).trimEnd();
|
|
1012
|
-
if (withoutColon.endsWith('"')) {
|
|
1013
|
-
const keyStart = withoutColon.lastIndexOf('"', withoutColon.length - 2);
|
|
1014
|
-
if (keyStart >= 0) {
|
|
1015
|
-
let before = withoutColon.slice(0, keyStart).trimEnd();
|
|
1016
|
-
if (before.endsWith(",")) {
|
|
1017
|
-
before = before.slice(0, -1);
|
|
1018
|
-
}
|
|
1019
|
-
s = before;
|
|
1020
|
-
changed = true;
|
|
1021
|
-
continue;
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
s = withoutColon;
|
|
1025
|
-
changed = true;
|
|
1026
|
-
continue;
|
|
1027
|
-
}
|
|
1028
|
-
const bareTokenMatch = trimmed.match(/,\s*"[^"]*"\s*:\s*(?:tru|fal|nul|true|false|null|[\d.eE+-]+)$/);
|
|
1029
|
-
if (bareTokenMatch) {
|
|
1030
|
-
const valueStr = trimmed.slice(trimmed.lastIndexOf(":") + 1).trim();
|
|
1031
|
-
try {
|
|
1032
|
-
JSON.parse(valueStr);
|
|
1033
|
-
} catch {
|
|
1034
|
-
s = trimmed.slice(0, bareTokenMatch.index).trimEnd();
|
|
1035
|
-
if (s.endsWith(","))
|
|
1036
|
-
s = s.slice(0, -1);
|
|
1037
|
-
changed = true;
|
|
1038
|
-
continue;
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
return s;
|
|
1043
|
-
}
|
|
1044
|
-
function closeStack(text, stack) {
|
|
1045
|
-
let result = text;
|
|
1046
|
-
for (let i = stack.length - 1;i >= 0; i--) {
|
|
1047
|
-
result += stack[i];
|
|
1048
|
-
}
|
|
1049
|
-
return result;
|
|
1050
|
-
}
|
|
1051
433
|
// src/utilities/objectOfArraysAsArrayOfObjects.ts
|
|
1052
434
|
function objectOfArraysAsArrayOfObjects(data) {
|
|
1053
435
|
const keys = Object.keys(data);
|
|
@@ -1354,236 +736,6 @@ function objectOfArraysAsArrayOfObjects(data) {
|
|
|
1354
736
|
}
|
|
1355
737
|
});
|
|
1356
738
|
}
|
|
1357
|
-
// src/vector/TypedArray.ts
|
|
1358
|
-
function isTypedArray(value) {
|
|
1359
|
-
return ArrayBuffer.isView(value) && !(value instanceof DataView);
|
|
1360
|
-
}
|
|
1361
|
-
var TypedArrayType = null;
|
|
1362
|
-
var TypedArraySchemaOptions = {
|
|
1363
|
-
...FromSchemaDefaultOptions,
|
|
1364
|
-
deserialize: [
|
|
1365
|
-
{
|
|
1366
|
-
pattern: { type: "array", format: "TypedArray:Float64Array" },
|
|
1367
|
-
output: Float64Array
|
|
1368
|
-
},
|
|
1369
|
-
{
|
|
1370
|
-
pattern: { type: "array", format: "TypedArray:Float32Array" },
|
|
1371
|
-
output: Float32Array
|
|
1372
|
-
},
|
|
1373
|
-
{
|
|
1374
|
-
pattern: { type: "array", format: "TypedArray:Float16Array" },
|
|
1375
|
-
output: Float16Array
|
|
1376
|
-
},
|
|
1377
|
-
{
|
|
1378
|
-
pattern: { type: "array", format: "TypedArray:Int16Array" },
|
|
1379
|
-
output: Int16Array
|
|
1380
|
-
},
|
|
1381
|
-
{
|
|
1382
|
-
pattern: { type: "array", format: "TypedArray:Int8Array" },
|
|
1383
|
-
output: Int8Array
|
|
1384
|
-
},
|
|
1385
|
-
{
|
|
1386
|
-
pattern: { type: "array", format: "TypedArray:Uint8Array" },
|
|
1387
|
-
output: Uint8Array
|
|
1388
|
-
},
|
|
1389
|
-
{
|
|
1390
|
-
pattern: { type: "array", format: "TypedArray:Uint16Array" },
|
|
1391
|
-
output: Uint16Array
|
|
1392
|
-
},
|
|
1393
|
-
{
|
|
1394
|
-
pattern: { type: "array", format: "TypedArray" },
|
|
1395
|
-
output: TypedArrayType
|
|
1396
|
-
}
|
|
1397
|
-
]
|
|
1398
|
-
};
|
|
1399
|
-
var TypedArraySchema = (annotations = {}) => {
|
|
1400
|
-
return {
|
|
1401
|
-
type: "array",
|
|
1402
|
-
format: "TypedArray",
|
|
1403
|
-
title: "Typed Array",
|
|
1404
|
-
description: "A typed array (Float32Array, Int8Array, etc.)",
|
|
1405
|
-
...annotations
|
|
1406
|
-
};
|
|
1407
|
-
};
|
|
1408
|
-
|
|
1409
|
-
// src/vector/Tensor.ts
|
|
1410
|
-
var TensorType = {
|
|
1411
|
-
FLOAT16: "float16",
|
|
1412
|
-
FLOAT32: "float32",
|
|
1413
|
-
FLOAT64: "float64",
|
|
1414
|
-
INT8: "int8",
|
|
1415
|
-
UINT8: "uint8",
|
|
1416
|
-
INT16: "int16",
|
|
1417
|
-
UINT16: "uint16"
|
|
1418
|
-
};
|
|
1419
|
-
var TensorSchema = (annotations = {}) => ({
|
|
1420
|
-
type: "object",
|
|
1421
|
-
properties: {
|
|
1422
|
-
type: {
|
|
1423
|
-
type: "string",
|
|
1424
|
-
enum: Object.values(TensorType),
|
|
1425
|
-
title: "Type",
|
|
1426
|
-
description: "The type of the tensor"
|
|
1427
|
-
},
|
|
1428
|
-
data: TypedArraySchema({
|
|
1429
|
-
title: "Data",
|
|
1430
|
-
description: "The data of the tensor"
|
|
1431
|
-
}),
|
|
1432
|
-
shape: {
|
|
1433
|
-
type: "array",
|
|
1434
|
-
items: { type: "number" },
|
|
1435
|
-
title: "Shape",
|
|
1436
|
-
description: "The shape of the tensor (dimensions)",
|
|
1437
|
-
minItems: 1,
|
|
1438
|
-
default: [1]
|
|
1439
|
-
},
|
|
1440
|
-
normalized: {
|
|
1441
|
-
type: "boolean",
|
|
1442
|
-
title: "Normalized",
|
|
1443
|
-
description: "Whether the tensor data is normalized",
|
|
1444
|
-
default: false
|
|
1445
|
-
}
|
|
1446
|
-
},
|
|
1447
|
-
required: ["data"],
|
|
1448
|
-
additionalProperties: false,
|
|
1449
|
-
...annotations
|
|
1450
|
-
});
|
|
1451
|
-
// src/vector/TypedArrayUtils.ts
|
|
1452
|
-
var WIDTH_RANK = {
|
|
1453
|
-
Float64Array: 6,
|
|
1454
|
-
Float32Array: 5,
|
|
1455
|
-
Float16Array: 4,
|
|
1456
|
-
Int16Array: 3,
|
|
1457
|
-
Uint16Array: 3,
|
|
1458
|
-
Int8Array: 2,
|
|
1459
|
-
Uint8Array: 2
|
|
1460
|
-
};
|
|
1461
|
-
function getWidthRank(arr) {
|
|
1462
|
-
return WIDTH_RANK[arr.constructor.name] ?? 0;
|
|
1463
|
-
}
|
|
1464
|
-
function widestConstructor(sources) {
|
|
1465
|
-
let best = sources[0];
|
|
1466
|
-
for (let i = 1;i < sources.length; i++) {
|
|
1467
|
-
if (getWidthRank(sources[i]) > getWidthRank(best))
|
|
1468
|
-
best = sources[i];
|
|
1469
|
-
}
|
|
1470
|
-
return best.constructor;
|
|
1471
|
-
}
|
|
1472
|
-
function createTypedArrayFrom(sources, values) {
|
|
1473
|
-
const Ctor = widestConstructor(sources);
|
|
1474
|
-
const result = new Ctor(values.length);
|
|
1475
|
-
for (let i = 0;i < values.length; i++)
|
|
1476
|
-
result[i] = values[i];
|
|
1477
|
-
return result;
|
|
1478
|
-
}
|
|
1479
|
-
// src/vector/VectorSimilarityUtils.ts
|
|
1480
|
-
function cosineSimilarity(a, b) {
|
|
1481
|
-
if (a.length !== b.length) {
|
|
1482
|
-
throw new Error("Vectors must have the same length");
|
|
1483
|
-
}
|
|
1484
|
-
let dotProduct = 0;
|
|
1485
|
-
let normA = 0;
|
|
1486
|
-
let normB = 0;
|
|
1487
|
-
for (let i = 0;i < a.length; i++) {
|
|
1488
|
-
dotProduct += a[i] * b[i];
|
|
1489
|
-
normA += a[i] * a[i];
|
|
1490
|
-
normB += b[i] * b[i];
|
|
1491
|
-
}
|
|
1492
|
-
const denominator = Math.sqrt(normA) * Math.sqrt(normB);
|
|
1493
|
-
if (denominator === 0) {
|
|
1494
|
-
return 0;
|
|
1495
|
-
}
|
|
1496
|
-
return dotProduct / denominator;
|
|
1497
|
-
}
|
|
1498
|
-
function jaccardSimilarity(a, b) {
|
|
1499
|
-
if (a.length !== b.length) {
|
|
1500
|
-
throw new Error("Vectors must have the same length");
|
|
1501
|
-
}
|
|
1502
|
-
let globalMin = a[0];
|
|
1503
|
-
for (let i = 0;i < a.length; i++) {
|
|
1504
|
-
globalMin = Math.min(globalMin, a[i], b[i]);
|
|
1505
|
-
}
|
|
1506
|
-
const shift = globalMin < 0 ? -globalMin : 0;
|
|
1507
|
-
let minSum = 0;
|
|
1508
|
-
let maxSum = 0;
|
|
1509
|
-
for (let i = 0;i < a.length; i++) {
|
|
1510
|
-
const shiftedA = a[i] + shift;
|
|
1511
|
-
const shiftedB = b[i] + shift;
|
|
1512
|
-
minSum += Math.min(shiftedA, shiftedB);
|
|
1513
|
-
maxSum += Math.max(shiftedA, shiftedB);
|
|
1514
|
-
}
|
|
1515
|
-
return maxSum === 0 ? 0 : minSum / maxSum;
|
|
1516
|
-
}
|
|
1517
|
-
function hammingDistance(a, b) {
|
|
1518
|
-
if (a.length !== b.length) {
|
|
1519
|
-
throw new Error("Vectors must have the same length");
|
|
1520
|
-
}
|
|
1521
|
-
let differences = 0;
|
|
1522
|
-
for (let i = 0;i < a.length; i++) {
|
|
1523
|
-
if (a[i] !== b[i]) {
|
|
1524
|
-
differences++;
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
return differences / a.length;
|
|
1528
|
-
}
|
|
1529
|
-
function hammingSimilarity(a, b) {
|
|
1530
|
-
return 1 - hammingDistance(a, b);
|
|
1531
|
-
}
|
|
1532
|
-
// src/vector/VectorUtils.ts
|
|
1533
|
-
function magnitude(arr) {
|
|
1534
|
-
return Math.sqrt(arr.reduce((acc, val) => acc + val * val, 0));
|
|
1535
|
-
}
|
|
1536
|
-
function inner(arr1, arr2) {
|
|
1537
|
-
if (arr1.length !== arr2.length) {
|
|
1538
|
-
throw new Error("Vectors must have the same length to compute inner product.");
|
|
1539
|
-
}
|
|
1540
|
-
return arr1.reduce((acc, val, i) => acc + val * arr2[i], 0);
|
|
1541
|
-
}
|
|
1542
|
-
function normalize(vector, throwOnZero = true, float32 = false) {
|
|
1543
|
-
const mag = magnitude(vector);
|
|
1544
|
-
if (mag === 0) {
|
|
1545
|
-
if (throwOnZero) {
|
|
1546
|
-
throw new Error("Cannot normalize a zero vector.");
|
|
1547
|
-
}
|
|
1548
|
-
return vector;
|
|
1549
|
-
}
|
|
1550
|
-
const normalized = Array.from(vector).map((val) => Number(val) / mag);
|
|
1551
|
-
if (float32) {
|
|
1552
|
-
return new Float32Array(normalized);
|
|
1553
|
-
}
|
|
1554
|
-
if (vector instanceof Float64Array) {
|
|
1555
|
-
return new Float64Array(normalized);
|
|
1556
|
-
}
|
|
1557
|
-
if (vector instanceof Float16Array) {
|
|
1558
|
-
return new Float16Array(normalized);
|
|
1559
|
-
}
|
|
1560
|
-
if (vector instanceof Float32Array) {
|
|
1561
|
-
return new Float32Array(normalized);
|
|
1562
|
-
}
|
|
1563
|
-
if (vector instanceof Int8Array) {
|
|
1564
|
-
return new Int8Array(normalized);
|
|
1565
|
-
}
|
|
1566
|
-
if (vector instanceof Uint8Array) {
|
|
1567
|
-
return new Uint8Array(normalized);
|
|
1568
|
-
}
|
|
1569
|
-
if (vector instanceof Int16Array) {
|
|
1570
|
-
return new Int16Array(normalized);
|
|
1571
|
-
}
|
|
1572
|
-
if (vector instanceof Uint16Array) {
|
|
1573
|
-
return new Uint16Array(normalized);
|
|
1574
|
-
}
|
|
1575
|
-
return new Float32Array(normalized);
|
|
1576
|
-
}
|
|
1577
|
-
function normalizeNumberArray(values, throwOnZero = false) {
|
|
1578
|
-
const norm = magnitude(values);
|
|
1579
|
-
if (norm === 0) {
|
|
1580
|
-
if (throwOnZero) {
|
|
1581
|
-
throw new Error("Cannot normalize a zero vector.");
|
|
1582
|
-
}
|
|
1583
|
-
return values;
|
|
1584
|
-
}
|
|
1585
|
-
return values.map((v) => v / norm);
|
|
1586
|
-
}
|
|
1587
739
|
// src/worker/WorkerManager.ts
|
|
1588
740
|
class WorkerManager {
|
|
1589
741
|
workers = new Map;
|
|
@@ -2213,70 +1365,6 @@ function getTelemetryProvider() {
|
|
|
2213
1365
|
function setTelemetryProvider(provider) {
|
|
2214
1366
|
globalServiceRegistry.registerInstance(TELEMETRY_PROVIDER, provider);
|
|
2215
1367
|
}
|
|
2216
|
-
// src/compress/compress.node.ts
|
|
2217
|
-
import { promisify } from "util";
|
|
2218
|
-
import zlib from "zlib";
|
|
2219
|
-
async function compress(input, algorithm = "gzip") {
|
|
2220
|
-
const compressFn = algorithm === "br" ? zlib.brotliCompress : zlib.gzip;
|
|
2221
|
-
const compressAsync = promisify(compressFn);
|
|
2222
|
-
const compressAsyncTyped = compressAsync;
|
|
2223
|
-
const sourceBuffer = Buffer.isBuffer(input) ? input : Buffer.from(input);
|
|
2224
|
-
const result = await compressAsyncTyped(sourceBuffer);
|
|
2225
|
-
return new Uint8Array(result.buffer, result.byteOffset, result.byteLength);
|
|
2226
|
-
}
|
|
2227
|
-
async function decompress(input, algorithm = "gzip") {
|
|
2228
|
-
const decompressFn = algorithm === "br" ? zlib.brotliDecompress : zlib.gunzip;
|
|
2229
|
-
const decompressAsync = promisify(decompressFn);
|
|
2230
|
-
const decompressAsyncTyped = decompressAsync;
|
|
2231
|
-
const sourceBuffer = Buffer.isBuffer(input) ? input : Buffer.from(input);
|
|
2232
|
-
const resultBuffer = await decompressAsyncTyped(sourceBuffer);
|
|
2233
|
-
return resultBuffer.toString();
|
|
2234
|
-
}
|
|
2235
|
-
// src/media/image.ts
|
|
2236
|
-
function parseDataUri(dataUri) {
|
|
2237
|
-
const match = dataUri.match(/^data:([^;]+);base64,(.+)$/);
|
|
2238
|
-
if (!match) {
|
|
2239
|
-
throw new Error("Invalid base64 data URI");
|
|
2240
|
-
}
|
|
2241
|
-
return {
|
|
2242
|
-
mimeType: match[1],
|
|
2243
|
-
base64: match[2]
|
|
2244
|
-
};
|
|
2245
|
-
}
|
|
2246
|
-
|
|
2247
|
-
// src/media/image.node.ts
|
|
2248
|
-
async function dataUriToBlob(string) {
|
|
2249
|
-
const { mimeType, base64 } = parseDataUri(string);
|
|
2250
|
-
const binary = atob(base64);
|
|
2251
|
-
const bytes = new Uint8Array(binary.length);
|
|
2252
|
-
for (let i = 0;i < binary.length; i++) {
|
|
2253
|
-
bytes[i] = binary.charCodeAt(i);
|
|
2254
|
-
}
|
|
2255
|
-
return new Blob([bytes], { type: mimeType });
|
|
2256
|
-
}
|
|
2257
|
-
async function convertImageDataToUseableForm(imageData, supports) {
|
|
2258
|
-
if (imageData === null || imageData === undefined) {
|
|
2259
|
-
throw new Error("Image data is null or undefined");
|
|
2260
|
-
}
|
|
2261
|
-
if (supports.includes("Blob") && imageData instanceof Blob) {
|
|
2262
|
-
return imageData;
|
|
2263
|
-
}
|
|
2264
|
-
if (supports.includes("ImageBinary") && typeof imageData === "object" && "data" in imageData && "width" in imageData && "height" in imageData && "channels" in imageData) {
|
|
2265
|
-
return {
|
|
2266
|
-
data: imageData.data,
|
|
2267
|
-
width: imageData.width,
|
|
2268
|
-
height: imageData.height,
|
|
2269
|
-
channels: imageData.channels
|
|
2270
|
-
};
|
|
2271
|
-
}
|
|
2272
|
-
if (supports.includes("Blob") && typeof imageData === "string") {
|
|
2273
|
-
return await dataUriToBlob(imageData);
|
|
2274
|
-
}
|
|
2275
|
-
if (supports.includes("DataUri") && typeof imageData === "string" && imageData.startsWith("data:")) {
|
|
2276
|
-
return imageData;
|
|
2277
|
-
}
|
|
2278
|
-
throw new Error(`Unsupported image data type: ${typeof imageData}`);
|
|
2279
|
-
}
|
|
2280
1368
|
// src/worker/Worker.node.ts
|
|
2281
1369
|
import { Worker as NodeWorker, isMainThread, parentPort } from "worker_threads";
|
|
2282
1370
|
import { pathToFileURL } from "url";
|
|
@@ -2514,19 +1602,9 @@ export {
|
|
|
2514
1602
|
serialize,
|
|
2515
1603
|
resolveCredential,
|
|
2516
1604
|
registerInputResolver,
|
|
2517
|
-
parsePartialJson,
|
|
2518
|
-
parseDataUri,
|
|
2519
1605
|
parentPort,
|
|
2520
1606
|
objectOfArraysAsArrayOfObjects,
|
|
2521
|
-
normalizeNumberArray,
|
|
2522
|
-
normalize,
|
|
2523
1607
|
makeFingerprint,
|
|
2524
|
-
magnitude,
|
|
2525
|
-
jaccardSimilarity,
|
|
2526
|
-
isTypedArray,
|
|
2527
|
-
inner,
|
|
2528
|
-
hammingSimilarity,
|
|
2529
|
-
hammingDistance,
|
|
2530
1608
|
globalServiceRegistry,
|
|
2531
1609
|
globalContainer,
|
|
2532
1610
|
getTelemetryProvider,
|
|
@@ -2538,12 +1616,7 @@ export {
|
|
|
2538
1616
|
deriveKey,
|
|
2539
1617
|
deepEqual,
|
|
2540
1618
|
decrypt,
|
|
2541
|
-
decompress,
|
|
2542
|
-
createTypedArrayFrom,
|
|
2543
1619
|
createServiceToken,
|
|
2544
|
-
cosineSimilarity,
|
|
2545
|
-
convertImageDataToUseableForm,
|
|
2546
|
-
compress,
|
|
2547
1620
|
collectPropertyValues,
|
|
2548
1621
|
bufToBase64,
|
|
2549
1622
|
base64ToBuf,
|
|
@@ -2552,27 +1625,17 @@ export {
|
|
|
2552
1625
|
Worker,
|
|
2553
1626
|
WORKER_SERVER,
|
|
2554
1627
|
WORKER_MANAGER,
|
|
2555
|
-
TypedArraySchema,
|
|
2556
|
-
TensorType,
|
|
2557
|
-
TensorSchema,
|
|
2558
1628
|
TELEMETRY_PROVIDER,
|
|
2559
1629
|
SpanStatusCode,
|
|
2560
1630
|
ServiceRegistry,
|
|
2561
1631
|
OTelTelemetryProvider,
|
|
2562
1632
|
NullLogger,
|
|
2563
1633
|
NoopTelemetryProvider,
|
|
2564
|
-
NodeDoesntExistError,
|
|
2565
|
-
NodeAlreadyExistsError,
|
|
2566
1634
|
LOGGER,
|
|
2567
1635
|
InMemoryCredentialStore,
|
|
2568
1636
|
INPUT_RESOLVERS,
|
|
2569
|
-
Graph,
|
|
2570
|
-
FromSchemaDefaultOptions,
|
|
2571
1637
|
EventEmitter,
|
|
2572
1638
|
EnvCredentialStore,
|
|
2573
|
-
DirectedGraph,
|
|
2574
|
-
DirectedAcyclicGraph,
|
|
2575
|
-
CycleError,
|
|
2576
1639
|
Container,
|
|
2577
1640
|
ConsoleTelemetryProvider,
|
|
2578
1641
|
ConsoleLogger,
|
|
@@ -2581,4 +1644,4 @@ export {
|
|
|
2581
1644
|
BaseError
|
|
2582
1645
|
};
|
|
2583
1646
|
|
|
2584
|
-
//# debugId=
|
|
1647
|
+
//# debugId=542A5A44460369BC64756E2164756E21
|