@stndrds/schema 1.0.0-alpha.95 → 1.0.0-alpha.97

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 (137) hide show
  1. package/dist/attributes-C-bhC0k5.d.ts +673 -0
  2. package/dist/attributes-DB76JqXm.d.mts +673 -0
  3. package/dist/chunk-2TEWGEUI.js +212 -0
  4. package/dist/chunk-4RGFTMQR.mjs +8 -0
  5. package/dist/chunk-5TLM4QXO.mjs +8 -0
  6. package/dist/chunk-67PQMHQA.mjs +199 -0
  7. package/dist/chunk-6HHSX6LP.js +64 -0
  8. package/dist/chunk-AHPXNPJC.js +105 -0
  9. package/dist/chunk-BEN6TE7Y.js +11 -0
  10. package/dist/chunk-BH3RPSC5.js +22 -0
  11. package/dist/chunk-BIQ35DLC.mjs +78 -0
  12. package/dist/chunk-CKZHFJQT.js +16 -0
  13. package/dist/chunk-E6XO2STS.js +11 -11
  14. package/dist/chunk-EIWGW2ML.mjs +99 -0
  15. package/dist/chunk-EKG35CSO.mjs +1 -0
  16. package/dist/chunk-IMEPIVTR.js +217 -0
  17. package/dist/chunk-J4ORNCAH.js +10 -0
  18. package/dist/chunk-KC4F3HB7.js +32 -0
  19. package/dist/chunk-LHXE7LLD.js +28 -0
  20. package/dist/chunk-MD6XGXTU.mjs +18 -0
  21. package/dist/chunk-N47XKY4R.js +14 -0
  22. package/dist/chunk-NXXSNUDI.mjs +8 -0
  23. package/dist/chunk-PKG3E5MW.mjs +18 -0
  24. package/dist/chunk-PZT3CIHD.mjs +192 -0
  25. package/dist/chunk-QL3UGPUG.mjs +60 -0
  26. package/dist/chunk-QY65ZSBL.js +16 -0
  27. package/dist/chunk-R6JFUC32.js +2 -0
  28. package/dist/chunk-RDXQ4CYT.mjs +9 -0
  29. package/dist/chunk-S5VJ2FZE.js +12 -0
  30. package/dist/chunk-SVII65W7.mjs +14 -0
  31. package/dist/chunk-U7VN3RUE.mjs +25 -0
  32. package/dist/chunk-VCPYYLCS.js +83 -0
  33. package/dist/chunk-VD3P2A6Q.js +10 -0
  34. package/dist/chunk-VPEV3W34.mjs +10 -0
  35. package/dist/chunk-WGFQMQMV.mjs +14 -0
  36. package/dist/chunk-X6VDDXG7.mjs +12 -0
  37. package/dist/chunk-XAORXFAX.mjs +1 -10
  38. package/dist/chunk-XEOG24K6.mjs +8 -0
  39. package/dist/chunk-XK6XC3V4.js +10 -0
  40. package/dist/chunk-XZ5B5MTG.js +20 -0
  41. package/dist/chunk-YKHC2AW6.js +10 -0
  42. package/dist/chunk-Z2T7ONKU.js +20 -0
  43. package/dist/chunk-ZFL7DXAE.mjs +28 -0
  44. package/dist/chunk-ZM7W2ZCF.mjs +20 -0
  45. package/dist/{validators-5XMwJOlV.d.ts → index-Bt-0XNSh.d.ts} +14 -1499
  46. package/dist/{validators-BCw4Sn01.d.mts → index-C9tOwUbK.d.mts} +14 -1499
  47. package/dist/index.d.mts +1267 -976
  48. package/dist/index.d.ts +1267 -976
  49. package/dist/index.js +1293 -1001
  50. package/dist/index.mjs +529 -785
  51. package/dist/types-B7nS2D1A.d.ts +39 -0
  52. package/dist/types-CjXbGsy8.d.mts +39 -0
  53. package/dist/utils.js +38 -20
  54. package/dist/utils.mjs +1 -20
  55. package/dist/validation/all.d.mts +23 -0
  56. package/dist/validation/all.d.ts +23 -0
  57. package/dist/validation/all.js +265 -0
  58. package/dist/validation/all.mjs +20 -0
  59. package/dist/validation/complex/currency.d.mts +15 -0
  60. package/dist/validation/complex/currency.d.ts +15 -0
  61. package/dist/validation/complex/currency.js +12 -0
  62. package/dist/validation/complex/currency.mjs +3 -0
  63. package/dist/validation/complex/file.d.mts +13 -0
  64. package/dist/validation/complex/file.d.ts +13 -0
  65. package/dist/validation/complex/file.js +12 -0
  66. package/dist/validation/complex/file.mjs +3 -0
  67. package/dist/validation/complex/location.d.mts +22 -0
  68. package/dist/validation/complex/location.d.ts +22 -0
  69. package/dist/validation/complex/location.js +12 -0
  70. package/dist/validation/complex/location.mjs +3 -0
  71. package/dist/validation/complex/phone.d.mts +22 -0
  72. package/dist/validation/complex/phone.d.ts +22 -0
  73. package/dist/validation/complex/phone.js +12 -0
  74. package/dist/validation/complex/phone.mjs +3 -0
  75. package/dist/validation/complex/relation.d.mts +25 -0
  76. package/dist/validation/complex/relation.d.ts +25 -0
  77. package/dist/validation/complex/relation.js +20 -0
  78. package/dist/validation/complex/relation.mjs +3 -0
  79. package/dist/validation/complex/richtext.d.mts +13 -0
  80. package/dist/validation/complex/richtext.d.ts +13 -0
  81. package/dist/validation/complex/richtext.js +12 -0
  82. package/dist/validation/complex/richtext.mjs +3 -0
  83. package/dist/validation/complex/select.d.mts +20 -0
  84. package/dist/validation/complex/select.d.ts +20 -0
  85. package/dist/validation/complex/select.js +20 -0
  86. package/dist/validation/complex/select.mjs +3 -0
  87. package/dist/validation/complex/user.d.mts +13 -0
  88. package/dist/validation/complex/user.d.ts +13 -0
  89. package/dist/validation/complex/user.js +12 -0
  90. package/dist/validation/complex/user.mjs +3 -0
  91. package/dist/validation/computed/formula.d.mts +14 -0
  92. package/dist/validation/computed/formula.d.ts +14 -0
  93. package/dist/validation/computed/formula.js +12 -0
  94. package/dist/validation/computed/formula.mjs +3 -0
  95. package/dist/validation/computed/rollup.d.mts +14 -0
  96. package/dist/validation/computed/rollup.d.ts +14 -0
  97. package/dist/validation/computed/rollup.js +12 -0
  98. package/dist/validation/computed/rollup.mjs +3 -0
  99. package/dist/validation/config/index.d.mts +421 -0
  100. package/dist/validation/config/index.d.ts +421 -0
  101. package/dist/validation/config/index.js +103 -0
  102. package/dist/validation/config/index.mjs +2 -0
  103. package/dist/validation/core/index.d.mts +85 -0
  104. package/dist/validation/core/index.d.ts +85 -0
  105. package/dist/validation/core/index.js +27 -0
  106. package/dist/validation/core/index.mjs +2 -0
  107. package/dist/validation/object/index.d.mts +6 -0
  108. package/dist/validation/object/index.d.ts +6 -0
  109. package/dist/validation/object/index.js +71 -0
  110. package/dist/validation/object/index.mjs +18 -0
  111. package/dist/validation/primitives/checkbox.d.mts +12 -0
  112. package/dist/validation/primitives/checkbox.d.ts +12 -0
  113. package/dist/validation/primitives/checkbox.js +12 -0
  114. package/dist/validation/primitives/checkbox.mjs +3 -0
  115. package/dist/validation/primitives/date.d.mts +12 -0
  116. package/dist/validation/primitives/date.d.ts +12 -0
  117. package/dist/validation/primitives/date.js +12 -0
  118. package/dist/validation/primitives/date.mjs +3 -0
  119. package/dist/validation/primitives/number.d.mts +12 -0
  120. package/dist/validation/primitives/number.d.ts +12 -0
  121. package/dist/validation/primitives/number.js +12 -0
  122. package/dist/validation/primitives/number.mjs +3 -0
  123. package/dist/validation/primitives/rating.d.mts +12 -0
  124. package/dist/validation/primitives/rating.d.ts +12 -0
  125. package/dist/validation/primitives/rating.js +12 -0
  126. package/dist/validation/primitives/rating.mjs +3 -0
  127. package/dist/validation/primitives/text.d.mts +17 -0
  128. package/dist/validation/primitives/text.d.ts +17 -0
  129. package/dist/validation/primitives/text.js +16 -0
  130. package/dist/validation/primitives/text.mjs +3 -0
  131. package/dist/validation/validators.d.mts +21 -2
  132. package/dist/validation/validators.d.ts +21 -2
  133. package/dist/validation/validators.js +265 -120
  134. package/dist/validation/validators.mjs +20 -120
  135. package/package.json +108 -5
  136. package/dist/chunk-4362R5F2.mjs +0 -780
  137. package/dist/chunk-7QUI6TSO.js +0 -780
