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