@workglow/util 0.0.52

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 (69) hide show
  1. package/LICENSE +203 -0
  2. package/README.md +318 -0
  3. package/dist/browser.js +1554 -0
  4. package/dist/browser.js.map +27 -0
  5. package/dist/bun.js +1558 -0
  6. package/dist/bun.js.map +27 -0
  7. package/dist/common.d.ts +20 -0
  8. package/dist/common.d.ts.map +1 -0
  9. package/dist/compress/compress.browser.d.ts +8 -0
  10. package/dist/compress/compress.browser.d.ts.map +1 -0
  11. package/dist/compress/compress.node.d.ts +8 -0
  12. package/dist/compress/compress.node.d.ts.map +1 -0
  13. package/dist/crypto/Crypto.browser.d.ts +9 -0
  14. package/dist/crypto/Crypto.browser.d.ts.map +1 -0
  15. package/dist/crypto/Crypto.bun.d.ts +9 -0
  16. package/dist/crypto/Crypto.bun.d.ts.map +1 -0
  17. package/dist/crypto/Crypto.node.d.ts +9 -0
  18. package/dist/crypto/Crypto.node.d.ts.map +1 -0
  19. package/dist/di/Container.d.ts +53 -0
  20. package/dist/di/Container.d.ts.map +1 -0
  21. package/dist/di/ServiceRegistry.d.ts +60 -0
  22. package/dist/di/ServiceRegistry.d.ts.map +1 -0
  23. package/dist/di/index.d.ts +8 -0
  24. package/dist/di/index.d.ts.map +1 -0
  25. package/dist/events/EventEmitter.d.ts +80 -0
  26. package/dist/events/EventEmitter.d.ts.map +1 -0
  27. package/dist/graph/directedAcyclicGraph.d.ts +70 -0
  28. package/dist/graph/directedAcyclicGraph.d.ts.map +1 -0
  29. package/dist/graph/directedGraph.d.ts +90 -0
  30. package/dist/graph/directedGraph.d.ts.map +1 -0
  31. package/dist/graph/errors.d.ts +38 -0
  32. package/dist/graph/errors.d.ts.map +1 -0
  33. package/dist/graph/graph.d.ts +217 -0
  34. package/dist/graph/graph.d.ts.map +1 -0
  35. package/dist/graph/index.d.ts +5 -0
  36. package/dist/graph/index.d.ts.map +1 -0
  37. package/dist/json-schema/DataPortSchema.d.ts +17 -0
  38. package/dist/json-schema/DataPortSchema.d.ts.map +1 -0
  39. package/dist/json-schema/FromSchema.d.ts +96 -0
  40. package/dist/json-schema/FromSchema.d.ts.map +1 -0
  41. package/dist/json-schema/JsonSchema.d.ts +22 -0
  42. package/dist/json-schema/JsonSchema.d.ts.map +1 -0
  43. package/dist/json-schema/SchemaUtils.d.ts +58 -0
  44. package/dist/json-schema/SchemaUtils.d.ts.map +1 -0
  45. package/dist/json-schema/SchemaValidation.d.ts +8 -0
  46. package/dist/json-schema/SchemaValidation.d.ts.map +1 -0
  47. package/dist/node.js +1579 -0
  48. package/dist/node.js.map +27 -0
  49. package/dist/types.d.ts +10 -0
  50. package/dist/types.d.ts.map +1 -0
  51. package/dist/utilities/BaseError.d.ts +14 -0
  52. package/dist/utilities/BaseError.d.ts.map +1 -0
  53. package/dist/utilities/Misc.d.ts +20 -0
  54. package/dist/utilities/Misc.d.ts.map +1 -0
  55. package/dist/utilities/TypeUtilities.d.ts +27 -0
  56. package/dist/utilities/TypeUtilities.d.ts.map +1 -0
  57. package/dist/utilities/objectOfArraysAsArrayOfObjects.d.ts +26 -0
  58. package/dist/utilities/objectOfArraysAsArrayOfObjects.d.ts.map +1 -0
  59. package/dist/worker/Worker.browser.d.ts +7 -0
  60. package/dist/worker/Worker.browser.d.ts.map +1 -0
  61. package/dist/worker/Worker.bun.d.ts +7 -0
  62. package/dist/worker/Worker.bun.d.ts.map +1 -0
  63. package/dist/worker/Worker.node.d.ts +11 -0
  64. package/dist/worker/Worker.node.d.ts.map +1 -0
  65. package/dist/worker/WorkerManager.d.ts +17 -0
  66. package/dist/worker/WorkerManager.d.ts.map +1 -0
  67. package/dist/worker/WorkerServer.d.ts +26 -0
  68. package/dist/worker/WorkerServer.d.ts.map +1 -0
  69. package/package.json +42 -0
