/
plot.go
155 lines (131 loc) · 3.7 KB
/
plot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package wfapi
import (
"fmt"
"github.com/ipfs/go-cid"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/ipld/go-ipld-prime/node/bindnode"
"github.com/ipld/go-ipld-prime/schema"
)
type PlotCID string
type PlotCapsule struct {
Plot *Plot
}
type Plot struct {
Inputs struct {
Keys []LocalLabel
Values map[LocalLabel]PlotInput
}
Steps struct {
Keys []StepName
Values map[StepName]Step
}
Outputs struct {
Keys []LocalLabel
Values map[LocalLabel]PlotOutput
}
}
func (plot *Plot) Cid() PlotCID {
// convert parsed release to node
nRelease := bindnode.Wrap(plot, TypeSystem.TypeByName("Plot"))
// compute CID of parsed release data
lsys := cidlink.DefaultLinkSystem()
lnk, errRaw := lsys.ComputeLink(cidlink.LinkPrototype{Prefix: cid.Prefix{
Version: 1, // Usually '1'.
Codec: 0x71, // 0x71 means "dag-cbor" -- See the multicodecs table: https://github.com/multiformats/multicodec/
MhType: 0x20, // 0x20 means "sha2-384" -- See the multicodecs table: https://github.com/multiformats/multicodec/
MhLength: 48, // sha2-384 hash has a 48-byte sum.
}}, nRelease.(schema.TypedNode).Representation())
if errRaw != nil {
// panic! this should never fail unless IPLD is broken
panic(fmt.Sprintf("Fatal IPLD Error: lsys.ComputeLink failed for CatalogRelease: %s", errRaw))
}
cid, errRaw := lnk.(cidlink.Link).StringOfBase('z')
if errRaw != nil {
panic(fmt.Sprintf("Fatal IPLD Error: failed to encode CID for CatalogRelease: %s", errRaw))
}
return PlotCID(cid)
}
// StepName is for assigning string names to Steps in a Plot.
// StepNames will be part of wiring things together using Pipes.
//
// Must not contain ':' charaters or unprintables or whitespace.
type StepName string
// LocalLabel is for referencing data within a Plot.
// Input data gets assigned a LocalLabel;
// Pipes pull info from a LocalLabel (possibly together with a StepName to scope it);
// when a Step is evaluated (e.g. turned into a Formula, executed, and produces results),
// the results will become identifiable by a LocalLabel (scoped by the StepName).
//
// (LocalLabel and OutputName are essentially the same thing: an OutputName
// gets casted to being considered a LocalLabel when a Formula's results are hoisted
// into the Plot.)
//
// Must not contain ':' charaters or unprintables or whitespace.
type LocalLabel string
type PlotInput struct {
PlotInputSimple *PlotInputSimple
PlotInputComplex *PlotInputComplex
}
func (pi *PlotInput) Basis() *PlotInputSimple {
switch {
case pi.PlotInputSimple != nil:
return pi.PlotInputSimple
case pi.PlotInputComplex != nil:
return &pi.PlotInputComplex.Basis
default:
panic("unreachable")
}
}
type PlotInputSimple struct {
WareID *WareID
Mount *Mount
Literal *Literal
Pipe *Pipe
CatalogRef *CatalogRef
Ingest *Ingest
}
type PlotInputComplex struct {
Basis PlotInputSimple
Filters FilterMap
}
type PlotOutput struct {
Pipe *Pipe
}
type Pipe struct {
StepName StepName
Label LocalLabel
}
type Step struct {
Plot *Plot
Protoformula *Protoformula
}
type Protoformula struct {
Inputs struct {
Keys []SandboxPort
Values map[SandboxPort]PlotInput
}
Action Action
Outputs struct {
Keys []LocalLabel
Values map[LocalLabel]GatherDirective
}
}
type ModuleName string
type ReleaseName string
type ItemLabel string
type CatalogRef struct {
ModuleName ModuleName
ReleaseName ReleaseName
ItemName ItemLabel
}
func (c *CatalogRef) String() string {
return fmt.Sprintf("catalog:%s:%s:%s", c.ModuleName, c.ReleaseName, c.ItemName)
}
type PlotResults struct {
Keys []LocalLabel
Values map[LocalLabel]WareID
}
type PlotExecConfig struct {
Recursive bool
FormulaExecConfig FormulaExecConfig
}