@sanoma-ai/workflows 0.0.0-stage → 0.2.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 +105 -0
- package/README.md +544 -2
- package/dist/apply-steps.d.ts +6 -0
- package/dist/apply-steps.js +93 -0
- package/dist/apply-steps.js.map +1 -0
- package/dist/apply.d.ts +197 -0
- package/dist/apply.js +470 -0
- package/dist/apply.js.map +1 -0
- package/dist/approvals.d.ts +46 -0
- package/dist/approvals.js +111 -0
- package/dist/approvals.js.map +1 -0
- package/dist/ast.d.ts +57 -0
- package/dist/ast.js +81 -0
- package/dist/ast.js.map +1 -0
- package/dist/call.d.ts +37 -0
- package/dist/call.js +417 -0
- package/dist/call.js.map +1 -0
- package/dist/client.d.ts +203 -0
- package/dist/client.js +457 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +126 -0
- package/dist/config.js +264 -0
- package/dist/config.js.map +1 -0
- package/dist/credentials.d.ts +55 -0
- package/dist/credentials.js +261 -0
- package/dist/credentials.js.map +1 -0
- package/dist/cucumber.d.ts +64 -0
- package/dist/cucumber.js +158 -0
- package/dist/cucumber.js.map +1 -0
- package/dist/datafile.d.ts +71 -0
- package/dist/datafile.js +380 -0
- package/dist/datafile.js.map +1 -0
- package/dist/db.d.ts +58 -0
- package/dist/db.js +179 -0
- package/dist/db.js.map +1 -0
- package/dist/define.d.ts +205 -0
- package/dist/define.js +103 -0
- package/dist/define.js.map +1 -0
- package/dist/describe.d.ts +141 -0
- package/dist/describe.js +135 -0
- package/dist/describe.js.map +1 -0
- package/dist/drift.d.ts +127 -0
- package/dist/drift.js +167 -0
- package/dist/drift.js.map +1 -0
- package/dist/env.d.ts +49 -0
- package/dist/env.js +83 -0
- package/dist/env.js.map +1 -0
- package/dist/errors.d.ts +88 -0
- package/dist/errors.js +148 -0
- package/dist/errors.js.map +1 -0
- package/dist/expectations.d.ts +26 -0
- package/dist/expectations.js +162 -0
- package/dist/expectations.js.map +1 -0
- package/dist/fake.d.ts +55 -0
- package/dist/fake.js +87 -0
- package/dist/fake.js.map +1 -0
- package/dist/fill.d.ts +9 -0
- package/dist/fill.js +17 -0
- package/dist/fill.js.map +1 -0
- package/dist/host.d.ts +56 -0
- package/dist/host.js +45 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/ledger.d.ts +217 -0
- package/dist/ledger.js +251 -0
- package/dist/ledger.js.map +1 -0
- package/dist/lint.d.ts +32 -0
- package/dist/lint.js +168 -0
- package/dist/lint.js.map +1 -0
- package/dist/lockfile.d.ts +36 -0
- package/dist/lockfile.js +69 -0
- package/dist/lockfile.js.map +1 -0
- package/dist/log.d.ts +24 -0
- package/dist/log.js +83 -0
- package/dist/log.js.map +1 -0
- package/dist/op.d.ts +260 -0
- package/dist/op.js +188 -0
- package/dist/op.js.map +1 -0
- package/dist/outline.d.ts +179 -0
- package/dist/outline.js +506 -0
- package/dist/outline.js.map +1 -0
- package/dist/paths.d.ts +11 -0
- package/dist/paths.js +30 -0
- package/dist/paths.js.map +1 -0
- package/dist/plugin.d.ts +28 -0
- package/dist/plugin.js +25 -0
- package/dist/plugin.js.map +1 -0
- package/dist/policy.d.ts +114 -0
- package/dist/policy.js +60 -0
- package/dist/policy.js.map +1 -0
- package/dist/resource.d.ts +378 -0
- package/dist/resource.js +430 -0
- package/dist/resource.js.map +1 -0
- package/dist/resources.d.ts +77 -0
- package/dist/resources.js +244 -0
- package/dist/resources.js.map +1 -0
- package/dist/run.d.ts +101 -0
- package/dist/run.js +7 -0
- package/dist/run.js.map +1 -0
- package/dist/sandbox.d.ts +33 -0
- package/dist/sandbox.js +127 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/scenario.d.ts +221 -0
- package/dist/scenario.js +1104 -0
- package/dist/scenario.js.map +1 -0
- package/dist/scenarios.d.ts +55 -0
- package/dist/scenarios.js +71 -0
- package/dist/scenarios.js.map +1 -0
- package/dist/secret.d.ts +42 -0
- package/dist/secret.js +58 -0
- package/dist/secret.js.map +1 -0
- package/dist/shared.d.ts +69 -0
- package/dist/shared.js +84 -0
- package/dist/shared.js.map +1 -0
- package/dist/source.d.ts +58 -0
- package/dist/source.js +54 -0
- package/dist/source.js.map +1 -0
- package/dist/steps.d.ts +76 -0
- package/dist/steps.js +23 -0
- package/dist/steps.js.map +1 -0
- package/dist/version.d.ts +29 -0
- package/dist/version.js +76 -0
- package/dist/version.js.map +1 -0
- package/dist/worker.d.ts +37 -0
- package/dist/worker.js +228 -0
- package/dist/worker.js.map +1 -0
- package/dist/writer.d.ts +35 -0
- package/dist/writer.js +201 -0
- package/dist/writer.js.map +1 -0
- package/oxlint.json +128 -0
- package/package.json +96 -3
- package/src/apply-steps.ts +110 -0
- package/src/apply.ts +626 -0
- package/src/approvals.ts +157 -0
- package/src/ast.ts +115 -0
- package/src/call.ts +483 -0
- package/src/client.ts +604 -0
- package/src/config.ts +404 -0
- package/src/credentials.ts +296 -0
- package/src/cucumber.ts +230 -0
- package/src/datafile.ts +481 -0
- package/src/db.ts +197 -0
- package/src/define.ts +285 -0
- package/src/describe.ts +282 -0
- package/src/drift.ts +259 -0
- package/src/env.ts +122 -0
- package/src/errors.ts +202 -0
- package/src/expectations.ts +191 -0
- package/src/fake.ts +156 -0
- package/src/fill.ts +24 -0
- package/src/host.ts +96 -0
- package/src/index.ts +143 -0
- package/src/ledger.ts +419 -0
- package/src/lint.ts +208 -0
- package/src/lockfile.ts +95 -0
- package/src/log.ts +82 -0
- package/src/op.ts +402 -0
- package/src/outline.ts +620 -0
- package/src/paths.ts +32 -0
- package/src/plugin.ts +37 -0
- package/src/policy.ts +139 -0
- package/src/resource.ts +670 -0
- package/src/resources.ts +311 -0
- package/src/run.ts +106 -0
- package/src/sandbox.ts +161 -0
- package/src/scenario.ts +1365 -0
- package/src/scenarios.ts +111 -0
- package/src/secret.ts +92 -0
- package/src/shared.ts +126 -0
- package/src/source.ts +82 -0
- package/src/steps.ts +90 -0
- package/src/version.ts +86 -0
- package/src/worker.ts +264 -0
- package/src/writer.ts +225 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAY7C,MAAM,MAAM,GAAG;IACb,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;IACxB,KAAK,EAAE;QACL,WAAW,EAAE;YACX,IAAI,EAAE;gBACJ,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE;oBACJ,WAAW,EACT,iJAAiJ;iBACpJ;aACF;YACD,MAAM,CAAC,OAAgB;gBACrB,OAAO;oBACL,OAAO,CAAC,OAAgB;wBACtB,KAAK,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;4BACvF,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;wBAC7D,CAAC;oBACH,CAAC;iBACF,CAAC;YACJ,CAAC;SACF;KACF;CACF,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/dist/policy.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type ApprovalState, Approver, type Principal } from "./define.ts";
|
|
3
|
+
import type { Effect, Op } from "./op.ts";
|
|
4
|
+
/** An operation as a policy sees it: plain data, without its schemas. */
|
|
5
|
+
export type PolicyOp = Pick<Op, "id" | "vendor" | "resource" | "name" | "effect">;
|
|
6
|
+
/**
|
|
7
|
+
* An operation as a policy sees it, for a `PolicyCall`: what the runtime passes, so a policy
|
|
8
|
+
* test can build a call from the connector, `{ op: policyOpOf(shop.order.refund), ... }`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const policyOpOf: ({ id, vendor, resource, name, effect }: Op) => PolicyOp;
|
|
11
|
+
/** What a policy sees for each operation a run calls. Plain data, so a test can build one by hand. */
|
|
12
|
+
export interface PolicyCall {
|
|
13
|
+
op: PolicyOp;
|
|
14
|
+
/** The same as `op.effect`. */
|
|
15
|
+
effect: Effect;
|
|
16
|
+
/** The resource instance the call acts on, from the operation's `target`, when it declares one. */
|
|
17
|
+
target?: string;
|
|
18
|
+
/** The operation's input, already checked against its schema. */
|
|
19
|
+
input: unknown;
|
|
20
|
+
/** Who started the run. */
|
|
21
|
+
actor: Principal;
|
|
22
|
+
/**
|
|
23
|
+
* The run so far: a copy of its approvals, including those the policy asked for earlier.
|
|
24
|
+
* A policy request has `requestedBy: "policy"` and the `op` it held.
|
|
25
|
+
*/
|
|
26
|
+
run: {
|
|
27
|
+
id: string;
|
|
28
|
+
workflow: string;
|
|
29
|
+
approvals: readonly ApprovalState[];
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A policy's answer. `reasons` say why, for whoever reads the ledger; they change nothing
|
|
34
|
+
* about what happens to the call.
|
|
35
|
+
*/
|
|
36
|
+
export type Decision = {
|
|
37
|
+
kind: "allow";
|
|
38
|
+
reasons?: string[];
|
|
39
|
+
} | {
|
|
40
|
+
kind: "deny";
|
|
41
|
+
reason: string;
|
|
42
|
+
reasons?: string[];
|
|
43
|
+
} | ApproveDecision;
|
|
44
|
+
/**
|
|
45
|
+
* Hold the call until the approver decides: a person's id, or `{ group }` for anyone in it.
|
|
46
|
+
* The approval covers the held operation, and `covers` adds others, so a policy can let their
|
|
47
|
+
* later calls through once it is approved.
|
|
48
|
+
*/
|
|
49
|
+
interface ApproveDecision {
|
|
50
|
+
kind: "approve";
|
|
51
|
+
approver: Approver;
|
|
52
|
+
title?: string;
|
|
53
|
+
covers?: Op[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Checks a policy's answer. Parsing also copies it, so nothing else the policy returned is kept,
|
|
57
|
+
* and turns `covers` into op ids.
|
|
58
|
+
*/
|
|
59
|
+
export declare const DecisionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
60
|
+
kind: z.ZodLiteral<"allow">;
|
|
61
|
+
reasons: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
62
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
63
|
+
kind: z.ZodLiteral<"deny">;
|
|
64
|
+
reason: z.ZodString;
|
|
65
|
+
reasons: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
66
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
67
|
+
kind: z.ZodLiteral<"approve">;
|
|
68
|
+
approver: z.ZodType<Approver, unknown, z.core.$ZodTypeInternals<Approver, unknown>>;
|
|
69
|
+
title: z.ZodOptional<z.ZodString>;
|
|
70
|
+
covers: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodObject<{
|
|
71
|
+
id: z.ZodString;
|
|
72
|
+
}, z.core.$strip>, z.ZodTransform<string, {
|
|
73
|
+
id: string;
|
|
74
|
+
}>>>>;
|
|
75
|
+
}, z.core.$strip>], "kind">;
|
|
76
|
+
/**
|
|
77
|
+
* A decision as checked and as the ledger records it: `covers` by op id, and the `version` of
|
|
78
|
+
* the policy that made it, when it has one.
|
|
79
|
+
*/
|
|
80
|
+
export type RecordedDecision = z.output<typeof DecisionSchema> & {
|
|
81
|
+
policyVersion?: string;
|
|
82
|
+
};
|
|
83
|
+
export declare const allow: (reasons?: string[]) => Decision;
|
|
84
|
+
export declare const deny: (reason: string, reasons?: string[]) => Decision;
|
|
85
|
+
/** Holds the call for `approver`. `covers` lists other operations the approval also stands for. */
|
|
86
|
+
export declare function approve(approver: Approver, { title, covers }?: {
|
|
87
|
+
title?: string;
|
|
88
|
+
covers?: Op[];
|
|
89
|
+
}): Decision;
|
|
90
|
+
/**
|
|
91
|
+
* Decides whether a run may make an operation call: allow it, deny it (the run fails),
|
|
92
|
+
* or hold it until someone approves. Runs are replayed after a restart, so a policy must
|
|
93
|
+
* decide the same way every time from the call alone: no clock, randomness or network.
|
|
94
|
+
* `lintWorkflow` checks a policy file for these too. Each decision is recorded once made,
|
|
95
|
+
* and a replay reuses it, but a call interrupted before that is decided again. A policy
|
|
96
|
+
* must not have side effects.
|
|
97
|
+
*/
|
|
98
|
+
export type Policy = ((call: PolicyCall) => Decision | Promise<Decision>) & {
|
|
99
|
+
/** Names this version of the policy, from `definePolicy(fn, { version })`. */
|
|
100
|
+
readonly version?: string;
|
|
101
|
+
};
|
|
102
|
+
/** A policy, optionally named with a version so a reader can tell which rules decided a call. */
|
|
103
|
+
export declare function definePolicy(policy: (call: PolicyCall) => Decision | Promise<Decision>, options?: {
|
|
104
|
+
version?: string;
|
|
105
|
+
}): Policy;
|
|
106
|
+
/** Allows every operation call. A config says so explicitly: `policy: allowAll`. */
|
|
107
|
+
export declare const allowAll: Policy;
|
|
108
|
+
/**
|
|
109
|
+
* True when an approval in the run was approved, covers the operation, and was addressed to
|
|
110
|
+
* `approver`. Check all three: a workflow can request an approval covering any operation from
|
|
111
|
+
* anyone it names, so an approval's `covers` alone does not say the right person approved.
|
|
112
|
+
*/
|
|
113
|
+
export declare function approvedFor(approvals: readonly ApprovalState[], opId: string, approver: Approver): boolean;
|
|
114
|
+
export {};
|
package/dist/policy.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { Approver, Covers, sameApprover } from "./define.js";
|
|
3
|
+
/**
|
|
4
|
+
* An operation as a policy sees it, for a `PolicyCall`: what the runtime passes, so a policy
|
|
5
|
+
* test can build a call from the connector, `{ op: policyOpOf(shop.order.refund), ... }`.
|
|
6
|
+
*/
|
|
7
|
+
export const policyOpOf = ({ id, vendor, resource, name, effect }) => ({
|
|
8
|
+
id,
|
|
9
|
+
vendor,
|
|
10
|
+
resource,
|
|
11
|
+
name,
|
|
12
|
+
effect,
|
|
13
|
+
});
|
|
14
|
+
const ReasonList = z.array(z.string(), { error: "reasons must be a list of strings" }).optional();
|
|
15
|
+
/**
|
|
16
|
+
* Checks a policy's answer. Parsing also copies it, so nothing else the policy returned is kept,
|
|
17
|
+
* and turns `covers` into op ids.
|
|
18
|
+
*/
|
|
19
|
+
export const DecisionSchema = z.discriminatedUnion("kind", [
|
|
20
|
+
z.object({ kind: z.literal("allow"), reasons: ReasonList }),
|
|
21
|
+
z.object({ kind: z.literal("deny"), reason: z.string({ error: "deny needs a reason" }), reasons: ReasonList }),
|
|
22
|
+
z.object({
|
|
23
|
+
kind: z.literal("approve"),
|
|
24
|
+
approver: Approver,
|
|
25
|
+
title: z.string({ error: "the title must be a string" }).optional(),
|
|
26
|
+
covers: Covers,
|
|
27
|
+
}),
|
|
28
|
+
], { error: "not a decision" });
|
|
29
|
+
export const allow = (reasons) => reasons === undefined ? { kind: "allow" } : { kind: "allow", reasons };
|
|
30
|
+
export const deny = (reason, reasons) => reasons === undefined ? { kind: "deny", reason } : { kind: "deny", reason, reasons };
|
|
31
|
+
/** Holds the call for `approver`. `covers` lists other operations the approval also stands for. */
|
|
32
|
+
export function approve(approver, { title, covers } = {}) {
|
|
33
|
+
return {
|
|
34
|
+
kind: "approve",
|
|
35
|
+
approver,
|
|
36
|
+
...(title === undefined ? {} : { title }),
|
|
37
|
+
...(covers === undefined ? {} : { covers }),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** A policy, optionally named with a version so a reader can tell which rules decided a call. */
|
|
41
|
+
export function definePolicy(policy, options = {}) {
|
|
42
|
+
if (typeof policy !== "function")
|
|
43
|
+
throw new Error("definePolicy expects a function of the call");
|
|
44
|
+
if (options.version !== undefined && (typeof options.version !== "string" || !options.version.trim())) {
|
|
45
|
+
throw new Error("definePolicy: `version` must be a non-empty string");
|
|
46
|
+
}
|
|
47
|
+
const defined = (call) => policy(call);
|
|
48
|
+
return Object.freeze(options.version === undefined ? defined : Object.assign(defined, { version: options.version }));
|
|
49
|
+
}
|
|
50
|
+
/** Allows every operation call. A config says so explicitly: `policy: allowAll`. */
|
|
51
|
+
export const allowAll = definePolicy(() => allow());
|
|
52
|
+
/**
|
|
53
|
+
* True when an approval in the run was approved, covers the operation, and was addressed to
|
|
54
|
+
* `approver`. Check all three: a workflow can request an approval covering any operation from
|
|
55
|
+
* anyone it names, so an approval's `covers` alone does not say the right person approved.
|
|
56
|
+
*/
|
|
57
|
+
export function approvedFor(approvals, opId, approver) {
|
|
58
|
+
return approvals.some((a) => a.status === "approved" && a.covers.includes(opId) && sameApprover(a.approver, approver));
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type HostSpec } from "./host.ts";
|
|
3
|
+
import { type Connector, type OpSpec, RESOURCE } from "./op.ts";
|
|
4
|
+
import { type Secret } from "./secret.ts";
|
|
5
|
+
/** Which fields of a resource are flagged, by dotted path (`pages.html_url`; a list's items have no index). */
|
|
6
|
+
export interface ResourceFields {
|
|
7
|
+
/** Changing it replaces the object. */
|
|
8
|
+
readonly immutable: readonly string[];
|
|
9
|
+
/** Set by the vendor only: never drift, and a data file may not declare it. */
|
|
10
|
+
readonly vendorOwned: readonly string[];
|
|
11
|
+
/** Sensitive or write-only: never read back, never compared, never in an operation's output. */
|
|
12
|
+
readonly writeOnly: readonly string[];
|
|
13
|
+
/** Lists whose order is the vendor's (a set): compared as multisets, in no order. */
|
|
14
|
+
readonly unordered?: readonly string[];
|
|
15
|
+
/**
|
|
16
|
+
* Fields that name another declared resource, by dotted path: the `<vendor>.<type>` it is, and
|
|
17
|
+
* how the vendor spells it (`by`): `{ repository_id: { type: "github.repository", by: ["name",
|
|
18
|
+
* "node_id"] } }`. A data file gives that resource there (`repository_id: site`), which stands
|
|
19
|
+
* for its `name`; anywhere else a resource is refused.
|
|
20
|
+
*/
|
|
21
|
+
readonly references?: References;
|
|
22
|
+
}
|
|
23
|
+
/** Where a field names another declared resource: see `ResourceFields.references`. */
|
|
24
|
+
export interface FieldReference {
|
|
25
|
+
/** The `<vendor>.<type>` of the resource it names. */
|
|
26
|
+
readonly type: string;
|
|
27
|
+
/**
|
|
28
|
+
* The fields of that resource's state the vendor may hold here instead of its `name`, such as
|
|
29
|
+
* GitHub's `node_id`: a drift check takes any of their values, read in the same run, as the
|
|
30
|
+
* declared one. Without it, the field holds the resource's `name`, and is compared as it is.
|
|
31
|
+
*/
|
|
32
|
+
readonly by?: readonly string[];
|
|
33
|
+
}
|
|
34
|
+
/** A resource type's `fields.references`: by dotted path, the resource each names. */
|
|
35
|
+
export type References = {
|
|
36
|
+
readonly [path: string]: FieldReference;
|
|
37
|
+
};
|
|
38
|
+
type State = Record<string, unknown>;
|
|
39
|
+
/** A resource type, as its connector declares it with `defineResource`. */
|
|
40
|
+
export interface ResourceSpec<S extends z.ZodObject = z.ZodObject> {
|
|
41
|
+
/** The connector's vendor id, such as `github`; `defineConnector` refuses a type of another vendor. */
|
|
42
|
+
vendor: string;
|
|
43
|
+
/** The type's name within the vendor, such as `repository`: its operations are `<vendor>.<type>.read` and `.import`. */
|
|
44
|
+
type: string;
|
|
45
|
+
/** What people call it, such as "Repository". */
|
|
46
|
+
title: string;
|
|
47
|
+
/**
|
|
48
|
+
* How `find` makes the import id, for people: `name`, `repository_id:pattern`. The fields it
|
|
49
|
+
* names stay declarable even when the vendor sets them. Absent with `find`: a type the vendor
|
|
50
|
+
* names alone (Stripe's) is found only by its binding.
|
|
51
|
+
*/
|
|
52
|
+
identity?: string;
|
|
53
|
+
/** The resource's fields as a read returns them; a data file declares them, less the vendor-owned ones. */
|
|
54
|
+
schema: S;
|
|
55
|
+
fields: ResourceFields;
|
|
56
|
+
/**
|
|
57
|
+
* The import id that finds a declared resource before it is bound, from its declared fields:
|
|
58
|
+
* its identity. Absent when its fields cannot name it.
|
|
59
|
+
*/
|
|
60
|
+
find?: (desired: z.input<S>) => string;
|
|
61
|
+
/**
|
|
62
|
+
* The id a binding keeps for an object, from its state: stable for the object's life (GitHub's
|
|
63
|
+
* `node_id`, not its name), and one `import` accepts. Default: `String(state.id)`.
|
|
64
|
+
*/
|
|
65
|
+
bindingId?: (state: State) => string;
|
|
66
|
+
/**
|
|
67
|
+
* The part of a state that a drift check compares, given what was declared. The check
|
|
68
|
+
* compares `normalize(actual, desired)` with `normalize(desired, desired)`. Default:
|
|
69
|
+
* `compareDeclared`, which keeps the declared fields only.
|
|
70
|
+
*/
|
|
71
|
+
normalize?: (state: State, desired: z.input<S>) => State;
|
|
72
|
+
/**
|
|
73
|
+
* True when apply may change its objects: the type then has the change operations `plan`,
|
|
74
|
+
* `create`, `update` and `delete` besides `read` and `import`. Default false.
|
|
75
|
+
*/
|
|
76
|
+
writable?: boolean;
|
|
77
|
+
/** Set when the type meets the `Host` contract: it runs the company. Such a type is `writable` and `stateless`. */
|
|
78
|
+
host?: HostSpec;
|
|
79
|
+
/**
|
|
80
|
+
* True when its objects hold no data, so one gone at the vendor is created again by apply
|
|
81
|
+
* without asking (a host running the company's code); otherwise apply asks first, as a
|
|
82
|
+
* recreated database looks fine and has lost its data. Default: true for a host, else false.
|
|
83
|
+
*/
|
|
84
|
+
stateless?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Operations apply calls, in order, right after it creates one of its objects and binds it: a
|
|
87
|
+
* Supabase project's health, until it is healthy, then its database URL stored.
|
|
88
|
+
*/
|
|
89
|
+
afterCreate?: readonly AfterCreate[];
|
|
90
|
+
}
|
|
91
|
+
/** One operation apply calls after a create (`ResourceSpec.afterCreate`). */
|
|
92
|
+
export interface AfterCreate {
|
|
93
|
+
/** The operation's id, among the config's: `supabase.database.storeUrl`. */
|
|
94
|
+
op: string;
|
|
95
|
+
/** Its input, from the new object's binding id and the data file's export that declares it. */
|
|
96
|
+
input: (made: {
|
|
97
|
+
id: string;
|
|
98
|
+
export: string;
|
|
99
|
+
}) => unknown;
|
|
100
|
+
/**
|
|
101
|
+
* Called again, every few seconds, until its output passes this, for up to 10 minutes; a call
|
|
102
|
+
* that fails meanwhile is one that did not pass, its output `undefined`.
|
|
103
|
+
*/
|
|
104
|
+
until?: (output: any) => boolean;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Where a declared resource keeps its brand, its type's `<vendor>.<type>`: a symbol, so a field
|
|
108
|
+
* holding a resource is told from data; a registered one (`Symbol.for`), so a copy of this
|
|
109
|
+
* package reads what another copy declared, as `VENDOR`.
|
|
110
|
+
*/
|
|
111
|
+
export declare const DECLARED: unique symbol;
|
|
112
|
+
/** A resource a data file declares: `github.repository({ name: "sanoma" })`. */
|
|
113
|
+
export interface Declared<Id extends string = string, T = State> {
|
|
114
|
+
readonly [DECLARED]: Id;
|
|
115
|
+
readonly vendor: string;
|
|
116
|
+
readonly type: string;
|
|
117
|
+
/** Its identity, the import id that finds it unbound: what `find` made of `desired`; absent without `find`. */
|
|
118
|
+
readonly name?: string;
|
|
119
|
+
/**
|
|
120
|
+
* Its fields, each resource it names replaced by that resource's `name`: what its type
|
|
121
|
+
* checked, and what a drift check compares.
|
|
122
|
+
*/
|
|
123
|
+
readonly desired: T;
|
|
124
|
+
/**
|
|
125
|
+
* Where it names another resource: the field's dotted path (a list item's with its index,
|
|
126
|
+
* `teams.0`) to that resource's `<vendor>.<type>:<name>`.
|
|
127
|
+
*/
|
|
128
|
+
readonly refs: Readonly<Record<string, string>>;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* What a resource type's constructor takes: its fields, where `R` (its `fields.references`)
|
|
132
|
+
* names a path, a declared resource of that type instead of a value (`repository_id: site`), and
|
|
133
|
+
* where a string goes, a secret (`secret("NAME")`), which the constructor allows at a write-only
|
|
134
|
+
* field only.
|
|
135
|
+
*/
|
|
136
|
+
export type Declaring<T, R extends References = {}> = [keyof R] extends [never] ? WithSecrets<T> : DeclaringAt<T, R, "">;
|
|
137
|
+
type WithSecrets<V> = V extends string ? V | Secret : V extends readonly (infer I)[] ? WithSecrets<I>[] : V extends object ? {
|
|
138
|
+
[K in keyof V]: WithSecrets<V[K]>;
|
|
139
|
+
} : V;
|
|
140
|
+
type DeclaringAt<T, R extends References, P extends string> = T extends readonly (infer I)[] ? DeclaringAt<I, R, P>[] : T extends object ? {
|
|
141
|
+
[K in keyof T]: K extends string ? DeclaringField<T[K], R, P extends "" ? K : `${P}.${K}`> : T[K];
|
|
142
|
+
} : WithSecrets<T>;
|
|
143
|
+
type DeclaringField<V, R extends References, P extends string> = P extends keyof R ? WithSecrets<V> | DeclaredOf<R[P]["type"]> : [Extract<keyof R, `${P}.${string}`>] extends [never] ? WithSecrets<V> : DeclaringAt<V, R, P>;
|
|
144
|
+
type DeclaredOf<Id> = Id extends string ? Declared<Id> : never;
|
|
145
|
+
/** What a plan of a change says will happen, as `PlanResponse.Action` names it. */
|
|
146
|
+
export declare const PLAN_ACTIONS: readonly ["none", "create", "update", "replace", "delete"];
|
|
147
|
+
export type PlanAction = (typeof PLAN_ACTIONS)[number];
|
|
148
|
+
/** The operations of a writable type that change its objects: only the apply workflow calls them (`isChangeOp`). */
|
|
149
|
+
export declare const CHANGE_OPS: readonly ["create", "update", "delete"];
|
|
150
|
+
declare const opsOf: <S extends z.ZodObject>(schema: S) => {
|
|
151
|
+
import: {
|
|
152
|
+
input: z.ZodObject<{
|
|
153
|
+
id: z.ZodString;
|
|
154
|
+
}, z.core.$strip>;
|
|
155
|
+
output: z.ZodObject<{
|
|
156
|
+
id: z.ZodString;
|
|
157
|
+
gone: z.ZodBoolean;
|
|
158
|
+
state: z.ZodOptional<S>;
|
|
159
|
+
handle: z.ZodOptional<z.ZodString>;
|
|
160
|
+
}, z.core.$strip>;
|
|
161
|
+
};
|
|
162
|
+
read: {
|
|
163
|
+
input: z.ZodObject<{
|
|
164
|
+
id: z.ZodString;
|
|
165
|
+
state: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
166
|
+
handle: z.ZodOptional<z.ZodString>;
|
|
167
|
+
}, z.core.$strip>;
|
|
168
|
+
output: z.ZodObject<{
|
|
169
|
+
id: z.ZodString;
|
|
170
|
+
gone: z.ZodBoolean;
|
|
171
|
+
state: z.ZodOptional<S>;
|
|
172
|
+
handle: z.ZodOptional<z.ZodString>;
|
|
173
|
+
}, z.core.$strip>;
|
|
174
|
+
};
|
|
175
|
+
plan: {
|
|
176
|
+
input: z.ZodObject<{
|
|
177
|
+
state: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
178
|
+
handle: z.ZodOptional<z.ZodString>;
|
|
179
|
+
id: z.ZodOptional<z.ZodString>;
|
|
180
|
+
desired: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
181
|
+
}, z.core.$strip>;
|
|
182
|
+
output: z.ZodObject<{
|
|
183
|
+
action: z.ZodEnum<{
|
|
184
|
+
create: "create";
|
|
185
|
+
delete: "delete";
|
|
186
|
+
none: "none";
|
|
187
|
+
replace: "replace";
|
|
188
|
+
update: "update";
|
|
189
|
+
}>;
|
|
190
|
+
planned: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
191
|
+
unknown: z.ZodArray<z.ZodString>;
|
|
192
|
+
replace: z.ZodArray<z.ZodString>;
|
|
193
|
+
}, z.core.$strip>;
|
|
194
|
+
};
|
|
195
|
+
create: {
|
|
196
|
+
input: z.ZodObject<{
|
|
197
|
+
desired: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
198
|
+
}, z.core.$strip>;
|
|
199
|
+
output: z.ZodObject<{
|
|
200
|
+
id: z.ZodString;
|
|
201
|
+
state: S;
|
|
202
|
+
handle: z.ZodOptional<z.ZodString>;
|
|
203
|
+
}, z.core.$strip>;
|
|
204
|
+
};
|
|
205
|
+
update: {
|
|
206
|
+
input: z.ZodObject<{
|
|
207
|
+
id: z.ZodString;
|
|
208
|
+
state: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
209
|
+
handle: z.ZodOptional<z.ZodString>;
|
|
210
|
+
desired: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
211
|
+
expect: z.ZodOptional<z.ZodObject<{
|
|
212
|
+
action: z.ZodEnum<{
|
|
213
|
+
create: "create";
|
|
214
|
+
delete: "delete";
|
|
215
|
+
none: "none";
|
|
216
|
+
replace: "replace";
|
|
217
|
+
update: "update";
|
|
218
|
+
}>;
|
|
219
|
+
replace: z.ZodArray<z.ZodString>;
|
|
220
|
+
}, z.core.$strip>>;
|
|
221
|
+
}, z.core.$strip>;
|
|
222
|
+
output: z.ZodObject<{
|
|
223
|
+
id: z.ZodString;
|
|
224
|
+
state: S;
|
|
225
|
+
handle: z.ZodOptional<z.ZodString>;
|
|
226
|
+
}, z.core.$strip>;
|
|
227
|
+
};
|
|
228
|
+
delete: {
|
|
229
|
+
input: z.ZodObject<{
|
|
230
|
+
id: z.ZodString;
|
|
231
|
+
state: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
232
|
+
handle: z.ZodOptional<z.ZodString>;
|
|
233
|
+
}, z.core.$strip>;
|
|
234
|
+
output: z.ZodObject<{
|
|
235
|
+
id: z.ZodString;
|
|
236
|
+
gone: z.ZodLiteral<true>;
|
|
237
|
+
}, z.core.$strip>;
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
type OpsOf<S extends z.ZodObject> = ReturnType<typeof opsOf<S>>;
|
|
241
|
+
type Specs<S extends z.ZodObject, N extends keyof OpsOf<S>> = {
|
|
242
|
+
[K in N]: OpSpec<OpsOf<S>[K]["input"], OpsOf<S>[K]["output"]>;
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* A resource type's operation specs: `read` and `import`, and for a writable type (`W`) the
|
|
246
|
+
* change operations `plan`, `create`, `update` and `delete`.
|
|
247
|
+
*/
|
|
248
|
+
export type ResourceOps<S extends z.ZodObject, W extends boolean = false> = Specs<S, "read" | "import"> & ([W] extends [true] ? Specs<S, "plan" | (typeof CHANGE_OPS)[number]> : {});
|
|
249
|
+
/**
|
|
250
|
+
* True for an operation that changes a writable type's objects (`CHANGE_OPS`), which only the
|
|
251
|
+
* apply workflow may call: by its vendor, resource and name, so a copy of a connector is told too.
|
|
252
|
+
*/
|
|
253
|
+
export declare function isChangeOp(op: {
|
|
254
|
+
readonly vendor: string;
|
|
255
|
+
readonly resource: string;
|
|
256
|
+
readonly name: string;
|
|
257
|
+
}, types: ReadonlyMap<string, Pick<Resource, "writable">>): boolean;
|
|
258
|
+
/**
|
|
259
|
+
* A resource type: call it to declare a resource in a data file, and give it to
|
|
260
|
+
* `defineConnector` as a group, under its `type`: `defineConnector("github", { repository })`.
|
|
261
|
+
*/
|
|
262
|
+
export interface Resource<S extends z.ZodObject = z.ZodObject, Id extends string = string, R extends References = {}, W extends boolean = boolean> extends Readonly<Required<Omit<ResourceSpec<S>, "identity" | "find" | "writable" | "host" | "stateless" | "afterCreate">>>, Readonly<Pick<ResourceSpec<S>, "identity" | "find" | "host" | "afterCreate">> {
|
|
263
|
+
(desired: Declaring<z.input<S>, R>): Declared<Id, z.input<S>>;
|
|
264
|
+
/** `read` and `import`, each effect `read`, idempotent, with the id as `target`; for a writable type, the change operations too. */
|
|
265
|
+
readonly ops: ResourceOps<S, W>;
|
|
266
|
+
/** True when apply may change its objects: it has the change operations. */
|
|
267
|
+
readonly writable: W;
|
|
268
|
+
/** True when apply may recreate or replace its objects as routine: they keep no data. */
|
|
269
|
+
readonly stateless: boolean;
|
|
270
|
+
readonly [RESOURCE]: true;
|
|
271
|
+
}
|
|
272
|
+
/** True for a plain object: not null, not a list. */
|
|
273
|
+
export declare const isObject: (v: unknown) => v is State;
|
|
274
|
+
/** `path.name`, or `name` at the top: a field's dotted path. */
|
|
275
|
+
export declare const joinPath: (path: string, name: string) => string;
|
|
276
|
+
/**
|
|
277
|
+
* The fields of `state` that `desired` declares, minus vendor-owned and write-only ones: only
|
|
278
|
+
* declared fields are compared, as CloudFormation does. An object is picked field by field, a
|
|
279
|
+
* list item by item against the declared item at its index, and an `unordered` list (a set)
|
|
280
|
+
* item by item against what its declared items declare, then sorted, so its order never
|
|
281
|
+
* drifts. Anything else is kept whole.
|
|
282
|
+
*
|
|
283
|
+
* So a field the data file leaves out is never drift, whatever the vendor holds. That covers
|
|
284
|
+
* attributes the provider marks `computed` and `optional`: they are the user's to set, not
|
|
285
|
+
* vendor-owned, but the vendor fills them when nobody does (GitHub's `etag`, `topics`,
|
|
286
|
+
* `visibility`), so they are compared only when declared.
|
|
287
|
+
*/
|
|
288
|
+
export declare function compareDeclared(fields: ResourceFields, state: State, desired: State): State;
|
|
289
|
+
/** A declared field the vendor holds another value in. */
|
|
290
|
+
export interface DriftField {
|
|
291
|
+
/** Its dotted path, a list item's with its index: `required_pull_request_reviews.0.dismiss_stale_reviews`. */
|
|
292
|
+
path: string;
|
|
293
|
+
/** What the data file declares. */
|
|
294
|
+
desired: unknown;
|
|
295
|
+
/** What the vendor holds, `null` for nothing. */
|
|
296
|
+
actual: unknown;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Where `state` differs from what `desired` declares: the type's `normalize` of each (by default
|
|
300
|
+
* `compareDeclared`: declared fields only, never vendor-owned or write-only ones, `unordered`
|
|
301
|
+
* lists as sets), then leaf by leaf: objects field by field, lists of one length item by item,
|
|
302
|
+
* and anything else (a list whose length changed, an `unordered` one) whole.
|
|
303
|
+
*
|
|
304
|
+
* `accept` is, by a reference's path as `refs` has it (`repository_id`, `teams.0`), the values
|
|
305
|
+
* the vendor may hold there for the resource it names (its `node_id`, say: see
|
|
306
|
+
* `FieldReference.by`): any of them counts as the declared value.
|
|
307
|
+
*/
|
|
308
|
+
export declare function diffDeclared(resource: {
|
|
309
|
+
readonly fields: ResourceFields;
|
|
310
|
+
readonly normalize: (state: State, desired: any) => State;
|
|
311
|
+
}, state: State, desired: State, accept?: Readonly<Record<string, readonly unknown[]>>): DriftField[];
|
|
312
|
+
/** The object or list holding the value at a dotted path (a list item's by its index), and its key there. */
|
|
313
|
+
export declare function holderOf(value: unknown, path: string): {
|
|
314
|
+
holder: State;
|
|
315
|
+
key: string;
|
|
316
|
+
} | undefined;
|
|
317
|
+
/** A field's dotted path as `fields` names it, without a list item's index: `teams.0` is `teams`. */
|
|
318
|
+
export declare const fieldPathOf: (at: string) => string;
|
|
319
|
+
/** The value at a dotted path, a list item's by its index. */
|
|
320
|
+
export declare const valueAt: (value: unknown, path: string) => unknown;
|
|
321
|
+
/**
|
|
322
|
+
* `desired` without the values at the fields the type marks write-only (a webhook's `secret`):
|
|
323
|
+
* what a run may record of a declaration. A list's items lose them too. A secret marker
|
|
324
|
+
* (`secret("NAME")`) stays, there or inside a write-only map (a host's `secrets`): it names a
|
|
325
|
+
* stored secret and holds none, and the driver resolves it.
|
|
326
|
+
*/
|
|
327
|
+
export declare function withoutWriteOnly(fields: ResourceFields, desired: State): State;
|
|
328
|
+
/**
|
|
329
|
+
* Declares a resource type: its schema, flagged fields, identity and how it is compared, and
|
|
330
|
+
* derives its operations, `<vendor>.<type>.read` and `<vendor>.<type>.import`, both effect
|
|
331
|
+
* `read` and idempotent, with the import id as the policy's `target`:
|
|
332
|
+
*
|
|
333
|
+
* - `import` takes `{ id }`, an identity (what `find` makes) or a binding id (what `bindingId`
|
|
334
|
+
* makes), and returns `{ gone: false, state }`, the object's
|
|
335
|
+
* state (with the driver's opaque `handle` when it keeps one), or `{ gone: true }` when the
|
|
336
|
+
* vendor has no such object.
|
|
337
|
+
* - `read` takes `{ id, state?, handle? }`, a state from an earlier `import` or `read`, and
|
|
338
|
+
* returns the same: `{ gone: true }` when the object no longer exists, else its fresh
|
|
339
|
+
* `state`. A driver may import first when it is given no state.
|
|
340
|
+
*
|
|
341
|
+
* A `writable` type has the change operations too, which only the apply workflow may call
|
|
342
|
+
* (`isChangeOp`): `create`, `update` and `delete` effect `write` (`delete` idempotent), and `plan`:
|
|
343
|
+
*
|
|
344
|
+
* - `plan` (`read`, idempotent) takes `{ id?, state?, handle?, desired? }`, no `desired` for a
|
|
345
|
+
* delete and no `id` for a create, and returns `{ action, planned?, unknown, replace }`:
|
|
346
|
+
* what apply would do, the new state without write-only fields, the paths known only after
|
|
347
|
+
* apply, and those whose change replaces the object.
|
|
348
|
+
* - `create` (`target` `new:<vendor>.<type>`) takes `{ desired }` and returns `{ id, state,
|
|
349
|
+
* handle? }`, `id` its binding id.
|
|
350
|
+
* - `update` takes `{ id, state?, handle?, desired, expect? }` and returns the same; given
|
|
351
|
+
* `expect` (a plan's `action` and `replace`), it refuses a fresh plan that differs
|
|
352
|
+
* (`DriverError`, `vendorCode` `plan_changed`).
|
|
353
|
+
* - `delete` takes `{ id, state?, handle? }` and returns `{ id, gone: true }`.
|
|
354
|
+
*
|
|
355
|
+
* `desired` may hold secret markers at write-only fields, which the driver resolves; no output
|
|
356
|
+
* holds a write-only value.
|
|
357
|
+
*
|
|
358
|
+
* The ledger records a `handle` as `"<handle>"`, never its bytes (the operations' `opaque`).
|
|
359
|
+
*
|
|
360
|
+
* Calling the result declares one resource, for a data file: `repository({ name: "sanoma" })`
|
|
361
|
+
* is a `Declared`, `{ vendor, type, name: "sanoma", desired, refs: {} }`. It refuses fields the
|
|
362
|
+
* schema does not have, fields the vendor owns (unless the identity names them), values the
|
|
363
|
+
* schema rejects, and an empty identity. Where `fields.references` allows it, a field may name
|
|
364
|
+
* another declared resource of that type (`repository_id: site`): `desired` holds, and the
|
|
365
|
+
* schema and `find` read, that resource's `name`, and `refs` says where it was named. A type
|
|
366
|
+
* without `find` declares resources without a `name`, found only by their bindings.
|
|
367
|
+
*/
|
|
368
|
+
export declare function defineResource<S extends z.ZodObject, const V extends string, const T extends string, const R extends References = {}, const W extends boolean = false>(spec: ResourceSpec<S> & {
|
|
369
|
+
vendor: V;
|
|
370
|
+
type: T;
|
|
371
|
+
fields: {
|
|
372
|
+
references?: R;
|
|
373
|
+
};
|
|
374
|
+
writable?: W;
|
|
375
|
+
}): Resource<S, `${V}.${T}`, R, W>;
|
|
376
|
+
/** Every resource type the connectors declare, by `<vendor>.<type>`. */
|
|
377
|
+
export declare function resourceTypesOf(connectors: readonly Connector<any, any>[]): Map<string, Resource>;
|
|
378
|
+
export {};
|