调整 Configuration声明,支持cors的origin可以是字符串或数组

This commit is contained in:
wkj 2024-11-11 13:38:30 +08:00
parent ecf5d0123c
commit b36268f1c7
3 changed files with 65 additions and 64 deletions

View File

@ -160,7 +160,7 @@ function pushStatementIntoSchemaAst(moduleName, statement, sourceFile) {
*/
function checkActionDefNameConsistent(filename, actionDefNode) {
const { name, type } = actionDefNode;
(0, assert_1.default)(ts.isTypeReferenceNode(type));
(0, assert_1.default)(ts.isTypeReferenceNode(type), "ActionDef应该是一个类型引用");
const { typeArguments } = type;
(0, assert_1.default)(typeArguments.length === 2);
const [actionNode, stateNode] = typeArguments;
@ -189,13 +189,13 @@ function addImportedFrom(moduleName, name, node) {
let propertyName;
if (typeof node === 'object') {
const { moduleSpecifier, importClause } = node;
(0, assert_1.default)(ts.isStringLiteral(moduleSpecifier));
(0, assert_1.default)(importClause);
(0, assert_1.default)(ts.isStringLiteral(moduleSpecifier), `${moduleName}中的${name}未引用正确的moduleSpecifier`);
(0, assert_1.default)(importClause, `${moduleName}中的${name}未引用正确的importClause`);
const { namedBindings } = importClause;
(0, assert_1.default)(namedBindings);
(0, assert_1.default)(namedBindings, `${moduleName}中的${name}未引用正确的namedBindings`);
(0, assert_1.default)(ts.isNamedImports(namedBindings));
const importSpecifier = namedBindings.elements.find((ele) => ele.name.text === name);
(0, assert_1.default)(importSpecifier);
(0, assert_1.default)(importSpecifier, `${moduleName}中的${name}未引用正确的importSpecifier`);
propertyName = importSpecifier.propertyName && importSpecifier.propertyName.text;
importFrom = moduleSpecifier.text;
}
@ -210,7 +210,7 @@ function addImportedFrom(moduleName, name, node) {
});
}
else {
(0, assert_1.default)(name.endsWith("State"));
(0, assert_1.default)(name.endsWith("State"), `${moduleName}中的${name}未以State结尾`);
(0, lodash_1.assign)(ast.importStateFrom, {
[name]: [importFrom, propertyName],
});
@ -226,15 +226,15 @@ function analyzeExternalAttrImport(node, program, importAttrFrom, relativePath)
if (ts.isImportSpecifier(declaration)) {
const name = declaration.name.text;
const importDeclartion = declaration.parent.parent.parent;
(0, assert_1.default)(ts.isImportDeclaration(importDeclartion));
(0, assert_1.default)(ts.isImportDeclaration(importDeclartion), `未找到${name}的importDeclaration`);
const { moduleSpecifier, importClause } = importDeclartion;
(0, assert_1.default)(ts.isStringLiteral(moduleSpecifier));
(0, assert_1.default)(importClause);
(0, assert_1.default)(ts.isStringLiteral(moduleSpecifier), `未找到${name}的moduleSpecifier`);
(0, assert_1.default)(importClause, `未找到${name}的importClause`);
const { namedBindings } = importClause;
(0, assert_1.default)(namedBindings);
(0, assert_1.default)(ts.isNamedImports(namedBindings));
(0, assert_1.default)(namedBindings, `未找到${name}的namedBindings`);
(0, assert_1.default)(ts.isNamedImports(namedBindings), `未找到${name}的namedImports`);
const importSpecifier = namedBindings.elements.find((ele) => ele.name.text === name);
(0, assert_1.default)(importSpecifier);
(0, assert_1.default)(importSpecifier, `未找到${name}的importSpecifier`);
const propertyName = importSpecifier.propertyName && importSpecifier.propertyName.text;
const importFrom = moduleSpecifier.text;
const importFromRelatively = importFrom.startsWith('.') ? (relativePath
@ -282,7 +282,7 @@ function tryGetStringLiteralValues(moduleName, filename, obj, node, program) {
if (['state', 'action'].includes(obj)) {
(0, assert_1.default)(values.length > 0, `${filename}中的${obj} ${node.typeName.getText()}未定义`);
const importDeclartion = declaration.parent.parent.parent;
(0, assert_1.default)(ts.isImportDeclaration(importDeclartion));
(0, assert_1.default)(ts.isImportDeclaration(importDeclartion), '未找到importDeclaration');
addImportedFrom(moduleName, declaration.name.text, importDeclartion);
}
}
@ -307,7 +307,7 @@ function tryGetStringLiteralValues(moduleName, filename, obj, node, program) {
values.push(action);
}
if (['state', 'action'].includes(obj)) {
(0, assert_1.default)(values.length > 0);
(0, assert_1.default)(values.length > 0, `${filename}中的${obj} ${node.typeName.getText()}未定义`);
const ast = ActionAsts[moduleName];
addImportedFrom(moduleName, declaration.name.text, './');
}
@ -340,8 +340,9 @@ function dealWithActionTypeNode(moduleName, filename, actionTypeNode, program, s
(0, assert_1.default)((0, lodash_1.intersection)(actionNames, RESERVED_ACTION_NAMES).length === 0, `${filename}中的Action命名不能是「${RESERVED_ACTION_NAMES.join(',')}」之一`);
actionTypeNode.types.forEach(ele => {
if (ts.isTypeReferenceNode(ele)) {
// 这里递归了类型定义去查找所有的action字符串
const actionStrings = tryGetStringLiteralValues(moduleName, filename, 'action', ele, program);
(0, assert_1.default)(actionStrings.length > 0);
(0, assert_1.default)(actionStrings.length > 0, `${filename}中的Action所引用的Type定义为空`);
actionTexts.push(...actionStrings);
}
else {
@ -355,7 +356,7 @@ function dealWithActionTypeNode(moduleName, filename, actionTypeNode, program, s
(0, assert_1.default)(!RESERVED_ACTION_NAMES.includes(actionTypeNode.typeName.text), `${filename}中的Action命名不能是「${RESERVED_ACTION_NAMES.join(',')}」之一`);
}
const actionStrings = tryGetStringLiteralValues(moduleName, filename, 'action', actionTypeNode, program);
(0, assert_1.default)(actionStrings.length > 0);
(0, assert_1.default)(actionStrings.length > 0, `${filename}中的Action定义为空`);
actionTexts.push(...actionStrings);
}
else {
@ -383,10 +384,10 @@ function dealWithActionDefInitializer(moduleName, initializer, program) {
// 是从别处的引用注入到mportActionDefFrom
const checker = program.getTypeChecker();
const identifier = ts.isIdentifier(initializer) ? initializer : initializer.expression;
(0, assert_1.default)(ts.isIdentifier(identifier));
(0, assert_1.default)(ts.isIdentifier(identifier), "ActionDef的initializer不是一个Identifier");
const symbol = checker.getSymbolAtLocation(identifier);
const declaration = symbol?.getDeclarations()[0];
(0, assert_1.default)(ts.isImportSpecifier(declaration));
(0, assert_1.default)(ts.isImportSpecifier(declaration), "ActionDef的initializer不是一个ImportSpecifier");
const importDeclartion = declaration.parent.parent.parent;
addImportedFrom(moduleName, identifier.text, importDeclartion);
}
@ -419,7 +420,7 @@ function getEntityImported(declaration) {
function checkLocaleEnumAttrs(node, attrs, filename) {
const { members } = node;
const memberKeys = members.map((ele) => {
(0, assert_1.default)(ts.isPropertySignature(ele) && ts.isIdentifier(ele.name));
(0, assert_1.default)(ts.isPropertySignature(ele) && ts.isIdentifier(ele.name), 'locale定义中的属性必须是identifier');
return ele.name.text;
});
const lack = (0, lodash_1.difference)(attrs, memberKeys);
@ -433,7 +434,7 @@ function checkLocaleExpressionPropertyExists(root, attr, exists, filename) {
(0, assert_1.default)(ts.isPropertyAssignment(ele) && (ts.isIdentifier(ele.name) || ts.isStringLiteral(ele.name)) && ts.isObjectLiteralExpression(ele.initializer));
const { properties: p2 } = ele.initializer;
const pp = p2.find((ele2) => {
(0, assert_1.default)(ts.isPropertyAssignment(ele2) && ts.isIdentifier(ele2.name));
(0, assert_1.default)(ts.isPropertyAssignment(ele2) && ts.isIdentifier(ele2.name), 'locale定义中的属性必须是identifier');
return ele2.name.text === attr;
});
if (exists && !pp) {
@ -594,7 +595,7 @@ function getImportedFilePath(path, fileSpecifierPath, filename) {
const cwd = process.cwd();
const fileSpecifierPaths = fileSpecifierPath.split('/');
const moduleName = fileSpecifierPaths[0] || fileSpecifierPaths[1];
(0, assert_1.default)(moduleName);
(0, assert_1.default)(moduleName, '「${filename}」中import路径不合法');
// 从path向外找package.json -> node_modules直至找到fileSpecifier
const paths = path.split('/');
for (let iter = paths.length; iter >= 0; iter--) {
@ -628,24 +629,24 @@ function analyzeSchemaDefinition(node, moduleName, filename, path, program, refe
let toLog = false;
const extendsFrom = [];
const { members, heritageClauses } = node;
(0, assert_1.default)(heritageClauses);
(0, assert_1.default)(heritageClauses, `${filename}」中的Schema定义需要继承EntityShape或者其他Entity`);
const heritagedResult = heritageClauses.map((clause) => {
const { expression } = clause.types[0];
(0, assert_1.default)(ts.isIdentifier(expression));
(0, assert_1.default)(ts.isIdentifier(expression), `${expression}不是一个合法的继承类型`);
if (expression.text === 'EntityShape') {
// import { EntityShape } from 'oak-domain/lib/types/Entities; 所有schema的公共祖先类型不用处理
return;
}
// 从其它文件的Schema类继承这里需要将所继承的对象的属性进行访问并展开
(0, assert_1.default)(referencedSchemas.includes(expression.text));
(0, assert_1.default)(referencedSchemas.includes(expression.text), `${filename}」中的Schema继承了未定义的实体「${expression.text}`);
const checker = program.getTypeChecker();
const symbol = checker.getSymbolAtLocation(expression);
let declaration = symbol?.getDeclarations()[0];
(0, assert_1.default)(ts.isImportSpecifier(declaration));
(0, assert_1.default)(ts.isImportSpecifier(declaration), `${declaration.getText()}应该是导入的类型`);
const importDeclaration = declaration.parent.parent.parent;
(0, assert_1.default)(ts.isImportDeclaration(importDeclaration));
(0, assert_1.default)(ts.isImportDeclaration(importDeclaration), `${declaration.getText()}应该是导入的类型`);
const { moduleSpecifier } = importDeclaration;
(0, assert_1.default)(ts.isStringLiteral(moduleSpecifier));
(0, assert_1.default)(ts.isStringLiteral(moduleSpecifier), `${declaration.getText()}应该是导入的类型`);
const { text: from } = moduleSpecifier;
extendsFrom.push(from);
// 创建编译器主机
@ -655,7 +656,7 @@ function analyzeSchemaDefinition(node, moduleName, filename, path, program, refe
// assert(resolvedModule.resolvedModule, "找不到module定义")
let pathName = "";
if (!resolvedModule.resolvedModule) {
console.warn(`${filename}」找不到相应的module定义${from}`);
console.warn(`${filename}」找不到相应的module定义${from},尝试查找本地文件`);
pathName = getImportedFilePath(path, from, filename);
}
else {
@ -745,7 +746,7 @@ function analyzeSchemaDefinition(node, moduleName, filename, path, program, refe
else {
schemaAttrs.push(attrNode);
if (ts.isUnionTypeNode(type) && ts.isLiteralTypeNode(type.types[0]) && ts.isStringLiteral(type.types[0].literal)) {
(0, assert_1.default)(ts.isIdentifier(name));
(0, assert_1.default)(ts.isIdentifier(name), `${filename}」中的属性定义不是String类型`);
const { types } = type;
const enumValues = types.map((ele) => checkStringLiteralLegal(filename, '属性', name.text, ele));
enumAttributes[name.text] = enumValues;
@ -840,13 +841,13 @@ function analyzeReferenceSchemaFile(moduleName, filename, path, sourceFile, prog
}
}
});
(0, assert_1.default)(result);
(0, assert_1.default)(result, `${filename}」中没有找到Schema定义`);
return result;
}
function analyzeEntity(filename, path, program, relativePath) {
const fullPath = `${path}/${filename}`;
const sourceFile = program.getSourceFile(fullPath);
(0, assert_1.default)(sourceFile);
(0, assert_1.default)(sourceFile, `${filename}」文件不存在`);
const moduleName = filename.split('.')[0];
if (Schema.hasOwnProperty(moduleName)) {
delete ActionAsts[moduleName];
@ -933,13 +934,13 @@ function analyzeEntity(filename, path, program, relativePath) {
(0, assert_1.default)(!localeDef, `${filename}】locale定义须在Relation之后`);
const relationValues = [];
if (ts.isLiteralTypeNode(node.type)) {
(0, assert_1.default)(ts.isStringLiteral(node.type.literal));
(0, assert_1.default)(ts.isStringLiteral(node.type.literal), `${filename}中的Relation的定义只能是string类型`);
(0, assert_1.default)(node.type.literal.text.length < env_1.STRING_LITERAL_MAX_LENGTH, `Relation定义的字符串长度不长于${env_1.STRING_LITERAL_MAX_LENGTH}${filename}${node.type.literal.text}`);
relationValues.push(node.type.literal.text);
}
else if (ts.isTypeReferenceNode(node.type)) {
const relationStrings = tryGetStringLiteralValues(moduleName, filename, 'relation', node.type, program);
(0, assert_1.default)(relationStrings.length > 0);
(0, assert_1.default)(relationStrings.length > 0, `文件${filename}中的relation${node.type.typeName.text}定义未找到字符串类型`);
relationValues.push(...relationStrings);
}
else {
@ -953,7 +954,7 @@ function analyzeEntity(filename, path, program, relativePath) {
else {
(0, assert_1.default)(ts.isTypeReferenceNode(ele), `Relation的定义只能是string类型或者string union类型或者两者的union${filename}`);
const relationStrings = tryGetStringLiteralValues(moduleName, filename, 'relation', ele, program);
(0, assert_1.default)(relationStrings.length > 0);
(0, assert_1.default)(relationStrings.length > 0, `文件${filename}中的relation${ele.typeName.text}定义未找到字符串类型`);
relationValues.push(...relationStrings);
}
});
@ -1005,7 +1006,7 @@ function analyzeEntity(filename, path, program, relativePath) {
]) : type), sourceFile);
}
else {
(0, assert_1.default)(ts.isLiteralTypeNode(type) || ts.isTypeReferenceNode(type), `${moduleName} - ${node.name}`);
(0, assert_1.default)(ts.isLiteralTypeNode(type) || ts.isTypeReferenceNode(type), `文件${filename}中的${type.getText()}应该是字面量或引用类型`);
pushStatementIntoActionAst(moduleName, factory.updateTypeAliasDeclaration(node, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], node.name, node.typeParameters, process.env.COMPLING_AS_LIB ? factory.createUnionTypeNode([
type,
factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
@ -1022,12 +1023,12 @@ function analyzeEntity(filename, path, program, relativePath) {
const dealWithActionDef = (declaration) => {
checkActionDefNameConsistent(filename, declaration);
const { typeArguments } = declaration.type;
(0, assert_1.default)(typeArguments.length === 2);
(0, assert_1.default)(typeArguments.length === 2, `文件${filename}中的action定义不是两个泛型参数`);
const [actionNode, stateNode] = typeArguments;
(0, assert_1.default)(ts.isTypeReferenceNode(actionNode));
(0, assert_1.default)(ts.isTypeReferenceNode(actionNode), `文件${filename}中的action定义不是TypeReferenceNode`);
// 这里有可能引用的Action不是本文件的定义要调用这个函数加到importFrom中
tryGetStringLiteralValues(moduleName, filename, 'action', actionNode, program);
(0, assert_1.default)(ts.isTypeReferenceNode(stateNode));
(0, assert_1.default)(ts.isTypeReferenceNode(stateNode), `文件${filename}中的action定义不是TypeReferenceNode`);
const enumStateValues = tryGetStringLiteralValues(moduleName, filename, 'state', stateNode, program);
(0, assert_1.default)(enumStateValues.length > 0, `文件${filename}中的state${stateNode.typeName.text}定义不是字符串类型`);
pushStatementIntoActionAst(moduleName, node, sourceFile);
@ -1044,18 +1045,18 @@ function analyzeEntity(filename, path, program, relativePath) {
const { elements } = declaration;
elements.forEach((ele) => {
let isFulltextIndex = false;
(0, assert_1.default)(ts.isObjectLiteralExpression(ele));
(0, assert_1.default)(ts.isObjectLiteralExpression(ele), `${filename}」中索引定义应该是对象字面量`);
const { properties } = ele;
const attrProperty = properties.find((ele2) => {
(0, assert_1.default)(ts.isPropertyAssignment(ele2));
(0, assert_1.default)(ts.isPropertyAssignment(ele2), `${filename}」中索引的属性不为PropertyAssignment`);
return ele2.name.getText() === 'attributes';
});
(0, assert_1.default)(ts.isArrayLiteralExpression(attrProperty.initializer));
(0, assert_1.default)(ts.isArrayLiteralExpression(attrProperty.initializer), `${filename}」中索引的attributes属性应该是数组字面量`);
const nameProperty = properties.find((ele2) => {
(0, assert_1.default)(ts.isPropertyAssignment(ele2));
return ele2.name.getText() === 'name';
});
(0, assert_1.default)(ts.isStringLiteral(nameProperty.initializer));
(0, assert_1.default)(ts.isStringLiteral(nameProperty.initializer), '「${filename}」中索引的name属性应该是字符串字面量');
const nameText = nameProperty.initializer.text;
if (indexNameDict[nameText]) {
throw new Error(`${filename}」索引定义重名「${nameText}`);
@ -1064,14 +1065,14 @@ function analyzeEntity(filename, path, program, relativePath) {
[nameText]: true,
});
const configProperty = properties.find((ele2) => {
(0, assert_1.default)(ts.isPropertyAssignment(ele2));
(0, assert_1.default)(ts.isPropertyAssignment(ele2), `${filename}」中索引的属性不为PropertyAssignment`);
return ele2.name.getText() === 'config';
});
if (configProperty) {
(0, assert_1.default)(ts.isObjectLiteralExpression(configProperty.initializer));
(0, assert_1.default)(ts.isObjectLiteralExpression(configProperty.initializer), `${filename}」中索引的config属性应该是对象字面量`);
const { properties: properties2 } = configProperty.initializer;
const typeProperty = properties2.find((ele2) => {
(0, assert_1.default)(ts.isPropertyAssignment(ele2));
(0, assert_1.default)(ts.isPropertyAssignment(ele2), `${filename}」中索引的属性不为PropertyAssignment`);
return ele2.name.getText() === 'type';
});
if (typeProperty && typeProperty.initializer.text === 'fulltext') {
@ -1186,21 +1187,21 @@ function analyzeEntity(filename, path, program, relativePath) {
if (ts.isObjectLiteralExpression(declaration)) {
const { properties } = declaration;
const localesProperty = properties.find(ele => ts.isPropertyAssignment(ele) && ts.isIdentifier(ele.name) && ele.name.text === 'locales');
(0, assert_1.default)(ts.isPropertyAssignment(localesProperty));
(0, assert_1.default)(ts.isPropertyAssignment(localesProperty), `${filename}」中entityDesc的locales应该是属性声明`);
dealWithLocales(localesProperty.initializer);
const indexesProperty = properties.find(ele => ts.isPropertyAssignment(ele) && ts.isIdentifier(ele.name) && ele.name.text === 'indexes');
if (indexesProperty) {
(0, assert_1.default)(ts.isPropertyAssignment(indexesProperty));
(0, assert_1.default)(ts.isPropertyAssignment(indexesProperty), `${filename}」中entityDesc的indexes应该是属性声明`);
dealWithIndexes(indexesProperty.initializer);
}
const configurationProperty = properties.find(ele => ts.isPropertyAssignment(ele) && ts.isIdentifier(ele.name) && ele.name.text === 'configuration');
if (configurationProperty) {
(0, assert_1.default)(ts.isPropertyAssignment(configurationProperty));
(0, assert_1.default)(ts.isPropertyAssignment(configurationProperty), `${filename}」中entityDesc的configuration应该是属性声明`);
dealWithConfiguration(configurationProperty.initializer);
}
const styleDescProperty = properties.find(ele => ts.isPropertyAssignment(ele) && ts.isIdentifier(ele.name) && ele.name.text === 'style');
if (styleDescProperty) {
(0, assert_1.default)(ts.isPropertyAssignment(styleDescProperty));
(0, assert_1.default)(ts.isPropertyAssignment(styleDescProperty), `${filename}」中entityDesc的style应该是属性声明`);
dealWithStyleDesc(styleDescProperty.initializer);
}
}
@ -1231,14 +1232,14 @@ function analyzeEntity(filename, path, program, relativePath) {
&& declaration.type.typeArguments[0].typeName.text === 'Index')) {
// 对索引Index的定义
console.log(`${filename}」直接定义indexes的写法已经过时请定义在entityDesc中`);
(0, assert_1.default)(ts.isArrayLiteralExpression(declaration.initializer));
(0, assert_1.default)(ts.isArrayLiteralExpression(declaration.initializer), `${filename}」中索引定义应该是数组字面量`);
dealWithIndexes(declaration.initializer);
}
else if (declaration.type && ts.isTypeReferenceNode(declaration.type) && ts.isIdentifier(declaration.type.typeName) && declaration.type.typeName.text === 'LocaleDef') {
// locale定义
console.log(`${filename}」直接定义locales的写法已经过时请定义在entityDesc中`);
const { type, initializer } = declaration;
(0, assert_1.default)(ts.isObjectLiteralExpression(initializer));
(0, assert_1.default)(ts.isObjectLiteralExpression(initializer), `${filename}」中locale定义应该是对象字面量`);
const { properties } = initializer;
(0, assert_1.default)(properties.length > 0, `${filename}至少需要有一种locale定义`);
const allEnumStringAttrs = Object.keys(enumAttributes);
@ -1275,12 +1276,12 @@ function analyzeEntity(filename, path, program, relativePath) {
}
else if (declaration.type && ts.isTypeReferenceNode(declaration.type) && ts.isIdentifier(declaration.type.typeName) && declaration.type.typeName.text === 'Configuration') {
console.log(`${filename}」直接定义configuration的写法已经过时请定义在entityDesc中`);
(0, assert_1.default)(ts.isObjectLiteralExpression(declaration.initializer));
(0, assert_1.default)(ts.isObjectLiteralExpression(declaration.initializer), `${filename}」中configuration定义应该是对象字面量`);
dealWithConfiguration(declaration.initializer);
}
else if (declaration.type && ts.isTypeReferenceNode(declaration.type) && ts.isIdentifier(declaration.type.typeName) && declaration.type.typeName.text === 'EntityDesc') {
const { initializer } = declaration;
(0, assert_1.default)(initializer);
(0, assert_1.default)(initializer, `${filename}」中entityDesc的定义不应该为空`);
dealWithEntityDesc(initializer);
}
else {
@ -1624,7 +1625,7 @@ function constructFilter(statements, entity) {
}
else {
// 此时应当是引用本地定义的shape
(0, assert_1.default)(type);
(0, assert_1.default)(type, `${entity}中的属性${name.toString()}有非法的属性类型定义`);
members.push(factory.createPropertySignature(undefined, name, undefined, factory.createTypeReferenceNode(factory.createIdentifier('JsonFilter'), [
type
])));
@ -3125,7 +3126,7 @@ function outputSchema(outputDir, printer) {
const fromLocalActionSpecifiers = ['Action', 'ParticularAction'];
const fromExtenalStates = {};
for (const state in importStateFrom) {
(0, assert_1.default)(state.endsWith('State'));
(0, assert_1.default)(state.endsWith('State'), `${state} should end with State`);
if (importStateFrom[state][0] === './') {
// 本地定义的State从 ./Action 中获取
fromLocalActionSpecifiers.push(state);
@ -3254,7 +3255,7 @@ function outputAction(outputDir, printer) {
const importStatements = [];
const fromExternalImports = {};
for (const state in importStateFrom) {
(0, assert_1.default)(state.endsWith('State'));
(0, assert_1.default)(state.endsWith('State'), `${state} should end with State`);
const [from, propertyName] = importStateFrom[state];
if (from !== './') {
if (fromExternalImports[from]) {
@ -3266,7 +3267,7 @@ function outputAction(outputDir, printer) {
}
}
for (const action in importActionFrom) {
(0, assert_1.default)(action.endsWith('Action'));
(0, assert_1.default)(action.endsWith('Action'), `${action} should end with Action`);
const [from, propertyName] = importActionFrom[action];
if (from !== './') {
if (fromExternalImports[from]) {
@ -3278,7 +3279,7 @@ function outputAction(outputDir, printer) {
}
}
for (const def in importActionDefFrom) {
(0, assert_1.default)(def.endsWith('ActionDef'));
(0, assert_1.default)(def.endsWith('ActionDef'), `${def} should end with ActionDef`);
const [from, propertyName] = importActionDefFrom[def];
if (from !== './') {
if (fromExternalImports[from]) {
@ -3420,11 +3421,11 @@ function constructAttributes(entity) {
if (ts.isUnionTypeNode(type)) {
if (ts.isLiteralTypeNode(type.types[0])) {
if (ts.isStringLiteral(type.types[0].literal)) {
(0, assert_1.default)(enumAttributes && enumAttributes[name.text]);
(0, assert_1.default)(enumAttributes && enumAttributes[name.text], `${entity}对象中的${name.text}属性没有定义enumAttributes`);
attrAssignments.push(factory.createPropertyAssignment('type', factory.createStringLiteral("enum")), factory.createPropertyAssignment('enumeration', factory.createArrayLiteralExpression(enumAttributes[name.text].map(ele => factory.createStringLiteral(ele)))));
}
else {
(0, assert_1.default)(ts.isNumericLiteral(type.types[0].literal));
(0, assert_1.default)(ts.isNumericLiteral(type.types[0].literal), `${entity}对象中的${type.types[0].literal.getText()}属性不是数字`);
attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("type"), factory.createStringLiteral("int")), factory.createPropertyAssignment(factory.createIdentifier("params"), factory.createObjectLiteralExpression([
factory.createPropertyAssignment(factory.createIdentifier("width"), factory.createNumericLiteral(env_1.INT_LITERL_DEFAULT_WIDTH))
], true)));
@ -3441,7 +3442,7 @@ function constructAttributes(entity) {
attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("type"), factory.createStringLiteral("varchar")), factory.createPropertyAssignment(factory.createIdentifier("params"), factory.createObjectLiteralExpression([factory.createPropertyAssignment(factory.createIdentifier("length"), factory.createNumericLiteral(env_1.STRING_LITERAL_MAX_LENGTH))], true)));
}
else {
(0, assert_1.default)(ts.isNumericLiteral(type.literal));
(0, assert_1.default)(ts.isNumericLiteral(type.literal), `${entity}对象中的${name.text}属性不是数字`);
attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("type"), factory.createStringLiteral("precision")), factory.createPropertyAssignment(factory.createIdentifier("params"), factory.createObjectLiteralExpression([
factory.createPropertyAssignment(factory.createIdentifier("precision"), factory.createNumericLiteral(env_1.NUMERICAL_LITERL_DEFAULT_PRECISION)),
factory.createPropertyAssignment(factory.createIdentifier("scale"), factory.createNumericLiteral(env_1.NUMERICAL_LITERL_DEFAULT_SCALE))
@ -3466,7 +3467,7 @@ function outputLocale(outputDir, printer) {
if (locale) {
const { properties } = locale;
properties.forEach((ele) => {
(0, assert_1.default)(ts.isPropertyAssignment(ele) && (ts.isIdentifier(ele.name) || ts.isStringLiteral(ele.name)) && ts.isObjectLiteralExpression(ele.initializer));
(0, assert_1.default)(ts.isPropertyAssignment(ele) && (ts.isIdentifier(ele.name) || ts.isStringLiteral(ele.name)) && ts.isObjectLiteralExpression(ele.initializer), `${entity}对象中的locale属性定义不正确`);
const lng = ele.name.text;
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray([
factory.createReturnStatement(ele.initializer)

View File

@ -29,7 +29,7 @@ export type ServerConfiguration = {
socketPath: string;
};
cors?: {
origin: string;
origin: string | string[];
headers?: string[];
methods?: string[];
};

View File

@ -31,7 +31,7 @@ export type ServerConfiguration = {
socketPath: string;
},
cors?: {
origin: string;
origin: string | string[];
headers?: string[];
methods?: string[];
},