@diagonal-hq/cli 0.14.1 → 0.15.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 +36 -19
- package/dist/cli.mjs +6444 -5435
- package/dist/fields.generated.d.ts +5 -1
- package/dist/index.d.ts +48 -27
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -70,20 +70,20 @@ The build reads each file with a parser. It runs only the workflow tests.
|
|
|
70
70
|
- `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`, and `Resources` from `@app/generated/resources`. 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.
|
|
71
71
|
- The build ignores the files at the root other than `diagonal.config.ts` and `assets.ts`, dotfiles, and `node_modules`. It does not build the files in `generated/`. It writes `generated/resources.ts` in every build.
|
|
72
72
|
|
|
73
|
-
- The build reads
|
|
73
|
+
- The build reads each `notifications/<folder>/type.ts` as a notification type, each `notifications/<folder>/<name>.template.ts` as a notification template, and each `email-layouts/<folder>/layout.ts` as an email layout. Each file must have a default export of its `defineX({...})` call, and it can import only `@diagonal-hq/cli` and `@app/generated/resources`. The build checks the types, templates, and layouts against each other. It ignores the other files in `notifications/` and `email-layouts/`, such as `.liquid` files, `fixtures/` folders, schedules, and a definition at another path. A publish does not write the definitions into the workspace yet. See [Notifications](#notifications).
|
|
74
74
|
|
|
75
75
|
## Definition uids and slugs
|
|
76
76
|
|
|
77
|
-
A definition can have two identity options. A resource, a page, a workflow `config`, a notification type, a notification template, an email layout, and the front matter of a skill file have a `uid`.
|
|
77
|
+
A definition can have two identity options. A resource, a field, a relation inverse, a page, a workflow `config`, a notification type, a notification template, an email layout, and the front matter of a skill file have a `uid`. A notification type, a notification template, and an email layout also have a `slug`.
|
|
78
78
|
|
|
79
79
|
- `uid` is the stable identity of the definition. Its value is a lowercase UUID string literal, such as `uid: '019a4d6e-3c2f-7b8a-9d1e-5f6a7b8c9d0e'`. In skill front matter, it is a YAML string, such as `uid: 019a4d6e-3c2f-7b8a-9d1e-5f6a7b8c9d0e`. A file move, a file rename, or a name change keeps the uid. Do not change a uid.
|
|
80
80
|
- `slug` is the editable, user-facing name of the definition. It is kebab-case: lowercase letters and digits in groups that one `-` joins, such as `job-postings`. A slug change keeps the uid.
|
|
81
81
|
|
|
82
|
-
`diagonal check` writes a new uid into each definition that has none. It adds `uid: '<uuid>'` as the first option of the `defineX()` object or of the `export const config` object of a workflow, or `uid: <uuid>` as the first line of the front matter of a skill file, and leaves the rest of the file unchanged. Commit the change.
|
|
82
|
+
`diagonal check` writes a new uid into each definition that has none. It adds `uid: '<uuid>'` as the first option of the `defineX()` object, of each `field.<type>({...})` call and `settings.inverse` object, or of the `export const config` object of a workflow, or `uid: <uuid>` as the first line of the front matter of a skill file, and leaves the rest of the file unchanged. Commit the change.
|
|
83
83
|
|
|
84
84
|
The platform writes the missing uids too: a save in Files, and every other commit that the platform makes, adds a uid to each definition of the changed files that has none. A git push does not, so a pushed definition without a uid fails the deploy, and the error tells you to run `diagonal check`.
|
|
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
|
|
86
|
+
A uid is unique among the definitions of one type. A field uid is unique in its resource, and an inverse field counts as a field of its target resource. Two definitions of one type with one uid are an error at the second definition, 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.
|
|
87
87
|
|
|
88
88
|
## Page bindings and seo
|
|
89
89
|
|
|
@@ -218,7 +218,14 @@ The file gives the resource its `Resources` entry, so source names it like any o
|
|
|
218
218
|
|
|
219
219
|
## Notifications
|
|
220
220
|
|
|
221
|
-
A notification has a type, one or more templates, and optionally an email layout. A schedule sends a template on dates of a resource, for example 7 days after each member's `joined_on`. Each definition is a static literal. Its Liquid is inline text or a `.liquid` file
|
|
221
|
+
A notification has a type, one or more templates, and optionally an email layout. A schedule sends a template on dates of a resource, for example 7 days after each member's `joined_on`. Each definition is a static literal. Its Liquid is inline text or a `.liquid` file in the folder of the definition, written as `{ file: './standard.email.liquid' }`.
|
|
222
|
+
|
|
223
|
+
Each type, template, and layout has a `uid` and a `slug`. See [Definition uids and slugs](#definition-uids-and-slugs).
|
|
224
|
+
|
|
225
|
+
- `uid` is the stable identity of the definition. `diagonal check` writes it. A publish writes the definition into the row with this uid, so the row keeps its id when you change the slug, rename the definition, or move the file.
|
|
226
|
+
- `slug` is the name that other files use, for example `'member-welcome'`. It follows the slug rule and has at most 64 characters. A template refers to its type by `type`, the type names its default template by `defaultTemplate`, and a template names its layout by `email.layout`. When you change a slug, change each reference too. The check reports each reference that breaks.
|
|
227
|
+
|
|
228
|
+
The paths below are required. The build reads a type only as `type.ts` in a folder of `notifications/`, a template only as a `<name>.template.ts` file in a folder of `notifications/`, and a layout only as `layout.ts` in a folder of `email-layouts/`. It ignores a definition at any other path. The folder and file names do not have to equal the slugs: a template names its type by `type`, not by its folder.
|
|
222
229
|
|
|
223
230
|
```text
|
|
224
231
|
notifications/
|
|
@@ -246,7 +253,7 @@ import { defineNotificationType, field } from '@diagonal-hq/cli';
|
|
|
246
253
|
|
|
247
254
|
export default defineNotificationType({
|
|
248
255
|
uid: '019a4d6e-3c2f-7b8a-9d1e-5f6a7b8c9d0e',
|
|
249
|
-
|
|
256
|
+
slug: 'member-welcome',
|
|
250
257
|
name: 'Member welcome',
|
|
251
258
|
recipient: { resource: Resources.Members.slug },
|
|
252
259
|
variables: {
|
|
@@ -260,11 +267,12 @@ export default defineNotificationType({
|
|
|
260
267
|
A template has an email, an SMS, or both. A channel is on when the template has it. The email gives a Liquid value for each field of its layout. `layout` defaults to `'default'`, the built-in layout, which has one field, `content`. `references` adds generators that the template reads as `{{ ref.<key> }}`.
|
|
261
268
|
|
|
262
269
|
```ts
|
|
270
|
+
import { Resources } from '@app/generated/resources';
|
|
263
271
|
import { defineNotificationTemplate } from '@diagonal-hq/cli';
|
|
264
272
|
|
|
265
273
|
export default defineNotificationTemplate({
|
|
266
274
|
uid: '019a4d6e-4a1b-7c2d-8e3f-6a7b8c9d0e1f',
|
|
267
|
-
|
|
275
|
+
slug: 'standard',
|
|
268
276
|
type: 'member-welcome',
|
|
269
277
|
name: 'Standard welcome',
|
|
270
278
|
email: {
|
|
@@ -279,13 +287,16 @@ export default defineNotificationTemplate({
|
|
|
279
287
|
references: {
|
|
280
288
|
portal_link: {
|
|
281
289
|
label: 'Member portal',
|
|
282
|
-
generator: '
|
|
283
|
-
settings: {
|
|
284
|
-
}
|
|
290
|
+
generator: 'workspace.login_url',
|
|
291
|
+
settings: { resource: Resources.Members.slug }
|
|
292
|
+
},
|
|
293
|
+
today: { label: 'Today', generator: 'date.current' }
|
|
285
294
|
}
|
|
286
295
|
});
|
|
287
296
|
```
|
|
288
297
|
|
|
298
|
+
A file can use three generators: `date.current` and `time.current`, which take no settings, and `workspace.login_url`, which takes the resource whose members sign in. The template editor also offers `page.url`, `workflow.url`, and `calendar.generate_link`. They need a page, a workflow, or a variable binding that a file cannot hold yet, so the check refuses them.
|
|
299
|
+
|
|
289
300
|
An email layout is the frame that templates fill in. Each field is a slot that a template fills with Liquid.
|
|
290
301
|
|
|
291
302
|
```ts
|
|
@@ -293,7 +304,7 @@ import { defineEmailLayout } from '@diagonal-hq/cli';
|
|
|
293
304
|
|
|
294
305
|
export default defineEmailLayout({
|
|
295
306
|
uid: '019a4d6e-5b2c-7d3e-9f4a-7b8c9d0e1f2a',
|
|
296
|
-
|
|
307
|
+
slug: 'standard',
|
|
297
308
|
name: 'Standard',
|
|
298
309
|
body: { file: './body.liquid' },
|
|
299
310
|
fields: {
|
|
@@ -336,13 +347,18 @@ A deployed schedule is a System Notification. It sends with no staff identity, a
|
|
|
336
347
|
|
|
337
348
|
### Rules
|
|
338
349
|
|
|
339
|
-
The editor checks the shape of each definition.
|
|
350
|
+
The editor checks the shape of each definition. `diagonal check` and the build also check these rules, and give the file, line, and column of each problem:
|
|
351
|
+
|
|
352
|
+
- Each type, template, and layout has a `uid` and a `slug` of at most 64 characters. No two definitions of one kind have the same uid. No two types, and no two layouts, have the same slug. No two templates of one type have the same slug. No two layouts have the same name. A `name` has 1 to 255 characters.
|
|
353
|
+
- A `{ file }` Liquid source names a `.liquid` file in the folder of the definition, and the file exists.
|
|
354
|
+
- A type's `recipient` resource and the resource of each record variable are resources of the workspace. A type has at most 100 variables. A variable key starts with a letter or `_` and has only letters, digits, and `_`. A variable cannot be named `record` or `ref`: templates read the recipient as `{{ record.* }}` and the generators as `{{ ref.* }}`. A variable is a value that the sender passes, so a `field` builder cannot have `default`, `unique`, `index`, `guard`, `computed`, `getter`, `setter`, or `setterWhenEmpty`.
|
|
355
|
+
- A type has at least one template, and its `defaultTemplate` names one of them.
|
|
356
|
+
- A template's `type` names a type of the workspace files. A template has an email, an SMS, or both. An email `subject` has 1 to 10,000 characters. `email.layout` names a layout of the workspace files, or `'default'`. An email's `fields` match the fields of its layout and fill each required field. A layout field key differs from `record` and from each variable key of the template's type. The built-in layout has the field `content`. An SMS `body` is not empty.
|
|
357
|
+
- 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.
|
|
358
|
+
- A layout's slug is 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.
|
|
359
|
+
|
|
360
|
+
These rules need other files or server data, so the check does not check them yet:
|
|
340
361
|
|
|
341
|
-
- A type cannot have a variable named `record` or `ref`. Templates read the recipient as `{{ record.* }}` and the generators as `{{ ref.* }}`.
|
|
342
|
-
- A template's `type` names an existing type, and the type's `defaultTemplate` names one of its templates.
|
|
343
|
-
- An email's `fields` match the fields of its layout, and fill each required field.
|
|
344
|
-
- A layout cannot use the key `default`.
|
|
345
|
-
- Each reference key starts with a lowercase letter. A template has at most 50 references, and each one names a generator that the server has.
|
|
346
362
|
- The `recipient` resource can receive notifications.
|
|
347
363
|
- A schedule's `type` is the type of its folder, and its `template` names a template of that type that has an email.
|
|
348
364
|
- A schedule's `dateField` is a date, datetime, or event schedule field of the source resource. Exact timing needs an event schedule field.
|
|
@@ -354,7 +370,7 @@ The editor checks the shape of each definition. These rules need other files or
|
|
|
354
370
|
Fixtures are sample data for previews. They are not tests, and they are never sent. A type folder and a layout folder can each have a `fixtures/` folder of JSON files. `default.json` is the case that a preview opens first.
|
|
355
371
|
|
|
356
372
|
- A layout fixture holds a value for each layout field, for example `{ "heading": "Welcome aboard", "body": "<p>Hi Avery.</p>" }`.
|
|
357
|
-
- A notification fixture holds a template
|
|
373
|
+
- A notification fixture holds a template slug, a sample recipient, and sample variables, for example `{ "template": "standard", "recipient": { "name": "Avery Shaw", "email": "avery@example.com", "phone": null }, "variables": { "joined_on": "2026-11-02", "first_event": { "name": "Open house" } } }`. A record variable holds the record's fields.
|
|
358
374
|
- A schedule has no fixtures. The type's fixture already holds the sample recipient and variables.
|
|
359
375
|
|
|
360
376
|
## Resources and fields
|
|
@@ -371,6 +387,7 @@ There is one `field.<type>` builder for each resource field type, in camel case:
|
|
|
371
387
|
|
|
372
388
|
A builder takes these options:
|
|
373
389
|
|
|
390
|
+
- `uid`: the stable identity of the field, unique in its resource. `diagonal check` writes a missing one. See [Definition uids and slugs](#definition-uids-and-slugs). The deploy stores it on the field, but the stored field id still derives from the resource and the field key, so a renamed key is still a new field.
|
|
374
391
|
- `label`, `description`, `required`, `default`, `unique`, and `index`.
|
|
375
392
|
- `guard`: more validation rules, for example `['max:255']`. Use `required` for the `required` and `nullable` rules.
|
|
376
393
|
- `settings`: the settings of the field type, with their stored names, and `settings.ui` for the record form. The seeder settings `seed_type`, `faker_method`, `faker_parameters`, and `seed_data` apply to every type.
|
|
@@ -378,7 +395,7 @@ A builder takes these options:
|
|
|
378
395
|
- `getter`: a resolver tree that transforms the stored value when it is read.
|
|
379
396
|
- `setter`: a resolver tree that computes the stored value before each create and update. `setterWhenEmpty: true` runs it only when the value is null or empty.
|
|
380
397
|
|
|
381
|
-
`field.select` takes `options` and `field.relation` takes `resource` (`Resources.<Name>.slug`) and `type` as options. Other settings go in `settings`. A setting that an option writes, such as `settings.unique`, is refused. A relation can declare `settings.inverse: { key, label?, settings? }`. The build then adds the inverse relation field to the target resource. A target that declares a field with the same key is an error.
|
|
398
|
+
`field.select` takes `options` and `field.relation` takes `resource` (`Resources.<Name>.slug`) and `type` as options. Other settings go in `settings`. A setting that an option writes, such as `settings.unique`, is refused. A relation can declare `settings.inverse: { uid, key, label?, settings? }`. `uid` is the uid of the inverse field. The build then adds the inverse relation field to the target resource. A target that declares a field with the same key is an error.
|
|
382
399
|
|
|
383
400
|
The platform deploy validates every field again with the rules of the resource builder, so a value that the build cannot check, such as an unknown guard rule, fails the deploy with the file path.
|
|
384
401
|
|