@diagonal-hq/cli 0.12.5 → 0.13.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,11 +69,11 @@ The build reads each file with a parser. It runs only the workflow tests.
69
69
  - `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.
70
70
  - 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.
71
71
 
72
- - The build does not read `notifications/` or `email-layouts/` yet. The editor type-checks the shape of their definitions. See [Notifications](#notifications).
72
+ - 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
73
 
74
74
  ## Definition uids and slugs
75
75
 
76
- A definition can have two identity options. A resource, a page, a workflow `config`, and the front matter of a skill file have a `uid`. No definition uses `slug` yet.
76
+ 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`. No definition uses `slug` yet.
77
77
 
78
78
  - `uid` is the stable identity of the definition. Its value is a lowercase UUID string literal, such as `uid: '3f2b8c1e-7d4a-4e9b-a6c5-1d0e9f8a7b6c'`. In skill front matter, it is a YAML string, such as `uid: 3f2b8c1e-7d4a-4e9b-a6c5-1d0e9f8a7b6c`. A file move, a file rename, or a name change keeps the uid. Do not change a uid.
79
79
  - `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.
@@ -168,6 +168,7 @@ import { Resources } from '@app/generated/resources';
168
168
  import { defineNotificationType, field } from '@diagonal-hq/cli';
169
169
 
170
170
  export default defineNotificationType({
171
+ uid: '3f2b8c1e-7d4a-4e9b-a6c5-1d0e9f8a7b6c',
171
172
  key: 'member-welcome',
172
173
  name: 'Member welcome',
173
174
  recipient: { resource: Resources.Members.slug },
@@ -185,6 +186,7 @@ A template has an email, an SMS, or both. A channel is on when the template has
185
186
  import { defineNotificationTemplate } from '@diagonal-hq/cli';
186
187
 
187
188
  export default defineNotificationTemplate({
189
+ uid: '9a1d4e7b-2c3f-4b8a-9e6d-5f0c1b2a3d4e',
188
190
  key: 'standard',
189
191
  type: 'member-welcome',
190
192
  name: 'Standard welcome',
@@ -213,6 +215,7 @@ An email layout is the frame that templates fill in. Each field is a slot that a
213
215
  import { defineEmailLayout } from '@diagonal-hq/cli';
214
216
 
215
217
  export default defineEmailLayout({
218
+ uid: 'c7e2a9f4-1b6d-4c3e-8a5f-2d9b0e1c4a7f',
216
219
  key: 'standard',
217
220
  name: 'Standard',
218
221
  body: { file: './body.liquid' },
package/dist/cli.mjs CHANGED
@@ -302705,6 +302705,14 @@ function buildWorkflows({
302705
302705
 
302706
302706
  // scripts/lib/runtime-build/build-workspace.mjs
302707
302707
  var CONFIG_PATH = "diagonal.config.ts";
302708
+ var NOTIFICATION_TYPE_PATTERN = /^notifications\/[^/]+\/type\.ts$/;
302709
+ var NOTIFICATION_TEMPLATE_PATTERN = /^notifications\/[^/]+\/[^/]+\.template\.ts$/;
302710
+ var EMAIL_LAYOUT_PATTERN = /^email-layouts\/[^/]+\/layout\.ts$/;
302711
+ var NOTIFICATION_DEFINITIONS = {
302712
+ notification_type: { type: "notification type", define: "defineNotificationType" },
302713
+ notification_template: { type: "notification template", define: "defineNotificationTemplate" },
302714
+ email_layout: { type: "email layout", define: "defineEmailLayout" }
302715
+ };
302708
302716
  var IGNORED_DIRECTORIES = /* @__PURE__ */ new Set(["node_modules"]);
302709
302717
  function listFiles(root) {
302710
302718
  const files = [];
@@ -302817,6 +302825,13 @@ function classify(path) {
302817
302825
  return isDirectChild(path, directory) && extension === ".ts" ? "navigation" : "unknown";
302818
302826
  case "skills":
302819
302827
  return isDirectChild(path, directory) && extension === ".md" ? "skill" : "unknown";
302828
+ case "notifications":
302829
+ if (NOTIFICATION_TYPE_PATTERN.test(path)) {
302830
+ return "notification_type";
302831
+ }
302832
+ return NOTIFICATION_TEMPLATE_PATTERN.test(path) ? "notification_template" : "ignored";
302833
+ case "email-layouts":
302834
+ return EMAIL_LAYOUT_PATTERN.test(path) ? "email_layout" : "ignored";
302820
302835
  default:
302821
302836
  return "ignored";
302822
302837
  }
@@ -302971,6 +302986,13 @@ function uidDefinitionNodes(kind, ast) {
302971
302986
  const node = workflowConfigObject(ast);
302972
302987
  return node === null ? [] : [{ type: "workflow", node }];
302973
302988
  }
302989
+ case "notification_type":
302990
+ case "notification_template":
302991
+ case "email_layout": {
302992
+ const { type, define: define2 } = NOTIFICATION_DEFINITIONS[kind];
302993
+ const { declaration } = defaultExportOf(ast, { extraImports: [GENERATED_RESOURCES_MODULE] });
302994
+ return [{ type, node: expectDefineCall(declaration, define2, 1)[0] }];
302995
+ }
302974
302996
  default:
302975
302997
  return [];
302976
302998
  }
@@ -303096,6 +303118,13 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false } = {})
303096
303118
  case "navigation":
303097
303119
  output.navigation.push(buildNavigation(path, ast));
303098
303120
  break;
303121
+ case "notification_type":
303122
+ case "notification_template":
303123
+ case "email_layout":
303124
+ for (const { type, node } of uidDefinitionNodes(kind, ast)) {
303125
+ uidDefinitions.push({ type, path, source, node });
303126
+ }
303127
+ break;
303099
303128
  }
303100
303129
  } catch (error) {
303101
303130
  diagnostics.push(diagnosticFromError(path, error));
package/dist/index.d.ts CHANGED
@@ -416,8 +416,8 @@ export type NotificationVariableDefinition =
416
416
  | FieldDefinition<Exclude<FieldType, 'relation'>>
417
417
  | RecordVariableDefinition;
418
418
 
419
- /** A `notifications/<key>/type.ts` file. */
420
- export type NotificationTypeDefinition = {
419
+ /** A `notifications/<key>/type.ts` file. `diagonal check` writes a missing `uid`. */
420
+ export type NotificationTypeDefinition = UidOption & {
421
421
  /**
422
422
  * Lowercase letters, digits, and hyphens, for example `'member-welcome'`.
423
423
  * Templates, fixtures, and workflows refer to it. Moving the file keeps it.
@@ -454,8 +454,11 @@ export type NotificationTemplateEmail = {
454
454
 
455
455
  export type NotificationTemplateSms = { body: LiquidSource };
456
456
 
457
- /** A `notifications/<type key>/<key>.template.ts` file. A template has an email, an SMS, or both. */
458
- export type NotificationTemplateDefinition = {
457
+ /**
458
+ * A `notifications/<type key>/<key>.template.ts` file. A template has an email, an SMS, or both.
459
+ * `diagonal check` writes a missing `uid`.
460
+ */
461
+ export type NotificationTemplateDefinition = UidOption & {
459
462
  /** Unique within its type, for example `'standard'`. */
460
463
  key: string;
461
464
  type: NotificationTypeReference;
@@ -463,9 +466,9 @@ export type NotificationTemplateDefinition = {
463
466
  /** Generators that the template reads as `{{ ref.<key> }}`. */
464
467
  references?: { readonly [key: string]: NotificationReference };
465
468
  } & (
466
- | { email: NotificationTemplateEmail; sms?: NotificationTemplateSms }
467
- | { email?: NotificationTemplateEmail; sms: NotificationTemplateSms }
468
- );
469
+ | { email: NotificationTemplateEmail; sms?: NotificationTemplateSms }
470
+ | { email?: NotificationTemplateEmail; sms: NotificationTemplateSms }
471
+ );
469
472
 
470
473
  export declare function defineNotificationTemplate<const T extends NotificationTemplateDefinition>(
471
474
  template: T
@@ -478,8 +481,8 @@ export type EmailLayoutFieldDefinition = {
478
481
  required?: boolean;
479
482
  };
480
483
 
481
- /** An `email-layouts/<key>/layout.ts` file. */
482
- export type EmailLayoutDefinition = {
484
+ /** An `email-layouts/<key>/layout.ts` file. `diagonal check` writes a missing `uid`. */
485
+ export type EmailLayoutDefinition = UidOption & {
483
486
  /**
484
487
  * Lowercase letters, digits, and hyphens, for example `'standard'`. Templates
485
488
  * refer to it. `'default'` is the built-in layout.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagonal-hq/cli",
3
- "version": "0.12.5",
3
+ "version": "0.13.0",
4
4
  "description": "The diagonal CLI and the configuration helpers for file-based Diagonal workspaces.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {