@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.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 = "
|
|
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/
|
|
322
|
-
var
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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/
|
|
413
|
-
var
|
|
414
|
-
|
|
415
|
-
|
|
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
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
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
|
-
|
|
444
|
-
|
|
445
|
-
|
|
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 {
|
|
448
|
-
|
|
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
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
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
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
422
|
+
* Recursively transform `nullable: true` to `type: ["...", "null"]`
|
|
502
423
|
*/
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
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 (
|
|
525
|
-
|
|
443
|
+
if (result.items) {
|
|
444
|
+
result.items = this.transformNullable(result.items);
|
|
526
445
|
}
|
|
527
|
-
if (typeof
|
|
528
|
-
|
|
446
|
+
if (result.additionalProperties && typeof result.additionalProperties === "object") {
|
|
447
|
+
result.additionalProperties = this.transformNullable(result.additionalProperties);
|
|
529
448
|
}
|
|
530
|
-
|
|
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 (
|
|
540
|
-
|
|
452
|
+
if (result.anyOf) {
|
|
453
|
+
result.anyOf = result.anyOf.map((s) => this.transformNullable(s));
|
|
541
454
|
}
|
|
542
|
-
if (
|
|
543
|
-
|
|
455
|
+
if (result.oneOf) {
|
|
456
|
+
result.oneOf = result.oneOf.map((s) => this.transformNullable(s));
|
|
544
457
|
}
|
|
545
|
-
if (
|
|
546
|
-
|
|
458
|
+
if (result.not) {
|
|
459
|
+
result.not = this.transformNullable(result.not);
|
|
547
460
|
}
|
|
548
|
-
return
|
|
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
|
-
*
|
|
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
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
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
|
-
*
|
|
494
|
+
* Reset adapters to default configuration.
|
|
495
|
+
* Removes all custom adapters.
|
|
574
496
|
*/
|
|
575
|
-
static
|
|
576
|
-
|
|
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
|
-
*
|
|
643
|
-
*
|
|
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
|
|
646
|
-
const
|
|
647
|
-
|
|
648
|
-
|
|
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
|
-
*
|
|
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
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
1217
|
-
exports.
|
|
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.
|
|
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.
|
|
962
|
+
exports.YupAdapter = YupAdapter;
|
|
963
|
+
exports.ZodAdapter = ZodAdapter;
|
|
1237
964
|
//# sourceMappingURL=index.cjs.map
|
|
1238
965
|
//# sourceMappingURL=index.cjs.map
|