@diagonal-hq/cli 0.14.1 → 0.14.2
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 +5 -4
- package/dist/cli.mjs +117 -10
- package/dist/fields.generated.d.ts +5 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,16 +74,16 @@ The build reads each file with a parser. It runs only the workflow tests.
|
|
|
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`. 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`. No definition uses `slug` yet.
|
|
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
|
|
|
@@ -371,6 +371,7 @@ There is one `field.<type>` builder for each resource field type, in camel case:
|
|
|
371
371
|
|
|
372
372
|
A builder takes these options:
|
|
373
373
|
|
|
374
|
+
- `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
375
|
- `label`, `description`, `required`, `default`, `unique`, and `index`.
|
|
375
376
|
- `guard`: more validation rules, for example `['max:255']`. Use `required` for the `required` and `nullable` rules.
|
|
376
377
|
- `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 +379,7 @@ A builder takes these options:
|
|
|
378
379
|
- `getter`: a resolver tree that transforms the stored value when it is read.
|
|
379
380
|
- `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
381
|
|
|
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.
|
|
382
|
+
`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
383
|
|
|
383
384
|
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
385
|
|
package/dist/cli.mjs
CHANGED
|
@@ -268225,11 +268225,20 @@ function readDefinitionUid(definition) {
|
|
|
268225
268225
|
if (definition.frontMatter !== void 0) {
|
|
268226
268226
|
return readFrontMatterUid(definition.source, definition.frontMatter);
|
|
268227
268227
|
}
|
|
268228
|
+
if (isCallWithoutArguments(definition.node)) {
|
|
268229
|
+
return { uid: null, at: definition.node };
|
|
268230
|
+
}
|
|
268228
268231
|
const uid2 = readUid(definition.node);
|
|
268229
268232
|
return { uid: uid2, at: uid2 === null ? definition.node : uidProperty(definition.node).value };
|
|
268230
268233
|
}
|
|
268234
|
+
function isCallWithoutArguments(node) {
|
|
268235
|
+
return node.type === "CallExpression" && node.arguments.length === 0;
|
|
268236
|
+
}
|
|
268231
268237
|
function uidInsertion(source, object, uid2) {
|
|
268232
268238
|
const property = `uid: '${uid2}'`;
|
|
268239
|
+
if (isCallWithoutArguments(object)) {
|
|
268240
|
+
return { start: object.end - 1, end: object.end - 1, text: `{ ${property} }` };
|
|
268241
|
+
}
|
|
268233
268242
|
const [first] = object.properties;
|
|
268234
268243
|
const anchor = first === void 0 ? object.innerComments?.[0] : first.leadingComments?.[0] ?? first;
|
|
268235
268244
|
if (anchor === void 0) {
|
|
@@ -268296,7 +268305,7 @@ function planDefinitionUids(definitions, { write }) {
|
|
|
268296
268305
|
continue;
|
|
268297
268306
|
}
|
|
268298
268307
|
if (uid2 !== null) {
|
|
268299
|
-
const key = `${definition.type}\0${uid2}`;
|
|
268308
|
+
const key = `${definition.type}\0${definition.scope ?? ""}\0${uid2}`;
|
|
268300
268309
|
const first = firstByUid.get(key);
|
|
268301
268310
|
if (first === void 0) {
|
|
268302
268311
|
firstByUid.set(key, definition);
|
|
@@ -299147,6 +299156,7 @@ var field_catalog_default = {
|
|
|
299147
299156
|
var FIELD_KEY_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
299148
299157
|
var FIELD_CATALOG = field_catalog_default;
|
|
299149
299158
|
var FIELD_OPTIONS = /* @__PURE__ */ new Set([
|
|
299159
|
+
"uid",
|
|
299150
299160
|
"label",
|
|
299151
299161
|
"description",
|
|
299152
299162
|
"required",
|
|
@@ -299171,7 +299181,7 @@ var OPTION_FOR_SETTING = {
|
|
|
299171
299181
|
var NULLABILITY_RULES = /* @__PURE__ */ new Set(["required", "nullable"]);
|
|
299172
299182
|
var COMPUTED_CONFLICTS = ["default", "getter", "setter", "setterWhenEmpty", "unique", "index"];
|
|
299173
299183
|
var DERIVED_INVERSE_SETTINGS = /* @__PURE__ */ new Set(["resource_id", "type", "inverse"]);
|
|
299174
|
-
var INVERSE_KEYS = /* @__PURE__ */ new Set(["key", "label", "description", "settings"]);
|
|
299184
|
+
var INVERSE_KEYS = /* @__PURE__ */ new Set(["uid", "key", "label", "description", "settings"]);
|
|
299175
299185
|
var OPTION_KEYS = /* @__PURE__ */ new Set(["label", "value", "color"]);
|
|
299176
299186
|
function optionNode(builder2, ...path) {
|
|
299177
299187
|
let node = builder2.node.arguments?.[0] ?? builder2.node;
|
|
@@ -303736,12 +303746,97 @@ function pageKeyOfSource(path, source) {
|
|
|
303736
303746
|
throw error;
|
|
303737
303747
|
}
|
|
303738
303748
|
}
|
|
303739
|
-
function
|
|
303749
|
+
function objectProperty2(object, key) {
|
|
303750
|
+
return object.properties.find(
|
|
303751
|
+
(property) => property.type === "ObjectProperty" && propertyKey(property) === key
|
|
303752
|
+
) ?? null;
|
|
303753
|
+
}
|
|
303754
|
+
function withoutTypeAssertions(node) {
|
|
303755
|
+
let current = node;
|
|
303756
|
+
while (current?.type === "TSAsExpression" || current?.type === "TSSatisfiesExpression") {
|
|
303757
|
+
current = current.expression;
|
|
303758
|
+
}
|
|
303759
|
+
return current;
|
|
303760
|
+
}
|
|
303761
|
+
function fieldUidNodes(definition) {
|
|
303762
|
+
const fields = withoutTypeAssertions(objectProperty2(definition, "fields")?.value);
|
|
303763
|
+
if (fields?.type !== "ObjectExpression") {
|
|
303764
|
+
return [];
|
|
303765
|
+
}
|
|
303766
|
+
const nodes = [];
|
|
303767
|
+
for (const property of fields.properties) {
|
|
303768
|
+
if (property.type !== "ObjectProperty") {
|
|
303769
|
+
continue;
|
|
303770
|
+
}
|
|
303771
|
+
const call = withoutTypeAssertions(property.value);
|
|
303772
|
+
if (call.type !== "CallExpression") {
|
|
303773
|
+
continue;
|
|
303774
|
+
}
|
|
303775
|
+
const field2 = propertyKey(property);
|
|
303776
|
+
const [argument] = call.arguments;
|
|
303777
|
+
if (argument === void 0) {
|
|
303778
|
+
nodes.push({ type: "field", node: call, field: field2, inverse: false });
|
|
303779
|
+
continue;
|
|
303780
|
+
}
|
|
303781
|
+
const options2 = withoutTypeAssertions(argument);
|
|
303782
|
+
if (options2.type !== "ObjectExpression") {
|
|
303783
|
+
continue;
|
|
303784
|
+
}
|
|
303785
|
+
nodes.push({ type: "field", node: options2, field: field2, inverse: false });
|
|
303786
|
+
const settings = withoutTypeAssertions(objectProperty2(options2, "settings")?.value);
|
|
303787
|
+
const inverse = settings?.type === "ObjectExpression" ? withoutTypeAssertions(objectProperty2(settings, "inverse")?.value) : void 0;
|
|
303788
|
+
if (inverse?.type === "ObjectExpression") {
|
|
303789
|
+
nodes.push({ type: "field", node: inverse, field: field2, inverse: true });
|
|
303790
|
+
}
|
|
303791
|
+
}
|
|
303792
|
+
return nodes;
|
|
303793
|
+
}
|
|
303794
|
+
function fieldUidPosition(path, field2, inverse) {
|
|
303795
|
+
return `${path}\0${field2}\0${inverse ? "inverse" : "field"}`;
|
|
303796
|
+
}
|
|
303797
|
+
function checkInverseFieldUids(resources, pathsBySlug, diagnostics) {
|
|
303798
|
+
for (const resource of resources) {
|
|
303799
|
+
const firstByUid = /* @__PURE__ */ new Map();
|
|
303800
|
+
for (const field2 of resource.fields) {
|
|
303801
|
+
if (field2.uid === null) {
|
|
303802
|
+
continue;
|
|
303803
|
+
}
|
|
303804
|
+
const path = field2.inverse_of === void 0 ? resource.path : pathsBySlug.get(field2.inverse_of.resource);
|
|
303805
|
+
const first = firstByUid.get(field2.uid);
|
|
303806
|
+
if (first === void 0) {
|
|
303807
|
+
firstByUid.set(field2.uid, { field: field2, path });
|
|
303808
|
+
continue;
|
|
303809
|
+
}
|
|
303810
|
+
if (first.field.inverse_of === void 0 && field2.inverse_of === void 0) {
|
|
303811
|
+
continue;
|
|
303812
|
+
}
|
|
303813
|
+
diagnostics.push(
|
|
303814
|
+
diagnosticAt(
|
|
303815
|
+
path,
|
|
303816
|
+
null,
|
|
303817
|
+
`Duplicate field uid "${field2.uid}" on resource "${resource.slug}". Field "${first.field.key}" from ${first.path} and field "${field2.key}" from ${path} use it. Give one of them a new uid`
|
|
303818
|
+
)
|
|
303819
|
+
);
|
|
303820
|
+
}
|
|
303821
|
+
}
|
|
303822
|
+
}
|
|
303823
|
+
function uidDefinitionNodes(kind, path, ast) {
|
|
303740
303824
|
switch (kind) {
|
|
303741
303825
|
case "resource": {
|
|
303742
303826
|
const node = defineResourceArgument(ast);
|
|
303743
|
-
|
|
303744
|
-
|
|
303827
|
+
if (node.type !== "ObjectExpression") {
|
|
303828
|
+
return [{ type: "resource", node }];
|
|
303829
|
+
}
|
|
303830
|
+
if (objectProperty2(node, "platform") !== null) {
|
|
303831
|
+
return [];
|
|
303832
|
+
}
|
|
303833
|
+
return [
|
|
303834
|
+
{ type: "resource", node },
|
|
303835
|
+
...fieldUidNodes(node).map((field2) => ({
|
|
303836
|
+
...field2,
|
|
303837
|
+
scope: field2.inverse ? fieldUidPosition(path, field2.field, true) : path
|
|
303838
|
+
}))
|
|
303839
|
+
];
|
|
303745
303840
|
}
|
|
303746
303841
|
case "page": {
|
|
303747
303842
|
const { declaration } = defaultExportOf(ast, { helpers: "anywhere", allowAppImports: true });
|
|
@@ -303784,6 +303879,7 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false, fixSou
|
|
|
303784
303879
|
const workflowFiles = [];
|
|
303785
303880
|
const uidDefinitions = [];
|
|
303786
303881
|
const uidPositions = /* @__PURE__ */ new Map();
|
|
303882
|
+
const fieldUidPositions = /* @__PURE__ */ new Map();
|
|
303787
303883
|
const migratedPages = /* @__PURE__ */ new Map();
|
|
303788
303884
|
const skillFiles = [];
|
|
303789
303885
|
const workflowTestFiles = [];
|
|
@@ -303848,8 +303944,13 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false, fixSou
|
|
|
303848
303944
|
output.platform_resources.push(resource);
|
|
303849
303945
|
} else {
|
|
303850
303946
|
output.resources.push(resource);
|
|
303851
|
-
for (const { type, node } of uidDefinitionNodes(kind, ast)) {
|
|
303852
|
-
|
|
303947
|
+
for (const { type, scope: scope2, node, field: field2, inverse } of uidDefinitionNodes(kind, path, ast)) {
|
|
303948
|
+
const position2 = uidDefinitions.push({ type, scope: scope2, path, source, node }) - 1;
|
|
303949
|
+
if (field2 === void 0) {
|
|
303950
|
+
uidPositions.set(path, position2);
|
|
303951
|
+
} else {
|
|
303952
|
+
fieldUidPositions.set(fieldUidPosition(path, field2, inverse), position2);
|
|
303953
|
+
}
|
|
303853
303954
|
}
|
|
303854
303955
|
}
|
|
303855
303956
|
diagnostics.push(...slugStringWarnings(path, definition, names2));
|
|
@@ -303863,7 +303964,7 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false, fixSou
|
|
|
303863
303964
|
}
|
|
303864
303965
|
const page = buildPage(path, fixed, pageAst, root, resourcesBinding(pageAst, names2));
|
|
303865
303966
|
output.pages.push(page);
|
|
303866
|
-
for (const { type, node } of uidDefinitionNodes(kind, pageAst)) {
|
|
303967
|
+
for (const { type, node } of uidDefinitionNodes(kind, path, pageAst)) {
|
|
303867
303968
|
uidPositions.set(path, uidDefinitions.push({ type, path, source: fixed, node }) - 1);
|
|
303868
303969
|
}
|
|
303869
303970
|
diagnostics.push(
|
|
@@ -303883,7 +303984,7 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false, fixSou
|
|
|
303883
303984
|
break;
|
|
303884
303985
|
case "workflow":
|
|
303885
303986
|
workflowFiles.push({ path, source, ast });
|
|
303886
|
-
for (const { type, node } of uidDefinitionNodes(kind, ast)) {
|
|
303987
|
+
for (const { type, node } of uidDefinitionNodes(kind, path, ast)) {
|
|
303887
303988
|
uidPositions.set(path, uidDefinitions.push({ type, path, source, node }) - 1);
|
|
303888
303989
|
}
|
|
303889
303990
|
break;
|
|
@@ -303896,7 +303997,7 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false, fixSou
|
|
|
303896
303997
|
case "notification_type":
|
|
303897
303998
|
case "notification_template":
|
|
303898
303999
|
case "email_layout":
|
|
303899
|
-
for (const { type, node } of uidDefinitionNodes(kind, ast)) {
|
|
304000
|
+
for (const { type, node } of uidDefinitionNodes(kind, path, ast)) {
|
|
303900
304001
|
uidDefinitions.push({ type, path, source, node });
|
|
303901
304002
|
}
|
|
303902
304003
|
break;
|
|
@@ -303941,9 +304042,15 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false, fixSou
|
|
|
303941
304042
|
writeFileSync4(join11(root, path), source);
|
|
303942
304043
|
}
|
|
303943
304044
|
}
|
|
304045
|
+
const pathsBySlug = new Map(output.resources.map((resource) => [resource.slug, resource.path]));
|
|
303944
304046
|
for (const resource of output.resources) {
|
|
303945
304047
|
resource.uid = uidCheck.uids[uidPositions.get(resource.path)];
|
|
304048
|
+
for (const field2 of resource.fields) {
|
|
304049
|
+
const position2 = field2.inverse_of === void 0 ? fieldUidPosition(resource.path, field2.key, false) : fieldUidPosition(pathsBySlug.get(field2.inverse_of.resource), field2.inverse_of.key, true);
|
|
304050
|
+
field2.uid = uidCheck.uids[fieldUidPositions.get(position2)] ?? null;
|
|
304051
|
+
}
|
|
303946
304052
|
}
|
|
304053
|
+
checkInverseFieldUids(output.resources, pathsBySlug, diagnostics);
|
|
303947
304054
|
for (const page of output.pages) {
|
|
303948
304055
|
page.uid = uidCheck.uids[uidPositions.get(page.path)];
|
|
303949
304056
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Generated by `artisan app:generate-custom-typescript` from VariableType. Do not edit.
|
|
2
2
|
// The field builders of defineResource, one for each resource field type, the data API endpoints, the filter operators, and the record meta fields.
|
|
3
3
|
|
|
4
|
-
import type { StaticValue } from './index';
|
|
4
|
+
import type { DefinitionUid, StaticValue } from './index';
|
|
5
5
|
|
|
6
6
|
export type FieldType = "boolean" | "color" | "content" | "date" | "datetime" | "dictionary" | "email" | "event_schedule" | "file_reference" | "liquid" | "list" | "location" | "markdown" | "money" | "number" | "password" | "phone" | "recurrence" | "regular_hours" | "relation" | "resource_reference" | "select" | "text" | "time" | "timezone" | "url" | "uuid" | "wallet_accounting_account" | "wallet_accounting_entity";
|
|
7
7
|
|
|
@@ -43,6 +43,8 @@ export type FieldDefinition<TType extends FieldType = FieldType> = {
|
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
type BaseFieldOptions<TSettings> = {
|
|
46
|
+
/** The uid of the field, unique in its resource. `diagonal check` writes a missing one. */
|
|
47
|
+
uid?: DefinitionUid;
|
|
46
48
|
label?: string;
|
|
47
49
|
description?: string | null;
|
|
48
50
|
/** Adds the `required` guard. Without it the field is nullable. */
|
|
@@ -371,6 +373,8 @@ export type WalletAccountingEntityFieldSettings = CommonFieldSettings & {
|
|
|
371
373
|
* and its relation type is the inverse of the declaring relation type.
|
|
372
374
|
*/
|
|
373
375
|
export type RelationInverse = {
|
|
376
|
+
/** The uid of the inverse field, unique in the target resource. `diagonal check` writes a missing one. */
|
|
377
|
+
uid?: DefinitionUid;
|
|
374
378
|
key: string;
|
|
375
379
|
label?: string;
|
|
376
380
|
description?: string | null;
|