@sanoma-ai/workflows 0.9.1 → 0.10.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 (190) hide show
  1. package/README.md +167 -50
  2. package/dist/apply-steps.js +5 -2
  3. package/dist/apply-steps.js.map +1 -1
  4. package/dist/apply.d.ts +3 -0
  5. package/dist/apply.js +27 -13
  6. package/dist/apply.js.map +1 -1
  7. package/dist/approvals.d.ts +1 -0
  8. package/dist/approvals.js +6 -1
  9. package/dist/approvals.js.map +1 -1
  10. package/dist/apps.d.ts +7 -24
  11. package/dist/apps.js +51 -67
  12. package/dist/apps.js.map +1 -1
  13. package/dist/ast.d.ts +9 -7
  14. package/dist/ast.js +2 -0
  15. package/dist/ast.js.map +1 -1
  16. package/dist/authentication.d.ts +24 -0
  17. package/dist/authentication.js +68 -0
  18. package/dist/authentication.js.map +1 -0
  19. package/dist/call-workflow.d.ts +5 -0
  20. package/dist/call-workflow.js +4 -3
  21. package/dist/call-workflow.js.map +1 -1
  22. package/dist/call.d.ts +3 -2
  23. package/dist/call.js +34 -7
  24. package/dist/call.js.map +1 -1
  25. package/dist/cedar.js +14 -1
  26. package/dist/cedar.js.map +1 -1
  27. package/dist/change-steps.js +7 -5
  28. package/dist/change-steps.js.map +1 -1
  29. package/dist/change.d.ts +7 -0
  30. package/dist/change.js +7 -0
  31. package/dist/change.js.map +1 -1
  32. package/dist/client.d.ts +10 -6
  33. package/dist/client.js +96 -43
  34. package/dist/client.js.map +1 -1
  35. package/dist/collection.d.ts +7 -0
  36. package/dist/collection.js +5 -2
  37. package/dist/collection.js.map +1 -1
  38. package/dist/config.d.ts +9 -0
  39. package/dist/config.js +45 -9
  40. package/dist/config.js.map +1 -1
  41. package/dist/connection.d.ts +168 -0
  42. package/dist/connection.js +327 -0
  43. package/dist/connection.js.map +1 -0
  44. package/dist/credentials.d.ts +7 -53
  45. package/dist/credentials.js +84 -247
  46. package/dist/credentials.js.map +1 -1
  47. package/dist/db.js +21 -2
  48. package/dist/db.js.map +1 -1
  49. package/dist/define.d.ts +9 -2
  50. package/dist/define.js.map +1 -1
  51. package/dist/definitions.d.ts +20 -0
  52. package/dist/definitions.js +16 -0
  53. package/dist/definitions.js.map +1 -0
  54. package/dist/deployment-key.d.ts +2 -0
  55. package/dist/deployment-key.js +22 -0
  56. package/dist/deployment-key.js.map +1 -0
  57. package/dist/describe.d.ts +9 -177
  58. package/dist/describe.js +71 -34
  59. package/dist/describe.js.map +1 -1
  60. package/dist/description.d.ts +532 -0
  61. package/dist/description.js +381 -0
  62. package/dist/description.js.map +1 -0
  63. package/dist/direct.js +3 -0
  64. package/dist/direct.js.map +1 -1
  65. package/dist/drift.d.ts +1 -1
  66. package/dist/drift.js +1 -1
  67. package/dist/drift.js.map +1 -1
  68. package/dist/env.d.ts +2 -0
  69. package/dist/env.js +2 -2
  70. package/dist/env.js.map +1 -1
  71. package/dist/index.d.ts +10 -2
  72. package/dist/index.js +10 -2
  73. package/dist/index.js.map +1 -1
  74. package/dist/ledger.d.ts +2 -0
  75. package/dist/ledger.js +1 -1
  76. package/dist/ledger.js.map +1 -1
  77. package/dist/lint.d.ts +0 -9
  78. package/dist/lint.js +1 -16
  79. package/dist/lint.js.map +1 -1
  80. package/dist/load.d.ts +74 -0
  81. package/dist/load.js +357 -0
  82. package/dist/load.js.map +1 -0
  83. package/dist/lockfile.d.ts +2 -0
  84. package/dist/lockfile.js +8 -3
  85. package/dist/lockfile.js.map +1 -1
  86. package/dist/op.d.ts +10 -1
  87. package/dist/op.js +1 -1
  88. package/dist/op.js.map +1 -1
  89. package/dist/outline.js +13 -4
  90. package/dist/outline.js.map +1 -1
  91. package/dist/paths.d.ts +18 -0
  92. package/dist/paths.js +21 -3
  93. package/dist/paths.js.map +1 -1
  94. package/dist/plugin.d.ts +0 -11
  95. package/dist/plugin.js +3 -18
  96. package/dist/plugin.js.map +1 -1
  97. package/dist/policy.d.ts +2 -0
  98. package/dist/policy.js.map +1 -1
  99. package/dist/resource.d.ts +10 -4
  100. package/dist/resource.js +11 -4
  101. package/dist/resource.js.map +1 -1
  102. package/dist/resources.d.ts +33 -76
  103. package/dist/resources.js +219 -227
  104. package/dist/resources.js.map +1 -1
  105. package/dist/run.d.ts +2 -0
  106. package/dist/run.js.map +1 -1
  107. package/dist/sandbox.d.ts +1 -1
  108. package/dist/sandbox.js +5 -2
  109. package/dist/sandbox.js.map +1 -1
  110. package/dist/scenarios.js +7 -1
  111. package/dist/scenarios.js.map +1 -1
  112. package/dist/schema.js +8 -0
  113. package/dist/schema.js.map +1 -1
  114. package/dist/secret-store-check.d.ts +11 -0
  115. package/dist/secret-store-check.js +76 -0
  116. package/dist/secret-store-check.js.map +1 -0
  117. package/dist/secret-store.d.ts +106 -0
  118. package/dist/secret-store.js +228 -0
  119. package/dist/secret-store.js.map +1 -0
  120. package/dist/shared.d.ts +17 -11
  121. package/dist/shared.js +34 -7
  122. package/dist/shared.js.map +1 -1
  123. package/dist/sites.d.ts +4 -93
  124. package/dist/sites.js +61 -84
  125. package/dist/sites.js.map +1 -1
  126. package/dist/version.d.ts +2 -1
  127. package/dist/version.js +2 -1
  128. package/dist/version.js.map +1 -1
  129. package/dist/wakeup-driver.js +15 -6
  130. package/dist/wakeup-driver.js.map +1 -1
  131. package/dist/worker.js +12 -8
  132. package/dist/worker.js.map +1 -1
  133. package/dist/writer.d.ts +53 -14
  134. package/dist/writer.js +113 -43
  135. package/dist/writer.js.map +1 -1
  136. package/oxlint.json +0 -5
  137. package/package.json +5 -1
  138. package/src/apply-steps.ts +5 -2
  139. package/src/apply.ts +54 -21
  140. package/src/approvals.ts +7 -1
  141. package/src/apps.ts +54 -85
  142. package/src/ast.ts +6 -6
  143. package/src/authentication.ts +74 -0
  144. package/src/call-workflow.ts +5 -4
  145. package/src/call.ts +53 -9
  146. package/src/cedar.ts +14 -1
  147. package/src/change-steps.ts +7 -4
  148. package/src/change.ts +10 -0
  149. package/src/client.ts +108 -41
  150. package/src/collection.ts +10 -2
  151. package/src/config.ts +62 -8
  152. package/src/connection.ts +446 -0
  153. package/src/credentials.ts +94 -281
  154. package/src/db.ts +21 -2
  155. package/src/define.ts +7 -2
  156. package/src/definitions.ts +31 -0
  157. package/src/deployment-key.ts +23 -0
  158. package/src/describe.ts +102 -230
  159. package/src/description.ts +426 -0
  160. package/src/direct.ts +3 -0
  161. package/src/drift.ts +10 -2
  162. package/src/env.ts +4 -2
  163. package/src/index.ts +42 -1
  164. package/src/ledger.ts +3 -1
  165. package/src/lint.ts +1 -16
  166. package/src/load.ts +437 -0
  167. package/src/lockfile.ts +10 -3
  168. package/src/op.ts +10 -1
  169. package/src/outline.ts +18 -5
  170. package/src/paths.ts +24 -2
  171. package/src/plugin.ts +3 -24
  172. package/src/policy.ts +2 -0
  173. package/src/resource.ts +24 -6
  174. package/src/resources.ts +246 -301
  175. package/src/run.ts +2 -0
  176. package/src/sandbox.ts +6 -2
  177. package/src/scenarios.ts +7 -1
  178. package/src/schema.ts +10 -0
  179. package/src/secret-store-check.ts +93 -0
  180. package/src/secret-store.ts +314 -0
  181. package/src/shared.ts +35 -10
  182. package/src/sites.ts +70 -180
  183. package/src/version.ts +2 -1
  184. package/src/wakeup-driver.ts +22 -6
  185. package/src/worker.ts +12 -8
  186. package/src/writer.ts +145 -56
  187. package/dist/datafile.d.ts +0 -97
  188. package/dist/datafile.js +0 -479
  189. package/dist/datafile.js.map +0 -1
  190. package/src/datafile.ts +0 -601
