@diagonal-hq/cli 0.8.1 → 0.9.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.
@@ -1,5 +1,5 @@
1
1
  // Generated by `artisan app:generate-custom-typescript` from VariableType. Do not edit.
2
- // The field builders of defineResource, one for each resource field type, and the data API endpoints.
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
4
  import type { StaticValue } from './index';
5
5
 
@@ -8,6 +8,12 @@ export type FieldType = "boolean" | "color" | "content" | "date" | "datetime" |
8
8
  /** A switch of `dataApi.endpoints` in defineResource. */
9
9
  export type DataApiEndpoint = "analytics_distribution" | "analytics_kpi" | "analytics_leaderboard" | "analytics_time_series" | "count" | "create" | "create_many" | "create_many_from_file" | "delete" | "delete_many" | "export" | "index" | "restore" | "search" | "show" | "update" | "update_many" | "upsert" | "upsert_many";
10
10
 
11
+ /** The operator of a filter condition, as in a record search. */
12
+ export type FilterOperator = "all" | "between" | "contains" | "elem_match" | "ends_with" | "=" | "exists" | ">" | ">=" | "has_value" | "in" | "is" | "is_not" | "is_not_null" | "is_null" | "<" | "<=" | "missing_value" | "mod" | "not" | "!=" | "not_exists" | "not_in" | "regex" | "search" | "starts_with";
13
+
14
+ /** A key that every record has without a field, such as `id`. */
15
+ export type RecordMetaField = "id" | "workspace_id" | "resource_id" | "__meta" | "created_at" | "updated_at" | "deleted_at" | "cascade_key";
16
+
11
17
  /** A declarative resolver tree, for example `{ $type: 'text.slugify', $value: { ... } }`. */
12
18
  export type Resolver = { readonly $type: string; readonly $value?: StaticValue };
13
19
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,13 @@
1
1
  import './globals';
2
2
  import type { ResourceCapabilities } from './capabilities.generated';
3
- import type { DataApiEndpoint, FieldDefinition, FieldType } from './fields.generated';
3
+ import type {
4
+ DataApiEndpoint,
5
+ FieldDefinition,
6
+ FieldType,
7
+ FilterOperator,
8
+ RecordMetaField,
9
+ Resolver
10
+ } from './fields.generated';
4
11
 
5
12
  // The configuration helpers of file-based workspaces. The workspace build
6
13
  // reads these calls as static data. index.js implements each define* function
