@operad-io/engine 0.0.0-stage → 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.
- package/LICENSE +21 -0
- package/README.md +11 -2
- package/config.schema.json +188 -0
- package/keys.schema.json +12 -0
- package/package.json +22 -4
- package/src/config/config.ts +627 -0
- package/src/config/index.ts +1 -0
- package/src/flow/define-flow.ts +57 -0
- package/src/flow/index.ts +5 -0
- package/src/flow/load.ts +41 -0
- package/src/flow/types.ts +107 -0
- package/src/flow/validate.ts +296 -0
- package/src/http/address.ts +142 -0
- package/src/http/index.ts +25 -0
- package/src/http/link.ts +20 -0
- package/src/http/server.ts +920 -0
- package/src/http/token.ts +90 -0
- package/src/index.ts +18 -0
- package/src/kernel/decide.ts +689 -0
- package/src/kernel/index.ts +3 -0
- package/src/kernel/state.ts +275 -0
- package/src/kernel/types.ts +366 -0
- package/src/log/errors.ts +77 -0
- package/src/log/facts.ts +50 -0
- package/src/log/index.ts +6 -0
- package/src/log/json-value.ts +67 -0
- package/src/log/open-log.ts +17 -0
- package/src/log/schema.ts +5 -0
- package/src/log/secret.ts +30 -0
- package/src/log/sqlite.ts +1011 -0
- package/src/log/types.ts +230 -0
- package/src/loop/code-watch.ts +486 -0
- package/src/loop/index.ts +3 -0
- package/src/loop/older-code.ts +58 -0
- package/src/loop/serve.ts +483 -0
- package/src/markdown.ts +451 -0
- package/src/notify/index.ts +10 -0
- package/src/notify/notify.ts +256 -0
- package/src/platform/file-lock.ts +385 -0
- package/src/platform/index.ts +13 -0
- package/src/platform/load.ts +18 -0
- package/src/platform/process-group.ts +675 -0
- package/src/platform/process-watch.ts +152 -0
- package/src/platform/sqlite-open.ts +104 -0
- package/src/platform/step-reap.ts +668 -0
- package/src/platform/watch.ts +158 -0
- package/src/platform/worker-reports.ts +34 -0
- package/src/plugin/action-schema.ts +550 -0
- package/src/plugin/declared-flows.ts +74 -0
- package/src/plugin/define-plugin.ts +12 -0
- package/src/plugin/errors.ts +73 -0
- package/src/plugin/filters.ts +46 -0
- package/src/plugin/harness.ts +50 -0
- package/src/plugin/home.ts +13 -0
- package/src/plugin/index.ts +65 -0
- package/src/plugin/install.ts +268 -0
- package/src/plugin/keys.ts +63 -0
- package/src/plugin/load.ts +256 -0
- package/src/plugin/logger.ts +30 -0
- package/src/plugin/object-facts.ts +132 -0
- package/src/plugin/open-store.ts +32 -0
- package/src/plugin/paging.ts +133 -0
- package/src/plugin/registry.ts +1786 -0
- package/src/plugin/secrets.ts +141 -0
- package/src/plugin/semver.ts +110 -0
- package/src/plugin/settings.ts +64 -0
- package/src/plugin/sqlite-store.ts +756 -0
- package/src/plugin/store.ts +318 -0
- package/src/plugin/types.ts +1243 -0
- package/src/plugin/usage.ts +157 -0
- package/src/plugin/validate.ts +1028 -0
- package/src/runner/answer.ts +156 -0
- package/src/runner/ask.ts +483 -0
- package/src/runner/cancel.ts +51 -0
- package/src/runner/errors.ts +20 -0
- package/src/runner/grants.ts +92 -0
- package/src/runner/index.ts +33 -0
- package/src/runner/limits.ts +403 -0
- package/src/runner/lock.ts +140 -0
- package/src/runner/runner.ts +1175 -0
- package/src/runner/service.ts +184 -0
- package/src/runner/step-worker.ts +303 -0
- package/src/testing/clock.ts +67 -0
- package/src/testing/index.ts +90 -0
- package/src/testing/types.ts +116 -0
- package/src/testing/world.ts +369 -0
- package/src/trigger/cron.ts +193 -0
- package/src/trigger/index.ts +32 -0
- package/src/trigger/kernel.ts +1221 -0
- package/src/trigger/rules.ts +300 -0
- package/src/trigger/store.ts +233 -0
- package/src/trigger/types.ts +156 -0
- package/src/util.ts +50 -0
- package/src/views/history.ts +634 -0
- package/src/views/index.ts +7 -0
- package/src/views/pending.ts +209 -0
- package/src/views/presentation.ts +2609 -0
- package/src/views/running.ts +255 -0
- package/src/views/settings.ts +452 -0
- package/src/views/types.ts +72 -0
- package/src/views/uploads.ts +228 -0
- package/triggers.schema.json +48 -0
package/src/log/types.ts
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/** The public shapes of the append-only fact log. */
|
|
2
|
+
|
|
3
|
+
import type { FollowOptions } from "../platform/watch.ts";
|
|
4
|
+
|
|
5
|
+
/** A value that JSON can represent without losing anything. */
|
|
6
|
+
export type JsonValue =
|
|
7
|
+
| string
|
|
8
|
+
| number
|
|
9
|
+
| boolean
|
|
10
|
+
| null
|
|
11
|
+
| JsonValue[]
|
|
12
|
+
| { [key: string]: JsonValue };
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* What caused a fact: the sequence number of an earlier fact in the same run,
|
|
16
|
+
* or the id returned by `recordInput`.
|
|
17
|
+
*/
|
|
18
|
+
export type FactCause = number | string;
|
|
19
|
+
|
|
20
|
+
/** A fact before the backend gives it a run id, a sequence number and a time. */
|
|
21
|
+
export interface NewFact {
|
|
22
|
+
readonly kind: string;
|
|
23
|
+
readonly payload: JsonValue;
|
|
24
|
+
readonly cause: FactCause;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** A fact as it is stored and read. */
|
|
28
|
+
export interface Fact extends NewFact {
|
|
29
|
+
readonly runId: string;
|
|
30
|
+
readonly seq: number;
|
|
31
|
+
readonly time: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A fact that belongs to no run, such as an event the kernel only observed. */
|
|
35
|
+
export interface GlobalFact extends NewFact {
|
|
36
|
+
readonly seq: number;
|
|
37
|
+
readonly time: number;
|
|
38
|
+
/** The key `appendGlobal` was given, when it was given one. */
|
|
39
|
+
readonly uniqueKey?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface RunInfo {
|
|
43
|
+
readonly runId: string;
|
|
44
|
+
readonly flow: string;
|
|
45
|
+
readonly object: string;
|
|
46
|
+
readonly active: boolean;
|
|
47
|
+
readonly startedAt: number;
|
|
48
|
+
readonly endedAt: number | null;
|
|
49
|
+
readonly lastSeq: number;
|
|
50
|
+
/** The access profile recorded when the run started, if any. */
|
|
51
|
+
readonly access?: JsonValue | undefined;
|
|
52
|
+
/** The input whose start created this run, or null for a plain start. */
|
|
53
|
+
readonly startInputId: string | null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** One recorded input, as the log keeps it. */
|
|
57
|
+
export interface InputRecord {
|
|
58
|
+
readonly inputId: string;
|
|
59
|
+
readonly runId: string | null;
|
|
60
|
+
readonly source: string;
|
|
61
|
+
readonly sourceKey: string;
|
|
62
|
+
readonly payload: JsonValue;
|
|
63
|
+
readonly time: number;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface RecordInputResult {
|
|
67
|
+
readonly duplicate: boolean;
|
|
68
|
+
readonly inputId: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* What the kernel decided to do with a recorded input, keyed by
|
|
73
|
+
* `(inputId, kind)`. The first write for a kind wins, so concurrent callers
|
|
74
|
+
* cannot record two different outcomes for one event.
|
|
75
|
+
*/
|
|
76
|
+
export interface InputOutcome {
|
|
77
|
+
readonly inputId: string;
|
|
78
|
+
readonly kind: string;
|
|
79
|
+
readonly payload: JsonValue;
|
|
80
|
+
readonly seq: number;
|
|
81
|
+
readonly time: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Inputs read after a position, with the position that continues the read. */
|
|
85
|
+
export interface InputsAfter {
|
|
86
|
+
readonly inputs: readonly InputRecord[];
|
|
87
|
+
readonly position: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface RecordOutcomeResult {
|
|
91
|
+
readonly duplicate: boolean;
|
|
92
|
+
readonly outcome: InputOutcome;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface AppendResult {
|
|
96
|
+
readonly lastSeq: number;
|
|
97
|
+
readonly facts: readonly Fact[];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface RunsOptions {
|
|
101
|
+
readonly active?: boolean;
|
|
102
|
+
/** Only the runs of this object key, such as `task:42`. */
|
|
103
|
+
readonly object?: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface LogBackendOptions extends FollowOptions {
|
|
107
|
+
/** The clock every stored time comes from. Defaults to `Date.now`. */
|
|
108
|
+
readonly clock?: () => number;
|
|
109
|
+
/**
|
|
110
|
+
* Makes the id of each new run. Defaults to a random UUID. A copy of a log
|
|
111
|
+
* passes the ids of the runs it copies.
|
|
112
|
+
*/
|
|
113
|
+
readonly runId?: () => string;
|
|
114
|
+
/**
|
|
115
|
+
* How often an open subscription re-reads storage for another process's
|
|
116
|
+
* write, in milliseconds. Defaults to 500. The watch is the fast path; this
|
|
117
|
+
* check is the one that cannot miss a write the watch does not report.
|
|
118
|
+
*/
|
|
119
|
+
readonly pollMs?: number;
|
|
120
|
+
/** Called each time a subscription reads every run's last sequence. A test counts it. */
|
|
121
|
+
readonly onSnapshot?: () => void;
|
|
122
|
+
/**
|
|
123
|
+
* Starts a repeating timer that calls `callback` every `ms` and returns a
|
|
124
|
+
* stop function. Defaults to `setInterval`. A test passes a stub it fires by
|
|
125
|
+
* hand, so no test waits on wall time.
|
|
126
|
+
*/
|
|
127
|
+
readonly repeat?: (ms: number, callback: () => void) => () => void;
|
|
128
|
+
/**
|
|
129
|
+
* Watches a directory for another process's write and returns a stop
|
|
130
|
+
* function. Defaults to `fs.watch`. A test passes a stub that never fires.
|
|
131
|
+
*/
|
|
132
|
+
readonly watch?: (
|
|
133
|
+
directory: string,
|
|
134
|
+
onChange: (filename: string | null) => void,
|
|
135
|
+
) => () => void;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** A change to a run: a start, an end, or one appended batch. */
|
|
139
|
+
export interface LogChange {
|
|
140
|
+
readonly runId: string;
|
|
141
|
+
/** The run's object key, such as `task:42`; undefined when it cannot be read. */
|
|
142
|
+
readonly object: string | undefined;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Options for a log backend that can notify a local listener. */
|
|
146
|
+
export interface LogSubscription {
|
|
147
|
+
subscribe(listener: (change: LogChange) => void): () => void;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface LogBackend extends Partial<LogSubscription> {
|
|
151
|
+
/**
|
|
152
|
+
* Start a run, unless the same flow/object pair already has an active one.
|
|
153
|
+
* `startInputId` records the input that caused the start, so the log alone
|
|
154
|
+
* can answer which run an event started; `access` is the run's profile.
|
|
155
|
+
*/
|
|
156
|
+
startRun(
|
|
157
|
+
flow: string,
|
|
158
|
+
object: string,
|
|
159
|
+
startInputId?: string | null,
|
|
160
|
+
access?: JsonValue,
|
|
161
|
+
): Promise<RunInfo>;
|
|
162
|
+
/** End an active run. Ending an ended run is a no-op. */
|
|
163
|
+
endRun(runId: string): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Record one input for a run, or a global input when `runId` is null. A
|
|
166
|
+
* repeated (source, sourceKey) is a duplicate: `duplicate` is true and
|
|
167
|
+
* nothing is written.
|
|
168
|
+
*/
|
|
169
|
+
recordInput(
|
|
170
|
+
runId: string | null,
|
|
171
|
+
source: string,
|
|
172
|
+
sourceKey: string,
|
|
173
|
+
payload: JsonValue,
|
|
174
|
+
): Promise<RecordInputResult>;
|
|
175
|
+
/**
|
|
176
|
+
* Append one batch of facts. The whole batch is written or nothing is. The
|
|
177
|
+
* run's last sequence must equal `expectedSeq`; the backend assigns the
|
|
178
|
+
* following sequence numbers and the times.
|
|
179
|
+
*/
|
|
180
|
+
append(
|
|
181
|
+
runId: string,
|
|
182
|
+
expectedSeq: number,
|
|
183
|
+
facts: readonly NewFact[],
|
|
184
|
+
): Promise<AppendResult>;
|
|
185
|
+
/** Stream the facts of a run in sequence order. */
|
|
186
|
+
read(runId: string): AsyncIterable<Fact>;
|
|
187
|
+
/** List runs, optionally only the active ones. */
|
|
188
|
+
runs(options?: RunsOptions): Promise<RunInfo[]>;
|
|
189
|
+
/**
|
|
190
|
+
* Append one fact that belongs to no run. Global facts keep their order.
|
|
191
|
+
* With a `uniqueKey`, the first fact for that key wins: a later call writes
|
|
192
|
+
* nothing and returns the stored fact.
|
|
193
|
+
*/
|
|
194
|
+
appendGlobal(fact: NewFact, uniqueKey?: string): Promise<GlobalFact>;
|
|
195
|
+
/** Stream the global facts in sequence order. */
|
|
196
|
+
readGlobal(): AsyncIterable<GlobalFact>;
|
|
197
|
+
/** Stream every recorded input, oldest first. */
|
|
198
|
+
readInputs(): AsyncIterable<InputRecord>;
|
|
199
|
+
/**
|
|
200
|
+
* The inputs recorded after a position, oldest first, and the position to
|
|
201
|
+
* ask from next time. Position 0 is the start. A caller that remembers the
|
|
202
|
+
* position reads only what is new, so its cost follows what changed.
|
|
203
|
+
*/
|
|
204
|
+
readInputsAfter(position: number): Promise<InputsAfter>;
|
|
205
|
+
/** One input by id, or undefined. */
|
|
206
|
+
findInput(inputId: string): Promise<InputRecord | undefined>;
|
|
207
|
+
/** The outcome stored for `(inputId, kind)`, or undefined. */
|
|
208
|
+
readOutcome(inputId: string, kind: string): Promise<InputOutcome | undefined>;
|
|
209
|
+
/** The outcomes with a sequence above `seq`, in order. */
|
|
210
|
+
readOutcomesAfter(seq: number): Promise<InputOutcome[]>;
|
|
211
|
+
/**
|
|
212
|
+
* Record the kernel's outcome for an input. A repeated `(inputId, kind)` is
|
|
213
|
+
* a duplicate: `duplicate` is true, nothing is written, and the stored
|
|
214
|
+
* outcome is returned. Concurrent callers therefore agree on one outcome.
|
|
215
|
+
*/
|
|
216
|
+
recordOutcome(
|
|
217
|
+
inputId: string,
|
|
218
|
+
kind: string,
|
|
219
|
+
payload: JsonValue,
|
|
220
|
+
): Promise<RecordOutcomeResult>;
|
|
221
|
+
/** Stream every recorded outcome in the order it was written. */
|
|
222
|
+
readOutcomes(): AsyncIterable<InputOutcome>;
|
|
223
|
+
close(): Promise<void>;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** A backend implementation, as a storage directory plus its name. */
|
|
227
|
+
export interface LogBackendFactory {
|
|
228
|
+
readonly name: string;
|
|
229
|
+
open(directory: string, options?: LogBackendOptions): LogBackend | Promise<LogBackend>;
|
|
230
|
+
}
|