feat(reset): 以构造器模式重构
- 加了大文件传输自定义分片协议 BREAKING CHANGES: 0.1.0(latest)
This commit is contained in:
35
decorators/meta.ts
Normal file
35
decorators/meta.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* API 方法元数据接口
|
||||
*/
|
||||
export interface ApiMethodMeta {
|
||||
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
||||
path: string;
|
||||
}
|
||||
|
||||
// 使用 WeakMap 存储元数据,避免内存泄漏
|
||||
const metaStore = new WeakMap<Function, Map<string, ApiMethodMeta>>();
|
||||
|
||||
/**
|
||||
* 设置函数的元数据
|
||||
* @param target 目标函数
|
||||
* @param key 元数据键名
|
||||
* @param value 元数据值
|
||||
*/
|
||||
export function setMeta(target: Function, _key: string, value: ApiMethodMeta): void {
|
||||
let map = metaStore.get(target);
|
||||
if (!map) {
|
||||
map = new Map();
|
||||
metaStore.set(target, map);
|
||||
}
|
||||
map.set(_key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取函数的元数据
|
||||
* @param target 目标函数
|
||||
* @param key 元数据键名
|
||||
* @returns 元数据值或undefined
|
||||
*/
|
||||
export function getMeta(target: Function, key: string): ApiMethodMeta | undefined {
|
||||
return metaStore.get(target)?.get(key);
|
||||
}
|
||||
Reference in New Issue
Block a user