调整文档,改进设计

This commit is contained in:
xief
2025-07-04 16:47:14 +08:00
parent fd68920e01
commit 92b49c7035
6 changed files with 54 additions and 50 deletions

View File

@@ -1,31 +1,5 @@
/**
* 配置基类,下划线开头的变量不会被序列化
*/
export class ConfigBase {
name: string = '';
version:string = '1.0.0';
[key: string]: any;
import { ConfigBase } from "./models/config";
/**
* 加载反序列化数据
* @param data
*/
load(data:Record<string,unknown>){
for (const key of Object.getOwnPropertyNames(this).filter(i=>i[0]!=='_')) {
if(data[key]!=undefined){
this[key] = data[key];
}
}
}
/**
* 序列化json方法
* @returns
*/
toJson(){
return JSON.stringify(this,(k,v)=>k[0]=='_'?undefined:v);
}
}
/**
* 加工处理器上下文
@@ -52,13 +26,4 @@ export abstract class ProcessorBase<TInput,TOutput,TConfig extends ConfigBase> {
public readonly name: string = '';
public readonly version: string = '1.0.0';
public abstract exec(context:ProcessorContext<TInput,TOutput,TConfig>):Promise<void>|void
}
export interface FileOptions {
encode?: string;
addBOM?: boolean;
}
export interface FileInfo extends FileOptions {
name: string,
content: string | Blob | Uint8Array,
}

View File

@@ -1,3 +1,4 @@
export * from './base';
export * from './processors';
export * from './parsers';
export * from './parsers';
export * from './models/config';
export * from './models/file';

28
src/models/config.ts Normal file
View File

@@ -0,0 +1,28 @@
/**
* 配置基类,下划线开头的变量不会被序列化
*/
export class ConfigBase {
name: string = '';
version:string = '1.0.0';
[key: string]: any;
/**
* 加载反序列化数据
* @param data
*/
load(data:Record<string,unknown>){
for (const key of Object.getOwnPropertyNames(this).filter(i=>i[0]!=='_')) {
if(data[key]!=undefined){
this[key] = data[key];
}
}
}
/**
* 序列化json方法
* @returns
*/
toJson(){
return JSON.stringify(this,(k,v)=>k[0]=='_'?undefined:v);
}
}

8
src/models/file.ts Normal file
View File

@@ -0,0 +1,8 @@
export interface FileOptions {
encode?: string;
addBOM?: boolean;
}
export interface FileInfo extends FileOptions {
name: string,
content: string | Blob | Uint8Array,
}

View File

@@ -1,4 +1,6 @@
import { ConfigBase, FileInfo, ProcessorBase } from "./base";
import { ProcessorBase } from "./base";
import { ConfigBase } from "./models/config";
import { FileInfo } from "./models/file";
// todo: 类型参数待补完