@diagonal-hq/cli 0.33.7 → 0.33.9

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
@@ -75,11 +75,11 @@ The build reads each file with a parser. It runs only the workflow and migration
75
75
  - 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.
76
76
  - 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.`
77
77
  - 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)`.
78
- - Each `workflows/<name>.ts` is a script workflow. Its default export is `defineWorkflow({ uid, name, trigger, runAs?, input?, 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` 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. `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 tree of a `recordEvent` trigger's `filters` (see [Policies](#policies)), and the run-as rules. A `recordEvent`, `recordSchedule`, `scheduled`, or `workflowEvent` workflow needs `runAs`.
78
+ - Each `workflows/<name>.ts` is a script workflow. Its default export is `defineWorkflow({ uid, name, trigger, runAs?, 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 tree of a `recordEvent` trigger's `filters` (see [Policies](#policies)), and the run-as rules. A `recordEvent`, `recordSchedule`, `scheduled`, or `workflowEvent` workflow needs `runAs`.
79
79
  - 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.
80
80
  - 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.
81
81
  - Each `skills/<name>.md` is a workspace AI skill: YAML front matter with `uid`, `name`, `description`, and optionally `enabled` and `manualOnly`, then a Markdown body with its instructions. The build validates the front matter, the uid (see [Definition uids and slugs](#definition-uids-and-slugs)), and that no two skill files declare one `name`. The build writes `generated/skills.ts`, which exports `Skills`: the `uid`, `name`, and `description` of each skill, keyed by the studly case of its file name, so `skills/front-desk.md` is `Skills.FrontDesk`. It never holds the instructions. Import it from `@app/generated/skills`. The build replaces each `Skills.<Name>.<key>` reference in a page or workflow with its value, as it does for `Resources`. A file name that gives no identifier, and a second file with one name, get no entry and a warning.
82
- - The build removes the config options other than `input` and `validate`, and the `@diagonal-hq/cli` imports, from the workflow, with spaces in their place, and compiles the rest with the workflow script compiler against the workspace resources. The compiled script calls `defineWorkflow({ input, validate }, handler)`, so a change to a static option does not change the compiled code. A compiler error has the line and column of the workflow file.
82
+ - The build removes the config options other than `input`, `output`, and `validate`, and the `@diagonal-hq/cli` imports, from the workflow, with spaces in their place, and compiles the rest with the workflow script compiler against the workspace resources. The compiled script calls `defineWorkflow({ input, output, validate }, handler)`, so a change to a static option does not change the compiled code. A compiler error has the line and column of the workflow file.
83
83
  - `workflows/<name>.test.ts` tests `workflows/<name>.ts` with `node:test` and `node:assert`. It imports the workflow, `runWorkflow` and `MockTransport` from `@diagonal/workflow/testing`, `Resources` from `@app/generated/resources`, and `Assets` from `@app/generated/assets`. The build transpiles the test and the workflows and runs them in one Node process. The process can read only its own temporary directory, cannot start processes, and has an empty environment. Each failing test is an error at the test. A test file without a workflow is an error.
84
84
  - Each `migrations/YYYYMMDDHHmmss_name.ts` is an ordinary script workflow. Its filename is a 14-digit timestamp, `_`, then a lowercase name with underscores, for example `20261105143000_backfill_post_slug.ts`. Its default export is `defineWorkflow({ name, trigger: { type: 'manual' } }, handler)` from `@diagonal/workflow`, with the same config rules as a workflow. It always runs as system, and the build ignores a `runAs` that the file sets. The script uses the ordinary workflow SDK for reads and writes. Manual and nested workflow calls cannot run migration files. After deployment activation, all unseen filenames queue independently as ordinary asynchronous workflows and can run concurrently. The timestamp sorts filenames for listing and history and does not enforce execution order. Put dependent operations in one script. The platform records each filename for the workspace environment in Postgres before launch and records its terminal outcome. A recorded filename never runs again, including when its workflow fails. Read the existing workflow execution status for errors, then add a new migration to correct them. Schema guards still run before migration launch; deploy an optional field and its backfill before a later release makes it required.
85
85
  - `migrations/<id>.test.ts` tests `migrations/<id>.ts` in the same way that a workflow test tests its workflow. It imports the migration, and `runWorkflow` from `@diagonal/workflow/testing`.
@@ -454,7 +454,7 @@ The build reads `Permissions.<Name>.uid` and `SystemPermissions.<Name>.uid` like
454
454
 
455
455
  Page code reads one member of `Permissions` at a time, such as `Permissions.ManageBookings.uid`. The build replaces each member reference with its value. A page cannot use `Permissions` as a whole, for example in `Object.keys(Permissions)` or `Object.values(Permissions)`. A dynamic import of `@app/generated/permissions` and a re-export of `Permissions` also fail the build. To list some permissions, write an array of member references, such as `[Permissions.ManageBookings.uid, Permissions.ManageEvents.uid]`.
456
456
 
457
- The deploy writes every system permission and each permission of `permissions/` as the records of the platform Permissions resource, each with its uid as its record id. Then the resource is locked: the Security admin shows the permissions read-only, and every other write to them is refused. A new system permission appears on the next deploy with no change to the files. The System Administrator role holds every permission. A deploy that removes a permission that a role other than System Administrator grants is refused: remove the grant first.
457
+ The deploy writes every system permission and each permission of `permissions/` as the records of the platform Permissions resource, each with its uid as its record id. Then the resource is locked, so only the deploy writes the records. The Security admin, the record API, and the AI record plans create, edit, delete, and restore a custom permission by committing to its file and deploying it. A new system permission appears on the next deploy with no change to the files. The System Administrator role holds every permission. A deploy that removes a permission that a role other than System Administrator grants is refused: remove the grant first.
458
458
 
459
459
  The first deploy of a workspace matches each seeded system permission by its slug. It changes the id of the stored record to the uid and rewrites the role grants, so the roles keep their permissions. The deploy does not take over a custom permission that the workspace created. A declared permission whose slug a stored record already has blocks the deploy: delete that record, or remove the declaration. A stored custom permission that `permissions/` does not declare also blocks that deploy: declare it with its current record id as its `uid`, or delete it first. To get the record id, open the actions of the permission in the Security admin and select **Copy Permission ID**. Declare the permission with that `uid` in the file of its current slug, so it keeps its id and its role grants. Do not let `diagonal check` generate a new uid for it, because a new uid blocks the deploy.
460
460
 
@@ -489,7 +489,7 @@ export default defineRole({
489
489
  - `@diagonal-hq/cli` exports `SystemRoles`. The platform declares `SystemRoles.SystemAdministrator`, with a fixed `uid`. That role holds every permission, declared and system, so `roles/` cannot declare or change it.
490
490
  - A `roles.ts` file at the root is an error: move each role to `roles/<slug>.ts`.
491
491
 
492
- The deploy writes each role of `roles/` and System Administrator as the records of the platform Roles resource, each with its uid as its record id. Then the resource is locked: the Security admin shows the roles and their grants read-only. The assignment of roles to people stays data, so the Security admin still assigns them.
492
+ The deploy writes each role of `roles/` and System Administrator as the records of the platform Roles resource, each with its uid as its record id. Then the resource is locked, so only the deploy writes the records. The Security admin, the record API, and the AI record plans change a role and its grants by committing to its file and deploying it; only a person with `access_system_admin` can make a role grant `access_system_admin`. The assignment of roles to people stays data, so the Security admin still assigns them.
493
493
 
494
494
  ## Workflow references
495
495