@lcap/asl
Version:
NetEase Application Specific Language
77 lines (70 loc) • 3.16 kB
text/typescript
import { BasicSchema } from '..';
export enum BASIC_TYPE {
Boolean = 'Boolean',
Integer = 'Integer',
Long = 'Long',
Decimal = 'Decimal',
String = 'String',
Text = 'Text',
Binary = 'Binary',
Date = 'Date',
Time = 'Time',
DateTime = 'DateTime',
Email = 'Email',
}
export const basicTypeList = [
{ kind: 'basicType', text: 'Boolean 布尔值', value: '#/basicTypes/Boolean' },
{ kind: 'basicType', text: 'Integer 整数', value: '#/basicTypes/Integer' },
{ kind: 'basicType', text: 'Long 长整数', value: '#/basicTypes/Long' },
{ kind: 'basicType', text: 'Double 小数', value: '#/basicTypes/Decimal' },
{ kind: 'basicType', text: 'String 字符串', value: '#/basicTypes/String' },
{ kind: 'basicType', text: 'Text 长文本', value: '#/basicTypes/Text' },
{ kind: 'basicType', text: 'Binary 二进制流', value: '#/basicTypes/Binary' },
{ kind: 'basicType', text: 'Date 日期', value: '#/basicTypes/Date' },
{ kind: 'basicType', text: 'Time 时间', value: '#/basicTypes/Time' },
{ kind: 'basicType', text: 'DateTime 日期时间', value: '#/basicTypes/DateTime' },
{ kind: 'basicType', text: 'Email 电子邮箱', value: '#/basicTypes/Email' },
];
export const basicTypeMap: { [name: string]: BasicSchema } = {
'#/basicTypes/Boolean': { type: 'boolean', format: '' },
'#/basicTypes/Integer': { type: 'integer', format: 'int' },
'#/basicTypes/Long': { type: 'integer', format: 'long' },
'#/basicTypes/Decimal': { type: 'number', format: 'double' },
'#/basicTypes/String': { type: 'string', format: '' },
'#/basicTypes/Text': { type: 'string', format: 'text' },
'#/basicTypes/Binary': { type: 'string', format: 'binary' },
'#/basicTypes/Date': { type: 'string', format: 'date' },
'#/basicTypes/Time': { type: 'string', format: 'time' },
'#/basicTypes/DateTime': { type: 'string', format: 'date-time' },
'#/basicTypes/Email': { type: 'string', format: 'email' },
};
export function getBasicTypeName(type: string, format: string) {
if (type === 'boolean')
return BASIC_TYPE.Boolean;
else if (type === 'integer' && format === 'long')
return BASIC_TYPE.Long;
else if (type === 'integer')
return BASIC_TYPE.Integer;
else if (type === 'number')
return BASIC_TYPE.Decimal;
else if (type === 'string' && format === 'text')
return BASIC_TYPE.Text;
else if (type === 'string' && format === 'binary')
return BASIC_TYPE.Binary;
else if (type === 'string' && format === 'date')
return BASIC_TYPE.Date;
else if (type === 'string' && format === 'time')
return BASIC_TYPE.Time;
else if (type === 'string' && format === 'date-time')
return BASIC_TYPE.DateTime;
else if (type === 'string' && format === 'email')
return BASIC_TYPE.Email;
else if (type === 'string')
return BASIC_TYPE.String;
}
export function getBasicTypeRef(type: string, format: string) {
return `#/basicTypes/${getBasicTypeName(type, format)}`;
}
export function getBasicTypeDefaultValue(value?: any): void {
return undefined;
}