@workglow/task-graph 0.0.125 → 0.0.126
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -12
- package/dist/browser.js +605 -771
- package/dist/browser.js.map +19 -20
- package/dist/bun.js +605 -767
- package/dist/bun.js.map +19 -20
- package/dist/node.js +605 -767
- package/dist/node.js.map +19 -20
- package/dist/task-graph/Conversions.d.ts.map +1 -1
- package/package.json +20 -11
- package/src/storage/README.md +51 -5
- package/dist/types.d.ts +0 -8
- 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 {
|
|
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
|
|
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 {
|
|
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
|
|
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
|
-
|
|
825
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|