@feng0531/dsh-vcs 0.4.9 → 0.4.10
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.
- package/dist/client.js +3 -3
- package/dist/frontend.json +1 -1
- package/dist/interface.js +3 -3
- package/dist/svn-host.mjs +1 -1
- package/git-history.mjs +6 -1
- package/index.mjs +285 -116
- package/package.json +1 -1
- package/vcs.mjs +103 -94
package/dist/svn-host.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createHandler as Pe}from"../index.mjs";import{XMLParser as ye,XMLValidator as Se}from"fast-xml-parser";function O(r){if(typeof r!="string"||Buffer.byteLength(r)>2097152||/<!DOCTYPE|<!ENTITY/i.test(r)||Se.validate(r)!==!0)throw Error("Invalid DAV XML");let o=new ye({preserveOrder:!0,ignoreAttributes:!1,parseTagValue:!1,parseAttributeValue:!1,trimValues:!1}).parse(r),t=0,e=(s,n,i=0)=>{if(i>32)throw Error("DAV XML too deep");let a=Object.create(null),f="";for(let c of s){if(++t>1e4)throw Error("DAV XML too many nodes");if(Object.hasOwn(c,"#text")){f+=c["#text"];continue}let p=Object.keys(c).filter(S=>S!==":@");if(p.length!==1)throw Error("Invalid DAV XML node");let l=p[0];if(l==="?xml"){if(i!==0)throw Error("Unexpected XML declaration");continue}let m={...n},w={};for(let[S,V]of Object.entries(c[":@"]||{}))S==="@_xmlns"?m[""]=V:S.startsWith("@_xmlns:")?m[S.slice(8)]=V:w[S]=V;let g=l.split(":");if(g.length>2)throw Error("Invalid DAV XML name");let u=g.length===2?g[0]:"",d=g.at(-1),h=m[u],y=h==="DAV:"?"D:"+d:h==="http://subversion.tigris.org/xmlns/dav/"?"S:"+d:h==="svn:"?"L:"+d:h==="http://subversion.tigris.org/xmlns/svn/"?"P:"+d:h==="http://subversion.tigris.org/xmlns/custom/"?"C:"+d:null;if(!y)throw Error("Unsupported DAV namespace");let b=["L:added-path","L:deleted-path","L:modified-path","L:replaced-path"].includes(y);if(Object.keys(w).length&&(!b||Object.keys(w).some(S=>!["@_node-kind","@_text-mods","@_prop-mods","@_copyfrom-path","@_copyfrom-rev"].includes(S))))throw Error("Unexpected DAV attribute");let v=e(c[l],m,i+1);if(b&&typeof v!="string")throw Error("Invalid DAV path text");let E=b?{...w,"#text":v}:v;if(["D:response","D:propstat","L:log-item","L:added-path","L:deleted-path","L:modified-path","L:replaced-path"].includes(y))(a[y]??=[]).push(E);else{if(Object.hasOwn(a,y))throw Error("Duplicate DAV expanded name");a[y]=E}}if(!Object.keys(a).length)return f;if(f.trim())throw Error("Mixed DAV XML content");return a};return e(o,{})}var De=9223372036854775807n;function D(r){if(typeof r!="string"||r.length>19||!/^(0|[1-9][0-9]*)$/.test(r))throw new Error("Invalid SVN revision");let o=BigInt(r);if(o>De)throw new Error("SVN revision exceeds supported range");return o}function U(r){let o=D(r);return o===0n?null:String(o-1n)}function _(r,{snapshot:o,cursor:t=o,limit:e=50}={}){let s=D(o),n=D(t);if(n>s||!Number.isInteger(e)||e<1||e>100||!Array.isArray(r)||r.length>e+1)throw new Error("Invalid SVN page bounds");let i=n+1n;for(let f of r){let c=D(f);if(c>n||c>=i)throw new Error("SVN revisions must descend within cursor");i=c}let a=r.slice(0,e);return{snapshot:o,revisions:a,nextRevision:r.length>e?U(a.at(-1)):null}}function Q(r,o){let t=O(r);if(!t||typeof t!="object"||Object.keys(t).length!==1||!Object.hasOwn(t,"L:log-report"))throw Error("Invalid DAV log root");let e=t["L:log-report"],s;if(e==="")s=[];else{if(!e||typeof e!="object"||Object.keys(e).some(a=>a!=="L:log-item")||!Array.isArray(e["L:log-item"]))throw Error("Invalid DAV log structure");s=e["L:log-item"]}if(s.length>101)throw Error("DAV log entries exceed limit");let n=s.map(a=>{if(!a||typeof a!="object"||Array.isArray(a)||Object.keys(a).some(c=>!["D:version-name","D:comment","D:creator-displayname","L:date"].includes(c)))throw Error("Unsupported DAV log item");let f=c=>{let p=a[c]??"";if(typeof p!="string")throw Error("Invalid DAV log text");return p};return{revision:f("D:version-name"),message:f("D:comment"),author:f("D:creator-displayname"),date:f("L:date")}}),i=_(n.map(a=>a.revision),o);return{snapshot:i.snapshot,entries:n.slice(0,i.revisions.length),nextRevision:i.nextRevision}}function R(r){if(typeof r!="string"||r.length>32768||!r.startsWith("/")||/[\u0000-\u001f\u007f\\]/.test(r))throw new Error("Invalid SVN repository path");if(r!=="/"&&r.slice(1).split("/").some(o=>o===""||o==="."||o===".."))throw new Error("Noncanonical SVN repository path");return r}function j(r,o){return R(r),R(o),o==="/"||r===o||r.startsWith(o+"/")}function B(r,o){if(!Array.isArray(r)||r.length>1e4)throw new Error("Invalid SVN path nodes");let t=r.map(e=>{let s=["#text","@_action","@_kind","@_copyfrom-path","@_copyfrom-rev","@_text-mods","@_prop-mods"];if(!e||typeof e!="object"||Array.isArray(e)||Object.keys(e).some(n=>!s.includes(n)))throw new Error("Invalid SVN path node");for(let n of["@_text-mods","@_prop-mods"])if(Object.hasOwn(e,n)&&!["true","false","unknown"].includes(e[n]))throw new Error("Invalid SVN modification flag");return{...Object.hasOwn(e,"@_text-mods")?{textModified:e["@_text-mods"]}:{},...Object.hasOwn(e,"@_prop-mods")?{propertiesModified:e["@_prop-mods"]}:{},path:e["#text"],action:e["@_action"],kind:e["@_kind"],...Object.hasOwn(e,"@_copyfrom-path")?{copyFromPath:e["@_copyfrom-path"]}:{},...Object.hasOwn(e,"@_copyfrom-rev")?{copyFromRevision:e["@_copyfrom-rev"]}:{}}});return W(t,o)}function W(r,{scope:o,revision:t}={}){R(o);let e=D(t);if(!Array.isArray(r)||r.length>1e4||e===0n&&r.length!==0)throw new Error("Invalid SVN changed paths");let s=new Set;return r.map(i=>{if(!i||typeof i!="object"||Array.isArray(i)||Object.keys(i).some(u=>!["path","action","kind","copyFromPath","copyFromRevision","copySourceOutsideScope","textModified","propertiesModified"].includes(u)))throw new Error("Invalid SVN change structure");let{path:a,action:f,kind:c,copyFromPath:p,copyFromRevision:l}=i;if(R(a),s.has(a)||!["A","D","M","R"].includes(f)||!["file","dir","unknown"].includes(c))throw new Error("Invalid SVN change");s.add(a);let m=p!==void 0||l!==void 0;if(m&&(R(p),!["A","R"].includes(f)||D(l)>=e))throw new Error("Invalid SVN copy source");let w=Object.hasOwn(i,"copySourceOutsideScope");if(w&&(i.copySourceOutsideScope!==!0||m||!["A","R"].includes(f)))throw new Error("Invalid SVN redacted copy source");let g={path:a,action:f,kind:c,...w?{copySourceOutsideScope:!0}:{}};for(let u of["textModified","propertiesModified"])if(Object.hasOwn(i,u)){if(!["true","false","unknown"].includes(i[u]))throw new Error("Invalid SVN modification flag");g[u]=i[u]}return m&&(j(p,o)?(g.copyFromPath=p,g.copyFromRevision=l):g.copySourceOutsideScope=!0),g}).filter(i=>j(i.path,o))}function Z(r,{scope:o,revision:t}={}){D(t);let e=O(r),s=(p,l)=>{if(!p||typeof p!="object"||Array.isArray(p)||Object.keys(p).some(m=>!l.includes(m)))throw Error("Invalid DAV detail structure")};s(e,["L:log-report"]);let n=e["L:log-report"];if(s(n,["L:log-item"]),n["L:log-item"]?.length!==1)throw Error("One DAV detail revision required");let i=n["L:log-item"][0],a={"L:added-path":"A","L:deleted-path":"D","L:modified-path":"M","L:replaced-path":"R"};if(s(i,["D:version-name","D:comment","D:creator-displayname","L:date",...Object.keys(a)]),i["D:version-name"]!==t)throw Error("DAV detail revision mismatch");let f=p=>{let l=i[p]??"";if(typeof l!="string")throw Error("Invalid DAV detail text");return l},c=[];for(let[p,l]of Object.entries(a))for(let m of i[p]??[]){let{"@_node-kind":w,...g}=m;c.push({...g,"@_kind":w??"unknown","@_action":l})}return{revision:t,author:f("D:creator-displayname"),date:f("L:date"),message:f("D:comment"),changes:B(c,{scope:o,revision:t})}}import{XMLParser as be,XMLValidator as Ee}from"fast-xml-parser";function N(r,o,t){if(R(o),D(t),typeof r!="string"||r.length>32768||/[\x00-\x20\x7f\\?#]/.test(r))throw new Error("Invalid SVN HTTPS root");let e=new URL(r);if(e.protocol!=="https:"||e.username||e.password||e.href!==r)throw new Error("Noncanonical SVN HTTPS root");let s=e.pathname.split("/").slice(1);s.at(-1)===""&&s.pop();for(let f of s){let c=decodeURIComponent(f);if(!f||c==="."||c===".."||/[\x00-\x1f\x7f/\\]/.test(c))throw new Error("Invalid SVN root path")}let n=r.endsWith("/")?r.slice(0,-1):r,i=o==="/"?"":o.split("/").map(f=>encodeURIComponent(f).replace(/[!'()*]/g,c=>"%"+c.charCodeAt(0).toString(16).toUpperCase())).join("/"),a=n+(i||(e.pathname==="/"?"/":""))+"@"+t;if(a.length>32768)throw new Error("SVN target too long");return a}function L(r,{root:o}={}){if(N(o,"/","0"),typeof r!="string"||!r||r.length>32768||/[\\?#]/.test(r)||[...r].some(n=>n.charCodeAt(0)<=32||n.charCodeAt(0)===127))throw Error("Invalid DAV href");if(!(r.startsWith("/")&&!r.startsWith("//"))&&!r.startsWith("https://"))throw Error("DAV href must be absolute path or HTTPS URL");let t=new URL(r,new URL(o).origin);if(t.protocol!=="https:"||t.origin!==new URL(o).origin||t.username||t.password||t.search||t.hash)throw Error("DAV href outside authorized origin");if(r.startsWith("https://")&&t.href!==r||r.startsWith("/")&&t.pathname!==r)throw Error("Noncanonical DAV href");let e=t.pathname.split("/").slice(1);e.at(-1)===""&&e.pop();for(let n of e){let i=decodeURIComponent(n);if(!n||i==="."||i===".."||[...i].some(a=>a.charCodeAt(0)<32||a.charCodeAt(0)===127||a==="/"||a.charCodeAt(0)===92))throw Error("Unsafe DAV href path")}let s=new URL(o).pathname.replace(/[/]$/,"");if(s&&t.pathname!==s&&!t.pathname.startsWith(s+"/"))throw Error("DAV href outside repository root");return t.href}function ee(r,{target:o,revision:t,root:e,uuid:s}={}){if(typeof r!="string"||Buffer.byteLength(r)>2097152||/<!DOCTYPE|<!ENTITY/i.test(r)||Ee.validate(r)!==!0)throw Error("Invalid SVN node kind XML");let i=new be({ignoreAttributes:!1,parseAttributeValue:!1,parseTagValue:!1,trimValues:!1,isArray:f=>f==="entry"}).parse(r)?.info?.entry;if(!Array.isArray(i)||i.length!==1)throw Error("Expected one SVN node kind entry");let a=i[0];if(a.url!==o||a["@_revision"]!==t||a.repository?.root!==e||a.repository?.uuid!==s)throw Error("SVN node kind identity mismatch");if(!["file","dir"].includes(a["@_kind"]))throw Error("Unknown SVN node kind");return a["@_kind"]}function re(r,{root:o,target:t}={}){let e=O(r),s=(p,l)=>{if(!p||typeof p!="object"||Array.isArray(p)||Object.keys(p).some(m=>!l.includes(m)))throw Error("Invalid DAV node kind structure")};s(e,["D:multistatus"]),s(e["D:multistatus"],["D:response"]);let n=e["D:multistatus"]["D:response"];if(n?.length!==1)throw Error("Expected one DAV node kind response");let i=n[0];s(i,["D:href","D:propstat"]);let a=L(i["D:href"],{root:o});if(i["D:propstat"]?.length!==1)throw Error("Expected one DAV node kind status");let f=i["D:propstat"][0];if(s(f,["D:status","D:prop"]),!/^HTTP[/]1[.][01] 200(?: OK)?$/.test(f["D:status"]))throw Error("DAV node kind unavailable");s(f["D:prop"],["D:resourcetype"]);let c=f["D:prop"]["D:resourcetype"];if(c===""){if(a!==t)throw Error("DAV node kind target mismatch");return"file"}if(s(c,["D:collection"]),c["D:collection"]!=="")throw Error("Unknown DAV node kind");if(a!==t&&a!==t+"/")throw Error("DAV node kind target mismatch");return"dir"}function M({root:r,scope:o,path:t=o,snapshot:e,revision:s}={}){if(D(s)>D(e))throw new Error("SVN selected revision exceeds snapshot");if(!j(t,o))throw new Error("SVN detail path outside scope");let n=N(r,t,e);return{scope:o,revision:s,snapshot:e,args:["log","--xml","--verbose","--stop-on-copy","--non-interactive","--no-auth-cache","--limit","1","-r",s+":"+s,"--",n]}}function q({root:r,scope:o,path:t=o,snapshot:e,cursor:s=e,limit:n=50}={}){if(_([],{snapshot:e,cursor:s,limit:n}),!j(t,o))throw new Error("SVN history path outside scope");let i=N(r,t,e);return{snapshot:e,cursor:s,limit:n,args:["log","--xml","--stop-on-copy","--non-interactive","--no-auth-cache","--limit",String(n+1),"-r",s+":0","--",i]}}function H(r,o){let t=r?.args;if(!Array.isArray(t)||t.length>16||t.some(l=>typeof l!="string"))throw Error("Invalid SVN command");let e=t.at(-1),s=e.lastIndexOf("@"),n=e.slice(s+1);D(n);let i=o.root.endsWith("/")?o.root.slice(0,-1):o.root;N(o.root,"/",n);let a=e.slice(0,s);if(!(a===i||a.startsWith(i+"/")))throw Error("SVN command target outside root");let f=a.slice(i.length),c=f?"/"+f.slice(1).split("/").map(l=>decodeURIComponent(l)).join("/"):"/";if(!j(c,o.scope)||N(o.root,c,n)!==e)throw Error("SVN command target outside scope or noncanonical");let p;if(t[0]==="cat"||t[0]==="proplist"||t[0]==="info"){D(t[t[0]==="cat"?4:5]);let l=t[t[0]==="cat"?4:5];if(l!==n)throw Error("SVN content operative and peg mismatch");p=t[0]==="cat"?["cat","--non-interactive","--no-auth-cache","-r",l,"--",e]:[t[0],"--xml","--non-interactive","--no-auth-cache","-r",l,"--",e]}else if(t[0]==="log")if(t.includes("--verbose")){let l=t[9]?.split(":")[0];p=M({...o,path:c,snapshot:n,revision:l}).args}else{let l=t[8]?.split(":")[0],m=Number(t[6])-1;p=q({...o,path:c,snapshot:n,cursor:l,limit:m}).args}else throw Error("SVN command is not readonly history");if(JSON.stringify(t)!==JSON.stringify(p))throw Error("Unsupported SVN command shape");return{path:c,pegRevision:n,args:[...p]}}function te(r,{scope:o,revision:t,path:e}={}){if(D(t)===0n)throw new Error("SVN r0 has no change comparison");let s=W(r,{scope:o,revision:t}).find(a=>a.path===e);if(!s)throw new Error("SVN path is not an authorized changed member");if(s.kind!=="file")throw new Error("Only SVN file changes can be compared");let n=U(t),i=a=>a===null?{empty:!0}:{empty:!1,path:s.path,revision:a,pegRevision:a};return{path:s.path,action:s.action,left:i(s.action==="A"?null:n),right:i(s.action==="D"?null:t)}}import{XMLParser as Ae,XMLValidator as Ve}from"fast-xml-parser";function oe(r,{target:o,allowEmpty:t=!1}={}){if(typeof o!="string"||!o||o.length>32768)throw new Error("Invalid SVN property target");if(typeof r!="string"||Buffer.byteLength(r,"utf8")>2*1024*1024||/<!DOCTYPE|<!ENTITY/i.test(r)||Ve.validate(r)!==!0)throw new Error("Invalid SVN property XML");let e=new Ae({ignoreAttributes:!1,parseAttributeValue:!1,parseTagValue:!1,trimValues:!1,isArray:p=>p==="target"||p==="property"}).parse(r),s=(p,l)=>{if(!p||typeof p!="object"||Array.isArray(p)||Object.keys(p).some(m=>!l.includes(m)&&!(m==="#text"&&typeof p[m]=="string"&&/^[ \t\r\n]*$/.test(p[m]))))throw new Error("Invalid SVN property structure")};if(s(e,["?xml","properties"]),t===!0&&typeof e.properties=="string"&&/^[ \t\r\n]*$/.test(e.properties))return{target:o,names:[],special:!1};s(e.properties,["target"]);let n=e.properties.target;if(!Array.isArray(n)||n.length!==1)throw new Error("Expected one SVN property target");let i=n[0];if(s(i,["@_path","property"]),i["@_path"]!==o)throw new Error("SVN property target mismatch");let a=i.property??[];if(!Array.isArray(a)||a.length>1e4)throw new Error("Too many SVN properties");let f=[],c=new Set;for(let p of a){s(p,["@_name"]);let l=p["@_name"];if(typeof l!="string"||!l||l.length>1024||/[\x00-\x20\x7f]/.test(l)||c.has(l))throw new Error("Invalid SVN property name");c.add(l),f.push(l)}return{target:o,names:f,special:c.has("svn:special")}}import{createHash as Re}from"node:crypto";import{XMLParser as xe,XMLValidator as Ie}from"fast-xml-parser";function ne(r,{scope:o,revision:t}={}){if(D(t),typeof r!="string"||Buffer.byteLength(r,"utf8")>2*1024*1024||/<!DOCTYPE|<!ENTITY/i.test(r)||Ie.validate(r)!==!0)throw new Error("Invalid SVN detail XML");let e=new xe({ignoreAttributes:!1,parseAttributeValue:!1,parseTagValue:!1,trimValues:!1,isArray:c=>c==="logentry"||c==="path"}).parse(r),s=(c,p)=>{if(!c||typeof c!="object"||Array.isArray(c)||Object.keys(c).some(l=>!p.includes(l)&&!(l==="#text"&&typeof c[l]=="string"&&/^[ \t\r\n]*$/.test(c[l]))))throw new Error("Invalid SVN detail structure")};if(s(e,["?xml","log"]),s(e.log,["logentry"]),!Array.isArray(e.log.logentry)||e.log.logentry.length!==1)throw new Error("Expected one SVN revision");let n=e.log.logentry[0];if(s(n,["@_revision","author","date","msg","paths"]),n["@_revision"]!==t)throw new Error("SVN detail revision mismatch");let i=c=>{let p=n[c]??"";if(typeof p!="string")throw new Error("Invalid SVN detail text");return p},a=[];n.paths!==void 0&&!(typeof n.paths=="string"&&/^[ \t\r\n]*$/.test(n.paths))&&(s(n.paths,["path"]),a=n.paths.path??[]);let f=B(a,{scope:o,revision:t});return{revision:t,author:i("author"),date:i("date"),message:i("msg"),pathsAvailable:Object.hasOwn(n,"paths"),changes:f}}import{randomBytes as Ne}from"node:crypto";function se(r){if(!r||typeof r!="object")throw Error("Invalid SVN consent identity");let{sessionId:o,cwd:t,repositoryId:e,root:s,uuid:n,scope:i}=r;for(let a of[o,t,e])if(typeof a!="string"||!a||a.length>32768||a.includes("\0"))throw Error("Invalid SVN consent scope");if(N(s,"/","0"),R(i),typeof n!="string"||!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(n))throw Error("Invalid SVN repository UUID");return JSON.stringify([o,t,e,s,n,i])}function Y({now:r=Date.now,ttlMs:o=3e5,maxEntries:t=32,onRevoke:e=()=>{}}={}){if(!Number.isInteger(o)||o<1||o>3e5||!Number.isInteger(t)||t<1||t>32)throw Error("Invalid SVN consent bounds");if(typeof e!="function")throw Error("Invalid SVN revoke listener");let s=new Map,n=a=>{s.delete(a)&&e(a)},i=()=>{for(let[a,f]of s)f.expires<=r()&&n(a)};return{grant(a,{explicit:f=!1}={}){if(f!==!0)throw Error("Explicit SVN network consent required");let c=se(a);i();for(let[l,m]of s)m.key===c&&n(l);for(;s.size>=t;)n(s.keys().next().value);let p=Ne(32).toString("hex");return s.set(p,{key:c,sessionId:a.sessionId,expires:r()+o}),p},assert(a,f){i();let c=se(f),p=s.get(a);if(!p||p.key!==c)throw Object.assign(Error("SVN network consent missing, expired or identity changed"),{code:"vcs/svn-consent-required"})},revokeSession(a){for(let[f,c]of s)c.sessionId===a&&n(f)},revoke(a){n(a)},clear(){for(let a of[...s.keys()])n(a)}}}import{XMLParser as ke,XMLValidator as Oe}from"fast-xml-parser";function ie(r,o){let t=Le(r),e=_(t.map(s=>s.revision),o);return{snapshot:e.snapshot,entries:t.slice(0,e.revisions.length),nextRevision:e.nextRevision}}function Le(r){if(typeof r!="string"||Buffer.byteLength(r,"utf8")>2*1024*1024||/<!DOCTYPE|<!ENTITY/i.test(r)||Oe.validate(r)!==!0)throw new Error("Invalid SVN log XML");let t=new ke({ignoreAttributes:!1,parseAttributeValue:!1,parseTagValue:!1,trimValues:!1,isArray:n=>n==="logentry"}).parse(r);if(!Object.hasOwn(t,"log")||Object.keys(t).some(n=>n!=="log"&&n!=="?xml"))throw new Error("Invalid SVN log root");let e=t.log;if(typeof e=="string"&&/^[ \t\r\n]*$/.test(e))return[];if(e&&typeof e=="object"&&typeof e["#text"]=="string"&&/^[ \t\r\n]*$/.test(e["#text"])&&delete e["#text"],!e||typeof e!="object"||Object.keys(e).some(n=>n!=="logentry")||!Array.isArray(e.logentry)||e.logentry.length>101)throw new Error("Invalid SVN log entries");let s=new Set;return e.logentry.map(n=>{if(!n||typeof n!="object"||Array.isArray(n)||Object.keys(n).some(f=>!["@_revision","author","date","msg","#text"].includes(f))||"#text"in n&&(typeof n["#text"]!="string"||!/^[ \t\r\n]*$/.test(n["#text"])))throw new Error("Unsupported SVN log entry structure");let i=n["@_revision"];if(D(i),s.has(i))throw new Error("Duplicate SVN revision");s.add(i);let a=f=>{let c=n[f]??"";if(typeof c!="string")throw new Error("Invalid SVN log text");return c};return{revision:i,author:a("author"),date:a("date"),message:a("msg")}})}function ae({resolveIdentity:r,transport:o,now:t=Date.now,timeoutMs:e=15e3,transportFormat:s="cli"}={}){if(!["cli","dav"].includes(s))throw Error("Invalid SVN transport format");if(!Number.isInteger(e)||e<1||e>15e3)throw Error("Invalid SVN runtime deadline");if(typeof r!="function")throw Error("Local identity resolver required");let n=Y({now:t}),i=Y({now:t,onRevoke:u=>m(u)}),a=!1,f=()=>{if(a)throw new DOMException("SVN runtime disposed","AbortError")},c=async(u,d)=>{f(),d?.throwIfAborted();let h=await r(u,d);return f(),d?.throwIfAborted(),{...h,sessionId:u.sessionId,cwd:h.cwd,repositoryId:u.repositoryId}},p=u=>u.revision===void 0?{}:(D(u.revision),{snapshot:u.revision}),l=new Map,m=u=>{for(let d of l.get(u)||[])d.controller.abort(new DOMException("SVN consent revoked","AbortError"))},w=async(u,d)=>{f(),H(u,d.identity),d.signal?.throwIfAborted(),i.assert(d.token,d.identity);let h=new AbortController,y=()=>h.abort(d.signal.reason);d.signal?.addEventListener("abort",y,{once:!0});let b={controller:h,sessionId:d.identity.sessionId};l.has(d.token)||l.set(d.token,new Set),l.get(d.token).add(b);let v=setTimeout(()=>h.abort(new DOMException("SVN transport deadline exceeded","TimeoutError")),e);try{let E=async()=>{h.signal.throwIfAborted();let V=await c({sessionId:d.identity.sessionId,repositoryId:d.identity.repositoryId},h.signal);i.assert(d.token,V),h.signal.throwIfAborted()},S=await o(u,{...d,timeoutMs:e,signal:h.signal,assertAuthorized:E});if(h.signal.throwIfAborted(),!(typeof S=="string"||Buffer.isBuffer(S))||Buffer.byteLength(S)>d.maxBytes)throw Error("SVN transport output exceeds byte limit or has invalid type");return Buffer.isBuffer(S)&&u.args[0]!=="cat"?new TextDecoder("utf-8",{fatal:!0}).decode(S):S}catch(E){throw h.signal.aborted?h.signal.reason:E}finally{let E=l.get(d.token);E?.delete(b),E?.size||l.delete(d.token),clearTimeout(v),d.signal?.removeEventListener("abort",y)}},g={async describe(u,{signal:d}={}){let h=await c(u,d),y=p(h),b=n.grant(h,{explicit:!0});return{...y,offer:b,root:h.root,uuid:h.uuid,scope:h.scope,origin:new URL(h.root).origin,expiresAt:t()+3e5,remoteEnabled:typeof o=="function"}},async approve(u,{offer:d,explicit:h=!1,signal:y}={}){if(h!==!0)throw Error("Explicit SVN network consent required");let b=await c(u,y);if(n.assert(d,b),typeof o!="function")throw Error("SVN remote transport disabled");let v=p(b),E=i.grant(b,{explicit:!0});return n.revoke(d),{...v,token:E,expiresAt:t()+3e5}},async log(u,{token:d,snapshot:h,cursor:y,limit:b,path:v,signal:E}={}){let S=await c(u,E);if(i.assert(d,S),typeof o!="function")throw Error("SVN remote transport disabled");let V=q({...S,snapshot:h,cursor:y,limit:b,path:v});E?.throwIfAborted();let A=await w(V,{identity:S,token:d,signal:E,maxBytes:2097152,timeoutMs:15e3});E?.throwIfAborted();let x=await c(u,E);return i.assert(d,x),(s==="dav"?Q:ie)(A,V)},async detail(u,{token:d,snapshot:h,revision:y,signal:b}={}){let v=await c(u,b);if(i.assert(d,v),typeof o!="function")throw Error("SVN remote transport disabled");let E=M({...v,snapshot:h,revision:y}),S=await w(E,{identity:v,token:d,signal:b,maxBytes:2097152,timeoutMs:15e3});b?.throwIfAborted(),i.assert(d,await c(u,b));let V=s==="dav"?{...Z(S,E),pathsAvailable:!0}:ne(S,E);return{...V,snapshot:h,changes:V.changes.map(A=>({...A,id:Re("sha256").update(JSON.stringify([v.root,v.uuid,v.scope,h,y,A])).digest("hex")}))}},async compare(u,{token:d,snapshot:h,revision:y,id:b,signal:v}={}){if(typeof b!="string"||!/^[a-f0-9]{64}$/.test(b))throw Error("Invalid SVN change ID");let E=await g.detail(u,{token:d,snapshot:h,revision:y,signal:v}),S=E.changes.find(I=>I.id===b);if(!S)throw Error("SVN change is not selected revision member");let V=await c(u,v);i.assert(d,V);let A=te(E.changes.map(({id:I,...P})=>P),{scope:V.scope,revision:y,path:S.path}),x=async I=>{if(I.empty)return{label:"empty",text:"",absent:!0};let P=await c(u,v);i.assert(d,P);let C=N(P.root,I.path,I.pegRevision),J={identity:P,token:d,signal:v,maxBytes:2097152,timeoutMs:15e3},we=await w({args:["proplist","--xml","--non-interactive","--no-auth-cache","-r",I.revision,"--",C]},J);if(v?.throwIfAborted(),i.assert(d,await c(u,v)),oe(we,{target:C.slice(0,C.lastIndexOf("@")),allowEmpty:!0}).special)throw Error("SVN special files cannot be compared");let F=await w({args:["cat","--non-interactive","--no-auth-cache","-r",I.revision,"--",C]},J);v?.throwIfAborted(),i.assert(d,await c(u,v));let $=Buffer.isBuffer(F)?F:Buffer.from(F);if($.length>2097152)throw Error("SVN text exceeds 2 MiB");if($.includes(0))return{label:"r"+I.revision,text:"",binary:!0};let G;try{G=new TextDecoder("utf-8",{fatal:!0}).decode($)}catch{return{label:"r"+I.revision,text:"",binary:!0}}return{label:"r"+I.revision,text:G}},k=A.left;if(S.action==="R"&&!k.empty){let I=await c(u,v);i.assert(d,I);let P=N(I.root,k.path,k.pegRevision),C=await w({args:["info","--xml","--non-interactive","--no-auth-cache","-r",k.revision,"--",P]},{identity:I,token:d,signal:v,maxBytes:2097152,timeoutMs:15e3});v?.throwIfAborted(),i.assert(d,await c(u,v)),ee(C,{target:P.slice(0,P.lastIndexOf("@")),revision:k.revision,root:I.root,uuid:I.uuid})==="dir"&&(k={empty:!0})}let T=await x(k),K=await x(A.right);return{path:S.path,revision:y,snapshot:h,left:T,right:K,binary:!!(T.binary||K.binary)}},async trace(u,{token:d,snapshot:h,revision:y,id:b,cursor:v,limit:E=50,signal:S}={}){if(typeof b!="string"||!/^[a-f0-9]{64}$/.test(b))throw Error("Invalid SVN change ID");let V=await g.detail(u,{token:d,snapshot:h,revision:y,signal:S}),A=V.changes.find(T=>T.id===b);if(!A||A.kind!=="file")throw Error("SVN tracing requires selected file member");let x=A.action==="D"?U(y):y;return{...await g.log(u,{token:d,snapshot:x,cursor:v??x,limit:E,path:A.path,signal:S}),selectionSnapshot:h,selectionRevision:y,path:A.path,pegRevision:x,stopOnCopy:!0,copySourceOutsideScope:!!A.copySourceOutsideScope}},async copytrace(u,{token:d,snapshot:h,revision:y,id:b,cursor:v,limit:E=50,signal:S}={}){if(typeof b!="string"||!/^[a-f0-9]{64}$/.test(b))throw Error("Invalid SVN change ID");let V=await g.detail(u,{token:d,snapshot:h,revision:y,signal:S}),A=V.changes.find(T=>T.id===b);if(!A||A.kind!=="file"||A.copySourceOutsideScope||A.copyFromPath===void 0||A.copyFromRevision===void 0)throw Error("Selected file has no authorized copy source");let x=A.copyFromRevision;return{...await g.log(u,{token:d,snapshot:x,cursor:v??x,limit:E,path:A.copyFromPath,signal:S}),selectionSnapshot:h,selectionRevision:y,path:A.copyFromPath,pegRevision:x,sourceForPath:A.path,stopOnCopy:!0}},async revoke(u,{token:d,signal:h}={}){let y=await c(u,h);return i.assert(d,y),i.revoke(d),m(d),{revoked:!0}},dispose(){a=!0,n.clear(),i.clear();for(let u of l.keys())m(u)},revokeSession(u){n.revokeSession(u),i.revokeSession(u);for(let[d,h]of l)[...h].some(y=>y.sessionId===u)&&m(d)}};return g}var z=(r,o)=>({ok:!1,error:{code:r,message:o,details:{}}}),ce={revoke:["token"],describe:[],approve:["offer","explicit"],log:["token","snapshot","cursor","limit"],detail:["token","snapshot","revision"],compare:["token","snapshot","revision","id"],trace:["token","snapshot","revision","id","cursor","limit"],copytrace:["token","snapshot","revision","id","cursor","limit"]};function Te(r,o){if(!o||typeof o!="object"||Array.isArray(o))throw Error("Object payload required");if(Object.keys(o).some(t=>!["sessionId","repositoryId",...ce[r]].includes(t)))throw Error("Unknown SVN request field");for(let t of["sessionId","repositoryId"])if(typeof o[t]!="string"||!o[t]||o[t].length>1024||o[t].includes("\0"))throw Error("Invalid SVN Session address");if(r==="approve"&&(o.explicit!==!0||typeof o.offer!="string"||!/^[a-f0-9]{64}$/.test(o.offer)))throw Error("Explicit scoped offer required");if(!["describe","approve"].includes(r)){if(typeof o.token!="string"||!/^[a-f0-9]{64}$/.test(o.token))throw Error("SVN consent token required");if(r!=="revoke"&&D(o.snapshot),o.revision!==void 0&&D(o.revision),["detail","compare","trace","copytrace"].includes(r)&&o.revision===void 0)throw Error("Selected SVN revision required");if(o.cursor!==void 0&&D(o.cursor),o.limit!==void 0&&(!Number.isInteger(o.limit)||o.limit<1||o.limit>100))throw Error("Invalid SVN page size");if(["compare","trace","copytrace"].includes(r)&&(typeof o.id!="string"||!/^[a-f0-9]{64}$/.test(o.id)))throw Error("Selected SVN change ID required")}}function pe(r,{timeoutMs:o=15e3}={}){if(!Number.isInteger(o)||o<1||o>15e3)throw Error("Invalid SVN RPC deadline");let t=0;return async(e,s,n)=>{let i=e.startsWith("vcs/svn-")?e.slice(8):"";if(!Object.hasOwn(ce,i))return z("vcs/not-found","Unknown SVN endpoint");if(i!=="revoke"&&t>=2)return z("vcs/busy","SVN history requests busy");i!=="revoke"&&t++;let a=new AbortController,f=()=>a.abort(n.reason);n?.addEventListener("abort",f,{once:!0}),n?.aborted&&f();let c=setTimeout(()=>a.abort(new DOMException("SVN operation deadline exceeded","TimeoutError")),o);try{n?.throwIfAborted(),Te(i,s);let{sessionId:p,repositoryId:l,...m}=s,w=await r[i]({sessionId:p,repositoryId:l},{...m,signal:a.signal});return a.signal.throwIfAborted(),{ok:!0,value:w}}catch(p){let l=n?.aborted||p?.name==="AbortError"?"vcs/cancelled":["vcs/rediscover-required","vcs/svn-consent-required"].includes(p?.code)?p.code:"vcs/operation-failed",m=a.signal.aborted?a.signal.reason:p,w=m instanceof Error?m.message:String(m);return z(l,w)}finally{clearTimeout(c),n?.removeEventListener("abort",f),i!=="revoke"&&t--}}}var je=new Set(["describe","approve","log","detail","compare","trace","copytrace","revoke"]);function fe(r,o,{transport:t,transportFormat:e="cli",now:s=Date.now,timeoutMs:n=15e3}={}){let i,a=Pe(r,o,4,{now:s,bindSvnIdentityResolver:p=>{i=p}}),f=ae({resolveIdentity:i,transport:t,transportFormat:e,now:s,timeoutMs:n}),c=pe(f,{timeoutMs:n});return{handle(p,l,m){let w=p.startsWith("vcs/svn-")?p.slice(8):"";return je.has(w)?c(p,l,m):a(p,l,m)},revokeSession:p=>f.revokeSession(p),dispose:()=>f.dispose()}}import{request as Ce}from"node:https";function le({request:r=Ce}={}){return async(o,{origin:t,method:e="GET",body:s="",depth:n,label:i,signal:a,maxBytes:f=2097152,timeoutMs:c=15e3}={})=>{let p=new URL(o);if(p.protocol!=="https:"||p.origin!==t||p.username||p.password||p.hash||p.href!==o||!["GET","PROPFIND","REPORT"].includes(e)||typeof s!="string"||Buffer.byteLength(s)>65536||!Number.isInteger(f)||f<1||f>2097152||!Number.isInteger(c)||c<1||c>15e3)throw Error("Invalid bounded HTTPS request");if(n!==void 0&&(e!=="PROPFIND"||n!==0))throw Error("Invalid DAV depth");if(i!==void 0){if(e!=="PROPFIND"||n!==0)throw Error("Invalid DAV label");D(i)}let l={...n===0?{Depth:"0"}:{},...i!==void 0?{Label:i}:{}};return a?.throwIfAborted(),new Promise((m,w)=>{let g,u,d=null,h=null,y=0,b=[],v=A=>{d??=A,u?.destroy(),g?.destroy()},E=()=>v(a.reason??new DOMException("HTTPS cancelled","AbortError")),S=setTimeout(()=>v(new DOMException("HTTPS deadline exceeded","TimeoutError")),c),V=()=>{clearTimeout(S),a?.removeEventListener("abort",E)};try{g=r(p,{method:e,agent:!1,rejectUnauthorized:!0,maxHeaderSize:16384,headers:{...l,"Accept-Encoding":"identity","Content-Type":"text/xml; charset=utf-8","Content-Length":String(Buffer.byteLength(s))}},A=>{u=A;let x=u.statusCode??0;if(x>=300&&x<400){v(Error("HTTPS redirects forbidden"));return}if(x<200||x>=300){v(Error("HTTPS status "+x));return}if(u.headers["content-encoding"]&&u.headers["content-encoding"]!=="identity"){v(Error("HTTPS compressed responses forbidden"));return}let k=u.headers["content-length"];if(k!==void 0&&(!/^[0-9]+$/.test(k)||Number(k)>f)){v(Error("HTTPS response exceeds byte limit"));return}u.on("data",T=>{y+=T.length,y>f?v(Error("HTTPS response exceeds byte limit")):d||b.push(T)}),u.on("error",v),u.on("end",()=>{if(!u.complete){v(Error("HTTPS response incomplete"));return}h=Buffer.concat(b)})}),g.on("error",A=>{d??=A}),g.once("close",()=>{V(),d?w(d):h!==null?m(h):w(Error("HTTPS response closed before completion"))}),a?.addEventListener("abort",E,{once:!0}),a?.aborted?E():g.end(s)}catch(A){V(),g?.destroy(),w(A)}})}}var _e=r=>r.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'");function de(r,o){let t=H(r,o),e=t.args;if(e[0]!=="log")throw Error("DAV log report requires readonly log plan");let s=e.includes("--verbose"),n=e[s?9:8].split(":"),i=e[s?7:6],a=t.path==="/"?"":t.path.slice(1),f='<?xml version="1.0" encoding="utf-8"?><S:log-report xmlns:S="svn:" xmlns:D="DAV:"><S:start-revision>'+n[0]+"</S:start-revision><S:end-revision>"+n[1]+"</S:end-revision><S:limit>"+i+"</S:limit><S:strict-node-history/>"+(s?"<S:discover-changed-paths/>":"")+"<S:path>"+_e(a)+"</S:path><S:revprop>svn:author</S:revprop><S:revprop>svn:date</S:revprop><S:revprop>svn:log</S:revprop></S:log-report>";if(Buffer.byteLength(f)>65536)throw Error("DAV request body exceeds limit");return{method:"REPORT",body:f,pegRevision:t.pegRevision,path:t.path,requiresVerifiedBaseline:!0}}function ue(r,{root:o,uuid:t,target:e}={}){let s=O(r),n=(l,m)=>{if(!l||typeof l!="object"||Array.isArray(l)||Object.keys(l).some(w=>!m.includes(w)&&!(w==="#text"&&typeof l[w]=="string"&&l[w].trim()==="")))throw Error("Unsupported DAV discovery structure")};n(s,["?xml","D:multistatus"]);let i=s["D:multistatus"];if(n(i,["D:response"]),!Array.isArray(i["D:response"])||i["D:response"].length!==1)throw Error("DAV discovery requires one response");let a=i["D:response"][0];if(n(a,["D:href","D:propstat"]),L(a["D:href"],{root:o})!==e)throw Error("DAV response target mismatch");if(!Array.isArray(a["D:propstat"])||a["D:propstat"].length!==1)throw Error("DAV discovery requires one property status");let f=a["D:propstat"][0];if(n(f,["D:prop","D:status"]),!/^HTTP[/]1[.][01] 200(?: OK)?$/.test(f["D:status"]))throw Error("DAV discovery properties unavailable");let c=f["D:prop"];if(n(c,["S:repository-uuid","D:version-controlled-configuration"]),c["S:repository-uuid"]!==t||typeof t!="string"||!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(t))throw Error("DAV UUID does not match local identity");let p=c["D:version-controlled-configuration"];return n(p,["D:href"]),{uuid:t,vcc:L(p["D:href"],{root:o}),target:e}}function he(r,{root:o,revision:t}={}){D(t);let e=O(r),s=(l,m)=>{if(!l||typeof l!="object"||Array.isArray(l)||Object.keys(l).some(w=>!m.includes(w)))throw Error("Invalid DAV baseline structure")};s(e,["D:multistatus"]);let n=e["D:multistatus"];if(s(n,["D:response"]),n["D:response"]?.length!==1)throw Error("One DAV baseline response required");let i=n["D:response"][0];s(i,["D:href","D:propstat"]);let a=L(i["D:href"],{root:o});if(i["D:propstat"]?.length!==1)throw Error("One DAV baseline status required");let f=i["D:propstat"][0];if(s(f,["D:status","D:prop"]),f["D:status"]!=="HTTP/1.1 200 OK")throw Error("DAV baseline status unavailable");let c=f["D:prop"];if(s(c,["D:version-name","D:baseline-collection"]),c["D:version-name"]!==t)throw Error("DAV baseline revision mismatch");s(c["D:baseline-collection"],["D:href"]);let p=L(c["D:baseline-collection"]["D:href"],{root:o});if(!p.endsWith("/"))throw Error("DAV baseline collection must end in slash");return{revision:t,baseline:a,collection:p}}function me({request:r,assertAuthorized:o}={}){if(typeof r!="function"||typeof o!="function")throw Error("DAV chain requires transport and authorization");return async(t,{revision:e,signal:s}={})=>{D(e),N(t.root,t.scope,e);let n=t.root,i=new URL(n).origin,a=n.endsWith("/")?n:n+"/",f=async(m,w)=>{s?.throwIfAborted(),await o(t,{signal:s}),s?.throwIfAborted();let g=await r(m,{origin:i,signal:s,...w});if(s?.throwIfAborted(),await o(t,{signal:s}),s?.throwIfAborted(),!Buffer.isBuffer(g)||g.length>2097152)throw Error("Invalid DAV response bytes");return new TextDecoder("utf-8",{fatal:!0}).decode(g)},c=await f(a,{method:"PROPFIND",depth:0,body:'<D:propfind xmlns:D="DAV:" xmlns:S="http://subversion.tigris.org/xmlns/dav/"><D:prop><S:repository-uuid/><D:version-controlled-configuration/></D:prop></D:propfind>'}),{vcc:p}=ue(c,{root:n,target:a,uuid:t.uuid}),l=await f(p,{method:"PROPFIND",depth:0,label:e,body:'<D:propfind xmlns:D="DAV:"><D:prop><D:baseline-collection/><D:version-name/></D:prop></D:propfind>'});return{...he(l,{root:n,revision:e}),uuid:t.uuid}}}function ve(r,{root:o,target:t}={}){let e=O(r),s=(p,l)=>{if(!p||typeof p!="object"||Array.isArray(p)||Object.keys(p).some(m=>!l.includes(m)))throw Error("Invalid DAV property names structure")};s(e,["D:multistatus"]);let n=e["D:multistatus"];if(s(n,["D:response"]),n["D:response"]?.length!==1)throw Error("One DAV property response required");let i=n["D:response"][0];if(s(i,["D:href","D:propstat"]),L(i["D:href"],{root:o})!==t)throw Error("DAV property target mismatch");if(i["D:propstat"]?.length!==1)throw Error("One DAV property status required");let a=i["D:propstat"][0];if(s(a,["D:status","D:prop"]),a["D:status"]!=="HTTP/1.1 200 OK")throw Error("DAV property names unavailable");let f=a["D:prop"];if(f!==""&&(!f||typeof f!="object"||Array.isArray(f)||Object.keys(f).length>1e3||Object.entries(f).some(([p,l])=>!/^[DSPC]:[^:]+$/.test(p)||l!=="")))throw Error("DAV property names must be empty");let c=f===""?[]:Object.keys(f);return{names:c,special:c.includes("P:special")}}var X=r=>r.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""");function ge({request:r}={}){if(typeof r!="function")throw Error("Bounded DAV request required");return async(o,{identity:t,assertAuthorized:e,signal:s}={})=>{let n=H(o,t),i=n.args[0],a=me({request:r,assertAuthorized:e}),f=await a(t,{revision:n.pegRevision,signal:s}),c=async(g,u)=>{s?.throwIfAborted(),await e(),s?.throwIfAborted();let d=await r(g,{origin:new URL(t.root).origin,...u,signal:s});if(s?.throwIfAborted(),await e(),s?.throwIfAborted(),!Buffer.isBuffer(d)||d.length>2097152)throw Error("Invalid DAV transport bytes");return d};if(i==="log"){let g=de(o,t);return c(f.collection,{method:"REPORT",body:g.body})}let p=n.path.slice(1).split("/").map(g=>encodeURIComponent(g).replace(/[!'()*]/g,u=>"%"+u.charCodeAt(0).toString(16).toUpperCase())).join("/"),l=L(f.collection+p,{root:t.root});if(i==="info"){let g=await c(l,{method:"PROPFIND",depth:0,body:'<D:propfind xmlns:D="DAV:"><D:prop><D:resourcetype/></D:prop></D:propfind>'}),u=re(new TextDecoder("utf-8",{fatal:!0}).decode(g),{root:t.root,target:l}),d=n.args.at(-1).slice(0,n.args.at(-1).lastIndexOf("@"));return'<info><entry kind="'+u+'" revision="'+n.pegRevision+'"><url>'+X(d)+"</url><repository><root>"+X(t.root)+"</root><uuid>"+X(t.uuid)+"</uuid></repository></entry></info>"}let m=await c(l,{method:"PROPFIND",depth:0,body:'<D:propfind xmlns:D="DAV:"><D:propname/></D:propfind>'}),w=ve(new TextDecoder("utf-8",{fatal:!0}).decode(m),{root:t.root,target:l});if(i==="proplist")return'<properties><target path="'+X(n.args.at(-1).slice(0,n.args.at(-1).lastIndexOf("@")))+'">'+(w.special?'<property name="svn:special"/>':"")+"</target></properties>";if(w.special)throw Error("SVN special content forbidden");return c(l,{method:"GET"})}}function kt(r,o){return fe(r,o,{transportFormat:"dav",transport:ge({request:le()})})}export{kt as createSvnHttpsHost};
|
|
1
|
+
import{createHandler as Ge}from"../index.mjs";import{createHash as $e}from"node:crypto";var Le=9223372036854775807n;function w(e){if(typeof e!="string"||e.length>19||!/^(0|[1-9][0-9]*)$/.test(e))throw new Error("Invalid SVN revision");let o=BigInt(e);if(o>Le)throw new Error("SVN revision exceeds supported range");return o}function q(e){let o=w(e);return o===0n?null:String(o-1n)}function H(e,{snapshot:o,cursor:r=o,limit:t=50}={}){let s=w(o),n=w(r);if(n>s||!Number.isInteger(t)||t<1||t>100||!Array.isArray(e)||e.length>t+1)throw new Error("Invalid SVN page bounds");let a=n+1n;for(let p of e){let f=w(p);if(f>n||f>=a)throw new Error("SVN revisions must descend within cursor");a=f}let i=e.slice(0,t);return{snapshot:o,revisions:i,nextRevision:e.length>t?q(i.at(-1)):null}}function j(e){if(typeof e!="string"||e.length>32768||!e.startsWith("/")||/[\u0000-\u001f\u007f\\]/.test(e))throw new Error("Invalid SVN repository path");if(e!=="/"&&e.slice(1).split("/").some(o=>o===""||o==="."||o===".."))throw new Error("Noncanonical SVN repository path");return e}function C(e,o){return j(e),j(o),o==="/"||e===o||e.startsWith(o+"/")}function O(e,o,r){if(j(o),w(r),typeof e!="string"||e.length>32768||/[\x00-\x20\x7f\\?#]/.test(e))throw new Error("Invalid SVN HTTPS root");let t=new URL(e);if(t.protocol!=="https:"||t.username||t.password||t.href!==e)throw new Error("Noncanonical SVN HTTPS root");let s=t.pathname.split("/").slice(1);s.at(-1)===""&&s.pop();for(let p of s){let f=decodeURIComponent(p);if(!p||f==="."||f===".."||/[\x00-\x1f\x7f/\\]/.test(f))throw new Error("Invalid SVN root path")}let n=e.endsWith("/")?e.slice(0,-1):e,a=o==="/"?"":o.split("/").map(p=>encodeURIComponent(p).replace(/[!'()*]/g,f=>"%"+f.charCodeAt(0).toString(16).toUpperCase())).join("/"),i=n+(a||(t.pathname==="/"?"/":""))+"@"+r;if(i.length>32768)throw new Error("SVN target too long");return i}function F({root:e,scope:o,path:r=o,snapshot:t,revision:s}={}){if(w(s)>w(t))throw new Error("SVN selected revision exceeds snapshot");if(!C(r,o))throw new Error("SVN detail path outside scope");let n=O(e,r,t);return{scope:o,revision:s,snapshot:t,args:["log","--xml","--verbose","--stop-on-copy","--non-interactive","--no-auth-cache","--limit","1","-r",s+":"+s,"--",n]}}function $({root:e,scope:o,path:r=o,snapshot:t,cursor:s=t,limit:n=50}={}){if(H([],{snapshot:t,cursor:s,limit:n}),!C(r,o))throw new Error("SVN history path outside scope");let a=O(e,r,t);return{snapshot:t,cursor:s,limit:n,args:["log","--xml","--stop-on-copy","--non-interactive","--no-auth-cache","--limit",String(n+1),"-r",s+":0","--",a]}}function M(e,o){let r=e?.args;if(!Array.isArray(r)||r.length>16||r.some(l=>typeof l!="string"))throw Error("Invalid SVN command");let t=r.at(-1),s=t.lastIndexOf("@"),n=t.slice(s+1);w(n);let a=o.root.endsWith("/")?o.root.slice(0,-1):o.root;O(o.root,"/",n);let i=t.slice(0,s);if(!(i===a||i.startsWith(a+"/")))throw Error("SVN command target outside root");let p=i.slice(a.length),f=p?"/"+p.slice(1).split("/").map(l=>decodeURIComponent(l)).join("/"):"/";if(!C(f,o.scope)||O(o.root,f,n)!==t)throw Error("SVN command target outside scope or noncanonical");let c;if(r[0]==="cat"||r[0]==="proplist"||r[0]==="info"){w(r[r[0]==="cat"?4:5]);let l=r[r[0]==="cat"?4:5];if(l!==n)throw Error("SVN content operative and peg mismatch");c=r[0]==="cat"?["cat","--non-interactive","--no-auth-cache","-r",l,"--",t]:[r[0],"--xml","--non-interactive","--no-auth-cache","-r",l,"--",t]}else if(r[0]==="log")if(r.includes("--verbose")){let l=r[9]?.split(":")[0];c=F({...o,path:f,snapshot:n,revision:l}).args}else{let l=r[8]?.split(":")[0],m=Number(r[6])-1;c=$({...o,path:f,snapshot:n,cursor:l,limit:m}).args}else throw Error("SVN command is not readonly history");if(JSON.stringify(r)!==JSON.stringify(c))throw Error("Unsupported SVN command shape");return{path:f,pegRevision:n,args:[...c]}}function W(e,o){if(!Array.isArray(e)||e.length>1e4)throw new Error("Invalid SVN path nodes");let r=e.map(t=>{let s=["#text","@_action","@_kind","@_copyfrom-path","@_copyfrom-rev","@_text-mods","@_prop-mods"];if(!t||typeof t!="object"||Array.isArray(t)||Object.keys(t).some(n=>!s.includes(n)))throw new Error("Invalid SVN path node");for(let n of["@_text-mods","@_prop-mods"])if(Object.hasOwn(t,n)&&!["true","false","unknown"].includes(t[n]))throw new Error("Invalid SVN modification flag");return{...Object.hasOwn(t,"@_text-mods")?{textModified:t["@_text-mods"]}:{},...Object.hasOwn(t,"@_prop-mods")?{propertiesModified:t["@_prop-mods"]}:{},path:t["#text"],action:t["@_action"],kind:t["@_kind"],...Object.hasOwn(t,"@_copyfrom-path")?{copyFromPath:t["@_copyfrom-path"]}:{},...Object.hasOwn(t,"@_copyfrom-rev")?{copyFromRevision:t["@_copyfrom-rev"]}:{}}});return Z(r,o)}function Z(e,{scope:o,revision:r}={}){j(o);let t=w(r);if(!Array.isArray(e)||e.length>1e4||t===0n&&e.length!==0)throw new Error("Invalid SVN changed paths");let s=new Set;return e.map(a=>{if(!a||typeof a!="object"||Array.isArray(a)||Object.keys(a).some(S=>!["path","action","kind","copyFromPath","copyFromRevision","copySourceOutsideScope","textModified","propertiesModified"].includes(S)))throw new Error("Invalid SVN change structure");let{path:i,action:p,kind:f,copyFromPath:c,copyFromRevision:l}=a;if(j(i),s.has(i)||!["A","D","M","R"].includes(p)||!["file","dir","unknown"].includes(f))throw new Error("Invalid SVN change");s.add(i);let m=c!==void 0||l!==void 0;if(m&&(j(c),!["A","R"].includes(p)||w(l)>=t))throw new Error("Invalid SVN copy source");let g=Object.hasOwn(a,"copySourceOutsideScope");if(g&&(a.copySourceOutsideScope!==!0||m||!["A","R"].includes(p)))throw new Error("Invalid SVN redacted copy source");let y={path:i,action:p,kind:f,...g?{copySourceOutsideScope:!0}:{}};for(let S of["textModified","propertiesModified"])if(Object.hasOwn(a,S)){if(!["true","false","unknown"].includes(a[S]))throw new Error("Invalid SVN modification flag");y[S]=a[S]}return m&&(C(c,o)?(y.copyFromPath=c,y.copyFromRevision=l):y.copySourceOutsideScope=!0),y}).filter(a=>C(a.path,o))}function ie(e,{scope:o,revision:r,path:t}={}){if(w(r)===0n)throw new Error("SVN r0 has no change comparison");let s=Z(e,{scope:o,revision:r}).find(i=>i.path===t);if(!s)throw new Error("SVN path is not an authorized changed member");if(s.kind!=="file")throw new Error("Only SVN file changes can be compared");let n=q(r),a=i=>i===null?{empty:!0}:{empty:!1,path:s.path,revision:i,pegRevision:i};return{path:s.path,action:s.action,left:a(s.action==="A"?null:n),right:a(s.action==="D"?null:r)}}import{randomBytes as Re}from"node:crypto";function ae(e){if(!e||typeof e!="object")throw Error("Invalid SVN consent identity");let{sessionId:o,cwd:r,repositoryId:t,root:s,uuid:n,scope:a}=e;for(let i of[o,r,t])if(typeof i!="string"||!i||i.length>32768||i.includes("\0"))throw Error("Invalid SVN consent scope");if(O(s,"/","0"),j(a),typeof n!="string"||!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(n))throw Error("Invalid SVN repository UUID");return JSON.stringify([o,r,t,s,n,a])}function Q({now:e=Date.now,ttlMs:o=3e5,maxEntries:r=32,onRevoke:t=()=>{}}={}){if(!Number.isInteger(o)||o<1||o>3e5||!Number.isInteger(r)||r<1||r>32)throw Error("Invalid SVN consent bounds");if(typeof t!="function")throw Error("Invalid SVN revoke listener");let s=new Map,n=i=>{s.delete(i)&&t(i)},a=()=>{for(let[i,p]of s)p.expires<=e()&&n(i)};return{grant(i,{explicit:p=!1}={}){if(p!==!0)throw Error("Explicit SVN network consent required");let f=ae(i);a();for(let[l,m]of s)m.key===f&&n(l);for(;s.size>=r;)n(s.keys().next().value);let c=Re(32).toString("hex");return s.set(c,{key:f,sessionId:i.sessionId,expires:e()+o}),c},assert(i,p){a();let f=ae(p),c=s.get(i);if(!c||c.key!==f)throw Object.assign(Error("SVN network consent missing, expired or identity changed"),{code:"vcs/svn-consent-required"})},revokeSession(i){for(let[p,f]of s)f.sessionId===i&&n(p)},revoke(i){n(i)},clear(){for(let i of[...s.keys()])n(i)}}}import{XMLParser as Pe,XMLValidator as je}from"fast-xml-parser";function L(e){if(typeof e!="string"||Buffer.byteLength(e)>2097152||/<!DOCTYPE|<!ENTITY/i.test(e)||je.validate(e)!==!0)throw Error("Invalid DAV XML");let o=new Pe({preserveOrder:!0,ignoreAttributes:!1,parseTagValue:!1,parseAttributeValue:!1,trimValues:!1}).parse(e),r=0,t=(s,n,a=0)=>{if(a>32)throw Error("DAV XML too deep");let i=Object.create(null),p="";for(let f of s){if(++r>1e4)throw Error("DAV XML too many nodes");if(Object.hasOwn(f,"#text")){p+=f["#text"];continue}let c=Object.keys(f).filter(v=>v!==":@");if(c.length!==1)throw Error("Invalid DAV XML node");let l=c[0];if(l==="?xml"){if(a!==0)throw Error("Unexpected XML declaration");continue}let m={...n},g={};for(let[v,b]of Object.entries(f[":@"]||{}))v==="@_xmlns"?m[""]=b:v.startsWith("@_xmlns:")?m[v.slice(8)]=b:g[v]=b;let y=l.split(":");if(y.length>2)throw Error("Invalid DAV XML name");let S=y.length===2?y[0]:"",A=y.at(-1),k=m[S],I=k==="DAV:"?"D:"+A:k==="http://subversion.tigris.org/xmlns/dav/"?"S:"+A:k==="svn:"?"L:"+A:k==="http://subversion.tigris.org/xmlns/svn/"?"P:"+A:k==="http://subversion.tigris.org/xmlns/custom/"?"C:"+A:null;if(!I)throw Error("Unsupported DAV namespace");let u=["L:added-path","L:deleted-path","L:modified-path","L:replaced-path"].includes(I);if(Object.keys(g).length&&(!u||Object.keys(g).some(v=>!["@_node-kind","@_text-mods","@_prop-mods","@_copyfrom-path","@_copyfrom-rev"].includes(v))))throw Error("Unexpected DAV attribute");let d=t(f[l],m,a+1);if(u&&typeof d!="string")throw Error("Invalid DAV path text");let h=u?{...g,"#text":d}:d;if(["D:response","D:propstat","L:log-item","L:added-path","L:deleted-path","L:modified-path","L:replaced-path"].includes(I))(i[I]??=[]).push(h);else{if(Object.hasOwn(i,I))throw Error("Duplicate DAV expanded name");i[I]=h}}if(!Object.keys(i).length)return p;if(p.trim())throw Error("Mixed DAV XML content");return i};return t(o,{})}function ce(e,{scope:o,revision:r}={}){w(r);let t=L(e),s=(c,l)=>{if(!c||typeof c!="object"||Array.isArray(c)||Object.keys(c).some(m=>!l.includes(m)))throw Error("Invalid DAV detail structure")};s(t,["L:log-report"]);let n=t["L:log-report"];if(s(n,["L:log-item"]),n["L:log-item"]?.length!==1)throw Error("One DAV detail revision required");let a=n["L:log-item"][0],i={"L:added-path":"A","L:deleted-path":"D","L:modified-path":"M","L:replaced-path":"R"};if(s(a,["D:version-name","D:comment","D:creator-displayname","L:date",...Object.keys(i)]),a["D:version-name"]!==r)throw Error("DAV detail revision mismatch");let p=c=>{let l=a[c]??"";if(typeof l!="string")throw Error("Invalid DAV detail text");return l},f=[];for(let[c,l]of Object.entries(i))for(let m of a[c]??[]){let{"@_node-kind":g,...y}=m;f.push({...y,"@_kind":g??"unknown","@_action":l})}return{revision:r,author:p("D:creator-displayname"),date:p("L:date"),message:p("D:comment"),changes:W(f,{scope:o,revision:r})}}function pe(e,o){let r=L(e);if(!r||typeof r!="object"||Object.keys(r).length!==1||!Object.hasOwn(r,"L:log-report"))throw Error("Invalid DAV log root");let t=r["L:log-report"],s;if(t==="")s=[];else{if(!t||typeof t!="object"||Object.keys(t).some(i=>i!=="L:log-item")||!Array.isArray(t["L:log-item"]))throw Error("Invalid DAV log structure");s=t["L:log-item"]}if(s.length>101)throw Error("DAV log entries exceed limit");let n=s.map(i=>{if(!i||typeof i!="object"||Array.isArray(i)||Object.keys(i).some(f=>!["D:version-name","D:comment","D:creator-displayname","L:date"].includes(f)))throw Error("Unsupported DAV log item");let p=f=>{let c=i[f]??"";if(typeof c!="string")throw Error("Invalid DAV log text");return c};return{revision:p("D:version-name"),message:p("D:comment"),author:p("D:creator-displayname"),date:p("L:date")}}),a=H(n.map(i=>i.revision),o);return{snapshot:a.snapshot,entries:n.slice(0,a.revisions.length),nextRevision:a.nextRevision}}import{XMLParser as _e,XMLValidator as Ce}from"fast-xml-parser";function fe(e,{scope:o,revision:r}={}){if(w(r),typeof e!="string"||Buffer.byteLength(e,"utf8")>2*1024*1024||/<!DOCTYPE|<!ENTITY/i.test(e)||Ce.validate(e)!==!0)throw new Error("Invalid SVN detail XML");let t=new _e({ignoreAttributes:!1,parseAttributeValue:!1,parseTagValue:!1,trimValues:!1,isArray:f=>f==="logentry"||f==="path"}).parse(e),s=(f,c)=>{if(!f||typeof f!="object"||Array.isArray(f)||Object.keys(f).some(l=>!c.includes(l)&&!(l==="#text"&&typeof f[l]=="string"&&/^[ \t\r\n]*$/.test(f[l]))))throw new Error("Invalid SVN detail structure")};if(s(t,["?xml","log"]),s(t.log,["logentry"]),!Array.isArray(t.log.logentry)||t.log.logentry.length!==1)throw new Error("Expected one SVN revision");let n=t.log.logentry[0];if(s(n,["@_revision","author","date","msg","paths"]),n["@_revision"]!==r)throw new Error("SVN detail revision mismatch");let a=f=>{let c=n[f]??"";if(typeof c!="string")throw new Error("Invalid SVN detail text");return c},i=[];n.paths!==void 0&&!(typeof n.paths=="string"&&/^[ \t\r\n]*$/.test(n.paths))&&(s(n.paths,["path"]),i=n.paths.path??[]);let p=W(i,{scope:o,revision:r});return{revision:r,author:a("author"),date:a("date"),message:a("msg"),pathsAvailable:Object.hasOwn(n,"paths"),changes:p}}import{XMLParser as Ue,XMLValidator as He}from"fast-xml-parser";function le(e,o){let r=Me(e),t=H(r.map(s=>s.revision),o);return{snapshot:t.snapshot,entries:r.slice(0,t.revisions.length),nextRevision:t.nextRevision}}function Me(e){if(typeof e!="string"||Buffer.byteLength(e,"utf8")>2*1024*1024||/<!DOCTYPE|<!ENTITY/i.test(e)||He.validate(e)!==!0)throw new Error("Invalid SVN log XML");let r=new Ue({ignoreAttributes:!1,parseAttributeValue:!1,parseTagValue:!1,trimValues:!1,isArray:n=>n==="logentry"}).parse(e);if(!Object.hasOwn(r,"log")||Object.keys(r).some(n=>n!=="log"&&n!=="?xml"))throw new Error("Invalid SVN log root");let t=r.log;if(typeof t=="string"&&/^[ \t\r\n]*$/.test(t))return[];if(t&&typeof t=="object"&&typeof t["#text"]=="string"&&/^[ \t\r\n]*$/.test(t["#text"])&&delete t["#text"],!t||typeof t!="object"||Object.keys(t).some(n=>n!=="logentry")||!Array.isArray(t.logentry)||t.logentry.length>101)throw new Error("Invalid SVN log entries");let s=new Set;return t.logentry.map(n=>{if(!n||typeof n!="object"||Array.isArray(n)||Object.keys(n).some(p=>!["@_revision","author","date","msg","#text"].includes(p))||"#text"in n&&(typeof n["#text"]!="string"||!/^[ \t\r\n]*$/.test(n["#text"])))throw new Error("Unsupported SVN log entry structure");let a=n["@_revision"];if(w(a),s.has(a))throw new Error("Duplicate SVN revision");s.add(a);let i=p=>{let f=n[p]??"";if(typeof f!="string")throw new Error("Invalid SVN log text");return f};return{revision:a,author:i("author"),date:i("date"),message:i("msg")}})}import{XMLParser as qe,XMLValidator as Be}from"fast-xml-parser";function R(e,{root:o}={}){if(O(o,"/","0"),typeof e!="string"||!e||e.length>32768||/[\\?#]/.test(e)||[...e].some(n=>n.charCodeAt(0)<=32||n.charCodeAt(0)===127))throw Error("Invalid DAV href");if(!(e.startsWith("/")&&!e.startsWith("//"))&&!e.startsWith("https://"))throw Error("DAV href must be absolute path or HTTPS URL");let r=new URL(e,new URL(o).origin);if(r.protocol!=="https:"||r.origin!==new URL(o).origin||r.username||r.password||r.search||r.hash)throw Error("DAV href outside authorized origin");if(e.startsWith("https://")&&r.href!==e||e.startsWith("/")&&r.pathname!==e)throw Error("Noncanonical DAV href");let t=r.pathname.split("/").slice(1);t.at(-1)===""&&t.pop();for(let n of t){let a=decodeURIComponent(n);if(!n||a==="."||a===".."||[...a].some(i=>i.charCodeAt(0)<32||i.charCodeAt(0)===127||i==="/"||i.charCodeAt(0)===92))throw Error("Unsafe DAV href path")}let s=new URL(o).pathname.replace(/[/]$/,"");if(s&&r.pathname!==s&&!r.pathname.startsWith(s+"/"))throw Error("DAV href outside repository root");return r.href}function de(e,{target:o,revision:r,root:t,uuid:s}={}){if(typeof e!="string"||Buffer.byteLength(e)>2097152||/<!DOCTYPE|<!ENTITY/i.test(e)||Be.validate(e)!==!0)throw Error("Invalid SVN node kind XML");let a=new qe({ignoreAttributes:!1,parseAttributeValue:!1,parseTagValue:!1,trimValues:!1,isArray:p=>p==="entry"}).parse(e)?.info?.entry;if(!Array.isArray(a)||a.length!==1)throw Error("Expected one SVN node kind entry");let i=a[0];if(i.url!==o||i["@_revision"]!==r||i.repository?.root!==t||i.repository?.uuid!==s)throw Error("SVN node kind identity mismatch");if(!["file","dir"].includes(i["@_kind"]))throw Error("Unknown SVN node kind");return i["@_kind"]}function ue(e,{root:o,target:r}={}){let t=L(e),s=(c,l)=>{if(!c||typeof c!="object"||Array.isArray(c)||Object.keys(c).some(m=>!l.includes(m)))throw Error("Invalid DAV node kind structure")};s(t,["D:multistatus"]),s(t["D:multistatus"],["D:response"]);let n=t["D:multistatus"]["D:response"];if(n?.length!==1)throw Error("Expected one DAV node kind response");let a=n[0];s(a,["D:href","D:propstat"]);let i=R(a["D:href"],{root:o});if(a["D:propstat"]?.length!==1)throw Error("Expected one DAV node kind status");let p=a["D:propstat"][0];if(s(p,["D:status","D:prop"]),!/^HTTP[/]1[.][01] 200(?: OK)?$/.test(p["D:status"]))throw Error("DAV node kind unavailable");s(p["D:prop"],["D:resourcetype"]);let f=p["D:prop"]["D:resourcetype"];if(f===""){if(i!==r)throw Error("DAV node kind target mismatch");return"file"}if(s(f,["D:collection"]),f["D:collection"]!=="")throw Error("Unknown DAV node kind");if(i!==r&&i!==r+"/")throw Error("DAV node kind target mismatch");return"dir"}import{XMLParser as Xe,XMLValidator as Fe}from"fast-xml-parser";function he(e,{target:o,allowEmpty:r=!1}={}){if(typeof o!="string"||!o||o.length>32768)throw new Error("Invalid SVN property target");if(typeof e!="string"||Buffer.byteLength(e,"utf8")>2*1024*1024||/<!DOCTYPE|<!ENTITY/i.test(e)||Fe.validate(e)!==!0)throw new Error("Invalid SVN property XML");let t=new Xe({ignoreAttributes:!1,parseAttributeValue:!1,parseTagValue:!1,trimValues:!1,isArray:c=>c==="target"||c==="property"}).parse(e),s=(c,l)=>{if(!c||typeof c!="object"||Array.isArray(c)||Object.keys(c).some(m=>!l.includes(m)&&!(m==="#text"&&typeof c[m]=="string"&&/^[ \t\r\n]*$/.test(c[m]))))throw new Error("Invalid SVN property structure")};if(s(t,["?xml","properties"]),r===!0&&typeof t.properties=="string"&&/^[ \t\r\n]*$/.test(t.properties))return{target:o,names:[],special:!1};s(t.properties,["target"]);let n=t.properties.target;if(!Array.isArray(n)||n.length!==1)throw new Error("Expected one SVN property target");let a=n[0];if(s(a,["@_path","property"]),a["@_path"]!==o)throw new Error("SVN property target mismatch");let i=a.property??[];if(!Array.isArray(i)||i.length>1e4)throw new Error("Too many SVN properties");let p=[],f=new Set;for(let c of i){s(c,["@_name"]);let l=c["@_name"];if(typeof l!="string"||!l||l.length>1024||/[\x00-\x20\x7f]/.test(l)||f.has(l))throw new Error("Invalid SVN property name");f.add(l),p.push(l)}return{target:o,names:p,special:f.has("svn:special")}}var ye=2*1024*1024,me=15e3,ve=3e5,ge=50,We=/^[a-f0-9]{64}$/,ee=e=>{if(typeof e!="string"||!We.test(e))throw Error("Invalid SVN change ID")},re=(e,o,r)=>{let t=e.changes.find(s=>s.id===o);return r===void 0||t?.kind===r?t:void 0},we=e=>e.slice(0,e.lastIndexOf("@")),Ye=(e,o,r,t)=>$e("sha256").update(JSON.stringify([e.root,e.uuid,e.scope,o,r,t])).digest("hex"),ze=(e,o,r)=>{if(!(typeof e=="string"||Buffer.isBuffer(e))||Buffer.byteLength(e)>r)throw Error("SVN transport output exceeds byte limit or has invalid type");return Buffer.isBuffer(e)&&o.args[0]!=="cat"?new TextDecoder("utf-8",{fatal:!0}).decode(e):e},Y=(e,o,r)=>({identity:e,token:o,signal:r,maxBytes:ye});function Se({resolveIdentity:e,transport:o,now:r=Date.now,timeoutMs:t=me,transportFormat:s="cli"}={}){if(!["cli","dav"].includes(s))throw Error("Invalid SVN transport format");if(!Number.isInteger(t)||t<1||t>me)throw Error("Invalid SVN runtime deadline");if(typeof e!="function")throw Error("Local identity resolver required");let n=!1,a=()=>{if(n)throw new DOMException("SVN runtime disposed","AbortError")},i=new Map,p=u=>{for(let d of i.get(u)||[])d.controller.abort(new DOMException("SVN consent revoked","AbortError"))},f=Q({now:r}),c=Q({now:r,onRevoke:u=>p(u)}),l=typeof o=="function",m=()=>{if(!l)throw Error("SVN remote transport disabled")},g=async(u,d)=>{a(),d?.throwIfAborted();let h=await e(u,d);return a(),d?.throwIfAborted(),{...h,sessionId:u.sessionId,cwd:h.cwd,repositoryId:u.repositoryId}},y=u=>u.revision===void 0?{}:(w(u.revision),{snapshot:u.revision}),S=async(u,d,h)=>{let v=await g(u,h);return c.assert(d,v),v},A=async(u,d,h)=>{h?.throwIfAborted(),c.assert(d,await g(u,h))},k=async(u,d)=>{a(),M(u,d.identity),d.signal?.throwIfAborted(),c.assert(d.token,d.identity);let h=new AbortController,v=()=>h.abort(d.signal.reason);d.signal?.addEventListener("abort",v,{once:!0});let b={controller:h,sessionId:d.identity.sessionId};i.has(d.token)||i.set(d.token,new Set),i.get(d.token).add(b);let D=setTimeout(()=>h.abort(new DOMException("SVN transport deadline exceeded","TimeoutError")),t);try{let E=async()=>{h.signal.throwIfAborted();let N=await g({sessionId:d.identity.sessionId,repositoryId:d.identity.repositoryId},h.signal);c.assert(d.token,N),h.signal.throwIfAborted()},V=await o(u,{...d,timeoutMs:t,signal:h.signal,assertAuthorized:E});return h.signal.throwIfAborted(),ze(V,u,d.maxBytes)}catch(E){throw h.signal.aborted?h.signal.reason:E}finally{let E=i.get(d.token);E?.delete(b),E?.size||i.delete(d.token),clearTimeout(D),d.signal?.removeEventListener("abort",v)}},I={async describe(u,{signal:d}={}){let h=await g(u,d),v=y(h),b=f.grant(h,{explicit:!0});return{...v,offer:b,root:h.root,uuid:h.uuid,scope:h.scope,origin:new URL(h.root).origin,expiresAt:r()+ve,remoteEnabled:l}},async approve(u,{offer:d,explicit:h=!1,signal:v}={}){if(h!==!0)throw Error("Explicit SVN network consent required");let b=await g(u,v);f.assert(d,b),m();let D=y(b),E=c.grant(b,{explicit:!0});return f.revoke(d),{...D,token:E,expiresAt:r()+ve}},async log(u,{token:d,snapshot:h,cursor:v,limit:b,path:D,signal:E}={}){let V=await S(u,d,E);m();let N=$({...V,snapshot:h,cursor:v,limit:b,path:D});E?.throwIfAborted();let x=await k(N,Y(V,d,E));return await A(u,d,E),(s==="dav"?pe:le)(x,N)},async detail(u,{token:d,snapshot:h,revision:v,signal:b}={}){let D=await S(u,d,b);m();let E=F({...D,snapshot:h,revision:v}),V=await k(E,Y(D,d,b));await A(u,d,b);let N=s==="dav"?{...ce(V,E),pathsAvailable:!0}:fe(V,E);return{...N,snapshot:h,changes:N.changes.map(x=>({...x,id:Ye(D,h,v,x)}))}},async compare(u,{token:d,snapshot:h,revision:v,id:b,signal:D}={}){ee(b);let E=await I.detail(u,{token:d,snapshot:h,revision:v,signal:D}),V=re(E,b);if(!V)throw Error("SVN change is not selected revision member");let N=await S(u,d,D),x=ie(E.changes.map(({id:T,..._})=>_),{scope:N.scope,revision:v,path:V.path}),P=async T=>{if(T.empty)return{label:"empty",text:"",absent:!0};let _=await S(u,d,D),U=O(_.root,T.path,T.pegRevision),X=Y(_,d,D),Te=await k({args:["proplist","--xml","--non-interactive","--no-auth-cache","-r",T.revision,"--",U]},X);if(await A(u,d,D),he(Te,{target:we(U),allowEmpty:!0}).special)throw Error("SVN special files cannot be compared");let G=await k({args:["cat","--non-interactive","--no-auth-cache","-r",T.revision,"--",U]},X);await A(u,d,D);let J=Buffer.isBuffer(G)?G:Buffer.from(G);if(J.length>ye)throw Error("SVN text exceeds 2 MiB");if(J.includes(0))return{label:"r"+T.revision,text:"",binary:!0};let se;try{se=new TextDecoder("utf-8",{fatal:!0}).decode(J)}catch{return{label:"r"+T.revision,text:"",binary:!0}}return{label:"r"+T.revision,text:se}},K=async T=>{let _=await S(u,d,D),U=O(_.root,T.path,T.pegRevision),X=await k({args:["info","--xml","--non-interactive","--no-auth-cache","-r",T.revision,"--",U]},Y(_,d,D));return await A(u,d,D),de(X,{target:we(U),revision:T.revision,root:_.root,uuid:_.uuid})},B=x.left;V.action==="R"&&!B.empty&&await K(B)==="dir"&&(B={empty:!0});let oe=await P(B),ne=await P(x.right);return{path:V.path,revision:v,snapshot:h,left:oe,right:ne,binary:!!(oe.binary||ne.binary)}},async trace(u,{token:d,snapshot:h,revision:v,id:b,cursor:D,limit:E=ge,signal:V}={}){ee(b);let N=await I.detail(u,{token:d,snapshot:h,revision:v,signal:V}),x=re(N,b,"file");if(!x)throw Error("SVN tracing requires selected file member");let P=x.action==="D"?q(v):v;return{...await I.log(u,{token:d,snapshot:P,cursor:D??P,limit:E,path:x.path,signal:V}),selectionSnapshot:h,selectionRevision:v,path:x.path,pegRevision:P,stopOnCopy:!0,copySourceOutsideScope:!!x.copySourceOutsideScope}},async copytrace(u,{token:d,snapshot:h,revision:v,id:b,cursor:D,limit:E=ge,signal:V}={}){ee(b);let N=await I.detail(u,{token:d,snapshot:h,revision:v,signal:V}),x=re(N,b,"file");if(!x||x.copySourceOutsideScope||x.copyFromPath===void 0||x.copyFromRevision===void 0)throw Error("Selected file has no authorized copy source");let P=x.copyFromRevision;return{...await I.log(u,{token:d,snapshot:P,cursor:D??P,limit:E,path:x.copyFromPath,signal:V}),selectionSnapshot:h,selectionRevision:v,path:x.copyFromPath,pegRevision:P,sourceForPath:x.path,stopOnCopy:!0}},async revoke(u,{token:d,signal:h}={}){return await S(u,d,h),c.revoke(d),p(d),{revoked:!0}},dispose(){n=!0,f.clear(),c.clear();for(let u of i.keys())p(u)},revokeSession(u){f.revokeSession(u),c.revokeSession(u);for(let[d,h]of i)[...h].some(v=>v.sessionId===u)&&p(d)}};return I}var te=(e,o)=>({ok:!1,error:{code:e,message:o,details:{}}}),De={revoke:["token"],describe:[],approve:["offer","explicit"],log:["token","snapshot","cursor","limit"],detail:["token","snapshot","revision"],compare:["token","snapshot","revision","id"],trace:["token","snapshot","revision","id","cursor","limit"],copytrace:["token","snapshot","revision","id","cursor","limit"]};function Ke(e,o){if(!o||typeof o!="object"||Array.isArray(o))throw Error("Object payload required");if(Object.keys(o).some(r=>!["sessionId","repositoryId",...De[e]].includes(r)))throw Error("Unknown SVN request field");for(let r of["sessionId","repositoryId"])if(typeof o[r]!="string"||!o[r]||o[r].length>1024||o[r].includes("\0"))throw Error("Invalid SVN Session address");if(e==="approve"&&(o.explicit!==!0||typeof o.offer!="string"||!/^[a-f0-9]{64}$/.test(o.offer)))throw Error("Explicit scoped offer required");if(!["describe","approve"].includes(e)){if(typeof o.token!="string"||!/^[a-f0-9]{64}$/.test(o.token))throw Error("SVN consent token required");if(e!=="revoke"&&w(o.snapshot),o.revision!==void 0&&w(o.revision),["detail","compare","trace","copytrace"].includes(e)&&o.revision===void 0)throw Error("Selected SVN revision required");if(o.cursor!==void 0&&w(o.cursor),o.limit!==void 0&&(!Number.isInteger(o.limit)||o.limit<1||o.limit>100))throw Error("Invalid SVN page size");if(["compare","trace","copytrace"].includes(e)&&(typeof o.id!="string"||!/^[a-f0-9]{64}$/.test(o.id)))throw Error("Selected SVN change ID required")}}function be(e,{timeoutMs:o=15e3}={}){if(!Number.isInteger(o)||o<1||o>15e3)throw Error("Invalid SVN RPC deadline");let r=0;return async(t,s,n)=>{let a=t.startsWith("vcs/svn-")?t.slice(8):"";if(!Object.hasOwn(De,a))return te("vcs/not-found","Unknown SVN endpoint");if(a!=="revoke"&&r>=2)return te("vcs/busy","SVN history requests busy");a!=="revoke"&&r++;let i=new AbortController,p=()=>i.abort(n.reason);n?.addEventListener("abort",p,{once:!0}),n?.aborted&&p();let f=setTimeout(()=>i.abort(new DOMException("SVN operation deadline exceeded","TimeoutError")),o);try{n?.throwIfAborted(),Ke(a,s);let{sessionId:c,repositoryId:l,...m}=s,g=await e[a]({sessionId:c,repositoryId:l},{...m,signal:i.signal});return i.signal.throwIfAborted(),{ok:!0,value:g}}catch(c){let l=n?.aborted||c?.name==="AbortError"?"vcs/cancelled":["vcs/rediscover-required","vcs/svn-consent-required"].includes(c?.code)?c.code:"vcs/operation-failed",m=i.signal.aborted?i.signal.reason:c,g=m instanceof Error?m.message:String(m);return te(l,g)}finally{clearTimeout(f),n?.removeEventListener("abort",p),a!=="revoke"&&r--}}}var Je=new Set(["describe","approve","log","detail","compare","trace","copytrace","revoke"]);function Ee(e,o,{transport:r,transportFormat:t="cli",now:s=Date.now,timeoutMs:n=15e3}={}){let a,i=Ge(e,o,4,{now:s,bindSvnIdentityResolver:c=>{a=c}}),p=Se({resolveIdentity:a,transport:r,transportFormat:t,now:s,timeoutMs:n}),f=be(p,{timeoutMs:n});return{handle(c,l,m){let g=c.startsWith("vcs/svn-")?c.slice(8):"";return Je.has(g)?f(c,l,m):i(c,l,m)},revokeSession:c=>p.revokeSession(c),dispose:()=>p.dispose()}}import{request as Ze}from"node:https";function Ae({request:e=Ze}={}){return async(o,{origin:r,method:t="GET",body:s="",depth:n,label:a,signal:i,maxBytes:p=2097152,timeoutMs:f=15e3}={})=>{let c=new URL(o);if(c.protocol!=="https:"||c.origin!==r||c.username||c.password||c.hash||c.href!==o||!["GET","PROPFIND","REPORT"].includes(t)||typeof s!="string"||Buffer.byteLength(s)>65536||!Number.isInteger(p)||p<1||p>2097152||!Number.isInteger(f)||f<1||f>15e3)throw Error("Invalid bounded HTTPS request");if(n!==void 0&&(t!=="PROPFIND"||n!==0))throw Error("Invalid DAV depth");if(a!==void 0){if(t!=="PROPFIND"||n!==0)throw Error("Invalid DAV label");w(a)}let l={...n===0?{Depth:"0"}:{},...a!==void 0?{Label:a}:{}};return i?.throwIfAborted(),new Promise((m,g)=>{let y,S,A=null,k=null,I=0,u=[],d=D=>{A??=D,S?.destroy(),y?.destroy()},h=()=>d(i.reason??new DOMException("HTTPS cancelled","AbortError")),v=setTimeout(()=>d(new DOMException("HTTPS deadline exceeded","TimeoutError")),f),b=()=>{clearTimeout(v),i?.removeEventListener("abort",h)};try{y=e(c,{method:t,agent:!1,rejectUnauthorized:!0,maxHeaderSize:16384,headers:{...l,"Accept-Encoding":"identity","Content-Type":"text/xml; charset=utf-8","Content-Length":String(Buffer.byteLength(s))}},D=>{S=D;let E=S.statusCode??0;if(E>=300&&E<400){d(Error("HTTPS redirects forbidden"));return}if(E<200||E>=300){d(Error("HTTPS status "+E));return}if(S.headers["content-encoding"]&&S.headers["content-encoding"]!=="identity"){d(Error("HTTPS compressed responses forbidden"));return}let V=S.headers["content-length"];if(V!==void 0&&(!/^[0-9]+$/.test(V)||Number(V)>p)){d(Error("HTTPS response exceeds byte limit"));return}S.on("data",N=>{I+=N.length,I>p?d(Error("HTTPS response exceeds byte limit")):A||u.push(N)}),S.on("error",d),S.on("end",()=>{if(!S.complete){d(Error("HTTPS response incomplete"));return}k=Buffer.concat(u)})}),y.on("error",D=>{A??=D}),y.once("close",()=>{b(),A?g(A):k!==null?m(k):g(Error("HTTPS response closed before completion"))}),i?.addEventListener("abort",h,{once:!0}),i?.aborted?h():y.end(s)}catch(D){b(),y?.destroy(),g(D)}})}}var Qe=e=>e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'");function Ve(e,o){let r=M(e,o),t=r.args;if(t[0]!=="log")throw Error("DAV log report requires readonly log plan");let s=t.includes("--verbose"),n=t[s?9:8].split(":"),a=t[s?7:6],i=r.path==="/"?"":r.path.slice(1),p='<?xml version="1.0" encoding="utf-8"?><S:log-report xmlns:S="svn:" xmlns:D="DAV:"><S:start-revision>'+n[0]+"</S:start-revision><S:end-revision>"+n[1]+"</S:end-revision><S:limit>"+a+"</S:limit><S:strict-node-history/>"+(s?"<S:discover-changed-paths/>":"")+"<S:path>"+Qe(i)+"</S:path><S:revprop>svn:author</S:revprop><S:revprop>svn:date</S:revprop><S:revprop>svn:log</S:revprop></S:log-report>";if(Buffer.byteLength(p)>65536)throw Error("DAV request body exceeds limit");return{method:"REPORT",body:p,pegRevision:r.pegRevision,path:r.path,requiresVerifiedBaseline:!0}}function xe(e,{root:o,uuid:r,target:t}={}){let s=L(e),n=(l,m)=>{if(!l||typeof l!="object"||Array.isArray(l)||Object.keys(l).some(g=>!m.includes(g)&&!(g==="#text"&&typeof l[g]=="string"&&l[g].trim()==="")))throw Error("Unsupported DAV discovery structure")};n(s,["?xml","D:multistatus"]);let a=s["D:multistatus"];if(n(a,["D:response"]),!Array.isArray(a["D:response"])||a["D:response"].length!==1)throw Error("DAV discovery requires one response");let i=a["D:response"][0];if(n(i,["D:href","D:propstat"]),R(i["D:href"],{root:o})!==t)throw Error("DAV response target mismatch");if(!Array.isArray(i["D:propstat"])||i["D:propstat"].length!==1)throw Error("DAV discovery requires one property status");let p=i["D:propstat"][0];if(n(p,["D:prop","D:status"]),!/^HTTP[/]1[.][01] 200(?: OK)?$/.test(p["D:status"]))throw Error("DAV discovery properties unavailable");let f=p["D:prop"];if(n(f,["S:repository-uuid","D:version-controlled-configuration"]),f["S:repository-uuid"]!==r||typeof r!="string"||!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(r))throw Error("DAV UUID does not match local identity");let c=f["D:version-controlled-configuration"];return n(c,["D:href"]),{uuid:r,vcc:R(c["D:href"],{root:o}),target:t}}function Ie(e,{root:o,revision:r}={}){w(r);let t=L(e),s=(l,m)=>{if(!l||typeof l!="object"||Array.isArray(l)||Object.keys(l).some(g=>!m.includes(g)))throw Error("Invalid DAV baseline structure")};s(t,["D:multistatus"]);let n=t["D:multistatus"];if(s(n,["D:response"]),n["D:response"]?.length!==1)throw Error("One DAV baseline response required");let a=n["D:response"][0];s(a,["D:href","D:propstat"]);let i=R(a["D:href"],{root:o});if(a["D:propstat"]?.length!==1)throw Error("One DAV baseline status required");let p=a["D:propstat"][0];if(s(p,["D:status","D:prop"]),p["D:status"]!=="HTTP/1.1 200 OK")throw Error("DAV baseline status unavailable");let f=p["D:prop"];if(s(f,["D:version-name","D:baseline-collection"]),f["D:version-name"]!==r)throw Error("DAV baseline revision mismatch");s(f["D:baseline-collection"],["D:href"]);let c=R(f["D:baseline-collection"]["D:href"],{root:o});if(!c.endsWith("/"))throw Error("DAV baseline collection must end in slash");return{revision:r,baseline:i,collection:c}}function Ne({request:e,assertAuthorized:o}={}){if(typeof e!="function"||typeof o!="function")throw Error("DAV chain requires transport and authorization");return async(r,{revision:t,signal:s}={})=>{w(t),O(r.root,r.scope,t);let n=r.root,a=new URL(n).origin,i=n.endsWith("/")?n:n+"/",p=async(m,g)=>{s?.throwIfAborted(),await o(r,{signal:s}),s?.throwIfAborted();let y=await e(m,{origin:a,signal:s,...g});if(s?.throwIfAborted(),await o(r,{signal:s}),s?.throwIfAborted(),!Buffer.isBuffer(y)||y.length>2097152)throw Error("Invalid DAV response bytes");return new TextDecoder("utf-8",{fatal:!0}).decode(y)},f=await p(i,{method:"PROPFIND",depth:0,body:'<D:propfind xmlns:D="DAV:" xmlns:S="http://subversion.tigris.org/xmlns/dav/"><D:prop><S:repository-uuid/><D:version-controlled-configuration/></D:prop></D:propfind>'}),{vcc:c}=xe(f,{root:n,target:i,uuid:r.uuid}),l=await p(c,{method:"PROPFIND",depth:0,label:t,body:'<D:propfind xmlns:D="DAV:"><D:prop><D:baseline-collection/><D:version-name/></D:prop></D:propfind>'});return{...Ie(l,{root:n,revision:t}),uuid:r.uuid}}}function ke(e,{root:o,target:r}={}){let t=L(e),s=(c,l)=>{if(!c||typeof c!="object"||Array.isArray(c)||Object.keys(c).some(m=>!l.includes(m)))throw Error("Invalid DAV property names structure")};s(t,["D:multistatus"]);let n=t["D:multistatus"];if(s(n,["D:response"]),n["D:response"]?.length!==1)throw Error("One DAV property response required");let a=n["D:response"][0];if(s(a,["D:href","D:propstat"]),R(a["D:href"],{root:o})!==r)throw Error("DAV property target mismatch");if(a["D:propstat"]?.length!==1)throw Error("One DAV property status required");let i=a["D:propstat"][0];if(s(i,["D:status","D:prop"]),i["D:status"]!=="HTTP/1.1 200 OK")throw Error("DAV property names unavailable");let p=i["D:prop"];if(p!==""&&(!p||typeof p!="object"||Array.isArray(p)||Object.keys(p).length>1e3||Object.entries(p).some(([c,l])=>!/^[DSPC]:[^:]+$/.test(c)||l!=="")))throw Error("DAV property names must be empty");let f=p===""?[]:Object.keys(p);return{names:f,special:f.includes("P:special")}}var z=e=>e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""");function Oe({request:e}={}){if(typeof e!="function")throw Error("Bounded DAV request required");return async(o,{identity:r,assertAuthorized:t,signal:s}={})=>{let n=M(o,r),a=n.args[0],i=Ne({request:e,assertAuthorized:t}),p=await i(r,{revision:n.pegRevision,signal:s}),f=async(y,S)=>{s?.throwIfAborted(),await t(),s?.throwIfAborted();let A=await e(y,{origin:new URL(r.root).origin,...S,signal:s});if(s?.throwIfAborted(),await t(),s?.throwIfAborted(),!Buffer.isBuffer(A)||A.length>2097152)throw Error("Invalid DAV transport bytes");return A};if(a==="log"){let y=Ve(o,r);return f(p.collection,{method:"REPORT",body:y.body})}let c=n.path.slice(1).split("/").map(y=>encodeURIComponent(y).replace(/[!'()*]/g,S=>"%"+S.charCodeAt(0).toString(16).toUpperCase())).join("/"),l=R(p.collection+c,{root:r.root});if(a==="info"){let y=await f(l,{method:"PROPFIND",depth:0,body:'<D:propfind xmlns:D="DAV:"><D:prop><D:resourcetype/></D:prop></D:propfind>'}),S=ue(new TextDecoder("utf-8",{fatal:!0}).decode(y),{root:r.root,target:l}),A=n.args.at(-1).slice(0,n.args.at(-1).lastIndexOf("@"));return'<info><entry kind="'+S+'" revision="'+n.pegRevision+'"><url>'+z(A)+"</url><repository><root>"+z(r.root)+"</root><uuid>"+z(r.uuid)+"</uuid></repository></entry></info>"}let m=await f(l,{method:"PROPFIND",depth:0,body:'<D:propfind xmlns:D="DAV:"><D:propname/></D:propfind>'}),g=ke(new TextDecoder("utf-8",{fatal:!0}).decode(m),{root:r.root,target:l});if(a==="proplist")return'<properties><target path="'+z(n.args.at(-1).slice(0,n.args.at(-1).lastIndexOf("@")))+'">'+(g.special?'<property name="svn:special"/>':"")+"</target></properties>";if(g.special)throw Error("SVN special content forbidden");return f(l,{method:"GET"})}}function Ft(e,o){return Ee(e,o,{transportFormat:"dav",transport:Oe({request:Ae()})})}export{Ft as createSvnHttpsHost};
|
package/git-history.mjs
CHANGED
|
@@ -10,6 +10,11 @@ export function validateDateBound(value){
|
|
|
10
10
|
if(month<1||month>12||day<1||day>dim[month-1])throw new Error('Invalid history date bound');
|
|
11
11
|
return value;
|
|
12
12
|
}
|
|
13
|
+
/** Full Git object id: lowercase SHA-1 (40) or SHA-256 (64) hexadecimal. */
|
|
14
|
+
export const isObjectId = value => /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(value);
|
|
15
|
+
/** Opaque SHA-256 change id used by this plugin's read-only change selections. */
|
|
16
|
+
export const isChangeId = value => /^[a-f0-9]{64}$/.test(value);
|
|
17
|
+
|
|
13
18
|
export function historySearchArgs(search) {
|
|
14
19
|
if (search === undefined) return {args: [], paths: []};
|
|
15
20
|
const keys = ['message', 'author', 'path', 'since', 'until'];
|
|
@@ -105,7 +110,7 @@ export function parseReferences(text){
|
|
|
105
110
|
|
|
106
111
|
// Format for: git log -z --format=<HISTORY_FORMAT>. NUL separates fields/records.
|
|
107
112
|
export const HISTORY_FORMAT = '%H%x00%P%x00%an%x00%aI%x00%s';
|
|
108
|
-
const oid =
|
|
113
|
+
const oid = isObjectId;
|
|
109
114
|
export function historyPage(rows,snapshot,offset,limit){
|
|
110
115
|
const hasMore=rows.length>limit;
|
|
111
116
|
const truncated=hasMore&&offset+limit>10000;
|