micro-contracts 0.17.5 → 0.17.6

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.
@@ -5043,7 +5043,7 @@ ${o}`:Array.isArray(a)&&a.length>0?`${r}${n}:
5043
5043
  ${o}`:`${r}${n}: ${o}`}).join(`
5044
5044
  `)}return String(e)}async function Qre(e){let t=await YF(e.config,e.module);if(e.showPrompt)return t;let r={adapter:e.adapter,model:e.model},i={failOn:e.failOn,logFile:e.logFile};try{let n=await Es(t,"audit-openapi-design",r,i),a=xs(n,e.reportFormat??"text");await ks(a,e.output);let o=$s(n,i);o!==0&&process.exit(o)}catch(n){let a=n.exitCode;throw(a===Ro||a===Bo)&&(console.error(du.red(n.message)),process.exit(a)),n}}async function ene(e){let t=await XF(e.config,e.module);if(e.showPrompt)return t;let r={adapter:e.adapter,model:e.model},i={failOn:e.failOn,logFile:e.logFile};try{let n=await Es(t,"audit-published-api",r,i),a=xs(n,e.reportFormat??"text");await ks(a,e.output);let o=$s(n,i);o!==0&&process.exit(o)}catch(n){let a=n.exitCode;throw(a===Ro||a===Bo)&&(console.error(du.red(n.message)),process.exit(a)),n}}async function tne(e){let t=await QF(e.config,e.module);if(e.showPrompt)return t;let r={adapter:e.adapter,model:e.model},i={failOn:e.failOn,logFile:e.logFile};try{let n=await Es(t,"propose-overlay-candidates",r,i),a=xs(n,e.reportFormat??"json");await ks(a,e.output);let o=$s(n,i);o!==0&&process.exit(o)}catch(n){let a=n.exitCode;throw(a===Ro||a===Bo)&&(console.error(du.red(n.message)),process.exit(a)),n}}async function rne(e){let t=await eM(e.config,e.guardrails);if(e.showPrompt)return t;let r={adapter:e.adapter,model:e.model},i={failOn:e.failOn,logFile:e.logFile};try{let n=await Es(t,"audit-guardrails-coverage",r,i),a=xs(n,e.reportFormat??"text");await ks(a,e.output);let o=$s(n,i);o!==0&&process.exit(o)}catch(n){let a=n.exitCode;throw(a===Ro||a===Bo)&&(console.error(du.red(n.message)),process.exit(a)),n}}import MC from"fs";import As from"path";import{createRequire as XTe}from"module";Ii();Ii();var QTe=XTe(import.meta.url),eNe=QTe("../../package.json"),une="micro-contracts",tNe="api_contract_declaration",nne=.9;function rNe(e){let t=["micro-contracts.config.yaml","micro-contracts.config.yml","api-framework.config.yaml","api-framework.config.yml"];for(let r of t){let i=As.join(e,r);if(MC.existsSync(i))return i}return null}function ine(e,t){let r=As.relative(e,t);return r.startsWith("..")?t:r.split(As.sep).join("/")}function FC(e){return e.raw}function B6(e,t,r){return`${e}/services/${t}ServiceApi.ts#${r}`}function nNe(e,t){let r=e.split(`
5045
5045
  `);for(let i=0;i<r.length;i++)if(r[i].includes(t))return i+1}function ane(e,t,r,i,n){let a=i?nNe(r,i):void 0;return{kind:tNe,detail:e,filePath:t,...a!==void 0?{line:a}:{},...n!==void 0?{symbolId:n}:{}}}function iNe(e){let t=new Map,r=["get","post","put","patch","delete"];for(let i of Object.values(e.paths))for(let n of r){let a=i[n];if(!a?.operationId)continue;let o=a["x-micro-contracts-service"],s=a["x-micro-contracts-method"];typeof o=="string"&&typeof s=="string"&&t.set(a.operationId,{service:o,method:s})}return t}function one(e,t,r){return`${e}.${t}.${r}`}function sne(e,t,r){return`${e}\0${t}\0${r}`}function aNe(e,t){return{symbolId:B6(e,t.service,t.method),filePath:`${e}/services/${t.service}ServiceApi.ts`,startLine:1,endLine:1}}function zC(e,t={}){let r=As.resolve(e),i=t.configPath?As.resolve(t.configPath):rNe(r);if(!i)throw new Error("micro-contracts.config.yaml not found. Run from project root or pass --config.");let n=as(i);if(!bo(n))throw new Error("Insight provider requires multi-module config with modules.");let a=As.dirname(i),o=n.defaults??{},s=[],u=new Map;for(let[h,g]of Object.entries(n.modules)){let y=xc(h,g,o),_=As.resolve(a,y.openapi);if(!MC.existsSync(_))continue;let w=is(_),S=ine(r,_),C=ine(r,As.resolve(r,y.contractOutput));u.set(h,C),s.push({name:h,openapiRel:S,resolved:y,spec:w})}let l=[],c=new Set,d=new Map,p=h=>{d.has(h.name)||d.set(h.name,{domainId:h.name,filePaths:[h.openapiRel,h.resolved.contractOutput]})},f=h=>{let g=FC(h);if(d.has(g))return;let y=u.get(h.module);if(!y)return;let _=s.find(S=>S.name===h.module),w=_?[_.openapiRel,y]:[y];d.set(g,{domainId:g,filePaths:w,symbolIds:[B6(y,h.service,h.method)],symbols:[aNe(y,h)]})},m=(h,g,y,_,w)=>{let S=one(h,g,y);if(d.has(S))return;let C=B6(_,g,y);d.set(S,{domainId:S,filePaths:[w,_],symbolIds:[C],symbols:[{symbolId:C,filePath:`${_}/services/${g}ServiceApi.ts`,startLine:1,endLine:1}]})};for(let h of s){p(h);let g=MC.readFileSync(As.resolve(r,h.openapiRel),"utf-8"),y=uf(h.spec),_=u.get(h.name),w=iNe(h.spec);for(let S of y.moduleLevelDeps){let C=h.name,D=FC(S),E="api_dependency",A=sne(C,D,E);c.has(A)||(c.add(A),f(S),l.push({from:C,to:D,kind:E,propagation:"forward",weight:nne,evidence:[ane(`module declares dependency on ${S.raw}`,h.openapiRel,g,S.raw)]}))}for(let[S,C]of y.operationLevelDeps){let D=w.get(S);if(!D)continue;let E=one(h.name,D.service,D.method);m(h.name,D.service,D.method,_,h.openapiRel);for(let A of C){let P=FC(A),O="api_operation_dependency",$=sne(E,P,O);if(c.has($))continue;c.add($),f(A);let x=B6(_,D.service,D.method);l.push({from:E,to:P,kind:O,propagation:"forward",weight:nne,evidence:[ane(`operation ${E} declares dependency on ${A.raw}`,h.openapiRel,g,A.raw,x)]})}}}return{source:une,sourceVersion:eNe.version,generatedAt:new Date().toISOString(),edges:l,anchorMapping:[...d.values()]}}var LC=class{name=une;async provide(t){return zC(t.projectRoot)}},xWe=new LC;async function lne(e){let t=e.format??"json";if(t!=="json")throw new Error(`Unsupported --format: ${t}. Only "json" is supported.`);let r=e.projectRoot??process.cwd(),i=zC(r,{configPath:e.config});process.stdout.write(`${JSON.stringify(i)}