@@ -0,0 +1,673 @@
1
+ import { IconName, CountryIso3, CurrencyCode, ColorId, MimeType } from '@stndrds/constants';
2
+ import { Uuid } from './utils.js';
3
+
4
+ /**
5
+ * Feature flag levels (resolution priority: user > tenant > global).
6
+ *
7
+ * - `global`: Applies to all tenants and users
8
+ * - `tenant`: Applies to a specific tenant
9
+ * - `user`: Applies to a specific user within a tenant
10
+ */
11
+ type FlagLevel = "global" | "tenant" | "user";
12
+ /**
13
+ * Flag value types supported by the system.
14
+ */
15
+ type FlagValueType = "boolean" | "string" | "number" | "json";
16
+ /**
17
+ * Definition of a feature flag.
18
+ * Created using the flag builders (booleanFlag, stringFlag, etc.)
19
+ */
20
+ interface FeatureFlagDefinition<T = unknown> {
21
+ /** Unique identifier for the flag (kebab-case) */
22
+ name: string;
23
+ /** Human-readable label */
24
+ label: string;
25
+ /** Optional description */
26
+ description?: string;
27
+ /** Type of the flag value */
28
+ valueType: FlagValueType;
29
+ /** Default value when no override exists */
30
+ defaultValue: T;
31
+ /** Levels at which this flag can be overridden */
32
+ allowedLevels: FlagLevel[];
33
+ /** Grouping category for UI */
34
+ category?: string;
35
+ /** System flag - cannot be modified via API */
36
+ system?: boolean;
37
+ }
38
+ /**
39
+ * Stored override for a feature flag.
40
+ * Represents a row in the feature_flag_overrides table.
41
+ */
42
+ interface FlagOverride<T = unknown> {
43
+ /** Name of the flag being overridden */
44
+ flagName: string;
45
+ /** Level of the override */
46
+ level: FlagLevel;
47
+ /** Target ID (tenantId for tenant-level, userId for user-level) */
48
+ targetId?: string;
49
+ /** Override value */
50
+ value: T;
51
+ /** Optional expiration date */
52
+ expiresAt?: Date;
53
+ /** Who created this override */
54
+ createdBy?: string;
55
+ /** When the override was created */
56
+ createdAt: Date;
57
+ /** When the override was last updated */
58
+ updatedAt: Date;
59
+ }
60
+ /**
61
+ * Resolved flag value with source information.
62
+ * Result of flag resolution including where the value came from.
63
+ */
64
+ interface ResolvedFlag<T = unknown> {
65
+ /** Flag name */
66
+ name: string;
67
+ /** Resolved value */
68
+ value: T;
69
+ /** Where the value came from */
70
+ source: FlagLevel | "default";
71
+ /** ID of the source (tenantId or userId) if not default */
72
+ sourceId?: string;
73
+ }
74
+ /**
75
+ * Feature gate configuration for conditional attribute visibility.
76
+ * Used with the `.featureGate()` builder method.
77
+ */
78
+ interface FeatureGate {
79
+ /** Name of the flag to check */
80
+ flag: string;
81
+ /**
82
+ * Expected value for the gate to pass.
83
+ * For boolean flags, defaults to `true`.
84
+ * For other types, compares with strict equality.
85
+ */
86
+ expectedValue?: unknown;
87
+ /**
88
+ * Behavior when the gate fails.
89
+ * - `hide`: Attribute is completely hidden (default)
90
+ * - `show`: Attribute is shown regardless (no gating)
91
+ * - `disable`: Attribute is visible but read-only
92
+ */
93
+ fallback?: "hide" | "show" | "disable";
94
+ }
95
+ /**
96
+ * Repository interface for feature flag overrides storage.
97
+ * Added to DatabaseAdapter as an optional repository.
98
+ *
99
+ * If not provided, only static defaults from module config are used.
100
+ */
101
+ interface FeatureFlagsRepository {
102
+ /**
103
+ * Get all overrides matching the criteria.
104
+ * Returns overrides from the database (global, tenant, or user level).
105
+ */
106
+ getOverrides(options: {
107
+ /** Filter by level */
108
+ level?: FlagLevel;
109
+ /** Filter by target ID (tenantId or userId) */
110
+ targetId?: string;
111
+ /** Filter by flag names (for efficient single/batch lookups) */
112
+ flagNames?: string[];
113
+ }): Promise<FlagOverride[]>;
114
+ /**
115
+ * Create or update an override.
116
+ * Uses upsert semantics based on (flagName, level, targetId).
117
+ */
118
+ setOverride(override: Omit<FlagOverride, "createdAt" | "updatedAt">): Promise<FlagOverride>;
119
+ /**
120
+ * Delete an override.
121
+ */
122
+ deleteOverride(flagName: string, level: FlagLevel, targetId?: string): Promise<void>;
123
+ }
124
+ /**
125
+ * Static flag default value for module configuration.
126
+ */
127
+ interface StaticFlagDefault {
128
+ /** Flag name */
129
+ name: string;
130
+ /** Default value */
131
+ value: unknown;
132
+ }
133
+ /**
134
+ * Feature flags configuration for SchemaModule.
135
+ */
136
+ interface FeatureFlagsConfig {
137
+ /**
138
+ * Static default values for flags.
139
+ * These are always applied and used when no database override exists.
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * featureFlags: {
144
+ * defaults: [
145
+ * { name: "architect-mode", value: false },
146
+ * { name: "ai-chat", value: false },
147
+ * { name: "tier", value: "free" },
148
+ * ],
149
+ * }
150
+ * ```
151
+ */
152
+ defaults?: StaticFlagDefault[];
153
+ }
154
+
155
+ /**
156
+ * Allowed attribute types in .qualifyWith()
157
+ *
158
+ * IMPORTANT: Complex types (formula, rollup, relation, file, user, document, richtext)
159
+ * are NOT supported to avoid duplicating backend behavior.
160
+ */
161
+ type PropertyType = "text" | "textarea" | "number" | "checkbox" | "date" | "phone" | "currency" | "status" | "select" | "multiselect" | "rating" | "location";
162
+ /**
163
+ * Forbidden property types that would require complex backend duplication
164
+ */
165
+ declare const FORBIDDEN_PROPERTY_TYPES: readonly ["formula", "rollup", "relation", "file", "user", "document", "richtext"];
166
+ type ForbiddenPropertyType = (typeof FORBIDDEN_PROPERTY_TYPES)[number];
167
+ /**
168
+ * Union of attribute types allowed as qualified relation properties.
169
+ *
170
+ * These are the same Attribute types used for object attributes,
171
+ * restricted to simple types that don't require complex backend duplication.
172
+ */
173
+ type PropertyAttribute = TextAttribute | TextAreaAttribute | NumberAttribute | CheckboxAttribute | DateAttribute | PhoneAttribute | CurrencyAttribute | StatusAttribute | SelectAttribute | MultiselectAttribute | RatingAttribute | LocationAttribute;
174
+ /**
175
+ * Schema defining properties for a qualified relation.
176
+ *
177
+ * Uses the same Attribute types as object attributes, enabling DRY builders:
178
+ *
179
+ * @example
180
+ * ```typescript
181
+ * relation({ name: "companies", label: "Companies" })
182
+ * .to("companies").many()
183
+ * .qualifyWith(
184
+ * select({ name: "role", label: "Role" }).options([...]).required(),
185
+ * number({ name: "shares", label: "Shares" }).min(0),
186
+ * )
187
+ * ```
188
+ */
189
+ interface PropertySchema {
190
+ definitions: PropertyAttribute[];
191
+ }
192
+ /**
193
+ * Property attribute types that have an `options` array.
194
+ */
195
+ type OptionPropertyAttribute = SelectAttribute | StatusAttribute | MultiselectAttribute;
196
+ /**
197
+ * Type guard to check if a property attribute has options.
198
+ *
199
+ * @param attr - The property attribute to check
200
+ * @returns true if the attribute is a select, status, or multiselect type with options
201
+ *
202
+ * @example
203
+ * ```typescript
204
+ * for (const def of definitions) {
205
+ * if (hasOptions(def)) {
206
+ * // TypeScript knows def.options exists and is Option[]
207
+ * for (const option of def.options) {
208
+ * console.log(option.value);
209
+ * }
210
+ * }
211
+ * }
212
+ * ```
213
+ */
214
+ declare function hasOptions(attr: PropertyAttribute): attr is OptionPropertyAttribute;
215
+
216
+ type AttributeType = "text" | "textarea" | "richtext" | "number" | "checkbox" | "date" | "phone" | "currency" | "status" | "location" | "select" | "multiselect" | "file" | "user" | "relation" | "rating" | "formula" | "rollup" | "document";
217
+ /**
218
+ * Status group categorization
219
+ */
220
+ type StatusGroup = "idle" | "in_progress" | "finished";
221
+ /**
222
+ * Unified option type for select-like fields
223
+ */
224
+ interface Option {
225
+ id: string;
226
+ label: string;
227
+ value: string;
228
+ color?: ColorId;
229
+ icon?: IconName;
230
+ description?: string;
231
+ group?: StatusGroup;
232
+ /** Value of the inverse option for bilateral relations (e.g. "parent" → "child") */
233
+ inverse?: string;
234
+ }
235
+ /**
236
+ * Attribute grouping for UI organization
237
+ */
238
+ interface AttributeGroup {
239
+ id: string;
240
+ label: string;
241
+ description?: string;
242
+ attributeIds: string[];
243
+ collapsible?: boolean;
244
+ collapsed?: boolean;
245
+ order?: number;
246
+ }
247
+ interface BaseAttribute<DefaultValueType = unknown> {
248
+ id: Uuid;
249
+ name: string;
250
+ label: string;
251
+ type: AttributeType;
252
+ required: boolean;
253
+ disabled?: boolean;
254
+ placeholder?: string;
255
+ description?: string;
256
+ defaultValue?: DefaultValueType;
257
+ icon?: IconName;
258
+ order?: number;
259
+ hidden?: boolean;
260
+ archived?: boolean;
261
+ deprecated?: boolean;
262
+ system?: boolean;
263
+ /**
264
+ * Feature gate to conditionally show/hide/disable this attribute.
265
+ * When the flag condition is not met, the attribute behavior depends on `fallback`:
266
+ * - "hide" (default): Attribute is completely hidden
267
+ * - "disable": Attribute is visible but read-only
268
+ * - "show": No gating (useful for overriding parent settings)
269
+ */
270
+ featureGate?: FeatureGate;
271
+ metadata?: Record<string, unknown>;
272
+ }
273
+ interface TextAttribute extends BaseAttribute<string> {
274
+ type: "text";
275
+ minLength?: number;
276
+ maxLength?: number;
277
+ pattern?: string;
278
+ }
279
+ type NumberUnit = "integer" | "decimal" | "percentage";
280
+ interface NumberAttribute extends BaseAttribute<number> {
281
+ type: "number";
282
+ min?: number;
283
+ max?: number;
284
+ unit?: NumberUnit;
285
+ decimals?: number;
286
+ }
287
+ interface CheckboxAttribute extends BaseAttribute<boolean> {
288
+ type: "checkbox";
289
+ }
290
+ type DateFormat = "short" | "long" | "full" | "relative";
291
+ type DateValue = string | "today";
292
+ interface DateAttribute extends BaseAttribute<string> {
293
+ type: "date";
294
+ dateFormat?: DateFormat;
295
+ minDate?: DateValue;
296
+ maxDate?: DateValue;
297
+ }
298
+ interface Phone {
299
+ countryCode: CountryIso3;
300
+ phoneNumber: string;
301
+ }
302
+ interface PhoneAttribute extends BaseAttribute<Phone> {
303
+ type: "phone";
304
+ defaultCountryCode?: CountryIso3;
305
+ }
306
+ interface Currency {
307
+ code: CurrencyCode;
308
+ value: number;
309
+ }
310
+ interface CurrencyAttribute extends BaseAttribute<Currency> {
311
+ type: "currency";
312
+ defaultCurrency?: CurrencyCode;
313
+ allowedCurrencies?: CurrencyCode[];
314
+ }
315
+ /**
316
+ * StatusAttribute - For workflow states with semantic grouping (idle/in_progress/finished)
317
+ * Use this for: Task status, Order status, Project phases, Process states
318
+ * Use SelectAttribute for: Categories, Types, simple choices without workflow
319
+ */
320
+ interface StatusAttribute extends BaseAttribute<string> {
321
+ type: "status";
322
+ options: Option[];
323
+ }
324
+ interface Location {
325
+ address?: string;
326
+ address2?: string;
327
+ city?: string;
328
+ state?: string;
329
+ postalCode?: string;
330
+ country?: CountryIso3;
331
+ latitude?: number;
332
+ longitude?: number;
333
+ }
334
+ type LocationGranularity = "full" | "address" | "city" | "state" | "country" | "coordinates";
335
+ interface LocationAttribute extends BaseAttribute<Location> {
336
+ type: "location";
337
+ granularity: LocationGranularity;
338
+ enableAutocomplete?: boolean;
339
+ enableMap?: boolean;
340
+ defaultCountry?: CountryIso3;
341
+ allowedCountries?: CountryIso3[];
342
+ displayFormat?: "single_line" | "multi_line" | "compact";
343
+ }
344
+ /**
345
+ * SelectAttribute - For simple single-choice selection
346
+ * Use this for: Categories, Document types, Departments, Priorities
347
+ * Options can be grouped (e.g., countries by continent) but no workflow logic
348
+ */
349
+ interface SelectAttribute extends BaseAttribute<string> {
350
+ type: "select";
351
+ options: Option[];
352
+ }
353
+ interface MultiselectAttribute extends BaseAttribute<string[]> {
354
+ type: "multiselect";
355
+ options: Option[];
356
+ }
357
+ interface FileAttribute extends BaseAttribute<string> {
358
+ type: "file";
359
+ maxFiles?: number;
360
+ maxSize?: number;
361
+ allowedTypes?: MimeType[] | readonly MimeType[];
362
+ multiple?: boolean;
363
+ }
364
+ interface UserAttribute extends BaseAttribute<string> {
365
+ type: "user";
366
+ allowedRoles?: string[];
367
+ multiple?: boolean;
368
+ }
369
+ /**
370
+ * Wildcard marker for universal relations (can link to any object)
371
+ * Use with `.toAny()` builder method
372
+ */
373
+ declare const RELATION_TARGET_ANY: "*";
374
+ /**
375
+ * Configuration for bilateral synchronization (bidirectional relations)
376
+ */
377
+ interface BilateralConfig {
378
+ /** Target object containing the inverse attribute */
379
+ object: string;
380
+ /** Name of the inverse attribute */
381
+ attribute: string;
382
+ /** Optional cardinality override (inferred by default) */
383
+ cardinality?: "one" | "many";
384
+ /** When true, this side owns the storage direction for qualified properties.
385
+ * Set to false on the inverse side (enriched at read time). */
386
+ storageOwner?: boolean;
387
+ }
388
+ /**
389
+ * Target object for a relation - defines which objects can be linked
390
+ */
391
+ interface RelationTarget {
392
+ /** Object name (e.g., "companies", "contacts") or "*" for any object */
393
+ object: string;
394
+ /**
395
+ * Display template for the label using mustache-like syntax
396
+ * @example "{name}" or "{firstName} {lastName} — {email}"
397
+ */
398
+ displayTemplate?: string;
399
+ /**
400
+ * Optional filter to restrict available records
401
+ * @example { status: "active" }
402
+ */
403
+ filter?: Record<string, unknown>;
404
+ }
405
+ /**
406
+ * Base properties shared by both single and multi relation attributes
407
+ *
408
+ * Note: Deletion behavior is always "restrict" - if a record is referenced
409
+ * by other records, it cannot be deleted until those references are removed.
410
+ * This is enforced by RecordService.deleteRecord() which throws
411
+ * RecordReferencedError when attempting to delete a referenced record.
412
+ */
413
+ interface RelationAttributeBase extends Omit<BaseAttribute<unknown>, "defaultValue"> {
414
+ type: "relation";
415
+ /** Target objects that can be linked */
416
+ targets: RelationTarget[];
417
+ /** Optional properties schema for qualified relations */
418
+ properties?: PropertySchema;
419
+ /** Configuration for bilateral synchronization (opt-in) */
420
+ bilateral?: BilateralConfig;
421
+ }
422
+ /**
423
+ * Single relation attribute (one-to-one or many-to-one)
424
+ * Stores a single record ID or null
425
+ */
426
+ interface SingleRelationAttribute extends RelationAttributeBase {
427
+ cardinality: "one";
428
+ defaultValue?: string | null;
429
+ }
430
+ /**
431
+ * Multi relation attribute (one-to-many or many-to-many)
432
+ * Stores an array of record IDs
433
+ */
434
+ interface MultiRelationAttribute extends RelationAttributeBase {
435
+ cardinality: "many";
436
+ defaultValue?: string[];
437
+ /** Minimum number of relations required */
438
+ minItems?: number;
439
+ /** Maximum number of relations allowed */
440
+ maxItems?: number;
441
+ }
442
+ /**
443
+ * RelationAttribute links to other objects/records
444
+ * Discriminated union by cardinality for type-safe value handling
445
+ *
446
+ * @example Single relation (many-to-one)
447
+ * ```typescript
448
+ * relation({ name: "company", label: "Company" })
449
+ * .to("companies")
450
+ * .required()
451
+ * // → Value: "rec-uuid-123" | null
452
+ * ```
453
+ *
454
+ * @example Multi relation (many-to-many)
455
+ * ```typescript
456
+ * relation({ name: "contacts", label: "Contacts" })
457
+ * .to("contacts", { displayTemplate: "{firstName} {lastName}" })
458
+ * .many()
459
+ * .maxItems(5)
460
+ * // → Value: ["rec-1", "rec-2", ...]
461
+ * ```
462
+ *
463
+ * @example Polymorphic relation (multiple target objects)
464
+ * ```typescript
465
+ * relation({ name: "linked", label: "Linked Items" })
466
+ * .to("companies")
467
+ * .to("contacts")
468
+ * .to("deals")
469
+ * .many()
470
+ * // → Can link to records from any of these objects
471
+ * ```
472
+ */
473
+ type RelationAttribute = SingleRelationAttribute | MultiRelationAttribute;
474
+ /**
475
+ * Check if a relation attribute is universal (can link to any object)
476
+ * Universal relations have `targets: [{ object: "*" }]`
477
+ */
478
+ declare function isUniversalRelation(attr: RelationAttribute): boolean;
479
+ /**
480
+ * Check if a relation attribute has bilateral synchronization enabled
481
+ */
482
+ declare function isBilateralRelation(attr: RelationAttribute): attr is RelationAttribute & {
483
+ bilateral: BilateralConfig;
484
+ };
485
+ /**
486
+ * Infer the cardinality of the inverse relation
487
+ * - one → many (contact.company ↔ company.contacts)
488
+ * - many → many (contact.tags ↔ tag.contacts)
489
+ */
490
+ declare function inferInverseCardinality(cardinality: "one" | "many"): "one" | "many";
491
+ interface TextAreaAttribute extends BaseAttribute<string> {
492
+ type: "textarea";
493
+ }
494
+ /**
495
+ * Available features for richtext editor
496
+ */
497
+ type RichtextFeature = "headings" | "bold" | "italic" | "lists" | "links" | "images" | "codeBlocks" | "tables";
498
+ /**
499
+ * RichtextAttribute - Rich text content using semantic markdown
500
+ *
501
+ * Stores content as semantic markdown string (with directives like :::callout).
502
+ * Parsed at runtime to Tiptap JSON for editing.
503
+ * Use this for: Notes, articles, descriptions, long-form content.
504
+ *
505
+ * @example
506
+ * ```typescript
507
+ * richtext({ name: "content", label: "Content" })
508
+ * .features(["headings", "bold", "italic", "lists", "links"])
509
+ * .required()
510
+ * ```
511
+ */
512
+ interface RichtextAttribute extends BaseAttribute<string> {
513
+ type: "richtext";
514
+ /** Enabled features. If undefined, all features are enabled. */
515
+ features?: RichtextFeature[];
516
+ }
517
+ interface RatingAttribute extends BaseAttribute<number> {
518
+ type: "rating";
519
+ max?: number;
520
+ iconType?: "star" | "heart" | "thumbs" | "number";
521
+ }
522
+ /**
523
+ * Return type for formula expressions
524
+ */
525
+ type FormulaReturnType = "text" | "number" | "boolean" | "date";
526
+ /**
527
+ * FormulaAttribute - Computed value based on other attributes
528
+ *
529
+ * Formulas are calculated at read-time and are always read-only.
530
+ * Users cannot directly edit formula values.
531
+ *
532
+ * @example Simple calculation
533
+ * ```typescript
534
+ * formula({ name: "total", label: "Total" })
535
+ * .expression("price * quantity")
536
+ * .returns("number")
537
+ * .decimals(2)
538
+ * ```
539
+ *
540
+ * @example With functions
541
+ * ```typescript
542
+ * formula({ name: "fullName", label: "Full Name" })
543
+ * .expression("CONCAT(firstName, ' ', lastName)")
544
+ * .returns("text")
545
+ * ```
546
+ */
547
+ interface FormulaAttribute extends Omit<BaseAttribute<never>, "defaultValue" | "required"> {
548
+ type: "formula";
549
+ /** Expression to evaluate (e.g., "price * quantity") */
550
+ expression: string;
551
+ /** Expected return type for formatting */
552
+ returnType: FormulaReturnType;
553
+ /** Decimal places for number results */
554
+ decimals?: number;
555
+ /** Whether to allow relation references in the expression (e.g., "company.name") */
556
+ allowRelations?: boolean;
557
+ /** Formula is always not required (read-only) */
558
+ required: false;
559
+ }
560
+ /**
561
+ * Aggregation functions for rollup attributes
562
+ *
563
+ * Categories:
564
+ * - Numeric (sum, avg): Only for number, currency, rating types
565
+ * - Date (earliest, latest): Only for date type
566
+ * - Count (count, countValues, countUniqueValues, countEmpty): Universal
567
+ * - Percent (percentEmpty, percentNotEmpty): Universal
568
+ * - Lookup (original): Returns all values as array, rendered as target type
569
+ */
570
+ type RollupFunction = "sum" | "avg" | "earliest" | "latest" | "count" | "countValues" | "countUniqueValues" | "countEmpty" | "percentEmpty" | "percentNotEmpty" | "original";
571
+ /**
572
+ * RollupAttribute - Aggregates values from related records
573
+ *
574
+ * Rollups are calculated and stored (denormalized) for performance.
575
+ * They are automatically recalculated when related records change.
576
+ * Users cannot directly edit rollup values.
577
+ *
578
+ * @example Sum of related amounts
579
+ * ```typescript
580
+ * rollup({ name: "totalOrders", label: "Total Orders" })
581
+ * .from("orders") // relation attribute name
582
+ * .aggregate("amount") // target attribute to sum
583
+ * .using("sum")
584
+ * .decimals(2)
585
+ * ```
586
+ *
587
+ * @example Count of related records
588
+ * ```typescript
589
+ * rollup({ name: "orderCount", label: "Number of Orders" })
590
+ * .from("orders")
591
+ * .using("count")
592
+ * ```
593
+ */
594
+ interface RollupAttribute extends Omit<BaseAttribute<never>, "defaultValue" | "required"> {
595
+ type: "rollup";
596
+ /** Name of the relation attribute on this object */
597
+ relationAttribute: string;
598
+ /**
599
+ * Dot notation path for multi-level traversal (Phase 4+)
600
+ * @example "orders.items" - traverse through orders to items
601
+ */
602
+ relationPath?: string;
603
+ /** Attribute name on the target object to aggregate */
604
+ targetAttribute: string;
605
+ /** Aggregation function to apply */
606
+ function: RollupFunction;
607
+ /** Decimal places for numeric results */
608
+ decimals?: number;
609
+ /** Rollup is always not required (read-only) */
610
+ required: false;
611
+ /**
612
+ * Cached type of the target attribute for display purposes
613
+ * Used when function="original" to render values as the target type
614
+ */
615
+ targetAttributeType?: AttributeType;
616
+ /**
617
+ * Cached options from target attribute (for select/status/multiselect display)
618
+ * Required when function="original" and target is a select-like type
619
+ */
620
+ targetAttributeOptions?: Option[];
621
+ }
622
+ /**
623
+ * DocumentAttribute - References one or multiple structured documents.
624
+ *
625
+ * Unlike FileAttribute which stores raw file references, DocumentAttribute
626
+ * provides structured document handling with multi-file support and
627
+ * optional agent-compatible processing (for example OCR).
628
+ *
629
+ * @example Single document
630
+ * ```typescript
631
+ * document({ name: "identityDocument", label: "Pièce d'identité" })
632
+ * .autoProcess()
633
+ * .required()
634
+ * ```
635
+ *
636
+ * @example Multiple documents
637
+ * ```typescript
638
+ * document({ name: "contracts", label: "Contrats" })
639
+ * .multiple()
640
+ * .maxDocuments(10)
641
+ * ```
642
+ */
643
+ interface DocumentAttribute extends BaseAttribute<string | string[]> {
644
+ type: "document";
645
+ /**
646
+ * Allow multiple documents.
647
+ * If true, value is string[] (document IDs).
648
+ * If false/undefined, value is string (single document ID).
649
+ */
650
+ multiple?: boolean;
651
+ /**
652
+ * Maximum number of documents when multiple: true.
653
+ */
654
+ maxDocuments?: number;
655
+ /**
656
+ * Automatically trigger agent-compatible processing on upload.
657
+ */
658
+ autoProcess?: boolean;
659
+ }
660
+ type Attribute = TextAttribute | TextAreaAttribute | RichtextAttribute | NumberAttribute | CheckboxAttribute | DateAttribute | PhoneAttribute | CurrencyAttribute | StatusAttribute | LocationAttribute | SelectAttribute | MultiselectAttribute | FileAttribute | UserAttribute | RelationAttribute | RatingAttribute | FormulaAttribute | RollupAttribute | DocumentAttribute;
661
+ /**
662
+ * Attribute types that are not sortable by default.
663
+ * These types have complex/binary values without a meaningful natural order.
664
+ */
665
+ declare const NON_SORTABLE_TYPES: ReadonlySet<AttributeType>;
666
+ /**
667
+ * Check if an attribute supports sorting based on its type.
668
+ */
669
+ declare function isAttributeSortable(attr: {
670
+ type: AttributeType;
671
+ }): boolean;
672
+
673
+ export { type PropertyType as $, type Attribute as A, type BilateralConfig as B, type CurrencyAttribute as C, type DateAttribute as D, type AttributeGroup as E, type FileAttribute as F, type BaseAttribute as G, type DateFormat as H, type DateValue as I, FORBIDDEN_PROPERTY_TYPES as J, type FeatureFlagsConfig as K, type LocationAttribute as L, type MultiRelationAttribute as M, type NumberAttribute as N, type Option as O, type PhoneAttribute as P, type FlagOverride as Q, type RelationAttribute as R, type SingleRelationAttribute as S, type TextAreaAttribute as T, type UserAttribute as U, type ForbiddenPropertyType as V, NON_SORTABLE_TYPES as W, type NumberUnit as X, type OptionPropertyAttribute as Y, type PropertyAttribute as Z, type PropertySchema as _, type RichtextAttribute as a, RELATION_TARGET_ANY as a0, type StatusGroup as a1, hasOptions as a2, inferInverseCardinality as a3, isAttributeSortable as a4, isBilateralRelation as a5, isUniversalRelation as a6, type MultiselectAttribute as b, type SelectAttribute as c, type StatusAttribute as d, type FormulaAttribute as e, type RollupAttribute as f, type CheckboxAttribute as g, type RatingAttribute as h, type TextAttribute as i, type AttributeType as j, type LocationGranularity as k, type Location as l, type Phone as m, type Currency as n, type DocumentAttribute as o, type FeatureGate as p, type RichtextFeature as q, type RelationTarget as r, type FormulaReturnType as s, type RollupFunction as t, type FlagValueType as u, type FeatureFlagDefinition as v, type FlagLevel as w, type FeatureFlagsRepository as x, type StaticFlagDefault as y, type ResolvedFlag as z };