@workglow/task-graph 0.0.125 → 0.1.0

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 (57) hide show
  1. package/README.md +104 -36
  2. package/dist/browser.js +888 -1031
  3. package/dist/browser.js.map +26 -28
  4. package/dist/bun.js +888 -1027
  5. package/dist/bun.js.map +25 -27
  6. package/dist/debug/console/ConsoleFormatters.d.ts.map +1 -1
  7. package/dist/node.js +888 -1027
  8. package/dist/node.js.map +25 -27
  9. package/dist/task/ConditionalTask.d.ts +1 -0
  10. package/dist/task/ConditionalTask.d.ts.map +1 -1
  11. package/dist/task/FallbackTask.d.ts +0 -1
  12. package/dist/task/FallbackTask.d.ts.map +1 -1
  13. package/dist/task/GraphAsTask.d.ts.map +1 -1
  14. package/dist/task/ITask.d.ts +6 -0
  15. package/dist/task/ITask.d.ts.map +1 -1
  16. package/dist/task/InputResolver.d.ts +6 -0
  17. package/dist/task/InputResolver.d.ts.map +1 -1
  18. package/dist/task/IteratorTask.d.ts +11 -0
  19. package/dist/task/IteratorTask.d.ts.map +1 -1
  20. package/dist/task/IteratorTaskRunner.d.ts.map +1 -1
  21. package/dist/task/JobQueueFactory.d.ts +3 -4
  22. package/dist/task/JobQueueFactory.d.ts.map +1 -1
  23. package/dist/task/MapTask.d.ts +4 -0
  24. package/dist/task/MapTask.d.ts.map +1 -1
  25. package/dist/task/ReduceTask.d.ts +4 -0
  26. package/dist/task/ReduceTask.d.ts.map +1 -1
  27. package/dist/task/Task.d.ts +13 -1
  28. package/dist/task/Task.d.ts.map +1 -1
  29. package/dist/task/TaskError.d.ts +23 -0
  30. package/dist/task/TaskError.d.ts.map +1 -1
  31. package/dist/task/TaskEvents.d.ts +1 -1
  32. package/dist/task/TaskEvents.d.ts.map +1 -1
  33. package/dist/task/TaskJSON.d.ts +17 -7
  34. package/dist/task/TaskJSON.d.ts.map +1 -1
  35. package/dist/task/TaskQueueRegistry.d.ts +8 -0
  36. package/dist/task/TaskQueueRegistry.d.ts.map +1 -1
  37. package/dist/task/TaskRunner.d.ts.map +1 -1
  38. package/dist/task/WhileTask.d.ts +1 -0
  39. package/dist/task/WhileTask.d.ts.map +1 -1
  40. package/dist/task/index.d.ts +0 -1
  41. package/dist/task/index.d.ts.map +1 -1
  42. package/dist/task-graph/Conversions.d.ts.map +1 -1
  43. package/dist/task-graph/Dataflow.d.ts +11 -0
  44. package/dist/task-graph/Dataflow.d.ts.map +1 -1
  45. package/dist/task-graph/GraphSchemaUtils.d.ts.map +1 -1
  46. package/dist/task-graph/TaskGraph.d.ts +10 -0
  47. package/dist/task-graph/TaskGraph.d.ts.map +1 -1
  48. package/dist/task-graph/TaskGraphRunner.d.ts +15 -2
  49. package/dist/task-graph/TaskGraphRunner.d.ts.map +1 -1
  50. package/dist/task-graph/Workflow.d.ts.map +1 -1
  51. package/package.json +20 -11
  52. package/src/storage/README.md +51 -5
  53. package/src/task/README.md +0 -17
  54. package/dist/task/JobQueueTask.d.ts +0 -130
  55. package/dist/task/JobQueueTask.d.ts.map +0 -1
  56. package/dist/types.d.ts +0 -8
  57. package/dist/types.d.ts.map +0 -1
