@synova-cloud/sdk 1.9.1 → 2.0.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/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.1" ;
99
+ var SDK_VERSION = "2.0.0" ;
111
100
 
112
101
  // src/utils/http.ts
113
102
  var HttpClient = class {
@@ -318,462 +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 getSchemaMetadata(key, target, propertyKey) {
409
- return Reflect.getMetadata(key, target, propertyKey);
410
- }
411
333
 
412
- // src/schema/class-schema.ts
413
- var ClassSchema = class {
414
- /**
415
- * Generate JSON Schema from a class
416
- */
417
- static generate(targetClass, options = {}) {
418
- const { additionalProperties = false } = options;
419
- const properties = this.getProperties(targetClass);
420
- const required = this.getRequiredProperties(targetClass, properties);
421
- return {
422
- type: "object",
423
- properties,
424
- required: required.length > 0 ? required : void 0,
425
- additionalProperties
426
- };
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;
427
339
  }
428
- /**
429
- * Get all properties with their schemas
430
- */
431
- static getProperties(targetClass) {
432
- const properties = {};
433
- const prototype = targetClass.prototype;
434
- const classValidatorProperties = this.getClassValidatorProperties(targetClass);
435
- const decoratorProperties = this.getDecoratorProperties(prototype);
436
- const allProperties = /* @__PURE__ */ new Set([...classValidatorProperties, ...decoratorProperties]);
437
- for (const propertyName of allProperties) {
438
- 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}`);
439
351
  }
440
- return properties;
441
352
  }
442
- /**
443
- * Get property names from class-validator metadata
444
- */
445
- 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;
446
359
  try {
447
- const { getMetadataStorage } = __require("class-validator");
448
- const metadataStorage = getMetadataStorage();
449
- const targetMetadatas = metadataStorage.getTargetValidationMetadatas(
450
- targetClass,
451
- "",
452
- true,
453
- false
454
- );
455
- const propertyNames = targetMetadatas.map((m) => m.propertyName);
456
- return [...new Set(propertyNames)];
360
+ const { isSchema } = __require("joi");
361
+ return isSchema(schema);
457
362
  } catch {
458
- return [];
363
+ return false;
459
364
  }
460
365
  }
461
- /**
462
- * Get property names from our decorator metadata
463
- */
464
- static getDecoratorProperties(prototype) {
465
- const properties = [];
466
- const ownKeys = Reflect.ownKeys(prototype);
467
- for (const key of ownKeys) {
468
- if (typeof key === "string" && key !== "constructor") {
469
- for (const metaKey of Object.values(SCHEMA_METADATA_KEYS)) {
470
- if (Reflect.hasMetadata(metaKey, prototype, key)) {
471
- properties.push(key);
472
- break;
473
- }
474
- }
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
+ );
475
375
  }
376
+ throw new Error(`Failed to convert Joi schema: ${error.message}`);
476
377
  }
477
- return properties;
478
378
  }
479
- /**
480
- * Get JSON Schema for a single property
481
- */
482
- static getPropertySchema(targetClass, propertyName) {
483
- const prototype = targetClass.prototype;
484
- const schema = {};
485
- const designType = Reflect.getMetadata("design:type", prototype, propertyName);
486
- const baseSchema = this.getBaseTypeSchema(designType, targetClass, propertyName);
487
- Object.assign(schema, baseSchema);
488
- this.applyClassValidatorConstraints(schema, targetClass, propertyName);
489
- this.applyDecoratorMetadata(schema, prototype, propertyName);
490
- const isNullable = getSchemaMetadata(
491
- SCHEMA_METADATA_KEYS.NULLABLE,
492
- prototype,
493
- propertyName
494
- );
495
- if (isNullable && schema.type && typeof schema.type === "string") {
496
- 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;
497
408
  }
498
- 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);
499
420
  }
500
421
  /**
501
- * Get base schema from TypeScript type
422
+ * Recursively transform `nullable: true` to `type: ["...", "null"]`
502
423
  */
503
- static getBaseTypeSchema(designType, targetClass, propertyName) {
504
- if (designType === String) {
505
- return { type: "string" };
506
- }
507
- if (designType === Number) {
508
- return { type: "number" };
509
- }
510
- if (designType === Boolean) {
511
- return { type: "boolean" };
512
- }
513
- if (designType === Array) {
514
- const itemType = getSchemaMetadata(
515
- SCHEMA_METADATA_KEYS.ARRAY_ITEM_TYPE,
516
- targetClass.prototype,
517
- 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
+ ])
518
441
  );
519
- return {
520
- type: "array",
521
- items: this.getArrayItemSchema(itemType)
522
- };
523
442
  }
524
- if (designType === Object) {
525
- return { type: "object" };
443
+ if (result.items) {
444
+ result.items = this.transformNullable(result.items);
526
445
  }
527
- if (typeof designType === "function" && designType.prototype) {
528
- return this.generate(designType);
446
+ if (result.additionalProperties && typeof result.additionalProperties === "object") {
447
+ result.additionalProperties = this.transformNullable(result.additionalProperties);
529
448
  }
530
- return { type: "string" };
531
- }
532
- /**
533
- * Get schema for array items
534
- */
535
- static getArrayItemSchema(itemType) {
536
- if (!itemType) {
537
- return { type: "string" };
449
+ if (result.allOf) {
450
+ result.allOf = result.allOf.map((s) => this.transformNullable(s));
538
451
  }
539
- if (itemType === String) {
540
- return { type: "string" };
452
+ if (result.anyOf) {
453
+ result.anyOf = result.anyOf.map((s) => this.transformNullable(s));
541
454
  }
542
- if (itemType === Number) {
543
- return { type: "number" };
455
+ if (result.oneOf) {
456
+ result.oneOf = result.oneOf.map((s) => this.transformNullable(s));
544
457
  }
545
- if (itemType === Boolean) {
546
- return { type: "boolean" };
458
+ if (result.not) {
459
+ result.not = this.transformNullable(result.not);
547
460
  }
548
- return this.generate(itemType);
461
+ return result;
549
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
+ ];
550
474
  /**
551
- * 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
+ * ```
552
485
  */
553
- static applyClassValidatorConstraints(schema, targetClass, propertyName) {
554
- try {
555
- const { getMetadataStorage } = __require("class-validator");
556
- const metadataStorage = getMetadataStorage();
557
- const targetMetadatas = metadataStorage.getTargetValidationMetadatas(
558
- targetClass,
559
- "",
560
- true,
561
- false
562
- );
563
- const propertyMetadatas = targetMetadatas.filter(
564
- (m) => m.propertyName === propertyName
565
- );
566
- for (const metadata of propertyMetadatas) {
567
- this.applyValidationConstraint(schema, metadata);
568
- }
569
- } 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);
570
491
  }
571
492
  }
572
493
  /**
573
- * Apply a single class-validator constraint
494
+ * Reset adapters to default configuration.
495
+ * Removes all custom adapters.
574
496
  */
575
- static applyValidationConstraint(schema, metadata) {
576
- const constraintType = metadata.name || metadata.type || "";
577
- const constraints = metadata.constraints || [];
578
- switch (constraintType) {
579
- case "isString":
580
- schema.type = "string";
581
- break;
582
- case "isNumber":
583
- case "isInt":
584
- schema.type = constraintType === "isInt" ? "integer" : "number";
585
- break;
586
- case "isBoolean":
587
- schema.type = "boolean";
588
- break;
589
- case "isArray":
590
- schema.type = "array";
591
- break;
592
- case "isEnum":
593
- if (constraints[0]) {
594
- schema.enum = Object.values(constraints[0]);
595
- }
596
- break;
597
- case "minLength":
598
- schema.minLength = constraints[0];
599
- break;
600
- case "maxLength":
601
- schema.maxLength = constraints[0];
602
- break;
603
- case "min":
604
- schema.minimum = constraints[0];
605
- break;
606
- case "max":
607
- schema.maximum = constraints[0];
608
- break;
609
- case "isEmail":
610
- schema.format = "email";
611
- break;
612
- case "isUrl":
613
- case "isURL":
614
- schema.format = "uri";
615
- break;
616
- case "isUUID":
617
- schema.format = "uuid";
618
- break;
619
- case "isDateString":
620
- case "isISO8601":
621
- schema.format = "date-time";
622
- break;
623
- case "matches":
624
- if (constraints[0] instanceof RegExp) {
625
- schema.pattern = constraints[0].source;
626
- } else if (typeof constraints[0] === "string") {
627
- schema.pattern = constraints[0];
628
- }
629
- break;
630
- case "arrayMinSize":
631
- schema.minItems = constraints[0];
632
- break;
633
- case "arrayMaxSize":
634
- schema.maxItems = constraints[0];
635
- break;
636
- case "arrayUnique":
637
- schema.uniqueItems = true;
638
- break;
639
- }
497
+ static resetAdapters() {
498
+ this.adapters = [new ZodAdapter(), new YupAdapter(), new JoiAdapter(), new JsonSchemaAdapter()];
640
499
  }
641
500
  /**
642
- * Apply our decorator metadata to schema.
643
- * 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
+ * ```
644
525
  */
645
- static applyDecoratorMetadata(schema, prototype, propertyName) {
646
- const description = getSchemaMetadata(
647
- SCHEMA_METADATA_KEYS.DESCRIPTION,
648
- prototype,
649
- propertyName
650
- );
651
- if (description) schema.description = description;
652
- const examples = getSchemaMetadata(
653
- SCHEMA_METADATA_KEYS.EXAMPLES,
654
- prototype,
655
- propertyName
656
- );
657
- if (examples) schema.examples = examples;
658
- const defaultValue = getSchemaMetadata(
659
- SCHEMA_METADATA_KEYS.DEFAULT,
660
- prototype,
661
- propertyName
662
- );
663
- if (defaultValue !== void 0) schema.default = defaultValue;
664
- const format = getSchemaMetadata(SCHEMA_METADATA_KEYS.FORMAT, prototype, propertyName);
665
- if (format) schema.format = format;
666
- const enumValues = getSchemaMetadata(
667
- SCHEMA_METADATA_KEYS.ENUM,
668
- prototype,
669
- propertyName
670
- );
671
- if (enumValues) schema.enum = enumValues;
672
- const minLength = getSchemaMetadata(
673
- SCHEMA_METADATA_KEYS.MIN_LENGTH,
674
- prototype,
675
- propertyName
676
- );
677
- if (minLength !== void 0) schema.minLength = minLength;
678
- const maxLength = getSchemaMetadata(
679
- SCHEMA_METADATA_KEYS.MAX_LENGTH,
680
- prototype,
681
- propertyName
682
- );
683
- if (maxLength !== void 0) schema.maxLength = maxLength;
684
- const pattern = getSchemaMetadata(
685
- SCHEMA_METADATA_KEYS.PATTERN,
686
- prototype,
687
- propertyName
688
- );
689
- if (pattern) schema.pattern = pattern;
690
- const minimum = getSchemaMetadata(
691
- SCHEMA_METADATA_KEYS.MINIMUM,
692
- prototype,
693
- propertyName
694
- );
695
- if (minimum !== void 0) schema.minimum = minimum;
696
- const maximum = getSchemaMetadata(
697
- SCHEMA_METADATA_KEYS.MAXIMUM,
698
- prototype,
699
- propertyName
700
- );
701
- if (maximum !== void 0) schema.maximum = maximum;
702
- const exclusiveMinimum = getSchemaMetadata(
703
- SCHEMA_METADATA_KEYS.EXCLUSIVE_MINIMUM,
704
- prototype,
705
- propertyName
706
- );
707
- if (exclusiveMinimum !== void 0) schema.exclusiveMinimum = exclusiveMinimum;
708
- const exclusiveMaximum = getSchemaMetadata(
709
- SCHEMA_METADATA_KEYS.EXCLUSIVE_MAXIMUM,
710
- prototype,
711
- propertyName
712
- );
713
- if (exclusiveMaximum !== void 0) schema.exclusiveMaximum = exclusiveMaximum;
714
- const multipleOf = getSchemaMetadata(
715
- SCHEMA_METADATA_KEYS.MULTIPLE_OF,
716
- prototype,
717
- propertyName
718
- );
719
- if (multipleOf !== void 0) schema.multipleOf = multipleOf;
720
- const minItems = getSchemaMetadata(
721
- SCHEMA_METADATA_KEYS.MIN_ITEMS,
722
- prototype,
723
- propertyName
724
- );
725
- if (minItems !== void 0) schema.minItems = minItems;
726
- const maxItems = getSchemaMetadata(
727
- SCHEMA_METADATA_KEYS.MAX_ITEMS,
728
- prototype,
729
- propertyName
730
- );
731
- if (maxItems !== void 0) schema.maxItems = maxItems;
732
- const uniqueItems = getSchemaMetadata(
733
- SCHEMA_METADATA_KEYS.UNIQUE_ITEMS,
734
- prototype,
735
- propertyName
736
- );
737
- if (uniqueItems) schema.uniqueItems = uniqueItems;
738
- const additionalProperties = getSchemaMetadata(
739
- SCHEMA_METADATA_KEYS.ADDITIONAL_PROPERTIES,
740
- prototype,
741
- propertyName
742
- );
743
- if (additionalProperties !== void 0) {
744
- if (schema.type === "array" && schema.items) {
745
- schema.items.additionalProperties = additionalProperties;
746
- } else {
747
- schema.additionalProperties = additionalProperties;
526
+ static resolve(schema) {
527
+ for (const adapter of this.adapters) {
528
+ if (adapter.canHandle(schema)) {
529
+ return adapter.toJsonSchema(schema);
748
530
  }
749
531
  }
532
+ throw new Error(
533
+ "Unsupported schema type. Supported types: Zod, Yup, Joi, or raw JSON Schema object."
534
+ );
750
535
  }
751
536
  /**
752
- * 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
753
541
  */
754
- static getRequiredProperties(targetClass, properties) {
755
- const required = [];
756
- try {
757
- const { getMetadataStorage } = __require("class-validator");
758
- const metadataStorage = getMetadataStorage();
759
- const targetMetadatas = metadataStorage.getTargetValidationMetadatas(
760
- targetClass,
761
- "",
762
- true,
763
- false
764
- );
765
- for (const propertyName of Object.keys(properties)) {
766
- const isOptional = targetMetadatas.some(
767
- (m) => m.propertyName === propertyName && (m.type === "isOptional" || m.type === "conditionalValidation")
768
- );
769
- if (!isOptional) {
770
- required.push(propertyName);
771
- }
772
- }
773
- } catch {
774
- 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";
775
558
  }
776
- 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";
777
566
  }
778
567
  };
779
568
 
@@ -805,22 +594,6 @@ var PromptsResource = class {
805
594
  });
806
595
  }
807
596
  async execute(promptId, options) {
808
- if ("responseClass" in options && options.responseClass) {
809
- return this.executeTyped(promptId, options);
810
- }
811
- return this.executeRaw(promptId, options);
812
- }
813
- async executeByTag(promptId, tag, options) {
814
- return this.execute(promptId, { ...options, tag });
815
- }
816
- async executeByVersion(promptId, version, options) {
817
- return this.execute(promptId, { ...options, version });
818
- }
819
- /**
820
- * Execute raw request without typed response
821
- * @throws {ExecutionSynovaError} If LLM returns an error
822
- */
823
- async executeRaw(promptId, options) {
824
597
  const body = {
825
598
  provider: options.provider,
826
599
  model: options.model
@@ -833,8 +606,10 @@ var PromptsResource = class {
833
606
  if (options.version !== void 0) body.version = options.version;
834
607
  if (options.metadata !== void 0) body.metadata = options.metadata;
835
608
  if (options.parameters !== void 0) body.parameters = options.parameters;
836
- if (options.responseSchema !== void 0) body.responseSchema = options.responseSchema;
837
609
  if (options.sessionId !== void 0) body.sessionId = options.sessionId;
610
+ if (options.responseSchema !== void 0) {
611
+ body.responseSchema = SchemaResolver.resolve(options.responseSchema);
612
+ }
838
613
  const response = await this.http.request({
839
614
  method: "POST",
840
615
  path: `/api/v1/prompts/${promptId}/run`,
@@ -843,51 +618,19 @@ var PromptsResource = class {
843
618
  if (response.type === "error" && response.error) {
844
619
  throw new ExecutionSynovaError(response.error);
845
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.object;
626
+ }
846
627
  return response;
847
628
  }
848
- /**
849
- * Execute with typed response class
850
- */
851
- async executeTyped(promptId, options) {
852
- const { responseClass, validate = true, ...executeOptions } = options;
853
- const responseSchema = ClassSchema.generate(responseClass);
854
- const response = await this.executeRaw(promptId, {
855
- ...executeOptions,
856
- responseSchema
857
- });
858
- const object = response.object;
859
- if (validate) {
860
- await this.validateObject(object, responseClass);
861
- }
862
- return object;
629
+ async executeByTag(promptId, tag, options) {
630
+ return this.execute(promptId, { ...options, tag });
863
631
  }
864
- /**
865
- * Validate object using class-validator
866
- */
867
- async validateObject(object, responseClass) {
868
- try {
869
- const { plainToInstance } = __require("class-transformer");
870
- const { validate } = __require("class-validator");
871
- const instance = plainToInstance(responseClass, object);
872
- const errors = await validate(instance);
873
- if (errors.length > 0) {
874
- const violations = errors.map(
875
- (error) => ({
876
- property: error.property,
877
- constraints: error.constraints || {},
878
- value: error.value
879
- })
880
- );
881
- throw new ValidationSynovaError(violations);
882
- }
883
- } catch (error) {
884
- if (error instanceof ValidationSynovaError) {
885
- throw error;
886
- }
887
- console.warn(
888
- "[Synova SDK] Validation skipped: class-validator or class-transformer not installed. Install them with: npm install class-validator class-transformer"
889
- );
890
- }
632
+ async executeByVersion(promptId, version, options) {
633
+ return this.execute(promptId, { ...options, version });
891
634
  }
892
635
  };
893
636
 
@@ -1204,35 +947,19 @@ var SynovaCloudSdk = class {
1204
947
  };
1205
948
 
1206
949
  exports.ApiSynovaError = ApiSynovaError;
1207
- exports.ArrayItems = ArrayItems;
1208
950
  exports.AuthSynovaError = AuthSynovaError;
1209
- exports.ClassSchema = ClassSchema;
1210
- exports.Default = Default;
1211
- exports.Description = Description;
1212
- exports.Example = Example;
1213
- exports.ExclusiveMax = ExclusiveMax;
1214
- exports.ExclusiveMin = ExclusiveMin;
1215
951
  exports.ExecutionSynovaError = ExecutionSynovaError;
1216
- exports.Format = Format;
1217
- exports.MultipleOf = MultipleOf;
952
+ exports.JoiAdapter = JoiAdapter;
953
+ exports.JsonSchemaAdapter = JsonSchemaAdapter;
1218
954
  exports.NetworkSynovaError = NetworkSynovaError;
1219
955
  exports.NotFoundSynovaError = NotFoundSynovaError;
1220
- exports.Nullable = Nullable;
1221
956
  exports.RateLimitSynovaError = RateLimitSynovaError;
1222
- exports.SCHEMA_METADATA_KEYS = SCHEMA_METADATA_KEYS;
1223
- exports.SchemaEnum = SchemaEnum;
1224
- exports.SchemaMax = SchemaMax;
1225
- exports.SchemaMaxItems = SchemaMaxItems;
1226
- exports.SchemaMaxLength = SchemaMaxLength;
1227
- exports.SchemaMin = SchemaMin;
1228
- exports.SchemaMinItems = SchemaMinItems;
1229
- exports.SchemaMinLength = SchemaMinLength;
1230
- exports.SchemaPattern = SchemaPattern;
1231
- exports.SchemaUniqueItems = SchemaUniqueItems;
957
+ exports.SchemaResolver = SchemaResolver;
1232
958
  exports.ServerSynovaError = ServerSynovaError;
1233
959
  exports.SynovaCloudSdk = SynovaCloudSdk;
1234
960
  exports.SynovaError = SynovaError;
1235
961
  exports.TimeoutSynovaError = TimeoutSynovaError;
1236
- exports.ValidationSynovaError = ValidationSynovaError;
962
+ exports.YupAdapter = YupAdapter;
963
+ exports.ZodAdapter = ZodAdapter;
1237
964
  //# sourceMappingURL=index.cjs.map
1238
965
  //# sourceMappingURL=index.cjs.map