@diagonal-hq/cli 0.13.0 → 0.14.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 +81 -4
- package/dist/cli.mjs +1675 -979
- package/dist/index.d.ts +172 -18
- package/dist/index.js +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
This package is the authoring SDK for file-based workspaces. A workspace repository installs it as a dev dependency. It gives these things:
|
|
4
4
|
|
|
5
|
-
- The configuration helpers: `defineConfig`, `defineResource`, `definePage`, `defineNavigation`, `defineAssets`, `asset.version`, `defineNotificationType`, `defineNotificationTemplate`, `defineEmailLayout`, `defineNotificationSchedule`, and the `field` builders. Each `define*` function returns its first argument. Each `field.<type>(options)` call returns `{ $field, ...options }`, where `$field` is the stored field type. The package root exports them as ESM JavaScript with declarations, so a Vite build or a Node script can import a configuration file.
|
|
5
|
+
- The configuration helpers: `defineConfig`, `defineResource`, `definePage`, `text.template`, `defineNavigation`, `defineAssets`, `asset.version`, `defineNotificationType`, `defineNotificationTemplate`, `defineEmailLayout`, `defineNotificationSchedule`, and the `field` builders. Each `define*` function returns its first argument. Each `field.<type>(options)` call returns `{ $field, ...options }`, where `$field` is the stored field type. The package root exports them as ESM JavaScript with declarations, so a Vite build or a Node script can import a configuration file.
|
|
6
6
|
- Types for the helpers, `WorkflowConfig`, and the `Sdk` and `React` globals.
|
|
7
7
|
- Editor types for the workflow script SDK: `@diagonal/workflow`, `@diagonal/workflow/testing`, and `@diagonal/workflow/workspace`.
|
|
8
8
|
- The `diagonal check` command. It runs the same build and checks that a platform deploy runs, including the workflow tests. It also writes `generated/resources.ts` and the missing definition uids.
|
|
@@ -19,10 +19,11 @@ npm run check
|
|
|
19
19
|
`npm run check` runs `diagonal check .`. The command options are:
|
|
20
20
|
|
|
21
21
|
```text
|
|
22
|
-
diagonal check [dir] [--json]
|
|
22
|
+
diagonal check [dir] [--fix] [--json]
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
- `dir` is the workspace root. The default is the current directory.
|
|
26
|
+
- `--fix` rewrites the deprecated page options to their new shape. See [Page bindings and seo](#page-bindings-and-seo).
|
|
26
27
|
- `--json` prints `{ "ok": boolean, "diagnostics": [...] }`.
|
|
27
28
|
|
|
28
29
|
Each diagnostic prints as `path:line:column severity message`. The command exits with 1 when an error exists, with 2 for a usage error, and with 0 otherwise.
|
|
@@ -55,7 +56,7 @@ diagonal logs [path | execution id] [--status <status>] [--limit <1-100>] [--jso
|
|
|
55
56
|
|
|
56
57
|
The build reads each file with a parser. It runs only the workflow tests.
|
|
57
58
|
|
|
58
|
-
- `defineConfig`, `defineResource`, `defineNavigation`, and the first argument of `definePage` must be static literals. The `field.<type>({...})` calls are the only calls that the build accepts in this data.
|
|
59
|
+
- `defineConfig`, `defineResource`, `defineNavigation`, and the first argument of `definePage` must be static literals. 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).
|
|
59
60
|
- Each `resources/*.ts` file goes through the resource checks in [Resources and fields](#resources-and-fields).
|
|
60
61
|
- 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`. Workflow scripts can also import `@diagonal/workflow` and `@diagonal/workflow/workspace`. Other external imports in these source files are rejected.
|
|
61
62
|
- The second argument of `definePage`, and the default export of a layout or component file, must be one function.
|
|
@@ -84,6 +85,82 @@ The platform writes the missing uids too: a save in Files, and every other commi
|
|
|
84
85
|
|
|
85
86
|
A uid is unique among the definitions of one type. Two definitions of one type with one uid are an error at the second file, and the error names the first file. The check does not replace a duplicate uid. When you copy a definition file, delete its `uid` and run `diagonal check`. A uid that is not a lowercase UUID is an error.
|
|
86
87
|
|
|
88
|
+
## Page bindings and seo
|
|
89
|
+
|
|
90
|
+
A page binds its route parameters to records in `bindings` and sets its head tags in `seo`:
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
import { Resources } from '@app/generated/resources';
|
|
94
|
+
import { definePage, text } from '@diagonal-hq/cli';
|
|
95
|
+
|
|
96
|
+
export default definePage(
|
|
97
|
+
{
|
|
98
|
+
uid: '…',
|
|
99
|
+
key: 'class',
|
|
100
|
+
route: '/classes/{class}',
|
|
101
|
+
name: 'Class',
|
|
102
|
+
layout: 'app',
|
|
103
|
+
authorizer: null,
|
|
104
|
+
bindings: { class: { resource: Resources.Classes.slug, relations: ['instructor', 'room'] } },
|
|
105
|
+
seo: {
|
|
106
|
+
title: ({ bindings }) =>
|
|
107
|
+
text.template('{{title}} with {{instructor}} | Northside Studio', {
|
|
108
|
+
title: bindings.class.title,
|
|
109
|
+
instructor: bindings.class.instructor.name
|
|
110
|
+
}),
|
|
111
|
+
description: ({ bindings }) => bindings.class.summary,
|
|
112
|
+
image: ({ bindings }) => bindings.class.instructor.photo
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
function ClassPage() {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Bindings
|
|
122
|
+
|
|
123
|
+
- `bindings` is keyed by route parameter name. Each value is `{ resource: Resources.<Name>.slug, lookupField?, relations?, scope? }`.
|
|
124
|
+
- A binding key is equal to its route parameter name. The parameter matches the record id unless `lookupField` is set.
|
|
125
|
+
- When you rename a route parameter, also change its binding key, each `Sdk.helpers.getRouteParam()` call, and each `Pages.<key>.url({...})` call that passes it. `diagonal check --fix` does not rename route parameters.
|
|
126
|
+
- 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.
|
|
127
|
+
|
|
128
|
+
### Seo values
|
|
129
|
+
|
|
130
|
+
`seo` has the keys `title`, `description`, and `image`. Each value is one of these:
|
|
131
|
+
|
|
132
|
+
- A string. For `image`, the string is the id of a public Media Library file.
|
|
133
|
+
- `null`.
|
|
134
|
+
- A function of `bindings` with one expression. It returns a field read, a string, or `text.template(...)`. Import `text` from `@diagonal-hq/cli`.
|
|
135
|
+
|
|
136
|
+
The build reads the function's syntax and does not run it. The server resolves the value for each request. The browser module contains no `definePage` options.
|
|
137
|
+
|
|
138
|
+
- TypeScript types each binding and each field from `generated/resources.ts`. The editor completes binding names, field names, and the fields of a loaded relation. The fields of a platform resource are open and have no types.
|
|
139
|
+
- Read a binding as `bindings.<name>`, for example `bindings.class`. Do not destructure binding names: `class` is a reserved word.
|
|
140
|
+
- A seo value reads at most one relation level, for example `bindings.class.instructor.name`.
|
|
141
|
+
- `seo.image` takes a function that returns a public `file_reference` field (`settings: { visibility: 'public' }`), or a Media Library file id string.
|
|
142
|
+
- A Markdown or long text field goes into the description as written. Prefer a short plain text field.
|
|
143
|
+
- `text.template` placeholders are `{{name}}`, with no spaces. Each placeholder needs a value, and each value must be used. An empty value leaves the text around it: `'{{title}} with {{instructor}}'` gives `Morning flow with ` when the instructor has no name. The Brand Kit fallback applies only when the whole result is empty.
|
|
144
|
+
- `name` is the admin name of the page. A page with a function `seo.title` and no `name` shows its file name in the admin. Set `name` on such a page.
|
|
145
|
+
|
|
146
|
+
The build reports each of these errors at `file:line:column`:
|
|
147
|
+
|
|
148
|
+
- An unknown binding.
|
|
149
|
+
- An unknown field.
|
|
150
|
+
- A field of the wrong type.
|
|
151
|
+
- A relation that the binding does not load. Add it to `relations`.
|
|
152
|
+
- An expression that cannot become a server value, such as a template literal, `?:`, `??`, or a method call. The error for a template literal prints the `text.template` rewrite.
|
|
153
|
+
|
|
154
|
+
### Deprecated options
|
|
155
|
+
|
|
156
|
+
`params` was renamed to `bindings`. It still builds with the warning `"params" is now "bindings". Rename the option`. The flat `title`, `description`, and `ogImage` options still build with a warning that names `seo.title`, `seo.description`, or `seo.image`. A later release changes these warnings to errors.
|
|
157
|
+
|
|
158
|
+
`diagonal check --fix` rewrites `params` and the flat options to `bindings` and `seo` in place. It changes only the options object, and the rest of the file stays byte-identical. It writes in the same pass as a missing `uid`. Without `--fix`, `diagonal check` only warns. A resolver object of another type in a flat option stays in place, and the build reports an error at that option. A `text.template` or `page.binding` resolver in a flat option also stays, with the other flat options of the page, and the build warns at it. Write it as a seo function. The page builder's **Save** writes the new shape too.
|
|
159
|
+
|
|
160
|
+
The page builder shows a function seo value as read-only, with "Set in the page file". **Save** keeps the function.
|
|
161
|
+
|
|
162
|
+
The change is forward-only. A file with `seo` needs a `@diagonal-hq/cli` version that has this option. An older version reports `Unknown page option "seo"`.
|
|
163
|
+
|
|
87
164
|
## Resource references
|
|
88
165
|
|
|
89
166
|
The file name is the resource slug: `resources/job-postings.ts` declares the resource `job-postings`. A file name must start with a lowercase letter and contain only a-z, 0-9, `_`, and `-`. A resource has no `id` in source. Each resource file has a `uid`, which the deploy stores on the resource. The platform still derives the stored id from the workspace and the slug, so each branch and environment has its own ids, and a renamed file is still a new resource.
|
|
@@ -123,7 +200,7 @@ export const Resources = {
|
|
|
123
200
|
|
|
124
201
|
Each property is the studly case of a slug. Its value is the metadata that the resource file declares: the slug, the name, the singular name, the display field, and for each field its key, type, label, description, and required flag, with the options of a select field and the target slug of a relation field. It holds no policies, capabilities, indexes, or field guards and setters. A platform resource file declares only its slug. Two slugs with the same name, such as `job-postings` and `job_postings`, are an error.
|
|
125
202
|
|
|
126
|
-
Name a resource with `Resources.<Name>.slug` from `@app/generated/resources` everywhere: `field.relation({ resource: Resources.User.slug })`, a workflow `trigger.resource` and `runAs.resource`, a page `authorizer.resource` and `
|
|
203
|
+
Name a resource with `Resources.<Name>.slug` from `@app/generated/resources` everywhere: `field.relation({ resource: Resources.User.slug })`, a workflow `trigger.resource` and `runAs.resource`, a page `authorizer.resource` and `bindings.<name>.resource`, `Sdk.resource(Resources.User.slug)`, `data.search({ resource: Resources.User.slug })`, and `v.record(Resources.User.slug)`. The build reads `Resources.<Name>.slug` like a literal. An unknown name is an error at its location, and the editor reports it too. A bare `Resources.User` in one of these places is an error.
|
|
127
204
|
|
|
128
205
|
Read the other metadata in pages and workflows, for example `Resources.User.name` or `Resources.User.fields.plan.options`. The build replaces each such reference with its value, so a page carries only the metadata that it reads, and a compiled workflow changes only when a value that it reads changes. A page cannot use `Resources` as a whole, for example in `Object.keys(Resources)`, or re-export it.
|
|
129
206
|
|