@stndrds/schema 1.0.0-alpha.91 → 1.0.0-alpha.93

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