chore: add tests

This commit is contained in:
2026-04-13 10:18:12 +08:00
parent 14948fb5f6
commit 51a11a26bf
5 changed files with 521 additions and 5 deletions
+11 -2
View File
@@ -230,9 +230,13 @@ function schemaToTypeString(schema: Schema, resourceNames?: Map<string, string>)
return 'number';
case 'boolean':
return 'boolean';
case 'stringLiteral':
return `"${schema.value}"`;
case 'union':
return schema.members.map(m => schemaToTypeString(m, resourceNames)).join(' | ');
case 'reference': {
// Use the resource name mapping if provided, otherwise capitalize table name
const typeName = resourceNames?.get(schema.tableName) ||
const typeName = resourceNames?.get(schema.tableName) ||
schema.tableName.charAt(0).toUpperCase() + schema.tableName.slice(1);
return schema.isArray ? `readonly ${typeName}[]` : typeName;
}
@@ -244,7 +248,12 @@ function schemaToTypeString(schema: Schema, resourceNames?: Map<string, string>)
});
return `readonly [${tupleElements.join(', ')}]`;
}
return `readonly ${schemaToTypeString(schema.element, resourceNames)}[]`;
// Wrap union types in parentheses to maintain correct precedence
const elementType = schemaToTypeString(schema.element, resourceNames);
if (schema.element.type === 'union') {
return `readonly (${elementType})[]`;
}
return `readonly ${elementType}[]`;
case 'tuple':
const tupleElements = schema.elements.map((el) => {
const typeStr = schemaToTypeString(el.schema, resourceNames);