package/src/resource.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { ConnectionRef } from "./connection.ts";
1
2
  import { z } from "zod";
2
3
  import { checkDatabase, type DatabaseSpec } from "./database.ts";
3
4
  import { isRunControlError } from "./errors.ts";
@@ -173,7 +174,7 @@ export async function callAfterCreate(
173
174
  */
174
175
  export const DECLARED: unique symbol = Symbol.for("sanoma.declared");
175
176
 
176
- /** A resource a data file declares: `github.repository({ name: "sanoma" })`. */
177
+ /** A resource a data file declares: `github.repository({ owner: "acme", name: "sanoma" })`. */
177
178
  export interface Declared<Id extends string = string, T = State> {
178
179
  readonly [DECLARED]: Id;
179
180
  readonly vendor: string;
@@ -185,6 +186,7 @@ export interface Declared<Id extends string = string, T = State> {
185
186
  * checked, and what a drift check compares.
186
187
  */
187
188
  readonly desired: T;
189
+ readonly connection?: ConnectionRef;
188
190
  /**
189
191
  * Where it names another resource: the field's dotted path (a list item's with its index,
190
192
  * `teams.0`) to that resource's `<vendor>.<type>:<name>`.
@@ -331,7 +333,10 @@ export interface Resource<
331
333
  >
332
334
  >,
333
335
  Readonly<Pick<ResourceSpec<S>, "identity" | "find" | "host" | "wakeup" | "database" | "afterCreate">> {
334
- (desired: Declaring<z.input<S>, R>): Declared<Id, z.input<S>>;
336
+ (
337
+ desired: Declaring<z.input<S>, R>,
338
+ options?: { connection?: ConnectionRef<Id extends `${infer V}.${string}` ? V : string> },
339
+ ): Declared<Id, z.input<S>>;
335
340
  /** `read` and `import`, each effect `read`, idempotent, with the id as `target`; for a writable type, the change operations too. */
336
341
  readonly ops: ResourceOps<S, W>;
337
342
  /** True when apply may change its objects: it has the change operations. */
@@ -349,7 +354,9 @@ export const isObject = (v: unknown): v is State => typeof v === "object" && v !
349
354
  /** `path.name`, or `name` at the top: a field's dotted path. */
350
355
  export const joinPath = (path: string, name: string) => (path ? `${path}.${name}` : name);
351
356
 
352
- const isDeclared = (v: unknown): v is Declared => isObject(v) && typeof (v as Partial<Declared>)[DECLARED] === "string";
357
+ /** A declared resource: what a constructor returns, made by any copy of this package. */
358
+ export const isDeclared = (v: unknown): v is Declared =>
359
+ isObject(v) && typeof (v as Partial<Declared>)[DECLARED] === "string";
353
360
 
354
361
  /** One order for a list compared as a multiset: by each item's JSON. */
355
362
  const canonical = (items: unknown[]) =>
@@ -577,8 +584,8 @@ function pathsIn(value: unknown, paths: ReadonlySet<string>, prefix = ""): strin
577
584
  *
578
585
  * The ledger records a `handle` as `"<handle>"`, never its bytes (the operations' `opaque`).
579
586
  *
580
- * Calling the result declares one resource, for a data file: `repository({ name: "sanoma" })`
581
- * is a `Declared`, `{ vendor, type, name: "sanoma", desired, refs: {} }`. It refuses fields the
587
+ * Calling the result declares one resource, for a data file: `repository({ owner: "acme", name: "sanoma" })`
588
+ * is a `Declared`, `{ vendor, type, name: "acme/sanoma", desired, refs: {} }`. It refuses fields the
582
589
  * schema does not have, fields the vendor owns (unless the identity names them), values the
583
590
  * schema rejects, and an empty identity. Where `fields.references` allows it, a field may name
584
591
  * another declared resource of that type (`repository_id: site`): `desired` holds, and the
@@ -663,7 +670,17 @@ export function defineResource<
663
670
  const owned = new Set(fields.vendorOwned.filter((path) => !named.has(path)));
664
671
  const references: References = fields.references ?? {};
665
672
  const writeOnly = new Set(fields.writeOnly);
666
- const declare = (given: Declaring<z.input<S>, R>): Declared<`${V}.${T}`, z.input<S>> => {
673
+ const declare = (
674
+ given: Declaring<z.input<S>, R>,
675
+ options?: { connection?: ConnectionRef },
676
+ ): Declared<`${V}.${T}`, z.input<S>> => {
677
+ const connection = options?.connection;
678
+ if (
679
+ connection &&
680
+ (connection.vendor !== vendor || !new RegExp(`^${vendor}/[a-z][a-z0-9-]{0,63}$`).test(connection.$connection))
681
+ ) {
682
+ throw new Error(`${what}: select a declared connection of this connector`);
683
+ }
667
684
  const refs: Record<string, string> = {};
668
685
  // Where a secret is given, with list items' indexes: the schema does not judge its marker.
669
686
  const secrets = new Set<string>();
@@ -723,6 +740,7 @@ export function defineResource<
723
740
  ...(name !== undefined && { name }),
724
741
  desired,
725
742
  refs: Object.freeze(refs),
743
+ ...(connection && { connection: Object.freeze({ ...connection }) }),
726
744
  });
727
745
  };
728
746
  const resource = Object.assign(declare, {