@arcteninc/core 0.0.32 → 0.0.33
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/package.json
CHANGED
|
@@ -14,7 +14,8 @@ interface JsonSchemaProperty {
|
|
|
14
14
|
type?: string | string[]; // Can be string, array of strings, or omitted for anyOf/oneOf/$ref
|
|
15
15
|
description?: string;
|
|
16
16
|
default?: string;
|
|
17
|
-
enum?: string[]; // For enum types
|
|
17
|
+
enum?: (string | number)[]; // For enum types (can be string or number enums)
|
|
18
|
+
const?: string | number | boolean; // For literal values
|
|
18
19
|
items?: JsonSchemaProperty; // For array types
|
|
19
20
|
properties?: Record<string, JsonSchemaProperty>; // For object types
|
|
20
21
|
required?: string[]; // For nested objects
|
|
@@ -428,7 +429,7 @@ function serializeType(
|
|
|
428
429
|
depth = 0
|
|
429
430
|
): { isOptional: boolean; schema: JsonSchemaProperty } {
|
|
430
431
|
const typeString = checker.typeToString(type);
|
|
431
|
-
|
|
432
|
+
|
|
432
433
|
if (depth > 10) {
|
|
433
434
|
return { isOptional: false, schema: { type: 'any' } };
|
|
434
435
|
}
|
|
@@ -448,6 +449,26 @@ function serializeType(
|
|
|
448
449
|
if (type.flags & ts.TypeFlags.Boolean) {
|
|
449
450
|
return { isOptional: false, schema: { type: 'boolean' } };
|
|
450
451
|
}
|
|
452
|
+
|
|
453
|
+
// Handle boolean literals (true/false)
|
|
454
|
+
if (type.flags & ts.TypeFlags.BooleanLiteral) {
|
|
455
|
+
// Access the value through the intrinsicName property
|
|
456
|
+
const value = (type as any).intrinsicName === 'true';
|
|
457
|
+
return { isOptional: false, schema: { type: 'boolean', const: value } };
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// Handle number literals
|
|
461
|
+
if (type.flags & ts.TypeFlags.NumberLiteral) {
|
|
462
|
+
const value = (type as any).value;
|
|
463
|
+
return { isOptional: false, schema: { type: 'number', const: value } };
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// Handle string literals (enum members)
|
|
467
|
+
if (type.flags & ts.TypeFlags.StringLiteral) {
|
|
468
|
+
const value = (type as any).value;
|
|
469
|
+
return { isOptional: false, schema: { type: 'string', const: value } };
|
|
470
|
+
}
|
|
471
|
+
|
|
451
472
|
if (type.flags & ts.TypeFlags.Undefined || type.flags & ts.TypeFlags.Void) {
|
|
452
473
|
return { isOptional: true, schema: { type: 'null' } };
|
|
453
474
|
}
|
|
@@ -514,6 +535,18 @@ function serializeType(
|
|
|
514
535
|
anyOf.push({ type: 'number' });
|
|
515
536
|
} else if (unionType.flags & ts.TypeFlags.Boolean) {
|
|
516
537
|
anyOf.push({ type: 'boolean' });
|
|
538
|
+
} else if (unionType.flags & ts.TypeFlags.BooleanLiteral) {
|
|
539
|
+
// Boolean literal (true/false)
|
|
540
|
+
const value = (unionType as any).intrinsicName === 'true';
|
|
541
|
+
anyOf.push({ type: 'boolean', const: value });
|
|
542
|
+
} else if (unionType.flags & ts.TypeFlags.NumberLiteral) {
|
|
543
|
+
// Number literal
|
|
544
|
+
const value = (unionType as any).value;
|
|
545
|
+
anyOf.push({ type: 'number', const: value });
|
|
546
|
+
} else if (unionType.flags & ts.TypeFlags.StringLiteral) {
|
|
547
|
+
// String literal (enum member)
|
|
548
|
+
const value = (unionType as any).value;
|
|
549
|
+
anyOf.push({ type: 'string', const: value });
|
|
517
550
|
} else if (checker.isArrayType(unionType)) {
|
|
518
551
|
// Handle array types
|
|
519
552
|
const typeArgs = (unionType as ts.TypeReference).typeArguments;
|
|
@@ -645,10 +678,74 @@ function serializeType(
|
|
|
645
678
|
}
|
|
646
679
|
}
|
|
647
680
|
|
|
648
|
-
// Fallback
|
|
681
|
+
// Fallback - check type flags to determine if it's a valid JSON Schema type
|
|
682
|
+
// Valid JSON Schema types: string, number, integer, boolean, object, array, null
|
|
683
|
+
|
|
684
|
+
// Check if it's an enum type (TypeScript enum)
|
|
685
|
+
if (type.flags & ts.TypeFlags.Enum) {
|
|
686
|
+
// Try to get enum members
|
|
687
|
+
const symbol = type.symbol || (type as any).symbol;
|
|
688
|
+
if (symbol) {
|
|
689
|
+
const enumMembers = checker.getPropertiesOfType(type);
|
|
690
|
+
if (enumMembers.length > 0) {
|
|
691
|
+
// Extract enum values - enum members are typically string or number literals
|
|
692
|
+
const values: (string | number)[] = [];
|
|
693
|
+
for (const member of enumMembers) {
|
|
694
|
+
const memberType = checker.getTypeOfSymbolAtLocation(member, member.valueDeclaration || member.declarations?.[0] || type as any);
|
|
695
|
+
if (memberType.flags & ts.TypeFlags.StringLiteral) {
|
|
696
|
+
values.push((memberType as any).value);
|
|
697
|
+
} else if (memberType.flags & ts.TypeFlags.NumberLiteral) {
|
|
698
|
+
values.push((memberType as any).value);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
if (values.length > 0) {
|
|
702
|
+
// Check if all values are strings or all are numbers
|
|
703
|
+
const allStrings = values.every(v => typeof v === 'string');
|
|
704
|
+
const allNumbers = values.every(v => typeof v === 'number');
|
|
705
|
+
if (allStrings) {
|
|
706
|
+
return { isOptional: false, schema: { type: 'string', enum: values.filter((v): v is string => typeof v === 'string') } };
|
|
707
|
+
} else if (allNumbers) {
|
|
708
|
+
const numberValues = values.filter((v): v is number => typeof v === 'number');
|
|
709
|
+
return { isOptional: false, schema: { type: 'number', enum: numberValues } };
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
// If we can't extract enum values, use 'any'
|
|
715
|
+
return { isOptional: false, schema: { type: 'any' } };
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
// Check if it's a type reference (like InternalFilterType.StringFilter)
|
|
719
|
+
// Type references that aren't objects/arrays/primitives should use 'any'
|
|
720
|
+
if (type.flags & ts.TypeFlags.Object) {
|
|
721
|
+
// Already handled above, but check if it's an empty object type
|
|
722
|
+
const props = checker.getPropertiesOfType(type);
|
|
723
|
+
if (props.length === 0) {
|
|
724
|
+
// Empty object or type reference we can't resolve
|
|
725
|
+
// Check if typeString suggests it's a named type reference
|
|
726
|
+
if (typeString && typeString.includes('.')) {
|
|
727
|
+
return { isOptional: false, schema: { type: 'any' } };
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
// Check if typeString is a valid JSON Schema primitive type
|
|
733
|
+
const validJsonSchemaTypes = new Set(['string', 'number', 'integer', 'boolean', 'object', 'array', 'null']);
|
|
734
|
+
const lowerTypeString = typeString?.toLowerCase();
|
|
735
|
+
|
|
736
|
+
// If it's a valid JSON Schema type, use it (shouldn't happen here, but safety check)
|
|
737
|
+
if (lowerTypeString && validJsonSchemaTypes.has(lowerTypeString)) {
|
|
738
|
+
return {
|
|
739
|
+
isOptional: false,
|
|
740
|
+
schema: { type: lowerTypeString as any }
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
// For any other unrecognized type, use 'any' instead of invalid type strings
|
|
745
|
+
// This prevents errors like "type": "InternalFilterType.StringFilter"
|
|
649
746
|
return {
|
|
650
747
|
isOptional: false,
|
|
651
|
-
schema: { type:
|
|
748
|
+
schema: { type: 'any' }
|
|
652
749
|
};
|
|
653
750
|
}
|
|
654
751
|
|