@diagonal-hq/cli 0.42.12 → 0.42.14

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.
@@ -2580,6 +2580,54 @@ var PAGES_EXPORT = "Pages";
2580
2580
  function pageName2(path) {
2581
2581
  return pageName(withoutDevInfix(path));
2582
2582
  }
2583
+ var BINDING_KEYS = ["resource", "lookupField", "relations", "scope"];
2584
+ var RECORD_SCOPES = ["active", "activeOrArchived", "archived"];
2585
+ function bindingOptionsProblem(binding, label) {
2586
+ const unknown = Object.keys(binding).find((name) => !BINDING_KEYS.includes(name));
2587
+ if (unknown !== void 0) {
2588
+ return `Unknown option "${label}.${unknown}"`;
2589
+ }
2590
+ const { lookupField = null, relations = [], scope = null } = binding;
2591
+ if (lookupField !== null && (typeof lookupField !== "string" || lookupField === "")) {
2592
+ return `"${label}.lookupField" must be a field key`;
2593
+ }
2594
+ if (!Array.isArray(relations) || relations.some((relation) => typeof relation !== "string")) {
2595
+ return `"${label}.relations" must be a list of field keys`;
2596
+ }
2597
+ if (scope !== null && !RECORD_SCOPES.includes(scope)) {
2598
+ return `"${label}.scope" must be "active", "activeOrArchived", or "archived"`;
2599
+ }
2600
+ return null;
2601
+ }
2602
+ function routeBindingsSource(bindings, route, label, reference) {
2603
+ if (bindings === void 0 || bindings === null) {
2604
+ return null;
2605
+ }
2606
+ if (!isPlainObject(bindings)) {
2607
+ throw new SourceError(`"${label}" must be an object keyed by route parameter.`);
2608
+ }
2609
+ const params = routeParamNames(route);
2610
+ const written = {};
2611
+ for (const [key, binding] of Object.entries(bindings)) {
2612
+ if (!params.includes(key)) {
2613
+ throw new SourceError(`"${label}.${key}" is not a parameter of "${route}".`);
2614
+ }
2615
+ if (!isPlainObject(binding)) {
2616
+ throw new SourceError(`"${label}.${key}" must be an object.`);
2617
+ }
2618
+ const problem = bindingOptionsProblem(binding, `${label}.${key}`);
2619
+ if (problem !== null) {
2620
+ throw new SourceError(`${problem}.`);
2621
+ }
2622
+ if (typeof binding.resource !== "string" || binding.resource === "") {
2623
+ throw new SourceError(
2624
+ `"${label}.${key}.resource" must be Resources.<Name>.slug or a resource slug.`
2625
+ );
2626
+ }
2627
+ written[key] = { ...binding, resource: reference(binding.resource) };
2628
+ }
2629
+ return written;
2630
+ }
2583
2631
  function routeParamNames(route) {
2584
2632
  return [...route.matchAll(/\{([^}/]+)\}/g)].map((match) => match[1]);
2585
2633
  }
@@ -3170,6 +3218,8 @@ export {
3170
3218
  GENERATED_PAGES_PATH,
3171
3219
  GENERATED_PAGES_MODULE,
3172
3220
  pageName2 as pageName,
3221
+ bindingOptionsProblem,
3222
+ routeBindingsSource,
3173
3223
  routeParamNames,
3174
3224
  pagesBinding,
3175
3225
  FIELD_CATALOG,
@@ -130,6 +130,79 @@ function inputKeys(ast) {
130
130
  }
131
131
  return keys;
132
132
  }
