@diagonal-hq/cli 0.12.4 → 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 +6 -2
- package/dist/cli.mjs +41 -0
- package/dist/index.d.ts +13 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,6 +60,7 @@ The build reads each file with a parser. It runs only the workflow tests.
|
|
|
60
60
|
- 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
61
|
- The second argument of `definePage`, and the default export of a layout or component file, must be one function.
|
|
62
62
|
- Each page has a key that is unique in the workspace: a camelCase name of at most 64 letters and digits, such as `members`. The page's id comes from the key. Without a `key` option, the key comes from the file path below `pages/`: `pages/members/[id].tsx` is `membersId`, `pages/404.tsx` is `page404`, and `pages/index.tsx` is `home`. Set `key` when the page must keep its identity and its `Pages.<key>` links after a file move. Two pages with the same key fail at the second file.
|
|
63
|
+
- Each page also has a `uid`. See [Definition uids and slugs](#definition-uids-and-slugs). Nothing reads it yet: the key still gives the page its id.
|
|
63
64
|
- Pages, layouts, and components link to a page with `Pages.<key>`: `Pages.members.url()`, `Pages.member.url({ id })`, and `Pages.members.navigate()`. `Pages` needs no import, and `import { Pages } from '@diagonal/pages'` also works. The check fails at an unknown key and at a call without the route parameters of the page.
|
|
64
65
|
- 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 names a resource by slug, for example `Sdk.resource(Resources.Members.slug)`.
|
|
65
66
|
- Each `workflows/<name>.ts` is a script workflow. It has one `export const config = { uid, title, trigger, runAs? } satisfies WorkflowConfig` and one `export default defineWorkflow(...)`. The config must be a static literal. 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 paths of `workflowEvent` triggers, and the run-as rules. A `recordEvent`, `recordSchedule`, `scheduled`, or `workflowEvent` workflow needs `runAs`.
|
|
@@ -68,11 +69,11 @@ The build reads each file with a parser. It runs only the workflow tests.
|
|
|
68
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.
|
|
69
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.
|
|
70
71
|
|
|
71
|
-
- The build
|
|
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).
|
|
72
73
|
|
|
73
74
|
## Definition uids and slugs
|
|
74
75
|
|
|
75
|
-
A definition can have two identity options. A resource, 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.
|
|
76
77
|
|
|
77
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.
|
|
78
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.
|
|
@@ -167,6 +168,7 @@ import { Resources } from '@app/generated/resources';
|
|
|
167
168
|
import { defineNotificationType, field } from '@diagonal-hq/cli';
|
|
168
169
|
|
|
169
170
|
export default defineNotificationType({
|
|
171
|
+
uid: '3f2b8c1e-7d4a-4e9b-a6c5-1d0e9f8a7b6c',
|
|
170
172
|
key: 'member-welcome',
|
|
171
173
|
name: 'Member welcome',
|
|
172
174
|
recipient: { resource: Resources.Members.slug },
|
|
@@ -184,6 +186,7 @@ A template has an email, an SMS, or both. A channel is on when the template has
|
|
|
184
186
|
import { defineNotificationTemplate } from '@diagonal-hq/cli';
|
|
185
187
|
|
|
186
188
|
export default defineNotificationTemplate({
|
|
189
|
+
uid: '9a1d4e7b-2c3f-4b8a-9e6d-5f0c1b2a3d4e',
|
|
187
190
|
key: 'standard',
|
|
188
191
|
type: 'member-welcome',
|
|
189
192
|
name: 'Standard welcome',
|
|
@@ -212,6 +215,7 @@ An email layout is the frame that templates fill in. Each field is a slot that a
|
|
|
212
215
|
import { defineEmailLayout } from '@diagonal-hq/cli';
|
|
213
216
|
|
|
214
217
|
export default defineEmailLayout({
|
|
218
|
+
uid: 'c7e2a9f4-1b6d-4c3e-8a5f-2d9b0e1c4a7f',
|
|
215
219
|
key: 'standard',
|
|
216
220
|
name: 'Standard',
|
|
217
221
|
body: { file: './body.liquid' },
|
package/dist/cli.mjs
CHANGED
|
@@ -300015,6 +300015,7 @@ function derivedPageKey(path) {
|
|
|
300015
300015
|
var COMPONENT_NAME_PATTERN = /^[A-Z][A-Za-z0-9]*$/;
|
|
300016
300016
|
var PAGE_AUTHORIZERS = /* @__PURE__ */ new Set(["authenticated"]);
|
|
300017
300017
|
var PAGE_KEYS = /* @__PURE__ */ new Set([
|
|
300018
|
+
"uid",
|
|
300018
300019
|
"key",
|
|
300019
300020
|
"route",
|
|
300020
300021
|
"name",
|
|
@@ -302704,6 +302705,14 @@ function buildWorkflows({
|
|
|
302704
302705
|
|
|
302705
302706
|
// scripts/lib/runtime-build/build-workspace.mjs
|
|
302706
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
|
+
};
|
|
302707
302716
|
var IGNORED_DIRECTORIES = /* @__PURE__ */ new Set(["node_modules"]);
|
|
302708
302717
|
function listFiles(root) {
|
|
302709
302718
|
const files = [];
|
|
@@ -302816,6 +302825,13 @@ function classify(path) {
|
|
|
302816
302825
|
return isDirectChild(path, directory) && extension === ".ts" ? "navigation" : "unknown";
|
|
302817
302826
|
case "skills":
|
|
302818
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";
|
|
302819
302835
|
default:
|
|
302820
302836
|
return "ignored";
|
|
302821
302837
|
}
|
|
@@ -302961,10 +302977,22 @@ function uidDefinitionNodes(kind, ast) {
|
|
|
302961
302977
|
const platform = node.type === "ObjectExpression" && node.properties.some((property) => property.type === "ObjectProperty" && propertyKey(property) === "platform");
|
|
302962
302978
|
return platform ? [] : [{ type: "resource", node }];
|
|
302963
302979
|
}
|
|
302980
|
+
case "page": {
|
|
302981
|
+
const { declaration } = defaultExportOf(ast, { helpers: "anywhere", allowAppImports: true });
|
|
302982
|
+
const [node] = expectDefineCall(declaration, "definePage", 2);
|
|
302983
|
+
return [{ type: "page", node }];
|
|
302984
|
+
}
|
|
302964
302985
|
case "workflow": {
|
|
302965
302986
|
const node = workflowConfigObject(ast);
|
|
302966
302987
|
return node === null ? [] : [{ type: "workflow", node }];
|
|
302967
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
|
+
}
|
|
302968
302996
|
default:
|
|
302969
302997
|
return [];
|
|
302970
302998
|
}
|
|
@@ -303063,6 +303091,9 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false } = {})
|
|
|
303063
303091
|
case "page": {
|
|
303064
303092
|
const page = buildPage(path, source, ast, root, resourcesBinding(ast, names2));
|
|
303065
303093
|
output.pages.push(page);
|
|
303094
|
+
for (const { type, node } of uidDefinitionNodes(kind, ast)) {
|
|
303095
|
+
uidPositions.set(path, uidDefinitions.push({ type, path, source, node }) - 1);
|
|
303096
|
+
}
|
|
303066
303097
|
diagnostics.push(...slugStringWarnings(path, page.resourceNodes.meta, names2));
|
|
303067
303098
|
uiEntries.push({ path, source, ast });
|
|
303068
303099
|
break;
|
|
@@ -303087,6 +303118,13 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false } = {})
|
|
|
303087
303118
|
case "navigation":
|
|
303088
303119
|
output.navigation.push(buildNavigation(path, ast));
|
|
303089
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;
|
|
303090
303128
|
}
|
|
303091
303129
|
} catch (error) {
|
|
303092
303130
|
diagnostics.push(diagnosticFromError(path, error));
|
|
@@ -303126,6 +303164,9 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false } = {})
|
|
|
303126
303164
|
for (const resource of output.resources) {
|
|
303127
303165
|
resource.uid = uidCheck.uids[uidPositions.get(resource.path)];
|
|
303128
303166
|
}
|
|
303167
|
+
for (const page of output.pages) {
|
|
303168
|
+
page.uid = uidCheck.uids[uidPositions.get(page.path)];
|
|
303169
|
+
}
|
|
303129
303170
|
if (output.config === null && !diagnostics.some((diagnostic2) => diagnostic2.path === CONFIG_PATH)) {
|
|
303130
303171
|
diagnostics.push(diagnosticAt(CONFIG_PATH, null, "The workspace has no diagonal.config.ts"));
|
|
303131
303172
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -251,7 +251,7 @@ export type PageAuthorizer =
|
|
|
251
251
|
permissions?: readonly string[];
|
|
252
252
|
};
|
|
253
253
|
|
|
254
|
-
export type PageDefinition = {
|
|
254
|
+
export type PageDefinition = UidOption & {
|
|
255
255
|
/**
|
|
256
256
|
* The page's identity, unique in the workspace: a camelCase name of at most
|
|
257
257
|
* 64 letters and digits that starts with a lowercase letter, such as
|
|
@@ -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
|
-
/**
|
|
458
|
-
|
|
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
|
-
|
|
467
|
-
|
|
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.
|