package/README.md CHANGED
@@ -715,9 +715,16 @@ const result = await workflow.run();
715
715
  Output caching lets repeat executions with identical inputs return instantly without redoing work.
716
716
 
717
717
  ```typescript
718
- import { Task, TaskGraph, Workflow } from "@workglow/task-graph";
718
+ import {
719
+ Task,
720
+ TaskGraph,
721
+ Workflow,
722
+ TaskOutputPrimaryKeyNames,
723
+ TaskOutputSchema,
724
+ TaskOutputTabularRepository,
725
+ } from "@workglow/task-graph";
726
+ import { InMemoryTabularStorage } from "@workglow/storage";
719
727
  import { DataPortSchema } from "@workglow/util";
720
- import { InMemoryTaskOutputRepository } from "@workglow/test";
721
728
 
722
729
  // A cacheable task that simulates expensive work
723
730
  class ExpensiveTask extends Task<{ n: number }, { result: number }> {
@@ -754,7 +761,11 @@ class ExpensiveTask extends Task<{ n: number }, { result: number }> {
754
761
  }
755
762
 
756
763
  // Create an output cache
757
- const outputCache = new InMemoryTaskOutputRepository();
764
+ const outputCache = new TaskOutputTabularRepository({
765
+ tabularRepository: new InMemoryTabularStorage(TaskOutputSchema, TaskOutputPrimaryKeyNames, [
766
+ "createdAt",
767
+ ]),
768
+ });
758
769
 
759
770
  // Example 1: TaskGraph caching (second run is near-instant)
760
771
  const graph = new TaskGraph({ outputCache });
@@ -803,10 +814,22 @@ console.log({ wfFirstMs, wfSecondMs });
803
814
  ### Task Graph Persistence
804
815
 
805
816
  ```typescript
806
- import { FsFolderTaskGraphRepository } from "@workglow/test";
817
+ import {
818
+ TaskGraph,
819
+ TaskGraphPrimaryKeyNames,
820
+ TaskGraphSchema,
821
+ TaskGraphTabularRepository,
822
+ } from "@workglow/task-graph";
823
+ import { FsFolderTabularStorage } from "@workglow/storage";
807
824
 
808
825
  // Create repository
809
- const repository = new FsFolderTaskGraphRepository("./task-graphs");
826
+ const repository = new TaskGraphTabularRepository({
827
+ tabularRepository: new FsFolderTabularStorage(
828
+ "./task-graphs",
829
+ TaskGraphSchema,
830
+ TaskGraphPrimaryKeyNames
831
+ ),
832
+ });
810
833
 
811
834
  // Save task graph
812
835
  const graph = new TaskGraph();
@@ -820,18 +843,87 @@ const results = await loadedGraph.run();
820
843
 
821
844
  ### Different Storage Options
822
845
 
