@langchain/core 1.1.41 → 1.1.42
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/CHANGELOG.md +6 -0
- package/dist/callbacks/base.cjs +3 -3
- package/dist/callbacks/base.cjs.map +1 -1
- package/dist/callbacks/base.js +3 -2
- package/dist/callbacks/base.js.map +1 -1
- package/dist/callbacks/manager.cjs +8 -7
- package/dist/callbacks/manager.cjs.map +1 -1
- package/dist/callbacks/manager.js +2 -1
- package/dist/callbacks/manager.js.map +1 -1
- package/dist/indexing/base.cjs +4 -4
- package/dist/indexing/base.cjs.map +1 -1
- package/dist/indexing/base.js +2 -1
- package/dist/indexing/base.js.map +1 -1
- package/dist/language_models/base.cjs +1 -1
- package/dist/language_models/base.js +1 -1
- package/dist/load/import_map.cjs +2 -0
- package/dist/load/import_map.cjs.map +1 -1
- package/dist/load/import_map.js +2 -0
- package/dist/load/import_map.js.map +1 -1
- package/dist/runnables/base.cjs +3 -2
- package/dist/runnables/base.cjs.map +1 -1
- package/dist/runnables/base.js +2 -1
- package/dist/runnables/base.js.map +1 -1
- package/dist/runnables/graph.cjs +8 -6
- package/dist/runnables/graph.cjs.map +1 -1
- package/dist/runnables/graph.js +3 -1
- package/dist/runnables/graph.js.map +1 -1
- package/dist/utils/uuid/index.cjs +44 -0
- package/dist/utils/uuid/index.cjs.map +1 -0
- package/dist/utils/uuid/index.d.cts +12 -0
- package/dist/utils/uuid/index.d.ts +12 -0
- package/dist/utils/uuid/index.js +28 -0
- package/dist/utils/uuid/index.js.map +1 -0
- package/dist/utils/uuid/max.cjs +6 -0
- package/dist/utils/uuid/max.cjs.map +1 -0
- package/dist/utils/uuid/max.d.cts +5 -0
- package/dist/utils/uuid/max.d.cts.map +1 -0
- package/dist/utils/uuid/max.d.ts +5 -0
- package/dist/utils/uuid/max.d.ts.map +1 -0
- package/dist/utils/uuid/max.js +6 -0
- package/dist/utils/uuid/max.js.map +1 -0
- package/dist/utils/uuid/nil.cjs +6 -0
- package/dist/utils/uuid/nil.cjs.map +1 -0
- package/dist/utils/uuid/nil.d.cts +5 -0
- package/dist/utils/uuid/nil.d.cts.map +1 -0
- package/dist/utils/uuid/nil.d.ts +5 -0
- package/dist/utils/uuid/nil.d.ts.map +1 -0
- package/dist/utils/uuid/nil.js +6 -0
- package/dist/utils/uuid/nil.js.map +1 -0
- package/dist/utils/uuid/parse.cjs +11 -0
- package/dist/utils/uuid/parse.cjs.map +1 -0
- package/dist/utils/uuid/parse.d.cts +7 -0
- package/dist/utils/uuid/parse.d.cts.map +1 -0
- package/dist/utils/uuid/parse.d.ts +7 -0
- package/dist/utils/uuid/parse.d.ts.map +1 -0
- package/dist/utils/uuid/parse.js +11 -0
- package/dist/utils/uuid/parse.js.map +1 -0
- package/dist/utils/uuid/regex.cjs +6 -0
- package/dist/utils/uuid/regex.cjs.map +1 -0
- package/dist/utils/uuid/regex.js +6 -0
- package/dist/utils/uuid/regex.js.map +1 -0
- package/dist/utils/uuid/rng.cjs +9 -0
- package/dist/utils/uuid/rng.cjs.map +1 -0
- package/dist/utils/uuid/rng.js +9 -0
- package/dist/utils/uuid/rng.js.map +1 -0
- package/dist/utils/uuid/sha1.cjs +71 -0
- package/dist/utils/uuid/sha1.cjs.map +1 -0
- package/dist/utils/uuid/sha1.js +71 -0
- package/dist/utils/uuid/sha1.js.map +1 -0
- package/dist/utils/uuid/stringify.cjs +21 -0
- package/dist/utils/uuid/stringify.cjs.map +1 -0
- package/dist/utils/uuid/stringify.d.cts +5 -0
- package/dist/utils/uuid/stringify.d.cts.map +1 -0
- package/dist/utils/uuid/stringify.d.ts +5 -0
- package/dist/utils/uuid/stringify.d.ts.map +1 -0
- package/dist/utils/uuid/stringify.js +20 -0
- package/dist/utils/uuid/stringify.js.map +1 -0
- package/dist/utils/uuid/types.d.cts +26 -0
- package/dist/utils/uuid/types.d.cts.map +1 -0
- package/dist/utils/uuid/types.d.ts +26 -0
- package/dist/utils/uuid/types.d.ts.map +1 -0
- package/dist/utils/uuid/v1.cjs +69 -0
- package/dist/utils/uuid/v1.cjs.map +1 -0
- package/dist/utils/uuid/v1.d.cts +8 -0
- package/dist/utils/uuid/v1.d.cts.map +1 -0
- package/dist/utils/uuid/v1.d.ts +8 -0
- package/dist/utils/uuid/v1.d.ts.map +1 -0
- package/dist/utils/uuid/v1.js +69 -0
- package/dist/utils/uuid/v1.js.map +1 -0
- package/dist/utils/uuid/v35.cjs +36 -0
- package/dist/utils/uuid/v35.cjs.map +1 -0
- package/dist/utils/uuid/v35.js +34 -0
- package/dist/utils/uuid/v35.js.map +1 -0
- package/dist/utils/uuid/v4.cjs +25 -0
- package/dist/utils/uuid/v4.cjs.map +1 -0
- package/dist/utils/uuid/v4.d.cts +8 -0
- package/dist/utils/uuid/v4.d.cts.map +1 -0
- package/dist/utils/uuid/v4.d.ts +8 -0
- package/dist/utils/uuid/v4.d.ts.map +1 -0
- package/dist/utils/uuid/v4.js +25 -0
- package/dist/utils/uuid/v4.js.map +1 -0
- package/dist/utils/uuid/v5.cjs +12 -0
- package/dist/utils/uuid/v5.cjs.map +1 -0
- package/dist/utils/uuid/v5.d.cts +14 -0
- package/dist/utils/uuid/v5.d.cts.map +1 -0
- package/dist/utils/uuid/v5.d.ts +14 -0
- package/dist/utils/uuid/v5.d.ts.map +1 -0
- package/dist/utils/uuid/v5.js +12 -0
- package/dist/utils/uuid/v5.js.map +1 -0
- package/dist/utils/uuid/v7.cjs +57 -0
- package/dist/utils/uuid/v7.cjs.map +1 -0
- package/dist/utils/uuid/v7.d.cts +8 -0
- package/dist/utils/uuid/v7.d.cts.map +1 -0
- package/dist/utils/uuid/v7.d.ts +8 -0
- package/dist/utils/uuid/v7.d.ts.map +1 -0
- package/dist/utils/uuid/v7.js +57 -0
- package/dist/utils/uuid/v7.js.map +1 -0
- package/dist/utils/uuid/validate.cjs +9 -0
- package/dist/utils/uuid/validate.cjs.map +1 -0
- package/dist/utils/uuid/validate.d.cts +5 -0
- package/dist/utils/uuid/validate.d.cts.map +1 -0
- package/dist/utils/uuid/validate.d.ts +5 -0
- package/dist/utils/uuid/validate.d.ts.map +1 -0
- package/dist/utils/uuid/validate.js +9 -0
- package/dist/utils/uuid/validate.js.map +1 -0
- package/dist/utils/uuid/version.cjs +10 -0
- package/dist/utils/uuid/version.cjs.map +1 -0
- package/dist/utils/uuid/version.d.cts +5 -0
- package/dist/utils/uuid/version.d.cts.map +1 -0
- package/dist/utils/uuid/version.d.ts +5 -0
- package/dist/utils/uuid/version.d.ts.map +1 -0
- package/dist/utils/uuid/version.js +10 -0
- package/dist/utils/uuid/version.js.map +1 -0
- package/package.json +12 -2
- package/utils/uuid.cjs +1 -0
- package/utils/uuid.d.cts +1 -0
- package/utils/uuid.d.ts +1 -0
- package/utils/uuid.js +1 -0
package/dist/runnables/graph.cjs
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_validate = require("../utils/uuid/validate.cjs");
|
|
4
|
+
const require_v4 = require("../utils/uuid/v4.cjs");
|
|
5
|
+
require("../utils/uuid/index.cjs");
|
|
3
6
|
const require_utils = require("./utils.cjs");
|
|
4
7
|
const require_graph_mermaid = require("./graph_mermaid.cjs");
|
|
5
8
|
const require_utils_json_schema = require("../utils/json_schema.cjs");
|
|
6
|
-
let uuid = require("uuid");
|
|
7
9
|
//#region src/runnables/graph.ts
|
|
8
10
|
var graph_exports = /* @__PURE__ */ require_runtime.__exportAll({ Graph: () => Graph });
|
|
9
11
|
function nodeDataStr(id, data) {
|
|
10
|
-
if (id !== void 0 && !
|
|
12
|
+
if (id !== void 0 && !require_validate.default(id)) return id;
|
|
11
13
|
else if (require_utils.isRunnableInterface(data)) try {
|
|
12
14
|
let dataStr = data.getName();
|
|
13
15
|
dataStr = dataStr.startsWith("Runnable") ? dataStr.slice(8) : dataStr;
|
|
@@ -43,7 +45,7 @@ var Graph = class Graph {
|
|
|
43
45
|
toJSON() {
|
|
44
46
|
const stableNodeIds = {};
|
|
45
47
|
Object.values(this.nodes).forEach((node, i) => {
|
|
46
|
-
stableNodeIds[node.id] =
|
|
48
|
+
stableNodeIds[node.id] = require_validate.default(node.id) ? i : node.id;
|
|
47
49
|
});
|
|
48
50
|
return {
|
|
49
51
|
nodes: Object.values(this.nodes).map((node) => ({
|
|
@@ -63,7 +65,7 @@ var Graph = class Graph {
|
|
|
63
65
|
}
|
|
64
66
|
addNode(data, id, metadata) {
|
|
65
67
|
if (id !== void 0 && this.nodes[id] !== void 0) throw new Error(`Node with id ${id} already exists`);
|
|
66
|
-
const nodeId = id ??
|
|
68
|
+
const nodeId = id ?? require_v4.default();
|
|
67
69
|
const node = {
|
|
68
70
|
id: nodeId,
|
|
69
71
|
data,
|
|
@@ -101,7 +103,7 @@ var Graph = class Graph {
|
|
|
101
103
|
*/
|
|
102
104
|
extend(graph, prefix = "") {
|
|
103
105
|
let finalPrefix = prefix;
|
|
104
|
-
if (Object.values(graph.nodes).map((node) => node.id).every(
|
|
106
|
+
if (Object.values(graph.nodes).map((node) => node.id).every(require_validate.default)) finalPrefix = "";
|
|
105
107
|
const prefixed = (id) => {
|
|
106
108
|
return finalPrefix ? `${finalPrefix}:${id}` : id;
|
|
107
109
|
};
|
|
@@ -149,7 +151,7 @@ var Graph = class Graph {
|
|
|
149
151
|
});
|
|
150
152
|
const getNodeId = (nodeId) => {
|
|
151
153
|
const label = nodeLabels[nodeId];
|
|
152
|
-
if (
|
|
154
|
+
if (require_validate.default(nodeId) && nodeLabelCounts.get(label) === 1) return label;
|
|
153
155
|
else return nodeId;
|
|
154
156
|
};
|
|
155
157
|
return new Graph({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph.cjs","names":["isRunnableInterface","toJsonSchema","isUuid","drawMermaid","drawMermaidImage"],"sources":["../../src/runnables/graph.ts"],"sourcesContent":["import { v4 as uuidv4, validate as isUuid } from \"uuid\";\nimport type {\n RunnableInterface,\n RunnableIOSchema,\n Node,\n Edge,\n} from \"./types.js\";\nimport { isRunnableInterface } from \"./utils.js\";\nimport { drawMermaid, drawMermaidImage } from \"./graph_mermaid.js\";\nimport { toJsonSchema } from \"../utils/json_schema.js\";\n\nexport { Node, Edge };\n\nfunction nodeDataStr(\n id: string | undefined,\n data: RunnableInterface | RunnableIOSchema\n): string {\n if (id !== undefined && !isUuid(id)) {\n return id;\n } else if (isRunnableInterface(data)) {\n try {\n let dataStr = data.getName();\n dataStr = dataStr.startsWith(\"Runnable\")\n ? dataStr.slice(\"Runnable\".length)\n : dataStr;\n return dataStr;\n } catch {\n return data.getName();\n }\n } else {\n return data.name ?? \"UnknownSchema\";\n }\n}\n\nfunction nodeDataJson(node: Node) {\n // if node.data implements Runnable\n if (isRunnableInterface(node.data)) {\n return {\n type: \"runnable\",\n data: {\n id: node.data.lc_id,\n name: node.data.getName(),\n },\n };\n } else {\n return {\n type: \"schema\",\n data: { ...toJsonSchema(node.data.schema), title: node.data.name },\n };\n }\n}\n\nexport class Graph {\n nodes: Record<string, Node> = {};\n\n edges: Edge[] = [];\n\n constructor(params?: { nodes: Record<string, Node>; edges: Edge[] }) {\n this.nodes = params?.nodes ?? this.nodes;\n this.edges = params?.edges ?? this.edges;\n }\n\n // Convert the graph to a JSON-serializable format.\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n toJSON(): Record<string, any> {\n const stableNodeIds: Record<string, string | number> = {};\n Object.values(this.nodes).forEach((node, i) => {\n stableNodeIds[node.id] = isUuid(node.id) ? i : node.id;\n });\n\n return {\n nodes: Object.values(this.nodes).map((node) => ({\n id: stableNodeIds[node.id],\n ...nodeDataJson(node),\n })),\n edges: this.edges.map((edge) => {\n const item: Record<string, unknown> = {\n source: stableNodeIds[edge.source],\n target: stableNodeIds[edge.target],\n };\n\n if (typeof edge.data !== \"undefined\") {\n item.data = edge.data;\n }\n\n if (typeof edge.conditional !== \"undefined\") {\n item.conditional = edge.conditional;\n }\n return item;\n }),\n };\n }\n\n addNode(\n data: RunnableInterface | RunnableIOSchema,\n id?: string,\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n metadata?: Record<string, any>\n ): Node {\n if (id !== undefined && this.nodes[id] !== undefined) {\n throw new Error(`Node with id ${id} already exists`);\n }\n const nodeId = id ?? uuidv4();\n const node: Node = {\n id: nodeId,\n data,\n name: nodeDataStr(id, data),\n metadata,\n };\n this.nodes[nodeId] = node;\n return node;\n }\n\n removeNode(node: Node): void {\n // Remove the node from the nodes map\n delete this.nodes[node.id];\n\n // Filter out edges connected to the node\n this.edges = this.edges.filter(\n (edge) => edge.source !== node.id && edge.target !== node.id\n );\n }\n\n addEdge(\n source: Node,\n target: Node,\n data?: string,\n conditional?: boolean\n ): Edge {\n if (this.nodes[source.id] === undefined) {\n throw new Error(`Source node ${source.id} not in graph`);\n }\n if (this.nodes[target.id] === undefined) {\n throw new Error(`Target node ${target.id} not in graph`);\n }\n const edge: Edge = {\n source: source.id,\n target: target.id,\n data,\n conditional,\n };\n this.edges.push(edge);\n return edge;\n }\n\n firstNode(): Node | undefined {\n return _firstNode(this);\n }\n\n lastNode(): Node | undefined {\n return _lastNode(this);\n }\n\n /**\n * Add all nodes and edges from another graph.\n * Note this doesn't check for duplicates, nor does it connect the graphs.\n */\n extend(graph: Graph, prefix = \"\") {\n let finalPrefix = prefix;\n const nodeIds = Object.values(graph.nodes).map((node) => node.id);\n if (nodeIds.every(isUuid)) {\n finalPrefix = \"\";\n }\n\n const prefixed = (id: string) => {\n return finalPrefix ? `${finalPrefix}:${id}` : id;\n };\n\n Object.entries(graph.nodes).forEach(([key, value]) => {\n this.nodes[prefixed(key)] = { ...value, id: prefixed(key) };\n });\n\n const newEdges = graph.edges.map((edge) => {\n return {\n ...edge,\n source: prefixed(edge.source),\n target: prefixed(edge.target),\n };\n });\n // Add all edges from the other graph\n this.edges = [...this.edges, ...newEdges];\n const first = graph.firstNode();\n const last = graph.lastNode();\n return [\n first ? { id: prefixed(first.id), data: first.data } : undefined,\n last ? { id: prefixed(last.id), data: last.data } : undefined,\n ];\n }\n\n trimFirstNode(): void {\n const firstNode = this.firstNode();\n if (firstNode && _firstNode(this, [firstNode.id])) {\n this.removeNode(firstNode);\n }\n }\n\n trimLastNode(): void {\n const lastNode = this.lastNode();\n if (lastNode && _lastNode(this, [lastNode.id])) {\n this.removeNode(lastNode);\n }\n }\n\n /**\n * Return a new graph with all nodes re-identified,\n * using their unique, readable names where possible.\n */\n reid(): Graph {\n const nodeLabels: Record<string, string> = Object.fromEntries(\n Object.values(this.nodes).map((node) => [node.id, node.name])\n );\n const nodeLabelCounts = new Map<string, number>();\n Object.values(nodeLabels).forEach((label) => {\n nodeLabelCounts.set(label, (nodeLabelCounts.get(label) || 0) + 1);\n });\n\n const getNodeId = (nodeId: string): string => {\n const label = nodeLabels[nodeId];\n if (isUuid(nodeId) && nodeLabelCounts.get(label) === 1) {\n return label;\n } else {\n return nodeId;\n }\n };\n\n return new Graph({\n nodes: Object.fromEntries(\n Object.entries(this.nodes).map(([id, node]) => [\n getNodeId(id),\n { ...node, id: getNodeId(id) },\n ])\n ),\n edges: this.edges.map((edge) => ({\n ...edge,\n source: getNodeId(edge.source),\n target: getNodeId(edge.target),\n })),\n });\n }\n\n drawMermaid(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n }): string {\n const {\n withStyles,\n curveStyle,\n nodeColors = {\n default: \"fill:#f2f0ff,line-height:1.2\",\n first: \"fill-opacity:0\",\n last: \"fill:#bfb6fc\",\n },\n wrapLabelNWords,\n } = params ?? {};\n const graph = this.reid();\n const firstNode = graph.firstNode();\n\n const lastNode = graph.lastNode();\n\n return drawMermaid(graph.nodes, graph.edges, {\n firstNode: firstNode?.id,\n lastNode: lastNode?.id,\n withStyles,\n curveStyle,\n nodeColors,\n wrapLabelNWords,\n });\n }\n\n async drawMermaidPng(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<Blob> {\n const mermaidSyntax = this.drawMermaid(params);\n return drawMermaidImage(mermaidSyntax, {\n backgroundColor: params?.backgroundColor,\n });\n }\n}\n/**\n * Find the single node that is not a target of any edge.\n * Exclude nodes/sources with ids in the exclude list.\n * If there is no such node, or there are multiple, return undefined.\n * When drawing the graph, this node would be the origin.\n */\nfunction _firstNode(graph: Graph, exclude: string[] = []): Node | undefined {\n const targets = new Set(\n graph.edges\n .filter((edge) => !exclude.includes(edge.source))\n .map((edge) => edge.target)\n );\n\n const found: Node[] = [];\n for (const node of Object.values(graph.nodes)) {\n if (!exclude.includes(node.id) && !targets.has(node.id)) {\n found.push(node);\n }\n }\n return found.length === 1 ? found[0] : undefined;\n}\n\n/**\n * Find the single node that is not a source of any edge.\n * Exclude nodes/targets with ids in the exclude list.\n * If there is no such node, or there are multiple, return undefined.\n * When drawing the graph, this node would be the destination.\n */\nfunction _lastNode(graph: Graph, exclude: string[] = []): Node | undefined {\n const sources = new Set(\n graph.edges\n .filter((edge) => !exclude.includes(edge.target))\n .map((edge) => edge.source)\n );\n\n const found: Node[] = [];\n for (const node of Object.values(graph.nodes)) {\n if (!exclude.includes(node.id) && !sources.has(node.id)) {\n found.push(node);\n }\n }\n return found.length === 1 ? found[0] : undefined;\n}\n"],"mappings":";;;;;;;;AAaA,SAAS,YACP,IACA,MACQ;AACR,KAAI,OAAO,KAAA,KAAa,EAAA,GAAA,KAAA,UAAQ,GAAG,CACjC,QAAO;UACEA,cAAAA,oBAAoB,KAAK,CAClC,KAAI;EACF,IAAI,UAAU,KAAK,SAAS;AAC5B,YAAU,QAAQ,WAAW,WAAW,GACpC,QAAQ,MAAM,EAAkB,GAChC;AACJ,SAAO;SACD;AACN,SAAO,KAAK,SAAS;;KAGvB,QAAO,KAAK,QAAQ;;AAIxB,SAAS,aAAa,MAAY;AAEhC,KAAIA,cAAAA,oBAA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chema","uuidv4","drawMermaid","drawMermaidImage"],"sources":["../../src/runnables/graph.ts"],"sourcesContent":["import { v4 as uuidv4, validate as isUuid } from \"../utils/uuid/index.js\";\nimport type {\n RunnableInterface,\n RunnableIOSchema,\n Node,\n Edge,\n} from \"./types.js\";\nimport { isRunnableInterface } from \"./utils.js\";\nimport { drawMermaid, drawMermaidImage } from \"./graph_mermaid.js\";\nimport { toJsonSchema } from \"../utils/json_schema.js\";\n\nexport { Node, Edge };\n\nfunction nodeDataStr(\n id: string | undefined,\n data: RunnableInterface | RunnableIOSchema\n): string {\n if (id !== undefined && !isUuid(id)) {\n return id;\n } else if (isRunnableInterface(data)) {\n try {\n let dataStr = data.getName();\n dataStr = dataStr.startsWith(\"Runnable\")\n ? dataStr.slice(\"Runnable\".length)\n : dataStr;\n return dataStr;\n } catch {\n return data.getName();\n }\n } else {\n return data.name ?? \"UnknownSchema\";\n }\n}\n\nfunction nodeDataJson(node: Node) {\n // if node.data implements Runnable\n if (isRunnableInterface(node.data)) {\n return {\n type: \"runnable\",\n data: {\n id: node.data.lc_id,\n name: node.data.getName(),\n },\n };\n } else {\n return {\n type: \"schema\",\n data: { ...toJsonSchema(node.data.schema), title: node.data.name },\n };\n }\n}\n\nexport class Graph {\n nodes: Record<string, Node> = {};\n\n edges: Edge[] = [];\n\n constructor(params?: { nodes: Record<string, Node>; edges: Edge[] }) {\n this.nodes = params?.nodes ?? this.nodes;\n this.edges = params?.edges ?? this.edges;\n }\n\n // Convert the graph to a JSON-serializable format.\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n toJSON(): Record<string, any> {\n const stableNodeIds: Record<string, string | number> = {};\n Object.values(this.nodes).forEach((node, i) => {\n stableNodeIds[node.id] = isUuid(node.id) ? i : node.id;\n });\n\n return {\n nodes: Object.values(this.nodes).map((node) => ({\n id: stableNodeIds[node.id],\n ...nodeDataJson(node),\n })),\n edges: this.edges.map((edge) => {\n const item: Record<string, unknown> = {\n source: stableNodeIds[edge.source],\n target: stableNodeIds[edge.target],\n };\n\n if (typeof edge.data !== \"undefined\") {\n item.data = edge.data;\n }\n\n if (typeof edge.conditional !== \"undefined\") {\n item.conditional = edge.conditional;\n }\n return item;\n }),\n };\n }\n\n addNode(\n data: RunnableInterface | RunnableIOSchema,\n id?: string,\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n metadata?: Record<string, any>\n ): Node {\n if (id !== undefined && this.nodes[id] !== undefined) {\n throw new Error(`Node with id ${id} already exists`);\n }\n const nodeId = id ?? uuidv4();\n const node: Node = {\n id: nodeId,\n data,\n name: nodeDataStr(id, data),\n metadata,\n };\n this.nodes[nodeId] = node;\n return node;\n }\n\n removeNode(node: Node): void {\n // Remove the node from the nodes map\n delete this.nodes[node.id];\n\n // Filter out edges connected to the node\n this.edges = this.edges.filter(\n (edge) => edge.source !== node.id && edge.target !== node.id\n );\n }\n\n addEdge(\n source: Node,\n target: Node,\n data?: string,\n conditional?: boolean\n ): Edge {\n if (this.nodes[source.id] === undefined) {\n throw new Error(`Source node ${source.id} not in graph`);\n }\n if (this.nodes[target.id] === undefined) {\n throw new Error(`Target node ${target.id} not in graph`);\n }\n const edge: Edge = {\n source: source.id,\n target: target.id,\n data,\n conditional,\n };\n this.edges.push(edge);\n return edge;\n }\n\n firstNode(): Node | undefined {\n return _firstNode(this);\n }\n\n lastNode(): Node | undefined {\n return _lastNode(this);\n }\n\n /**\n * Add all nodes and edges from another graph.\n * Note this doesn't check for duplicates, nor does it connect the graphs.\n */\n extend(graph: Graph, prefix = \"\") {\n let finalPrefix = prefix;\n const nodeIds = Object.values(graph.nodes).map((node) => node.id);\n if (nodeIds.every(isUuid)) {\n finalPrefix = \"\";\n }\n\n const prefixed = (id: string) => {\n return finalPrefix ? `${finalPrefix}:${id}` : id;\n };\n\n Object.entries(graph.nodes).forEach(([key, value]) => {\n this.nodes[prefixed(key)] = { ...value, id: prefixed(key) };\n });\n\n const newEdges = graph.edges.map((edge) => {\n return {\n ...edge,\n source: prefixed(edge.source),\n target: prefixed(edge.target),\n };\n });\n // Add all edges from the other graph\n this.edges = [...this.edges, ...newEdges];\n const first = graph.firstNode();\n const last = graph.lastNode();\n return [\n first ? { id: prefixed(first.id), data: first.data } : undefined,\n last ? { id: prefixed(last.id), data: last.data } : undefined,\n ];\n }\n\n trimFirstNode(): void {\n const firstNode = this.firstNode();\n if (firstNode && _firstNode(this, [firstNode.id])) {\n this.removeNode(firstNode);\n }\n }\n\n trimLastNode(): void {\n const lastNode = this.lastNode();\n if (lastNode && _lastNode(this, [lastNode.id])) {\n this.removeNode(lastNode);\n }\n }\n\n /**\n * Return a new graph with all nodes re-identified,\n * using their unique, readable names where possible.\n */\n reid(): Graph {\n const nodeLabels: Record<string, string> = Object.fromEntries(\n Object.values(this.nodes).map((node) => [node.id, node.name])\n );\n const nodeLabelCounts = new Map<string, number>();\n Object.values(nodeLabels).forEach((label) => {\n nodeLabelCounts.set(label, (nodeLabelCounts.get(label) || 0) + 1);\n });\n\n const getNodeId = (nodeId: string): string => {\n const label = nodeLabels[nodeId];\n if (isUuid(nodeId) && nodeLabelCounts.get(label) === 1) {\n return label;\n } else {\n return nodeId;\n }\n };\n\n return new Graph({\n nodes: Object.fromEntries(\n Object.entries(this.nodes).map(([id, node]) => [\n getNodeId(id),\n { ...node, id: getNodeId(id) },\n ])\n ),\n edges: this.edges.map((edge) => ({\n ...edge,\n source: getNodeId(edge.source),\n target: getNodeId(edge.target),\n })),\n });\n }\n\n drawMermaid(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n }): string {\n const {\n withStyles,\n curveStyle,\n nodeColors = {\n default: \"fill:#f2f0ff,line-height:1.2\",\n first: \"fill-opacity:0\",\n last: \"fill:#bfb6fc\",\n },\n wrapLabelNWords,\n } = params ?? {};\n const graph = this.reid();\n const firstNode = graph.firstNode();\n\n const lastNode = graph.lastNode();\n\n return drawMermaid(graph.nodes, graph.edges, {\n firstNode: firstNode?.id,\n lastNode: lastNode?.id,\n withStyles,\n curveStyle,\n nodeColors,\n wrapLabelNWords,\n });\n }\n\n async drawMermaidPng(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<Blob> {\n const mermaidSyntax = this.drawMermaid(params);\n return drawMermaidImage(mermaidSyntax, {\n backgroundColor: params?.backgroundColor,\n });\n }\n}\n/**\n * Find the single node that is not a target of any edge.\n * Exclude nodes/sources with ids in the exclude list.\n * If there is no such node, or there are multiple, return undefined.\n * When drawing the graph, this node would be the origin.\n */\nfunction _firstNode(graph: Graph, exclude: string[] = []): Node | undefined {\n const targets = new Set(\n graph.edges\n .filter((edge) => !exclude.includes(edge.source))\n .map((edge) => edge.target)\n );\n\n const found: Node[] = [];\n for (const node of Object.values(graph.nodes)) {\n if (!exclude.includes(node.id) && !targets.has(node.id)) {\n found.push(node);\n }\n }\n return found.length === 1 ? found[0] : undefined;\n}\n\n/**\n * Find the single node that is not a source of any edge.\n * Exclude nodes/targets with ids in the exclude list.\n * If there is no such node, or there are multiple, return undefined.\n * When drawing the graph, this node would be the destination.\n */\nfunction _lastNode(graph: Graph, exclude: string[] = []): Node | undefined {\n const sources = new Set(\n graph.edges\n .filter((edge) => !exclude.includes(edge.target))\n .map((edge) => edge.source)\n );\n\n const found: Node[] = [];\n for (const node of Object.values(graph.nodes)) {\n if (!exclude.includes(node.id) && !sources.has(node.id)) {\n found.push(node);\n }\n }\n return found.length === 1 ? found[0] : undefined;\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAS,YACP,IACA,MACQ;AACR,KAAI,OAAO,KAAA,KAAa,CAACA,iBAAAA,QAAO,GAAG,CACjC,QAAO;UACEC,cAAAA,oBAAoB,KAAK,CAClC,KAAI;EACF,IAAI,UAAU,KAAK,SAAS;AAC5B,YAAU,QAAQ,WAAW,WAAW,GACpC,QAAQ,MAAM,EAAkB,GAChC;AACJ,SAAO;SACD;AACN,SAAO,KAAK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I,MAAM,KAAK,KAAA"}
|
package/dist/runnables/graph.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import validate from "../utils/uuid/validate.js";
|
|
3
|
+
import v4 from "../utils/uuid/v4.js";
|
|
4
|
+
import "../utils/uuid/index.js";
|
|
2
5
|
import { isRunnableInterface } from "./utils.js";
|
|
3
6
|
import { drawMermaid, drawMermaidImage } from "./graph_mermaid.js";
|
|
4
7
|
import { toJsonSchema } from "../utils/json_schema.js";
|
|
5
|
-
import { v4, validate } from "uuid";
|
|
6
8
|
//#region src/runnables/graph.ts
|
|
7
9
|
var graph_exports = /* @__PURE__ */ __exportAll({ Graph: () => Graph });
|
|
8
10
|
function nodeDataStr(id, data) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph.js","names":["isUuid","uuidv4"],"sources":["../../src/runnables/graph.ts"],"sourcesContent":["import { v4 as uuidv4, validate as isUuid } from \"uuid\";\nimport type {\n RunnableInterface,\n RunnableIOSchema,\n Node,\n Edge,\n} from \"./types.js\";\nimport { isRunnableInterface } from \"./utils.js\";\nimport { drawMermaid, drawMermaidImage } from \"./graph_mermaid.js\";\nimport { toJsonSchema } from \"../utils/json_schema.js\";\n\nexport { Node, Edge };\n\nfunction nodeDataStr(\n id: string | undefined,\n data: RunnableInterface | RunnableIOSchema\n): string {\n if (id !== undefined && !isUuid(id)) {\n return id;\n } else if (isRunnableInterface(data)) {\n try {\n let dataStr = data.getName();\n dataStr = dataStr.startsWith(\"Runnable\")\n ? dataStr.slice(\"Runnable\".length)\n : dataStr;\n return dataStr;\n } catch {\n return data.getName();\n }\n } else {\n return data.name ?? \"UnknownSchema\";\n }\n}\n\nfunction nodeDataJson(node: Node) {\n // if node.data implements Runnable\n if (isRunnableInterface(node.data)) {\n return {\n type: \"runnable\",\n data: {\n id: node.data.lc_id,\n name: node.data.getName(),\n },\n };\n } else {\n return {\n type: \"schema\",\n data: { ...toJsonSchema(node.data.schema), title: node.data.name },\n };\n }\n}\n\nexport class Graph {\n nodes: Record<string, Node> = {};\n\n edges: Edge[] = [];\n\n constructor(params?: { nodes: Record<string, Node>; edges: Edge[] }) {\n this.nodes = params?.nodes ?? this.nodes;\n this.edges = params?.edges ?? this.edges;\n }\n\n // Convert the graph to a JSON-serializable format.\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n toJSON(): Record<string, any> {\n const stableNodeIds: Record<string, string | number> = {};\n Object.values(this.nodes).forEach((node, i) => {\n stableNodeIds[node.id] = isUuid(node.id) ? i : node.id;\n });\n\n return {\n nodes: Object.values(this.nodes).map((node) => ({\n id: stableNodeIds[node.id],\n ...nodeDataJson(node),\n })),\n edges: this.edges.map((edge) => {\n const item: Record<string, unknown> = {\n source: stableNodeIds[edge.source],\n target: stableNodeIds[edge.target],\n };\n\n if (typeof edge.data !== \"undefined\") {\n item.data = edge.data;\n }\n\n if (typeof edge.conditional !== \"undefined\") {\n item.conditional = edge.conditional;\n }\n return item;\n }),\n };\n }\n\n addNode(\n data: RunnableInterface | RunnableIOSchema,\n id?: string,\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n metadata?: Record<string, any>\n ): Node {\n if (id !== undefined && this.nodes[id] !== undefined) {\n throw new Error(`Node with id ${id} already exists`);\n }\n const nodeId = id ?? uuidv4();\n const node: Node = {\n id: nodeId,\n data,\n name: nodeDataStr(id, data),\n metadata,\n };\n this.nodes[nodeId] = node;\n return node;\n }\n\n removeNode(node: Node): void {\n // Remove the node from the nodes map\n delete this.nodes[node.id];\n\n // Filter out edges connected to the node\n this.edges = this.edges.filter(\n (edge) => edge.source !== node.id && edge.target !== node.id\n );\n }\n\n addEdge(\n source: Node,\n target: Node,\n data?: string,\n conditional?: boolean\n ): Edge {\n if (this.nodes[source.id] === undefined) {\n throw new Error(`Source node ${source.id} not in graph`);\n }\n if (this.nodes[target.id] === undefined) {\n throw new Error(`Target node ${target.id} not in graph`);\n }\n const edge: Edge = {\n source: source.id,\n target: target.id,\n data,\n conditional,\n };\n this.edges.push(edge);\n return edge;\n }\n\n firstNode(): Node | undefined {\n return _firstNode(this);\n }\n\n lastNode(): Node | undefined {\n return _lastNode(this);\n }\n\n /**\n * Add all nodes and edges from another graph.\n * Note this doesn't check for duplicates, nor does it connect the graphs.\n */\n extend(graph: Graph, prefix = \"\") {\n let finalPrefix = prefix;\n const nodeIds = Object.values(graph.nodes).map((node) => node.id);\n if (nodeIds.every(isUuid)) {\n finalPrefix = \"\";\n }\n\n const prefixed = (id: string) => {\n return finalPrefix ? `${finalPrefix}:${id}` : id;\n };\n\n Object.entries(graph.nodes).forEach(([key, value]) => {\n this.nodes[prefixed(key)] = { ...value, id: prefixed(key) };\n });\n\n const newEdges = graph.edges.map((edge) => {\n return {\n ...edge,\n source: prefixed(edge.source),\n target: prefixed(edge.target),\n };\n });\n // Add all edges from the other graph\n this.edges = [...this.edges, ...newEdges];\n const first = graph.firstNode();\n const last = graph.lastNode();\n return [\n first ? { id: prefixed(first.id), data: first.data } : undefined,\n last ? { id: prefixed(last.id), data: last.data } : undefined,\n ];\n }\n\n trimFirstNode(): void {\n const firstNode = this.firstNode();\n if (firstNode && _firstNode(this, [firstNode.id])) {\n this.removeNode(firstNode);\n }\n }\n\n trimLastNode(): void {\n const lastNode = this.lastNode();\n if (lastNode && _lastNode(this, [lastNode.id])) {\n this.removeNode(lastNode);\n }\n }\n\n /**\n * Return a new graph with all nodes re-identified,\n * using their unique, readable names where possible.\n */\n reid(): Graph {\n const nodeLabels: Record<string, string> = Object.fromEntries(\n Object.values(this.nodes).map((node) => [node.id, node.name])\n );\n const nodeLabelCounts = new Map<string, number>();\n Object.values(nodeLabels).forEach((label) => {\n nodeLabelCounts.set(label, (nodeLabelCounts.get(label) || 0) + 1);\n });\n\n const getNodeId = (nodeId: string): string => {\n const label = nodeLabels[nodeId];\n if (isUuid(nodeId) && nodeLabelCounts.get(label) === 1) {\n return label;\n } else {\n return nodeId;\n }\n };\n\n return new Graph({\n nodes: Object.fromEntries(\n Object.entries(this.nodes).map(([id, node]) => [\n getNodeId(id),\n { ...node, id: getNodeId(id) },\n ])\n ),\n edges: this.edges.map((edge) => ({\n ...edge,\n source: getNodeId(edge.source),\n target: getNodeId(edge.target),\n })),\n });\n }\n\n drawMermaid(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n }): string {\n const {\n withStyles,\n curveStyle,\n nodeColors = {\n default: \"fill:#f2f0ff,line-height:1.2\",\n first: \"fill-opacity:0\",\n last: \"fill:#bfb6fc\",\n },\n wrapLabelNWords,\n } = params ?? {};\n const graph = this.reid();\n const firstNode = graph.firstNode();\n\n const lastNode = graph.lastNode();\n\n return drawMermaid(graph.nodes, graph.edges, {\n firstNode: firstNode?.id,\n lastNode: lastNode?.id,\n withStyles,\n curveStyle,\n nodeColors,\n wrapLabelNWords,\n });\n }\n\n async drawMermaidPng(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<Blob> {\n const mermaidSyntax = this.drawMermaid(params);\n return drawMermaidImage(mermaidSyntax, {\n backgroundColor: params?.backgroundColor,\n });\n }\n}\n/**\n * Find the single node that is not a target of any edge.\n * Exclude nodes/sources with ids in the exclude list.\n * If there is no such node, or there are multiple, return undefined.\n * When drawing the graph, this node would be the origin.\n */\nfunction _firstNode(graph: Graph, exclude: string[] = []): Node | undefined {\n const targets = new Set(\n graph.edges\n .filter((edge) => !exclude.includes(edge.source))\n .map((edge) => edge.target)\n );\n\n const found: Node[] = [];\n for (const node of Object.values(graph.nodes)) {\n if (!exclude.includes(node.id) && !targets.has(node.id)) {\n found.push(node);\n }\n }\n return found.length === 1 ? found[0] : undefined;\n}\n\n/**\n * Find the single node that is not a source of any edge.\n * Exclude nodes/targets with ids in the exclude list.\n * If there is no such node, or there are multiple, return undefined.\n * When drawing the graph, this node would be the destination.\n */\nfunction _lastNode(graph: Graph, exclude: string[] = []): Node | undefined {\n const sources = new Set(\n graph.edges\n .filter((edge) => !exclude.includes(edge.target))\n .map((edge) => edge.source)\n );\n\n const found: Node[] = [];\n for (const node of Object.values(graph.nodes)) {\n if (!exclude.includes(node.id) && !sources.has(node.id)) {\n found.push(node);\n }\n }\n return found.length === 1 ? found[0] : undefined;\n}\n"],"mappings":";;;;;;;AAaA,SAAS,YACP,IACA,MACQ;AACR,KAAI,OAAO,KAAA,KAAa,CAACA,SAAO,GAAG,CACjC,QAAO;UACE,oBAAoB,KAAK,CAClC,KAAI;EACF,IAAI,UAAU,KAAK,SAAS;AAC5B,YAAU,QAAQ,WAAW,WAAW,GACpC,QAAQ,MAAM,EAAkB,GAChC;AACJ,SAAO;SACD;AACN,SAAO,KAAK,SAAS;;KAGvB,QAAO,KAAK,QAAQ;;AAIxB,SAAS,aAAa,MAAY;AAEhC,KAAI,oBAAoB,KAAK,KAAK,CAChC,QAAO;EACL,MAAM;EACN,MAAM;GACJ,IAAI,KAAK,KAAK;GACd,MAAM,KAAK,KAAK,SAAS;GAC1B;EACF;KAED,QAAO;EACL,MAAM;EACN,MAAM;GAAE,GAAG,aAAa,KAAK,KAAK,OAAO;GAAE,OAAO,KAAK,KAAK;GAAM;EACnE;;AAIL,IAAa,QAAb,MAAa,MAAM;CACjB,QAA8B,EAAE;CAEhC,QAAgB,EAAE;CAElB,YAAY,QAAyD;AACnE,OAAK,QAAQ,QAAQ,SAAS,KAAK;AACnC,OAAK,QAAQ,QAAQ,SAAS,KAAK;;CAKrC,SAA8B;EAC5B,MAAM,gBAAiD,EAAE;AACzD,SAAO,OAAO,KAAK,MAAM,CAAC,SAAS,MAAM,MAAM;AAC7C,iBAAc,KAAK,MAAMA,SAAO,KAAK,GAAG,GAAG,IAAI,KAAK;IACpD;AAEF,SAAO;GACL,OAAO,OAAO,OAAO,KAAK,MAAM,CAAC,KAAK,UAAU;IAC9C,IAAI,cAAc,KAAK;IACvB,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,QAAO,MAAM,WAAW,IAAI,MAAM,KAAK,KAAA;;;;;;;;AASzC,SAAS,UAAU,OAAc,UAAoB,EAAE,EAAoB;CACzE,MAAM,UAAU,IAAI,IAClB,MAAM,MACH,QAAQ,SAAS,CAAC,QAAQ,SAAS,KAAK,OAAO,CAAC,CAChD,KAAK,SAAS,KAAK,OAAO,CAC9B;CAED,MAAM,QAAgB,EAAE;AACxB,MAAK,MAAM,QAAQ,OAAO,OAAO,MAAM,MAAM,CAC3C,KAAI,CAAC,QAAQ,SAAS,KAAK,GAAG,IAAI,CAAC,QAAQ,IAAI,KAAK,GAAG,CACrD,OAAM,KAAK,KAAK;AAGpB,QAAO,MAAM,WAAW,IAAI,MAAM,KAAK,KAAA"}
|
|
1
|
+
{"version":3,"file":"graph.js","names":["isUuid","uuidv4"],"sources":["../../src/runnables/graph.ts"],"sourcesContent":["import { v4 as uuidv4, validate as isUuid } from \"../utils/uuid/index.js\";\nimport type {\n RunnableInterface,\n RunnableIOSchema,\n Node,\n Edge,\n} from \"./types.js\";\nimport { isRunnableInterface } from \"./utils.js\";\nimport { drawMermaid, drawMermaidImage } from \"./graph_mermaid.js\";\nimport { toJsonSchema } from \"../utils/json_schema.js\";\n\nexport { Node, Edge };\n\nfunction nodeDataStr(\n id: string | undefined,\n data: RunnableInterface | RunnableIOSchema\n): string {\n if (id !== undefined && !isUuid(id)) {\n return id;\n } else if (isRunnableInterface(data)) {\n try {\n let dataStr = data.getName();\n dataStr = dataStr.startsWith(\"Runnable\")\n ? dataStr.slice(\"Runnable\".length)\n : dataStr;\n return dataStr;\n } catch {\n return data.getName();\n }\n } else {\n return data.name ?? \"UnknownSchema\";\n }\n}\n\nfunction nodeDataJson(node: Node) {\n // if node.data implements Runnable\n if (isRunnableInterface(node.data)) {\n return {\n type: \"runnable\",\n data: {\n id: node.data.lc_id,\n name: node.data.getName(),\n },\n };\n } else {\n return {\n type: \"schema\",\n data: { ...toJsonSchema(node.data.schema), title: node.data.name },\n };\n }\n}\n\nexport class Graph {\n nodes: Record<string, Node> = {};\n\n edges: Edge[] = [];\n\n constructor(params?: { nodes: Record<string, Node>; edges: Edge[] }) {\n this.nodes = params?.nodes ?? this.nodes;\n this.edges = params?.edges ?? this.edges;\n }\n\n // Convert the graph to a JSON-serializable format.\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n toJSON(): Record<string, any> {\n const stableNodeIds: Record<string, string | number> = {};\n Object.values(this.nodes).forEach((node, i) => {\n stableNodeIds[node.id] = isUuid(node.id) ? i : node.id;\n });\n\n return {\n nodes: Object.values(this.nodes).map((node) => ({\n id: stableNodeIds[node.id],\n ...nodeDataJson(node),\n })),\n edges: this.edges.map((edge) => {\n const item: Record<string, unknown> = {\n source: stableNodeIds[edge.source],\n target: stableNodeIds[edge.target],\n };\n\n if (typeof edge.data !== \"undefined\") {\n item.data = edge.data;\n }\n\n if (typeof edge.conditional !== \"undefined\") {\n item.conditional = edge.conditional;\n }\n return item;\n }),\n };\n }\n\n addNode(\n data: RunnableInterface | RunnableIOSchema,\n id?: string,\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n metadata?: Record<string, any>\n ): Node {\n if (id !== undefined && this.nodes[id] !== undefined) {\n throw new Error(`Node with id ${id} already exists`);\n }\n const nodeId = id ?? uuidv4();\n const node: Node = {\n id: nodeId,\n data,\n name: nodeDataStr(id, data),\n metadata,\n };\n this.nodes[nodeId] = node;\n return node;\n }\n\n removeNode(node: Node): void {\n // Remove the node from the nodes map\n delete this.nodes[node.id];\n\n // Filter out edges connected to the node\n this.edges = this.edges.filter(\n (edge) => edge.source !== node.id && edge.target !== node.id\n );\n }\n\n addEdge(\n source: Node,\n target: Node,\n data?: string,\n conditional?: boolean\n ): Edge {\n if (this.nodes[source.id] === undefined) {\n throw new Error(`Source node ${source.id} not in graph`);\n }\n if (this.nodes[target.id] === undefined) {\n throw new Error(`Target node ${target.id} not in graph`);\n }\n const edge: Edge = {\n source: source.id,\n target: target.id,\n data,\n conditional,\n };\n this.edges.push(edge);\n return edge;\n }\n\n firstNode(): Node | undefined {\n return _firstNode(this);\n }\n\n lastNode(): Node | undefined {\n return _lastNode(this);\n }\n\n /**\n * Add all nodes and edges from another graph.\n * Note this doesn't check for duplicates, nor does it connect the graphs.\n */\n extend(graph: Graph, prefix = \"\") {\n let finalPrefix = prefix;\n const nodeIds = Object.values(graph.nodes).map((node) => node.id);\n if (nodeIds.every(isUuid)) {\n finalPrefix = \"\";\n }\n\n const prefixed = (id: string) => {\n return finalPrefix ? `${finalPrefix}:${id}` : id;\n };\n\n Object.entries(graph.nodes).forEach(([key, value]) => {\n this.nodes[prefixed(key)] = { ...value, id: prefixed(key) };\n });\n\n const newEdges = graph.edges.map((edge) => {\n return {\n ...edge,\n source: prefixed(edge.source),\n target: prefixed(edge.target),\n };\n });\n // Add all edges from the other graph\n this.edges = [...this.edges, ...newEdges];\n const first = graph.firstNode();\n const last = graph.lastNode();\n return [\n first ? { id: prefixed(first.id), data: first.data } : undefined,\n last ? { id: prefixed(last.id), data: last.data } : undefined,\n ];\n }\n\n trimFirstNode(): void {\n const firstNode = this.firstNode();\n if (firstNode && _firstNode(this, [firstNode.id])) {\n this.removeNode(firstNode);\n }\n }\n\n trimLastNode(): void {\n const lastNode = this.lastNode();\n if (lastNode && _lastNode(this, [lastNode.id])) {\n this.removeNode(lastNode);\n }\n }\n\n /**\n * Return a new graph with all nodes re-identified,\n * using their unique, readable names where possible.\n */\n reid(): Graph {\n const nodeLabels: Record<string, string> = Object.fromEntries(\n Object.values(this.nodes).map((node) => [node.id, node.name])\n );\n const nodeLabelCounts = new Map<string, number>();\n Object.values(nodeLabels).forEach((label) => {\n nodeLabelCounts.set(label, (nodeLabelCounts.get(label) || 0) + 1);\n });\n\n const getNodeId = (nodeId: string): string => {\n const label = nodeLabels[nodeId];\n if (isUuid(nodeId) && nodeLabelCounts.get(label) === 1) {\n return label;\n } else {\n return nodeId;\n }\n };\n\n return new Graph({\n nodes: Object.fromEntries(\n Object.entries(this.nodes).map(([id, node]) => [\n getNodeId(id),\n { ...node, id: getNodeId(id) },\n ])\n ),\n edges: this.edges.map((edge) => ({\n ...edge,\n source: getNodeId(edge.source),\n target: getNodeId(edge.target),\n })),\n });\n }\n\n drawMermaid(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n }): string {\n const {\n withStyles,\n curveStyle,\n nodeColors = {\n default: \"fill:#f2f0ff,line-height:1.2\",\n first: \"fill-opacity:0\",\n last: \"fill:#bfb6fc\",\n },\n wrapLabelNWords,\n } = params ?? {};\n const graph = this.reid();\n const firstNode = graph.firstNode();\n\n const lastNode = graph.lastNode();\n\n return drawMermaid(graph.nodes, graph.edges, {\n firstNode: firstNode?.id,\n lastNode: lastNode?.id,\n withStyles,\n curveStyle,\n nodeColors,\n wrapLabelNWords,\n });\n }\n\n async drawMermaidPng(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<Blob> {\n const mermaidSyntax = this.drawMermaid(params);\n return drawMermaidImage(mermaidSyntax, {\n backgroundColor: params?.backgroundColor,\n });\n }\n}\n/**\n * Find the single node that is not a target of any edge.\n * Exclude nodes/sources with ids in the exclude list.\n * If there is no such node, or there are multiple, return undefined.\n * When drawing the graph, this node would be the origin.\n */\nfunction _firstNode(graph: Graph, exclude: string[] = []): Node | undefined {\n const targets = new Set(\n graph.edges\n .filter((edge) => !exclude.includes(edge.source))\n .map((edge) => edge.target)\n );\n\n const found: Node[] = [];\n for (const node of Object.values(graph.nodes)) {\n if (!exclude.includes(node.id) && !targets.has(node.id)) {\n found.push(node);\n }\n }\n return found.length === 1 ? found[0] : undefined;\n}\n\n/**\n * Find the single node that is not a source of any edge.\n * Exclude nodes/targets with ids in the exclude list.\n * If there is no such node, or there are multiple, return undefined.\n * When drawing the graph, this node would be the destination.\n */\nfunction _lastNode(graph: Graph, exclude: string[] = []): Node | undefined {\n const sources = new Set(\n graph.edges\n .filter((edge) => !exclude.includes(edge.target))\n .map((edge) => edge.source)\n );\n\n const found: Node[] = [];\n for (const node of Object.values(graph.nodes)) {\n if (!exclude.includes(node.id) && !sources.has(node.id)) {\n found.push(node);\n }\n }\n return found.length === 1 ? found[0] : undefined;\n}\n"],"mappings":";;;;;;;;;AAaA,SAAS,YACP,IACA,MACQ;AACR,KAAI,OAAO,KAAA,KAAa,CAACA,SAAO,GAAG,CACjC,QAAO;UACE,oBAAoB,KAAK,CAClC,KAAI;EACF,IAAI,UAAU,KAAK,SAAS;AAC5B,YAAU,QAAQ,WAAW,WAAW,GACpC,QAAQ,MAAM,EAAkB,GAChC;AACJ,SAAO;SACD;AACN,SAAO,KAAK,SAAS;;KAGvB,QAAO,KAAK,QAAQ;;AAIxB,SAAS,aAAa,MAAY;AAEhC,KAAI,oBAAoB,KAAK,KAAK,CAChC,QAAO;EACL,MAAM;EACN,MAAM;GACJ,IAAI,KAAK,KAAK;GACd,MAAM,KAAK,KAAK,SAAS;GAC1B;EACF;KAED,QAAO;EACL,MAAM;EACN,MAAM;GAAE,GAAG,aAAa,KAAK,KAAK,OAAO;GAAE,OAAO,KAAK,KAAK;GAAM;EACnE;;AAIL,IAAa,QAAb,MAAa,MAAM;CACjB,QAA8B,EAAE;CAEhC,QAAgB,EAAE;CAElB,YAAY,QAAyD;AACnE,OAAK,QAAQ,QAAQ,SAAS,KAAK;AACnC,OAAK,QAAQ,QAAQ,SAAS,KAAK;;CAKrC,SAA8B;EAC5B,MAAM,gBAAiD,EAAE;AACzD,SAAO,OAAO,KAAK,MAAM,CAAC,SAAS,MAAM,MAAM;AAC7C,iBAAc,KAAK,MAAMA,SAAO,KAAK,GAAG,GAAG,IAAI,KAAK;IACpD;AAEF,SAAO;GACL,OAAO,OAAO,OAAO,KAAK,MAAM,CAAC,KAAK,UAAU;IAC9C,IAAI,cAAc,KAAK;IACvB,GAAG,aAAa,KAAK;IACtB,EAAE;GACH,OAAO,KAAK,M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;;;AASzC,SAAS,UAAU,OAAc,UAAoB,EAAE,EAAoB;CACzE,MAAM,UAAU,IAAI,IAClB,MAAM,MACH,QAAQ,SAAS,CAAC,QAAQ,SAAS,KAAK,OAAO,CAAC,CAChD,KAAK,SAAS,KAAK,OAAO,CAC9B;CAED,MAAM,QAAgB,EAAE;AACxB,MAAK,MAAM,QAAQ,OAAO,OAAO,MAAM,MAAM,CAC3C,KAAI,CAAC,QAAQ,SAAS,KAAK,GAAG,IAAI,CAAC,QAAQ,IAAI,KAAK,GAAG,CACrD,OAAM,KAAK,KAAK;AAGpB,QAAO,MAAM,WAAW,IAAI,MAAM,KAAK,KAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_max = require("./max.cjs");
|
|
4
|
+
const require_nil = require("./nil.cjs");
|
|
5
|
+
const require_validate = require("./validate.cjs");
|
|
6
|
+
const require_parse = require("./parse.cjs");
|
|
7
|
+
const require_stringify = require("./stringify.cjs");
|
|
8
|
+
const require_v1 = require("./v1.cjs");
|
|
9
|
+
const require_v4 = require("./v4.cjs");
|
|
10
|
+
const require_v5 = require("./v5.cjs");
|
|
11
|
+
const require_v7 = require("./v7.cjs");
|
|
12
|
+
const require_version = require("./version.cjs");
|
|
13
|
+
//#region src/utils/uuid/index.ts
|
|
14
|
+
var uuid_exports = /* @__PURE__ */ require_runtime.__exportAll({
|
|
15
|
+
MAX: () => require_max.default,
|
|
16
|
+
NIL: () => require_nil.default,
|
|
17
|
+
parse: () => require_parse.default,
|
|
18
|
+
stringify: () => require_stringify.default,
|
|
19
|
+
v1: () => require_v1.default,
|
|
20
|
+
v4: () => require_v4.default,
|
|
21
|
+
v5: () => require_v5.default,
|
|
22
|
+
v7: () => require_v7.default,
|
|
23
|
+
validate: () => require_validate.default,
|
|
24
|
+
version: () => require_version.default
|
|
25
|
+
});
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.MAX = require_max;
|
|
28
|
+
exports.NIL = require_nil;
|
|
29
|
+
exports.parse = require_parse;
|
|
30
|
+
exports.stringify = require_stringify;
|
|
31
|
+
Object.defineProperty(exports, "uuid_exports", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function() {
|
|
34
|
+
return uuid_exports;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
exports.v1 = require_v1;
|
|
38
|
+
exports.v4 = require_v4;
|
|
39
|
+
exports.v5 = require_v5;
|
|
40
|
+
exports.v7 = require_v7;
|
|
41
|
+
exports.validate = require_validate;
|
|
42
|
+
exports.version = require_version;
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../../src/utils/uuid/index.ts"],"sourcesContent":["export { default as MAX } from \"./max.js\";\nexport { default as NIL } from \"./nil.js\";\nexport { default as parse } from \"./parse.js\";\nexport { default as stringify } from \"./stringify.js\";\nexport type * from \"./types.js\";\nexport { default as v1 } from \"./v1.js\";\nexport { default as v4 } from \"./v4.js\";\nexport { default as v5 } from \"./v5.js\";\nexport { default as v7 } from \"./v7.js\";\nexport { default as validate } from \"./validate.js\";\nexport { default as version } from \"./version.js\";\n"],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { _default } from "./max.cjs";
|
|
2
|
+
import { _default as _default$1 } from "./nil.cjs";
|
|
3
|
+
import { NonSharedArrayBuffer, UUIDTypes, Version1Options, Version4Options, Version6Options, Version7Options } from "./types.cjs";
|
|
4
|
+
import { parse } from "./parse.cjs";
|
|
5
|
+
import { stringify } from "./stringify.cjs";
|
|
6
|
+
import { v1 } from "./v1.cjs";
|
|
7
|
+
import { v4 } from "./v4.cjs";
|
|
8
|
+
import { v5 } from "./v5.cjs";
|
|
9
|
+
import { v7 } from "./v7.cjs";
|
|
10
|
+
import { validate } from "./validate.cjs";
|
|
11
|
+
import { version } from "./version.cjs";
|
|
12
|
+
export { _default as MAX, _default$1 as NIL, NonSharedArrayBuffer, UUIDTypes, Version1Options, Version4Options, Version6Options, Version7Options, parse, stringify, v1, v4, v5, v7, validate, version };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { _default } from "./max.js";
|
|
2
|
+
import { _default as _default$1 } from "./nil.js";
|
|
3
|
+
import { NonSharedArrayBuffer, UUIDTypes, Version1Options, Version4Options, Version6Options, Version7Options } from "./types.js";
|
|
4
|
+
import { parse } from "./parse.js";
|
|
5
|
+
import { stringify } from "./stringify.js";
|
|
6
|
+
import { v1 } from "./v1.js";
|
|
7
|
+
import { v4 } from "./v4.js";
|
|
8
|
+
import { v5 } from "./v5.js";
|
|
9
|
+
import { v7 } from "./v7.js";
|
|
10
|
+
import { validate } from "./validate.js";
|
|
11
|
+
import { version } from "./version.js";
|
|
12
|
+
export { _default as MAX, _default$1 as NIL, NonSharedArrayBuffer, UUIDTypes, Version1Options, Version4Options, Version6Options, Version7Options, parse, stringify, v1, v4, v5, v7, validate, version };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { __exportAll } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import max_default from "./max.js";
|
|
3
|
+
import nil_default from "./nil.js";
|
|
4
|
+
import validate from "./validate.js";
|
|
5
|
+
import parse from "./parse.js";
|
|
6
|
+
import stringify from "./stringify.js";
|
|
7
|
+
import v1 from "./v1.js";
|
|
8
|
+
import v4 from "./v4.js";
|
|
9
|
+
import v5 from "./v5.js";
|
|
10
|
+
import v7 from "./v7.js";
|
|
11
|
+
import version from "./version.js";
|
|
12
|
+
//#region src/utils/uuid/index.ts
|
|
13
|
+
var uuid_exports = /* @__PURE__ */ __exportAll({
|
|
14
|
+
MAX: () => max_default,
|
|
15
|
+
NIL: () => nil_default,
|
|
16
|
+
parse: () => parse,
|
|
17
|
+
stringify: () => stringify,
|
|
18
|
+
v1: () => v1,
|
|
19
|
+
v4: () => v4,
|
|
20
|
+
v5: () => v5,
|
|
21
|
+
v7: () => v7,
|
|
22
|
+
validate: () => validate,
|
|
23
|
+
version: () => version
|
|
24
|
+
});
|
|
25
|
+
//#endregion
|
|
26
|
+
export { max_default as MAX, nil_default as NIL, parse, stringify, uuid_exports, v1, v4, v5, v7, validate, version };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/utils/uuid/index.ts"],"sourcesContent":["export { default as MAX } from \"./max.js\";\nexport { default as NIL } from \"./nil.js\";\nexport { default as parse } from \"./parse.js\";\nexport { default as stringify } from \"./stringify.js\";\nexport type * from \"./types.js\";\nexport { default as v1 } from \"./v1.js\";\nexport { default as v4 } from \"./v4.js\";\nexport { default as v5 } from \"./v5.js\";\nexport { default as v7 } from \"./v7.js\";\nexport { default as validate } from \"./validate.js\";\nexport { default as version } from \"./version.js\";\n"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"max.cjs","names":[],"sources":["../../../src/utils/uuid/max.ts"],"sourcesContent":["export default \"ffffffff-ffff-ffff-ffff-ffffffffffff\";\n"],"mappings":";AAAA,IAAA,cAAe"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"max.d.cts","names":[],"sources":["../../../src/utils/uuid/max.ts"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"max.d.ts","names":[],"sources":["../../../src/utils/uuid/max.ts"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"max.js","names":[],"sources":["../../../src/utils/uuid/max.ts"],"sourcesContent":["export default \"ffffffff-ffff-ffff-ffff-ffffffffffff\";\n"],"mappings":";AAAA,IAAA,cAAe"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nil.cjs","names":[],"sources":["../../../src/utils/uuid/nil.ts"],"sourcesContent":["export default \"00000000-0000-0000-0000-000000000000\";\n"],"mappings":";AAAA,IAAA,cAAe"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nil.d.cts","names":[],"sources":["../../../src/utils/uuid/nil.ts"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nil.d.ts","names":[],"sources":["../../../src/utils/uuid/nil.ts"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nil.js","names":[],"sources":["../../../src/utils/uuid/nil.ts"],"sourcesContent":["export default \"00000000-0000-0000-0000-000000000000\";\n"],"mappings":";AAAA,IAAA,cAAe"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const require_validate = require("./validate.cjs");
|
|
2
|
+
//#region src/utils/uuid/parse.ts
|
|
3
|
+
function parse(uuid) {
|
|
4
|
+
if (!require_validate.default(uuid)) throw TypeError("Invalid UUID");
|
|
5
|
+
let v;
|
|
6
|
+
return Uint8Array.of((v = parseInt(uuid.slice(0, 8), 16)) >>> 24, v >>> 16 & 255, v >>> 8 & 255, v & 255, (v = parseInt(uuid.slice(9, 13), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(14, 18), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(19, 23), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(24, 36), 16)) / 1099511627776 & 255, v / 4294967296 & 255, v >>> 24 & 255, v >>> 16 & 255, v >>> 8 & 255, v & 255);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
exports.default = parse;
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=parse.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.cjs","names":["validate"],"sources":["../../../src/utils/uuid/parse.ts"],"sourcesContent":["import type { NonSharedArrayBuffer } from \"./types.js\";\nimport validate from \"./validate.js\";\n\nfunction parse(uuid: string): NonSharedArrayBuffer {\n if (!validate(uuid)) {\n throw TypeError(\"Invalid UUID\");\n }\n\n let v: number;\n return Uint8Array.of(\n (v = parseInt(uuid.slice(0, 8), 16)) >>> 24,\n (v >>> 16) & 0xff,\n (v >>> 8) & 0xff,\n v & 0xff,\n\n // Parse ........-####-....-....-............\n (v = parseInt(uuid.slice(9, 13), 16)) >>> 8,\n v & 0xff,\n\n // Parse ........-....-####-....-............\n (v = parseInt(uuid.slice(14, 18), 16)) >>> 8,\n v & 0xff,\n\n // Parse ........-....-....-####-............\n (v = parseInt(uuid.slice(19, 23), 16)) >>> 8,\n v & 0xff,\n\n // Parse ........-....-....-....-############\n // (Use \"/\" to avoid 32-bit truncation when bit-shifting high-order bytes)\n ((v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000) & 0xff,\n (v / 0x100000000) & 0xff,\n (v >>> 24) & 0xff,\n (v >>> 16) & 0xff,\n (v >>> 8) & 0xff,\n v & 0xff\n );\n}\n\nexport default parse;\n"],"mappings":";;AAGA,SAAS,MAAM,MAAoC;AACjD,KAAI,CAACA,iBAAAA,QAAS,KAAK,CACjB,OAAM,UAAU,eAAe;CAGjC,IAAI;AACJ,QAAO,WAAW,IACf,IAAI,SAAS,KAAK,MAAM,GAAG,EAAE,EAAE,GAAG,MAAM,IACxC,MAAM,KAAM,KACZ,MAAM,IAAK,KACZ,IAAI,MAGH,IAAI,SAAS,KAAK,MAAM,GAAG,GAAG,EAAE,GAAG,MAAM,GAC1C,IAAI,MAGH,IAAI,SAAS,KAAK,MAAM,IAAI,GAAG,EAAE,GAAG,MAAM,GAC3C,IAAI,MAGH,IAAI,SAAS,KAAK,MAAM,IAAI,GAAG,EAAE,GAAG,MAAM,GAC3C,IAAI,MAIF,IAAI,SAAS,KAAK,MAAM,IAAI,GAAG,EAAE,GAAG,IAAI,gBAAiB,KAC1D,IAAI,aAAe,KACnB,MAAM,KAAM,KACZ,MAAM,KAAM,KACZ,MAAM,IAAK,KACZ,IAAI,IACL"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.cts","names":[],"sources":["../../../src/utils/uuid/parse.ts"],"mappings":";;;iBAGS,KAAA,CAAM,IAAA,WAAe,oBAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","names":[],"sources":["../../../src/utils/uuid/parse.ts"],"mappings":";;;iBAGS,KAAA,CAAM,IAAA,WAAe,oBAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import validate from "./validate.js";
|
|
2
|
+
//#region src/utils/uuid/parse.ts
|
|
3
|
+
function parse(uuid) {
|
|
4
|
+
if (!validate(uuid)) throw TypeError("Invalid UUID");
|
|
5
|
+
let v;
|
|
6
|
+
return Uint8Array.of((v = parseInt(uuid.slice(0, 8), 16)) >>> 24, v >>> 16 & 255, v >>> 8 & 255, v & 255, (v = parseInt(uuid.slice(9, 13), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(14, 18), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(19, 23), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(24, 36), 16)) / 1099511627776 & 255, v / 4294967296 & 255, v >>> 24 & 255, v >>> 16 & 255, v >>> 8 & 255, v & 255);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { parse as default };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","names":[],"sources":["../../../src/utils/uuid/parse.ts"],"sourcesContent":["import type { NonSharedArrayBuffer } from \"./types.js\";\nimport validate from \"./validate.js\";\n\nfunction parse(uuid: string): NonSharedArrayBuffer {\n if (!validate(uuid)) {\n throw TypeError(\"Invalid UUID\");\n }\n\n let v: number;\n return Uint8Array.of(\n (v = parseInt(uuid.slice(0, 8), 16)) >>> 24,\n (v >>> 16) & 0xff,\n (v >>> 8) & 0xff,\n v & 0xff,\n\n // Parse ........-####-....-....-............\n (v = parseInt(uuid.slice(9, 13), 16)) >>> 8,\n v & 0xff,\n\n // Parse ........-....-####-....-............\n (v = parseInt(uuid.slice(14, 18), 16)) >>> 8,\n v & 0xff,\n\n // Parse ........-....-....-####-............\n (v = parseInt(uuid.slice(19, 23), 16)) >>> 8,\n v & 0xff,\n\n // Parse ........-....-....-....-############\n // (Use \"/\" to avoid 32-bit truncation when bit-shifting high-order bytes)\n ((v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000) & 0xff,\n (v / 0x100000000) & 0xff,\n (v >>> 24) & 0xff,\n (v >>> 16) & 0xff,\n (v >>> 8) & 0xff,\n v & 0xff\n );\n}\n\nexport default parse;\n"],"mappings":";;AAGA,SAAS,MAAM,MAAoC;AACjD,KAAI,CAAC,SAAS,KAAK,CACjB,OAAM,UAAU,eAAe;CAGjC,IAAI;AACJ,QAAO,WAAW,IACf,IAAI,SAAS,KAAK,MAAM,GAAG,EAAE,EAAE,GAAG,MAAM,IACxC,MAAM,KAAM,KACZ,MAAM,IAAK,KACZ,IAAI,MAGH,IAAI,SAAS,KAAK,MAAM,GAAG,GAAG,EAAE,GAAG,MAAM,GAC1C,IAAI,MAGH,IAAI,SAAS,KAAK,MAAM,IAAI,GAAG,EAAE,GAAG,MAAM,GAC3C,IAAI,MAGH,IAAI,SAAS,KAAK,MAAM,IAAI,GAAG,EAAE,GAAG,MAAM,GAC3C,IAAI,MAIF,IAAI,SAAS,KAAK,MAAM,IAAI,GAAG,EAAE,GAAG,IAAI,gBAAiB,KAC1D,IAAI,aAAe,KACnB,MAAM,KAAM,KACZ,MAAM,KAAM,KACZ,MAAM,IAAK,KACZ,IAAI,IACL"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region src/utils/uuid/regex.ts
|
|
2
|
+
var regex_default = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
|
|
3
|
+
//#endregion
|
|
4
|
+
exports.default = regex_default;
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=regex.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regex.cjs","names":[],"sources":["../../../src/utils/uuid/regex.ts"],"sourcesContent":["export default /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;\n"],"mappings":";AAAA,IAAA,gBAAe"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region src/utils/uuid/regex.ts
|
|
2
|
+
var regex_default = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
|
|
3
|
+
//#endregion
|
|
4
|
+
export { regex_default as default };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=regex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regex.js","names":[],"sources":["../../../src/utils/uuid/regex.ts"],"sourcesContent":["export default /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;\n"],"mappings":";AAAA,IAAA,gBAAe"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rng.cjs","names":[],"sources":["../../../src/utils/uuid/rng.ts"],"sourcesContent":["// RNG values for use in UUID generation. This *must* use a high-quality source\n// of entropy, such as `crypto.getRandomValues()`. And we reuse an array for\n// performance.\nconst rnds8 = new Uint8Array(16);\nexport default function rng() {\n return crypto.getRandomValues(rnds8);\n}\n"],"mappings":";AAGA,MAAM,QAAQ,IAAI,WAAW,GAAG;AAChC,SAAwB,MAAM;AAC5B,QAAO,OAAO,gBAAgB,MAAM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rng.js","names":[],"sources":["../../../src/utils/uuid/rng.ts"],"sourcesContent":["// RNG values for use in UUID generation. This *must* use a high-quality source\n// of entropy, such as `crypto.getRandomValues()`. And we reuse an array for\n// performance.\nconst rnds8 = new Uint8Array(16);\nexport default function rng() {\n return crypto.getRandomValues(rnds8);\n}\n"],"mappings":";AAGA,MAAM,QAAQ,IAAI,WAAW,GAAG;AAChC,SAAwB,MAAM;AAC5B,QAAO,OAAO,gBAAgB,MAAM"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
//#region src/utils/uuid/sha1.ts
|
|
2
|
+
function f(s, x, y, z) {
|
|
3
|
+
switch (s) {
|
|
4
|
+
case 0: return x & y ^ ~x & z;
|
|
5
|
+
case 1: return x ^ y ^ z;
|
|
6
|
+
case 2: return x & y ^ x & z ^ y & z;
|
|
7
|
+
case 3: return x ^ y ^ z;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function ROTL(x, n) {
|
|
11
|
+
return x << n | x >>> 32 - n;
|
|
12
|
+
}
|
|
13
|
+
function sha1(bytes) {
|
|
14
|
+
const K = [
|
|
15
|
+
1518500249,
|
|
16
|
+
1859775393,
|
|
17
|
+
2400959708,
|
|
18
|
+
3395469782
|
|
19
|
+
];
|
|
20
|
+
const H = [
|
|
21
|
+
1732584193,
|
|
22
|
+
4023233417,
|
|
23
|
+
2562383102,
|
|
24
|
+
271733878,
|
|
25
|
+
3285377520
|
|
26
|
+
];
|
|
27
|
+
const newBytes = new Uint8Array(bytes.length + 1);
|
|
28
|
+
newBytes.set(bytes);
|
|
29
|
+
newBytes[bytes.length] = 128;
|
|
30
|
+
bytes = newBytes;
|
|
31
|
+
const l = bytes.length / 4 + 2;
|
|
32
|
+
const N = Math.ceil(l / 16);
|
|
33
|
+
const M = new Array(N);
|
|
34
|
+
for (let i = 0; i < N; ++i) {
|
|
35
|
+
const arr = new Uint32Array(16);
|
|
36
|
+
for (let j = 0; j < 16; ++j) arr[j] = bytes[i * 64 + j * 4] << 24 | bytes[i * 64 + j * 4 + 1] << 16 | bytes[i * 64 + j * 4 + 2] << 8 | bytes[i * 64 + j * 4 + 3];
|
|
37
|
+
M[i] = arr;
|
|
38
|
+
}
|
|
39
|
+
M[N - 1][14] = (bytes.length - 1) * 8 / 2 ** 32;
|
|
40
|
+
M[N - 1][14] = Math.floor(M[N - 1][14]);
|
|
41
|
+
M[N - 1][15] = (bytes.length - 1) * 8 & 4294967295;
|
|
42
|
+
for (let i = 0; i < N; ++i) {
|
|
43
|
+
const W = new Uint32Array(80);
|
|
44
|
+
for (let t = 0; t < 16; ++t) W[t] = M[i][t];
|
|
45
|
+
for (let t = 16; t < 80; ++t) W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
|
|
46
|
+
let a = H[0];
|
|
47
|
+
let b = H[1];
|
|
48
|
+
let c = H[2];
|
|
49
|
+
let d = H[3];
|
|
50
|
+
let e = H[4];
|
|
51
|
+
for (let t = 0; t < 80; ++t) {
|
|
52
|
+
const s = Math.floor(t / 20);
|
|
53
|
+
const T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0;
|
|
54
|
+
e = d;
|
|
55
|
+
d = c;
|
|
56
|
+
c = ROTL(b, 30) >>> 0;
|
|
57
|
+
b = a;
|
|
58
|
+
a = T;
|
|
59
|
+
}
|
|
60
|
+
H[0] = H[0] + a >>> 0;
|
|
61
|
+
H[1] = H[1] + b >>> 0;
|
|
62
|
+
H[2] = H[2] + c >>> 0;
|
|
63
|
+
H[3] = H[3] + d >>> 0;
|
|
64
|
+
H[4] = H[4] + e >>> 0;
|
|
65
|
+
}
|
|
66
|
+
return Uint8Array.of(H[0] >> 24, H[0] >> 16, H[0] >> 8, H[0], H[1] >> 24, H[1] >> 16, H[1] >> 8, H[1], H[2] >> 24, H[2] >> 16, H[2] >> 8, H[2], H[3] >> 24, H[3] >> 16, H[3] >> 8, H[3], H[4] >> 24, H[4] >> 16, H[4] >> 8, H[4]);
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
exports.default = sha1;
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=sha1.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sha1.cjs","names":[],"sources":["../../../src/utils/uuid/sha1.ts"],"sourcesContent":["// Adapted from Chris Veness' SHA1 code at\n// http://www.movable-type.co.uk/scripts/sha1.html\nfunction f(s: 0 | 1 | 2 | 3, x: number, y: number, z: number) {\n switch (s) {\n case 0:\n return (x & y) ^ (~x & z);\n case 1:\n return x ^ y ^ z;\n case 2:\n return (x & y) ^ (x & z) ^ (y & z);\n case 3:\n return x ^ y ^ z;\n }\n}\n\nfunction ROTL(x: number, n: number) {\n return (x << n) | (x >>> (32 - n));\n}\n\nfunction sha1(bytes: Uint8Array): Uint8Array {\n const K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];\n const H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];\n\n const newBytes = new Uint8Array(bytes.length + 1);\n newBytes.set(bytes);\n newBytes[bytes.length] = 0x80;\n bytes = newBytes;\n\n const l = bytes.length / 4 + 2;\n const N = Math.ceil(l / 16);\n const M: Uint32Array[] = new Array(N);\n\n for (let i = 0; i < N; ++i) {\n const arr = new Uint32Array(16);\n\n for (let j = 0; j < 16; ++j) {\n arr[j] =\n (bytes[i * 64 + j * 4] << 24) |\n (bytes[i * 64 + j * 4 + 1] << 16) |\n (bytes[i * 64 + j * 4 + 2] << 8) |\n bytes[i * 64 + j * 4 + 3];\n }\n\n M[i] = arr;\n }\n\n M[N - 1][14] = ((bytes.length - 1) * 8) / 2 ** 32;\n M[N - 1][14] = Math.floor(M[N - 1][14]);\n M[N - 1][15] = ((bytes.length - 1) * 8) & 0xffffffff;\n\n for (let i = 0; i < N; ++i) {\n const W = new Uint32Array(80);\n\n for (let t = 0; t < 16; ++t) {\n W[t] = M[i][t];\n }\n\n for (let t = 16; t < 80; ++t) {\n W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);\n }\n\n let a = H[0];\n let b = H[1];\n let c = H[2];\n let d = H[3];\n let e = H[4];\n\n for (let t = 0; t < 80; ++t) {\n const s = Math.floor(t / 20) as 0 | 1 | 2 | 3;\n const T = (ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t]) >>> 0;\n e = d;\n d = c;\n c = ROTL(b, 30) >>> 0;\n b = a;\n a = T;\n }\n\n H[0] = (H[0] + a) >>> 0;\n H[1] = (H[1] + b) >>> 0;\n H[2] = (H[2] + c) >>> 0;\n H[3] = (H[3] + d) >>> 0;\n H[4] = (H[4] + e) >>> 0;\n }\n\n // Note: Uint8Array.of() does `& 0xff` for each value\n return Uint8Array.of(\n H[0] >> 24,\n H[0] >> 16,\n H[0] >> 8,\n H[0],\n H[1] >> 24,\n H[1] >> 16,\n H[1] >> 8,\n H[1],\n H[2] >> 24,\n H[2] >> 16,\n H[2] >> 8,\n H[2],\n H[3] >> 24,\n H[3] >> 16,\n H[3] >> 8,\n H[3],\n H[4] >> 24,\n H[4] >> 16,\n H[4] >> 8,\n H[4]\n );\n}\n\nexport default sha1;\n"],"mappings":";AAEA,SAAS,EAAE,GAAkB,GAAW,GAAW,GAAW;AAC5D,SAAQ,GAAR;EACE,KAAK,EACH,QAAQ,IAAI,IAAM,CAAC,IAAI;EACzB,KAAK,EACH,QAAO,IAAI,IAAI;EACjB,KAAK,EACH,QAAQ,IAAI,IAAM,IAAI,IAAM,IAAI;EAClC,KAAK,EACH,QAAO,IAAI,IAAI;;;AAIrB,SAAS,KAAK,GAAW,GAAW;AAClC,QAAQ,KAAK,IAAM,MAAO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