25e8b9cb5c
parseWxrStream(readable, {limits, now}) → AsyncGenerator<WxrEvent>:
逐 chunk 喂入 saxes(^6.0.0,ISC;计划所写 ^0.9 不存在于版本历史),
item/term 按文档序交错产出;任一时刻只持有当前聚合状态 + 单 chunk 内
待 yield 队列,绝不收集已产出 item 列表(峰值内存与文件大小解耦)。
- 字段:postId(数值解析)/postType/status/postName/link/title/
contentEncoded/excerptEncoded/postDate/postModified/attachmentUrl/
creator + metas{key,value}[] + categories{domain,nicename,value}[] +
rawLocation(wxr://item/<n>、wxr://term/<n>)
- 错误体系照 PhpError 先例:WxrError 基类;WxrParseError 带 saxes
行列位置(error 事件同步抛出时捕获);WxrLimitError 按 kind 区分
- 限额:bytes/items/terms/depth/cdata/fieldLength(先检查后追加,
超限内容永不入缓冲)/metaPerItem/time(可注入时钟)——超限即抛,
不静默截断
- 实体防线(测试钉死):saxes 实体表固定为五预定义 + 数字引用,
DOCTYPE 内部/SYSTEM 实体不注册——引用即 WxrParseError,替换文本
不进产出;纯字符串解析,全程无网络 I/O
- 跨 chunk 喂入(7 字节/块)与单 chunk 产出一致(StringDecoder 处理
多字节边界);畸形 XML(提前闭合/截断)→ WxrParseError 带行列
130 测试全绿(新增 22)。
Co-Authored-By: Claude Code <noreply@anthropic.com>
23 lines
562 B
JSON
23 lines
562 B
JSON
{
|
|
"name": "@sf/adapter-wp",
|
|
"version": "0.1.0",
|
|
"description": "SiteForge WordPress WXR 适配器:流式解析 + UniversalRow 映射(纯函数包)",
|
|
"type": "module",
|
|
"main": "./dist/src/index.js",
|
|
"types": "./dist/src/index.d.ts",
|
|
"exports": {
|
|
".": {
|
|
"types": "./dist/src/index.d.ts",
|
|
"default": "./dist/src/index.js"
|
|
}
|
|
},
|
|
"scripts": {
|
|
"build": "tsc -p tsconfig.build.json",
|
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
},
|
|
"dependencies": {
|
|
"@sf/contracts": "workspace:*",
|
|
"saxes": "^6.0.0"
|
|
}
|
|
}
|