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