@diagonal-hq/cli 0.13.0 → 0.14.1
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 +85 -8
- package/dist/cli.mjs +1784 -1001
- package/dist/index.d.ts +173 -19
- package/dist/index.js +5 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export type StaticValue =
|
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* The stable identity of a definition: a lowercase UUID string literal, such as
|
|
42
|
-
* `'
|
|
42
|
+
* `'019a4d6e-3c2f-7b8a-9d1e-5f6a7b8c9d0e'`. `diagonal check` writes one into a
|
|
43
43
|
* definition that has none. A file move or a rename keeps it. Do not change it.
|
|
44
44
|
*/
|
|
45
45
|
export type DefinitionUid = string;
|
|
@@ -228,19 +228,34 @@ export declare function defineResource<const TFields extends Record<string, Fiel
|
|
|
228
228
|
resource: ResourceDefinition<TFields> | PlatformResourceDefinition
|
|
229
229
|
): ResourceDefinition<TFields> | PlatformResourceDefinition;
|
|
230
230
|
|
|
231
|
-
/**
|
|
232
|
-
|
|
231
|
+
/**
|
|
232
|
+
* A resolver object in a deprecated flat meta option. The build accepts only a
|
|
233
|
+
* text-only `tiptap.parse` value, which it reads as its text.
|
|
234
|
+
*/
|
|
235
|
+
export type PageMetaResolver =
|
|
236
|
+
| { readonly type: string; readonly [key: string]: unknown }
|
|
237
|
+
| { readonly $type: string; readonly $value?: unknown };
|
|
233
238
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
239
|
+
/**
|
|
240
|
+
* The metadata of each workspace resource, keyed by slug. `diagonal check`
|
|
241
|
+
* fills it in `generated/resources.ts` from `Resources.<Name>`. A platform
|
|
242
|
+
* resource has no member, so its bound fields are open.
|
|
243
|
+
*/
|
|
244
|
+
export interface WorkspaceResources {}
|
|
245
|
+
|
|
246
|
+
export type PageBinding<R extends ResourceReference = ResourceReference> = {
|
|
247
|
+
/** The resource whose record the route parameter names, as `Resources.<Name>.slug`. */
|
|
248
|
+
resource: R;
|
|
237
249
|
/** The field the parameter matches. Defaults to the record id. */
|
|
238
250
|
lookupField?: string | null;
|
|
239
|
-
/** Relation fields to load with the record. */
|
|
251
|
+
/** Relation fields to load with the record. A `seo` function reads only these relations. */
|
|
240
252
|
relations?: readonly string[];
|
|
241
253
|
scope?: 'active' | 'activeOrArchived' | 'archived' | null;
|
|
242
254
|
};
|
|
243
255
|
|
|
256
|
+
/** @deprecated Use `PageBinding`. */
|
|
257
|
+
export type PageRouteParam = PageBinding;
|
|
258
|
+
|
|
244
259
|
export type PageAuthorizer =
|
|
245
260
|
| null
|
|
246
261
|
| 'authenticated'
|
|
@@ -251,7 +266,139 @@ export type PageAuthorizer =
|
|
|
251
266
|
permissions?: readonly string[];
|
|
252
267
|
};
|
|
253
268
|
|
|
254
|
-
|
|
269
|
+
declare const boundValue: unique symbol;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* A field of a bound record in a `seo` function. It has no value in code:
|
|
273
|
+
* the build makes a server resolver from the read, and the server reads the
|
|
274
|
+
* record for each request.
|
|
275
|
+
*/
|
|
276
|
+
export type BoundValue<TKind extends 'text' | 'scalar' | 'file' | 'other'> = {
|
|
277
|
+
readonly [boundValue]: TKind;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
/** A bound text, date, or select field, or a text made from them. */
|
|
281
|
+
export type BoundText = BoundValue<'text'>;
|
|
282
|
+
|
|
283
|
+
/** A bound number or boolean field. `text.template` makes it text. */
|
|
284
|
+
export type BoundScalar = BoundValue<'scalar'>;
|
|
285
|
+
|
|
286
|
+
/** A bound `file_reference` field. Only a public file can be a social image. */
|
|
287
|
+
export type BoundFile = BoundValue<'file'>;
|
|
288
|
+
|
|
289
|
+
/** A bound field that has no text form, such as money or a location. */
|
|
290
|
+
export type BoundOther = BoundValue<'other'>;
|
|
291
|
+
|
|
292
|
+
/** A relation that the binding does not load. Add its key to the binding's `relations`. */
|
|
293
|
+
export type RelationNotLoaded<TKey> = { readonly addToBindingRelations: TKey };
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* A field of a resource whose fields the types do not know, such as a
|
|
297
|
+
* platform resource. The build still checks the read.
|
|
298
|
+
*/
|
|
299
|
+
export type OpenBoundField = { readonly [boundValue]: never } & {
|
|
300
|
+
readonly [key: string]: OpenBoundField;
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
type TextFieldType =
|
|
304
|
+
| 'text'
|
|
305
|
+
| 'email'
|
|
306
|
+
| 'url'
|
|
307
|
+
| 'phone'
|
|
308
|
+
| 'uuid'
|
|
309
|
+
| 'select'
|
|
310
|
+
| 'date'
|
|
311
|
+
| 'datetime'
|
|
312
|
+
| 'time'
|
|
313
|
+
| 'timezone'
|
|
314
|
+
| 'markdown'
|
|
315
|
+
| 'color';
|
|
316
|
+
|
|
317
|
+
type ResourceFields<R> = R extends keyof WorkspaceResources
|
|
318
|
+
? WorkspaceResources[R] extends { readonly fields: infer TFields }
|
|
319
|
+
? TFields
|
|
320
|
+
: never
|
|
321
|
+
: never;
|
|
322
|
+
|
|
323
|
+
type BoundField<F, TKey, TLoaded> = F extends { readonly type: 'file_reference' }
|
|
324
|
+
? BoundFile
|
|
325
|
+
: F extends { readonly type: 'relation' }
|
|
326
|
+
? TKey extends TLoaded
|
|
327
|
+
? F extends { readonly resource: infer R }
|
|
328
|
+
? BoundRecord<R>
|
|
329
|
+
: { readonly [key: string]: OpenBoundField }
|
|
330
|
+
: RelationNotLoaded<TKey>
|
|
331
|
+
: F extends { readonly type: TextFieldType }
|
|
332
|
+
? BoundText
|
|
333
|
+
: F extends { readonly type: 'number' | 'boolean' }
|
|
334
|
+
? BoundScalar
|
|
335
|
+
: BoundOther;
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* The fields of a record that a page binds. `TLoaded` names the relations
|
|
339
|
+
* that the binding loads. A read goes through at most one relation, so the
|
|
340
|
+
* relations of a related record are not loaded.
|
|
341
|
+
*/
|
|
342
|
+
export type BoundRecord<R, TLoaded = never> = [ResourceFields<R>] extends [never]
|
|
343
|
+
? { readonly [key: string]: OpenBoundField }
|
|
344
|
+
: { readonly id: BoundText } & {
|
|
345
|
+
readonly [K in keyof ResourceFields<R>]: BoundField<ResourceFields<R>[K], K, TLoaded>;
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
type LoadedRelations<TBinding> = TBinding extends { readonly relations: readonly (infer K)[] }
|
|
349
|
+
? K
|
|
350
|
+
: never;
|
|
351
|
+
|
|
352
|
+
/** What a `seo` function reads: the record of each binding, by binding name. */
|
|
353
|
+
export type SeoContext<TBindings> = {
|
|
354
|
+
readonly bindings: {
|
|
355
|
+
readonly [K in keyof TBindings]: TBindings[K] extends PageBinding<infer R>
|
|
356
|
+
? BoundRecord<R, LoadedRelations<TBindings[K]>>
|
|
357
|
+
: never;
|
|
358
|
+
};
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
type TemplatePlaceholders<T extends string> = T extends `${string}{{${infer K}}}${infer Rest}`
|
|
362
|
+
? K | TemplatePlaceholders<Rest>
|
|
363
|
+
: never;
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* The resolver builders of a `seo` function. Each is the inline value form of
|
|
367
|
+
* the workflow code task with the same name. The build reads the call and
|
|
368
|
+
* never runs it.
|
|
369
|
+
*/
|
|
370
|
+
export declare const text: {
|
|
371
|
+
/**
|
|
372
|
+
* Replaces each `{{name}}` in the template with its value, for example
|
|
373
|
+
* `text.template('{{title}} | Studio', { title: bindings.class.title })`. An
|
|
374
|
+
* empty value leaves the text around it.
|
|
375
|
+
*/
|
|
376
|
+
template<const T extends string>(
|
|
377
|
+
template: T,
|
|
378
|
+
values: { readonly [K in TemplatePlaceholders<T>]: BoundText | BoundScalar | string }
|
|
379
|
+
): BoundText;
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* The search and link preview metadata of a page. Each value is a string, or
|
|
384
|
+
* a function of the page's bound records that the build makes into a server
|
|
385
|
+
* resolver. The browser never runs it.
|
|
386
|
+
*/
|
|
387
|
+
export type PageSeo<TBindings = {}> = {
|
|
388
|
+
/** The browser tab and search result title. Defaults to the Brand Kit SEO title. */
|
|
389
|
+
title?: string | null | ((context: SeoContext<TBindings>) => BoundText | string);
|
|
390
|
+
/** The meta description. Defaults to the Brand Kit SEO description. */
|
|
391
|
+
description?: string | null | ((context: SeoContext<TBindings>) => BoundText | string);
|
|
392
|
+
/**
|
|
393
|
+
* The social image: the id of a public Media Library file, or a public
|
|
394
|
+
* `file_reference` field of a bound record. Defaults to the Brand Kit image.
|
|
395
|
+
*/
|
|
396
|
+
image?: string | null | ((context: SeoContext<TBindings>) => BoundFile | string);
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
export type PageDefinition<
|
|
400
|
+
TBindings extends Readonly<Record<string, PageBinding>> = Readonly<Record<string, PageBinding>>
|
|
401
|
+
> = UidOption & {
|
|
255
402
|
/**
|
|
256
403
|
* The page's identity, unique in the workspace: a camelCase name of at most
|
|
257
404
|
* 64 letters and digits that starts with a lowercase letter, such as
|
|
@@ -263,12 +410,9 @@ export type PageDefinition = UidOption & {
|
|
|
263
410
|
key?: string;
|
|
264
411
|
/** The URL pattern. Route parameters use `{name}`, for example `/members/{id}`. */
|
|
265
412
|
route: string;
|
|
266
|
-
/** The name in the admin. Defaults to the
|
|
413
|
+
/** The name in the admin. Defaults to a string `seo.title`, then the file name. */
|
|
267
414
|
name?: string | null;
|
|
268
|
-
|
|
269
|
-
description?: string | PageMetaResolver | null;
|
|
270
|
-
/** A public workspace file id, or a resolver that names one. */
|
|
271
|
-
ogImage?: string | PageMetaResolver | null;
|
|
415
|
+
seo?: PageSeo<TBindings>;
|
|
272
416
|
/** HTML added to the page's `<head>`. */
|
|
273
417
|
headHtml?: string | null;
|
|
274
418
|
/** The file name of a layout in `layouts/`, without the extension. */
|
|
@@ -282,16 +426,26 @@ export type PageDefinition = UidOption & {
|
|
|
282
426
|
/** A paused page does not serve. */
|
|
283
427
|
paused?: boolean;
|
|
284
428
|
authorizer?: PageAuthorizer;
|
|
285
|
-
/**
|
|
286
|
-
|
|
429
|
+
/**
|
|
430
|
+
* The record that each route parameter binds to, keyed by parameter name.
|
|
431
|
+
* Name the parameter after the record: `/classes/{class}`.
|
|
432
|
+
*/
|
|
433
|
+
bindings?: TBindings;
|
|
434
|
+
/** @deprecated Use `seo.title`. The build reads it with a warning. */
|
|
435
|
+
title?: string | PageMetaResolver | null;
|
|
436
|
+
/** @deprecated Use `seo.description`. The build reads it with a warning. */
|
|
437
|
+
description?: string | PageMetaResolver | null;
|
|
438
|
+
/** @deprecated Use `seo.image`. The build reads it with a warning. */
|
|
439
|
+
ogImage?: string | PageMetaResolver | null;
|
|
440
|
+
/** @deprecated Use `bindings`. The build reads it with a warning. */
|
|
441
|
+
params?: Readonly<Record<string, PageBinding>>;
|
|
287
442
|
};
|
|
288
443
|
|
|
289
444
|
export type PageComponent = () => unknown;
|
|
290
445
|
|
|
291
|
-
export declare function definePage<
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
): T;
|
|
446
|
+
export declare function definePage<
|
|
447
|
+
const TBindings extends Readonly<Record<string, PageBinding>> = {}
|
|
448
|
+
>(page: PageDefinition<TBindings>, component: PageComponent): PageDefinition<TBindings>;
|
|
295
449
|
|
|
296
450
|
export type LayoutProps = { children?: React.ReactNode };
|
|
297
451
|
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,11 @@ export const defineResource = (resource) => resource;
|
|
|
21
21
|
|
|
22
22
|
export const definePage = (page, _component) => page;
|
|
23
23
|
|
|
24
|
+
// The build reads a text.template call in a seo function and never runs it.
|
|
25
|
+
export const text = {
|
|
26
|
+
template: (template, values) => ({ $type: 'text.template', template, values })
|
|
27
|
+
};
|
|
28
|
+
|
|
24
29
|
export const defineNavigation = (navigation) => navigation;
|
|
25
30
|
|
|
26
31
|
export const defineNotificationType = (type) => type;
|