@workglow/util 0.0.122 → 0.0.124
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 +772 -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/browser.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,86 +1365,6 @@ function getTelemetryProvider() {
|
|
|
2213
1365
|
function setTelemetryProvider(provider) {
|
|
2214
1366
|
globalServiceRegistry.registerInstance(TELEMETRY_PROVIDER, provider);
|
|
2215
1367
|
}
|
|
2216
|
-
// src/compress/compress.browser.ts
|
|
2217
|
-
async function compress(input, algorithm = "gzip") {
|
|
2218
|
-
const sourceBlob = new Blob([typeof input === "string" ? input : new Uint8Array(input)]);
|
|
2219
|
-
const compressedStream = sourceBlob.stream().pipeThrough(new CompressionStream(algorithm));
|
|
2220
|
-
const compressedBuffer = await new Response(compressedStream).arrayBuffer();
|
|
2221
|
-
return new Uint8Array(compressedBuffer);
|
|
2222
|
-
}
|
|
2223
|
-
async function decompress(input, algorithm = "gzip") {
|
|
2224
|
-
const sourceBlob = new Blob([new Uint8Array(input)]);
|
|
2225
|
-
const decompressedStream = sourceBlob.stream().pipeThrough(new DecompressionStream(algorithm));
|
|
2226
|
-
return await new Response(decompressedStream).text();
|
|
2227
|
-
}
|
|
2228
|
-
// src/media/image.ts
|
|
2229
|
-
function parseDataUri(dataUri) {
|
|
2230
|
-
const match = dataUri.match(/^data:([^;]+);base64,(.+)$/);
|
|
2231
|
-
if (!match) {
|
|
2232
|
-
throw new Error("Invalid base64 data URI");
|
|
2233
|
-
}
|
|
2234
|
-
return {
|
|
2235
|
-
mimeType: match[1],
|
|
2236
|
-
base64: match[2]
|
|
2237
|
-
};
|
|
2238
|
-
}
|
|
2239
|
-
|
|
2240
|
-
// src/media/image.browser.ts
|
|
2241
|
-
var convertBlobToOffscreenCanvas = async (blob) => {
|
|
2242
|
-
const img = await createImageBitmap(blob);
|
|
2243
|
-
const ctx = new OffscreenCanvas(img.width, img.height).getContext("2d");
|
|
2244
|
-
if (!ctx) {
|
|
2245
|
-
throw new Error("Failed to get context.");
|
|
2246
|
-
}
|
|
2247
|
-
ctx.drawImage(img, 0, 0);
|
|
2248
|
-
return ctx.canvas;
|
|
2249
|
-
};
|
|
2250
|
-
function dataUriToBlob(dataUri) {
|
|
2251
|
-
const { mimeType, base64 } = parseDataUri(dataUri);
|
|
2252
|
-
const binary = atob(base64);
|
|
2253
|
-
const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
2254
|
-
const blob = new Blob([bytes], { type: mimeType });
|
|
2255
|
-
return blob;
|
|
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("ImageBitmap") && imageData instanceof ImageBitmap) {
|
|
2262
|
-
return imageData;
|
|
2263
|
-
}
|
|
2264
|
-
if (supports.includes("VideoFrame") && imageData instanceof VideoFrame) {
|
|
2265
|
-
return imageData;
|
|
2266
|
-
}
|
|
2267
|
-
if (supports.includes("Blob") && imageData instanceof Blob) {
|
|
2268
|
-
return imageData;
|
|
2269
|
-
}
|
|
2270
|
-
if (supports.includes("ImageBinary") && typeof imageData === "object" && "data" in imageData && "width" in imageData && "height" in imageData && "channels" in imageData) {
|
|
2271
|
-
return imageData;
|
|
2272
|
-
}
|
|
2273
|
-
if (supports.includes("ImageBitmap") && imageData instanceof Blob) {
|
|
2274
|
-
return createImageBitmap(imageData);
|
|
2275
|
-
}
|
|
2276
|
-
if (supports.includes("OffscreenCanvas") && imageData instanceof Blob) {
|
|
2277
|
-
return await convertBlobToOffscreenCanvas(imageData);
|
|
2278
|
-
}
|
|
2279
|
-
if (supports.includes("ImageBitmap") && imageData instanceof OffscreenCanvas) {
|
|
2280
|
-
return imageData.transferToImageBitmap();
|
|
2281
|
-
}
|
|
2282
|
-
if (supports.includes("ImageBitmap") && typeof imageData === "string") {
|
|
2283
|
-
return createImageBitmap(dataUriToBlob(imageData));
|
|
2284
|
-
}
|
|
2285
|
-
if (supports.includes("OffscreenCanvas") && typeof imageData === "string") {
|
|
2286
|
-
return convertBlobToOffscreenCanvas(dataUriToBlob(imageData));
|
|
2287
|
-
}
|
|
2288
|
-
if (supports.includes("Blob") && typeof imageData === "string") {
|
|
2289
|
-
return dataUriToBlob(imageData);
|
|
2290
|
-
}
|
|
2291
|
-
if (supports.includes("DataUri") && typeof imageData === "string" && imageData.startsWith("data:")) {
|
|
2292
|
-
return imageData;
|
|
2293
|
-
}
|
|
2294
|
-
throw new Error(`Unsupported image data type: ${typeof imageData} `);
|
|
2295
|
-
}
|
|
2296
1368
|
// src/worker/WorkerServerBase.ts
|
|
2297
1369
|
var WORKER_SERVER = createServiceToken("worker.server");
|
|
2298
1370
|
function extractTransferables(obj) {
|
|
@@ -2508,19 +1580,9 @@ export {
|
|
|
2508
1580
|
serialize,
|
|
2509
1581
|
resolveCredential,
|
|
2510
1582
|
registerInputResolver,
|
|
2511
|
-
parsePartialJson,
|
|
2512
|
-
parseDataUri,
|
|
2513
1583
|
parentPort,
|
|
2514
1584
|
objectOfArraysAsArrayOfObjects,
|
|
2515
|
-
normalizeNumberArray,
|
|
2516
|
-
normalize,
|
|
2517
1585
|
makeFingerprint,
|
|
2518
|
-
magnitude,
|
|
2519
|
-
jaccardSimilarity,
|
|
2520
|
-
isTypedArray,
|
|
2521
|
-
inner,
|
|
2522
|
-
hammingSimilarity,
|
|
2523
|
-
hammingDistance,
|
|
2524
1586
|
globalServiceRegistry,
|
|
2525
1587
|
globalContainer,
|
|
2526
1588
|
getTelemetryProvider,
|
|
@@ -2532,12 +1594,7 @@ export {
|
|
|
2532
1594
|
deriveKey,
|
|
2533
1595
|
deepEqual,
|
|
2534
1596
|
decrypt,
|
|
2535
|
-
decompress,
|
|
2536
|
-
createTypedArrayFrom,
|
|
2537
1597
|
createServiceToken,
|
|
2538
|
-
cosineSimilarity,
|
|
2539
|
-
convertImageDataToUseableForm,
|
|
2540
|
-
compress,
|
|
2541
1598
|
collectPropertyValues,
|
|
2542
1599
|
bufToBase64,
|
|
2543
1600
|
base64ToBuf,
|
|
@@ -2546,27 +1603,17 @@ export {
|
|
|
2546
1603
|
Worker,
|
|
2547
1604
|
WORKER_SERVER,
|
|
2548
1605
|
WORKER_MANAGER,
|
|
2549
|
-
TypedArraySchema,
|
|
2550
|
-
TensorType,
|
|
2551
|
-
TensorSchema,
|
|
2552
1606
|
TELEMETRY_PROVIDER,
|
|
2553
1607
|
SpanStatusCode,
|
|
2554
1608
|
ServiceRegistry,
|
|
2555
1609
|
OTelTelemetryProvider,
|
|
2556
1610
|
NullLogger,
|
|
2557
1611
|
NoopTelemetryProvider,
|
|
2558
|
-
NodeDoesntExistError,
|
|
2559
|
-
NodeAlreadyExistsError,
|
|
2560
1612
|
LOGGER,
|
|
2561
1613
|
InMemoryCredentialStore,
|
|
2562
1614
|
INPUT_RESOLVERS,
|
|
2563
|
-
Graph,
|
|
2564
|
-
FromSchemaDefaultOptions,
|
|
2565
1615
|
EventEmitter,
|
|
2566
1616
|
EnvCredentialStore,
|
|
2567
|
-
DirectedGraph,
|
|
2568
|
-
DirectedAcyclicGraph,
|
|
2569
|
-
CycleError,
|
|
2570
1617
|
Container,
|
|
2571
1618
|
ConsoleTelemetryProvider,
|
|
2572
1619
|
ConsoleLogger,
|
|
@@ -2575,4 +1622,4 @@ export {
|
|
|
2575
1622
|
BaseError
|
|
2576
1623
|
};
|
|
2577
1624
|
|
|
2578
|
-
//# debugId=
|
|
1625
|
+
//# debugId=C665251EA27E791364756E2164756E21
|