@diagonal-hq/cli 0.32.2 → 0.33.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/dist/index.d.ts CHANGED
@@ -486,14 +486,51 @@ export type ResourceDataApi = {
486
486
  };
487
487
 
488
488
  /**
489
- * One record of a static resource: a value for each field key, and a `uid`.
490
- * The uid is the record id in every environment, a UUID version 7 that
491
- * `diagonal check` writes.
489
+ * The metadata of each resource of the workspace, keyed by the name of its
490
+ * folder in `resources/`. `diagonal check` fills it in
491
+ * `generated/resources.ts`. A file of a resource folder names its folder in
492
+ * the type argument of its define call, such as `definePolicy<'posts'>`, to
493
+ * get the field keys of its resource. The build checks that the argument is
494
+ * the folder of the file.
495
+ */
496
+ export interface WorkspaceResourceFolders {}
497
+
498
+ /**
499
+ * The fields of the resource folder `TFolder`, as field definitions by key.
500
+ * A folder that `WorkspaceResourceFolders` does not have yet, such as a new
501
+ * resource before `diagonal check`, has open fields.
502
+ */
503
+ export type ResourceFolderFields<TFolder extends string> =
504
+ TFolder extends keyof WorkspaceResourceFolders
505
+ ? WorkspaceResourceFolders[TFolder] extends { readonly fields: infer TFields }
506
+ ? {
507
+ [TKey in keyof TFields]: TFields[TKey] extends {
508
+ readonly type: infer TType extends FieldType;
509
+ }
510
+ ? FieldDefinition<TType>
511
+ : FieldDefinition;
512
+ }
513
+ : Record<string, FieldDefinition>
514
+ : Record<string, FieldDefinition>;
515
+
516
+ /**
517
+ * One record of a static resource, in `resources/<folder>/records/<key>.ts`:
518
+ * a value for each field key, and a `uid`. The uid is the record id in every
519
+ * environment, a UUID version 7 that `diagonal check` writes. Code names a
520
+ * record as `Resources.<Name>.records.<key>`, with its `uid` and the value of
521
+ * each field. The file name is the record key.
492
522
  */
493
523
  export type StaticRecordDefinition<
494
524
  TFields extends Record<string, FieldDefinition> = Record<string, FieldDefinition>
495
525
  > = UidOption & { readonly [K in Extract<keyof TFields, string>]?: StaticValue };
496
526
 
527
+ /**
528
+ * The settings of a resource, in `resources/<folder>/resource.ts`. Each field
529
+ * is a file in `fields/`, each policy a file in `policies/`, and each record of
530
+ * a static resource a file in `records/` of the same folder. The folder name
531
+ * is the slug of a resource without a `slug` option, and it gives the name in
532
+ * `Resources`.
533
+ */
497
534
  export type ResourceDefinition<
498
535
  TFields extends Record<string, FieldDefinition> = Record<string, FieldDefinition>
499
536
  > = UidOption &
@@ -510,26 +547,21 @@ export type ResourceDefinition<
510
547
  | Extract<keyof TFields, string>
511
548
  | `${Extract<keyof TFields, string>}.${string}`
512
549
  )[];
513
- /** Every field key once, in the order that forms and tables show them. Defaults to the order of `fields`. */
550
+ /**
551
+ * The field keys that forms and tables show first, in this order. The
552
+ * other fields follow in the order in which they were made (their uid
553
+ * order), so a new field does not need an entry.
554
+ */
514
555
  fieldOrder?: readonly Extract<keyof TFields, string>[];
515
- fields: TFields;
516
556
  indexes?: readonly IndexDefinition<Extract<keyof TFields, string>>[];
517
557
  embeddings?: ResourceEmbeddings<Extract<keyof TFields, string>>;
518
558
  dataApi?: ResourceDataApi;
519
559
  /**
520
- * A static resource declares all of its records in `records`. The deploy
560
+ * A static resource declares all of its records in `records/`. The deploy
521
561
  * writes them, and normal record writes to the resource are refused. A
522
562
  * static resource has no capabilities and no relation fields of its own.
523
563
  */
524
564
  static?: boolean;
525
- /**
526
- * Every record of a static resource, by record key, for example
527
- * `{ standard: { uid: '019a…', name: 'Standard' } }`. Use `{}` for no records.
528
- * Code names a record as `Resources.<Name>.records.<key>`, with its `uid`
529
- * and the value of each field.
530
- */
531
- records?: { readonly [key: string]: StaticRecordDefinition<TFields> };
532
- policies: readonly PolicyDefinition<Extract<keyof TFields, string> | RecordMetaField>[];
533
565
  /**
534
566
  * The platform capabilities of the resource, keyed by capability. A field
535
567
  * reference names a field of this resource by its key. The deploy validates
@@ -538,9 +570,33 @@ export type ResourceDefinition<
538
570
  capabilities?: ResourceCapabilities<TFields>;
539
571
  };
540
572
 
541
- export declare function defineResource<const TFields extends Record<string, FieldDefinition>>(
542
- resource: ResourceDefinition<TFields>
543
- ): ResourceDefinition<TFields>;
573
+ /**
574
+ * The settings of the resource in `resources/<folder>/resource.ts`. Give the
575
+ * folder as the type argument, `defineResource<'posts'>({...})`, to check the
576
+ * field keys of the settings against the fields of the resource.
577
+ */
578
+ export declare function defineResource<TFolder extends string = string>(
579
+ resource: ResourceDefinition<ResourceFolderFields<TFolder>>
580
+ ): ResourceDefinition<ResourceFolderFields<TFolder>>;
581
+
582
+ /**
583
+ * One policy of a resource, in `resources/<folder>/policies/<key>.ts`. The
584
+ * file name gives its key in `Resources.<Name>.policies`. Give the folder as
585
+ * the type argument, `definePolicy<'posts'>({...})`, to check the field keys
586
+ * of `fields`.
587
+ */
588
+ export declare function definePolicy<TFolder extends string = string>(
589
+ policy: PolicyDefinition<Extract<keyof ResourceFolderFields<TFolder>, string> | RecordMetaField>
590
+ ): PolicyDefinition<Extract<keyof ResourceFolderFields<TFolder>, string> | RecordMetaField>;
591
+
592
+ /**
593
+ * One record of a static resource, in `resources/<folder>/records/<key>.ts`.
594
+ * Give the folder as the type argument, `defineRecord<'rooms'>({...})`, to
595
+ * check the field keys of the values.
596
+ */
597
+ export declare function defineRecord<TFolder extends string = string>(
598
+ record: StaticRecordDefinition<ResourceFolderFields<TFolder>>
599
+ ): StaticRecordDefinition<ResourceFolderFields<TFolder>>;
544
600
 
545
601
  /**
546
602
  * A resolver object in a deprecated flat meta option. The build accepts only a
package/dist/index.js CHANGED
@@ -31,6 +31,10 @@ export const defineRole = (role) => role;
31
31
 
32
32
  export const defineResource = (resource) => resource;
33
33
 
34
+ export const definePolicy = (policy) => policy;
35
+
36
+ export const defineRecord = (record) => record;
37
+
34
38
  export const definePage = (page, _component) => page;
35
39
 
36
40
  // The build reads a text.template call in a seo function and never runs it.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagonal-hq/cli",
3
- "version": "0.32.2",
3
+ "version": "0.33.0",
4
4
  "description": "The diagonal CLI and the configuration helpers for file-based Diagonal workspaces.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {