@longzai-intelligence-pendings-markdown/core 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -9,4 +9,4 @@ import"./rolldown-runtime-BqT_7tdF.js";import{contentHash as e,createCatalogReco
9
9
  `))return{head:t,arrays:n,body:e};let r=e.indexOf(`
10
10
  ---
11
11
  `,4);if(r===-1)return{head:t,arrays:n,body:e};let i=e.slice(4,r).split(`
12
- `),a=e.slice(r+5).replace(/^\n/,``),o=null;for(let e of i){if(e.startsWith(` - `)&&o!==null){let t=P(e.slice(4).trim());n[o]=[...n[o]??[],t];continue}if(o=null,e.endsWith(`: []`)){o=e.slice(0,-4),n[o]=[];continue}if(e.endsWith(`:`)){o=e.slice(0,-1),n[o]=[];continue}let r=e.indexOf(`: `);r>0&&!e.startsWith(` `)&&(t[e.slice(0,r)]=P(e.slice(r+2)))}return{head:t,arrays:n,body:a}},I=`pendings`,L=/^\d{4}-\d{2}$/,R=/^\d{4}-\d{2}-\d{2}$/,te=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,ne=[`choice`,`approve`,`inform`],z=[`P0`,`P1`,`P2`,`P3`],B=[`pending`,`decided`,`dropped`],V={id:e=>te.test(e)?null:`id 非 kebab 形态:${e}`,title:e=>e.length>=1?null:`title 为空`,kind:e=>ne.includes(e)?null:`kind 非法:${e}`,priority:e=>z.includes(e)?null:`priority 非法:${e}`,status:e=>B.includes(e)?null:`status 非法:${e}`,raised:e=>R.test(e)?null:`raised 非 YYYY-MM-DD:${e}`},H={due:e=>R.test(e)?null:`due 非 YYYY-MM-DD:${e}`,origin_repo:e=>/^longzai-intelligence-[a-z0-9-]+$/.test(e)?null:`origin_repo 形态非法:${e}`,origin:e=>e.length>=1?null:`origin 为空`,recommendation:e=>e.length>=1?null:`recommendation 为空`,decision:e=>e.length>=1?null:`decision 为空`,decided_by:e=>e.length>=1?null:`decided_by 为空`,decided_at:e=>R.test(e)?null:`decided_at 非 YYYY-MM-DD:${e}`,decision_basis:e=>e.length>=1?null:`decision_basis 为空`},U=[`options`,`context_refs`];function W(e,t){let n=[],r=/* @__PURE__ */ new Set([...Object.keys(V),...Object.keys(H),...U]);for(let[t,r]of Object.entries(V)){let i=e[t];if(typeof i!=`string`){n.push(`必填字段缺失或非标量:${t}`);continue}let a=r(i);a!==null&&n.push(a)}for(let[t,r]of Object.entries(H)){let i=e[t];if(i===void 0)continue;if(typeof i!=`string`){n.push(`可选字段非标量:${t}`);continue}let a=r(i);a!==null&&n.push(a)}for(let t of U){let r=e[t];if(r!==void 0){if(!Array.isArray(r))n.push(`数组字段非数组形态:${t}`);else for(let e of r)if(e.length<1){n.push(`数组字段含空项:${t}`);break}}}for(let t of Object.keys(e))r.has(t)||n.push(`未知字段:${t}`);let i=e.id;return typeof i==`string`&&i!==t&&n.push(`id 字段 ${i} 与文件名主干 ${t} 不一致`),n}function G(e){let t=d(e,I),n=[],r=[];if(!c(t))return{docs:n,violations:r};let i=[...u(t,{withFileTypes:!0})].sort((e,t)=>e.name<t.name?-1:1);for(let a of i){if(!a.isDirectory()||!L.test(a.name))continue;let i=u(d(t,a.name)).sort();for(let t of i){if(!t.endsWith(`.pending.md`))continue;let i=`${I}/${a.name}/${t}`,o=l(d(e,i),`utf8`),s=F(o),c={...s.head,...s.arrays},u=t.slice(0,-11),f=W(c,u);f.length>0?r.push({relativePath:i,violations:f}):n.push({slug:u,month:a.name,fields:c,body:s.body})}}return{docs:n.sort((e,t)=>`${e.month}-${e.slug}`<`${t.month}-${t.slug}`?-1:1),violations:r}}function K(e){return{ok:!0,value:e}}function q(e){return{ok:!1,error:e}}const J=/^\d{4}-\d{2}$/;function Y(e){let t=e.month!==void 0,n=[t,e.all===!0].filter(Boolean).length;if(n===0)return q({code:`SELECTION_INVALID`,message:`缺少选择器:--month <YYYY-MM> 与 --all 二选一`});if(n>1)return q({code:`SELECTION_INVALID`,message:`选择器互斥:--month 与 --all 只能选一种`});if(t){let t=e.month;return t===void 0||!J.test(t)?q({code:`MONTH_INVALID`,message:`--month 格式非法:${t??`空`},应为 YYYY-MM`}):K([t])}return K(null)}async function X(e,t){let n=Y(t);if(!n.ok)return q(n.error);let r=G(e.sourceHome),i=n.value===null?[...new Set(r.docs.map(e=>e.month))].sort():n.value.filter(e=>r.docs.some(t=>t.month===e)),a=new N({dataRoot:e.dataRoot}),o={dryRun:t.dryRun===!0},s=[];for(let e of i){let t=r.docs.filter(t=>t.month===e),n=await a.writeMonth(e,t,o);s.push({month:e,docs:t.length,written:n.written,skipped:n.skipped})}let c=await new j({dataRoot:e.dataRoot}).refresh(o);return K({months:s,violations:r.violations,catalog:c})}const Z=`LZI_PENDINGS_DATA_HOME`,Q=r({variables:[{name:Z,comment:`源台账 data-home 即 pendings 仓待裁档与目录册所在数据区,本工具只读消费`,placeholder:`/path/to/pendings-data-home`}],toEnvConfig:e=>({sourceHome:f(e.LZI_PENDINGS_DATA_HOME??``)}),defaultTemplateTitle:`lzi-pendings-markdown 环境配置`});function $(e=process.env){return Q.resolveEnv(e)}const re=Q;async function ie(e){let t=await p(e);if(!t.ok)return{ok:!1,error:t.error};let n=$();return n.ok?{ok:!0,value:{channel:`config-file`,env:{dataRoot:t.config.dataRoot,sourceHome:n.value.sourceHome},configPath:t.path}}:{ok:!1,error:n.error}}async function ae(t){if(!c(t.dataRoot))return q({code:`DATA_ROOT_MISSING`,message:`数据根不存在:${t.dataRoot}`});let n=new j({dataRoot:t.dataRoot}),r=await n.scan(),i=[],a=[],s=/* @__PURE__ */ new Map;for(let n of r){let r=d(t.dataRoot,`pendings`,n.month),f=c(r)?u(r).filter(e=>e.endsWith(`.pending.md`)&&!e.startsWith(`.`)):[];for(let t of f){let c=d(r,t),{head:u,body:f}=o(l(c,`utf8`)),p=e(f);u.content_hash!==void 0&&u.content_hash!==p&&i.push({file:c,expected:u.content_hash,actual:p});let m=t.slice(0,-11),h=s.get(m);h===void 0?s.set(m,n.month):a.push(`slug ${m} 跨月重复:${h} 与 ${n.month}`)}let p=d(r,`README.md`);if(c(p)){let{head:e}=o(l(p,`utf8`));e.doc_count!==void 0&&e.doc_count!==String(f.length)&&a.push(`${n.month}/README.md 登记档数 ${e.doc_count} 与实测 ${f.length} 不符`)}else a.push(`${n.month} 缺 README.md`)}let f=await n.check();return a.push(...f),K({hashDrifts:i,issues:a,ok:i.length===0&&a.length===0})}export{j as CatalogService,Z as ENV_SOURCE_HOME,N as MonthRepoService,q as failure,G as loadPendingSource,w as monthRelDir,g as normalizeFrontmatterQuotes,F as parseDeclaration,b as pendingDocFileName,re as pendingsMarkdownEnvKit,y as renderAlignedTable,T as renderCatalog,E as renderDataRootReadme,C as renderMonthReadme,x as renderPendingDocument,$ as resolveEnv,ie as resolveRuntimeEnv,X as runConvert,ae as runVerify,K as success};
12
+ `),a=e.slice(r+5).replace(/^\n/,``),o=null;for(let e of i){if(e.startsWith(` - `)&&o!==null){let t=P(e.slice(4).trim());n[o]=[...n[o]??[],t];continue}if(o=null,e.endsWith(`: []`)){o=e.slice(0,-4),n[o]=[];continue}if(e.endsWith(`:`)){o=e.slice(0,-1),n[o]=[];continue}let r=e.indexOf(`: `);r>0&&!e.startsWith(` `)&&(t[e.slice(0,r)]=P(e.slice(r+2)))}return{head:t,arrays:n,body:a}},I=`pendings`,L=/^\d{4}-\d{2}$/,R=/^\d{4}-\d{2}-\d{2}$/,te=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,ne=[`choice`,`approve`,`inform`],z=[`P0`,`P1`,`P2`,`P3`],B=[`pending`,`decided`,`dropped`],V={id:e=>te.test(e)?null:`id 非 kebab 形态:${e}`,title:e=>e.length>=1?null:`title 为空`,kind:e=>ne.includes(e)?null:`kind 非法:${e}`,priority:e=>z.includes(e)?null:`priority 非法:${e}`,status:e=>B.includes(e)?null:`status 非法:${e}`,raised:e=>R.test(e)?null:`raised 非 YYYY-MM-DD:${e}`},H={due:e=>R.test(e)?null:`due 非 YYYY-MM-DD:${e}`,origin_repo:e=>/^longzai-intelligence-[a-z0-9-]+$/.test(e)?null:`origin_repo 形态非法:${e}`,origin:e=>e.length>=1?null:`origin 为空`,recommendation:e=>e.length>=1?null:`recommendation 为空`,decision:e=>e.length>=1?null:`decision 为空`,decided_by:e=>e.length>=1?null:`decided_by 为空`,decided_at:e=>R.test(e)?null:`decided_at 非 YYYY-MM-DD:${e}`,decision_basis:e=>e.length>=1?null:`decision_basis 为空`,body_format:e=>e===`markdown`||e===`html`?null:`body_format 非法:${e}`},U=[`options`,`context_refs`];function W(e,t){let n=[],r=/* @__PURE__ */ new Set([...Object.keys(V),...Object.keys(H),...U]);for(let[t,r]of Object.entries(V)){let i=e[t];if(typeof i!=`string`){n.push(`必填字段缺失或非标量:${t}`);continue}let a=r(i);a!==null&&n.push(a)}for(let[t,r]of Object.entries(H)){let i=e[t];if(i===void 0)continue;if(typeof i!=`string`){n.push(`可选字段非标量:${t}`);continue}let a=r(i);a!==null&&n.push(a)}for(let t of U){let r=e[t];if(r!==void 0){if(!Array.isArray(r))n.push(`数组字段非数组形态:${t}`);else for(let e of r)if(e.length<1){n.push(`数组字段含空项:${t}`);break}}}for(let t of Object.keys(e))r.has(t)||n.push(`未知字段:${t}`);let i=e.id;return typeof i==`string`&&i!==t&&n.push(`id 字段 ${i} 与文件名主干 ${t} 不一致`),n}function G(e){let t=d(e,I),n=[],r=[];if(!c(t))return{docs:n,violations:r};let i=[...u(t,{withFileTypes:!0})].sort((e,t)=>e.name<t.name?-1:1);for(let a of i){if(!a.isDirectory()||!L.test(a.name))continue;let i=u(d(t,a.name)).sort();for(let t of i){if(!t.endsWith(`.pending.md`))continue;let i=`${I}/${a.name}/${t}`,o=l(d(e,i),`utf8`),s=F(o),c={...s.head,...s.arrays},u=t.slice(0,-11),f=W(c,u);f.length>0?r.push({relativePath:i,violations:f}):n.push({slug:u,month:a.name,fields:c,body:s.body})}}return{docs:n.sort((e,t)=>`${e.month}-${e.slug}`<`${t.month}-${t.slug}`?-1:1),violations:r}}function K(e){return{ok:!0,value:e}}function q(e){return{ok:!1,error:e}}const J=/^\d{4}-\d{2}$/;function Y(e){let t=e.month!==void 0,n=[t,e.all===!0].filter(Boolean).length;if(n===0)return q({code:`SELECTION_INVALID`,message:`缺少选择器:--month <YYYY-MM> 与 --all 二选一`});if(n>1)return q({code:`SELECTION_INVALID`,message:`选择器互斥:--month 与 --all 只能选一种`});if(t){let t=e.month;return t===void 0||!J.test(t)?q({code:`MONTH_INVALID`,message:`--month 格式非法:${t??`空`},应为 YYYY-MM`}):K([t])}return K(null)}async function X(e,t){let n=Y(t);if(!n.ok)return q(n.error);let r=G(e.sourceHome),i=n.value===null?[...new Set(r.docs.map(e=>e.month))].sort():n.value.filter(e=>r.docs.some(t=>t.month===e)),a=new N({dataRoot:e.dataRoot}),o={dryRun:t.dryRun===!0},s=[];for(let e of i){let t=r.docs.filter(t=>t.month===e),n=await a.writeMonth(e,t,o);s.push({month:e,docs:t.length,written:n.written,skipped:n.skipped})}let c=await new j({dataRoot:e.dataRoot}).refresh(o);return K({months:s,violations:r.violations,catalog:c})}const Z=`LZI_PENDINGS_DATA_HOME`,Q=r({variables:[{name:Z,comment:`源台账 data-home 即 pendings 仓待裁档与目录册所在数据区,本工具只读消费`,placeholder:`/path/to/pendings-data-home`}],toEnvConfig:e=>({sourceHome:f(e.LZI_PENDINGS_DATA_HOME??``)}),defaultTemplateTitle:`lzi-pendings-markdown 环境配置`});function $(e=process.env){return Q.resolveEnv(e)}const re=Q;async function ie(e){let t=await p(e);if(!t.ok)return{ok:!1,error:t.error};let n=$();return n.ok?{ok:!0,value:{channel:`config-file`,env:{dataRoot:t.config.dataRoot,sourceHome:n.value.sourceHome},configPath:t.path}}:{ok:!1,error:n.error}}async function ae(t){if(!c(t.dataRoot))return q({code:`DATA_ROOT_MISSING`,message:`数据根不存在:${t.dataRoot}`});let n=new j({dataRoot:t.dataRoot}),r=await n.scan(),i=[],a=[],s=/* @__PURE__ */ new Map;for(let n of r){let r=d(t.dataRoot,`pendings`,n.month),f=c(r)?u(r).filter(e=>e.endsWith(`.pending.md`)&&!e.startsWith(`.`)):[];for(let t of f){let c=d(r,t),{head:u,body:f}=o(l(c,`utf8`)),p=e(f);u.content_hash!==void 0&&u.content_hash!==p&&i.push({file:c,expected:u.content_hash,actual:p});let m=t.slice(0,-11),h=s.get(m);h===void 0?s.set(m,n.month):a.push(`slug ${m} 跨月重复:${h} 与 ${n.month}`)}let p=d(r,`README.md`);if(c(p)){let{head:e}=o(l(p,`utf8`));e.doc_count!==void 0&&e.doc_count!==String(f.length)&&a.push(`${n.month}/README.md 登记档数 ${e.doc_count} 与实测 ${f.length} 不符`)}else a.push(`${n.month} 缺 README.md`)}let f=await n.check();return a.push(...f),K({hashDrifts:i,issues:a,ok:i.length===0&&a.length===0})}export{j as CatalogService,Z as ENV_SOURCE_HOME,N as MonthRepoService,q as failure,G as loadPendingSource,w as monthRelDir,g as normalizeFrontmatterQuotes,F as parseDeclaration,b as pendingDocFileName,re as pendingsMarkdownEnvKit,y as renderAlignedTable,T as renderCatalog,E as renderDataRootReadme,C as renderMonthReadme,x as renderPendingDocument,$ as resolveEnv,ie as resolveRuntimeEnv,X as runConvert,ae as runVerify,K as success};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-pendings-markdown/core",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Longzai Intelligence pendings markdown core - 投影转换引擎,源台账读取与确定性渲染与幂等写入",
5
5
  "keywords": [
6
6
  "convert",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@longzai-intelligence-markdown/data-engine": "^0.0.6",
42
- "@longzai-intelligence-pendings-markdown/config": "0.0.1",
42
+ "@longzai-intelligence-pendings-markdown/config": "0.0.2",
43
43
  "zod": "^4.6.5"
44
44
  },
45
45
  "devDependencies": {