@synova-cloud/sdk 1.6.0 → 1.7.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.
- package/README.md +131 -7
- package/dist/index.cjs +558 -108
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +451 -77
- package/dist/index.d.ts +451 -77
- package/dist/index.js +537 -109
- package/dist/index.js.map +1 -1
- package/package.json +16 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
+
}) : x)(function(x) {
|
|
6
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
+
});
|
|
9
|
+
|
|
1
10
|
// src/errors/index.ts
|
|
2
11
|
var SynovaError = class extends Error {
|
|
3
12
|
constructor(message) {
|
|
@@ -69,9 +78,34 @@ var NetworkSynovaError = class extends SynovaError {
|
|
|
69
78
|
this.cause = cause;
|
|
70
79
|
}
|
|
71
80
|
};
|
|
81
|
+
var ExecutionSynovaError = class extends SynovaError {
|
|
82
|
+
code;
|
|
83
|
+
provider;
|
|
84
|
+
retryable;
|
|
85
|
+
retryAfterMs;
|
|
86
|
+
details;
|
|
87
|
+
constructor(error) {
|
|
88
|
+
super(error.message);
|
|
89
|
+
this.name = "ExecutionSynovaError";
|
|
90
|
+
this.code = error.code;
|
|
91
|
+
this.provider = error.provider;
|
|
92
|
+
this.retryable = error.retryable;
|
|
93
|
+
this.retryAfterMs = error.retryAfterMs;
|
|
94
|
+
this.details = error.details;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
var ValidationSynovaError = class extends SynovaError {
|
|
98
|
+
violations;
|
|
99
|
+
constructor(violations) {
|
|
100
|
+
const message = `Validation failed: ${violations.map((v) => v.property).join(", ")}`;
|
|
101
|
+
super(message);
|
|
102
|
+
this.name = "ValidationSynovaError";
|
|
103
|
+
this.violations = violations;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
72
106
|
|
|
73
107
|
// src/version.ts
|
|
74
|
-
var SDK_VERSION = "1.
|
|
108
|
+
var SDK_VERSION = "1.7.0" ;
|
|
75
109
|
|
|
76
110
|
// src/utils/http.ts
|
|
77
111
|
var HttpClient = class {
|
|
@@ -282,6 +316,451 @@ var HttpClient = class {
|
|
|
282
316
|
}
|
|
283
317
|
};
|
|
284
318
|
|
|
319
|
+
// src/schema/types.ts
|
|
320
|
+
var SCHEMA_METADATA_KEYS = {
|
|
321
|
+
// Metadata
|
|
322
|
+
DESCRIPTION: "synova:schema:description",
|
|
323
|
+
EXAMPLES: "synova:schema:examples",
|
|
324
|
+
DEFAULT: "synova:schema:default",
|
|
325
|
+
// Type helpers
|
|
326
|
+
FORMAT: "synova:schema:format",
|
|
327
|
+
ARRAY_ITEM_TYPE: "synova:schema:arrayItemType",
|
|
328
|
+
NULLABLE: "synova:schema:nullable",
|
|
329
|
+
ENUM: "synova:schema:enum",
|
|
330
|
+
// String constraints
|
|
331
|
+
MIN_LENGTH: "synova:schema:minLength",
|
|
332
|
+
MAX_LENGTH: "synova:schema:maxLength",
|
|
333
|
+
PATTERN: "synova:schema:pattern",
|
|
334
|
+
// Number constraints
|
|
335
|
+
MINIMUM: "synova:schema:minimum",
|
|
336
|
+
MAXIMUM: "synova:schema:maximum",
|
|
337
|
+
EXCLUSIVE_MINIMUM: "synova:schema:exclusiveMinimum",
|
|
338
|
+
EXCLUSIVE_MAXIMUM: "synova:schema:exclusiveMaximum",
|
|
339
|
+
MULTIPLE_OF: "synova:schema:multipleOf",
|
|
340
|
+
// Array constraints
|
|
341
|
+
MIN_ITEMS: "synova:schema:minItems",
|
|
342
|
+
MAX_ITEMS: "synova:schema:maxItems",
|
|
343
|
+
UNIQUE_ITEMS: "synova:schema:uniqueItems"
|
|
344
|
+
};
|
|
345
|
+
function createMetadataDecorator(key, value) {
|
|
346
|
+
return function(target, propertyKey) {
|
|
347
|
+
Reflect.defineMetadata(key, value, target, propertyKey);
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
function Description(description) {
|
|
351
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.DESCRIPTION, description);
|
|
352
|
+
}
|
|
353
|
+
function Example(...examples) {
|
|
354
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.EXAMPLES, examples);
|
|
355
|
+
}
|
|
356
|
+
function Default(value) {
|
|
357
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.DEFAULT, value);
|
|
358
|
+
}
|
|
359
|
+
function ArrayItems(itemType) {
|
|
360
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.ARRAY_ITEM_TYPE, itemType);
|
|
361
|
+
}
|
|
362
|
+
function Format(format) {
|
|
363
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.FORMAT, format);
|
|
364
|
+
}
|
|
365
|
+
function Nullable() {
|
|
366
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.NULLABLE, true);
|
|
367
|
+
}
|
|
368
|
+
function SchemaMinLength(length) {
|
|
369
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.MIN_LENGTH, length);
|
|
370
|
+
}
|
|
371
|
+
function SchemaMaxLength(length) {
|
|
372
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.MAX_LENGTH, length);
|
|
373
|
+
}
|
|
374
|
+
function SchemaPattern(pattern) {
|
|
375
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.PATTERN, pattern);
|
|
376
|
+
}
|
|
377
|
+
function SchemaMin(value) {
|
|
378
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.MINIMUM, value);
|
|
379
|
+
}
|
|
380
|
+
function SchemaMax(value) {
|
|
381
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.MAXIMUM, value);
|
|
382
|
+
}
|
|
383
|
+
function ExclusiveMin(value) {
|
|
384
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.EXCLUSIVE_MINIMUM, value);
|
|
385
|
+
}
|
|
386
|
+
function ExclusiveMax(value) {
|
|
387
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.EXCLUSIVE_MAXIMUM, value);
|
|
388
|
+
}
|
|
389
|
+
function MultipleOf(value) {
|
|
390
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.MULTIPLE_OF, value);
|
|
391
|
+
}
|
|
392
|
+
function SchemaMinItems(count) {
|
|
393
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.MIN_ITEMS, count);
|
|
394
|
+
}
|
|
395
|
+
function SchemaMaxItems(count) {
|
|
396
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.MAX_ITEMS, count);
|
|
397
|
+
}
|
|
398
|
+
function SchemaUniqueItems() {
|
|
399
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.UNIQUE_ITEMS, true);
|
|
400
|
+
}
|
|
401
|
+
function SchemaEnum(values) {
|
|
402
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.ENUM, values);
|
|
403
|
+
}
|
|
404
|
+
function getSchemaMetadata(key, target, propertyKey) {
|
|
405
|
+
return Reflect.getMetadata(key, target, propertyKey);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// src/schema/class-schema.ts
|
|
409
|
+
var ClassSchema = class {
|
|
410
|
+
/**
|
|
411
|
+
* Generate JSON Schema from a class
|
|
412
|
+
*/
|
|
413
|
+
static generate(targetClass, options = {}) {
|
|
414
|
+
const { additionalProperties = false } = options;
|
|
415
|
+
const properties = this.getProperties(targetClass);
|
|
416
|
+
const required = this.getRequiredProperties(targetClass, properties);
|
|
417
|
+
return {
|
|
418
|
+
type: "object",
|
|
419
|
+
properties,
|
|
420
|
+
required: required.length > 0 ? required : void 0,
|
|
421
|
+
additionalProperties
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Get all properties with their schemas
|
|
426
|
+
*/
|
|
427
|
+
static getProperties(targetClass) {
|
|
428
|
+
const properties = {};
|
|
429
|
+
const prototype = targetClass.prototype;
|
|
430
|
+
const classValidatorProperties = this.getClassValidatorProperties(targetClass);
|
|
431
|
+
const decoratorProperties = this.getDecoratorProperties(prototype);
|
|
432
|
+
const allProperties = /* @__PURE__ */ new Set([...classValidatorProperties, ...decoratorProperties]);
|
|
433
|
+
for (const propertyName of allProperties) {
|
|
434
|
+
properties[propertyName] = this.getPropertySchema(targetClass, propertyName);
|
|
435
|
+
}
|
|
436
|
+
return properties;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Get property names from class-validator metadata
|
|
440
|
+
*/
|
|
441
|
+
static getClassValidatorProperties(targetClass) {
|
|
442
|
+
try {
|
|
443
|
+
const { getMetadataStorage } = __require("class-validator");
|
|
444
|
+
const metadataStorage = getMetadataStorage();
|
|
445
|
+
const targetMetadatas = metadataStorage.getTargetValidationMetadatas(
|
|
446
|
+
targetClass,
|
|
447
|
+
"",
|
|
448
|
+
true,
|
|
449
|
+
false
|
|
450
|
+
);
|
|
451
|
+
const propertyNames = targetMetadatas.map((m) => m.propertyName);
|
|
452
|
+
return [...new Set(propertyNames)];
|
|
453
|
+
} catch {
|
|
454
|
+
return [];
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Get property names from our decorator metadata
|
|
459
|
+
*/
|
|
460
|
+
static getDecoratorProperties(prototype) {
|
|
461
|
+
const properties = [];
|
|
462
|
+
const ownKeys = Reflect.ownKeys(prototype);
|
|
463
|
+
for (const key of ownKeys) {
|
|
464
|
+
if (typeof key === "string" && key !== "constructor") {
|
|
465
|
+
for (const metaKey of Object.values(SCHEMA_METADATA_KEYS)) {
|
|
466
|
+
if (Reflect.hasMetadata(metaKey, prototype, key)) {
|
|
467
|
+
properties.push(key);
|
|
468
|
+
break;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return properties;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Get JSON Schema for a single property
|
|
477
|
+
*/
|
|
478
|
+
static getPropertySchema(targetClass, propertyName) {
|
|
479
|
+
const prototype = targetClass.prototype;
|
|
480
|
+
const schema = {};
|
|
481
|
+
const designType = Reflect.getMetadata("design:type", prototype, propertyName);
|
|
482
|
+
const baseSchema = this.getBaseTypeSchema(designType, targetClass, propertyName);
|
|
483
|
+
Object.assign(schema, baseSchema);
|
|
484
|
+
this.applyClassValidatorConstraints(schema, targetClass, propertyName);
|
|
485
|
+
this.applyDecoratorMetadata(schema, prototype, propertyName);
|
|
486
|
+
const isNullable = getSchemaMetadata(
|
|
487
|
+
SCHEMA_METADATA_KEYS.NULLABLE,
|
|
488
|
+
prototype,
|
|
489
|
+
propertyName
|
|
490
|
+
);
|
|
491
|
+
if (isNullable && schema.type && typeof schema.type === "string") {
|
|
492
|
+
schema.type = [schema.type, "null"];
|
|
493
|
+
}
|
|
494
|
+
return schema;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Get base schema from TypeScript type
|
|
498
|
+
*/
|
|
499
|
+
static getBaseTypeSchema(designType, targetClass, propertyName) {
|
|
500
|
+
if (designType === String) {
|
|
501
|
+
return { type: "string" };
|
|
502
|
+
}
|
|
503
|
+
if (designType === Number) {
|
|
504
|
+
return { type: "number" };
|
|
505
|
+
}
|
|
506
|
+
if (designType === Boolean) {
|
|
507
|
+
return { type: "boolean" };
|
|
508
|
+
}
|
|
509
|
+
if (designType === Array) {
|
|
510
|
+
const itemType = getSchemaMetadata(
|
|
511
|
+
SCHEMA_METADATA_KEYS.ARRAY_ITEM_TYPE,
|
|
512
|
+
targetClass.prototype,
|
|
513
|
+
propertyName
|
|
514
|
+
);
|
|
515
|
+
return {
|
|
516
|
+
type: "array",
|
|
517
|
+
items: this.getArrayItemSchema(itemType)
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
if (designType === Object) {
|
|
521
|
+
return { type: "object" };
|
|
522
|
+
}
|
|
523
|
+
if (typeof designType === "function" && designType.prototype) {
|
|
524
|
+
return this.generate(designType);
|
|
525
|
+
}
|
|
526
|
+
return { type: "string" };
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Get schema for array items
|
|
530
|
+
*/
|
|
531
|
+
static getArrayItemSchema(itemType) {
|
|
532
|
+
if (!itemType) {
|
|
533
|
+
return { type: "string" };
|
|
534
|
+
}
|
|
535
|
+
if (itemType === String) {
|
|
536
|
+
return { type: "string" };
|
|
537
|
+
}
|
|
538
|
+
if (itemType === Number) {
|
|
539
|
+
return { type: "number" };
|
|
540
|
+
}
|
|
541
|
+
if (itemType === Boolean) {
|
|
542
|
+
return { type: "boolean" };
|
|
543
|
+
}
|
|
544
|
+
return this.generate(itemType);
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Apply class-validator constraints to schema
|
|
548
|
+
*/
|
|
549
|
+
static applyClassValidatorConstraints(schema, targetClass, propertyName) {
|
|
550
|
+
try {
|
|
551
|
+
const { getMetadataStorage } = __require("class-validator");
|
|
552
|
+
const metadataStorage = getMetadataStorage();
|
|
553
|
+
const targetMetadatas = metadataStorage.getTargetValidationMetadatas(
|
|
554
|
+
targetClass,
|
|
555
|
+
"",
|
|
556
|
+
true,
|
|
557
|
+
false
|
|
558
|
+
);
|
|
559
|
+
const propertyMetadatas = targetMetadatas.filter(
|
|
560
|
+
(m) => m.propertyName === propertyName
|
|
561
|
+
);
|
|
562
|
+
for (const metadata of propertyMetadatas) {
|
|
563
|
+
this.applyValidationConstraint(schema, metadata);
|
|
564
|
+
}
|
|
565
|
+
} catch {
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Apply a single class-validator constraint
|
|
570
|
+
*/
|
|
571
|
+
static applyValidationConstraint(schema, metadata) {
|
|
572
|
+
const constraintType = metadata.name || metadata.type || "";
|
|
573
|
+
const constraints = metadata.constraints || [];
|
|
574
|
+
switch (constraintType) {
|
|
575
|
+
case "isString":
|
|
576
|
+
schema.type = "string";
|
|
577
|
+
break;
|
|
578
|
+
case "isNumber":
|
|
579
|
+
case "isInt":
|
|
580
|
+
schema.type = constraintType === "isInt" ? "integer" : "number";
|
|
581
|
+
break;
|
|
582
|
+
case "isBoolean":
|
|
583
|
+
schema.type = "boolean";
|
|
584
|
+
break;
|
|
585
|
+
case "isArray":
|
|
586
|
+
schema.type = "array";
|
|
587
|
+
break;
|
|
588
|
+
case "isEnum":
|
|
589
|
+
if (constraints[0]) {
|
|
590
|
+
schema.enum = Object.values(constraints[0]);
|
|
591
|
+
}
|
|
592
|
+
break;
|
|
593
|
+
case "minLength":
|
|
594
|
+
schema.minLength = constraints[0];
|
|
595
|
+
break;
|
|
596
|
+
case "maxLength":
|
|
597
|
+
schema.maxLength = constraints[0];
|
|
598
|
+
break;
|
|
599
|
+
case "min":
|
|
600
|
+
schema.minimum = constraints[0];
|
|
601
|
+
break;
|
|
602
|
+
case "max":
|
|
603
|
+
schema.maximum = constraints[0];
|
|
604
|
+
break;
|
|
605
|
+
case "isEmail":
|
|
606
|
+
schema.format = "email";
|
|
607
|
+
break;
|
|
608
|
+
case "isUrl":
|
|
609
|
+
case "isURL":
|
|
610
|
+
schema.format = "uri";
|
|
611
|
+
break;
|
|
612
|
+
case "isUUID":
|
|
613
|
+
schema.format = "uuid";
|
|
614
|
+
break;
|
|
615
|
+
case "isDateString":
|
|
616
|
+
case "isISO8601":
|
|
617
|
+
schema.format = "date-time";
|
|
618
|
+
break;
|
|
619
|
+
case "matches":
|
|
620
|
+
if (constraints[0] instanceof RegExp) {
|
|
621
|
+
schema.pattern = constraints[0].source;
|
|
622
|
+
} else if (typeof constraints[0] === "string") {
|
|
623
|
+
schema.pattern = constraints[0];
|
|
624
|
+
}
|
|
625
|
+
break;
|
|
626
|
+
case "arrayMinSize":
|
|
627
|
+
schema.minItems = constraints[0];
|
|
628
|
+
break;
|
|
629
|
+
case "arrayMaxSize":
|
|
630
|
+
schema.maxItems = constraints[0];
|
|
631
|
+
break;
|
|
632
|
+
case "arrayUnique":
|
|
633
|
+
schema.uniqueItems = true;
|
|
634
|
+
break;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Apply our decorator metadata to schema.
|
|
639
|
+
* Our decorators take precedence over class-validator if both are used.
|
|
640
|
+
*/
|
|
641
|
+
static applyDecoratorMetadata(schema, prototype, propertyName) {
|
|
642
|
+
const description = getSchemaMetadata(
|
|
643
|
+
SCHEMA_METADATA_KEYS.DESCRIPTION,
|
|
644
|
+
prototype,
|
|
645
|
+
propertyName
|
|
646
|
+
);
|
|
647
|
+
if (description) schema.description = description;
|
|
648
|
+
const examples = getSchemaMetadata(
|
|
649
|
+
SCHEMA_METADATA_KEYS.EXAMPLES,
|
|
650
|
+
prototype,
|
|
651
|
+
propertyName
|
|
652
|
+
);
|
|
653
|
+
if (examples) schema.examples = examples;
|
|
654
|
+
const defaultValue = getSchemaMetadata(
|
|
655
|
+
SCHEMA_METADATA_KEYS.DEFAULT,
|
|
656
|
+
prototype,
|
|
657
|
+
propertyName
|
|
658
|
+
);
|
|
659
|
+
if (defaultValue !== void 0) schema.default = defaultValue;
|
|
660
|
+
const format = getSchemaMetadata(SCHEMA_METADATA_KEYS.FORMAT, prototype, propertyName);
|
|
661
|
+
if (format) schema.format = format;
|
|
662
|
+
const enumValues = getSchemaMetadata(
|
|
663
|
+
SCHEMA_METADATA_KEYS.ENUM,
|
|
664
|
+
prototype,
|
|
665
|
+
propertyName
|
|
666
|
+
);
|
|
667
|
+
if (enumValues) schema.enum = enumValues;
|
|
668
|
+
const minLength = getSchemaMetadata(
|
|
669
|
+
SCHEMA_METADATA_KEYS.MIN_LENGTH,
|
|
670
|
+
prototype,
|
|
671
|
+
propertyName
|
|
672
|
+
);
|
|
673
|
+
if (minLength !== void 0) schema.minLength = minLength;
|
|
674
|
+
const maxLength = getSchemaMetadata(
|
|
675
|
+
SCHEMA_METADATA_KEYS.MAX_LENGTH,
|
|
676
|
+
prototype,
|
|
677
|
+
propertyName
|
|
678
|
+
);
|
|
679
|
+
if (maxLength !== void 0) schema.maxLength = maxLength;
|
|
680
|
+
const pattern = getSchemaMetadata(
|
|
681
|
+
SCHEMA_METADATA_KEYS.PATTERN,
|
|
682
|
+
prototype,
|
|
683
|
+
propertyName
|
|
684
|
+
);
|
|
685
|
+
if (pattern) schema.pattern = pattern;
|
|
686
|
+
const minimum = getSchemaMetadata(
|
|
687
|
+
SCHEMA_METADATA_KEYS.MINIMUM,
|
|
688
|
+
prototype,
|
|
689
|
+
propertyName
|
|
690
|
+
);
|
|
691
|
+
if (minimum !== void 0) schema.minimum = minimum;
|
|
692
|
+
const maximum = getSchemaMetadata(
|
|
693
|
+
SCHEMA_METADATA_KEYS.MAXIMUM,
|
|
694
|
+
prototype,
|
|
695
|
+
propertyName
|
|
696
|
+
);
|
|
697
|
+
if (maximum !== void 0) schema.maximum = maximum;
|
|
698
|
+
const exclusiveMinimum = getSchemaMetadata(
|
|
699
|
+
SCHEMA_METADATA_KEYS.EXCLUSIVE_MINIMUM,
|
|
700
|
+
prototype,
|
|
701
|
+
propertyName
|
|
702
|
+
);
|
|
703
|
+
if (exclusiveMinimum !== void 0) schema.exclusiveMinimum = exclusiveMinimum;
|
|
704
|
+
const exclusiveMaximum = getSchemaMetadata(
|
|
705
|
+
SCHEMA_METADATA_KEYS.EXCLUSIVE_MAXIMUM,
|
|
706
|
+
prototype,
|
|
707
|
+
propertyName
|
|
708
|
+
);
|
|
709
|
+
if (exclusiveMaximum !== void 0) schema.exclusiveMaximum = exclusiveMaximum;
|
|
710
|
+
const multipleOf = getSchemaMetadata(
|
|
711
|
+
SCHEMA_METADATA_KEYS.MULTIPLE_OF,
|
|
712
|
+
prototype,
|
|
713
|
+
propertyName
|
|
714
|
+
);
|
|
715
|
+
if (multipleOf !== void 0) schema.multipleOf = multipleOf;
|
|
716
|
+
const minItems = getSchemaMetadata(
|
|
717
|
+
SCHEMA_METADATA_KEYS.MIN_ITEMS,
|
|
718
|
+
prototype,
|
|
719
|
+
propertyName
|
|
720
|
+
);
|
|
721
|
+
if (minItems !== void 0) schema.minItems = minItems;
|
|
722
|
+
const maxItems = getSchemaMetadata(
|
|
723
|
+
SCHEMA_METADATA_KEYS.MAX_ITEMS,
|
|
724
|
+
prototype,
|
|
725
|
+
propertyName
|
|
726
|
+
);
|
|
727
|
+
if (maxItems !== void 0) schema.maxItems = maxItems;
|
|
728
|
+
const uniqueItems = getSchemaMetadata(
|
|
729
|
+
SCHEMA_METADATA_KEYS.UNIQUE_ITEMS,
|
|
730
|
+
prototype,
|
|
731
|
+
propertyName
|
|
732
|
+
);
|
|
733
|
+
if (uniqueItems) schema.uniqueItems = uniqueItems;
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Get required properties (properties without @IsOptional)
|
|
737
|
+
*/
|
|
738
|
+
static getRequiredProperties(targetClass, properties) {
|
|
739
|
+
const required = [];
|
|
740
|
+
try {
|
|
741
|
+
const { getMetadataStorage } = __require("class-validator");
|
|
742
|
+
const metadataStorage = getMetadataStorage();
|
|
743
|
+
const targetMetadatas = metadataStorage.getTargetValidationMetadatas(
|
|
744
|
+
targetClass,
|
|
745
|
+
"",
|
|
746
|
+
true,
|
|
747
|
+
false
|
|
748
|
+
);
|
|
749
|
+
for (const propertyName of Object.keys(properties)) {
|
|
750
|
+
const isOptional = targetMetadatas.some(
|
|
751
|
+
(m) => m.propertyName === propertyName && (m.type === "isOptional" || m.type === "conditionalValidation")
|
|
752
|
+
);
|
|
753
|
+
if (!isOptional) {
|
|
754
|
+
required.push(propertyName);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
} catch {
|
|
758
|
+
required.push(...Object.keys(properties));
|
|
759
|
+
}
|
|
760
|
+
return required;
|
|
761
|
+
}
|
|
762
|
+
};
|
|
763
|
+
|
|
285
764
|
// src/resources/prompts.ts
|
|
286
765
|
var PromptsResource = class {
|
|
287
766
|
constructor(http) {
|
|
@@ -289,22 +768,6 @@ var PromptsResource = class {
|
|
|
289
768
|
}
|
|
290
769
|
/**
|
|
291
770
|
* Get a prompt by ID (returns version with 'latest' tag)
|
|
292
|
-
*
|
|
293
|
-
* @param promptId - The prompt ID (e.g., 'prm_abc123')
|
|
294
|
-
* @param options - Optional settings
|
|
295
|
-
* @returns The prompt data
|
|
296
|
-
*
|
|
297
|
-
* @example
|
|
298
|
-
* ```ts
|
|
299
|
-
* // Get default (latest) version
|
|
300
|
-
* const prompt = await client.prompts.get('prm_abc123');
|
|
301
|
-
*
|
|
302
|
-
* // Get by specific tag
|
|
303
|
-
* const production = await client.prompts.get('prm_abc123', { tag: 'production' });
|
|
304
|
-
*
|
|
305
|
-
* // Get specific version
|
|
306
|
-
* const v2 = await client.prompts.get('prm_abc123', { version: '2.0.0' });
|
|
307
|
-
* ```
|
|
308
771
|
*/
|
|
309
772
|
async get(promptId, options) {
|
|
310
773
|
if (options?.version) {
|
|
@@ -325,38 +788,23 @@ var PromptsResource = class {
|
|
|
325
788
|
path: `/api/v1/prompts/${promptId}/tags/${tag}`
|
|
326
789
|
});
|
|
327
790
|
}
|
|
791
|
+
async execute(promptId, options) {
|
|
792
|
+
if ("responseClass" in options && options.responseClass) {
|
|
793
|
+
return this.executeTyped(promptId, options);
|
|
794
|
+
}
|
|
795
|
+
return this.executeRaw(promptId, options);
|
|
796
|
+
}
|
|
797
|
+
async executeByTag(promptId, tag, options) {
|
|
798
|
+
return this.execute(promptId, { ...options, tag });
|
|
799
|
+
}
|
|
800
|
+
async executeByVersion(promptId, version, options) {
|
|
801
|
+
return this.execute(promptId, { ...options, version });
|
|
802
|
+
}
|
|
328
803
|
/**
|
|
329
|
-
* Execute
|
|
330
|
-
*
|
|
331
|
-
* @param promptId - The prompt ID
|
|
332
|
-
* @param options - Execution options including provider, model and variables
|
|
333
|
-
* @returns The execution response
|
|
334
|
-
*
|
|
335
|
-
* @example
|
|
336
|
-
* ```ts
|
|
337
|
-
* const result = await client.prompts.execute('prm_abc123', {
|
|
338
|
-
* provider: 'openai',
|
|
339
|
-
* model: 'gpt-4o',
|
|
340
|
-
* variables: { topic: 'TypeScript' },
|
|
341
|
-
* });
|
|
342
|
-
*
|
|
343
|
-
* if (result.type === 'message') {
|
|
344
|
-
* console.log(result.content);
|
|
345
|
-
* }
|
|
346
|
-
*
|
|
347
|
-
* // Image generation
|
|
348
|
-
* const imageResult = await client.prompts.execute('prm_image123', {
|
|
349
|
-
* provider: 'google',
|
|
350
|
-
* model: 'gemini-2.0-flash-exp',
|
|
351
|
-
* variables: { style: 'modern' },
|
|
352
|
-
* });
|
|
353
|
-
*
|
|
354
|
-
* if (imageResult.type === 'image') {
|
|
355
|
-
* console.log('Generated images:', imageResult.files);
|
|
356
|
-
* }
|
|
357
|
-
* ```
|
|
804
|
+
* Execute raw request without typed response
|
|
805
|
+
* @throws {ExecutionSynovaError} If LLM returns an error
|
|
358
806
|
*/
|
|
359
|
-
async
|
|
807
|
+
async executeRaw(promptId, options) {
|
|
360
808
|
const body = {
|
|
361
809
|
provider: options.provider,
|
|
362
810
|
model: options.model
|
|
@@ -370,79 +818,59 @@ var PromptsResource = class {
|
|
|
370
818
|
if (options.metadata !== void 0) body.metadata = options.metadata;
|
|
371
819
|
if (options.parameters !== void 0) body.parameters = options.parameters;
|
|
372
820
|
if (options.responseSchema !== void 0) body.responseSchema = options.responseSchema;
|
|
373
|
-
|
|
821
|
+
const response = await this.http.request({
|
|
374
822
|
method: "POST",
|
|
375
823
|
path: `/api/v1/prompts/${promptId}/run`,
|
|
376
824
|
body
|
|
377
825
|
});
|
|
826
|
+
if (response.type === "error" && response.error) {
|
|
827
|
+
throw new ExecutionSynovaError(response.error);
|
|
828
|
+
}
|
|
829
|
+
return response;
|
|
378
830
|
}
|
|
379
831
|
/**
|
|
380
|
-
* Execute
|
|
381
|
-
*
|
|
382
|
-
* @param promptId - The prompt ID
|
|
383
|
-
* @param tag - The tag (e.g., 'latest', 'production', 'staging')
|
|
384
|
-
* @param options - Execution options
|
|
385
|
-
* @returns The execution response
|
|
386
|
-
*
|
|
387
|
-
* @example
|
|
388
|
-
* ```ts
|
|
389
|
-
* const result = await client.prompts.executeByTag('prm_abc123', 'production', {
|
|
390
|
-
* provider: 'openai',
|
|
391
|
-
* model: 'gpt-4o',
|
|
392
|
-
* variables: { topic: 'TypeScript' },
|
|
393
|
-
* });
|
|
394
|
-
* ```
|
|
832
|
+
* Execute with typed response class
|
|
395
833
|
*/
|
|
396
|
-
async
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
provider: options.provider,
|
|
403
|
-
model: options.model,
|
|
404
|
-
apiKey: options.apiKey,
|
|
405
|
-
azureEndpoint: options.azureEndpoint,
|
|
406
|
-
variables: options.variables,
|
|
407
|
-
messages: options.messages,
|
|
408
|
-
metadata: options.metadata,
|
|
409
|
-
parameters: options.parameters
|
|
410
|
-
}
|
|
834
|
+
async executeTyped(promptId, options) {
|
|
835
|
+
const { responseClass, validate = true, ...executeOptions } = options;
|
|
836
|
+
const responseSchema = ClassSchema.generate(responseClass);
|
|
837
|
+
const response = await this.executeRaw(promptId, {
|
|
838
|
+
...executeOptions,
|
|
839
|
+
responseSchema
|
|
411
840
|
});
|
|
841
|
+
const object = response.object;
|
|
842
|
+
if (validate) {
|
|
843
|
+
await this.validateObject(object, responseClass);
|
|
844
|
+
}
|
|
845
|
+
return object;
|
|
412
846
|
}
|
|
413
847
|
/**
|
|
414
|
-
*
|
|
415
|
-
*
|
|
416
|
-
* @param promptId - The prompt ID
|
|
417
|
-
* @param version - The semantic version (e.g., '1.0.0', '2.1.0')
|
|
418
|
-
* @param options - Execution options
|
|
419
|
-
* @returns The execution response
|
|
420
|
-
*
|
|
421
|
-
* @example
|
|
422
|
-
* ```ts
|
|
423
|
-
* const result = await client.prompts.executeByVersion('prm_abc123', '1.2.0', {
|
|
424
|
-
* provider: 'openai',
|
|
425
|
-
* model: 'gpt-4o',
|
|
426
|
-
* variables: { topic: 'TypeScript' },
|
|
427
|
-
* });
|
|
428
|
-
* ```
|
|
848
|
+
* Validate object using class-validator
|
|
429
849
|
*/
|
|
430
|
-
async
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
850
|
+
async validateObject(object, responseClass) {
|
|
851
|
+
try {
|
|
852
|
+
const { plainToInstance } = __require("class-transformer");
|
|
853
|
+
const { validate } = __require("class-validator");
|
|
854
|
+
const instance = plainToInstance(responseClass, object);
|
|
855
|
+
const errors = await validate(instance);
|
|
856
|
+
if (errors.length > 0) {
|
|
857
|
+
const violations = errors.map(
|
|
858
|
+
(error) => ({
|
|
859
|
+
property: error.property,
|
|
860
|
+
constraints: error.constraints || {},
|
|
861
|
+
value: error.value
|
|
862
|
+
})
|
|
863
|
+
);
|
|
864
|
+
throw new ValidationSynovaError(violations);
|
|
444
865
|
}
|
|
445
|
-
})
|
|
866
|
+
} catch (error) {
|
|
867
|
+
if (error instanceof ValidationSynovaError) {
|
|
868
|
+
throw error;
|
|
869
|
+
}
|
|
870
|
+
console.warn(
|
|
871
|
+
"[Synova SDK] Validation skipped: class-validator or class-transformer not installed. Install them with: npm install class-validator class-transformer"
|
|
872
|
+
);
|
|
873
|
+
}
|
|
446
874
|
}
|
|
447
875
|
};
|
|
448
876
|
|
|
@@ -625,6 +1053,6 @@ var SynovaCloudSdk = class {
|
|
|
625
1053
|
}
|
|
626
1054
|
};
|
|
627
1055
|
|
|
628
|
-
export { ApiSynovaError, AuthSynovaError, NetworkSynovaError, NotFoundSynovaError, RateLimitSynovaError, ServerSynovaError, SynovaCloudSdk, SynovaError, TimeoutSynovaError };
|
|
1056
|
+
export { ApiSynovaError, ArrayItems, AuthSynovaError, ClassSchema, Default, Description, Example, ExclusiveMax, ExclusiveMin, ExecutionSynovaError, Format, MultipleOf, NetworkSynovaError, NotFoundSynovaError, Nullable, RateLimitSynovaError, SCHEMA_METADATA_KEYS, SchemaEnum, SchemaMax, SchemaMaxItems, SchemaMaxLength, SchemaMin, SchemaMinItems, SchemaMinLength, SchemaPattern, SchemaUniqueItems, ServerSynovaError, SynovaCloudSdk, SynovaError, TimeoutSynovaError, ValidationSynovaError };
|
|
629
1057
|
//# sourceMappingURL=index.js.map
|
|
630
1058
|
//# sourceMappingURL=index.js.map
|