@stndrds/schema 0.1.0-alpha.56 → 0.1.0-alpha.58

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.
@@ -0,0 +1,1488 @@
1
+ import { z } from 'zod';
2
+ import { ColorId, IconName, CountryIso3, CurrencyCode, MimeType } from '@stndrds/constants';
3
+ import { Uuid } from './utils.mjs';
4
+
5
+ /**
6
+ * Feature flag levels (resolution priority: user > tenant > global).
7
+ *
8
+ * - `global`: Applies to all tenants and users
9
+ * - `tenant`: Applies to a specific tenant
10
+ * - `user`: Applies to a specific user within a tenant
11
+ */
12
+ type FlagLevel = "global" | "tenant" | "user";
13
+ /**
14
+ * Flag value types supported by the system.
15
+ */
16
+ type FlagValueType = "boolean" | "string" | "number" | "json";
17
+ /**
18
+ * Definition of a feature flag.
19
+ * Created using the flag builders (booleanFlag, stringFlag, etc.)
20
+ */
21
+ interface FeatureFlagDefinition<T = unknown> {
22
+ /** Unique identifier for the flag (kebab-case) */
23
+ name: string;
24
+ /** Human-readable label */
25
+ label: string;
26
+ /** Optional description */
27
+ description?: string;
28
+ /** Type of the flag value */
29
+ valueType: FlagValueType;
30
+ /** Default value when no override exists */
31
+ defaultValue: T;
32
+ /** Levels at which this flag can be overridden */
33
+ allowedLevels: FlagLevel[];
34
+ /** Grouping category for UI */
35
+ category?: string;
36
+ /** System flag - cannot be modified via API */
37
+ system?: boolean;
38
+ }
39
+ /**
40
+ * Stored override for a feature flag.
41
+ * Represents a row in the feature_flag_overrides table.
42
+ */
43
+ interface FlagOverride<T = unknown> {
44
+ /** Name of the flag being overridden */
45
+ flagName: string;
46
+ /** Level of the override */
47
+ level: FlagLevel;
48
+ /** Target ID (tenantId for tenant-level, userId for user-level) */
49
+ targetId?: string;
50
+ /** Override value */
51
+ value: T;
52
+ /** Optional expiration date */
53
+ expiresAt?: Date;
54
+ /** Who created this override */
55
+ createdBy?: string;
56
+ /** When the override was created */
57
+ createdAt: Date;
58
+ /** When the override was last updated */
59
+ updatedAt: Date;
60
+ }
61
+ /**
62
+ * Resolved flag value with source information.
63
+ * Result of flag resolution including where the value came from.
64
+ */
65
+ interface ResolvedFlag<T = unknown> {
66
+ /** Flag name */
67
+ name: string;
68
+ /** Resolved value */
69
+ value: T;
70
+ /** Where the value came from */
71
+ source: FlagLevel | "default";
72
+ /** ID of the source (tenantId or userId) if not default */
73
+ sourceId?: string;
74
+ }
75
+ /**
76
+ * Feature gate configuration for conditional attribute visibility.
77
+ * Used with the `.featureGate()` builder method.
78
+ */
79
+ interface FeatureGate {
80
+ /** Name of the flag to check */
81
+ flag: string;
82
+ /**
83
+ * Expected value for the gate to pass.
84
+ * For boolean flags, defaults to `true`.
85
+ * For other types, compares with strict equality.
86
+ */
87
+ expectedValue?: unknown;
88
+ /**
89
+ * Behavior when the gate fails.
90
+ * - `hide`: Attribute is completely hidden (default)
91
+ * - `show`: Attribute is shown regardless (no gating)
92
+ * - `disable`: Attribute is visible but read-only
93
+ */
94
+ fallback?: "hide" | "show" | "disable";
95
+ }
96
+ /**
97
+ * Repository interface for feature flag overrides storage.
98
+ * Added to DatabaseAdapter as an optional repository.
99
+ *
100
+ * If not provided, only static defaults from module config are used.
101
+ */
102
+ interface FeatureFlagsRepository {
103
+ /**
104
+ * Get all overrides matching the criteria.
105
+ * Returns overrides from the database (global, tenant, or user level).
106
+ */
107
+ getOverrides(options: {
108
+ /** Filter by level */
109
+ level?: FlagLevel;
110
+ /** Filter by target ID (tenantId or userId) */
111
+ targetId?: string;
112
+ }): Promise<FlagOverride[]>;
113
+ /**
114
+ * Create or update an override.
115
+ * Uses upsert semantics based on (flagName, level, targetId).
116
+ */
117
+ setOverride(override: Omit<FlagOverride, "createdAt" | "updatedAt">): Promise<FlagOverride>;
118
+ /**
119
+ * Delete an override.
120
+ */
121
+ deleteOverride(flagName: string, level: FlagLevel, targetId?: string): Promise<void>;
122
+ }
123
+ /**
124
+ * Static flag default value for module configuration.
125
+ */
126
+ interface StaticFlagDefault {
127
+ /** Flag name */
128
+ name: string;
129
+ /** Default value */
130
+ value: unknown;
131
+ }
132
+ /**
133
+ * Feature flags configuration for SchemaModule.
134
+ */
135
+ interface FeatureFlagsConfig {
136
+ /**
137
+ * Static default values for flags.
138
+ * These are always applied and used when no database override exists.
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * featureFlags: {
143
+ * defaults: [
144
+ * { name: "architect-mode", value: false },
145
+ * { name: "ai-chat", value: false },
146
+ * { name: "tier", value: "free" },
147
+ * ],
148
+ * }
149
+ * ```
150
+ */
151
+ defaults?: StaticFlagDefault[];
152
+ }
153
+
154
+ type AttributeType = "text" | "textarea" | "richtext" | "number" | "checkbox" | "date" | "phone" | "currency" | "status" | "location" | "select" | "multiselect" | "file" | "user" | "relation" | "rating" | "formula" | "rollup" | "document";
155
+ /**
156
+ * Status group categorization
157
+ */
158
+ type StatusGroup = "idle" | "in_progress" | "finished";
159
+ /**
160
+ * Unified option type for select-like fields
161
+ */
162
+ interface Option {
163
+ id: string;
164
+ label: string;
165
+ value: string;
166
+ color?: ColorId;
167
+ icon?: IconName;
168
+ description?: string;
169
+ group?: StatusGroup;
170
+ }
171
+ /**
172
+ * Attribute grouping for UI organization
173
+ */
174
+ interface AttributeGroup {
175
+ id: string;
176
+ label: string;
177
+ description?: string;
178
+ attributeIds: string[];
179
+ collapsible?: boolean;
180
+ collapsed?: boolean;
181
+ order?: number;
182
+ }
183
+ interface BaseAttribute<DefaultValueType = unknown> {
184
+ id: Uuid;
185
+ name: string;
186
+ label: string;
187
+ type: AttributeType;
188
+ required: boolean;
189
+ disabled?: boolean;
190
+ placeholder?: string;
191
+ description?: string;
192
+ defaultValue?: DefaultValueType;
193
+ icon?: IconName;
194
+ order?: number;
195
+ hidden?: boolean;
196
+ archived?: boolean;
197
+ deprecated?: boolean;
198
+ system?: boolean;
199
+ /**
200
+ * Feature gate to conditionally show/hide/disable this attribute.
201
+ * When the flag condition is not met, the attribute behavior depends on `fallback`:
202
+ * - "hide" (default): Attribute is completely hidden
203
+ * - "disable": Attribute is visible but read-only
204
+ * - "show": No gating (useful for overriding parent settings)
205
+ */
206
+ featureGate?: FeatureGate;
207
+ metadata?: Record<string, unknown>;
208
+ }
209
+ interface TextAttribute extends BaseAttribute<string> {
210
+ type: "text";
211
+ minLength?: number;
212
+ maxLength?: number;
213
+ pattern?: string;
214
+ }
215
+ type NumberUnit = "integer" | "decimal" | "percentage";
216
+ interface NumberAttribute extends BaseAttribute<number> {
217
+ type: "number";
218
+ min?: number;
219
+ max?: number;
220
+ unit?: NumberUnit;
221
+ decimals?: number;
222
+ }
223
+ interface CheckboxAttribute extends BaseAttribute<boolean> {
224
+ type: "checkbox";
225
+ }
226
+ type DateFormat = "short" | "long" | "full" | "relative";
227
+ type DateValue = string | "today";
228
+ interface DateAttribute extends BaseAttribute<string> {
229
+ type: "date";
230
+ dateFormat?: DateFormat;
231
+ minDate?: DateValue;
232
+ maxDate?: DateValue;
233
+ }
234
+ interface Phone {
235
+ countryCode: CountryIso3;
236
+ phoneNumber: string;
237
+ }
238
+ interface PhoneAttribute extends BaseAttribute<Phone> {
239
+ type: "phone";
240
+ defaultCountryCode?: CountryIso3;
241
+ }
242
+ interface Currency {
243
+ code: CurrencyCode;
244
+ value: number;
245
+ }
246
+ interface CurrencyAttribute extends BaseAttribute<Currency> {
247
+ type: "currency";
248
+ defaultCurrency?: CurrencyCode;
249
+ allowedCurrencies?: CurrencyCode[];
250
+ }
251
+ /**
252
+ * StatusAttribute - For workflow states with semantic grouping (idle/in_progress/finished)
253
+ * Use this for: Task status, Order status, Project phases, Process states
254
+ * Use SelectAttribute for: Categories, Types, simple choices without workflow
255
+ */
256
+ interface StatusAttribute extends BaseAttribute<string> {
257
+ type: "status";
258
+ options: Option[];
259
+ }
260
+ interface Location {
261
+ address?: string;
262
+ address2?: string;
263
+ city?: string;
264
+ state?: string;
265
+ postalCode?: string;
266
+ country?: CountryIso3;
267
+ latitude?: number;
268
+ longitude?: number;
269
+ }
270
+ type LocationGranularity = "full" | "address" | "city" | "state" | "country" | "coordinates";
271
+ interface LocationAttribute extends BaseAttribute<Location> {
272
+ type: "location";
273
+ granularity: LocationGranularity;
274
+ enableAutocomplete?: boolean;
275
+ enableMap?: boolean;
276
+ defaultCountry?: CountryIso3;
277
+ allowedCountries?: CountryIso3[];
278
+ displayFormat?: "single_line" | "multi_line" | "compact";
279
+ }
280
+ /**
281
+ * SelectAttribute - For simple single-choice selection
282
+ * Use this for: Categories, Document types, Departments, Priorities
283
+ * Options can be grouped (e.g., countries by continent) but no workflow logic
284
+ */
285
+ interface SelectAttribute extends BaseAttribute<string> {
286
+ type: "select";
287
+ options: Option[];
288
+ }
289
+ interface MultiselectAttribute extends BaseAttribute<string[]> {
290
+ type: "multiselect";
291
+ options: Option[];
292
+ }
293
+ interface FileAttribute extends BaseAttribute<string> {
294
+ type: "file";
295
+ maxFiles?: number;
296
+ maxSize?: number;
297
+ allowedTypes?: MimeType[] | readonly MimeType[];
298
+ multiple?: boolean;
299
+ }
300
+ interface UserAttribute extends BaseAttribute<string> {
301
+ type: "user";
302
+ allowedRoles?: string[];
303
+ multiple?: boolean;
304
+ }
305
+ /**
306
+ * Wildcard marker for universal relations (can link to any object)
307
+ * Use with `.toAny()` builder method
308
+ */
309
+ declare const RELATION_TARGET_ANY: "*";
310
+ /**
311
+ * Target object for a relation - defines which objects can be linked
312
+ */
313
+ interface RelationTarget {
314
+ /** Object name (e.g., "companies", "contacts") or "*" for any object */
315
+ object: string;
316
+ /**
317
+ * Display template for the label using mustache-like syntax
318
+ * @example "{name}" or "{firstName} {lastName} — {email}"
319
+ */
320
+ displayTemplate?: string;
321
+ /**
322
+ * Optional filter to restrict available records
323
+ * @example { status: "active" }
324
+ */
325
+ filter?: Record<string, unknown>;
326
+ }
327
+ /**
328
+ * Base properties shared by both single and multi relation attributes
329
+ *
330
+ * Note: Deletion behavior is always "restrict" - if a record is referenced
331
+ * by other records, it cannot be deleted until those references are removed.
332
+ * This is enforced by RecordService.deleteRecord() which throws
333
+ * RecordReferencedError when attempting to delete a referenced record.
334
+ */
335
+ interface RelationAttributeBase extends Omit<BaseAttribute<unknown>, "defaultValue"> {
336
+ type: "relation";
337
+ /** Target objects that can be linked */
338
+ targets: RelationTarget[];
339
+ }
340
+ /**
341
+ * Single relation attribute (one-to-one or many-to-one)
342
+ * Stores a single record ID or null
343
+ */
344
+ interface SingleRelationAttribute extends RelationAttributeBase {
345
+ cardinality: "one";
346
+ defaultValue?: string | null;
347
+ }
348
+ /**
349
+ * Multi relation attribute (one-to-many or many-to-many)
350
+ * Stores an array of record IDs
351
+ */
352
+ interface MultiRelationAttribute extends RelationAttributeBase {
353
+ cardinality: "many";
354
+ defaultValue?: string[];
355
+ /** Minimum number of relations required */
356
+ minItems?: number;
357
+ /** Maximum number of relations allowed */
358
+ maxItems?: number;
359
+ }
360
+ /**
361
+ * RelationAttribute links to other objects/records
362
+ * Discriminated union by cardinality for type-safe value handling
363
+ *
364
+ * @example Single relation (many-to-one)
365
+ * ```typescript
366
+ * relation({ name: "company", label: "Company" })
367
+ * .to("companies")
368
+ * .required()
369
+ * // → Value: "rec-uuid-123" | null
370
+ * ```
371
+ *
372
+ * @example Multi relation (many-to-many)
373
+ * ```typescript
374
+ * relation({ name: "contacts", label: "Contacts" })
375
+ * .to("contacts", { displayTemplate: "{firstName} {lastName}" })
376
+ * .many()
377
+ * .maxItems(5)
378
+ * // → Value: ["rec-1", "rec-2", ...]
379
+ * ```
380
+ *
381
+ * @example Polymorphic relation (multiple target objects)
382
+ * ```typescript
383
+ * relation({ name: "linked", label: "Linked Items" })
384
+ * .to("companies")
385
+ * .to("contacts")
386
+ * .to("deals")
387
+ * .many()
388
+ * // → Can link to records from any of these objects
389
+ * ```
390
+ */
391
+ type RelationAttribute = SingleRelationAttribute | MultiRelationAttribute;
392
+ /**
393
+ * Check if a relation attribute is universal (can link to any object)
394
+ * Universal relations have `targets: [{ object: "*" }]`
395
+ */
396
+ declare function isUniversalRelation(attr: RelationAttribute): boolean;
397
+ interface TextAreaAttribute extends BaseAttribute<string> {
398
+ type: "textarea";
399
+ }
400
+ /**
401
+ * Available features for richtext editor
402
+ */
403
+ type RichtextFeature = "headings" | "bold" | "italic" | "lists" | "links" | "images" | "codeBlocks" | "tables";
404
+ /**
405
+ * RichtextAttribute - Rich text content using semantic markdown
406
+ *
407
+ * Stores content as semantic markdown string (with directives like :::callout).
408
+ * Parsed at runtime to Tiptap JSON for editing.
409
+ * Use this for: Notes, articles, descriptions, long-form content.
410
+ *
411
+ * @example
412
+ * ```typescript
413
+ * richtext({ name: "content", label: "Content" })
414
+ * .features(["headings", "bold", "italic", "lists", "links"])
415
+ * .required()
416
+ * ```
417
+ */
418
+ interface RichtextAttribute extends BaseAttribute<string> {
419
+ type: "richtext";
420
+ /** Enabled features. If undefined, all features are enabled. */
421
+ features?: RichtextFeature[];
422
+ }
423
+ interface RatingAttribute extends BaseAttribute<number> {
424
+ type: "rating";
425
+ max?: number;
426
+ iconType?: "star" | "heart" | "thumbs" | "number";
427
+ }
428
+ /**
429
+ * Return type for formula expressions
430
+ */
431
+ type FormulaReturnType = "text" | "number" | "boolean" | "date";
432
+ /**
433
+ * FormulaAttribute - Computed value based on other attributes
434
+ *
435
+ * Formulas are calculated at read-time and are always read-only.
436
+ * Users cannot directly edit formula values.
437
+ *
438
+ * @example Simple calculation
439
+ * ```typescript
440
+ * formula({ name: "total", label: "Total" })
441
+ * .expression("price * quantity")
442
+ * .returns("number")
443
+ * .decimals(2)
444
+ * ```
445
+ *
446
+ * @example With functions
447
+ * ```typescript
448
+ * formula({ name: "fullName", label: "Full Name" })
449
+ * .expression("CONCAT(firstName, ' ', lastName)")
450
+ * .returns("text")
451
+ * ```
452
+ */
453
+ interface FormulaAttribute extends Omit<BaseAttribute<never>, "defaultValue" | "required"> {
454
+ type: "formula";
455
+ /** Expression to evaluate (e.g., "price * quantity") */
456
+ expression: string;
457
+ /** Expected return type for formatting */
458
+ returnType: FormulaReturnType;
459
+ /** Decimal places for number results */
460
+ decimals?: number;
461
+ /** Whether to allow relation references in the expression (e.g., "company.name") */
462
+ allowRelations?: boolean;
463
+ /** Formula is always not required (read-only) */
464
+ required: false;
465
+ }
466
+ /**
467
+ * Aggregation functions for rollup attributes
468
+ *
469
+ * Categories:
470
+ * - Numeric (sum, avg): Only for number, currency, rating types
471
+ * - Date (earliest, latest): Only for date type
472
+ * - Count (count, countValues, countUniqueValues, countEmpty): Universal
473
+ * - Percent (percentEmpty, percentNotEmpty): Universal
474
+ * - Lookup (original): Returns all values as array, rendered as target type
475
+ */
476
+ type RollupFunction = "sum" | "avg" | "earliest" | "latest" | "count" | "countValues" | "countUniqueValues" | "countEmpty" | "percentEmpty" | "percentNotEmpty" | "original";
477
+ /**
478
+ * RollupAttribute - Aggregates values from related records
479
+ *
480
+ * Rollups are calculated and stored (denormalized) for performance.
481
+ * They are automatically recalculated when related records change.
482
+ * Users cannot directly edit rollup values.
483
+ *
484
+ * @example Sum of related amounts
485
+ * ```typescript
486
+ * rollup({ name: "totalOrders", label: "Total Orders" })
487
+ * .from("orders") // relation attribute name
488
+ * .aggregate("amount") // target attribute to sum
489
+ * .using("sum")
490
+ * .decimals(2)
491
+ * ```
492
+ *
493
+ * @example Count of related records
494
+ * ```typescript
495
+ * rollup({ name: "orderCount", label: "Number of Orders" })
496
+ * .from("orders")
497
+ * .using("count")
498
+ * ```
499
+ */
500
+ interface RollupAttribute extends Omit<BaseAttribute<never>, "defaultValue" | "required"> {
501
+ type: "rollup";
502
+ /** Name of the relation attribute on this object */
503
+ relationAttribute: string;
504
+ /**
505
+ * Dot notation path for multi-level traversal (Phase 4+)
506
+ * @example "orders.items" - traverse through orders to items
507
+ */
508
+ relationPath?: string;
509
+ /** Attribute name on the target object to aggregate */
510
+ targetAttribute: string;
511
+ /** Aggregation function to apply */
512
+ function: RollupFunction;
513
+ /** Decimal places for numeric results */
514
+ decimals?: number;
515
+ /** Rollup is always not required (read-only) */
516
+ required: false;
517
+ /**
518
+ * Cached type of the target attribute for display purposes
519
+ * Used when function="original" to render values as the target type
520
+ */
521
+ targetAttributeType?: AttributeType;
522
+ /**
523
+ * Cached options from target attribute (for select/status/multiselect display)
524
+ * Required when function="original" and target is a select-like type
525
+ */
526
+ targetAttributeOptions?: Option[];
527
+ }
528
+ /**
529
+ * DocumentAttribute - References one or multiple documents with templates.
530
+ *
531
+ * Unlike FileAttribute which stores raw file references, DocumentAttribute
532
+ * provides structured document handling with templates, multi-file support,
533
+ * and automatic processing (OCR, signature, identity verification).
534
+ *
535
+ * @example Single document with template choice
536
+ * ```typescript
537
+ * document({ name: "identityDocument", label: "Pièce d'identité" })
538
+ * .templates(["french_id_card", "passport"])
539
+ * .autoProcess()
540
+ * .required()
541
+ * ```
542
+ *
543
+ * @example Multiple documents with fixed template
544
+ * ```typescript
545
+ * document({ name: "contracts", label: "Contrats" })
546
+ * .template("signable_contract")
547
+ * .multiple()
548
+ * .maxDocuments(10)
549
+ * ```
550
+ */
551
+ interface DocumentAttribute extends BaseAttribute<string | string[]> {
552
+ type: "document";
553
+ /**
554
+ * Single template ID (strict mode).
555
+ * If set, only documents using this template can be attached.
556
+ */
557
+ templateId?: string;
558
+ /**
559
+ * Multiple allowed template IDs.
560
+ * User can choose which template to use when uploading.
561
+ */
562
+ allowedTemplates?: string[];
563
+ /**
564
+ * Allow multiple documents.
565
+ * If true, value is string[] (document IDs).
566
+ * If false/undefined, value is string (single document ID).
567
+ */
568
+ multiple?: boolean;
569
+ /**
570
+ * Maximum number of documents when multiple: true.
571
+ */
572
+ maxDocuments?: number;
573
+ /**
574
+ * Automatically trigger processing (OCR, verification) on upload.
575
+ */
576
+ autoProcess?: boolean;
577
+ }
578
+ type Attribute = TextAttribute | TextAreaAttribute | RichtextAttribute | NumberAttribute | CheckboxAttribute | DateAttribute | PhoneAttribute | CurrencyAttribute | StatusAttribute | LocationAttribute | SelectAttribute | MultiselectAttribute | FileAttribute | UserAttribute | RelationAttribute | RatingAttribute | FormulaAttribute | RollupAttribute | DocumentAttribute;
579
+
580
+ /**
581
+ * Timestamps for tracking creation and updates
582
+ */
583
+ interface Timestamps {
584
+ createdAt: Date;
585
+ updatedAt: Date;
586
+ }
587
+ /**
588
+ * Sharing mode for multi-tenant object access.
589
+ *
590
+ * - `private`: Object is only visible to its owner tenant (default)
591
+ * - `shared`: Object is readable by all tenants, but only writable by the owner tenant
592
+ *
593
+ * Records inherit the sharing mode of their parent object.
594
+ */
595
+ type SharingMode = "private" | "shared";
596
+ /**
597
+ * Object definition - Represents a database table/entity
598
+ */
599
+ interface ObjectDefinition {
600
+ id?: Uuid;
601
+ name: string;
602
+ label: string;
603
+ pluralLabel?: string;
604
+ description?: string;
605
+ icon?: IconName;
606
+ /**
607
+ * Template expression used to compute the object's display label.
608
+ * Supports variable interpolation and pipes for formatting.
609
+ *
610
+ * @example
611
+ * ```typescript
612
+ * // Simple attribute reference
613
+ * labelExpression: "{{ name }}"
614
+ *
615
+ * // Multiple attributes
616
+ * labelExpression: "{{ firstName }} {{ lastName }}"
617
+ *
618
+ * // With pipes for formatting
619
+ * labelExpression: "{{ code | UPPER }} - {{ name | capitalize }}"
620
+ * ```
621
+ *
622
+ * Available pipes: UPPER, LOWER, capitalize, trim
623
+ */
624
+ labelExpression: string;
625
+ attributes: Attribute[];
626
+ system?: boolean;
627
+ /**
628
+ * Sharing mode for multi-tenant access.
629
+ * - `private`: Only visible to the owner tenant (default)
630
+ * - `shared`: Readable by all tenants, writable only by the owner
631
+ *
632
+ * Records inherit the sharing mode of their parent object.
633
+ * @default "private"
634
+ */
635
+ sharingMode?: SharingMode;
636
+ metadata?: Record<string, unknown>;
637
+ }
638
+ /**
639
+ * Links an attribute to an object
640
+ */
641
+ interface ObjectAttribute {
642
+ objectId: Uuid;
643
+ attributeId: Uuid;
644
+ order?: number;
645
+ required?: boolean;
646
+ }
647
+ /**
648
+ * Completion status of a record based on data completeness.
649
+ *
650
+ * - `draft`: Record is missing one or more required attribute values.
651
+ * Can be saved but is considered incomplete.
652
+ * - `complete`: All required attribute values are present and valid.
653
+ * Record is ready for use.
654
+ *
655
+ * This is different from workflow status (e.g., "pending", "approved").
656
+ * Completion status is computed dynamically based on the object schema.
657
+ */
658
+ type CompletionStatus = "draft" | "complete";
659
+ /**
660
+ * Record - Instance of an Object (a row in the database)
661
+ */
662
+ interface ObjectRecord extends Timestamps {
663
+ id: Uuid;
664
+ objectId: Uuid;
665
+ /**
666
+ * Display label computed from the object's labelExpression.
667
+ * Computed dynamically based on record values.
668
+ *
669
+ * @example "John Doe" (from "{{ firstName }} {{ lastName }}")
670
+ */
671
+ label: string;
672
+ /**
673
+ * Completion status of the record.
674
+ * - `draft`: Missing required values, record is incomplete
675
+ * - `complete`: All required values present and valid
676
+ *
677
+ * Computed dynamically based on the object's schema.
678
+ */
679
+ completionStatus: CompletionStatus;
680
+ values: Record<string, unknown>;
681
+ /**
682
+ * Custom metadata for the record.
683
+ * Use this for UI/UX state, feature flags, or any application-specific data.
684
+ * Unlike system fields (id, createdAt, updatedAt), metadata can be updated.
685
+ */
686
+ metadata?: Record<string, unknown>;
687
+ /**
688
+ * Soft delete timestamp.
689
+ * If set, the record is considered deleted but can be restored.
690
+ * Queries exclude soft-deleted records by default.
691
+ */
692
+ deletedAt?: Date | null;
693
+ /**
694
+ * User ID who created this record.
695
+ * Automatically set by RecordService when userId is configured.
696
+ * Optional for backward compatibility with existing records.
697
+ */
698
+ createdBy?: string;
699
+ /**
700
+ * User ID who last updated this record.
701
+ * Automatically set by RecordService when userId is configured.
702
+ * Optional for backward compatibility with existing records.
703
+ */
704
+ lastUpdatedBy?: string;
705
+ }
706
+ /**
707
+ * System-managed field names on ObjectRecord.
708
+ * These are stored as SQL columns (not in JSONB `values`).
709
+ *
710
+ * Use this in adapters to determine if a filter/sort attribute is a table column
711
+ * vs. a JSONB value field.
712
+ *
713
+ * @example
714
+ * ```typescript
715
+ * if (SYSTEM_FIELD_NAMES.includes(filter.attribute)) {
716
+ * // Filter on SQL column (e.g., WHERE created_at > ...)
717
+ * } else {
718
+ * // Filter on JSONB field (e.g., WHERE values->>'name' = ...)
719
+ * }
720
+ * ```
721
+ */
722
+ declare const SYSTEM_FIELD_NAMES: readonly ["id", "createdAt", "updatedAt", "createdBy", "lastUpdatedBy"];
723
+ /**
724
+ * Type for system field names
725
+ */
726
+ type SystemFieldName = (typeof SYSTEM_FIELD_NAMES)[number];
727
+ /**
728
+ * Reserved attribute names that cannot be used for custom attributes.
729
+ * These names conflict with ObjectRecord properties.
730
+ *
731
+ * Includes:
732
+ * - System fields (id, createdAt, updatedAt, createdBy, lastUpdatedBy)
733
+ * - Other ObjectRecord properties (objectId, label, completionStatus, values, metadata, deletedAt)
734
+ *
735
+ * @example
736
+ * ```typescript
737
+ * if (RESERVED_ATTRIBUTE_NAMES.includes(attributeName)) {
738
+ * throw new Error(`"${attributeName}" is a reserved name`);
739
+ * }
740
+ * ```
741
+ */
742
+ declare const RESERVED_ATTRIBUTE_NAMES: readonly ["id", "createdAt", "updatedAt", "createdBy", "lastUpdatedBy", "objectId", "label", "completionStatus", "values", "metadata", "deletedAt"];
743
+ /**
744
+ * Type for reserved attribute names
745
+ */
746
+ type ReservedAttributeName = (typeof RESERVED_ATTRIBUTE_NAMES)[number];
747
+
748
+ /**
749
+ * Format Zod validation errors into a consistent structure.
750
+ * This eliminates code duplication across multiple validation functions.
751
+ */
752
+ declare function formatZodErrors(error: z.ZodError): Array<{
753
+ path: string[];
754
+ message: string;
755
+ }>;
756
+
757
+ /**
758
+ * Validation messages for Zod validators.
759
+ * All functions receive the full Attribute to access label, type, etc.
760
+ * Can be customized for i18n support.
761
+ */
762
+ interface ValidationMessages {
763
+ required: (attr: Attribute) => string;
764
+ invalidType: (attr: Attribute, expected: string) => string;
765
+ minLength: (attr: Attribute, min: number) => string;
766
+ maxLength: (attr: Attribute, max: number) => string;
767
+ invalidPattern: (attr: Attribute) => string;
768
+ minValue: (attr: Attribute, min: number) => string;
769
+ maxValue: (attr: Attribute, max: number) => string;
770
+ mustBeInteger: (attr: Attribute) => string;
771
+ invalidDate: (attr: Attribute) => string;
772
+ invalidOption: (attr: Attribute, options: string[]) => string;
773
+ invalidId: (attr: Attribute) => string;
774
+ minItems: (attr: Attribute, min: number) => string;
775
+ maxItems: (attr: Attribute, max: number) => string;
776
+ invalidRichtext: (attr: Attribute) => string;
777
+ invalidPhone: (attr: Attribute) => string;
778
+ invalidCurrency: (attr: Attribute) => string;
779
+ invalidLocation: (attr: Attribute) => string;
780
+ }
781
+ declare const DEFAULT_VALIDATION_MESSAGES: ValidationMessages;
782
+ /**
783
+ * Text attribute config schema
784
+ */
785
+ declare const textConfigSchema: z.ZodObject<{
786
+ disabled: z.ZodOptional<z.ZodBoolean>;
787
+ placeholder: z.ZodOptional<z.ZodString>;
788
+ description: z.ZodOptional<z.ZodString>;
789
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
790
+ icon: z.ZodOptional<z.ZodString>;
791
+ order: z.ZodOptional<z.ZodNumber>;
792
+ hidden: z.ZodOptional<z.ZodBoolean>;
793
+ archived: z.ZodOptional<z.ZodBoolean>;
794
+ deprecated: z.ZodOptional<z.ZodBoolean>;
795
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
796
+ minLength: z.ZodOptional<z.ZodNumber>;
797
+ maxLength: z.ZodOptional<z.ZodNumber>;
798
+ pattern: z.ZodOptional<z.ZodString>;
799
+ }, z.core.$strip>;
800
+ /**
801
+ * Textarea attribute config schema
802
+ */
803
+ declare const textareaConfigSchema: z.ZodObject<{
804
+ disabled: z.ZodOptional<z.ZodBoolean>;
805
+ placeholder: z.ZodOptional<z.ZodString>;
806
+ description: z.ZodOptional<z.ZodString>;
807
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
808
+ icon: z.ZodOptional<z.ZodString>;
809
+ order: z.ZodOptional<z.ZodNumber>;
810
+ hidden: z.ZodOptional<z.ZodBoolean>;
811
+ archived: z.ZodOptional<z.ZodBoolean>;
812
+ deprecated: z.ZodOptional<z.ZodBoolean>;
813
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
814
+ }, z.core.$strip>;
815
+ /**
816
+ * Richtext attribute config schema
817
+ */
818
+ declare const richtextConfigSchema: z.ZodObject<{
819
+ disabled: z.ZodOptional<z.ZodBoolean>;
820
+ placeholder: z.ZodOptional<z.ZodString>;
821
+ description: z.ZodOptional<z.ZodString>;
822
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
823
+ icon: z.ZodOptional<z.ZodString>;
824
+ order: z.ZodOptional<z.ZodNumber>;
825
+ hidden: z.ZodOptional<z.ZodBoolean>;
826
+ archived: z.ZodOptional<z.ZodBoolean>;
827
+ deprecated: z.ZodOptional<z.ZodBoolean>;
828
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
829
+ features: z.ZodOptional<z.ZodArray<z.ZodEnum<{
830
+ headings: "headings";
831
+ bold: "bold";
832
+ italic: "italic";
833
+ lists: "lists";
834
+ links: "links";
835
+ images: "images";
836
+ codeBlocks: "codeBlocks";
837
+ tables: "tables";
838
+ }>>>;
839
+ }, z.core.$strip>;
840
+ /**
841
+ * Number attribute config schema
842
+ */
843
+ declare const numberConfigSchema: z.ZodObject<{
844
+ disabled: z.ZodOptional<z.ZodBoolean>;
845
+ placeholder: z.ZodOptional<z.ZodString>;
846
+ description: z.ZodOptional<z.ZodString>;
847
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
848
+ icon: z.ZodOptional<z.ZodString>;
849
+ order: z.ZodOptional<z.ZodNumber>;
850
+ hidden: z.ZodOptional<z.ZodBoolean>;
851
+ archived: z.ZodOptional<z.ZodBoolean>;
852
+ deprecated: z.ZodOptional<z.ZodBoolean>;
853
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
854
+ min: z.ZodOptional<z.ZodNumber>;
855
+ max: z.ZodOptional<z.ZodNumber>;
856
+ unit: z.ZodOptional<z.ZodEnum<{
857
+ percentage: "percentage";
858
+ integer: "integer";
859
+ decimal: "decimal";
860
+ }>>;
861
+ decimals: z.ZodOptional<z.ZodNumber>;
862
+ }, z.core.$strip>;
863
+ /**
864
+ * Checkbox attribute config schema
865
+ */
866
+ declare const checkboxConfigSchema: z.ZodObject<{
867
+ disabled: z.ZodOptional<z.ZodBoolean>;
868
+ placeholder: z.ZodOptional<z.ZodString>;
869
+ description: z.ZodOptional<z.ZodString>;
870
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
871
+ icon: z.ZodOptional<z.ZodString>;
872
+ order: z.ZodOptional<z.ZodNumber>;
873
+ hidden: z.ZodOptional<z.ZodBoolean>;
874
+ archived: z.ZodOptional<z.ZodBoolean>;
875
+ deprecated: z.ZodOptional<z.ZodBoolean>;
876
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
877
+ }, z.core.$strip>;
878
+ /**
879
+ * Date attribute config schema
880
+ */
881
+ declare const dateConfigSchema: z.ZodObject<{
882
+ disabled: z.ZodOptional<z.ZodBoolean>;
883
+ placeholder: z.ZodOptional<z.ZodString>;
884
+ description: z.ZodOptional<z.ZodString>;
885
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
886
+ icon: z.ZodOptional<z.ZodString>;
887
+ order: z.ZodOptional<z.ZodNumber>;
888
+ hidden: z.ZodOptional<z.ZodBoolean>;
889
+ archived: z.ZodOptional<z.ZodBoolean>;
890
+ deprecated: z.ZodOptional<z.ZodBoolean>;
891
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
892
+ dateFormat: z.ZodOptional<z.ZodEnum<{
893
+ short: "short";
894
+ long: "long";
895
+ full: "full";
896
+ relative: "relative";
897
+ }>>;
898
+ minDate: z.ZodOptional<z.ZodString>;
899
+ maxDate: z.ZodOptional<z.ZodString>;
900
+ }, z.core.$strip>;
901
+ /**
902
+ * Phone attribute config schema
903
+ */
904
+ declare const phoneConfigSchema: z.ZodObject<{
905
+ disabled: z.ZodOptional<z.ZodBoolean>;
906
+ placeholder: z.ZodOptional<z.ZodString>;
907
+ description: z.ZodOptional<z.ZodString>;
908
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
909
+ icon: z.ZodOptional<z.ZodString>;
910
+ order: z.ZodOptional<z.ZodNumber>;
911
+ hidden: z.ZodOptional<z.ZodBoolean>;
912
+ archived: z.ZodOptional<z.ZodBoolean>;
913
+ deprecated: z.ZodOptional<z.ZodBoolean>;
914
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
915
+ defaultCountryCode: z.ZodOptional<z.ZodString>;
916
+ }, z.core.$strip>;
917
+ /**
918
+ * Currency attribute config schema
919
+ */
920
+ declare const currencyConfigSchema: z.ZodObject<{
921
+ disabled: z.ZodOptional<z.ZodBoolean>;
922
+ placeholder: z.ZodOptional<z.ZodString>;
923
+ description: z.ZodOptional<z.ZodString>;
924
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
925
+ icon: z.ZodOptional<z.ZodString>;
926
+ order: z.ZodOptional<z.ZodNumber>;
927
+ hidden: z.ZodOptional<z.ZodBoolean>;
928
+ archived: z.ZodOptional<z.ZodBoolean>;
929
+ deprecated: z.ZodOptional<z.ZodBoolean>;
930
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
931
+ defaultCurrency: z.ZodOptional<z.ZodString>;
932
+ allowedCurrencies: z.ZodOptional<z.ZodArray<z.ZodString>>;
933
+ }, z.core.$strip>;
934
+ /**
935
+ * Status attribute config schema
936
+ */
937
+ declare const statusConfigSchema: z.ZodObject<{
938
+ disabled: z.ZodOptional<z.ZodBoolean>;
939
+ placeholder: z.ZodOptional<z.ZodString>;
940
+ description: z.ZodOptional<z.ZodString>;
941
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
942
+ icon: z.ZodOptional<z.ZodString>;
943
+ order: z.ZodOptional<z.ZodNumber>;
944
+ hidden: z.ZodOptional<z.ZodBoolean>;
945
+ archived: z.ZodOptional<z.ZodBoolean>;
946
+ deprecated: z.ZodOptional<z.ZodBoolean>;
947
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
948
+ options: z.ZodArray<z.ZodObject<{
949
+ id: z.ZodString;
950
+ label: z.ZodString;
951
+ value: z.ZodString;
952
+ color: z.ZodOptional<z.ZodString>;
953
+ icon: z.ZodOptional<z.ZodString>;
954
+ description: z.ZodOptional<z.ZodString>;
955
+ group: z.ZodOptional<z.ZodEnum<{
956
+ in_progress: "in_progress";
957
+ idle: "idle";
958
+ finished: "finished";
959
+ }>>;
960
+ }, z.core.$strip>>;
961
+ }, z.core.$strip>;
962
+ /**
963
+ * Location attribute config schema
964
+ */
965
+ declare const locationConfigSchema: z.ZodObject<{
966
+ disabled: z.ZodOptional<z.ZodBoolean>;
967
+ placeholder: z.ZodOptional<z.ZodString>;
968
+ description: z.ZodOptional<z.ZodString>;
969
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
970
+ icon: z.ZodOptional<z.ZodString>;
971
+ order: z.ZodOptional<z.ZodNumber>;
972
+ hidden: z.ZodOptional<z.ZodBoolean>;
973
+ archived: z.ZodOptional<z.ZodBoolean>;
974
+ deprecated: z.ZodOptional<z.ZodBoolean>;
975
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
976
+ granularity: z.ZodEnum<{
977
+ full: "full";
978
+ address: "address";
979
+ city: "city";
980
+ state: "state";
981
+ country: "country";
982
+ coordinates: "coordinates";
983
+ }>;
984
+ enableAutocomplete: z.ZodOptional<z.ZodBoolean>;
985
+ enableMap: z.ZodOptional<z.ZodBoolean>;
986
+ defaultCountry: z.ZodOptional<z.ZodString>;
987
+ allowedCountries: z.ZodOptional<z.ZodArray<z.ZodString>>;
988
+ displayFormat: z.ZodOptional<z.ZodEnum<{
989
+ single_line: "single_line";
990
+ multi_line: "multi_line";
991
+ compact: "compact";
992
+ }>>;
993
+ }, z.core.$strip>;
994
+ /**
995
+ * Select attribute config schema
996
+ */
997
+ declare const selectConfigSchema: z.ZodObject<{
998
+ disabled: z.ZodOptional<z.ZodBoolean>;
999
+ placeholder: z.ZodOptional<z.ZodString>;
1000
+ description: z.ZodOptional<z.ZodString>;
1001
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
1002
+ icon: z.ZodOptional<z.ZodString>;
1003
+ order: z.ZodOptional<z.ZodNumber>;
1004
+ hidden: z.ZodOptional<z.ZodBoolean>;
1005
+ archived: z.ZodOptional<z.ZodBoolean>;
1006
+ deprecated: z.ZodOptional<z.ZodBoolean>;
1007
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1008
+ options: z.ZodArray<z.ZodObject<{
1009
+ id: z.ZodString;
1010
+ label: z.ZodString;
1011
+ value: z.ZodString;
1012
+ color: z.ZodOptional<z.ZodString>;
1013
+ icon: z.ZodOptional<z.ZodString>;
1014
+ description: z.ZodOptional<z.ZodString>;
1015
+ group: z.ZodOptional<z.ZodEnum<{
1016
+ in_progress: "in_progress";
1017
+ idle: "idle";
1018
+ finished: "finished";
1019
+ }>>;
1020
+ }, z.core.$strip>>;
1021
+ }, z.core.$strip>;
1022
+ /**
1023
+ * Multiselect attribute config schema
1024
+ */
1025
+ declare const multiselectConfigSchema: z.ZodObject<{
1026
+ disabled: z.ZodOptional<z.ZodBoolean>;
1027
+ placeholder: z.ZodOptional<z.ZodString>;
1028
+ description: z.ZodOptional<z.ZodString>;
1029
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
1030
+ icon: z.ZodOptional<z.ZodString>;
1031
+ order: z.ZodOptional<z.ZodNumber>;
1032
+ hidden: z.ZodOptional<z.ZodBoolean>;
1033
+ archived: z.ZodOptional<z.ZodBoolean>;
1034
+ deprecated: z.ZodOptional<z.ZodBoolean>;
1035
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1036
+ options: z.ZodArray<z.ZodObject<{
1037
+ id: z.ZodString;
1038
+ label: z.ZodString;
1039
+ value: z.ZodString;
1040
+ color: z.ZodOptional<z.ZodString>;
1041
+ icon: z.ZodOptional<z.ZodString>;
1042
+ description: z.ZodOptional<z.ZodString>;
1043
+ group: z.ZodOptional<z.ZodEnum<{
1044
+ in_progress: "in_progress";
1045
+ idle: "idle";
1046
+ finished: "finished";
1047
+ }>>;
1048
+ }, z.core.$strip>>;
1049
+ }, z.core.$strip>;
1050
+ /**
1051
+ * File attribute config schema
1052
+ */
1053
+ declare const fileConfigSchema: z.ZodObject<{
1054
+ disabled: z.ZodOptional<z.ZodBoolean>;
1055
+ placeholder: z.ZodOptional<z.ZodString>;
1056
+ description: z.ZodOptional<z.ZodString>;
1057
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
1058
+ icon: z.ZodOptional<z.ZodString>;
1059
+ order: z.ZodOptional<z.ZodNumber>;
1060
+ hidden: z.ZodOptional<z.ZodBoolean>;
1061
+ archived: z.ZodOptional<z.ZodBoolean>;
1062
+ deprecated: z.ZodOptional<z.ZodBoolean>;
1063
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1064
+ maxFiles: z.ZodOptional<z.ZodNumber>;
1065
+ maxSize: z.ZodOptional<z.ZodNumber>;
1066
+ allowedTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
1067
+ multiple: z.ZodOptional<z.ZodBoolean>;
1068
+ }, z.core.$strip>;
1069
+ /**
1070
+ * User attribute config schema
1071
+ */
1072
+ declare const userConfigSchema: z.ZodObject<{
1073
+ disabled: z.ZodOptional<z.ZodBoolean>;
1074
+ placeholder: z.ZodOptional<z.ZodString>;
1075
+ description: z.ZodOptional<z.ZodString>;
1076
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
1077
+ icon: z.ZodOptional<z.ZodString>;
1078
+ order: z.ZodOptional<z.ZodNumber>;
1079
+ hidden: z.ZodOptional<z.ZodBoolean>;
1080
+ archived: z.ZodOptional<z.ZodBoolean>;
1081
+ deprecated: z.ZodOptional<z.ZodBoolean>;
1082
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1083
+ allowedRoles: z.ZodOptional<z.ZodArray<z.ZodString>>;
1084
+ multiple: z.ZodOptional<z.ZodBoolean>;
1085
+ }, z.core.$strip>;
1086
+ /**
1087
+ * Relation attribute config schema
1088
+ */
1089
+ declare const relationConfigSchema: z.ZodObject<{
1090
+ disabled: z.ZodOptional<z.ZodBoolean>;
1091
+ placeholder: z.ZodOptional<z.ZodString>;
1092
+ description: z.ZodOptional<z.ZodString>;
1093
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
1094
+ icon: z.ZodOptional<z.ZodString>;
1095
+ order: z.ZodOptional<z.ZodNumber>;
1096
+ hidden: z.ZodOptional<z.ZodBoolean>;
1097
+ archived: z.ZodOptional<z.ZodBoolean>;
1098
+ deprecated: z.ZodOptional<z.ZodBoolean>;
1099
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1100
+ targets: z.ZodArray<z.ZodObject<{
1101
+ object: z.ZodString;
1102
+ displayTemplate: z.ZodOptional<z.ZodString>;
1103
+ filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1104
+ }, z.core.$strip>>;
1105
+ cardinality: z.ZodEnum<{
1106
+ one: "one";
1107
+ many: "many";
1108
+ }>;
1109
+ minItems: z.ZodOptional<z.ZodNumber>;
1110
+ maxItems: z.ZodOptional<z.ZodNumber>;
1111
+ }, z.core.$strip>;
1112
+ /**
1113
+ * Rating attribute config schema
1114
+ */
1115
+ declare const ratingConfigSchema: z.ZodObject<{
1116
+ disabled: z.ZodOptional<z.ZodBoolean>;
1117
+ placeholder: z.ZodOptional<z.ZodString>;
1118
+ description: z.ZodOptional<z.ZodString>;
1119
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
1120
+ icon: z.ZodOptional<z.ZodString>;
1121
+ order: z.ZodOptional<z.ZodNumber>;
1122
+ hidden: z.ZodOptional<z.ZodBoolean>;
1123
+ archived: z.ZodOptional<z.ZodBoolean>;
1124
+ deprecated: z.ZodOptional<z.ZodBoolean>;
1125
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1126
+ max: z.ZodOptional<z.ZodNumber>;
1127
+ iconType: z.ZodOptional<z.ZodEnum<{
1128
+ number: "number";
1129
+ heart: "heart";
1130
+ star: "star";
1131
+ thumbs: "thumbs";
1132
+ }>>;
1133
+ }, z.core.$strip>;
1134
+ /**
1135
+ * Formula attribute config schema
1136
+ */
1137
+ declare const formulaConfigSchema: z.ZodObject<{
1138
+ disabled: z.ZodOptional<z.ZodBoolean>;
1139
+ placeholder: z.ZodOptional<z.ZodString>;
1140
+ description: z.ZodOptional<z.ZodString>;
1141
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
1142
+ icon: z.ZodOptional<z.ZodString>;
1143
+ order: z.ZodOptional<z.ZodNumber>;
1144
+ hidden: z.ZodOptional<z.ZodBoolean>;
1145
+ archived: z.ZodOptional<z.ZodBoolean>;
1146
+ deprecated: z.ZodOptional<z.ZodBoolean>;
1147
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1148
+ expression: z.ZodString;
1149
+ returnType: z.ZodEnum<{
1150
+ number: "number";
1151
+ boolean: "boolean";
1152
+ text: "text";
1153
+ date: "date";
1154
+ }>;
1155
+ decimals: z.ZodOptional<z.ZodNumber>;
1156
+ allowRelations: z.ZodOptional<z.ZodBoolean>;
1157
+ }, z.core.$strip>;
1158
+ /**
1159
+ * Rollup attribute config schema
1160
+ */
1161
+ declare const rollupConfigSchema: z.ZodObject<{
1162
+ disabled: z.ZodOptional<z.ZodBoolean>;
1163
+ placeholder: z.ZodOptional<z.ZodString>;
1164
+ description: z.ZodOptional<z.ZodString>;
1165
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
1166
+ icon: z.ZodOptional<z.ZodString>;
1167
+ order: z.ZodOptional<z.ZodNumber>;
1168
+ hidden: z.ZodOptional<z.ZodBoolean>;
1169
+ archived: z.ZodOptional<z.ZodBoolean>;
1170
+ deprecated: z.ZodOptional<z.ZodBoolean>;
1171
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1172
+ relationAttribute: z.ZodOptional<z.ZodString>;
1173
+ relationPath: z.ZodOptional<z.ZodString>;
1174
+ targetAttribute: z.ZodString;
1175
+ function: z.ZodEnum<{
1176
+ sum: "sum";
1177
+ avg: "avg";
1178
+ earliest: "earliest";
1179
+ latest: "latest";
1180
+ count: "count";
1181
+ countValues: "countValues";
1182
+ countUniqueValues: "countUniqueValues";
1183
+ countEmpty: "countEmpty";
1184
+ percentEmpty: "percentEmpty";
1185
+ percentNotEmpty: "percentNotEmpty";
1186
+ original: "original";
1187
+ }>;
1188
+ decimals: z.ZodOptional<z.ZodNumber>;
1189
+ targetAttributeType: z.ZodOptional<z.ZodString>;
1190
+ targetAttributeOptions: z.ZodOptional<z.ZodArray<z.ZodObject<{
1191
+ id: z.ZodString;
1192
+ label: z.ZodString;
1193
+ value: z.ZodString;
1194
+ color: z.ZodOptional<z.ZodString>;
1195
+ icon: z.ZodOptional<z.ZodString>;
1196
+ description: z.ZodOptional<z.ZodString>;
1197
+ group: z.ZodOptional<z.ZodEnum<{
1198
+ in_progress: "in_progress";
1199
+ idle: "idle";
1200
+ finished: "finished";
1201
+ }>>;
1202
+ }, z.core.$strip>>>;
1203
+ }, z.core.$strip>;
1204
+ /**
1205
+ * Document attribute config schema
1206
+ */
1207
+ declare const documentConfigSchema: z.ZodObject<{
1208
+ disabled: z.ZodOptional<z.ZodBoolean>;
1209
+ placeholder: z.ZodOptional<z.ZodString>;
1210
+ description: z.ZodOptional<z.ZodString>;
1211
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
1212
+ icon: z.ZodOptional<z.ZodString>;
1213
+ order: z.ZodOptional<z.ZodNumber>;
1214
+ hidden: z.ZodOptional<z.ZodBoolean>;
1215
+ archived: z.ZodOptional<z.ZodBoolean>;
1216
+ deprecated: z.ZodOptional<z.ZodBoolean>;
1217
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1218
+ templateId: z.ZodOptional<z.ZodString>;
1219
+ allowedTemplates: z.ZodOptional<z.ZodArray<z.ZodString>>;
1220
+ multiple: z.ZodOptional<z.ZodBoolean>;
1221
+ maxDocuments: z.ZodOptional<z.ZodNumber>;
1222
+ autoProcess: z.ZodOptional<z.ZodBoolean>;
1223
+ }, z.core.$strip>;
1224
+ /**
1225
+ * Map of attribute type to config schema
1226
+ */
1227
+ declare const attributeConfigSchemas: Record<AttributeType, z.ZodObject<z.ZodRawShape>>;
1228
+ /**
1229
+ * Get the config schema for a specific attribute type
1230
+ */
1231
+ declare function getAttributeConfigSchema(type: AttributeType): z.ZodObject<z.ZodRawShape>;
1232
+ /**
1233
+ * Validate attribute config for a specific type
1234
+ * Returns the validated config with only allowed properties
1235
+ */
1236
+ declare function validateAttributeConfig(type: AttributeType, config: Record<string, unknown>): {
1237
+ success: true;
1238
+ data: Record<string, unknown>;
1239
+ } | {
1240
+ success: false;
1241
+ errors: string[];
1242
+ };
1243
+ /**
1244
+ * Validate and strip unknown properties from attribute config
1245
+ * This ensures only allowed properties are stored in the database
1246
+ */
1247
+ declare function parseAttributeConfig(type: AttributeType, config: Record<string, unknown>): Record<string, unknown>;
1248
+ /**
1249
+ * Safely parse attribute config, returning undefined for invalid configs
1250
+ */
1251
+ declare function safeParseAttributeConfig(type: AttributeType, config: Record<string, unknown>): Record<string, unknown> | undefined;
1252
+ /**
1253
+ * Create a Zod schema for a text attribute
1254
+ */
1255
+ declare function createTextValidator(attr: TextAttribute, messages?: ValidationMessages): z.ZodString;
1256
+ /**
1257
+ * Create a Zod schema for a number attribute
1258
+ */
1259
+ declare function createNumberValidator(attr: NumberAttribute, messages?: ValidationMessages): z.ZodNumber;
1260
+ /**
1261
+ * Create a Zod schema for a checkbox attribute
1262
+ */
1263
+ declare function createCheckboxValidator(_attr: CheckboxAttribute, _messages?: ValidationMessages): z.ZodBoolean;
1264
+ /**
1265
+ * Create a Zod schema for a date attribute
1266
+ */
1267
+ declare function createDateValidator(attr: DateAttribute, messages?: ValidationMessages): z.ZodTypeAny;
1268
+ /**
1269
+ * Create a Zod schema for a phone attribute
1270
+ */
1271
+ declare function createPhoneValidator(attr: PhoneAttribute, messages?: ValidationMessages): z.ZodType<{
1272
+ countryCode: string;
1273
+ phoneNumber: string;
1274
+ }>;
1275
+ /**
1276
+ * Create a Zod schema for a currency attribute
1277
+ */
1278
+ declare function createCurrencyValidator(attr: CurrencyAttribute, messages?: ValidationMessages): z.ZodType<{
1279
+ code: string;
1280
+ value: number;
1281
+ }>;
1282
+ /**
1283
+ * Create a Zod schema for a status attribute
1284
+ */
1285
+ declare function createStatusValidator(attr: StatusAttribute, messages?: ValidationMessages): z.ZodEnum<Readonly<Record<string, string>>>;
1286
+ /**
1287
+ * Create a Zod schema for a select attribute
1288
+ */
1289
+ declare function createSelectValidator(attr: SelectAttribute, messages?: ValidationMessages): z.ZodEnum<Readonly<Record<string, string>>>;
1290
+ /**
1291
+ * Create a Zod schema for a multiselect attribute
1292
+ */
1293
+ declare function createMultiselectValidator(attr: MultiselectAttribute, messages?: ValidationMessages): z.ZodArray<z.ZodEnum<Readonly<Record<string, string>>>>;
1294
+ /**
1295
+ * Create a Zod schema for a location attribute
1296
+ */
1297
+ type LocationShape = {
1298
+ address?: string;
1299
+ address2?: string;
1300
+ city?: string;
1301
+ state?: string;
1302
+ postalCode?: string;
1303
+ country?: string;
1304
+ latitude?: number;
1305
+ longitude?: number;
1306
+ };
1307
+ declare function createLocationValidator(attr: LocationAttribute, messages?: ValidationMessages): z.ZodType<LocationShape>;
1308
+ /**
1309
+ * Create a Zod schema for a file attribute
1310
+ * Supports both single file (UUID) and multiple files (array of UUIDs)
1311
+ */
1312
+ declare function createFileValidator(attr: FileAttribute, messages?: ValidationMessages): z.ZodTypeAny;
1313
+ /**
1314
+ * Create a Zod schema for a user attribute
1315
+ * Supports both single user (UUID) and multiple users (array of UUIDs)
1316
+ */
1317
+ declare function createUserValidator(attr: UserAttribute, messages?: ValidationMessages): z.ZodTypeAny;
1318
+ /**
1319
+ * Create a Zod schema for a single relation attribute (cardinality: "one")
1320
+ */
1321
+ declare function createSingleRelationValidator(attr: SingleRelationAttribute, messages?: ValidationMessages): z.ZodUnion<[z.ZodUUID, z.ZodNull]>;
1322
+ /**
1323
+ * Create a Zod schema for a multi relation attribute (cardinality: "many")
1324
+ */
1325
+ declare function createMultiRelationValidator(attr: MultiRelationAttribute, messages?: ValidationMessages): z.ZodArray<z.ZodUUID>;
1326
+ /**
1327
+ * Create a Zod schema for a relation attribute
1328
+ * Dispatches to single or multi validator based on cardinality
1329
+ */
1330
+ declare function createRelationValidator(attr: RelationAttribute, messages?: ValidationMessages): z.ZodUnion<[z.ZodUUID, z.ZodNull]> | z.ZodArray<z.ZodUUID>;
1331
+ /**
1332
+ * Create a Zod schema for a rating attribute
1333
+ */
1334
+ declare function createRatingValidator(attr: RatingAttribute, messages?: ValidationMessages): z.ZodNumber;
1335
+ /**
1336
+ * Create a Zod schema for a formula attribute.
1337
+ * Formula attributes are read-only (computed at runtime).
1338
+ * They accept any value during validation but are ignored during record creation/update.
1339
+ */
1340
+ declare function createFormulaValidator(_attr: FormulaAttribute, _messages?: ValidationMessages): z.ZodUnknown;
1341
+ /**
1342
+ * Create a Zod schema for a rollup attribute.
1343
+ * Rollup attributes are read-only (computed from related records).
1344
+ * They accept any value during validation but are ignored during record creation/update.
1345
+ */
1346
+ declare function createRollupValidator(_attr: RollupAttribute, _messages?: ValidationMessages): z.ZodUnknown;
1347
+ /**
1348
+ * Create a Zod schema for a textarea attribute.
1349
+ * Validates that the value is a string.
1350
+ */
1351
+ declare function createTextAreaValidator(_attr: TextAreaAttribute, _messages?: ValidationMessages): z.ZodString;
1352
+ /**
1353
+ * Create a Zod schema for a richtext attribute.
1354
+ * Validates semantic markdown content as a string.
1355
+ *
1356
+ * @example Valid richtext content (semantic markdown)
1357
+ * ```typescript
1358
+ * `# Heading
1359
+ *
1360
+ * Some paragraph text.
1361
+ *
1362
+ * :::callout{variant="info"}
1363
+ * This is a callout block
1364
+ * :::
1365
+ * `
1366
+ * ```
1367
+ */
1368
+ declare function createRichtextValidator(attr: RichtextAttribute, messages?: ValidationMessages): z.ZodTypeAny;
1369
+ /**
1370
+ * Create a Zod schema for any attribute type.
1371
+ * Returns a strict validator that does NOT handle optional fields.
1372
+ * Use createFormAttributeValidator for form validation with optional support.
1373
+ *
1374
+ * @param attr - The attribute to create a validator for
1375
+ * @param messages - Custom validation messages for i18n support
1376
+ */
1377
+ declare function createAttributeValidator(attr: Attribute, messages?: ValidationMessages): z.ZodTypeAny;
1378
+ /**
1379
+ * Create a Zod schema for form validation.
1380
+ * - Normalizes empty values (empty strings, empty objects) to null for optional fields
1381
+ * - Accepts custom messages for i18n support
1382
+ *
1383
+ * Use this in UI forms where optional fields may have null/undefined values.
1384
+ *
1385
+ * @param attr - The attribute to create a validator for
1386
+ * @param messages - Custom validation messages for i18n support
1387
+ */
1388
+ declare function createFormAttributeValidator(attr: Attribute, messages?: ValidationMessages): z.ZodTypeAny;
1389
+ /**
1390
+ * Create a Zod schema for an entire object
1391
+ *
1392
+ * Uses passthrough mode to allow computed fields (formula, rollup) that may be
1393
+ * present in record data but are not part of the mutable schema.
1394
+ */
1395
+ declare function createObjectValidator(objectDef: ObjectDefinition): z.ZodType<Record<string, unknown>>;
1396
+ /**
1397
+ * Validation result
1398
+ */
1399
+ interface ValidationResult {
1400
+ success: boolean;
1401
+ data?: Record<string, unknown>;
1402
+ errors?: Array<{
1403
+ path: string[];
1404
+ message: string;
1405
+ }>;
1406
+ }
1407
+ /**
1408
+ * Validate data against an attribute schema
1409
+ */
1410
+ declare function validateAttribute(attr: Attribute, value: unknown): ValidationResult;
1411
+ /**
1412
+ * Validate data against an object schema
1413
+ */
1414
+ declare function validateObject(objectDef: ObjectDefinition, data: Record<string, unknown>): ValidationResult;
1415
+ /**
1416
+ * Validate and throw if invalid
1417
+ */
1418
+ declare function validateObjectOrThrow(objectDef: ObjectDefinition, data: Record<string, unknown>): Record<string, unknown>;
1419
+ /**
1420
+ * Create a Zod schema for draft validation.
1421
+ * All attributes become optional, but provided values are still validated.
1422
+ *
1423
+ * Uses passthrough mode to allow computed fields (formula, rollup) that may be
1424
+ * present in record data but are not part of the mutable schema.
1425
+ */
1426
+ declare function createDraftValidator(objectDef: ObjectDefinition): z.ZodType<Record<string, unknown>>;
1427
+ /**
1428
+ * Validate data in draft mode.
1429
+ * - All attributes are treated as optional (no required validation)
1430
+ * - Provided values are still validated for format/type correctness
1431
+ *
1432
+ * Use this when creating records that may be incomplete (drafts).
1433
+ *
1434
+ * @example
1435
+ * ```typescript
1436
+ * const result = validateDraft(PRODUCT, { name: "Draft" });
1437
+ * // → success even if "price" is required but missing
1438
+ *
1439
+ * const result2 = validateDraft(PRODUCT, { price: -10 });
1440
+ * // → fails because price must be >= 0 (format validation still applies)
1441
+ * ```
1442
+ */
1443
+ declare function validateDraft(objectDef: ObjectDefinition, data: Record<string, unknown>): ValidationResult;
1444
+ /**
1445
+ * Validate draft data and throw if format validation fails.
1446
+ */
1447
+ declare function validateDraftOrThrow(objectDef: ObjectDefinition, data: Record<string, unknown>): Record<string, unknown>;
1448
+ /**
1449
+ * Get the list of required attributes that are missing values.
1450
+ *
1451
+ * @example
1452
+ * ```typescript
1453
+ * const missing = getMissingRequiredAttributes(PRODUCT, { name: "Test" });
1454
+ * // → [priceAttribute, statusAttribute] if price and status are required but missing
1455
+ * ```
1456
+ */
1457
+ declare function getMissingRequiredAttributes(objectDef: ObjectDefinition, data: Record<string, unknown>): Attribute[];
1458
+ /**
1459
+ * Check if a record is complete (all required attributes have valid values).
1460
+ *
1461
+ * @returns `true` if all required values are present and valid, `false` otherwise
1462
+ */
1463
+ declare function isRecordComplete(objectDef: ObjectDefinition, data: Record<string, unknown>): boolean;
1464
+ /**
1465
+ * Compute the completion status of a record based on its data.
1466
+ *
1467
+ * - `"complete"`: All required values are present and valid
1468
+ * - `"draft"`: One or more required values are missing or invalid
1469
+ *
1470
+ * This function is used to dynamically determine the status when
1471
+ * creating or updating records.
1472
+ *
1473
+ * @example
1474
+ * ```typescript
1475
+ * const status = computeRecordStatus(PRODUCT, {
1476
+ * name: "Nike Air Max",
1477
+ * price: 129.99,
1478
+ * status: "active"
1479
+ * });
1480
+ * // → "complete"
1481
+ *
1482
+ * const status2 = computeRecordStatus(PRODUCT, { name: "Draft Product" });
1483
+ * // → "draft" (missing required fields)
1484
+ * ```
1485
+ */
1486
+ declare function computeRecordStatus(objectDef: ObjectDefinition, data: Record<string, unknown>): CompletionStatus;
1487
+
1488
+ export { type SystemFieldName as $, type Attribute as A, type BaseAttribute as B, type CheckboxAttribute as C, type DateAttribute as D, type DateValue as E, type FeatureGate as F, type Phone as G, type Currency as H, type Location as I, type LocationGranularity as J, RELATION_TARGET_ANY as K, type LocationAttribute as L, type MultiselectAttribute as M, type NumberAttribute as N, type Option as O, type PhoneAttribute as P, type RelationAttribute as Q, type RichtextAttribute as R, type StatusAttribute as S, type TextAttribute as T, type UserAttribute as U, isUniversalRelation as V, type FlagOverride as W, type FeatureFlagsConfig as X, RESERVED_ATTRIBUTE_NAMES as Y, SYSTEM_FIELD_NAMES as Z, type ReservedAttributeName as _, type DocumentAttribute as a, isRecordComplete as a$, type Timestamps as a0, type SharingMode as a1, type ObjectAttribute as a2, type CompletionStatus as a3, type ObjectRecord as a4, formatZodErrors as a5, type ValidationMessages as a6, DEFAULT_VALIDATION_MESSAGES as a7, textConfigSchema as a8, textareaConfigSchema as a9, createPhoneValidator as aA, createCurrencyValidator as aB, createStatusValidator as aC, createSelectValidator as aD, createMultiselectValidator as aE, createLocationValidator as aF, createFileValidator as aG, createUserValidator as aH, createSingleRelationValidator as aI, createMultiRelationValidator as aJ, createRelationValidator as aK, createRatingValidator as aL, createFormulaValidator as aM, createRollupValidator as aN, createTextAreaValidator as aO, createRichtextValidator as aP, createAttributeValidator as aQ, createFormAttributeValidator as aR, createObjectValidator as aS, type ValidationResult as aT, validateAttribute as aU, validateObject as aV, validateObjectOrThrow as aW, createDraftValidator as aX, validateDraft as aY, validateDraftOrThrow as aZ, getMissingRequiredAttributes as a_, richtextConfigSchema as aa, numberConfigSchema as ab, checkboxConfigSchema as ac, dateConfigSchema as ad, phoneConfigSchema as ae, currencyConfigSchema as af, statusConfigSchema as ag, locationConfigSchema as ah, selectConfigSchema as ai, multiselectConfigSchema as aj, fileConfigSchema as ak, userConfigSchema as al, relationConfigSchema as am, ratingConfigSchema as an, formulaConfigSchema as ao, rollupConfigSchema as ap, documentConfigSchema as aq, attributeConfigSchemas as ar, getAttributeConfigSchema as as, validateAttributeConfig as at, parseAttributeConfig as au, safeParseAttributeConfig as av, createTextValidator as aw, createNumberValidator as ax, createCheckboxValidator as ay, createDateValidator as az, type TextAreaAttribute as b, computeRecordStatus as b0, type RichtextFeature as c, type CurrencyAttribute as d, type SelectAttribute as e, type FileAttribute as f, type SingleRelationAttribute as g, type MultiRelationAttribute as h, type RelationTarget as i, type RatingAttribute as j, type FormulaAttribute as k, type FormulaReturnType as l, type RollupAttribute as m, type RollupFunction as n, type AttributeType as o, type ObjectDefinition as p, type FlagValueType as q, type FeatureFlagDefinition as r, type FlagLevel as s, type FeatureFlagsRepository as t, type StaticFlagDefault as u, type ResolvedFlag as v, type StatusGroup as w, type AttributeGroup as x, type NumberUnit as y, type DateFormat as z };