@rebasepro/sdk-generator 0.0.1-canary.4d4fb3e
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/LICENSE +6 -0
- package/dist/common/src/collections/CollectionRegistry.d.ts +48 -0
- package/dist/common/src/collections/index.d.ts +1 -0
- package/dist/common/src/data/buildRebaseData.d.ts +14 -0
- package/dist/common/src/index.d.ts +3 -0
- package/dist/common/src/util/builders.d.ts +57 -0
- package/dist/common/src/util/callbacks.d.ts +6 -0
- package/dist/common/src/util/collections.d.ts +11 -0
- package/dist/common/src/util/common.d.ts +2 -0
- package/dist/common/src/util/conditions.d.ts +26 -0
- package/dist/common/src/util/entities.d.ts +36 -0
- package/dist/common/src/util/enums.d.ts +3 -0
- package/dist/common/src/util/index.d.ts +16 -0
- package/dist/common/src/util/navigation_from_path.d.ts +34 -0
- package/dist/common/src/util/navigation_utils.d.ts +20 -0
- package/dist/common/src/util/parent_references_from_path.d.ts +6 -0
- package/dist/common/src/util/paths.d.ts +14 -0
- package/dist/common/src/util/permissions.d.ts +5 -0
- package/dist/common/src/util/references.d.ts +2 -0
- package/dist/common/src/util/relations.d.ts +12 -0
- package/dist/common/src/util/resolutions.d.ts +72 -0
- package/dist/common/src/util/storage.d.ts +24 -0
- package/dist/index.cjs +211 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.es.js +208 -0
- package/dist/index.es.js.map +1 -0
- package/dist/sdk-generator/src/generate-types.d.ts +2 -0
- package/dist/sdk-generator/src/index.d.ts +19 -0
- package/dist/sdk-generator/src/utils.d.ts +22 -0
- package/dist/types/src/controllers/analytics_controller.d.ts +7 -0
- package/dist/types/src/controllers/auth.d.ts +117 -0
- package/dist/types/src/controllers/client.d.ts +58 -0
- package/dist/types/src/controllers/collection_registry.d.ts +44 -0
- package/dist/types/src/controllers/customization_controller.d.ts +54 -0
- package/dist/types/src/controllers/data.d.ts +141 -0
- package/dist/types/src/controllers/data_driver.d.ts +168 -0
- package/dist/types/src/controllers/database_admin.d.ts +11 -0
- package/dist/types/src/controllers/dialogs_controller.d.ts +36 -0
- package/dist/types/src/controllers/effective_role.d.ts +4 -0
- package/dist/types/src/controllers/index.d.ts +17 -0
- package/dist/types/src/controllers/local_config_persistence.d.ts +20 -0
- package/dist/types/src/controllers/navigation.d.ts +213 -0
- package/dist/types/src/controllers/registry.d.ts +51 -0
- package/dist/types/src/controllers/side_dialogs_controller.d.ts +67 -0
- package/dist/types/src/controllers/side_entity_controller.d.ts +89 -0
- package/dist/types/src/controllers/snackbar.d.ts +24 -0
- package/dist/types/src/controllers/storage.d.ts +173 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/rebase_context.d.ts +101 -0
- package/dist/types/src/types/backend.d.ts +533 -0
- package/dist/types/src/types/builders.d.ts +14 -0
- package/dist/types/src/types/chips.d.ts +5 -0
- package/dist/types/src/types/collections.d.ts +812 -0
- package/dist/types/src/types/data_source.d.ts +64 -0
- package/dist/types/src/types/entities.d.ts +145 -0
- package/dist/types/src/types/entity_actions.d.ts +98 -0
- package/dist/types/src/types/entity_callbacks.d.ts +173 -0
- package/dist/types/src/types/entity_link_builder.d.ts +7 -0
- package/dist/types/src/types/entity_overrides.d.ts +9 -0
- package/dist/types/src/types/entity_views.d.ts +61 -0
- package/dist/types/src/types/export_import.d.ts +21 -0
- package/dist/types/src/types/index.d.ts +22 -0
- package/dist/types/src/types/locales.d.ts +4 -0
- package/dist/types/src/types/modify_collections.d.ts +5 -0
- package/dist/types/src/types/plugins.d.ts +225 -0
- package/dist/types/src/types/properties.d.ts +1091 -0
- package/dist/types/src/types/property_config.d.ts +70 -0
- package/dist/types/src/types/relations.d.ts +336 -0
- package/dist/types/src/types/slots.d.ts +228 -0
- package/dist/types/src/types/translations.d.ts +826 -0
- package/dist/types/src/types/user_management_delegate.d.ts +120 -0
- package/dist/types/src/types/websockets.d.ts +78 -0
- package/dist/types/src/users/index.d.ts +2 -0
- package/dist/types/src/users/roles.d.ts +22 -0
- package/dist/types/src/users/user.d.ts +46 -0
- package/jest.config.cjs +13 -0
- package/package.json +51 -0
- package/src/generate-types.ts +176 -0
- package/src/index.ts +71 -0
- package/src/json-logic-js.d.ts +8 -0
- package/src/utils.ts +42 -0
- package/test/sdk-generator.test.ts +78 -0
- package/tsconfig.json +26 -0
- package/vite.config.ts +49 -0
|
@@ -0,0 +1,1091 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { EntityReference, EntityRelation, EntityValues, GeoPoint, Entity } from "./entities";
|
|
3
|
+
import { FilterValues } from "./collections";
|
|
4
|
+
import { ColorKey, ColorScheme } from "./chips";
|
|
5
|
+
import { AuthController } from "../controllers";
|
|
6
|
+
import { Relation } from "./relations";
|
|
7
|
+
import { EntityAfterReadProps, EntityBeforeSaveProps } from "./entity_callbacks";
|
|
8
|
+
import { User } from "../users";
|
|
9
|
+
/**
|
|
10
|
+
* Callbacks/Hooks for individual property fields
|
|
11
|
+
* @group Entity properties
|
|
12
|
+
*/
|
|
13
|
+
export type PropertyCallbacks<T = unknown, M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> = {
|
|
14
|
+
/**
|
|
15
|
+
* Callback used after fetching data, to transform the value before rendering
|
|
16
|
+
*/
|
|
17
|
+
afterRead?(props: Omit<EntityAfterReadProps<M, USER>, 'entity'> & {
|
|
18
|
+
value: T;
|
|
19
|
+
entity: Entity<M> | undefined;
|
|
20
|
+
}): Promise<T> | T;
|
|
21
|
+
/**
|
|
22
|
+
* Callback used before saving, after validation.
|
|
23
|
+
* You can modify the value before it's saved.
|
|
24
|
+
*/
|
|
25
|
+
beforeSave?(props: Omit<EntityBeforeSaveProps<M, USER>, 'values'> & {
|
|
26
|
+
value: T;
|
|
27
|
+
previousValue: T | undefined;
|
|
28
|
+
values: Partial<M>;
|
|
29
|
+
}): Promise<T> | T;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* @group Entity properties
|
|
33
|
+
*/
|
|
34
|
+
export type DataType = "string" | "number" | "boolean" | "date" | "geopoint" | "reference" | "relation" | "array" | "map";
|
|
35
|
+
export type Property = StringProperty | NumberProperty | BooleanProperty | DateProperty | GeopointProperty | ReferenceProperty | RelationProperty | ArrayProperty | MapProperty;
|
|
36
|
+
export type Properties = {
|
|
37
|
+
[key: string]: Property;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* A helper type to infer the underlying data type from a Property definition.
|
|
41
|
+
* This is the core of the type inference system.
|
|
42
|
+
*/
|
|
43
|
+
export type InferPropertyType<P extends Property> = P extends StringProperty ? string : P extends NumberProperty ? number : P extends BooleanProperty ? boolean : P extends DateProperty ? Date : P extends GeopointProperty ? GeoPoint : P extends ReferenceProperty ? EntityReference : P extends RelationProperty ? EntityRelation | EntityRelation[] : P extends ArrayProperty ? (P["of"] extends Property ? InferPropertyType<P["of"]>[] : unknown[]) : P extends MapProperty ? (P["properties"] extends Properties ? InferEntityType<P["properties"]> : Record<string, unknown>) : never;
|
|
44
|
+
/**
|
|
45
|
+
* A generic type that converts a `Properties` schema definition into a corresponding
|
|
46
|
+
* TypeScript entity type. It correctly handles required and optional properties.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const productSchema = {
|
|
50
|
+
* name: { type: 'string', validation: { required: true } },
|
|
51
|
+
* price: { type: 'number' }
|
|
52
|
+
* };
|
|
53
|
+
* type Product = InferEntityType<typeof productSchema>;
|
|
54
|
+
* // Result: { name: string; price?: number; }
|
|
55
|
+
*/
|
|
56
|
+
export type InferEntityType<P extends Properties> = {
|
|
57
|
+
-readonly [K in keyof P as P[K] extends {
|
|
58
|
+
validation?: {
|
|
59
|
+
required: true;
|
|
60
|
+
};
|
|
61
|
+
} ? K : never]: InferPropertyType<P[K]>;
|
|
62
|
+
} & {
|
|
63
|
+
-readonly [K in keyof P as P[K] extends {
|
|
64
|
+
validation?: {
|
|
65
|
+
required: true;
|
|
66
|
+
};
|
|
67
|
+
} ? never : K]?: InferPropertyType<P[K]>;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Interface including all common properties of a CMS property.
|
|
71
|
+
* @group Entity properties
|
|
72
|
+
*/
|
|
73
|
+
export interface BaseProperty<CustomProps = unknown> {
|
|
74
|
+
/**
|
|
75
|
+
* Property name (e.g. Product)
|
|
76
|
+
*/
|
|
77
|
+
name: string;
|
|
78
|
+
/**
|
|
79
|
+
* Property description, always displayed under the field
|
|
80
|
+
*/
|
|
81
|
+
description?: string;
|
|
82
|
+
/**
|
|
83
|
+
* You can use this prop to reuse a property that has been defined
|
|
84
|
+
* in the top level of the CMS in the prop `fields`.
|
|
85
|
+
* All the configuration will be taken from the inherited config, and
|
|
86
|
+
* overwritten by the current property config.
|
|
87
|
+
*/
|
|
88
|
+
propertyConfig?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Width in pixels of this column in the collection view. If not set
|
|
91
|
+
* the width is inferred based on the other configurations
|
|
92
|
+
*/
|
|
93
|
+
columnWidth?: number;
|
|
94
|
+
/**
|
|
95
|
+
* Do not show this property in the collection view
|
|
96
|
+
*/
|
|
97
|
+
hideFromCollection?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Is this a read only property. When set to true, it gets rendered as a
|
|
100
|
+
* preview.
|
|
101
|
+
*/
|
|
102
|
+
readOnly?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Is this field disabled.
|
|
105
|
+
* When set to true, it gets rendered as a
|
|
106
|
+
* disabled field. You can also specify a configuration for defining the
|
|
107
|
+
* behaviour of disabled properties (including custom messages, clear value on
|
|
108
|
+
* disabled or hide the field completely)
|
|
109
|
+
*/
|
|
110
|
+
disabled?: boolean | PropertyDisabledConfig;
|
|
111
|
+
/**
|
|
112
|
+
* Rules for validating this property
|
|
113
|
+
*/
|
|
114
|
+
validation?: PropertyValidationSchema;
|
|
115
|
+
/**
|
|
116
|
+
* This value will be set by default for new entities.
|
|
117
|
+
*/
|
|
118
|
+
defaultValue?: unknown;
|
|
119
|
+
/**
|
|
120
|
+
* A number between 0 and 100 that indicates the width of the field in the form view.
|
|
121
|
+
* It defaults to 100, but you can set it to 50 to have two fields in the same row.
|
|
122
|
+
*/
|
|
123
|
+
widthPercentage?: number;
|
|
124
|
+
/**
|
|
125
|
+
* Additional props that are passed to the components defined in `field`
|
|
126
|
+
* or in `preview`.
|
|
127
|
+
*/
|
|
128
|
+
customProps?: CustomProps;
|
|
129
|
+
/**
|
|
130
|
+
* Use this to define dynamic properties that change based on certain conditions
|
|
131
|
+
* or on the entity's values. For example, you can make a field read-only if
|
|
132
|
+
* another field has a certain value.
|
|
133
|
+
* This function receives the same props as a `PropertyBuilder` and should return a partial `Property` object.
|
|
134
|
+
*/
|
|
135
|
+
dynamicProps?: (props: PropertyBuilderProps) => Partial<Property>;
|
|
136
|
+
/**
|
|
137
|
+
* Declarative conditions for dynamic property behavior using JSON Logic.
|
|
138
|
+
*
|
|
139
|
+
* An alternative to PropertyBuilder functions that can be:
|
|
140
|
+
* - Stored in the database as JSON
|
|
141
|
+
* - Edited via the collection editor UI
|
|
142
|
+
* - Evaluated at runtime like property builders
|
|
143
|
+
*
|
|
144
|
+
* @see PropertyConditions for available condition options
|
|
145
|
+
* @see https://jsonlogic.com/ for JSON Logic syntax
|
|
146
|
+
*/
|
|
147
|
+
conditions?: PropertyConditions;
|
|
148
|
+
/**
|
|
149
|
+
* Callbacks/Hooks for this property field to transform and sanitize data during its lifecycle.
|
|
150
|
+
*/
|
|
151
|
+
callbacks?: PropertyCallbacks;
|
|
152
|
+
/**
|
|
153
|
+
* Custom field component to render this property in forms.
|
|
154
|
+
* Used by the CMS layer.
|
|
155
|
+
*/
|
|
156
|
+
Field?: React.ComponentType<any>;
|
|
157
|
+
/**
|
|
158
|
+
* Custom preview component to render this property in previews/tables.
|
|
159
|
+
* Used by the CMS layer.
|
|
160
|
+
*/
|
|
161
|
+
Preview?: React.ComponentType<any>;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* @group Entity properties
|
|
165
|
+
*/
|
|
166
|
+
export interface StringProperty extends BaseProperty {
|
|
167
|
+
type: "string";
|
|
168
|
+
/**
|
|
169
|
+
* Optional database column type. If not set, it defaults to `varchar` or `uuid` depending on `isId` configuration.
|
|
170
|
+
* Use `text` for strings with unbound length, `char` for fixed-length strings, or `varchar` for variable-length strings with a limit.
|
|
171
|
+
*/
|
|
172
|
+
columnType?: "varchar" | "text" | "char";
|
|
173
|
+
/**
|
|
174
|
+
* Rules for validating this property
|
|
175
|
+
*/
|
|
176
|
+
validation?: StringPropertyValidationSchema;
|
|
177
|
+
/**
|
|
178
|
+
* Marks this field as a Primary Key / Unique Identifier.
|
|
179
|
+
* Framework behavior: Auto-maps to `collection.primaryKeys` internally if not explicitly set.
|
|
180
|
+
* Drizzle append: `.primaryKey()`
|
|
181
|
+
* UI behavior: Field value cannot be changed after creation.
|
|
182
|
+
*
|
|
183
|
+
* You can set this to `"manual"` for a user-defined ID, or specify a generation strategy:
|
|
184
|
+
* 'uuid' -> Drizzle `.defaultRandom()` (Postgres gen_random_uuid())
|
|
185
|
+
* 'cuid' -> Drizzle `.default(sql\`cuid()\`)`
|
|
186
|
+
* Or any other random string to act as a raw SQL default expression: e.g. `nanoid()`
|
|
187
|
+
*
|
|
188
|
+
* On the UI side, the field automatically gets disabled on new entities if a string strategy is provided.
|
|
189
|
+
*/
|
|
190
|
+
isId?: boolean | "manual" | "uuid" | "cuid" | string;
|
|
191
|
+
/**
|
|
192
|
+
* You can use the enum values providing a map of possible
|
|
193
|
+
* exclusive values the property can take, mapped to the label that it is
|
|
194
|
+
* displayed in the dropdown. You can use a simple object with the format
|
|
195
|
+
* `value` => `label`, or with the format `value` => `EnumValueConfig` if you
|
|
196
|
+
* need extra customization, (like disabling specific options or assigning
|
|
197
|
+
* colors). If you need to ensure the order of the elements, you can pass
|
|
198
|
+
* a `Map` instead of a plain object.
|
|
199
|
+
*
|
|
200
|
+
*/
|
|
201
|
+
enum?: EnumValues;
|
|
202
|
+
/**
|
|
203
|
+
* Is this string property long enough so it should be displayed in
|
|
204
|
+
* a multiple line field. Defaults to false. If set to true,
|
|
205
|
+
* the number of lines adapts to the content
|
|
206
|
+
*/
|
|
207
|
+
multiline?: boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Should this string property be displayed as a markdown field. If true,
|
|
210
|
+
* the field is rendered as a text editors that supports markdown highlight
|
|
211
|
+
* syntax. It also includes a preview of the result.
|
|
212
|
+
*/
|
|
213
|
+
markdown?: boolean;
|
|
214
|
+
/**
|
|
215
|
+
* You can specify a `Storage` configuration. It is used to
|
|
216
|
+
* indicate that this string refers to a path in your storage provider.
|
|
217
|
+
*/
|
|
218
|
+
storage?: StorageConfig;
|
|
219
|
+
/**
|
|
220
|
+
* This property is used to indicate that the string is a user ID, and
|
|
221
|
+
* it will be rendered as a user picker.
|
|
222
|
+
* Note that the user ID needs to be the one used in your authentication
|
|
223
|
+
* provider, e.g. Firebase Auth.
|
|
224
|
+
* You can also use a property builder to specify the user path dynamically
|
|
225
|
+
* based on other values of the entity.
|
|
226
|
+
*/
|
|
227
|
+
userSelect?: boolean;
|
|
228
|
+
/**
|
|
229
|
+
* If the value of this property is a URL, you can set this flag to true
|
|
230
|
+
* to add a link, or one of the supported media types to render a preview
|
|
231
|
+
*/
|
|
232
|
+
url?: boolean | PreviewType;
|
|
233
|
+
/**
|
|
234
|
+
* Does this field include an email
|
|
235
|
+
*/
|
|
236
|
+
email?: boolean;
|
|
237
|
+
/**
|
|
238
|
+
* Should this string be rendered as a tag instead of just text.
|
|
239
|
+
*/
|
|
240
|
+
previewAsTag?: boolean;
|
|
241
|
+
/**
|
|
242
|
+
* Add an icon to clear the value and set it to `null`. Defaults to `false`
|
|
243
|
+
*/
|
|
244
|
+
clearable?: boolean;
|
|
245
|
+
/**
|
|
246
|
+
* You can use this property (a string) to behave as a reference to another
|
|
247
|
+
* collection. The stored value is the ID of the entity in the
|
|
248
|
+
* collection, and the `path` prop is used to
|
|
249
|
+
* define the collection this reference points to.
|
|
250
|
+
*/
|
|
251
|
+
reference?: ReferenceProperty;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* @group Entity properties
|
|
255
|
+
*/
|
|
256
|
+
export interface NumberProperty extends BaseProperty {
|
|
257
|
+
type: "number";
|
|
258
|
+
/**
|
|
259
|
+
* Optional database column type. Allows specifying exact database numeric types.
|
|
260
|
+
* If not provided, integer fields (where validation.integer is true or isId is true) default to `integer`, others to `numeric`.
|
|
261
|
+
*/
|
|
262
|
+
columnType?: "integer" | "real" | "double precision" | "numeric" | "bigint" | "serial" | "bigserial";
|
|
263
|
+
/**
|
|
264
|
+
* Rules for validating this property
|
|
265
|
+
*/
|
|
266
|
+
validation?: NumberPropertyValidationSchema;
|
|
267
|
+
/**
|
|
268
|
+
* Marks this field as a Primary Key / Unique Identifier.
|
|
269
|
+
* Framework behavior: Auto-maps to `collection.primaryKeys` internally if not explicitly set.
|
|
270
|
+
* Drizzle append: `.primaryKey()`
|
|
271
|
+
* UI behavior: Field value cannot be changed after creation.
|
|
272
|
+
*
|
|
273
|
+
* You can set this to `"manual"` for a user-defined ID, or specify a generation strategy:
|
|
274
|
+
* 'increment' -> PostgreSQL `GENERATED BY DEFAULT AS IDENTITY` or auto-incrementing integer.
|
|
275
|
+
* Or any other random string to act as a raw SQL default expression.
|
|
276
|
+
*/
|
|
277
|
+
isId?: boolean | "manual" | "increment" | string;
|
|
278
|
+
/**
|
|
279
|
+
* You can use the enum values providing a map of possible
|
|
280
|
+
* exclusive values the property can take, mapped to the label that it is
|
|
281
|
+
* displayed in the dropdown.
|
|
282
|
+
*/
|
|
283
|
+
enum?: EnumValues;
|
|
284
|
+
/**
|
|
285
|
+
* Add an icon to clear the value and set it to `null`. Defaults to `false`
|
|
286
|
+
*/
|
|
287
|
+
clearable?: boolean;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* @group Entity properties
|
|
291
|
+
*/
|
|
292
|
+
export interface BooleanProperty extends BaseProperty {
|
|
293
|
+
type: "boolean";
|
|
294
|
+
/**
|
|
295
|
+
* Rules for validating this property
|
|
296
|
+
*/
|
|
297
|
+
validation?: PropertyValidationSchema;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* @group Entity properties
|
|
301
|
+
*/
|
|
302
|
+
export interface DateProperty extends BaseProperty {
|
|
303
|
+
type: "date";
|
|
304
|
+
/**
|
|
305
|
+
* Optional database column type. If not set, defaults to `timestamp` with timezone.
|
|
306
|
+
*/
|
|
307
|
+
columnType?: "timestamp" | "date" | "time";
|
|
308
|
+
/**
|
|
309
|
+
* Rules for validating this property
|
|
310
|
+
*/
|
|
311
|
+
validation?: DatePropertyValidationSchema;
|
|
312
|
+
/**
|
|
313
|
+
* Set the granularity of the field to a date or date + time.
|
|
314
|
+
* Defaults to `date_time`.
|
|
315
|
+
*
|
|
316
|
+
*/
|
|
317
|
+
mode?: "date" | "date_time";
|
|
318
|
+
/**
|
|
319
|
+
* Timezone string to evaluate the date in.
|
|
320
|
+
*/
|
|
321
|
+
timezone?: string;
|
|
322
|
+
/**
|
|
323
|
+
* If this flag is set to `on_create` or `on_update` this timestamp is
|
|
324
|
+
* updated automatically on creation of the entity only or on every
|
|
325
|
+
* update (including creation). Useful for creating `created_on` or
|
|
326
|
+
* `updated_on` fields
|
|
327
|
+
*/
|
|
328
|
+
autoValue?: "on_create" | "on_update";
|
|
329
|
+
/**
|
|
330
|
+
* Add an icon to clear the value and set it to `null`. Defaults to `false`
|
|
331
|
+
*/
|
|
332
|
+
clearable?: boolean;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* @group Entity properties
|
|
336
|
+
*/
|
|
337
|
+
export interface GeopointProperty extends BaseProperty {
|
|
338
|
+
type: "geopoint";
|
|
339
|
+
/**
|
|
340
|
+
* Rules for validating this property
|
|
341
|
+
*/
|
|
342
|
+
validation?: PropertyValidationSchema;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* @group Entity properties
|
|
346
|
+
*/
|
|
347
|
+
export interface ReferenceProperty extends BaseProperty {
|
|
348
|
+
type: "reference";
|
|
349
|
+
/**
|
|
350
|
+
* Marks this field as a Primary Key / Unique Identifier.
|
|
351
|
+
* Framework behavior: Auto-maps to `collection.primaryKeys` internally if not explicitly set.
|
|
352
|
+
* Drizzle append: `.primaryKey()`
|
|
353
|
+
* UI behavior: Field value cannot be changed after creation.
|
|
354
|
+
*/
|
|
355
|
+
isId?: boolean;
|
|
356
|
+
/**
|
|
357
|
+
* Absolute collection path of the collection this reference points to.
|
|
358
|
+
* The collection of the entity is inferred based on the root navigation, so
|
|
359
|
+
* the filters and search delegate existing there are applied to this view
|
|
360
|
+
* as well.
|
|
361
|
+
* You can leave this prop undefined if the path is not yet know, e.g.
|
|
362
|
+
* you are using a property builder and the path depends on a different
|
|
363
|
+
* property.
|
|
364
|
+
*/
|
|
365
|
+
path?: string;
|
|
366
|
+
/**
|
|
367
|
+
* Allow selection of entities that pass the given filter only.
|
|
368
|
+
* e.g. `forceFilter: { age: [">=", 18] }`
|
|
369
|
+
*/
|
|
370
|
+
forceFilter?: FilterValues<string>;
|
|
371
|
+
/**
|
|
372
|
+
* Properties that need to be rendered when displaying a preview of this
|
|
373
|
+
* reference. If not specified the first 3 are used. Only the first 3
|
|
374
|
+
* specified values are considered.
|
|
375
|
+
*/
|
|
376
|
+
previewProperties?: string[];
|
|
377
|
+
/**
|
|
378
|
+
* Should the reference include the ID of the entity. Defaults to `true`
|
|
379
|
+
*/
|
|
380
|
+
includeId?: boolean;
|
|
381
|
+
/**
|
|
382
|
+
* Should the reference include a link to the entity (open the entity details). Defaults to `true`
|
|
383
|
+
*/
|
|
384
|
+
includeEntityLink?: boolean;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* @group Entity properties
|
|
388
|
+
*/
|
|
389
|
+
export interface RelationProperty extends BaseProperty {
|
|
390
|
+
type: "relation";
|
|
391
|
+
/**
|
|
392
|
+
* Marks this field as a Primary Key / Unique Identifier.
|
|
393
|
+
* Framework behavior: Auto-maps to `collection.primaryKeys` internally if not explicitly set.
|
|
394
|
+
* Drizzle append: `.primaryKey()`
|
|
395
|
+
* UI behavior: Field value cannot be changed after creation.
|
|
396
|
+
*/
|
|
397
|
+
isId?: boolean;
|
|
398
|
+
/**
|
|
399
|
+
* The name of the relation this property refers to. This name must match
|
|
400
|
+
* one of the `relationName`s defined in the top-level `relations` array
|
|
401
|
+
* of the collection.
|
|
402
|
+
*/
|
|
403
|
+
relationName: string;
|
|
404
|
+
/**
|
|
405
|
+
* The resolved relation object.
|
|
406
|
+
* This is set by the framework
|
|
407
|
+
*/
|
|
408
|
+
relation?: Relation;
|
|
409
|
+
/**
|
|
410
|
+
* Allow selection of entities that pass the given filter only.
|
|
411
|
+
* e.g. `forceFilter: { age: [">=", 18] }`
|
|
412
|
+
*/
|
|
413
|
+
forceFilter?: FilterValues<string>;
|
|
414
|
+
/**
|
|
415
|
+
* Properties that need to be rendered when displaying a preview of this
|
|
416
|
+
* reference. If not specified the first 3 are used. Only the first 3
|
|
417
|
+
* specified values are considered.
|
|
418
|
+
*/
|
|
419
|
+
previewProperties?: string[];
|
|
420
|
+
/**
|
|
421
|
+
* Should the reference include the ID of the entity. Defaults to `true`
|
|
422
|
+
*/
|
|
423
|
+
includeId?: boolean;
|
|
424
|
+
/**
|
|
425
|
+
* Should the reference include a link to the entity (open the entity details). Defaults to `true`
|
|
426
|
+
*/
|
|
427
|
+
includeEntityLink?: boolean;
|
|
428
|
+
/**
|
|
429
|
+
* Choose the widget to use for selecting the relation.
|
|
430
|
+
* Defaults to `select`.
|
|
431
|
+
*/
|
|
432
|
+
widget?: "select" | "dialog";
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* @group Entity properties
|
|
436
|
+
*/
|
|
437
|
+
export interface ArrayProperty extends BaseProperty {
|
|
438
|
+
type: "array";
|
|
439
|
+
/**
|
|
440
|
+
* Optional database column type. Defaults to `jsonb`.
|
|
441
|
+
*/
|
|
442
|
+
columnType?: "json" | "jsonb";
|
|
443
|
+
/**
|
|
444
|
+
* The property of this array.
|
|
445
|
+
* You can specify any property (except another Array property)
|
|
446
|
+
* You can leave this field empty only if you are providing a custom field,
|
|
447
|
+
* or using the `oneOf` prop, otherwise an error will be thrown.
|
|
448
|
+
*/
|
|
449
|
+
of?: Property | Property[];
|
|
450
|
+
/**
|
|
451
|
+
* Use this field if you would like to have an array of typed objects.
|
|
452
|
+
* It is useful if you need to have values of different types in the same
|
|
453
|
+
* array.
|
|
454
|
+
* Each entry of the array is an object with the shape:
|
|
455
|
+
* ```
|
|
456
|
+
* { type: "YOUR_TYPE", value: "YOUR_VALUE"}
|
|
457
|
+
* ```
|
|
458
|
+
* Note that you can use any property so `value` can take any value (strings,
|
|
459
|
+
* numbers, array, objects...)
|
|
460
|
+
* You can customise the `type` and `value` fields to suit your needs.
|
|
461
|
+
*
|
|
462
|
+
* An example use case for this feature may be a blog entry, where you have
|
|
463
|
+
* images and text blocks using markdown.
|
|
464
|
+
*/
|
|
465
|
+
oneOf?: {
|
|
466
|
+
/**
|
|
467
|
+
* Record of properties, where the key is the `type` and the value
|
|
468
|
+
* is the corresponding property
|
|
469
|
+
*/
|
|
470
|
+
properties: Properties;
|
|
471
|
+
/**
|
|
472
|
+
* Order in which the properties are displayed.
|
|
473
|
+
* If you are specifying your collection as code, the order is the same as the
|
|
474
|
+
* one you define in `properties`, and you don't need to specify this prop.
|
|
475
|
+
*/
|
|
476
|
+
propertiesOrder?: string[];
|
|
477
|
+
/**
|
|
478
|
+
* Name of the field to use as the discriminator for type
|
|
479
|
+
* Defaults to `type`
|
|
480
|
+
*/
|
|
481
|
+
typeField?: string;
|
|
482
|
+
/**
|
|
483
|
+
* Name of the field to use as the value
|
|
484
|
+
* Defaults to `value`
|
|
485
|
+
*/
|
|
486
|
+
valueField?: string;
|
|
487
|
+
};
|
|
488
|
+
/**
|
|
489
|
+
* Rules for validating this property
|
|
490
|
+
*/
|
|
491
|
+
validation?: ArrayPropertyValidationSchema;
|
|
492
|
+
/**
|
|
493
|
+
* Should the field be initially expanded. Defaults to `true`
|
|
494
|
+
*/
|
|
495
|
+
expanded?: boolean;
|
|
496
|
+
/**
|
|
497
|
+
* Display the child properties directly, without being wrapped in an
|
|
498
|
+
* extendable panel.
|
|
499
|
+
*/
|
|
500
|
+
minimalistView?: boolean;
|
|
501
|
+
/**
|
|
502
|
+
* Can the elements in this array be reordered. Defaults to `true`.
|
|
503
|
+
* This prop has no effect if `disabled` is set to true.
|
|
504
|
+
*/
|
|
505
|
+
sortable?: boolean;
|
|
506
|
+
/**
|
|
507
|
+
* Can the elements in this array be added. Defaults to `true`
|
|
508
|
+
* This prop has no effect if `disabled` is set to true.
|
|
509
|
+
*/
|
|
510
|
+
canAddElements?: boolean;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* @group Entity properties
|
|
514
|
+
*/
|
|
515
|
+
export interface MapProperty extends BaseProperty {
|
|
516
|
+
type: "map";
|
|
517
|
+
/**
|
|
518
|
+
* Optional database column type. Defaults to `jsonb`.
|
|
519
|
+
*/
|
|
520
|
+
columnType?: "json" | "jsonb";
|
|
521
|
+
/**
|
|
522
|
+
* Record of properties included in this map.
|
|
523
|
+
*/
|
|
524
|
+
properties?: Properties;
|
|
525
|
+
/**
|
|
526
|
+
* Order in which the properties are displayed.
|
|
527
|
+
* If you are specifying your collection as code, the order is the same as the
|
|
528
|
+
* one you define in `properties`, and you don't need to specify this prop.
|
|
529
|
+
*/
|
|
530
|
+
propertiesOrder?: string[];
|
|
531
|
+
/**
|
|
532
|
+
* Rules for validating this property.
|
|
533
|
+
* NOTE: If you don't set `required` in the map property, an empty object
|
|
534
|
+
* will be considered valid, even if you set `required` in the properties.
|
|
535
|
+
*/
|
|
536
|
+
validation?: PropertyValidationSchema;
|
|
537
|
+
/**
|
|
538
|
+
* Properties that are displayed when rendered as a preview
|
|
539
|
+
*/
|
|
540
|
+
previewProperties?: string[];
|
|
541
|
+
/**
|
|
542
|
+
* Allow the user to add only some keys in this map.
|
|
543
|
+
* By default, all properties of the map have the corresponding field in
|
|
544
|
+
* the form view. Setting this flag to true allows to pick only some.
|
|
545
|
+
* Useful for map that can have a lot of sub-properties that may not be
|
|
546
|
+
* needed
|
|
547
|
+
*/
|
|
548
|
+
pickOnlySomeKeys?: boolean;
|
|
549
|
+
/**
|
|
550
|
+
* Display the child properties as independent columns in the collection
|
|
551
|
+
* view
|
|
552
|
+
*/
|
|
553
|
+
spreadChildren?: boolean;
|
|
554
|
+
/**
|
|
555
|
+
* Display the child properties directly, without being wrapped in an
|
|
556
|
+
* extendable panel. Note that this will also hide the title of this property.
|
|
557
|
+
*/
|
|
558
|
+
minimalistView?: boolean;
|
|
559
|
+
/**
|
|
560
|
+
* Should the field be initially expanded. Defaults to `true`
|
|
561
|
+
*/
|
|
562
|
+
expanded?: boolean;
|
|
563
|
+
/**
|
|
564
|
+
* Render this map as a key-value table that allows to use
|
|
565
|
+
* arbitrary keys. You don't need to define the properties in this case.
|
|
566
|
+
*/
|
|
567
|
+
keyValue?: boolean;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* @group Entity properties
|
|
571
|
+
*/
|
|
572
|
+
export type PropertyBuilderProps<M extends Record<string, unknown> = Record<string, unknown>> = {
|
|
573
|
+
values: Partial<M>;
|
|
574
|
+
previousValues?: Partial<M>;
|
|
575
|
+
propertyValue?: unknown;
|
|
576
|
+
index?: number;
|
|
577
|
+
path: string;
|
|
578
|
+
entityId?: string | number;
|
|
579
|
+
authController: AuthController;
|
|
580
|
+
};
|
|
581
|
+
/**
|
|
582
|
+
* @group Entity properties
|
|
583
|
+
*/
|
|
584
|
+
export interface PropertyDisabledConfig {
|
|
585
|
+
/**
|
|
586
|
+
* Enable this flag if you would like to clear the value of the field
|
|
587
|
+
* when the corresponding property gets disabled.
|
|
588
|
+
*
|
|
589
|
+
* This is useful for keeping data consistency when you have conditional
|
|
590
|
+
* properties.
|
|
591
|
+
*/
|
|
592
|
+
clearOnDisabled?: boolean;
|
|
593
|
+
/**
|
|
594
|
+
* Explanation of why this property is disabled (e.g. a different field
|
|
595
|
+
* needs to be enabled)
|
|
596
|
+
*/
|
|
597
|
+
disabledMessage?: string;
|
|
598
|
+
/**
|
|
599
|
+
* Set this flag to true if you want to hide this field when disabled
|
|
600
|
+
*/
|
|
601
|
+
hidden?: boolean;
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* We use this type to define mapping between string or number values in
|
|
605
|
+
* the data source to a label (such in a select dropdown).
|
|
606
|
+
* The key in this Record is the value saved in the driver, and the value in
|
|
607
|
+
* this record is the label displayed in the UI.
|
|
608
|
+
* You can add additional customization by assigning a {@link EnumValueConfig} for the
|
|
609
|
+
* label instead of a simple string (for enabling or disabling options and
|
|
610
|
+
* choosing colors).
|
|
611
|
+
* If you need to ensure the order of the elements use an array of {@link EnumValueConfig}
|
|
612
|
+
* @group Entity properties
|
|
613
|
+
*/
|
|
614
|
+
export type EnumValues = EnumValueConfig[] | Record<string | number, string | EnumValueConfig>;
|
|
615
|
+
/**
|
|
616
|
+
* Configuration for a particular entry in an `EnumValues`
|
|
617
|
+
* @group Entity properties
|
|
618
|
+
*/
|
|
619
|
+
export type EnumValueConfig = {
|
|
620
|
+
/**
|
|
621
|
+
* Value stored in the data source.
|
|
622
|
+
*/
|
|
623
|
+
id: string | number;
|
|
624
|
+
/**
|
|
625
|
+
* Displayed label
|
|
626
|
+
*/
|
|
627
|
+
label: string;
|
|
628
|
+
/**
|
|
629
|
+
* This value will not be selectable
|
|
630
|
+
*/
|
|
631
|
+
disabled?: boolean;
|
|
632
|
+
/**
|
|
633
|
+
* You can pick from a list of predefined color combinations or define
|
|
634
|
+
* your own {@link ColorScheme}
|
|
635
|
+
*/
|
|
636
|
+
color?: ColorKey | ColorScheme;
|
|
637
|
+
};
|
|
638
|
+
/**
|
|
639
|
+
* Rules to validate any property. Some properties have specific rules
|
|
640
|
+
* additionally to these.
|
|
641
|
+
* @group Entity properties
|
|
642
|
+
*/
|
|
643
|
+
export interface PropertyValidationSchema {
|
|
644
|
+
/**
|
|
645
|
+
* Is this field required
|
|
646
|
+
*/
|
|
647
|
+
required?: boolean;
|
|
648
|
+
/**
|
|
649
|
+
* Customize the required message when the property is not set
|
|
650
|
+
*/
|
|
651
|
+
requiredMessage?: string;
|
|
652
|
+
/**
|
|
653
|
+
* If the unique flag is set to `true`, you can only have one entity in the
|
|
654
|
+
* collection with this value.
|
|
655
|
+
*/
|
|
656
|
+
unique?: boolean;
|
|
657
|
+
/**
|
|
658
|
+
* If the uniqueInArray flag is set to `true`, you can only have this value
|
|
659
|
+
* once per entry in the parent `ArrayProperty`. It has no effect if this
|
|
660
|
+
* property is not a child of an `ArrayProperty`. It works on direct
|
|
661
|
+
* children of an `ArrayProperty` or first level children of `MapProperty`
|
|
662
|
+
*/
|
|
663
|
+
uniqueInArray?: boolean;
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Validation rules for numbers
|
|
667
|
+
* @group Entity properties
|
|
668
|
+
*/
|
|
669
|
+
export interface NumberPropertyValidationSchema extends PropertyValidationSchema {
|
|
670
|
+
min?: number;
|
|
671
|
+
max?: number;
|
|
672
|
+
lessThan?: number;
|
|
673
|
+
moreThan?: number;
|
|
674
|
+
positive?: boolean;
|
|
675
|
+
negative?: boolean;
|
|
676
|
+
integer?: boolean;
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Validation rules for strings
|
|
680
|
+
* @group Entity properties
|
|
681
|
+
*/
|
|
682
|
+
export interface StringPropertyValidationSchema extends PropertyValidationSchema {
|
|
683
|
+
length?: number;
|
|
684
|
+
min?: number;
|
|
685
|
+
max?: number;
|
|
686
|
+
matches?: string | RegExp;
|
|
687
|
+
/**
|
|
688
|
+
* Message displayed when the input does not satisfy the regex in `matches`
|
|
689
|
+
*/
|
|
690
|
+
matchesMessage?: string;
|
|
691
|
+
trim?: boolean;
|
|
692
|
+
lowercase?: boolean;
|
|
693
|
+
uppercase?: boolean;
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Validation rules for dates
|
|
697
|
+
* @group Entity properties
|
|
698
|
+
*/
|
|
699
|
+
export interface DatePropertyValidationSchema extends PropertyValidationSchema {
|
|
700
|
+
min?: Date;
|
|
701
|
+
max?: Date;
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Validation rules for arrays
|
|
705
|
+
* @group Entity properties
|
|
706
|
+
*/
|
|
707
|
+
export interface ArrayPropertyValidationSchema extends PropertyValidationSchema {
|
|
708
|
+
min?: number;
|
|
709
|
+
max?: number;
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Additional configuration related to Storage related fields
|
|
713
|
+
* @group Entity properties
|
|
714
|
+
*/
|
|
715
|
+
export type StorageConfig = {
|
|
716
|
+
/**
|
|
717
|
+
* File MIME types that can be uploaded to this reference. Don't specify for
|
|
718
|
+
* all.
|
|
719
|
+
* Note that you can also use the asterisk notation, so `image/*`
|
|
720
|
+
* accepts any image file, and so on.
|
|
721
|
+
*/
|
|
722
|
+
acceptedFiles?: FileType[];
|
|
723
|
+
/**
|
|
724
|
+
* Advanced image resizing and cropping configuration.
|
|
725
|
+
* Applied before upload to optimize storage and bandwidth.
|
|
726
|
+
* Only applies to image MIME types: image/jpeg, image/png, image/webp
|
|
727
|
+
*/
|
|
728
|
+
imageResize?: ImageResize;
|
|
729
|
+
/**
|
|
730
|
+
* Specific metadata set in your uploaded file.
|
|
731
|
+
* For the default Firebase implementation, the values passed here are of type
|
|
732
|
+
* `firebase.storage.UploadMetadata`
|
|
733
|
+
*/
|
|
734
|
+
metadata?: Record<string, unknown>;
|
|
735
|
+
/**
|
|
736
|
+
* You can use this prop to customize the uploaded filename.
|
|
737
|
+
* You can use a function as a callback or a string where you
|
|
738
|
+
* specify some placeholders that get replaced with the corresponding values.
|
|
739
|
+
* - `{file}` - Full file name
|
|
740
|
+
* - `{file.name}` - Name of the file without extension
|
|
741
|
+
* - `{file.ext}` - Extension of the file
|
|
742
|
+
* - `{rand}` - Random value used to avoid name collisions
|
|
743
|
+
* - `{entityId}` - ID of the entity
|
|
744
|
+
* - `{propertyKey}` - ID of this property
|
|
745
|
+
* - `{path}` - Path of this entity
|
|
746
|
+
*
|
|
747
|
+
* @param context
|
|
748
|
+
*/
|
|
749
|
+
fileName?: string | ((context: UploadedFileContext) => string | Promise<string>);
|
|
750
|
+
/**
|
|
751
|
+
* Absolute path in your bucket.
|
|
752
|
+
*
|
|
753
|
+
* You can use a function as a callback or a string where you
|
|
754
|
+
* specify some placeholders that get replaced with the corresponding values.
|
|
755
|
+
* - `{file}` - Full file name
|
|
756
|
+
* - `{file.name}` - Name of the file without extension
|
|
757
|
+
* - `{file.ext}` - Extension of the file
|
|
758
|
+
* - `{rand}` - Random value used to avoid name collisions
|
|
759
|
+
* - `{entityId}` - ID of the entity
|
|
760
|
+
* - `{propertyKey}` - ID of this property
|
|
761
|
+
* - `{path}` - Path of this entity
|
|
762
|
+
*/
|
|
763
|
+
storagePath: string | ((context: UploadedFileContext) => string);
|
|
764
|
+
/**
|
|
765
|
+
* When set to true, this flag indicates that the bucket name will be
|
|
766
|
+
* included in the saved storage path.
|
|
767
|
+
*
|
|
768
|
+
* E.g. `gs://my-bucket/path/to/file.png` instead of just `path/to/file.png`
|
|
769
|
+
*
|
|
770
|
+
* Defaults to false.
|
|
771
|
+
*/
|
|
772
|
+
includeBucketUrl?: boolean;
|
|
773
|
+
/**
|
|
774
|
+
* When set to true, this flag indicates that the download URL of the file
|
|
775
|
+
* will be saved in the driver, instead of the storage path.
|
|
776
|
+
*
|
|
777
|
+
* Note that the generated URL may use a token that, if disabled, may
|
|
778
|
+
* make the URL unusable and lose the original reference to Cloud Storage,
|
|
779
|
+
* so it is not encouraged to use this flag.
|
|
780
|
+
*
|
|
781
|
+
* Defaults to false.
|
|
782
|
+
*/
|
|
783
|
+
storeUrl?: boolean;
|
|
784
|
+
/**
|
|
785
|
+
* Define maximal file size in bytes
|
|
786
|
+
*/
|
|
787
|
+
maxSize?: number;
|
|
788
|
+
/**
|
|
789
|
+
* Use this callback to process the file before uploading it to the storage.
|
|
790
|
+
* If nothing is returned, the file is uploaded as it is.
|
|
791
|
+
* @param file
|
|
792
|
+
*/
|
|
793
|
+
processFile?: (file: File) => Promise<File> | undefined;
|
|
794
|
+
/**
|
|
795
|
+
* Postprocess the saved value (storage path or URL)
|
|
796
|
+
* after it has been resolved.
|
|
797
|
+
*/
|
|
798
|
+
postProcess?: (pathOrUrl: string) => Promise<string>;
|
|
799
|
+
/**
|
|
800
|
+
* You can use this prop in order to provide a custom preview URL.
|
|
801
|
+
* Useful when the file's path is different from the original field value
|
|
802
|
+
*/
|
|
803
|
+
previewUrl?: (fileName: string) => string;
|
|
804
|
+
};
|
|
805
|
+
/**
|
|
806
|
+
* @group Entity properties
|
|
807
|
+
*/
|
|
808
|
+
export interface UploadedFileContext {
|
|
809
|
+
/**
|
|
810
|
+
* Uploaded file
|
|
811
|
+
*/
|
|
812
|
+
file: File;
|
|
813
|
+
/**
|
|
814
|
+
* Property field name
|
|
815
|
+
*/
|
|
816
|
+
propertyKey: string;
|
|
817
|
+
/**
|
|
818
|
+
* Property related to this upload
|
|
819
|
+
*/
|
|
820
|
+
property: StringProperty | ArrayProperty;
|
|
821
|
+
/**
|
|
822
|
+
* Entity ID
|
|
823
|
+
*/
|
|
824
|
+
entityId?: string | number;
|
|
825
|
+
/**
|
|
826
|
+
* Entity path. E.g. `products/PID/locales`
|
|
827
|
+
*/
|
|
828
|
+
path?: string;
|
|
829
|
+
/**
|
|
830
|
+
* Values of the current entity
|
|
831
|
+
*/
|
|
832
|
+
values: EntityValues<any>;
|
|
833
|
+
/**
|
|
834
|
+
* Storage meta specified by the developer
|
|
835
|
+
*/
|
|
836
|
+
storage: StorageConfig;
|
|
837
|
+
}
|
|
838
|
+
/**
|
|
839
|
+
* Used for previewing urls if the download file is known
|
|
840
|
+
* @group Entity properties
|
|
841
|
+
*/
|
|
842
|
+
export type PreviewType = "image" | "video" | "audio" | "file";
|
|
843
|
+
/**
|
|
844
|
+
* MIME types for storage fields
|
|
845
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
|
|
846
|
+
* @group Entity properties
|
|
847
|
+
*/
|
|
848
|
+
export type FileType = "image/*" | "video/*" | "audio/*" | "application/*" | "text/*" | "font/*" | string;
|
|
849
|
+
export interface ImageResize {
|
|
850
|
+
/**
|
|
851
|
+
* Maximum width in pixels. Image will be scaled down proportionally if wider.
|
|
852
|
+
*/
|
|
853
|
+
maxWidth?: number;
|
|
854
|
+
/**
|
|
855
|
+
* Maximum height in pixels. Image will be scaled down proportionally if taller.
|
|
856
|
+
*/
|
|
857
|
+
maxHeight?: number;
|
|
858
|
+
/**
|
|
859
|
+
* Resize mode determines how the image fits within maxWidth/maxHeight bounds.
|
|
860
|
+
* - `contain`: Scale down to fit within bounds, preserving aspect ratio (default)
|
|
861
|
+
* - `cover`: Scale to fill bounds, preserving aspect ratio (may crop)
|
|
862
|
+
*/
|
|
863
|
+
mode?: 'contain' | 'cover';
|
|
864
|
+
/**
|
|
865
|
+
* Output format for the resized image.
|
|
866
|
+
* - `original`: Keep the original format (default)
|
|
867
|
+
* - `jpeg`: Convert to JPEG
|
|
868
|
+
* - `png`: Convert to PNG
|
|
869
|
+
* - `webp`: Convert to WebP
|
|
870
|
+
*/
|
|
871
|
+
format?: 'original' | 'jpeg' | 'png' | 'webp';
|
|
872
|
+
/**
|
|
873
|
+
* Quality for lossy formats (JPEG, WebP). Number between 0 and 100.
|
|
874
|
+
* Higher is better quality but larger file size. Defaults to 80.
|
|
875
|
+
*/
|
|
876
|
+
quality?: number;
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* A JSON Logic rule that gets evaluated at runtime.
|
|
880
|
+
* @see https://jsonlogic.com/
|
|
881
|
+
*
|
|
882
|
+
* Common operators:
|
|
883
|
+
* - Comparison: ==, !=, ===, !==, >, <, >=, <=
|
|
884
|
+
* - Logic: and, or, !, !!
|
|
885
|
+
* - Data access: var, missing, missing_some
|
|
886
|
+
* - Array: in, map, filter, reduce, all, some, none, merge
|
|
887
|
+
* - String: substr, cat
|
|
888
|
+
* - Numeric: +, -, *, /, %, min, max
|
|
889
|
+
*
|
|
890
|
+
* Custom operators:
|
|
891
|
+
* - hasRole(roleId) - check if user has role by ID
|
|
892
|
+
* - hasAnyRole([roleIds]) - check if user has any of the roles
|
|
893
|
+
* - isToday(timestamp) - check if timestamp is today
|
|
894
|
+
* - isPast(timestamp) - check if timestamp is in the past
|
|
895
|
+
* - isFuture(timestamp) - check if timestamp is in the future
|
|
896
|
+
*
|
|
897
|
+
* @group Entity properties
|
|
898
|
+
*/
|
|
899
|
+
export type JsonLogicRule = Record<string, any>;
|
|
900
|
+
/**
|
|
901
|
+
* Conditions for individual enum values within a property.
|
|
902
|
+
* @group Entity properties
|
|
903
|
+
*/
|
|
904
|
+
export interface EnumValueConditions {
|
|
905
|
+
/**
|
|
906
|
+
* Disable this enum option when condition is true.
|
|
907
|
+
* The option appears grayed out and cannot be selected.
|
|
908
|
+
*/
|
|
909
|
+
disabled?: JsonLogicRule;
|
|
910
|
+
/**
|
|
911
|
+
* Message explaining why this option is disabled.
|
|
912
|
+
*/
|
|
913
|
+
disabledMessage?: string;
|
|
914
|
+
/**
|
|
915
|
+
* Completely hide this enum option when condition is true.
|
|
916
|
+
* The option is removed from the dropdown/list.
|
|
917
|
+
*/
|
|
918
|
+
hidden?: JsonLogicRule;
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Declarative conditions for dynamic property behavior.
|
|
922
|
+
* All conditions are JSON Logic rules evaluated against ConditionContext.
|
|
923
|
+
*
|
|
924
|
+
* An alternative to PropertyBuilder functions that can be:
|
|
925
|
+
* - Stored in the database as JSON
|
|
926
|
+
* - Edited via the collection editor UI
|
|
927
|
+
* - Evaluated at runtime like property builders
|
|
928
|
+
*
|
|
929
|
+
* @see https://jsonlogic.com/ for JSON Logic syntax
|
|
930
|
+
* @group Entity properties
|
|
931
|
+
*/
|
|
932
|
+
export interface PropertyConditions {
|
|
933
|
+
/**
|
|
934
|
+
* Disable the field when this condition evaluates to true.
|
|
935
|
+
* The field becomes non-editable but still visible (unless also hidden).
|
|
936
|
+
*
|
|
937
|
+
* @example Disable when another field has a specific value
|
|
938
|
+
* \`\`\`json
|
|
939
|
+
* { "==": [{ "var": "values.status" }, "archived"] }
|
|
940
|
+
* \`\`\`
|
|
941
|
+
*/
|
|
942
|
+
disabled?: JsonLogicRule;
|
|
943
|
+
/**
|
|
944
|
+
* Message to display when the field is disabled by a condition.
|
|
945
|
+
*/
|
|
946
|
+
disabledMessage?: string;
|
|
947
|
+
/**
|
|
948
|
+
* Clear the field's value when it becomes disabled.
|
|
949
|
+
* @default false
|
|
950
|
+
*/
|
|
951
|
+
clearOnDisabled?: boolean;
|
|
952
|
+
/**
|
|
953
|
+
* Hide the field completely when this condition evaluates to true.
|
|
954
|
+
* The field is removed from the form (not just visually hidden).
|
|
955
|
+
*/
|
|
956
|
+
hidden?: JsonLogicRule;
|
|
957
|
+
/**
|
|
958
|
+
* Make the field read-only when this condition evaluates to true.
|
|
959
|
+
* Renders as a preview instead of an input.
|
|
960
|
+
*/
|
|
961
|
+
readOnly?: JsonLogicRule;
|
|
962
|
+
/**
|
|
963
|
+
* Make the field required when this condition evaluates to true.
|
|
964
|
+
* Overrides the static `validation.required` setting.
|
|
965
|
+
*/
|
|
966
|
+
required?: JsonLogicRule;
|
|
967
|
+
/**
|
|
968
|
+
* Custom message when conditional required validation fails.
|
|
969
|
+
*/
|
|
970
|
+
requiredMessage?: string;
|
|
971
|
+
/**
|
|
972
|
+
* Dynamic minimum value for number/string length.
|
|
973
|
+
* Should evaluate to a number.
|
|
974
|
+
*/
|
|
975
|
+
min?: JsonLogicRule;
|
|
976
|
+
/**
|
|
977
|
+
* Dynamic maximum value for number/string length.
|
|
978
|
+
* Should evaluate to a number.
|
|
979
|
+
*/
|
|
980
|
+
max?: JsonLogicRule;
|
|
981
|
+
/**
|
|
982
|
+
* Dynamic default value for new entities.
|
|
983
|
+
* Should evaluate to a value of the appropriate type for the field.
|
|
984
|
+
* Only applied when entityId is empty (new entity).
|
|
985
|
+
*/
|
|
986
|
+
defaultValue?: JsonLogicRule;
|
|
987
|
+
/**
|
|
988
|
+
* Conditions for individual enum values.
|
|
989
|
+
* Keys are the enum value IDs, values are condition configs.
|
|
990
|
+
*
|
|
991
|
+
* @example Disable certain enum options based on user role
|
|
992
|
+
* \`\`\`json
|
|
993
|
+
* {
|
|
994
|
+
* "admin": {
|
|
995
|
+
* "disabled": { "!": { "hasRole": "admin" } },
|
|
996
|
+
* "disabledMessage": "Admin option requires admin role"
|
|
997
|
+
* }
|
|
998
|
+
* }
|
|
999
|
+
* \`\`\`
|
|
1000
|
+
*/
|
|
1001
|
+
enumConditions?: Record<string | number, EnumValueConditions>;
|
|
1002
|
+
/**
|
|
1003
|
+
* Filter which enum values are available.
|
|
1004
|
+
* Should evaluate to an array of allowed enum value IDs.
|
|
1005
|
+
*/
|
|
1006
|
+
allowedEnumValues?: JsonLogicRule;
|
|
1007
|
+
/**
|
|
1008
|
+
* Exclude specific enum values.
|
|
1009
|
+
* Should evaluate to an array of enum value IDs to exclude.
|
|
1010
|
+
*/
|
|
1011
|
+
excludedEnumValues?: JsonLogicRule;
|
|
1012
|
+
/**
|
|
1013
|
+
* Dynamic path for reference properties.
|
|
1014
|
+
* Should evaluate to a collection path string.
|
|
1015
|
+
*/
|
|
1016
|
+
referencePath?: JsonLogicRule;
|
|
1017
|
+
/**
|
|
1018
|
+
* Dynamic filter for reference selection.
|
|
1019
|
+
* Should evaluate to a FilterValues object.
|
|
1020
|
+
*/
|
|
1021
|
+
referenceFilter?: JsonLogicRule;
|
|
1022
|
+
/**
|
|
1023
|
+
* Can elements be added to the array?
|
|
1024
|
+
*/
|
|
1025
|
+
canAddElements?: JsonLogicRule;
|
|
1026
|
+
/**
|
|
1027
|
+
* Can elements be reordered in the array?
|
|
1028
|
+
*/
|
|
1029
|
+
sortable?: JsonLogicRule;
|
|
1030
|
+
/**
|
|
1031
|
+
* Dynamic accepted file types.
|
|
1032
|
+
* Should evaluate to an array of MIME types.
|
|
1033
|
+
*/
|
|
1034
|
+
acceptedFiles?: JsonLogicRule;
|
|
1035
|
+
/**
|
|
1036
|
+
* Dynamic maximum file size in bytes.
|
|
1037
|
+
* Should evaluate to a number.
|
|
1038
|
+
*/
|
|
1039
|
+
maxFileSize?: JsonLogicRule;
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* Context available during JSON Logic condition evaluation.
|
|
1043
|
+
* Mirrors PropertyBuilderProps but adapted for JSON serialization.
|
|
1044
|
+
* @group Entity properties
|
|
1045
|
+
*/
|
|
1046
|
+
export interface ConditionContext {
|
|
1047
|
+
/**
|
|
1048
|
+
* Current form/entity values.
|
|
1049
|
+
* Date values are converted to Unix timestamps (milliseconds).
|
|
1050
|
+
*/
|
|
1051
|
+
values: Record<string, any>;
|
|
1052
|
+
/**
|
|
1053
|
+
* Previous values before the current edit session.
|
|
1054
|
+
*/
|
|
1055
|
+
previousValues: Record<string, any>;
|
|
1056
|
+
/**
|
|
1057
|
+
* Current value of this property specifically.
|
|
1058
|
+
*/
|
|
1059
|
+
propertyValue: unknown;
|
|
1060
|
+
/**
|
|
1061
|
+
* Collection path (e.g., "products", "users/uid123/orders")
|
|
1062
|
+
*/
|
|
1063
|
+
path: string;
|
|
1064
|
+
/**
|
|
1065
|
+
* Entity ID. Undefined for new entities.
|
|
1066
|
+
*/
|
|
1067
|
+
entityId?: string;
|
|
1068
|
+
/**
|
|
1069
|
+
* Whether this is a new entity being created.
|
|
1070
|
+
*/
|
|
1071
|
+
isNew: boolean;
|
|
1072
|
+
/**
|
|
1073
|
+
* Index of this property (only for array items).
|
|
1074
|
+
*/
|
|
1075
|
+
index?: number;
|
|
1076
|
+
/**
|
|
1077
|
+
* Current authenticated user information.
|
|
1078
|
+
*/
|
|
1079
|
+
user: {
|
|
1080
|
+
uid: string;
|
|
1081
|
+
email: string | null;
|
|
1082
|
+
displayName: string | null;
|
|
1083
|
+
photoURL: string | null;
|
|
1084
|
+
/** Role IDs the user has (extracted from Role[].id) */
|
|
1085
|
+
roles: string[];
|
|
1086
|
+
};
|
|
1087
|
+
/**
|
|
1088
|
+
* Current timestamp as Unix milliseconds.
|
|
1089
|
+
*/
|
|
1090
|
+
now: number;
|
|
1091
|
+
}
|