@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.
package/README.md CHANGED
@@ -91,7 +91,7 @@ The build reads each file with a parser. It runs only the workflow and migration
91
91
  - Each page also has a `uid`. See [Definition uids and slugs](#definition-uids-and-slugs). The uid is the identity of the page. A file move or rename changes the page name, but the uid stays. Settings that store the uid still resolve. Resource capability settings name a page by this uid.
92
92
  - Every file that names a page imports `Pages` from `@app/generated/pages`: `diagonal.config.ts`, `resource.ts` files, pages, layouts, components, and menus. There is one `Pages` object. `Pages` is not a global, and `@diagonal-hq/pages` does not export it. A file that uses `Pages` without the import fails the check with `'Pages' is not defined`. Every file names a page by its uid, `Pages.<Name>.uid`, as it names a workflow by `Workflows.<Name>.slug`. Pages, layouts, and components pass the uid to `utils` from `@diagonal-hq/pages`: `utils.page.url(Pages.Members.uid)`, `utils.page.url(Pages.Members_$Id.uid, { id })`, `utils.page.navigate(Pages.Members.uid)`, and `utils.page.navigate(Pages.Members_$Id.uid, { id }, { openInNewTab: true })`. A menu item is `{ kind: 'page', label, page: Pages.Members.uid }`. A config or resource file names a page with `Pages.<Name>.uid` too. See [Page reference settings](#page-reference-settings). The check fails at an unknown name, such as a stale name after a file move: `Unknown page "Pages.X". Each name in Pages is a file in pages/`. The type check also fails at a call without the route parameters of the page, at route parameters for a page without any, and at a menu item for a page with route parameters. The error names the page and its route, such as `Pages.Members_$Id has the route /members/{id}. Pass its route parameters as params.`
93
93
  - Pages, layouts, and components go through the page lint gate: syntax, scope, the component return shape, and a type check against the page Sdk contract and the workspace resources. A page imports the Page SDK members that it uses from `@diagonal-hq/pages`, such as `import { resource, useRecords } from '@diagonal-hq/pages'`. A page names a resource by slug, for example `resource(Resources.Members.slug)`.
94
- - Each `workflows/<name>.ts` is a script workflow. Its default export is `defineWorkflow({ uid, name, trigger, runAs?, executionMode?, input?, output?, validate? }, handler)` from `@diagonal/workflow`, the same shape as `definePage(options, component)`. The config is the first argument and must be an object literal. The build reads every option except `input`, `output`, and `validate` as static data and never runs the handler to find it. `input` is a `v.object({...})` schema, or a top-level `const` of one, which the script compiler reads. `output` is a `v` schema of the handler's return value, which the script compiler reads the same way; the API documentation of a request workflow shows it, and each run's return value is checked against it. `validate` is a function that runs after the input check and before the handler, with the same input type. It returns errors keyed by field, and any error ends the run with a 422. The editor checks the config against `WorkflowConfig` from `@diagonal-hq/cli`. The build validates it: the uid (see [Definition uids and slugs](#definition-uids-and-slugs)), the trigger fields, the resources (see [Resource references](#resource-references)), the workflow references of `workflowEvent` triggers (see [Workflow references](#workflow-references)), the filter trees of a `recordEvent` or `recordLifecycle` trigger's `filters` and `previousFilters` (see [Policies](#policies)), the relation paths of a `recordEvent` trigger's `relations`, and the run-as rules. `previousFilters` matches the record before the change, so a trigger runs on a change from one value to another. Only the `updated` event and the `updating` hook take it. `relations` lists the relations to load with the trigger record, such as `['member', 'member.company']`: each part of a path is the key of a relation field of the resource that the part before it relates to. The deploy checks the relations of a trigger on the Roles or Permissions resource against the stored resource. A `recordEvent`, `recordSchedule`, `scheduled`, or `workflowEvent` workflow needs `runAs`. A request workflow takes `authorizer`, as a page does: `'authenticated'`, or `{ resource, permissions }` with an authenticatable resource as `Resources.<Name>.slug` and permission uids as `Permissions.<Name>.uid` or `SystemPermissions.<Name>.uid`. A caller needs any one of the permissions. The build refuses a resource that is not authenticatable and a permission that the workspace does not declare. A request workflow without `authorizer` is public. A `manual` or `request` workflow can set `executionMode: 'async'` to run in the queue: the caller gets the queued run at once, without the output. Without it, the workflow runs synchronously, with a 55-second limit. The build refuses `executionMode` on another trigger, which has a fixed mode.
94
+ - Each `workflows/<name>.ts` is a script workflow. Its default export is `defineWorkflow({ uid, name, trigger, runAs?, executionMode?, input?, output?, validate? }, handler)` from `@diagonal/workflow`, the same shape as `definePage(options, component)`. The config is the first argument and must be an object literal. The build reads every option except `input`, `output`, and `validate` as static data and never runs the handler to find it. `input` is a `v.object({...})` schema, or a top-level `const` of one, which the script compiler reads. `output` is a `v` schema of the handler's return value, which the script compiler reads the same way; the API documentation of a request workflow shows it, and each run's return value is checked against it. `validate` is a function that runs after the input check and before the handler, with the same input type. It returns errors keyed by field, and any error ends the run with a 422. The editor checks the config against `WorkflowConfig` from `@diagonal-hq/cli`. The build validates it: the uid (see [Definition uids and slugs](#definition-uids-and-slugs)), the trigger fields, the resources (see [Resource references](#resource-references)), the workflow references of `workflowEvent` triggers (see [Workflow references](#workflow-references)), the filter trees of a `recordEvent` or `recordLifecycle` trigger's `filters` and `previousFilters` (see [Policies](#policies)), the relation paths of a `recordEvent` trigger's `relations`, the `bindings` of a `request` trigger, and the run-as rules. `previousFilters` matches the record before the change, so a trigger runs on a change from one value to another. Only the `updated` event and the `updating` hook take it. `relations` lists the relations to load with the trigger record, such as `['member', 'member.company']`: each part of a path is the key of a relation field of the resource that the part before it relates to. The deploy checks the relations of a trigger on the Roles or Permissions resource against the stored resource. A `request` trigger binds a route parameter to a record with `bindings: { member: { resource: Resources.Members.slug, lookupField?, relations?, scope? } }`, the same shape as the `bindings` of a page, and the handler receives the record as `input.member`. A `recordEvent`, `recordSchedule`, `scheduled`, or `workflowEvent` workflow needs `runAs`. A request workflow takes `authorizer`, as a page does: `'authenticated'`, or `{ resource, permissions }` with an authenticatable resource as `Resources.<Name>.slug` and permission uids as `Permissions.<Name>.uid` or `SystemPermissions.<Name>.uid`. A caller needs any one of the permissions. The build refuses a resource that is not authenticatable and a permission that the workspace does not declare. A request workflow without `authorizer` is public. A `manual` or `request` workflow can set `executionMode: 'async'` to run in the queue: the caller gets the queued run at once, without the output. Without it, the workflow runs synchronously, with a 55-second limit. The build refuses `executionMode` on another trigger, which has a fixed mode.
95
95
  - `paused: true` in a workflow config pauses the workflow. It deploys, but no route, trigger, or manual run starts it. A migration cannot be paused.
96
96
  - A `recordSchedule` trigger runs each offset from the `dateField` of each record. `timing` defaults to `'day'`, which runs at 8 a.m. in the workspace timezone on the day of the field plus the offset, and ignores the time of the field. Day timing takes whole-day offsets only, so the build refuses an offset such as `'-PT2H'` or `'+PT0M'`. `timing: 'exact'` runs at the time of the field plus the offset, for example 2 hours before a class with `offsets: ['-PT2H']`. Exact timing needs a datetime field.
97
97
  - A workflow with `export const config = { title, ... }` and `export default defineWorkflow(handler)` or `defineWorkflow(input, handler)` still builds. The build warns at the config export and at `title`. Move the config into the `defineWorkflow` call and rename `title` to `name`. A workflow cannot have both forms of config, or both `name` and `title`. A `validateInput` export still runs before the handler, with a warning; move it into the config as `validate`. A workflow cannot have both.
@@ -182,6 +182,7 @@ export default definePage(
182
182
 
183
183
  - `bindings` is keyed by route parameter name. Each value is `{ resource: Resources.<Name>.slug, lookupField?, relations?, scope? }`.
184
184
  - A binding key is equal to its route parameter name. The parameter matches the record id unless `lookupField` is set.
185
+ - A `request` trigger of `defineWorkflow` takes the same `bindings` option, with the same type (`RouteBinding`) and the same checks. The build reports a key that is not a route parameter, an unknown resource, a `lookupField` that is not a field of the resource, an unknown option, and an unknown `scope`, at the same message for a page and a workflow.
185
186
  - When you rename a route parameter, also change its binding key, each `params.<old>` and `bindings.<old>` read, each `getRouteParam()` call, and each `utils.page.url(Pages.<Name>.uid, {...})` and `utils.page.navigate(Pages.<Name>.uid, {...})` call that passes it. `diagonal check --fix` does not rename route parameters.
186
187
  - The build warns when a public page (`authorizer: null`) binds a resource whose `show` policy is not public. Route binding fails for visitors, so they cannot open the page.
187
188