133
+ function editableInputSchema(ast) {
134
+ const argument = defineConfigArgument(ast);
135
+ if (argument === null) {
136
+ return {
137
+ refusal: "The workflow has no config object as the first argument of defineWorkflow, so the app cannot edit its input. Write defineWorkflow({ ... }, handler) in Files."
138
+ };
139
+ }
140
+ const config = unwrap(argument);
141
+ if (config.properties.some((option) => option.type === "SpreadElement" || option.computed)) {
142
+ return {
143
+ refusal: "The workflow config uses a spread or a computed name, so the app cannot edit its input. Edit the input in Files."
144
+ };
145
+ }
146
+ const property = config.properties.find((option) => propertyKey(option) === "input") ?? null;
147
+ if (property === null) {
148
+ return {
149
+ refusal: null,
150
+ config,
151
+ property: null,
152
+ shape: null,
153
+ inline: false
154
+ };
155
+ }
156
+ if (property.type !== "ObjectProperty") {
157
+ return {
158
+ refusal: "The input is a method, so the app cannot edit its fields. Write input: v.object({ ... }) in Files."
159
+ };
160
+ }
161
+ let schema = unwrap(property.value);
162
+ const inline = schema.type !== "Identifier";
163
+ if (!inline) {
164
+ const name = schema.name;
165
+ schema = topLevelConst(ast, name);
166
+ if (schema === null) {
167
+ return {
168
+ refusal: `The input is ${name}, which is not a top-level const of this file, so the app cannot edit its fields. Edit the input in Files.`
169
+ };
170
+ }
171
+ }
172
+ const shape = isVObjectCall(schema) ? unwrap(schema.arguments[0]) : null;
173
+ if (shape?.type !== "ObjectExpression") {
174
+ return {
175
+ refusal: "The input is not written as v.object({ ... }) with the v of '@diagonal/workflow', so the app cannot edit its fields. Edit the input in Files."
176
+ };
177
+ }
178
+ const named = shape.properties.every(
179
+ (field) => field.type === "ObjectProperty" && !field.computed
180
+ );
181
+ if (!named) {
182
+ return {
183
+ refusal: "The input has a field that is not a named property, such as a spread, so the app cannot edit its fields. Edit the input in Files."
184
+ };
185
+ }
186
+ const reader = shape.properties.find((field) => !readsBody(field.value));
187
+ if (reader !== void 0) {
188
+ return {
189
+ refusal: `The input field "${propertyKey(reader)}" reads a header or a path parameter with .from(), and the app edits only body fields. Edit the input in Files.`
190
+ };
191
+ }
192
+ return { refusal: null, config, property, shape, inline };
193
+ }
194
+ function readsBody(node) {
195
+ let current = unwrap(node);
196
+ while (current?.type === "CallExpression" && current.callee.type === "MemberExpression") {
197
+ const { callee } = current;
198
+ if (!callee.computed && callee.property.type === "Identifier" && callee.property.name === "from") {
199
+ const location = unwrap(current.arguments[0]);
200
+ return location?.type === "StringLiteral" && location.value === "body";
201
+ }
202
+ current = unwrap(callee.object);
203
+ }
204
+ return true;
205
+ }
133
206
  function topLevelConst(ast, name) {
134
207
  for (const statement of ast.program.body) {
135
208
  const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
@@ -419,6 +492,7 @@ export {
419
492
  WORKFLOW_STAGE,
420
493
  workflowConfigObject,
421
494
  workflowMetadata,
495
+ editableInputSchema,
422
496
  tarballName,
423
497
  isVersion,
424
498
  compareVersions,
@@ -3,7 +3,7 @@ const require = __diagonalCreateRequire(import.meta.url);
3
3
  import {
4
4
  WORKFLOW_STAGE,
5
5
  stripTypes
6
- } from "./cli-chunk-IHJR3KQG.mjs";
6
+ } from "./cli-chunk-KWMNEXZC.mjs";
7
7
  import {
8
8
  scriptSdkRuntimeFiles
9
9
  } from "./cli-chunk-YSDTJ57P.mjs";
package/dist/cli.mjs CHANGED
@@ -18,6 +18,7 @@ import {
18
18
  GENERATED_RECORD_BINDINGS_MODULE,
19
19
  PERMISSIONS_EXPORT,
20
20
  SYSTEM_PERMISSIONS_EXPORT,
21
+ bindingOptionsProblem,
21
22
  brand_kit_catalog_default,
22
23
  buildField,
23
24
  buildPermission,
@@ -42,11 +43,13 @@ import {
42
43
  readWorkspaceField,
43
44
  readWorkspaceFieldDefinition,
44
45
  readWorkspaceSettings,
46
+ routeBindingsSource,
45
47
  routeParamNames,
46
48
  workspace_settings_catalog_default
47
- } from "./cli-chunk-SD7APJJ6.mjs";
49
+ } from "./cli-chunk-HMV62NPA.mjs";
48
50
  import {
49
51
  compareVersions,
52
+ editableInputSchema,
50
53
  isVersion,
51
54
  runWorkspaceBuild,
52
55
  runWorkspaceBuildAsync,
@@ -54,7 +57,7 @@ import {
54
57
  workflowConfigObject,
55
58
  workflowMetadata,
56
59
  workspaceBuildNeeds
57
- } from "./cli-chunk-IHJR3KQG.mjs";
60
+ } from "./cli-chunk-KWMNEXZC.mjs";
58
61
  import {
59
62
  GENERATED_NOTIFICATION_TYPES_MODULE,
60
63
  GENERATED_WORKFLOWS_MODULE,
@@ -6427,8 +6430,6 @@ var PAGE_KEYS = /* @__PURE__ */ new Set([
6427
6430
  "seo"
6428
6431
  ]);
6429
6432
  var PAGE_RENDER_PROFILES = /* @__PURE__ */ new Set(["standard", "print"]);
6430
- var PARAM_KEYS = /* @__PURE__ */ new Set(["resource", "lookupField", "relations", "scope"]);
6431
- var RECORD_SCOPES = /* @__PURE__ */ new Set(["active", "activeOrArchived", "archived"]);
6432
6433
  function compile(code, functionNode) {
6433
6434
  try {
6434
6435
  return transformJsx(code);
@@ -6778,10 +6779,9 @@ function pageBindings(meta, nodes, route, option) {
6778
6779
  if (typeof binding !== "object" || binding === null || Array.isArray(binding)) {
6779
6780
  throw new SourceError(`"${option}.${key}" must be an object`, nodes[option]);
6780
6781
  }
6781
- for (const name of Object.keys(binding)) {
6782
- if (!PARAM_KEYS.has(name)) {
6783
- throw new SourceError(`Unknown option "${option}.${key}.${name}"`, nodes[option]);
6784
- }
6782
+ const problem2 = bindingOptionsProblem(binding, `${option}.${key}`);
6783
+ if (problem2 !== null) {
6784
+ throw new SourceError(problem2, nodes[option]);
6785
6785
  }
6786
6786
  const { resource = null, lookupField = null, relations = [], scope = null } = binding;
6787
6787
  if (typeof resource !== "string" || resource === "") {
@@ -6790,18 +6790,6 @@ function pageBindings(meta, nodes, route, option) {
6790
6790
  nodes[option]
6791
6791
  );
6792
6792
  }
6793
- if (lookupField !== null && (typeof lookupField !== "string" || lookupField === "")) {
6794
- throw new SourceError(`"${option}.${key}.lookupField" must be a field key`, nodes[option]);
6795
- }
6796
- if (!Array.isArray(relations) || relations.some((relation) => typeof relation !== "string")) {
6797
- throw new SourceError(`"${option}.${key}.relations" must be a list of field keys`, nodes[option]);
6798
- }
6799
- if (scope !== null && !RECORD_SCOPES.has(scope)) {
6800
- throw new SourceError(
6801
- `"${option}.${key}.scope" must be "active", "activeOrArchived", or "archived"`,
6802
- nodes[option]
6803
- );
6804
- }
6805
6793
  bindings.push({ key, resource, lookupField, relations, scope });
6806
6794
  }
6807
6795
  return bindings;
@@ -7562,8 +7550,11 @@ function withResourceReferences(options, namesBySlug, local) {
7562
7550
  const withResource = (value) => isPlainObject(value) && Object.hasOwn(value, "resource") ? { ...value, resource: reference(value.resource) } : value;
7563
7551
  const result = { ...options, authorizer: withResource(options.authorizer) };
7564
7552
  if (isPlainObject(options.bindings)) {
7565
- result.bindings = Object.fromEntries(
7566
- Object.entries(options.bindings).map(([key, binding]) => [key, withResource(binding)])
7553
+ result.bindings = routeBindingsSource(
7554
+ options.bindings,
7555
+ String(options.route ?? "/"),
7556
+ "bindings",
7557
+ reference
7567
7558
  );
7568
7559
  }
7569
7560
  return { options: result, used };
@@ -9388,6 +9379,29 @@ var RECORD_EVENTS = ["created", "updated", "deleted", "restored", "saved"];
9388
9379
  var LIFECYCLE_HOOKS = ["creating", "updating", "saving", "deleting", "restoring"];
9389
9380
  var WORKFLOW_EVENTS = ["execution.success", "execution.error", "execution.exception"];
9390
9381
  var EXECUTION_MODES = ["sync", "async"];
9382
+ var SDK_MODULE = "@diagonal/workflow";
9383
+ var SCALAR_KINDS = [
9384
+ "text",
9385
+ "email",
9386
+ "url",
9387
+ "uuid",
9388
+ "phone",
9389
+ "date",
9390
+ "datetime",
9391
+ "time",
9392
+ "timezone",
9393
+ "color",
9394
+ "number",
9395
+ "integer",
9396
+ "money",
9397
+ "boolean",
9398
+ "roleReference"
9399
+ ];
9400
+ var RECORD_SCOPES = ["active", "archived", "activeOrArchived"];
9401
+ var FILE_VISIBILITIES = ["public", "private"];
9402
+ var CONTENT_OPTIONS = ["multiLine", "extensions", "allowedNodes"];
9403
+ var SIZE_RULE = /^(min|max|size):(-?\d+(?:\.\d+)?)$/;
9404
+ var BETWEEN_RULE = /^between:(-?\d+(?:\.\d+)?),(-?\d+(?:\.\d+)?)$/;
9391
9405
  function isWorkflowConfigPath(path) {
9392
9406
  return WORKFLOW_PATH.test(path) && !path.endsWith(".test.ts") && !path.endsWith(".d.ts");
9393
9407
  }
@@ -9428,7 +9442,8 @@ function readWorkflowConfigFile(path, source) {
9428
9442
  uid,
9429
9443
  slug,
9430
9444
  name: literalString(properties.get("name") ?? properties.get("title")),
9431
- description: literalString(properties.get("description"))
9445
+ description: literalString(properties.get("description")),
9446
+ input_refusal: editableInputSchema(ast).refusal
9432
9447
  };
9433
9448
  }
9434
9449
  function nonEmptyString(value, label) {
@@ -9525,6 +9540,15 @@ function referenceWriter(ast, resources, permissions) {
9525
9540
  }
9526
9541
  };
9527
9542
  }
9543
+ function bindingsOptionOf(bindings, route, references2) {
9544
+ const written = routeBindingsSource(
9545
+ bindings,
9546
+ route,
9547
+ "trigger.bindings",
9548
+ (slug) => references2.resource({ slug })
9549
+ );
9550
+ return written === null || Object.keys(written).length === 0 ? {} : { bindings: written };
9551
+ }
9528
9552
  function triggerOf(trigger, references2) {
9529
9553
  if (!isPlainObject(trigger)) {
9530
9554
  throw new SourceError('"trigger" must be an object with a type.');
@@ -9539,15 +9563,17 @@ function triggerOf(trigger, references2) {
9539
9563
  if (domain !== null && (typeof domain !== "string" || domain === "")) {
9540
9564
  throw new SourceError('"trigger.domain" must be a domain key or null.');
9541
9565
  }
9566
+ const route = path.startsWith("/") ? path : `/${path}`;
9542
9567
  const apiDocs = trigger.apiDocs ?? true;
9543
9568
  if (typeof apiDocs !== "boolean") {
9544
9569
  throw new SourceError('"trigger.apiDocs" must be true, false, or null.');
9545
9570
  }
9546
9571
  return {
9547
9572
  type: "request",
9548
- path: path.startsWith("/") ? path : `/${path}`,
9573
+ path: route,
9549
9574
  method,
9550
9575
  ...domain === null ? {} : { domain: references2.domain(domain) },
9576
+ ...bindingsOptionOf(trigger.bindings, route, references2),
9551
9577
  ...apiDocs ? {} : { apiDocs: false }
9552
9578
  };
9553
9579
  }
@@ -9697,6 +9723,243 @@ function routeEdits(source, properties, changes) {
9697
9723
  0
9698
9724
  );
9699
9725
  }
9726
+ function optionalText2(value, label) {
9727
+ if (value !== void 0 && value !== null && typeof value !== "string") {
9728
+ throw new SourceError(`"${label}" must be a string or null.`);
9729
+ }
9730
+ return typeof value === "string" && value.trim() !== "" ? value : null;
9731
+ }
9732
+ function finiteLiteral(value, label) {
9733
+ if (typeof value === "string" || typeof value === "number" && Number.isFinite(value)) {
9734
+ return value;
9735
+ }
9736
+ throw new SourceError(`"${label}" must be a string or a finite number.`);
9737
+ }
9738
+ function ruleText(rule, label) {
9739
+ if (typeof rule !== "string" || rule.trim() === "") {
9740
+ throw new SourceError(`"${label}" must be a list of validation rules.`);
9741
+ }
9742
+ const size = SIZE_RULE.exec(rule);
9743
+ if (size !== null && String(Number(size[2])) === size[2]) {
9744
+ return `.${size[1]}(${size[2]})`;
9745
+ }
9746
+ const between = BETWEEN_RULE.exec(rule);
9747
+ if (between !== null && String(Number(between[1])) === between[1] && String(Number(between[2])) === between[2]) {
9748
+ return `.between(${between[1]}, ${between[2]})`;
9749
+ }
9750
+ return `.rule(${quotedLiteral(rule)})`;
9751
+ }
9752
+ function optionsText(options) {
9753
+ return Object.keys(options).length === 0 ? "" : valueText(options, "", 0);
9754
+ }
9755
+ function builderText(spec, label, references2, v) {
9756
+ const kind = spec.kind;
9757
+ if (SCALAR_KINDS.includes(kind)) {
9758
+ return `${v}.${kind}()`;
9759
+ }
9760
+ switch (kind) {
9761
+ case "select": {
9762
+ const options = spec.options;
9763
+ if (!Array.isArray(options) || options.length === 0) {
9764
+ throw new SourceError(`"${label}" is a select field with no options.`);
9765
+ }
9766
+ return `${v}.select(${valueText(
9767
+ options.map((option) => finiteLiteral(option, `${label}.options`)),
9768
+ "",
9769
+ 0
9770
+ )})`;
9771
+ }
9772
+ case "list":
9773
+ return `${v}.list(${fieldText(spec.items, `${label}.items`, references2, v)})`;
9774
+ case "object":
9775
+ return `${v}.object(${shapeText(fieldEntries(spec.fields, `${label}.fields`), "", 0, references2, v)})`;
9776
+ case "record":
9777
+ return `${v}.record(${valueText(references2.resource(spec.resource), "", 0)})`;
9778
+ case "recordReference": {
9779
+ const scope = spec.scope ?? null;
9780
+ return `${v}.recordReference(${valueText(references2.resource(spec.resource), "", 0)}${scope === null ? "" : `, { scope: ${quotedLiteral(oneOf(scope, RECORD_SCOPES, `${label}.scope`))} }`})`;
9781
+ }
9782
+ case "file": {
9783
+ const options = {};
9784
+ if (spec.accept !== void 0 && spec.accept !== null) {
9785
+ if (!Array.isArray(spec.accept) || spec.accept.some((mime) => typeof mime !== "string")) {
9786
+ throw new SourceError(`"${label}.accept" must be a list of MIME types.`);
9787
+ }
9788
+ options.accept = spec.accept;
9789
+ }
9790
+ if (spec.visibility !== void 0 && spec.visibility !== null) {
9791
+ options.visibility = oneOf(spec.visibility, FILE_VISIBILITIES, `${label}.visibility`);
9792
+ }
9793
+ return `${v}.file(${optionsText(options)})`;
9794
+ }
9795
+ case "content": {
9796
+ const content = spec.content ?? {};
9797
+ if (!isPlainObject(content) || Object.keys(content).some((key) => !CONTENT_OPTIONS.includes(key))) {
9798
+ throw new SourceError(
9799
+ `"${label}.content" must be content options: ${CONTENT_OPTIONS.join(", ")}.`
9800
+ );
9801
+ }
9802
+ return `${v}.content(${optionsText(content)})`;
9803
+ }
9804
+ default:
9805
+ throw new SourceError(`"${label}.kind" must be a v field kind.`);
9806
+ }
9807
+ }
9808
+ function fieldText(spec, label, references2, v) {
9809
+ if (!isPlainObject(spec)) {
9810
+ throw new SourceError(`"${label}" must be a field spec.`);
9811
+ }
9812
+ const rules = spec.rules ?? [];
9813
+ if (!Array.isArray(rules)) {
9814
+ throw new SourceError(`"${label}.rules" must be a list of validation rules.`);
9815
+ }
9816
+ const fieldLabel = optionalText2(spec.label, `${label}.label`);
9817
+ const description = optionalText2(spec.description, `${label}.description`);
9818
+ return [
9819
+ builderText(spec, label, references2, v),
9820
+ ...rules.map((rule) => ruleText(rule, `${label}.rules`)),
9821
+ spec.optional === true ? ".optional()" : "",
9822
+ spec.nullable === true ? ".nullable()" : "",
9823
+ fieldLabel === null ? "" : `.label(${quotedLiteral(fieldLabel)})`,
9824
+ description === null ? "" : `.description(${quotedLiteral(description)})`
9825
+ ].join("");
9826
+ }
9827
+ function fieldEntries(fields2, label) {
9828
+ if (!Array.isArray(fields2)) {
9829
+ throw new SourceError(`"${label}" must be a list of { key, spec } fields.`);
9830
+ }
9831
+ const keys2 = /* @__PURE__ */ new Set();
9832
+ for (const field of fields2) {
9833
+ if (!isPlainObject(field) || typeof field.key !== "string" || field.key.trim() === "") {
9834
+ throw new SourceError(`"${label}" must name each field with a non-empty key.`);
9835
+ }
9836
+ if (keys2.has(field.key)) {
9837
+ throw new SourceError(`"${label}" names the field "${field.key}" twice.`);
9838
+ }
9839
+ keys2.add(field.key);
9840
+ }
9841
+ return fields2;
9842
+ }
9843
+ function existingField(existing, name, use) {
9844
+ const property2 = existing.get(name);
9845
+ if (property2 === void 0) {
9846
+ throw new SourceError(`The input has no field "${name}" to ${use}.`);
9847
+ }
9848
+ return property2;
9849
+ }
9850
+ function leadingComments2(source, property2) {
9851
+ return (property2.leadingComments ?? []).map((comment) => source.slice(comment.start, comment.end)).join("\n");
9852
+ }
9853
+ function shapeText(fields2, indent, lead, references2, v, source = "", existing = /* @__PURE__ */ new Map()) {
9854
+ const entries = fields2.map((field) => {
9855
+ const name = objectKeyLiteral(field.key);
9856
+ if (field.keep === void 0) {
9857
+ return {
9858
+ comments: field.replaces === void 0 ? "" : leadingComments2(source, existingField(existing, field.replaces, "replace")),
9859
+ text: `${name}: ${fieldText(field.spec, field.key, references2, v)}`
9860
+ };
9861
+ }
9862
+ const property2 = existingField(existing, field.keep, "keep");
9863
+ const comments = leadingComments2(source, property2);
9864
+ const value = source.slice(property2.value.start, property2.value.end);
9865
+ return {
9866
+ comments,
9867
+ text: !property2.shorthand && field.keep === field.key ? source.slice(property2.start, property2.end) : `${name}: ${value}`
9868
+ };
9869
+ });
9870
+ if (entries.length === 0) {
9871
+ return "{}";
9872
+ }
9873
+ const inline = `{ ${entries.map((entry2) => entry2.text).join(", ")} }`;
9874
+ if (lead + inline.length <= INLINE_WIDTH && entries.every((entry2) => entry2.comments === "" && !entry2.text.includes("\n"))) {
9875
+ return inline;
9876
+ }
9877
+ const inner = indent + INDENT;
9878
+ const lines = entries.map(
9879
+ (entry2) => [
9880
+ ...entry2.comments === "" ? [] : entry2.comments.split("\n").map((line) => `${inner}${line.trim()}`),
9881
+ `${inner}${entry2.text}`
9882
+ ].join("\n")
9883
+ );
9884
+ return `{
9885
+ ${lines.join(",\n")}
9886
+ ${indent}}`;
9887
+ }
9888
+ function vImport(ast) {
9889
+ const local = generatedBindingLocal(ast, SDK_MODULE, "v");
9890
+ if (local !== null) {
9891
+ return { local, edits: [] };
9892
+ }
9893
+ const declaration = ast.program.body.find(
9894
+ (statement) => statement.type === "ImportDeclaration" && statement.source.value === SDK_MODULE && statement.importKind !== "type" && statement.specifiers.length > 0 && statement.specifiers.every((item) => item.type === "ImportSpecifier")
9895
+ );
9896
+ if (declaration !== void 0) {
9897
+ const last = declaration.specifiers.at(-1);
9898
+ return {
9899
+ local: "v",
9900
+ edits: [{ start: last.end, end: last.end, text: ", v" }]
9901
+ };
9902
+ }
9903
+ const imports = ast.program.body.filter((statement) => statement.type === "ImportDeclaration");
9904
+ const at = imports.at(-1)?.end ?? 0;
9905
+ const line = `import { v } from '${SDK_MODULE}';`;
9906
+ return {
9907
+ local: "v",
9908
+ edits: [{ start: at, end: at, text: at === 0 ? `${line}
9909
+ ` : `
9910
+ ${line}` }]
9911
+ };
9912
+ }
9913
+ function inputEdits(ast, source, changes, references2) {
9914
+ if (changes.input === void 0) {
9915
+ return { options: {}, edits: [] };
9916
+ }
9917
+ if (!isPlainObject(changes.input)) {
9918
+ throw new SourceError('"input" must be { fields }.');
9919
+ }
9920
+ const fields2 = fieldEntries(changes.input.fields, "input.fields");
9921
+ const schema = editableInputSchema(ast);
9922
+ if (schema.refusal !== null) {
9923
+ throw new SourceError(schema.refusal);
9924
+ }
9925
+ if (schema.property === null) {
9926
+ if (fields2.length === 0) {
9927
+ return { options: {}, edits: [] };
9928
+ }
9929
+ if (fields2.some((field) => field.keep !== void 0)) {
9930
+ throw new SourceError("The workflow has no input fields to keep.");
9931
+ }
9932
+ const { local, edits } = vImport(ast);
9933
+ const indent = indentOf(source, schema.config.properties.at(-1) ?? schema.config);
9934
+ const prefix = `input: ${local}.object(`;
9935
+ const shape2 = shapeText(fields2, indent, indent.length + prefix.length, references2, local);
9936
+ return {
9937
+ options: {
9938
+ input: new SourceExpression(`${local}.object(${shape2})`)
9939
+ },
9940
+ edits
9941
+ };
9942
+ }
9943
+ if (fields2.length === 0 && schema.inline) {
9944
+ return { options: { input: null }, edits: [] };
9945
+ }
9946
+ const { shape } = schema;
9947
+ const existing = new Map(shape.properties.map((property2) => [propertyKey(property2), property2]));
9948
+ const column = shape.start - (source.lastIndexOf("\n", shape.start - 1) + 1);
9949
+ const text = shapeText(
9950
+ fields2,
9951
+ indentOf(source, shape),
9952
+ column,
9953
+ references2,
9954
+ "v",
9955
+ source,
9956
+ existing
9957
+ );
9958
+ return {
9959
+ options: {},
9960
+ edits: [{ start: shape.start, end: shape.end, text }]
9961
+ };
9962
+ }
9700
9963
  function importEdits2(ast, { imports }) {
9701
9964
  const declarations = ast.program.body.filter(
9702
9965
  (statement) => statement.type === "ImportDeclaration"
@@ -9718,9 +9981,13 @@ function importEdits2(ast, { imports }) {
9718
9981
  }
9719
9982
  if (lines.length > 0) {
9720
9983
  const at = declarations.at(-1)?.end ?? 0;
9721
- edits.push({ start: at, end: at, text: at === 0 ? `${lines.join("\n")}
9984
+ edits.push({
9985
+ start: at,
9986
+ end: at,
9987
+ text: at === 0 ? `${lines.join("\n")}
9722
9988
  ` : `
9723
- ${lines.join("\n")}` });
9989
+ ${lines.join("\n")}`
9990
+ });
9724
9991
  }
9725
9992
  return edits;
9726
9993
  }
@@ -9737,10 +10004,15 @@ function writeWorkflowConfigFile(path, source, changes, resources = [], permissi
9737
10004
  node.properties.filter((property2) => property2.type === "ObjectProperty" || property2.type === "ObjectMethod").map((property2) => [propertyKey(property2), property2])
9738
10005
  );
9739
10006
  const references2 = referenceWriter(ast, resources, permissions);
9740
- const options = optionsOf2(changes, properties, references2);
10007
+ const input = inputEdits(ast, source, changes, references2);
10008
+ const options = {
10009
+ ...optionsOf2(changes, properties, references2),
10010
+ ...input.options
10011
+ };
9741
10012
  const written = applySourceEdits(source, [
9742
10013
  ...objectPatchEdits(source, node, options, "config", 0),
9743
10014
  ...routeEdits(source, properties, changes),
10015
+ ...input.edits,
9744
10016
  ...importEdits2(ast, references2)
9745
10017
  ]);
9746
10018
  if (readWorkflowConfigFile(path, written).uid !== before) {
@@ -9752,7 +10024,18 @@ function writeWorkflowConfigFile(path, source, changes, resources = [], permissi
9752
10024
  // scripts/lib/runtime-build/source-adapters/workflow-config.mjs
9753
10025
  var workflowConfigAdapter = Object.freeze({
9754
10026
  contextFields: ["resources", "resource_slugs", "permissions"],
9755
- writeFields: ["name", "slug", "description", "trigger", "route", "run_as", "authorizer", "execution_mode", "paused"],
10027
+ writeFields: [
10028
+ "name",
10029
+ "slug",
10030
+ "description",
10031
+ "trigger",
10032
+ "route",
10033
+ "run_as",
10034
+ "authorizer",
10035
+ "execution_mode",
10036
+ "paused",
10037
+ "input"
10038
+ ],
9756
10039
  accepts: isWorkflowConfigPath,
9757
10040
  identity: (data) => data.uid,
9758
10041
  read({ path, source }) {
@@ -11207,7 +11490,7 @@ async function checkSources() {
11207
11490
  if (existsSync4(DATA_FILE) && existsSync4(SDK_FILE)) {
11208
11491
  return { dataFile: DATA_FILE, sdkFile: SDK_FILE };
11209
11492
  }
11210
- const { checkData, scriptSdk } = await import("./cli-check-data-EAKFHVPZ.mjs");
11493
+ const { checkData, scriptSdk } = await import("./cli-check-data-QTGYTWFR.mjs");
11211
11494
  return { data: checkData(), sdk: scriptSdk() };
11212
11495
  }
11213
11496
  function isScriptTestPath(path) {
@@ -11227,7 +11510,7 @@ function holdsSkills(root, plan) {
11227
11510
  async function checkCheckout(root, options) {
11228
11511
  const sources = await checkSources();
11229
11512
  const plan = composePackages(root);
11230
- const testRunner = async () => (await import("./cli-workflows-DUSY244F.mjs")).runBuildTests;
11513
+ const testRunner = async () => (await import("./cli-workflows-NQK747FY.mjs")).runBuildTests;
11231
11514
  const skillReader = async () => (await import("./cli-skill-file-PHFXSLAU.mjs")).skillFrontMatter;
11232
11515
  const finish = (checkoutRoot, buildPlan, answer, runTests2) => {
11233
11516
  const run = hasScriptTests(answer) ? runTests2(checkoutRoot, answer.tests) : null;
package/dist/index.d.ts CHANGED
@@ -583,8 +583,12 @@ export type ResourceDefinition<
583
583
  dataApi?: ResourceDataApi;
584
584
  /**
585
585
  * A static resource declares all of its records in `records/`. The deploy
586
- * writes them, and normal record writes to the resource are refused. A
587
- * static resource has no capabilities and no relation fields of its own.
586
+ * writes them, and normal record writes to the resource are refused.
587
+ * A static resource can have the `price` capability and the `product`
588
+ * capability with `accounting_entity_field` and `revenue_account_field`
589
+ * unset. The build refuses all other capabilities to prevent capability
590
+ * code from writing to static records. A `belongs_to` or `belongs_to_many`
591
+ * relation can target only another static resource.
588
592
  */
589
593
  static?: boolean;
590
594
  /**
@@ -638,16 +642,20 @@ export type PageMetaResolver =
638
642
  */
639
643
  export interface WorkspaceResources {}
640
644
 
641
- export type PageBinding<R extends ResourceReference = ResourceReference> = {
645
+ /** The record that a route parameter of a page or a request workflow binds to. */
646
+ export type RouteBinding<R extends ResourceReference = ResourceReference> = {
642
647
  /** The resource whose record the route parameter names, as `Resources.<Name>.slug`. */
643
648
  resource: R;
644
649
  /** The field the parameter matches. Defaults to the record id. */
645
650
  lookupField?: string | null;
646
- /** Relation fields to load with the record. A `seo` function reads only these relations. */
651
+ /** Relation fields to load with the record. A page `seo` function reads only these relations. */
647
652
  relations?: readonly string[];
653
+ /** The records that the parameter can name. Defaults to `'active'`. */
648
654
  scope?: 'active' | 'activeOrArchived' | 'archived' | null;
649
655
  };
650
656
 
657
+ export type PageBinding<R extends ResourceReference = ResourceReference> = RouteBinding<R>;
658
+
651
659
  /** @deprecated Use `PageBinding`. */
652
660
  export type PageRouteParam = PageBinding;
653
661
 
@@ -1016,6 +1024,14 @@ export type RequestTrigger = {
1016
1024
  * job calls. Without `apiDocs`, the docs document it.
1017
1025
  */
1018
1026
  apiDocs?: boolean;
1027
+ /**
1028
+ * The record that each route parameter binds to, keyed by parameter name:
1029
+ * `{ member: { resource: Resources.Members.slug, lookupField: 'email' } }`.
1030
+ * The handler receives each record as `input.<name>`, and
1031
+ * `ctx.request.params.<name>` keeps the raw value. A request for a record
1032
+ * that does not exist answers 404, as in a row-based workspace.
1033
+ */
1034
+ bindings?: Readonly<Record<string, RouteBinding>>;
1019
1035
  };
1020
1036
 
1021
1037
  export type RecordEventTrigger = {