@@ -0,0 +1,80 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * A type that represents a listener function for an event.
8
+ * @template Events - A record of event names and their corresponding listener functions
9
+ * @template EventType - The name of the event
10
+ */
11
+ type EventListener<Events, EventType extends keyof Events> = Events[EventType];
12
+ /**
13
+ * A type that represents the parameters of an event.
14
+ * @template Events - A record of event names and their corresponding listener functions
15
+ * @template EventType - The name of the event
16
+ */
17
+ export type EventParameters<Events, EventType extends keyof Events> = {
18
+ [Event in EventType]: EventListener<Events, EventType> extends (...args: infer P) => any ? P : never;
19
+ }[EventType];
20
+ /**
21
+ * A type that represents the return type of the emitted method.
22
+ * @template Events - A record of event names and their corresponding listener functions
23
+ * @template EventType - The name of the event
24
+ */
25
+ export type EmittedReturnType<Events, EventType extends keyof Events> = EventParameters<Events, EventType>;
26
+ /**
27
+ * A class that implements an event emitter pattern.
28
+ * @template EventListenerTypes - A record of event names and their corresponding listener functions
29
+ */
30
+ export declare class EventEmitter<EventListenerTypes extends Record<string, (...args: any) => any>> {
31
+ private listeners;
32
+ /**
33
+ * Remove all listeners for a specific event or all events
34
+ * @param event - Optional event name. If not provided, removes all listeners for all events
35
+ * @returns this, so that calls can be chained
36
+ */
37
+ removeAllListeners<Event extends keyof EventListenerTypes>(event?: Event): this;
38
+ /**
39
+ * Adds a listener function for the event
40
+ * @param event - The event name to listen for
41
+ * @param listener - The listener function to add
42
+ * @returns this, so that calls can be chained
43
+ */
44
+ on<Event extends keyof EventListenerTypes>(event: Event, listener: EventListener<EventListenerTypes, Event>): this;
45
+ /**
46
+ * Removes a listener function for the event
47
+ * @param event - The event name to remove the listener from
48
+ * @param listener - The listener function to remove
49
+ * @returns this, so that calls can be chained
50
+ */
51
+ off<Event extends keyof EventListenerTypes>(event: Event, listener: EventListener<EventListenerTypes, Event>): this;
52
+ /**
53
+ * Adds a listener function for the event that will be called only once
54
+ * @param event - The event name to listen for
55
+ * @param listener - The listener function to add
56
+ * @returns this, so that calls can be chained
57
+ */
58
+ once<Event extends keyof EventListenerTypes>(event: Event, listener: EventListener<EventListenerTypes, Event>): this;
59
+ /**
60
+ * Returns a promise that resolves when the event is emitted
61
+ * @param event - The event name to listen for
62
+ * @returns a promise that resolves to an array of all parameters of the event (empty array for events with no parameters)
63
+ */
64
+ waitOn<Event extends keyof EventListenerTypes>(event: Event): Promise<EmittedReturnType<EventListenerTypes, Event>>;
65
+ /**
66
+ * Emits an event with the specified name and arguments
67
+ * @param event - The event name to emit
68
+ * @param args - Arguments to pass to the event listeners
69
+ */
70
+ emit<Event extends keyof EventListenerTypes>(this: EventEmitter<EventListenerTypes>, event: Event, ...args: EventParameters<EventListenerTypes, Event>): void;
71
+ /**
72
+ * Subscribes to an event and returns a function to unsubscribe
73
+ * @param event - The event name to subscribe to
74
+ * @param listener - The listener function to add
75
+ * @returns a function to unsubscribe from the event
76
+ */
77
+ subscribe<Event extends keyof EventListenerTypes>(event: Event, listener: EventListener<EventListenerTypes, Event>): () => void;
78
+ }
79
+ export {};
80
+ //# sourceMappingURL=EventEmitter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventEmitter.d.ts","sourceRoot":"","sources":["../../src/events/EventEmitter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,KAAK,aAAa,CAAC,MAAM,EAAE,SAAS,SAAS,MAAM,MAAM,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC;AAY/E;;;;GAIG;AACH,MAAM,MAAM,eAAe,CAAC,MAAM,EAAE,SAAS,SAAS,MAAM,MAAM,IAAI;KACnE,KAAK,IAAI,SAAS,GAAG,aAAa,CAAC,MAAM,EAAE,SAAS,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,GAAG,GACpF,CAAC,GACD,KAAK;CACV,CAAC,SAAS,CAAC,CAAC;AAEb;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,CAAC,MAAM,EAAE,SAAS,SAAS,MAAM,MAAM,IAAI,eAAe,CACrF,MAAM,EACN,SAAS,CACV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Id"}
@@ -0,0 +1,70 @@
1
+ import { DirectedGraph } from "./directedGraph";
2
+ /**
3
+ * # DirectedAcyclicGraph
4
+ *
5
+ * A DirectedAcyclicGraph is builds on a [[`DirectedGraph`]] but enforces acyclicality. You cannot add an edge to a DirectedAcyclicGraph that would create a cycle.
6
+ *
7
+ * @typeParam Node `Node` is the node type of the graph. Nodes can be anything in all the included examples they are simple objects.
8
+ * @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.
9
+ * @typeParam NodeId `NodeId` is the identity type of the node, by default it is a `unknown`, though most will use `string` or `number`.
10
+ * @typeParam EdgeId `EdgeId` is the identity type of the edge, by default it is a `unknown`, though most will use `string` or `number`.
11
+ */
12
+ export declare class DirectedAcyclicGraph<Node, Edge = true, NodeId = unknown, EdgeId = unknown> extends DirectedGraph<Node, Edge, NodeId, EdgeId> {
13
+ private _topologicallySortedNodes?;
14
+ /**
15
+ * Converts an existing directed graph into a directed acyclic graph.
16
+ * Throws a {@linkcode CycleError} if the graph attempting to be converted contains a cycle.
17
+ * @param graph The source directed graph to convert into a DAG
18
+ */
19
+ static fromDirectedGraph<Node, Edge, NodeId, EdgeId>(graph: DirectedGraph<Node, Edge, NodeId, EdgeId>): DirectedAcyclicGraph<Node, Edge, NodeId, EdgeId>;
20
+ /**
21
+ * Adds an edge to the graph similarly to [[`DirectedGraph.addEdge`]] but maintains correctness of the acyclic graph.
22
+ * Thows a [[`CycleError`]] if adding the requested edge would create a cycle.
23
+ * Adding an edge invalidates the cache of topologically sorted nodes, rather than updating it.
24
+ *
25
+ * @param sourceNodeIdentity The identity string of the node the edge should run from.
26
+ * @param targetNodeIdentity The identity string of the node the edge should run to.
27
+ * @param edge The edge to add to the graph. If not provided it defaults to `true`.
28
+ */
29
+ addEdge(sourceNodeIdentity: NodeId, targetNodeIdentity: NodeId, edge?: Edge): EdgeId;
30
+ /**
31
+ * Inserts a node into the graph and maintains topologic sort cache by prepending the node
32
+ * (since all newly created nodes have an [[ indegreeOfNode | indegree ]] of zero.)
33
+ *
34
+ * @param node The node to insert
35
+ */
36
+ insert(node: Node): NodeId;
37
+ /**
38
+ * Topologically sort the nodes using Kahn's algorithm. Uses a cache which means that repeated calls should be O(1) after the first call.
39
+ * Non-cached calls are potentially expensive, Kahn's algorithim is O(|EdgeCount| + |NodeCount|).
40
+ * There may be more than one valid topological sort order for a single graph,
41
+ * so just because two graphs are the same does not mean that order of the resultant arrays will be.
42
+ *
43
+ * @returns An array of nodes sorted by the topological order.
44
+ */
45
+ topologicallySortedNodes(): Node[];
46
+ /**
47
+ * Given a starting node this returns a new [[`DirectedA`]] containing all the nodes that can be reached.
48
+ * Throws a [[`NodeDoesntExistError`]] if the start node does not exist.
49
+ *
50
+ * @param startNodeIdentity The string identity of the node from which the subgraph search should start.
51
+ */
52
+ getSubGraphStartingFrom(startNodeIdentity: NodeId): DirectedAcyclicGraph<Node, Edge, NodeId, EdgeId>;
53
+ /**
54
+ * Deletes an edge between two nodes in the graph.
55
+ * Throws a [[`NodeDoesNotExistsError`]] if either of the nodes do not exist.
56
+ *
57
+ * @param sourceNodeIdentity The identity of the source node
58
+ * @param targetNodeIdentity The identity of the target node
59
+ * @param edgeIdentity The identity of the edge to be deleted. If not provided, all edges between the two nodes will be deleted.
60
+ */
61
+ removeEdge(sourceNodeIdentity: NodeId, targetNodeIdentity: NodeId, edgeIdentity?: EdgeId): void;
62
+ /**
63
+ * Deletes a node from the graph, along with any edges associated with it.
64
+ * Throws a [[`NodeDoesNotExistsError`]] if the node does not exist.
65
+ *
66
+ * @param nodeIdentity The identity of the node to be deleted.
67
+ */
68
+ remove(nodeIdentity: NodeId): void;
69
+ }
70
+ //# sourceMappingURL=directedAcyclicGraph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directedAcyclicGraph.d.ts","sourceRoot":"","sources":["../../src/graph/directedAcyclicGraph.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD;;;;;;;;;GASG;AACH,qBAAa,oBAAoB,CAC/B,IAAI,EACJ,IAAI,GAAG,IAAI,EACX,MAAM,GAAG,OAAO,EAChB,MAAM,GAAG,OAAO,CAChB,SAAQ,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC;IACjD,OAAO,CAAC,yBAAyB,CAAC,CAAS;IAE3C;;;;OAIG;IACH,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EACjD,KAAK,EAAE,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,GAC/C,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC;IAiBnD;;;;;;;;OAQG;IACH,OAAO,CAAC,kBAAkB,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM;IAiBpF;;;;;OAKG;IACH,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM;IAQ1B;;;;;;;OAOG;IACH,wBAAwB,IAAI,IAAI,EAAE;IA0DlC;;;;;OAKG;IACH,uBAAuB,CACrB,iBAAiB,EAAE,MAAM,GACxB,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC;IAInD;;;;;;;OAOG;IACH,UAAU,CAAC,kBAAkB,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI;IAO/F;;;;;OAKG;IACH,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;CAMnC"}
@@ -0,0 +1,90 @@
1
+ import { Graph } from "./graph";
2
+ /**
3
+ * # DirectedGraph
4
+ *
5
+ * A DirectedGraph is similar a [[`Graph`]] but with additional functionality.
6
+ *
7
+ * @typeParam Node `Node` is the node type of the graph. Nodes can be anything in all the included examples they are simple objects.
8
+ * @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.
9
+ * @typeParam NodeId `NodeId` is the identity type of the node, by default it is a `unknown`, though most will use `string` or `number`.
10
+ * @typeParam EdgeId `EdgeId` is the identity type of the edge, by default it is a `unknown`, though most will use `string` or `number`.
11
+ */
12
+ export declare class DirectedGraph<Node, Edge = true, NodeId = unknown, EdgeId = unknown> extends Graph<Node, Edge, NodeId, EdgeId> {
13
+ /** Caches if the graph contains a cycle. If `undefined` then it is unknown. */
14
+ protected hasCycle: boolean | undefined;
15
+ /**
16
+ * Returns `true` if there are no cycles in the graph.
17
+ * 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.
18
+ * Non-cached calls are potentially expensive, the implementation is based on Kahn's algorithim which is O(|EdgeCount| + |NodeCount|).
19
+ */
20
+ isAcyclic(): boolean;
21
+ /**
22
+ * The indegree of a node is the number of edges that point to it. This will always be an integer.
23
+ *
24
+ * Throws a [[`NodeDoesntExistError`]] the node does not exist.
25
+ *
26
+ * @param nodeID The string of the node identity of the node to calculate indegree for.
27
+ */
28
+ indegreeOfNode(nodeID: NodeId): number;
29
+ /**
30
+ * Add a directed edge to the graph.
31
+ *
32
+ * @param sourceNodeIdentity The identity string of the node the edge should run from.
33
+ * @param targetNodeIdentity The identity string of the node the edge should run to.
34
+ * @param edge The edge to add to the graph. If not provided it defaults to `true`.
35
+ * @param skipUpdatingCyclicality This boolean indicates if the cache of the cyclicality of the graph should be updated.
36
+ * If `false` is passed the cycle cache will be invalidated because we can not assure that a cycle has not been created.
37
+ */
38
+ addEdge(sourceNodeIdentity: NodeId, targetNodeIdentity: NodeId, edge?: Edge, skipUpdatingCyclicality?: boolean): EdgeId;
39
+ /**
40
+ * Depth first search to see if one node is reachable from another following the directed edges.
41
+ *
42
+ * __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.
43
+ *
44
+ * @param startNode The string identity of the node to start at.
45
+ * @param endNode The string identity of the node we are attempting to reach.
46
+ */
47
+ canReachFrom(startNode: NodeId, endNode: NodeId): boolean;
48
+ /**
49
+ * Checks if adding the specified edge would create a cycle.
50
+ * Returns true in O(1) if the graph already contains a known cycle, or if `sourceNodeIdentity` and `targetNodeIdentity` are the same.
51
+ *
52
+ * @param sourceNodeIdentity The string identity of the node the edge is from.
53
+ * @param targetNodeIdentity The string identity of the node the edge is to.
54
+ */
55
+ wouldAddingEdgeCreateCycle(sourceNodeIdentity: NodeId, targetNodeIdentity: NodeId): boolean;
56
+ /**
57
+ * Given a starting node this returns a new [[`DirectedGraph`]] containing all the nodes that can be reached.
58
+ * Throws a [[`NodeDoesntExistError`]] if the start node does not exist.
59
+ *
60
+ * @param startNodeIdentity The string identity of the node from which the subgraph search should start.
61
+ */
62
+ getSubGraphStartingFrom(startNodeIdentity: NodeId): DirectedGraph<Node, Edge, NodeId, EdgeId>;
63
+ private subAdj;
64
+ /**
65
+ * Returns all edges in the graph as an array of tuples.
66
+ */
67
+ getEdges(): Array<[sourceNodeIdentity: NodeId, targetNodeIdentity: NodeId, edge: Edge]>;
68
+ /**
69
+ * Deletes an edge between two nodes in the graph.
70
+ * Throws a [[`NodeDoesNotExistsError`]] if either of the nodes do not exist.
71
+ *
72
+ * @param sourceNodeIdentity The identity of the source node
73
+ * @param targetNodeIdentity The identity of the target node
74
+ * @param edgeIdentity The identity of the edge to be deleted. If not provided, all edges between the two nodes will be deleted.
75
+ */
76
+ removeEdge(sourceNodeIdentity: NodeId, targetNodeIdentity: NodeId, edgeIdentity?: EdgeId): void;
77
+ /**
78
+ * Deletes a node from the graph, along with any edges associated with it.
79
+ * Throws a [[`NodeDoesNotExistsError`]] if the node does not exist.
80
+ *
81
+ * @param nodeIdentity The identity of the node to be deleted.
82
+ */
83
+ remove(nodeIdentity: NodeId): void;
84
+ /**
85
+ * Add edges
86
+ * @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.
87
+ */
88
+ addEdges(edges: Array<[sourceNodeIdentity: NodeId, targetNodeIdentity: NodeId, edge?: Edge | undefined]>): EdgeId[];
89
+ }
90
+ //# sourceMappingURL=directedGraph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directedGraph.d.ts","sourceRoot":"","sources":["../../src/graph/directedGraph.ts"],"names":[],"mappings":"AAKA,OAAO,EAAwB,KAAK,EAAE,MAAM,SAAS,CAAC;AAEtD;;;;;;;;;GASG;AACH,qBAAa,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,MAAM,GAAG,OAAO,EAAE,MAAM,GAAG,OAAO,CAAE,SAAQ,KAAK,CAC7F,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,MAAM,CACP;IACC,+EAA+E;IAC/E,SAAS,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAS;IAEhD;;;;OAIG;IACH,SAAS,IAAI,OAAO;IAyCpB;;;;;;OAMG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAatC;;;;;;;;OAQG;IACH,OAAO,CACL,kBAAkB,EAAE,MAAM,EAC1B,kBAAkB,EAAE,MAAM,EAC1B,IAAI,CAAC,EAAE,IAAI,EACX,uBAAuB,GAAE,OAAe,GACvC,MAAM;IAaT;;;;;;;OAOG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO;IAkBzD;;;;;;OAMG;IACH,0BAA0B,CAAC,kBAAkB,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAG,OAAO;IAQ3F;;;;;OAKG;IACH,uBAAuB,CAAC,iBAAiB,EAAE,MAAM,GAAG,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC;IA0C7F,OAAO,CAAC,MAAM;IAad;;OAEG;IACH,QAAQ,IAAI,KAAK,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAIvF;;;;;;;OAOG;IACH,UAAU,CAAC,kBAAkB,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI;IAO/F;;;;;OAKG;IACH,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;IAOlC;;;OAGG;IACH,QAAQ,CACN,KAAK,EAAE,KAAK,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC,CAAC,GAC9F,MAAM,EAAE;CAGZ"}
@@ -0,0 +1,38 @@
1
+ import { BaseError } from "../utilities/BaseError";
2
+ /**
3
+ * # NodeAlreadyExistsError
4
+ *
5
+ * This error is thrown when trying to create a node with the same identity as an existing node.
6
+ *
7
+ * @category Errors
8
+ */
9
+ export declare class NodeAlreadyExistsError<T> extends BaseError {
10
+ static type: string;
11
+ newNode: T;
12
+ oldNode: T;
13
+ identity: unknown;
14
+ constructor(newNode: T, oldNode: T, identity: unknown);
15
+ }
16
+ /**
17
+ * # NodeDoesntExistError
18
+ * This error is thrown when trying to access a node in a graph by it's identity when that node doesn't exist
19
+ *
20
+ * @category Errors
21
+ */
22
+ export declare class NodeDoesntExistError extends BaseError {
23
+ static type: string;
24
+ identity: unknown;
25
+ constructor(identity: unknown);
26
+ }
27
+ /**
28
+ * # CycleError
29
+ *
30
+ * This error is thrown when attempting to create or update a Directed Acyclic Graph that contains a cycle.
31
+ *
32
+ * @category Errors
33
+ */
34
+ export declare class CycleError extends BaseError {
35
+ static type: string;
36
+ constructor(message: string);
37
+ }
38
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/graph/errors.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD;;;;;;GAMG;AACH,qBAAa,sBAAsB,CAAC,CAAC,CAAE,SAAQ,SAAS;IACtD,OAAc,IAAI,EAAE,MAAM,CAA4B;IAC/C,OAAO,EAAE,CAAC,CAAC;IACX,OAAO,EAAE,CAAC,CAAC;IACX,QAAQ,EAAE,OAAO,CAAC;gBAEb,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,OAAO;CActD;AAED;;;;;GAKG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;IACjD,OAAc,IAAI,EAAE,MAAM,CAA0B;IAC7C,QAAQ,EAAE,OAAO,CAAC;gBAEb,QAAQ,EAAE,OAAO;CAQ9B;AAED;;;;;;GAMG;AACH,qBAAa,UAAW,SAAQ,SAAS;IACvC,OAAc,IAAI,EAAE,MAAM,CAAgB;gBAC9B,OAAO,EAAE,MAAM;CAO5B"}
@@ -0,0 +1,217 @@
1
+ import { EventEmitter } from "../events/EventEmitter";
2
+ /**
3
+ * This is the default [[Graph.constructor | `nodeIdentity`]] function it is simply imported from [object-hash](https://www.npmjs.com/package/object-hash)
4
+ */
5
+ /**
6
+ * # Graph
7
+ *
8
+ * 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`]].
9
+ *
10
+ * ## Creating a Graph
11
+ *
12
+ * You can create a graph to contain any type of node, for example:
13
+ *
14
+ * ```typescript
15
+ * type NodeType = { a: Number, b: string }
16
+ * const graph = new Graph<NodeType>()
17
+ *
18
+ * // Add a node of the defined type
19
+ * const node: string = graph.insert({ a: 10, b: 'string' })
20
+ *
21
+ * // Get the node back
22
+ * const nodeValue: NodeType | undefined = graph.getNode(node);
23
+ * ```
24
+ *
25
+ * ### Defining a custom node identity
26
+ *
27
+ * When you create a graph you likely want to create include a custom `nodeIdentity` function.
28
+ * This function tells the graph how to uniquely identify nodes in a graph,
29
+ * default is to simply use an [[hash]] which means that functionality like [[`replace`]] will not work.
30
+ *
31
+ * ```typescript
32
+ * type NodeType = { count: number, name: string }
33
+ * const graph = new Graph<NodeType>((n) => n.name)
34
+ *
35
+ * // Add a node
36
+ * graph.insert({ count: 5, name: 'node1' })
37
+ * // This will throw an error even though `count` is different because they share a name.
38
+ * graph.insert({ count: 20, name: 'node1' })
39
+ * ```
40
+ *
41
+ * ### Adding an edge
42
+ *
43
+ * Graphs without edges aren't very useful. Inserting edges is done using the node identity string returned by the node identity function.
44
+ *
45
+ * ```typescript
46
+ * const node1: string = graph.insert({ count: 5, name: 'node1' })
47
+ * const node2: string = graph.insert({ count: 20, name: 'node2' })
48
+ *
49
+ * graph.addEdge(node1, node2)
50
+ *
51
+ * // This will throw an error since there is no node with the later name.
52
+ * graph.addEdge(node1, 'not a real node')
53
+ * ```
54
+ *
55
+ * In an undirected graph the order in which you input the node names doesn't matter,
56
+ * but in directed graphs the "from node" comes first and the "to node" will come second.
57
+ *
58
+ * ### Replacing a node
59
+ *
60
+ * If a node already exists you can update it using [[`replace`]]. `nodeIdentity(newNode)` must be equal to `nodeIdentity(oldNode)`.
61
+ *
62
+ * ```typescript
63
+ * const node1: string = graph.insert({ count: 5, name: 'node1' })
64
+ * const node2: string = graph.insert({ count: 20, name: 'node2' })
65
+ *
66
+ * // This will work because the name has not changed.
67
+ * graph.replace({ count: 15, name: 'node1' })
68
+ *
69
+ * // This will not work because the name has changed.
70
+ * graph.replace({ count: 20, name: 'node3' })
71
+ * ```
72
+ *
73
+ * [[`replace`]] will throw a [[`NodeDoesntExistError`]] exception if you are trying to replace a node that is missing from the graph.
74
+ *
75
+ * ### Upsert
76
+ *
77
+ * Often you will want to create a node node if it doesn't exist and update it does. This can be achieved using [[`upsert`]].
78
+ *
79
+ * ```typescript
80
+ * const node1: string = graph.insert({ count: 5, name: 'node1' })
81
+ *
82
+ * // Both of these will work, the first updating node1 and the second creating a node.
83
+ * const node2: string = graph.upsert({ count: 15, name: 'node1' })
84
+ * const node3: string = graph.upsert({ count: 25, name: 'node3' })
85
+ * ```
86
+ *
87
+ * [[`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.
88
+ *
89
+ * @typeParam Node `Node` is the node type of the graph. Nodes can be anything in all the included examples they are simple objects.
90
+ * @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.
91
+ * @typeParam NodeId `NodeId` is the identity type of the node, by default it is a `unknown`, though most will use `string` or `number`.
92
+ * @typeParam EdgeId `EdgeId` is the identity type of the edge, by default it is a `unknown`, though most will use `string` or `number`.
93
+ */
94
+ export type AdjacencyValue<Edge> = null | Array<Edge>;
95
+ export type AdjacencyMatrix<Edge> = Array<Array<AdjacencyValue<Edge>>>;
96
+ /**
97
+ * Events that can be emitted by the TaskGraph
98
+ */
99
+ export type GraphEvents<Node, Edge> = keyof GraphEventListeners<Node, Edge>;
100
+ export type GraphEventListeners<Node, Edge> = {
101
+ "node-added": (node: Node) => void;
102
+ "node-removed": (node: Node) => void;
103
+ "node-replaced": (node: Node) => void;
104
+ "edge-added": (edge: Edge) => void;
105
+ "edge-removed": (edge: Edge) => void;
106
+ "edge-replaced": (edge: Edge) => void;
107
+ };
108
+ export type GraphEventListener<Node, Edge, Event extends GraphEvents<Node, Edge>> = GraphEventListeners<Node, Edge>[Event];
109
+ export type GraphEventParameters<Node, Edge, Event extends GraphEvents<Node, Edge>> = Parameters<GraphEventListeners<Node, Edge>[Event]>;
110
+ export declare class Graph<Node, Edge = true, NodeId = unknown, EdgeId = unknown> {
111
+ protected nodes: Map<NodeId, Node>;
112
+ protected adjacency: AdjacencyMatrix<Edge>;
113
+ protected nodeIdentity: (t: Node) => NodeId;
114
+ protected edgeIdentity: (t: Edge, n1: NodeId, n2: NodeId) => EdgeId;
115
+ constructor(nodeIdentity: (node: Node) => NodeId, edgeIdentity: (edge: Edge, node1Identity: NodeId, node2Identit: NodeId) => EdgeId);
116
+ events: EventEmitter<GraphEventListeners<Node, Edge>>;
117
+ on(name: GraphEvents<Node, Edge>, fn: (...args: any[]) => void): void;
118
+ off(name: GraphEvents<Node, Edge>, fn: (...args: any[]) => void): void;
119
+ emit(name: GraphEvents<Node, Edge>, ...args: any[]): void;
120
+ /**
121
+ * Add a node to the graph if it doesn't already exist. If it does, throw a [[`NodeAlreadyExistsError`]].
122
+ *
123
+ * @param node The node to be added
124
+ * @returns A `string` that is the identity of the newly inserted node. This is created by applying the [[constructor | `nodeIdentity`]].
125
+ */
126
+ insert(node: Node): NodeId;
127
+ /**
128
+ * This replaces an existing node in the graph with an updated version.
129
+ * Throws a [[`NodeDoesNotExistsError`]] if no node with the same identity already exists.
130
+ *
131
+ * __Caveat_:_ The default identity function means that this will never work since if the node changes it will have a different [[`hash`]].
132
+ *
133
+ * @param node The new node that is replacing the old one.
134
+ */
135
+ replace(node: Node): void;
136
+ /**
137
+ * This essentially combines the behavior of [[`insert`]] and [[`replace`]].
138
+ * If the node doesn't exist, create it. If the node already exists, replace it with the updated version.
139
+ *
140
+ * @param node The node to insert or update
141
+ * @returns The identity string of the node inserted or updated.
142
+ */
143
+ upsert(node: Node): NodeId;
144
+ /**
145
+ * Create an edge between two nodes in the graph.
146
+ * Throws a [[`NodeDoesNotExistsError`]] if no either of the nodes you are attempting to connect do not exist.
147
+ *
148
+ * @param node1Identity The first node to connect (in [[`DirectedGraph`]]s and [[`DirectedAcyclicGraph`]]s this is the `source` node.)
149
+ * @param node2Identity The second node to connect (in [[`DirectedGraph`]]s and [[`DirectedAcyclicGraph`]]s this is the `target` node)
150
+ * @param edge The edge to be added. By default this is `true` but it can be any type.
151
+ */
152
+ addEdge(node1Identity: NodeId, node2Identity: NodeId, edge?: Edge): EdgeId;
153
+ /**
154
+ * This simply returns all the nodes stored in the graph
155
+ *
156
+ * @param compareFunc An optional function that indicates the sort order of the returned array
157
+ */
158
+ getNodes(compareFunc?: (a: Node, b: Node) => number): Node[];
159
+ /**
160
+ * Returns a specific node given the node identity returned from the [[`insert`]] function
161
+ */
162
+ getNode(nodeIdentity: NodeId): Node | undefined;
163
+ /**
164
+ * Returns true if the node exists in the graph.
165
+ */
166
+ hasNode(nodeIdentity: NodeId): boolean;
167
+ /**
168
+ * Returns all edges in the graph as an array of tuples.
169
+ */
170
+ getEdges(): Array<[node1Identity: NodeId, node2Identity: NodeId, edge: Edge]>;
171
+ /**
172
+ * Returns the out edges for a specific node.
173
+ */
174
+ outEdges(node1Identity: NodeId): Array<[node1Identity: NodeId, node2Identity: NodeId, edge: Edge]>;
175
+ /**
176
+ * Returns the in edges for a specific node.
177
+ */
178
+ inEdges(node2Identity: NodeId): Array<[node1Identity: NodeId, node2Identity: NodeId, edge: Edge]>;
179
+ /**
180
+ * Returns the edges for a specific node.
181
+ */
182
+ nodeEdges(nodeIdentity: NodeId): Array<[node1Identity: NodeId, node2Identity: NodeId, edge: Edge]>;
183
+ /**
184
+ * Deletes an edge between two nodes in the graph.
185
+ * Throws a [[`NodeDoesNotExistsError`]] if either of the nodes do not exist.
186
+ *
187
+ * @param node1Identity The identity of the first node (in [[`DirectedGraph`]]s and [[`DirectedAcyclicGraph`]]s this is the `from` node.)
188
+ * @param node2Identity The identity of the second node (in [[`DirectedGraph`]]s and [[`DirectedAcyclicGraph`]]s this is the `to` node)
189
+ * @param edgeIdentity The identity of the edge to be deleted. If not provided, all edges between the two nodes will be deleted.
190
+ */
191
+ removeEdge(node1Identity: NodeId, node2Identity: NodeId, edgeIdentity?: EdgeId): void;
192
+ /**
193
+ * Deletes a node from the graph, along with any edges associated with it.
194
+ * Throws a [[`NodeDoesNotExistsError`]] if the node does not exist.
195
+ *
196
+ * @param nodeIdentity The identity of the node to be deleted.
197
+ */
198
+ remove(nodeIdentity: NodeId): void;
199
+ /**
200
+ * @alias remove
201
+ */
202
+ removeNode(nodeIdentity: NodeId): void;
203
+ /**
204
+ * @alias insert
205
+ */
206
+ addNode(node: Node): NodeId;
207
+ /**
208
+ * Add nodes in bulk
209
+ */
210
+ addNodes(nodes: Node[]): NodeId[];
211
+ /**
212
+ * Add edges
213
+ * @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.
214
+ */
215
+ addEdges(edges: Array<[node1Identity: NodeId, node2Identity: NodeId, edge?: Edge | undefined]>): EdgeId[];
216
+ }
217
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/graph/graph.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAmB,MAAM,wBAAwB,CAAC;AAGvE;;GAEG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwFG;AAEH,MAAM,MAAM,cAAc,CAAC,IAAI,IAAI,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;AACtD,MAAM,MAAM,eAAe,CAAC,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAEvE;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,IAAI,EAAE,IAAI,IAAI,MAAM,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAE5E,MAAM,MAAM,mBAAmB,CAAC,IAAI,EAAE,IAAI,IAAI;IAC5C,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACnC,cAAc,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACrC,eAAe,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACtC,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACnC,cAAc,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACrC,eAAe,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,kBAAkB,CAC5B,IAAI,EACJ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I,CAAC,CAAC;IAIpE;;;;;;;OAOG;IACH,UAAU,CAAC,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI;IAsCrF;;;;;OAKG;IACH,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;IAoBlC;;OAEG;IACH,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;IAItC;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM;IAI3B;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,EAAE;IAIjC;;;OAGG;IACH,QAAQ,CACN,KAAK,EAAE,KAAK,CAAC,CAAC,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC,CAAC,GACpF,MAAM,EAAE;CAKZ"}
@@ -0,0 +1,5 @@
1
+ export * from "./directedAcyclicGraph";
2
+ export * from "./directedGraph";
3
+ export * from "./graph";
4
+ export * from "./errors";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/graph/index.ts"],"names":[],"mappings":"AAIA,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { JSONSchemaExtension } from "json-schema-to-ts";
7
+ import { JsonSchema, JsonSchemaCustomProps } from "./JsonSchema";
8
+ export type DataPortSchemaNonBoolean<EXTENSION extends JSONSchemaExtension = JsonSchemaCustomProps> = Exclude<JsonSchema<EXTENSION>, Boolean>;
9
+ /**
10
+ * Narrows to object schemas while preserving all schema properties.
11
+ */
12
+ export type DataPortSchemaObject<EXTENSION extends JSONSchemaExtension = JsonSchemaCustomProps> = DataPortSchemaNonBoolean<EXTENSION> & {
13
+ readonly type: "object";
14
+ readonly properties: Record<string, DataPortSchemaNonBoolean<EXTENSION>>;
15
+ };
16
+ export type DataPortSchema<EXTENSION extends JSONSchemaExtension = JsonSchemaCustomProps> = boolean | DataPortSchemaObject<EXTENSION>;
17
+ //# sourceMappingURL=DataPortSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DataPortSchema.d.ts","sourceRoot":"","sources":["../../src/json-schema/DataPortSchema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAEjE,MAAM,MAAM,wBAAwB,CAClC,SAAS,SAAS,mBAAmB,GAAG,qBAAqB,IAC3D,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,oBAAoB,CAAC,SAAS,SAAS,mBAAmB,GAAG,qBAAqB,IAC5F,wBAAwB,CAAC,SAAS,CAAC,GAAG;IACpC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,SAAS,CAAC,CAAC,CAAC;CAC1E,CAAC;AAEJ,MAAM,MAAM,cAAc,CAAC,SAAS,SAAS,mBAAmB,GAAG,qBAAqB,IACpF,OAAO,GACP,oBAAoB,CAAC,SAAS,CAAC,CAAC"}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { FromExtendedSchema, FromExtendedSchemaOptions, FromSchemaOptions } from "json-schema-to-ts";
7
+ import type { JsonSchema, JsonSchemaCustomProps } from "./JsonSchema";
8
+ export { FromSchemaOptions };
9
+ /**
10
+ * Removes the [$JSONSchema] symbol property from a type
11
+ * This is needed because json-schema-to-ts adds this property which cannot be serialized
12
+ */
13
+ export type StripJSONSchema<T> = T extends object ? {
14
+ [K in keyof T as K extends symbol ? never : K]: T[K];
15
+ } : T;
16
+ export declare const FromSchemaDefaultOptions: {
17
+ readonly parseNotKeyword: true;
18
+ readonly parseIfThenElseKeywords: false;
19
+ readonly keepDefaultedPropertiesOptional: true;
20
+ readonly references: false;
21
+ readonly deserialize: false;
22
+ };
23
+ export type FromSchema<SCHEMA extends JsonSchema<EXTENSION>, OPTIONS extends FromExtendedSchemaOptions<EXTENSION> = typeof FromSchemaDefaultOptions, EXTENSION extends JsonSchemaCustomProps = JsonSchemaCustomProps> = StripJSONSchema<FromExtendedSchema<EXTENSION, SCHEMA, OPTIONS>>;
24
+ /**
25
+ * IncludeProps - Returns a new schema with only the specified properties
26
+ *
27
+ * This is a schema transformer that returns a new schema object.
28
+ * Use with FromSchema like: FromSchema<IncludeProps<typeof schema, typeof ["prop1", "prop2"]>>
29
+ *
30
+ * @template Schema - The JSON schema object (with 'as const')
31
+ * @template Keys - Readonly array type of property keys to include (use typeof ["key1", "key2"] as const)
32
+ *
33
+ * @example
34
+ * const schema = {
35
+ * type: "object",
36
+ * properties: {
37
+ * name: { type: "string" },
38
+ * age: { type: "number" },
39
+ * email: { type: "string" }
40
+ * },
41
+ * required: ["name"],
42
+ * additionalProperties: false
43
+ * } as const;
44
+ *
45
+ * type Filtered = FromSchema<IncludeProps<typeof schema, typeof ["name", "age"]>>;
46
+ * // => { name: string, age?: number }
47
+ */
48
+ export type IncludeProps<Schema extends {
49
+ readonly type: "object";
50
+ readonly properties: Record<string, unknown>;
51
+ }, Keys extends readonly (keyof Schema["properties"])[]> = Omit<Schema, "properties" | "required"> & {
52
+ readonly properties: {
53
+ readonly [K in Extract<keyof Schema["properties"], Keys[number]>]: Schema["properties"][K];
54
+ };
55
+ } & (Schema extends {
56
+ readonly required: readonly (infer R extends string)[];
57
+ } ? {
58
+ readonly required: readonly Extract<R, Keys[number]>[];
59
+ } : {});
60
+ /**
61
+ * ExcludeProps - Returns a new schema without the specified properties
62
+ *
63
+ * This is a schema transformer that returns a new schema object.
64
+ * Use with FromSchema like: FromSchema<ExcludeProps<typeof schema, typeof ["prop1", "prop2"]>>
65
+ *
66
+ * @template Schema - The JSON schema object (with 'as const')
67
+ * @template Keys - Readonly array type of property keys to exclude (use typeof ["key1", "key2"] as const)
68
+ *
69
+ * @example
70
+ * const schema = {
71
+ * type: "object",
72
+ * properties: {
73
+ * name: { type: "string" },
74
+ * age: { type: "number" },
75
+ * email: { type: "string" }
76
+ * },
77
+ * required: ["name"],
78
+ * additionalProperties: false
79
+ * } as const;
80
+ *
81
+ * type Filtered = FromSchema<ExcludeProps<typeof schema, typeof ["email"]>>;
82
+ * // => { name: string, age?: number }
83
+ */
84
+ export type ExcludeProps<Schema extends {
85
+ readonly type: "object";
86
+ readonly properties: Record<string, unknown>;
87
+ }, Keys extends readonly (keyof Schema["properties"])[]> = Omit<Schema, "properties" | "required"> & {
88
+ readonly properties: {
89
+ readonly [K in Exclude<keyof Schema["properties"], Keys[number]>]: Schema["properties"][K];
90
+ };
91
+ } & (Schema extends {
92
+ readonly required: readonly (infer R extends string)[];
93
+ } ? {
94
+ readonly required: readonly Exclude<R, Keys[number]>[];
95
+ } : {});
96
+ //# sourceMappingURL=FromSchema.d.ts.map