@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,2534 @@
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
+ values: data.data,
366
+ createdAt: /* @__PURE__ */ new Date(),
367
+ updatedAt: /* @__PURE__ */ new Date()
368
+ };
369
+ stores.objectRecords.set(internal.id, internal);
370
+ const { tenantId: _, ...record } = internal;
371
+ return Promise.resolve(record);
372
+ },
373
+ update(id, data) {
374
+ const existing = stores.objectRecords.get(id);
375
+ if (!existing) {
376
+ return Promise.reject(new Error(`ObjectRecord ${id} not found`));
377
+ }
378
+ const updated = {
379
+ ...existing,
380
+ values: { ...existing.values, ...data },
381
+ updatedAt: /* @__PURE__ */ new Date()
382
+ };
383
+ stores.objectRecords.set(id, updated);
384
+ const { tenantId: _, ...record } = updated;
385
+ return Promise.resolve(record);
386
+ },
387
+ delete(id) {
388
+ stores.objectRecords.delete(id);
389
+ return Promise.resolve();
390
+ },
391
+ list(tenantId, objectId, options) {
392
+ let results = Array.from(stores.objectRecords.values()).filter(
393
+ (r) => r.tenantId === tenantId && r.objectId === objectId
394
+ );
395
+ const total = results.length;
396
+ if (options?.limit) {
397
+ results = results.slice(options.offset ?? 0, (options.offset ?? 0) + options.limit);
398
+ }
399
+ const records = results.map(({ tenantId: _, ...r }) => r);
400
+ return Promise.resolve({ records, total });
401
+ },
402
+ search(tenantId, objectId, query, options) {
403
+ const lowerQuery = query.toLowerCase();
404
+ let results = Array.from(stores.objectRecords.values()).filter((r) => {
405
+ if (r.tenantId !== tenantId || r.objectId !== objectId) return false;
406
+ return Object.values(r.values).some(
407
+ (val) => String(val).toLowerCase().includes(lowerQuery)
408
+ );
409
+ });
410
+ const total = results.length;
411
+ if (options?.limit) {
412
+ results = results.slice(options.offset ?? 0, (options.offset ?? 0) + options.limit);
413
+ }
414
+ const records = results.map(({ tenantId: _, ...r }) => r);
415
+ return Promise.resolve({ records, total });
416
+ }
417
+ };
418
+ }
419
+ function createMockAdapter() {
420
+ const stores = {
421
+ objects: /* @__PURE__ */ new Map(),
422
+ attributes: /* @__PURE__ */ new Map(),
423
+ userProfiles: /* @__PURE__ */ new Map(),
424
+ files: /* @__PURE__ */ new Map(),
425
+ objectRecords: /* @__PURE__ */ new Map()
426
+ };
427
+ const adapter = {
428
+ objects: createMockObjectsRepository(stores),
429
+ attributes: createMockAttributesRepository(stores),
430
+ userProfiles: createMockUserProfilesRepository(stores),
431
+ files: createMockFilesRepository(stores),
432
+ objectRecords: createMockObjectRecordsRepository(stores),
433
+ async transaction(callback) {
434
+ return await callback(adapter);
435
+ },
436
+ // Expose stores for testing inspection
437
+ _stores: stores,
438
+ // Reset all stores (useful between tests)
439
+ reset() {
440
+ stores.objects.clear();
441
+ stores.attributes.clear();
442
+ stores.userProfiles.clear();
443
+ stores.files.clear();
444
+ stores.objectRecords.clear();
445
+ }
446
+ };
447
+ return adapter;
448
+ }
449
+
450
+ // src/runtime/services/file.service.ts
451
+ var FileService = class {
452
+ constructor(adapter, tenantId) {
453
+ this.adapter = adapter;
454
+ this.tenantId = tenantId;
455
+ }
456
+ /**
457
+ * Create a new file record (after upload to storage)
458
+ *
459
+ * @param data - File metadata
460
+ * @returns Created file record
461
+ *
462
+ * @example
463
+ * ```typescript
464
+ * const service = new FileService(adapter, "tenant-123");
465
+ *
466
+ * // After uploading to S3
467
+ * const file = await service.createFile({
468
+ * tenantId: "tenant-123",
469
+ * name: "contract-2025.pdf",
470
+ * originalName: "Contract Acme Corp 2025.pdf",
471
+ * mimeType: "application/pdf",
472
+ * size: 2458624,
473
+ * storageProvider: "s3",
474
+ * storagePath: "tenants/123/files/2025/contract.pdf",
475
+ * storageBucket: "my-app-files",
476
+ * url: "https://cdn.example.com/files/file-123",
477
+ * uploadedBy: "profile-456",
478
+ * visibility: "private"
479
+ * });
480
+ * ```
481
+ */
482
+ async createFile(data) {
483
+ if (data.tenantId !== this.tenantId) {
484
+ throw new Error(
485
+ `Tenant mismatch: service initialized with "${this.tenantId}" but data has "${data.tenantId}"`
486
+ );
487
+ }
488
+ return await this.adapter.files.create(data);
489
+ }
490
+ /**
491
+ * Get file by ID
492
+ */
493
+ async getFile(fileId) {
494
+ const file2 = await this.adapter.files.findById(fileId);
495
+ if (file2?.deletedAt) {
496
+ return null;
497
+ }
498
+ return file2;
499
+ }
500
+ /**
501
+ * Get file by ID or throw
502
+ */
503
+ async getFileOrThrow(fileId) {
504
+ const file2 = await this.getFile(fileId);
505
+ if (!file2) {
506
+ throw new Error(`File with id "${fileId}" not found`);
507
+ }
508
+ return file2;
509
+ }
510
+ /**
511
+ * Update file metadata
512
+ *
513
+ * @param fileId - File UUID
514
+ * @param data - Data to update
515
+ * @returns Updated file
516
+ */
517
+ async updateFile(fileId, data) {
518
+ await this.getFileOrThrow(fileId);
519
+ return await this.adapter.files.update(fileId, data);
520
+ }
521
+ /**
522
+ * Delete file (soft delete)
523
+ *
524
+ * @param fileId - File UUID
525
+ * @param options - Delete options
526
+ */
527
+ async deleteFile(fileId, options) {
528
+ if (options?.checkOwnership && options.userId) {
529
+ const file2 = await this.getFileOrThrow(fileId);
530
+ if (file2.uploadedBy !== options.userId) {
531
+ throw new Error("You can only delete files you uploaded");
532
+ }
533
+ }
534
+ if (options?.hard) {
535
+ await this.adapter.files.hardDelete(fileId);
536
+ } else {
537
+ await this.adapter.files.delete(fileId);
538
+ }
539
+ }
540
+ /**
541
+ * List files for the tenant
542
+ */
543
+ async listFiles(options) {
544
+ return await this.adapter.files.list(this.tenantId, options);
545
+ }
546
+ /**
547
+ * List files by folder
548
+ */
549
+ async listFilesByFolder(folderPath) {
550
+ return await this.adapter.files.findByFolder(this.tenantId, folderPath);
551
+ }
552
+ /**
553
+ * List files uploaded by a specific user
554
+ */
555
+ async listFilesByUploader(uploadedBy) {
556
+ return await this.adapter.files.findByUploader(uploadedBy);
557
+ }
558
+ /**
559
+ * Change file visibility
560
+ *
561
+ * @param fileId - File UUID
562
+ * @param visibility - New visibility level
563
+ * @param allowedUsers - Users allowed to access (if restricted)
564
+ */
565
+ async changeVisibility(fileId, visibility, allowedUsers) {
566
+ const updateData = { visibility };
567
+ if (visibility === "restricted" && allowedUsers) {
568
+ updateData.allowedUsers = allowedUsers;
569
+ }
570
+ return await this.updateFile(fileId, updateData);
571
+ }
572
+ /**
573
+ * Grant access to a file for specific users
574
+ *
575
+ * @param fileId - File UUID
576
+ * @param userIds - User IDs to grant access
577
+ */
578
+ async grantAccess(fileId, userIds) {
579
+ const file2 = await this.getFileOrThrow(fileId);
580
+ const currentAllowed = file2.allowedUsers || [];
581
+ const newAllowed = [.../* @__PURE__ */ new Set([...currentAllowed, ...userIds])];
582
+ return await this.updateFile(fileId, {
583
+ visibility: "restricted",
584
+ allowedUsers: newAllowed
585
+ });
586
+ }
587
+ /**
588
+ * Revoke access to a file for specific users
589
+ *
590
+ * @param fileId - File UUID
591
+ * @param userIds - User IDs to revoke access
592
+ */
593
+ async revokeAccess(fileId, userIds) {
594
+ const file2 = await this.getFileOrThrow(fileId);
595
+ const currentAllowed = file2.allowedUsers || [];
596
+ const newAllowed = currentAllowed.filter((id) => !userIds.includes(id));
597
+ return await this.updateFile(fileId, {
598
+ allowedUsers: newAllowed
599
+ });
600
+ }
601
+ /**
602
+ * Check if user has access to a file
603
+ *
604
+ * @param fileId - File UUID
605
+ * @param userId - User ID to check
606
+ * @returns true if user can access the file
607
+ */
608
+ async canAccess(fileId, userId) {
609
+ const file2 = await this.getFile(fileId);
610
+ if (!file2) {
611
+ return false;
612
+ }
613
+ if (file2.visibility === "public") {
614
+ return true;
615
+ }
616
+ if (file2.uploadedBy === userId) {
617
+ return true;
618
+ }
619
+ if (file2.visibility === "restricted") {
620
+ return file2.allowedUsers?.includes(userId) ?? false;
621
+ }
622
+ return false;
623
+ }
624
+ /**
625
+ * Move file to different folder
626
+ */
627
+ async moveToFolder(fileId, newFolderPath) {
628
+ return await this.updateFile(fileId, { folderPath: newFolderPath });
629
+ }
630
+ /**
631
+ * Add tags to file
632
+ */
633
+ async addTags(fileId, tags) {
634
+ const file2 = await this.getFileOrThrow(fileId);
635
+ const currentTags = file2.tags || [];
636
+ const newTags = [.../* @__PURE__ */ new Set([...currentTags, ...tags])];
637
+ return await this.updateFile(fileId, { tags: newTags });
638
+ }
639
+ /**
640
+ * Remove tags from file
641
+ */
642
+ async removeTags(fileId, tags) {
643
+ const file2 = await this.getFileOrThrow(fileId);
644
+ const currentTags = file2.tags || [];
645
+ const newTags = currentTags.filter((tag) => !tags.includes(tag));
646
+ return await this.updateFile(fileId, { tags: newTags });
647
+ }
648
+ };
649
+
650
+ // src/builders/attribute-builders.ts
651
+ import { z } from "zod";
652
+ var BaseAttributeBuilder = class {
653
+ constructor(type, name, label) {
654
+ this.validateVariableName(name);
655
+ this.attr = {
656
+ name,
657
+ label,
658
+ type,
659
+ required: false
660
+ };
661
+ }
662
+ /**
663
+ * Validate attribute name as valid variable identifier
664
+ * Accepts: camelCase, snake_case, PascalCase, UPPER_CASE
665
+ */
666
+ validateVariableName(name) {
667
+ 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_]*$/, {
668
+ 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'"
669
+ });
670
+ try {
671
+ variableNameSchema.parse(name);
672
+ } catch (error) {
673
+ if (error instanceof z.ZodError) {
674
+ throw new Error(`[AttributeBuilder] ${error.errors[0].message}`);
675
+ }
676
+ throw error;
677
+ }
678
+ }
679
+ setRequired(value) {
680
+ this.attr.required = value;
681
+ }
682
+ system() {
683
+ this.attr.system = true;
684
+ return this;
685
+ }
686
+ disabled() {
687
+ this.attr.disabled = true;
688
+ return this;
689
+ }
690
+ hidden() {
691
+ this.attr.hidden = true;
692
+ return this;
693
+ }
694
+ placeholder(value) {
695
+ this.attr.placeholder = value;
696
+ return this;
697
+ }
698
+ description(value) {
699
+ this.attr.description = value;
700
+ return this;
701
+ }
702
+ icon(value) {
703
+ this.attr.icon = value;
704
+ return this;
705
+ }
706
+ order(value) {
707
+ this.attr.order = value;
708
+ return this;
709
+ }
710
+ defaultValue(value) {
711
+ this.attr.defaultValue = value;
712
+ return this;
713
+ }
714
+ metadata(value) {
715
+ this.attr.metadata = value;
716
+ return this;
717
+ }
718
+ build() {
719
+ return this.attr;
720
+ }
721
+ };
722
+ var TextAttributeBuilder = class extends BaseAttributeBuilder {
723
+ constructor(name, label) {
724
+ super("text", name, label);
725
+ }
726
+ minLength(value) {
727
+ this.attr.minLength = value;
728
+ return this;
729
+ }
730
+ maxLength(value) {
731
+ this.attr.maxLength = value;
732
+ return this;
733
+ }
734
+ pattern(value) {
735
+ this.attr.pattern = value;
736
+ return this;
737
+ }
738
+ required() {
739
+ this.setRequired(true);
740
+ return this;
741
+ }
742
+ optional() {
743
+ this.setRequired(false);
744
+ return this;
745
+ }
746
+ /**
747
+ * Set email validation pattern
748
+ */
749
+ email() {
750
+ this.attr.pattern = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
751
+ return this;
752
+ }
753
+ /**
754
+ * Set URL validation pattern
755
+ */
756
+ url() {
757
+ this.attr.pattern = "^https?:\\/\\/[\\w\\-]+(\\.[\\w\\-]+)+[/#?]?.*$";
758
+ return this;
759
+ }
760
+ /**
761
+ * Set slug validation pattern
762
+ */
763
+ slug() {
764
+ this.attr.pattern = "^[a-z0-9]+(?:-[a-z0-9]+)*$";
765
+ return this;
766
+ }
767
+ };
768
+ function text(config) {
769
+ return new TextAttributeBuilder(config.name, config.label);
770
+ }
771
+ var TextAreaAttributeBuilder = class extends BaseAttributeBuilder {
772
+ constructor(name, label) {
773
+ super("textarea", name, label);
774
+ }
775
+ required() {
776
+ this.setRequired(true);
777
+ return this;
778
+ }
779
+ optional() {
780
+ this.setRequired(false);
781
+ return this;
782
+ }
783
+ };
784
+ function textarea(config) {
785
+ return new TextAreaAttributeBuilder(config.name, config.label);
786
+ }
787
+ var NumberAttributeBuilder = class extends BaseAttributeBuilder {
788
+ constructor(name, label) {
789
+ super("number", name, label);
790
+ }
791
+ min(value) {
792
+ this.attr.min = value;
793
+ return this;
794
+ }
795
+ max(value) {
796
+ this.attr.max = value;
797
+ return this;
798
+ }
799
+ integer() {
800
+ this.attr.unit = "integer";
801
+ this.attr.decimals = 0;
802
+ return this;
803
+ }
804
+ decimal(decimals = 2) {
805
+ this.attr.unit = "decimal";
806
+ this.attr.decimals = decimals;
807
+ return this;
808
+ }
809
+ percentage() {
810
+ this.attr.unit = "percentage";
811
+ return this;
812
+ }
813
+ required() {
814
+ this.setRequired(true);
815
+ return this;
816
+ }
817
+ optional() {
818
+ this.setRequired(false);
819
+ return this;
820
+ }
821
+ };
822
+ function number(config) {
823
+ return new NumberAttributeBuilder(config.name, config.label);
824
+ }
825
+ var CheckboxAttributeBuilder = class extends BaseAttributeBuilder {
826
+ constructor(name, label) {
827
+ super("checkbox", name, label);
828
+ }
829
+ required() {
830
+ this.setRequired(true);
831
+ return this;
832
+ }
833
+ optional() {
834
+ this.setRequired(false);
835
+ return this;
836
+ }
837
+ };
838
+ function checkbox(config) {
839
+ return new CheckboxAttributeBuilder(config.name, config.label);
840
+ }
841
+ var DateAttributeBuilder = class extends BaseAttributeBuilder {
842
+ constructor(name, label) {
843
+ super("date", name, label);
844
+ }
845
+ format(value) {
846
+ this.attr.dateFormat = value;
847
+ return this;
848
+ }
849
+ minDate(value) {
850
+ this.attr.minDate = value;
851
+ return this;
852
+ }
853
+ maxDate(value) {
854
+ this.attr.maxDate = value;
855
+ return this;
856
+ }
857
+ required() {
858
+ this.setRequired(true);
859
+ return this;
860
+ }
861
+ optional() {
862
+ this.setRequired(false);
863
+ return this;
864
+ }
865
+ };
866
+ function date(config) {
867
+ return new DateAttributeBuilder(config.name, config.label);
868
+ }
869
+ var PhoneAttributeBuilder = class extends BaseAttributeBuilder {
870
+ constructor(name, label) {
871
+ super("phone", name, label);
872
+ }
873
+ defaultCountry(value) {
874
+ this.attr.defaultCountryCode = value;
875
+ return this;
876
+ }
877
+ required() {
878
+ this.setRequired(true);
879
+ return this;
880
+ }
881
+ optional() {
882
+ this.setRequired(false);
883
+ return this;
884
+ }
885
+ };
886
+ function phone(config) {
887
+ return new PhoneAttributeBuilder(config.name, config.label);
888
+ }
889
+ var CurrencyAttributeBuilder = class extends BaseAttributeBuilder {
890
+ constructor(name, label) {
891
+ super("currency", name, label);
892
+ }
893
+ defaultCurrency(value) {
894
+ this.attr.defaultCurrency = value;
895
+ return this;
896
+ }
897
+ allowedCurrencies(value) {
898
+ this.attr.allowedCurrencies = value;
899
+ return this;
900
+ }
901
+ required() {
902
+ this.setRequired(true);
903
+ return this;
904
+ }
905
+ optional() {
906
+ this.setRequired(false);
907
+ return this;
908
+ }
909
+ };
910
+ function currency(config) {
911
+ return new CurrencyAttributeBuilder(config.name, config.label);
912
+ }
913
+ var StatusAttributeBuilder = class extends BaseAttributeBuilder {
914
+ constructor(name, label) {
915
+ super("status", name, label);
916
+ }
917
+ /**
918
+ * Set all options at once (preserves literal types for values)
919
+ */
920
+ options(value) {
921
+ this.attr.options = value;
922
+ return this;
923
+ }
924
+ option(config) {
925
+ if (!this.attr.options) {
926
+ this.attr.options = [];
927
+ }
928
+ this.attr.options.push(config);
929
+ return this;
930
+ }
931
+ required() {
932
+ this.setRequired(true);
933
+ return this;
934
+ }
935
+ optional() {
936
+ this.setRequired(false);
937
+ return this;
938
+ }
939
+ };
940
+ function status(config) {
941
+ return new StatusAttributeBuilder(config.name, config.label);
942
+ }
943
+ var SelectAttributeBuilder = class extends BaseAttributeBuilder {
944
+ constructor(name, label) {
945
+ super("select", name, label);
946
+ }
947
+ /**
948
+ * Set all options at once (preserves literal types for values)
949
+ */
950
+ options(value) {
951
+ this.attr.options = value;
952
+ return this;
953
+ }
954
+ option(config) {
955
+ if (!this.attr.options) {
956
+ this.attr.options = [];
957
+ }
958
+ this.attr.options.push(config);
959
+ return this;
960
+ }
961
+ required() {
962
+ this.setRequired(true);
963
+ return this;
964
+ }
965
+ optional() {
966
+ this.setRequired(false);
967
+ return this;
968
+ }
969
+ };
970
+ function select(config) {
971
+ return new SelectAttributeBuilder(config.name, config.label);
972
+ }
973
+ var MultiselectAttributeBuilder = class extends BaseAttributeBuilder {
974
+ constructor(name, label) {
975
+ super("multiselect", name, label);
976
+ }
977
+ /**
978
+ * Set all options at once (preserves literal types for values)
979
+ */
980
+ options(value) {
981
+ this.attr.options = value;
982
+ return this;
983
+ }
984
+ option(config) {
985
+ if (!this.attr.options) {
986
+ this.attr.options = [];
987
+ }
988
+ this.attr.options.push(config);
989
+ return this;
990
+ }
991
+ required() {
992
+ this.setRequired(true);
993
+ return this;
994
+ }
995
+ optional() {
996
+ this.setRequired(false);
997
+ return this;
998
+ }
999
+ };
1000
+ function multiselect(config) {
1001
+ return new MultiselectAttributeBuilder(config.name, config.label);
1002
+ }
1003
+ var LocationAttributeBuilder = class extends BaseAttributeBuilder {
1004
+ constructor(name, label) {
1005
+ super("location", name, label);
1006
+ }
1007
+ granularity(value) {
1008
+ this.attr.granularity = value;
1009
+ return this;
1010
+ }
1011
+ enableAutocomplete() {
1012
+ this.attr.enableAutocomplete = true;
1013
+ return this;
1014
+ }
1015
+ enableMap() {
1016
+ this.attr.enableMap = true;
1017
+ return this;
1018
+ }
1019
+ defaultCountry(value) {
1020
+ this.attr.defaultCountry = value;
1021
+ return this;
1022
+ }
1023
+ allowedCountries(value) {
1024
+ this.attr.allowedCountries = value;
1025
+ return this;
1026
+ }
1027
+ displayFormat(value) {
1028
+ this.attr.displayFormat = value;
1029
+ return this;
1030
+ }
1031
+ required() {
1032
+ this.setRequired(true);
1033
+ return this;
1034
+ }
1035
+ optional() {
1036
+ this.setRequired(false);
1037
+ return this;
1038
+ }
1039
+ };
1040
+ function location(config) {
1041
+ return new LocationAttributeBuilder(config.name, config.label);
1042
+ }
1043
+ var TimestampAttributeBuilder = class extends BaseAttributeBuilder {
1044
+ constructor(name, label) {
1045
+ super("timestamp", name, label);
1046
+ }
1047
+ autoUpdate() {
1048
+ this.attr.autoUpdate = true;
1049
+ return this;
1050
+ }
1051
+ required() {
1052
+ this.setRequired(true);
1053
+ return this;
1054
+ }
1055
+ optional() {
1056
+ this.setRequired(false);
1057
+ return this;
1058
+ }
1059
+ };
1060
+ function timestamp(config) {
1061
+ return new TimestampAttributeBuilder(config.name, config.label);
1062
+ }
1063
+ var FileAttributeBuilder = class extends BaseAttributeBuilder {
1064
+ constructor(name, label) {
1065
+ super("file", name, label);
1066
+ }
1067
+ maxFiles(value) {
1068
+ this.attr.maxFiles = value;
1069
+ return this;
1070
+ }
1071
+ maxSize(bytes) {
1072
+ this.attr.maxSize = bytes;
1073
+ return this;
1074
+ }
1075
+ allowedTypes(types) {
1076
+ this.attr.allowedTypes = types;
1077
+ return this;
1078
+ }
1079
+ verification(config) {
1080
+ this.attr.verification = config;
1081
+ return this;
1082
+ }
1083
+ required() {
1084
+ this.setRequired(true);
1085
+ return this;
1086
+ }
1087
+ optional() {
1088
+ this.setRequired(false);
1089
+ return this;
1090
+ }
1091
+ };
1092
+ function file(config) {
1093
+ return new FileAttributeBuilder(config.name, config.label);
1094
+ }
1095
+ var UserAttributeBuilder = class extends BaseAttributeBuilder {
1096
+ constructor(name, label) {
1097
+ super("user", name, label);
1098
+ }
1099
+ allowedRoles(roles) {
1100
+ this.attr.allowedRoles = roles;
1101
+ return this;
1102
+ }
1103
+ required() {
1104
+ this.setRequired(true);
1105
+ return this;
1106
+ }
1107
+ optional() {
1108
+ this.setRequired(false);
1109
+ return this;
1110
+ }
1111
+ };
1112
+ function user(config) {
1113
+ return new UserAttributeBuilder(config.name, config.label);
1114
+ }
1115
+ var RelationAttributeBuilder = class extends BaseAttributeBuilder {
1116
+ constructor(name, label) {
1117
+ super("relation", name, label);
1118
+ }
1119
+ relation(objectIds) {
1120
+ this.attr.relation = objectIds;
1121
+ return this;
1122
+ }
1123
+ limit(value) {
1124
+ this.attr.limit = value;
1125
+ return this;
1126
+ }
1127
+ cascadeDelete() {
1128
+ this.attr.cascadeDelete = true;
1129
+ return this;
1130
+ }
1131
+ required() {
1132
+ this.setRequired(true);
1133
+ return this;
1134
+ }
1135
+ optional() {
1136
+ this.setRequired(false);
1137
+ return this;
1138
+ }
1139
+ };
1140
+ function relation(config) {
1141
+ return new RelationAttributeBuilder(config.name, config.label);
1142
+ }
1143
+ var RatingAttributeBuilder = class extends BaseAttributeBuilder {
1144
+ constructor(name, label) {
1145
+ super("rating", name, label);
1146
+ }
1147
+ max(value) {
1148
+ this.attr.max = value;
1149
+ return this;
1150
+ }
1151
+ iconType(value) {
1152
+ this.attr.iconType = value;
1153
+ return this;
1154
+ }
1155
+ required() {
1156
+ this.setRequired(true);
1157
+ return this;
1158
+ }
1159
+ optional() {
1160
+ this.setRequired(false);
1161
+ return this;
1162
+ }
1163
+ };
1164
+ function rating(config) {
1165
+ return new RatingAttributeBuilder(config.name, config.label);
1166
+ }
1167
+
1168
+ // src/builders/object-builder.ts
1169
+ import z2 from "zod";
1170
+ var ObjectBuilder = class {
1171
+ constructor(config) {
1172
+ this.validateName(config.name);
1173
+ this.obj = {
1174
+ name: config.name,
1175
+ label: config.label,
1176
+ attributes: [],
1177
+ system: false
1178
+ };
1179
+ }
1180
+ /**
1181
+ * Set object description
1182
+ */
1183
+ description(value) {
1184
+ this.obj.description = value;
1185
+ return this;
1186
+ }
1187
+ /**
1188
+ * Set object icon
1189
+ */
1190
+ icon(value) {
1191
+ this.obj.icon = value;
1192
+ return this;
1193
+ }
1194
+ /**
1195
+ * Mark as system/native object (defined in code, protected)
1196
+ * System objects cannot be deleted/modified by clients
1197
+ */
1198
+ system() {
1199
+ this.obj.system = true;
1200
+ return this;
1201
+ }
1202
+ /**
1203
+ * Add an attribute to the object with type accumulation
1204
+ *
1205
+ * The return type accumulates the attribute's name and value type
1206
+ * into the TRecord generic, enabling full inference.
1207
+ *
1208
+ * @param attr - Attribute definition or builder (auto-builds if builder)
1209
+ */
1210
+ attribute(attr) {
1211
+ if (!this.obj.attributes) {
1212
+ this.obj.attributes = [];
1213
+ }
1214
+ const finalAttr = "build" in attr && typeof attr.build === "function" ? attr.build() : attr;
1215
+ this.obj.attributes.push(finalAttr);
1216
+ return this;
1217
+ }
1218
+ /**
1219
+ * Add multiple attributes at once
1220
+ * Note: For full type inference, prefer chaining .attribute() calls
1221
+ */
1222
+ attributes(attrs) {
1223
+ if (!this.obj.attributes) {
1224
+ this.obj.attributes = [];
1225
+ }
1226
+ const finalAttrs = attrs.map((attr) => "build" in attr ? attr.build() : attr);
1227
+ this.obj.attributes.push(...finalAttrs);
1228
+ return this;
1229
+ }
1230
+ /**
1231
+ * Set metadata
1232
+ */
1233
+ metadata(value) {
1234
+ this.obj.metadata = value;
1235
+ return this;
1236
+ }
1237
+ /**
1238
+ * Set the title attribute (the text attribute used to display the object's name)
1239
+ * Must reference a text attribute that has been added to the object.
1240
+ * If not set, the first text attribute becomes the title attribute.
1241
+ *
1242
+ * @param attributeName - The name of a text attribute
1243
+ */
1244
+ titleAttribute(attributeName) {
1245
+ this._titleAttribute = attributeName;
1246
+ return this;
1247
+ }
1248
+ /**
1249
+ * Build the final ObjectDefinition
1250
+ * @throws Error if required fields are missing or invalid
1251
+ */
1252
+ build() {
1253
+ if (!this.obj.name) {
1254
+ throw new Error("[ObjectBuilder] Missing required field: name");
1255
+ }
1256
+ if (!this.obj.label) {
1257
+ throw new Error("[ObjectBuilder] Missing required field: label");
1258
+ }
1259
+ const textAttributes = (this.obj.attributes ?? []).filter((attr) => attr.type === "text");
1260
+ if (textAttributes.length === 0) {
1261
+ throw new Error(
1262
+ `[ObjectBuilder] Object "${this.obj.name}" must have at least one text attribute.
1263
+ A text attribute is required to serve as the object's title/display name.
1264
+ \u2705 Example: .attribute(text({ name: 'name', label: 'Name' }).required())`
1265
+ );
1266
+ }
1267
+ const titleAttrName = this._titleAttribute ?? textAttributes[0].name;
1268
+ const titleAttr = textAttributes.find((attr) => attr.name === titleAttrName);
1269
+ if (!titleAttr) {
1270
+ const availableTextAttrs = textAttributes.map((a) => `'${a.name}'`).join(", ");
1271
+ throw new Error(
1272
+ `[ObjectBuilder] titleAttribute "${titleAttrName}" must be a text attribute.
1273
+ Available text attributes: ${availableTextAttrs}`
1274
+ );
1275
+ }
1276
+ const metadata = this.obj.metadata ?? {};
1277
+ metadata.titleAttribute = titleAttrName;
1278
+ this.obj.metadata = metadata;
1279
+ return this.obj;
1280
+ }
1281
+ /**
1282
+ * Validate object name format
1283
+ * Must be kebab-case (slug format), max 63 characters
1284
+ * @internal
1285
+ */
1286
+ validateName(name) {
1287
+ if (name === void 0) {
1288
+ return;
1289
+ }
1290
+ 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-]*$/, {
1291
+ 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'"
1292
+ });
1293
+ try {
1294
+ objectNameSchema.parse(name);
1295
+ } catch (error) {
1296
+ if (error instanceof z2.ZodError) {
1297
+ throw new Error(`[ObjectBuilder] ${error.errors[0].message}`);
1298
+ }
1299
+ throw error;
1300
+ }
1301
+ }
1302
+ };
1303
+ function object(config) {
1304
+ return new ObjectBuilder(config);
1305
+ }
1306
+
1307
+ // src/runtime/services/object-schema.service.ts
1308
+ var ObjectSchemaService = class {
1309
+ constructor(adapter, nativeRegistry) {
1310
+ this.adapter = adapter;
1311
+ this.nativeRegistry = nativeRegistry;
1312
+ }
1313
+ /**
1314
+ * Create a new custom object
1315
+ * Validates name format and ensures system=false
1316
+ *
1317
+ * @param definition - Object definition (attributes can be raw definitions or builders)
1318
+ * @param tenantId - Tenant ID owning the object
1319
+ * @returns Created ObjectDefinition
1320
+ */
1321
+ async createCustomObject(definition, tenantId) {
1322
+ const builder = object({
1323
+ name: definition.name,
1324
+ label: definition.label
1325
+ });
1326
+ if (definition.description) builder.description(definition.description);
1327
+ if (definition.icon) builder.icon(definition.icon);
1328
+ if (definition.metadata) builder.metadata(definition.metadata);
1329
+ if (definition.attributes && definition.attributes.length > 0) {
1330
+ builder.attributes(definition.attributes);
1331
+ }
1332
+ const objectDef = builder.build();
1333
+ const existing = await this.adapter.objects.findByName(tenantId, objectDef.name);
1334
+ if (existing) {
1335
+ throw new Error(`Object with name "${objectDef.name}" already exists`);
1336
+ }
1337
+ const metadata = {
1338
+ ...objectDef.metadata,
1339
+ icon: objectDef.icon
1340
+ };
1341
+ const dbObject = await this.adapter.objects.create({
1342
+ tenantId,
1343
+ name: objectDef.name,
1344
+ label: objectDef.label,
1345
+ description: objectDef.description,
1346
+ system: false,
1347
+ // Always false for custom objects
1348
+ metadata
1349
+ });
1350
+ const createdAttributes = [];
1351
+ if (objectDef.attributes.length > 0) {
1352
+ for (const attr of objectDef.attributes) {
1353
+ const dbAttr = await this.adapter.attributes.create({
1354
+ objectId: dbObject.id,
1355
+ name: attr.name,
1356
+ label: attr.label,
1357
+ type: attr.type,
1358
+ required: attr.required ?? false,
1359
+ system: false,
1360
+ // Always false for custom attributes
1361
+ config: {
1362
+ ...attr,
1363
+ // Remove common fields stored in columns
1364
+ id: void 0,
1365
+ name: void 0,
1366
+ label: void 0,
1367
+ type: void 0,
1368
+ required: void 0,
1369
+ system: void 0
1370
+ }
1371
+ });
1372
+ createdAttributes.push(this.convertDBAttributeToAttribute(dbAttr));
1373
+ }
1374
+ }
1375
+ return {
1376
+ ...objectDef,
1377
+ id: dbObject.id,
1378
+ attributes: createdAttributes,
1379
+ system: false
1380
+ };
1381
+ }
1382
+ /**
1383
+ * Add a custom attribute to an existing object
1384
+ * Can be used on both custom and native objects
1385
+ * Attributes added via API are always custom (system=false)
1386
+ *
1387
+ * @param objectId - Object UUID from database
1388
+ * @param attribute - Attribute definition
1389
+ * @returns Created Attribute
1390
+ */
1391
+ async addAttributeToObject(objectId, attribute) {
1392
+ this.validateAttributeName(attribute.name);
1393
+ const dbObject = await this.adapter.objects.findById(objectId);
1394
+ if (!dbObject) {
1395
+ throw new Error(`Object with id "${objectId}" not found`);
1396
+ }
1397
+ const existingAttributes = await this.adapter.attributes.findByObjectId(objectId);
1398
+ const duplicate = existingAttributes.find((attr) => attr.name === attribute.name);
1399
+ if (duplicate) {
1400
+ throw new Error(
1401
+ `Attribute with name "${attribute.name}" already exists on object "${dbObject.name}"`
1402
+ );
1403
+ }
1404
+ const dbAttr = await this.adapter.attributes.create({
1405
+ objectId,
1406
+ name: attribute.name,
1407
+ label: attribute.label,
1408
+ type: attribute.type,
1409
+ required: attribute.required ?? false,
1410
+ unique: attribute.unique ?? false,
1411
+ system: false,
1412
+ // Always false for attributes added via API
1413
+ config: {
1414
+ // Store all extra properties in config
1415
+ ...attribute,
1416
+ // Remove common fields stored in columns
1417
+ name: void 0,
1418
+ label: void 0,
1419
+ type: void 0,
1420
+ required: void 0,
1421
+ unique: void 0,
1422
+ system: void 0
1423
+ }
1424
+ });
1425
+ return this.convertDBAttributeToAttribute(dbAttr);
1426
+ }
1427
+ /**
1428
+ * Update an attribute
1429
+ * Can only update custom attributes (system=false)
1430
+ *
1431
+ * @param attributeId - Attribute UUID
1432
+ * @param updates - Partial attribute updates
1433
+ * @returns Updated Attribute
1434
+ */
1435
+ async updateAttribute(attributeId, updates) {
1436
+ const dbAttr = await this.adapter.attributes.findById(attributeId);
1437
+ if (!dbAttr) {
1438
+ throw new Error(`Attribute with id "${attributeId}" not found`);
1439
+ }
1440
+ if (dbAttr.system) {
1441
+ throw new Error(
1442
+ `Cannot modify system attribute "${dbAttr.name}". System attributes are protected.`
1443
+ );
1444
+ }
1445
+ if (updates.name && updates.name !== dbAttr.name) {
1446
+ throw new Error(
1447
+ "Attribute name cannot be changed after creation. Create a new attribute instead."
1448
+ );
1449
+ }
1450
+ if (updates.type && updates.type !== dbAttr.type) {
1451
+ throw new Error(
1452
+ "Attribute type cannot be changed after creation. Create a new attribute instead."
1453
+ );
1454
+ }
1455
+ const updatedDbAttr = await this.adapter.attributes.update(attributeId, {
1456
+ label: updates.label,
1457
+ required: updates.required,
1458
+ config: updates ? {
1459
+ ...dbAttr.config,
1460
+ ...updates,
1461
+ // Remove common fields
1462
+ name: void 0,
1463
+ label: void 0,
1464
+ type: void 0,
1465
+ required: void 0,
1466
+ unique: void 0,
1467
+ system: void 0
1468
+ } : dbAttr.config
1469
+ });
1470
+ return this.convertDBAttributeToAttribute(updatedDbAttr);
1471
+ }
1472
+ /**
1473
+ * Delete an attribute
1474
+ * Can only delete custom attributes (system=false)
1475
+ *
1476
+ * @param attributeId - Attribute UUID
1477
+ */
1478
+ async deleteAttribute(attributeId) {
1479
+ const dbAttr = await this.adapter.attributes.findById(attributeId);
1480
+ if (!dbAttr) {
1481
+ throw new Error(`Attribute with id "${attributeId}" not found`);
1482
+ }
1483
+ if (dbAttr.system) {
1484
+ throw new Error(
1485
+ `Cannot delete system attribute "${dbAttr.name}". System attributes are protected.`
1486
+ );
1487
+ }
1488
+ await this.adapter.attributes.delete(attributeId);
1489
+ }
1490
+ /**
1491
+ * List attributes for an object
1492
+ *
1493
+ * @param objectId - Object UUID
1494
+ * @param options - Filter options
1495
+ * @returns List of attributes
1496
+ */
1497
+ async listAttributes(objectId, options) {
1498
+ const dbAttributes = await this.adapter.attributes.findByObjectId(objectId);
1499
+ let filtered = dbAttributes;
1500
+ if (options?.systemOnly) {
1501
+ filtered = dbAttributes.filter((attr) => attr.system);
1502
+ } else if (options?.customOnly) {
1503
+ filtered = dbAttributes.filter((attr) => !attr.system);
1504
+ }
1505
+ return filtered.map((attr) => this.convertDBAttributeToAttribute(attr));
1506
+ }
1507
+ /**
1508
+ * Validate attribute name format (variable identifier)
1509
+ * @internal
1510
+ */
1511
+ validateAttributeName(name) {
1512
+ const variableNameRegex = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
1513
+ if (!name || name.length === 0) {
1514
+ throw new Error("Attribute name cannot be empty");
1515
+ }
1516
+ if (name.length > 63) {
1517
+ throw new Error("Attribute name is too long (max 63 characters)");
1518
+ }
1519
+ if (!variableNameRegex.test(name)) {
1520
+ throw new Error(
1521
+ "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'"
1522
+ );
1523
+ }
1524
+ }
1525
+ /**
1526
+ * Get complete object schema (system + custom attributes)
1527
+ * If object is native, merges registry definition with DB custom attributes
1528
+ * If object is custom, returns DB definition only
1529
+ *
1530
+ * @param objectId - Object UUID from database
1531
+ * @returns Complete ObjectDefinition with all attributes
1532
+ *
1533
+ * @example
1534
+ * ```typescript
1535
+ * const service = new ObjectSchemaService(adapter, registry);
1536
+ * const productSchema = await service.getObjectSchema("obj-123");
1537
+ *
1538
+ * console.log(productSchema.attributes); // System + custom attributes
1539
+ * ```
1540
+ */
1541
+ async getObjectSchema(objectId) {
1542
+ const dbObject = await this.adapter.objects.findById(objectId);
1543
+ if (!dbObject) {
1544
+ throw new Error(`Object with id "${objectId}" not found`);
1545
+ }
1546
+ const dbAttributes = await this.adapter.attributes.findByObjectId(objectId);
1547
+ if (dbObject.system) {
1548
+ return this.mergeNativeObject(dbObject, dbAttributes);
1549
+ }
1550
+ return this.convertDBObjectToDefinition(dbObject, dbAttributes);
1551
+ }
1552
+ /**
1553
+ * Get object schema by name (for system/native objects)
1554
+ */
1555
+ async getObjectSchemaByName(name) {
1556
+ const dbObject = await this.adapter.objects.findSystemByName(name);
1557
+ if (!dbObject) {
1558
+ throw new Error(`Native object "${name}" not found in database`);
1559
+ }
1560
+ const dbAttributes = await this.adapter.attributes.findByObjectId(dbObject.id);
1561
+ return this.mergeNativeObject(dbObject, dbAttributes);
1562
+ }
1563
+ /**
1564
+ * List all object schemas for a tenant
1565
+ */
1566
+ async listObjectSchemas(tenantId) {
1567
+ const dbObjects = await this.adapter.objects.list(tenantId);
1568
+ const schemas = await Promise.all(
1569
+ dbObjects.map(async (dbObject) => {
1570
+ const dbAttributes = await this.adapter.attributes.findByObjectId(dbObject.id);
1571
+ if (dbObject.system) {
1572
+ return this.mergeNativeObject(dbObject, dbAttributes);
1573
+ }
1574
+ return this.convertDBObjectToDefinition(dbObject, dbAttributes);
1575
+ })
1576
+ );
1577
+ return schemas;
1578
+ }
1579
+ /**
1580
+ * Merge native object from registry with custom attributes from DB
1581
+ * @internal
1582
+ */
1583
+ mergeNativeObject(dbObject, dbAttributes) {
1584
+ const nativeObject = this.nativeRegistry.getByName(dbObject.name);
1585
+ if (!nativeObject) {
1586
+ throw new Error(
1587
+ `Native object "${dbObject.name}" not found in registry. Make sure to register it before querying.`
1588
+ );
1589
+ }
1590
+ const customAttributes = dbAttributes.filter((attr) => !attr.system);
1591
+ const customAttrs = customAttributes.map(
1592
+ (dbAttr) => this.convertDBAttributeToAttribute(dbAttr)
1593
+ );
1594
+ return {
1595
+ ...nativeObject,
1596
+ id: dbObject.id,
1597
+ attributes: [
1598
+ ...nativeObject.attributes,
1599
+ // System attributes from code
1600
+ ...customAttrs
1601
+ // Custom attributes from DB
1602
+ ]
1603
+ };
1604
+ }
1605
+ /**
1606
+ * Convert DB object + attributes to ObjectDefinition
1607
+ * @internal
1608
+ */
1609
+ convertDBObjectToDefinition(dbObject, dbAttributes) {
1610
+ const attributes = dbAttributes.map(
1611
+ (dbAttr) => this.convertDBAttributeToAttribute(dbAttr)
1612
+ );
1613
+ return {
1614
+ id: dbObject.id,
1615
+ name: dbObject.name,
1616
+ label: dbObject.label,
1617
+ description: dbObject.description,
1618
+ icon: dbObject.metadata?.icon,
1619
+ attributes,
1620
+ system: dbObject.system,
1621
+ metadata: dbObject.metadata
1622
+ };
1623
+ }
1624
+ /**
1625
+ * Convert DB attribute to Attribute type
1626
+ * @internal
1627
+ */
1628
+ convertDBAttributeToAttribute(dbAttr) {
1629
+ const baseAttr = {
1630
+ ...dbAttr.config,
1631
+ id: dbAttr.id,
1632
+ name: dbAttr.name,
1633
+ label: dbAttr.label,
1634
+ type: dbAttr.type,
1635
+ required: dbAttr.required,
1636
+ system: dbAttr.system,
1637
+ unique: dbAttr.unique
1638
+ };
1639
+ return baseAttr;
1640
+ }
1641
+ };
1642
+
1643
+ // src/native/registry.ts
1644
+ var NativeObjectRegistryClass = class {
1645
+ constructor() {
1646
+ this.objects = /* @__PURE__ */ new Map();
1647
+ }
1648
+ /**
1649
+ * Register one or more native objects
1650
+ * Auto-builds if ObjectBuilder is passed instead of ObjectDefinition
1651
+ * @param objects - Single object/builder or array of objects/builders to register
1652
+ * @returns this (for chaining)
1653
+ * @throws Error if object is invalid or already registered
1654
+ *
1655
+ * @example
1656
+ * ```typescript
1657
+ * // No .build() needed - registry auto-builds!
1658
+ * const PRODUCT = object({ id: "obj-product", name: "products", label: "Product" })
1659
+ * .system()
1660
+ * .attribute(text({ id: "attr-name", name: "name", label: "Name" }));
1661
+ *
1662
+ * registry.register(PRODUCT); // ← Auto-builds here
1663
+ *
1664
+ * // Can still explicitly .build() if you want
1665
+ * registry.register(PRODUCT.build());
1666
+ *
1667
+ * // Register multiple
1668
+ * registry.register([PRODUCT, ORDER, CUSTOMER]);
1669
+ * ```
1670
+ */
1671
+ register(objects) {
1672
+ const objectsArray = Array.isArray(objects) ? objects : [objects];
1673
+ for (const obj of objectsArray) {
1674
+ const object2 = "build" in obj && typeof obj.build === "function" ? obj.build() : obj;
1675
+ this.validateAndRegister(object2);
1676
+ }
1677
+ return this;
1678
+ }
1679
+ /**
1680
+ * Validate and register a single object
1681
+ * @internal
1682
+ */
1683
+ validateAndRegister(object2) {
1684
+ if (!object2.system) {
1685
+ throw new Error(
1686
+ `[NativeObjectRegistry] Cannot register object "${object2.name}" (id: ${object2.id}): missing system flag.
1687
+ Native objects must have system=true. Did you forget to call .system() in your builder?`
1688
+ );
1689
+ }
1690
+ if (this.objects.has(object2.name)) {
1691
+ const existing = this.objects.get(object2.name);
1692
+ throw new Error(
1693
+ `[NativeObjectRegistry] Duplicate object name "${object2.name}":
1694
+ - Existing: "${existing?.label}" (id: ${existing?.id})
1695
+ - New: "${object2.label}" (id: ${object2.id})
1696
+ Please use unique names for each native object.`
1697
+ );
1698
+ }
1699
+ this.objects.set(object2.name, object2);
1700
+ }
1701
+ /**
1702
+ * Get a native object by its name
1703
+ * @param name - The object name
1704
+ * @returns The object definition or undefined if not found
1705
+ *
1706
+ * @example
1707
+ * ```typescript
1708
+ * const product = registry.getByName("products");
1709
+ * if (product) {
1710
+ * console.log(product.label); // "Product"
1711
+ * }
1712
+ * ```
1713
+ */
1714
+ getByName(name) {
1715
+ return this.objects.get(name);
1716
+ }
1717
+ /**
1718
+ * Get a native object or throw if not found
1719
+ * @param name - The object name
1720
+ * @returns The object definition
1721
+ * @throws Error if not found
1722
+ */
1723
+ getByNameOrThrow(name) {
1724
+ const object2 = this.objects.get(name);
1725
+ if (!object2) {
1726
+ throw new Error(
1727
+ `[NativeObjectRegistry] Native object "${name}" not found.
1728
+ Available objects: ${this.listNames().join(", ")}`
1729
+ );
1730
+ }
1731
+ return object2;
1732
+ }
1733
+ /**
1734
+ * Get all registered native objects
1735
+ * @returns Array of all registered object definitions
1736
+ */
1737
+ getAll() {
1738
+ return Array.from(this.objects.values());
1739
+ }
1740
+ /**
1741
+ * Get all registered native object names
1742
+ * @returns Array of object names
1743
+ */
1744
+ listNames() {
1745
+ return Array.from(this.objects.keys());
1746
+ }
1747
+ /**
1748
+ * Check if a native object is registered
1749
+ * @param name - The object name
1750
+ * @returns true if registered, false otherwise
1751
+ */
1752
+ has(name) {
1753
+ return this.objects.has(name);
1754
+ }
1755
+ /**
1756
+ * Get the number of registered objects
1757
+ */
1758
+ get size() {
1759
+ return this.objects.size;
1760
+ }
1761
+ /**
1762
+ * Clear all registered objects (useful for testing)
1763
+ * @internal
1764
+ */
1765
+ clear() {
1766
+ this.objects.clear();
1767
+ }
1768
+ /**
1769
+ * Get registry summary for debugging
1770
+ */
1771
+ summary() {
1772
+ const objects = this.getAll();
1773
+ return [
1774
+ `[NativeObjectRegistry] ${this.size} native object(s) registered:`,
1775
+ ...objects.map(
1776
+ (obj) => ` - ${obj.name}: "${obj.label}" (${obj.attributes.length} attributes)`
1777
+ )
1778
+ ].join("\n");
1779
+ }
1780
+ /**
1781
+ * Log registry summary to console
1782
+ */
1783
+ debug() {
1784
+ console.info(this.summary());
1785
+ }
1786
+ };
1787
+ var registry = new NativeObjectRegistryClass();
1788
+
1789
+ // src/validation/validators.ts
1790
+ import { z as z3 } from "zod";
1791
+ function createTextValidator(attr) {
1792
+ let schema = z3.string();
1793
+ if (attr.minLength !== void 0) {
1794
+ schema = schema.min(
1795
+ attr.minLength,
1796
+ `${attr.label} must be at least ${attr.minLength} characters`
1797
+ );
1798
+ }
1799
+ if (attr.maxLength !== void 0) {
1800
+ schema = schema.max(
1801
+ attr.maxLength,
1802
+ `${attr.label} must be at most ${attr.maxLength} characters`
1803
+ );
1804
+ }
1805
+ if (attr.pattern) {
1806
+ schema = schema.regex(new RegExp(attr.pattern), `${attr.label} format is invalid`);
1807
+ }
1808
+ return schema;
1809
+ }
1810
+ function createNumberValidator(attr) {
1811
+ let schema = z3.number();
1812
+ if (attr.min !== void 0) {
1813
+ schema = schema.min(attr.min, `${attr.label} must be at least ${attr.min}`);
1814
+ }
1815
+ if (attr.max !== void 0) {
1816
+ schema = schema.max(attr.max, `${attr.label} must be at most ${attr.max}`);
1817
+ }
1818
+ if (attr.unit === "integer") {
1819
+ schema = schema.int(`${attr.label} must be an integer`);
1820
+ }
1821
+ return schema;
1822
+ }
1823
+ function createCheckboxValidator(_attr) {
1824
+ return z3.boolean();
1825
+ }
1826
+ function createDateValidator(attr) {
1827
+ return z3.string().datetime({ message: `${attr.label} must be a valid ISO date` });
1828
+ }
1829
+ function createPhoneValidator(_attr) {
1830
+ return z3.object({
1831
+ countryCode: z3.string().length(3),
1832
+ phoneNumber: z3.string().min(1)
1833
+ });
1834
+ }
1835
+ function createCurrencyValidator(_attr) {
1836
+ return z3.object({
1837
+ code: z3.string().length(3),
1838
+ value: z3.number().min(0)
1839
+ });
1840
+ }
1841
+ function createStatusValidator(attr) {
1842
+ const validValues = attr.options.map((opt) => opt.value);
1843
+ return z3.enum(validValues, {
1844
+ errorMap: () => ({
1845
+ message: `${attr.label} must be one of: ${validValues.join(", ")}`
1846
+ })
1847
+ });
1848
+ }
1849
+ function createSelectValidator(attr) {
1850
+ const validValues = attr.options.map((opt) => opt.value);
1851
+ return z3.enum(validValues, {
1852
+ errorMap: () => ({
1853
+ message: `${attr.label} must be one of: ${validValues.join(", ")}`
1854
+ })
1855
+ });
1856
+ }
1857
+ function createMultiselectValidator(attr) {
1858
+ const validValues = attr.options.map((opt) => opt.value);
1859
+ return z3.array(
1860
+ z3.enum(validValues, {
1861
+ errorMap: () => ({
1862
+ message: `Each value must be one of: ${validValues.join(", ")}`
1863
+ })
1864
+ })
1865
+ );
1866
+ }
1867
+ function createLocationValidator(_attr) {
1868
+ return z3.object({
1869
+ address: z3.string().optional(),
1870
+ address2: z3.string().optional(),
1871
+ city: z3.string().optional(),
1872
+ state: z3.string().optional(),
1873
+ postalCode: z3.string().optional(),
1874
+ country: z3.string().length(3).optional(),
1875
+ latitude: z3.number().optional(),
1876
+ longitude: z3.number().optional()
1877
+ });
1878
+ }
1879
+ function createTimestampValidator(_attr) {
1880
+ return z3.number().int().positive();
1881
+ }
1882
+ function createFileValidator(_attr) {
1883
+ return z3.string().uuid();
1884
+ }
1885
+ function createUserValidator(_attr) {
1886
+ return z3.string().uuid();
1887
+ }
1888
+ function createRelationValidator(_attr) {
1889
+ return z3.string().uuid();
1890
+ }
1891
+ function createRatingValidator(attr) {
1892
+ let schema = z3.number().int().min(0);
1893
+ if (attr.max !== void 0) {
1894
+ schema = schema.max(attr.max, `${attr.label} must be at most ${attr.max}`);
1895
+ }
1896
+ return schema;
1897
+ }
1898
+ function createAttributeValidator(attr) {
1899
+ switch (attr.type) {
1900
+ case "text":
1901
+ return createTextValidator(attr);
1902
+ case "number":
1903
+ return createNumberValidator(attr);
1904
+ case "checkbox":
1905
+ return createCheckboxValidator(attr);
1906
+ case "date":
1907
+ return createDateValidator(attr);
1908
+ case "phone":
1909
+ return createPhoneValidator(attr);
1910
+ case "currency":
1911
+ return createCurrencyValidator(attr);
1912
+ case "status":
1913
+ return createStatusValidator(attr);
1914
+ case "location":
1915
+ return createLocationValidator(attr);
1916
+ case "timestamp":
1917
+ return createTimestampValidator(attr);
1918
+ case "select":
1919
+ return createSelectValidator(attr);
1920
+ case "multiselect":
1921
+ return createMultiselectValidator(attr);
1922
+ case "file":
1923
+ return createFileValidator(attr);
1924
+ case "user":
1925
+ return createUserValidator(attr);
1926
+ case "relation":
1927
+ return createRelationValidator(attr);
1928
+ case "rating":
1929
+ return createRatingValidator(attr);
1930
+ default:
1931
+ return z3.unknown();
1932
+ }
1933
+ }
1934
+ function createObjectValidator(objectDef) {
1935
+ const shape = {};
1936
+ for (const attr of objectDef.attributes) {
1937
+ let validator = createAttributeValidator(attr);
1938
+ if (!attr.required) {
1939
+ validator = validator.optional();
1940
+ }
1941
+ shape[attr.name] = validator;
1942
+ }
1943
+ return z3.object(shape);
1944
+ }
1945
+ function validateAttribute(attr, value) {
1946
+ const validator = createAttributeValidator(attr);
1947
+ if (!attr.required && (value === void 0 || value === null)) {
1948
+ return { success: true, data: { [attr.name]: value } };
1949
+ }
1950
+ const result = validator.safeParse(value);
1951
+ if (result.success) {
1952
+ return {
1953
+ success: true,
1954
+ data: { [attr.name]: result.data }
1955
+ };
1956
+ }
1957
+ return {
1958
+ success: false,
1959
+ errors: result.error.errors.map((err) => ({
1960
+ path: [attr.name, ...err.path.map(String)],
1961
+ message: err.message
1962
+ }))
1963
+ };
1964
+ }
1965
+ function validateObject(objectDef, data) {
1966
+ const validator = createObjectValidator(objectDef);
1967
+ const result = validator.safeParse(data);
1968
+ if (result.success) {
1969
+ return {
1970
+ success: true,
1971
+ data: result.data
1972
+ };
1973
+ }
1974
+ return {
1975
+ success: false,
1976
+ errors: result.error.errors.map((err) => ({
1977
+ path: err.path.map(String),
1978
+ message: err.message
1979
+ }))
1980
+ };
1981
+ }
1982
+ function validateObjectOrThrow(objectDef, data) {
1983
+ const result = validateObject(objectDef, data);
1984
+ if (!result.success) {
1985
+ const errorMessages = result.errors?.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
1986
+ throw new Error(`Validation failed for ${objectDef.label}:
1987
+ ${errorMessages}`);
1988
+ }
1989
+ return result.data;
1990
+ }
1991
+
1992
+ // src/runtime/services/record.service.ts
1993
+ var RecordService = class {
1994
+ constructor(adapter, tenantId) {
1995
+ this.adapter = adapter;
1996
+ this.tenantId = tenantId;
1997
+ this.schemaService = new ObjectSchemaService(adapter, registry);
1998
+ }
1999
+ /**
2000
+ * Create a new record with validation
2001
+ *
2002
+ * @param objectId - Object UUID
2003
+ * @param data - Record data (attribute values)
2004
+ * @param options - Creation options
2005
+ * @returns Created record
2006
+ *
2007
+ * @example
2008
+ * ```typescript
2009
+ * const service = new RecordService(adapter, "tenant-123");
2010
+ *
2011
+ * const product = await service.createRecord("obj-product", {
2012
+ * name: "Nike Air Max",
2013
+ * price: 129.99,
2014
+ * sku: "NIKE-AM-001"
2015
+ * });
2016
+ * ```
2017
+ */
2018
+ async createRecord(objectId, data, options) {
2019
+ const schema = await this.schemaService.getObjectSchema(objectId);
2020
+ if (options?.validate !== false) {
2021
+ validateObjectOrThrow(schema, data);
2022
+ }
2023
+ const record = await this.adapter.objectRecords.create({
2024
+ tenantId: this.tenantId,
2025
+ objectId,
2026
+ data
2027
+ });
2028
+ return record;
2029
+ }
2030
+ /**
2031
+ * Get a record by ID
2032
+ *
2033
+ * @param recordId - Record UUID
2034
+ * @param options - Query options
2035
+ * @returns Record or null if not found
2036
+ */
2037
+ async getRecord(recordId, options) {
2038
+ const record = await this.adapter.objectRecords.findById(recordId);
2039
+ if (!record) {
2040
+ return null;
2041
+ }
2042
+ if (options?.includeSchema) {
2043
+ const schema = await this.schemaService.getObjectSchema(record.objectId);
2044
+ const recordWithSchema = record;
2045
+ recordWithSchema.schema = schema;
2046
+ return recordWithSchema;
2047
+ }
2048
+ return record;
2049
+ }
2050
+ /**
2051
+ * Get a record by ID or throw if not found
2052
+ */
2053
+ async getRecordOrThrow(recordId) {
2054
+ const record = await this.getRecord(recordId);
2055
+ if (!record) {
2056
+ throw new Error(`Record with id "${recordId}" not found`);
2057
+ }
2058
+ return record;
2059
+ }
2060
+ /**
2061
+ * Update a record with validation
2062
+ *
2063
+ * @param recordId - Record UUID
2064
+ * @param data - Partial data to update
2065
+ * @param options - Update options
2066
+ * @returns Updated record
2067
+ */
2068
+ async updateRecord(recordId, data, options) {
2069
+ const existing = await this.getRecordOrThrow(recordId);
2070
+ const schema = await this.schemaService.getObjectSchema(existing.objectId);
2071
+ const mergedData = { ...existing.values, ...data };
2072
+ if (options?.validate !== false && !options?.partial) {
2073
+ validateObjectOrThrow(schema, mergedData);
2074
+ }
2075
+ const updated = await this.adapter.objectRecords.update(recordId, data);
2076
+ return updated;
2077
+ }
2078
+ /**
2079
+ * Delete a record
2080
+ *
2081
+ * @param recordId - Record UUID
2082
+ * @param options - Delete options
2083
+ */
2084
+ async deleteRecord(recordId, options) {
2085
+ if (options?.checkSystem) {
2086
+ const record = await this.getRecordOrThrow(recordId);
2087
+ const schema = await this.schemaService.getObjectSchema(record.objectId);
2088
+ if (schema.system) {
2089
+ throw new Error(`Cannot delete record of system object "${schema.label}"`);
2090
+ }
2091
+ }
2092
+ await this.adapter.objectRecords.delete(recordId);
2093
+ }
2094
+ /**
2095
+ * List records for an object with pagination
2096
+ *
2097
+ * @param objectId - Object UUID
2098
+ * @param options - List options
2099
+ * @returns Records and total count
2100
+ */
2101
+ async listRecords(objectId, options) {
2102
+ return await this.adapter.objectRecords.list(this.tenantId, objectId, options);
2103
+ }
2104
+ /**
2105
+ * Search records using full-text search
2106
+ *
2107
+ * @param objectId - Object UUID
2108
+ * @param query - Search query
2109
+ * @param options - Search options
2110
+ * @returns Matching records and total count
2111
+ */
2112
+ async searchRecords(objectId, query, options) {
2113
+ return await this.adapter.objectRecords.search(this.tenantId, objectId, query, options);
2114
+ }
2115
+ /**
2116
+ * Validate data against object schema without saving
2117
+ *
2118
+ * @param objectId - Object UUID
2119
+ * @param data - Data to validate
2120
+ * @returns Validation result
2121
+ */
2122
+ async validateData(objectId, data) {
2123
+ const schema = await this.schemaService.getObjectSchema(objectId);
2124
+ return validateObject(schema, data);
2125
+ }
2126
+ };
2127
+
2128
+ // src/runtime/services/user-profile.service.ts
2129
+ var UserProfileService = class {
2130
+ constructor(adapter, tenantId) {
2131
+ this.adapter = adapter;
2132
+ this.tenantId = tenantId;
2133
+ }
2134
+ /**
2135
+ * Create a new user profile (typically after first auth)
2136
+ *
2137
+ * @param data - User profile creation data
2138
+ * @returns Created user profile
2139
+ *
2140
+ * @example
2141
+ * ```typescript
2142
+ * const service = new UserProfileService(adapter, "tenant-123");
2143
+ *
2144
+ * // After Supabase auth
2145
+ * const profile = await service.createProfile({
2146
+ * tenantId: "tenant-123",
2147
+ * authId: authUser.id,
2148
+ * email: authUser.email,
2149
+ * firstName: authUser.user_metadata.first_name,
2150
+ * lastName: authUser.user_metadata.last_name,
2151
+ * role: "member",
2152
+ * status: "active"
2153
+ * });
2154
+ * ```
2155
+ */
2156
+ async createProfile(data) {
2157
+ if (data.tenantId !== this.tenantId) {
2158
+ throw new Error(
2159
+ `Tenant mismatch: service initialized with "${this.tenantId}" but data has "${data.tenantId}"`
2160
+ );
2161
+ }
2162
+ const existing = await this.adapter.userProfiles.findByAuthId(data.authId);
2163
+ if (existing) {
2164
+ throw new Error(`User profile with authId "${data.authId}" already exists`);
2165
+ }
2166
+ const existingEmail = await this.adapter.userProfiles.findByEmail(this.tenantId, data.email);
2167
+ if (existingEmail) {
2168
+ throw new Error(`User profile with email "${data.email}" already exists in this tenant`);
2169
+ }
2170
+ return await this.adapter.userProfiles.create(data);
2171
+ }
2172
+ /**
2173
+ * Get user profile by ID
2174
+ */
2175
+ async getProfile(profileId) {
2176
+ return await this.adapter.userProfiles.findById(profileId);
2177
+ }
2178
+ /**
2179
+ * Get user profile by ID or throw
2180
+ */
2181
+ async getProfileOrThrow(profileId) {
2182
+ const profile = await this.getProfile(profileId);
2183
+ if (!profile) {
2184
+ throw new Error(`User profile with id "${profileId}" not found`);
2185
+ }
2186
+ return profile;
2187
+ }
2188
+ /**
2189
+ * Get user profile by auth provider ID
2190
+ *
2191
+ * @param authId - Auth provider user ID (Supabase, Clerk, etc.)
2192
+ * @returns User profile or null
2193
+ */
2194
+ async getProfileByAuthId(authId) {
2195
+ return await this.adapter.userProfiles.findByAuthId(authId);
2196
+ }
2197
+ /**
2198
+ * Get or create user profile (idempotent operation)
2199
+ * Useful for auth callbacks - ensures profile exists
2200
+ *
2201
+ * @param authId - Auth provider user ID
2202
+ * @param data - Profile data to create if doesn't exist
2203
+ * @returns Existing or newly created profile
2204
+ *
2205
+ * @example
2206
+ * ```typescript
2207
+ * // In Supabase auth callback
2208
+ * const profile = await service.getOrCreateProfile(
2209
+ * authUser.id,
2210
+ * {
2211
+ * tenantId: "tenant-123",
2212
+ * authId: authUser.id,
2213
+ * email: authUser.email,
2214
+ * role: "member",
2215
+ * status: "active"
2216
+ * }
2217
+ * );
2218
+ * ```
2219
+ */
2220
+ async getOrCreateProfile(authId, data) {
2221
+ const existing = await this.getProfileByAuthId(authId);
2222
+ if (existing) {
2223
+ return existing;
2224
+ }
2225
+ return await this.createProfile(data);
2226
+ }
2227
+ /**
2228
+ * Update user profile
2229
+ */
2230
+ async updateProfile(profileId, data) {
2231
+ await this.getProfileOrThrow(profileId);
2232
+ return await this.adapter.userProfiles.update(profileId, data);
2233
+ }
2234
+ /**
2235
+ * Delete user profile
2236
+ *
2237
+ * @param profileId - Profile UUID
2238
+ * @param options - Delete options
2239
+ */
2240
+ async deleteProfile(profileId, options) {
2241
+ if (options?.checkAdmin) {
2242
+ const profile = await this.getProfileOrThrow(profileId);
2243
+ if (profile.role === "admin") {
2244
+ const allProfiles = await this.listProfiles();
2245
+ const adminCount = allProfiles.filter((p) => p.role === "admin").length;
2246
+ if (adminCount <= 1) {
2247
+ throw new Error("Cannot delete the last admin user");
2248
+ }
2249
+ }
2250
+ }
2251
+ await this.adapter.userProfiles.delete(profileId);
2252
+ }
2253
+ /**
2254
+ * List all user profiles for the tenant
2255
+ */
2256
+ async listProfiles(options) {
2257
+ return await this.adapter.userProfiles.list(this.tenantId, options);
2258
+ }
2259
+ /**
2260
+ * Update last login timestamp
2261
+ *
2262
+ * @param profileId - Profile UUID
2263
+ *
2264
+ * @example
2265
+ * ```typescript
2266
+ * // After successful auth
2267
+ * await service.updateLastLogin(profile.id);
2268
+ * ```
2269
+ */
2270
+ async updateLastLogin(profileId) {
2271
+ await this.adapter.userProfiles.updateLastLogin(profileId);
2272
+ }
2273
+ /**
2274
+ * Change user role
2275
+ *
2276
+ * @param profileId - Profile UUID
2277
+ * @param newRole - New role
2278
+ */
2279
+ async changeRole(profileId, newRole) {
2280
+ return await this.updateProfile(profileId, { role: newRole });
2281
+ }
2282
+ /**
2283
+ * Change user status
2284
+ *
2285
+ * @param profileId - Profile UUID
2286
+ * @param newStatus - New status
2287
+ */
2288
+ async changeStatus(profileId, newStatus) {
2289
+ return await this.updateProfile(profileId, { status: newStatus });
2290
+ }
2291
+ /**
2292
+ * Get user by email
2293
+ */
2294
+ async getProfileByEmail(email) {
2295
+ return await this.adapter.userProfiles.findByEmail(this.tenantId, email);
2296
+ }
2297
+ /**
2298
+ * Check if user has role
2299
+ */
2300
+ async hasRole(profileId, role) {
2301
+ const profile = await this.getProfile(profileId);
2302
+ return profile?.role === role;
2303
+ }
2304
+ /**
2305
+ * Check if user is admin
2306
+ */
2307
+ async isAdmin(profileId) {
2308
+ return await this.hasRole(profileId, "admin");
2309
+ }
2310
+ };
2311
+
2312
+ // src/runtime/sync.ts
2313
+ var BASE_ATTRIBUTE_KEYS = /* @__PURE__ */ new Set([
2314
+ "id",
2315
+ "name",
2316
+ "label",
2317
+ "type",
2318
+ "required",
2319
+ "system",
2320
+ "unique",
2321
+ "order"
2322
+ ]);
2323
+ function extractAttributeConfig(attr) {
2324
+ return Object.fromEntries(
2325
+ Object.entries(attr).filter(
2326
+ ([key, value]) => !BASE_ATTRIBUTE_KEYS.has(key) && value !== void 0
2327
+ )
2328
+ );
2329
+ }
2330
+ async function syncNativeObjects(adapter, nativeRegistry, options = {}) {
2331
+ const result = {
2332
+ success: true,
2333
+ objectsSynced: 0,
2334
+ attributesSynced: 0,
2335
+ objectsCreated: 0,
2336
+ objectsUpdated: 0,
2337
+ attributesCreated: 0,
2338
+ attributesUpdated: 0,
2339
+ attributesDeleted: 0,
2340
+ errors: []
2341
+ };
2342
+ const nativeObjects = nativeRegistry.getAll();
2343
+ if (options.verbose) {
2344
+ console.info(`[SyncService] Starting sync for ${nativeObjects.length} native objects...`);
2345
+ }
2346
+ try {
2347
+ await adapter.transaction(async (tx) => {
2348
+ for (const nativeObject of nativeObjects) {
2349
+ try {
2350
+ await syncSingleObject(tx, nativeObject, result, options);
2351
+ } catch (error) {
2352
+ result.success = false;
2353
+ result.errors.push({
2354
+ objectName: nativeObject.name,
2355
+ error: error instanceof Error ? error.message : String(error)
2356
+ });
2357
+ if (options.verbose) {
2358
+ console.error(`[SyncService] \u2717 Failed to sync ${nativeObject.name}:`, error);
2359
+ }
2360
+ }
2361
+ }
2362
+ });
2363
+ } catch (error) {
2364
+ result.success = false;
2365
+ result.errors.push({
2366
+ objectName: "transaction",
2367
+ error: error instanceof Error ? error.message : String(error)
2368
+ });
2369
+ }
2370
+ if (options.verbose) {
2371
+ console.info(
2372
+ `[SyncService] ${result.success ? "\u2713" : "\u2717"} Sync complete:
2373
+ Objects: ${result.objectsCreated} created, ${result.objectsUpdated} updated
2374
+ Attributes: ${result.attributesCreated} created, ${result.attributesUpdated} updated, ${result.attributesDeleted} deleted
2375
+ Errors: ${result.errors.length}`
2376
+ );
2377
+ }
2378
+ return result;
2379
+ }
2380
+ async function syncSingleObject(adapter, nativeObject, result, options) {
2381
+ if (!nativeObject.system) {
2382
+ throw new Error(`Object ${nativeObject.name} is not marked as system`);
2383
+ }
2384
+ const existingObject = await adapter.objects.findSystemByName(nativeObject.name);
2385
+ const isNew = !existingObject;
2386
+ updateObjectStats(result, isNew);
2387
+ if (options.dryRun) {
2388
+ await handleDryRun(adapter, nativeObject, existingObject, result, options, isNew);
2389
+ return;
2390
+ }
2391
+ const dbObject = await upsertObject(adapter, nativeObject, options);
2392
+ await syncAttributes(adapter, nativeObject, dbObject, existingObject, result);
2393
+ if (!isNew) {
2394
+ await cleanupAttributes(adapter, dbObject.id, nativeObject, result);
2395
+ }
2396
+ logSyncSuccess(nativeObject, options);
2397
+ }
2398
+ function updateObjectStats(result, isNew) {
2399
+ if (isNew) {
2400
+ result.objectsCreated++;
2401
+ } else {
2402
+ result.objectsUpdated++;
2403
+ }
2404
+ result.objectsSynced++;
2405
+ }
2406
+ async function handleDryRun(adapter, nativeObject, existingObject, result, options, isNew) {
2407
+ if (options.verbose) {
2408
+ console.info(`[SyncService] Would ${isNew ? "create" : "update"} object: ${nativeObject.name}`);
2409
+ }
2410
+ for (const attr of nativeObject.attributes) {
2411
+ const existingAttr = existingObject ? await adapter.attributes.findByObjectId(existingObject.id).then((attrs) => attrs.find((a) => a.name === attr.name)) : null;
2412
+ if (existingAttr) {
2413
+ result.attributesUpdated++;
2414
+ } else {
2415
+ result.attributesCreated++;
2416
+ }
2417
+ result.attributesSynced++;
2418
+ }
2419
+ }
2420
+ async function upsertObject(adapter, nativeObject, options) {
2421
+ return await adapter.objects.upsert({
2422
+ tenantId: options.tenantId || "default",
2423
+ system: true,
2424
+ name: nativeObject.name,
2425
+ label: nativeObject.label,
2426
+ description: nativeObject.description,
2427
+ metadata: nativeObject.metadata
2428
+ });
2429
+ }
2430
+ async function syncAttributes(adapter, nativeObject, dbObject, existingObject, result) {
2431
+ for (const [index, attr] of nativeObject.attributes.entries()) {
2432
+ const existingAttr = existingObject ? await adapter.attributes.findByObjectId(dbObject.id).then((attrs) => attrs.find((a) => a.name === attr.name)) : null;
2433
+ await adapter.attributes.upsert({
2434
+ objectId: dbObject.id,
2435
+ name: attr.name,
2436
+ label: attr.label,
2437
+ type: attr.type,
2438
+ description: attr.description,
2439
+ icon: attr.icon,
2440
+ system: attr.system ?? true,
2441
+ required: attr.required ?? false,
2442
+ order: attr.order ?? index,
2443
+ hidden: attr.hidden,
2444
+ archived: attr.archived,
2445
+ deprecated: attr.deprecated,
2446
+ defaultValue: attr.defaultValue,
2447
+ config: extractAttributeConfig(attr)
2448
+ });
2449
+ if (existingAttr) {
2450
+ result.attributesUpdated++;
2451
+ } else {
2452
+ result.attributesCreated++;
2453
+ }
2454
+ result.attributesSynced++;
2455
+ }
2456
+ }
2457
+ async function cleanupAttributes(adapter, objectId, nativeObject, result) {
2458
+ const attributeNames = nativeObject.attributes.map((attr) => attr.name);
2459
+ const deletedCount = await adapter.attributes.deleteByNames(objectId, attributeNames);
2460
+ result.attributesDeleted += deletedCount;
2461
+ }
2462
+ function logSyncSuccess(nativeObject, options) {
2463
+ if (options.verbose) {
2464
+ console.info(
2465
+ `[SyncService] \u2713 Synced ${nativeObject.name}: ${nativeObject.attributes.length} attributes`
2466
+ );
2467
+ }
2468
+ }
2469
+ async function verifyNativeObjectsSync(adapter, nativeRegistry) {
2470
+ const nativeObjects = nativeRegistry.getAll();
2471
+ for (const obj of nativeObjects) {
2472
+ if (!obj.system) continue;
2473
+ const existing = await adapter.objects.findSystemByName(obj.name);
2474
+ if (!existing) {
2475
+ return false;
2476
+ }
2477
+ }
2478
+ return true;
2479
+ }
2480
+ async function getSyncPreview(adapter, nativeRegistry) {
2481
+ return await syncNativeObjects(adapter, nativeRegistry, { dryRun: true });
2482
+ }
2483
+
2484
+ export {
2485
+ generateId,
2486
+ generatePrefixedId,
2487
+ text,
2488
+ textarea,
2489
+ number,
2490
+ checkbox,
2491
+ date,
2492
+ phone,
2493
+ currency,
2494
+ status,
2495
+ select,
2496
+ multiselect,
2497
+ location,
2498
+ timestamp,
2499
+ file,
2500
+ user,
2501
+ relation,
2502
+ rating,
2503
+ ObjectBuilder,
2504
+ object,
2505
+ registry,
2506
+ createTextValidator,
2507
+ createNumberValidator,
2508
+ createCheckboxValidator,
2509
+ createDateValidator,
2510
+ createPhoneValidator,
2511
+ createCurrencyValidator,
2512
+ createStatusValidator,
2513
+ createSelectValidator,
2514
+ createMultiselectValidator,
2515
+ createLocationValidator,
2516
+ createTimestampValidator,
2517
+ createFileValidator,
2518
+ createUserValidator,
2519
+ createRelationValidator,
2520
+ createRatingValidator,
2521
+ createAttributeValidator,
2522
+ createObjectValidator,
2523
+ validateAttribute,
2524
+ validateObject,
2525
+ validateObjectOrThrow,
2526
+ createMockAdapter,
2527
+ FileService,
2528
+ ObjectSchemaService,
2529
+ RecordService,
2530
+ UserProfileService,
2531
+ syncNativeObjects,
2532
+ verifyNativeObjectsSync,
2533
+ getSyncPreview
2534
+ };