@diagonal-hq/cli 0.12.0 → 0.12.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 -3
- package/dist/cli.mjs +36 -5
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,20 +71,20 @@ The build reads each file with a parser. It runs only the workflow tests.
|
|
|
71
71
|
|
|
72
72
|
## Definition uids and slugs
|
|
73
73
|
|
|
74
|
-
A definition can have two identity options. No definition uses
|
|
74
|
+
A definition can have two identity options. A resource has a `uid`. No definition uses `slug` yet.
|
|
75
75
|
|
|
76
76
|
- `uid` is the stable identity of the definition. Its value is a lowercase UUID string literal, 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.
|
|
77
77
|
- `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.
|
|
78
78
|
|
|
79
79
|
`diagonal check` writes a new uid into each definition that has none. It adds `uid: '<uuid>'` as the first option of the `defineX()` object and leaves the rest of the file unchanged. Commit the change.
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
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`.
|
|
82
82
|
|
|
83
83
|
A uid is unique among the definitions of one type. Two definitions of one type with one uid are an error at the second file, 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 string literal is an error.
|
|
84
84
|
|
|
85
85
|
## Resource references
|
|
86
86
|
|
|
87
|
-
The file name is the resource slug: `resources/job-postings.ts` declares the resource `job-postings`. A file name must start with a lowercase letter and contain only a-z, 0-9, `_`, and `-`. A resource has no `id` in source. The platform derives the stored id from the workspace and the slug, so each branch and environment has its own ids.
|
|
87
|
+
The file name is the resource slug: `resources/job-postings.ts` declares the resource `job-postings`. A file name must start with a lowercase letter and contain only a-z, 0-9, `_`, and `-`. A resource has no `id` in source. Each resource file has a `uid`, which the deploy stores on the resource. The platform still derives the stored id from the workspace and the slug, so each branch and environment has its own ids, and a renamed file is still a new resource.
|
|
88
88
|
|
|
89
89
|
The build writes `generated/resources.ts` from the resource files. `diagonal check` writes it on your machine, so the editor knows the types of `Resources`. The file is a build output: the workspace `.gitignore` lists it, and a deploy writes its own copy.
|
|
90
90
|
|
|
@@ -394,6 +394,8 @@ A workflow script reads the capabilities of each resource from `@diagonal/workfl
|
|
|
394
394
|
|
|
395
395
|
## Application asset references
|
|
396
396
|
|
|
397
|
+
The admin's Application Assets page (`/admin/application-assets`) uploads assets and new versions and shows each version reference with a copy button.
|
|
398
|
+
|
|
397
399
|
Run the upload command in the workspace root, the folder with `diagonal.config.ts`:
|
|
398
400
|
|
|
399
401
|
```text
|
package/dist/cli.mjs
CHANGED
|
@@ -268140,7 +268140,7 @@ function withInsertions(source, insertions) {
|
|
|
268140
268140
|
}
|
|
268141
268141
|
return result;
|
|
268142
268142
|
}
|
|
268143
|
-
function
|
|
268143
|
+
function planDefinitionUids(definitions, { write }) {
|
|
268144
268144
|
const diagnostics = [];
|
|
268145
268145
|
const uids = [];
|
|
268146
268146
|
const firstByUid = /* @__PURE__ */ new Map();
|
|
@@ -268194,10 +268194,18 @@ function checkDefinitionUids(root, definitions, { write }) {
|
|
|
268194
268194
|
insertionsByPath.set(definition.path, insertions);
|
|
268195
268195
|
uids.push(generated);
|
|
268196
268196
|
}
|
|
268197
|
-
|
|
268198
|
-
|
|
268197
|
+
const written = [...insertionsByPath].map(([path, insertions]) => ({
|
|
268198
|
+
path,
|
|
268199
|
+
source: withInsertions(sourceByPath.get(path), insertions)
|
|
268200
|
+
}));
|
|
268201
|
+
return { uids, diagnostics, written };
|
|
268202
|
+
}
|
|
268203
|
+
function checkDefinitionUids(root, definitions, options2) {
|
|
268204
|
+
const result = planDefinitionUids(definitions, options2);
|
|
268205
|
+
for (const { path, source } of result.written) {
|
|
268206
|
+
writeFileSync2(join3(root, path), source);
|
|
268199
268207
|
}
|
|
268200
|
-
return
|
|
268208
|
+
return result;
|
|
268201
268209
|
}
|
|
268202
268210
|
|
|
268203
268211
|
// scripts/lib/runtime-build/module-graph.mjs
|
|
@@ -299062,6 +299070,7 @@ function checkPolicyResources(resources, platformSlugs, names2, diagnostics) {
|
|
|
299062
299070
|
// scripts/lib/runtime-build/resources.mjs
|
|
299063
299071
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
299064
299072
|
var RESOURCE_KEYS = /* @__PURE__ */ new Set([
|
|
299073
|
+
"uid",
|
|
299065
299074
|
"name",
|
|
299066
299075
|
"singularName",
|
|
299067
299076
|
"displayField",
|
|
@@ -302854,6 +302863,17 @@ function pageKeyOfSource(path, source) {
|
|
|
302854
302863
|
throw error;
|
|
302855
302864
|
}
|
|
302856
302865
|
}
|
|
302866
|
+
function uidDefinitionNodes(kind, ast) {
|
|
302867
|
+
switch (kind) {
|
|
302868
|
+
case "resource": {
|
|
302869
|
+
const node = defineResourceArgument(ast);
|
|
302870
|
+
const platform = node.type === "ObjectExpression" && node.properties.some((property) => property.type === "ObjectProperty" && propertyKey(property) === "platform");
|
|
302871
|
+
return platform ? [] : [{ type: "resource", node }];
|
|
302872
|
+
}
|
|
302873
|
+
default:
|
|
302874
|
+
return [];
|
|
302875
|
+
}
|
|
302876
|
+
}
|
|
302857
302877
|
function hasErrors(diagnostics) {
|
|
302858
302878
|
return diagnostics.some((diagnostic2) => diagnostic2.severity === "error");
|
|
302859
302879
|
}
|
|
@@ -302874,6 +302894,7 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false } = {})
|
|
|
302874
302894
|
};
|
|
302875
302895
|
const workflowFiles = [];
|
|
302876
302896
|
const uidDefinitions = [];
|
|
302897
|
+
const uidPositions = /* @__PURE__ */ new Map();
|
|
302877
302898
|
const skillFiles = [];
|
|
302878
302899
|
const workflowTestFiles = [];
|
|
302879
302900
|
const files = listFiles(root);
|
|
@@ -302933,7 +302954,14 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false } = {})
|
|
|
302933
302954
|
slug,
|
|
302934
302955
|
resources: resourcesBinding(ast, names2)
|
|
302935
302956
|
});
|
|
302936
|
-
(resource.platform
|
|
302957
|
+
if (resource.platform) {
|
|
302958
|
+
output.platform_resources.push(resource);
|
|
302959
|
+
} else {
|
|
302960
|
+
output.resources.push(resource);
|
|
302961
|
+
for (const { type, node } of uidDefinitionNodes(kind, ast)) {
|
|
302962
|
+
uidPositions.set(path, uidDefinitions.push({ type, path, source, node }) - 1);
|
|
302963
|
+
}
|
|
302964
|
+
}
|
|
302937
302965
|
diagnostics.push(...slugStringWarnings(path, definition, names2));
|
|
302938
302966
|
break;
|
|
302939
302967
|
}
|
|
@@ -302997,6 +303025,9 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false } = {})
|
|
|
302997
303025
|
}
|
|
302998
303026
|
const uidCheck = checkDefinitionUids(root, uidDefinitions, { write: writeSource });
|
|
302999
303027
|
diagnostics.push(...uidCheck.diagnostics);
|
|
303028
|
+
for (const resource of output.resources) {
|
|
303029
|
+
resource.uid = uidCheck.uids[uidPositions.get(resource.path)];
|
|
303030
|
+
}
|
|
303000
303031
|
if (output.config === null && !diagnostics.some((diagnostic2) => diagnostic2.path === CONFIG_PATH)) {
|
|
303001
303032
|
diagnostics.push(diagnosticAt(CONFIG_PATH, null, "The workspace has no diagonal.config.ts"));
|
|
303002
303033
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -186,7 +186,7 @@ export type ResourceDataApi = {
|
|
|
186
186
|
|
|
187
187
|
export type ResourceDefinition<
|
|
188
188
|
TFields extends Record<string, FieldDefinition> = Record<string, FieldDefinition>
|
|
189
|
-
> = {
|
|
189
|
+
> = UidOption & {
|
|
190
190
|
/** Only a platform resource reference sets `platform`. */
|
|
191
191
|
platform?: never;
|
|
192
192
|
name: string;
|