@arcteninc/core 0.0.67 → 0.0.68

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.67",
3
+ "version": "0.0.68",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -106,3 +106,4 @@ async function run() {
106
106
 
107
107
  run();
108
108
 
109
+
@@ -1,25 +1,25 @@
1
- #!/usr/bin/env node
2
- /**
3
- * JavaScript wrapper for the CommonJS wrapper script
4
- * This file exists to ensure binary resolution works correctly
5
- * when package managers look for .js files
6
- *
7
- * Works in both Bun and Node.js environments, even when package.json has "type": "module"
8
- */
9
-
10
- import { createRequire } from 'module';
11
- import { fileURLToPath } from 'url';
12
- import { dirname, join } from 'path';
13
-
14
- // Get __dirname equivalent for ES modules
15
- const __filename = fileURLToPath(import.meta.url);
16
- const __dirname = dirname(__filename);
17
-
18
- // Create require function that works in ES module context
19
- const require = createRequire(import.meta.url);
20
-
21
- // Load and execute the CommonJS wrapper
22
- // This works in both Node.js (v12+) and Bun
23
- const wrapperPath = join(__dirname, 'cli-extract-types-auto-wrapper.cjs');
24
- require(wrapperPath);
25
-
1
+ #!/usr/bin/env node
2
+ /**
3
+ * JavaScript wrapper for the CommonJS wrapper script
4
+ * This file exists to ensure binary resolution works correctly
5
+ * when package managers look for .js files
6
+ *
7
+ * Works in both Bun and Node.js environments, even when package.json has "type": "module"
8
+ */
9
+
10
+ import { createRequire } from 'module';
11
+ import { fileURLToPath } from 'url';
12
+ import { dirname, join } from 'path';
13
+
14
+ // Get __dirname equivalent for ES modules
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = dirname(__filename);
17
+
18
+ // Create require function that works in ES module context
19
+ const require = createRequire(import.meta.url);
20
+
21
+ // Load and execute the CommonJS wrapper
22
+ // This works in both Node.js (v12+) and Bun
23
+ const wrapperPath = join(__dirname, 'cli-extract-types-auto-wrapper.cjs');
24
+ require(wrapperPath);
25
+
@@ -843,6 +843,75 @@ function serializeTypeCustom(
843
843
  }
844
844
  }
845
845
 
846
+ // Handle Partial<T> utility type
847
+ // Check if this is a type reference (like Partial<Settings>)
848
+ // TypeScript represents Partial<T> as a TypeReference with typeArguments
849
+ if (type.flags & ts.TypeFlags.Object) {
850
+ const typeRef = type as ts.TypeReference;
851
+ if (typeRef.typeArguments && typeRef.typeArguments.length > 0) {
852
+ const typeSymbol = type.getSymbol();
853
+ const aliasSymbol = (type as any).getAliasSymbol ? (type as any).getAliasSymbol(checker) : null;
854
+
855
+ // Check symbol name or alias symbol name
856
+ const typeName = typeSymbol?.getName() || aliasSymbol?.getName();
857
+
858
+ // Also check type string as fallback (e.g., "Partial<Settings>")
859
+ const typeString = checker.typeToString(type);
860
+
861
+ // Check if it's Partial utility type
862
+ if (typeName === 'Partial' || typeString.startsWith('Partial<')) {
863
+ // Extract the type argument (the T in Partial<T>)
864
+ const baseType = typeRef.typeArguments[0];
865
+
866
+ // Process the base type to get its properties
867
+ const baseResult = serializeTypeCustom(baseType, checker, defs, visited, depth + 1);
868
+
869
+ // If the base type is an object with properties, make all properties optional
870
+ if (baseResult.schema.type === 'object' && baseResult.schema.properties) {
871
+ return {
872
+ isOptional: false,
873
+ schema: {
874
+ type: 'object',
875
+ properties: baseResult.schema.properties,
876
+ // Don't include 'required' - all properties are optional in Partial<T>
877
+ }
878
+ };
879
+ }
880
+
881
+ // If base type uses $ref, we need to handle it differently
882
+ // For Partial<SomeInterface>, we need to make all properties optional
883
+ if (baseResult.schema.$ref) {
884
+ // Get the referenced type and process it
885
+ const refTypeName = baseResult.schema.$ref.replace('#/$defs/', '');
886
+ if (defs && defs[refTypeName]) {
887
+ const refSchema = defs[refTypeName];
888
+ if (refSchema.type === 'object' && refSchema.properties) {
889
+ // Create a new schema with all properties optional
890
+ return {
891
+ isOptional: false,
892
+ schema: {
893
+ type: 'object',
894
+ properties: refSchema.properties,
895
+ // No required array - all optional
896
+ }
897
+ };
898
+ }
899
+ }
900
+ }
901
+
902
+ // Fallback: return the base result but mark as all optional
903
+ return {
904
+ isOptional: false,
905
+ schema: {
906
+ ...baseResult.schema,
907
+ // Remove required if present
908
+ required: undefined,
909
+ }
910
+ };
911
+ }
912
+ }
913
+ }
914
+
846
915
  // Handle arrays
