@rebasepro/types 0.17.3 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +4 -0
  2. package/dist/call_context.d.ts +20 -0
  3. package/dist/controllers/client.d.ts +36 -4
  4. package/dist/controllers/data.d.ts +120 -10
  5. package/dist/errors.d.ts +83 -4
  6. package/dist/index.es.js +522 -160
  7. package/dist/index.es.js.map +1 -1
  8. package/dist/types/admin_block.d.ts +2 -2
  9. package/dist/types/auth_adapter.d.ts +41 -6
  10. package/dist/types/backend.d.ts +48 -0
  11. package/dist/types/collections.d.ts +25 -1
  12. package/dist/types/cron.d.ts +34 -0
  13. package/dist/types/database_adapter.d.ts +39 -0
  14. package/dist/types/entity_callbacks.d.ts +14 -1
  15. package/dist/types/filter-operators.d.ts +24 -1
  16. package/dist/types/policy.d.ts +29 -1
  17. package/dist/types/properties.d.ts +216 -3
  18. package/dist/types/relations.d.ts +65 -7
  19. package/dist/types/resource_kinds.d.ts +173 -17
  20. package/dist/types/resources.d.ts +108 -7
  21. package/dist/types/rls-functions.d.ts +11 -0
  22. package/dist/types/storage_source.d.ts +12 -23
  23. package/package.json +24 -23
  24. package/src/call_context.ts +0 -120
  25. package/src/controllers/auth_state.ts +0 -24
  26. package/src/controllers/client.ts +0 -494
  27. package/src/controllers/collection_registry.ts +0 -62
  28. package/src/controllers/data.ts +0 -1012
  29. package/src/controllers/data_driver.ts +0 -576
  30. package/src/controllers/effective_role.ts +0 -4
  31. package/src/controllers/email.ts +0 -91
  32. package/src/controllers/index.ts +0 -11
  33. package/src/controllers/storage.ts +0 -252
  34. package/src/errors.ts +0 -119
  35. package/src/index.ts +0 -5
  36. package/src/types/admin_block.ts +0 -209
  37. package/src/types/api_keys.ts +0 -108
  38. package/src/types/auth_adapter.ts +0 -580
  39. package/src/types/backend.ts +0 -987
  40. package/src/types/backup.ts +0 -26
  41. package/src/types/channel_bus.ts +0 -202
  42. package/src/types/chips.ts +0 -34
  43. package/src/types/collection_contract.ts +0 -278
  44. package/src/types/collections.ts +0 -763
  45. package/src/types/component_ref.ts +0 -92
  46. package/src/types/cron.ts +0 -213
  47. package/src/types/data_source.ts +0 -357
  48. package/src/types/database_adapter.ts +0 -267
  49. package/src/types/entities.ts +0 -226
  50. package/src/types/entity_callbacks.ts +0 -229
  51. package/src/types/filter-operators.ts +0 -444
  52. package/src/types/history.ts +0 -66
  53. package/src/types/index.ts +0 -36
  54. package/src/types/indexes.ts +0 -180
  55. package/src/types/policy.ts +0 -328
  56. package/src/types/postgres_introspection.ts +0 -101
  57. package/src/types/project_manifest.ts +0 -598
  58. package/src/types/properties.ts +0 -1368
  59. package/src/types/relations.ts +0 -417
  60. package/src/types/resource_kinds.ts +0 -390
  61. package/src/types/resources.ts +0 -368
  62. package/src/types/rls-functions.ts +0 -98
  63. package/src/types/schema_editing.ts +0 -157
  64. package/src/types/schema_version.ts +0 -112
  65. package/src/types/search.ts +0 -247
  66. package/src/types/security_rules.ts +0 -344
  67. package/src/types/storage_authorize.ts +0 -77
  68. package/src/types/storage_source.ts +0 -248
  69. package/src/types/websockets.ts +0 -117
  70. package/src/users/index.ts +0 -2
  71. package/src/users/user.ts +0 -69
