@lcap/nasl
Version:
NetEase Application Specific Language
100 lines (96 loc) • 4.29 kB
TypeScript
// 基本类型定义
type Any = any;
type Long = number;
type Decimal = number;
type Boolean = boolean;
type String = string;
/* 日期类型 */
type Date = globalThis.Date;
/* 时间类型 */
class Time {
accept: 'Time';
}
/* 日期时间类型 */
class DateTime {
accept: 'DateTime';
}
type List<T> = Array<T>;
/*
* for...of 语句
* 这是唯一一个可以在逻辑中使用的循环语句,用于遍历列表中的元素,禁止使用for、while等其他循环语句。
* param index: Long,当前索引,必填
* param item: T,当前元素,必填
* [index, item] 为解构赋值,顺序不可颠倒。
* ListEntries 仅用于for...of循环,声明为: function ListEntries<T>(list: T[], start?: Long, end?: Long): [Long, T][];
* param list: List<T>,需要遍历的列表,必填
* param start: Long,开始索引,默认值 0
* param end: Long,结束索引,默认值 list.length
* ListEntries([1, 2, 3]) => [[0, 1], [1, 2], [2, 3]]
* ListEntries([1, 2, 3], 1, 2) => [[1, 2]]
* @example for (const [index, item] of ListEntries(list, start, end)) { console.log(index, item); }
* @example for (const [index, item] of ListEntries(nasl.util.ListRange(2, 5, 1))) { console.log(index, item); }
*/
// 基本运算函数,用于数学计算
declare function plus(left: Decimal, right: Decimal): Decimal;
declare function minus(left: Decimal, right: Decimal): Decimal;
declare function multiply(left: Decimal, right: Decimal): Decimal;
declare function divide(left: Decimal, right: Decimal): Decimal;
declare function remainder(left: Decimal, right: Decimal): Decimal;
/**
* 数据实体接口
* 作用:查询、创建、更新和删除数据表中的数据
*/
interface Entity<T> {
/* 根据主键ID获取一条数据 */
get(id: Long): T;
/**
* 将传入的数据实体插入到数据表中
* @param entity 数据实体,T类型。不包含id, createTime, updateTime, createdBy, updatedBy字段
* @returns 返回插入的数据实体,T类型。已自动生成id, createTime, updateTime, createdBy, updatedBy字段, 可以通过返回值获取插入数据在数据库中的id
* @example const person = nasl.util.NewEntity<Person>({name: 'test', age: 18}; insertPerson = PersonEntity.create(person); // 可以根据insertPerson.id获取插入数据在数据库中的id
*/
create(entity: T): T;
/* 根据传入的数据对象更新数据表中的数据 */
update(entity: T): T;
/* 根据主键ID删除数据表中的数据 */
delete(id: Long): void;
/* 根据传入的数据对象创建或更新数据表中的数据 */
createOrUpdate(body: T): T;
/* 根据主键ID列表批量删除数据表中的数据 */
batchCreate(list: List<T>): List<T>;
/* 根据传入的数据对象列表批量更新数据表中的数据 */
batchUpdate(list: List<T>): List<T>;
/* 根据主键ID列表批量删除数据表中的数据 */
batchDelete(list: List<Long>): void;
}
/*
* createEntity函数:根据数据表类型创建一个数据实体接口,然后通过该接口调用数据表中的数据。
* @example const LCAPUserEntity = createEntity<LCAPUser>(); LCAPUserEntity.delete(id);
* 注意:对应接口已经在下面的实体列表中定义好了,不需要重新定义。
*/
declare const createEntity: <T>() => Entity<T>;
/* EntityRelation函数:用于定义数据表内的外键关联关系。*/
declare function EntityRelation(property: any): any;
/* 系统逻辑: 认证与权限 */
declare namespace nasl.auth {
/* 判断当前登录用户是否拥有该资源路径的访问权限 */
export function hasAuth(authPath: String): Boolean;
/* 退出当前登录状态,无输出参数 */
export function logout(): void;
/* 将输入的字符串使用AES算法进行加密, 输出参数为一个加密后的字符串 */
export function encryptByAES(rawStr: String): String;
/* 对加密的字符串使用AES算法进行解密, 输出参数为一个解密后的字符串 */
export function decryptByAES(encryptedStr: String): String;
/* 当前登录用户信息 */
export const userInfo: {
Status: String;
UserName: String;
Email: String;
UserId: String;
Phone: String;
CreateTime: Long;
UpdateTime: Long;
LoginCount: Long;
Source: String;
};
}