@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 +235 -508
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +180 -362
- package/dist/index.d.ts +180 -362
- package/dist/index.js +231 -488
- package/dist/index.js.map +1 -1
- package/package.json +28 -9
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 = "
|
|
97
|
+
var SDK_VERSION = "2.0.0" ;
|
|
109
98
|
|
|
110
99
|
// src/utils/http.ts
|
|
111
100
|
var HttpClient = class {
|
|
@@ -316,462 +305,262 @@ var HttpClient = class {
|
|
|
316
305
|
}
|
|
317
306
|
};
|
|
318
307
|
|
|
319
|
-
// src/schema/
|
|
320
|
-
var
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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 getSchemaMetadata(key, target, propertyKey) {
|
|
407
|
-
return Reflect.getMetadata(key, target, propertyKey);
|
|
408
|
-
}
|
|
409
331
|
|
|
410
|
-
// src/schema/
|
|
411
|
-
var
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
static generate(targetClass, options = {}) {
|
|
416
|
-
const { additionalProperties = false } = options;
|
|
417
|
-
const properties = this.getProperties(targetClass);
|
|
418
|
-
const required = this.getRequiredProperties(targetClass, properties);
|
|
419
|
-
return {
|
|
420
|
-
type: "object",
|
|
421
|
-
properties,
|
|
422
|
-
required: required.length > 0 ? required : void 0,
|
|
423
|
-
additionalProperties
|
|
424
|
-
};
|
|
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;
|
|
425
337
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
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}`);
|
|
437
349
|
}
|
|
438
|
-
return properties;
|
|
439
350
|
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
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;
|
|
444
357
|
try {
|
|
445
|
-
const {
|
|
446
|
-
|
|
447
|
-
const targetMetadatas = metadataStorage.getTargetValidationMetadatas(
|
|
448
|
-
targetClass,
|
|
449
|
-
"",
|
|
450
|
-
true,
|
|
451
|
-
false
|
|
452
|
-
);
|
|
453
|
-
const propertyNames = targetMetadatas.map((m) => m.propertyName);
|
|
454
|
-
return [...new Set(propertyNames)];
|
|
358
|
+
const { isSchema } = __require("joi");
|
|
359
|
+
return isSchema(schema);
|
|
455
360
|
} catch {
|
|
456
|
-
return
|
|
361
|
+
return false;
|
|
457
362
|
}
|
|
458
363
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
if (Reflect.hasMetadata(metaKey, prototype, key)) {
|
|
469
|
-
properties.push(key);
|
|
470
|
-
break;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
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
|
+
);
|
|
473
373
|
}
|
|
374
|
+
throw new Error(`Failed to convert Joi schema: ${error.message}`);
|
|
474
375
|
}
|
|
475
|
-
return properties;
|
|
476
376
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
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;
|
|
495
406
|
}
|
|
496
|
-
|
|
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);
|
|
497
418
|
}
|
|
498
419
|
/**
|
|
499
|
-
*
|
|
420
|
+
* Recursively transform `nullable: true` to `type: ["...", "null"]`
|
|
500
421
|
*/
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
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
|
+
])
|
|
516
439
|
);
|
|
517
|
-
return {
|
|
518
|
-
type: "array",
|
|
519
|
-
items: this.getArrayItemSchema(itemType)
|
|
520
|
-
};
|
|
521
440
|
}
|
|
522
|
-
if (
|
|
523
|
-
|
|
441
|
+
if (result.items) {
|
|
442
|
+
result.items = this.transformNullable(result.items);
|
|
524
443
|
}
|
|
525
|
-
if (typeof
|
|
526
|
-
|
|
444
|
+
if (result.additionalProperties && typeof result.additionalProperties === "object") {
|
|
445
|
+
result.additionalProperties = this.transformNullable(result.additionalProperties);
|
|
527
446
|
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
/**
|
|
531
|
-
* Get schema for array items
|
|
532
|
-
*/
|
|
533
|
-
static getArrayItemSchema(itemType) {
|
|
534
|
-
if (!itemType) {
|
|
535
|
-
return { type: "string" };
|
|
447
|
+
if (result.allOf) {
|
|
448
|
+
result.allOf = result.allOf.map((s) => this.transformNullable(s));
|
|
536
449
|
}
|
|
537
|
-
if (
|
|
538
|
-
|
|
450
|
+
if (result.anyOf) {
|
|
451
|
+
result.anyOf = result.anyOf.map((s) => this.transformNullable(s));
|
|
539
452
|
}
|
|
540
|
-
if (
|
|
541
|
-
|
|
453
|
+
if (result.oneOf) {
|
|
454
|
+
result.oneOf = result.oneOf.map((s) => this.transformNullable(s));
|
|
542
455
|
}
|
|
543
|
-
if (
|
|
544
|
-
|
|
456
|
+
if (result.not) {
|
|
457
|
+
result.not = this.transformNullable(result.not);
|
|
545
458
|
}
|
|
546
|
-
return
|
|
459
|
+
return result;
|
|
547
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
|
+
];
|
|
548
472
|
/**
|
|
549
|
-
*
|
|
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
|
+
* ```
|
|
550
483
|
*/
|
|
551
|
-
static
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
targetClass,
|
|
557
|
-
"",
|
|
558
|
-
true,
|
|
559
|
-
false
|
|
560
|
-
);
|
|
561
|
-
const propertyMetadatas = targetMetadatas.filter(
|
|
562
|
-
(m) => m.propertyName === propertyName
|
|
563
|
-
);
|
|
564
|
-
for (const metadata of propertyMetadatas) {
|
|
565
|
-
this.applyValidationConstraint(schema, metadata);
|
|
566
|
-
}
|
|
567
|
-
} 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);
|
|
568
489
|
}
|
|
569
490
|
}
|
|
570
491
|
/**
|
|
571
|
-
*
|
|
492
|
+
* Reset adapters to default configuration.
|
|
493
|
+
* Removes all custom adapters.
|
|
572
494
|
*/
|
|
573
|
-
static
|
|
574
|
-
|
|
575
|
-
const constraints = metadata.constraints || [];
|
|
576
|
-
switch (constraintType) {
|
|
577
|
-
case "isString":
|
|
578
|
-
schema.type = "string";
|
|
579
|
-
break;
|
|
580
|
-
case "isNumber":
|
|
581
|
-
case "isInt":
|
|
582
|
-
schema.type = constraintType === "isInt" ? "integer" : "number";
|
|
583
|
-
break;
|
|
584
|
-
case "isBoolean":
|
|
585
|
-
schema.type = "boolean";
|
|
586
|
-
break;
|
|
587
|
-
case "isArray":
|
|
588
|
-
schema.type = "array";
|
|
589
|
-
break;
|
|
590
|
-
case "isEnum":
|
|
591
|
-
if (constraints[0]) {
|
|
592
|
-
schema.enum = Object.values(constraints[0]);
|
|
593
|
-
}
|
|
594
|
-
break;
|
|
595
|
-
case "minLength":
|
|
596
|
-
schema.minLength = constraints[0];
|
|
597
|
-
break;
|
|
598
|
-
case "maxLength":
|
|
599
|
-
schema.maxLength = constraints[0];
|
|
600
|
-
break;
|
|
601
|
-
case "min":
|
|
602
|
-
schema.minimum = constraints[0];
|
|
603
|
-
break;
|
|
604
|
-
case "max":
|
|
605
|
-
schema.maximum = constraints[0];
|
|
606
|
-
break;
|
|
607
|
-
case "isEmail":
|
|
608
|
-
schema.format = "email";
|
|
609
|
-
break;
|
|
610
|
-
case "isUrl":
|
|
611
|
-
case "isURL":
|
|
612
|
-
schema.format = "uri";
|
|
613
|
-
break;
|
|
614
|
-
case "isUUID":
|
|
615
|
-
schema.format = "uuid";
|
|
616
|
-
break;
|
|
617
|
-
case "isDateString":
|
|
618
|
-
case "isISO8601":
|
|
619
|
-
schema.format = "date-time";
|
|
620
|
-
break;
|
|
621
|
-
case "matches":
|
|
622
|
-
if (constraints[0] instanceof RegExp) {
|
|
623
|
-
schema.pattern = constraints[0].source;
|
|
624
|
-
} else if (typeof constraints[0] === "string") {
|
|
625
|
-
schema.pattern = constraints[0];
|
|
626
|
-
}
|
|
627
|
-
break;
|
|
628
|
-
case "arrayMinSize":
|
|
629
|
-
schema.minItems = constraints[0];
|
|
630
|
-
break;
|
|
631
|
-
case "arrayMaxSize":
|
|
632
|
-
schema.maxItems = constraints[0];
|
|
633
|
-
break;
|
|
634
|
-
case "arrayUnique":
|
|
635
|
-
schema.uniqueItems = true;
|
|
636
|
-
break;
|
|
637
|
-
}
|
|
495
|
+
static resetAdapters() {
|
|
496
|
+
this.adapters = [new ZodAdapter(), new YupAdapter(), new JoiAdapter(), new JsonSchemaAdapter()];
|
|
638
497
|
}
|
|
639
498
|
/**
|
|
640
|
-
*
|
|
641
|
-
*
|
|
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
|
+
* ```
|
|
642
523
|
*/
|
|
643
|
-
static
|
|
644
|
-
const
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
propertyName
|
|
648
|
-
);
|
|
649
|
-
if (description) schema.description = description;
|
|
650
|
-
const examples = getSchemaMetadata(
|
|
651
|
-
SCHEMA_METADATA_KEYS.EXAMPLES,
|
|
652
|
-
prototype,
|
|
653
|
-
propertyName
|
|
654
|
-
);
|
|
655
|
-
if (examples) schema.examples = examples;
|
|
656
|
-
const defaultValue = getSchemaMetadata(
|
|
657
|
-
SCHEMA_METADATA_KEYS.DEFAULT,
|
|
658
|
-
prototype,
|
|
659
|
-
propertyName
|
|
660
|
-
);
|
|
661
|
-
if (defaultValue !== void 0) schema.default = defaultValue;
|
|
662
|
-
const format = getSchemaMetadata(SCHEMA_METADATA_KEYS.FORMAT, prototype, propertyName);
|
|
663
|
-
if (format) schema.format = format;
|
|
664
|
-
const enumValues = getSchemaMetadata(
|
|
665
|
-
SCHEMA_METADATA_KEYS.ENUM,
|
|
666
|
-
prototype,
|
|
667
|
-
propertyName
|
|
668
|
-
);
|
|
669
|
-
if (enumValues) schema.enum = enumValues;
|
|
670
|
-
const minLength = getSchemaMetadata(
|
|
671
|
-
SCHEMA_METADATA_KEYS.MIN_LENGTH,
|
|
672
|
-
prototype,
|
|
673
|
-
propertyName
|
|
674
|
-
);
|
|
675
|
-
if (minLength !== void 0) schema.minLength = minLength;
|
|
676
|
-
const maxLength = getSchemaMetadata(
|
|
677
|
-
SCHEMA_METADATA_KEYS.MAX_LENGTH,
|
|
678
|
-
prototype,
|
|
679
|
-
propertyName
|
|
680
|
-
);
|
|
681
|
-
if (maxLength !== void 0) schema.maxLength = maxLength;
|
|
682
|
-
const pattern = getSchemaMetadata(
|
|
683
|
-
SCHEMA_METADATA_KEYS.PATTERN,
|
|
684
|
-
prototype,
|
|
685
|
-
propertyName
|
|
686
|
-
);
|
|
687
|
-
if (pattern) schema.pattern = pattern;
|
|
688
|
-
const minimum = getSchemaMetadata(
|
|
689
|
-
SCHEMA_METADATA_KEYS.MINIMUM,
|
|
690
|
-
prototype,
|
|
691
|
-
propertyName
|
|
692
|
-
);
|
|
693
|
-
if (minimum !== void 0) schema.minimum = minimum;
|
|
694
|
-
const maximum = getSchemaMetadata(
|
|
695
|
-
SCHEMA_METADATA_KEYS.MAXIMUM,
|
|
696
|
-
prototype,
|
|
697
|
-
propertyName
|
|
698
|
-
);
|
|
699
|
-
if (maximum !== void 0) schema.maximum = maximum;
|
|
700
|
-
const exclusiveMinimum = getSchemaMetadata(
|
|
701
|
-
SCHEMA_METADATA_KEYS.EXCLUSIVE_MINIMUM,
|
|
702
|
-
prototype,
|
|
703
|
-
propertyName
|
|
704
|
-
);
|
|
705
|
-
if (exclusiveMinimum !== void 0) schema.exclusiveMinimum = exclusiveMinimum;
|
|
706
|
-
const exclusiveMaximum = getSchemaMetadata(
|
|
707
|
-
SCHEMA_METADATA_KEYS.EXCLUSIVE_MAXIMUM,
|
|
708
|
-
prototype,
|
|
709
|
-
propertyName
|
|
710
|
-
);
|
|
711
|
-
if (exclusiveMaximum !== void 0) schema.exclusiveMaximum = exclusiveMaximum;
|
|
712
|
-
const multipleOf = getSchemaMetadata(
|
|
713
|
-
SCHEMA_METADATA_KEYS.MULTIPLE_OF,
|
|
714
|
-
prototype,
|
|
715
|
-
propertyName
|
|
716
|
-
);
|
|
717
|
-
if (multipleOf !== void 0) schema.multipleOf = multipleOf;
|
|
718
|
-
const minItems = getSchemaMetadata(
|
|
719
|
-
SCHEMA_METADATA_KEYS.MIN_ITEMS,
|
|
720
|
-
prototype,
|
|
721
|
-
propertyName
|
|
722
|
-
);
|
|
723
|
-
if (minItems !== void 0) schema.minItems = minItems;
|
|
724
|
-
const maxItems = getSchemaMetadata(
|
|
725
|
-
SCHEMA_METADATA_KEYS.MAX_ITEMS,
|
|
726
|
-
prototype,
|
|
727
|
-
propertyName
|
|
728
|
-
);
|
|
729
|
-
if (maxItems !== void 0) schema.maxItems = maxItems;
|
|
730
|
-
const uniqueItems = getSchemaMetadata(
|
|
731
|
-
SCHEMA_METADATA_KEYS.UNIQUE_ITEMS,
|
|
732
|
-
prototype,
|
|
733
|
-
propertyName
|
|
734
|
-
);
|
|
735
|
-
if (uniqueItems) schema.uniqueItems = uniqueItems;
|
|
736
|
-
const additionalProperties = getSchemaMetadata(
|
|
737
|
-
SCHEMA_METADATA_KEYS.ADDITIONAL_PROPERTIES,
|
|
738
|
-
prototype,
|
|
739
|
-
propertyName
|
|
740
|
-
);
|
|
741
|
-
if (additionalProperties !== void 0) {
|
|
742
|
-
if (schema.type === "array" && schema.items) {
|
|
743
|
-
schema.items.additionalProperties = additionalProperties;
|
|
744
|
-
} else {
|
|
745
|
-
schema.additionalProperties = additionalProperties;
|
|
524
|
+
static resolve(schema) {
|
|
525
|
+
for (const adapter of this.adapters) {
|
|
526
|
+
if (adapter.canHandle(schema)) {
|
|
527
|
+
return adapter.toJsonSchema(schema);
|
|
746
528
|
}
|
|
747
529
|
}
|
|
530
|
+
throw new Error(
|
|
531
|
+
"Unsupported schema type. Supported types: Zod, Yup, Joi, or raw JSON Schema object."
|
|
532
|
+
);
|
|
748
533
|
}
|
|
749
534
|
/**
|
|
750
|
-
*
|
|
535
|
+
* Check if a schema is supported.
|
|
536
|
+
*
|
|
537
|
+
* @param schema - Schema to check
|
|
538
|
+
* @returns true if the schema is supported
|
|
751
539
|
*/
|
|
752
|
-
static
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
required.push(propertyName);
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
} catch {
|
|
772
|
-
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";
|
|
773
556
|
}
|
|
774
|
-
|
|
557
|
+
if (adapters[2].canHandle(schema)) {
|
|
558
|
+
return "joi";
|
|
559
|
+
}
|
|
560
|
+
if (adapters[3].canHandle(schema)) {
|
|
561
|
+
return "json-schema";
|
|
562
|
+
}
|
|
563
|
+
return "unknown";
|
|
775
564
|
}
|
|
776
565
|
};
|
|
777
566
|
|
|
@@ -803,22 +592,6 @@ var PromptsResource = class {
|
|
|
803
592
|
});
|
|
804
593
|
}
|
|
805
594
|
async execute(promptId, options) {
|
|
806
|
-
if ("responseClass" in options && options.responseClass) {
|
|
807
|
-
return this.executeTyped(promptId, options);
|
|
808
|
-
}
|
|
809
|
-
return this.executeRaw(promptId, options);
|
|
810
|
-
}
|
|
811
|
-
async executeByTag(promptId, tag, options) {
|
|
812
|
-
return this.execute(promptId, { ...options, tag });
|
|
813
|
-
}
|
|
814
|
-
async executeByVersion(promptId, version, options) {
|
|
815
|
-
return this.execute(promptId, { ...options, version });
|
|
816
|
-
}
|
|
817
|
-
/**
|
|
818
|
-
* Execute raw request without typed response
|
|
819
|
-
* @throws {ExecutionSynovaError} If LLM returns an error
|
|
820
|
-
*/
|
|
821
|
-
async executeRaw(promptId, options) {
|
|
822
595
|
const body = {
|
|
823
596
|
provider: options.provider,
|
|
824
597
|
model: options.model
|
|
@@ -831,8 +604,10 @@ var PromptsResource = class {
|
|
|
831
604
|
if (options.version !== void 0) body.version = options.version;
|
|
832
605
|
if (options.metadata !== void 0) body.metadata = options.metadata;
|
|
833
606
|
if (options.parameters !== void 0) body.parameters = options.parameters;
|
|
834
|
-
if (options.responseSchema !== void 0) body.responseSchema = options.responseSchema;
|
|
835
607
|
if (options.sessionId !== void 0) body.sessionId = options.sessionId;
|
|
608
|
+
if (options.responseSchema !== void 0) {
|
|
609
|
+
body.responseSchema = SchemaResolver.resolve(options.responseSchema);
|
|
610
|
+
}
|
|
836
611
|
const response = await this.http.request({
|
|
837
612
|
method: "POST",
|
|
838
613
|
path: `/api/v1/prompts/${promptId}/run`,
|
|
@@ -841,51 +616,19 @@ var PromptsResource = class {
|
|
|
841
616
|
if (response.type === "error" && response.error) {
|
|
842
617
|
throw new ExecutionSynovaError(response.error);
|
|
843
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
|
+
}
|
|
844
625
|
return response;
|
|
845
626
|
}
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
*/
|
|
849
|
-
async executeTyped(promptId, options) {
|
|
850
|
-
const { responseClass, validate = true, ...executeOptions } = options;
|
|
851
|
-
const responseSchema = ClassSchema.generate(responseClass);
|
|
852
|
-
const response = await this.executeRaw(promptId, {
|
|
853
|
-
...executeOptions,
|
|
854
|
-
responseSchema
|
|
855
|
-
});
|
|
856
|
-
const object = response.object;
|
|
857
|
-
if (validate) {
|
|
858
|
-
await this.validateObject(object, responseClass);
|
|
859
|
-
}
|
|
860
|
-
return object;
|
|
627
|
+
async executeByTag(promptId, tag, options) {
|
|
628
|
+
return this.execute(promptId, { ...options, tag });
|
|
861
629
|
}
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
*/
|
|
865
|
-
async validateObject(object, responseClass) {
|
|
866
|
-
try {
|
|
867
|
-
const { plainToInstance } = __require("class-transformer");
|
|
868
|
-
const { validate } = __require("class-validator");
|
|
869
|
-
const instance = plainToInstance(responseClass, object);
|
|
870
|
-
const errors = await validate(instance);
|
|
871
|
-
if (errors.length > 0) {
|
|
872
|
-
const violations = errors.map(
|
|
873
|
-
(error) => ({
|
|
874
|
-
property: error.property,
|
|
875
|
-
constraints: error.constraints || {},
|
|
876
|
-
value: error.value
|
|
877
|
-
})
|
|
878
|
-
);
|
|
879
|
-
throw new ValidationSynovaError(violations);
|
|
880
|
-
}
|
|
881
|
-
} catch (error) {
|
|
882
|
-
if (error instanceof ValidationSynovaError) {
|
|
883
|
-
throw error;
|
|
884
|
-
}
|
|
885
|
-
console.warn(
|
|
886
|
-
"[Synova SDK] Validation skipped: class-validator or class-transformer not installed. Install them with: npm install class-validator class-transformer"
|
|
887
|
-
);
|
|
888
|
-
}
|
|
630
|
+
async executeByVersion(promptId, version, options) {
|
|
631
|
+
return this.execute(promptId, { ...options, version });
|
|
889
632
|
}
|
|
890
633
|
};
|
|
891
634
|
|
|
@@ -1201,6 +944,6 @@ var SynovaCloudSdk = class {
|
|
|
1201
944
|
}
|
|
1202
945
|
};
|
|
1203
946
|
|
|
1204
|
-
export { ApiSynovaError,
|
|
947
|
+
export { ApiSynovaError, AuthSynovaError, ExecutionSynovaError, JoiAdapter, JsonSchemaAdapter, NetworkSynovaError, NotFoundSynovaError, RateLimitSynovaError, SchemaResolver, ServerSynovaError, SynovaCloudSdk, SynovaError, TimeoutSynovaError, YupAdapter, ZodAdapter };
|
|
1205
948
|
//# sourceMappingURL=index.js.map
|
|
1206
949
|
//# sourceMappingURL=index.js.map
|