@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.
@@ -1,664 +0,0 @@
1
- //#region src/configure/types/field.ts
2
- /**
3
- * Normalize allowed values into EnumValue objects with descriptions.
4
- * @param values - Allowed values as strings or EnumValue objects
5
- * @returns Normalized allowed values
6
- */
7
- function mapAllowedValues(values) {
8
- return values.map((value) => {
9
- if (typeof value === "string") return {
10
- value,
11
- description: ""
12
- };
13
- return {
14
- ...value,
15
- description: value.description ?? ""
16
- };
17
- });
18
- }
19
-
20
- //#endregion
21
- //#region src/configure/types/type.ts
22
- const regex = {
23
- uuid: /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
24
- date: /^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$/,
25
- time: /^(?<hour>\d{2}):(?<minute>\d{2})$/,
26
- datetime: /^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})T(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})(.(?<millisec>\d{3}))?Z$/
27
- };
28
- var TailorField = class TailorField {
29
- _metadata;
30
- _defined = void 0;
31
- _output = void 0;
32
- get metadata() {
33
- return { ...this._metadata };
34
- }
35
- constructor(type, options, fields = {}, values) {
36
- this.type = type;
37
- this.fields = fields;
38
- this._metadata = { required: true };
39
- if (options) {
40
- if (options.optional === true) this._metadata.required = false;
41
- if (options.array === true) this._metadata.array = true;
42
- }
43
- if (values) this._metadata.allowedValues = mapAllowedValues(values);
44
- }
45
- static create(type, options, fields, values) {
46
- return new TailorField(type, options, fields, values);
47
- }
48
- description(description) {
49
- this._metadata.description = description;
50
- return this;
51
- }
52
- typeName(typeName) {
53
- this._metadata.typeName = typeName;
54
- return this;
55
- }
56
- validate(...validate) {
57
- this._metadata.validate = validate;
58
- return this;
59
- }
60
- /**
61
- * Parse and validate a value against this field's validation rules
62
- * Returns StandardSchema Result type with success or failure
63
- * @param args - Value, context data, and user
64
- * @returns Validation result
65
- */
66
- parse(args) {
67
- return this._parseInternal({
68
- value: args.value,
69
- data: args.data,
70
- user: args.user,
71
- pathArray: []
72
- });
73
- }
74
- /**
75
- * Validate a single value (not an array element)
76
- * Used internally for array element validation
77
- * @private
78
- * @param args - Validation arguments
79
- * @returns Validation issues
80
- */
81
- _validateValue(args) {
82
- const { value, data, user, pathArray } = args;
83
- const issues = [];
84
- switch (this.type) {
85
- case "string":
86
- if (typeof value !== "string") issues.push({
87
- message: `Expected a string: received ${String(value)}`,
88
- path: pathArray.length > 0 ? pathArray : void 0
89
- });
90
- break;
91
- case "integer":
92
- if (typeof value !== "number" || !Number.isInteger(value)) issues.push({
93
- message: `Expected an integer: received ${String(value)}`,
94
- path: pathArray.length > 0 ? pathArray : void 0
95
- });
96
- break;
97
- case "float":
98
- if (typeof value !== "number" || !Number.isFinite(value)) issues.push({
99
- message: `Expected a number: received ${String(value)}`,
100
- path: pathArray.length > 0 ? pathArray : void 0
101
- });
102
- break;
103
- case "boolean":
104
- if (typeof value !== "boolean") issues.push({
105
- message: `Expected a boolean: received ${String(value)}`,
106
- path: pathArray.length > 0 ? pathArray : void 0
107
- });
108
- break;
109
- case "uuid":
110
- if (typeof value !== "string" || !regex.uuid.test(value)) issues.push({
111
- message: `Expected a valid UUID: received ${String(value)}`,
112
- path: pathArray.length > 0 ? pathArray : void 0
113
- });
114
- break;
115
- case "date":
116
- if (typeof value !== "string" || !regex.date.test(value)) issues.push({
117
- message: `Expected to match "yyyy-MM-dd" format: received ${String(value)}`,
118
- path: pathArray.length > 0 ? pathArray : void 0
119
- });
120
- break;
121
- case "datetime":
122
- if (typeof value !== "string" || !regex.datetime.test(value)) issues.push({
123
- message: `Expected to match ISO format: received ${String(value)}`,
124
- path: pathArray.length > 0 ? pathArray : void 0
125
- });
126
- break;
127
- case "time":
128
- if (typeof value !== "string" || !regex.time.test(value)) issues.push({
129
- message: `Expected to match "HH:mm" format: received ${String(value)}`,
130
- path: pathArray.length > 0 ? pathArray : void 0
131
- });
132
- break;
133
- case "enum":
134
- if (this.metadata.allowedValues) {
135
- const allowedValues = this.metadata.allowedValues.map((v) => v.value);
136
- if (typeof value !== "string" || !allowedValues.includes(value)) issues.push({
137
- message: `Must be one of [${allowedValues.join(", ")}]: received ${String(value)}`,
138
- path: pathArray.length > 0 ? pathArray : void 0
139
- });
140
- }
141
- break;
142
- case "nested":
143
- if (typeof value !== "object" || value === null || Array.isArray(value) || value instanceof Date) issues.push({
144
- message: `Expected an object: received ${String(value)}`,
145
- path: pathArray.length > 0 ? pathArray : void 0
146
- });
147
- else if (this.fields && Object.keys(this.fields).length > 0) for (const [fieldName, field] of Object.entries(this.fields)) {
148
- const fieldValue = value?.[fieldName];
149
- const result = field._parseInternal({
150
- value: fieldValue,
151
- data,
152
- user,
153
- pathArray: pathArray.concat(fieldName)
154
- });
155
- if (result.issues) issues.push(...result.issues);
156
- }
157
- break;
158
- }
159
- const validateFns = this.metadata.validate;
160
- if (validateFns && validateFns.length > 0) for (const validateInput of validateFns) {
161
- const { fn, message } = typeof validateInput === "function" ? {
162
- fn: validateInput,
163
- message: "Validation failed"
164
- } : {
165
- fn: validateInput[0],
166
- message: validateInput[1]
167
- };
168
- if (!fn({
169
- value,
170
- data,
171
- user
172
- })) issues.push({
173
- message,
174
- path: pathArray.length > 0 ? pathArray : void 0
175
- });
176
- }
177
- return issues;
178
- }
179
- /**
180
- * Internal parse method that tracks field path for nested validation
181
- * @private
182
- * @param args - Parse arguments
183
- * @returns Validation result
184
- */
185
- _parseInternal(args) {
186
- const { value, data, user, pathArray } = args;
187
- const issues = [];
188
- const isNullOrUndefined = value === null || value === void 0;
189
- if (this.metadata.required && isNullOrUndefined) {
190
- issues.push({
191
- message: "Required field is missing",
192
- path: pathArray.length > 0 ? pathArray : void 0
193
- });
194
- return { issues };
195
- }
196
- if (!this.metadata.required && isNullOrUndefined) return { value };
197
- if (this.metadata.array) {
198
- if (!Array.isArray(value)) {
199
- issues.push({
200
- message: "Expected an array",
201
- path: pathArray.length > 0 ? pathArray : void 0
202
- });
203
- return { issues };
204
- }
205
- for (let i = 0; i < value.length; i++) {
206
- const elementValue = value[i];
207
- const elementPath = pathArray.concat(`[${i}]`);
208
- const elementIssues = this._validateValue({
209
- value: elementValue,
210
- data,
211
- user,
212
- pathArray: elementPath
213
- });
214
- if (elementIssues.length > 0) issues.push(...elementIssues);
215
- }
216
- if (issues.length > 0) return { issues };
217
- return { value };
218
- }
219
- const valueIssues = this._validateValue({
220
- value,
221
- data,
222
- user,
223
- pathArray
224
- });
225
- issues.push(...valueIssues);
226
- if (issues.length > 0) return { issues };
227
- return { value };
228
- }
229
- };
230
- const createField$1 = TailorField.create;
231
- function uuid$1(options) {
232
- return createField$1("uuid", options);
233
- }
234
- function string$1(options) {
235
- return createField$1("string", options);
236
- }
237
- function bool$1(options) {
238
- return createField$1("boolean", options);
239
- }
240
- function int$1(options) {
241
- return createField$1("integer", options);
242
- }
243
- function float$1(options) {
244
- return createField$1("float", options);
245
- }
246
- function date$1(options) {
247
- return createField$1("date", options);
248
- }
249
- function datetime$1(options) {
250
- return createField$1("datetime", options);
251
- }
252
- function time$1(options) {
253
- return createField$1("time", options);
254
- }
255
- function _enum$1(values, options) {
256
- return createField$1("enum", options, void 0, values);
257
- }
258
- function object$1(fields, options) {
259
- return createField$1("nested", options, fields);
260
- }
261
- const t = {
262
- uuid: uuid$1,
263
- string: string$1,
264
- bool: bool$1,
265
- int: int$1,
266
- float: float$1,
267
- date: date$1,
268
- datetime: datetime$1,
269
- time: time$1,
270
- enum: _enum$1,
271
- object: object$1
272
- };
273
-
274
- //#endregion
275
- //#region src/configure/types/user.ts
276
- /** Represents an unauthenticated user in the Tailor platform. */
277
- const unauthenticatedTailorUser = {
278
- id: "00000000-0000-0000-0000-000000000000",
279
- type: "",
280
- workspaceId: "00000000-0000-0000-0000-000000000000",
281
- attributes: null,
282
- attributeList: []
283
- };
284
-
285
- //#endregion
286
- //#region src/configure/services/tailordb/permission.ts
287
- /**
288
- * Grants full record-level access without any conditions.
289
- *
290
- * Unsafe and intended only for local development, prototyping, or tests.
291
- * Do not use this in production environments, as it effectively disables
292
- * authorization checks.
293
- */
294
- const unsafeAllowAllTypePermission = {
295
- create: [{
296
- conditions: [],
297
- permit: true
298
- }],
299
- read: [{
300
- conditions: [],
301
- permit: true
302
- }],
303
- update: [{
304
- conditions: [],
305
- permit: true
306
- }],
307
- delete: [{
308
- conditions: [],
309
- permit: true
310
- }]
311
- };
312
- /**
313
- * Grants full GraphQL access (all actions) without any conditions.
314
- *
315
- * Unsafe and intended only for local development, prototyping, or tests.
316
- * Do not use this in production environments, as it effectively disables
317
- * authorization checks.
318
- */
319
- const unsafeAllowAllGqlPermission = [{
320
- conditions: [],
321
- actions: "all",
322
- permit: true
323
- }];
324
-
325
- //#endregion
326
- //#region src/configure/services/tailordb/schema.ts
327
- function isRelationSelfConfig(config) {
328
- return config.toward.type === "self";
329
- }
330
- var TailorDBField = class TailorDBField extends TailorField {
331
- _rawRelation = void 0;
332
- get rawRelation() {
333
- return this._rawRelation ? {
334
- ...this._rawRelation,
335
- toward: { ...this._rawRelation.toward }
336
- } : void 0;
337
- }
338
- get metadata() {
339
- return { ...this._metadata };
340
- }
341
- constructor(type, options, fields, values) {
342
- super(type, options, fields, values);
343
- }
344
- static create(type, options, fields, values) {
345
- return new TailorDBField(type, options, fields, values);
346
- }
347
- description(description) {
348
- return super.description(description);
349
- }
350
- relation(config) {
351
- const targetType = isRelationSelfConfig(config) ? "self" : config.toward.type.name;
352
- this._rawRelation = {
353
- type: config.type,
354
- toward: {
355
- type: targetType,
356
- as: config.toward.as,
357
- key: config.toward.key
358
- },
359
- backward: config.backward
360
- };
361
- return this;
362
- }
363
- index() {
364
- this._metadata.index = true;
365
- return this;
366
- }
367
- unique() {
368
- this._metadata.unique = true;
369
- this._metadata.index = true;
370
- return this;
371
- }
372
- vector() {
373
- this._metadata.vector = true;
374
- return this;
375
- }
376
- hooks(hooks) {
377
- this._metadata.hooks = hooks;
378
- return this;
379
- }
380
- validate(...validate) {
381
- this._metadata.validate = validate;
382
- return this;
383
- }
384
- serial(config) {
385
- this._metadata.serial = config;
386
- return this;
387
- }
388
- /**
389
- * Clone the field with optional overrides for field options
390
- * @param options - Optional field options to override
391
- * @returns A new TailorDBField instance with the same configuration
392
- */
393
- clone(options) {
394
- const clonedField = Object.create(Object.getPrototypeOf(this));
395
- Object.assign(clonedField, {
396
- type: this.type,
397
- fields: this.fields,
398
- _defined: this._defined,
399
- _output: this._output
400
- });
401
- clonedField._metadata = { ...this._metadata };
402
- if (options) {
403
- if (options.optional !== void 0) clonedField._metadata.required = !options.optional;
404
- if (options.array !== void 0) clonedField._metadata.array = options.array;
405
- }
406
- if (this._rawRelation) clonedField._rawRelation = {
407
- ...this._rawRelation,
408
- toward: { ...this._rawRelation.toward }
409
- };
410
- return clonedField;
411
- }
412
- };
413
- const createField = TailorDBField.create;
414
- function uuid(options) {
415
- return createField("uuid", options);
416
- }
417
- function string(options) {
418
- return createField("string", options);
419
- }
420
- function bool(options) {
421
- return createField("boolean", options);
422
- }
423
- function int(options) {
424
- return createField("integer", options);
425
- }
426
- function float(options) {
427
- return createField("float", options);
428
- }
429
- function date(options) {
430
- return createField("date", options);
431
- }
432
- function datetime(options) {
433
- return createField("datetime", options);
434
- }
435
- function time(options) {
436
- return createField("time", options);
437
- }
438
- function _enum(values, options) {
439
- return createField("enum", options, void 0, values);
440
- }
441
- function object(fields, options) {
442
- return createField("nested", options, fields);
443
- }
444
- var TailorDBType = class {
445
- _output = null;
446
- _description;
447
- _settings = {};
448
- _indexes = [];
449
- _permissions = {};
450
- _files = {};
451
- constructor(name, fields, options) {
452
- this.name = name;
453
- this.fields = fields;
454
- this._description = options.description;
455
- if (options.pluralForm) {
456
- if (name === options.pluralForm) throw new Error(`The name and the plural form must be different. name=${name}`);
457
- this._settings.pluralForm = options.pluralForm;
458
- }
459
- }
460
- get metadata() {
461
- const indexes = {};
462
- if (this._indexes && this._indexes.length > 0) this._indexes.forEach((index) => {
463
- const fieldNames = index.fields.map((field) => String(field));
464
- const key = index.name || `idx_${fieldNames.join("_")}`;
465
- indexes[key] = {
466
- fields: fieldNames,
467
- unique: index.unique
468
- };
469
- });
470
- return {
471
- name: this.name,
472
- description: this._description,
473
- settings: this._settings,
474
- permissions: this._permissions,
475
- files: this._files,
476
- ...Object.keys(indexes).length > 0 && { indexes }
477
- };
478
- }
479
- hooks(hooks) {
480
- Object.entries(hooks).forEach(([fieldName, fieldHooks]) => {
481
- this.fields[fieldName].hooks(fieldHooks);
482
- });
483
- return this;
484
- }
485
- validate(validators) {
486
- Object.entries(validators).forEach(([fieldName, fieldValidators]) => {
487
- const field = this.fields[fieldName];
488
- const validators$1 = fieldValidators;
489
- const isValidateConfig = (v) => {
490
- return Array.isArray(v) && v.length === 2 && typeof v[1] === "string";
491
- };
492
- if (Array.isArray(validators$1)) if (isValidateConfig(validators$1)) field.validate(validators$1);
493
- else field.validate(...validators$1);
494
- else field.validate(validators$1);
495
- });
496
- return this;
497
- }
498
- features(features) {
499
- this._settings = {
500
- ...this._settings,
501
- ...features
502
- };
503
- return this;
504
- }
505
- indexes(...indexes) {
506
- this._indexes = indexes;
507
- return this;
508
- }
509
- files(files) {
510
- this._files = files;
511
- return this;
512
- }
513
- permission(permission) {
514
- const ret = this;
515
- ret._permissions.record = permission;
516
- return ret;
517
- }
518
- gqlPermission(permission) {
519
- const ret = this;
520
- ret._permissions.gql = permission;
521
- return ret;
522
- }
523
- description(description) {
524
- this._description = description;
525
- return this;
526
- }
527
- /**
528
- * Pick specific fields from the type
529
- * @param keys - Array of field keys to pick
530
- * @param options - Optional field options to apply to picked fields
531
- * @returns An object containing only the specified fields
532
- */
533
- pickFields(keys, options) {
534
- const result = {};
535
- for (const key of keys) if (options) result[key] = this.fields[key].clone(options);
536
- else result[key] = this.fields[key];
537
- return result;
538
- }
539
- /**
540
- * Omit specific fields from the type
541
- * @template K
542
- * @param keys - Array of field keys to omit
543
- * @returns An object containing all fields except the specified ones
544
- */
545
- omitFields(keys) {
546
- const keysSet = new Set(keys);
547
- const result = {};
548
- for (const key in this.fields) if (Object.hasOwn(this.fields, key) && !keysSet.has(key)) result[key] = this.fields[key];
549
- return result;
550
- }
551
- };
552
- const idField = uuid();
553
- function dbType(name, fieldsOrDescription, fields) {
554
- const typeName = Array.isArray(name) ? name[0] : name;
555
- const pluralForm = Array.isArray(name) ? name[1] : void 0;
556
- let description;
557
- let fieldDef;
558
- if (typeof fieldsOrDescription === "string") {
559
- description = fieldsOrDescription;
560
- fieldDef = fields;
561
- } else fieldDef = fieldsOrDescription;
562
- return new TailorDBType(typeName, {
563
- id: idField,
564
- ...fieldDef
565
- }, {
566
- pluralForm,
567
- description
568
- });
569
- }
570
- const db = {
571
- type: dbType,
572
- uuid,
573
- string,
574
- bool,
575
- int,
576
- float,
577
- date,
578
- datetime,
579
- time,
580
- enum: _enum,
581
- object,
582
- fields: { timestamps: () => ({
583
- createdAt: datetime().hooks({ create: () => /* @__PURE__ */ new Date() }).description("Record creation timestamp"),
584
- updatedAt: datetime({ optional: true }).hooks({ update: () => /* @__PURE__ */ new Date() }).description("Record last update timestamp")
585
- }) }
586
- };
587
-
588
- //#endregion
589
- //#region src/configure/services/auth/index.ts
590
- /**
591
- * Define an auth service for the Tailor SDK.
592
- * @template Name
593
- * @template User
594
- * @template AttributeMap
595
- * @template AttributeList
596
- * @template MachineUserNames
597
- * @template M
598
- * @param name - Auth service name
599
- * @param config - Auth service configuration
600
- * @returns Defined auth service
601
- */
602
- function defineAuth(name, config) {
603
- return {
604
- ...config,
605
- name,
606
- invoker(machineUser) {
607
- return {
608
- namespace: name,
609
- machineUserName: machineUser
610
- };
611
- }
612
- };
613
- }
614
-
615
- //#endregion
616
- //#region src/configure/services/workflow/job.ts
617
- /**
618
- * Symbol used to brand WorkflowJob objects created by createWorkflowJob.
619
- * This enables reliable runtime detection of workflow jobs regardless of
620
- * how they were imported or assigned (variable reassignment, destructuring, etc.)
621
- */
622
- const WORKFLOW_JOB_BRAND = Symbol.for("tailor:workflow-job");
623
- const createWorkflowJob = (config) => {
624
- return {
625
- [WORKFLOW_JOB_BRAND]: true,
626
- name: config.name,
627
- trigger: async (args) => {
628
- const ret = await tailor.workflow.triggerJobFunction(config.name, args);
629
- return ret ? JSON.parse(JSON.stringify(ret)) : ret;
630
- },
631
- body: config.body
632
- };
633
- };
634
-
635
- //#endregion
636
- //#region src/configure/config.ts
637
- let distPath = null;
638
- const getDistDir = () => {
639
- const configured = process.env.TAILOR_SDK_OUTPUT_DIR;
640
- if (configured && configured !== distPath) distPath = configured;
641
- else if (distPath === null) distPath = configured || ".tailor-sdk";
642
- return distPath;
643
- };
644
- /**
645
- * Define a Tailor SDK application configuration with shallow exactness.
646
- * @template Config
647
- * @param config - Application configuration
648
- * @returns The same configuration object
649
- */
650
- function defineConfig(config) {
651
- return config;
652
- }
653
- /**
654
- * Define generators to be used with the Tailor SDK.
655
- * @param configs - Generator configurations
656
- * @returns Generator configurations as given
657
- */
658
- function defineGenerators(...configs) {
659
- return configs;
660
- }
661
-
662
- //#endregion
663
- export { createWorkflowJob as a, unsafeAllowAllGqlPermission as c, TailorField as d, t as f, WORKFLOW_JOB_BRAND as i, unsafeAllowAllTypePermission as l, defineGenerators as n, defineAuth as o, getDistDir as r, db as s, defineConfig as t, unauthenticatedTailorUser as u };
664
- //# sourceMappingURL=config-CBpYlVa-.mjs.map