@@ -66,6 +73,8 @@ export type {
66
73
  FieldSchemaDefinition,
67
74
  FieldSchemaSetting,
68
75
  FieldType,
76
+ FilterOperator,
77
+ RecordMetaField,
69
78
  RelationFieldOptions,
70
79
  RelationInverse,
71
80
  Resolver
@@ -86,13 +95,79 @@ export type PolicyScope =
86
95
 
87
96
  export type PolicyAccess = 'public' | 'protected';
88
97
 
89
- export type PolicyDefinition = {
98
+ /**
99
+ * One condition of a filter tree, in the shape of a record search filter. The
100
+ * field is a field key or a path, for example `author.id`. The value can be a
101
+ * resolver, for example `{ $type: 'user.current', $value: { key: 'id' } }`
102
+ * for the signed-in member.
103
+ */
104
+ export type FilterCondition = {
105
+ field: string;
106
+ operator: FilterOperator;
107
+ value?: StaticValue | Resolver;
108
+ case_insensitive?: boolean;
109
+ };
110
+
111
+ export type FilterGroup = {
112
+ operator: 'and' | 'or' | 'nor';
113
+ conditions: readonly (FilterGroup | FilterCondition)[];
114
+ };
115
+
116
+ /**
117
+ * A field that a policy lets through, by key. A relation path, for example
118
+ * `teacher.name`, limits the related record to that key. A key alone always
119
+ * shows the field. A `condition` is a resolver that returns true when the
120
+ * field shows.
121
+ */
122
+ export type PolicyFieldKey<TKey extends string = string> = TKey | `${TKey}.${string}`;
123
+
124
+ export type PolicyField<TKey extends string = string> =
125
+ | PolicyFieldKey<TKey>
126
+ | { key: PolicyFieldKey<TKey>; condition?: Resolver };
127
+
128
+ type PolicyBase<TKey extends string> = {
90
129
  name: string;
91
130
  scope: 'all' | readonly PolicyScope[];
92
- access: PolicyAccess;
93
131
  description?: string | null;
132
+ /** A disabled policy grants nothing. Defaults to true. */
133
+ enabled?: boolean;
134
+ /** Limits the records that the policy covers, for example the member's own records. */
135
+ filter?: FilterGroup;
136
+ /**
137
+ * The fields that the policy lets through. A field that the list leaves out
138
+ * is hidden from reads and refused on writes. Without a list, the policy
139
+ * covers every field.
140
+ */
141
+ fields?: readonly PolicyField<TKey>[];
94
142
  };
95
143
 
144
+ /** Grants access to every visitor, signed in or not. */
145
+ export type PublicPolicyDefinition<TKey extends string = string> = PolicyBase<TKey> & {
146
+ access: 'public';
147
+ resource?: never;
148
+ authorizer?: never;
149
+ };
150
+
151
+ /**
152
+ * Grants access to the signed-in members of `resource`, an `authenticatable`
153
+ * resource or the platform staff resource. Without `resource`, only system
154
+ * administrators have access.
155
+ */
156
+ export type ProtectedPolicyDefinition<TKey extends string = string> = PolicyBase<TKey> & {
157
+ access?: 'protected';
158
+ /** The resource that members sign in as, as `Resources.<Name>.slug`. */
159
+ resource?: ResourceReference;
160
+ /**
161
+ * Tests the signed-in member's own record, for example a role. The policy
162
+ * applies only when the member's record matches.
163
+ */
164
+ authorizer?: FilterGroup;
165
+ };
166
+
167
+ export type PolicyDefinition<TKey extends string = string> =
168
+ | PublicPolicyDefinition<TKey>
169
+ | ProtectedPolicyDefinition<TKey>;
170
+
96
171
  export type IndexDefinition<TKey extends string = string> = {
97
172
  fields: readonly TKey[];
98
173
  unique?: boolean;
@@ -134,7 +209,7 @@ export type ResourceDefinition<
134
209
  dataApi?: ResourceDataApi;
135
210
  /** A static resource refuses normal record writes. */
136
211
  static?: boolean;
137
- policies: readonly PolicyDefinition[];
212
+ policies: readonly PolicyDefinition<Extract<keyof TFields, string> | RecordMetaField>[];
138
213
  /**
139
214
  * The platform capabilities of the resource, keyed by capability. A field
140
215
  * reference names a field of this resource by its key. The deploy validates
@@ -157,7 +232,7 @@ export declare function defineResource<const TFields extends Record<string, Fiel
157
232
  export type PageMetaResolver = { readonly type: string; readonly [key: string]: unknown };
158
233
 
159
234
  export type PageRouteParam = {
160
- /** The resource whose record the parameter names, as `Resources.<Name>`. */
235
+ /** The resource whose record the parameter names, as `Resources.<Name>.slug`. */
161
236
  resource: ResourceReference;
162
237
  /** The field the parameter matches. Defaults to the record id. */
163
238
  lookupField?: string | null;
@@ -170,7 +245,7 @@ export type PageAuthorizer =
170
245
  | null
171
246
  | 'authenticated'
172
247
  | {
173
- /** The resource whose signed-in records may view the page, as `Resources.<Name>`. */
248
+ /** The resource whose signed-in records may view the page, as `Resources.<Name>.slug`. */
174
249
  resource?: ResourceReference | null;
175
250
  /** Permission ids. A viewer needs any one of them. */
176
251
  permissions?: readonly string[];
@@ -227,9 +302,10 @@ export type NavigationDefinition = { id: string; items: readonly NavigationItem[
227
302
  export declare function defineNavigation<const T extends NavigationDefinition>(navigation: T): T;
228
303
 
229
304
  /**
230
- * The slug of a resource: its file name in `resources/`. Use `Resources.<Name>`
231
- * from `@app/generated/resources`, which `diagonal check` writes, so the editor
232
- * and the build catch a wrong name. A slug string builds with a warning.
305
+ * The slug of a resource: its file name in `resources/`. Use
306
+ * `Resources.<Name>.slug` from `@app/generated/resources`, which `diagonal check`
307
+ * writes, so the editor and the build catch a wrong name. A slug string builds
308
+ * with a warning.
233
309
  */
234
310
  export type ResourceReference = string;
235
311
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagonal-hq/cli",
3
- "version": "0.8.1",
3
+ "version": "0.9.1",
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": {