@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,3867 @@
1
+ // src/utils.ts
2
+ function generateId() {
3
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
4
+ return crypto.randomUUID();
5
+ }
6
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
7
+ const r = Math.random() * 16 | 0;
8
+ const v = c === "x" ? r : r & 3 | 8;
9
+ return v.toString(16);
10
+ });
11
+ }
12
+ function generatePrefixedId(prefix) {
13
+ return `${prefix}_${generateId()}`;
14
+ }
15
+
16
+ // src/runtime/mock-adapter.ts
17
+ function createMockObjectsRepository(stores) {
18
+ return {
19
+ findById(id) {
20
+ return Promise.resolve(stores.objects.get(id) ?? null);
21
+ },
22
+ findByName(tenantId, name) {
23
+ for (const obj of stores.objects.values()) {
24
+ if (obj.tenantId === tenantId && obj.name === name) {
25
+ return Promise.resolve(obj);
26
+ }
27
+ }
28
+ return Promise.resolve(null);
29
+ },
30
+ findSystemByName(name) {
31
+ for (const obj of stores.objects.values()) {
32
+ if (obj.system && obj.name === name) {
33
+ return Promise.resolve(obj);
34
+ }
35
+ }
36
+ return Promise.resolve(null);
37
+ },
38
+ create(data) {
39
+ const obj = {
40
+ id: generateId(),
41
+ tenantId: data.tenantId,
42
+ name: data.name,
43
+ label: data.label,
44
+ description: data.description,
45
+ icon: data.icon,
46
+ system: data.system ?? false,
47
+ metadata: data.metadata,
48
+ createdAt: /* @__PURE__ */ new Date(),
49
+ updatedAt: /* @__PURE__ */ new Date()
50
+ };
51
+ stores.objects.set(obj.id, obj);
52
+ return Promise.resolve(obj);
53
+ },
54
+ update(id, data) {
55
+ const existing = stores.objects.get(id);
56
+ if (!existing) {
57
+ return Promise.reject(new Error(`Object ${id} not found`));
58
+ }
59
+ const updated = {
60
+ ...existing,
61
+ ...data,
62
+ updatedAt: /* @__PURE__ */ new Date()
63
+ };
64
+ stores.objects.set(id, updated);
65
+ return Promise.resolve(updated);
66
+ },
67
+ delete(id) {
68
+ stores.objects.delete(id);
69
+ return Promise.resolve();
70
+ },
71
+ list(tenantId) {
72
+ const results = Array.from(stores.objects.values()).filter(
73
+ (obj) => obj.tenantId === tenantId
74
+ );
75
+ return Promise.resolve(results);
76
+ },
77
+ upsert(data) {
78
+ for (const obj of stores.objects.values()) {
79
+ if (obj.system && obj.name === data.name) {
80
+ const updated = {
81
+ ...obj,
82
+ label: data.label,
83
+ description: data.description,
84
+ icon: data.icon,
85
+ metadata: data.metadata,
86
+ updatedAt: /* @__PURE__ */ new Date()
87
+ };
88
+ stores.objects.set(obj.id, updated);
89
+ return Promise.resolve(updated);
90
+ }
91
+ }
92
+ const newObj = {
93
+ id: generateId(),
94
+ tenantId: data.tenantId,
95
+ name: data.name,
96
+ label: data.label,
97
+ description: data.description,
98
+ icon: data.icon,
99
+ system: data.system,
100
+ metadata: data.metadata,
101
+ createdAt: /* @__PURE__ */ new Date(),
102
+ updatedAt: /* @__PURE__ */ new Date()
103
+ };
104
+ stores.objects.set(newObj.id, newObj);
105
+ return Promise.resolve(newObj);
106
+ }
107
+ };
108
+ }
109
+ function createMockAttributesRepository(stores) {
110
+ return {
111
+ findById(id) {
112
+ return Promise.resolve(stores.attributes.get(id) ?? null);
113
+ },
114
+ findByObjectId(objectId) {
115
+ const results = Array.from(stores.attributes.values()).filter(
116
+ (attr) => attr.objectId === objectId
117
+ );
118
+ return Promise.resolve(results);
119
+ },
120
+ create(data) {
121
+ const attr = {
122
+ id: generateId(),
123
+ objectId: data.objectId,
124
+ name: data.name,
125
+ label: data.label,
126
+ type: data.type,
127
+ description: data.description,
128
+ icon: data.icon,
129
+ system: data.system ?? false,
130
+ required: data.required ?? false,
131
+ unique: data.unique ?? false,
132
+ order: data.order ?? 0,
133
+ hidden: data.hidden,
134
+ archived: data.archived,
135
+ deprecated: data.deprecated,
136
+ defaultValue: data.defaultValue,
137
+ config: data.config ?? {},
138
+ createdAt: /* @__PURE__ */ new Date(),
139
+ updatedAt: /* @__PURE__ */ new Date()
140
+ };
141
+ stores.attributes.set(attr.id, attr);
142
+ return Promise.resolve(attr);
143
+ },
144
+ update(id, data) {
145
+ const existing = stores.attributes.get(id);
146
+ if (!existing) {
147
+ return Promise.reject(new Error(`Attribute ${id} not found`));
148
+ }
149
+ const updated = {
150
+ ...existing,
151
+ ...data,
152
+ updatedAt: /* @__PURE__ */ new Date()
153
+ };
154
+ stores.attributes.set(id, updated);
155
+ return Promise.resolve(updated);
156
+ },
157
+ delete(id) {
158
+ stores.attributes.delete(id);
159
+ return Promise.resolve();
160
+ },
161
+ deleteByNames(objectId, excludeNames) {
162
+ let count = 0;
163
+ for (const [id, attr] of stores.attributes.entries()) {
164
+ if (attr.objectId === objectId && !excludeNames.includes(attr.name)) {
165
+ stores.attributes.delete(id);
166
+ count++;
167
+ }
168
+ }
169
+ return Promise.resolve(count);
170
+ },
171
+ upsert(data) {
172
+ for (const attr of stores.attributes.values()) {
173
+ if (attr.objectId === data.objectId && attr.name === data.name) {
174
+ const updated = {
175
+ ...attr,
176
+ label: data.label ?? attr.label,
177
+ type: data.type ?? attr.type,
178
+ description: data.description ?? attr.description,
179
+ icon: data.icon ?? attr.icon,
180
+ system: data.system ?? attr.system,
181
+ required: data.required ?? attr.required,
182
+ unique: data.unique ?? attr.unique,
183
+ order: data.order ?? attr.order,
184
+ hidden: data.hidden ?? attr.hidden,
185
+ archived: data.archived ?? attr.archived,
186
+ deprecated: data.deprecated ?? attr.deprecated,
187
+ defaultValue: data.defaultValue ?? attr.defaultValue,
188
+ config: data.config ?? attr.config,
189
+ updatedAt: /* @__PURE__ */ new Date()
190
+ };
191
+ stores.attributes.set(attr.id, updated);
192
+ return Promise.resolve(updated);
193
+ }
194
+ }
195
+ return this.create(data);
196
+ }
197
+ };
198
+ }
199
+ function createMockUserProfilesRepository(stores) {
200
+ return {
201
+ findById(id) {
202
+ return Promise.resolve(stores.userProfiles.get(id) ?? null);
203
+ },
204
+ findByAuthId(authId) {
205
+ for (const profile of stores.userProfiles.values()) {
206
+ if (profile.authId === authId) {
207
+ return Promise.resolve(profile);
208
+ }
209
+ }
210
+ return Promise.resolve(null);
211
+ },
212
+ findByEmail(tenantId, email) {
213
+ for (const profile of stores.userProfiles.values()) {
214
+ if (profile.tenantId === tenantId && profile.email === email) {
215
+ return Promise.resolve(profile);
216
+ }
217
+ }
218
+ return Promise.resolve(null);
219
+ },
220
+ create(data) {
221
+ const profile = {
222
+ id: generateId(),
223
+ tenantId: data.tenantId,
224
+ authId: data.authId,
225
+ email: data.email,
226
+ firstName: data.firstName,
227
+ lastName: data.lastName,
228
+ avatarUrl: data.avatarUrl,
229
+ role: data.role ?? "member",
230
+ status: data.status ?? "active",
231
+ createdAt: /* @__PURE__ */ new Date(),
232
+ updatedAt: /* @__PURE__ */ new Date()
233
+ };
234
+ stores.userProfiles.set(profile.id, profile);
235
+ return Promise.resolve(profile);
236
+ },
237
+ update(id, data) {
238
+ const existing = stores.userProfiles.get(id);
239
+ if (!existing) {
240
+ return Promise.reject(new Error(`UserProfile ${id} not found`));
241
+ }
242
+ const updated = {
243
+ ...existing,
244
+ ...data,
245
+ updatedAt: /* @__PURE__ */ new Date()
246
+ };
247
+ stores.userProfiles.set(id, updated);
248
+ return Promise.resolve(updated);
249
+ },
250
+ delete(id) {
251
+ stores.userProfiles.delete(id);
252
+ return Promise.resolve();
253
+ },
254
+ list(tenantId, options) {
255
+ let results = Array.from(stores.userProfiles.values()).filter((p) => p.tenantId === tenantId);
256
+ if (options?.limit) {
257
+ results = results.slice(options.offset ?? 0, (options.offset ?? 0) + options.limit);
258
+ }
259
+ return Promise.resolve(results);
260
+ },
261
+ updateLastLogin(id) {
262
+ const profile = stores.userProfiles.get(id);
263
+ if (profile) {
264
+ profile.lastLoginAt = /* @__PURE__ */ new Date();
265
+ stores.userProfiles.set(id, profile);
266
+ }
267
+ return Promise.resolve();
268
+ }
269
+ };
270
+ }
271
+ function createMockFilesRepository(stores) {
272
+ return {
273
+ findById(id) {
274
+ const file2 = stores.files.get(id);
275
+ if (file2?.deletedAt) return Promise.resolve(null);
276
+ return Promise.resolve(file2 ?? null);
277
+ },
278
+ create(data) {
279
+ const file2 = {
280
+ id: generateId(),
281
+ tenantId: data.tenantId,
282
+ name: data.name,
283
+ originalName: data.originalName,
284
+ mimeType: data.mimeType,
285
+ size: data.size,
286
+ storageProvider: data.storageProvider,
287
+ storagePath: data.storagePath,
288
+ storageBucket: data.storageBucket,
289
+ url: data.url,
290
+ uploadedBy: data.uploadedBy,
291
+ folderPath: data.folderPath,
292
+ tags: data.tags,
293
+ visibility: data.visibility ?? "private",
294
+ allowedUsers: data.allowedUsers,
295
+ createdAt: /* @__PURE__ */ new Date(),
296
+ updatedAt: /* @__PURE__ */ new Date()
297
+ };
298
+ stores.files.set(file2.id, file2);
299
+ return Promise.resolve(file2);
300
+ },
301
+ update(id, data) {
302
+ const existing = stores.files.get(id);
303
+ if (!existing) {
304
+ return Promise.reject(new Error(`File ${id} not found`));
305
+ }
306
+ const updated = {
307
+ ...existing,
308
+ ...data,
309
+ updatedAt: /* @__PURE__ */ new Date()
310
+ };
311
+ stores.files.set(id, updated);
312
+ return Promise.resolve(updated);
313
+ },
314
+ delete(id) {
315
+ const file2 = stores.files.get(id);
316
+ if (file2) {
317
+ file2.deletedAt = /* @__PURE__ */ new Date();
318
+ stores.files.set(id, file2);
319
+ }
320
+ return Promise.resolve();
321
+ },
322
+ hardDelete(id) {
323
+ stores.files.delete(id);
324
+ return Promise.resolve();
325
+ },
326
+ list(tenantId, options) {
327
+ let results = Array.from(stores.files.values()).filter(
328
+ (f) => f.tenantId === tenantId && !f.deletedAt
329
+ );
330
+ if (options?.mimeType) {
331
+ results = results.filter((f) => f.mimeType === options.mimeType);
332
+ }
333
+ if (options?.limit) {
334
+ results = results.slice(options.offset ?? 0, (options.offset ?? 0) + options.limit);
335
+ }
336
+ return Promise.resolve(results);
337
+ },
338
+ findByFolder(tenantId, folderPath) {
339
+ const results = Array.from(stores.files.values()).filter(
340
+ (f) => f.tenantId === tenantId && f.folderPath === folderPath && !f.deletedAt
341
+ );
342
+ return Promise.resolve(results);
343
+ },
344
+ findByUploader(uploadedBy) {
345
+ const results = Array.from(stores.files.values()).filter(
346
+ (f) => f.uploadedBy === uploadedBy && !f.deletedAt
347
+ );
348
+ return Promise.resolve(results);
349
+ }
350
+ };
351
+ }
352
+ function createMockObjectRecordsRepository(stores) {
353
+ return {
354
+ findById(id) {
355
+ const internal = stores.objectRecords.get(id);
356
+ if (!internal) return Promise.resolve(null);
357
+ const { tenantId: _, ...record } = internal;
358
+ return Promise.resolve(record);
359
+ },
360
+ create(data) {
361
+ const internal = {
362
+ id: generateId(),
363
+ tenantId: data.tenantId,
364
+ objectId: data.objectId,
365
+ completionStatus: data.completionStatus,
366
+ values: data.data,
367
+ createdAt: /* @__PURE__ */ new Date(),
368
+ updatedAt: /* @__PURE__ */ new Date()
369
+ };
370
+ stores.objectRecords.set(internal.id, internal);
371
+ const { tenantId: _, ...record } = internal;
372
+ return Promise.resolve(record);
373
+ },
374
+ update(id, data) {
375
+ const existing = stores.objectRecords.get(id);
376
+ if (!existing) {
377
+ return Promise.reject(new Error(`ObjectRecord ${id} not found`));
378
+ }
379
+ const { __completionStatus, ...valueData } = data;
380
+ const updated = {
381
+ ...existing,
382
+ completionStatus: __completionStatus ?? existing.completionStatus,
383
+ values: { ...existing.values, ...valueData },
384
+ updatedAt: /* @__PURE__ */ new Date()
385
+ };
386
+ stores.objectRecords.set(id, updated);
387
+ const { tenantId: _, ...record } = updated;
388
+ return Promise.resolve(record);
389
+ },
390
+ delete(id) {
391
+ stores.objectRecords.delete(id);
392
+ return Promise.resolve();
393
+ },
394
+ list(tenantId, objectId, options) {
395
+ let results = Array.from(stores.objectRecords.values()).filter(
396
+ (r) => r.tenantId === tenantId && r.objectId === objectId
397
+ );
398
+ const total = results.length;
399
+ if (options?.limit) {
400
+ results = results.slice(options.offset ?? 0, (options.offset ?? 0) + options.limit);
401
+ }
402
+ const records = results.map(({ tenantId: _, ...r }) => r);
403
+ return Promise.resolve({ records, total });
404
+ },
405
+ search(tenantId, objectId, query, options) {
406
+ const lowerQuery = query.toLowerCase();
407
+ let results = Array.from(stores.objectRecords.values()).filter((r) => {
408
+ if (r.tenantId !== tenantId || r.objectId !== objectId) return false;
409
+ return Object.values(r.values).some(
410
+ (val) => String(val).toLowerCase().includes(lowerQuery)
411
+ );
412
+ });
413
+ const total = results.length;
414
+ if (options?.limit) {
415
+ results = results.slice(options.offset ?? 0, (options.offset ?? 0) + options.limit);
416
+ }
417
+ const records = results.map(({ tenantId: _, ...r }) => r);
418
+ return Promise.resolve({ records, total });
419
+ }
420
+ };
421
+ }
422
+ function createMockAdapter() {
423
+ const stores = {
424
+ objects: /* @__PURE__ */ new Map(),
425
+ attributes: /* @__PURE__ */ new Map(),
426
+ userProfiles: /* @__PURE__ */ new Map(),
427
+ files: /* @__PURE__ */ new Map(),
428
+ objectRecords: /* @__PURE__ */ new Map()
429
+ };
430
+ const adapter = {
431
+ objects: createMockObjectsRepository(stores),
432
+ attributes: createMockAttributesRepository(stores),
433
+ userProfiles: createMockUserProfilesRepository(stores),
434
+ files: createMockFilesRepository(stores),
435
+ objectRecords: createMockObjectRecordsRepository(stores),
436
+ async transaction(callback) {
437
+ return await callback(adapter);
438
+ },
439
+ // Expose stores for testing inspection
440
+ _stores: stores,
441
+ // Reset all stores (useful between tests)
442
+ reset() {
443
+ stores.objects.clear();
444
+ stores.attributes.clear();
445
+ stores.userProfiles.clear();
446
+ stores.files.clear();
447
+ stores.objectRecords.clear();
448
+ }
449
+ };
450
+ return adapter;
451
+ }
452
+
453
+ // src/runtime/services/file.service.ts
454
+ var FileService = class {
455
+ constructor(adapter, tenantId) {
456
+ this.adapter = adapter;
457
+ this.tenantId = tenantId;
458
+ }
459
+ /**
460
+ * Create a new file record (after upload to storage)
461
+ *
462
+ * @param data - File metadata
463
+ * @returns Created file record
464
+ *
465
+ * @example
466
+ * ```typescript
467
+ * const service = new FileService(adapter, "tenant-123");
468
+ *
469
+ * // After uploading to S3
470
+ * const file = await service.createFile({
471
+ * tenantId: "tenant-123",
472
+ * name: "contract-2025.pdf",
473
+ * originalName: "Contract Acme Corp 2025.pdf",
474
+ * mimeType: "application/pdf",
475
+ * size: 2458624,
476
+ * storageProvider: "s3",
477
+ * storagePath: "tenants/123/files/2025/contract.pdf",
478
+ * storageBucket: "my-app-files",
479
+ * url: "https://cdn.example.com/files/file-123",
480
+ * uploadedBy: "profile-456",
481
+ * visibility: "private"
482
+ * });
483
+ * ```
484
+ */
485
+ async createFile(data) {
486
+ if (data.tenantId !== this.tenantId) {
487
+ throw new Error(
488
+ `Tenant mismatch: service initialized with "${this.tenantId}" but data has "${data.tenantId}"`
489
+ );
490
+ }
491
+ return await this.adapter.files.create(data);
492
+ }
493
+ /**
494
+ * Get file by ID
495
+ */
496
+ async getFile(fileId) {
497
+ const file2 = await this.adapter.files.findById(fileId);
498
+ if (file2?.deletedAt) {
499
+ return null;
500
+ }
501
+ return file2;
502
+ }
503
+ /**
504
+ * Get file by ID or throw
505
+ */
506
+ async getFileOrThrow(fileId) {
507
+ const file2 = await this.getFile(fileId);
508
+ if (!file2) {
509
+ throw new Error(`File with id "${fileId}" not found`);
510
+ }
511
+ return file2;
512
+ }
513
+ /**
514
+ * Update file metadata
515
+ *
516
+ * @param fileId - File UUID
517
+ * @param data - Data to update
518
+ * @returns Updated file
519
+ */
520
+ async updateFile(fileId, data) {
521
+ await this.getFileOrThrow(fileId);
522
+ return await this.adapter.files.update(fileId, data);
523
+ }
524
+ /**
525
+ * Delete file (soft delete)
526
+ *
527
+ * @param fileId - File UUID
528
+ * @param options - Delete options
529
+ */
530
+ async deleteFile(fileId, options) {
531
+ if (options?.checkOwnership && options.userId) {
532
+ const file2 = await this.getFileOrThrow(fileId);
533
+ if (file2.uploadedBy !== options.userId) {
534
+ throw new Error("You can only delete files you uploaded");
535
+ }
536
+ }
537
+ if (options?.hard) {
538
+ await this.adapter.files.hardDelete(fileId);
539
+ } else {
540
+ await this.adapter.files.delete(fileId);
541
+ }
542
+ }
543
+ /**
544
+ * List files for the tenant
545
+ */
546
+ async listFiles(options) {
547
+ return await this.adapter.files.list(this.tenantId, options);
548
+ }
549
+ /**
550
+ * List files by folder
551
+ */
552
+ async listFilesByFolder(folderPath) {
553
+ return await this.adapter.files.findByFolder(this.tenantId, folderPath);
554
+ }
555
+ /**
556
+ * List files uploaded by a specific user
557
+ */
558
+ async listFilesByUploader(uploadedBy) {
559
+ return await this.adapter.files.findByUploader(uploadedBy);
560
+ }
561
+ /**
562
+ * Change file visibility
563
+ *
564
+ * @param fileId - File UUID
565
+ * @param visibility - New visibility level
566
+ * @param allowedUsers - Users allowed to access (if restricted)
567
+ */
568
+ async changeVisibility(fileId, visibility, allowedUsers) {
569
+ const updateData = { visibility };
570
+ if (visibility === "restricted" && allowedUsers) {
571
+ updateData.allowedUsers = allowedUsers;
572
+ }
573
+ return await this.updateFile(fileId, updateData);
574
+ }
575
+ /**
576
+ * Grant access to a file for specific users
577
+ *
578
+ * @param fileId - File UUID
579
+ * @param userIds - User IDs to grant access
580
+ */
581
+ async grantAccess(fileId, userIds) {
582
+ const file2 = await this.getFileOrThrow(fileId);
583
+ const currentAllowed = file2.allowedUsers || [];
584
+ const newAllowed = [.../* @__PURE__ */ new Set([...currentAllowed, ...userIds])];
585
+ return await this.updateFile(fileId, {
586
+ visibility: "restricted",
587
+ allowedUsers: newAllowed
588
+ });
589
+ }
590
+ /**
591
+ * Revoke access to a file for specific users
592
+ *
593
+ * @param fileId - File UUID
594
+ * @param userIds - User IDs to revoke access
595
+ */
596
+ async revokeAccess(fileId, userIds) {
597
+ const file2 = await this.getFileOrThrow(fileId);
598
+ const currentAllowed = file2.allowedUsers || [];
599
+ const newAllowed = currentAllowed.filter((id) => !userIds.includes(id));
600
+ return await this.updateFile(fileId, {
601
+ allowedUsers: newAllowed
602
+ });
603
+ }
604
+ /**
605
+ * Check if user has access to a file
606
+ *
607
+ * @param fileId - File UUID
608
+ * @param userId - User ID to check
609
+ * @returns true if user can access the file
610
+ */
611
+ async canAccess(fileId, userId) {
612
+ const file2 = await this.getFile(fileId);
613
+ if (!file2) {
614
+ return false;
615
+ }
616
+ if (file2.visibility === "public") {
617
+ return true;
618
+ }
619
+ if (file2.uploadedBy === userId) {
620
+ return true;
621
+ }
622
+ if (file2.visibility === "restricted") {
623
+ return file2.allowedUsers?.includes(userId) ?? false;
624
+ }
625
+ return false;
626
+ }
627
+ /**
628
+ * Move file to different folder
629
+ */
630
+ async moveToFolder(fileId, newFolderPath) {
631
+ return await this.updateFile(fileId, { folderPath: newFolderPath });
632
+ }
633
+ /**
634
+ * Add tags to file
635
+ */
636
+ async addTags(fileId, tags) {
637
+ const file2 = await this.getFileOrThrow(fileId);
638
+ const currentTags = file2.tags || [];
639
+ const newTags = [.../* @__PURE__ */ new Set([...currentTags, ...tags])];
640
+ return await this.updateFile(fileId, { tags: newTags });
641
+ }
642
+ /**
643
+ * Remove tags from file
644
+ */
645
+ async removeTags(fileId, tags) {
646
+ const file2 = await this.getFileOrThrow(fileId);
647
+ const currentTags = file2.tags || [];
648
+ const newTags = currentTags.filter((tag) => !tags.includes(tag));
649
+ return await this.updateFile(fileId, { tags: newTags });
650
+ }
651
+ };
652
+
653
+ // src/runtime/services/geocoding.service.ts
654
+ var GeocodingService = class {
655
+ constructor(adapter) {
656
+ this.adapter = adapter;
657
+ }
658
+ /**
659
+ * Search for address suggestions as the user types
660
+ */
661
+ async autocomplete(params) {
662
+ if (!params.query || params.query.trim().length < 2) {
663
+ return [];
664
+ }
665
+ return await this.adapter.autocomplete({
666
+ ...params,
667
+ query: params.query.trim(),
668
+ limit: params.limit ?? 5
669
+ });
670
+ }
671
+ /**
672
+ * Reverse geocode coordinates to an address
673
+ */
674
+ async reverse(params) {
675
+ if (!this.adapter.reverse) {
676
+ throw new Error("Reverse geocoding is not supported by the configured adapter");
677
+ }
678
+ return await this.adapter.reverse(params);
679
+ }
680
+ /**
681
+ * Geocode a structured address to coordinates
682
+ */
683
+ async geocode(params) {
684
+ if (!this.adapter.geocode) {
685
+ throw new Error("Geocoding is not supported by the configured adapter");
686
+ }
687
+ return await this.adapter.geocode(params);
688
+ }
689
+ };
690
+
691
+ // src/builders/attribute-builders.ts
692
+ import { z } from "zod";
693
+ var BaseAttributeBuilder = class {
694
+ constructor(type, name, label) {
695
+ this.validateVariableName(name);
696
+ this.attr = {
697
+ name,
698
+ label,
699
+ type,
700
+ required: false
701
+ };
702
+ }
703
+ /**
704
+ * Validate attribute name as valid variable identifier
705
+ * Accepts: camelCase, snake_case, PascalCase, UPPER_CASE
706
+ */
707
+ validateVariableName(name) {
708
+ const variableNameSchema = z.string().min(1, "Attribute name cannot be empty").max(63, "Attribute name is too long (max 63 characters)").regex(/^[a-zA-Z_][a-zA-Z0-9_]*$/, {
709
+ message: "Invalid attribute name format.\nName must be a valid variable identifier:\n \u2705 Valid: 'firstName', 'first_name', 'FirstName', 'FIRST_NAME'\n \u274C Invalid: 'first-name', 'first name', '123name', 'first.name'"
710
+ });
711
+ try {
712
+ variableNameSchema.parse(name);
713
+ } catch (error) {
714
+ if (error instanceof z.ZodError) {
715
+ throw new Error(`[AttributeBuilder] ${error.errors[0].message}`);
716
+ }
717
+ throw error;
718
+ }
719
+ }
720
+ setRequired(value) {
721
+ this.attr.required = value;
722
+ }
723
+ system() {
724
+ this.attr.system = true;
725
+ return this;
726
+ }
727
+ disabled() {
728
+ this.attr.disabled = true;
729
+ return this;
730
+ }
731
+ hidden() {
732
+ this.attr.hidden = true;
733
+ return this;
734
+ }
735
+ placeholder(value) {
736
+ this.attr.placeholder = value;
737
+ return this;
738
+ }
739
+ description(value) {
740
+ this.attr.description = value;
741
+ return this;
742
+ }
743
+ icon(value) {
744
+ this.attr.icon = value;
745
+ return this;
746
+ }
747
+ order(value) {
748
+ this.attr.order = value;
749
+ return this;
750
+ }
751
+ defaultValue(value) {
752
+ this.attr.defaultValue = value;
753
+ return this;
754
+ }
755
+ metadata(value) {
756
+ this.attr.metadata = value;
757
+ return this;
758
+ }
759
+ build() {
760
+ return this.attr;
761
+ }
762
+ };
763
+ var TextAttributeBuilder = class extends BaseAttributeBuilder {
764
+ constructor(name, label) {
765
+ super("text", name, label);
766
+ }
767
+ minLength(value) {
768
+ this.attr.minLength = value;
769
+ return this;
770
+ }
771
+ maxLength(value) {
772
+ this.attr.maxLength = value;
773
+ return this;
774
+ }
775
+ pattern(value) {
776
+ this.attr.pattern = value;
777
+ return this;
778
+ }
779
+ required() {
780
+ this.setRequired(true);
781
+ return this;
782
+ }
783
+ optional() {
784
+ this.setRequired(false);
785
+ return this;
786
+ }
787
+ /**
788
+ * Set email validation pattern
789
+ */
790
+ email() {
791
+ this.attr.pattern = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
792
+ return this;
793
+ }
794
+ /**
795
+ * Set URL validation pattern
796
+ */
797
+ url() {
798
+ this.attr.pattern = "^https?:\\/\\/[\\w\\-]+(\\.[\\w\\-]+)+[/#?]?.*$";
799
+ return this;
800
+ }
801
+ /**
802
+ * Set slug validation pattern
803
+ */
804
+ slug() {
805
+ this.attr.pattern = "^[a-z0-9]+(?:-[a-z0-9]+)*$";
806
+ return this;
807
+ }
808
+ };
809
+ function text(config) {
810
+ return new TextAttributeBuilder(config.name, config.label);
811
+ }
812
+ var TextAreaAttributeBuilder = class extends BaseAttributeBuilder {
813
+ constructor(name, label) {
814
+ super("textarea", name, label);
815
+ }
816
+ required() {
817
+ this.setRequired(true);
818
+ return this;
819
+ }
820
+ optional() {
821
+ this.setRequired(false);
822
+ return this;
823
+ }
824
+ };
825
+ function textarea(config) {
826
+ return new TextAreaAttributeBuilder(config.name, config.label);
827
+ }
828
+ var NumberAttributeBuilder = class extends BaseAttributeBuilder {
829
+ constructor(name, label) {
830
+ super("number", name, label);
831
+ }
832
+ min(value) {
833
+ this.attr.min = value;
834
+ return this;
835
+ }
836
+ max(value) {
837
+ this.attr.max = value;
838
+ return this;
839
+ }
840
+ integer() {
841
+ this.attr.unit = "integer";
842
+ this.attr.decimals = 0;
843
+ return this;
844
+ }
845
+ decimal(decimals = 2) {
846
+ this.attr.unit = "decimal";
847
+ this.attr.decimals = decimals;
848
+ return this;
849
+ }
850
+ percentage() {
851
+ this.attr.unit = "percentage";
852
+ return this;
853
+ }
854
+ required() {
855
+ this.setRequired(true);
856
+ return this;
857
+ }
858
+ optional() {
859
+ this.setRequired(false);
860
+ return this;
861
+ }
862
+ };
863
+ function number(config) {
864
+ return new NumberAttributeBuilder(config.name, config.label);
865
+ }
866
+ var CheckboxAttributeBuilder = class extends BaseAttributeBuilder {
867
+ constructor(name, label) {
868
+ super("checkbox", name, label);
869
+ }
870
+ required() {
871
+ this.setRequired(true);
872
+ return this;
873
+ }
874
+ optional() {
875
+ this.setRequired(false);
876
+ return this;
877
+ }
878
+ };
879
+ function checkbox(config) {
880
+ return new CheckboxAttributeBuilder(config.name, config.label);
881
+ }
882
+ var DateAttributeBuilder = class extends BaseAttributeBuilder {
883
+ constructor(name, label) {
884
+ super("date", name, label);
885
+ }
886
+ format(value) {
887
+ this.attr.dateFormat = value;
888
+ return this;
889
+ }
890
+ minDate(value) {
891
+ this.attr.minDate = value;
892
+ return this;
893
+ }
894
+ maxDate(value) {
895
+ this.attr.maxDate = value;
896
+ return this;
897
+ }
898
+ required() {
899
+ this.setRequired(true);
900
+ return this;
901
+ }
902
+ optional() {
903
+ this.setRequired(false);
904
+ return this;
905
+ }
906
+ };
907
+ function date(config) {
908
+ return new DateAttributeBuilder(config.name, config.label);
909
+ }
910
+ var PhoneAttributeBuilder = class extends BaseAttributeBuilder {
911
+ constructor(name, label) {
912
+ super("phone", name, label);
913
+ }
914
+ defaultCountry(value) {
915
+ this.attr.defaultCountryCode = value;
916
+ return this;
917
+ }
918
+ required() {
919
+ this.setRequired(true);
920
+ return this;
921
+ }
922
+ optional() {
923
+ this.setRequired(false);
924
+ return this;
925
+ }
926
+ };
927
+ function phone(config) {
928
+ return new PhoneAttributeBuilder(config.name, config.label);
929
+ }
930
+ var CurrencyAttributeBuilder = class extends BaseAttributeBuilder {
931
+ constructor(name, label) {
932
+ super("currency", name, label);
933
+ }
934
+ defaultCurrency(value) {
935
+ this.attr.defaultCurrency = value;
936
+ return this;
937
+ }
938
+ allowedCurrencies(value) {
939
+ this.attr.allowedCurrencies = value;
940
+ return this;
941
+ }
942
+ required() {
943
+ this.setRequired(true);
944
+ return this;
945
+ }
946
+ optional() {
947
+ this.setRequired(false);
948
+ return this;
949
+ }
950
+ };
951
+ function currency(config) {
952
+ return new CurrencyAttributeBuilder(config.name, config.label);
953
+ }
954
+ var StatusAttributeBuilder = class extends BaseAttributeBuilder {
955
+ constructor(name, label) {
956
+ super("status", name, label);
957
+ }
958
+ /**
959
+ * Set all options at once (preserves literal types for values)
960
+ */
961
+ options(value) {
962
+ this.attr.options = value;
963
+ return this;
964
+ }
965
+ option(config) {
966
+ if (!this.attr.options) {
967
+ this.attr.options = [];
968
+ }
969
+ this.attr.options.push(config);
970
+ return this;
971
+ }
972
+ required() {
973
+ this.setRequired(true);
974
+ return this;
975
+ }
976
+ optional() {
977
+ this.setRequired(false);
978
+ return this;
979
+ }
980
+ };
981
+ function status(config) {
982
+ return new StatusAttributeBuilder(config.name, config.label);
983
+ }
984
+ var SelectAttributeBuilder = class extends BaseAttributeBuilder {
985
+ constructor(name, label) {
986
+ super("select", name, label);
987
+ }
988
+ /**
989
+ * Set all options at once (preserves literal types for values)
990
+ */
991
+ options(value) {
992
+ this.attr.options = value;
993
+ return this;
994
+ }
995
+ option(config) {
996
+ if (!this.attr.options) {
997
+ this.attr.options = [];
998
+ }
999
+ this.attr.options.push(config);
1000
+ return this;
1001
+ }
1002
+ required() {
1003
+ this.setRequired(true);
1004
+ return this;
1005
+ }
1006
+ optional() {
1007
+ this.setRequired(false);
1008
+ return this;
1009
+ }
1010
+ };
1011
+ function select(config) {
1012
+ return new SelectAttributeBuilder(config.name, config.label);
1013
+ }
1014
+ var MultiselectAttributeBuilder = class extends BaseAttributeBuilder {
1015
+ constructor(name, label) {
1016
+ super("multiselect", name, label);
1017
+ }
1018
+ /**
1019
+ * Set all options at once (preserves literal types for values)
1020
+ */
1021
+ options(value) {
1022
+ this.attr.options = value;
1023
+ return this;
1024
+ }
1025
+ option(config) {
1026
+ if (!this.attr.options) {
1027
+ this.attr.options = [];
1028
+ }
1029
+ this.attr.options.push(config);
1030
+ return this;
1031
+ }
1032
+ required() {
1033
+ this.setRequired(true);
1034
+ return this;
1035
+ }
1036
+ optional() {
1037
+ this.setRequired(false);
1038
+ return this;
1039
+ }
1040
+ };
1041
+ function multiselect(config) {
1042
+ return new MultiselectAttributeBuilder(config.name, config.label);
1043
+ }
1044
+ var LocationAttributeBuilder = class extends BaseAttributeBuilder {
1045
+ constructor(name, label) {
1046
+ super("location", name, label);
1047
+ }
1048
+ granularity(value) {
1049
+ this.attr.granularity = value;
1050
+ return this;
1051
+ }
1052
+ enableAutocomplete() {
1053
+ this.attr.enableAutocomplete = true;
1054
+ return this;
1055
+ }
1056
+ enableMap() {
1057
+ this.attr.enableMap = true;
1058
+ return this;
1059
+ }
1060
+ defaultCountry(value) {
1061
+ this.attr.defaultCountry = value;
1062
+ return this;
1063
+ }
1064
+ allowedCountries(value) {
1065
+ this.attr.allowedCountries = value;
1066
+ return this;
1067
+ }
1068
+ displayFormat(value) {
1069
+ this.attr.displayFormat = value;
1070
+ return this;
1071
+ }
1072
+ required() {
1073
+ this.setRequired(true);
1074
+ return this;
1075
+ }
1076
+ optional() {
1077
+ this.setRequired(false);
1078
+ return this;
1079
+ }
1080
+ };
1081
+ function location(config) {
1082
+ return new LocationAttributeBuilder(config.name, config.label);
1083
+ }
1084
+ var TimestampAttributeBuilder = class extends BaseAttributeBuilder {
1085
+ constructor(name, label) {
1086
+ super("timestamp", name, label);
1087
+ }
1088
+ autoUpdate() {
1089
+ this.attr.autoUpdate = true;
1090
+ return this;
1091
+ }
1092
+ required() {
1093
+ this.setRequired(true);
1094
+ return this;
1095
+ }
1096
+ optional() {
1097
+ this.setRequired(false);
1098
+ return this;
1099
+ }
1100
+ };
1101
+ function timestamp(config) {
1102
+ return new TimestampAttributeBuilder(config.name, config.label);
1103
+ }
1104
+ var FileAttributeBuilder = class extends BaseAttributeBuilder {
1105
+ constructor(name, label) {
1106
+ super("file", name, label);
1107
+ }
1108
+ maxFiles(value) {
1109
+ this.attr.maxFiles = value;
1110
+ return this;
1111
+ }
1112
+ maxSize(bytes) {
1113
+ this.attr.maxSize = bytes;
1114
+ return this;
1115
+ }
1116
+ allowedTypes(types) {
1117
+ this.attr.allowedTypes = types;
1118
+ return this;
1119
+ }
1120
+ verification(config) {
1121
+ this.attr.verification = config;
1122
+ return this;
1123
+ }
1124
+ required() {
1125
+ this.setRequired(true);
1126
+ return this;
1127
+ }
1128
+ optional() {
1129
+ this.setRequired(false);
1130
+ return this;
1131
+ }
1132
+ };
1133
+ function file(config) {
1134
+ return new FileAttributeBuilder(config.name, config.label);
1135
+ }
1136
+ var UserAttributeBuilder = class extends BaseAttributeBuilder {
1137
+ constructor(name, label) {
1138
+ super("user", name, label);
1139
+ }
1140
+ allowedRoles(roles) {
1141
+ this.attr.allowedRoles = roles;
1142
+ return this;
1143
+ }
1144
+ required() {
1145
+ this.setRequired(true);
1146
+ return this;
1147
+ }
1148
+ optional() {
1149
+ this.setRequired(false);
1150
+ return this;
1151
+ }
1152
+ };
1153
+ function user(config) {
1154
+ return new UserAttributeBuilder(config.name, config.label);
1155
+ }
1156
+ var SingleRelationAttributeBuilder = class extends BaseAttributeBuilder {
1157
+ constructor(name, label) {
1158
+ super("relation", name, label);
1159
+ this.attr.cardinality = "one";
1160
+ this.attr.targets = [];
1161
+ }
1162
+ /**
1163
+ * Add a target object that can be linked
1164
+ * @param objectName - Name of the object (e.g., "companies")
1165
+ * @param options - Display template and filter options
1166
+ */
1167
+ to(objectName, options) {
1168
+ const target = {
1169
+ object: objectName,
1170
+ ...options
1171
+ };
1172
+ this.attr.targets?.push(target);
1173
+ return this;
1174
+ }
1175
+ /**
1176
+ * Set the deletion strategy when target record is deleted
1177
+ * @param strategy - "restrict" (default), "cascade", or "set_null"
1178
+ */
1179
+ onDelete(strategy) {
1180
+ this.attr.onDelete = strategy;
1181
+ return this;
1182
+ }
1183
+ /**
1184
+ * Convert to a multi-relation (cardinality: "many")
1185
+ */
1186
+ many() {
1187
+ const multiBuilder = new MultiRelationAttributeBuilder(
1188
+ this.attr.name,
1189
+ this.attr.label ?? "",
1190
+ {
1191
+ targets: this.attr.targets,
1192
+ onDelete: this.attr.onDelete,
1193
+ isRequired: this.attr.required
1194
+ }
1195
+ );
1196
+ return multiBuilder;
1197
+ }
1198
+ required() {
1199
+ this.setRequired(true);
1200
+ return this;
1201
+ }
1202
+ optional() {
1203
+ this.setRequired(false);
1204
+ return this;
1205
+ }
1206
+ };
1207
+ var MultiRelationAttributeBuilder = class extends BaseAttributeBuilder {
1208
+ constructor(name, label, initOptions) {
1209
+ super("relation", name, label);
1210
+ this.attr.cardinality = "many";
1211
+ this.attr.targets = initOptions?.targets ?? [];
1212
+ this.attr.defaultValue = [];
1213
+ if (initOptions?.onDelete) {
1214
+ this.attr.onDelete = initOptions.onDelete;
1215
+ }
1216
+ if (initOptions?.isRequired) {
1217
+ this.setRequired(true);
1218
+ }
1219
+ }
1220
+ /**
1221
+ * Add a target object that can be linked
1222
+ * @param objectName - Name of the object (e.g., "companies")
1223
+ * @param options - Display template and filter options
1224
+ */
1225
+ to(objectName, options) {
1226
+ const target = {
1227
+ object: objectName,
1228
+ ...options
1229
+ };
1230
+ this.attr.targets?.push(target);
1231
+ return this;
1232
+ }
1233
+ /**
1234
+ * Set the deletion strategy when target record is deleted
1235
+ * @param strategy - "restrict" (default), "cascade", or "set_null"
1236
+ */
1237
+ onDelete(strategy) {
1238
+ this.attr.onDelete = strategy;
1239
+ return this;
1240
+ }
1241
+ /**
1242
+ * Set minimum number of relations required
1243
+ */
1244
+ minItems(count) {
1245
+ this.attr.minItems = count;
1246
+ return this;
1247
+ }
1248
+ /**
1249
+ * Set maximum number of relations allowed
1250
+ */
1251
+ maxItems(count) {
1252
+ this.attr.maxItems = count;
1253
+ return this;
1254
+ }
1255
+ required() {
1256
+ this.setRequired(true);
1257
+ return this;
1258
+ }
1259
+ optional() {
1260
+ this.setRequired(false);
1261
+ return this;
1262
+ }
1263
+ };
1264
+ function relation(config) {
1265
+ return new SingleRelationAttributeBuilder(config.name, config.label);
1266
+ }
1267
+ var RatingAttributeBuilder = class extends BaseAttributeBuilder {
1268
+ constructor(name, label) {
1269
+ super("rating", name, label);
1270
+ }
1271
+ max(value) {
1272
+ this.attr.max = value;
1273
+ return this;
1274
+ }
1275
+ iconType(value) {
1276
+ this.attr.iconType = value;
1277
+ return this;
1278
+ }
1279
+ required() {
1280
+ this.setRequired(true);
1281
+ return this;
1282
+ }
1283
+ optional() {
1284
+ this.setRequired(false);
1285
+ return this;
1286
+ }
1287
+ };
1288
+ function rating(config) {
1289
+ return new RatingAttributeBuilder(config.name, config.label);
1290
+ }
1291
+
1292
+ // src/builders/object-builder.ts
1293
+ import z2 from "zod";
1294
+ var ObjectBuilder = class {
1295
+ constructor(config) {
1296
+ this.validateName(config.name);
1297
+ this.obj = {
1298
+ name: config.name,
1299
+ label: config.label,
1300
+ attributes: [],
1301
+ system: false
1302
+ };
1303
+ }
1304
+ /**
1305
+ * Set object description
1306
+ */
1307
+ description(value) {
1308
+ this.obj.description = value;
1309
+ return this;
1310
+ }
1311
+ /**
1312
+ * Set object icon
1313
+ */
1314
+ icon(value) {
1315
+ this.obj.icon = value;
1316
+ return this;
1317
+ }
1318
+ /**
1319
+ * Mark as system/native object (defined in code, protected)
1320
+ * System objects cannot be deleted/modified by clients
1321
+ */
1322
+ system() {
1323
+ this.obj.system = true;
1324
+ return this;
1325
+ }
1326
+ /**
1327
+ * Add an attribute to the object with type accumulation
1328
+ *
1329
+ * The return type accumulates the attribute's name and value type
1330
+ * into the TRecord generic, enabling full inference.
1331
+ *
1332
+ * @param attr - Attribute definition or builder (auto-builds if builder)
1333
+ */
1334
+ attribute(attr) {
1335
+ if (!this.obj.attributes) {
1336
+ this.obj.attributes = [];
1337
+ }
1338
+ const finalAttr = "build" in attr && typeof attr.build === "function" ? attr.build() : attr;
1339
+ this.obj.attributes.push(finalAttr);
1340
+ return this;
1341
+ }
1342
+ /**
1343
+ * Add multiple attributes at once
1344
+ * Note: For full type inference, prefer chaining .attribute() calls
1345
+ */
1346
+ attributes(attrs) {
1347
+ if (!this.obj.attributes) {
1348
+ this.obj.attributes = [];
1349
+ }
1350
+ const finalAttrs = attrs.map((attr) => "build" in attr ? attr.build() : attr);
1351
+ this.obj.attributes.push(...finalAttrs);
1352
+ return this;
1353
+ }
1354
+ /**
1355
+ * Set metadata
1356
+ */
1357
+ metadata(value) {
1358
+ this.obj.metadata = value;
1359
+ return this;
1360
+ }
1361
+ /**
1362
+ * Set the title attribute (the text attribute used to display the object's name)
1363
+ * Must reference a text attribute that has been added to the object.
1364
+ * If not set, the first text attribute becomes the title attribute.
1365
+ *
1366
+ * @param attributeName - The name of a text attribute
1367
+ */
1368
+ titleAttribute(attributeName) {
1369
+ this._titleAttribute = attributeName;
1370
+ return this;
1371
+ }
1372
+ /**
1373
+ * Build the final ObjectDefinition
1374
+ * @throws Error if required fields are missing or invalid
1375
+ */
1376
+ build() {
1377
+ if (!this.obj.name) {
1378
+ throw new Error("[ObjectBuilder] Missing required field: name");
1379
+ }
1380
+ if (!this.obj.label) {
1381
+ throw new Error("[ObjectBuilder] Missing required field: label");
1382
+ }
1383
+ const textAttributes = (this.obj.attributes ?? []).filter((attr) => attr.type === "text");
1384
+ if (textAttributes.length === 0) {
1385
+ throw new Error(
1386
+ `[ObjectBuilder] Object "${this.obj.name}" must have at least one text attribute.
1387
+ A text attribute is required to serve as the object's title/display name.
1388
+ \u2705 Example: .attribute(text({ name: 'name', label: 'Name' }).required())`
1389
+ );
1390
+ }
1391
+ const titleAttrName = this._titleAttribute ?? textAttributes[0].name;
1392
+ const titleAttr = textAttributes.find((attr) => attr.name === titleAttrName);
1393
+ if (!titleAttr) {
1394
+ const availableTextAttrs = textAttributes.map((a) => `'${a.name}'`).join(", ");
1395
+ throw new Error(
1396
+ `[ObjectBuilder] titleAttribute "${titleAttrName}" must be a text attribute.
1397
+ Available text attributes: ${availableTextAttrs}`
1398
+ );
1399
+ }
1400
+ return {
1401
+ ...this.obj,
1402
+ titleAttribute: titleAttrName
1403
+ };
1404
+ }
1405
+ /**
1406
+ * Validate object name format
1407
+ * Must be kebab-case (slug format), max 63 characters
1408
+ * @internal
1409
+ */
1410
+ validateName(name) {
1411
+ if (name === void 0) {
1412
+ return;
1413
+ }
1414
+ const objectNameSchema = z2.string().min(1, "Object name cannot be empty").max(63, "Object name is too long (max 63 characters)").regex(/^[a-z][a-z0-9-]*$/, {
1415
+ message: "Invalid object name format.\nName must be in kebab-case (slug format):\n \u2705 Valid: 'products', 'user-profiles', 'order-items'\n \u274C Invalid: 'Products', 'userProfiles', 'user_profiles'"
1416
+ });
1417
+ try {
1418
+ objectNameSchema.parse(name);
1419
+ } catch (error) {
1420
+ if (error instanceof z2.ZodError) {
1421
+ throw new Error(`[ObjectBuilder] ${error.errors[0].message}`);
1422
+ }
1423
+ throw error;
1424
+ }
1425
+ }
1426
+ };
1427
+ function object(config) {
1428
+ return new ObjectBuilder(config);
1429
+ }
1430
+
1431
+ // src/builders/view-builder.ts
1432
+ import { z as z3 } from "zod";
1433
+ var GroupBuilder = class {
1434
+ constructor(id, label) {
1435
+ this.data = { fields: [] };
1436
+ this.data.id = id;
1437
+ this.data.label = label;
1438
+ }
1439
+ /**
1440
+ * Set group description
1441
+ */
1442
+ description(value) {
1443
+ this.data.description = value;
1444
+ return this;
1445
+ }
1446
+ /**
1447
+ * Make group collapsible
1448
+ * @param collapsed - Initial collapsed state (default: false)
1449
+ */
1450
+ collapsible(collapsed = false) {
1451
+ this.data.collapsible = true;
1452
+ this.data.collapsed = collapsed;
1453
+ return this;
1454
+ }
1455
+ /**
1456
+ * Set display order
1457
+ */
1458
+ order(value) {
1459
+ this.data.order = value;
1460
+ return this;
1461
+ }
1462
+ /**
1463
+ * Add multiple fields with default options
1464
+ * @example .fields("name", "email", "phone")
1465
+ */
1466
+ fields(...names) {
1467
+ for (const name of names) {
1468
+ this.data.fields?.push({ attribute: name });
1469
+ }
1470
+ return this;
1471
+ }
1472
+ /**
1473
+ * Add a single field with options
1474
+ * @example .field("name", { span: 8, readOnly: true })
1475
+ */
1476
+ field(attribute, options) {
1477
+ this.data.fields?.push({ attribute, ...options });
1478
+ return this;
1479
+ }
1480
+ /**
1481
+ * Build the group definition
1482
+ */
1483
+ build() {
1484
+ if (!this.data.id) {
1485
+ throw new Error("[GroupBuilder] id is required");
1486
+ }
1487
+ if (!this.data.label) {
1488
+ throw new Error("[GroupBuilder] label is required");
1489
+ }
1490
+ if (!this.data.fields || this.data.fields.length === 0) {
1491
+ throw new Error("[GroupBuilder] At least one field is required");
1492
+ }
1493
+ return this.data;
1494
+ }
1495
+ };
1496
+ var TableTabConfig = class {
1497
+ /** @internal */
1498
+ constructor(view2, base, relation2) {
1499
+ this.view = view2;
1500
+ this.tabData = { ...base, type: "table", relation: relation2, columns: [] };
1501
+ }
1502
+ /**
1503
+ * Set columns to display
1504
+ * @example .columns("firstName", "lastName", "email")
1505
+ */
1506
+ columns(...names) {
1507
+ this.tabData.columns = names;
1508
+ return this;
1509
+ }
1510
+ /**
1511
+ * Allow creating new records
1512
+ */
1513
+ create() {
1514
+ this.tabData.allowCreate = true;
1515
+ return this;
1516
+ }
1517
+ /**
1518
+ * Allow inline editing
1519
+ */
1520
+ edit() {
1521
+ this.tabData.allowEdit = true;
1522
+ return this;
1523
+ }
1524
+ /**
1525
+ * Allow deleting records
1526
+ */
1527
+ delete() {
1528
+ this.tabData.allowDelete = true;
1529
+ return this;
1530
+ }
1531
+ /**
1532
+ * Enable all CRUD operations (create, edit, delete)
1533
+ */
1534
+ crud() {
1535
+ this.tabData.allowCreate = true;
1536
+ this.tabData.allowEdit = true;
1537
+ this.tabData.allowDelete = true;
1538
+ return this;
1539
+ }
1540
+ /**
1541
+ * Set default filters
1542
+ */
1543
+ filters(value) {
1544
+ this.tabData.filters = value;
1545
+ return this;
1546
+ }
1547
+ /**
1548
+ * Set default sort
1549
+ * @example .sort("lastName") or .sort("createdAt", "desc")
1550
+ */
1551
+ sort(field, order = "asc") {
1552
+ this.tabData.sort = { field, order };
1553
+ return this;
1554
+ }
1555
+ /**
1556
+ * Continue building with a new tab
1557
+ */
1558
+ tab(name, label) {
1559
+ this.finalize();
1560
+ return new TabBuilder(this.view, name, label);
1561
+ }
1562
+ /**
1563
+ * Finish this tab and return to ViewBuilder
1564
+ */
1565
+ done() {
1566
+ this.finalize();
1567
+ return this.view;
1568
+ }
1569
+ /**
1570
+ * Build the final view definition
1571
+ */
1572
+ build() {
1573
+ this.finalize();
1574
+ return this.view.build();
1575
+ }
1576
+ finalize() {
1577
+ if (!this.tabData.columns || this.tabData.columns.length === 0) {
1578
+ throw new Error(`[TableTabConfig] columns() is required for tab "${this.tabData.name}"`);
1579
+ }
1580
+ this.view._addTab(this.tabData);
1581
+ }
1582
+ };
1583
+ var CustomTabConfig = class {
1584
+ /** @internal */
1585
+ constructor(view2, base, component) {
1586
+ this.view = view2;
1587
+ this.tabData = { ...base, type: "custom", component };
1588
+ }
1589
+ /**
1590
+ * Set props to pass to the component
1591
+ */
1592
+ props(value) {
1593
+ this.tabData.props = value;
1594
+ return this;
1595
+ }
1596
+ /**
1597
+ * Continue building with a new tab
1598
+ */
1599
+ tab(name, label) {
1600
+ this.view._addTab(this.tabData);
1601
+ return new TabBuilder(this.view, name, label);
1602
+ }
1603
+ /**
1604
+ * Finish this tab and return to ViewBuilder
1605
+ */
1606
+ done() {
1607
+ this.view._addTab(this.tabData);
1608
+ return this.view;
1609
+ }
1610
+ /**
1611
+ * Build the final view definition
1612
+ */
1613
+ build() {
1614
+ this.view._addTab(this.tabData);
1615
+ return this.view.build();
1616
+ }
1617
+ };
1618
+ var TabBuilder = class {
1619
+ /** @internal */
1620
+ constructor(view2, name, label) {
1621
+ this.view = view2;
1622
+ this.base = {
1623
+ id: name,
1624
+ name,
1625
+ label
1626
+ };
1627
+ }
1628
+ /**
1629
+ * Set tab icon
1630
+ */
1631
+ icon(value) {
1632
+ this.base.icon = value;
1633
+ return this;
1634
+ }
1635
+ /**
1636
+ * Set display order
1637
+ */
1638
+ order(value) {
1639
+ this.base.order = value;
1640
+ return this;
1641
+ }
1642
+ /**
1643
+ * Mark as system tab (protected)
1644
+ */
1645
+ system() {
1646
+ this.base.system = true;
1647
+ return this;
1648
+ }
1649
+ // ─────────────────────────────────────────────────────────────────────────
1650
+ // TYPE DISCRIMINATORS
1651
+ // ─────────────────────────────────────────────────────────────────────────
1652
+ /**
1653
+ * Create a form tab with groups
1654
+ * @example .form(group("info", "Info").fields("name", "email"))
1655
+ */
1656
+ form(...groups) {
1657
+ if (groups.length === 0) {
1658
+ throw new Error(
1659
+ `[TabBuilder] form() requires at least one group for tab "${this.base.name}"`
1660
+ );
1661
+ }
1662
+ const tab = {
1663
+ ...this.base,
1664
+ type: "form",
1665
+ groups: groups.map((g) => g instanceof GroupBuilder ? g.build() : g)
1666
+ };
1667
+ return this.view._addTab(tab);
1668
+ }
1669
+ /**
1670
+ * Create a table tab for a relation
1671
+ * @example .table("contacts").columns("name", "email").crud()
1672
+ */
1673
+ table(relation2) {
1674
+ return new TableTabConfig(this.view, this.base, relation2);
1675
+ }
1676
+ /**
1677
+ * Create a custom tab with a component
1678
+ * @example .custom("AnalyticsWidget").props({ period: "12m" })
1679
+ */
1680
+ custom(component) {
1681
+ return new CustomTabConfig(this.view, this.base, component);
1682
+ }
1683
+ };
1684
+ var ViewBuilder = class {
1685
+ constructor(name, label) {
1686
+ this.data = { tabs: [] };
1687
+ this.validated = false;
1688
+ this.validateName(name);
1689
+ this.data.name = name;
1690
+ this.data.label = label;
1691
+ }
1692
+ /**
1693
+ * Set view description
1694
+ */
1695
+ description(value) {
1696
+ this.data.description = value;
1697
+ return this;
1698
+ }
1699
+ /**
1700
+ * Set view icon
1701
+ */
1702
+ icon(value) {
1703
+ this.data.icon = value;
1704
+ return this;
1705
+ }
1706
+ /**
1707
+ * Associate view with an object
1708
+ * @param objectName - Object name (kebab-case)
1709
+ */
1710
+ for(objectName) {
1711
+ this.data.object = objectName;
1712
+ return this;
1713
+ }
1714
+ /**
1715
+ * Mark as default view for the object
1716
+ */
1717
+ default() {
1718
+ this.data.default = true;
1719
+ return this;
1720
+ }
1721
+ /**
1722
+ * Mark as system view (protected, defined by developer)
1723
+ */
1724
+ system() {
1725
+ this.data.system = true;
1726
+ return this;
1727
+ }
1728
+ /**
1729
+ * Set metadata
1730
+ */
1731
+ metadata(value) {
1732
+ this.data.metadata = value;
1733
+ return this;
1734
+ }
1735
+ /**
1736
+ * Start building a new tab
1737
+ */
1738
+ tab(name, label) {
1739
+ return new TabBuilder(this, name, label);
1740
+ }
1741
+ /**
1742
+ * Add a pre-built tab
1743
+ */
1744
+ addTab(tab) {
1745
+ this.data.tabs?.push(tab);
1746
+ return this;
1747
+ }
1748
+ /**
1749
+ * @internal Used by TabBuilder to add tabs
1750
+ */
1751
+ _addTab(tab) {
1752
+ this.data.tabs?.push(tab);
1753
+ return this;
1754
+ }
1755
+ /**
1756
+ * Build the final view definition
1757
+ */
1758
+ build() {
1759
+ if (!this.data.object) {
1760
+ throw new Error("[ViewBuilder] for() is required - specify the target object");
1761
+ }
1762
+ if (!this.data.tabs || this.data.tabs.length === 0) {
1763
+ throw new Error("[ViewBuilder] At least one tab is required");
1764
+ }
1765
+ const tabNames = /* @__PURE__ */ new Set();
1766
+ for (const tab of this.data.tabs) {
1767
+ if (tabNames.has(tab.name)) {
1768
+ throw new Error(`[ViewBuilder] Duplicate tab name "${tab.name}"`);
1769
+ }
1770
+ tabNames.add(tab.name);
1771
+ }
1772
+ this.validated = true;
1773
+ return this.data;
1774
+ }
1775
+ /**
1776
+ * Validate view name format (kebab-case)
1777
+ */
1778
+ validateName(name) {
1779
+ const viewNameSchema = z3.string().min(1, "View name cannot be empty").max(63, "View name is too long (max 63 characters)").regex(/^[a-z][a-z0-9-]*$/, {
1780
+ message: "Invalid view name format.\nName must be in kebab-case:\n \u2705 Valid: 'detail', 'list-view', 'company-detail'\n \u274C Invalid: 'Detail', 'listView', 'list_view'"
1781
+ });
1782
+ try {
1783
+ viewNameSchema.parse(name);
1784
+ } catch (error) {
1785
+ if (error instanceof z3.ZodError) {
1786
+ throw new Error(`[ViewBuilder] ${error.errors[0].message}`);
1787
+ }
1788
+ throw error;
1789
+ }
1790
+ }
1791
+ };
1792
+ function view(name, label) {
1793
+ return new ViewBuilder(name, label);
1794
+ }
1795
+ function group(id, label) {
1796
+ return new GroupBuilder(id, label);
1797
+ }
1798
+
1799
+ // src/runtime/services/object-schema.service.ts
1800
+ var ObjectSchemaService = class {
1801
+ constructor(adapter, nativeRegistry) {
1802
+ this.adapter = adapter;
1803
+ this.nativeRegistry = nativeRegistry;
1804
+ }
1805
+ /**
1806
+ * Create a new custom object
1807
+ * Validates name format and ensures system=false
1808
+ *
1809
+ * @param definition - Object definition (attributes can be raw definitions or builders)
1810
+ * @param tenantId - Tenant ID owning the object
1811
+ * @returns Created ObjectDefinition
1812
+ */
1813
+ async createCustomObject(definition, tenantId) {
1814
+ const builder = object({
1815
+ name: definition.name,
1816
+ label: definition.label
1817
+ });
1818
+ if (definition.description) builder.description(definition.description);
1819
+ if (definition.icon) builder.icon(definition.icon);
1820
+ if (definition.metadata) builder.metadata(definition.metadata);
1821
+ if (definition.attributes && definition.attributes.length > 0) {
1822
+ builder.attributes(definition.attributes);
1823
+ }
1824
+ const objectDef = builder.build();
1825
+ const existing = await this.adapter.objects.findByName(tenantId, objectDef.name);
1826
+ if (existing) {
1827
+ throw new Error(`Object with name "${objectDef.name}" already exists`);
1828
+ }
1829
+ const metadata = {
1830
+ ...objectDef.metadata,
1831
+ icon: objectDef.icon
1832
+ };
1833
+ const dbObject = await this.adapter.objects.create({
1834
+ tenantId,
1835
+ name: objectDef.name,
1836
+ label: objectDef.label,
1837
+ description: objectDef.description,
1838
+ system: false,
1839
+ // Always false for custom objects
1840
+ metadata
1841
+ });
1842
+ const createdAttributes = [];
1843
+ if (objectDef.attributes.length > 0) {
1844
+ for (const attr of objectDef.attributes) {
1845
+ const dbAttr = await this.adapter.attributes.create({
1846
+ objectId: dbObject.id,
1847
+ name: attr.name,
1848
+ label: attr.label,
1849
+ type: attr.type,
1850
+ required: attr.required ?? false,
1851
+ system: false,
1852
+ // Always false for custom attributes
1853
+ config: {
1854
+ ...attr,
1855
+ // Remove common fields stored in columns
1856
+ id: void 0,
1857
+ name: void 0,
1858
+ label: void 0,
1859
+ type: void 0,
1860
+ required: void 0,
1861
+ system: void 0
1862
+ }
1863
+ });
1864
+ createdAttributes.push(this.convertDBAttributeToAttribute(dbAttr));
1865
+ }
1866
+ }
1867
+ return {
1868
+ ...objectDef,
1869
+ id: dbObject.id,
1870
+ attributes: createdAttributes,
1871
+ system: false
1872
+ };
1873
+ }
1874
+ /**
1875
+ * Add a custom attribute to an existing object
1876
+ * Can be used on both custom and native objects
1877
+ * Attributes added via API are always custom (system=false)
1878
+ *
1879
+ * @param objectId - Object UUID from database
1880
+ * @param attribute - Attribute definition
1881
+ * @returns Created Attribute
1882
+ */
1883
+ async addAttributeToObject(objectId, attribute) {
1884
+ this.validateAttributeName(attribute.name);
1885
+ const dbObject = await this.adapter.objects.findById(objectId);
1886
+ if (!dbObject) {
1887
+ throw new Error(`Object with id "${objectId}" not found`);
1888
+ }
1889
+ const existingAttributes = await this.adapter.attributes.findByObjectId(objectId);
1890
+ const duplicate = existingAttributes.find((attr) => attr.name === attribute.name);
1891
+ if (duplicate) {
1892
+ throw new Error(
1893
+ `Attribute with name "${attribute.name}" already exists on object "${dbObject.name}"`
1894
+ );
1895
+ }
1896
+ const dbAttr = await this.adapter.attributes.create({
1897
+ objectId,
1898
+ name: attribute.name,
1899
+ label: attribute.label,
1900
+ type: attribute.type,
1901
+ required: attribute.required ?? false,
1902
+ unique: attribute.unique ?? false,
1903
+ system: false,
1904
+ // Always false for attributes added via API
1905
+ config: {
1906
+ // Store all extra properties in config
1907
+ ...attribute,
1908
+ // Remove common fields stored in columns
1909
+ name: void 0,
1910
+ label: void 0,
1911
+ type: void 0,
1912
+ required: void 0,
1913
+ unique: void 0,
1914
+ system: void 0
1915
+ }
1916
+ });
1917
+ return this.convertDBAttributeToAttribute(dbAttr);
1918
+ }
1919
+ /**
1920
+ * Update an attribute
1921
+ * Can only update custom attributes (system=false)
1922
+ *
1923
+ * @param attributeId - Attribute UUID
1924
+ * @param updates - Partial attribute updates
1925
+ * @returns Updated Attribute
1926
+ */
1927
+ async updateAttribute(attributeId, updates) {
1928
+ const dbAttr = await this.adapter.attributes.findById(attributeId);
1929
+ if (!dbAttr) {
1930
+ throw new Error(`Attribute with id "${attributeId}" not found`);
1931
+ }
1932
+ if (dbAttr.system) {
1933
+ throw new Error(
1934
+ `Cannot modify system attribute "${dbAttr.name}". System attributes are protected.`
1935
+ );
1936
+ }
1937
+ if (updates.name && updates.name !== dbAttr.name) {
1938
+ throw new Error(
1939
+ "Attribute name cannot be changed after creation. Create a new attribute instead."
1940
+ );
1941
+ }
1942
+ if (updates.type && updates.type !== dbAttr.type) {
1943
+ throw new Error(
1944
+ "Attribute type cannot be changed after creation. Create a new attribute instead."
1945
+ );
1946
+ }
1947
+ const updatedDbAttr = await this.adapter.attributes.update(attributeId, {
1948
+ label: updates.label,
1949
+ required: updates.required,
1950
+ config: updates ? {
1951
+ ...dbAttr.config,
1952
+ ...updates,
1953
+ // Remove common fields
1954
+ name: void 0,
1955
+ label: void 0,
1956
+ type: void 0,
1957
+ required: void 0,
1958
+ unique: void 0,
1959
+ system: void 0
1960
+ } : dbAttr.config
1961
+ });
1962
+ return this.convertDBAttributeToAttribute(updatedDbAttr);
1963
+ }
1964
+ /**
1965
+ * Delete an attribute
1966
+ * Can only delete custom attributes (system=false)
1967
+ *
1968
+ * @param attributeId - Attribute UUID
1969
+ */
1970
+ async deleteAttribute(attributeId) {
1971
+ const dbAttr = await this.adapter.attributes.findById(attributeId);
1972
+ if (!dbAttr) {
1973
+ throw new Error(`Attribute with id "${attributeId}" not found`);
1974
+ }
1975
+ if (dbAttr.system) {
1976
+ throw new Error(
1977
+ `Cannot delete system attribute "${dbAttr.name}". System attributes are protected.`
1978
+ );
1979
+ }
1980
+ await this.adapter.attributes.delete(attributeId);
1981
+ }
1982
+ /**
1983
+ * List attributes for an object
1984
+ *
1985
+ * @param objectId - Object UUID
1986
+ * @param options - Filter options
1987
+ * @returns List of attributes
1988
+ */
1989
+ async listAttributes(objectId, options) {
1990
+ const dbAttributes = await this.adapter.attributes.findByObjectId(objectId);
1991
+ let filtered = dbAttributes;
1992
+ if (options?.systemOnly) {
1993
+ filtered = dbAttributes.filter((attr) => attr.system);
1994
+ } else if (options?.customOnly) {
1995
+ filtered = dbAttributes.filter((attr) => !attr.system);
1996
+ }
1997
+ return filtered.map((attr) => this.convertDBAttributeToAttribute(attr));
1998
+ }
1999
+ /**
2000
+ * Validate attribute name format (variable identifier)
2001
+ * @internal
2002
+ */
2003
+ validateAttributeName(name) {
2004
+ const variableNameRegex = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
2005
+ if (!name || name.length === 0) {
2006
+ throw new Error("Attribute name cannot be empty");
2007
+ }
2008
+ if (name.length > 63) {
2009
+ throw new Error("Attribute name is too long (max 63 characters)");
2010
+ }
2011
+ if (!variableNameRegex.test(name)) {
2012
+ throw new Error(
2013
+ "Invalid attribute name format.\nName must be a valid variable identifier:\n \u2705 Valid: 'firstName', 'first_name', 'FirstName', 'FIRST_NAME'\n \u274C Invalid: 'first-name', 'first name', '123name', 'first.name'"
2014
+ );
2015
+ }
2016
+ }
2017
+ /**
2018
+ * Get complete object schema (system + custom attributes)
2019
+ * If object is native, merges registry definition with DB custom attributes
2020
+ * If object is custom, returns DB definition only
2021
+ *
2022
+ * @param objectId - Object UUID from database
2023
+ * @returns Complete ObjectDefinition with all attributes
2024
+ *
2025
+ * @example
2026
+ * ```typescript
2027
+ * const service = new ObjectSchemaService(adapter, registry);
2028
+ * const productSchema = await service.getObjectSchema("obj-123");
2029
+ *
2030
+ * console.log(productSchema.attributes); // System + custom attributes
2031
+ * ```
2032
+ */
2033
+ async getObjectSchema(objectId) {
2034
+ const dbObject = await this.adapter.objects.findById(objectId);
2035
+ if (!dbObject) {
2036
+ throw new Error(`Object with id "${objectId}" not found`);
2037
+ }
2038
+ const dbAttributes = await this.adapter.attributes.findByObjectId(objectId);
2039
+ if (dbObject.system) {
2040
+ return this.mergeNativeObject(dbObject, dbAttributes);
2041
+ }
2042
+ return this.convertDBObjectToDefinition(dbObject, dbAttributes);
2043
+ }
2044
+ /**
2045
+ * Get object schema by name (for system/native objects)
2046
+ * @deprecated Use getObjectSchemaByNameForTenant for custom objects support
2047
+ */
2048
+ async getObjectSchemaByName(name) {
2049
+ const dbObject = await this.adapter.objects.findSystemByName(name);
2050
+ if (!dbObject) {
2051
+ throw new Error(`Native object "${name}" not found in database`);
2052
+ }
2053
+ const dbAttributes = await this.adapter.attributes.findByObjectId(dbObject.id);
2054
+ return this.mergeNativeObject(dbObject, dbAttributes);
2055
+ }
2056
+ /**
2057
+ * Get object schema by name for a tenant (supports both native and custom objects)
2058
+ */
2059
+ async getObjectSchemaByNameForTenant(name, tenantId) {
2060
+ let dbObject = await this.adapter.objects.findByName(tenantId, name);
2061
+ if (!dbObject) {
2062
+ dbObject = await this.adapter.objects.findSystemByName(name);
2063
+ }
2064
+ if (!dbObject) {
2065
+ throw new Error(`Object "${name}" not found`);
2066
+ }
2067
+ const dbAttributes = await this.adapter.attributes.findByObjectId(dbObject.id);
2068
+ if (dbObject.system) {
2069
+ return this.mergeNativeObject(dbObject, dbAttributes);
2070
+ }
2071
+ return this.convertDBObjectToDefinition(dbObject, dbAttributes);
2072
+ }
2073
+ /**
2074
+ * List all object schemas for a tenant
2075
+ */
2076
+ async listObjectSchemas(tenantId) {
2077
+ const dbObjects = await this.adapter.objects.list(tenantId);
2078
+ const schemas = await Promise.all(
2079
+ dbObjects.map(async (dbObject) => {
2080
+ const dbAttributes = await this.adapter.attributes.findByObjectId(dbObject.id);
2081
+ if (dbObject.system) {
2082
+ return this.mergeNativeObject(dbObject, dbAttributes);
2083
+ }
2084
+ return this.convertDBObjectToDefinition(dbObject, dbAttributes);
2085
+ })
2086
+ );
2087
+ return schemas;
2088
+ }
2089
+ /**
2090
+ * Merge native object from registry with custom attributes from DB
2091
+ * @internal
2092
+ */
2093
+ mergeNativeObject(dbObject, dbAttributes) {
2094
+ const nativeObject = this.nativeRegistry.getByName(dbObject.name);
2095
+ if (!nativeObject) {
2096
+ throw new Error(
2097
+ `Native object "${dbObject.name}" not found in registry. Make sure to register it before querying.`
2098
+ );
2099
+ }
2100
+ const systemAttributesFromDB = dbAttributes.filter((attr) => attr.system);
2101
+ const customAttributes = dbAttributes.filter((attr) => !attr.system);
2102
+ const dbAttrByName = new Map(systemAttributesFromDB.map((attr) => [attr.name, attr]));
2103
+ const systemAttrs = nativeObject.attributes.map((registryAttr) => {
2104
+ const dbAttr = dbAttrByName.get(registryAttr.name);
2105
+ if (dbAttr) {
2106
+ return {
2107
+ ...registryAttr,
2108
+ id: dbAttr.id
2109
+ };
2110
+ }
2111
+ return registryAttr;
2112
+ });
2113
+ const customAttrs = customAttributes.map(
2114
+ (dbAttr) => this.convertDBAttributeToAttribute(dbAttr)
2115
+ );
2116
+ return {
2117
+ ...nativeObject,
2118
+ id: dbObject.id,
2119
+ attributes: [
2120
+ ...systemAttrs,
2121
+ // System attributes from registry (with DB IDs if synced)
2122
+ ...customAttrs
2123
+ // Custom attributes from DB
2124
+ ]
2125
+ };
2126
+ }
2127
+ /**
2128
+ * Convert DB object + attributes to ObjectDefinition
2129
+ * @internal
2130
+ */
2131
+ convertDBObjectToDefinition(dbObject, dbAttributes) {
2132
+ const attributes = dbAttributes.map(
2133
+ (dbAttr) => this.convertDBAttributeToAttribute(dbAttr)
2134
+ );
2135
+ const titleAttribute = dbObject.metadata?.titleAttribute ?? attributes.find((attr) => attr.type === "text")?.name ?? attributes[0]?.name ?? "name";
2136
+ return {
2137
+ id: dbObject.id,
2138
+ name: dbObject.name,
2139
+ label: dbObject.label,
2140
+ description: dbObject.description,
2141
+ icon: dbObject.metadata?.icon,
2142
+ titleAttribute,
2143
+ attributes,
2144
+ system: dbObject.system,
2145
+ metadata: dbObject.metadata
2146
+ };
2147
+ }
2148
+ /**
2149
+ * Convert DB attribute to Attribute type
2150
+ * @internal
2151
+ */
2152
+ convertDBAttributeToAttribute(dbAttr) {
2153
+ const baseAttr = {
2154
+ ...dbAttr.config,
2155
+ id: dbAttr.id,
2156
+ name: dbAttr.name,
2157
+ label: dbAttr.label,
2158
+ type: dbAttr.type,
2159
+ required: dbAttr.required,
2160
+ system: dbAttr.system,
2161
+ unique: dbAttr.unique
2162
+ };
2163
+ return baseAttr;
2164
+ }
2165
+ };
2166
+
2167
+ // src/native/registry.ts
2168
+ var NativeObjectRegistryClass = class {
2169
+ constructor() {
2170
+ this.objects = /* @__PURE__ */ new Map();
2171
+ }
2172
+ /**
2173
+ * Register one or more native objects
2174
+ * Auto-builds if ObjectBuilder is passed instead of ObjectDefinition
2175
+ * @param objects - Single object/builder or array of objects/builders to register
2176
+ * @returns this (for chaining)
2177
+ * @throws Error if object is invalid or already registered
2178
+ *
2179
+ * @example
2180
+ * ```typescript
2181
+ * // No .build() needed - registry auto-builds!
2182
+ * const PRODUCT = object({ id: "obj-product", name: "products", label: "Product" })
2183
+ * .system()
2184
+ * .attribute(text({ id: "attr-name", name: "name", label: "Name" }));
2185
+ *
2186
+ * registry.register(PRODUCT); // ← Auto-builds here
2187
+ *
2188
+ * // Can still explicitly .build() if you want
2189
+ * registry.register(PRODUCT.build());
2190
+ *
2191
+ * // Register multiple
2192
+ * registry.register([PRODUCT, ORDER, CUSTOMER]);
2193
+ * ```
2194
+ */
2195
+ register(objects) {
2196
+ const objectsArray = Array.isArray(objects) ? objects : [objects];
2197
+ for (const obj of objectsArray) {
2198
+ const object2 = "build" in obj && typeof obj.build === "function" ? obj.build() : obj;
2199
+ this.validateAndRegister(object2);
2200
+ }
2201
+ return this;
2202
+ }
2203
+ /**
2204
+ * Validate and register a single object
2205
+ * @internal
2206
+ */
2207
+ validateAndRegister(object2) {
2208
+ if (!object2.system) {
2209
+ throw new Error(
2210
+ `[NativeObjectRegistry] Cannot register object "${object2.name}" (id: ${object2.id}): missing system flag.
2211
+ Native objects must have system=true. Did you forget to call .system() in your builder?`
2212
+ );
2213
+ }
2214
+ if (this.objects.has(object2.name)) {
2215
+ const existing = this.objects.get(object2.name);
2216
+ throw new Error(
2217
+ `[NativeObjectRegistry] Duplicate object name "${object2.name}":
2218
+ - Existing: "${existing?.label}" (id: ${existing?.id})
2219
+ - New: "${object2.label}" (id: ${object2.id})
2220
+ Please use unique names for each native object.`
2221
+ );
2222
+ }
2223
+ this.objects.set(object2.name, object2);
2224
+ }
2225
+ /**
2226
+ * Get a native object by its name
2227
+ * @param name - The object name
2228
+ * @returns The object definition or undefined if not found
2229
+ *
2230
+ * @example
2231
+ * ```typescript
2232
+ * const product = registry.getByName("products");
2233
+ * if (product) {
2234
+ * console.log(product.label); // "Product"
2235
+ * }
2236
+ * ```
2237
+ */
2238
+ getByName(name) {
2239
+ return this.objects.get(name);
2240
+ }
2241
+ /**
2242
+ * Get a native object or throw if not found
2243
+ * @param name - The object name
2244
+ * @returns The object definition
2245
+ * @throws Error if not found
2246
+ */
2247
+ getByNameOrThrow(name) {
2248
+ const object2 = this.objects.get(name);
2249
+ if (!object2) {
2250
+ throw new Error(
2251
+ `[NativeObjectRegistry] Native object "${name}" not found.
2252
+ Available objects: ${this.listNames().join(", ")}`
2253
+ );
2254
+ }
2255
+ return object2;
2256
+ }
2257
+ /**
2258
+ * Get all registered native objects
2259
+ * @returns Array of all registered object definitions
2260
+ */
2261
+ getAll() {
2262
+ return Array.from(this.objects.values());
2263
+ }
2264
+ /**
2265
+ * Get all registered native object names
2266
+ * @returns Array of object names
2267
+ */
2268
+ listNames() {
2269
+ return Array.from(this.objects.keys());
2270
+ }
2271
+ /**
2272
+ * Check if a native object is registered
2273
+ * @param name - The object name
2274
+ * @returns true if registered, false otherwise
2275
+ */
2276
+ has(name) {
2277
+ return this.objects.has(name);
2278
+ }
2279
+ /**
2280
+ * Get the number of registered objects
2281
+ */
2282
+ get size() {
2283
+ return this.objects.size;
2284
+ }
2285
+ /**
2286
+ * Clear all registered objects (useful for testing)
2287
+ * @internal
2288
+ */
2289
+ clear() {
2290
+ this.objects.clear();
2291
+ }
2292
+ /**
2293
+ * Get registry summary for debugging
2294
+ */
2295
+ summary() {
2296
+ const objects = this.getAll();
2297
+ return [
2298
+ `[NativeObjectRegistry] ${this.size} native object(s) registered:`,
2299
+ ...objects.map(
2300
+ (obj) => ` - ${obj.name}: "${obj.label}" (${obj.attributes.length} attributes)`
2301
+ )
2302
+ ].join("\n");
2303
+ }
2304
+ /**
2305
+ * Log registry summary to console
2306
+ */
2307
+ debug() {
2308
+ console.info(this.summary());
2309
+ }
2310
+ };
2311
+ var registry = new NativeObjectRegistryClass();
2312
+
2313
+ // src/validation/validators.ts
2314
+ import { z as z4 } from "zod";
2315
+ function createTextValidator(attr) {
2316
+ let schema = z4.string();
2317
+ if (attr.minLength !== void 0) {
2318
+ schema = schema.min(
2319
+ attr.minLength,
2320
+ `${attr.label} must be at least ${attr.minLength} characters`
2321
+ );
2322
+ }
2323
+ if (attr.maxLength !== void 0) {
2324
+ schema = schema.max(
2325
+ attr.maxLength,
2326
+ `${attr.label} must be at most ${attr.maxLength} characters`
2327
+ );
2328
+ }
2329
+ if (attr.pattern) {
2330
+ schema = schema.regex(new RegExp(attr.pattern), `${attr.label} format is invalid`);
2331
+ }
2332
+ return schema;
2333
+ }
2334
+ function createNumberValidator(attr) {
2335
+ let schema = z4.number();
2336
+ if (attr.min !== void 0) {
2337
+ schema = schema.min(attr.min, `${attr.label} must be at least ${attr.min}`);
2338
+ }
2339
+ if (attr.max !== void 0) {
2340
+ schema = schema.max(attr.max, `${attr.label} must be at most ${attr.max}`);
2341
+ }
2342
+ if (attr.unit === "integer") {
2343
+ schema = schema.int(`${attr.label} must be an integer`);
2344
+ }
2345
+ return schema;
2346
+ }
2347
+ function createCheckboxValidator(_attr) {
2348
+ return z4.boolean();
2349
+ }
2350
+ function createDateValidator(attr) {
2351
+ return z4.string().datetime({ message: `${attr.label} must be a valid ISO date` });
2352
+ }
2353
+ function createPhoneValidator(_attr) {
2354
+ return z4.object({
2355
+ countryCode: z4.string().length(3),
2356
+ phoneNumber: z4.string().min(1)
2357
+ });
2358
+ }
2359
+ function createCurrencyValidator(_attr) {
2360
+ return z4.object({
2361
+ code: z4.string().length(3),
2362
+ value: z4.number().min(0)
2363
+ });
2364
+ }
2365
+ function createStatusValidator(attr) {
2366
+ const validValues = attr.options.map((opt) => opt.value);
2367
+ return z4.enum(validValues, {
2368
+ errorMap: () => ({
2369
+ message: `${attr.label} must be one of: ${validValues.join(", ")}`
2370
+ })
2371
+ });
2372
+ }
2373
+ function createSelectValidator(attr) {
2374
+ const validValues = attr.options.map((opt) => opt.value);
2375
+ return z4.enum(validValues, {
2376
+ errorMap: () => ({
2377
+ message: `${attr.label} must be one of: ${validValues.join(", ")}`
2378
+ })
2379
+ });
2380
+ }
2381
+ function createMultiselectValidator(attr) {
2382
+ const validValues = attr.options.map((opt) => opt.value);
2383
+ return z4.array(
2384
+ z4.enum(validValues, {
2385
+ errorMap: () => ({
2386
+ message: `Each value must be one of: ${validValues.join(", ")}`
2387
+ })
2388
+ })
2389
+ );
2390
+ }
2391
+ function createLocationValidator(_attr) {
2392
+ return z4.object({
2393
+ address: z4.string().optional(),
2394
+ address2: z4.string().optional(),
2395
+ city: z4.string().optional(),
2396
+ state: z4.string().optional(),
2397
+ postalCode: z4.string().optional(),
2398
+ country: z4.string().length(3).optional(),
2399
+ latitude: z4.number().optional(),
2400
+ longitude: z4.number().optional()
2401
+ });
2402
+ }
2403
+ function createTimestampValidator(_attr) {
2404
+ return z4.number().int().positive();
2405
+ }
2406
+ function createFileValidator(_attr) {
2407
+ return z4.string().uuid();
2408
+ }
2409
+ function createUserValidator(_attr) {
2410
+ return z4.string().uuid();
2411
+ }
2412
+ function createSingleRelationValidator(attr) {
2413
+ const uuidSchema = z4.string().uuid({
2414
+ message: `${attr.label} must be a valid record ID`
2415
+ });
2416
+ return z4.union([uuidSchema, z4.null()]);
2417
+ }
2418
+ function createMultiRelationValidator(attr) {
2419
+ const uuidSchema = z4.string().uuid({
2420
+ message: `Each ${attr.label} item must be a valid record ID`
2421
+ });
2422
+ let arraySchema = z4.array(uuidSchema);
2423
+ if (attr.minItems !== void 0) {
2424
+ arraySchema = arraySchema.min(
2425
+ attr.minItems,
2426
+ `${attr.label} must have at least ${attr.minItems} item${attr.minItems > 1 ? "s" : ""}`
2427
+ );
2428
+ }
2429
+ if (attr.maxItems !== void 0) {
2430
+ arraySchema = arraySchema.max(
2431
+ attr.maxItems,
2432
+ `${attr.label} must have at most ${attr.maxItems} item${attr.maxItems > 1 ? "s" : ""}`
2433
+ );
2434
+ }
2435
+ return arraySchema;
2436
+ }
2437
+ function createRelationValidator(attr) {
2438
+ if (attr.cardinality === "many") {
2439
+ return createMultiRelationValidator(attr);
2440
+ }
2441
+ return createSingleRelationValidator(attr);
2442
+ }
2443
+ function createRatingValidator(attr) {
2444
+ let schema = z4.number().int().min(0);
2445
+ if (attr.max !== void 0) {
2446
+ schema = schema.max(attr.max, `${attr.label} must be at most ${attr.max}`);
2447
+ }
2448
+ return schema;
2449
+ }
2450
+ function createAttributeValidator(attr) {
2451
+ switch (attr.type) {
2452
+ case "text":
2453
+ return createTextValidator(attr);
2454
+ case "number":
2455
+ return createNumberValidator(attr);
2456
+ case "checkbox":
2457
+ return createCheckboxValidator(attr);
2458
+ case "date":
2459
+ return createDateValidator(attr);
2460
+ case "phone":
2461
+ return createPhoneValidator(attr);
2462
+ case "currency":
2463
+ return createCurrencyValidator(attr);
2464
+ case "status":
2465
+ return createStatusValidator(attr);
2466
+ case "location":
2467
+ return createLocationValidator(attr);
2468
+ case "timestamp":
2469
+ return createTimestampValidator(attr);
2470
+ case "select":
2471
+ return createSelectValidator(attr);
2472
+ case "multiselect":
2473
+ return createMultiselectValidator(attr);
2474
+ case "file":
2475
+ return createFileValidator(attr);
2476
+ case "user":
2477
+ return createUserValidator(attr);
2478
+ case "relation":
2479
+ return createRelationValidator(attr);
2480
+ case "rating":
2481
+ return createRatingValidator(attr);
2482
+ default:
2483
+ return z4.unknown();
2484
+ }
2485
+ }
2486
+ function createObjectValidator(objectDef) {
2487
+ const shape = {};
2488
+ for (const attr of objectDef.attributes) {
2489
+ let validator = createAttributeValidator(attr);
2490
+ if (!attr.required) {
2491
+ validator = validator.optional();
2492
+ }
2493
+ shape[attr.name] = validator;
2494
+ }
2495
+ return z4.object(shape);
2496
+ }
2497
+ function validateAttribute(attr, value) {
2498
+ const validator = createAttributeValidator(attr);
2499
+ if (!attr.required && (value === void 0 || value === null)) {
2500
+ return { success: true, data: { [attr.name]: value } };
2501
+ }
2502
+ const result = validator.safeParse(value);
2503
+ if (result.success) {
2504
+ return {
2505
+ success: true,
2506
+ data: { [attr.name]: result.data }
2507
+ };
2508
+ }
2509
+ return {
2510
+ success: false,
2511
+ errors: result.error.errors.map((err) => ({
2512
+ path: [attr.name, ...err.path.map(String)],
2513
+ message: err.message
2514
+ }))
2515
+ };
2516
+ }
2517
+ function validateObject(objectDef, data) {
2518
+ const validator = createObjectValidator(objectDef);
2519
+ const result = validator.safeParse(data);
2520
+ if (result.success) {
2521
+ return {
2522
+ success: true,
2523
+ data: result.data
2524
+ };
2525
+ }
2526
+ return {
2527
+ success: false,
2528
+ errors: result.error.errors.map((err) => ({
2529
+ path: err.path.map(String),
2530
+ message: err.message
2531
+ }))
2532
+ };
2533
+ }
2534
+ function validateObjectOrThrow(objectDef, data) {
2535
+ const result = validateObject(objectDef, data);
2536
+ if (!result.success) {
2537
+ const errorMessages = result.errors?.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
2538
+ throw new Error(`Validation failed for ${objectDef.label}:
2539
+ ${errorMessages}`);
2540
+ }
2541
+ return result.data;
2542
+ }
2543
+ function createDraftValidator(objectDef) {
2544
+ const shape = {};
2545
+ for (const attr of objectDef.attributes) {
2546
+ const validator = createAttributeValidator(attr).optional();
2547
+ shape[attr.name] = validator;
2548
+ }
2549
+ return z4.object(shape);
2550
+ }
2551
+ function validateDraft(objectDef, data) {
2552
+ const validator = createDraftValidator(objectDef);
2553
+ const result = validator.safeParse(data);
2554
+ if (result.success) {
2555
+ return {
2556
+ success: true,
2557
+ data: result.data
2558
+ };
2559
+ }
2560
+ return {
2561
+ success: false,
2562
+ errors: result.error.errors.map((err) => ({
2563
+ path: err.path.map(String),
2564
+ message: err.message
2565
+ }))
2566
+ };
2567
+ }
2568
+ function validateDraftOrThrow(objectDef, data) {
2569
+ const result = validateDraft(objectDef, data);
2570
+ if (!result.success) {
2571
+ const errorMessages = result.errors?.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
2572
+ throw new Error(`Draft validation failed for ${objectDef.label}:
2573
+ ${errorMessages}`);
2574
+ }
2575
+ return result.data;
2576
+ }
2577
+ function isValuePresent(value) {
2578
+ if (value === void 0 || value === null) {
2579
+ return false;
2580
+ }
2581
+ if (typeof value === "string" && value.trim() === "") {
2582
+ return false;
2583
+ }
2584
+ return true;
2585
+ }
2586
+ function getMissingRequiredAttributes(objectDef, data) {
2587
+ const missing = [];
2588
+ for (const attr of objectDef.attributes) {
2589
+ if (attr.required && !isValuePresent(data[attr.name])) {
2590
+ missing.push(attr);
2591
+ }
2592
+ }
2593
+ return missing;
2594
+ }
2595
+ function isRecordComplete(objectDef, data) {
2596
+ const missing = getMissingRequiredAttributes(objectDef, data);
2597
+ if (missing.length > 0) {
2598
+ return false;
2599
+ }
2600
+ const validation = validateObject(objectDef, data);
2601
+ return validation.success;
2602
+ }
2603
+ function computeRecordStatus(objectDef, data) {
2604
+ return isRecordComplete(objectDef, data) ? "complete" : "draft";
2605
+ }
2606
+
2607
+ // src/runtime/services/relation.service.ts
2608
+ var RelationService = class {
2609
+ constructor(adapter, nativeRegistry) {
2610
+ this.adapter = adapter;
2611
+ this.schemaService = new ObjectSchemaService(adapter, nativeRegistry);
2612
+ }
2613
+ /**
2614
+ * Validate all relation attributes in the data
2615
+ *
2616
+ * @param schema - Object schema containing attribute definitions
2617
+ * @param data - Record data to validate
2618
+ * @returns Validation result with errors if any
2619
+ *
2620
+ * @example
2621
+ * ```typescript
2622
+ * const result = await relationService.validateRelations(schema, {
2623
+ * company: "rec-123",
2624
+ * contacts: ["rec-456", "rec-789"]
2625
+ * });
2626
+ *
2627
+ * if (!result.valid) {
2628
+ * console.log(result.errors);
2629
+ * // [{ attribute: "company", message: "Record not found", invalidIds: ["rec-123"] }]
2630
+ * }
2631
+ * ```
2632
+ */
2633
+ async validateRelations(schema, data) {
2634
+ const errors = [];
2635
+ const relationAttrs = schema.attributes.filter(
2636
+ (attr) => attr.type === "relation"
2637
+ );
2638
+ for (const attr of relationAttrs) {
2639
+ const value = data[attr.name];
2640
+ if (value === void 0 || value === null) {
2641
+ continue;
2642
+ }
2643
+ const attrErrors = await this.validateRelationAttribute(attr, value);
2644
+ errors.push(...attrErrors);
2645
+ }
2646
+ return {
2647
+ valid: errors.length === 0,
2648
+ errors
2649
+ };
2650
+ }
2651
+ /**
2652
+ * Validate a single relation attribute value
2653
+ */
2654
+ async validateRelationAttribute(attr, value) {
2655
+ const errors = [];
2656
+ const ids = this.extractIds(attr, value);
2657
+ if (ids.length === 0) {
2658
+ return errors;
2659
+ }
2660
+ const validObjectIds = await this.getValidObjectIds(attr.targets);
2661
+ if (validObjectIds.size === 0) {
2662
+ errors.push({
2663
+ attribute: attr.name,
2664
+ message: `No valid target objects found for ${attr.label}`
2665
+ });
2666
+ return errors;
2667
+ }
2668
+ const invalidIds = [];
2669
+ for (const id of ids) {
2670
+ const record = await this.adapter.objectRecords.findById(id);
2671
+ if (!record) {
2672
+ invalidIds.push(id);
2673
+ continue;
2674
+ }
2675
+ if (!validObjectIds.has(record.objectId)) {
2676
+ invalidIds.push(id);
2677
+ }
2678
+ }
2679
+ if (invalidIds.length > 0) {
2680
+ errors.push({
2681
+ attribute: attr.name,
2682
+ message: `Invalid or non-existent records for ${attr.label}`,
2683
+ invalidIds
2684
+ });
2685
+ }
2686
+ return errors;
2687
+ }
2688
+ /**
2689
+ * Extract IDs from relation value based on cardinality
2690
+ */
2691
+ extractIds(attr, value) {
2692
+ if (attr.cardinality === "many") {
2693
+ if (!Array.isArray(value)) {
2694
+ return [];
2695
+ }
2696
+ return value.filter((v) => typeof v === "string");
2697
+ }
2698
+ if (typeof value === "string") {
2699
+ return [value];
2700
+ }
2701
+ return [];
2702
+ }
2703
+ /**
2704
+ * Get valid object IDs from relation targets
2705
+ */
2706
+ async getValidObjectIds(targets) {
2707
+ const objectIds = /* @__PURE__ */ new Set();
2708
+ for (const target of targets) {
2709
+ try {
2710
+ const objectSchema = await this.schemaService.getObjectSchemaByName(target.object);
2711
+ if (objectSchema?.id) {
2712
+ objectIds.add(objectSchema.id);
2713
+ }
2714
+ } catch {
2715
+ }
2716
+ }
2717
+ return objectIds;
2718
+ }
2719
+ /**
2720
+ * Validate relations and throw if invalid
2721
+ */
2722
+ async validateRelationsOrThrow(schema, data) {
2723
+ const result = await this.validateRelations(schema, data);
2724
+ if (!result.valid) {
2725
+ const messages = result.errors.map((e) => `${e.attribute}: ${e.message}`).join("; ");
2726
+ throw new Error(`Relation validation failed: ${messages}`);
2727
+ }
2728
+ }
2729
+ // ============================================================================
2730
+ // OPTIONS & RESOLUTION
2731
+ // ============================================================================
2732
+ /**
2733
+ * Get available options for a relation attribute
2734
+ * Searches across all target objects defined in the relation
2735
+ *
2736
+ * @param attribute - Relation attribute definition
2737
+ * @param tenantId - Tenant ID for multi-tenant isolation
2738
+ * @param params - Query parameters
2739
+ *
2740
+ * @example
2741
+ * ```typescript
2742
+ * const options = await relationService.getOptions(attribute, "tenant-1", {
2743
+ * query: "nike",
2744
+ * page: 1,
2745
+ * pageSize: 20
2746
+ * });
2747
+ * ```
2748
+ */
2749
+ async getOptions(attribute, tenantId, params = {}) {
2750
+ const { query = "", page = 1, pageSize = 20, targetObject } = params;
2751
+ const targets = attribute.targets;
2752
+ const filteredTargets = targetObject ? targets.filter((t) => t.object === targetObject) : targets;
2753
+ if (filteredTargets.length === 0) {
2754
+ return { options: [], hasMore: false, total: 0 };
2755
+ }
2756
+ const allOptions = [];
2757
+ let totalCount = 0;
2758
+ const recordService = new RecordService(this.adapter, tenantId);
2759
+ for (const target of filteredTargets) {
2760
+ const objectSchema = await this.schemaService.getObjectSchemaByName(target.object);
2761
+ if (!objectSchema?.id) {
2762
+ continue;
2763
+ }
2764
+ const result = query ? await recordService.searchRecords(objectSchema.id, query, {
2765
+ limit: pageSize,
2766
+ offset: (page - 1) * pageSize
2767
+ }) : await recordService.listRecords(objectSchema.id, {
2768
+ limit: pageSize,
2769
+ offset: (page - 1) * pageSize
2770
+ });
2771
+ totalCount += result.total;
2772
+ for (const record of result.records) {
2773
+ const label = this.resolveLabel(
2774
+ record.values,
2775
+ objectSchema.titleAttribute,
2776
+ target.displayTemplate
2777
+ );
2778
+ allOptions.push({
2779
+ id: record.id,
2780
+ objectId: objectSchema.id,
2781
+ objectName: objectSchema.name,
2782
+ objectLabel: objectSchema.label,
2783
+ objectIcon: objectSchema.icon,
2784
+ label,
2785
+ data: record.values
2786
+ });
2787
+ }
2788
+ }
2789
+ const hasMore = totalCount > page * pageSize;
2790
+ return {
2791
+ options: allOptions.slice(0, pageSize),
2792
+ hasMore,
2793
+ total: totalCount
2794
+ };
2795
+ }
2796
+ /**
2797
+ * Resolve record IDs to their display labels
2798
+ * Useful for displaying current values in the UI
2799
+ *
2800
+ * @param ids - Record IDs to resolve
2801
+ * @param tenantId - Tenant ID for multi-tenant isolation
2802
+ *
2803
+ * @example
2804
+ * ```typescript
2805
+ * const resolved = await relationService.resolveIds(["rec-1", "rec-2"], "tenant-1");
2806
+ * // [{ id: "rec-1", label: "Nike Air Max", objectName: "products", ... }]
2807
+ * ```
2808
+ */
2809
+ async resolveIds(ids, tenantId) {
2810
+ if (!ids || ids.length === 0) {
2811
+ return [];
2812
+ }
2813
+ const recordService = new RecordService(this.adapter, tenantId);
2814
+ const resolved = [];
2815
+ for (const id of ids) {
2816
+ const record = await recordService.getRecord(id);
2817
+ if (!record) {
2818
+ continue;
2819
+ }
2820
+ const objectSchema = await this.schemaService.getObjectSchema(record.objectId);
2821
+ if (!objectSchema) {
2822
+ continue;
2823
+ }
2824
+ const label = this.resolveLabel(record.values, objectSchema.titleAttribute);
2825
+ resolved.push({
2826
+ id: record.id,
2827
+ objectId: record.objectId,
2828
+ objectName: objectSchema.name,
2829
+ objectLabel: objectSchema.label,
2830
+ objectIcon: objectSchema.icon,
2831
+ label,
2832
+ data: record.values
2833
+ });
2834
+ }
2835
+ return resolved;
2836
+ }
2837
+ /**
2838
+ * Find a relation attribute by ID
2839
+ */
2840
+ async findAttributeById(attributeId) {
2841
+ const attribute = await this.adapter.attributes.findById(attributeId);
2842
+ if (!attribute || attribute.type !== "relation") {
2843
+ return null;
2844
+ }
2845
+ return {
2846
+ ...attribute.config,
2847
+ ...attribute
2848
+ };
2849
+ }
2850
+ /**
2851
+ * Resolve display label from record values
2852
+ * Uses displayTemplate if provided, otherwise falls back to titleAttribute
2853
+ */
2854
+ resolveLabel(values, titleAttribute, displayTemplate) {
2855
+ if (displayTemplate) {
2856
+ return displayTemplate.replace(/\{(\w+)\}/g, (_, key) => {
2857
+ const value = values[key];
2858
+ return value !== void 0 && value !== null ? String(value) : "";
2859
+ });
2860
+ }
2861
+ const titleValue = values[titleAttribute];
2862
+ return titleValue !== void 0 && titleValue !== null ? String(titleValue) : "(Untitled)";
2863
+ }
2864
+ };
2865
+
2866
+ // src/runtime/services/record.service.ts
2867
+ var RecordService = class {
2868
+ constructor(adapter, tenantId) {
2869
+ this.adapter = adapter;
2870
+ this.tenantId = tenantId;
2871
+ this.schemaService = new ObjectSchemaService(adapter, registry);
2872
+ this.relationService = new RelationService(adapter, registry);
2873
+ }
2874
+ /**
2875
+ * Create a new record with validation
2876
+ *
2877
+ * @param objectId - Object UUID
2878
+ * @param data - Record data (attribute values)
2879
+ * @param options - Creation options
2880
+ * @returns Created record with computed completionStatus
2881
+ *
2882
+ * @example
2883
+ * ```typescript
2884
+ * const service = new RecordService(adapter, "tenant-123");
2885
+ *
2886
+ * // Create a complete record (strict validation)
2887
+ * const product = await service.createRecord("obj-product", {
2888
+ * name: "Nike Air Max",
2889
+ * price: 129.99,
2890
+ * status: "active"
2891
+ * });
2892
+ * // → product.completionStatus = "complete"
2893
+ *
2894
+ * // Create a draft record (allows missing required fields)
2895
+ * const draft = await service.createRecord("obj-product", {
2896
+ * name: "Draft Product"
2897
+ * }, { allowDraft: true });
2898
+ * // → draft.completionStatus = "draft"
2899
+ * ```
2900
+ */
2901
+ async createRecord(objectId, data, options) {
2902
+ const schema = await this.schemaService.getObjectSchema(objectId);
2903
+ if (options?.validate !== false) {
2904
+ if (options?.allowDraft) {
2905
+ validateDraftOrThrow(schema, data);
2906
+ } else {
2907
+ validateObjectOrThrow(schema, data);
2908
+ }
2909
+ if (!options?.skipRelationValidation) {
2910
+ await this.relationService.validateRelationsOrThrow(schema, data);
2911
+ }
2912
+ }
2913
+ const completionStatus = computeRecordStatus(schema, data);
2914
+ const record = await this.adapter.objectRecords.create({
2915
+ tenantId: this.tenantId,
2916
+ objectId,
2917
+ data,
2918
+ completionStatus
2919
+ });
2920
+ return record;
2921
+ }
2922
+ /**
2923
+ * Get a record by ID
2924
+ *
2925
+ * @param recordId - Record UUID
2926
+ * @param options - Query options
2927
+ * @returns Record or null if not found
2928
+ */
2929
+ async getRecord(recordId, options) {
2930
+ const record = await this.adapter.objectRecords.findById(recordId);
2931
+ if (!record) {
2932
+ return null;
2933
+ }
2934
+ if (options?.includeSchema) {
2935
+ const schema = await this.schemaService.getObjectSchema(record.objectId);
2936
+ const recordWithSchema = record;
2937
+ recordWithSchema.schema = schema;
2938
+ return recordWithSchema;
2939
+ }
2940
+ return record;
2941
+ }
2942
+ /**
2943
+ * Get a record by ID or throw if not found
2944
+ */
2945
+ async getRecordOrThrow(recordId) {
2946
+ const record = await this.getRecord(recordId);
2947
+ if (!record) {
2948
+ throw new Error(`Record with id "${recordId}" not found`);
2949
+ }
2950
+ return record;
2951
+ }
2952
+ /**
2953
+ * Update a record with validation
2954
+ *
2955
+ * The completion status is automatically recalculated after each update.
2956
+ * A draft record becomes complete when all required fields are filled.
2957
+ *
2958
+ * @param recordId - Record UUID
2959
+ * @param data - Partial data to update
2960
+ * @param options - Update options
2961
+ * @returns Updated record with recalculated completionStatus
2962
+ *
2963
+ * @example
2964
+ * ```typescript
2965
+ * // Update a draft record to make it complete
2966
+ * const updated = await service.updateRecord(draftId, {
2967
+ * price: 99.99,
2968
+ * status: "active"
2969
+ * });
2970
+ * // → updated.completionStatus = "complete" if all required fields now present
2971
+ * ```
2972
+ */
2973
+ async updateRecord(recordId, data, options) {
2974
+ const existing = await this.getRecordOrThrow(recordId);
2975
+ const schema = await this.schemaService.getObjectSchema(existing.objectId);
2976
+ const mergedData = { ...existing.values, ...data };
2977
+ if (options?.validate !== false) {
2978
+ if (options?.partial) {
2979
+ validateDraftOrThrow(schema, mergedData);
2980
+ } else {
2981
+ validateObjectOrThrow(schema, mergedData);
2982
+ }
2983
+ if (!options?.skipRelationValidation) {
2984
+ await this.relationService.validateRelationsOrThrow(schema, data);
2985
+ }
2986
+ }
2987
+ const completionStatus = computeRecordStatus(schema, mergedData);
2988
+ const updated = await this.adapter.objectRecords.update(recordId, {
2989
+ ...data,
2990
+ __completionStatus: completionStatus
2991
+ });
2992
+ return updated;
2993
+ }
2994
+ /**
2995
+ * Delete a record
2996
+ *
2997
+ * @param recordId - Record UUID
2998
+ * @param options - Delete options
2999
+ */
3000
+ async deleteRecord(recordId, options) {
3001
+ if (options?.checkSystem) {
3002
+ const record = await this.getRecordOrThrow(recordId);
3003
+ const schema = await this.schemaService.getObjectSchema(record.objectId);
3004
+ if (schema.system) {
3005
+ throw new Error(`Cannot delete record of system object "${schema.label}"`);
3006
+ }
3007
+ }
3008
+ await this.adapter.objectRecords.delete(recordId);
3009
+ }
3010
+ /**
3011
+ * List records for an object with pagination
3012
+ *
3013
+ * @param objectId - Object UUID
3014
+ * @param options - List options
3015
+ * @returns Records and total count
3016
+ */
3017
+ async listRecords(objectId, options) {
3018
+ return await this.adapter.objectRecords.list(this.tenantId, objectId, options);
3019
+ }
3020
+ /**
3021
+ * Search records using full-text search
3022
+ *
3023
+ * @param objectId - Object UUID
3024
+ * @param query - Search query
3025
+ * @param options - Search options
3026
+ * @returns Matching records and total count
3027
+ */
3028
+ async searchRecords(objectId, query, options) {
3029
+ return await this.adapter.objectRecords.search(this.tenantId, objectId, query, options);
3030
+ }
3031
+ /**
3032
+ * Validate data against object schema without saving
3033
+ *
3034
+ * @param objectId - Object UUID
3035
+ * @param data - Data to validate
3036
+ * @returns Validation result
3037
+ */
3038
+ async validateData(objectId, data) {
3039
+ const schema = await this.schemaService.getObjectSchema(objectId);
3040
+ return validateObject(schema, data);
3041
+ }
3042
+ /**
3043
+ * Compute the completion status for given data without saving.
3044
+ * Useful for UI to show draft/complete status before submitting.
3045
+ *
3046
+ * @param objectId - Object UUID
3047
+ * @param data - Data to check
3048
+ * @returns Computed completion status
3049
+ */
3050
+ async computeStatus(objectId, data) {
3051
+ const schema = await this.schemaService.getObjectSchema(objectId);
3052
+ return computeRecordStatus(schema, data);
3053
+ }
3054
+ /**
3055
+ * Refresh the completion status of an existing record.
3056
+ * Useful when schema changes and you need to recompute statuses.
3057
+ *
3058
+ * @param recordId - Record UUID
3059
+ * @returns Updated completion status
3060
+ */
3061
+ async refreshRecordStatus(recordId) {
3062
+ const record = await this.getRecordOrThrow(recordId);
3063
+ const schema = await this.schemaService.getObjectSchema(record.objectId);
3064
+ const newStatus = computeRecordStatus(schema, record.values);
3065
+ if (record.completionStatus !== newStatus) {
3066
+ await this.adapter.objectRecords.update(recordId, {
3067
+ __completionStatus: newStatus
3068
+ });
3069
+ }
3070
+ return newStatus;
3071
+ }
3072
+ };
3073
+
3074
+ // src/runtime/services/user-profile.service.ts
3075
+ var UserProfileService = class {
3076
+ constructor(adapter, tenantId) {
3077
+ this.adapter = adapter;
3078
+ this.tenantId = tenantId;
3079
+ }
3080
+ /**
3081
+ * Create a new user profile (typically after first auth)
3082
+ *
3083
+ * @param data - User profile creation data
3084
+ * @returns Created user profile
3085
+ *
3086
+ * @example
3087
+ * ```typescript
3088
+ * const service = new UserProfileService(adapter, "tenant-123");
3089
+ *
3090
+ * // After Supabase auth
3091
+ * const profile = await service.createProfile({
3092
+ * tenantId: "tenant-123",
3093
+ * authId: authUser.id,
3094
+ * email: authUser.email,
3095
+ * firstName: authUser.user_metadata.first_name,
3096
+ * lastName: authUser.user_metadata.last_name,
3097
+ * role: "member",
3098
+ * status: "active"
3099
+ * });
3100
+ * ```
3101
+ */
3102
+ async createProfile(data) {
3103
+ if (data.tenantId !== this.tenantId) {
3104
+ throw new Error(
3105
+ `Tenant mismatch: service initialized with "${this.tenantId}" but data has "${data.tenantId}"`
3106
+ );
3107
+ }
3108
+ const existing = await this.adapter.userProfiles.findByAuthId(data.authId);
3109
+ if (existing) {
3110
+ throw new Error(`User profile with authId "${data.authId}" already exists`);
3111
+ }
3112
+ const existingEmail = await this.adapter.userProfiles.findByEmail(this.tenantId, data.email);
3113
+ if (existingEmail) {
3114
+ throw new Error(`User profile with email "${data.email}" already exists in this tenant`);
3115
+ }
3116
+ return await this.adapter.userProfiles.create(data);
3117
+ }
3118
+ /**
3119
+ * Get user profile by ID
3120
+ */
3121
+ async getProfile(profileId) {
3122
+ return await this.adapter.userProfiles.findById(profileId);
3123
+ }
3124
+ /**
3125
+ * Get user profile by ID or throw
3126
+ */
3127
+ async getProfileOrThrow(profileId) {
3128
+ const profile = await this.getProfile(profileId);
3129
+ if (!profile) {
3130
+ throw new Error(`User profile with id "${profileId}" not found`);
3131
+ }
3132
+ return profile;
3133
+ }
3134
+ /**
3135
+ * Get user profile by auth provider ID
3136
+ *
3137
+ * @param authId - Auth provider user ID (Supabase, Clerk, etc.)
3138
+ * @returns User profile or null
3139
+ */
3140
+ async getProfileByAuthId(authId) {
3141
+ return await this.adapter.userProfiles.findByAuthId(authId);
3142
+ }
3143
+ /**
3144
+ * Get or create user profile (idempotent operation)
3145
+ * Useful for auth callbacks - ensures profile exists
3146
+ *
3147
+ * @param authId - Auth provider user ID
3148
+ * @param data - Profile data to create if doesn't exist
3149
+ * @returns Existing or newly created profile
3150
+ *
3151
+ * @example
3152
+ * ```typescript
3153
+ * // In Supabase auth callback
3154
+ * const profile = await service.getOrCreateProfile(
3155
+ * authUser.id,
3156
+ * {
3157
+ * tenantId: "tenant-123",
3158
+ * authId: authUser.id,
3159
+ * email: authUser.email,
3160
+ * role: "member",
3161
+ * status: "active"
3162
+ * }
3163
+ * );
3164
+ * ```
3165
+ */
3166
+ async getOrCreateProfile(authId, data) {
3167
+ const existing = await this.getProfileByAuthId(authId);
3168
+ if (existing) {
3169
+ return existing;
3170
+ }
3171
+ return await this.createProfile(data);
3172
+ }
3173
+ /**
3174
+ * Update user profile
3175
+ */
3176
+ async updateProfile(profileId, data) {
3177
+ await this.getProfileOrThrow(profileId);
3178
+ return await this.adapter.userProfiles.update(profileId, data);
3179
+ }
3180
+ /**
3181
+ * Delete user profile
3182
+ *
3183
+ * @param profileId - Profile UUID
3184
+ * @param options - Delete options
3185
+ */
3186
+ async deleteProfile(profileId, options) {
3187
+ if (options?.checkAdmin) {
3188
+ const profile = await this.getProfileOrThrow(profileId);
3189
+ if (profile.role === "admin") {
3190
+ const allProfiles = await this.listProfiles();
3191
+ const adminCount = allProfiles.filter((p) => p.role === "admin").length;
3192
+ if (adminCount <= 1) {
3193
+ throw new Error("Cannot delete the last admin user");
3194
+ }
3195
+ }
3196
+ }
3197
+ await this.adapter.userProfiles.delete(profileId);
3198
+ }
3199
+ /**
3200
+ * List all user profiles for the tenant
3201
+ */
3202
+ async listProfiles(options) {
3203
+ return await this.adapter.userProfiles.list(this.tenantId, options);
3204
+ }
3205
+ /**
3206
+ * Update last login timestamp
3207
+ *
3208
+ * @param profileId - Profile UUID
3209
+ *
3210
+ * @example
3211
+ * ```typescript
3212
+ * // After successful auth
3213
+ * await service.updateLastLogin(profile.id);
3214
+ * ```
3215
+ */
3216
+ async updateLastLogin(profileId) {
3217
+ await this.adapter.userProfiles.updateLastLogin(profileId);
3218
+ }
3219
+ /**
3220
+ * Change user role
3221
+ *
3222
+ * @param profileId - Profile UUID
3223
+ * @param newRole - New role
3224
+ */
3225
+ async changeRole(profileId, newRole) {
3226
+ return await this.updateProfile(profileId, { role: newRole });
3227
+ }
3228
+ /**
3229
+ * Change user status
3230
+ *
3231
+ * @param profileId - Profile UUID
3232
+ * @param newStatus - New status
3233
+ */
3234
+ async changeStatus(profileId, newStatus) {
3235
+ return await this.updateProfile(profileId, { status: newStatus });
3236
+ }
3237
+ /**
3238
+ * Get user by email
3239
+ */
3240
+ async getProfileByEmail(email) {
3241
+ return await this.adapter.userProfiles.findByEmail(this.tenantId, email);
3242
+ }
3243
+ /**
3244
+ * Check if user has role
3245
+ */
3246
+ async hasRole(profileId, role) {
3247
+ const profile = await this.getProfile(profileId);
3248
+ return profile?.role === role;
3249
+ }
3250
+ /**
3251
+ * Check if user is admin
3252
+ */
3253
+ async isAdmin(profileId) {
3254
+ return await this.hasRole(profileId, "admin");
3255
+ }
3256
+ };
3257
+
3258
+ // src/runtime/services/view.service.ts
3259
+ var ViewService = class {
3260
+ constructor(adapter, nativeViews) {
3261
+ this.adapter = adapter;
3262
+ this.nativeViews = nativeViews;
3263
+ }
3264
+ /**
3265
+ * Get all views for an object (native + custom)
3266
+ *
3267
+ * @param objectName - Object name
3268
+ * @param tenantId - Tenant ID
3269
+ * @returns All views for the object
3270
+ */
3271
+ async getViewsForObject(objectName, tenantId) {
3272
+ const nativeViewDefs = this.nativeViews.getByObjectName(objectName);
3273
+ const dbViews = await this.adapter.views.findByObjectName(tenantId, objectName);
3274
+ const customViews = dbViews.filter((v) => !v.system).map(this.convertDBViewToDefinition);
3275
+ return [...nativeViewDefs, ...customViews];
3276
+ }
3277
+ /**
3278
+ * Get a specific view by name
3279
+ *
3280
+ * @param objectName - Object name
3281
+ * @param viewName - View name
3282
+ * @param tenantId - Tenant ID
3283
+ * @returns View definition or null
3284
+ */
3285
+ async getView(objectName, viewName, tenantId) {
3286
+ const nativeView = this.nativeViews.get(objectName, viewName);
3287
+ if (nativeView) {
3288
+ return nativeView;
3289
+ }
3290
+ const dbView = await this.adapter.views.findByName(tenantId, objectName, viewName);
3291
+ if (dbView) {
3292
+ return this.convertDBViewToDefinition(dbView);
3293
+ }
3294
+ return null;
3295
+ }
3296
+ /**
3297
+ * Get the default view for an object
3298
+ *
3299
+ * Priority:
3300
+ * 1. Custom view marked as default
3301
+ * 2. Native view marked as default
3302
+ * 3. First available view
3303
+ *
3304
+ * @param objectName - Object name
3305
+ * @param tenantId - Tenant ID
3306
+ * @returns Default view or null
3307
+ */
3308
+ async getDefaultView(objectName, tenantId) {
3309
+ const views = await this.getViewsForObject(objectName, tenantId);
3310
+ const customDefault = views.find((v) => v.default && !v.system);
3311
+ if (customDefault) return customDefault;
3312
+ const nativeDefault = views.find((v) => v.default && v.system);
3313
+ if (nativeDefault) return nativeDefault;
3314
+ return views[0] ?? null;
3315
+ }
3316
+ /**
3317
+ * Create a custom view
3318
+ *
3319
+ * @param input - View definition
3320
+ * @param tenantId - Tenant ID
3321
+ * @returns Created view
3322
+ */
3323
+ async createView(input, tenantId) {
3324
+ this.validateViewName(input.name);
3325
+ const existing = await this.adapter.views.findByName(tenantId, input.objectName, input.name);
3326
+ if (existing) {
3327
+ throw new Error(`View "${input.name}" already exists for object "${input.objectName}"`);
3328
+ }
3329
+ if (this.nativeViews.has(input.objectName, input.name)) {
3330
+ throw new Error(
3331
+ `Cannot create view "${input.name}": a system view with this name already exists`
3332
+ );
3333
+ }
3334
+ if (!input.tabs || input.tabs.length === 0) {
3335
+ throw new Error("View must have at least one tab");
3336
+ }
3337
+ const dbView = await this.adapter.views.create({
3338
+ tenantId,
3339
+ objectName: input.objectName,
3340
+ name: input.name,
3341
+ label: input.label,
3342
+ description: input.description,
3343
+ icon: input.icon,
3344
+ tabs: input.tabs,
3345
+ default: input.default ?? false,
3346
+ system: false,
3347
+ // Custom views are never system
3348
+ metadata: input.metadata
3349
+ });
3350
+ return this.convertDBViewToDefinition(dbView);
3351
+ }
3352
+ /**
3353
+ * Update a custom view
3354
+ *
3355
+ * @param viewId - View ID
3356
+ * @param input - Update data
3357
+ * @returns Updated view
3358
+ */
3359
+ async updateView(viewId, input) {
3360
+ const dbView = await this.adapter.views.findById(viewId);
3361
+ if (!dbView) {
3362
+ throw new Error(`View with id "${viewId}" not found`);
3363
+ }
3364
+ if (dbView.system) {
3365
+ throw new Error("Cannot modify system views. System views are protected.");
3366
+ }
3367
+ if (input.tabs && input.tabs.length === 0) {
3368
+ throw new Error("View must have at least one tab");
3369
+ }
3370
+ const updated = await this.adapter.views.update(viewId, {
3371
+ label: input.label,
3372
+ description: input.description,
3373
+ icon: input.icon,
3374
+ tabs: input.tabs,
3375
+ default: input.default,
3376
+ metadata: input.metadata
3377
+ });
3378
+ return this.convertDBViewToDefinition(updated);
3379
+ }
3380
+ /**
3381
+ * Delete a custom view
3382
+ *
3383
+ * @param viewId - View ID
3384
+ */
3385
+ async deleteView(viewId) {
3386
+ const dbView = await this.adapter.views.findById(viewId);
3387
+ if (!dbView) {
3388
+ throw new Error(`View with id "${viewId}" not found`);
3389
+ }
3390
+ if (dbView.system) {
3391
+ throw new Error("Cannot delete system views. System views are protected.");
3392
+ }
3393
+ await this.adapter.views.delete(viewId);
3394
+ }
3395
+ /**
3396
+ * Set a view as default for its object
3397
+ *
3398
+ * @param viewId - View ID
3399
+ * @param tenantId - Tenant ID
3400
+ * @returns Updated view
3401
+ */
3402
+ async setDefaultView(viewId, tenantId) {
3403
+ const dbView = await this.adapter.views.findById(viewId);
3404
+ if (!dbView) {
3405
+ throw new Error(`View with id "${viewId}" not found`);
3406
+ }
3407
+ const currentViews = await this.adapter.views.findByObjectName(tenantId, dbView.objectName);
3408
+ for (const v of currentViews) {
3409
+ if (v.default && v.id !== viewId && !v.system) {
3410
+ await this.adapter.views.update(v.id, { default: false });
3411
+ }
3412
+ }
3413
+ const updated = await this.adapter.views.update(viewId, { default: true });
3414
+ return this.convertDBViewToDefinition(updated);
3415
+ }
3416
+ // ============================================================================
3417
+ // PRIVATE HELPERS
3418
+ // ============================================================================
3419
+ /**
3420
+ * Validate view name format (kebab-case)
3421
+ */
3422
+ validateViewName(name) {
3423
+ if (!name || name.length === 0) {
3424
+ throw new Error("View name cannot be empty");
3425
+ }
3426
+ if (name.length > 63) {
3427
+ throw new Error("View name is too long (max 63 characters)");
3428
+ }
3429
+ const kebabCaseRegex = /^[a-z][a-z0-9-]*$/;
3430
+ if (!kebabCaseRegex.test(name)) {
3431
+ throw new Error(
3432
+ "Invalid view name format. Name must be in kebab-case (e.g., 'detail', 'list-view')"
3433
+ );
3434
+ }
3435
+ }
3436
+ /**
3437
+ * Convert database view to ViewDefinition
3438
+ */
3439
+ convertDBViewToDefinition(dbView) {
3440
+ return {
3441
+ id: dbView.id,
3442
+ name: dbView.name,
3443
+ label: dbView.label,
3444
+ description: dbView.description,
3445
+ icon: dbView.icon,
3446
+ object: dbView.objectName,
3447
+ tabs: dbView.tabs,
3448
+ default: dbView.default,
3449
+ system: dbView.system,
3450
+ metadata: dbView.metadata
3451
+ };
3452
+ }
3453
+ };
3454
+
3455
+ // src/runtime/view-sync.ts
3456
+ async function syncNativeViews(adapter, nativeViewRegistry, options = {}) {
3457
+ const result = {
3458
+ success: true,
3459
+ viewsSynced: 0,
3460
+ viewsCreated: 0,
3461
+ viewsUpdated: 0,
3462
+ viewsDeleted: 0,
3463
+ errors: []
3464
+ };
3465
+ const nativeViews = nativeViewRegistry.getAll();
3466
+ if (options.verbose) {
3467
+ console.info(`[ViewSync] Starting sync for ${nativeViews.length} native views...`);
3468
+ }
3469
+ try {
3470
+ await adapter.transaction(async (tx) => {
3471
+ const viewsByObject = await syncAllViews(tx, nativeViews, result, options);
3472
+ await cleanupRemovedViews(tx, viewsByObject, result, options);
3473
+ });
3474
+ } catch (error) {
3475
+ handleTransactionError(result, error);
3476
+ }
3477
+ logSyncComplete(result, options);
3478
+ return result;
3479
+ }
3480
+ async function syncAllViews(tx, nativeViews, result, options) {
3481
+ const viewsByObject = /* @__PURE__ */ new Map();
3482
+ for (const nativeView of nativeViews) {
3483
+ try {
3484
+ await syncSingleView(tx, nativeView, result, options);
3485
+ trackViewByObject(viewsByObject, nativeView);
3486
+ } catch (error) {
3487
+ handleViewSyncError(result, nativeView, error, options);
3488
+ }
3489
+ }
3490
+ return viewsByObject;
3491
+ }
3492
+ function trackViewByObject(viewsByObject, nativeView) {
3493
+ const objectViews = viewsByObject.get(nativeView.object) ?? [];
3494
+ objectViews.push(nativeView.name);
3495
+ viewsByObject.set(nativeView.object, objectViews);
3496
+ }
3497
+ function handleViewSyncError(result, nativeView, error, options) {
3498
+ result.success = false;
3499
+ result.errors.push({
3500
+ viewName: nativeView.name,
3501
+ objectName: nativeView.object,
3502
+ error: error instanceof Error ? error.message : String(error)
3503
+ });
3504
+ if (options.verbose) {
3505
+ console.error(`[ViewSync] \u2717 Failed to sync ${nativeView.object}:${nativeView.name}:`, error);
3506
+ }
3507
+ }
3508
+ async function cleanupRemovedViews(tx, viewsByObject, result, options) {
3509
+ if (options.dryRun) return;
3510
+ for (const [objectName, viewNames] of viewsByObject) {
3511
+ const deletedCount = await tx.views.deleteNotIn(objectName, viewNames);
3512
+ result.viewsDeleted += deletedCount;
3513
+ if (options.verbose && deletedCount > 0) {
3514
+ console.info(`[ViewSync] Deleted ${deletedCount} obsolete views for ${objectName}`);
3515
+ }
3516
+ }
3517
+ }
3518
+ function handleTransactionError(result, error) {
3519
+ result.success = false;
3520
+ result.errors.push({
3521
+ viewName: "transaction",
3522
+ objectName: "",
3523
+ error: error instanceof Error ? error.message : String(error)
3524
+ });
3525
+ }
3526
+ function logSyncComplete(result, options) {
3527
+ if (options.verbose) {
3528
+ console.info(
3529
+ `[ViewSync] ${result.success ? "\u2713" : "\u2717"} Sync complete:
3530
+ Views: ${result.viewsCreated} created, ${result.viewsUpdated} updated, ${result.viewsDeleted} deleted
3531
+ Errors: ${result.errors.length}`
3532
+ );
3533
+ }
3534
+ }
3535
+ async function syncSingleView(adapter, nativeView, result, options) {
3536
+ if (!nativeView.system) {
3537
+ throw new Error(`View ${nativeView.name} is not marked as system`);
3538
+ }
3539
+ const existingView = await adapter.views.findSystemByName(nativeView.object, nativeView.name);
3540
+ const isNew = !existingView;
3541
+ if (isNew) {
3542
+ result.viewsCreated++;
3543
+ } else {
3544
+ result.viewsUpdated++;
3545
+ }
3546
+ result.viewsSynced++;
3547
+ if (options.dryRun) {
3548
+ if (options.verbose) {
3549
+ console.info(
3550
+ `[ViewSync] Would ${isNew ? "create" : "update"} view: ${nativeView.object}:${nativeView.name}`
3551
+ );
3552
+ }
3553
+ return;
3554
+ }
3555
+ await adapter.views.upsert({
3556
+ tenantId: options.tenantId || "default",
3557
+ objectName: nativeView.object,
3558
+ name: nativeView.name,
3559
+ label: nativeView.label,
3560
+ description: nativeView.description,
3561
+ icon: nativeView.icon,
3562
+ tabs: nativeView.tabs,
3563
+ default: nativeView.default ?? false,
3564
+ system: true,
3565
+ metadata: nativeView.metadata
3566
+ });
3567
+ if (options.verbose) {
3568
+ console.info(
3569
+ `[ViewSync] \u2713 Synced ${nativeView.object}:${nativeView.name}: ${nativeView.tabs.length} tabs`
3570
+ );
3571
+ }
3572
+ }
3573
+ async function verifyNativeViewsSync(adapter, nativeViewRegistry) {
3574
+ const nativeViews = nativeViewRegistry.getAll();
3575
+ for (const view2 of nativeViews) {
3576
+ if (!view2.system) continue;
3577
+ const existing = await adapter.views.findSystemByName(view2.object, view2.name);
3578
+ if (!existing) {
3579
+ return false;
3580
+ }
3581
+ }
3582
+ return true;
3583
+ }
3584
+ async function getViewSyncPreview(adapter, nativeViewRegistry) {
3585
+ return await syncNativeViews(adapter, nativeViewRegistry, { dryRun: true });
3586
+ }
3587
+
3588
+ // src/runtime/sync.ts
3589
+ var BASE_ATTRIBUTE_KEYS = /* @__PURE__ */ new Set([
3590
+ "id",
3591
+ "name",
3592
+ "label",
3593
+ "type",
3594
+ "required",
3595
+ "system",
3596
+ "unique",
3597
+ "order"
3598
+ ]);
3599
+ function extractAttributeConfig(attr) {
3600
+ return Object.fromEntries(
3601
+ Object.entries(attr).filter(
3602
+ ([key, value]) => !BASE_ATTRIBUTE_KEYS.has(key) && value !== void 0
3603
+ )
3604
+ );
3605
+ }
3606
+ async function syncNativeObjects(adapter, nativeRegistry, options = {}) {
3607
+ const result = {
3608
+ success: true,
3609
+ objectsSynced: 0,
3610
+ attributesSynced: 0,
3611
+ objectsCreated: 0,
3612
+ objectsUpdated: 0,
3613
+ attributesCreated: 0,
3614
+ attributesUpdated: 0,
3615
+ attributesDeleted: 0,
3616
+ errors: []
3617
+ };
3618
+ const nativeObjects = nativeRegistry.getAll();
3619
+ if (options.verbose) {
3620
+ console.info(`[SyncService] Starting sync for ${nativeObjects.length} native objects...`);
3621
+ }
3622
+ try {
3623
+ await adapter.transaction(async (tx) => {
3624
+ for (const nativeObject of nativeObjects) {
3625
+ try {
3626
+ await syncSingleObject(tx, nativeObject, result, options);
3627
+ } catch (error) {
3628
+ result.success = false;
3629
+ result.errors.push({
3630
+ objectName: nativeObject.name,
3631
+ error: error instanceof Error ? error.message : String(error)
3632
+ });
3633
+ if (options.verbose) {
3634
+ console.error(`[SyncService] \u2717 Failed to sync ${nativeObject.name}:`, error);
3635
+ }
3636
+ }
3637
+ }
3638
+ });
3639
+ } catch (error) {
3640
+ result.success = false;
3641
+ result.errors.push({
3642
+ objectName: "transaction",
3643
+ error: error instanceof Error ? error.message : String(error)
3644
+ });
3645
+ }
3646
+ if (options.verbose) {
3647
+ console.info(
3648
+ `[SyncService] ${result.success ? "\u2713" : "\u2717"} Sync complete:
3649
+ Objects: ${result.objectsCreated} created, ${result.objectsUpdated} updated
3650
+ Attributes: ${result.attributesCreated} created, ${result.attributesUpdated} updated, ${result.attributesDeleted} deleted
3651
+ Errors: ${result.errors.length}`
3652
+ );
3653
+ }
3654
+ return result;
3655
+ }
3656
+ async function syncSingleObject(adapter, nativeObject, result, options) {
3657
+ if (!nativeObject.system) {
3658
+ throw new Error(`Object ${nativeObject.name} is not marked as system`);
3659
+ }
3660
+ const existingObject = await adapter.objects.findSystemByName(nativeObject.name);
3661
+ const isNew = !existingObject;
3662
+ updateObjectStats(result, isNew);
3663
+ if (options.dryRun) {
3664
+ await handleDryRun(adapter, nativeObject, existingObject, result, options, isNew);
3665
+ return;
3666
+ }
3667
+ const dbObject = await upsertObject(adapter, nativeObject, options);
3668
+ await syncAttributes(adapter, nativeObject, dbObject, existingObject, result);
3669
+ if (!isNew) {
3670
+ await cleanupAttributes(adapter, dbObject.id, nativeObject, result);
3671
+ }
3672
+ logSyncSuccess(nativeObject, options);
3673
+ }
3674
+ function updateObjectStats(result, isNew) {
3675
+ if (isNew) {
3676
+ result.objectsCreated++;
3677
+ } else {
3678
+ result.objectsUpdated++;
3679
+ }
3680
+ result.objectsSynced++;
3681
+ }
3682
+ async function handleDryRun(adapter, nativeObject, existingObject, result, options, isNew) {
3683
+ if (options.verbose) {
3684
+ console.info(`[SyncService] Would ${isNew ? "create" : "update"} object: ${nativeObject.name}`);
3685
+ }
3686
+ for (const attr of nativeObject.attributes) {
3687
+ const existingAttr = existingObject ? await adapter.attributes.findByObjectId(existingObject.id).then((attrs) => attrs.find((a) => a.name === attr.name)) : null;
3688
+ if (existingAttr) {
3689
+ result.attributesUpdated++;
3690
+ } else {
3691
+ result.attributesCreated++;
3692
+ }
3693
+ result.attributesSynced++;
3694
+ }
3695
+ }
3696
+ async function upsertObject(adapter, nativeObject, options) {
3697
+ return await adapter.objects.upsert({
3698
+ tenantId: options.tenantId || "default",
3699
+ system: true,
3700
+ name: nativeObject.name,
3701
+ label: nativeObject.label,
3702
+ description: nativeObject.description,
3703
+ metadata: nativeObject.metadata
3704
+ });
3705
+ }
3706
+ async function syncAttributes(adapter, nativeObject, dbObject, existingObject, result) {
3707
+ for (const [index, attr] of nativeObject.attributes.entries()) {
3708
+ const existingAttr = existingObject ? await adapter.attributes.findByObjectId(dbObject.id).then((attrs) => attrs.find((a) => a.name === attr.name)) : null;
3709
+ await adapter.attributes.upsert({
3710
+ objectId: dbObject.id,
3711
+ name: attr.name,
3712
+ label: attr.label,
3713
+ type: attr.type,
3714
+ description: attr.description,
3715
+ icon: attr.icon,
3716
+ system: attr.system ?? true,
3717
+ required: attr.required ?? false,
3718
+ order: attr.order ?? index,
3719
+ hidden: attr.hidden,
3720
+ archived: attr.archived,
3721
+ deprecated: attr.deprecated,
3722
+ defaultValue: attr.defaultValue,
3723
+ config: extractAttributeConfig(attr)
3724
+ });
3725
+ if (existingAttr) {
3726
+ result.attributesUpdated++;
3727
+ } else {
3728
+ result.attributesCreated++;
3729
+ }
3730
+ result.attributesSynced++;
3731
+ }
3732
+ }
3733
+ async function cleanupAttributes(adapter, objectId, nativeObject, result) {
3734
+ const attributeNames = nativeObject.attributes.map((attr) => attr.name);
3735
+ const deletedCount = await adapter.attributes.deleteByNames(objectId, attributeNames);
3736
+ result.attributesDeleted += deletedCount;
3737
+ }
3738
+ function logSyncSuccess(nativeObject, options) {
3739
+ if (options.verbose) {
3740
+ console.info(
3741
+ `[SyncService] \u2713 Synced ${nativeObject.name}: ${nativeObject.attributes.length} attributes`
3742
+ );
3743
+ }
3744
+ }
3745
+ async function verifyNativeObjectsSync(adapter, nativeRegistry) {
3746
+ const nativeObjects = nativeRegistry.getAll();
3747
+ for (const obj of nativeObjects) {
3748
+ if (!obj.system) continue;
3749
+ const existing = await adapter.objects.findSystemByName(obj.name);
3750
+ if (!existing) {
3751
+ return false;
3752
+ }
3753
+ }
3754
+ return true;
3755
+ }
3756
+ async function getSyncPreview(adapter, nativeRegistry) {
3757
+ return await syncNativeObjects(adapter, nativeRegistry, { dryRun: true });
3758
+ }
3759
+ async function syncAll(adapter, objectRegistry, nativeViewRegistry, options = {}) {
3760
+ if (options.verbose) {
3761
+ console.info("[SyncAll] Starting full sync...");
3762
+ }
3763
+ const objectsResult = await syncNativeObjects(adapter, objectRegistry, options);
3764
+ const viewsResult = await syncNativeViews(adapter, nativeViewRegistry, options);
3765
+ const result = {
3766
+ success: objectsResult.success && viewsResult.success,
3767
+ objects: objectsResult,
3768
+ views: viewsResult
3769
+ };
3770
+ if (options.verbose) {
3771
+ console.info(
3772
+ `[SyncAll] ${result.success ? "\u2713" : "\u2717"} Full sync complete:
3773
+ Objects: ${objectsResult.objectsSynced} synced (${objectsResult.objectsCreated} created, ${objectsResult.objectsUpdated} updated)
3774
+ Views: ${viewsResult.viewsSynced} synced (${viewsResult.viewsCreated} created, ${viewsResult.viewsUpdated} updated)
3775
+ Errors: ${objectsResult.errors.length + viewsResult.errors.length}`
3776
+ );
3777
+ }
3778
+ return result;
3779
+ }
3780
+
3781
+ // src/types/geocoding.ts
3782
+ var NoopGeocodingAdapter = class {
3783
+ async autocomplete() {
3784
+ return await Promise.resolve([]);
3785
+ }
3786
+ async reverse() {
3787
+ return await Promise.resolve(null);
3788
+ }
3789
+ async geocode() {
3790
+ return await Promise.resolve(null);
3791
+ }
3792
+ };
3793
+
3794
+ export {
3795
+ NoopGeocodingAdapter,
3796
+ generateId,
3797
+ generatePrefixedId,
3798
+ text,
3799
+ textarea,
3800
+ number,
3801
+ checkbox,
3802
+ date,
3803
+ phone,
3804
+ currency,
3805
+ status,
3806
+ select,
3807
+ multiselect,
3808
+ location,
3809
+ timestamp,
3810
+ file,
3811
+ user,
3812
+ relation,
3813
+ rating,
3814
+ ObjectBuilder,
3815
+ object,
3816
+ GroupBuilder,
3817
+ TableTabConfig,
3818
+ CustomTabConfig,
3819
+ TabBuilder,
3820
+ ViewBuilder,
3821
+ view,
3822
+ group,
3823
+ registry,
3824
+ createTextValidator,
3825
+ createNumberValidator,
3826
+ createCheckboxValidator,
3827
+ createDateValidator,
3828
+ createPhoneValidator,
3829
+ createCurrencyValidator,
3830
+ createStatusValidator,
3831
+ createSelectValidator,
3832
+ createMultiselectValidator,
3833
+ createLocationValidator,
3834
+ createTimestampValidator,
3835
+ createFileValidator,
3836
+ createUserValidator,
3837
+ createSingleRelationValidator,
3838
+ createMultiRelationValidator,
3839
+ createRelationValidator,
3840
+ createRatingValidator,
3841
+ createAttributeValidator,
3842
+ createObjectValidator,
3843
+ validateAttribute,
3844
+ validateObject,
3845
+ validateObjectOrThrow,
3846
+ createDraftValidator,
3847
+ validateDraft,
3848
+ validateDraftOrThrow,
3849
+ getMissingRequiredAttributes,
3850
+ isRecordComplete,
3851
+ computeRecordStatus,
3852
+ createMockAdapter,
3853
+ FileService,
3854
+ GeocodingService,
3855
+ ObjectSchemaService,
3856
+ RelationService,
3857
+ RecordService,
3858
+ UserProfileService,
3859
+ ViewService,
3860
+ syncNativeViews,
3861
+ verifyNativeViewsSync,
3862
+ getViewSyncPreview,
3863
+ syncNativeObjects,
3864
+ verifyNativeObjectsSync,
3865
+ getSyncPreview,
3866
+ syncAll
3867
+ };