@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/facts.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** Validation and id derivation shared by the log backends. */
|
|
2
|
+
|
|
3
|
+
import { InvalidPayloadError } from "./errors.ts";
|
|
4
|
+
import { assertJsonValue } from "./json-value.ts";
|
|
5
|
+
import type { NewFact } from "./types.ts";
|
|
6
|
+
|
|
7
|
+
const RUN_ID = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
8
|
+
|
|
9
|
+
export function assertName(value: string, label: string): void {
|
|
10
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
11
|
+
throw new InvalidPayloadError(`${label} must be a non-empty string`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function assertRunId(runId: string): void {
|
|
16
|
+
if (!RUN_ID.test(runId)) {
|
|
17
|
+
throw new InvalidPayloadError(`invalid run id ${JSON.stringify(runId)}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function assertExpectedSeq(expectedSeq: number): void {
|
|
22
|
+
if (!Number.isInteger(expectedSeq) || expectedSeq < 0) {
|
|
23
|
+
throw new InvalidPayloadError("expectedSeq must be a non-negative integer");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function validateNewFact(fact: NewFact): void {
|
|
28
|
+
if (typeof fact !== "object" || fact === null) {
|
|
29
|
+
throw new InvalidPayloadError("a fact must be an object");
|
|
30
|
+
}
|
|
31
|
+
if (typeof fact.kind !== "string" || fact.kind.length === 0) {
|
|
32
|
+
throw new InvalidPayloadError("a fact must have a non-empty kind");
|
|
33
|
+
}
|
|
34
|
+
if (typeof fact.cause === "number") {
|
|
35
|
+
if (!Number.isInteger(fact.cause) || fact.cause < 1) {
|
|
36
|
+
throw new InvalidPayloadError("a numeric fact cause must be a positive sequence number");
|
|
37
|
+
}
|
|
38
|
+
} else if (typeof fact.cause !== "string" || fact.cause.length === 0) {
|
|
39
|
+
throw new InvalidPayloadError("a fact cause must be a sequence number or an input id");
|
|
40
|
+
}
|
|
41
|
+
assertJsonValue(fact.payload, "fact payload");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function inputKey(source: string, sourceKey: string): string {
|
|
45
|
+
return JSON.stringify([source, sourceKey]);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function inputIdFor(source: string, sourceKey: string): string {
|
|
49
|
+
return `input_${Buffer.from(inputKey(source, sourceKey), "utf8").toString("base64url")}`;
|
|
50
|
+
}
|
package/src/log/index.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { InvalidPayloadError, SecretSerializationError } from "./errors.ts";
|
|
2
|
+
import { Secret } from "./secret.ts";
|
|
3
|
+
import type { JsonValue } from "./types.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Accept only values JSON can represent. This rejects the cases
|
|
7
|
+
* `JSON.stringify` silently drops (`undefined`, functions) and class instances
|
|
8
|
+
* such as `Secret`, before anything is written.
|
|
9
|
+
*/
|
|
10
|
+
export function assertJsonValue(value: unknown, path = "payload"): asserts value is JsonValue {
|
|
11
|
+
const seen = new WeakSet<object>();
|
|
12
|
+
|
|
13
|
+
function walk(current: unknown, at: string): void {
|
|
14
|
+
if (current === null) return;
|
|
15
|
+
switch (typeof current) {
|
|
16
|
+
case "string":
|
|
17
|
+
case "boolean":
|
|
18
|
+
return;
|
|
19
|
+
case "number":
|
|
20
|
+
if (!Number.isFinite(current)) {
|
|
21
|
+
throw new InvalidPayloadError(`${at} is not a finite JSON number`);
|
|
22
|
+
}
|
|
23
|
+
return;
|
|
24
|
+
case "object":
|
|
25
|
+
break;
|
|
26
|
+
default:
|
|
27
|
+
throw new InvalidPayloadError(`${at} is not JSON (${typeof current})`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (current instanceof Secret) {
|
|
31
|
+
throw new SecretSerializationError();
|
|
32
|
+
}
|
|
33
|
+
if (seen.has(current)) {
|
|
34
|
+
throw new InvalidPayloadError(`${at} contains a cycle`);
|
|
35
|
+
}
|
|
36
|
+
seen.add(current);
|
|
37
|
+
|
|
38
|
+
// `JSON.stringify` calls `toJSON` even when it is not enumerable, so the
|
|
39
|
+
// value it would store differs from the value inspected here.
|
|
40
|
+
if (typeof (current as { toJSON?: unknown }).toJSON === "function") {
|
|
41
|
+
throw new InvalidPayloadError(
|
|
42
|
+
`${at} has a toJSON method, so its JSON form is not the value inspected`,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (Array.isArray(current)) {
|
|
47
|
+
for (let index = 0; index < current.length; index += 1) {
|
|
48
|
+
if (!(index in current)) {
|
|
49
|
+
throw new InvalidPayloadError(`${at}[${index}] is a hole, not a JSON value`);
|
|
50
|
+
}
|
|
51
|
+
walk(current[index], `${at}[${index}]`);
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
const prototype = Object.getPrototypeOf(current);
|
|
55
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
56
|
+
throw new InvalidPayloadError(`${at} is not a plain JSON object`);
|
|
57
|
+
}
|
|
58
|
+
for (const [key, item] of Object.entries(current)) {
|
|
59
|
+
walk(item, `${at}.${key}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
seen.delete(current);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
walk(value, path);
|
|
67
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Opening a log by backend name, without reading repository configuration. */
|
|
2
|
+
|
|
3
|
+
import { openSqliteLogBackend } from "./sqlite.ts";
|
|
4
|
+
import type { LogBackend, LogBackendOptions } from "./types.ts";
|
|
5
|
+
|
|
6
|
+
export type LogBackendName = "sqlite";
|
|
7
|
+
|
|
8
|
+
export interface OpenLogOptions extends LogBackendOptions {
|
|
9
|
+
readonly backend: LogBackendName;
|
|
10
|
+
/** The database file. */
|
|
11
|
+
readonly path: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Open the log a store uses. The caller decides the backend; this reads no config. */
|
|
15
|
+
export function openLog(options: OpenLogOptions): LogBackend {
|
|
16
|
+
return openSqliteLogBackend(options.path, options);
|
|
17
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { SecretSerializationError } from "./errors.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A value that must never reach the log. JSON serialisation throws, so a fact
|
|
5
|
+
* that carries one cannot be stored by accident.
|
|
6
|
+
*/
|
|
7
|
+
export class Secret<T = string> {
|
|
8
|
+
readonly #value: T;
|
|
9
|
+
|
|
10
|
+
constructor(value: T) {
|
|
11
|
+
this.#value = value;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Read the value. Callers that reveal a secret do so deliberately. */
|
|
15
|
+
reveal(): T {
|
|
16
|
+
return this.#value;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
toJSON(): never {
|
|
20
|
+
throw new SecretSerializationError();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
toString(): string {
|
|
24
|
+
return "[Secret]";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function secret<T>(value: T): Secret<T> {
|
|
29
|
+
return new Secret(value);
|
|
30
|
+
}
|