@stndrds/schema 0.1.0-alpha.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/dist/chunk-3ABIOLKO.mjs +4624 -0
  2. package/dist/chunk-3IRX2BDY.mjs +3970 -0
  3. package/dist/chunk-4OTLPWSP.mjs +4448 -0
  4. package/dist/chunk-54ODQBUN.mjs +3867 -0
  5. package/dist/chunk-6HIA3FR2.mjs +4230 -0
  6. package/dist/chunk-6P3XHNLD.mjs +4171 -0
  7. package/dist/chunk-7LJECNAS.mjs +4167 -0
  8. package/dist/chunk-A2WNLUKV.mjs +4475 -0
  9. package/dist/chunk-AA3234RM.mjs +4475 -0
  10. package/dist/chunk-ADNXDLLD.mjs +3136 -0
  11. package/dist/chunk-B4DCDQUI.mjs +4695 -0
  12. package/dist/chunk-B4PSXY6I.mjs +4527 -0
  13. package/dist/chunk-BJHJBZCM.mjs +4228 -0
  14. package/dist/chunk-C3ZWTO6G.mjs +4474 -0
  15. package/dist/chunk-CLOGNKDD.mjs +4040 -0
  16. package/dist/chunk-EW4V63PA.mjs +3053 -0
  17. package/dist/chunk-FR2LCO6R.mjs +2485 -0
  18. package/dist/chunk-GJSF2RKL.mjs +2786 -0
  19. package/dist/chunk-GO5NPP2X.mjs +4726 -0
  20. package/dist/chunk-H3ZYJUDS.mjs +3050 -0
  21. package/dist/chunk-IDDLSFSK.mjs +4230 -0
  22. package/dist/chunk-JRADUJQ7.mjs +4726 -0
  23. package/dist/chunk-NEDR6N7R.mjs +3118 -0
  24. package/dist/chunk-NESPRMDF.mjs +2482 -0
  25. package/dist/chunk-NWFGRJBW.mjs +4612 -0
  26. package/dist/chunk-NXJ57GSN.mjs +2918 -0
  27. package/dist/chunk-O4C5FCTS.mjs +3961 -0
  28. package/dist/chunk-O4PRB27Q.mjs +2513 -0
  29. package/dist/chunk-OJDFNUCR.mjs +4463 -0
  30. package/dist/chunk-OSEKVBHC.mjs +4627 -0
  31. package/dist/chunk-QX4U6U6K.mjs +2484 -0
  32. package/dist/chunk-RMDQ6LKV.mjs +3046 -0
  33. package/dist/chunk-SBXKDATH.mjs +2673 -0
  34. package/dist/chunk-SKMP3AP3.mjs +2918 -0
  35. package/dist/chunk-STMS7WZD.mjs +2623 -0
  36. package/dist/chunk-T3T6PTFG.mjs +3057 -0
  37. package/dist/chunk-TPW72RAH.mjs +4624 -0
  38. package/dist/chunk-TUQEGNGV.mjs +2534 -0
  39. package/dist/chunk-TVKFS3YN.mjs +2449 -0
  40. package/dist/chunk-TZTH3BHG.mjs +3110 -0
  41. package/dist/chunk-W6MU3XPG.mjs +4612 -0
  42. package/dist/chunk-WL7Z3YFR.mjs +4603 -0
  43. package/dist/chunk-XNVVYHH3.mjs +4602 -0
  44. package/dist/chunk-XTA3WY64.mjs +2918 -0
  45. package/dist/chunk-YV7DEZFZ.mjs +2528 -0
  46. package/dist/chunk-ZLJPJND6.mjs +4474 -0
  47. package/dist/chunk-ZNZXTCEX.mjs +4234 -0
  48. package/dist/index.d.mts +1222 -0
  49. package/dist/index.d.ts +1222 -0
  50. package/dist/index.js +5320 -0
  51. package/dist/index.mjs +635 -0
  52. package/dist/runtime-2iKarXtl.d.mts +1924 -0
  53. package/dist/runtime-2iKarXtl.d.ts +1924 -0
  54. package/dist/runtime-4l2ddHZ7.d.mts +2242 -0
  55. package/dist/runtime-4l2ddHZ7.d.ts +2243 -0
  56. package/dist/runtime-8hKS6zAv.d.mts +2226 -0
  57. package/dist/runtime-8hKS6zAv.d.ts +2226 -0
  58. package/dist/runtime-B6yjtoR3.d.mts +4142 -0
  59. package/dist/runtime-B6yjtoR3.d.ts +4142 -0
  60. package/dist/runtime-BGCShrZB.d.mts +2001 -0
  61. package/dist/runtime-BGCShrZB.d.ts +2001 -0
  62. package/dist/runtime-BRW4NGAk.d.mts +1668 -0
  63. package/dist/runtime-BRW4NGAk.d.ts +1668 -0
  64. package/dist/runtime-BnfBr314.d.mts +1683 -0
  65. package/dist/runtime-BnfBr314.d.ts +1683 -0
  66. package/dist/runtime-BrqhiJUF.d.mts +4151 -0
  67. package/dist/runtime-BrqhiJUF.d.ts +4151 -0
  68. package/dist/runtime-Bvj8c-BE.d.mts +4277 -0
  69. package/dist/runtime-Bvj8c-BE.d.ts +4277 -0
  70. package/dist/runtime-C03qT4qU.d.mts +4267 -0
  71. package/dist/runtime-C03qT4qU.d.ts +4267 -0
  72. package/dist/runtime-CaCZ7mSf.d.mts +2974 -0
  73. package/dist/runtime-CaCZ7mSf.d.ts +2974 -0
  74. package/dist/runtime-CaIzNX0Z.d.mts +4091 -0
  75. package/dist/runtime-CaIzNX0Z.d.ts +4091 -0
  76. package/dist/runtime-ChPTgmLP.d.mts +4320 -0
  77. package/dist/runtime-ChPTgmLP.d.ts +4320 -0
  78. package/dist/runtime-CnImZ1Vv.d.mts +4267 -0
  79. package/dist/runtime-CnImZ1Vv.d.ts +4267 -0
  80. package/dist/runtime-Cp-B26Nj.d.mts +2890 -0
  81. package/dist/runtime-Cp-B26Nj.d.ts +2890 -0
  82. package/dist/runtime-Cq8jfk3c.d.mts +4277 -0
  83. package/dist/runtime-Cq8jfk3c.d.ts +4277 -0
  84. package/dist/runtime-CqDFXhhP.d.mts +1685 -0
  85. package/dist/runtime-CqDFXhhP.d.ts +1685 -0
  86. package/dist/runtime-CqtpZLdL.d.mts +4280 -0
  87. package/dist/runtime-CqtpZLdL.d.ts +4280 -0
  88. package/dist/runtime-D-4DblaZ.d.mts +4147 -0
  89. package/dist/runtime-D-4DblaZ.d.ts +4147 -0
  90. package/dist/runtime-D59sSqNl.d.mts +4146 -0
  91. package/dist/runtime-D59sSqNl.d.ts +4146 -0
  92. package/dist/runtime-DEfPk3wT.d.mts +1840 -0
  93. package/dist/runtime-DEfPk3wT.d.ts +1840 -0
  94. package/dist/runtime-DGV-7vES.d.mts +1685 -0
  95. package/dist/runtime-DGV-7vES.d.ts +1685 -0
  96. package/dist/runtime-DNacghqc.d.mts +3971 -0
  97. package/dist/runtime-DNacghqc.d.ts +3971 -0
  98. package/dist/runtime-DPLsUHYK.d.mts +3977 -0
  99. package/dist/runtime-DPLsUHYK.d.ts +3977 -0
  100. package/dist/runtime-DTxCw60F.d.mts +2973 -0
  101. package/dist/runtime-DTxCw60F.d.ts +2973 -0
  102. package/dist/runtime-DUXJ-zNS.d.mts +2788 -0
  103. package/dist/runtime-DUXJ-zNS.d.ts +2788 -0
  104. package/dist/runtime-DbljInhV.d.mts +2237 -0
  105. package/dist/runtime-DbljInhV.d.ts +2237 -0
  106. package/dist/runtime-DcH3y6Yu.d.mts +4272 -0
  107. package/dist/runtime-DcH3y6Yu.d.ts +4272 -0
  108. package/dist/runtime-DdBFz85g.d.mts +4229 -0
  109. package/dist/runtime-DdBFz85g.d.ts +4229 -0
  110. package/dist/runtime-DjMWhjkm.d.mts +4321 -0
  111. package/dist/runtime-DjMWhjkm.d.ts +4321 -0
  112. package/dist/runtime-Djz3fOBE.d.mts +2078 -0
  113. package/dist/runtime-Djz3fOBE.d.ts +2078 -0
  114. package/dist/runtime-Dli8g3Aq.d.mts +2082 -0
  115. package/dist/runtime-Dli8g3Aq.d.ts +2082 -0
  116. package/dist/runtime-a8J378im.d.mts +4123 -0
  117. package/dist/runtime-a8J378im.d.ts +4123 -0
  118. package/dist/runtime-dp3rb3Lf.d.mts +2968 -0
  119. package/dist/runtime-dp3rb3Lf.d.ts +2968 -0
  120. package/dist/runtime-iWXlSN_H.d.mts +1683 -0
  121. package/dist/runtime-iWXlSN_H.d.ts +1683 -0
  122. package/dist/runtime-yMql0npY.d.mts +4321 -0
  123. package/dist/runtime-yMql0npY.d.ts +4321 -0
  124. package/dist/runtime.d.mts +3 -0
  125. package/dist/runtime.d.ts +3 -0
  126. package/dist/runtime.js +3626 -0
  127. package/dist/runtime.mjs +48 -0
  128. package/package.json +58 -0
