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