@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
@@ -0,0 +1,15 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/utilities/BaseError.ts", "../src/graph/errors.ts", "../src/events/EventEmitter.ts", "../src/graph/graph.ts", "../src/graph/directedGraph.ts", "../src/graph/directedAcyclicGraph.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport class BaseError {\n public static type: string = \"BaseError\";\n public message: string;\n public name: string;\n public stack?: string;\n\n constructor(message: string = \"\") {\n this.message = message;\n const constructor = this.constructor as any;\n this.name = constructor.type ?? this.constructor.name;\n\n // Capture stack trace if available\n if (typeof Error !== \"undefined\" && Error.captureStackTrace) {\n const temp = { stack: \"\" };\n Error.captureStackTrace(temp, this.constructor);\n this.stack = temp.stack;\n } else {\n try {\n throw new Error(message);\n } catch (err) {\n if (err instanceof Error) {\n this.stack = err.stack;\n }\n }\n }\n }\n\n toString(): string {\n return `${this.name}: ${this.message}`;\n }\n}\n",
6
+ "// original source: https://github.com/SegFaultx64/typescript-graph\n// previous fork: https://github.com/sroussey/typescript-graph\n// license: MIT\n\nimport { BaseError } from \"../utilities/BaseError\";\n\n/**\n * # NodeAlreadyExistsError\n *\n * This error is thrown when trying to create a node with the same identity as an existing node.\n *\n * @category Errors\n */\nexport class NodeAlreadyExistsError<T> extends BaseError {\n public static type: string = \"NodeAlreadyExistsError\";\n public newNode: T;\n public oldNode: T;\n public identity: unknown;\n\n constructor(newNode: T, oldNode: T, identity: unknown) {\n super(\n `${JSON.stringify(newNode)} shares an identity (${String(identity)}) with ${JSON.stringify(\n oldNode\n )}`\n );\n this.newNode = newNode;\n this.oldNode = oldNode;\n this.identity = identity;\n this.name = \"NodeAlreadyExistsError\";\n\n // This bs is due to a limitation of Typescript: https://github.com/facebook/jest/issues/8279\n Object.setPrototypeOf(this, NodeAlreadyExistsError.prototype);\n }\n}\n\n/**\n * # NodeDoesntExistError\n * This error is thrown when trying to access a node in a graph by it's identity when that node doesn't exist\n *\n * @category Errors\n */\nexport class NodeDoesntExistError extends BaseError {\n public static type: string = \"NodeDoesntExistError\";\n public identity: unknown;\n\n constructor(identity: unknown) {\n super(`A node with identity ${String(identity)} doesn't exist in the graph`);\n this.identity = identity;\n this.name = \"NodeDoesntExistError\";\n\n // This bs is due to a limitation of Typescript: https://github.com/facebook/jest/issues/8279\n Object.setPrototypeOf(this, NodeDoesntExistError.prototype);\n }\n}\n\n/**\n * # CycleError\n *\n * This error is thrown when attempting to create or update a Directed Acyclic Graph that contains a cycle.\n *\n * @category Errors\n */\nexport class CycleError extends BaseError {\n public static type: string = \"CycleError\";\n constructor(message: string) {\n super(message);\n this.name = \"CycleError\";\n\n // This bs is due to a limitation of Typescript: https://github.com/facebook/jest/issues/8279\n Object.setPrototypeOf(this, CycleError.prototype);\n }\n}\n",
7
+ "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * A type that represents a listener function for an event.\n * @template Events - A record of event names and their corresponding listener functions\n * @template EventType - The name of the event\n */\ntype EventListener<Events, EventType extends keyof Events> = Events[EventType];\n\n/**\n * A type that represents a list of listener functions for an event.\n * @template Events - A record of event names and their corresponding listener functions\n * @template EventType - The name of the event\n */\ntype EventListeners<Events, EventType extends keyof Events> = Array<{\n listener: EventListener<Events, EventType>;\n once?: boolean;\n}>;\n\n/**\n * A type that represents the parameters of an event.\n * @template Events - A record of event names and their corresponding listener functions\n * @template EventType - The name of the event\n */\nexport type EventParameters<Events, EventType extends keyof Events> = {\n [Event in EventType]: EventListener<Events, EventType> extends (...args: infer P) => any\n ? P\n : never;\n}[EventType];\n\n/**\n * A type that represents the return type of the emitted method.\n * @template Events - A record of event names and their corresponding listener functions\n * @template EventType - The name of the event\n */\nexport type EmittedReturnType<Events, EventType extends keyof Events> = EventParameters<\n Events,\n EventType\n>;\n\n/**\n * A class that implements an event emitter pattern.\n * @template EventListenerTypes - A record of event names and their corresponding listener functions\n */\nexport class EventEmitter<EventListenerTypes extends Record<string, (...args: any) => any>> {\n private listeners: {\n [Event in keyof EventListenerTypes]?: EventListeners<EventListenerTypes, Event>;\n } = {};\n\n /**\n * Remove all listeners for a specific event or all events\n * @param event - Optional event name. If not provided, removes all listeners for all events\n * @returns this, so that calls can be chained\n */\n removeAllListeners<Event extends keyof EventListenerTypes>(event?: Event): this {\n if (event) {\n delete this.listeners[event];\n } else {\n this.listeners = {};\n }\n return this;\n }\n\n /**\n * Adds a listener function for the event\n * @param event - The event name to listen for\n * @param listener - The listener function to add\n * @returns this, so that calls can be chained\n */\n on<Event extends keyof EventListenerTypes>(\n event: Event,\n listener: EventListener<EventListenerTypes, Event>\n ): this {\n const listeners: EventListeners<EventListenerTypes, Event> =\n this.listeners[event] || (this.listeners[event] = []);\n listeners.push({ listener });\n return this;\n }\n\n /**\n * Removes a listener function for the event\n * @param event - The event name to remove the listener from\n * @param listener - The listener function to remove\n * @returns this, so that calls can be chained\n */\n off<Event extends keyof EventListenerTypes>(\n event: Event,\n listener: EventListener<EventListenerTypes, Event>\n ): this {\n const listeners = this.listeners[event];\n if (!listeners) return this;\n\n const index = listeners.findIndex((l) => l.listener === listener);\n if (index >= 0) {\n listeners.splice(index, 1);\n }\n return this;\n }\n\n /**\n * Adds a listener function for the event that will be called only once\n * @param event - The event name to listen for\n * @param listener - The listener function to add\n * @returns this, so that calls can be chained\n */\n once<Event extends keyof EventListenerTypes>(\n event: Event,\n listener: EventListener<EventListenerTypes, Event>\n ): this {\n const listeners: EventListeners<EventListenerTypes, Event> =\n this.listeners[event] || (this.listeners[event] = []);\n listeners.push({ listener, once: true });\n return this;\n }\n\n /**\n * Returns a promise that resolves when the event is emitted\n * @param event - The event name to listen for\n * @returns a promise that resolves to an array of all parameters of the event (empty array for events with no parameters)\n */\n waitOn<Event extends keyof EventListenerTypes>(\n event: Event\n ): Promise<EmittedReturnType<EventListenerTypes, Event>> {\n return new Promise((resolve) => {\n // Create an anonymous function that captures all arguments and passes them to resolve\n const listener = ((...args: any[]) => {\n // Always resolve with the array of arguments (which may be empty)\n resolve(args as any);\n }) as EventListener<EventListenerTypes, Event>;\n\n this.once(event, listener);\n });\n }\n\n /**\n * Emits an event with the specified name and arguments\n * @param event - The event name to emit\n * @param args - Arguments to pass to the event listeners\n */\n public emit<Event extends keyof EventListenerTypes>(\n this: EventEmitter<EventListenerTypes>,\n event: Event,\n ...args: EventParameters<EventListenerTypes, Event>\n ) {\n const listeners: EventListeners<EventListenerTypes, Event> | undefined = this.listeners[event];\n if (listeners) {\n listeners.forEach(({ listener }) => {\n listener(...args);\n });\n // Remove once listeners we just called\n this.listeners[event] = listeners.filter((l) => !l.once);\n }\n }\n\n /**\n * Subscribes to an event and returns a function to unsubscribe\n * @param event - The event name to subscribe to\n * @param listener - The listener function to add\n * @returns a function to unsubscribe from the event\n */\n public subscribe<Event extends keyof EventListenerTypes>(\n event: Event,\n listener: EventListener<EventListenerTypes, Event>\n ): () => void {\n this.on(event, listener);\n return () => this.off(event, listener);\n }\n}\n",
8
+ "// original source: https://github.com/SegFaultx64/typescript-graph\n// previous fork: https://github.com/sroussey/typescript-graph\n// license: MIT\n\nimport { EventEmitter } from \"../events/EventEmitter\";\nimport { NodeAlreadyExistsError, NodeDoesntExistError } from \"./errors\";\n\n/**\n * This is the default [[Graph.constructor | `nodeIdentity`]] function it is simply imported from [object-hash](https://www.npmjs.com/package/object-hash)\n */\n\n/**\n * # Graph\n *\n * A `Graph` is is a simple undirected graph. On it's own it isn't too useful but it forms the basic functionality for the [[`DirectedGraph`]] and [[`DirectedAcyclicGraph`]].\n *\n * ## Creating a Graph\n *\n * You can create a graph to contain any type of node, for example:\n *\n * ```typescript\n * type NodeType = { a: Number, b: string }\n * const graph = new Graph<NodeType>()\n *\n * // Add a node of the defined type\n * const node: string = graph.insert({ a: 10, b: 'string' })\n *\n * // Get the node back\n * const nodeValue: NodeType | undefined = graph.getNode(node);\n * ```\n *\n * ### Defining a custom node identity\n *\n * When you create a graph you likely want to create include a custom `nodeIdentity` function.\n * This function tells the graph how to uniquely identify nodes in a graph,\n * default is to simply use an [[hash]] which means that functionality like [[`replace`]] will not work.\n *\n * ```typescript\n * type NodeType = { count: number, name: string }\n * const graph = new Graph<NodeType>((n) => n.name)\n *\n * // Add a node\n * graph.insert({ count: 5, name: 'node1' })\n * // This will throw an error even though `count` is different because they share a name.\n * graph.insert({ count: 20, name: 'node1' })\n * ```\n *\n * ### Adding an edge\n *\n * Graphs without edges aren't very useful. Inserting edges is done using the node identity string returned by the node identity function.\n *\n * ```typescript\n * const node1: string = graph.insert({ count: 5, name: 'node1' })\n * const node2: string = graph.insert({ count: 20, name: 'node2' })\n *\n * graph.addEdge(node1, node2)\n *\n * // This will throw an error since there is no node with the later name.\n * graph.addEdge(node1, 'not a real node')\n * ```\n *\n * In an undirected graph the order in which you input the node names doesn't matter,\n * but in directed graphs the \"from node\" comes first and the \"to node\" will come second.\n *\n * ### Replacing a node\n *\n * If a node already exists you can update it using [[`replace`]]. `nodeIdentity(newNode)` must be equal to `nodeIdentity(oldNode)`.\n *\n * ```typescript\n * const node1: string = graph.insert({ count: 5, name: 'node1' })\n * const node2: string = graph.insert({ count: 20, name: 'node2' })\n *\n * // This will work because the name has not changed.\n * graph.replace({ count: 15, name: 'node1' })\n *\n * // This will not work because the name has changed.\n * graph.replace({ count: 20, name: 'node3' })\n * ```\n *\n * [[`replace`]] will throw a [[`NodeDoesntExistError`]] exception if you are trying to replace a node that is missing from the graph.\n *\n * ### Upsert\n *\n * Often you will want to create a node node if it doesn't exist and update it does. This can be achieved using [[`upsert`]].\n *\n * ```typescript\n * const node1: string = graph.insert({ count: 5, name: 'node1' })\n *\n * // Both of these will work, the first updating node1 and the second creating a node.\n * const node2: string = graph.upsert({ count: 15, name: 'node1' })\n * const node3: string = graph.upsert({ count: 25, name: 'node3' })\n * ```\n *\n * [[`upsert`]] always return the node identity string of the inserted or updated node. At presented there is no way to tell if the node was created or updated.\n *\n * @typeParam Node `Node` is the node type of the graph. Nodes can be anything in all the included examples they are simple objects.\n * @typeParam Edge `Edge` is the edge type of the graph. Edges can be of any type, but must be truethy and by default they are `true` which is a simple boolean.\n * @typeParam NodeId `NodeId` is the identity type of the node, by default it is a `unknown`, though most will use `string` or `number`.\n * @typeParam EdgeId `EdgeId` is the identity type of the edge, by default it is a `unknown`, though most will use `string` or `number`.\n */\n\nexport type AdjacencyValue<Edge> = null | Array<Edge>;\nexport type AdjacencyMatrix<Edge> = Array<Array<AdjacencyValue<Edge>>>;\n\n/**\n * Events that can be emitted by the TaskGraph\n */\nexport type GraphEvents<NodeId, EdgeId> = keyof GraphEventListeners<NodeId, EdgeId>;\n\nexport type GraphEventListeners<NodeId, EdgeId> = {\n \"node-added\": (node: NodeId) => void;\n \"node-removed\": (node: NodeId) => void;\n \"node-replaced\": (node: NodeId) => void;\n \"edge-added\": (edge: EdgeId) => void;\n \"edge-removed\": (edge: EdgeId) => void;\n \"edge-replaced\": (edge: EdgeId) => void;\n};\n\nexport type GraphEventListener<\n NodeId,\n EdgeId,\n Event extends GraphEvents<NodeId, EdgeId>,\n> = GraphEventListeners<NodeId, EdgeId>[Event];\n\nexport type GraphEventParameters<\n NodeId,\n EdgeId,\n Event extends GraphEvents<NodeId, EdgeId>,\n> = Parameters<GraphEventListeners<NodeId, EdgeId>[Event]>;\n\nexport class Graph<Node, Edge = true, NodeId = unknown, EdgeId = unknown> {\n protected nodes: Map<NodeId, Node>;\n protected adjacency: AdjacencyMatrix<Edge>;\n protected nodeIdentity: (t: Node) => NodeId;\n protected edgeIdentity: (t: Edge, n1: NodeId, n2: NodeId) => EdgeId;\n\n constructor(\n nodeIdentity: (node: Node) => NodeId,\n edgeIdentity: (edge: Edge, node1Identity: NodeId, node2Identit: NodeId) => EdgeId\n ) {\n this.nodes = new Map();\n this.adjacency = [];\n this.nodeIdentity = nodeIdentity;\n this.edgeIdentity = edgeIdentity;\n }\n\n events = new EventEmitter<GraphEventListeners<NodeId, EdgeId>>();\n on<Event extends GraphEvents<NodeId, EdgeId>>(\n name: Event,\n fn: GraphEventListener<NodeId, EdgeId, Event>\n ) {\n this.events.on.call(this.events, name, fn);\n }\n off<Event extends GraphEvents<NodeId, EdgeId>>(\n name: Event,\n fn: GraphEventListener<NodeId, EdgeId, Event>\n ) {\n this.events.off.call(this.events, name, fn);\n }\n emit<Event extends GraphEvents<NodeId, EdgeId>>(\n name: Event,\n ...args: Parameters<GraphEventListener<NodeId, EdgeId, Event>>\n ) {\n this.events.emit<Event>(name, ...args);\n }\n\n /**\n * Add a node to the graph if it doesn't already exist. If it does, throw a [[`NodeAlreadyExistsError`]].\n *\n * @param node The node to be added\n * @returns A `string` that is the identity of the newly inserted node. This is created by applying the [[constructor | `nodeIdentity`]].\n */\n insert(node: Node): NodeId {\n const id = this.nodeIdentity(node);\n const isOverwrite = this.nodes.has(id);\n\n if (isOverwrite) {\n throw new NodeAlreadyExistsError(node, this.nodes.get(id), id);\n }\n\n this.nodes.set(id, node);\n this.adjacency.map((adj) => adj.push(null));\n this.adjacency.push(new Array<AdjacencyValue<Edge>>(this.adjacency.length + 1).fill(null));\n\n this.emit(\"node-added\", id);\n\n return id;\n }\n\n /**\n * This replaces an existing node in the graph with an updated version.\n * Throws a [[`NodeDoesNotExistsError`]] if no node with the same identity already exists.\n *\n * __Caveat_:_ The default identity function means that this will never work since if the node changes it will have a different [[`hash`]].\n *\n * @param node The new node that is replacing the old one.\n */\n replace(node: Node): void {\n const id = this.nodeIdentity(node);\n const isOverwrite = this.nodes.has(id);\n\n if (!isOverwrite) {\n throw new NodeDoesntExistError(id);\n }\n\n this.nodes.set(id, node);\n\n this.emit(\"node-replaced\", id);\n }\n\n /**\n * This essentially combines the behavior of [[`insert`]] and [[`replace`]].\n * If the node doesn't exist, create it. If the node already exists, replace it with the updated version.\n *\n * @param node The node to insert or update\n * @returns The identity string of the node inserted or updated.\n */\n upsert(node: Node): NodeId {\n const id = this.nodeIdentity(node);\n const isOverwrite = this.nodes.has(id);\n\n this.nodes.set(id, node);\n\n if (!isOverwrite) {\n this.adjacency.map((adj) => adj.push(null));\n this.adjacency.push(new Array<AdjacencyValue<Edge>>(this.adjacency.length + 1).fill(null));\n this.emit(\"node-added\", id);\n } else {\n this.emit(\"node-replaced\", id);\n }\n\n return id;\n }\n\n /**\n * Create an edge between two nodes in the graph.\n * Throws a [[`NodeDoesNotExistsError`]] if no either of the nodes you are attempting to connect do not exist.\n *\n * @param node1Identity The first node to connect (in [[`DirectedGraph`]]s and [[`DirectedAcyclicGraph`]]s this is the `source` node.)\n * @param node2Identity The second node to connect (in [[`DirectedGraph`]]s and [[`DirectedAcyclicGraph`]]s this is the `target` node)\n * @param edge The edge to be added. By default this is `true` but it can be any type.\n */\n addEdge(node1Identity: NodeId, node2Identity: NodeId, edge?: Edge): EdgeId {\n if (edge === undefined) {\n edge = true as Edge;\n }\n const node1Exists = this.nodes.has(node1Identity);\n const node2Exists = this.nodes.has(node2Identity);\n\n if (!node1Exists) {\n throw new NodeDoesntExistError(node1Identity);\n }\n\n if (!node2Exists) {\n throw new NodeDoesntExistError(node2Identity);\n }\n\n const node1Index = Array.from(this.nodes.keys()).indexOf(node1Identity);\n const node2Index = Array.from(this.nodes.keys()).indexOf(node2Identity);\n\n if (this.adjacency[node1Index][node2Index] === null) {\n this.adjacency[node1Index][node2Index] = [edge];\n } else {\n if (!this.adjacency[node1Index][node2Index]!.includes(edge)) {\n this.adjacency[node1Index][node2Index]!.push(edge);\n }\n }\n\n const id = this.edgeIdentity(edge, node1Identity, node2Identity);\n this.emit(\"edge-added\", id);\n\n return id;\n }\n\n /**\n * This simply returns all the nodes stored in the graph\n *\n * @param compareFunc An optional function that indicates the sort order of the returned array\n */\n getNodes(compareFunc?: (a: Node, b: Node) => number): Node[] {\n const temp = Array.from(this.nodes.values());\n\n if (compareFunc !== undefined) {\n return temp.sort(compareFunc);\n }\n\n return temp;\n }\n\n /**\n * Returns a specific node given the node identity returned from the [[`insert`]] function\n */\n getNode(nodeIdentity: NodeId): Node | undefined {\n return this.nodes.get(nodeIdentity);\n }\n\n /**\n * Returns true if the node exists in the graph.\n */\n hasNode(nodeIdentity: NodeId): boolean {\n return this.nodes.has(nodeIdentity);\n }\n\n /**\n * Returns all edges in the graph as an array of tuples.\n */\n getEdges(): Array<[node1Identity: NodeId, node2Identity: NodeId, edge: Edge]> {\n const toReturn: Array<[node1Identity: NodeId, node2Identity: NodeId, edge: Edge]> = [];\n\n const nodeKeys = Array.from(this.nodes.keys());\n this.adjacency.forEach((row, rowIndex) => {\n const node1Identity = nodeKeys[rowIndex];\n if (node1Identity != null) {\n row.forEach((edges, colIndex) => {\n if (edges !== null) {\n const node2Identity = nodeKeys[colIndex];\n if (node2Identity != null) {\n for (const edge of edges) {\n toReturn.push([node1Identity, node2Identity, edge]);\n }\n }\n }\n });\n }\n });\n\n return toReturn;\n }\n\n /**\n * Returns the out edges for a specific node.\n */\n outEdges(\n node1Identity: NodeId\n ): Array<[node1Identity: NodeId, node2Identity: NodeId, edge: Edge]> {\n const nodeKeys = Array.from(this.nodes.keys());\n const nodeIndex = nodeKeys.indexOf(node1Identity);\n\n const toReturn: Array<[node1Identity: NodeId, node2Identity: NodeId, edge: Edge]> = [];\n\n this.adjacency[nodeIndex].forEach((edges, colIndex) => {\n if (edges !== null) {\n const node2Identity = nodeKeys[colIndex];\n if (node2Identity != null) {\n for (const edge of edges) {\n toReturn.push([node1Identity, node2Identity, edge]);\n }\n }\n }\n });\n\n return toReturn;\n }\n\n /**\n * Returns the in edges for a specific node.\n */\n inEdges(\n node2Identity: NodeId\n ): Array<[node1Identity: NodeId, node2Identity: NodeId, edge: Edge]> {\n const nodeKeys = Array.from(this.nodes.keys());\n const node2Index = nodeKeys.indexOf(node2Identity);\n\n const toReturn: Array<[node1Identity: NodeId, node2Identity: NodeId, edge: Edge]> = [];\n\n this.adjacency.forEach((row, rowIndex) => {\n const node1Identity = nodeKeys[rowIndex];\n const edges = row[node2Index];\n if (edges !== null) {\n for (const edge of edges) {\n toReturn.push([node1Identity, node2Identity, edge]);\n }\n }\n });\n\n return toReturn;\n }\n\n /**\n * Returns the edges for a specific node.\n */\n nodeEdges(\n nodeIdentity: NodeId\n ): Array<[node1Identity: NodeId, node2Identity: NodeId, edge: Edge]> {\n return [...this.outEdges(nodeIdentity), ...this.inEdges(nodeIdentity)];\n }\n\n /**\n * Deletes an edge between two nodes in the graph.\n * Throws a [[`NodeDoesNotExistsError`]] if either of the nodes do not exist.\n *\n * @param node1Identity The identity of the first node (in [[`DirectedGraph`]]s and [[`DirectedAcyclicGraph`]]s this is the `from` node.)\n * @param node2Identity The identity of the second node (in [[`DirectedGraph`]]s and [[`DirectedAcyclicGraph`]]s this is the `to` node)\n * @param edgeIdentity The identity of the edge to be deleted. If not provided, all edges between the two nodes will be deleted.\n */\n removeEdge(node1Identity: NodeId, node2Identity: NodeId, edgeIdentity?: EdgeId): void {\n const node1Exists = this.nodes.has(node1Identity);\n const node2Exists = this.nodes.has(node2Identity);\n\n if (!node1Exists) {\n throw new NodeDoesntExistError(node1Identity);\n }\n\n if (!node2Exists) {\n throw new NodeDoesntExistError(node2Identity);\n }\n\n const node1Index = Array.from(this.nodes.keys()).indexOf(node1Identity);\n const node2Index = Array.from(this.nodes.keys()).indexOf(node2Identity);\n\n if (edgeIdentity === undefined) {\n this.adjacency[node1Index][node2Index] = null;\n } else {\n // Remove the corresponding column from the adjacency matrix\n // this is not an optimized way to do this but we have edge as an opaque type\n for (const row of this.adjacency) {\n for (const edgelist of row) {\n if (edgelist !== null) {\n for (let edgeIndex = 0; edgeIndex < edgelist.length; edgeIndex++) {\n if (\n this.edgeIdentity(edgelist[edgeIndex], node1Identity, node2Identity) ===\n edgeIdentity\n ) {\n edgelist.splice(edgeIndex, 1);\n }\n }\n }\n }\n }\n }\n this.emit(\"edge-removed\", edgeIdentity as EdgeId);\n }\n\n /**\n * Deletes a node from the graph, along with any edges associated with it.\n * Throws a [[`NodeDoesNotExistsError`]] if the node does not exist.\n *\n * @param nodeIdentity The identity of the node to be deleted.\n */\n remove(nodeIdentity: NodeId): void {\n if (!this.nodes.has(nodeIdentity)) {\n throw new NodeDoesntExistError(nodeIdentity);\n }\n\n // Remove the node from the nodes map\n this.nodes.delete(nodeIdentity);\n\n // Find the index of the node in the adjacency matrix\n const nodeIndex = Array.from(this.nodes.keys()).indexOf(nodeIdentity);\n\n // Remove the corresponding row from the adjacency matrix\n this.adjacency.splice(nodeIndex, 1);\n\n // Remove the corresponding column from the adjacency matrix\n this.adjacency.forEach((row) => row.splice(nodeIndex, 1));\n\n this.emit(\"node-removed\", nodeIdentity);\n }\n\n /**\n * @alias remove\n */\n removeNode(nodeIdentity: NodeId): void {\n return this.remove(nodeIdentity);\n }\n\n /**\n * @alias insert\n */\n addNode(node: Node): NodeId {\n return this.insert(node);\n }\n\n /**\n * Add nodes in bulk\n */\n addNodes(nodes: Node[]): NodeId[] {\n return nodes.map((node) => this.insert(node));\n }\n\n /**\n * Add edges\n * @param edges An array of tuples, each tuple containing the identity of the source node, the identity of the target node, and the edge to add.\n */\n addEdges(\n edges: Array<[node1Identity: NodeId, node2Identity: NodeId, edge?: Edge | undefined]>\n ): EdgeId[] {\n return edges.map(([node1Identity, node2Identity, edge]) =>\n this.addEdge(node1Identity, node2Identity, edge)\n );\n }\n}\n",
9
+ "// original source: https://github.com/SegFaultx64/typescript-graph\n// previous fork: https://github.com/sroussey/typescript-graph\n// license: MIT\n\nimport { NodeDoesntExistError } from \"./errors\";\nimport { type AdjacencyMatrix, Graph } from \"./graph\";\n\n/**\n * # DirectedGraph\n *\n * A DirectedGraph is similar a [[`Graph`]] but with additional functionality.\n *\n * @typeParam Node `Node` is the node type of the graph. Nodes can be anything in all the included examples they are simple objects.\n * @typeParam Edge `Edge` is the edge type of the graph. Edges can be of any type, but must be truethy and by default they are `true` which is a simple boolean.\n * @typeParam NodeId `NodeId` is the identity type of the node, by default it is a `unknown`, though most will use `string` or `number`.\n * @typeParam EdgeId `EdgeId` is the identity type of the edge, by default it is a `unknown`, though most will use `string` or `number`.\n */\nexport class DirectedGraph<Node, Edge = true, NodeId = unknown, EdgeId = unknown> extends Graph<\n Node,\n Edge,\n NodeId,\n EdgeId\n> {\n /** Caches if the graph contains a cycle. If `undefined` then it is unknown. */\n protected hasCycle: boolean | undefined = false;\n\n /**\n * Returns `true` if there are no cycles in the graph.\n * This relies on a cached value so calling it multiple times without adding edges to the graph should be O(1) after the first call.\n * Non-cached calls are potentially expensive, the implementation is based on Kahn's algorithim which is O(|EdgeCount| + |NodeCount|).\n */\n isAcyclic(): boolean {\n if (this.hasCycle !== undefined) {\n return !this.hasCycle;\n }\n\n const nodeIndices = Array.from(this.nodes.keys());\n const nodeInDegrees = new Map(\n Array.from(this.nodes.keys()).map((n) => [n, this.indegreeOfNode(n)])\n );\n\n const toSearch = Array.from(nodeInDegrees).filter((pair) => pair[1] === 0);\n\n let visitedNodes = 0;\n\n while (toSearch.length > 0) {\n const cur = toSearch.pop();\n if (cur === undefined) {\n continue;\n }\n\n const nodeIndex = nodeIndices.indexOf(cur[0]);\n this.adjacency[nodeIndex].forEach((hasAdj, index) => {\n if (hasAdj !== null) {\n const currentInDegree = nodeInDegrees.get(nodeIndices[index]);\n if (currentInDegree !== undefined) {\n nodeInDegrees.set(nodeIndices[index], currentInDegree - 1);\n if (currentInDegree - 1 === 0) {\n toSearch.push([nodeIndices[index], currentInDegree - 1]);\n }\n }\n }\n });\n\n visitedNodes++;\n }\n\n this.hasCycle = !(visitedNodes === this.nodes.size);\n\n return visitedNodes === this.nodes.size;\n }\n\n /**\n * The indegree of a node is the number of edges that point to it. This will always be an integer.\n *\n * Throws a [[`NodeDoesntExistError`]] the node does not exist.\n *\n * @param nodeID The string of the node identity of the node to calculate indegree for.\n */\n indegreeOfNode(nodeID: NodeId): number {\n const nodeIdentities = Array.from(this.nodes.keys());\n const indexOfNode = nodeIdentities.indexOf(nodeID);\n\n if (indexOfNode === -1) {\n throw new NodeDoesntExistError(nodeID);\n }\n\n return this.adjacency.reduce<number>((carry, row) => {\n return carry + (row[indexOfNode] == null ? 0 : 1);\n }, 0);\n }\n\n /**\n * Add a directed edge to the graph.\n *\n * @param sourceNodeIdentity The identity string of the node the edge should run from.\n * @param targetNodeIdentity The identity string of the node the edge should run to.\n * @param edge The edge to add to the graph. If not provided it defaults to `true`.\n * @param skipUpdatingCyclicality This boolean indicates if the cache of the cyclicality of the graph should be updated.\n * If `false` is passed the cycle cache will be invalidated because we can not assure that a cycle has not been created.\n */\n addEdge(\n sourceNodeIdentity: NodeId,\n targetNodeIdentity: NodeId,\n edge?: Edge,\n skipUpdatingCyclicality: boolean = false\n ): EdgeId {\n if (edge === undefined) {\n edge = true as Edge;\n }\n if (this.hasCycle === false && !skipUpdatingCyclicality) {\n this.hasCycle = this.wouldAddingEdgeCreateCycle(sourceNodeIdentity, targetNodeIdentity);\n } else if (skipUpdatingCyclicality) {\n this.hasCycle = undefined;\n }\n\n return super.addEdge(sourceNodeIdentity, targetNodeIdentity, edge);\n }\n\n /**\n * Depth first search to see if one node is reachable from another following the directed edges.\n *\n * __Caveat:__ This will return false if `startNode` and `endNode` are the same node and there is not a cycle or a loop edge connecting them.\n *\n * @param startNode The string identity of the node to start at.\n * @param endNode The string identity of the node we are attempting to reach.\n */\n canReachFrom(startNode: NodeId, endNode: NodeId): boolean {\n const nodeIdentities = Array.from(this.nodes.keys());\n const startNodeIndex = nodeIdentities.indexOf(startNode);\n const endNodeIndex = nodeIdentities.indexOf(endNode);\n\n if (this.adjacency[startNodeIndex][endNodeIndex] != null) {\n return true;\n }\n\n return this.adjacency[startNodeIndex].reduce<boolean>((carry, edge, index) => {\n if (carry || edge === null) {\n return carry;\n }\n\n return this.canReachFrom(nodeIdentities[index], endNode);\n }, false);\n }\n\n /**\n * Checks if adding the specified edge would create a cycle.\n * Returns true in O(1) if the graph already contains a known cycle, or if `sourceNodeIdentity` and `targetNodeIdentity` are the same.\n *\n * @param sourceNodeIdentity The string identity of the node the edge is from.\n * @param targetNodeIdentity The string identity of the node the edge is to.\n */\n wouldAddingEdgeCreateCycle(sourceNodeIdentity: NodeId, targetNodeIdentity: NodeId): boolean {\n return (\n this.hasCycle ||\n sourceNodeIdentity === targetNodeIdentity ||\n this.canReachFrom(targetNodeIdentity, sourceNodeIdentity)\n );\n }\n\n /**\n * Given a starting node this returns a new [[`DirectedGraph`]] containing all the nodes that can be reached.\n * Throws a [[`NodeDoesntExistError`]] if the start node does not exist.\n *\n * @param startNodeIdentity The string identity of the node from which the subgraph search should start.\n */\n getSubGraphStartingFrom(startNodeIdentity: NodeId): DirectedGraph<Node, Edge, NodeId, EdgeId> {\n const nodeIndices = Array.from(this.nodes.keys());\n const initalNode = this.nodes.get(startNodeIdentity);\n\n if (initalNode == null) {\n throw new NodeDoesntExistError(startNodeIdentity);\n }\n\n const recur = (startNodeIdentity: NodeId, nodesToInclude: Node[]): Node[] => {\n let toReturn = [...nodesToInclude];\n const nodeIndex = nodeIndices.indexOf(startNodeIdentity);\n this.adjacency[nodeIndex].forEach((hasAdj, index) => {\n if (\n hasAdj !== null &&\n nodesToInclude.find((n) => this.nodeIdentity(n) === nodeIndices[index]) == null\n ) {\n const newNode = this.nodes.get(nodeIndices[index]);\n\n if (newNode != null) {\n toReturn = [...recur(nodeIndices[index], toReturn), newNode];\n }\n }\n });\n\n return toReturn;\n };\n\n const newGraph = new DirectedGraph<Node, Edge, NodeId, EdgeId>(\n this.nodeIdentity,\n this.edgeIdentity\n );\n const nodeList = recur(startNodeIdentity, [initalNode]);\n const includeIdents = nodeList.map((t) => this.nodeIdentity(t));\n Array.from(this.nodes.values()).forEach((n) => {\n if (includeIdents.includes(this.nodeIdentity(n))) {\n newGraph.insert(n);\n }\n });\n newGraph.adjacency = this.subAdj(nodeList);\n return newGraph;\n }\n\n private subAdj(include: Node[]): AdjacencyMatrix<Edge> {\n const includeIdents = include.map((t) => this.nodeIdentity(t));\n const nodeIndices = Array.from(this.nodes.keys());\n\n return this.adjacency.reduce<AdjacencyMatrix<Edge>>((carry, cur, index) => {\n if (includeIdents.includes(nodeIndices[index])) {\n return [...carry, cur.filter((_, index) => includeIdents.includes(nodeIndices[index]))];\n } else {\n return carry;\n }\n }, []);\n }\n\n /**\n * Returns all edges in the graph as an array of tuples.\n */\n getEdges(): Array<[sourceNodeIdentity: NodeId, targetNodeIdentity: NodeId, edge: Edge]> {\n return super.getEdges();\n }\n\n /**\n * Deletes an edge between two nodes in the graph.\n * Throws a [[`NodeDoesNotExistsError`]] if either of the nodes do not exist.\n *\n * @param sourceNodeIdentity The identity of the source node\n * @param targetNodeIdentity The identity of the target node\n * @param edgeIdentity The identity of the edge to be deleted. If not provided, all edges between the two nodes will be deleted.\n */\n removeEdge(sourceNodeIdentity: NodeId, targetNodeIdentity: NodeId, edgeIdentity?: EdgeId): void {\n super.removeEdge(sourceNodeIdentity, targetNodeIdentity, edgeIdentity);\n\n // Invalidate the cycle cache as the graph structure has changed\n this.hasCycle = undefined;\n }\n\n /**\n * Deletes a node from the graph, along with any edges associated with it.\n * Throws a [[`NodeDoesNotExistsError`]] if the node does not exist.\n *\n * @param nodeIdentity The identity of the node to be deleted.\n */\n remove(nodeIdentity: NodeId): void {\n super.remove(nodeIdentity);\n\n // Invalidate the cycle cache as the graph structure has changed\n this.hasCycle = undefined;\n }\n\n /**\n * Add edges\n * @param edges An array of tuples, each tuple containing the identity of the source node, the identity of the target node, and the edge to add.\n */\n addEdges(\n edges: Array<[sourceNodeIdentity: NodeId, targetNodeIdentity: NodeId, edge?: Edge | undefined]>\n ): EdgeId[] {\n return super.addEdges(edges);\n }\n}\n",
10
+ "// original source: https://github.com/SegFaultx64/typescript-graph\n// previous fork: https://github.com/sroussey/typescript-graph\n// license: MIT\n\nimport { DirectedGraph } from \"./directedGraph\";\nimport { CycleError } from \"./errors\";\n\n/**\n * # DirectedAcyclicGraph\n *\n * A DirectedAcyclicGraph is builds on a [[`DirectedGraph`]] but enforces acyclicality. You cannot add an edge to a DirectedAcyclicGraph that would create a cycle.\n *\n * @typeParam Node `Node` is the node type of the graph. Nodes can be anything in all the included examples they are simple objects.\n * @typeParam Edge `Edge` is the edge type of the graph. Edges can be of any type, but must be truethy and by default they are `true` which is a simple boolean.\n * @typeParam NodeId `NodeId` is the identity type of the node, by default it is a `unknown`, though most will use `string` or `number`.\n * @typeParam EdgeId `EdgeId` is the identity type of the edge, by default it is a `unknown`, though most will use `string` or `number`.\n */\nexport class DirectedAcyclicGraph<\n Node,\n Edge = true,\n NodeId = unknown,\n EdgeId = unknown,\n> extends DirectedGraph<Node, Edge, NodeId, EdgeId> {\n private _topologicallySortedNodes?: Node[];\n\n /**\n * Converts an existing directed graph into a directed acyclic graph.\n * Throws a {@linkcode CycleError} if the graph attempting to be converted contains a cycle.\n * @param graph The source directed graph to convert into a DAG\n */\n static fromDirectedGraph<Node, Edge, NodeId, EdgeId>(\n graph: DirectedGraph<Node, Edge, NodeId, EdgeId>\n ): DirectedAcyclicGraph<Node, Edge, NodeId, EdgeId> {\n if (!graph.isAcyclic()) {\n throw new CycleError(\"Can't convert that graph to a DAG because it contains a cycle\");\n }\n const toRet = new DirectedAcyclicGraph<Node, Edge, NodeId, EdgeId>(\n // @ts-expect-error\n graph.nodeIdentity,\n // @ts-expect-error\n graph.edgeIdentity\n );\n\n toRet.nodes = (graph as any).nodes;\n toRet.adjacency = (graph as any).adjacency;\n\n return toRet;\n }\n\n /**\n * Adds an edge to the graph similarly to [[`DirectedGraph.addEdge`]] but maintains correctness of the acyclic graph.\n * Thows a [[`CycleError`]] if adding the requested edge would create a cycle.\n * Adding an edge invalidates the cache of topologically sorted nodes, rather than updating it.\n *\n * @param sourceNodeIdentity The identity string of the node the edge should run from.\n * @param targetNodeIdentity The identity string of the node the edge should run to.\n * @param edge The edge to add to the graph. If not provided it defaults to `true`.\n */\n addEdge(sourceNodeIdentity: NodeId, targetNodeIdentity: NodeId, edge?: Edge): EdgeId {\n if (edge === undefined) {\n edge = true as Edge;\n }\n if (this.wouldAddingEdgeCreateCycle(sourceNodeIdentity, targetNodeIdentity)) {\n throw new CycleError(\n `Can't add edge from ${String(sourceNodeIdentity)} to ${String(\n targetNodeIdentity\n )} it would create a cycle`\n );\n }\n\n // Invalidate cache of toposorted nodes\n this._topologicallySortedNodes = undefined;\n return super.addEdge(sourceNodeIdentity, targetNodeIdentity, edge, true);\n }\n\n /**\n * Inserts a node into the graph and maintains topologic sort cache by prepending the node\n * (since all newly created nodes have an [[ indegreeOfNode | indegree ]] of zero.)\n *\n * @param node The node to insert\n */\n insert(node: Node): NodeId {\n if (this._topologicallySortedNodes !== undefined) {\n this._topologicallySortedNodes = [node, ...this._topologicallySortedNodes];\n }\n\n return super.insert(node);\n }\n\n /**\n * Topologically sort the nodes using Kahn's algorithm. Uses a cache which means that repeated calls should be O(1) after the first call.\n * Non-cached calls are potentially expensive, Kahn's algorithim is O(|EdgeCount| + |NodeCount|).\n * There may be more than one valid topological sort order for a single graph,\n * so just because two graphs are the same does not mean that order of the resultant arrays will be.\n *\n * @returns An array of nodes sorted by the topological order.\n */\n topologicallySortedNodes(): Node[] {\n if (this._topologicallySortedNodes !== undefined) {\n return this._topologicallySortedNodes;\n }\n\n const nodeIndices = Array.from(this.nodes.keys());\n const nodeInDegrees = new Map(\n Array.from(this.nodes.keys()).map((n) => [n, this.indegreeOfNode(n)])\n );\n\n const adjCopy = this.adjacency.map((a) => [...a]);\n\n const toSearch = Array.from(nodeInDegrees).filter((pair) => pair[1] === 0);\n\n if (toSearch.length === this.nodes.size) {\n const arrayOfNodes = Array.from(this.nodes.values());\n this._topologicallySortedNodes = arrayOfNodes;\n return arrayOfNodes;\n }\n\n const toReturn: Node[] = [];\n\n while (toSearch.length > 0) {\n const n = toSearch.pop();\n if (n === undefined) {\n throw new Error(\"Unexpected empty array\");\n }\n const curNode = this.nodes.get(n[0]);\n if (curNode == null) {\n throw new Error(\"This should never happen\");\n }\n toReturn.push(curNode);\n\n adjCopy[nodeIndices.indexOf(n[0])]?.forEach((edge, index) => {\n if (edge !== null) {\n adjCopy[nodeIndices.indexOf(n[0])][index] = null;\n const target = nodeInDegrees.get(nodeIndices[index]);\n if (target !== undefined) {\n nodeInDegrees.set(nodeIndices[index], target - 1);\n if (target - 1 === 0) {\n toSearch.push([nodeIndices[index], 0]);\n }\n } else {\n throw new Error(\"This should never happen\");\n }\n }\n });\n }\n\n // Update cache\n this._topologicallySortedNodes = toReturn;\n\n // we shouldn't need to account for the error case of there being a cycle because it shouldn't\n // be possible to instantiate this class in a state (or put it in a state) where there is a cycle.\n\n return toReturn;\n }\n\n /**\n * Given a starting node this returns a new [[`DirectedA`]] containing all the nodes that can be reached.\n * Throws a [[`NodeDoesntExistError`]] if the start node does not exist.\n *\n * @param startNodeIdentity The string identity of the node from which the subgraph search should start.\n */\n getSubGraphStartingFrom(\n startNodeIdentity: NodeId\n ): DirectedAcyclicGraph<Node, Edge, NodeId, EdgeId> {\n return DirectedAcyclicGraph.fromDirectedGraph(super.getSubGraphStartingFrom(startNodeIdentity));\n }\n\n /**\n * Deletes an edge between two nodes in the graph.\n * Throws a [[`NodeDoesNotExistsError`]] if either of the nodes do not exist.\n *\n * @param sourceNodeIdentity The identity of the source node\n * @param targetNodeIdentity The identity of the target node\n * @param edgeIdentity The identity of the edge to be deleted. If not provided, all edges between the two nodes will be deleted.\n */\n removeEdge(sourceNodeIdentity: NodeId, targetNodeIdentity: NodeId, edgeIdentity?: EdgeId): void {\n super.removeEdge(sourceNodeIdentity, targetNodeIdentity, edgeIdentity);\n\n // Invalidate the topologically sorted nodes cache\n this._topologicallySortedNodes = undefined;\n }\n\n /**\n * Deletes a node from the graph, along with any edges associated with it.\n * Throws a [[`NodeDoesNotExistsError`]] if the node does not exist.\n *\n * @param nodeIdentity The identity of the node to be deleted.\n */\n remove(nodeIdentity: NodeId): void {\n super.remove(nodeIdentity);\n\n // Invalidate the topologically sorted nodes cache\n this._topologicallySortedNodes = undefined;\n }\n}\n"
11
+ ],
12
+ "mappings": ";AAMO,MAAM,UAAU;AAAA,SACP,OAAe;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA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AAAA,EAST,uBAAuB,CACrB,mBACkD;AAAA,IAClD,OAAO,qBAAqB,kBAAkB,MAAM,wBAAwB,iBAAiB,CAAC;AAAA;AAAA,EAWhG,UAAU,CAAC,oBAA4B,oBAA4B,cAA6B;AAAA,IAC9F,MAAM,WAAW,oBAAoB,oBAAoB,YAAY;AAAA,IAGrE,KAAK,4BAA4B;AAAA;AAAA,EASnC,MAAM,CAAC,cAA4B;AAAA,IACjC,MAAM,OAAO,YAAY;AAAA,IAGzB,KAAK,4BAA4B;AAAA;AAErC;",
13
+ "debugId": "1E5D727E61CDDE0164756E2164756E21",
14
+ "names": []
15
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Semantic Compatibility Utilities for Task Graph Dataflows
8
+ *
9
+ * In this project, task graphs have connections between tasks called dataflows.
10
+ * These dataflows have different kinds of compatibility checks:
11
+ *
12
+ * **Static Compatibility:**
13
+ * Static rules help decide if an edge should be connected at all. A connection
14
+ * is statically compatible if:
15
+ * - The source and target are the same exact type
16
+ * - The source connects to the equivalent of "any" (target accepts anything)
17
+ * - The source type is acceptable to the target (e.g., a string to something
18
+ * that accepts oneOf[string[], string])
19
+ *
20
+ * **Runtime Compatibility:**
21
+ * Assuming the connection is allowed at design time (passes static check),
22
+ * runtime rules determine if they are compatible during execution.
23
+ *
24
+ * Currently, there is one runtime compatibility check:
25
+ * - If both input and output schemas have 'format' annotations attached,
26
+ * the format annotation has the format /\w+(:\w+)?/ where the first part
27
+ * is the "name" and if alone matches any other with the same "name".
28
+ * If there is a second part, then that narrows the type.
29
+ * - Format checks apply to all types (strings, arrays, etc.), not just strings
30
+ * - A schema with format can connect to a schema with no format (source has format, target doesn't)
31
+ * - A schema with no format cannot connect to a schema with format (source doesn't have format, target does)
32
+ *
33
+ * Example: In the AI package, 'format':'model' and 'format': 'model:EmbeddingTask'
34
+ * are used on string types. An input with property `model` and 'format':'model'
35
+ * connects to a target with property `model` and 'format':'model:EmbeddingTask' --
36
+ * this compatibility is called "runtime". It first passes the static check as
37
+ * compatible and then notices a difference in format runtime.
38
+ *
39
+ * Format is also used on array types, e.g., 'format':'Float64Array' on arrays
40
+ * containing Float64 numbers.
41
+ *
42
+ * Only connections that pass the runtime check will pass data at runtime.
43
+ */
44
+ import type { JsonSchema } from "./JsonSchema";
45
+ /**
46
+ * Checks if two JSON schemas are semantically compatible.
47
+ * Returns:
48
+ * - "static": Compatible at design time, no runtime check needed
49
+ * - "runtime": Compatible at design time, but needs runtime semantic check
50
+ * - "incompatible": Not compatible
51
+ */
52
+ export declare function areSemanticallyCompatible(sourceSchema: JsonSchema, targetSchema: JsonSchema): "static" | "runtime" | "incompatible";
53
+ /**
54
+ * Checks if two object schemas are semantically compatible.
55
+ * This is a helper function for checking object-level schema compatibility.
56
+ */
57
+ export declare function areObjectSchemasSemanticallyCompatible(sourceSchema: JsonSchema, targetSchema: JsonSchema): "static" | "runtime" | "incompatible";
58
+ //# sourceMappingURL=SchemaUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaUtils.d.ts","sourceRoot":"","sources":["../../src/json-schema/SchemaUtils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AA8N/C;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,UAAU,EACxB,YAAY,EAAE,UAAU,GACvB,QAAQ,GAAG,SAAS,GAAG,cAAc,CA8RvC;AAED;;;GAGG;AACH,wBAAgB,sCAAsC,CACpD,YAAY,EAAE,UAAU,EACxB,YAAY,EAAE,UAAU,GACvB,QAAQ,GAAG,SAAS,GAAG,cAAc,CAEvC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export { compileSchema } from "@sroussey/json-schema-library";
7
+ export type { SchemaNode } from "@sroussey/json-schema-library";
8
+ //# sourceMappingURL=SchemaValidation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaValidation.d.ts","sourceRoot":"","sources":["../../src/json-schema/SchemaValidation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,YAAY,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export * from "./media/image";
7
+ export * from "./media/image.browser";
8
+ //# sourceMappingURL=media-browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media-browser.d.ts","sourceRoot":"","sources":["../src/media-browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,73 @@
1
+ // src/media/image.ts
2
+ function parseDataUri(dataUri) {
3
+ const match = dataUri.match(/^data:([^;]+);base64,(.+)$/);
4
+ if (!match) {
5
+ throw new Error("Invalid base64 data URI");
6
+ }
7
+ return {
8
+ mimeType: match[1],
9
+ base64: match[2]
10
+ };
11
+ }
12
+ // src/media/image.browser.ts
13
+ var convertBlobToOffscreenCanvas = async (blob) => {
14
+ const img = await createImageBitmap(blob);
15
+ const ctx = new OffscreenCanvas(img.width, img.height).getContext("2d");
16
+ if (!ctx) {
17
+ throw new Error("Failed to get context.");
18
+ }
19
+ ctx.drawImage(img, 0, 0);
20
+ return ctx.canvas;
21
+ };
22
+ function dataUriToBlob(dataUri) {
23
+ const { mimeType, base64 } = parseDataUri(dataUri);
24
+ const binary = atob(base64);
25
+ const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
26
+ const blob = new Blob([bytes], { type: mimeType });
27
+ return blob;
28
+ }
29
+ async function convertImageDataToUseableForm(imageData, supports) {
30
+ if (imageData === null || imageData === undefined) {
31
+ throw new Error("Image data is null or undefined");
32
+ }
33
+ if (supports.includes("ImageBitmap") && imageData instanceof ImageBitmap) {
34
+ return imageData;
35
+ }
36
+ if (supports.includes("VideoFrame") && imageData instanceof VideoFrame) {
37
+ return imageData;
38
+ }
39
+ if (supports.includes("Blob") && imageData instanceof Blob) {
40
+ return imageData;
41
+ }
42
+ if (supports.includes("ImageBinary") && typeof imageData === "object" && "data" in imageData && "width" in imageData && "height" in imageData && "channels" in imageData) {
43
+ return imageData;
44
+ }
45
+ if (supports.includes("ImageBitmap") && imageData instanceof Blob) {
46
+ return createImageBitmap(imageData);
47
+ }
48
+ if (supports.includes("OffscreenCanvas") && imageData instanceof Blob) {
49
+ return await convertBlobToOffscreenCanvas(imageData);
50
+ }
51
+ if (supports.includes("ImageBitmap") && imageData instanceof OffscreenCanvas) {
52
+ return imageData.transferToImageBitmap();
53
+ }
54
+ if (supports.includes("ImageBitmap") && typeof imageData === "string") {
55
+ return createImageBitmap(dataUriToBlob(imageData));
56
+ }
57
+ if (supports.includes("OffscreenCanvas") && typeof imageData === "string") {
58
+ return convertBlobToOffscreenCanvas(dataUriToBlob(imageData));
59
+ }
60
+ if (supports.includes("Blob") && typeof imageData === "string") {
61
+ return dataUriToBlob(imageData);
62
+ }
63
+ if (supports.includes("DataUri") && typeof imageData === "string" && imageData.startsWith("data:")) {
64
+ return imageData;
65
+ }
66
+ throw new Error(`Unsupported image data type: ${typeof imageData} `);
67
+ }
68
+ export {
69
+ parseDataUri,
70
+ convertImageDataToUseableForm
71
+ };
72
+
73
+ //# debugId=7D52B745FDBDACD364756E2164756E21
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/media/image.ts", "../src/media/image.browser.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport type ImageChannels = 1 | 3 | 4; // grayscale, rgb, rgba\n\nexport type ImageDataSupport =\n | \"Blob\"\n | \"ImageBinary\"\n | \"ImageBitmap\"\n | \"OffscreenCanvas\"\n | \"VideoFrame\"\n | \"RawImage\"\n | \"DataUri\"\n | \"Sharp\";\n\nexport interface ImageBinary {\n data: Uint8ClampedArray;\n width: number;\n height: number;\n channels: ImageChannels;\n rawChannels?: number | undefined;\n}\n\nexport function parseDataUri(dataUri: string): {\n mimeType: string;\n base64: string;\n} {\n const match = dataUri.match(/^data:([^;]+);base64,(.+)$/);\n if (!match) {\n throw new Error(\"Invalid base64 data URI\");\n }\n\n return {\n mimeType: match[1], // e.g. \"image/png\"\n base64: match[2],\n };\n}\n",
6
+ "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ImageBinary, ImageChannels, ImageDataSupport } from \"./image\";\nimport { parseDataUri } from \"./image\";\n\nexport { parseDataUri };\nexport type { ImageBinary, ImageChannels, ImageDataSupport };\n\nconst convertBlobToOffscreenCanvas = async (blob: Blob): Promise<OffscreenCanvas> => {\n const img = await createImageBitmap(blob);\n const ctx = new OffscreenCanvas(img.width, img.height).getContext(\"2d\");\n if (!ctx) {\n throw new Error(\"Failed to get context.\");\n }\n ctx.drawImage(img, 0, 0);\n return ctx.canvas;\n};\n\nfunction dataUriToBlob(dataUri: string): Blob {\n const { mimeType, base64 } = parseDataUri(dataUri);\n\n const binary = atob(base64);\n const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));\n\n const blob = new Blob([bytes], { type: mimeType });\n return blob;\n}\n\nexport async function convertImageDataToUseableForm(\n imageData: unknown,\n supports: ImageDataSupport[]\n): Promise<unknown> {\n if (imageData === null || imageData === undefined) {\n throw new Error(\"Image data is null or undefined\");\n }\n\n // first check if the image data is already in the supported format\n if (supports.includes(\"ImageBitmap\") && imageData instanceof ImageBitmap) {\n return imageData;\n }\n if (supports.includes(\"VideoFrame\") && imageData instanceof VideoFrame) {\n return imageData;\n }\n if (supports.includes(\"Blob\") && imageData instanceof Blob) {\n return imageData;\n }\n if (\n supports.includes(\"ImageBinary\") &&\n typeof imageData === \"object\" &&\n \"data\" in imageData &&\n \"width\" in imageData &&\n \"height\" in imageData &&\n \"channels\" in imageData\n ) {\n return imageData;\n }\n\n // if not, convert it to the first supported format\n if (supports.includes(\"ImageBitmap\") && imageData instanceof Blob) {\n return createImageBitmap(imageData);\n }\n if (supports.includes(\"OffscreenCanvas\") && imageData instanceof Blob) {\n return await convertBlobToOffscreenCanvas(imageData);\n }\n if (supports.includes(\"ImageBitmap\") && imageData instanceof OffscreenCanvas) {\n return imageData.transferToImageBitmap();\n }\n // if not, convert it to the first supported format\n if (supports.includes(\"ImageBitmap\") && typeof imageData === \"string\") {\n return createImageBitmap(dataUriToBlob(imageData));\n }\n if (supports.includes(\"OffscreenCanvas\") && typeof imageData === \"string\") {\n return convertBlobToOffscreenCanvas(dataUriToBlob(imageData));\n }\n if (supports.includes(\"Blob\") && typeof imageData === \"string\") {\n return dataUriToBlob(imageData);\n }\n if (\n supports.includes(\"DataUri\") &&\n typeof imageData === \"string\" &&\n imageData.startsWith(\"data:\")\n ) {\n return imageData;\n }\n throw new Error(`Unsupported image data type: ${typeof imageData} `);\n}\n"
7
+ ],
8
+ "mappings": ";AA0BO,SAAS,YAAY,CAAC,SAG3B;AAAA,EACA,MAAM,QAAQ,QAAQ,MAAM,4BAA4B;AAAA,EACxD,IAAI,CAAC,OAAO;AAAA,IACV,MAAM,IAAI,MAAM,yBAAyB;AAAA,EAC3C;AAAA,EAEA,OAAO;AAAA,IACL,UAAU,MAAM;AAAA,IAChB,QAAQ,MAAM;AAAA,EAChB;AAAA;;AC1BF,IAAM,+BAA+B,OAAO,SAAyC;AAAA,EACnF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B,MAAM;AAAA,IACrE,OAAO,MAAM,6BAA6B,SAAS;AAAA,EACrD;AAAA,EACA,IAAI,SAAS,SAAS,aAAa,KAAK,qBAAqB,iBAAiB;AAAA,IAC5E,OAAO,UAAU,sBAAsB;AAAA,EACzC;AAAA,EAEA,IAAI,SAAS,SAAS,aAAa,KAAK,OAAO,cAAc,UAAU;AAAA,IACrE,OAAO,kBAAkB,cAAc,SAAS,CAAC;AAAA,EACnD;AAAA,EACA,IAAI,SAAS,SAAS,iBAAiB,KAAK,OAAO,cAAc,UAAU;AAAA,IACzE,OAAO,6BAA6B,cAAc,SAAS,CAAC;AAAA,EAC9D;AAAA,EACA,IAAI,SAAS,SAAS,MAAM,KAAK,OAAO,cAAc,UAAU;AAAA,IAC9D,OAAO,cAAc,SAAS;AAAA,EAChC;AAAA,EACA,IACE,SAAS,SAAS,SAAS,KAC3B,OAAO,cAAc,YACrB,UAAU,WAAW,OAAO,GAC5B;AAAA,IACA,OAAO;AAAA,EACT;AAAA,EACA,MAAM,IAAI,MAAM,gCAAgC,OAAO,YAAY;AAAA;",
9
+ "debugId": "7D52B745FDBDACD364756E2164756E21",
10
+ "names": []
11
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export * from "./media/image";
7
+ export * from "./media/image.node";
8
+ //# sourceMappingURL=media-node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media-node.d.ts","sourceRoot":"","sources":["../src/media-node.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,50 @@
1
+ // src/media/image.ts
2
+ function parseDataUri(dataUri) {
3
+ const match = dataUri.match(/^data:([^;]+);base64,(.+)$/);
4
+ if (!match) {
5
+ throw new Error("Invalid base64 data URI");
6
+ }
7
+ return {
8
+ mimeType: match[1],
9
+ base64: match[2]
10
+ };
11
+ }
12
+ // src/media/image.node.ts
13
+ async function dataUriToBlob(string) {
14
+ const { mimeType, base64 } = parseDataUri(string);
15
+ const binary = atob(base64);
16
+ const bytes = new Uint8Array(binary.length);
17
+ for (let i = 0;i < binary.length; i++) {
18
+ bytes[i] = binary.charCodeAt(i);
19
+ }
20
+ return new Blob([bytes], { type: mimeType });
21
+ }
22
+ async function convertImageDataToUseableForm(imageData, supports) {
23
+ if (imageData === null || imageData === undefined) {
24
+ throw new Error("Image data is null or undefined");
25
+ }
26
+ if (supports.includes("Blob") && imageData instanceof Blob) {
27
+ return imageData;
28
+ }
29
+ if (supports.includes("ImageBinary") && typeof imageData === "object" && "data" in imageData && "width" in imageData && "height" in imageData && "channels" in imageData) {
30
+ return {
31
+ data: imageData.data,
32
+ width: imageData.width,
33
+ height: imageData.height,
34
+ channels: imageData.channels
35
+ };
36
+ }
37
+ if (supports.includes("Blob") && typeof imageData === "string") {
38
+ return await dataUriToBlob(imageData);
39
+ }
40
+ if (supports.includes("DataUri") && typeof imageData === "string" && imageData.startsWith("data:")) {
41
+ return imageData;
42
+ }
43
+ throw new Error(`Unsupported image data type: ${typeof imageData}`);
44
+ }
45
+ export {
46
+ parseDataUri,
47
+ convertImageDataToUseableForm
48
+ };
49
+
50
+ //# debugId=75A795737E74157164756E2164756E21
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/media/image.ts", "../src/media/image.node.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport type ImageChannels = 1 | 3 | 4; // grayscale, rgb, rgba\n\nexport type ImageDataSupport =\n | \"Blob\"\n | \"ImageBinary\"\n | \"ImageBitmap\"\n | \"OffscreenCanvas\"\n | \"VideoFrame\"\n | \"RawImage\"\n | \"DataUri\"\n | \"Sharp\";\n\nexport interface ImageBinary {\n data: Uint8ClampedArray;\n width: number;\n height: number;\n channels: ImageChannels;\n rawChannels?: number | undefined;\n}\n\nexport function parseDataUri(dataUri: string): {\n mimeType: string;\n base64: string;\n} {\n const match = dataUri.match(/^data:([^;]+);base64,(.+)$/);\n if (!match) {\n throw new Error(\"Invalid base64 data URI\");\n }\n\n return {\n mimeType: match[1], // e.g. \"image/png\"\n base64: match[2],\n };\n}\n",
6
+ "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ImageBinary, ImageChannels, ImageDataSupport } from \"./image\";\nimport { parseDataUri } from \"./image\";\n\nexport { parseDataUri };\nexport type { ImageBinary, ImageChannels, ImageDataSupport };\n\nasync function dataUriToBlob(string: string): Promise<Blob> {\n const { mimeType, base64 } = parseDataUri(string);\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return new Blob([bytes], { type: mimeType });\n}\n\nexport async function convertImageDataToUseableForm(\n imageData: unknown,\n supports: ImageDataSupport[]\n): Promise<unknown> {\n if (imageData === null || imageData === undefined) {\n throw new Error(\"Image data is null or undefined\");\n }\n\n // first check if the image data is already in the supported format\n if (supports.includes(\"Blob\") && imageData instanceof Blob) {\n return imageData;\n }\n\n if (\n supports.includes(\"ImageBinary\") &&\n typeof imageData === \"object\" &&\n \"data\" in imageData &&\n \"width\" in imageData &&\n \"height\" in imageData &&\n \"channels\" in imageData\n ) {\n return {\n data: imageData.data,\n width: imageData.width,\n height: imageData.height,\n channels: imageData.channels,\n };\n }\n\n // if not, convert it to the first supported format\n if (supports.includes(\"Blob\") && typeof imageData === \"string\") {\n return await dataUriToBlob(imageData);\n }\n\n if (\n supports.includes(\"DataUri\") &&\n typeof imageData === \"string\" &&\n imageData.startsWith(\"data:\")\n ) {\n return imageData;\n }\n\n throw new Error(`Unsupported image data type: ${typeof imageData}`);\n}\n"
7
+ ],
8
+ "mappings": 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