@@ -0,0 +1,2890 @@
1
+ import { ColorId, IconName, CountryIso3, CurrencyCode, MimeType } from '@andyoucreate/constants';
2
+ import { z } from 'zod';
3
+
4
+ /**
5
+ * UUID string type for all identifiers
6
+ */
7
+ type Uuid = string;
8
+ /**
9
+ * Tenant identifier for multi-tenant isolation
10
+ * Phase 1: Type defined but not yet used in interfaces
11
+ * Phase 2+: Will be added to ObjectRecord and services for SaaS mode
12
+ */
13
+ type TenantId = string;
14
+ /**
15
+ * Generate a unique UUID v4
16
+ * Uses crypto.randomUUID() when available (Node.js 19+, modern browsers)
17
+ * Falls back to a manual implementation for older environments
18
+ *
19
+ * @returns A UUID v4 string
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const id = generateId();
24
+ * // "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d"
25
+ * ```
26
+ */
27
+ declare function generateId(): Uuid;
28
+ /**
29
+ * Generate a prefixed ID for better debugging and readability
30
+ *
31
+ * @param prefix - Prefix for the ID (e.g., "obj", "attr", "rec")
32
+ * @returns A prefixed UUID string
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const objectId = generatePrefixedId("obj");
37
+ * // "obj_a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d"
38
+ *
39
+ * const attrId = generatePrefixedId("attr");
40
+ * // "attr_a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d"
41
+ * ```
42
+ */
43
+ declare function generatePrefixedId(prefix: string): Uuid;
44
+
45
+ type AttributeType = "text" | "textarea" | "number" | "checkbox" | "date" | "phone" | "currency" | "status" | "location" | "timestamp" | "select" | "multiselect" | "file" | "user" | "relation" | "rating";
46
+ /**
47
+ * Status group categorization
48
+ */
49
+ type StatusGroup = "idle" | "in_progress" | "finished";
50
+ /**
51
+ * Unified option type for select-like fields
52
+ */
53
+ interface Option {
54
+ id: string;
55
+ label: string;
56
+ value: string;
57
+ color?: ColorId;
58
+ icon?: IconName;
59
+ description?: string;
60
+ group?: StatusGroup;
61
+ }
62
+ /**
63
+ * Attribute grouping for UI organization
64
+ */
65
+ interface AttributeGroup {
66
+ id: string;
67
+ label: string;
68
+ description?: string;
69
+ attributeIds: string[];
70
+ collapsible?: boolean;
71
+ collapsed?: boolean;
72
+ order?: number;
73
+ }
74
+ interface BaseAttribute<DefaultValueType = unknown> {
75
+ id: Uuid;
76
+ name: string;
77
+ label: string;
78
+ type: AttributeType;
79
+ required: boolean;
80
+ disabled?: boolean;
81
+ placeholder?: string;
82
+ description?: string;
83
+ defaultValue?: DefaultValueType;
84
+ icon?: IconName;
85
+ order?: number;
86
+ hidden?: boolean;
87
+ archived?: boolean;
88
+ deprecated?: boolean;
89
+ system?: boolean;
90
+ metadata?: Record<string, unknown>;
91
+ }
92
+ interface TextAttribute extends BaseAttribute<string> {
93
+ type: "text";
94
+ minLength?: number;
95
+ maxLength?: number;
96
+ pattern?: string;
97
+ }
98
+ type NumberUnit = "integer" | "decimal" | "percentage";
99
+ interface NumberAttribute extends BaseAttribute<number> {
100
+ type: "number";
101
+ min?: number;
102
+ max?: number;
103
+ unit?: NumberUnit;
104
+ decimals?: number;
105
+ }
106
+ interface CheckboxAttribute extends BaseAttribute<boolean> {
107
+ type: "checkbox";
108
+ }
109
+ type DateFormat = "short" | "long" | "full" | "relative";
110
+ type DateValue = string | "today";
111
+ interface DateAttribute extends BaseAttribute<string> {
112
+ type: "date";
113
+ dateFormat?: DateFormat;
114
+ minDate?: DateValue;
115
+ maxDate?: DateValue;
116
+ }
117
+ interface Phone {
118
+ countryCode: CountryIso3;
119
+ phoneNumber: string;
120
+ }
121
+ interface PhoneAttribute extends BaseAttribute<Phone> {
122
+ type: "phone";
123
+ defaultCountryCode?: CountryIso3;
124
+ }
125
+ interface Currency {
126
+ code: CurrencyCode;
127
+ value: number;
128
+ }
129
+ interface CurrencyAttribute extends BaseAttribute<Currency> {
130
+ type: "currency";
131
+ defaultCurrency?: CurrencyCode;
132
+ allowedCurrencies?: CurrencyCode[];
133
+ }
134
+ /**
135
+ * StatusAttribute - For workflow states with semantic grouping (idle/in_progress/finished)
136
+ * Use this for: Task status, Order status, Project phases, Process states
137
+ * Use SelectAttribute for: Categories, Types, simple choices without workflow
138
+ */
139
+ interface StatusAttribute extends BaseAttribute<string> {
140
+ type: "status";
141
+ options: Option[];
142
+ }
143
+ interface Location {
144
+ address?: string;
145
+ address2?: string;
146
+ city?: string;
147
+ state?: string;
148
+ postalCode?: string;
149
+ country?: CountryIso3;
150
+ latitude?: number;
151
+ longitude?: number;
152
+ }
153
+ type LocationGranularity = "full" | "address" | "city" | "state" | "country" | "coordinates";
154
+ interface LocationAttribute extends BaseAttribute<Location> {
155
+ type: "location";
156
+ granularity: LocationGranularity;
157
+ enableAutocomplete?: boolean;
158
+ enableMap?: boolean;
159
+ defaultCountry?: CountryIso3;
160
+ allowedCountries?: CountryIso3[];
161
+ displayFormat?: "single_line" | "multi_line" | "compact";
162
+ }
163
+ interface TimestampAttribute extends BaseAttribute<number> {
164
+ type: "timestamp";
165
+ autoUpdate?: boolean;
166
+ }
167
+ /**
168
+ * SelectAttribute - For simple single-choice selection
169
+ * Use this for: Categories, Document types, Departments, Priorities
170
+ * Options can be grouped (e.g., countries by continent) but no workflow logic
171
+ */
172
+ interface SelectAttribute extends BaseAttribute<string> {
173
+ type: "select";
174
+ options: Option[];
175
+ }
176
+ interface MultiselectAttribute extends BaseAttribute<string[]> {
177
+ type: "multiselect";
178
+ options: Option[];
179
+ }
180
+ type DocumentType = "id_card" | "passport" | "incorporation_certificate" | "driver_license" | "birth_certificate" | "residence_permit" | "bank_statement" | "proof_of_address" | "custom";
181
+ type DocumentFace = "front" | "back" | "single";
182
+ interface DocumentTypeConfig {
183
+ type: DocumentType;
184
+ label: string;
185
+ faces: DocumentFace[];
186
+ attributeMapping?: {
187
+ attributeId: string;
188
+ extractedKey: string;
189
+ face?: DocumentFace;
190
+ required?: boolean;
191
+ }[];
192
+ }
193
+ interface FileVerificationConfig {
194
+ enabled: boolean;
195
+ documentTypes: DocumentTypeConfig[];
196
+ autoExtract?: boolean;
197
+ autoValidate?: boolean;
198
+ }
199
+ interface FileAttribute extends BaseAttribute<string> {
200
+ type: "file";
201
+ maxFiles?: number;
202
+ maxSize?: number;
203
+ allowedTypes?: MimeType[] | readonly MimeType[];
204
+ verification?: FileVerificationConfig;
205
+ }
206
+ interface UserAttribute extends BaseAttribute<string> {
207
+ type: "user";
208
+ allowedRoles?: string[];
209
+ }
210
+ /**
211
+ * Target object for a relation - defines which objects can be linked
212
+ */
213
+ interface RelationTarget {
214
+ /** Object name (e.g., "companies", "contacts") */
215
+ object: string;
216
+ /**
217
+ * Display template for the label using mustache-like syntax
218
+ * @example "{name}" or "{firstName} {lastName} — {email}"
219
+ */
220
+ displayTemplate?: string;
221
+ /**
222
+ * Optional filter to restrict available records
223
+ * @example { status: "active" }
224
+ */
225
+ filter?: Record<string, unknown>;
226
+ }
227
+ /**
228
+ * Strategy when a target record is deleted
229
+ * - "restrict": Prevent deletion if relations exist (default)
230
+ * - "cascade": Delete this record too
231
+ * - "set_null": Set the relation value to null
232
+ */
233
+ type RelationOnDelete = "restrict" | "cascade" | "set_null";
234
+ /**
235
+ * Base properties shared by both single and multi relation attributes
236
+ */
237
+ interface RelationAttributeBase extends Omit<BaseAttribute<unknown>, "defaultValue"> {
238
+ type: "relation";
239
+ /** Target objects that can be linked */
240
+ targets: RelationTarget[];
241
+ /** Deletion strategy when target record is deleted */
242
+ onDelete?: RelationOnDelete;
243
+ }
244
+ /**
245
+ * Single relation attribute (one-to-one or many-to-one)
246
+ * Stores a single record ID or null
247
+ */
248
+ interface SingleRelationAttribute extends RelationAttributeBase {
249
+ cardinality: "one";
250
+ defaultValue?: string | null;
251
+ }
252
+ /**
253
+ * Multi relation attribute (one-to-many or many-to-many)
254
+ * Stores an array of record IDs
255
+ */
256
+ interface MultiRelationAttribute extends RelationAttributeBase {
257
+ cardinality: "many";
258
+ defaultValue?: string[];
259
+ /** Minimum number of relations required */
260
+ minItems?: number;
261
+ /** Maximum number of relations allowed */
262
+ maxItems?: number;
263
+ }
264
+ /**
265
+ * RelationAttribute links to other objects/records
266
+ * Discriminated union by cardinality for type-safe value handling
267
+ *
268
+ * @example Single relation (many-to-one)
269
+ * ```typescript
270
+ * relation({ name: "company", label: "Company" })
271
+ * .to("companies")
272
+ * .required()
273
+ * // → Value: "rec-uuid-123" | null
274
+ * ```
275
+ *
276
+ * @example Multi relation (many-to-many)
277
+ * ```typescript
278
+ * relation({ name: "contacts", label: "Contacts" })
279
+ * .to("contacts", { displayTemplate: "{firstName} {lastName}" })
280
+ * .many()
281
+ * .maxItems(5)
282
+ * // → Value: ["rec-1", "rec-2", ...]
283
+ * ```
284
+ *
285
+ * @example Polymorphic relation (multiple target objects)
286
+ * ```typescript
287
+ * relation({ name: "linked", label: "Linked Items" })
288
+ * .to("companies")
289
+ * .to("contacts")
290
+ * .to("deals")
291
+ * .many()
292
+ * // → Can link to records from any of these objects
293
+ * ```
294
+ */
295
+ type RelationAttribute = SingleRelationAttribute | MultiRelationAttribute;
296
+ interface TextAreaAttribute extends BaseAttribute<string> {
297
+ type: "textarea";
298
+ }
299
+ interface RatingAttribute extends BaseAttribute<number> {
300
+ type: "rating";
301
+ max?: number;
302
+ iconType?: "star" | "heart" | "thumbs" | "number";
303
+ }
304
+ type Attribute = TextAttribute | TextAreaAttribute | NumberAttribute | CheckboxAttribute | DateAttribute | PhoneAttribute | CurrencyAttribute | StatusAttribute | LocationAttribute | TimestampAttribute | SelectAttribute | MultiselectAttribute | FileAttribute | UserAttribute | RelationAttribute | RatingAttribute;
305
+
306
+ /**
307
+ * Timestamps for tracking creation and updates
308
+ */
309
+ interface Timestamps {
310
+ createdAt: Date;
311
+ updatedAt: Date;
312
+ }
313
+ /**
314
+ * Object definition - Represents a database table/entity
315
+ */
316
+ interface ObjectDefinition {
317
+ id?: Uuid;
318
+ name: string;
319
+ label: string;
320
+ description?: string;
321
+ icon?: IconName;
322
+ /**
323
+ * Name of the text attribute used as the object's title/display name.
324
+ * This attribute is used to represent the record in lists, relations, etc.
325
+ * Must reference an existing text attribute.
326
+ */
327
+ titleAttribute: string;
328
+ attributes: Attribute[];
329
+ system?: boolean;
330
+ metadata?: Record<string, unknown>;
331
+ }
332
+ /**
333
+ * Links an attribute to an object
334
+ */
335
+ interface ObjectAttribute {
336
+ objectId: Uuid;
337
+ attributeId: Uuid;
338
+ order?: number;
339
+ required?: boolean;
340
+ }
341
+ /**
342
+ * Completion status of a record based on data completeness.
343
+ *
344
+ * - `draft`: Record is missing one or more required attribute values.
345
+ * Can be saved but is considered incomplete.
346
+ * - `complete`: All required attribute values are present and valid.
347
+ * Record is ready for use.
348
+ *
349
+ * This is different from workflow status (e.g., "pending", "approved").
350
+ * Completion status is computed dynamically based on the object schema.
351
+ */
352
+ type CompletionStatus = "draft" | "complete";
353
+ /**
354
+ * Record - Instance of an Object (a row in the database)
355
+ */
356
+ interface ObjectRecord extends Timestamps {
357
+ id: Uuid;
358
+ objectId: Uuid;
359
+ /**
360
+ * Completion status of the record.
361
+ * - `draft`: Missing required values, record is incomplete
362
+ * - `complete`: All required values present and valid
363
+ *
364
+ * Computed dynamically based on the object's schema.
365
+ */
366
+ completionStatus: CompletionStatus;
367
+ values: Record<string, unknown>;
368
+ }
369
+
370
+ /**
371
+ * Storage provider type
372
+ */
373
+ type StorageProvider = "s3" | "gcs" | "azure" | "local" | "cloudflare-r2" | string;
374
+ /**
375
+ * File visibility level
376
+ */
377
+ type FileVisibility = "public" | "private" | "restricted";
378
+ /**
379
+ * File - Represents uploaded file metadata and storage info
380
+ *
381
+ * ARCHITECTURE:
382
+ * - Fixed table (no custom attributes)
383
+ * - Manages file storage, permissions, and metadata
384
+ * - uploadedBy links to user_profiles table
385
+ * - Supports soft delete via deletedAt
386
+ *
387
+ * @example
388
+ * ```typescript
389
+ * const file: File = {
390
+ * id: "file-123",
391
+ * tenantId: "tenant-456",
392
+ * name: "contract-2025.pdf",
393
+ * originalName: "Contract Acme Corp 2025.pdf",
394
+ * mimeType: "application/pdf",
395
+ * size: 2458624,
396
+ * storageProvider: "s3",
397
+ * storagePath: "tenants/456/files/2025/11/contract-2025.pdf",
398
+ * storageBucket: "my-app-files",
399
+ * url: "https://cdn.example.com/files/file-123",
400
+ * uploadedBy: "profile-789",
401
+ * folderPath: "/contracts/2025",
402
+ * tags: ["contract", "legal"],
403
+ * visibility: "restricted",
404
+ * allowedUsers: ["profile-789", "profile-456"],
405
+ * createdAt: new Date(),
406
+ * updatedAt: new Date(),
407
+ * };
408
+ * ```
409
+ */
410
+ interface File extends Timestamps {
411
+ id: Uuid;
412
+ tenantId: Uuid;
413
+ /**
414
+ * File name (sanitized for storage)
415
+ */
416
+ name: string;
417
+ /**
418
+ * Original file name (as uploaded by user)
419
+ */
420
+ originalName: string;
421
+ /**
422
+ * MIME type (e.g., "application/pdf", "image/jpeg")
423
+ */
424
+ mimeType: MimeType | string;
425
+ /**
426
+ * File size in bytes
427
+ */
428
+ size: number;
429
+ /**
430
+ * Storage provider (s3, gcs, azure, local, etc.)
431
+ */
432
+ storageProvider: StorageProvider;
433
+ /**
434
+ * Path in the storage bucket
435
+ */
436
+ storagePath: string;
437
+ /**
438
+ * Storage bucket name (if applicable)
439
+ */
440
+ storageBucket?: string;
441
+ /**
442
+ * Public or signed URL to access the file
443
+ */
444
+ url: string;
445
+ /**
446
+ * User who uploaded the file (FK to user_profiles)
447
+ */
448
+ uploadedBy: Uuid;
449
+ /**
450
+ * Folder path for organization (e.g., "/contracts/2025")
451
+ */
452
+ folderPath?: string;
453
+ /**
454
+ * Tags for search and categorization
455
+ */
456
+ tags?: string[];
457
+ /**
458
+ * File visibility level
459
+ * - public: Anyone with the URL can access
460
+ * - private: Only uploadedBy can access
461
+ * - restricted: Only specific users (allowedUsers) can access
462
+ */
463
+ visibility: FileVisibility;
464
+ /**
465
+ * List of user IDs authorized to access this file (if visibility = "restricted")
466
+ */
467
+ allowedUsers?: Uuid[];
468
+ /**
469
+ * Soft delete timestamp (null = not deleted)
470
+ */
471
+ deletedAt?: Date;
472
+ }
473
+ /**
474
+ * Data required to create a new file record
475
+ */
476
+ interface CreateFile {
477
+ tenantId: Uuid;
478
+ name: string;
479
+ originalName: string;
480
+ mimeType: MimeType | string;
481
+ size: number;
482
+ storageProvider: StorageProvider;
483
+ storagePath: string;
484
+ storageBucket?: string;
485
+ url: string;
486
+ uploadedBy: Uuid;
487
+ folderPath?: string;
488
+ tags?: string[];
489
+ visibility?: FileVisibility;
490
+ allowedUsers?: Uuid[];
491
+ }
492
+ /**
493
+ * Data for updating an existing file record
494
+ */
495
+ interface UpdateFile {
496
+ name?: string;
497
+ folderPath?: string;
498
+ tags?: string[];
499
+ visibility?: FileVisibility;
500
+ allowedUsers?: Uuid[];
501
+ }
502
+
503
+ /**
504
+ * Autocomplete suggestion from geocoding service
505
+ */
506
+ interface GeocodingSuggestion {
507
+ /** Unique identifier from the provider */
508
+ id: string;
509
+ /** Human-readable label for display */
510
+ label: string;
511
+ /** Structured location data */
512
+ location: Location;
513
+ /** Optional match score/confidence (0-1) */
514
+ score?: number;
515
+ /** Optional additional metadata from the provider */
516
+ metadata?: Record<string, unknown>;
517
+ }
518
+ /**
519
+ * Parameters for autocomplete search
520
+ */
521
+ interface GeocodingAutocompleteParams {
522
+ /** Search query */
523
+ query: string;
524
+ /** Restrict results to specific countries */
525
+ countries?: CountryIso3[];
526
+ /** Preferred language for results (ISO 639-1) */
527
+ language?: string;
528
+ /** Maximum number of results */
529
+ limit?: number;
530
+ /** Bias results toward a specific location */
531
+ biasLocation?: {
532
+ latitude: number;
533
+ longitude: number;
534
+ };
535
+ /** Session token for billing optimization (some providers) */
536
+ sessionToken?: string;
537
+ /**
538
+ * Level of address detail expected
539
+ * Adapters can use this to filter/optimize results
540
+ * - "full": Full address with street, city, postal code, etc.
541
+ * - "address": Street address without postal code
542
+ * - "city": City level only
543
+ * - "state": State/region level only
544
+ * - "country": Country level only
545
+ * - "coordinates": Only coordinates (lat/lng)
546
+ */
547
+ granularity?: LocationGranularity;
548
+ }
549
+ /**
550
+ * Parameters for reverse geocoding
551
+ */
552
+ interface ReverseGeocodingParams {
553
+ /** Latitude */
554
+ latitude: number;
555
+ /** Longitude */
556
+ longitude: number;
557
+ /** Preferred language for results */
558
+ language?: string;
559
+ }
560
+ /**
561
+ * Parameters for geocoding a structured address
562
+ */
563
+ interface GeocodingParams {
564
+ /** Structured address components */
565
+ address: Partial<Location>;
566
+ /** Preferred language for results */
567
+ language?: string;
568
+ }
569
+ /**
570
+ * Abstract geocoding adapter interface
571
+ * Implement this interface for different geocoding providers
572
+ *
573
+ * @example Google Maps implementation
574
+ * ```typescript
575
+ * class GoogleMapsGeocodingAdapter implements GeocodingAdapter {
576
+ * async autocomplete(params) {
577
+ * const response = await fetch(
578
+ * `https://maps.googleapis.com/maps/api/place/autocomplete/json?input=${params.query}&key=${this.apiKey}`
579
+ * );
580
+ * // Transform response to GeocodingSuggestion[]
581
+ * }
582
+ * }
583
+ * ```
584
+ *
585
+ * @example Mapbox implementation
586
+ * ```typescript
587
+ * class MapboxGeocodingAdapter implements GeocodingAdapter {
588
+ * async autocomplete(params) {
589
+ * const response = await fetch(
590
+ * `https://api.mapbox.com/geocoding/v5/mapbox.places/${params.query}.json?access_token=${this.token}`
591
+ * );
592
+ * // Transform response to GeocodingSuggestion[]
593
+ * }
594
+ * }
595
+ * ```
596
+ */
597
+ interface GeocodingAdapter {
598
+ /**
599
+ * Autocomplete address search
600
+ * Returns suggestions as the user types
601
+ */
602
+ autocomplete(params: GeocodingAutocompleteParams): Promise<GeocodingSuggestion[]>;
603
+ /**
604
+ * Reverse geocode coordinates to an address
605
+ * Optional - some providers may not support this
606
+ */
607
+ reverse?(params: ReverseGeocodingParams): Promise<GeocodingSuggestion | null>;
608
+ /**
609
+ * Geocode a structured address to coordinates
610
+ * Optional - some providers may not support this
611
+ */
612
+ geocode?(params: GeocodingParams): Promise<GeocodingSuggestion | null>;
613
+ }
614
+ /**
615
+ * No-op geocoding adapter
616
+ * Returns empty results when no geocoding provider is configured
617
+ */
618
+ declare class NoopGeocodingAdapter implements GeocodingAdapter {
619
+ autocomplete(): Promise<GeocodingSuggestion[]>;
620
+ reverse(): Promise<null>;
621
+ geocode(): Promise<null>;
622
+ }
623
+
624
+ /**
625
+ * User role in the application
626
+ * Can be extended with custom roles as needed
627
+ */
628
+ type UserRole = "admin" | "member" | "guest" | string;
629
+ /**
630
+ * User status for account management
631
+ */
632
+ type UserStatus = "active" | "pending" | "inactive" | "suspended";
633
+ /**
634
+ * User Profile - Represents application user data (authorization)
635
+ *
636
+ * ARCHITECTURE:
637
+ * - authId links to external auth provider (Supabase, Clerk, Auth0, etc.)
638
+ * - email is denormalized from auth provider for performance
639
+ * - Auth provider handles authentication (passwords, sessions, OAuth)
640
+ * - This type handles authorization (roles, permissions, tenant membership)
641
+ *
642
+ * @example
643
+ * ```typescript
644
+ * const profile: UserProfile = {
645
+ * id: "profile-123",
646
+ * tenantId: "tenant-456",
647
+ * authId: "supabase-auth-uuid-789",
648
+ * email: "john@example.com",
649
+ * firstName: "John",
650
+ * lastName: "Doe",
651
+ * role: "admin",
652
+ * status: "active",
653
+ * createdAt: new Date(),
654
+ * updatedAt: new Date(),
655
+ * };
656
+ * ```
657
+ */
658
+ interface UserProfile extends Timestamps {
659
+ id: Uuid;
660
+ tenantId: Uuid;
661
+ /**
662
+ * Link to external auth provider (Supabase auth.users.id, Clerk user ID, etc.)
663
+ * This is the bridge between authentication (provider) and authorization (your app)
664
+ */
665
+ authId: string;
666
+ /**
667
+ * Email address (denormalized from auth provider)
668
+ * Allows efficient querying and filtering without hitting auth provider API
669
+ */
670
+ email: string;
671
+ /**
672
+ * User's first name
673
+ */
674
+ firstName?: string;
675
+ /**
676
+ * User's last name
677
+ */
678
+ lastName?: string;
679
+ /**
680
+ * Avatar/profile picture URL
681
+ */
682
+ avatarUrl?: string;
683
+ /**
684
+ * User role for authorization
685
+ * Common values: "admin", "member", "guest"
686
+ * Can be extended with custom roles
687
+ */
688
+ role: UserRole;
689
+ /**
690
+ * Account status
691
+ * - active: Normal user, full access
692
+ * - pending: Awaiting activation/approval
693
+ * - inactive: Deactivated account
694
+ * - suspended: Temporarily blocked
695
+ */
696
+ status: UserStatus;
697
+ /**
698
+ * Last login timestamp (updated on each successful auth)
699
+ */
700
+ lastLoginAt?: Date;
701
+ }
702
+ /**
703
+ * Data required to create a new user profile
704
+ */
705
+ interface CreateUserProfile {
706
+ tenantId: Uuid;
707
+ authId: string;
708
+ email: string;
709
+ firstName?: string;
710
+ lastName?: string;
711
+ avatarUrl?: string;
712
+ role?: UserRole;
713
+ status?: UserStatus;
714
+ }
715
+ /**
716
+ * Data for updating an existing user profile
717
+ */
718
+ interface UpdateUserProfile {
719
+ firstName?: string;
720
+ lastName?: string;
721
+ avatarUrl?: string;
722
+ role?: UserRole;
723
+ status?: UserStatus;
724
+ lastLoginAt?: Date;
725
+ }
726
+
727
+ /**
728
+ * Field definition within a form group
729
+ */
730
+ interface Field {
731
+ /** Attribute name to display */
732
+ attribute: string;
733
+ /** Grid span (1-12 columns) */
734
+ span?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
735
+ /** Override label for this view */
736
+ label?: string;
737
+ /** Force read-only display */
738
+ readOnly?: boolean;
739
+ }
740
+ /**
741
+ * Group of fields for organizing forms
742
+ */
743
+ interface Group {
744
+ id: string;
745
+ label: string;
746
+ description?: string;
747
+ fields: Field[];
748
+ collapsible?: boolean;
749
+ collapsed?: boolean;
750
+ order?: number;
751
+ }
752
+ type TabType = "form" | "table" | "custom";
753
+ /**
754
+ * Base properties shared by all tab types
755
+ */
756
+ interface BaseTab {
757
+ id: string;
758
+ name: string;
759
+ label: string;
760
+ icon?: IconName;
761
+ order?: number;
762
+ /** If true, tab is defined by developer (protected) */
763
+ system?: boolean;
764
+ }
765
+ /**
766
+ * Form tab - displays attributes organized in groups
767
+ */
768
+ interface FormTab extends BaseTab {
769
+ type: "form";
770
+ groups: Group[];
771
+ }
772
+ /**
773
+ * Table tab - displays records from a relation attribute
774
+ */
775
+ interface TableTab extends BaseTab {
776
+ type: "table";
777
+ /** Name of the relation attribute */
778
+ relation: string;
779
+ /** Columns to display (attribute names from target object) */
780
+ columns: string[];
781
+ /** Allow creating new records */
782
+ allowCreate?: boolean;
783
+ /** Allow inline editing */
784
+ allowEdit?: boolean;
785
+ /** Allow deleting records */
786
+ allowDelete?: boolean;
787
+ /** Default filters */
788
+ filters?: Record<string, unknown>;
789
+ /** Default sort */
790
+ sort?: {
791
+ field: string;
792
+ order: "asc" | "desc";
793
+ };
794
+ }
795
+ /**
796
+ * Custom tab - renders a developer-defined component
797
+ */
798
+ interface CustomTab extends BaseTab {
799
+ type: "custom";
800
+ /** Component identifier to render */
801
+ component: string;
802
+ /** Props to pass to the component */
803
+ props?: Record<string, unknown>;
804
+ }
805
+ /**
806
+ * Union of all tab types
807
+ */
808
+ type Tab = FormTab | TableTab | CustomTab;
809
+ /**
810
+ * View definition - organizes object attributes into tabs/pages
811
+ *
812
+ * @example
813
+ * ```typescript
814
+ * const companyView: ViewDefinition = {
815
+ * name: "detail",
816
+ * label: "Company Detail",
817
+ * object: "companies",
818
+ * tabs: [
819
+ * { type: "form", name: "general", label: "Info", groups: [...] },
820
+ * { type: "table", name: "contacts", label: "Contacts", relation: "contacts", columns: [...] }
821
+ * ],
822
+ * default: true,
823
+ * system: true
824
+ * };
825
+ * ```
826
+ */
827
+ interface ViewDefinition {
828
+ id?: Uuid;
829
+ /** Technical name (kebab-case) */
830
+ name: string;
831
+ /** Display label */
832
+ label: string;
833
+ /** Description */
834
+ description?: string;
835
+ /** Icon */
836
+ icon?: IconName;
837
+ /** Object this view belongs to (object name) */
838
+ object: string;
839
+ /** Tabs in this view */
840
+ tabs: Tab[];
841
+ /** Default view for this object */
842
+ default?: boolean;
843
+ /** System view (defined by developer, protected) */
844
+ system?: boolean;
845
+ /** Extensible metadata */
846
+ metadata?: Record<string, unknown>;
847
+ }
848
+ /**
849
+ * Check if a tab is a form tab
850
+ */
851
+ declare function isFormTab(tab: Tab): tab is FormTab;
852
+ /**
853
+ * Check if a tab is a table tab
854
+ */
855
+ declare function isTableTab(tab: Tab): tab is TableTab;
856
+ /**
857
+ * Check if a tab is a custom tab
858
+ */
859
+ declare function isCustomTab(tab: Tab): tab is CustomTab;
860
+
861
+ /**
862
+ * Registry for native objects defined in code
863
+ * Native objects are system objects that cannot be deleted/modified by clients
864
+ * They are defined by developers and synced to the database at startup
865
+ */
866
+ declare class NativeObjectRegistryClass {
867
+ private objects;
868
+ /**
869
+ * Register one or more native objects
870
+ * Auto-builds if ObjectBuilder is passed instead of ObjectDefinition
871
+ * @param objects - Single object/builder or array of objects/builders to register
872
+ * @returns this (for chaining)
873
+ * @throws Error if object is invalid or already registered
874
+ *
875
+ * @example
876
+ * ```typescript
877
+ * // No .build() needed - registry auto-builds!
878
+ * const PRODUCT = object({ id: "obj-product", name: "products", label: "Product" })
879
+ * .system()
880
+ * .attribute(text({ id: "attr-name", name: "name", label: "Name" }));
881
+ *
882
+ * registry.register(PRODUCT); // ← Auto-builds here
883
+ *
884
+ * // Can still explicitly .build() if you want
885
+ * registry.register(PRODUCT.build());
886
+ *
887
+ * // Register multiple
888
+ * registry.register([PRODUCT, ORDER, CUSTOMER]);
889
+ * ```
890
+ */
891
+ register(objects: ObjectDefinition | ObjectDefinition[] | {
892
+ build: () => ObjectDefinition;
893
+ } | Array<{
894
+ build: () => ObjectDefinition;
895
+ }>): this;
896
+ /**
897
+ * Validate and register a single object
898
+ * @internal
899
+ */
900
+ private validateAndRegister;
901
+ /**
902
+ * Get a native object by its name
903
+ * @param name - The object name
904
+ * @returns The object definition or undefined if not found
905
+ *
906
+ * @example
907
+ * ```typescript
908
+ * const product = registry.getByName("products");
909
+ * if (product) {
910
+ * console.log(product.label); // "Product"
911
+ * }
912
+ * ```
913
+ */
914
+ getByName(name: string): ObjectDefinition | undefined;
915
+ /**
916
+ * Get a native object or throw if not found
917
+ * @param name - The object name
918
+ * @returns The object definition
919
+ * @throws Error if not found
920
+ */
921
+ getByNameOrThrow(name: string): ObjectDefinition;
922
+ /**
923
+ * Get all registered native objects
924
+ * @returns Array of all registered object definitions
925
+ */
926
+ getAll(): ObjectDefinition[];
927
+ /**
928
+ * Get all registered native object names
929
+ * @returns Array of object names
930
+ */
931
+ listNames(): string[];
932
+ /**
933
+ * Check if a native object is registered
934
+ * @param name - The object name
935
+ * @returns true if registered, false otherwise
936
+ */
937
+ has(name: string): boolean;
938
+ /**
939
+ * Get the number of registered objects
940
+ */
941
+ get size(): number;
942
+ /**
943
+ * Clear all registered objects (useful for testing)
944
+ * @internal
945
+ */
946
+ clear(): void;
947
+ /**
948
+ * Get registry summary for debugging
949
+ */
950
+ summary(): string;
951
+ /**
952
+ * Log registry summary to console
953
+ */
954
+ debug(): void;
955
+ }
956
+ /**
957
+ * Singleton instance of the registry
958
+ * Use this to register and retrieve native objects
959
+ *
960
+ * @example
961
+ * ```typescript
962
+ * import { registry } from "@andyoucreate/schema";
963
+ *
964
+ * // Register objects
965
+ * registry.register([PRODUCT, ORDER, CUSTOMER]);
966
+ *
967
+ * // Get object by name
968
+ * const product = registry.getByName("products");
969
+ *
970
+ * // List all
971
+ * console.log(registry.listNames()); // ["products", "orders", ...]
972
+ *
973
+ * // Debug
974
+ * registry.debug();
975
+ * ```
976
+ */
977
+ declare const registry: NativeObjectRegistryClass;
978
+
979
+ /**
980
+ * Registry for native view definitions
981
+ *
982
+ * Views registered here are considered "system" views, defined by the developer.
983
+ * They are protected from modification by end-users and synced to the database
984
+ * at application startup.
985
+ *
986
+ * @example
987
+ * ```typescript
988
+ * import { view, group, viewRegistry } from "@andyoucreate/schema";
989
+ *
990
+ * const COMPANY_DETAIL = view("detail", "Detail")
991
+ * .for("companies")
992
+ * .system()
993
+ * .tab("general", "Info")
994
+ * .form(group("main", "Main").fields("name", "status"))
995
+ * .build();
996
+ *
997
+ * viewRegistry.register(COMPANY_DETAIL);
998
+ * ```
999
+ */
1000
+ declare class ViewRegistry {
1001
+ private views;
1002
+ private byObject;
1003
+ /**
1004
+ * Register a native view
1005
+ * @param viewOrViews - Single view or array of views
1006
+ * @throws Error if view is not marked as system
1007
+ * @throws Error if view with same name already exists for the object
1008
+ */
1009
+ register(viewOrViews: ViewDefinition | ViewDefinition[]): this;
1010
+ private registerSingle;
1011
+ /**
1012
+ * Get all views for an object
1013
+ */
1014
+ getByObjectName(objectName: string): ViewDefinition[];
1015
+ /**
1016
+ * Get a specific view by object and view name
1017
+ */
1018
+ get(objectName: string, viewName: string): ViewDefinition | undefined;
1019
+ /**
1020
+ * Get a view or throw if not found
1021
+ */
1022
+ getOrThrow(objectName: string, viewName: string): ViewDefinition;
1023
+ /**
1024
+ * Get all registered views
1025
+ */
1026
+ getAll(): ViewDefinition[];
1027
+ /**
1028
+ * Check if a view exists
1029
+ */
1030
+ has(objectName: string, viewName: string): boolean;
1031
+ /**
1032
+ * Check if any views exist for an object
1033
+ */
1034
+ hasObject(objectName: string): boolean;
1035
+ /**
1036
+ * Get number of registered views
1037
+ */
1038
+ get size(): number;
1039
+ /**
1040
+ * List all object names that have views
1041
+ */
1042
+ listObjectNames(): string[];
1043
+ /**
1044
+ * Get default view for an object (if any)
1045
+ */
1046
+ getDefault(objectName: string): ViewDefinition | undefined;
1047
+ /**
1048
+ * Clear all registered views (for testing)
1049
+ */
1050
+ clear(): void;
1051
+ /**
1052
+ * Generate summary string for debugging
1053
+ */
1054
+ summary(): string;
1055
+ /**
1056
+ * Log summary to console
1057
+ */
1058
+ debug(): void;
1059
+ private makeKey;
1060
+ }
1061
+ /**
1062
+ * Global registry for native views
1063
+ */
1064
+ declare const viewRegistry: ViewRegistry;
1065
+
1066
+ /**
1067
+ * Create a Zod schema for a text attribute
1068
+ */
1069
+ declare function createTextValidator(attr: TextAttribute): z.ZodString;
1070
+ /**
1071
+ * Create a Zod schema for a number attribute
1072
+ */
1073
+ declare function createNumberValidator(attr: NumberAttribute): z.ZodNumber;
1074
+ /**
1075
+ * Create a Zod schema for a checkbox attribute
1076
+ */
1077
+ declare function createCheckboxValidator(_attr: CheckboxAttribute): z.ZodBoolean;
1078
+ /**
1079
+ * Create a Zod schema for a date attribute
1080
+ */
1081
+ declare function createDateValidator(attr: DateAttribute): z.ZodString;
1082
+ /**
1083
+ * Create a Zod schema for a phone attribute
1084
+ */
1085
+ declare function createPhoneValidator(_attr: PhoneAttribute): z.ZodType<{
1086
+ countryCode: string;
1087
+ phoneNumber: string;
1088
+ }>;
1089
+ /**
1090
+ * Create a Zod schema for a currency attribute
1091
+ */
1092
+ declare function createCurrencyValidator(_attr: CurrencyAttribute): z.ZodType<{
1093
+ code: string;
1094
+ value: number;
1095
+ }>;
1096
+ /**
1097
+ * Create a Zod schema for a status attribute
1098
+ */
1099
+ declare function createStatusValidator(attr: StatusAttribute): z.ZodEnum<[string, ...string[]]>;
1100
+ /**
1101
+ * Create a Zod schema for a select attribute
1102
+ */
1103
+ declare function createSelectValidator(attr: SelectAttribute): z.ZodEnum<[string, ...string[]]>;
1104
+ /**
1105
+ * Create a Zod schema for a multiselect attribute
1106
+ */
1107
+ declare function createMultiselectValidator(attr: MultiselectAttribute): z.ZodArray<z.ZodEnum<[string, ...string[]]>>;
1108
+ /**
1109
+ * Create a Zod schema for a location attribute
1110
+ */
1111
+ type LocationShape = {
1112
+ address?: string;
1113
+ address2?: string;
1114
+ city?: string;
1115
+ state?: string;
1116
+ postalCode?: string;
1117
+ country?: string;
1118
+ latitude?: number;
1119
+ longitude?: number;
1120
+ };
1121
+ declare function createLocationValidator(_attr: LocationAttribute): z.ZodType<LocationShape>;
1122
+ /**
1123
+ * Create a Zod schema for a timestamp attribute
1124
+ */
1125
+ declare function createTimestampValidator(_attr: TimestampAttribute): z.ZodNumber;
1126
+ /**
1127
+ * Create a Zod schema for a file attribute
1128
+ */
1129
+ declare function createFileValidator(_attr: FileAttribute): z.ZodString;
1130
+ /**
1131
+ * Create a Zod schema for a user attribute
1132
+ */
1133
+ declare function createUserValidator(_attr: UserAttribute): z.ZodString;
1134
+ /**
1135
+ * Create a Zod schema for a single relation attribute (cardinality: "one")
1136
+ */
1137
+ declare function createSingleRelationValidator(attr: SingleRelationAttribute): z.ZodUnion<[z.ZodString, z.ZodNull]>;
1138
+ /**
1139
+ * Create a Zod schema for a multi relation attribute (cardinality: "many")
1140
+ */
1141
+ declare function createMultiRelationValidator(attr: MultiRelationAttribute): z.ZodArray<z.ZodString>;
1142
+ /**
1143
+ * Create a Zod schema for a relation attribute
1144
+ * Dispatches to single or multi validator based on cardinality
1145
+ */
1146
+ declare function createRelationValidator(attr: RelationAttribute): z.ZodUnion<[z.ZodString, z.ZodNull]> | z.ZodArray<z.ZodString>;
1147
+ /**
1148
+ * Create a Zod schema for a rating attribute
1149
+ */
1150
+ declare function createRatingValidator(attr: RatingAttribute): z.ZodNumber;
1151
+ /**
1152
+ * Create a Zod schema for any attribute type
1153
+ */
1154
+ declare function createAttributeValidator(attr: Attribute): z.ZodTypeAny;
1155
+ /**
1156
+ * Create a Zod schema for an entire object
1157
+ */
1158
+ declare function createObjectValidator(objectDef: ObjectDefinition): z.ZodType<Record<string, unknown>>;
1159
+ /**
1160
+ * Validation result
1161
+ */
1162
+ interface ValidationResult {
1163
+ success: boolean;
1164
+ data?: Record<string, unknown>;
1165
+ errors?: Array<{
1166
+ path: string[];
1167
+ message: string;
1168
+ }>;
1169
+ }
1170
+ /**
1171
+ * Validate data against an attribute schema
1172
+ */
1173
+ declare function validateAttribute(attr: Attribute, value: unknown): ValidationResult;
1174
+ /**
1175
+ * Validate data against an object schema
1176
+ */
1177
+ declare function validateObject(objectDef: ObjectDefinition, data: Record<string, unknown>): ValidationResult;
1178
+ /**
1179
+ * Validate and throw if invalid
1180
+ */
1181
+ declare function validateObjectOrThrow(objectDef: ObjectDefinition, data: Record<string, unknown>): Record<string, unknown>;
1182
+ /**
1183
+ * Create a Zod schema for draft validation.
1184
+ * All attributes become optional, but provided values are still validated.
1185
+ */
1186
+ declare function createDraftValidator(objectDef: ObjectDefinition): z.ZodType<Record<string, unknown>>;
1187
+ /**
1188
+ * Validate data in draft mode.
1189
+ * - All attributes are treated as optional (no required validation)
1190
+ * - Provided values are still validated for format/type correctness
1191
+ *
1192
+ * Use this when creating records that may be incomplete (drafts).
1193
+ *
1194
+ * @example
1195
+ * ```typescript
1196
+ * const result = validateDraft(PRODUCT, { name: "Draft" });
1197
+ * // → success even if "price" is required but missing
1198
+ *
1199
+ * const result2 = validateDraft(PRODUCT, { price: -10 });
1200
+ * // → fails because price must be >= 0 (format validation still applies)
1201
+ * ```
1202
+ */
1203
+ declare function validateDraft(objectDef: ObjectDefinition, data: Record<string, unknown>): ValidationResult;
1204
+ /**
1205
+ * Validate draft data and throw if format validation fails.
1206
+ */
1207
+ declare function validateDraftOrThrow(objectDef: ObjectDefinition, data: Record<string, unknown>): Record<string, unknown>;
1208
+ /**
1209
+ * Get the list of required attributes that are missing values.
1210
+ *
1211
+ * @example
1212
+ * ```typescript
1213
+ * const missing = getMissingRequiredAttributes(PRODUCT, { name: "Test" });
1214
+ * // → [priceAttribute, statusAttribute] if price and status are required but missing
1215
+ * ```
1216
+ */
1217
+ declare function getMissingRequiredAttributes(objectDef: ObjectDefinition, data: Record<string, unknown>): Attribute[];
1218
+ /**
1219
+ * Check if a record is complete (all required attributes have valid values).
1220
+ *
1221
+ * @returns `true` if all required values are present and valid, `false` otherwise
1222
+ */
1223
+ declare function isRecordComplete(objectDef: ObjectDefinition, data: Record<string, unknown>): boolean;
1224
+ /**
1225
+ * Compute the completion status of a record based on its data.
1226
+ *
1227
+ * - `"complete"`: All required values are present and valid
1228
+ * - `"draft"`: One or more required values are missing or invalid
1229
+ *
1230
+ * This function is used to dynamically determine the status when
1231
+ * creating or updating records.
1232
+ *
1233
+ * @example
1234
+ * ```typescript
1235
+ * const status = computeRecordStatus(PRODUCT, {
1236
+ * name: "Nike Air Max",
1237
+ * price: 129.99,
1238
+ * status: "active"
1239
+ * });
1240
+ * // → "complete"
1241
+ *
1242
+ * const status2 = computeRecordStatus(PRODUCT, { name: "Draft Product" });
1243
+ * // → "draft" (missing required fields)
1244
+ * ```
1245
+ */
1246
+ declare function computeRecordStatus(objectDef: ObjectDefinition, data: Record<string, unknown>): CompletionStatus;
1247
+
1248
+ /**
1249
+ * Object as stored in database (metadata)
1250
+ */
1251
+ interface DBObject extends Timestamps {
1252
+ id: Uuid;
1253
+ tenantId: TenantId;
1254
+ name: string;
1255
+ label: string;
1256
+ description?: string;
1257
+ icon?: IconName;
1258
+ system: boolean;
1259
+ metadata?: Record<string, unknown>;
1260
+ }
1261
+ interface CreateDBObject {
1262
+ tenantId: TenantId;
1263
+ name: string;
1264
+ label: string;
1265
+ description?: string;
1266
+ icon?: IconName;
1267
+ system?: boolean;
1268
+ metadata?: Record<string, unknown>;
1269
+ }
1270
+ interface UpdateDBObject {
1271
+ label?: string;
1272
+ description?: string;
1273
+ icon?: IconName;
1274
+ metadata?: Record<string, unknown>;
1275
+ }
1276
+ interface UpsertDBObject extends CreateDBObject {
1277
+ system: boolean;
1278
+ }
1279
+ /**
1280
+ * Attribute as stored in database (metadata)
1281
+ */
1282
+ interface DBAttribute extends Timestamps {
1283
+ id: Uuid;
1284
+ objectId: Uuid;
1285
+ name: string;
1286
+ label: string;
1287
+ type: AttributeType;
1288
+ description?: string;
1289
+ icon?: IconName;
1290
+ system: boolean;
1291
+ required: boolean;
1292
+ unique: boolean;
1293
+ order: number;
1294
+ hidden?: boolean;
1295
+ archived?: boolean;
1296
+ deprecated?: boolean;
1297
+ defaultValue?: unknown;
1298
+ config: Record<string, unknown>;
1299
+ }
1300
+ interface CreateDBAttribute {
1301
+ objectId: Uuid;
1302
+ name: string;
1303
+ label: string;
1304
+ type: AttributeType;
1305
+ description?: string;
1306
+ icon?: IconName;
1307
+ system?: boolean;
1308
+ required?: boolean;
1309
+ unique?: boolean;
1310
+ order?: number;
1311
+ hidden?: boolean;
1312
+ archived?: boolean;
1313
+ deprecated?: boolean;
1314
+ defaultValue?: unknown;
1315
+ config?: Record<string, unknown>;
1316
+ }
1317
+ interface UpdateDBAttribute {
1318
+ label?: string;
1319
+ description?: string;
1320
+ icon?: IconName;
1321
+ required?: boolean;
1322
+ order?: number;
1323
+ hidden?: boolean;
1324
+ archived?: boolean;
1325
+ deprecated?: boolean;
1326
+ defaultValue?: unknown;
1327
+ config?: Record<string, unknown>;
1328
+ }
1329
+ interface UpsertDBAttribute extends CreateDBAttribute {
1330
+ objectId: Uuid;
1331
+ name: string;
1332
+ }
1333
+
1334
+ /**
1335
+ * Object record creation data
1336
+ */
1337
+ interface CreateObjectRecord {
1338
+ tenantId: TenantId;
1339
+ objectId: Uuid;
1340
+ data: Record<string, unknown>;
1341
+ /**
1342
+ * Completion status of the record.
1343
+ * - `draft`: Record is incomplete (missing required values)
1344
+ * - `complete`: All required values are present and valid
1345
+ */
1346
+ completionStatus: "draft" | "complete";
1347
+ }
1348
+ /**
1349
+ * Generic list options for pagination and sorting
1350
+ */
1351
+ interface ListOptions {
1352
+ limit?: number;
1353
+ offset?: number;
1354
+ orderBy?: string;
1355
+ orderDirection?: "asc" | "desc";
1356
+ }
1357
+ /**
1358
+ * Search options for full-text search
1359
+ */
1360
+ interface SearchOptions extends ListOptions {
1361
+ filters?: Record<string, unknown>;
1362
+ highlight?: boolean;
1363
+ }
1364
+ /**
1365
+ * Global search options
1366
+ */
1367
+ interface GlobalSearchOptions extends ListOptions {
1368
+ /**
1369
+ * Limit results to specific object names
1370
+ */
1371
+ objectNames?: string[];
1372
+ /**
1373
+ * Whether to include object metadata in results
1374
+ */
1375
+ includeObjectInfo?: boolean;
1376
+ }
1377
+ /**
1378
+ * Global search result item
1379
+ */
1380
+ interface GlobalSearchResultItem {
1381
+ objectId: string;
1382
+ objectName: string;
1383
+ objectLabel: string;
1384
+ recordId: string;
1385
+ values: Record<string, unknown>;
1386
+ completionStatus: "draft" | "complete";
1387
+ createdAt: Date;
1388
+ updatedAt: Date;
1389
+ }
1390
+ /**
1391
+ * File-specific list options
1392
+ */
1393
+ interface FileListOptions extends ListOptions {
1394
+ folderPath?: string;
1395
+ mimeType?: string;
1396
+ uploadedBy?: Uuid;
1397
+ includeDeleted?: boolean;
1398
+ }
1399
+ /**
1400
+ * View as stored in database
1401
+ */
1402
+ interface DBView extends Timestamps {
1403
+ id: Uuid;
1404
+ tenantId: TenantId;
1405
+ objectId?: Uuid;
1406
+ objectName: string;
1407
+ name: string;
1408
+ label: string;
1409
+ description?: string;
1410
+ icon?: IconName;
1411
+ tabs: Tab[];
1412
+ default: boolean;
1413
+ system: boolean;
1414
+ metadata?: Record<string, unknown>;
1415
+ }
1416
+ interface CreateDBView {
1417
+ tenantId: TenantId;
1418
+ objectId?: Uuid;
1419
+ objectName: string;
1420
+ name: string;
1421
+ label: string;
1422
+ description?: string;
1423
+ icon?: IconName;
1424
+ tabs: Tab[];
1425
+ default?: boolean;
1426
+ system?: boolean;
1427
+ metadata?: Record<string, unknown>;
1428
+ }
1429
+ interface UpdateDBView {
1430
+ label?: string;
1431
+ description?: string;
1432
+ icon?: IconName;
1433
+ tabs?: Tab[];
1434
+ default?: boolean;
1435
+ metadata?: Record<string, unknown>;
1436
+ }
1437
+ interface UpsertDBView {
1438
+ tenantId: TenantId;
1439
+ objectName: string;
1440
+ name: string;
1441
+ label: string;
1442
+ description?: string;
1443
+ icon?: IconName;
1444
+ tabs: Tab[];
1445
+ default?: boolean;
1446
+ system?: boolean;
1447
+ metadata?: Record<string, unknown>;
1448
+ }
1449
+ /**
1450
+ * Result of an operation
1451
+ */
1452
+ interface OperationResult<T = unknown> {
1453
+ success: boolean;
1454
+ data?: T;
1455
+ error?: {
1456
+ code: string;
1457
+ message: string;
1458
+ details?: Record<string, unknown>;
1459
+ };
1460
+ }
1461
+
1462
+ /**
1463
+ * Repository for objects table (metadata)
1464
+ */
1465
+ interface ObjectsRepository {
1466
+ /**
1467
+ * Find object by ID
1468
+ */
1469
+ findById(id: Uuid): Promise<DBObject | null>;
1470
+ /**
1471
+ * Find object by name and tenant
1472
+ */
1473
+ findByName(tenantId: TenantId, name: string): Promise<DBObject | null>;
1474
+ /**
1475
+ * Find system/native object by name (system=true, for sync)
1476
+ */
1477
+ findSystemByName(name: string): Promise<DBObject | null>;
1478
+ /**
1479
+ * Create object
1480
+ */
1481
+ create(data: CreateDBObject): Promise<DBObject>;
1482
+ /**
1483
+ * Update object
1484
+ */
1485
+ update(id: Uuid, data: Partial<UpdateDBObject>): Promise<DBObject>;
1486
+ /**
1487
+ * Delete object
1488
+ */
1489
+ delete(id: Uuid): Promise<void>;
1490
+ /**
1491
+ * List all objects for a tenant
1492
+ */
1493
+ list(tenantId: TenantId): Promise<DBObject[]>;
1494
+ /**
1495
+ * Upsert object (create or update based on nativeObjectId)
1496
+ */
1497
+ upsert(data: UpsertDBObject): Promise<DBObject>;
1498
+ }
1499
+ /**
1500
+ * Repository for attributes table (metadata)
1501
+ */
1502
+ interface AttributesRepository {
1503
+ /**
1504
+ * Find attribute by ID
1505
+ */
1506
+ findById(id: Uuid): Promise<DBAttribute | null>;
1507
+ /**
1508
+ * Find attributes by object ID
1509
+ */
1510
+ findByObjectId(objectId: Uuid): Promise<DBAttribute[]>;
1511
+ /**
1512
+ * Create attribute
1513
+ */
1514
+ create(data: CreateDBAttribute): Promise<DBAttribute>;
1515
+ /**
1516
+ * Update attribute
1517
+ */
1518
+ update(id: Uuid, data: Partial<UpdateDBAttribute>): Promise<DBAttribute>;
1519
+ /**
1520
+ * Delete attribute
1521
+ */
1522
+ delete(id: Uuid): Promise<void>;
1523
+ /**
1524
+ * Delete multiple attributes by names (for sync cleanup)
1525
+ */
1526
+ deleteByNames(objectId: Uuid, excludeNames: string[]): Promise<number>;
1527
+ /**
1528
+ * Upsert attribute (create or update based on objectId + name)
1529
+ */
1530
+ upsert(data: UpsertDBAttribute): Promise<DBAttribute>;
1531
+ }
1532
+ /**
1533
+ * Repository for user_profiles table
1534
+ */
1535
+ interface UserProfilesRepository {
1536
+ /**
1537
+ * Find user profile by ID
1538
+ */
1539
+ findById(id: Uuid): Promise<UserProfile | null>;
1540
+ /**
1541
+ * Find user profile by auth ID (external auth provider)
1542
+ */
1543
+ findByAuthId(authId: string): Promise<UserProfile | null>;
1544
+ /**
1545
+ * Find user profile by email
1546
+ */
1547
+ findByEmail(tenantId: TenantId, email: string): Promise<UserProfile | null>;
1548
+ /**
1549
+ * Create user profile
1550
+ */
1551
+ create(data: CreateUserProfile): Promise<UserProfile>;
1552
+ /**
1553
+ * Update user profile
1554
+ */
1555
+ update(id: Uuid, data: UpdateUserProfile): Promise<UserProfile>;
1556
+ /**
1557
+ * Delete user profile
1558
+ */
1559
+ delete(id: Uuid): Promise<void>;
1560
+ /**
1561
+ * List all user profiles for a tenant
1562
+ */
1563
+ list(tenantId: TenantId, options?: ListOptions): Promise<UserProfile[]>;
1564
+ /**
1565
+ * Update last login timestamp
1566
+ */
1567
+ updateLastLogin(id: Uuid): Promise<void>;
1568
+ }
1569
+ /**
1570
+ * Repository for files table
1571
+ */
1572
+ interface FilesRepository {
1573
+ /**
1574
+ * Find file by ID
1575
+ */
1576
+ findById(id: Uuid): Promise<File | null>;
1577
+ /**
1578
+ * Create file
1579
+ */
1580
+ create(data: CreateFile): Promise<File>;
1581
+ /**
1582
+ * Update file
1583
+ */
1584
+ update(id: Uuid, data: UpdateFile): Promise<File>;
1585
+ /**
1586
+ * Delete file (soft delete)
1587
+ */
1588
+ delete(id: Uuid): Promise<void>;
1589
+ /**
1590
+ * Hard delete file (permanent)
1591
+ */
1592
+ hardDelete(id: Uuid): Promise<void>;
1593
+ /**
1594
+ * List files for a tenant
1595
+ */
1596
+ list(tenantId: TenantId, options?: FileListOptions): Promise<File[]>;
1597
+ /**
1598
+ * Find files by folder path
1599
+ */
1600
+ findByFolder(tenantId: TenantId, folderPath: string): Promise<File[]>;
1601
+ /**
1602
+ * Find files by uploader
1603
+ */
1604
+ findByUploader(uploadedBy: Uuid): Promise<File[]>;
1605
+ }
1606
+ /**
1607
+ * Repository for object_records table (unified JSONB)
1608
+ */
1609
+ interface ObjectRecordsRepository {
1610
+ /**
1611
+ * Find record by ID
1612
+ */
1613
+ findById(id: Uuid): Promise<ObjectRecord | null>;
1614
+ /**
1615
+ * Create record
1616
+ */
1617
+ create(data: CreateObjectRecord): Promise<ObjectRecord>;
1618
+ /**
1619
+ * Update record
1620
+ */
1621
+ update(id: Uuid, data: Partial<Record<string, unknown>>): Promise<ObjectRecord>;
1622
+ /**
1623
+ * Delete record
1624
+ */
1625
+ delete(id: Uuid): Promise<void>;
1626
+ /**
1627
+ * List records for an object
1628
+ */
1629
+ list(tenantId: TenantId, objectId: Uuid, options?: ListOptions): Promise<{
1630
+ records: ObjectRecord[];
1631
+ total: number;
1632
+ }>;
1633
+ /**
1634
+ * Search records using PostgreSQL full-text search
1635
+ */
1636
+ search(tenantId: TenantId, objectId: Uuid, query: string, options?: SearchOptions): Promise<{
1637
+ records: ObjectRecord[];
1638
+ total: number;
1639
+ }>;
1640
+ /**
1641
+ * Global search across all object records for a tenant
1642
+ * Searches in all objects or a subset specified by objectNames
1643
+ */
1644
+ globalSearch(tenantId: TenantId, query: string, options?: GlobalSearchOptions): Promise<{
1645
+ results: GlobalSearchResultItem[];
1646
+ total: number;
1647
+ }>;
1648
+ }
1649
+ /**
1650
+ * Repository for views table
1651
+ */
1652
+ interface ViewsRepository {
1653
+ /**
1654
+ * Find view by ID
1655
+ */
1656
+ findById(id: Uuid): Promise<DBView | null>;
1657
+ /**
1658
+ * Find view by name for an object and tenant
1659
+ */
1660
+ findByName(tenantId: TenantId, objectName: string, viewName: string): Promise<DBView | null>;
1661
+ /**
1662
+ * Find all views for an object and tenant
1663
+ */
1664
+ findByObjectName(tenantId: TenantId, objectName: string): Promise<DBView[]>;
1665
+ /**
1666
+ * Find all views for a tenant
1667
+ */
1668
+ findAllForTenant(tenantId: TenantId): Promise<DBView[]>;
1669
+ /**
1670
+ * Find system view by name (for sync)
1671
+ */
1672
+ findSystemByName(objectName: string, viewName: string): Promise<DBView | null>;
1673
+ /**
1674
+ * Find all system views for an object
1675
+ */
1676
+ findSystemByObjectName(objectName: string): Promise<DBView[]>;
1677
+ /**
1678
+ * Create view
1679
+ */
1680
+ create(data: CreateDBView): Promise<DBView>;
1681
+ /**
1682
+ * Update view
1683
+ */
1684
+ update(id: Uuid, data: Partial<UpdateDBView>): Promise<DBView>;
1685
+ /**
1686
+ * Delete view
1687
+ */
1688
+ delete(id: Uuid): Promise<void>;
1689
+ /**
1690
+ * Delete views not in the list (for sync cleanup)
1691
+ * @returns Number of deleted views
1692
+ */
1693
+ deleteNotIn(objectName: string, keepViewNames: string[]): Promise<number>;
1694
+ /**
1695
+ * Upsert view (create or update based on objectName + name)
1696
+ */
1697
+ upsert(data: UpsertDBView): Promise<DBView>;
1698
+ }
1699
+
1700
+ /**
1701
+ * Generic database adapter interface
1702
+ * Any ORM (Drizzle, Prisma, Kysely, TypeORM) can implement this interface
1703
+ * to work with @andyoucreate/schema runtime services
1704
+ *
1705
+ * @example
1706
+ * ```typescript
1707
+ * // Drizzle implementation
1708
+ * import { createDrizzleAdapter } from "./adapters/drizzle";
1709
+ * import { db } from "./db";
1710
+ *
1711
+ * const adapter = createDrizzleAdapter(db);
1712
+ *
1713
+ * // Prisma implementation
1714
+ * import { createPrismaAdapter } from "./adapters/prisma";
1715
+ * import { prisma } from "./db";
1716
+ *
1717
+ * const adapter = createPrismaAdapter(prisma);
1718
+ * ```
1719
+ */
1720
+ interface DatabaseAdapter {
1721
+ objects: ObjectsRepository;
1722
+ attributes: AttributesRepository;
1723
+ views: ViewsRepository;
1724
+ userProfiles: UserProfilesRepository;
1725
+ files: FilesRepository;
1726
+ objectRecords: ObjectRecordsRepository;
1727
+ transaction<T>(callback: (adapter: DatabaseAdapter) => Promise<T>): Promise<T>;
1728
+ }
1729
+
1730
+ interface InternalObjectRecord extends ObjectRecord {
1731
+ tenantId: TenantId;
1732
+ }
1733
+ interface MockStores {
1734
+ objects: Map<Uuid, DBObject>;
1735
+ attributes: Map<Uuid, DBAttribute>;
1736
+ userProfiles: Map<Uuid, UserProfile>;
1737
+ files: Map<Uuid, File>;
1738
+ objectRecords: Map<Uuid, InternalObjectRecord>;
1739
+ views: Map<Uuid, DBView>;
1740
+ }
1741
+ /**
1742
+ * Create an in-memory mock adapter for testing and development
1743
+ *
1744
+ * This adapter stores all data in memory and is perfect for:
1745
+ * - Unit tests
1746
+ * - Integration tests
1747
+ * - Local development without a database
1748
+ * - Understanding the adapter interface
1749
+ *
1750
+ * @returns A DatabaseAdapter implementation using in-memory storage
1751
+ *
1752
+ * @example
1753
+ * ```typescript
1754
+ * import { createMockAdapter, RecordService } from "@andyoucreate/schema";
1755
+ *
1756
+ * // Create adapter
1757
+ * const adapter = createMockAdapter();
1758
+ *
1759
+ * // Use with services
1760
+ * const recordService = new RecordService(adapter, "tenant-123");
1761
+ *
1762
+ * // Create a record
1763
+ * const product = await recordService.createRecord("obj-product", {
1764
+ * name: "Nike Air Max",
1765
+ * price: 129.99
1766
+ * });
1767
+ *
1768
+ * // List records
1769
+ * const { records, total } = await recordService.listRecords("obj-product");
1770
+ * ```
1771
+ */
1772
+ declare function createMockAdapter(): DatabaseAdapter & {
1773
+ _stores: MockStores;
1774
+ reset(): void;
1775
+ };
1776
+
1777
+ /**
1778
+ * Service for managing files
1779
+ * Handles file metadata CRUD, permissions, and soft delete
1780
+ */
1781
+ declare class FileService {
1782
+ private adapter;
1783
+ private tenantId;
1784
+ constructor(adapter: DatabaseAdapter, tenantId: string);
1785
+ /**
1786
+ * Create a new file record (after upload to storage)
1787
+ *
1788
+ * @param data - File metadata
1789
+ * @returns Created file record
1790
+ *
1791
+ * @example
1792
+ * ```typescript
1793
+ * const service = new FileService(adapter, "tenant-123");
1794
+ *
1795
+ * // After uploading to S3
1796
+ * const file = await service.createFile({
1797
+ * tenantId: "tenant-123",
1798
+ * name: "contract-2025.pdf",
1799
+ * originalName: "Contract Acme Corp 2025.pdf",
1800
+ * mimeType: "application/pdf",
1801
+ * size: 2458624,
1802
+ * storageProvider: "s3",
1803
+ * storagePath: "tenants/123/files/2025/contract.pdf",
1804
+ * storageBucket: "my-app-files",
1805
+ * url: "https://cdn.example.com/files/file-123",
1806
+ * uploadedBy: "profile-456",
1807
+ * visibility: "private"
1808
+ * });
1809
+ * ```
1810
+ */
1811
+ createFile(data: CreateFile): Promise<File>;
1812
+ /**
1813
+ * Get file by ID
1814
+ */
1815
+ getFile(fileId: string): Promise<File | null>;
1816
+ /**
1817
+ * Get file by ID or throw
1818
+ */
1819
+ getFileOrThrow(fileId: string): Promise<File>;
1820
+ /**
1821
+ * Update file metadata
1822
+ *
1823
+ * @param fileId - File UUID
1824
+ * @param data - Data to update
1825
+ * @returns Updated file
1826
+ */
1827
+ updateFile(fileId: string, data: UpdateFile): Promise<File>;
1828
+ /**
1829
+ * Delete file (soft delete)
1830
+ *
1831
+ * @param fileId - File UUID
1832
+ * @param options - Delete options
1833
+ */
1834
+ deleteFile(fileId: string, options?: {
1835
+ hard?: boolean;
1836
+ checkOwnership?: boolean;
1837
+ userId?: string;
1838
+ }): Promise<void>;
1839
+ /**
1840
+ * List files for the tenant
1841
+ */
1842
+ listFiles(options?: FileListOptions): Promise<File[]>;
1843
+ /**
1844
+ * List files by folder
1845
+ */
1846
+ listFilesByFolder(folderPath: string): Promise<File[]>;
1847
+ /**
1848
+ * List files uploaded by a specific user
1849
+ */
1850
+ listFilesByUploader(uploadedBy: string): Promise<File[]>;
1851
+ /**
1852
+ * Change file visibility
1853
+ *
1854
+ * @param fileId - File UUID
1855
+ * @param visibility - New visibility level
1856
+ * @param allowedUsers - Users allowed to access (if restricted)
1857
+ */
1858
+ changeVisibility(fileId: string, visibility: "public" | "private" | "restricted", allowedUsers?: string[]): Promise<File>;
1859
+ /**
1860
+ * Grant access to a file for specific users
1861
+ *
1862
+ * @param fileId - File UUID
1863
+ * @param userIds - User IDs to grant access
1864
+ */
1865
+ grantAccess(fileId: string, userIds: string[]): Promise<File>;
1866
+ /**
1867
+ * Revoke access to a file for specific users
1868
+ *
1869
+ * @param fileId - File UUID
1870
+ * @param userIds - User IDs to revoke access
1871
+ */
1872
+ revokeAccess(fileId: string, userIds: string[]): Promise<File>;
1873
+ /**
1874
+ * Check if user has access to a file
1875
+ *
1876
+ * @param fileId - File UUID
1877
+ * @param userId - User ID to check
1878
+ * @returns true if user can access the file
1879
+ */
1880
+ canAccess(fileId: string, userId: string): Promise<boolean>;
1881
+ /**
1882
+ * Move file to different folder
1883
+ */
1884
+ moveToFolder(fileId: string, newFolderPath: string): Promise<File>;
1885
+ /**
1886
+ * Add tags to file
1887
+ */
1888
+ addTags(fileId: string, tags: string[]): Promise<File>;
1889
+ /**
1890
+ * Remove tags from file
1891
+ */
1892
+ removeTags(fileId: string, tags: string[]): Promise<File>;
1893
+ }
1894
+
1895
+ /**
1896
+ * Geocoding service for address autocomplete and geocoding operations
1897
+ *
1898
+ * @example
1899
+ * ```typescript
1900
+ * import { GeocodingService } from "@andyoucreate/schema";
1901
+ * import { GoogleMapsAdapter } from "./adapters/google-maps";
1902
+ *
1903
+ * const geocoding = new GeocodingService(new GoogleMapsAdapter({ apiKey: "..." }));
1904
+ *
1905
+ * const suggestions = await geocoding.autocomplete({
1906
+ * query: "40 Quai des Belges",
1907
+ * countries: ["FRA"],
1908
+ * limit: 5,
1909
+ * });
1910
+ * ```
1911
+ */
1912
+ declare class GeocodingService {
1913
+ private readonly adapter;
1914
+ constructor(adapter: GeocodingAdapter);
1915
+ /**
1916
+ * Search for address suggestions as the user types
1917
+ */
1918
+ autocomplete(params: GeocodingAutocompleteParams): Promise<GeocodingSuggestion[]>;
1919
+ /**
1920
+ * Reverse geocode coordinates to an address
1921
+ */
1922
+ reverse(params: ReverseGeocodingParams): Promise<GeocodingSuggestion | null>;
1923
+ /**
1924
+ * Geocode a structured address to coordinates
1925
+ */
1926
+ geocode(params: GeocodingParams): Promise<GeocodingSuggestion | null>;
1927
+ }
1928
+
1929
+ /**
1930
+ * Service for global search across all object records
1931
+ * Allows searching across all objects or a subset of objects for a tenant
1932
+ *
1933
+ * @example
1934
+ * ```typescript
1935
+ * const service = new GlobalSearchService(adapter, "tenant-123");
1936
+ *
1937
+ * // Search across all objects
1938
+ * const { results, total } = await service.search("nike");
1939
+ *
1940
+ * // Search only in specific objects
1941
+ * const { results, total } = await service.search("nike", {
1942
+ * objectNames: ["products", "orders"],
1943
+ * limit: 20
1944
+ * });
1945
+ * ```
1946
+ */
1947
+ declare class GlobalSearchService {
1948
+ private adapter;
1949
+ private tenantId;
1950
+ constructor(adapter: DatabaseAdapter, tenantId: string);
1951
+ /**
1952
+ * Search across all object records for the tenant
1953
+ *
1954
+ * @param query - Search query string
1955
+ * @param options - Search options (pagination, object filters)
1956
+ * @returns Matching records with object metadata and total count
1957
+ *
1958
+ * @example
1959
+ * ```typescript
1960
+ * // Basic search
1961
+ * const { results, total } = await service.search("nike air");
1962
+ *
1963
+ * // With pagination
1964
+ * const { results, total } = await service.search("nike", {
1965
+ * limit: 10,
1966
+ * offset: 20
1967
+ * });
1968
+ *
1969
+ * // Filter by object types
1970
+ * const { results, total } = await service.search("nike", {
1971
+ * objectNames: ["products", "orders"]
1972
+ * });
1973
+ * ```
1974
+ */
1975
+ search(query: string, options?: GlobalSearchOptions): Promise<{
1976
+ results: GlobalSearchResultItem[];
1977
+ total: number;
1978
+ }>;
1979
+ /**
1980
+ * Search and group results by object type
1981
+ *
1982
+ * @param query - Search query string
1983
+ * @param options - Search options
1984
+ * @returns Results grouped by object name
1985
+ */
1986
+ searchGrouped(query: string, options?: Omit<GlobalSearchOptions, "limit" | "offset">): Promise<{
1987
+ groups: Array<{
1988
+ objectName: string;
1989
+ objectLabel: string;
1990
+ results: GlobalSearchResultItem[];
1991
+ count: number;
1992
+ }>;
1993
+ total: number;
1994
+ }>;
1995
+ }
1996
+
1997
+ /**
1998
+ * Input for creating a custom object
1999
+ */
2000
+ interface CreateCustomObjectInput {
2001
+ name: string;
2002
+ label: string;
2003
+ description?: string;
2004
+ icon?: IconName;
2005
+ attributes?: (Attribute | {
2006
+ build: () => Attribute;
2007
+ })[];
2008
+ metadata?: Record<string, unknown>;
2009
+ }
2010
+ /**
2011
+ * Input for adding an attribute to an object
2012
+ */
2013
+ interface AddAttributeInput {
2014
+ name: string;
2015
+ label: string;
2016
+ type: AttributeType;
2017
+ required?: boolean;
2018
+ unique?: boolean;
2019
+ description?: string;
2020
+ placeholder?: string;
2021
+ icon?: IconName;
2022
+ defaultValue?: unknown;
2023
+ metadata?: Record<string, unknown>;
2024
+ [key: string]: unknown;
2025
+ }
2026
+ /**
2027
+ * Service for managing object schemas
2028
+ * Handles fusion of native objects (from registry) and custom objects (from database)
2029
+ */
2030
+ declare class ObjectSchemaService {
2031
+ private adapter;
2032
+ private nativeRegistry;
2033
+ constructor(adapter: DatabaseAdapter, nativeRegistry: typeof registry);
2034
+ /**
2035
+ * Create a new custom object
2036
+ * Validates name format and ensures system=false
2037
+ *
2038
+ * @param definition - Object definition (attributes can be raw definitions or builders)
2039
+ * @param tenantId - Tenant ID owning the object
2040
+ * @returns Created ObjectDefinition
2041
+ */
2042
+ createCustomObject(definition: CreateCustomObjectInput, tenantId: string): Promise<ObjectDefinition>;
2043
+ /**
2044
+ * Add a custom attribute to an existing object
2045
+ * Can be used on both custom and native objects
2046
+ * Attributes added via API are always custom (system=false)
2047
+ *
2048
+ * @param objectId - Object UUID from database
2049
+ * @param attribute - Attribute definition
2050
+ * @returns Created Attribute
2051
+ */
2052
+ addAttributeToObject(objectId: string, attribute: AddAttributeInput): Promise<Attribute>;
2053
+ /**
2054
+ * Update an attribute
2055
+ * Can only update custom attributes (system=false)
2056
+ *
2057
+ * @param attributeId - Attribute UUID
2058
+ * @param updates - Partial attribute updates
2059
+ * @returns Updated Attribute
2060
+ */
2061
+ updateAttribute(attributeId: string, updates: Partial<AddAttributeInput>): Promise<Attribute>;
2062
+ /**
2063
+ * Delete an attribute
2064
+ * Can only delete custom attributes (system=false)
2065
+ *
2066
+ * @param attributeId - Attribute UUID
2067
+ */
2068
+ deleteAttribute(attributeId: string): Promise<void>;
2069
+ /**
2070
+ * List attributes for an object
2071
+ *
2072
+ * @param objectId - Object UUID
2073
+ * @param options - Filter options
2074
+ * @returns List of attributes
2075
+ */
2076
+ listAttributes(objectId: string, options?: {
2077
+ systemOnly?: boolean;
2078
+ customOnly?: boolean;
2079
+ }): Promise<Attribute[]>;
2080
+ /**
2081
+ * Validate attribute name format (variable identifier)
2082
+ * @internal
2083
+ */
2084
+ private validateAttributeName;
2085
+ /**
2086
+ * Get complete object schema (system + custom attributes)
2087
+ * If object is native, merges registry definition with DB custom attributes
2088
+ * If object is custom, returns DB definition only
2089
+ *
2090
+ * @param objectId - Object UUID from database
2091
+ * @returns Complete ObjectDefinition with all attributes
2092
+ *
2093
+ * @example
2094
+ * ```typescript
2095
+ * const service = new ObjectSchemaService(adapter, registry);
2096
+ * const productSchema = await service.getObjectSchema("obj-123");
2097
+ *
2098
+ * console.log(productSchema.attributes); // System + custom attributes
2099
+ * ```
2100
+ */
2101
+ getObjectSchema(objectId: string): Promise<ObjectDefinition>;
2102
+ /**
2103
+ * Get object schema by name (for system/native objects)
2104
+ * @deprecated Use getObjectSchemaByNameForTenant for custom objects support
2105
+ */
2106
+ getObjectSchemaByName(name: string): Promise<ObjectDefinition>;
2107
+ /**
2108
+ * Get object schema by name for a tenant (supports both native and custom objects)
2109
+ */
2110
+ getObjectSchemaByNameForTenant(name: string, tenantId: string): Promise<ObjectDefinition>;
2111
+ /**
2112
+ * List all object schemas for a tenant
2113
+ */
2114
+ listObjectSchemas(tenantId: string): Promise<ObjectDefinition[]>;
2115
+ /**
2116
+ * Merge native object from registry with custom attributes from DB
2117
+ * @internal
2118
+ */
2119
+ private mergeNativeObject;
2120
+ /**
2121
+ * Convert DB object + attributes to ObjectDefinition
2122
+ * @internal
2123
+ */
2124
+ private convertDBObjectToDefinition;
2125
+ /**
2126
+ * Convert DB attribute to Attribute type
2127
+ * @internal
2128
+ */
2129
+ private convertDBAttributeToAttribute;
2130
+ }
2131
+
2132
+ /**
2133
+ * Service for managing object records (CRUD operations)
2134
+ * Handles validation, dispatch to correct table, and data consistency
2135
+ */
2136
+ declare class RecordService {
2137
+ private adapter;
2138
+ private tenantId;
2139
+ private schemaService;
2140
+ private relationService;
2141
+ constructor(adapter: DatabaseAdapter, tenantId: string);
2142
+ /**
2143
+ * Create a new record with validation
2144
+ *
2145
+ * @param objectId - Object UUID
2146
+ * @param data - Record data (attribute values)
2147
+ * @param options - Creation options
2148
+ * @returns Created record with computed completionStatus
2149
+ *
2150
+ * @example
2151
+ * ```typescript
2152
+ * const service = new RecordService(adapter, "tenant-123");
2153
+ *
2154
+ * // Create a complete record (strict validation)
2155
+ * const product = await service.createRecord("obj-product", {
2156
+ * name: "Nike Air Max",
2157
+ * price: 129.99,
2158
+ * status: "active"
2159
+ * });
2160
+ * // → product.completionStatus = "complete"
2161
+ *
2162
+ * // Create a draft record (allows missing required fields)
2163
+ * const draft = await service.createRecord("obj-product", {
2164
+ * name: "Draft Product"
2165
+ * }, { allowDraft: true });
2166
+ * // → draft.completionStatus = "draft"
2167
+ * ```
2168
+ */
2169
+ createRecord(objectId: string, data: Record<string, unknown>, options?: {
2170
+ /**
2171
+ * Allow creating records with missing required fields.
2172
+ * Format validation still applies to provided values.
2173
+ * @default false
2174
+ */
2175
+ allowDraft?: boolean;
2176
+ /**
2177
+ * Skip all validation (format + relations).
2178
+ * @default true
2179
+ */
2180
+ validate?: boolean;
2181
+ /**
2182
+ * Skip relation validation only.
2183
+ * Useful for bulk imports where relations are validated separately.
2184
+ * @default false
2185
+ */
2186
+ skipRelationValidation?: boolean;
2187
+ skipSystemCheck?: boolean;
2188
+ }): Promise<ObjectRecord>;
2189
+ /**
2190
+ * Get a record by ID
2191
+ *
2192
+ * @param recordId - Record UUID
2193
+ * @param options - Query options
2194
+ * @returns Record or null if not found
2195
+ */
2196
+ getRecord(recordId: string, options?: {
2197
+ includeSchema?: boolean;
2198
+ }): Promise<ObjectRecord | null>;
2199
+ /**
2200
+ * Get a record by ID or throw if not found
2201
+ */
2202
+ getRecordOrThrow(recordId: string): Promise<ObjectRecord>;
2203
+ /**
2204
+ * Update a record with validation
2205
+ *
2206
+ * The completion status is automatically recalculated after each update.
2207
+ * A draft record becomes complete when all required fields are filled.
2208
+ *
2209
+ * @param recordId - Record UUID
2210
+ * @param data - Partial data to update
2211
+ * @param options - Update options
2212
+ * @returns Updated record with recalculated completionStatus
2213
+ *
2214
+ * @example
2215
+ * ```typescript
2216
+ * // Update a draft record to make it complete
2217
+ * const updated = await service.updateRecord(draftId, {
2218
+ * price: 99.99,
2219
+ * status: "active"
2220
+ * });
2221
+ * // → updated.completionStatus = "complete" if all required fields now present
2222
+ * ```
2223
+ */
2224
+ updateRecord(recordId: string, data: Partial<Record<string, unknown>>, options?: {
2225
+ /**
2226
+ * Skip validation entirely (format + relations).
2227
+ * @default true
2228
+ */
2229
+ validate?: boolean;
2230
+ /**
2231
+ * Allow partial updates without strict validation.
2232
+ * Format validation still applies to provided values.
2233
+ * @default false
2234
+ */
2235
+ partial?: boolean;
2236
+ /**
2237
+ * Skip relation validation only.
2238
+ * @default false
2239
+ */
2240
+ skipRelationValidation?: boolean;
2241
+ }): Promise<ObjectRecord>;
2242
+ /**
2243
+ * Delete a record
2244
+ *
2245
+ * @param recordId - Record UUID
2246
+ * @param options - Delete options
2247
+ */
2248
+ deleteRecord(recordId: string, options?: {
2249
+ checkSystem?: boolean;
2250
+ }): Promise<void>;
2251
+ /**
2252
+ * List records for an object with pagination
2253
+ *
2254
+ * @param objectId - Object UUID
2255
+ * @param options - List options
2256
+ * @returns Records and total count
2257
+ */
2258
+ listRecords(objectId: string, options?: {
2259
+ limit?: number;
2260
+ offset?: number;
2261
+ orderBy?: string;
2262
+ orderDirection?: "asc" | "desc";
2263
+ }): Promise<{
2264
+ records: ObjectRecord[];
2265
+ total: number;
2266
+ }>;
2267
+ /**
2268
+ * Search records using full-text search
2269
+ *
2270
+ * @param objectId - Object UUID
2271
+ * @param query - Search query
2272
+ * @param options - Search options
2273
+ * @returns Matching records and total count
2274
+ */
2275
+ searchRecords(objectId: string, query: string, options?: {
2276
+ limit?: number;
2277
+ offset?: number;
2278
+ filters?: Record<string, unknown>;
2279
+ }): Promise<{
2280
+ records: ObjectRecord[];
2281
+ total: number;
2282
+ }>;
2283
+ /**
2284
+ * Validate data against object schema without saving
2285
+ *
2286
+ * @param objectId - Object UUID
2287
+ * @param data - Data to validate
2288
+ * @returns Validation result
2289
+ */
2290
+ validateData(objectId: string, data: Record<string, unknown>): Promise<ValidationResult>;
2291
+ /**
2292
+ * Compute the completion status for given data without saving.
2293
+ * Useful for UI to show draft/complete status before submitting.
2294
+ *
2295
+ * @param objectId - Object UUID
2296
+ * @param data - Data to check
2297
+ * @returns Computed completion status
2298
+ */
2299
+ computeStatus(objectId: string, data: Record<string, unknown>): Promise<CompletionStatus>;
2300
+ /**
2301
+ * Refresh the completion status of an existing record.
2302
+ * Useful when schema changes and you need to recompute statuses.
2303
+ *
2304
+ * @param recordId - Record UUID
2305
+ * @returns Updated completion status
2306
+ */
2307
+ refreshRecordStatus(recordId: string): Promise<CompletionStatus>;
2308
+ }
2309
+
2310
+ /**
2311
+ * Result of relation validation
2312
+ */
2313
+ interface RelationValidationResult {
2314
+ valid: boolean;
2315
+ errors: RelationValidationError[];
2316
+ }
2317
+ /**
2318
+ * Individual relation validation error
2319
+ */
2320
+ interface RelationValidationError {
2321
+ /** Attribute name */
2322
+ attribute: string;
2323
+ /** Error message */
2324
+ message: string;
2325
+ /** Invalid record IDs */
2326
+ invalidIds?: string[];
2327
+ }
2328
+ /**
2329
+ * Resolved relation option
2330
+ */
2331
+ interface RelationOption {
2332
+ /** Record ID */
2333
+ id: string;
2334
+ /** Object ID */
2335
+ objectId: string;
2336
+ /** Object name (technical name) */
2337
+ objectName: string;
2338
+ /** Object label (display name) */
2339
+ objectLabel: string;
2340
+ /** Object icon */
2341
+ objectIcon?: string;
2342
+ /** Display label (resolved from titleAttribute) */
2343
+ label: string;
2344
+ /** Additional record data */
2345
+ data?: Record<string, unknown>;
2346
+ }
2347
+ /**
2348
+ * Response for relation options
2349
+ */
2350
+ interface RelationOptionsResponse {
2351
+ options: RelationOption[];
2352
+ hasMore: boolean;
2353
+ total: number;
2354
+ }
2355
+ /**
2356
+ * Parameters for fetching relation options
2357
+ */
2358
+ interface GetRelationOptionsParams {
2359
+ /** Search query */
2360
+ query?: string;
2361
+ /** Page number (1-based) */
2362
+ page?: number;
2363
+ /** Page size */
2364
+ pageSize?: number;
2365
+ /** Filter by specific target object */
2366
+ targetObject?: string;
2367
+ }
2368
+ /**
2369
+ * Service for validating relation attributes
2370
+ * Ensures referenced records exist and belong to valid target objects
2371
+ */
2372
+ declare class RelationService {
2373
+ private adapter;
2374
+ private schemaService;
2375
+ constructor(adapter: DatabaseAdapter, nativeRegistry: typeof registry);
2376
+ /**
2377
+ * Validate all relation attributes in the data
2378
+ *
2379
+ * @param schema - Object schema containing attribute definitions
2380
+ * @param data - Record data to validate
2381
+ * @returns Validation result with errors if any
2382
+ *
2383
+ * @example
2384
+ * ```typescript
2385
+ * const result = await relationService.validateRelations(schema, {
2386
+ * company: "rec-123",
2387
+ * contacts: ["rec-456", "rec-789"]
2388
+ * });
2389
+ *
2390
+ * if (!result.valid) {
2391
+ * console.log(result.errors);
2392
+ * // [{ attribute: "company", message: "Record not found", invalidIds: ["rec-123"] }]
2393
+ * }
2394
+ * ```
2395
+ */
2396
+ validateRelations(schema: ObjectDefinition, data: Record<string, unknown>): Promise<RelationValidationResult>;
2397
+ /**
2398
+ * Validate a single relation attribute value
2399
+ */
2400
+ private validateRelationAttribute;
2401
+ /**
2402
+ * Extract IDs from relation value based on cardinality
2403
+ */
2404
+ private extractIds;
2405
+ /**
2406
+ * Get valid object IDs from relation targets
2407
+ */
2408
+ private getValidObjectIds;
2409
+ /**
2410
+ * Validate relations and throw if invalid
2411
+ */
2412
+ validateRelationsOrThrow(schema: ObjectDefinition, data: Record<string, unknown>): Promise<void>;
2413
+ /**
2414
+ * Get available options for a relation attribute
2415
+ * Searches across all target objects defined in the relation
2416
+ *
2417
+ * @param attribute - Relation attribute definition
2418
+ * @param tenantId - Tenant ID for multi-tenant isolation
2419
+ * @param params - Query parameters
2420
+ *
2421
+ * @example
2422
+ * ```typescript
2423
+ * const options = await relationService.getOptions(attribute, "tenant-1", {
2424
+ * query: "nike",
2425
+ * page: 1,
2426
+ * pageSize: 20
2427
+ * });
2428
+ * ```
2429
+ */
2430
+ getOptions(attribute: RelationAttribute, tenantId: string, params?: GetRelationOptionsParams): Promise<RelationOptionsResponse>;
2431
+ /**
2432
+ * Resolve record IDs to their display labels
2433
+ * Useful for displaying current values in the UI
2434
+ *
2435
+ * @param ids - Record IDs to resolve
2436
+ * @param tenantId - Tenant ID for multi-tenant isolation
2437
+ *
2438
+ * @example
2439
+ * ```typescript
2440
+ * const resolved = await relationService.resolveIds(["rec-1", "rec-2"], "tenant-1");
2441
+ * // [{ id: "rec-1", label: "Nike Air Max", objectName: "products", ... }]
2442
+ * ```
2443
+ */
2444
+ resolveIds(ids: string[], tenantId: string): Promise<RelationOption[]>;
2445
+ /**
2446
+ * Find a relation attribute by ID
2447
+ */
2448
+ findAttributeById(attributeId: string): Promise<RelationAttribute | null>;
2449
+ /**
2450
+ * Resolve display label from record values
2451
+ * Uses displayTemplate if provided, otherwise falls back to titleAttribute
2452
+ */
2453
+ private resolveLabel;
2454
+ }
2455
+
2456
+ /**
2457
+ * Service for managing user profiles
2458
+ * Handles user profile CRUD, auth provider sync, and role management
2459
+ */
2460
+ declare class UserProfileService {
2461
+ private adapter;
2462
+ private tenantId;
2463
+ constructor(adapter: DatabaseAdapter, tenantId: string);
2464
+ /**
2465
+ * Create a new user profile (typically after first auth)
2466
+ *
2467
+ * @param data - User profile creation data
2468
+ * @returns Created user profile
2469
+ *
2470
+ * @example
2471
+ * ```typescript
2472
+ * const service = new UserProfileService(adapter, "tenant-123");
2473
+ *
2474
+ * // After Supabase auth
2475
+ * const profile = await service.createProfile({
2476
+ * tenantId: "tenant-123",
2477
+ * authId: authUser.id,
2478
+ * email: authUser.email,
2479
+ * firstName: authUser.user_metadata.first_name,
2480
+ * lastName: authUser.user_metadata.last_name,
2481
+ * role: "member",
2482
+ * status: "active"
2483
+ * });
2484
+ * ```
2485
+ */
2486
+ createProfile(data: CreateUserProfile): Promise<UserProfile>;
2487
+ /**
2488
+ * Get user profile by ID
2489
+ */
2490
+ getProfile(profileId: string): Promise<UserProfile | null>;
2491
+ /**
2492
+ * Get user profile by ID or throw
2493
+ */
2494
+ getProfileOrThrow(profileId: string): Promise<UserProfile>;
2495
+ /**
2496
+ * Get user profile by auth provider ID
2497
+ *
2498
+ * @param authId - Auth provider user ID (Supabase, Clerk, etc.)
2499
+ * @returns User profile or null
2500
+ */
2501
+ getProfileByAuthId(authId: string): Promise<UserProfile | null>;
2502
+ /**
2503
+ * Get or create user profile (idempotent operation)
2504
+ * Useful for auth callbacks - ensures profile exists
2505
+ *
2506
+ * @param authId - Auth provider user ID
2507
+ * @param data - Profile data to create if doesn't exist
2508
+ * @returns Existing or newly created profile
2509
+ *
2510
+ * @example
2511
+ * ```typescript
2512
+ * // In Supabase auth callback
2513
+ * const profile = await service.getOrCreateProfile(
2514
+ * authUser.id,
2515
+ * {
2516
+ * tenantId: "tenant-123",
2517
+ * authId: authUser.id,
2518
+ * email: authUser.email,
2519
+ * role: "member",
2520
+ * status: "active"
2521
+ * }
2522
+ * );
2523
+ * ```
2524
+ */
2525
+ getOrCreateProfile(authId: string, data: CreateUserProfile): Promise<UserProfile>;
2526
+ /**
2527
+ * Update user profile
2528
+ */
2529
+ updateProfile(profileId: string, data: UpdateUserProfile): Promise<UserProfile>;
2530
+ /**
2531
+ * Delete user profile
2532
+ *
2533
+ * @param profileId - Profile UUID
2534
+ * @param options - Delete options
2535
+ */
2536
+ deleteProfile(profileId: string, options?: {
2537
+ checkAdmin?: boolean;
2538
+ }): Promise<void>;
2539
+ /**
2540
+ * List all user profiles for the tenant
2541
+ */
2542
+ listProfiles(options?: ListOptions): Promise<UserProfile[]>;
2543
+ /**
2544
+ * Update last login timestamp
2545
+ *
2546
+ * @param profileId - Profile UUID
2547
+ *
2548
+ * @example
2549
+ * ```typescript
2550
+ * // After successful auth
2551
+ * await service.updateLastLogin(profile.id);
2552
+ * ```
2553
+ */
2554
+ updateLastLogin(profileId: string): Promise<void>;
2555
+ /**
2556
+ * Change user role
2557
+ *
2558
+ * @param profileId - Profile UUID
2559
+ * @param newRole - New role
2560
+ */
2561
+ changeRole(profileId: string, newRole: string): Promise<UserProfile>;
2562
+ /**
2563
+ * Change user status
2564
+ *
2565
+ * @param profileId - Profile UUID
2566
+ * @param newStatus - New status
2567
+ */
2568
+ changeStatus(profileId: string, newStatus: "active" | "pending" | "inactive" | "suspended"): Promise<UserProfile>;
2569
+ /**
2570
+ * Get user by email
2571
+ */
2572
+ getProfileByEmail(email: string): Promise<UserProfile | null>;
2573
+ /**
2574
+ * Check if user has role
2575
+ */
2576
+ hasRole(profileId: string, role: string): Promise<boolean>;
2577
+ /**
2578
+ * Check if user is admin
2579
+ */
2580
+ isAdmin(profileId: string): Promise<boolean>;
2581
+ }
2582
+
2583
+ /**
2584
+ * Input for creating a custom view
2585
+ */
2586
+ interface CreateViewInput {
2587
+ name: string;
2588
+ label: string;
2589
+ objectName: string;
2590
+ description?: string;
2591
+ icon?: IconName;
2592
+ tabs: Tab[];
2593
+ default?: boolean;
2594
+ metadata?: Record<string, unknown>;
2595
+ }
2596
+ /**
2597
+ * Input for updating a view
2598
+ */
2599
+ interface UpdateViewInput {
2600
+ label?: string;
2601
+ description?: string;
2602
+ icon?: IconName;
2603
+ tabs?: Tab[];
2604
+ default?: boolean;
2605
+ metadata?: Record<string, unknown>;
2606
+ }
2607
+ /**
2608
+ * Service for managing views
2609
+ * Handles fusion of native views (from registry) and custom views (from database)
2610
+ */
2611
+ declare class ViewService {
2612
+ private adapter;
2613
+ private nativeViews;
2614
+ constructor(adapter: DatabaseAdapter, nativeViews: typeof viewRegistry);
2615
+ /**
2616
+ * Get all views for an object (native + custom)
2617
+ *
2618
+ * @param objectName - Object name
2619
+ * @param tenantId - Tenant ID
2620
+ * @returns All views for the object
2621
+ */
2622
+ getViewsForObject(objectName: string, tenantId: string): Promise<ViewDefinition[]>;
2623
+ /**
2624
+ * Get a specific view by name
2625
+ *
2626
+ * @param objectName - Object name
2627
+ * @param viewName - View name
2628
+ * @param tenantId - Tenant ID
2629
+ * @returns View definition or null
2630
+ */
2631
+ getView(objectName: string, viewName: string, tenantId: string): Promise<ViewDefinition | null>;
2632
+ /**
2633
+ * Get the default view for an object
2634
+ *
2635
+ * Priority:
2636
+ * 1. Custom view marked as default
2637
+ * 2. Native view marked as default
2638
+ * 3. First available view
2639
+ *
2640
+ * @param objectName - Object name
2641
+ * @param tenantId - Tenant ID
2642
+ * @returns Default view or null
2643
+ */
2644
+ getDefaultView(objectName: string, tenantId: string): Promise<ViewDefinition | null>;
2645
+ /**
2646
+ * Create a custom view
2647
+ *
2648
+ * @param input - View definition
2649
+ * @param tenantId - Tenant ID
2650
+ * @returns Created view
2651
+ */
2652
+ createView(input: CreateViewInput, tenantId: string): Promise<ViewDefinition>;
2653
+ /**
2654
+ * Update a custom view
2655
+ *
2656
+ * @param viewId - View ID
2657
+ * @param input - Update data
2658
+ * @returns Updated view
2659
+ */
2660
+ updateView(viewId: string, input: UpdateViewInput): Promise<ViewDefinition>;
2661
+ /**
2662
+ * Delete a custom view
2663
+ *
2664
+ * @param viewId - View ID
2665
+ */
2666
+ deleteView(viewId: string): Promise<void>;
2667
+ /**
2668
+ * Set a view as default for its object
2669
+ *
2670
+ * @param viewId - View ID
2671
+ * @param tenantId - Tenant ID
2672
+ * @returns Updated view
2673
+ */
2674
+ setDefaultView(viewId: string, tenantId: string): Promise<ViewDefinition>;
2675
+ /**
2676
+ * Validate view name format (kebab-case)
2677
+ */
2678
+ private validateViewName;
2679
+ /**
2680
+ * Convert database view to ViewDefinition
2681
+ */
2682
+ private convertDBViewToDefinition;
2683
+ }
2684
+
2685
+ /**
2686
+ * Result of view sync operation
2687
+ */
2688
+ interface ViewSyncResult {
2689
+ success: boolean;
2690
+ viewsSynced: number;
2691
+ viewsCreated: number;
2692
+ viewsUpdated: number;
2693
+ viewsDeleted: number;
2694
+ errors: Array<{
2695
+ viewName: string;
2696
+ objectName: string;
2697
+ error: string;
2698
+ }>;
2699
+ }
2700
+ /**
2701
+ * Options for view sync
2702
+ */
2703
+ interface ViewSyncOptions {
2704
+ dryRun?: boolean;
2705
+ verbose?: boolean;
2706
+ tenantId?: string;
2707
+ }
2708
+ /**
2709
+ * Sync native views from registry to database
2710
+ *
2711
+ * This function:
2712
+ * 1. Reads all registered native views from the registry
2713
+ * 2. Upserts them into the database (views table)
2714
+ * 3. Marks them as system=true for protection
2715
+ * 4. Removes views that were deleted from code
2716
+ *
2717
+ * @param adapter - Database adapter implementing DatabaseAdapter interface
2718
+ * @param nativeViewRegistry - Registry containing native views
2719
+ * @param options - Sync options (dryRun, verbose, tenantId)
2720
+ * @returns Sync result with statistics
2721
+ *
2722
+ * @example
2723
+ * ```typescript
2724
+ * import { syncNativeViews, viewRegistry } from "@andyoucreate/schema";
2725
+ * import { drizzleAdapter } from "./db/adapter";
2726
+ *
2727
+ * const result = await syncNativeViews(drizzleAdapter, viewRegistry, {
2728
+ * verbose: true,
2729
+ * tenantId: "default"
2730
+ * });
2731
+ *
2732
+ * if (result.success) {
2733
+ * console.log(`✓ Synced ${result.viewsSynced} views`);
2734
+ * }
2735
+ * ```
2736
+ */
2737
+ declare function syncNativeViews(adapter: DatabaseAdapter, nativeViewRegistry: typeof viewRegistry, options?: ViewSyncOptions): Promise<ViewSyncResult>;
2738
+ /**
2739
+ * Verify that all native views are synced to database
2740
+ *
2741
+ * @param adapter - Database adapter
2742
+ * @param nativeViewRegistry - Registry containing native views
2743
+ * @returns true if all views are synced, false otherwise
2744
+ *
2745
+ * @example
2746
+ * ```typescript
2747
+ * const isSynced = await verifyNativeViewsSync(adapter, viewRegistry);
2748
+ * if (!isSynced) {
2749
+ * console.warn("Native views not synced, running sync...");
2750
+ * await syncNativeViews(adapter, viewRegistry);
2751
+ * }
2752
+ * ```
2753
+ */
2754
+ declare function verifyNativeViewsSync(adapter: DatabaseAdapter, nativeViewRegistry: typeof viewRegistry): Promise<boolean>;
2755
+ /**
2756
+ * Get sync preview without modifying database
2757
+ *
2758
+ * @param adapter - Database adapter
2759
+ * @param nativeViewRegistry - Registry containing native views
2760
+ * @returns Sync result (dry run)
2761
+ */
2762
+ declare function getViewSyncPreview(adapter: DatabaseAdapter, nativeViewRegistry: typeof viewRegistry): Promise<ViewSyncResult>;
2763
+
2764
+ /**
2765
+ * Result of sync operation
2766
+ */
2767
+ interface SyncResult {
2768
+ success: boolean;
2769
+ objectsSynced: number;
2770
+ attributesSynced: number;
2771
+ objectsCreated: number;
2772
+ objectsUpdated: number;
2773
+ attributesCreated: number;
2774
+ attributesUpdated: number;
2775
+ attributesDeleted: number;
2776
+ errors: Array<{
2777
+ objectName: string;
2778
+ error: string;
2779
+ }>;
2780
+ }
2781
+ /**
2782
+ * Sync options
2783
+ */
2784
+ interface SyncOptions {
2785
+ dryRun?: boolean;
2786
+ verbose?: boolean;
2787
+ tenantId?: string;
2788
+ }
2789
+ /**
2790
+ * Sync native objects from registry to database
2791
+ *
2792
+ * This function:
2793
+ * 1. Reads all registered native objects from the registry
2794
+ * 2. Upserts them into the database (objects + attributes tables)
2795
+ * 3. Marks them as system=true for protection
2796
+ * 4. Removes attributes that were deleted from code
2797
+ *
2798
+ * @param adapter - Database adapter implementing DatabaseAdapter interface
2799
+ * @param nativeRegistry - Registry containing native objects
2800
+ * @param options - Sync options (dryRun, verbose, tenantId)
2801
+ * @returns Sync result with statistics
2802
+ *
2803
+ * @example
2804
+ * ```typescript
2805
+ * import { syncNativeObjects } from "@andyoucreate/schema/runtime";
2806
+ * import { registry } from "./objects/native";
2807
+ * import { drizzleAdapter } from "./db/adapter";
2808
+ *
2809
+ * const result = await syncNativeObjects(drizzleAdapter, registry, {
2810
+ * verbose: true,
2811
+ * tenantId: "default"
2812
+ * });
2813
+ *
2814
+ * if (result.success) {
2815
+ * console.log(`✓ Synced ${result.objectsSynced} objects`);
2816
+ * } else {
2817
+ * console.error("Sync errors:", result.errors);
2818
+ * }
2819
+ * ```
2820
+ */
2821
+ declare function syncNativeObjects(adapter: DatabaseAdapter, nativeRegistry: typeof registry, options?: SyncOptions): Promise<SyncResult>;
2822
+ /**
2823
+ * Verify that all native objects are synced to database
2824
+ *
2825
+ * @param adapter - Database adapter
2826
+ * @param nativeRegistry - Registry containing native objects
2827
+ * @returns true if all objects are synced, false otherwise
2828
+ *
2829
+ * @example
2830
+ * ```typescript
2831
+ * const isSynced = await verifyNativeObjectsSync(adapter, registry);
2832
+ * if (!isSynced) {
2833
+ * console.warn("Native objects not synced, running sync...");
2834
+ * await syncNativeObjects(adapter, registry);
2835
+ * }
2836
+ * ```
2837
+ */
2838
+ declare function verifyNativeObjectsSync(adapter: DatabaseAdapter, nativeRegistry: typeof registry): Promise<boolean>;
2839
+ /**
2840
+ * Get sync statistics without modifying database
2841
+ *
2842
+ * @param adapter - Database adapter
2843
+ * @param nativeRegistry - Registry containing native objects
2844
+ * @returns Sync result (dry run)
2845
+ */
2846
+ declare function getSyncPreview(adapter: DatabaseAdapter, nativeRegistry: typeof registry): Promise<SyncResult>;
2847
+ /**
2848
+ * Result of full sync operation (objects + views)
2849
+ */
2850
+ interface FullSyncResult {
2851
+ success: boolean;
2852
+ objects: SyncResult;
2853
+ views: ViewSyncResult;
2854
+ }
2855
+ /**
2856
+ * Options for full sync
2857
+ */
2858
+ interface FullSyncOptions extends SyncOptions, ViewSyncOptions {
2859
+ }
2860
+ /**
2861
+ * Sync all native objects and views from registries to database
2862
+ *
2863
+ * This is a convenience function that:
2864
+ * 1. Syncs native objects first (views may depend on objects)
2865
+ * 2. Syncs native views
2866
+ *
2867
+ * @param adapter - Database adapter
2868
+ * @param objectRegistry - Registry containing native objects
2869
+ * @param nativeViewRegistry - Registry containing native views
2870
+ * @param options - Sync options
2871
+ * @returns Combined sync result
2872
+ *
2873
+ * @example
2874
+ * ```typescript
2875
+ * import { syncAll, registry, viewRegistry } from "@andyoucreate/schema";
2876
+ * import { adapter } from "./db";
2877
+ *
2878
+ * const result = await syncAll(adapter, registry, viewRegistry, {
2879
+ * verbose: true,
2880
+ * tenantId: "default"
2881
+ * });
2882
+ *
2883
+ * if (result.success) {
2884
+ * console.log(`✓ Synced ${result.objects.objectsSynced} objects, ${result.views.viewsSynced} views`);
2885
+ * }
2886
+ * ```
2887
+ */
2888
+ declare function syncAll(adapter: DatabaseAdapter, objectRegistry: typeof registry, nativeViewRegistry: typeof viewRegistry, options?: FullSyncOptions): Promise<FullSyncResult>;
2889
+
2890
+ export { type Timestamps as $, type Attribute as A, type BaseAttribute as B, type Currency as C, type DateAttribute as D, type StorageProvider as E, type FileAttribute as F, type Group as G, type FileVisibility as H, type File as I, type CreateFile as J, type UpdateFile as K, type Location as L, type MultiselectAttribute as M, type NumberAttribute as N, type Option as O, type Phone as P, type GeocodingSuggestion as Q, type RelationOnDelete as R, type StatusAttribute as S, type TextAttribute as T, type UserAttribute as U, type ViewDefinition as V, type GeocodingAutocompleteParams as W, type ReverseGeocodingParams as X, type GeocodingParams as Y, type GeocodingAdapter as Z, NoopGeocodingAdapter as _, type SelectAttribute as a, ObjectSchemaService as a$, type ObjectAttribute as a0, type CompletionStatus as a1, type ObjectRecord as a2, type UserRole as a3, type UserStatus as a4, type UserProfile as a5, type CreateUserProfile as a6, type UpdateUserProfile as a7, type TabType as a8, type FormTab as a9, createRelationValidator as aA, createRatingValidator as aB, createAttributeValidator as aC, createObjectValidator as aD, type ValidationResult as aE, validateAttribute as aF, validateObject as aG, validateObjectOrThrow as aH, createDraftValidator as aI, validateDraft as aJ, validateDraftOrThrow as aK, getMissingRequiredAttributes as aL, isRecordComplete as aM, computeRecordStatus as aN, type DatabaseAdapter as aO, createMockAdapter as aP, type ObjectsRepository as aQ, type AttributesRepository as aR, type UserProfilesRepository as aS, type FilesRepository as aT, type ObjectRecordsRepository as aU, type ViewsRepository as aV, FileService as aW, GeocodingService as aX, GlobalSearchService as aY, type CreateCustomObjectInput as aZ, type AddAttributeInput as a_, type TableTab as aa, type CustomTab as ab, isFormTab as ac, isTableTab as ad, isCustomTab as ae, type Uuid as af, type TenantId as ag, generateId as ah, generatePrefixedId as ai, registry as aj, viewRegistry as ak, createTextValidator as al, createNumberValidator as am, createCheckboxValidator as an, createDateValidator as ao, createPhoneValidator as ap, createCurrencyValidator as aq, createStatusValidator as ar, createSelectValidator as as, createMultiselectValidator as at, createLocationValidator as au, createTimestampValidator as av, createFileValidator as aw, createUserValidator as ax, createSingleRelationValidator as ay, createMultiRelationValidator as az, type TextAreaAttribute as b, RecordService as b0, type RelationValidationResult as b1, type RelationValidationError as b2, type RelationOption as b3, type RelationOptionsResponse as b4, type GetRelationOptionsParams as b5, RelationService as b6, UserProfileService as b7, type CreateViewInput as b8, type UpdateViewInput as b9, type UpsertDBView as bA, type OperationResult as bB, type ViewSyncResult as bC, type ViewSyncOptions as bD, syncNativeViews as bE, verifyNativeViewsSync as bF, getViewSyncPreview as bG, ViewService as ba, type SyncResult as bb, type SyncOptions as bc, syncNativeObjects as bd, verifyNativeObjectsSync as be, getSyncPreview as bf, type FullSyncResult as bg, type FullSyncOptions as bh, syncAll as bi, type DBObject as bj, type CreateDBObject as bk, type UpdateDBObject as bl, type UpsertDBObject as bm, type DBAttribute as bn, type CreateDBAttribute as bo, type UpdateDBAttribute as bp, type UpsertDBAttribute as bq, type CreateObjectRecord as br, type ListOptions as bs, type SearchOptions as bt, type GlobalSearchOptions as bu, type GlobalSearchResultItem as bv, type FileListOptions as bw, type DBView as bx, type CreateDBView as by, type UpdateDBView as bz, type CheckboxAttribute as c, type PhoneAttribute as d, type CurrencyAttribute as e, type LocationAttribute as f, type TimestampAttribute as g, type SingleRelationAttribute as h, type MultiRelationAttribute as i, type RelationTarget as j, type RatingAttribute as k, type ObjectDefinition as l, type Field as m, type Tab as n, type AttributeType as o, type StatusGroup as p, type AttributeGroup as q, type NumberUnit as r, type DateFormat as s, type DateValue as t, type LocationGranularity as u, type DocumentType as v, type DocumentFace as w, type DocumentTypeConfig as x, type FileVerificationConfig as y, type RelationAttribute as z };