@diagonal-hq/cli 0.6.1 → 0.6.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 +1 -1
- package/dist/cli.mjs +18 -15
- package/dist/index.d.ts +5 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ The build reads each file with a parser. It runs only the workflow tests.
|
|
|
51
51
|
- Each `resources/*.ts` file goes through the resource checks in [Resources and fields](#resources-and-fields).
|
|
52
52
|
- 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.
|
|
53
53
|
- The second argument of `definePage`, and the default export of a layout or component file, must be one function.
|
|
54
|
-
- Each
|
|
54
|
+
- 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.
|
|
55
55
|
- 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.
|
|
56
56
|
- 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)`.
|
|
57
57
|
- Each `workflows/<name>.ts` is a script workflow. It has one `export const config = { title, trigger, runAs? } satisfies WorkflowConfig` and one `export default defineWorkflow(...)`. The config must be a static literal. The build validates it: 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`.
|
package/dist/cli.mjs
CHANGED
|
@@ -298721,7 +298721,7 @@ function pageKeyFrom(text, taken = []) {
|
|
|
298721
298721
|
}
|
|
298722
298722
|
return key;
|
|
298723
298723
|
}
|
|
298724
|
-
function
|
|
298724
|
+
function derivedPageKey(path) {
|
|
298725
298725
|
const route = path.replace(/^pages\//, "").replace(/\.tsx$/, "").replace(/(^|\/)index$/, "");
|
|
298726
298726
|
return route === "" ? "home" : pageKeyFrom(route);
|
|
298727
298727
|
}
|
|
@@ -299153,7 +299153,7 @@ function buildPage(path, source, ast, root = null, resources = null) {
|
|
|
299153
299153
|
throw new SourceError(`Unknown page option "${key2}"`, nodes[key2]);
|
|
299154
299154
|
}
|
|
299155
299155
|
}
|
|
299156
|
-
const key = pageKey(path, meta, nodes
|
|
299156
|
+
const key = pageKey(path, meta, nodes);
|
|
299157
299157
|
if (typeof meta.route !== "string" || !meta.route.startsWith("/")) {
|
|
299158
299158
|
throw new SourceError('"route" must be a string that starts with "/"', nodes.route ?? metaNode);
|
|
299159
299159
|
}
|
|
@@ -299189,7 +299189,7 @@ function buildPage(path, source, ast, root = null, resources = null) {
|
|
|
299189
299189
|
params: pageParams(meta, nodes, meta.route),
|
|
299190
299190
|
...functionUnit(source, ast, functionNode, helpers, appImports(root, path, source, ast)),
|
|
299191
299191
|
layoutNode: nodes.layout ?? null,
|
|
299192
|
-
keyNode: nodes.key,
|
|
299192
|
+
keyNode: nodes.key ?? metaNode,
|
|
299193
299193
|
resourceNodes: {
|
|
299194
299194
|
meta: metaNode,
|
|
299195
299195
|
authorizer: nodes.authorizer ?? null,
|
|
@@ -299197,12 +299197,9 @@ function buildPage(path, source, ast, root = null, resources = null) {
|
|
|
299197
299197
|
}
|
|
299198
299198
|
};
|
|
299199
299199
|
}
|
|
299200
|
-
function pageKey(path, meta, nodes
|
|
299200
|
+
function pageKey(path, meta, nodes) {
|
|
299201
299201
|
if (meta.key === void 0) {
|
|
299202
|
-
|
|
299203
|
-
`definePage needs a "key". Add key: '${suggestedPageKey(path)}'`,
|
|
299204
|
-
metaNode
|
|
299205
|
-
);
|
|
299202
|
+
return derivedPageKey(path);
|
|
299206
299203
|
}
|
|
299207
299204
|
if (!isPageKey(meta.key)) {
|
|
299208
299205
|
throw new SourceError(
|
|
@@ -299212,14 +299209,20 @@ function pageKey(path, meta, nodes, metaNode) {
|
|
|
299212
299209
|
}
|
|
299213
299210
|
return meta.key;
|
|
299214
299211
|
}
|
|
299215
|
-
function pageKeyOf(ast) {
|
|
299212
|
+
function pageKeyOf(path, ast) {
|
|
299216
299213
|
try {
|
|
299217
299214
|
const { declaration } = defaultExportOf(ast, { helpers: "anywhere", allowAppImports: true });
|
|
299218
299215
|
const [metaNode] = expectDefineCall(declaration, "definePage", 2);
|
|
299219
|
-
|
|
299216
|
+
if (metaNode.type !== "ObjectExpression") {
|
|
299217
|
+
return null;
|
|
299218
|
+
}
|
|
299219
|
+
const keyProperty = metaNode.properties.find(
|
|
299220
299220
|
(property) => property.type === "ObjectProperty" && !property.computed && (property.key.name ?? property.key.value) === "key"
|
|
299221
|
-
)
|
|
299222
|
-
|
|
299221
|
+
);
|
|
299222
|
+
if (keyProperty === void 0) {
|
|
299223
|
+
return derivedPageKey(path);
|
|
299224
|
+
}
|
|
299225
|
+
const value = keyProperty.value.type === "StringLiteral" ? keyProperty.value.value : null;
|
|
299223
299226
|
return isPageKey(value) ? value : null;
|
|
299224
299227
|
} catch (error) {
|
|
299225
299228
|
if (error instanceof SourceError) {
|
|
@@ -301359,9 +301362,9 @@ function lintUnits(units, resources, components, pages, diagnostics) {
|
|
|
301359
301362
|
diagnostics.push(...lintUnit(unit, catalogs));
|
|
301360
301363
|
}
|
|
301361
301364
|
}
|
|
301362
|
-
function pageKeyOfSource(source) {
|
|
301365
|
+
function pageKeyOfSource(path, source) {
|
|
301363
301366
|
try {
|
|
301364
|
-
const key = pageKeyOf(parseSource(source, { jsx: true }));
|
|
301367
|
+
const key = pageKeyOf(path, parseSource(source, { jsx: true }));
|
|
301365
301368
|
return key === null ? [] : [key];
|
|
301366
301369
|
} catch (error) {
|
|
301367
301370
|
if (error instanceof SyntaxError) {
|
|
@@ -301468,7 +301471,7 @@ function buildWorkspace(root, { assetCatalog = null, writeGeneratedResources = f
|
|
|
301468
301471
|
} catch (error) {
|
|
301469
301472
|
diagnostics.push(diagnosticFromError(path, error));
|
|
301470
301473
|
if (kind === "page") {
|
|
301471
|
-
failedPageKeys.push(...pageKeyOfSource(source));
|
|
301474
|
+
failedPageKeys.push(...pageKeyOfSource(path, source));
|
|
301472
301475
|
} else if (kind === "layout") {
|
|
301473
301476
|
failedLayouts.add(stem(path));
|
|
301474
301477
|
} else if (kind === "component") {
|
package/dist/index.d.ts
CHANGED
|
@@ -160,10 +160,12 @@ export type PageDefinition = {
|
|
|
160
160
|
/**
|
|
161
161
|
* The page's identity, unique in the workspace: a camelCase name of at most
|
|
162
162
|
* 64 letters and digits that starts with a lowercase letter, such as
|
|
163
|
-
* `members`. Code links to the page as `Pages.<key>`.
|
|
164
|
-
*
|
|
163
|
+
* `members`. Code links to the page as `Pages.<key>`. Without it, the key
|
|
164
|
+
* comes from the file path: `pages/members/[id].tsx` is `membersId`, and
|
|
165
|
+
* `pages/index.tsx` is `home`. Set it to keep the page's identity when the
|
|
166
|
+
* file moves. A key change is an identity change.
|
|
165
167
|
*/
|
|
166
|
-
key
|
|
168
|
+
key?: string;
|
|
167
169
|
/** The URL pattern. Route parameters use `{name}`, for example `/members/{id}`. */
|
|
168
170
|
route: string;
|
|
169
171
|
/** The name in the admin. Defaults to the title. */
|