847
916
  if (checker.isArrayType(type)) {
848
917
  const typeArgs = (type as ts.TypeReference).typeArguments;
@@ -984,6 +1053,73 @@ async function serializeType(
984
1053
  return { isOptional: false, schema: { type: 'number', const: literalType.value } };
985
1054
  }
986
1055
 
1056
+ // Handle Partial<T> utility type - check early before other type processing
1057
+ if (type.flags & ts.TypeFlags.Object) {
1058
+ const typeRef = type as ts.TypeReference;
1059
+ if (typeRef.typeArguments && typeRef.typeArguments.length > 0) {
1060
+ const typeSymbol = type.getSymbol();
1061
+ const aliasSymbol = (type as any).getAliasSymbol ? (type as any).getAliasSymbol(checker) : null;
1062
+
1063
+ // Check symbol name or alias symbol name
1064
+ const typeName = typeSymbol?.getName() || aliasSymbol?.getName();
1065
+
1066
+ // Also check type string as fallback (e.g., "Partial<Settings>")
1067
+ const typeString = checker.typeToString(type);
1068
+
1069
+ // Check if it's Partial utility type
1070
+ if (typeName === 'Partial' || typeString.startsWith('Partial<')) {
1071
+ // Extract the type argument (the T in Partial<T>)
1072
+ const baseType = typeRef.typeArguments[0];
1073
+
1074
+ // Process the base type to get its properties
1075
+ const baseResult = await serializeType(baseType, checker, program, configPath, defs);
1076
+
1077
+ // If the base type is an object with properties, make all properties optional
1078
+ if (baseResult.schema.type === 'object' && baseResult.schema.properties) {
1079
+ return {
1080
+ isOptional: false,
1081
+ schema: {
1082
+ type: 'object',
1083
+ properties: baseResult.schema.properties,
1084
+ // Don't include 'required' - all properties are optional in Partial<T>
1085
+ }
1086
+ };
1087
+ }
1088
+
1089
+ // If base type uses $ref, we need to handle it differently
1090
+ // For Partial<SomeInterface>, we need to make all properties optional
1091
+ if (baseResult.schema.$ref) {
1092
+ // Get the referenced type and process it
1093
+ const refTypeName = baseResult.schema.$ref.replace('#/$defs/', '');
1094
+ if (defs && defs[refTypeName]) {
1095
+ const refSchema = defs[refTypeName];
1096
+ if (refSchema.type === 'object' && refSchema.properties) {
1097
+ // Create a new schema with all properties optional
1098
+ return {
1099
+ isOptional: false,
1100
+ schema: {
1101
+ type: 'object',
1102
+ properties: refSchema.properties,
1103
+ // No required array - all optional
1104
+ }
1105
+ };
1106
+ }
1107
+ }
1108
+ }
1109
+
1110
+ // Fallback: return the base result but mark as all optional
1111
+ return {
1112
+ isOptional: false,
1113
+ schema: {
1114
+ ...baseResult.schema,
1115
+ // Remove required if present
1116
+ required: undefined,
1117
+ }
1118
+ };
1119
+ }
1120
+ }
1121
+ }
1122
+
987
1123
  // Handle arrays
988
1124
  if (checker.isArrayType(type)) {
989
1125
  const typeArgs = (type as ts.TypeReference).typeArguments;
@@ -1276,6 +1412,11 @@ async function extractFunctionMetadata(
1276
1412
  let isOptional = false;
1277
1413
 
1278
1414
  if (param.type) {
1415
+ // Check if the type node text contains "Partial<" before resolving
1416
+ // This helps us detect Partial<T> even if TypeScript resolves it differently
1417
+ const typeNodeText = param.type.getText(sourceFile);
1418
+ const isPartialType = typeNodeText.startsWith('Partial<') || typeNodeText.includes('Partial<');
1419
+
1279
1420
  // Try to get type from type annotation
1280
1421
  let type = checker.getTypeFromTypeNode(param.type);
1281
1422
 
@@ -1291,11 +1432,53 @@ async function extractFunctionMetadata(
1291
1432
  }
1292
1433
  }
1293
1434
 
1294
- // Use ts-json-schema-generator for named types only
1295
- // Anonymous types are not supported - agents can't use them anyway
1296
- const result = await serializeType(type, checker, program, configPath, defs);
1297
- propSchema = result.schema;
1298
- isOptional = result.isOptional;
1435
+ // If we detected Partial<T> from the type node, try to extract the base type
1436
+ if (isPartialType && ts.isTypeReferenceNode(param.type) && param.type.typeArguments && param.type.typeArguments.length > 0) {
1437
+ // Extract the base type (T from Partial<T>)
1438
+ const baseTypeNode = param.type.typeArguments[0];
1439
+ const baseType = checker.getTypeFromTypeNode(baseTypeNode);
1440
+
1441
+ // Process the base type
1442
+ const baseResult = await serializeType(baseType, checker, program, configPath, defs);
1443
+
1444
+ // Make all properties optional
1445
+ if (baseResult.schema.type === 'object' && baseResult.schema.properties) {
1446
+ propSchema = {
1447
+ type: 'object',
1448
+ properties: baseResult.schema.properties,
1449
+ // No required array - all properties optional
1450
+ };
1451
+ isOptional = false; // The parameter itself is not optional, but its properties are
1452
+ } else if (baseResult.schema.$ref) {
1453
+ // Handle $ref case
1454
+ const refTypeName = baseResult.schema.$ref.replace('#/$defs/', '');
1455
+ if (defs && defs[refTypeName]) {
1456
+ const refSchema = defs[refTypeName];
1457
+ if (refSchema.type === 'object' && refSchema.properties) {
1458
+ propSchema = {
1459
+ type: 'object',
1460
+ properties: refSchema.properties,
1461
+ };
1462
+ isOptional = false;
1463
+ } else {
1464
+ propSchema = baseResult.schema;
1465
+ isOptional = baseResult.isOptional;
1466
+ }
1467
+ } else {
1468
+ propSchema = baseResult.schema;
1469
+ isOptional = baseResult.isOptional;
1470
+ }
1471
+ } else {
1472
+ propSchema = baseResult.schema;
1473
+ isOptional = baseResult.isOptional;
1474
+ }
1475
+ } else {
1476
+ // Use ts-json-schema-generator for named types only
1477
+ // Anonymous types are not supported - agents can't use them anyway
1478
+ const result = await serializeType(type, checker, program, configPath, defs);
1479
+ propSchema = result.schema;
1480
+ isOptional = result.isOptional;
1481
+ }
1299
1482
  } else {
1300
1483
  propSchema = {}; // Empty schema = any value (JSON Schema draft 2020-12)
1301
1484
  }