@sanoma-ai/workflows 0.1.0 → 0.4.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.
Files changed (184) hide show
  1. package/README.md +186 -76
  2. package/dist/apply-steps.d.ts +6 -0
  3. package/dist/apply-steps.js +93 -0
  4. package/dist/apply-steps.js.map +1 -0
  5. package/dist/apply.d.ts +197 -0
  6. package/dist/apply.js +470 -0
  7. package/dist/apply.js.map +1 -0
  8. package/dist/approvals.d.ts +11 -6
  9. package/dist/approvals.js +38 -10
  10. package/dist/approvals.js.map +1 -1
  11. package/dist/call-workflow.d.ts +16 -0
  12. package/dist/call-workflow.js +35 -0
  13. package/dist/call-workflow.js.map +1 -0
  14. package/dist/call.d.ts +35 -2
  15. package/dist/call.js +123 -43
  16. package/dist/call.js.map +1 -1
  17. package/dist/cedar.d.ts +87 -0
  18. package/dist/cedar.js +365 -0
  19. package/dist/cedar.js.map +1 -0
  20. package/dist/client.d.ts +123 -9
  21. package/dist/client.js +355 -34
  22. package/dist/client.js.map +1 -1
  23. package/dist/collection.d.ts +107 -0
  24. package/dist/collection.js +306 -0
  25. package/dist/collection.js.map +1 -0
  26. package/dist/config.d.ts +42 -14
  27. package/dist/config.js +109 -28
  28. package/dist/config.js.map +1 -1
  29. package/dist/constructors.d.ts +2 -0
  30. package/dist/constructors.js +5 -0
  31. package/dist/constructors.js.map +1 -0
  32. package/dist/credentials.d.ts +25 -0
  33. package/dist/credentials.js +73 -5
  34. package/dist/credentials.js.map +1 -1
  35. package/dist/data.d.ts +2 -0
  36. package/dist/data.js +3 -0
  37. package/dist/data.js.map +1 -0
  38. package/dist/datafile.d.ts +38 -3
  39. package/dist/datafile.js +166 -13
  40. package/dist/datafile.js.map +1 -1
  41. package/dist/db.d.ts +5 -3
  42. package/dist/db.js +88 -21
  43. package/dist/db.js.map +1 -1
  44. package/dist/define.d.ts +10 -4
  45. package/dist/define.js +1 -5
  46. package/dist/define.js.map +1 -1
  47. package/dist/describe.d.ts +54 -8
  48. package/dist/describe.js +84 -11
  49. package/dist/describe.js.map +1 -1
  50. package/dist/direct.d.ts +9 -0
  51. package/dist/direct.js +11 -0
  52. package/dist/direct.js.map +1 -0
  53. package/dist/drift.d.ts +64 -12
  54. package/dist/drift.js +118 -41
  55. package/dist/drift.js.map +1 -1
  56. package/dist/errors.d.ts +16 -1
  57. package/dist/errors.js +30 -1
  58. package/dist/errors.js.map +1 -1
  59. package/dist/expectations.d.ts +4 -4
  60. package/dist/expectations.js +43 -9
  61. package/dist/expectations.js.map +1 -1
  62. package/dist/host.d.ts +56 -0
  63. package/dist/host.js +45 -0
  64. package/dist/host.js.map +1 -0
  65. package/dist/index.d.ts +13 -5
  66. package/dist/index.js +15 -5
  67. package/dist/index.js.map +1 -1
  68. package/dist/ledger.d.ts +12 -1
  69. package/dist/ledger.js +18 -11
  70. package/dist/ledger.js.map +1 -1
  71. package/dist/lint.d.ts +5 -4
  72. package/dist/lint.js +24 -7
  73. package/dist/lint.js.map +1 -1
  74. package/dist/lockfile.d.ts +36 -0
  75. package/dist/lockfile.js +69 -0
  76. package/dist/lockfile.js.map +1 -0
  77. package/dist/op.d.ts +9 -0
  78. package/dist/op.js.map +1 -1
  79. package/dist/outline.d.ts +2 -0
  80. package/dist/outline.js +1 -1
  81. package/dist/outline.js.map +1 -1
  82. package/dist/paths.d.ts +4 -0
  83. package/dist/paths.js +17 -3
  84. package/dist/paths.js.map +1 -1
  85. package/dist/person.d.ts +61 -0
  86. package/dist/person.js +69 -0
  87. package/dist/person.js.map +1 -0
  88. package/dist/plugin.js +1 -1
  89. package/dist/plugin.js.map +1 -1
  90. package/dist/policy.d.ts +51 -55
  91. package/dist/policy.js +14 -36
  92. package/dist/policy.js.map +1 -1
  93. package/dist/resource.d.ts +207 -25
  94. package/dist/resource.js +184 -30
  95. package/dist/resource.js.map +1 -1
  96. package/dist/resources.d.ts +76 -9
  97. package/dist/resources.js +170 -30
  98. package/dist/resources.js.map +1 -1
  99. package/dist/run.d.ts +31 -1
  100. package/dist/run.js +6 -1
  101. package/dist/run.js.map +1 -1
  102. package/dist/sandbox.js +5 -1
  103. package/dist/sandbox.js.map +1 -1
  104. package/dist/scenario.d.ts +25 -9
  105. package/dist/scenario.js +125 -27
  106. package/dist/scenario.js.map +1 -1
  107. package/dist/scenarios.d.ts +10 -6
  108. package/dist/scenarios.js +8 -4
  109. package/dist/scenarios.js.map +1 -1
  110. package/dist/schema.d.ts +32 -0
  111. package/dist/schema.js +225 -0
  112. package/dist/schema.js.map +1 -0
  113. package/dist/sdk.d.ts +34 -0
  114. package/dist/sdk.js +168 -0
  115. package/dist/sdk.js.map +1 -0
  116. package/dist/secret.d.ts +42 -0
  117. package/dist/secret.js +58 -0
  118. package/dist/secret.js.map +1 -0
  119. package/dist/shared.d.ts +188 -4
  120. package/dist/shared.js +165 -5
  121. package/dist/shared.js.map +1 -1
  122. package/dist/sites.d.ts +52 -0
  123. package/dist/sites.js +174 -0
  124. package/dist/sites.js.map +1 -0
  125. package/dist/source.d.ts +58 -0
  126. package/dist/source.js +54 -0
  127. package/dist/source.js.map +1 -0
  128. package/dist/version.d.ts +3 -2
  129. package/dist/version.js +3 -2
  130. package/dist/version.js.map +1 -1
  131. package/dist/worker.d.ts +6 -2
  132. package/dist/worker.js +37 -8
  133. package/dist/worker.js.map +1 -1
  134. package/dist/writer.d.ts +35 -0
  135. package/dist/writer.js +201 -0
  136. package/dist/writer.js.map +1 -0
  137. package/oxlint.json +5 -16
  138. package/package.json +11 -1
  139. package/src/apply-steps.ts +110 -0
  140. package/src/apply.ts +626 -0
  141. package/src/approvals.ts +49 -13
  142. package/src/call-workflow.ts +44 -0
  143. package/src/call.ts +173 -46
  144. package/src/cedar.ts +493 -0
  145. package/src/client.ts +450 -49
  146. package/src/collection.ts +431 -0
  147. package/src/config.ts +168 -48
  148. package/src/constructors.ts +4 -0
  149. package/src/credentials.ts +90 -5
  150. package/src/data.ts +10 -0
  151. package/src/datafile.ts +207 -15
  152. package/src/db.ts +90 -22
  153. package/src/define.ts +11 -9
  154. package/src/describe.ts +146 -23
  155. package/src/direct.ts +15 -0
  156. package/src/drift.ts +155 -45
  157. package/src/errors.ts +36 -1
  158. package/src/expectations.ts +46 -11
  159. package/src/host.ts +96 -0
  160. package/src/index.ts +56 -2
  161. package/src/ledger.ts +35 -17
  162. package/src/lint.ts +29 -12
  163. package/src/lockfile.ts +95 -0
  164. package/src/op.ts +9 -0
  165. package/src/outline.ts +1 -1
  166. package/src/paths.ts +18 -3
  167. package/src/person.ts +75 -0
  168. package/src/plugin.ts +1 -1
  169. package/src/policy.ts +59 -63
  170. package/src/resource.ts +302 -52
  171. package/src/resources.ts +226 -30
  172. package/src/run.ts +33 -1
  173. package/src/sandbox.ts +5 -1
  174. package/src/scenario.ts +175 -43
  175. package/src/scenarios.ts +15 -8
  176. package/src/schema.ts +261 -0
  177. package/src/sdk.ts +211 -0
  178. package/src/secret.ts +92 -0
  179. package/src/shared.ts +279 -6
  180. package/src/sites.ts +220 -0
  181. package/src/source.ts +82 -0
  182. package/src/version.ts +3 -2
  183. package/src/worker.ts +45 -11
  184. package/src/writer.ts +225 -0