@@ -1,1368 +0,0 @@
1
- import type { ComponentRef } from "./component_ref";
2
-
3
- import type { Entity, EntityReference, EntityRelation, EntityValues, GeoPoint, Vector } from "./entities";
4
- import type { JoinStep, OnAction, Relation, ResolvedRelation } from "./relations";
5
- import type { ColorKey, ColorScheme } from "./chips";
6
- import type { AuthState } from "../controllers/auth_state";
7
- import type { AfterReadProps, BeforeSaveProps } from "./entity_callbacks";
8
- import type { User } from "../users";
9
-
10
- /**
11
- * Callbacks/Hooks for individual property fields
12
- * @group Entity properties
13
- */
14
- export type PropertyCallbacks<T = unknown, M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> = {
15
- /**
16
- * Callback used after fetching data, to transform the value before rendering
17
- */
18
- afterRead?(props: Omit<AfterReadProps<M, USER>, "entity"> & {
19
- value: T;
20
- entity: Entity<M> | undefined;
21
- }): Promise<T> | T;
22
-
23
- /**
24
- * Callback used before saving, after validation.
25
- * You can modify the value before it's saved.
26
- */
27
- beforeSave?(props: Omit<BeforeSaveProps<M, USER>, "values"> & {
28
- value: T;
29
- previousValue: T | undefined;
30
- values: Partial<M>;
31
- }): Promise<T> | T;
32
- }
33
-
34
- /**
35
- * @group Entity properties
36
- */
37
- export type DataType =
38
- | "string"
39
- | "number"
40
- | "boolean"
41
- | "date"
42
- | "geopoint"
43
- | "reference"
44
- | "relation"
45
- | "array"
46
- | "map"
47
- | "vector"
48
- | "binary";
49
-
50
- export type Property =
51
- | StringProperty
52
- | NumberProperty
53
- | BooleanProperty
54
- | DateProperty
55
- | GeopointProperty
56
- | ReferenceProperty
57
- | RelationProperty
58
- | ArrayProperty
59
- | MapProperty
60
- | VectorProperty
61
- | BinaryProperty;
62
-
63
- export type Properties = {
64
- [key: string]: Property;
65
- };
66
-
67
- /**
68
- * `Omit` that survives a union.
69
- *
70
- * `Property` is a union discriminated on `type`, and a bare `Omit<Property, K>`
71
- * collapses it into one object whose `type` is the union of every tag — so
72
- * `property.type === "string"` stops narrowing and the concrete property types
73
- * become unreachable. The `T extends unknown` clause makes it distribute, so
74
- * each member is omitted from separately and keeps its own discriminant.
75
- */
76
- type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
77
-
78
- /**
79
- * The fields that describe a property's **column**, which only an engine with
80
- * columns has.
81
- *
82
- * `columnType` names a Postgres type (`uuid`, `bigserial`, `jsonb`, `text[]`)
83
- * and `columnName` overrides the snake_case derivation used to build a column
84
- * name. `DataSourceCapabilities.supportsColumnTypes` already reported this at
85
- * runtime — `false` for both document engines — while the types let a MongoDB
86
- * property declare `columnType: "bigserial"`.
87
- *
88
- * They stay declared on the concrete property interfaces rather than moving,
89
- * because that is where their per-type value unions live; what changes is that
90
- * the document engines' property aliases omit them.
91
- */
92
- type SqlColumnFields = "columnType" | "columnName";
93
-
94
- export type PostgresProperty = Exclude<Property, ReferenceProperty>;
95
- export type PostgresProperties = {
96
- [key: string]: PostgresProperty;
97
- };
98
-
99
- export type FirebaseProperty = DistributiveOmit<Exclude<Property, RelationProperty | VectorProperty>, SqlColumnFields>;
100
- export type FirebaseProperties = {
101
- [key: string]: FirebaseProperty;
102
- };
103
-
104
- // MongoDB is a document store: it uses references (stored pointers), not
105
- // SQL-style relations/joins. Same gating as Firestore.
106
- //
107
- // `vector` goes with them: it is pgvector-shaped, only `@rebasepro/server-postgres`
108
- // reads it, and `supportsVectors` on the engine's capabilities says so.
109
- export type MongoProperty = DistributiveOmit<Exclude<Property, RelationProperty | VectorProperty>, SqlColumnFields>;
110
- export type MongoProperties = {
111
- [key: string]: MongoProperty;
112
- };
113
-
114
- /**
115
- * Union of all engine-specific property maps. Use this at engine-agnostic
116
- * boundaries (collection editor, normalization) where the concrete engine is
117
- * unknown but the narrowed property constraint must be satisfied.
118
- */
119
- export type EngineProperties = PostgresProperties | FirebaseProperties | MongoProperties;
120
-
121
- /**
122
- * A helper type to infer the underlying data type from a Property definition.
123
- * This is the core of the type inference system.
124
- */
125
- export type InferPropertyType<P extends Property> =
126
- P extends StringProperty ? string :
127
- P extends NumberProperty ? number :
128
- P extends BooleanProperty ? boolean :
129
- P extends DateProperty ? Date :
130
- P extends GeopointProperty ? GeoPoint :
131
- P extends ReferenceProperty ? EntityReference :
132
- P extends RelationProperty ? EntityRelation | EntityRelation[] :
133
- P extends ArrayProperty ? (P["of"] extends Property ? InferPropertyType<P["of"]>[] : unknown[]) :
134
- P extends MapProperty ? (P["properties"] extends Properties ? InferEntityType<P["properties"]> : Record<string, unknown>) :
135
- P extends VectorProperty ? Vector :
136
- P extends BinaryProperty ? string :
137
- never;
138
-
139
- /**
140
- * Helper type that determines whether a property is required.
141
- * Uses direct structural matching against `{ validation: { required: true } }`
142
- * (without the optional marker on `validation`), which correctly narrows
143
- * literal `true` while treating widened `boolean` as not-required.
144
- */
145
- type IsRequired<P extends Property> = P extends { validation: { required: true } } ? true : false;
146
-
147
- /**
148
- * Extract keys from Properties where the property is required.
149
- */
150
- type RequiredPropertyKeys<P extends Properties> = {
151
- [K in keyof P]: IsRequired<P[K]> extends true ? K : never;
152
- }[keyof P];
153
-
154
- /**
155
- * Extract keys from Properties where the property is optional.
156
- */
157
- type OptionalPropertyKeys<P extends Properties> = {
158
- [K in keyof P]: IsRequired<P[K]> extends true ? never : K;
159
- }[keyof P];
160
-
161
- /**
162
- * A generic type that converts a `Properties` schema definition into a corresponding
163
- * TypeScript entity type. It correctly handles required and optional properties.
164
- *
165
- * A property is considered required when it has `validation: { required: true }`.
166
- * The `true` must be a literal type — if `required` is typed as `boolean`,
167
- * the property will be treated as optional (use `as const` for literal inference).
168
- *
169
- * @example
170
- * const productSchema = {
171
- * name: { type: 'string', validation: { required: true } },
172
- * price: { type: 'number' }
173
- * } as const satisfies Properties;
174
- * type Product = InferEntityType<typeof productSchema>;
175
- * // Result: { name: string; price?: number; }
176
- */
177
- export type InferEntityType<P extends Properties> = {
178
- -readonly [K in RequiredPropertyKeys<P>]: InferPropertyType<P[K]>;
179
- } & {
180
- -readonly [K in OptionalPropertyKeys<P>]?: InferPropertyType<P[K]>;
181
- };
182
-
183
- export interface BaseProperty<CustomProps = unknown> {
184
- /**
185
- * Property name (e.g. Product)
186
- */
187
- name: string;
188
-
189
- /**
190
- * Property description, always displayed under the field
191
- */
192
- description?: string;
193
-
194
- /**
195
- * You can use this prop to reuse a property that has been defined
196
- * in the top level of the admin in the prop `fields`.
197
- * All the configuration will be taken from the inherited config, and
198
- * overwritten by the current property config.
199
- */
200
- propertyConfig?: string;
201
-
202
- /**
203
- * Explicit database column name. When set, this value is used as-is
204
- * for the SQL column name, bypassing any snake_case conversion of
205
- * the property key.
206
- *
207
- * This is automatically populated by `rebase schema introspect`
208
- * to guarantee an exact match with the live database schema.
209
- *
210
- * For manually-authored collections you can omit this — the framework
211
- * will derive the column name from the property key via `toSnakeCase()`.
212
- */
213
- columnName?: string;
214
-
215
- /**
216
- * Rules for validating this property
217
- */
218
- validation?: PropertyValidationSchema;
219
-
220
- /**
221
- * Never mention this column on the API surface, in either direction.
222
- *
223
- * For secrets the server must store and read but no client should ever
224
- * receive — password hashes, verification tokens. The value is still
225
- * written and queryable server-side; it is stripped from every row the API
226
- * serves, for every caller, including admins and service keys, and it is
227
- * absent from every generated description of the surface: the SDK's `Row`,
228
- * `Insert` and `Update` types, and the OpenAPI schemas, filters and
229
- * parameters.
230
- *
231
- * The generated types are a *description*, not a second enforcement point:
232
- * the server still accepts such a field on a write, because that is how the
233
- * value gets written in the first place. Nothing generated offers it.
234
- *
235
- * This is a server-side guarantee, unlike `admin.hideFromCollection`, which
236
- * only stops the admin panel from *rendering* a field and leaves it in the
237
- * JSON payload.
238
- */
239
- excludeFromApi?: boolean;
240
-
241
- // NOTE: `defaultValue` is intentionally NOT on BaseProperty.
242
- // Each concrete property type (StringProperty, NumberProperty, etc.)
243
- // defines its own typed `defaultValue` for compile-time safety.
244
-
245
- /**
246
- * Use this to define dynamic properties that change based on certain conditions
247
- * or on the entity's values. For example, you can make a field read-only if
248
- * another field has a certain value.
249
- * This function receives the same props as a `PropertyBuilder` and should return a partial `Property` object.
250
- */
251
- dynamicProps?: (props: PropertyBuilderProps) => Partial<Property>;
252
-
253
- /**
254
- * Declarative conditions for dynamic property behavior using JSON Logic.
255
- *
256
- * An alternative to PropertyBuilder functions that can be:
257
- * - Stored in the database as JSON
258
- * - Edited via the collection editor UI
259
- * - Evaluated at runtime like property builders
260
- *
261
- * @see PropertyConditions for available condition options
262
- * @see https://jsonlogic.com/ for JSON Logic syntax
263
- */
264
- conditions?: PropertyConditions;
265
-
266
- /**
267
- * Callbacks/Hooks for this property field to transform and sanitize data during its lifecycle.
268
- */
269
- callbacks?: PropertyCallbacks;
270
-
271
- /**
272
- * Arbitrary key-value metadata for external consumers.
273
- * Not interpreted by Rebase — passed through serialization unchanged.
274
- * Used by domain apps to store custom per-property config
275
- * (e.g. CRM visibility flags, display hints).
276
- */
277
- metadata?: Record<string, unknown>;
278
-
279
- }
280
-
281
- export interface StringProperty extends BaseProperty {
282
- type: "string";
283
- /**
284
- * Default value for new entities. Must be a string.
285
- */
286
- defaultValue?: string;
287
- /**
288
- * Optional database column type. If not set, it defaults to `varchar` or `uuid` depending on `isId` configuration.
289
- * Use `text` for strings with unbound length, `char` for fixed-length strings, or `varchar` for variable-length strings with a limit.
290
- */
291
- columnType?: "varchar" | "text" | "char" | "uuid";
292
- /**
293
- * Rules for validating this property
294
- */
295
- validation?: StringPropertyValidationSchema;
296
- /**
297
- * Marks this field as a Primary Key / Unique Identifier.
298
- * Framework behavior: Auto-maps to `collection.primaryKeys` internally if not explicitly set.
299
- * Drizzle append: `.primaryKey()`
300
- * UI behavior: Field value cannot be changed after creation.
301
- *
302
- * You can set this to `"manual"` for a user-defined ID, or specify a generation strategy:
303
- * 'uuid' -> Drizzle `.defaultRandom()` (Postgres gen_random_uuid())
304
- * 'cuid' -> Drizzle `.default(sql\`cuid()\`)`
305
- * Or any other random string to act as a raw SQL default expression: e.g. `nanoid()`
306
- *
307
- * On the UI side, the field automatically gets disabled on new entities if a string strategy is provided.
308
- */
309
- isId?: boolean | "manual" | "uuid" | "cuid" | string;
310
- /**
311
- * You can use the enum values providing a map of possible
312
- * exclusive values the property can take, mapped to the label that it is
313
- * displayed in the dropdown. You can use a simple object with the format
314
- * `value` => `label`, or with the format `value` => `EnumValueConfig` if you
315
- * need extra customization, (like disabling specific options or assigning
316
- * colors). If you need to ensure the order of the elements, you can pass
317
- * a `Map` instead of a plain object.
318
- *
319
- */
320
- enum?: EnumValues;
321
- /**
322
- * You can specify a `Storage` configuration. It is used to
323
- * indicate that this string refers to a path in your storage provider.
324
- */
325
- storage?: StorageConfig;
326
-
327
- /**
328
- * This property is used to indicate that the string is a user ID, and
329
- * it will be rendered as a user picker.
330
- * Note that the user ID needs to be the one used in your authentication
331
- * provider (e.g. the ID in your `users` table).
332
- * You can also use a property builder to specify the user path dynamically
333
- * based on other values of the entity.
334
- */
335
- userSelect?: boolean;
336
-
337
- /**
338
- * Does this field include an email
339
- */
340
- email?: boolean;
341
-
342
- /**
343
- * Does this string hold a URL?
344
- *
345
- * A statement about the *data*, which is why it sits here beside `email`
346
- * rather than in the admin block: the OpenAPI generator turns it into
347
- * `format: "uri"`, so it is part of the published API contract. How the panel
348
- * renders it — as a link, an image, a video — is `admin.urlPreview`.
349
- */
350
- url?: boolean;
351
- }
352
-
353
- export interface NumberProperty extends BaseProperty {
354
- type: "number";
355
- /**
356
- * Default value for new entities. Must be a number.
357
- */
358
- defaultValue?: number;
359
- /**
360
- * Optional database column type. Allows specifying exact database numeric types.
361
- * If not provided, integer fields (where validation.integer is true or isId is true) default to `integer`, others to `numeric`.
362
- */
363
- columnType?: "integer" | "real" | "double precision" | "numeric" | "bigint" | "serial" | "bigserial";
364
- /**
365
- * Rules for validating this property
366
- */
367
- validation?: NumberPropertyValidationSchema;
368
- /**
369
- * Marks this field as a Primary Key / Unique Identifier.
370
- * Framework behavior: Auto-maps to `collection.primaryKeys` internally if not explicitly set.
371
- * Drizzle append: `.primaryKey()`
372
- * UI behavior: Field value cannot be changed after creation.
373
- *
374
- * You can set this to `"manual"` for a user-defined ID, or specify a generation strategy:
375
- * 'increment' -> PostgreSQL `GENERATED BY DEFAULT AS IDENTITY` or auto-incrementing integer.
376
- * Or any other random string to act as a raw SQL default expression.
377
- */
378
- isId?: boolean | "manual" | "increment" | string;
379
- /**
380
- * You can use the enum values providing a map of possible
381
- * exclusive values the property can take, mapped to the label that it is
382
- * displayed in the dropdown.
383
- */
384
- enum?: EnumValues;
385
-
386
- }
387
-
388
- /**
389
- * @group Entity properties
390
- */
391
- export interface BooleanProperty extends BaseProperty {
392
- type: "boolean";
393
- /**
394
- * Default value for new entities. Must be a boolean.
395
- */
396
- defaultValue?: boolean;
397
- /**
398
- * Rules for validating this property
399
- */
400
- validation?: PropertyValidationSchema;
401
- }
402
-
403
- /**
404
- * Which pgvector distance a query measures with, and therefore which operator
405
- * class an index has to be built for. The names match the `distance` option on
406
- * `vectorSearch`, because an index built for one operator is not used by a
407
- * query that asks for another.
408
- *
409
- * @group Entity properties
410
- */
411
- export type VectorDistance = "cosine" | "l2" | "inner_product";
412
-
413
- /**
414
- * How the ANN index over a vector column is built.
415
- *
416
- * Without an index, `vectorSearch` is an exact scan: correct at any size,
417
- * and linear in the number of rows. With one, it is approximate and fast.
418
- * That trade is why this is configurable rather than implied.
419
- *
420
- * @group Entity properties
421
- */
422
- export interface VectorIndexConfig {
423
- /**
424
- * `hnsw` (the default) builds a navigable-graph index: slower to build,
425
- * better recall, and it needs no training data, so it works on an empty
426
- * table. `ivfflat` is cheaper to build but partitions by centroid, so an
427
- * index built on an empty or tiny table has useless partitions — build it
428
- * after the data is loaded, and set {@link lists}.
429
- */
430
- method?: "hnsw" | "ivfflat";
431
- /**
432
- * Which distance operators to index, defaulting to `cosine` — the default
433
- * `vectorSearch` measures with. Name several to index several; each one is
434
- * a separate index with its own build cost and its own storage.
435
- */
436
- distance?: VectorDistance | VectorDistance[];
437
- /** HNSW: connections per node. Postgres defaults to 16. */
438
- m?: number;
439
- /** HNSW: candidate-list size while building. Postgres defaults to 64. */
440
- efConstruction?: number;
441
- /** IVFFlat: number of partitions. Postgres defaults to 100. */
442
- lists?: number;
443
- }
444
-
445
- export interface VectorProperty extends BaseProperty {
446
- type: "vector";
447
- /**
448
- * Default value for new entities.
449
- */
450
- defaultValue?: Vector;
451
- dimensions: number;
452
- /**
453
- * ANN index configuration for this column.
454
- *
455
- * Omitted, a single HNSW index for cosine distance is created — which is
456
- * what the default `vectorSearch` uses. `false` creates none, leaving
457
- * `vectorSearch` an exact scan.
458
- *
459
- * Indexes are only created when {@link dimensions} is at most 2000:
460
- * pgvector cannot index a wider `vector` column, so a 3072-dimension
461
- * embedding is left unindexed rather than failing the boot.
462
- */
463
- index?: VectorIndexConfig | false;
464
- validation?: PropertyValidationSchema;
465
- }
466
-
467
- /**
468
- * @group Entity properties
469
- */
470
- export interface BinaryProperty extends BaseProperty {
471
- type: "binary";
472
- /**
473
- * Default value for new entities. Must be a base64-encoded string.
474
- */
475
- defaultValue?: string;
476
- validation?: PropertyValidationSchema;
477
- }
478
-
479
- export interface DateProperty extends BaseProperty {
480
- type: "date";
481
- /**
482
- * Default value for new entities. Must be a Date.
483
- */
484
- defaultValue?: Date;
485
- /**
486
- * Optional database column type. If not set, defaults to `timestamp` with timezone.
487
- */
488
- columnType?: "timestamp" | "date" | "time";
489
- /**
490
- * Rules for validating this property
491
- */
492
- validation?: DatePropertyValidationSchema;
493
- /**
494
- * Set the granularity of the field to a date or date + time.
495
- * Defaults to `date_time`.
496
- *
497
- */
498
- mode?: "date" | "date_time";
499
- /**
500
- * Timezone string to evaluate the date in.
501
- */
502
- timezone?: string;
503
- /**
504
- * If this flag is set to `on_create` or `on_update` this timestamp is
505
- * updated automatically on creation of the entity only or on every
506
- * update (including creation). Useful for creating `created_on` or
507
- * `updated_on` fields
508
- */
509
- autoValue?: "on_create" | "on_update";
510
- }
511
-
512
- /**
513
- * @group Entity properties
514
- */
515
- export interface GeopointProperty extends BaseProperty {
516
- type: "geopoint";
517
- /**
518
- * Default value for new entities. Must be a GeoPoint.
519
- */
520
- defaultValue?: GeoPoint;
521
- /**
522
- * Rules for validating this property
523
- */
524
- validation?: PropertyValidationSchema;
525
- }
526
-
527
- /**
528
- * A pointer to a entity, stored **as a value** on the row (id + path, and
529
- * optionally a `driver`/`databaseId` for cross-datasource pointers).
530
- *
531
- * This is the native primitive of **document databases** — it maps 1:1 to a
532
- * Firestore `DocumentReference`, and is persisted by the MongoDB driver as a
533
- * tagged sub-document. It carries no schema-level relationship (no foreign key,
534
- * no join, no cascade) and is resolved on demand.
535
- *
536
- * **Which to use:**
537
- * - Firestore / MongoDB collection → use `reference`.
538
- * - Postgres collection → use {@link RelationProperty} (`type: "relation"`),
539
- * which models a real foreign key / join with prefetch and cascade.
540
- *
541
- * @group Entity properties
542
- */
543
- export interface ReferenceProperty extends BaseProperty {
544
- type: "reference";
545
- /**
546
- * Default value for new entities. Must be a EntityReference.
547
- */
548
- defaultValue?: EntityReference;
549
- /**
550
- * Marks this field as a Primary Key / Unique Identifier.
551
- * Framework behavior: Auto-maps to `collection.primaryKeys` internally if not explicitly set.
552
- * Drizzle append: `.primaryKey()`
553
- * UI behavior: Field value cannot be changed after creation.
554
- */
555
- isId?: boolean;
556
- /**
557
- * Absolute collection path of the collection this reference points to.
558
- * The collection of the entity is inferred based on the root navigation, so
559
- * the filters and search delegate existing there are applied to this view
560
- * as well.
561
- * You can leave this prop undefined if the path is not yet know, e.g.
562
- * you are using a property builder and the path depends on a different
563
- * property.
564
- */
565
- path?: string;
566
- }
567
-
568
- /**
569
- * A schema-level relationship between collections **within a single
570
- * datasource** — backed by a foreign key, junction table, or explicit join
571
- * path. The resolved value (an `EntityRelation`) can carry a prefetched entity
572
- * payload to eliminate N+1 queries, and supports `onUpdate`/`onDelete` cascade.
573
- *
574
- * This is the native primitive of **relational databases** (Postgres). It is
575
- * the SQL counterpart to {@link ReferenceProperty}.
576
- *
577
- * **Which to use:**
578
- * - Postgres collection → use `relation`.
579
- * - Firestore / MongoDB collection → use {@link ReferenceProperty}
580
- * (`type: "reference"`), a stored pointer with no join engine.
581
- *
582
- * @group Entity properties
583
- */
584
- export interface RelationProperty extends BaseProperty {
585
- type: "relation";
586
- /**
587
- * Default value for new entities. Must be a EntityRelation or array of EntityRelation.
588
- */
589
- defaultValue?: EntityRelation | EntityRelation[];
590
- /**
591
- * Marks this field as a Primary Key / Unique Identifier.
592
- * Framework behavior: Auto-maps to `collection.primaryKeys` internally if not explicitly set.
593
- * Drizzle append: `.primaryKey()`
594
- * UI behavior: Field value cannot be changed after creation.
595
- */
596
- isId?: boolean;
597
-
598
- /**
599
- * The link this field represents.
600
- *
601
- * A closed union: pick the `kind` and the type offers exactly the fields
602
- * that kind needs. This used to be the relation's fields spread flat across
603
- * the property — `target`, `cardinality`, `direction`, `localKey`,
604
- * `foreignKeyOnTarget`, `through` and `joinPath`, every one optional and all
605
- * of them simultaneously legal. Which link you meant then had to be
606
- * inferred, and combinations that meant nothing (a `many` relation carrying
607
- * a `localKey`) typechecked and corrupted writes.
608
- *
609
- * @example
610
- * ```ts
611
- * tags: {
612
- * name: "Tags",
613
- * type: "relation",
614
- * relation: { kind: "manyToMany", target: () => tagsCollection }
615
- * }
616
- * ```
617
- */
618
- relation?: Relation;
619
-
620
- /**
621
- * The same relation with every default filled in, stamped during
622
- * normalization. **Do not set manually** — it is derived from
623
- * {@link RelationProperty.relation}, or looked up by name from the
624
- * collection's `relations` array.
625
- */
626
- resolvedRelation?: ResolvedRelation;
627
- }
628
-
629
- export interface ArrayProperty extends BaseProperty {
630
- type: "array";
631
- /**
632
- * Default value for new entities. Must be an array.
633
- */
634
- defaultValue?: unknown[];
635
- /**
636
- * Optional database column type. By default, maps to a native Postgres array
637
- * (e.g. `text[]`, `integer[]`/`numeric[]`, `boolean[]`) if the element type
638
- * is a primitive, otherwise defaults to `jsonb`.
639
- */
640
- columnType?: "json" | "jsonb" | "text[]" | "integer[]" | "boolean[]" | "numeric[]";
641
- /**
642
- * The property of this array.
643
- * You can specify any property (except another Array property)
644
- * You can leave this field empty only if you are providing a custom field,
645
- * or using the `oneOf` prop, otherwise an error will be thrown.
646
- */
647
- of?: Property | Property[];
648
- /**
649
- * Use this field if you would like to have an array of typed objects.
650
- * It is useful if you need to have values of different types in the same
651
- * array.
652
- * Each entry of the array is an object with the shape:
653
- * ```
654
- * { type: "YOUR_TYPE", value: "YOUR_VALUE"}
655
- * ```
656
- * Note that you can use any property so `value` can take any value (strings,
657
- * numbers, array, objects...)
658
- * You can customise the `type` and `value` fields to suit your needs.
659
- *
660
- * An example use case for this feature may be a blog entry, where you have
661
- * images and text blocks using markdown.
662
- */
663
- oneOf?: {
664
- /**
665
- * Record of properties, where the key is the `type` and the value
666
- * is the corresponding property
667
- */
668
- properties: Properties;
669
- /**
670
- * Order in which the properties are displayed.
671
- * If you are specifying your collection as code, the order is the same as the
672
- * one you define in `properties`, and you don't need to specify this prop.
673
- */
674
- propertiesOrder?: string[];
675
- /**
676
- * Name of the field to use as the discriminator for type
677
- * Defaults to `type`
678
- */
679
- typeField?: string;
680
- /**
681
- * Name of the field to use as the value
682
- * Defaults to `value`
683
- */
684
- valueField?: string;
685
- };
686
- /**
687
- * Rules for validating this property
688
- */
689
- validation?: ArrayPropertyValidationSchema;
690
- }
691
-
692
- export interface MapProperty extends BaseProperty {
693
- type: "map";
694
- /**
695
- * Default value for new entities. Must be a record/object.
696
- */
697
- defaultValue?: Record<string, unknown>;
698
- /**
699
- * Optional database column type. Defaults to `jsonb`.
700
- */
701
- columnType?: "json" | "jsonb";
702
- /**
703
- * Record of properties included in this map.
704
- */
705
- properties?: Properties;
706
- /**
707
- * Order in which the properties are displayed.
708
- * If you are specifying your collection as code, the order is the same as the
709
- * one you define in `properties`, and you don't need to specify this prop.
710
- *
711
- * Stays on the property rather than moving to the `admin` block, unlike the
712
- * rest of the map's presentation options: `sortProperties` in
713
- * `@rebasepro/common` reads it recursively, and `@rebasepro/firebase` calls
714
- * that when it builds collections. A core package cannot read the admin
715
- * block — the field exists only once `@rebasepro/cms-types` is installed.
716
- */
717
- propertiesOrder?: string[];
718
- /**
719
- * Rules for validating this property.
720
- * NOTE: If you don't set `required` in the map property, an empty object
721
- * will be considered valid, even if you set `required` in the properties.
722
- */
723
- validation?: PropertyValidationSchema;
724
- /**
725
- * Render this map as a key-value table that allows to use
726
- * arbitrary keys. You don't need to define the properties in this case.
727
- *
728
- * Core rather than admin despite the wording: it says the map has no
729
- * declared shape, which is what the OpenAPI generator emits the schema
730
- * from (`additionalProperties` instead of a property list).
731
- */
732
- keyValue?: boolean;
733
- }
734
-
735
- /**
736
- * @group Entity properties
737
- */
738
- export type PropertyBuilderProps<M extends Record<string, unknown> = Record<string, unknown>> = {
739
- values: Partial<M>;
740
- previousValues?: Partial<M>;
741
- propertyValue?: unknown;
742
- index?: number;
743
- path: string;
744
- entityId?: string | number;
745
- authController: AuthState;
746
- };
747
-
748
- /**
749
- * We use this type to define mapping between string or number values in
750
- * the data source to a label (such in a select dropdown).
751
- * The key in this Record is the value saved in the driver, and the value in
752
- * this record is the label displayed in the UI.
753
- * You can add additional customization by assigning a {@link EnumValueConfig} for the
754
- * label instead of a simple string (for enabling or disabling options and
755
- * choosing colors).
756
- * If you need to ensure the order of the elements use an array of {@link EnumValueConfig}
757
- * @group Entity properties
758
- */
759
- export type EnumValues = EnumValueConfig[] | Record<string | number, string | EnumValueConfig>;
760
-
761
- /**
762
- * Configuration for a particular entry in an `EnumValues`
763
- * @group Entity properties
764
- */
765
- export type EnumValueConfig = {
766
- /**
767
- * Value stored in the data source.
768
- */
769
- id: string | number;
770
- /**
771
- * Displayed label
772
- */
773
- label: string;
774
- /**
775
- * This value will not be selectable
776
- */
777
- disabled?: boolean;
778
- /**
779
- * You can pick from a list of predefined color combinations or define
780
- * your own {@link ColorScheme}
781
- */
782
- color?: ColorKey | ColorScheme;
783
- }
784
-
785
- /**
786
- * Rules to validate any property. Some properties have specific rules
787
- * additionally to these.
788
- * @group Entity properties
789
- */
790
- export interface PropertyValidationSchema {
791
- /**
792
- * Is this field required
793
- */
794
- required?: boolean;
795
-
796
- /**
797
- * Customize the required message when the property is not set
798
- */
799
- requiredMessage?: string;
800
-
801
- /**
802
- * If the unique flag is set to `true`, you can only have one entity in the
803
- * collection with this value.
804
- */
805
- unique?: boolean;
806
-
807
- /**
808
- * If the uniqueInArray flag is set to `true`, you can only have this value
809
- * once per entry in the parent `ArrayProperty`. It has no effect if this
810
- * property is not a child of an `ArrayProperty`. It works on direct
811
- * children of an `ArrayProperty` or first level children of `MapProperty`
812
- */
813
- uniqueInArray?: boolean;
814
- }
815
-
816
- /**
817
- * Validation rules for numbers
818
- * @group Entity properties
819
- */
820
- export interface NumberPropertyValidationSchema extends PropertyValidationSchema {
821
- min?: number;
822
- max?: number;
823
- lessThan?: number;
824
- moreThan?: number;
825
- positive?: boolean;
826
- negative?: boolean;
827
- integer?: boolean;
828
- }
829
-
830
- /**
831
- * Validation rules for strings
832
- * @group Entity properties
833
- */
834
- export interface StringPropertyValidationSchema extends PropertyValidationSchema {
835
- length?: number;
836
- min?: number;
837
- max?: number;
838
- matches?: string | RegExp;
839
- /**
840
- * Message displayed when the input does not satisfy the regex in `matches`
841
- */
842
- matchesMessage?: string;
843
- trim?: boolean;
844
- lowercase?: boolean;
845
- uppercase?: boolean;
846
- }
847
-
848
- /**
849
- * Validation rules for dates
850
- * @group Entity properties
851
- */
852
- export interface DatePropertyValidationSchema extends PropertyValidationSchema {
853
- min?: Date;
854
- max?: Date;
855
- }
856
-
857
- /**
858
- * Validation rules for arrays
859
- * @group Entity properties
860
- */
861
- export interface ArrayPropertyValidationSchema extends PropertyValidationSchema {
862
- min?: number;
863
- max?: number;
864
- }
865
-
866
- /**
867
- * Additional configuration related to Storage related fields
868
- * @group Entity properties
869
- */
870
- export type StorageConfig = {
871
- /**
872
- * Key referencing a named storage backend from the StorageRegistry.
873
- * Must match a `StorageSourceDefinition.key` or a key registered
874
- * in `initializeRebaseBackend({ storage: { ... } })`.
875
- *
876
- * When omitted, the default storage source is used.
877
- */
878
- storageSource?: string;
879
-
880
- /**
881
- * Store files for this property as **public**: they are placed under the
882
- * public prefix and served via stable, token-less, permanent, CDN-cacheable
883
- * URLs (safe to persist and hotlink). Use for public assets like avatars or
884
- * storefront images. Defaults to `false` (private, short-lived signed URLs).
885
- */
886
- public?: boolean;
887
-
888
- /**
889
- * File MIME types that can be uploaded to this reference. Don't specify for
890
- * all.
891
- * Note that you can also use the asterisk notation, so `image/*`
892
- * accepts any image file, and so on.
893
- */
894
- acceptedFiles?: FileType[];
895
-
896
- /**
897
- * Advanced image resizing and cropping configuration.
898
- * Applied before upload to optimize storage and bandwidth.
899
- * Only applies to image MIME types: image/jpeg, image/png, image/webp
900
- */
901
- imageResize?: ImageResize;
902
-
903
- /**
904
- * Specific metadata set in your uploaded file.
905
- * For the default Firebase implementation, the values passed here are of type
906
- * `firebase.storage.UploadMetadata`
907
- */
908
- metadata?: Record<string, unknown>,
909
-
910
- /**
911
- * You can use this prop to customize the uploaded filename.
912
- * You can use a function as a callback or a string where you
913
- * specify some placeholders that get replaced with the corresponding values.
914
- * - `{file}` - Full file name
915
- * - `{file.name}` - Name of the file without extension
916
- * - `{file.ext}` - Extension of the file
917
- * - `{rand}` - Random value used to avoid name collisions
918
- * - `{entityId}` - ID of the entity
919
- * - `{propertyKey}` - ID of this property
920
- * - `{path}` - Path of this entity
921
- *
922
- * @param context
923
- */
924
- fileName?: string | ((context: UploadedFileContext) => string | Promise<string>);
925
-
926
- /**
927
- * Absolute path in your bucket.
928
- *
929
- * You can use a function as a callback or a string where you
930
- * specify some placeholders that get replaced with the corresponding values.
931
- * - `{file}` - Full file name
932
- * - `{file.name}` - Name of the file without extension
933
- * - `{file.ext}` - Extension of the file
934
- * - `{rand}` - Random value used to avoid name collisions
935
- * - `{entityId}` - ID of the entity
936
- * - `{propertyKey}` - ID of this property
937
- * - `{path}` - Path of this entity
938
- */
939
- storagePath: string | ((context: UploadedFileContext) => string);
940
-
941
- /**
942
- * When set to true, this flag indicates that the bucket name will be
943
- * included in the saved storage path.
944
- *
945
- * E.g. `s3://my-bucket/path/to/file.png` instead of just `path/to/file.png`
946
- *
947
- * Defaults to false.
948
- */
949
- includeBucketUrl?: boolean;
950
-
951
- /**
952
- * When set to true, this flag indicates that the download URL of the file
953
- * will be saved in the driver, instead of the storage path.
954
- *
955
- * Note that the generated URL may use a token that, if disabled, may
956
- * make the URL unusable and lose the original reference to Cloud Storage,
957
- * so it is not encouraged to use this flag.
958
- *
959
- * Defaults to false.
960
- */
961
- storeUrl?: boolean,
962
-
963
- /**
964
- * Define maximal file size in bytes
965
- */
966
- maxSize?: number,
967
-
968
- /**
969
- * Use this callback to process the file before uploading it to the storage.
970
- * If nothing is returned, the file is uploaded as it is.
971
- * @param file
972
- */
973
- processFile?: (file: File) => Promise<File> | undefined;
974
-
975
- /**
976
- * Postprocess the saved value (storage path or URL)
977
- * after it has been resolved.
978
- */
979
- postProcess?: (pathOrUrl: string) => Promise<string>;
980
-
981
- /**
982
- * You can use this prop in order to provide a custom preview URL.
983
- * Useful when the file's path is different from the original field value
984
- */
985
- previewUrl?: (fileName: string) => string;
986
- }
987
-
988
- /**
989
- * @group Entity properties
990
- */
991
- export interface UploadedFileContext {
992
- /**
993
- * Uploaded file
994
- */
995
- file: File;
996
-
997
- /**
998
- * Property field name
999
- */
1000
- propertyKey: string;
1001
-
1002
- /**
1003
- * Property related to this upload
1004
- */
1005
- property: StringProperty | ArrayProperty;
1006
-
1007
- /**
1008
- * Entity ID
1009
- */
1010
- entityId?: string | number;
1011
-
1012
- /**
1013
- * Entity path. E.g. `products/PID/locales`
1014
- */
1015
- path?: string;
1016
-
1017
- /**
1018
- * Values of the current entity
1019
- */
1020
- values: EntityValues<any>;
1021
-
1022
- /**
1023
- * Storage meta specified by the developer
1024
- */
1025
- storage: StorageConfig;
1026
- }
1027
-
1028
- /**
1029
- * MIME types for storage fields
1030
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
1031
- * @group Entity properties
1032
- */
1033
- export type FileType =
1034
- | "image/*"
1035
- | "video/*"
1036
- | "audio/*"
1037
- | "application/*"
1038
- | "text/*"
1039
- | "font/*"
1040
- | string;
1041
-
1042
- export interface ImageResize {
1043
- /**
1044
- * Maximum width in pixels. Image will be scaled down proportionally if wider.
1045
- */
1046
- maxWidth?: number;
1047
-
1048
- /**
1049
- * Maximum height in pixels. Image will be scaled down proportionally if taller.
1050
- */
1051
- maxHeight?: number;
1052
-
1053
- /**
1054
- * Resize mode determines how the image fits within maxWidth/maxHeight bounds.
1055
- * - `contain`: Scale down to fit within bounds, preserving aspect ratio (default)
1056
- * - `cover`: Scale to fill bounds, preserving aspect ratio (may crop)
1057
- */
1058
- mode?: "contain" | "cover";
1059
-
1060
- /**
1061
- * Output format for the resized image.
1062
- * - `original`: Keep the original format (default)
1063
- * - `jpeg`: Convert to JPEG
1064
- * - `png`: Convert to PNG
1065
- * - `webp`: Convert to WebP
1066
- */
1067
- format?: "original" | "jpeg" | "png" | "webp";
1068
-
1069
- /**
1070
- * Quality for lossy formats (JPEG, WebP). Number between 0 and 100.
1071
- * Higher is better quality but larger file size. Defaults to 80.
1072
- */
1073
- quality?: number;
1074
- }
1075
-
1076
- /**
1077
- * A JSON Logic rule that gets evaluated at runtime.
1078
- * @see https://jsonlogic.com/
1079
- *
1080
- * Common operators:
1081
- * - Comparison: ==, !=, ===, !==, >, <, >=, <=
1082
- * - Logic: and, or, !, !!
1083
- * - Data access: var, missing, missing_some
1084
- * - Array: in, map, filter, reduce, all, some, none, merge
1085
- * - String: substr, cat
1086
- * - Numeric: +, -, *, /, %, min, max
1087
- *
1088
- * Custom operators:
1089
- * - hasRole(roleId) - check if user has role by ID
1090
- * - hasAnyRole([roleIds]) - check if user has any of the roles
1091
- * - isToday(timestamp) - check if timestamp is today
1092
- * - isPast(timestamp) - check if timestamp is in the past
1093
- * - isFuture(timestamp) - check if timestamp is in the future
1094
- *
1095
- * @group Entity properties
1096
- */
1097
- export type JsonLogicRule = Record<string, any>;
1098
-
1099
- /**
1100
- * A condition that is either a JSON Logic rule or a literal answer.
1101
- *
1102
- * The unconditional case is the common one — "this field is never editable",
1103
- * "this field is never shown" — and with only a rule accepted it had to be
1104
- * spelled `{ "==": [1, 1] }`, which reads as a puzzle at the call site. A plain
1105
- * `true` says the same thing.
1106
- *
1107
- * @group Entity properties
1108
- */
1109
- export type ConditionRule = JsonLogicRule | boolean;
1110
-
1111
- /**
1112
- * Conditions for individual enum values within a property.
1113
- * @group Entity properties
1114
- */
1115
- export interface EnumValueConditions {
1116
- /**
1117
- * Disable this enum option when condition is true.
1118
- * The option appears grayed out and cannot be selected.
1119
- */
1120
- disabled?: JsonLogicRule;
1121
-
1122
- /**
1123
- * Message explaining why this option is disabled.
1124
- */
1125
- disabledMessage?: string;
1126
-
1127
- /**
1128
- * Completely hide this enum option when condition is true.
1129
- * The option is removed from the dropdown/list.
1130
- */
1131
- hidden?: JsonLogicRule;
1132
- }
1133
-
1134
- /**
1135
- * Declarative conditions for dynamic property behavior.
1136
- * All conditions are JSON Logic rules evaluated against ConditionContext.
1137
- *
1138
- * An alternative to PropertyBuilder functions that can be:
1139
- * - Stored in the database as JSON
1140
- * - Edited via the collection editor UI
1141
- * - Evaluated at runtime like property builders
1142
- *
1143
- * @see https://jsonlogic.com/ for JSON Logic syntax
1144
- * @group Entity properties
1145
- */
1146
- export interface PropertyConditions {
1147
-
1148
- // ═══════════════════════════════════════════════════════════════════════
1149
- // FIELD STATE CONDITIONS
1150
- // ═══════════════════════════════════════════════════════════════════════
1151
-
1152
- /**
1153
- * Disable the field when this condition evaluates to true.
1154
- * The field becomes non-editable but still visible (unless also hidden).
1155
- *
1156
- * @example Disable when another field has a specific value
1157
- * \`\`\`json
1158
- * { "==": [{ "var": "values.status" }, "archived"] }
1159
- * \`\`\`
1160
- *
1161
- * A literal `true` disables it unconditionally.
1162
- */
1163
- disabled?: ConditionRule;
1164
-
1165
- /**
1166
- * Message to display when the field is disabled by a condition.
1167
- */
1168
- disabledMessage?: string;
1169
-
1170
- /**
1171
- * Clear the field's value when it becomes disabled.
1172
- * @default false
1173
- */
1174
- clearOnDisabled?: boolean;
1175
-
1176
- /**
1177
- * Hide the field completely when this condition evaluates to true.
1178
- * The field is removed from the form (not just visually hidden).
1179
- *
1180
- * A literal `true` hides it unconditionally. This is the way to keep a
1181
- * property out of the form without keeping it out of the collection.
1182
- */
1183
- hidden?: ConditionRule;
1184
-
1185
- /**
1186
- * Make the field read-only when this condition evaluates to true.
1187
- * Renders as a preview instead of an input.
1188
- *
1189
- * A literal `true` makes it read-only unconditionally.
1190
- */
1191
- readOnly?: ConditionRule;
1192
-
1193
- // ═══════════════════════════════════════════════════════════════════════
1194
- // VALIDATION CONDITIONS
1195
- // ═══════════════════════════════════════════════════════════════════════
1196
-
1197
- /**
1198
- * Make the field required when this condition evaluates to true.
1199
- * Overrides the static `validation.required` setting.
1200
- */
1201
- required?: JsonLogicRule;
1202
-
1203
- /**
1204
- * Custom message when conditional required validation fails.
1205
- */
1206
- requiredMessage?: string;
1207
-
1208
- /**
1209
- * Dynamic minimum value for number/string length.
1210
- * Should evaluate to a number.
1211
- */
1212
- min?: JsonLogicRule;
1213
-
1214
- /**
1215
- * Dynamic maximum value for number/string length.
1216
- * Should evaluate to a number.
1217
- */
1218
- max?: JsonLogicRule;
1219
-
1220
- // ═══════════════════════════════════════════════════════════════════════
1221
- // VALUE CONDITIONS
1222
- // ═══════════════════════════════════════════════════════════════════════
1223
-
1224
- /**
1225
- * Dynamic default value for new entities.
1226
- * Should evaluate to a value of the appropriate type for the field.
1227
- * Only applied when entityId is empty (new entity).
1228
- */
1229
- defaultValue?: JsonLogicRule;
1230
-
1231
- // ═══════════════════════════════════════════════════════════════════════
1232
- // ENUM CONDITIONS (for string/number properties with enum values)
1233
- // ═══════════════════════════════════════════════════════════════════════
1234
-
1235
- /**
1236
- * Conditions for individual enum values.
1237
- * Keys are the enum value IDs, values are condition configs.
1238
- *
1239
- * @example Disable certain enum options based on user role
1240
- * \`\`\`json
1241
- * {
1242
- * "admin": {
1243
- * "disabled": { "!": { "hasRole": "admin" } },
1244
- * "disabledMessage": "Admin option requires admin role"
1245
- * }
1246
- * }
1247
- * \`\`\`
1248
- */
1249
- enumConditions?: Record<string | number, EnumValueConditions>;
1250
-
1251
- /**
1252
- * Filter which enum values are available.
1253
- * Should evaluate to an array of allowed enum value IDs.
1254
- */
1255
- allowedEnumValues?: JsonLogicRule;
1256
-
1257
- /**
1258
- * Exclude specific enum values.
1259
- * Should evaluate to an array of enum value IDs to exclude.
1260
- */
1261
- excludedEnumValues?: JsonLogicRule;
1262
-
1263
- // ═══════════════════════════════════════════════════════════════════════
1264
- // REFERENCE CONDITIONS (for reference properties)
1265
- // ═══════════════════════════════════════════════════════════════════════
1266
-
1267
- /**
1268
- * Dynamic path for reference properties.
1269
- * Should evaluate to a collection path string.
1270
- */
1271
- referencePath?: JsonLogicRule;
1272
-
1273
- /**
1274
- * Dynamic filter for reference selection.
1275
- * Should evaluate to a FilterValues object.
1276
- */
1277
- referenceFilter?: JsonLogicRule;
1278
-
1279
- // ═══════════════════════════════════════════════════════════════════════
1280
- // ARRAY CONDITIONS (for array properties)
1281
- // ═══════════════════════════════════════════════════════════════════════
1282
-
1283
- /**
1284
- * Can elements be added to the array?
1285
- */
1286
- canAddElements?: JsonLogicRule;
1287
-
1288
- /**
1289
- * Can elements be reordered in the array?
1290
- */
1291
- sortable?: JsonLogicRule;
1292
-
1293
- // ═══════════════════════════════════════════════════════════════════════
1294
- // STORAGE CONDITIONS (for file upload properties)
1295
- // ═══════════════════════════════════════════════════════════════════════
1296
-
1297
- /**
1298
- * Dynamic accepted file types.
1299
- * Should evaluate to an array of MIME types.
1300
- */
1301
- acceptedFiles?: JsonLogicRule;
1302
-
1303
- /**
1304
- * Dynamic maximum file size in bytes.
1305
- * Should evaluate to a number.
1306
- */
1307
- maxFileSize?: JsonLogicRule;
1308
- }
1309
-
1310
- /**
1311
- * Context available during JSON Logic condition evaluation.
1312
- * Mirrors PropertyBuilderProps but adapted for JSON serialization.
1313
- * @group Entity properties
1314
- */
1315
- export interface ConditionContext {
1316
- /**
1317
- * Current form/entity values.
1318
- * Date values are converted to Unix timestamps (milliseconds).
1319
- */
1320
- values: Record<string, unknown>;
1321
-
1322
- /**
1323
- * Previous values before the current edit session.
1324
- */
1325
- previousValues: Record<string, unknown>;
1326
-
1327
- /**
1328
- * Current value of this property specifically.
1329
- */
1330
- propertyValue: unknown;
1331
-
1332
- /**
1333
- * Collection path (e.g., "products", "users/uid123/orders")
1334
- */
1335
- path: string;
1336
-
1337
- /**
1338
- * Entity ID. Undefined for new entities.
1339
- */
1340
- entityId?: string;
1341
-
1342
- /**
1343
- * Whether this is a new entity being created.
1344
- */
1345
- isNew: boolean;
1346
-
1347
- /**
1348
- * Index of this property (only for array items).
1349
- */
1350
- index?: number;
1351
-
1352
- /**
1353
- * Current authenticated user information.
1354
- */
1355
- user: {
1356
- uid: string;
1357
- email: string | null;
1358
- displayName: string | null;
1359
- photoURL: string | null;
1360
- /** Role IDs the user has (extracted from Role[].id) */
1361
- roles: string[];
1362
- };
1363
-
1364
- /**
1365
- * Current timestamp as Unix milliseconds.
1366
- */
1367
- now: number;
1368
- }