capdag 1.426.27 → 1.457.27

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 CHANGED
@@ -28,10 +28,10 @@ imported, so importing it waits for that (top-level `await`), and a CommonJS
28
28
  import { CapUrn, CapUrnBuilder } from "capdag";
29
29
 
30
30
  const parsed = CapUrn.fromString(
31
- 'cap:disbind;in="media:ext=pdf";out="media:enc=utf-8;page"'
31
+ 'cap:disbind;in="media:document;ext=pdf";out="media:enc=utf-8;page"'
32
32
  );
33
33
  const built = new CapUrnBuilder()
34
- .inSpec("media:ext=pdf")
34
+ .inSpec("media:document;ext=pdf")
35
35
  .outSpec("media:enc=utf-8;page")
36
36
  .marker("disbind")
37
37
  .build();
@@ -42,11 +42,63 @@ console.log(parsed.toString() === built.toString());
42
42
  Treat URNs as opaque parsed values. Use the package's predicates for
43
43
  equivalence, conformance, dispatch, and ranking instead of string surgery.
44
44
 
45
+ ## Read and write Machine Notation
46
+
47
+ A machine is read against the definitions of the caps it names: they say what
48
+ each step takes and gives, by name and by type, and what a constant written in
49
+ the machine is held to.
50
+
51
+ ```javascript
52
+ import { Cap, CapArg, CapOutput, ArgSource, CapUrn, CapDefinitions, parseMachine } from "capdag";
53
+
54
+ const extract = new Cap(
55
+ CapUrn.fromString('cap:in="media:document;ext=pdf";extract;out="media:enc=utf-8;ext=txt"'),
56
+ "Extract Text", ["extract"]
57
+ );
58
+ extract.addArg(new CapArg("media:document;ext=pdf", "document", true,
59
+ [new ArgSource({ stdin: "media:document;ext=pdf" })]));
60
+ extract.addOutput(new CapOutput("media:enc=utf-8;ext=txt", "text", "The text"));
61
+
62
+ const definitions = new CapDefinitions().addCaps([extract]);
63
+ const machine = parseMachine(
64
+ '[extract cap:in="media:document;ext=pdf";extract;out="media:enc=utf-8;ext=txt"]' +
65
+ "[(document=pdf) -> extract -> text]",
66
+ definitions
67
+ );
68
+ console.log(machine.toMachineNotation());
69
+ ```
70
+
71
+ The definitions can come from the fabric registry instead. A client reads one
72
+ manifest of it — a pinned version, or the one the registry has promoted as its
73
+ latest — fetches each definition it needs, holds each cap to the definition
74
+ rules as it reads it, and then serves as the definitions a machine is parsed
75
+ against, fabric aliases included:
76
+
77
+ ```javascript
78
+ import { FabricRegistryClient, parseMachine } from "capdag";
79
+
80
+ const fabric = await FabricRegistryClient.latest("https://fabric.capdag.com");
81
+ await fabric.getCap('cap:in="media:document;ext=pdf";extract;out="media:enc=utf-8;ext=txt"');
82
+ const machine = parseMachine(
83
+ '[extract cap:in="media:document;ext=pdf";extract;out="media:enc=utf-8;ext=txt"]' +
84
+ "[pdf -> extract -> text]",
85
+ fabric
86
+ );
87
+ ```
88
+
89
+ `parseMachineWithAST` also returns every statement with where each part of it
90
+ stands in the text, and the name the text gave each node. A machine that names
91
+ other machines in step position is read with a `MachineSource`
92
+ (`MapMachineSource`, or `FileMachineSource` under Node.js). Anything with
93
+ `capDefinition(urn)` and `mediaDefinition(urn)` can stand in for
94
+ `CapDefinitions`.
95
+
45
96
  ## Find the relevant API
46
97
 
47
- - `capdag.js` provides URNs, definitions, dispatch, and matching.
98
+ - `capdag.js` provides URNs, definitions, dispatch, matching, and Machine
99
+ Notation: reading, resolving and writing machines.
48
100
  - `machine-parser.js` is generated from `machine.pegjs`.
49
- - `planner.js` provides planning and Machine Notation structures.
101
+ - `planner.js` provides the planner's request and result vocabulary.
50
102
  - `cap-fab-renderer.js` (`capdag/cap-fab-renderer`) renders graphs; the page
51
103
  provides cytoscape and cytoscape-elk.
52
104
  - `formal/` is the generated model code, with its WebAssembly program.