5046
- `)}var sp={version:"0.17.5"};function UC(){let e=["micro-contracts.config.yaml","micro-contracts.config.yml","api-framework.config.yaml","api-framework.config.yml"];for(let t of e){let r=sn.resolve(t);if(Sr.existsSync(r))return r}return null}var oNe={generate:async e=>{try{let t,r=e.config?sn.resolve(e.config):UC();r||(console.error("Error: No config file found."),console.error("Create micro-contracts.config.yaml or use --config <path>"),process.exit(1)),Sr.existsSync(r)||(console.error(`Config file not found: ${r}`),process.exit(1)),console.log(`Using config: ${r}`),t=as(r);let i=e.cache!==!1&&!e.force,n;if(bo(t)&&(n=Fg(t,r,sp.version),i)){let a=e.manifestDir||"packages/",o=await Gf(a,n);if(o.skip){console.log(`No input changes detected, skipping generation (${o.reason})`);return}}if(await u9(t,{contractsOnly:e.contractsOnly,serverOnly:e.serverOnly,frontendOnly:e.frontendOnly,docsOnly:e.docsOnly,skipLint:e.skipLint,modules:e.module}),e.manifest!==!1){let{config:a}=Ni();if(a?.generated&&a.generated.length>0){let o=e.manifestDir||"packages/";if(Sr.existsSync(o)){let s=e.cache!==!1?n:void 0,{manifest:u,changed:l}=await Hc(o,{generatorVersion:sp.version,inputHash:s}),c=Object.keys(u.files).length;if(l){let d=gl(u,o);console.log(`
5046
+ `)}var sp={version:"0.17.6"};function UC(){let e=["micro-contracts.config.yaml","micro-contracts.config.yml","api-framework.config.yaml","api-framework.config.yml"];for(let t of e){let r=sn.resolve(t);if(Sr.existsSync(r))return r}return null}var oNe={generate:async e=>{try{let t,r=e.config?sn.resolve(e.config):UC();r||(console.error("Error: No config file found."),console.error("Create micro-contracts.config.yaml or use --config <path>"),process.exit(1)),Sr.existsSync(r)||(console.error(`Config file not found: ${r}`),process.exit(1)),console.log(`Using config: ${r}`),t=as(r);let i=e.cache!==!1&&!e.force,n;if(bo(t)&&(n=Fg(t,r,sp.version),i)){let a=e.manifestDir||"packages/",o=await Gf(a,n);if(o.skip){console.log(`No input changes detected, skipping generation (${o.reason})`);return}}if(await u9(t,{contractsOnly:e.contractsOnly,serverOnly:e.serverOnly,frontendOnly:e.frontendOnly,docsOnly:e.docsOnly,skipLint:e.skipLint,modules:e.module}),e.manifest!==!1){let{config:a}=Ni();if(a?.generated&&a.generated.length>0){let o=e.manifestDir||"packages/";if(Sr.existsSync(o)){let s=e.cache!==!1?n:void 0,{manifest:u,changed:l}=await Hc(o,{generatorVersion:sp.version,inputHash:s}),c=Object.keys(u.files).length;if(l){let d=gl(u,o);console.log(`
5047
5047
  Manifest updated: ${d} (${c} files)`)}else console.log(`
5048
5048
  Manifest unchanged (${c} files)`)}}}}catch(t){console.error("Generation failed:",t instanceof Error?t.message:t),process.exit(1)}},lint:async e=>{try{let t=sn.resolve(e);Sr.existsSync(t)||(console.error(`OpenAPI spec not found: ${t}`),process.exit(1)),console.log(`Linting: ${t}
5049
5049
  `);let r=is(t),i=rs(r,{strict:!1});console.log(dl(i)),i.valid||process.exit(1)}catch(t){console.error("Lint failed:",t instanceof Error?t.message:t),process.exit(1)}},init:async(e,t)=>{console.log(`Initializing module "${e}"${t.screens?" (screen spec)":""}...