@tailor-platform/sdk 1.4.2 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,801 @@
1
+ //#region src/configure/types/brand.ts
2
+ /**
3
+ * Symbol brands for type identification.
4
+ * These symbols are used to reliably identify SDK objects
5
+ * without relying on instanceof checks or property shape detection.
6
+ */
7
+ /** Brand symbol for TailorField instances */
8
+ const TAILOR_FIELD_BRAND = Symbol.for("@tailor-platform/sdk/TailorField");
9
+ /** Brand symbol for TailorDBField instances */
10
+ const TAILOR_DB_FIELD_BRAND = Symbol.for("@tailor-platform/sdk/TailorDBField");
11
+ /** Brand symbol for TailorDBType instances */
12
+ const TAILOR_DB_TYPE_BRAND = Symbol.for("@tailor-platform/sdk/TailorDBType");
13
+
14
+ //#endregion
15
+ //#region src/configure/types/field.ts
16
+ /**
17
+ * Normalize allowed values into EnumValue objects with descriptions.
18
+ * @param values - Allowed values as strings or EnumValue objects
19
+ * @returns Normalized allowed values
20
+ */
21
+ function mapAllowedValues(values) {
22
+ return values.map((value) => {
23
+ if (typeof value === "string") return {
24
+ value,
25
+ description: ""
26
+ };
27
+ return {
28
+ ...value,
29
+ description: value.description ?? ""
30
+ };
31
+ });
32
+ }
33
+
34
+ //#endregion
35
+ //#region src/configure/types/type.ts
36
+ const regex$1 = {
37
+ uuid: /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
38
+ date: /^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$/,
39
+ time: /^(?<hour>\d{2}):(?<minute>\d{2})$/,
40
+ datetime: /^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})T(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})(.(?<millisec>\d{3}))?Z$/
41
+ };
42
+ /**
43
+ * Creates a new TailorField instance.
44
+ * @param type - Field type
45
+ * @param options - Field options
46
+ * @param fields - Nested fields for object-like types
47
+ * @param values - Allowed values for enum-like fields
48
+ * @returns A new TailorField
49
+ */
50
+ function createTailorField(type, options, fields, values) {
51
+ const _metadata = { required: true };
52
+ if (options) {
53
+ if (options.optional === true) _metadata.required = false;
54
+ if (options.array === true) _metadata.array = true;
55
+ }
56
+ if (values) _metadata.allowedValues = mapAllowedValues(values);
57
+ /**
58
+ * Validate a single value (not an array element)
59
+ * Used internally for array element validation
60
+ * @param args - Value, context data, and user
61
+ * @returns Array of validation issues
62
+ */
63
+ function validateValue(args) {
64
+ const { value, data, user, pathArray } = args;
65
+ const issues = [];
66
+ switch (type) {
67
+ case "string":
68
+ if (typeof value !== "string") issues.push({
69
+ message: `Expected a string: received ${String(value)}`,
70
+ path: pathArray.length > 0 ? pathArray : void 0
71
+ });
72
+ break;
73
+ case "integer":
74
+ if (typeof value !== "number" || !Number.isInteger(value)) issues.push({
75
+ message: `Expected an integer: received ${String(value)}`,
76
+ path: pathArray.length > 0 ? pathArray : void 0
77
+ });
78
+ break;
79
+ case "float":
80
+ if (typeof value !== "number" || !Number.isFinite(value)) issues.push({
81
+ message: `Expected a number: received ${String(value)}`,
82
+ path: pathArray.length > 0 ? pathArray : void 0
83
+ });
84
+ break;
85
+ case "boolean":
86
+ if (typeof value !== "boolean") issues.push({
87
+ message: `Expected a boolean: received ${String(value)}`,
88
+ path: pathArray.length > 0 ? pathArray : void 0
89
+ });
90
+ break;
91
+ case "uuid":
92
+ if (typeof value !== "string" || !regex$1.uuid.test(value)) issues.push({
93
+ message: `Expected a valid UUID: received ${String(value)}`,
94
+ path: pathArray.length > 0 ? pathArray : void 0
95
+ });
96
+ break;
97
+ case "date":
98
+ if (typeof value !== "string" || !regex$1.date.test(value)) issues.push({
99
+ message: `Expected to match "yyyy-MM-dd" format: received ${String(value)}`,
100
+ path: pathArray.length > 0 ? pathArray : void 0
101
+ });
102
+ break;
103
+ case "datetime":
104
+ if (typeof value !== "string" || !regex$1.datetime.test(value)) issues.push({
105
+ message: `Expected to match ISO format: received ${String(value)}`,
106
+ path: pathArray.length > 0 ? pathArray : void 0
107
+ });
108
+ break;
109
+ case "time":
110
+ if (typeof value !== "string" || !regex$1.time.test(value)) issues.push({
111
+ message: `Expected to match "HH:mm" format: received ${String(value)}`,
112
+ path: pathArray.length > 0 ? pathArray : void 0
113
+ });
114
+ break;
115
+ case "enum":
116
+ if (field._metadata.allowedValues) {
117
+ const allowedValues = field._metadata.allowedValues.map((v) => v.value);
118
+ if (typeof value !== "string" || !allowedValues.includes(value)) issues.push({
119
+ message: `Must be one of [${allowedValues.join(", ")}]: received ${String(value)}`,
120
+ path: pathArray.length > 0 ? pathArray : void 0
121
+ });
122
+ }
123
+ break;
124
+ case "nested":
125
+ if (typeof value !== "object" || value === null || Array.isArray(value) || value instanceof Date) issues.push({
126
+ message: `Expected an object: received ${String(value)}`,
127
+ path: pathArray.length > 0 ? pathArray : void 0
128
+ });
129
+ else if (field.fields && Object.keys(field.fields).length > 0) for (const [fieldName, nestedField] of Object.entries(field.fields)) {
130
+ const fieldValue = value?.[fieldName];
131
+ const result = nestedField._parseInternal({
132
+ value: fieldValue,
133
+ data,
134
+ user,
135
+ pathArray: pathArray.concat(fieldName)
136
+ });
137
+ if (result.issues) issues.push(...result.issues);
138
+ }
139
+ break;
140
+ }
141
+ const validateFns = field._metadata.validate;
142
+ if (validateFns && validateFns.length > 0) for (const validateInput of validateFns) {
143
+ const { fn, message } = typeof validateInput === "function" ? {
144
+ fn: validateInput,
145
+ message: "Validation failed"
146
+ } : {
147
+ fn: validateInput[0],
148
+ message: validateInput[1]
149
+ };
150
+ if (!fn({
151
+ value,
152
+ data,
153
+ user
154
+ })) issues.push({
155
+ message,
156
+ path: pathArray.length > 0 ? pathArray : void 0
157
+ });
158
+ }
159
+ return issues;
160
+ }
161
+ /**
162
+ * Internal parse method that tracks field path for nested validation
163
+ * @param args - Parse arguments
164
+ * @returns Parse result with value or issues
165
+ */
166
+ function parseInternal(args) {
167
+ const { value, data, user, pathArray } = args;
168
+ const issues = [];
169
+ const isNullOrUndefined = value === null || value === void 0;
170
+ if (field._metadata.required && isNullOrUndefined) {
171
+ issues.push({
172
+ message: "Required field is missing",
173
+ path: pathArray.length > 0 ? pathArray : void 0
174
+ });
175
+ return { issues };
176
+ }
177
+ if (!field._metadata.required && isNullOrUndefined) return { value: value ?? null };
178
+ if (field._metadata.array) {
179
+ if (!Array.isArray(value)) {
180
+ issues.push({
181
+ message: "Expected an array",
182
+ path: pathArray.length > 0 ? pathArray : void 0
183
+ });
184
+ return { issues };
185
+ }
186
+ for (let i = 0; i < value.length; i++) {
187
+ const elementValue = value[i];
188
+ const elementIssues = validateValue({
189
+ value: elementValue,
190
+ data,
191
+ user,
192
+ pathArray: pathArray.concat(`[${i}]`)
193
+ });
194
+ if (elementIssues.length > 0) issues.push(...elementIssues);
195
+ }
196
+ if (issues.length > 0) return { issues };
197
+ return { value };
198
+ }
199
+ const valueIssues = validateValue({
200
+ value,
201
+ data,
202
+ user,
203
+ pathArray
204
+ });
205
+ issues.push(...valueIssues);
206
+ if (issues.length > 0) return { issues };
207
+ return { value };
208
+ }
209
+ const field = {
210
+ [TAILOR_FIELD_BRAND]: true,
211
+ type,
212
+ fields: fields ?? {},
213
+ _defined: void 0,
214
+ _output: void 0,
215
+ _metadata,
216
+ get metadata() {
217
+ return { ...this._metadata };
218
+ },
219
+ description(description) {
220
+ this._metadata.description = description;
221
+ return this;
222
+ },
223
+ typeName(typeName) {
224
+ this._metadata.typeName = typeName;
225
+ return this;
226
+ },
227
+ validate(...validateInputs) {
228
+ this._metadata.validate = validateInputs;
229
+ return this;
230
+ },
231
+ parse(args) {
232
+ return parseInternal({
233
+ value: args.value,
234
+ data: args.data,
235
+ user: args.user,
236
+ pathArray: []
237
+ });
238
+ },
239
+ _parseInternal: parseInternal
240
+ };
241
+ return field;
242
+ }
243
+ function uuid$1(options) {
244
+ return createTailorField("uuid", options);
245
+ }
246
+ function string$1(options) {
247
+ return createTailorField("string", options);
248
+ }
249
+ function bool$1(options) {
250
+ return createTailorField("boolean", options);
251
+ }
252
+ function int$1(options) {
253
+ return createTailorField("integer", options);
254
+ }
255
+ function float$1(options) {
256
+ return createTailorField("float", options);
257
+ }
258
+ function date$1(options) {
259
+ return createTailorField("date", options);
260
+ }
261
+ function datetime$1(options) {
262
+ return createTailorField("datetime", options);
263
+ }
264
+ function time$1(options) {
265
+ return createTailorField("time", options);
266
+ }
267
+ function _enum$1(values, options) {
268
+ return createTailorField("enum", options, void 0, values);
269
+ }
270
+ function object$1(fields, options) {
271
+ return createTailorField("nested", options, fields);
272
+ }
273
+ const t = {
274
+ uuid: uuid$1,
275
+ string: string$1,
276
+ bool: bool$1,
277
+ int: int$1,
278
+ float: float$1,
279
+ date: date$1,
280
+ datetime: datetime$1,
281
+ time: time$1,
282
+ enum: _enum$1,
283
+ object: object$1
284
+ };
285
+
286
+ //#endregion
287
+ //#region src/configure/types/user.ts
288
+ /** Represents an unauthenticated user in the Tailor platform. */
289
+ const unauthenticatedTailorUser = {
290
+ id: "00000000-0000-0000-0000-000000000000",
291
+ type: "",
292
+ workspaceId: "00000000-0000-0000-0000-000000000000",
293
+ attributes: null,
294
+ attributeList: []
295
+ };
296
+
297
+ //#endregion
298
+ //#region src/configure/services/tailordb/permission.ts
299
+ /**
300
+ * Grants full record-level access without any conditions.
301
+ *
302
+ * Unsafe and intended only for local development, prototyping, or tests.
303
+ * Do not use this in production environments, as it effectively disables
304
+ * authorization checks.
305
+ */
306
+ const unsafeAllowAllTypePermission = {
307
+ create: [{
308
+ conditions: [],
309
+ permit: true
310
+ }],
311
+ read: [{
312
+ conditions: [],
313
+ permit: true
314
+ }],
315
+ update: [{
316
+ conditions: [],
317
+ permit: true
318
+ }],
319
+ delete: [{
320
+ conditions: [],
321
+ permit: true
322
+ }]
323
+ };
324
+ /**
325
+ * Grants full GraphQL access (all actions) without any conditions.
326
+ *
327
+ * Unsafe and intended only for local development, prototyping, or tests.
328
+ * Do not use this in production environments, as it effectively disables
329
+ * authorization checks.
330
+ */
331
+ const unsafeAllowAllGqlPermission = [{
332
+ conditions: [],
333
+ actions: "all",
334
+ permit: true
335
+ }];
336
+
337
+ //#endregion
338
+ //#region src/configure/services/tailordb/schema.ts
339
+ function isRelationSelfConfig(config) {
340
+ return config.toward.type === "self";
341
+ }
342
+ const regex = {
343
+ uuid: /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
344
+ date: /^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$/,
345
+ time: /^(?<hour>\d{2}):(?<minute>\d{2})$/,
346
+ datetime: /^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})T(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})(.(?<millisec>\d{3}))?Z$/
347
+ };
348
+ /**
349
+ * Creates a new TailorDBField instance.
350
+ * @param type - Field type
351
+ * @param options - Field options
352
+ * @param fields - Nested fields for object-like types
353
+ * @param values - Allowed values for enum-like fields
354
+ * @returns A new TailorDBField
355
+ */
356
+ function createTailorDBField(type, options, fields, values) {
357
+ const _metadata = { required: true };
358
+ let _rawRelation;
359
+ if (options) {
360
+ if (options.optional === true) _metadata.required = false;
361
+ if (options.array === true) _metadata.array = true;
362
+ }
363
+ if (values) _metadata.allowedValues = mapAllowedValues(values);
364
+ /**
365
+ * Validate a single value (not an array element)
366
+ * Used internally for array element validation
367
+ * @param args - Value, context data, and user
368
+ * @returns Array of validation issues
369
+ */
370
+ function validateValue(args) {
371
+ const { value, data, user, pathArray } = args;
372
+ const issues = [];
373
+ switch (type) {
374
+ case "string":
375
+ if (typeof value !== "string") issues.push({
376
+ message: `Expected a string: received ${String(value)}`,
377
+ path: pathArray.length > 0 ? pathArray : void 0
378
+ });
379
+ break;
380
+ case "integer":
381
+ if (typeof value !== "number" || !Number.isInteger(value)) issues.push({
382
+ message: `Expected an integer: received ${String(value)}`,
383
+ path: pathArray.length > 0 ? pathArray : void 0
384
+ });
385
+ break;
386
+ case "float":
387
+ if (typeof value !== "number" || !Number.isFinite(value)) issues.push({
388
+ message: `Expected a number: received ${String(value)}`,
389
+ path: pathArray.length > 0 ? pathArray : void 0
390
+ });
391
+ break;
392
+ case "boolean":
393
+ if (typeof value !== "boolean") issues.push({
394
+ message: `Expected a boolean: received ${String(value)}`,
395
+ path: pathArray.length > 0 ? pathArray : void 0
396
+ });
397
+ break;
398
+ case "uuid":
399
+ if (typeof value !== "string" || !regex.uuid.test(value)) issues.push({
400
+ message: `Expected a valid UUID: received ${String(value)}`,
401
+ path: pathArray.length > 0 ? pathArray : void 0
402
+ });
403
+ break;
404
+ case "date":
405
+ if (typeof value !== "string" || !regex.date.test(value)) issues.push({
406
+ message: `Expected to match "yyyy-MM-dd" format: received ${String(value)}`,
407
+ path: pathArray.length > 0 ? pathArray : void 0
408
+ });
409
+ break;
410
+ case "datetime":
411
+ if (typeof value !== "string" || !regex.datetime.test(value)) issues.push({
412
+ message: `Expected to match ISO format: received ${String(value)}`,
413
+ path: pathArray.length > 0 ? pathArray : void 0
414
+ });
415
+ break;
416
+ case "time":
417
+ if (typeof value !== "string" || !regex.time.test(value)) issues.push({
418
+ message: `Expected to match "HH:mm" format: received ${String(value)}`,
419
+ path: pathArray.length > 0 ? pathArray : void 0
420
+ });
421
+ break;
422
+ case "enum":
423
+ if (field._metadata.allowedValues) {
424
+ const allowedValues = field._metadata.allowedValues.map((v) => v.value);
425
+ if (typeof value !== "string" || !allowedValues.includes(value)) issues.push({
426
+ message: `Must be one of [${allowedValues.join(", ")}]: received ${String(value)}`,
427
+ path: pathArray.length > 0 ? pathArray : void 0
428
+ });
429
+ }
430
+ break;
431
+ case "nested":
432
+ if (typeof value !== "object" || value === null || Array.isArray(value) || value instanceof Date) issues.push({
433
+ message: `Expected an object: received ${String(value)}`,
434
+ path: pathArray.length > 0 ? pathArray : void 0
435
+ });
436
+ else if (field.fields && Object.keys(field.fields).length > 0) for (const [fieldName, nestedField] of Object.entries(field.fields)) {
437
+ const fieldValue = value?.[fieldName];
438
+ const result = nestedField._parseInternal({
439
+ value: fieldValue,
440
+ data,
441
+ user,
442
+ pathArray: pathArray.concat(fieldName)
443
+ });
444
+ if (result.issues) issues.push(...result.issues);
445
+ }
446
+ break;
447
+ }
448
+ const validateFns = field._metadata.validate;
449
+ if (validateFns && validateFns.length > 0) for (const validateInput of validateFns) {
450
+ const { fn, message } = typeof validateInput === "function" ? {
451
+ fn: validateInput,
452
+ message: "Validation failed"
453
+ } : {
454
+ fn: validateInput[0],
455
+ message: validateInput[1]
456
+ };
457
+ if (!fn({
458
+ value,
459
+ data,
460
+ user
461
+ })) issues.push({
462
+ message,
463
+ path: pathArray.length > 0 ? pathArray : void 0
464
+ });
465
+ }
466
+ return issues;
467
+ }
468
+ /**
469
+ * Internal parse method that tracks field path for nested validation
470
+ * @param args - Parse arguments
471
+ * @returns Parse result with value or issues
472
+ */
473
+ function parseInternal(args) {
474
+ const { value, data, user, pathArray } = args;
475
+ const issues = [];
476
+ const isNullOrUndefined = value === null || value === void 0;
477
+ if (field._metadata.required && isNullOrUndefined) {
478
+ issues.push({
479
+ message: "Required field is missing",
480
+ path: pathArray.length > 0 ? pathArray : void 0
481
+ });
482
+ return { issues };
483
+ }
484
+ if (!field._metadata.required && isNullOrUndefined) return { value: value ?? null };
485
+ if (field._metadata.array) {
486
+ if (!Array.isArray(value)) {
487
+ issues.push({
488
+ message: "Expected an array",
489
+ path: pathArray.length > 0 ? pathArray : void 0
490
+ });
491
+ return { issues };
492
+ }
493
+ for (let i = 0; i < value.length; i++) {
494
+ const elementValue = value[i];
495
+ const elementIssues = validateValue({
496
+ value: elementValue,
497
+ data,
498
+ user,
499
+ pathArray: pathArray.concat(`[${i}]`)
500
+ });
501
+ if (elementIssues.length > 0) issues.push(...elementIssues);
502
+ }
503
+ if (issues.length > 0) return { issues };
504
+ return { value };
505
+ }
506
+ const valueIssues = validateValue({
507
+ value,
508
+ data,
509
+ user,
510
+ pathArray
511
+ });
512
+ issues.push(...valueIssues);
513
+ if (issues.length > 0) return { issues };
514
+ return { value };
515
+ }
516
+ const field = {
517
+ [TAILOR_FIELD_BRAND]: true,
518
+ [TAILOR_DB_FIELD_BRAND]: true,
519
+ type,
520
+ fields: fields ?? {},
521
+ _defined: void 0,
522
+ _output: void 0,
523
+ _metadata,
524
+ get metadata() {
525
+ return { ...this._metadata };
526
+ },
527
+ get rawRelation() {
528
+ return _rawRelation ? {
529
+ ..._rawRelation,
530
+ toward: { ..._rawRelation.toward }
531
+ } : void 0;
532
+ },
533
+ description(description) {
534
+ this._metadata.description = description;
535
+ return this;
536
+ },
537
+ typeName(typeName) {
538
+ this._metadata.typeName = typeName;
539
+ return this;
540
+ },
541
+ validate(...validateInputs) {
542
+ this._metadata.validate = validateInputs;
543
+ return this;
544
+ },
545
+ parse(args) {
546
+ return parseInternal({
547
+ value: args.value,
548
+ data: args.data,
549
+ user: args.user,
550
+ pathArray: []
551
+ });
552
+ },
553
+ _parseInternal: parseInternal,
554
+ relation(config) {
555
+ const targetType = isRelationSelfConfig(config) ? "self" : config.toward.type.name;
556
+ _rawRelation = {
557
+ type: config.type,
558
+ toward: {
559
+ type: targetType,
560
+ as: config.toward.as,
561
+ key: config.toward.key
562
+ },
563
+ backward: config.backward
564
+ };
565
+ return this;
566
+ },
567
+ index() {
568
+ this._metadata.index = true;
569
+ return this;
570
+ },
571
+ unique() {
572
+ this._metadata.unique = true;
573
+ this._metadata.index = true;
574
+ return this;
575
+ },
576
+ vector() {
577
+ this._metadata.vector = true;
578
+ return this;
579
+ },
580
+ hooks(hooks) {
581
+ this._metadata.hooks = hooks;
582
+ return this;
583
+ },
584
+ serial(config) {
585
+ this._metadata.serial = config;
586
+ return this;
587
+ },
588
+ clone(cloneOptions) {
589
+ const clonedField = createTailorDBField(type, options, fields, values);
590
+ Object.assign(clonedField._metadata, this._metadata);
591
+ if (cloneOptions) {
592
+ if (cloneOptions.optional !== void 0) clonedField._metadata.required = !cloneOptions.optional;
593
+ if (cloneOptions.array !== void 0) clonedField._metadata.array = cloneOptions.array;
594
+ }
595
+ if (_rawRelation) {
596
+ const clonedRawRelation = {
597
+ ..._rawRelation,
598
+ toward: { ..._rawRelation.toward }
599
+ };
600
+ clonedField._setRawRelation(clonedRawRelation);
601
+ }
602
+ return clonedField;
603
+ },
604
+ _setRawRelation(relation) {
605
+ _rawRelation = relation;
606
+ }
607
+ };
608
+ return field;
609
+ }
610
+ const createField = createTailorDBField;
611
+ function uuid(options) {
612
+ return createField("uuid", options);
613
+ }
614
+ function string(options) {
615
+ return createField("string", options);
616
+ }
617
+ function bool(options) {
618
+ return createField("boolean", options);
619
+ }
620
+ function int(options) {
621
+ return createField("integer", options);
622
+ }
623
+ function float(options) {
624
+ return createField("float", options);
625
+ }
626
+ function date(options) {
627
+ return createField("date", options);
628
+ }
629
+ function datetime(options) {
630
+ return createField("datetime", options);
631
+ }
632
+ function time(options) {
633
+ return createField("time", options);
634
+ }
635
+ function _enum(values, options) {
636
+ return createField("enum", options, void 0, values);
637
+ }
638
+ function object(fields, options) {
639
+ return createField("nested", options, fields);
640
+ }
641
+ /**
642
+ * Creates a new TailorDBType instance.
643
+ * @param name - Type name
644
+ * @param fields - Field definitions
645
+ * @param options - Type options
646
+ * @param options.pluralForm - Optional plural form
647
+ * @param options.description - Optional description
648
+ * @returns A new TailorDBType
649
+ */
650
+ function createTailorDBType(name, fields, options) {
651
+ let _description = options.description;
652
+ let _settings = {};
653
+ let _indexes = [];
654
+ const _permissions = {};
655
+ let _files = {};
656
+ if (options.pluralForm) {
657
+ if (name === options.pluralForm) throw new Error(`The name and the plural form must be different. name=${name}`);
658
+ _settings.pluralForm = options.pluralForm;
659
+ }
660
+ return {
661
+ [TAILOR_DB_TYPE_BRAND]: true,
662
+ name,
663
+ fields,
664
+ _output: null,
665
+ _description,
666
+ get metadata() {
667
+ const indexes = {};
668
+ if (_indexes && _indexes.length > 0) _indexes.forEach((index) => {
669
+ const fieldNames = index.fields.map((field) => String(field));
670
+ const key = index.name || `idx_${fieldNames.join("_")}`;
671
+ indexes[key] = {
672
+ fields: fieldNames,
673
+ unique: index.unique
674
+ };
675
+ });
676
+ return {
677
+ name: this.name,
678
+ description: _description,
679
+ settings: _settings,
680
+ permissions: _permissions,
681
+ files: _files,
682
+ ...Object.keys(indexes).length > 0 && { indexes }
683
+ };
684
+ },
685
+ hooks(hooks) {
686
+ Object.entries(hooks).forEach(([fieldName, fieldHooks]) => {
687
+ this.fields[fieldName].hooks(fieldHooks);
688
+ });
689
+ return this;
690
+ },
691
+ validate(validators) {
692
+ Object.entries(validators).forEach(([fieldName, fieldValidators]) => {
693
+ const field = this.fields[fieldName];
694
+ const validators$1 = fieldValidators;
695
+ const isValidateConfig = (v) => {
696
+ return Array.isArray(v) && v.length === 2 && typeof v[1] === "string";
697
+ };
698
+ if (Array.isArray(validators$1)) if (isValidateConfig(validators$1)) field.validate(validators$1);
699
+ else field.validate(...validators$1);
700
+ else field.validate(validators$1);
701
+ });
702
+ return this;
703
+ },
704
+ features(features) {
705
+ _settings = {
706
+ ..._settings,
707
+ ...features
708
+ };
709
+ return this;
710
+ },
711
+ indexes(...indexes) {
712
+ _indexes = indexes;
713
+ return this;
714
+ },
715
+ files(files) {
716
+ _files = files;
717
+ return this;
718
+ },
719
+ permission(permission) {
720
+ const ret = this;
721
+ _permissions.record = permission;
722
+ return ret;
723
+ },
724
+ gqlPermission(permission) {
725
+ const ret = this;
726
+ _permissions.gql = permission;
727
+ return ret;
728
+ },
729
+ description(description) {
730
+ _description = description;
731
+ this._description = description;
732
+ return this;
733
+ },
734
+ pickFields(keys, options$1) {
735
+ const result = {};
736
+ for (const key of keys) if (options$1) result[key] = this.fields[key].clone(options$1);
737
+ else result[key] = this.fields[key];
738
+ return result;
739
+ },
740
+ omitFields(keys) {
741
+ const keysSet = new Set(keys);
742
+ const result = {};
743
+ for (const key in this.fields) if (Object.hasOwn(this.fields, key) && !keysSet.has(key)) result[key] = this.fields[key];
744
+ return result;
745
+ }
746
+ };
747
+ }
748
+ const idField = uuid();
749
+ function dbType(name, fieldsOrDescription, fields) {
750
+ const typeName = Array.isArray(name) ? name[0] : name;
751
+ const pluralForm = Array.isArray(name) ? name[1] : void 0;
752
+ let description;
753
+ let fieldDef;
754
+ if (typeof fieldsOrDescription === "string") {
755
+ description = fieldsOrDescription;
756
+ fieldDef = fields;
757
+ } else fieldDef = fieldsOrDescription;
758
+ return createTailorDBType(typeName, {
759
+ id: idField,
760
+ ...fieldDef
761
+ }, {
762
+ pluralForm,
763
+ description
764
+ });
765
+ }
766
+ const db = {
767
+ type: dbType,
768
+ uuid,
769
+ string,
770
+ bool,
771
+ int,
772
+ float,
773
+ date,
774
+ datetime,
775
+ time,
776
+ enum: _enum,
777
+ object,
778
+ fields: { timestamps: () => ({
779
+ createdAt: datetime().hooks({ create: () => /* @__PURE__ */ new Date() }).description("Record creation timestamp"),
780
+ updatedAt: datetime({ optional: true }).hooks({ update: () => /* @__PURE__ */ new Date() }).description("Record last update timestamp")
781
+ }) }
782
+ };
783
+
784
+ //#endregion
785
+ //#region src/configure/services/auth/index.ts
786
+ function defineAuth(name, config) {
787
+ return {
788
+ ...config,
789
+ name,
790
+ invoker(machineUser) {
791
+ return {
792
+ namespace: name,
793
+ machineUserName: machineUser
794
+ };
795
+ }
796
+ };
797
+ }
798
+
799
+ //#endregion
800
+ export { unauthenticatedTailorUser as a, TAILOR_FIELD_BRAND as c, unsafeAllowAllTypePermission as i, db as n, t as o, unsafeAllowAllGqlPermission as r, TAILOR_DB_TYPE_BRAND as s, defineAuth as t };
801
+ //# sourceMappingURL=auth-CZPUwA1p.mjs.map