@arcteninc/core 0.0.52 → 0.0.54

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcteninc/core",
3
- "version": "0.0.52",
3
+ "version": "0.0.54",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -824,6 +824,73 @@ function serializeTypeCustom(
824
824
  }
825
825
  }
826
826
 
827
+ // Handle arrays
828
+ if (checker.isArrayType(type)) {
829
+ const typeArgs = (type as ts.TypeReference).typeArguments;
830
+ if (typeArgs && typeArgs.length > 0) {
831
+ const itemResult = serializeTypeCustom(typeArgs[0], checker, defs, visited, depth + 1);
832
+ return {
833
+ isOptional: false,
834
+ schema: { type: 'array', items: itemResult.schema }
835
+ };
836
+ }
837
+ return { isOptional: false, schema: { type: 'array' } };
838
+ }
839
+
840
+ // Handle union types (like "file" | "folder" or string | null)
841
+ if (type.isUnion()) {
842
+ const types = type.types;
843
+ const hasNull = types.some(t => t.flags & ts.TypeFlags.Null);
844
+ const hasUndefined = types.some(t => t.flags & ts.TypeFlags.Undefined);
845
+ const nonNullUndefinedTypes = types.filter(
846
+ t => !(t.flags & ts.TypeFlags.Null) && !(t.flags & ts.TypeFlags.Undefined)
847
+ );
848
+
849
+ // If it's just T | undefined, make it optional
850
+ if (hasUndefined && nonNullUndefinedTypes.length === 1 && !hasNull) {
851
+ const result = serializeTypeCustom(nonNullUndefinedTypes[0], checker, defs, visited, depth + 1);
852
+ return { isOptional: true, schema: result.schema };
853
+ }
854
+
855
+ // Check if union is all string/number literals (enum-like union)
856
+ const allStringLiterals = nonNullUndefinedTypes.every(t => t.flags & ts.TypeFlags.StringLiteral);
857
+ const allNumberLiterals = nonNullUndefinedTypes.every(t => t.flags & ts.TypeFlags.NumberLiteral);
858
+
859
+ if (allStringLiterals && nonNullUndefinedTypes.length > 0) {
860
+ const enumValues = nonNullUndefinedTypes.map(t => {
861
+ const literalType = t as ts.StringLiteralType;
862
+ return literalType.value;
863
+ });
864
+ const schema: JsonSchemaProperty = { enum: enumValues };
865
+ return { isOptional: hasNull || hasUndefined, schema };
866
+ }
867
+
868
+ if (allNumberLiterals && nonNullUndefinedTypes.length > 0) {
869
+ const enumValues = nonNullUndefinedTypes.map(t => {
870
+ const literalType = t as ts.NumberLiteralType;
871
+ return literalType.value;
872
+ });
873
+ const schema: JsonSchemaProperty = { enum: enumValues };
874
+ return { isOptional: hasNull || hasUndefined, schema };
875
+ }
876
+
877
+ // Build anyOf for unions
878
+ if (nonNullUndefinedTypes.length > 0 || hasNull) {
879
+ const anyOf: JsonSchemaProperty[] = [];
880
+ if (hasNull || hasUndefined) {
881
+ anyOf.push({ type: 'null' });
882
+ }
883
+ for (const unionType of nonNullUndefinedTypes) {
884
+ const result = serializeTypeCustom(unionType, checker, defs, visited, depth + 1);
885
+ anyOf.push(result.schema);
886
+ }
887
+ if (anyOf.length === 1) {
888
+ return { isOptional: hasNull || hasUndefined, schema: anyOf[0] };
889
+ }
890
+ return { isOptional: false, schema: { anyOf } };
891
+ }
892
+ }
893
+
827
894
  // Handle object types with properties (anonymous types)
828
895
  if (type.flags & ts.TypeFlags.Object) {
829
896
  const props = checker.getPropertiesOfType(type);
@@ -837,7 +904,7 @@ function serializeTypeCustom(
837
904
  const isOptional = (prop.flags & ts.SymbolFlags.Optional) !== 0;
838
905
 
839
906
  // Recursively serialize the property type
840
- const propResult = serializeTypeCustom(propType, checker, defs, new Set(visited), depth + 1);
907
+ const propResult = serializeTypeCustom(propType, checker, defs, visited, depth + 1);
841
908
  properties[propName] = propResult.schema;
842
909
 
843
910
  if (!isOptional && !propResult.isOptional) {