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