@diagonal-hq/cli 0.20.4 → 0.21.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 +4 -3
- package/dist/cli.mjs +43 -7
- package/dist/index.d.ts +14 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -76,6 +76,7 @@ The build reads each file with a parser. It runs only the workflow and migration
|
|
|
76
76
|
- Every file that names a page imports `Pages` from `@app/generated/pages`: `diagonal.config.ts`, resource files, pages, layouts, components, and menus. There is one `Pages` object. `Pages` is not a global, and `@diagonal-hq/pages` does not export it. A file that uses `Pages` without the import fails the check with `'Pages' is not defined`. Every file names a page by its uid, `Pages.<Name>.uid`, as it names a workflow by `Workflows.<Name>.slug`. Pages, layouts, and components pass the uid to `utils` from `@diagonal-hq/pages`: `utils.page.url(Pages.Members.uid)`, `utils.page.url(Pages.Members_$Id.uid, { id })`, `utils.page.navigate(Pages.Members.uid)`, and `utils.page.navigate(Pages.Members_$Id.uid, { id }, { openInNewTab: true })`. A menu item is `{ kind: 'page', label, page: Pages.Members.uid }`. A config or resource file names a page with `Pages.<Name>.uid` too. See [Page reference settings](#page-reference-settings). The check fails at an unknown name, such as a stale name after a file move: `Unknown page "Pages.X". Each name in Pages is a file in pages/`. The type check also fails at a call without the route parameters of the page, at route parameters for a page without any, and at a menu item for a page with route parameters. The error names the page and its route, such as `Pages.Members_$Id has the route /members/{id}. Pass its route parameters as params.`
|
|
77
77
|
- 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 imports the Page SDK members that it uses from `@diagonal-hq/pages`, such as `import { resource, useRecords } from '@diagonal-hq/pages'`. A page names a resource by slug, for example `resource(Resources.Members.slug)`.
|
|
78
78
|
- Each `workflows/<name>.ts` is a script workflow. Its default export is `defineWorkflow({ uid, name, trigger, runAs?, input?, validate? }, handler)` from `@diagonal/workflow`, the same shape as `definePage(options, component)`. The config is the first argument and must be an object literal. The build reads every option except `input` and `validate` as static data and never runs the handler to find it. `input` is a `v.object({...})` schema, or a top-level `const` of one, which the script compiler reads. `validate` is a function that runs after the input check and before the handler, with the same input type. It returns errors keyed by field, and any error ends the run with a 422. The editor checks the config against `WorkflowConfig` from `@diagonal-hq/cli`. 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 references of `workflowEvent` triggers (see [Workflow references](#workflow-references)), the filter tree of a `recordEvent` trigger's `filters` (see [Policies](#policies)), and the run-as rules. A `recordEvent`, `recordSchedule`, `scheduled`, or `workflowEvent` workflow needs `runAs`.
|
|
79
|
+
- A `recordSchedule` trigger runs each offset from the `dateField` of each record. `timing` defaults to `'day'`, which runs at 8 a.m. in the workspace timezone on the day of the field plus the offset, and ignores the time of the field. Day timing takes whole-day offsets only, so the build refuses an offset such as `'-PT2H'` or `'+PT0M'`. `timing: 'exact'` runs at the time of the field plus the offset, for example 2 hours before a class with `offsets: ['-PT2H']`. Exact timing needs a datetime field.
|
|
79
80
|
- A workflow with `export const config = { title, ... }` and `export default defineWorkflow(handler)` or `defineWorkflow(input, handler)` still builds. The build warns at the config export and at `title`. Move the config into the `defineWorkflow` call and rename `title` to `name`. A workflow cannot have both forms of config, or both `name` and `title`. A `validateInput` export still runs before the handler, with a warning; move it into the config as `validate`. A workflow cannot have both.
|
|
80
81
|
- Each `skills/<name>.md` is a workspace AI skill: YAML front matter with `uid`, `name`, `description`, and optionally `enabled` and `manualOnly`, then a Markdown body with its instructions. The build validates the front matter, the uid (see [Definition uids and slugs](#definition-uids-and-slugs)), and that no two skill files declare one `name`. The build writes `generated/skills.ts`, which exports `Skills`: the `uid`, `name`, and `description` of each skill, keyed by the studly case of its file name, so `skills/front-desk.md` is `Skills.FrontDesk`. It never holds the instructions. Import it from `@app/generated/skills`. The build replaces each `Skills.<Name>.<key>` reference in a page or workflow with its value, as it does for `Resources`. A file name that gives no identifier, and a second file with one name, get no entry and a warning.
|
|
81
82
|
- The build removes the config options other than `input` and `validate`, and the `@diagonal-hq/cli` imports, from the workflow, with spaces in their place, and compiles the rest with the workflow script compiler against the workspace resources. The compiled script calls `defineWorkflow({ input, validate }, handler)`, so a change to a static option does not change the compiled code. A compiler error has the line and column of the workflow file.
|
|
@@ -658,8 +659,8 @@ export default defineNotificationSchedule({
|
|
|
658
659
|
|
|
659
660
|
This sends the Standard welcome 7 days after each active member's `joined_on`.
|
|
660
661
|
|
|
661
|
-
- `offsets` holds one to 30 distinct ISO 8601 durations in days, hours, or minutes: `'-P30D'` is 30 days before, `'P0D'` is the day, `'-PT2H'` is 2 hours before. A duration without a sign counts after the date, so `'P7D'` and `'+P7D'` are the same offset.
|
|
662
|
-
- `timing` defaults to `'day'`, which sends at 8 a.m. in the workspace timezone. `'exact'` sends at the
|
|
662
|
+
- `offsets` holds one to 30 distinct ISO 8601 durations in days, hours, or minutes: `'-P30D'` is 30 days before, `'P0D'` is the day, `'-PT2H'` is 2 hours before in exact timing. A duration without a sign counts after the date, so `'P7D'` and `'+P7D'` are the same offset.
|
|
663
|
+
- `timing` defaults to `'day'`, which sends at 8 a.m. in the workspace timezone on the day, so `'-PT2H'` sends at 6 a.m. `'exact'` sends at the time of a datetime field or the start of an event schedule field, plus the offset.
|
|
663
664
|
- `filters` is optional. It is a filter tree, `{ operator, conditions }`, with the shape of a policy `filter`. See [Policies](#policies).
|
|
664
665
|
- `recipient` is the path of single-record relations from the source record to the type's recipient, for example `'member'` on a `memberships` source. Leave it out when the source resource is the recipient, as here.
|
|
665
666
|
- `variables` maps each variable of the type to a field path on the source record. A record variable maps to a record's `id`.
|
|
@@ -722,7 +723,7 @@ The editor checks the shape of each definition. `diagonal check` and the build a
|
|
|
722
723
|
- 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.
|
|
723
724
|
- A layout's slug and its folder name are 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.
|
|
724
725
|
- A schedule has a `name` of 1 to 255 characters. Its `type` names a type of the workspace files that has a `recipient`, and its `template` names a template of that type that has an email. `source.resource` is a resource of the workspace. A schedule's `filters` is a filter tree with a known operator in each condition.
|
|
725
|
-
- A schedule's `dateField` is a date, datetime, or event schedule field of the source resource. Exact timing needs
|
|
726
|
+
- A schedule's `dateField` is a date, datetime, or event schedule field of the source resource. Exact timing needs a datetime or event schedule field. `offsets` holds 1 to 30 distinct durations.
|
|
726
727
|
- A schedule's `recipient` path reaches the type's recipient resource through relations that each hold one record. Without `recipient`, the source resource is the recipient resource.
|
|
727
728
|
- Each key of a schedule's `variables` is a variable of the type, and each path reaches a field of the source record or of a record that its single-record relations reach. A record variable maps to the id of a record of its resource, for example `'first_event.id'`. Each required variable is mapped.
|
|
728
729
|
|
package/dist/cli.mjs
CHANGED
|
@@ -310296,6 +310296,7 @@ function filterGroupProblem(group, path, node) {
|
|
|
310296
310296
|
// scripts/lib/runtime-build/record-schedule.mjs
|
|
310297
310297
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
310298
310298
|
var OFFSET_PATTERN = /^([+-]?)P(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?)?$/i;
|
|
310299
|
+
var TIMINGS = ["day", "exact"];
|
|
310299
310300
|
var FIELD_TYPE_LABELS = {
|
|
310300
310301
|
date: "date",
|
|
310301
310302
|
datetime: "datetime",
|
|
@@ -310333,9 +310334,26 @@ function dateFieldProblem(resource, dateField, fieldTypes) {
|
|
|
310333
310334
|
if (field2 !== void 0 && fieldTypes.includes(field2.type)) {
|
|
310334
310335
|
return null;
|
|
310335
310336
|
}
|
|
310337
|
+
return `"${dateField}" is not a ${fieldTypeList(fieldTypes)} field of resource "${resource.slug}"`;
|
|
310338
|
+
}
|
|
310339
|
+
function readTiming(timing, node, fail) {
|
|
310340
|
+
const value = timing ?? "day";
|
|
310341
|
+
if (!TIMINGS.includes(value)) {
|
|
310342
|
+
fail(node, `"timing" must be one of ${TIMINGS.join(", ")}`);
|
|
310343
|
+
return null;
|
|
310344
|
+
}
|
|
310345
|
+
return value;
|
|
310346
|
+
}
|
|
310347
|
+
function exactTimingProblem(field2, fieldTypes) {
|
|
310348
|
+
return fieldTypes.includes(field2.type) ? null : `Exact timing needs a ${fieldTypeList(fieldTypes)} field`;
|
|
310349
|
+
}
|
|
310350
|
+
function dayTimingOffsetsProblem(offsets) {
|
|
310351
|
+
const offset = offsets.find((item) => /T/i.test(item));
|
|
310352
|
+
return offset === void 0 ? null : `Offset ${JSON.stringify(offset)} has hours or minutes, but day timing runs at 8 a.m. on the day of the date field. Set timing: 'exact' to count from the time of the field, or use whole days, for example '-P1D'`;
|
|
310353
|
+
}
|
|
310354
|
+
function fieldTypeList(fieldTypes) {
|
|
310336
310355
|
const labels = fieldTypes.map((type) => FIELD_TYPE_LABELS[type]);
|
|
310337
|
-
|
|
310338
|
-
return `"${dateField}" is not a ${list} field of resource "${resource.slug}"`;
|
|
310356
|
+
return labels.length < 3 ? labels.join(" or ") : `${labels.slice(0, -1).join(", ")}, or ${labels.at(-1)}`;
|
|
310339
310357
|
}
|
|
310340
310358
|
|
|
310341
310359
|
// scripts/lib/runtime-build/workflow-references.mjs
|
|
@@ -310764,6 +310782,7 @@ var RECORD_EVENTS = ["created", "updated", "deleted", "restored", "saved"];
|
|
|
310764
310782
|
var LIFECYCLE_HOOKS = ["creating", "updating", "saving", "deleting", "restoring"];
|
|
310765
310783
|
var WORKFLOW_EVENTS = ["execution.success", "execution.error", "execution.exception"];
|
|
310766
310784
|
var SCHEDULE_FIELD_TYPES = ["date", "datetime"];
|
|
310785
|
+
var EXACT_TIMING_FIELD_TYPES = ["datetime"];
|
|
310767
310786
|
var TRIGGERS = {
|
|
310768
310787
|
request: {
|
|
310769
310788
|
type: "request",
|
|
@@ -310785,7 +310804,7 @@ var TRIGGERS = {
|
|
|
310785
310804
|
},
|
|
310786
310805
|
recordSchedule: {
|
|
310787
310806
|
type: "schedule.record",
|
|
310788
|
-
keys: ["type", "resource", "dateField", "offsets", "filters"],
|
|
310807
|
+
keys: ["type", "resource", "dateField", "offsets", "timing", "filters"],
|
|
310789
310808
|
background: true,
|
|
310790
310809
|
sync: false
|
|
310791
310810
|
},
|
|
@@ -311324,6 +311343,7 @@ function triggerSettings(trigger, at, context, fail) {
|
|
|
311324
311343
|
case "recordSchedule": {
|
|
311325
311344
|
const resource = resolveResource(trigger.resource, at("resource"), context, fail);
|
|
311326
311345
|
const offsets = readOffsets(trigger.offsets, at("offsets"), fail);
|
|
311346
|
+
const timing = readTiming(trigger.timing, at("timing"), fail);
|
|
311327
311347
|
const dateField = trigger.dateField;
|
|
311328
311348
|
if (typeof dateField !== "string" || dateField === "") {
|
|
311329
311349
|
fail(at("dateField"), '"dateField" must be the key of a date or datetime field');
|
|
@@ -311335,8 +311355,23 @@ function triggerSettings(trigger, at, context, fail) {
|
|
|
311335
311355
|
fail(at("dateField"), problem2);
|
|
311336
311356
|
return null;
|
|
311337
311357
|
}
|
|
311358
|
+
const field2 = resource.fields.find((item) => item.key === dateField);
|
|
311359
|
+
const timingProblem = timing === "exact" ? exactTimingProblem(field2, EXACT_TIMING_FIELD_TYPES) : null;
|
|
311360
|
+
if (timingProblem !== null) {
|
|
311361
|
+
fail(at("timing"), timingProblem);
|
|
311362
|
+
return null;
|
|
311363
|
+
}
|
|
311364
|
+
}
|
|
311365
|
+
const offsetsProblem = timing === "day" && offsets !== null ? dayTimingOffsetsProblem(offsets) : null;
|
|
311366
|
+
if (offsetsProblem !== null) {
|
|
311367
|
+
fail(at("offsets"), offsetsProblem);
|
|
311368
|
+
return null;
|
|
311338
311369
|
}
|
|
311339
|
-
|
|
311370
|
+
if (resource === null || offsets === null || timing === null) {
|
|
311371
|
+
return null;
|
|
311372
|
+
}
|
|
311373
|
+
const schedule = timing === "exact" ? { offsets, timing } : { offsets };
|
|
311374
|
+
return { schedule, date_field: dateField, resource: resource.slug, ...filters };
|
|
311340
311375
|
}
|
|
311341
311376
|
case "scheduled": {
|
|
311342
311377
|
const expression2 = trigger.expression;
|
|
@@ -315228,8 +315263,8 @@ var RECIPIENT_MAX_LENGTH = 255;
|
|
|
315228
315263
|
var VARIABLE_PATH_MAX_LENGTH = 500;
|
|
315229
315264
|
var VARIABLE_PATH_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_.-]*$/;
|
|
315230
315265
|
var RELATION_PATH_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*$/;
|
|
315231
|
-
var TIMINGS = ["day", "exact"];
|
|
315232
315266
|
var DATE_FIELD_TYPES = ["date", "datetime", "event_schedule"];
|
|
315267
|
+
var EXACT_TIMING_FIELD_TYPES2 = ["datetime", "event_schedule"];
|
|
315233
315268
|
var SINGULAR_RELATIONS = ["belongs_to", "has_one"];
|
|
315234
315269
|
function readReference(value, key, node, report, label) {
|
|
315235
315270
|
const item = value[key];
|
|
@@ -315492,10 +315527,11 @@ function resolveSchedules(schedules, definitions, context, diagnostics) {
|
|
|
315492
315527
|
if (source !== null && source !== void 0) {
|
|
315493
315528
|
const problem2 = dateFieldProblem(source, schedule.dateField, DATE_FIELD_TYPES);
|
|
315494
315529
|
const field2 = source.fields.find((item) => item.key === schedule.dateField);
|
|
315530
|
+
const timingProblem = problem2 === null && schedule.timing === "exact" ? exactTimingProblem(field2, EXACT_TIMING_FIELD_TYPES2) : null;
|
|
315495
315531
|
if (problem2 !== null) {
|
|
315496
315532
|
report(at("dateField"), problem2);
|
|
315497
|
-
} else if (
|
|
315498
|
-
report(at("timing"),
|
|
315533
|
+
} else if (timingProblem !== null) {
|
|
315534
|
+
report(at("timing"), timingProblem);
|
|
315499
315535
|
}
|
|
315500
315536
|
for (const [key, path] of Object.entries(schedule.variables)) {
|
|
315501
315537
|
const variable = variables.get(key);
|
package/dist/index.d.ts
CHANGED
|
@@ -947,8 +947,18 @@ export type RecordScheduleTrigger = {
|
|
|
947
947
|
resource: ResourceReference;
|
|
948
948
|
/** The key of a date or datetime field of the resource. */
|
|
949
949
|
dateField: string;
|
|
950
|
-
/**
|
|
950
|
+
/**
|
|
951
|
+
* Signed ISO 8601 durations, for example `'-P1D'`. Day timing takes whole
|
|
952
|
+
* days. Exact timing also takes hours and minutes, for example `'-PT2H'`.
|
|
953
|
+
*/
|
|
951
954
|
offsets: readonly string[];
|
|
955
|
+
/**
|
|
956
|
+
* When each offset runs. `'day'` (the default) runs at 8 a.m. in the
|
|
957
|
+
* workspace timezone on the day of the field plus the offset, and ignores
|
|
958
|
+
* the time of the field. `'exact'` runs at the time of the field plus the
|
|
959
|
+
* offset, and needs a datetime field.
|
|
960
|
+
*/
|
|
961
|
+
timing?: 'day' | 'exact';
|
|
952
962
|
filters?: FilterGroup;
|
|
953
963
|
};
|
|
954
964
|
|
|
@@ -1157,8 +1167,8 @@ export declare function defineEmailLayout<const T extends EmailLayoutDefinition>
|
|
|
1157
1167
|
|
|
1158
1168
|
/**
|
|
1159
1169
|
* When a schedule sends. `'day'` sends at 8 a.m. in the workspace timezone on
|
|
1160
|
-
* the day. `'exact'` sends at the
|
|
1161
|
-
* event schedule field.
|
|
1170
|
+
* the day. `'exact'` sends at the time of a datetime field or the start of an
|
|
1171
|
+
* event schedule field, plus the offset.
|
|
1162
1172
|
*/
|
|
1163
1173
|
export type NotificationScheduleTiming = 'day' | 'exact';
|
|
1164
1174
|
|
|
@@ -1187,7 +1197,7 @@ export type NotificationScheduleDefinition = UidOption & {
|
|
|
1187
1197
|
/**
|
|
1188
1198
|
* One to 30 distinct ISO 8601 durations from the date, for example
|
|
1189
1199
|
* `'-P30D'` (30 days before), `'P0D'` (the day), or `'-PT2H'` (2 hours
|
|
1190
|
-
* before). A duration without a sign counts after the date.
|
|
1200
|
+
* before in exact timing). A duration without a sign counts after the date.
|
|
1191
1201
|
*/
|
|
1192
1202
|
offsets: readonly string[];
|
|
1193
1203
|
/** Only the source records that match. */
|