@@ -1,5 +1,7 @@
1
1
  import { z } from "zod";
2
+ import { type HostSpec } from "./host.ts";
2
3
  import { type Connector, type OpSpec, RESOURCE } from "./op.ts";
4
+ import { type Secret } from "./secret.ts";
3
5
  /** Which fields of a resource are flagged, by dotted path (`pages.html_url`; a list's items have no index). */
4
6
  export interface ResourceFields {
5
7
  /** Changing it replaces the object. */
@@ -20,8 +22,8 @@ export interface ResourceFields {
20
22
  }
21
23
  /** Where a field names another declared resource: see `ResourceFields.references`. */
22
24
  export interface FieldReference {
23
- /** The `<vendor>.<type>` of the resource it names. */
24
- readonly type: string;
25
+ /** The `<vendor>.<type>` of the resource it names, or the types it may name one of. */
26
+ readonly type: string | readonly string[];
25
27
  /**
26
28
  * The fields of that resource's state the vendor may hold here instead of its `name`, such as
27
29
  * GitHub's `node_id`: a drift check takes any of their values, read in the same run, as the
@@ -44,20 +46,68 @@ export interface ResourceSpec<S extends z.ZodObject = z.ZodObject> {
44
46
  title: string;
45
47
  /**
46
48
  * How `find` makes the import id, for people: `name`, `repository_id:pattern`. The fields it
47
- * names stay declarable even when the vendor sets them (Stripe's `id`).
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.
48
51
  */
49
- identity: string;
52
+ identity?: string;
50
53
  /** The resource's fields as a read returns them; a data file declares them, less the vendor-owned ones. */
51
54
  schema: S;
52
55
  fields: ResourceFields;
53
- /** The vendor's id for a declared resource (the import id), from its declared fields. */
54
- find: (desired: z.input<S>) => string;
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;
55
66
  /**
56
67
  * The part of a state that a drift check compares, given what was declared. The check
57
68
  * compares `normalize(actual, desired)` with `normalize(desired, desired)`. Default:
58
69
  * `compareDeclared`, which keeps the declared fields only.
59
70
  */
60
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
+ * True when there is no vendor object behind a declaration: the repo is all there is of it (the
87
+ * runtime's people, `sanoma.person`). Such a type has no operations, so no driver, and drift and
88
+ * apply pass its resources by. Default false.
89
+ */
90
+ vendorless?: boolean;
91
+ /**
92
+ * Operations apply calls, in order, right after it creates one of its objects and binds it: a
93
+ * Supabase project's health, until it is healthy, then its database URL stored.
94
+ */
95
+ afterCreate?: readonly AfterCreate[];
96
+ }
97
+ /** One operation apply calls after a create (`ResourceSpec.afterCreate`). */
98
+ export interface AfterCreate {
99
+ /** The operation's id, among the config's: `supabase.database.storeUrl`. */
100
+ op: string;
101
+ /** Its input, from the new object's binding id and the data file's export that declares it. */
102
+ input: (made: {
103
+ id: string;
104
+ export: string;
105
+ }) => unknown;
106
+ /**
107
+ * Called again, every few seconds, until its output passes this, for up to 10 minutes; a call
108
+ * that fails meanwhile is one that did not pass, its output `undefined`.
109
+ */
110
+ until?: (output: any) => boolean;
61
111
  }
62
112
  /**
63
113
  * Where a declared resource keeps its brand, its type's `<vendor>.<type>`: a symbol, so a field
@@ -70,8 +120,8 @@ export interface Declared<Id extends string = string, T = State> {
70
120
  readonly [DECLARED]: Id;
71
121
  readonly vendor: string;
72
122
  readonly type: string;
73
- /** The vendor's id for it: what `find` made of `desired`. */
74
- readonly name: string;
123
+ /** Its identity, the import id that finds it unbound: what `find` made of `desired`; absent without `find`. */
124
+ readonly name?: string;
75
125
  /**
76
126
  * Its fields, each resource it names replaced by that resource's `name`: what its type
77
127
  * checked, and what a drift check compares.
@@ -85,14 +135,24 @@ export interface Declared<Id extends string = string, T = State> {
85
135
  }
86
136
  /**
87
137
  * What a resource type's constructor takes: its fields, where `R` (its `fields.references`)
88
- * names a path, a declared resource of that type instead of a value (`repository_id: site`).
138
+ * names a path, a declared resource of that type instead of a value (`repository_id: site`), and
139
+ * where a string goes, a secret (`secret("NAME")`), which the constructor allows at a write-only
140
+ * field only.
89
141
  */
90
- export type Declaring<T, R extends References = {}> = [keyof R] extends [never] ? T : DeclaringAt<T, R, "">;
142
+ export type Declaring<T, R extends References = {}> = [keyof R] extends [never] ? WithSecrets<T> : DeclaringAt<T, R, "">;
143
+ type WithSecrets<V> = V extends string ? V | Secret : V extends readonly (infer I)[] ? WithSecrets<I>[] : V extends object ? {
144
+ [K in keyof V]: WithSecrets<V[K]>;
145
+ } : V;
91
146
  type DeclaringAt<T, R extends References, P extends string> = T extends readonly (infer I)[] ? DeclaringAt<I, R, P>[] : T extends object ? {
92
147
  [K in keyof T]: K extends string ? DeclaringField<T[K], R, P extends "" ? K : `${P}.${K}`> : T[K];
93
- } : T;
94
- type DeclaringField<V, R extends References, P extends string> = P extends keyof R ? V | DeclaredOf<R[P]["type"]> : [Extract<keyof R, `${P}.${string}`>] extends [never] ? V : DeclaringAt<V, R, P>;
95
- type DeclaredOf<Id> = Id extends string ? Declared<Id> : never;
148
+ } : WithSecrets<T>;
149
+ type DeclaringField<V, R extends References, P extends string> = P extends keyof R ? V extends readonly (infer I)[] ? (WithSecrets<I> | DeclaredOf<R[P]["type"]>)[] : WithSecrets<V> | DeclaredOf<R[P]["type"]> : [Extract<keyof R, `${P}.${string}`>] extends [never] ? WithSecrets<V> : DeclaringAt<V, R, P>;
150
+ type DeclaredOf<Id> = Id extends string ? Declared<Id> : Id extends readonly (infer E)[] ? DeclaredOf<E> : never;
151
+ /** What a plan of a change says will happen, as `PlanResponse.Action` names it. */
152
+ export declare const PLAN_ACTIONS: readonly ["none", "create", "update", "replace", "delete"];
153
+ export type PlanAction = (typeof PLAN_ACTIONS)[number];
154
+ /** The operations of a writable type that change its objects: only the apply workflow calls them (`isChangeOp`). */
155
+ export declare const CHANGE_OPS: readonly ["create", "update", "delete"];
96
156
  declare const opsOf: <S extends z.ZodObject>(schema: S) => {
97
157
  import: {
98
158
  input: z.ZodObject<{
@@ -118,20 +178,111 @@ declare const opsOf: <S extends z.ZodObject>(schema: S) => {
118
178
  handle: z.ZodOptional<z.ZodString>;
119
179
  }, z.core.$strip>;
120
180
  };
181
+ plan: {
182
+ input: z.ZodObject<{
183
+ state: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
184
+ handle: z.ZodOptional<z.ZodString>;
185
+ id: z.ZodOptional<z.ZodString>;
186
+ desired: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
187
+ }, z.core.$strip>;
188
+ output: z.ZodObject<{
189
+ action: z.ZodEnum<{
190
+ create: "create";
191
+ delete: "delete";
192
+ none: "none";
193
+ replace: "replace";
194
+ update: "update";
195
+ }>;
196
+ planned: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
197
+ unknown: z.ZodArray<z.ZodString>;
198
+ replace: z.ZodArray<z.ZodString>;
199
+ }, z.core.$strip>;
200
+ };
201
+ create: {
202
+ input: z.ZodObject<{
203
+ desired: z.ZodRecord<z.ZodString, z.ZodUnknown>;
204
+ }, z.core.$strip>;
205
+ output: z.ZodObject<{
206
+ id: z.ZodString;
207
+ state: S;
208
+ handle: z.ZodOptional<z.ZodString>;
209
+ }, z.core.$strip>;
210
+ };
211
+ update: {
212
+ input: z.ZodObject<{
213
+ id: z.ZodString;
214
+ state: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
215
+ handle: z.ZodOptional<z.ZodString>;
216
+ desired: z.ZodRecord<z.ZodString, z.ZodUnknown>;
217
+ expect: z.ZodOptional<z.ZodObject<{
218
+ action: z.ZodEnum<{
219
+ create: "create";
220
+ delete: "delete";
221
+ none: "none";
222
+ replace: "replace";
223
+ update: "update";
224
+ }>;
225
+ replace: z.ZodArray<z.ZodString>;
226
+ }, z.core.$strip>>;
227
+ }, z.core.$strip>;
228
+ output: z.ZodObject<{
229
+ id: z.ZodString;
230
+ state: S;
231
+ handle: z.ZodOptional<z.ZodString>;
232
+ }, z.core.$strip>;
233
+ };
234
+ delete: {
235
+ input: z.ZodObject<{
236
+ id: z.ZodString;
237
+ state: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
238
+ handle: z.ZodOptional<z.ZodString>;
239
+ }, z.core.$strip>;
240
+ output: z.ZodObject<{
241
+ id: z.ZodString;
242
+ gone: z.ZodLiteral<true>;
243
+ }, z.core.$strip>;
244
+ };
121
245
  };
122
246
  type OpsOf<S extends z.ZodObject> = ReturnType<typeof opsOf<S>>;
123
- /** A resource type's operation specs: `read` and `import`. */
124
- export type ResourceOps<S extends z.ZodObject> = {
125
- [N in keyof OpsOf<S>]: OpSpec<OpsOf<S>[N]["input"], OpsOf<S>[N]["output"]>;
247
+ type Specs<S extends z.ZodObject, N extends keyof OpsOf<S>> = {
248
+ [K in N]: OpSpec<OpsOf<S>[K]["input"], OpsOf<S>[K]["output"]>;
126
249
  };
250
+ /**
251
+ * A resource type's operation specs: `read` and `import`, and for a writable type (`W`) the
252
+ * change operations `plan`, `create`, `update` and `delete`.
253
+ */
254
+ 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]> : {});
255
+ /**
256
+ * True for an operation that changes a writable type's objects (`CHANGE_OPS`), which only the
257
+ * apply workflow may call: by its vendor, resource and name, so a copy of a connector is told too.
258
+ */
259
+ export declare function isChangeOp(op: {
260
+ readonly vendor: string;
261
+ readonly resource: string;
262
+ readonly name: string;
263
+ }, types: ReadonlyMap<string, Pick<Resource, "writable">>): boolean;
264
+ /**
265
+ * True for an operation of a declared resource type (`read`, `import`, and a writable type's
266
+ * `plan` and change operations), which only drift and apply call: by its vendor and resource.
267
+ */
268
+ export declare const isResourceOp: (op: {
269
+ readonly vendor: string;
270
+ readonly resource: string;
271
+ }, types: ReadonlyMap<string, unknown>) => boolean;
127
272
  /**
128
273
  * A resource type: call it to declare a resource in a data file, and give it to
129
274
  * `defineConnector` as a group, under its `type`: `defineConnector("github", { repository })`.
130
275
  */
131
- export interface Resource<S extends z.ZodObject = z.ZodObject, Id extends string = string, R extends References = {}> extends Readonly<Required<ResourceSpec<S>>> {
276
+ 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" | "vendorless">>>, Readonly<Pick<ResourceSpec<S>, "identity" | "find" | "host" | "afterCreate">> {
132
277
  (desired: Declaring<z.input<S>, R>): Declared<Id, z.input<S>>;
133
- /** `read` and `import`, each effect `read`, idempotent, with the import id as `target`. */
134
- readonly ops: ResourceOps<S>;
278
+ /** `read` and `import`, each effect `read`, idempotent, with the id as `target`; for a writable type, the change operations too. */
279
+ readonly ops: ResourceOps<S, W>;
280
+ /** True when apply may change its objects: it has the change operations. */
281
+ readonly writable: W;
282
+ /** True when apply may recreate or replace its objects as routine: they keep no data. */
283
+ readonly stateless: boolean;
284
+ /** True when there is no vendor object behind it (`ResourceSpec.vendorless`): it has no operations. */
285
+ readonly vendorless: boolean;
135
286
  readonly [RESOURCE]: true;
136
287
  }
137
288
  /** True for a plain object: not null, not a list. */
@@ -174,9 +325,20 @@ export declare function diffDeclared(resource: {
174
325
  readonly fields: ResourceFields;
175
326
  readonly normalize: (state: State, desired: any) => State;
176
327
  }, state: State, desired: State, accept?: Readonly<Record<string, readonly unknown[]>>): DriftField[];
328
+ /** The object or list holding the value at a dotted path (a list item's by its index), and its key there. */
329
+ export declare function holderOf(value: unknown, path: string): {
330
+ holder: State;
331
+ key: string;
332
+ } | undefined;
333
+ /** A field's dotted path as `fields` names it, without a list item's index: `teams.0` is `teams`. */
334
+ export declare const fieldPathOf: (at: string) => string;
335
+ /** The value at a dotted path, a list item's by its index. */
336
+ export declare const valueAt: (value: unknown, path: string) => unknown;
177
337
  /**
178
- * `desired` without the fields the type marks write-only (a webhook's `secret`): what a run may
179
- * record of a declaration. A list's items lose them too.
338
+ * `desired` without the values at the fields the type marks write-only (a webhook's `secret`):
339
+ * what a run may record of a declaration. A list's items lose them too. A secret marker
340
+ * (`secret("NAME")`) stays, there or inside a write-only map (a host's `secrets`): it names a
341
+ * stored secret and holds none, and the driver resolves it.
180
342
  */
181
343
  export declare function withoutWriteOnly(fields: ResourceFields, desired: State): State;
182
344
  /**
@@ -184,13 +346,31 @@ export declare function withoutWriteOnly(fields: ResourceFields, desired: State)
184
346
  * derives its operations, `<vendor>.<type>.read` and `<vendor>.<type>.import`, both effect
185
347
  * `read` and idempotent, with the import id as the policy's `target`:
186
348
  *
187
- * - `import` takes `{ id }`, the import id, and returns `{ gone: false, state }`, the object's
349
+ * - `import` takes `{ id }`, an identity (what `find` makes) or a binding id (what `bindingId`
350
+ * makes), and returns `{ gone: false, state }`, the object's
188
351
  * state (with the driver's opaque `handle` when it keeps one), or `{ gone: true }` when the
189
352
  * vendor has no such object.
190
353
  * - `read` takes `{ id, state?, handle? }`, a state from an earlier `import` or `read`, and
191
354
  * returns the same: `{ gone: true }` when the object no longer exists, else its fresh
192
355
  * `state`. A driver may import first when it is given no state.
193
356
  *
357
+ * A `writable` type has the change operations too, which only the apply workflow may call
358
+ * (`isChangeOp`): `create`, `update` and `delete` effect `write` (`delete` idempotent), and `plan`:
359
+ *
360
+ * - `plan` (`read`, idempotent) takes `{ id?, state?, handle?, desired? }`, no `desired` for a
361
+ * delete and no `id` for a create, and returns `{ action, planned?, unknown, replace }`:
362
+ * what apply would do, the new state without write-only fields, the paths known only after
363
+ * apply, and those whose change replaces the object.
364
+ * - `create` (`target` `new:<vendor>.<type>`) takes `{ desired }` and returns `{ id, state,
365
+ * handle? }`, `id` its binding id.
366
+ * - `update` takes `{ id, state?, handle?, desired, expect? }` and returns the same; given
367
+ * `expect` (a plan's `action` and `replace`), it refuses a fresh plan that differs
368
+ * (`DriverError`, `vendorCode` `plan_changed`).
369
+ * - `delete` takes `{ id, state?, handle? }` and returns `{ id, gone: true }`.
370
+ *
371
+ * `desired` may hold secret markers at write-only fields, which the driver resolves; no output
372
+ * holds a write-only value.
373
+ *
194
374
  * The ledger records a `handle` as `"<handle>"`, never its bytes (the operations' `opaque`).
195
375
  *
196
376
  * Calling the result declares one resource, for a data file: `repository({ name: "sanoma" })`
@@ -198,15 +378,17 @@ export declare function withoutWriteOnly(fields: ResourceFields, desired: State)
198
378
  * schema does not have, fields the vendor owns (unless the identity names them), values the
199
379
  * schema rejects, and an empty identity. Where `fields.references` allows it, a field may name
200
380
  * another declared resource of that type (`repository_id: site`): `desired` holds, and the
201
- * schema and `find` read, that resource's `name`, and `refs` says where it was named.
381
+ * schema and `find` read, that resource's `name`, and `refs` says where it was named. A type
382
+ * without `find` declares resources without a `name`, found only by their bindings.
202
383
  */
203
- export declare function defineResource<S extends z.ZodObject, const V extends string, const T extends string, const R extends References = {}>(spec: ResourceSpec<S> & {
384
+ 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> & {
204
385
  vendor: V;
205
386
  type: T;
206
387
  fields: {
207
388
  references?: R;
208
389
  };
209
- }): Resource<S, `${V}.${T}`, R>;
390
+ writable?: W;
391
+ }): Resource<S, `${V}.${T}`, R, W>;
210
392
  /** Every resource type the connectors declare, by `<vendor>.<type>`. */
211
393
  export declare function resourceTypesOf(connectors: readonly Connector<any, any>[]): Map<string, Resource>;
212
394
  export {};