846
+ Wire `TaskOutputTabularRepository` / `TaskGraphTabularRepository` from `@workglow/task-graph` to a `*TabularStorage` from `@workglow/storage`:
847
+
823
848
  ```typescript
824
- // In-memory (for testing)
825
- import { InMemoryTaskOutputRepository, InMemoryTaskGraphRepository } from "@workglow/test";
849
+ import {
850
+ TaskGraphPrimaryKeyNames,
851
+ TaskGraphSchema,
852
+ TaskGraphTabularRepository,
853
+ TaskOutputPrimaryKeyNames,
854
+ TaskOutputSchema,
855
+ TaskOutputTabularRepository,
856
+ } from "@workglow/task-graph";
857
+ import {
858
+ FsFolderTabularStorage,
859
+ InMemoryTabularStorage,
860
+ IndexedDbTabularStorage,
861
+ SqliteTabularStorage,
862
+ } from "@workglow/storage";
863
+ import { Sqlite } from "@workglow/storage/sqlite";
864
+
865
+ // In-memory (e.g. tests)
866
+ const memoryOutput = new TaskOutputTabularRepository({
867
+ tabularRepository: new InMemoryTabularStorage(TaskOutputSchema, TaskOutputPrimaryKeyNames, [
868
+ "createdAt",
869
+ ]),
870
+ });
871
+ const memoryGraph = new TaskGraphTabularRepository({
872
+ tabularRepository: new InMemoryTabularStorage(TaskGraphSchema, TaskGraphPrimaryKeyNames),
873
+ });
826
874
 
827
875
  // File system
828
- import { FsFolderTaskOutputRepository, FsFolderTaskGraphRepository } from "@workglow/test";
876
+ const fsOutput = new TaskOutputTabularRepository({
877
+ tabularRepository: new FsFolderTabularStorage(
878
+ "./task-output-cache",
879
+ TaskOutputSchema,
880
+ TaskOutputPrimaryKeyNames
881
+ ),
882
+ });
883
+ const fsGraph = new TaskGraphTabularRepository({
884
+ tabularRepository: new FsFolderTabularStorage(
885
+ "./task-graphs",
886
+ TaskGraphSchema,
887
+ TaskGraphPrimaryKeyNames
888
+ ),
889
+ });
829
890
 
830
- // SQLite
831
- import { SqliteTaskOutputRepository, SqliteTaskGraphRepository } from "@workglow/test";
891
+ // SQLite (await Sqlite.init() once before using a path or new Sqlite.Database)
892
+ await Sqlite.init();
893
+ const sqliteOutput = new TaskOutputTabularRepository({
894
+ tabularRepository: new SqliteTabularStorage(
895
+ ":memory:",
896
+ "task_outputs",
897
+ TaskOutputSchema,
898
+ TaskOutputPrimaryKeyNames,
899
+ ["createdAt"]
900
+ ),
901
+ });
902
+ const sqliteGraph = new TaskGraphTabularRepository({
903
+ tabularRepository: new SqliteTabularStorage(
904
+ ":memory:",
905
+ "task_graphs",
906
+ TaskGraphSchema,
907
+ TaskGraphPrimaryKeyNames
908
+ ),
909
+ });
832
910
 
833
- // IndexedDB (browser)
834
- import { IndexedDbTaskOutputRepository, IndexedDbTaskGraphRepository } from "@workglow/test";
911
+ // IndexedDB (browser) — the `@workglow/web` example under `examples/web` includes small helpers
912
+ const idbOutput = new TaskOutputTabularRepository({
913
+ tabularRepository: new IndexedDbTabularStorage(
914
+ "task_outputs",
915
+ TaskOutputSchema,
916
+ TaskOutputPrimaryKeyNames,
917
+ ["createdAt"]
918
+ ),
919
+ });
920
+ const idbGraph = new TaskGraphTabularRepository({
921
+ tabularRepository: new IndexedDbTabularStorage(
922
+ "task_graphs",
923
+ TaskGraphSchema,
924
+ TaskGraphPrimaryKeyNames
925
+ ),
926
+ });
835
927
  ```
836
928
 
837
929
  ## Error Handling
@@ -926,30 +1018,6 @@ try {
926
1018
 
927
1019
  ## Advanced Patterns
928
1020
 
929
- ### Job Queue Tasks
930
-
931
- ```typescript
932
- class RemoteProcessingTask extends JobQueueTask<{ data: string }, { result: string }> {
933
- static readonly type = "RemoteProcessingTask";
934
-
935
- async createJob() {
936
- return new Job({
937
- input: this.runInputData,
938
- execute: async (input) => {
939
- // This runs in a job queue (can be distributed)
940
- const processed = await this.callRemoteAPI(input.data);
941
- return { result: processed };
942
- },
943
- });
944
- }
945
-
946
- private async callRemoteAPI(data: string): Promise<string> {
947
- // Simulate API call
948
- return `Processed: ${data}`;
949
- }
950
- }
951
- ```
952
-
953
1021
  ### Composite Tasks (Tasks that contain other tasks)
954
1022
 
955
1023
  ```typescript