@diagonal-hq/cli 0.14.2 → 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.
Files changed (4) hide show
  1. package/README.md +32 -16
  2. package/dist/cli.mjs +5948 -5046
  3. package/dist/index.d.ts +48 -27
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -70,11 +70,11 @@ 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 only the uid of each `notifications/<key>/type.ts`, `notifications/<type key>/<key>.template.ts`, and `email-layouts/<key>/layout.ts` file. Each file must have a default export of its `defineX({...})` call, and it can import only `@diagonal-hq/cli` and `@app/generated/resources`. The editor type-checks the rest of the definition. The build ignores the other files in `notifications/` and `email-layouts/`. See [Notifications](#notifications).
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 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`. No definition uses `slug` yet.
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.
@@ -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 next to it, written as `{ file: './standard.email.liquid' }`.
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
- key: 'member-welcome',
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
- key: 'standard',
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: 'page.url',
283
- settings: { page: 'portal/home' }
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
- key: 'standard',
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. These rules need other files or server data, so the editor does not check them yet:
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 key, 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.
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