@synova-cloud/sdk 1.9.2 → 2.0.1

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/dist/index.cjs CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- require('reflect-metadata');
4
-
5
3
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
6
4
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
7
5
  }) : x)(function(x) {
@@ -96,18 +94,9 @@ var ExecutionSynovaError = class extends SynovaError {
96
94
  this.details = error.details;
97
95
  }
98
96
  };
99
- var ValidationSynovaError = class extends SynovaError {
100
- violations;
101
- constructor(violations) {
102
- const message = `Validation failed: ${violations.map((v) => v.property).join(", ")}`;
103
- super(message);
104
- this.name = "ValidationSynovaError";
105
- this.violations = violations;
106
- }
107
- };
108
97
 
109
98
  // src/version.ts
110
- var SDK_VERSION = "1.9.2" ;
99
+ var SDK_VERSION = "2.0.1" ;
111
100
 
112
101
  // src/utils/http.ts
113
102
  var HttpClient = class {
@@ -318,465 +307,262 @@ var HttpClient = class {
318
307
  }
319
308
  };
320
309
 
321
- // src/schema/types.ts
322
- var SCHEMA_METADATA_KEYS = {
323
- // Metadata
324
- DESCRIPTION: "synova:schema:description",
325
- EXAMPLES: "synova:schema:examples",
326
- DEFAULT: "synova:schema:default",
327
- // Type helpers
328
- FORMAT: "synova:schema:format",
329
- ARRAY_ITEM_TYPE: "synova:schema:arrayItemType",
330
- NULLABLE: "synova:schema:nullable",
331
- ENUM: "synova:schema:enum",
332
- // String constraints
333
- MIN_LENGTH: "synova:schema:minLength",
334
- MAX_LENGTH: "synova:schema:maxLength",
335
- PATTERN: "synova:schema:pattern",
336
- // Number constraints
337
- MINIMUM: "synova:schema:minimum",
338
- MAXIMUM: "synova:schema:maximum",
339
- EXCLUSIVE_MINIMUM: "synova:schema:exclusiveMinimum",
340
- EXCLUSIVE_MAXIMUM: "synova:schema:exclusiveMaximum",
341
- MULTIPLE_OF: "synova:schema:multipleOf",
342
- // Array constraints
343
- MIN_ITEMS: "synova:schema:minItems",
344
- MAX_ITEMS: "synova:schema:maxItems",
345
- UNIQUE_ITEMS: "synova:schema:uniqueItems",
346
- // Object constraints
347
- ADDITIONAL_PROPERTIES: "synova:schema:additionalProperties"
310
+ // src/schema/adapters/zod.adapter.ts
311
+ var ZodAdapter = class {
312
+ canHandle(schema) {
313
+ if (typeof schema !== "object" || schema === null) return false;
314
+ const s = schema;
315
+ return typeof s._def === "object" && s._def !== null && typeof s._def.typeName === "string" && s._def.typeName.startsWith("Zod") && typeof s.safeParse === "function";
316
+ }
317
+ toJsonSchema(schema) {
318
+ try {
319
+ const { zodToJsonSchema } = __require("zod-to-json-schema");
320
+ const result = { ...zodToJsonSchema(schema, { $refStrategy: "none" }) };
321
+ delete result.$schema;
322
+ return result;
323
+ } catch (error) {
324
+ if (error.code === "MODULE_NOT_FOUND") {
325
+ throw new Error(
326
+ "zod-to-json-schema is required to convert Zod schemas. Install it with: npm install zod-to-json-schema"
327
+ );
328
+ }
329
+ throw new Error(`Failed to convert Zod schema: ${error.message}`);
330
+ }
331
+ }
348
332
  };
349
- function createMetadataDecorator(key, value) {
350
- return function(target, propertyKey) {
351
- Reflect.defineMetadata(key, value, target, propertyKey);
352
- };
353
- }
354
- function Description(description) {
355
- return createMetadataDecorator(SCHEMA_METADATA_KEYS.DESCRIPTION, description);
356
- }
357
- function Example(...examples) {
358
- return createMetadataDecorator(SCHEMA_METADATA_KEYS.EXAMPLES, examples);
359
- }
360
- function Default(value) {
361
- return createMetadataDecorator(SCHEMA_METADATA_KEYS.DEFAULT, value);
362
- }
363
- function ArrayItems(itemType) {
364
- return createMetadataDecorator(SCHEMA_METADATA_KEYS.ARRAY_ITEM_TYPE, itemType);
365
- }
366
- function Format(format) {
367
- return createMetadataDecorator(SCHEMA_METADATA_KEYS.FORMAT, format);
368
- }
369
- function Nullable() {
370
- return createMetadataDecorator(SCHEMA_METADATA_KEYS.NULLABLE, true);
371
- }
372
- function SchemaMinLength(length) {
373
- return createMetadataDecorator(SCHEMA_METADATA_KEYS.MIN_LENGTH, length);
374
- }
375
- function SchemaMaxLength(length) {
376
- return createMetadataDecorator(SCHEMA_METADATA_KEYS.MAX_LENGTH, length);
377
- }
378
- function SchemaPattern(pattern) {
379
- return createMetadataDecorator(SCHEMA_METADATA_KEYS.PATTERN, pattern);
380
- }
381
- function SchemaMin(value) {
382
- return createMetadataDecorator(SCHEMA_METADATA_KEYS.MINIMUM, value);
383
- }
384
- function SchemaMax(value) {
385
- return createMetadataDecorator(SCHEMA_METADATA_KEYS.MAXIMUM, value);
386
- }
387
- function ExclusiveMin(value) {
388
- return createMetadataDecorator(SCHEMA_METADATA_KEYS.EXCLUSIVE_MINIMUM, value);
389
- }
390
- function ExclusiveMax(value) {
391
- return createMetadataDecorator(SCHEMA_METADATA_KEYS.EXCLUSIVE_MAXIMUM, value);
392
- }
393
- function MultipleOf(value) {
394
- return createMetadataDecorator(SCHEMA_METADATA_KEYS.MULTIPLE_OF, value);
395
- }
396
- function SchemaMinItems(count) {
397
- return createMetadataDecorator(SCHEMA_METADATA_KEYS.MIN_ITEMS, count);
398
- }
399
- function SchemaMaxItems(count) {
400
- return createMetadataDecorator(SCHEMA_METADATA_KEYS.MAX_ITEMS, count);
401
- }
402
- function SchemaUniqueItems() {
403
- return createMetadataDecorator(SCHEMA_METADATA_KEYS.UNIQUE_ITEMS, true);
404
- }
405
- function SchemaEnum(values) {
406
- return createMetadataDecorator(SCHEMA_METADATA_KEYS.ENUM, values);
407
- }
408
- function AdditionalProperties(value = true) {
409
- return createMetadataDecorator(SCHEMA_METADATA_KEYS.ADDITIONAL_PROPERTIES, value);
410
- }
411
- function getSchemaMetadata(key, target, propertyKey) {
412
- return Reflect.getMetadata(key, target, propertyKey);
413
- }
414
333
 
415
- // src/schema/class-schema.ts
416
- var ClassSchema = class {
417
- /**
418
- * Generate JSON Schema from a class
419
- */
420
- static generate(targetClass, options = {}) {
421
- const { additionalProperties = false } = options;
422
- const properties = this.getProperties(targetClass);
423
- const required = this.getRequiredProperties(targetClass, properties);
424
- return {
425
- type: "object",
426
- properties,
427
- required: required.length > 0 ? required : void 0,
428
- additionalProperties
429
- };
334
+ // src/schema/adapters/yup.adapter.ts
335
+ var YupAdapter = class {
336
+ canHandle(schema) {
337
+ if (typeof schema !== "object" || schema === null) return false;
338
+ return schema.__isYupSchema__ === true;
430
339
  }
431
- /**
432
- * Get all properties with their schemas
433
- */
434
- static getProperties(targetClass) {
435
- const properties = {};
436
- const prototype = targetClass.prototype;
437
- const classValidatorProperties = this.getClassValidatorProperties(targetClass);
438
- const decoratorProperties = this.getDecoratorProperties(prototype);
439
- const allProperties = /* @__PURE__ */ new Set([...classValidatorProperties, ...decoratorProperties]);
440
- for (const propertyName of allProperties) {
441
- properties[propertyName] = this.getPropertySchema(targetClass, propertyName);
340
+ toJsonSchema(schema) {
341
+ try {
342
+ const { convertSchema } = __require("@sodaru/yup-to-json-schema");
343
+ return convertSchema(schema);
344
+ } catch (error) {
345
+ if (error.code === "MODULE_NOT_FOUND") {
346
+ throw new Error(
347
+ "@sodaru/yup-to-json-schema is required to convert Yup schemas. Install it with: npm install @sodaru/yup-to-json-schema"
348
+ );
349
+ }
350
+ throw new Error(`Failed to convert Yup schema: ${error.message}`);
442
351
  }
443
- return properties;
444
352
  }
445
- /**
446
- * Get property names from class-validator metadata
447
- */
448
- static getClassValidatorProperties(targetClass) {
353
+ };
354
+
355
+ // src/schema/adapters/joi.adapter.ts
356
+ var JoiAdapter = class {
357
+ canHandle(schema) {
358
+ if (typeof schema !== "object" || schema === null) return false;
449
359
  try {
450
- const { getMetadataStorage } = __require("class-validator");
451
- const metadataStorage = getMetadataStorage();
452
- const targetMetadatas = metadataStorage.getTargetValidationMetadatas(
453
- targetClass,
454
- "",
455
- true,
456
- false
457
- );
458
- const propertyNames = targetMetadatas.map((m) => m.propertyName);
459
- return [...new Set(propertyNames)];
360
+ const { isSchema } = __require("joi");
361
+ return isSchema(schema);
460
362
  } catch {
461
- return [];
363
+ return false;
462
364
  }
463
365
  }
464
- /**
465
- * Get property names from our decorator metadata
466
- */
467
- static getDecoratorProperties(prototype) {
468
- const properties = [];
469
- const ownKeys = Reflect.ownKeys(prototype);
470
- for (const key of ownKeys) {
471
- if (typeof key === "string" && key !== "constructor") {
472
- for (const metaKey of Object.values(SCHEMA_METADATA_KEYS)) {
473
- if (Reflect.hasMetadata(metaKey, prototype, key)) {
474
- properties.push(key);
475
- break;
476
- }
477
- }
366
+ toJsonSchema(schema) {
367
+ try {
368
+ const joiToJson = __require("joi-to-json");
369
+ return joiToJson(schema);
370
+ } catch (error) {
371
+ if (error.code === "MODULE_NOT_FOUND") {
372
+ throw new Error(
373
+ "joi-to-json is required to convert Joi schemas. Install it with: npm install joi-to-json"
374
+ );
478
375
  }
376
+ throw new Error(`Failed to convert Joi schema: ${error.message}`);
479
377
  }
480
- return properties;
481
378
  }
482
- /**
483
- * Get JSON Schema for a single property
484
- */
485
- static getPropertySchema(targetClass, propertyName) {
486
- const prototype = targetClass.prototype;
487
- const schema = {};
488
- const designType = Reflect.getMetadata("design:type", prototype, propertyName);
489
- const baseSchema = this.getBaseTypeSchema(designType, targetClass, propertyName);
490
- Object.assign(schema, baseSchema);
491
- this.applyClassValidatorConstraints(schema, targetClass, propertyName);
492
- this.applyDecoratorMetadata(schema, prototype, propertyName);
493
- const isNullable = getSchemaMetadata(
494
- SCHEMA_METADATA_KEYS.NULLABLE,
495
- prototype,
496
- propertyName
497
- );
498
- if (isNullable && schema.type && typeof schema.type === "string") {
499
- schema.type = [schema.type, "null"];
379
+ };
380
+
381
+ // src/schema/adapters/json-schema.adapter.ts
382
+ var JsonSchemaAdapter = class _JsonSchemaAdapter {
383
+ static VALID_JSON_SCHEMA_TYPES = [
384
+ "string",
385
+ "number",
386
+ "integer",
387
+ "boolean",
388
+ "object",
389
+ "array",
390
+ "null"
391
+ ];
392
+ canHandle(schema) {
393
+ if (typeof schema !== "object" || schema === null) {
394
+ return false;
395
+ }
396
+ const obj = schema;
397
+ if ("type" in obj) {
398
+ const type = obj.type;
399
+ if (typeof type === "string" && _JsonSchemaAdapter.VALID_JSON_SCHEMA_TYPES.includes(type)) {
400
+ return true;
401
+ }
402
+ if (Array.isArray(type) && type.every((t) => _JsonSchemaAdapter.VALID_JSON_SCHEMA_TYPES.includes(t))) {
403
+ return true;
404
+ }
405
+ }
406
+ if ("properties" in obj && typeof obj.properties === "object" && obj.properties !== null && !Array.isArray(obj.properties)) {
407
+ return true;
500
408
  }
501
- return schema;
409
+ if ("items" in obj && typeof obj.items === "object" && obj.items !== null && !Array.isArray(obj.items)) {
410
+ return true;
411
+ }
412
+ if ("anyOf" in obj && Array.isArray(obj.anyOf)) return true;
413
+ if ("oneOf" in obj && Array.isArray(obj.oneOf)) return true;
414
+ if ("allOf" in obj && Array.isArray(obj.allOf)) return true;
415
+ if ("enum" in obj && Array.isArray(obj.enum)) return true;
416
+ return false;
417
+ }
418
+ toJsonSchema(schema) {
419
+ return this.transformNullable(schema);
502
420
  }
503
421
  /**
504
- * Get base schema from TypeScript type
422
+ * Recursively transform `nullable: true` to `type: ["...", "null"]`
505
423
  */
506
- static getBaseTypeSchema(designType, targetClass, propertyName) {
507
- if (designType === String) {
508
- return { type: "string" };
509
- }
510
- if (designType === Number) {
511
- return { type: "number" };
512
- }
513
- if (designType === Boolean) {
514
- return { type: "boolean" };
515
- }
516
- if (designType === Array) {
517
- const itemType = getSchemaMetadata(
518
- SCHEMA_METADATA_KEYS.ARRAY_ITEM_TYPE,
519
- targetClass.prototype,
520
- propertyName
424
+ transformNullable(schema) {
425
+ const result = { ...schema };
426
+ const schemaWithNullable = schema;
427
+ if (schemaWithNullable.nullable === true && result.type) {
428
+ if (typeof result.type === "string") {
429
+ result.type = [result.type, "null"];
430
+ } else if (Array.isArray(result.type) && !result.type.includes("null")) {
431
+ result.type = [...result.type, "null"];
432
+ }
433
+ delete result.nullable;
434
+ }
435
+ if (result.properties) {
436
+ result.properties = Object.fromEntries(
437
+ Object.entries(result.properties).map(([key, value]) => [
438
+ key,
439
+ this.transformNullable(value)
440
+ ])
521
441
  );
522
- return {
523
- type: "array",
524
- items: this.getArrayItemSchema(itemType)
525
- };
526
442
  }
527
- if (designType === Object) {
528
- return { type: "object" };
443
+ if (result.items) {
444
+ result.items = this.transformNullable(result.items);
529
445
  }
530
- if (typeof designType === "function" && designType.prototype) {
531
- return this.generate(designType);
446
+ if (result.additionalProperties && typeof result.additionalProperties === "object") {
447
+ result.additionalProperties = this.transformNullable(result.additionalProperties);
532
448
  }
533
- return { type: "string" };
534
- }
535
- /**
536
- * Get schema for array items
537
- */
538
- static getArrayItemSchema(itemType) {
539
- if (!itemType) {
540
- return { type: "string" };
449
+ if (result.allOf) {
450
+ result.allOf = result.allOf.map((s) => this.transformNullable(s));
541
451
  }
542
- if (itemType === String) {
543
- return { type: "string" };
452
+ if (result.anyOf) {
453
+ result.anyOf = result.anyOf.map((s) => this.transformNullable(s));
544
454
  }
545
- if (itemType === Number) {
546
- return { type: "number" };
455
+ if (result.oneOf) {
456
+ result.oneOf = result.oneOf.map((s) => this.transformNullable(s));
547
457
  }
548
- if (itemType === Boolean) {
549
- return { type: "boolean" };
458
+ if (result.not) {
459
+ result.not = this.transformNullable(result.not);
550
460
  }
551
- return this.generate(itemType);
461
+ return result;
552
462
  }
463
+ };
464
+
465
+ // src/schema/resolver.ts
466
+ var SchemaResolver = class {
467
+ static adapters = [
468
+ // Order matters: Zod → Yup → Joi → JsonSchema (fallback)
469
+ new ZodAdapter(),
470
+ new YupAdapter(),
471
+ new JoiAdapter(),
472
+ new JsonSchemaAdapter()
473
+ ];
553
474
  /**
554
- * Apply class-validator constraints to schema
475
+ * Register a custom adapter.
476
+ *
477
+ * @param adapter - The adapter to register
478
+ * @param position - Where to insert: 'first' adds at the beginning,
479
+ * 'last' adds before JsonSchemaAdapter (fallback)
480
+ *
481
+ * @example
482
+ * ```typescript
483
+ * SchemaResolver.registerAdapter(new MyCustomAdapter(), 'first');
484
+ * ```
555
485
  */
556
- static applyClassValidatorConstraints(schema, targetClass, propertyName) {
557
- try {
558
- const { getMetadataStorage } = __require("class-validator");
559
- const metadataStorage = getMetadataStorage();
560
- const targetMetadatas = metadataStorage.getTargetValidationMetadatas(
561
- targetClass,
562
- "",
563
- true,
564
- false
565
- );
566
- const propertyMetadatas = targetMetadatas.filter(
567
- (m) => m.propertyName === propertyName
568
- );
569
- for (const metadata of propertyMetadatas) {
570
- this.applyValidationConstraint(schema, metadata);
571
- }
572
- } catch {
486
+ static registerAdapter(adapter, position = "first") {
487
+ if (position === "first") {
488
+ this.adapters.unshift(adapter);
489
+ } else {
490
+ this.adapters.splice(-1, 0, adapter);
573
491
  }
574
492
  }
575
493
  /**
576
- * Apply a single class-validator constraint
494
+ * Reset adapters to default configuration.
495
+ * Removes all custom adapters.
577
496
  */
578
- static applyValidationConstraint(schema, metadata) {
579
- const constraintType = metadata.name || metadata.type || "";
580
- const constraints = metadata.constraints || [];
581
- switch (constraintType) {
582
- case "isString":
583
- schema.type = "string";
584
- break;
585
- case "isNumber":
586
- case "isInt":
587
- schema.type = constraintType === "isInt" ? "integer" : "number";
588
- break;
589
- case "isBoolean":
590
- schema.type = "boolean";
591
- break;
592
- case "isArray":
593
- schema.type = "array";
594
- break;
595
- case "isEnum":
596
- if (constraints[0]) {
597
- schema.enum = Object.values(constraints[0]);
598
- }
599
- break;
600
- case "minLength":
601
- schema.minLength = constraints[0];
602
- break;
603
- case "maxLength":
604
- schema.maxLength = constraints[0];
605
- break;
606
- case "min":
607
- schema.minimum = constraints[0];
608
- break;
609
- case "max":
610
- schema.maximum = constraints[0];
611
- break;
612
- case "isEmail":
613
- schema.format = "email";
614
- break;
615
- case "isUrl":
616
- case "isURL":
617
- schema.format = "uri";
618
- break;
619
- case "isUUID":
620
- schema.format = "uuid";
621
- break;
622
- case "isDateString":
623
- case "isISO8601":
624
- schema.format = "date-time";
625
- break;
626
- case "matches":
627
- if (constraints[0] instanceof RegExp) {
628
- schema.pattern = constraints[0].source;
629
- } else if (typeof constraints[0] === "string") {
630
- schema.pattern = constraints[0];
631
- }
632
- break;
633
- case "arrayMinSize":
634
- schema.minItems = constraints[0];
635
- break;
636
- case "arrayMaxSize":
637
- schema.maxItems = constraints[0];
638
- break;
639
- case "arrayUnique":
640
- schema.uniqueItems = true;
641
- break;
642
- }
497
+ static resetAdapters() {
498
+ this.adapters = [new ZodAdapter(), new YupAdapter(), new JoiAdapter(), new JsonSchemaAdapter()];
643
499
  }
644
500
  /**
645
- * Apply our decorator metadata to schema.
646
- * Our decorators take precedence over class-validator if both are used.
501
+ * Resolve a schema input to JSON Schema format.
502
+ *
503
+ * @param schema - Schema from Zod, Yup, Joi, or raw JSON Schema
504
+ * @returns JSON Schema representation
505
+ * @throws Error if schema type is not supported
506
+ *
507
+ * @example
508
+ * ```typescript
509
+ * // Zod
510
+ * const zodSchema = z.object({ title: z.string() });
511
+ * const jsonSchema = SchemaResolver.resolve(zodSchema);
512
+ *
513
+ * // Yup
514
+ * const yupSchema = yup.object({ title: yup.string().required() });
515
+ * const jsonSchema = SchemaResolver.resolve(yupSchema);
516
+ *
517
+ * // Joi
518
+ * const joiSchema = Joi.object({ title: Joi.string() });
519
+ * const jsonSchema = SchemaResolver.resolve(joiSchema);
520
+ *
521
+ * // Raw JSON Schema (passthrough)
522
+ * const rawSchema = { type: 'object', properties: { title: { type: 'string' } } };
523
+ * const jsonSchema = SchemaResolver.resolve(rawSchema);
524
+ * ```
647
525
  */
648
- static applyDecoratorMetadata(schema, prototype, propertyName) {
649
- const description = getSchemaMetadata(
650
- SCHEMA_METADATA_KEYS.DESCRIPTION,
651
- prototype,
652
- propertyName
653
- );
654
- if (description) schema.description = description;
655
- const examples = getSchemaMetadata(
656
- SCHEMA_METADATA_KEYS.EXAMPLES,
657
- prototype,
658
- propertyName
659
- );
660
- if (examples) schema.examples = examples;
661
- const defaultValue = getSchemaMetadata(
662
- SCHEMA_METADATA_KEYS.DEFAULT,
663
- prototype,
664
- propertyName
665
- );
666
- if (defaultValue !== void 0) schema.default = defaultValue;
667
- const format = getSchemaMetadata(SCHEMA_METADATA_KEYS.FORMAT, prototype, propertyName);
668
- if (format) schema.format = format;
669
- const enumValues = getSchemaMetadata(
670
- SCHEMA_METADATA_KEYS.ENUM,
671
- prototype,
672
- propertyName
673
- );
674
- if (enumValues) schema.enum = enumValues;
675
- const minLength = getSchemaMetadata(
676
- SCHEMA_METADATA_KEYS.MIN_LENGTH,
677
- prototype,
678
- propertyName
679
- );
680
- if (minLength !== void 0) schema.minLength = minLength;
681
- const maxLength = getSchemaMetadata(
682
- SCHEMA_METADATA_KEYS.MAX_LENGTH,
683
- prototype,
684
- propertyName
685
- );
686
- if (maxLength !== void 0) schema.maxLength = maxLength;
687
- const pattern = getSchemaMetadata(
688
- SCHEMA_METADATA_KEYS.PATTERN,
689
- prototype,
690
- propertyName
691
- );
692
- if (pattern) schema.pattern = pattern;
693
- const minimum = getSchemaMetadata(
694
- SCHEMA_METADATA_KEYS.MINIMUM,
695
- prototype,
696
- propertyName
697
- );
698
- if (minimum !== void 0) schema.minimum = minimum;
699
- const maximum = getSchemaMetadata(
700
- SCHEMA_METADATA_KEYS.MAXIMUM,
701
- prototype,
702
- propertyName
703
- );
704
- if (maximum !== void 0) schema.maximum = maximum;
705
- const exclusiveMinimum = getSchemaMetadata(
706
- SCHEMA_METADATA_KEYS.EXCLUSIVE_MINIMUM,
707
- prototype,
708
- propertyName
709
- );
710
- if (exclusiveMinimum !== void 0) schema.exclusiveMinimum = exclusiveMinimum;
711
- const exclusiveMaximum = getSchemaMetadata(
712
- SCHEMA_METADATA_KEYS.EXCLUSIVE_MAXIMUM,
713
- prototype,
714
- propertyName
715
- );
716
- if (exclusiveMaximum !== void 0) schema.exclusiveMaximum = exclusiveMaximum;
717
- const multipleOf = getSchemaMetadata(
718
- SCHEMA_METADATA_KEYS.MULTIPLE_OF,
719
- prototype,
720
- propertyName
721
- );
722
- if (multipleOf !== void 0) schema.multipleOf = multipleOf;
723
- const minItems = getSchemaMetadata(
724
- SCHEMA_METADATA_KEYS.MIN_ITEMS,
725
- prototype,
726
- propertyName
727
- );
728
- if (minItems !== void 0) schema.minItems = minItems;
729
- const maxItems = getSchemaMetadata(
730
- SCHEMA_METADATA_KEYS.MAX_ITEMS,
731
- prototype,
732
- propertyName
733
- );
734
- if (maxItems !== void 0) schema.maxItems = maxItems;
735
- const uniqueItems = getSchemaMetadata(
736
- SCHEMA_METADATA_KEYS.UNIQUE_ITEMS,
737
- prototype,
738
- propertyName
739
- );
740
- if (uniqueItems) schema.uniqueItems = uniqueItems;
741
- const additionalProperties = getSchemaMetadata(
742
- SCHEMA_METADATA_KEYS.ADDITIONAL_PROPERTIES,
743
- prototype,
744
- propertyName
745
- );
746
- if (additionalProperties !== void 0) {
747
- if (schema.type === "array" && schema.items) {
748
- schema.items.additionalProperties = additionalProperties;
749
- } else {
750
- schema.additionalProperties = additionalProperties;
526
+ static resolve(schema) {
527
+ for (const adapter of this.adapters) {
528
+ if (adapter.canHandle(schema)) {
529
+ return adapter.toJsonSchema(schema);
751
530
  }
752
531
  }
532
+ throw new Error(
533
+ "Unsupported schema type. Supported types: Zod, Yup, Joi, or raw JSON Schema object."
534
+ );
753
535
  }
754
536
  /**
755
- * Get required properties (properties without @IsOptional)
537
+ * Check if a schema is supported.
538
+ *
539
+ * @param schema - Schema to check
540
+ * @returns true if the schema is supported
756
541
  */
757
- static getRequiredProperties(targetClass, properties) {
758
- const required = [];
759
- try {
760
- const { getMetadataStorage } = __require("class-validator");
761
- const metadataStorage = getMetadataStorage();
762
- const targetMetadatas = metadataStorage.getTargetValidationMetadatas(
763
- targetClass,
764
- "",
765
- true,
766
- false
767
- );
768
- for (const propertyName of Object.keys(properties)) {
769
- const isOptional = targetMetadatas.some(
770
- (m) => m.propertyName === propertyName && (m.type === "isOptional" || m.type === "conditionalValidation")
771
- );
772
- if (!isOptional) {
773
- required.push(propertyName);
774
- }
775
- }
776
- } catch {
777
- required.push(...Object.keys(properties));
542
+ static isSupported(schema) {
543
+ return this.adapters.some((adapter) => adapter.canHandle(schema));
544
+ }
545
+ /**
546
+ * Get the type of a schema.
547
+ *
548
+ * @param schema - Schema to identify
549
+ * @returns Schema type identifier
550
+ */
551
+ static getSchemaType(schema) {
552
+ const adapters = this.adapters;
553
+ if (adapters[0].canHandle(schema)) {
554
+ return "zod";
555
+ }
556
+ if (adapters[1].canHandle(schema)) {
557
+ return "yup";
778
558
  }
779
- return required;
559
+ if (adapters[2].canHandle(schema)) {
560
+ return "joi";
561
+ }
562
+ if (adapters[3].canHandle(schema)) {
563
+ return "json-schema";
564
+ }
565
+ return "unknown";
780
566
  }
781
567
  };
782
568
 
@@ -808,22 +594,6 @@ var PromptsResource = class {
808
594
  });
809
595
  }
810
596
  async execute(promptId, options) {
811
- if ("responseClass" in options && options.responseClass) {
812
- return this.executeTyped(promptId, options);
813
- }
814
- return this.executeRaw(promptId, options);
815
- }
816
- async executeByTag(promptId, tag, options) {
817
- return this.execute(promptId, { ...options, tag });
818
- }
819
- async executeByVersion(promptId, version, options) {
820
- return this.execute(promptId, { ...options, version });
821
- }
822
- /**
823
- * Execute raw request without typed response
824
- * @throws {ExecutionSynovaError} If LLM returns an error
825
- */
826
- async executeRaw(promptId, options) {
827
597
  const body = {
828
598
  provider: options.provider,
829
599
  model: options.model
@@ -836,8 +606,10 @@ var PromptsResource = class {
836
606
  if (options.version !== void 0) body.version = options.version;
837
607
  if (options.metadata !== void 0) body.metadata = options.metadata;
838
608
  if (options.parameters !== void 0) body.parameters = options.parameters;
839
- if (options.responseSchema !== void 0) body.responseSchema = options.responseSchema;
840
609
  if (options.sessionId !== void 0) body.sessionId = options.sessionId;
610
+ if (options.responseSchema !== void 0) {
611
+ body.responseSchema = SchemaResolver.resolve(options.responseSchema);
612
+ }
841
613
  const response = await this.http.request({
842
614
  method: "POST",
843
615
  path: `/api/v1/prompts/${promptId}/run`,
@@ -846,51 +618,19 @@ var PromptsResource = class {
846
618
  if (response.type === "error" && response.error) {
847
619
  throw new ExecutionSynovaError(response.error);
848
620
  }
621
+ if (options.responseSchema !== void 0) {
622
+ if (response.object === void 0) {
623
+ throw new Error("Expected structured response but received undefined");
624
+ }
625
+ return response;
626
+ }
849
627
  return response;
850
628
  }
851
- /**
852
- * Execute with typed response class
853
- */
854
- async executeTyped(promptId, options) {
855
- const { responseClass, validate = true, ...executeOptions } = options;
856
- const responseSchema = ClassSchema.generate(responseClass);
857
- const response = await this.executeRaw(promptId, {
858
- ...executeOptions,
859
- responseSchema
860
- });
861
- const object = response.object;
862
- if (validate) {
863
- await this.validateObject(object, responseClass);
864
- }
865
- return object;
629
+ async executeByTag(promptId, tag, options) {
630
+ return this.execute(promptId, { ...options, tag });
866
631
  }
867
- /**
868
- * Validate object using class-validator
869
- */
870
- async validateObject(object, responseClass) {
871
- try {
872
- const { plainToInstance } = __require("class-transformer");
873
- const { validate } = __require("class-validator");
874
- const instance = plainToInstance(responseClass, object);
875
- const errors = await validate(instance);
876
- if (errors.length > 0) {
877
- const violations = errors.map(
878
- (error) => ({
879
- property: error.property,
880
- constraints: error.constraints || {},
881
- value: error.value
882
- })
883
- );
884
- throw new ValidationSynovaError(violations);
885
- }
886
- } catch (error) {
887
- if (error instanceof ValidationSynovaError) {
888
- throw error;
889
- }
890
- console.warn(
891
- "[Synova SDK] Validation skipped: class-validator or class-transformer not installed. Install them with: npm install class-validator class-transformer"
892
- );
893
- }
632
+ async executeByVersion(promptId, version, options) {
633
+ return this.execute(promptId, { ...options, version });
894
634
  }
895
635
  };
896
636
 
@@ -1206,37 +946,20 @@ var SynovaCloudSdk = class {
1206
946
  }
1207
947
  };
1208
948
 
1209
- exports.AdditionalProperties = AdditionalProperties;
1210
949
  exports.ApiSynovaError = ApiSynovaError;
1211
- exports.ArrayItems = ArrayItems;
1212
950
  exports.AuthSynovaError = AuthSynovaError;
1213
- exports.ClassSchema = ClassSchema;
1214
- exports.Default = Default;
1215
- exports.Description = Description;
1216
- exports.Example = Example;
1217
- exports.ExclusiveMax = ExclusiveMax;
1218
- exports.ExclusiveMin = ExclusiveMin;
1219
951
  exports.ExecutionSynovaError = ExecutionSynovaError;
1220
- exports.Format = Format;
1221
- exports.MultipleOf = MultipleOf;
952
+ exports.JoiAdapter = JoiAdapter;
953
+ exports.JsonSchemaAdapter = JsonSchemaAdapter;
1222
954
  exports.NetworkSynovaError = NetworkSynovaError;
1223
955
  exports.NotFoundSynovaError = NotFoundSynovaError;
1224
- exports.Nullable = Nullable;
1225
956
  exports.RateLimitSynovaError = RateLimitSynovaError;
1226
- exports.SCHEMA_METADATA_KEYS = SCHEMA_METADATA_KEYS;
1227
- exports.SchemaEnum = SchemaEnum;
1228
- exports.SchemaMax = SchemaMax;
1229
- exports.SchemaMaxItems = SchemaMaxItems;
1230
- exports.SchemaMaxLength = SchemaMaxLength;
1231
- exports.SchemaMin = SchemaMin;
1232
- exports.SchemaMinItems = SchemaMinItems;
1233
- exports.SchemaMinLength = SchemaMinLength;
1234
- exports.SchemaPattern = SchemaPattern;
1235
- exports.SchemaUniqueItems = SchemaUniqueItems;
957
+ exports.SchemaResolver = SchemaResolver;
1236
958
  exports.ServerSynovaError = ServerSynovaError;
1237
959
  exports.SynovaCloudSdk = SynovaCloudSdk;
1238
960
  exports.SynovaError = SynovaError;
1239
961
  exports.TimeoutSynovaError = TimeoutSynovaError;
1240
- exports.ValidationSynovaError = ValidationSynovaError;
962
+ exports.YupAdapter = YupAdapter;
963
+ exports.ZodAdapter = ZodAdapter;
1241
964
  //# sourceMappingURL=index.cjs.map
1242
965
  //# sourceMappingURL=index.cjs.map