@diagonal-hq/cli 0.42.13 → 0.42.15

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,
@@ -9,7 +9,7 @@ import type { ContentDocument } from '../input';
9
9
  import type { DeepReadonly, Liquid, StaticLiquid } from '../liquid';
10
10
  import { invoke } from '../transport';
11
11
 
12
- export const SDK_VERSION = 83;
12
+ export const SDK_VERSION = 84;
13
13
 
14
14
  export interface WorkspaceSystemFields {
15
15
  "ai_custom_system_prompt": string | null;
@@ -6,7 +6,7 @@ import {
6
6
  } from "./cli-chunk-KWMNEXZC.mjs";
7
7
  import {
8
8
  scriptSdkRuntimeFiles
9
- } from "./cli-chunk-YSDTJ57P.mjs";
9
+ } from "./cli-chunk-6VD2BES2.mjs";
10
10
  import {
11
11
  AUTHORING_HELPERS_MODULE,
12
12
  GENERATED_NOTIFICATION_TYPES_PATH,
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,9 +43,10 @@ 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,
50
52
  editableInputSchema,
@@ -6428,8 +6430,6 @@ var PAGE_KEYS = /* @__PURE__ */ new Set([
6428
6430
  "seo"
6429
6431
  ]);
6430
6432
  var PAGE_RENDER_PROFILES = /* @__PURE__ */ new Set(["standard", "print"]);
6431
- var PARAM_KEYS = /* @__PURE__ */ new Set(["resource", "lookupField", "relations", "scope"]);
6432
- var RECORD_SCOPES = /* @__PURE__ */ new Set(["active", "activeOrArchived", "archived"]);
6433
6433
  function compile(code, functionNode) {
6434
6434
  try {
6435
6435
  return transformJsx(code);
@@ -6779,10 +6779,9 @@ function pageBindings(meta, nodes, route, option) {
6779
6779
  if (typeof binding !== "object" || binding === null || Array.isArray(binding)) {
6780
6780
  throw new SourceError(`"${option}.${key}" must be an object`, nodes[option]);
6781
6781
  }
6782
- for (const name of Object.keys(binding)) {
6783
- if (!PARAM_KEYS.has(name)) {
6784
- throw new SourceError(`Unknown option "${option}.${key}.${name}"`, nodes[option]);
6785
- }
6782
+ const problem2 = bindingOptionsProblem(binding, `${option}.${key}`);
6783
+ if (problem2 !== null) {
6784
+ throw new SourceError(problem2, nodes[option]);
6786
6785
  }
6787
6786
  const { resource = null, lookupField = null, relations = [], scope = null } = binding;
6788
6787
  if (typeof resource !== "string" || resource === "") {
@@ -6791,18 +6790,6 @@ function pageBindings(meta, nodes, route, option) {
6791
6790
  nodes[option]
6792
6791
  );
6793
6792
  }
6794
- if (lookupField !== null && (typeof lookupField !== "string" || lookupField === "")) {
6795
- throw new SourceError(`"${option}.${key}.lookupField" must be a field key`, nodes[option]);
6796
- }
6797
- if (!Array.isArray(relations) || relations.some((relation) => typeof relation !== "string")) {
6798
- throw new SourceError(`"${option}.${key}.relations" must be a list of field keys`, nodes[option]);
6799
- }
6800
- if (scope !== null && !RECORD_SCOPES.has(scope)) {
6801
- throw new SourceError(
6802
- `"${option}.${key}.scope" must be "active", "activeOrArchived", or "archived"`,
6803
- nodes[option]
6804
- );
6805
- }
6806
6793
  bindings.push({ key, resource, lookupField, relations, scope });
6807
6794
  }
6808
6795
  return bindings;
@@ -7563,8 +7550,11 @@ function withResourceReferences(options, namesBySlug, local) {
7563
7550
  const withResource = (value) => isPlainObject(value) && Object.hasOwn(value, "resource") ? { ...value, resource: reference(value.resource) } : value;
7564
7551
  const result = { ...options, authorizer: withResource(options.authorizer) };
7565
7552
  if (isPlainObject(options.bindings)) {
7566
- result.bindings = Object.fromEntries(
7567
- 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
7568
7558
  );
7569
7559
  }
7570
7560
  return { options: result, used };
@@ -9407,7 +9397,7 @@ var SCALAR_KINDS = [
9407
9397
  "boolean",
9408
9398
  "roleReference"
9409
9399
  ];
9410
- var RECORD_SCOPES2 = ["active", "archived", "activeOrArchived"];
9400
+ var RECORD_SCOPES = ["active", "archived", "activeOrArchived"];
9411
9401
  var FILE_VISIBILITIES = ["public", "private"];
9412
9402
  var CONTENT_OPTIONS = ["multiLine", "extensions", "allowedNodes"];
9413
9403
  var SIZE_RULE = /^(min|max|size):(-?\d+(?:\.\d+)?)$/;
@@ -9550,6 +9540,15 @@ function referenceWriter(ast, resources, permissions) {
9550
9540
  }
9551
9541
  };
9552
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
+ }
9553
9552
  function triggerOf(trigger, references2) {
9554
9553
  if (!isPlainObject(trigger)) {
9555
9554
  throw new SourceError('"trigger" must be an object with a type.');
@@ -9564,15 +9563,17 @@ function triggerOf(trigger, references2) {
9564
9563
  if (domain !== null && (typeof domain !== "string" || domain === "")) {
9565
9564
  throw new SourceError('"trigger.domain" must be a domain key or null.');
9566
9565
  }
9566
+ const route = path.startsWith("/") ? path : `/${path}`;
9567
9567
  const apiDocs = trigger.apiDocs ?? true;
9568
9568
  if (typeof apiDocs !== "boolean") {
9569
9569
  throw new SourceError('"trigger.apiDocs" must be true, false, or null.');
9570
9570
  }
9571
9571
  return {
9572
9572
  type: "request",
9573
- path: path.startsWith("/") ? path : `/${path}`,
9573
+ path: route,
9574
9574
  method,
9575
9575
  ...domain === null ? {} : { domain: references2.domain(domain) },
9576
+ ...bindingsOptionOf(trigger.bindings, route, references2),
9576
9577
  ...apiDocs ? {} : { apiDocs: false }
9577
9578
  };
9578
9579
  }
@@ -9776,7 +9777,7 @@ function builderText(spec, label, references2, v) {
9776
9777
  return `${v}.record(${valueText(references2.resource(spec.resource), "", 0)})`;
9777
9778
  case "recordReference": {
9778
9779
  const scope = spec.scope ?? null;
9779
- return `${v}.recordReference(${valueText(references2.resource(spec.resource), "", 0)}${scope === null ? "" : `, { scope: ${quotedLiteral(oneOf(scope, RECORD_SCOPES2, `${label}.scope`))} }`})`;
9780
+ return `${v}.recordReference(${valueText(references2.resource(spec.resource), "", 0)}${scope === null ? "" : `, { scope: ${quotedLiteral(oneOf(scope, RECORD_SCOPES, `${label}.scope`))} }`})`;
9780
9781
  }
9781
9782
  case "file": {
9782
9783
  const options = {};
@@ -11489,7 +11490,7 @@ async function checkSources() {
11489
11490
  if (existsSync4(DATA_FILE) && existsSync4(SDK_FILE)) {
11490
11491
  return { dataFile: DATA_FILE, sdkFile: SDK_FILE };
11491
11492
  }
11492
- const { checkData, scriptSdk } = await import("./cli-check-data-ULT4YSJN.mjs");
11493
+ const { checkData, scriptSdk } = await import("./cli-check-data-VYRAU2E4.mjs");
11493
11494
  return { data: checkData(), sdk: scriptSdk() };
11494
11495
  }
11495
11496
  function isScriptTestPath(path) {
@@ -11509,7 +11510,7 @@ function holdsSkills(root, plan) {
11509
11510
  async function checkCheckout(root, options) {
11510
11511
  const sources = await checkSources();
11511
11512
  const plan = composePackages(root);
11512
- const testRunner = async () => (await import("./cli-workflows-NQK747FY.mjs")).runBuildTests;
11513
+ const testRunner = async () => (await import("./cli-workflows-XE3FFNFV.mjs")).runBuildTests;
11513
11514
  const skillReader = async () => (await import("./cli-skill-file-PHFXSLAU.mjs")).skillFrontMatter;
11514
11515
  const finish = (checkoutRoot, buildPlan, answer, runTests2) => {
11515
11516
  const run = hasScriptTests(answer) ? runTests2(checkoutRoot, answer.tests) : null;
package/dist/index.d.ts CHANGED
@@ -642,16 +642,20 @@ export type PageMetaResolver =
642
642
  */
643
643
  export interface WorkspaceResources {}
644
644
 
645
- 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> = {
646
647
  /** The resource whose record the route parameter names, as `Resources.<Name>.slug`. */
647
648
  resource: R;
648
649
  /** The field the parameter matches. Defaults to the record id. */
649
650
  lookupField?: string | null;
650
- /** 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. */
651
652
  relations?: readonly string[];
653
+ /** The records that the parameter can name. Defaults to `'active'`. */
652
654
  scope?: 'active' | 'activeOrArchived' | 'archived' | null;
653
655
  };
654
656
 
657
+ export type PageBinding<R extends ResourceReference = ResourceReference> = RouteBinding<R>;
658
+
655
659
  /** @deprecated Use `PageBinding`. */
656
660
  export type PageRouteParam = PageBinding;
657
661
 
@@ -1020,6 +1024,14 @@ export type RequestTrigger = {
1020
1024
  * job calls. Without `apiDocs`, the docs document it.
1021
1025
  */
1022
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>>;
1023
1035
  };
1024
1036
 
1025
1037
  export type RecordEventTrigger = {