@diagonal-hq/cli 0.20.3 → 0.21.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.
package/README.md CHANGED
@@ -69,13 +69,14 @@ The build reads each file with a parser. It runs only the workflow and migration
69
69
 
70
70
  - `defineConfig`, `defineResource`, and the first argument of `definePage` must be static literals. `diagonal.config.ts` goes through the checks in [Workspace config](#workspace-config). The `field.<type>({...})` calls are the only calls that the build accepts in this data. The `seo` values of a page are the one exception: a `seo` value can be a one-expression function. See [Page bindings and seo](#page-bindings-and-seo).
71
71
  - Each `resources/*.ts` file goes through the resource checks in [Resources and fields](#resources-and-fields).
72
- - The build removes imports from `@diagonal-hq/cli`. Pages, layouts, components, and workflow scripts can import workspace files through `@app/`. A resource file can import only `@app/generated/resources` and `@app/generated/pages`. A notification type, template, or schedule file can import only `@app/generated/resources`, `@app/generated/notification-types`, and `@app/generated/email-layouts`, and an email layout file only `@app/generated/resources`. Workflow scripts can also import `@diagonal/workflow` and `@diagonal/workflow/workspace`. Other external imports in these source files are rejected.
72
+ - The build removes imports from `@diagonal-hq/cli`. Pages, layouts, components, and workflow scripts can import workspace files through `@app/`. A resource file can import only `@app/generated/resources`, `@app/generated/pages`, and `@app/generated/record-bindings`. A notification type, template, or schedule file can import only `@app/generated/resources`, `@app/generated/notification-types`, `@app/generated/email-layouts`, and `@app/generated/record-bindings`, and an email layout file only `@app/generated/resources` and `@app/generated/record-bindings`. `diagonal.config.ts` and each `workspace-fields/` file can also import `@app/generated/record-bindings`. Write `RecordBindings.<Name>.reference` from that module where a value needs a live record ID that each workspace selects. Workflow scripts can also import `@diagonal/workflow` and `@diagonal/workflow/workspace`. Other external imports in these source files are rejected.
73
73
  - The second argument of `definePage`, and the default export of a layout or component file, must be one function. A page imports a layout and passes it as `layout: AppLayout`, and imports a component and renders it as `<ClassCard />`. A string `layout` and `Sdk.Custom.<Name>` fail with the import to write. A component is any `.tsx` module that a page or layout reaches and that default-exports a PascalCase function, directly or as `export default Name` for a `const` function or arrow function of the file. It can also have named exports. It gets the page lint and type check at its own path.
74
74
  - Each page has one name: the studly case of each folder and file name below `pages/`, joined with `_`, without `.tsx`. A route parameter segment such as `[id]` gets the prefix `$`. `pages/sign-in.tsx` is `Pages.SignIn`, `pages/members/[id].tsx` is `Pages.Members_$Id`, `pages/index.tsx` is `Pages.Index`, and `pages/classes/index.tsx` is `Pages.Classes_Index`. A name that starts with a digit gets the prefix `Page`, so `pages/404.tsx` is `Pages.Page404`. Two page files with one name, such as `pages/members-list.tsx` and `pages/members_list.tsx`, fail at the second file: `The page files A and B both have the name Pages.Members_$Id. Rename one of the files`. `definePage` has no `key` option. The check refuses it with `Unknown page option "key"`.
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 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
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`.
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.
79
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.
80
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.
81
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.
@@ -84,7 +85,7 @@ The build reads each file with a parser. It runs only the workflow and migration
84
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`.
85
86
  - The build ignores the files at the root other than `diagonal.config.ts`, `assets.ts`, and `redirects.ts`, dotfiles, and `node_modules`. A `permissions.ts` or `roles.ts` at the root is an error. It does not build the files in `generated/`. It writes `generated/resources.ts`, `generated/workflows.ts`, `generated/notification-types.ts`, and `generated/email-layouts.ts` in every build, `generated/workspace-fields.ts` when the workspace has a file in `workspace-fields/`, `generated/permissions.ts` when the workspace has a file in `permissions/`, `generated/roles.ts` when it has a file in `roles/`, and `generated/assets.ts` when it has `assets.ts`. See [Permissions](#permissions) and [Roles](#roles).
86
87
 
87
- - The build reads each `notifications/<folder>/type.ts` as a notification type, each `notifications/<folder>/<name>.template.ts` as a notification template, each `notifications/<folder>/<handle>.schedule.ts` as a notification schedule, and each `email-layouts/<folder>/layout.ts` as an email layout. Each file must have a default export of its `defineX({...})` call. Its imports follow the rule above: a type, template, or schedule file can import `@app/generated/resources`, `@app/generated/notification-types`, and `@app/generated/email-layouts`, and an email layout file only `@app/generated/resources`. The build checks the types, templates, layouts, and schedules against each other and against the resources. It ignores the other files in `notifications/` and `email-layouts/`, such as `.liquid` files, `fixtures/` folders, and a definition at another path. A publish writes each type, template, layout, and schedule into the workspace. See [Notifications](#notifications).
88
+ - The build reads each `notifications/<folder>/type.ts` as a notification type, each `notifications/<folder>/<name>.template.ts` as a notification template, each `notifications/<folder>/<handle>.schedule.ts` as a notification schedule, and each `email-layouts/<folder>/layout.ts` as an email layout. Each file must have a default export of its `defineX({...})` call. Its imports follow the rule above: a type, template, or schedule file can import `@app/generated/resources`, `@app/generated/notification-types`, `@app/generated/email-layouts`, and `@app/generated/record-bindings`, and an email layout file only `@app/generated/resources` and `@app/generated/record-bindings`. The build checks the types, templates, layouts, and schedules against each other and against the resources. It ignores the other files in `notifications/` and `email-layouts/`, such as `.liquid` files, `fixtures/` folders, and a definition at another path. A publish writes each type, template, layout, and schedule into the workspace. See [Notifications](#notifications).
88
89
 
89
90
  ## Definition uids and slugs
90
91
 
@@ -327,7 +328,8 @@ export default defineWorkspaceField({
327
328
  - `definition` is a `field.<type>({...})` builder. A workspace field takes `label`, `description`, `required`, `guard`, and `settings`. It cannot be a `relation`, and the builder has no `uid`, `unique`, `index`, `computed`, `getter`, or `setter`.
328
329
  - `value` is the value of the field. It is required: write `null` for a field without a value. The type of `value` follows the field type. The file owns the value.
329
330
  - The build does not use `default`. A `default` in `definition` gives a warning at the `default`, and the field takes its value from `value`.
330
- - The check refuses a value that does not match its definition at the line of the value. The deploy checks each value again with the `guard` rules of the field.
331
+ - The check refuses a value that does not match its definition at the line of the value. The deploy checks each literal value again with the `guard` rules of the field.
332
+ - A value can contain `RecordBindings.<Name>.reference` from `@app/generated/record-bindings`, for example as the value of a UUID field. The deploy stores the reference and does not check it with the `guard` rules. Each read resolves the reference to the record that the workspace selects, and then checks the resolved value with the `guard` rules. A missing selection, a missing or archived record, or a failed guard rule gives a setup error when a page or workflow reads that field. The other fields stay available.
331
333
  - Each deploy writes the definition and the value to the workspace settings collection. The API, `WorkspaceStore`, and the Page SDK read them. A redeploy with a changed value, label, setting, key, or file name updates the same field. A key change moves the value to the new key, and each Liquid template or string that names the old key stops finding it. A field keeps its type: give the file a new uid to make a new field with another type.
332
334
  - A removed file archives its field on the next deploy, and a file with the same uid restores it. A field that something still uses, such as a workflow, stops the deploy with the message of the entity graph.
333
335
  - A deploy refuses a field without a `uid`. Run `diagonal check` to write one.
@@ -657,8 +659,8 @@ export default defineNotificationSchedule({
657
659
 
658
660
  This sends the Standard welcome 7 days after each active member's `joined_on`.
659
661
 
660
- - `offsets` holds one to 30 distinct ISO 8601 durations in days, hours, or minutes: `'-P30D'` is 30 days before, `'P0D'` is the day, `'-PT2H'` is 2 hours before. A duration without a sign counts after the date, so `'P7D'` and `'+P7D'` are the same offset.
661
- - `timing` defaults to `'day'`, which sends at 8 a.m. in the workspace timezone. `'exact'` sends at the event start plus the offset and needs an event schedule field.
662
+ - `offsets` holds one to 30 distinct ISO 8601 durations in days, hours, or minutes: `'-P30D'` is 30 days before, `'P0D'` is the day, `'-PT2H'` is 2 hours before in exact timing. A duration without a sign counts after the date, so `'P7D'` and `'+P7D'` are the same offset.
663
+ - `timing` defaults to `'day'`, which sends at 8 a.m. in the workspace timezone on the day, so `'-PT2H'` sends at 6 a.m. `'exact'` sends at the time of a datetime field or the start of an event schedule field, plus the offset.
662
664
  - `filters` is optional. It is a filter tree, `{ operator, conditions }`, with the shape of a policy `filter`. See [Policies](#policies).
663
665
  - `recipient` is the path of single-record relations from the source record to the type's recipient, for example `'member'` on a `memberships` source. Leave it out when the source resource is the recipient, as here.
664
666
  - `variables` maps each variable of the type to a field path on the source record. A record variable maps to a record's `id`.
@@ -721,7 +723,7 @@ The editor checks the shape of each definition. `diagonal check` and the build a
721
723
  - A template has at most 50 references. A reference key starts with a lowercase letter, has only a-z, 0-9, and `_`, and has at most 64 characters. A label has at most 255 characters. The generator is one that a file can deploy.
722
724
  - A layout's slug and its folder name are not `default`, and its `body` is not empty. A layout field key starts with a letter or `_` and has only letters, digits, and `_`. Each field has a `label` of at most 255 characters.
723
725
  - A schedule has a `name` of 1 to 255 characters. Its `type` names a type of the workspace files that has a `recipient`, and its `template` names a template of that type that has an email. `source.resource` is a resource of the workspace. A schedule's `filters` is a filter tree with a known operator in each condition.
724
- - A schedule's `dateField` is a date, datetime, or event schedule field of the source resource. Exact timing needs an event schedule field. `offsets` holds 1 to 30 distinct durations.
726
+ - A schedule's `dateField` is a date, datetime, or event schedule field of the source resource. Exact timing needs a datetime or event schedule field. `offsets` holds 1 to 30 distinct durations.
725
727
  - A schedule's `recipient` path reaches the type's recipient resource through relations that each hold one record. Without `recipient`, the source resource is the recipient resource.
726
728
  - Each key of a schedule's `variables` is a variable of the type, and each path reaches a field of the source record or of a record that its single-record relations reach. A record variable maps to the id of a record of its resource, for example `'first_event.id'`. Each required variable is mapped.
727
729