feat: setup barrelsby for automatic barrel file generation
Add barrelsby as a dev dependency with a `generate-barrels` npm script and a `barrelesby.json` config targeting `./src`. This automates creation of barrel/index files to simplify imports across the project.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* 最近记忆模型
|
||||
* 原始 Dart: RecentMemory (lib/data/models/user/recent_memory.dart)
|
||||
*
|
||||
* 注:原始 Dart 中 `createdAt` 为 `String?`,按"全部非空"约定兜底为空串。
|
||||
*/
|
||||
export class RecentMemory {
|
||||
readonly type: string;
|
||||
readonly content: string;
|
||||
readonly importance: number;
|
||||
readonly createdAt: string;
|
||||
|
||||
constructor(params: {
|
||||
type: string;
|
||||
content: string;
|
||||
importance: number;
|
||||
createdAt?: string;
|
||||
}) {
|
||||
this.type = params.type;
|
||||
this.content = params.content;
|
||||
this.importance = params.importance;
|
||||
this.createdAt = params.createdAt ?? "";
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
toJson(): Record<string, unknown> {
|
||||
return {
|
||||
type: this.type,
|
||||
content: this.content,
|
||||
importance: this.importance,
|
||||
createdAt: this.createdAt,
|
||||
};
|
||||
}
|
||||
|
||||
static fromJson(json: Record<string, unknown>): RecentMemory {
|
||||
const requireString = (key: string): string => {
|
||||
const v = json[key];
|
||||
if (typeof v !== "string") {
|
||||
throw new Error(
|
||||
`RecentMemory.${key} is required and must be a string`
|
||||
);
|
||||
}
|
||||
return v;
|
||||
};
|
||||
const importance = json.importance;
|
||||
if (typeof importance !== "number") {
|
||||
throw new Error(
|
||||
"RecentMemory.importance is required and must be a number"
|
||||
);
|
||||
}
|
||||
return new RecentMemory({
|
||||
type: requireString("type"),
|
||||
content: requireString("content"),
|
||||
importance,
|
||||
createdAt:
|
||||
typeof json.createdAt === "string" ? json.createdAt : undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user