@warmhub/sdk-ts 0.161.0 → 0.162.0

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/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  <!-- warmhub-changelog-artifact:v1 -->
4
4
 
5
+ ## 0.162.0
6
+
7
+ No new release notes.
8
+
5
9
  ## 0.161.0
6
10
 
7
11
  No new release notes.
package/changelog.json CHANGED
@@ -310,6 +310,11 @@
310
310
  "version": "0.161.0",
311
311
  "sourceSha": "d3f58daba8c0969416481148a4e3a9191d95cdc5",
312
312
  "notes": []
313
+ },
314
+ {
315
+ "version": "0.162.0",
316
+ "sourceSha": "ed4968f8add6a8a0bf7e70ce1a5c894d73afdfe4",
317
+ "notes": []
313
318
  }
314
319
  ]
315
320
  }
@@ -1,2 +1,2 @@
1
- import {ka,ha,la,pa,fa,ma,na,oa,ga}from'./chunk-RVSU4CXH.js';import {mkdtemp,chmod,rm,open}from'fs/promises';import {tmpdir}from'os';import {join}from'path';import {createHash}from'crypto';import {Writable}from'stream';import {pipeline}from'stream/promises';import {callbackify}from'util';import {createInflateRaw,crc32}from'zlib';import {once}from'events';import {createWriteStream,createReadStream}from'fs';var d=class extends Error{constructor(e){super(rt(e));this.reason=e;}reason;name="RepositoryCheckpointVerificationError"};function rt(r){switch(r){case "source_failed":return "Repository checkpoint source could not be read";case "archive_invalid":return "Repository checkpoint archive is invalid";case "archive_integrity_mismatch":return "Repository checkpoint archive integrity does not match";case "manifest_invalid":return "Repository checkpoint manifest is invalid";case "chunk_invalid":return "Repository checkpoint chunk is invalid";case "duplicate_durable_id":return "Repository checkpoint contains a duplicate durable identity";case "scratch_cleanup_failed":return "Repository checkpoint verifier scratch cleanup failed"}}var H=67324752,ht=33639248,dt=134695760,ut=101075792,ft=117853008,lt=101010256,Y=2056,Z=8,R=45,q=813,z=65535,m=4294967295,W=33,yt=33188,S=64*1024,pt=new RegExp(`^records/[0-9a-f]{64}/part-\\d{${ga}}\\.jsonl$`),mt=new TextDecoder("utf-8",{fatal:true}),E=class extends Error{};async function G(r,t){let e=new C(r);try{let i=[],n=new Set,s=!1;for(;await e.peekU32()===H;){if(s)throw new Error("manifest must be the final entry");let c=BigInt(e.position),h=await e.readExact(30);bt(h);let f=h.readUInt16LE(26),p=h.readUInt16LE(28);if(f===0||p!==20)throw new Error("local entry metadata is invalid");let a=K(await e.readExact(f));if(St(a),n.has(a))throw new Error("archive entry is duplicated");n.add(a),s=a===ha,It(await e.readExact(p));let y=t(a),l=await wt(e,y),et=await e.readExact(24);kt(et,l),await y.finish(),i.push({name:a,localOffset:c,...l});}if(!s||i.length===0)throw new Error("archive manifest entry is missing");return await vt(e,i),{...await e.finish(),entryNames:i.map(c=>c.name)}}finally{await e.close();}}async function wt(r,t){let e=createInflateRaw({chunkSize:S}),i=0n,n=0n,s=0,o=callbackify(async a=>{try{await t.write(a);}catch(y){throw y instanceof Error?y:new Error("checkpoint sink failed")}s=crc32(a,s),n+=BigInt(a.byteLength);}),c=new Writable({highWaterMark:S,write(a,y,l){o(a,l);}}),h=pipeline(e,c),f=new A,p=Et(h,f);try{for(;!e.readableEnded;){let a=await r.readSome(S);if(!a)throw new Error("archive entry is truncated");let y=e.bytesWritten;await gt(e,a,f);let l=e.bytesWritten-y;if(!Number.isSafeInteger(l)||l<0||l>a.byteLength)throw new Error("archive inflater consumed invalid input");if(i+=BigInt(l),l<a.byteLength&&r.unread(a.subarray(l)),e.readableEnded)break;if(l===0)throw new Error("archive inflater made no progress")}return await h,{crc:s>>>0,compressedSize:i,uncompressedSize:n}}finally{e.destroyed||e.destroy(),await p;}}var A=class{#i;#t;fail(t){let e=t instanceof Error?t:new Error("archive inflater failed");this.#i=e,this.#t?.(e),this.#t=void 0;}async race(t){if(this.#i)throw this.#i;let e,i=new Promise((n,s)=>{e=o=>s(o),this.#t=e;});try{return await Promise.race([t,i])}finally{e&&this.#t===e&&(this.#t=void 0);}}};async function Et(r,t){try{await r;}catch(e){t.fail(e);}}async function gt(r,t,e){let i=new Promise((n,s)=>{r.write(t,o=>{o?s(o):n();});});await e.race(i);}async function vt(r,t){let e=BigInt(r.position);for(let h of t){let f=await r.readExact(46);Ut(f,h);let p=f.readUInt16LE(28),a=f.readUInt16LE(30);if(a!==28||f.readUInt16LE(32)!==0)throw new Error("central entry metadata is invalid");if(K(await r.readExact(p))!==h.name)throw new Error("central entry order differs");Lt(await r.readExact(a),h);}let i=BigInt(r.position)-e,n=BigInt(r.position),s=await r.readExact(56);if(w(s,0,ut),s.readBigUInt64LE(4)!==44n||s.readUInt16LE(12)!==q||s.readUInt16LE(14)!==R||s.readUInt32LE(16)!==0||s.readUInt32LE(20)!==0||s.readBigUInt64LE(24)!==BigInt(t.length)||s.readBigUInt64LE(32)!==BigInt(t.length)||s.readBigUInt64LE(40)!==i||s.readBigUInt64LE(48)!==e)throw new Error("ZIP64 end record is invalid");let o=await r.readExact(20);if(w(o,0,ft),o.readUInt32LE(4)!==0||o.readBigUInt64LE(8)!==n||o.readUInt32LE(16)!==1)throw new Error("ZIP64 locator is invalid");let c=await r.readExact(22);if(w(c,0,lt),c.readUInt16LE(4)!==0||c.readUInt16LE(6)!==0||c.readUInt16LE(8)!==z||c.readUInt16LE(10)!==z||c.readUInt32LE(12)!==m||c.readUInt32LE(16)!==m||c.readUInt16LE(20)!==0)throw new Error("classic ZIP end record is invalid")}function bt(r){if(w(r,0,H),r.readUInt16LE(4)!==R||r.readUInt16LE(6)!==Y||r.readUInt16LE(8)!==Z||r.readUInt16LE(10)!==0||r.readUInt16LE(12)!==W||r.readUInt32LE(14)!==0||r.readUInt32LE(18)!==m||r.readUInt32LE(22)!==m)throw new Error("local entry header is invalid")}function It(r){if(r.readUInt16LE(0)!==1||r.readUInt16LE(2)!==16||r.readBigUInt64LE(4)!==0n||r.readBigUInt64LE(12)!==0n)throw new Error("local ZIP64 extra is invalid")}function kt(r,t){if(w(r,0,dt),r.readUInt32LE(4)!==t.crc||r.readBigUInt64LE(8)!==t.compressedSize||r.readBigUInt64LE(16)!==t.uncompressedSize)throw new Error("archive data descriptor is invalid")}function Ut(r,t){if(w(r,0,ht),r.readUInt16LE(4)!==q||r.readUInt16LE(6)!==R||r.readUInt16LE(8)!==Y||r.readUInt16LE(10)!==Z||r.readUInt16LE(12)!==0||r.readUInt16LE(14)!==W||r.readUInt32LE(16)!==t.crc||r.readUInt32LE(20)!==m||r.readUInt32LE(24)!==m||r.readUInt16LE(34)!==0||r.readUInt16LE(36)!==0||(r.readUInt32LE(38)>>>16&65535)!==yt||r.readUInt32LE(42)!==m)throw new Error("central entry header is invalid")}function Lt(r,t){if(r.readUInt16LE(0)!==1||r.readUInt16LE(2)!==24||r.readBigUInt64LE(4)!==t.uncompressedSize||r.readBigUInt64LE(12)!==t.compressedSize||r.readBigUInt64LE(20)!==t.localOffset)throw new Error("central ZIP64 extra is invalid")}function St(r){if(r!==ha&&!pt.test(r))throw new Error("archive entry name is invalid")}function K(r){let t=mt.decode(r);if(Buffer.byteLength(t,"utf8")!==r.byteLength)throw new Error("archive entry name is not canonical UTF-8");return t}function w(r,t,e){if(r.readUInt32LE(t)!==e)throw new Error("archive signature is invalid")}var C=class{#i;#t=createHash("sha256");#e=[];#r=0;#n=false;#o=0;position=0;constructor(t){this.#i=At(t)[Symbol.asyncIterator]();}async peekU32(){let t=await this.readExact(4);return this.unread(t),t.readUInt32LE(0)}async readExact(t){let e=Buffer.allocUnsafe(t),i=0;for(;i<t;){let n=await this.readSome(t-i);if(!n)throw new Error("archive is truncated");e.set(n,i),i+=n.byteLength;}return e}async readSome(t){for(;this.#e.length===0;)if(!await this.#s())return;let e=this.#e[0];if(!e)return;let i=e.byteLength-this.#r,n=Math.min(t,i),s=e.subarray(this.#r,this.#r+n);return this.#r+=n,this.position+=n,this.#r===e.byteLength&&(this.#e.shift(),this.#r=0),s}unread(t){if(t.byteLength!==0){if(this.#r>0){let e=this.#e[0];if(!e)throw new Error("archive reader queue is inconsistent");let i=e.subarray(this.#r);this.#e[0]=i,this.#r=0;}this.#e.unshift(t),this.position-=t.byteLength;}}async finish(){if(this.#e.length>0||await this.#s())throw new Error("archive contains trailing bytes");return {byteLength:this.#o,sha256:this.#t.digest("hex")}}async close(){try{await this.#i.return?.();}catch{}}async#s(){if(this.#n)return false;for(;;){let t;try{t=await this.#i.next();}catch{throw new E}if(t.done)return this.#n=true,false;if(!(t.value instanceof Uint8Array))throw new E;if(t.value.byteLength!==0){if(this.#t.update(t.value),this.#o+=t.value.byteLength,!Number.isSafeInteger(this.#o))throw new Error("archive byte length is unsafe");return this.#e.push(t.value),true}}}};function At(r){if(Symbol.asyncIterator in r)return r;let t=r;return {async*[Symbol.asyncIterator](){let e=t.getReader(),i=false;try{for(;;){let{value:n,done:s}=await e.read();if(s){i=!0;return}yield n;}}finally{if(!i)try{await e.cancel();}catch{}e.releaseLock();}}}}var xt=4*1024*1024,j=8,J=64*1024,Tt=16*1024,u=4,$=4,Ot=1,Vt=u+Ot,X=Vt+$,g=class extends Error{},k=class{#i;#t;#e=[];#r=0;#n;constructor(t,e={}){this.#i=t;let i=e.sortBudgetBytes??xt;if(this.#n=e.mergeFanIn??j,!Number.isSafeInteger(i)||i<X||!Number.isSafeInteger(this.#n)||this.#n<2||this.#n>j)throw new Error("checkpoint identity sort limits are invalid");this.#t=new _(i);}add(t){let e=Buffer.byteLength(t,"utf8");if(!this.#t.canFit(e))throw new Error("checkpoint durable identity exceeds the sort budget");if(this.#t.canAdd(e)){this.#t.add(t,e);return}return this.#o(t,e)}async finish(){if(this.#e.length===0){this.#t.sortAndAssertUnique(),this.#t.clear();return}for(this.#t.isEmpty||await this.#o();this.#e.length>this.#n;){let e=[];for(let i=0;i<this.#e.length;i+=this.#n){let n=this.#e.slice(i,i+this.#n),s=this.#s();await Ft(n,s),await Promise.all(n.map(o=>rm(o,{force:true}))),e.push(s);}this.#e=e;}let t;await tt(this.#e,e=>{if(t&&P(t,e)===0)throw new g;t=e;});}async#o(t,e){let i=this.#s();this.#t.sortAndAssertUnique(),await Mt(i,this.#t),this.#e.push(i),this.#t.clear(),t!==void 0&&e!==void 0&&this.#t.add(t,e);}#s(){let t=join(this.#i,`identity-run-${String(this.#r).padStart(8,"0")}.bin`);return this.#r+=1,t}},_=class{byteBudget;#i;#t;#e=0;#r=0;constructor(t){this.byteBudget=t;let e=Math.floor(t/X);this.#t=new Uint32Array(e),this.#i=Buffer.allocUnsafe(t-e*$);}get isEmpty(){return this.#r===0}canAdd(t){return this.canFit(t)&&this.#r<this.#t.length&&this.#e+u+t<=this.#i.length}canFit(t){return t<=4294967295&&this.#t.length>0&&u+t<=this.#i.length}add(t,e){if(!this.canAdd(e))throw new Error("checkpoint durable identity exceeds the sort budget");let i=this.#e;this.#t[this.#r]=i,this.#i.writeUInt32BE(e,i),this.#i.write(t,i+u,e,"utf8"),this.#e+=u+e,this.#r+=1;}sortAndAssertUnique(){let t=this.#t.subarray(0,this.#r);t.sort((e,i)=>this.#n(e,i));for(let e=1;e<t.length;e+=1){let i=t[e-1],n=t[e];if(i===void 0||n===void 0)throw new Error("checkpoint identity offset is missing");if(this.#n(i,n)===0)throw new g}}clear(){this.#e=0,this.#r=0;}forEachSorted(t){return Dt(this.#t.subarray(0,this.#r),e=>t(this.#s(e)))}#n(t,e){return P(this.#o(t),this.#o(e))}#o(t){let e=this.#i.readUInt32BE(t);return this.#i.subarray(t+u,t+u+e)}#s(t){let e=this.#i.readUInt32BE(t);return this.#i.subarray(t,t+u+e)}};async function Mt(r,t){await Q(r,async e=>{let i=new U(e);await t.forEachSorted(n=>i.write(n)),await i.finish();});}async function Ft(r,t){await Q(t,async e=>{let i=new U(e);await tt(r,n=>i.writeValue(n)),await i.finish();});}async function Q(r,t){await(await open(r,"wx",384)).close();let i=createWriteStream(r,{flags:"a",mode:384,highWaterMark:J});try{await t(i),i.end(),await once(i,"close");}catch(n){throw i.destroy(),n}}var U=class{#i;#t=Buffer.allocUnsafe(J);#e=0;constructor(t){this.#i=t;}write(t){if(t.byteLength>this.#t.length)return this.#r(t);if(this.#e+t.byteLength>this.#t.length)return this.#n(t);this.#t.set(t,this.#e),this.#e+=t.byteLength;}writeValue(t){let e=u+t.byteLength;if(e>this.#t.length)return this.#o(t);if(this.#e+e>this.#t.length)return this.#s(t);this.#c(t);}async finish(){await this.#a();}async#r(t){await this.#a(),await I(this.#i,t);}async#n(t){await this.#a(),this.#t.set(t,this.#e),this.#e+=t.byteLength;}async#o(t){await this.#a();let e=Buffer.allocUnsafe(u);e.writeUInt32BE(t.byteLength,0),await I(this.#i,e),await I(this.#i,t);}async#s(t){await this.#a(),this.#c(t);}async#a(){if(this.#e===0)return;let t=this.#t.subarray(0,this.#e);await I(this.#i,t),this.#e=0;}#c(t){this.#t.writeUInt32BE(t.byteLength,this.#e),this.#t.set(t,this.#e+u),this.#e+=u+t.byteLength;}};async function tt(r,t){let e=r.map(i=>new B(i));try{for(await Promise.all(e.map(i=>i.advance()));;){let i;for(let s of e)s.current&&(!i||P(s.current,i.current)<0)&&(i=s);if(!i?.current)return;let n=t(i.current);n&&await n,await i.advance();}}finally{for(let i of e)i.close();}}var B=class{#i;#t;#e=Buffer.alloc(0);#r=0;current;constructor(t){this.#i=createReadStream(t,{highWaterMark:Tt}),this.#t=this.#i[Symbol.asyncIterator]();}async advance(){let t=await this.#n(u);if(!t){this.current=void 0;return}let e=t.readUInt32BE(0);if(e===0)throw new Error("checkpoint identity run is invalid");let i=await this.#n(e);if(!i)throw new Error("checkpoint identity run is truncated");this.current=i;}close(){this.#i.destroy();}async#n(t){if(t===0)return Buffer.alloc(0);if(this.#e.length-this.#r>=t){let n=this.#e.subarray(this.#r,this.#r+t);return this.#r+=t,n}let e=Buffer.allocUnsafe(t),i=0;for(;i<t;){if(this.#r<this.#e.length){let s=Math.min(t-i,this.#e.length-this.#r);this.#e.copy(e,i,this.#r,this.#r+s),this.#r+=s,i+=s;continue}let n=await this.#t.next();if(n.done){if(i===0)return;throw new Error("checkpoint identity run is truncated")}this.#e=n.value,this.#r=0;}return e}};async function Dt(r,t){for(let e of r){let i=t(e);i&&await i;}}async function I(r,t){await new Promise((e,i)=>{r.write(t,n=>{n?i(n):e();});});}function P(r,t){let e=Math.min(r.length,t.length);for(let i=0;i<e;i+=1){let n=r[i],s=t[i];if(n===void 0||s===void 0)throw new Error("checkpoint identity byte is missing");let o=n-s;if(o!==0)return o}return r.length-t.length}var L=class{#i;#t=new Map;#e=new Map;#r=[];#n;constructor(t,e={}){this.#i=new k(t,{sortBudgetBytes:e.identitySortBudgetBytes,mergeFanIn:e.identityMergeFanIn});}openEntry(t){if(t===ha){let e=[];return {write:async i=>{e.push(i.slice());},finish:async()=>{this.#n=Buffer.concat(e);}}}return new N(t,this.#t,this.#e,this.#i,e=>this.#r.push(e))}async finish(){if(!this.#n)throw new Error("checkpoint manifest is missing");let t=await la(this.#n),e=t.streams.flatMap(i=>i.chunks.map(n=>({...n,shapeName:i.shapeName})));if(e.length!==this.#r.length)throw new Error("checkpoint chunk inventory does not match");for(let[i,n]of e.entries()){let s=this.#r[i];if(s.path!==n.path||s.shapeName!==n.shapeName||s.recordCount!==n.recordCount||s.byteLength!==n.byteLength||s.sha256!==n.sha256)throw new Error("checkpoint chunk integrity does not match")}for(let i of t.streams){let n=this.#t.get(i.shapeName);if(!n||pa(n)!==i.recordCount)throw new Error("checkpoint stream does not match its manifest")}if(this.#t.size!==t.streams.length)throw new Error("checkpoint contains an undeclared stream");return await this.#i.finish(),{manifest:t,chunkCount:e.length}}},N=class{#i;#t;#e;#r;#n;#o=createHash("sha256");#s=[];#a=0;#c;#h=0;#d=0;constructor(t,e,i,n,s){this.#i=t,this.#t=e,this.#e=i,this.#r=n,this.#n=s;}async write(t){if(this.#o.update(t),this.#d+=t.byteLength,!Number.isSafeInteger(this.#d))throw new Error("checkpoint chunk byte length is unsafe");let e=0;for(;e<t.byteLength;){let i=t.indexOf(10,e);if(i<0)break;let n=this.#u(this.#l(t.subarray(e,i+1)));n&&await n,e=i+1;}e<t.byteLength&&this.#f(t.subarray(e));}async finish(){if(this.#s.length!==0||this.#h===0||!this.#c)throw new Error("checkpoint chunk framing is invalid");if(this.#d>fa&&this.#h!==1)throw new Error("oversized checkpoint chunk has multiple rows");this.#n({path:this.#i,shapeName:this.#c,recordCount:this.#h,byteLength:this.#d,sha256:this.#o.digest("hex")});let t=this.#e.get(this.#c);if(!t)throw new Error("checkpoint stream chunk state is missing");t.previous={byteLength:this.#d};}#u(t){let e=ma(t),i=e.kind==="shape"?e.wref:e.shapeName;if(this.#c!==void 0&&this.#c!==i)throw new Error("checkpoint chunk mixes Shape streams");this.#c=i,this.#h===0&&this.#y(i,t.byteLength);let n=this.#t.get(i)??na(i);this.#t.set(i,n),oa(n,e);let s=this.#r.add(e.durableId);if(this.#h+=1,!Number.isSafeInteger(this.#h))throw new Error("checkpoint chunk row count is unsafe");return s}#f(t){if(t.byteLength!==0&&(this.#s.push(t.slice()),this.#a+=t.byteLength,!Number.isSafeInteger(this.#a)))throw new Error("checkpoint row byte length is unsafe")}#l(t){if(this.#s.length===0)return t;let e=Buffer.concat([...this.#s,t],this.#a+t.byteLength);return this.#s=[],this.#a=0,e}#y(t,e){let i=Number(this.#i.match(/part-(\d{10})\.jsonl$/)?.[1]??-1),n=this.#e.get(t)??{nextPart:0};if(i!==n.nextPart)throw new Error("checkpoint stream chunk parts are not contiguous");if(n.previous&&n.previous.byteLength<=fa&&n.previous.byteLength+e<=fa)throw new Error("checkpoint stream chunk closed before the byte limit");n.nextPart+=1,this.#e.set(t,n);}};async function Gt(r,t){return Kt(r,t)}async function Kt(r,t,e={}){let i=await mkdtemp(join(e.scratchParent??tmpdir(),"warmhub-checkpoint-verify-"));await chmod(i,448);let n,s;try{let o=new L(i,e),c=await G(r,p=>o.openEntry(p)),{manifest:h,chunkCount:f}=await o.finish();jt(t,c,h),n={valid:!0,checkpointId:h.checkpointId,repoSeq:h.repoSeq,recordCount:h.recordCount,chunkCount:f,totalBytes:c.byteLength,rootDigest:h.contentSha256,archiveDigest:c.sha256};}catch(o){s=Jt(o);}try{await rm(i,{recursive:!0,force:!0});}catch{s??=new d("scratch_cleanup_failed");}if(s)throw s;if(!n)throw new d("archive_invalid");return n}function jt(r,t,e){if(r&&(ka.parse(r.sha256),r.checkpointId!==e.checkpointId||r.repoSeq!==e.repoSeq||r.byteLength!==t.byteLength||r.sha256!==t.sha256))throw new d("archive_integrity_mismatch")}function Jt(r){if(r instanceof d)return r;if(r instanceof E)return new d("source_failed");if(r instanceof g)return new d("duplicate_durable_id");let t=r instanceof Error?r.message:"";return t.includes("manifest")?new d("manifest_invalid"):t.includes("chunk")||t.includes("row")||t.includes("Shape stream")?new d("chunk_invalid"):new d("archive_invalid")}export{d as RepositoryCheckpointVerificationError,Gt as verifyRepositoryCheckpointArchive};//# sourceMappingURL=checkpoint.js.map
1
+ import {ka,ha,la,pa,fa,ma,na,oa,ga}from'./chunk-BL6W7226.js';import {mkdtemp,chmod,rm,open}from'fs/promises';import {tmpdir}from'os';import {join}from'path';import {createHash}from'crypto';import {Writable}from'stream';import {pipeline}from'stream/promises';import {callbackify}from'util';import {createInflateRaw,crc32}from'zlib';import {once}from'events';import {createWriteStream,createReadStream}from'fs';var d=class extends Error{constructor(e){super(rt(e));this.reason=e;}reason;name="RepositoryCheckpointVerificationError"};function rt(r){switch(r){case "source_failed":return "Repository checkpoint source could not be read";case "archive_invalid":return "Repository checkpoint archive is invalid";case "archive_integrity_mismatch":return "Repository checkpoint archive integrity does not match";case "manifest_invalid":return "Repository checkpoint manifest is invalid";case "chunk_invalid":return "Repository checkpoint chunk is invalid";case "duplicate_durable_id":return "Repository checkpoint contains a duplicate durable identity";case "scratch_cleanup_failed":return "Repository checkpoint verifier scratch cleanup failed"}}var H=67324752,ht=33639248,dt=134695760,ut=101075792,ft=117853008,lt=101010256,Y=2056,Z=8,R=45,q=813,z=65535,m=4294967295,W=33,yt=33188,S=64*1024,pt=new RegExp(`^records/[0-9a-f]{64}/part-\\d{${ga}}\\.jsonl$`),mt=new TextDecoder("utf-8",{fatal:true}),E=class extends Error{};async function G(r,t){let e=new C(r);try{let i=[],n=new Set,s=!1;for(;await e.peekU32()===H;){if(s)throw new Error("manifest must be the final entry");let c=BigInt(e.position),h=await e.readExact(30);bt(h);let f=h.readUInt16LE(26),p=h.readUInt16LE(28);if(f===0||p!==20)throw new Error("local entry metadata is invalid");let a=K(await e.readExact(f));if(St(a),n.has(a))throw new Error("archive entry is duplicated");n.add(a),s=a===ha,It(await e.readExact(p));let y=t(a),l=await wt(e,y),et=await e.readExact(24);kt(et,l),await y.finish(),i.push({name:a,localOffset:c,...l});}if(!s||i.length===0)throw new Error("archive manifest entry is missing");return await vt(e,i),{...await e.finish(),entryNames:i.map(c=>c.name)}}finally{await e.close();}}async function wt(r,t){let e=createInflateRaw({chunkSize:S}),i=0n,n=0n,s=0,o=callbackify(async a=>{try{await t.write(a);}catch(y){throw y instanceof Error?y:new Error("checkpoint sink failed")}s=crc32(a,s),n+=BigInt(a.byteLength);}),c=new Writable({highWaterMark:S,write(a,y,l){o(a,l);}}),h=pipeline(e,c),f=new A,p=Et(h,f);try{for(;!e.readableEnded;){let a=await r.readSome(S);if(!a)throw new Error("archive entry is truncated");let y=e.bytesWritten;await gt(e,a,f);let l=e.bytesWritten-y;if(!Number.isSafeInteger(l)||l<0||l>a.byteLength)throw new Error("archive inflater consumed invalid input");if(i+=BigInt(l),l<a.byteLength&&r.unread(a.subarray(l)),e.readableEnded)break;if(l===0)throw new Error("archive inflater made no progress")}return await h,{crc:s>>>0,compressedSize:i,uncompressedSize:n}}finally{e.destroyed||e.destroy(),await p;}}var A=class{#i;#t;fail(t){let e=t instanceof Error?t:new Error("archive inflater failed");this.#i=e,this.#t?.(e),this.#t=void 0;}async race(t){if(this.#i)throw this.#i;let e,i=new Promise((n,s)=>{e=o=>s(o),this.#t=e;});try{return await Promise.race([t,i])}finally{e&&this.#t===e&&(this.#t=void 0);}}};async function Et(r,t){try{await r;}catch(e){t.fail(e);}}async function gt(r,t,e){let i=new Promise((n,s)=>{r.write(t,o=>{o?s(o):n();});});await e.race(i);}async function vt(r,t){let e=BigInt(r.position);for(let h of t){let f=await r.readExact(46);Ut(f,h);let p=f.readUInt16LE(28),a=f.readUInt16LE(30);if(a!==28||f.readUInt16LE(32)!==0)throw new Error("central entry metadata is invalid");if(K(await r.readExact(p))!==h.name)throw new Error("central entry order differs");Lt(await r.readExact(a),h);}let i=BigInt(r.position)-e,n=BigInt(r.position),s=await r.readExact(56);if(w(s,0,ut),s.readBigUInt64LE(4)!==44n||s.readUInt16LE(12)!==q||s.readUInt16LE(14)!==R||s.readUInt32LE(16)!==0||s.readUInt32LE(20)!==0||s.readBigUInt64LE(24)!==BigInt(t.length)||s.readBigUInt64LE(32)!==BigInt(t.length)||s.readBigUInt64LE(40)!==i||s.readBigUInt64LE(48)!==e)throw new Error("ZIP64 end record is invalid");let o=await r.readExact(20);if(w(o,0,ft),o.readUInt32LE(4)!==0||o.readBigUInt64LE(8)!==n||o.readUInt32LE(16)!==1)throw new Error("ZIP64 locator is invalid");let c=await r.readExact(22);if(w(c,0,lt),c.readUInt16LE(4)!==0||c.readUInt16LE(6)!==0||c.readUInt16LE(8)!==z||c.readUInt16LE(10)!==z||c.readUInt32LE(12)!==m||c.readUInt32LE(16)!==m||c.readUInt16LE(20)!==0)throw new Error("classic ZIP end record is invalid")}function bt(r){if(w(r,0,H),r.readUInt16LE(4)!==R||r.readUInt16LE(6)!==Y||r.readUInt16LE(8)!==Z||r.readUInt16LE(10)!==0||r.readUInt16LE(12)!==W||r.readUInt32LE(14)!==0||r.readUInt32LE(18)!==m||r.readUInt32LE(22)!==m)throw new Error("local entry header is invalid")}function It(r){if(r.readUInt16LE(0)!==1||r.readUInt16LE(2)!==16||r.readBigUInt64LE(4)!==0n||r.readBigUInt64LE(12)!==0n)throw new Error("local ZIP64 extra is invalid")}function kt(r,t){if(w(r,0,dt),r.readUInt32LE(4)!==t.crc||r.readBigUInt64LE(8)!==t.compressedSize||r.readBigUInt64LE(16)!==t.uncompressedSize)throw new Error("archive data descriptor is invalid")}function Ut(r,t){if(w(r,0,ht),r.readUInt16LE(4)!==q||r.readUInt16LE(6)!==R||r.readUInt16LE(8)!==Y||r.readUInt16LE(10)!==Z||r.readUInt16LE(12)!==0||r.readUInt16LE(14)!==W||r.readUInt32LE(16)!==t.crc||r.readUInt32LE(20)!==m||r.readUInt32LE(24)!==m||r.readUInt16LE(34)!==0||r.readUInt16LE(36)!==0||(r.readUInt32LE(38)>>>16&65535)!==yt||r.readUInt32LE(42)!==m)throw new Error("central entry header is invalid")}function Lt(r,t){if(r.readUInt16LE(0)!==1||r.readUInt16LE(2)!==24||r.readBigUInt64LE(4)!==t.uncompressedSize||r.readBigUInt64LE(12)!==t.compressedSize||r.readBigUInt64LE(20)!==t.localOffset)throw new Error("central ZIP64 extra is invalid")}function St(r){if(r!==ha&&!pt.test(r))throw new Error("archive entry name is invalid")}function K(r){let t=mt.decode(r);if(Buffer.byteLength(t,"utf8")!==r.byteLength)throw new Error("archive entry name is not canonical UTF-8");return t}function w(r,t,e){if(r.readUInt32LE(t)!==e)throw new Error("archive signature is invalid")}var C=class{#i;#t=createHash("sha256");#e=[];#r=0;#n=false;#o=0;position=0;constructor(t){this.#i=At(t)[Symbol.asyncIterator]();}async peekU32(){let t=await this.readExact(4);return this.unread(t),t.readUInt32LE(0)}async readExact(t){let e=Buffer.allocUnsafe(t),i=0;for(;i<t;){let n=await this.readSome(t-i);if(!n)throw new Error("archive is truncated");e.set(n,i),i+=n.byteLength;}return e}async readSome(t){for(;this.#e.length===0;)if(!await this.#s())return;let e=this.#e[0];if(!e)return;let i=e.byteLength-this.#r,n=Math.min(t,i),s=e.subarray(this.#r,this.#r+n);return this.#r+=n,this.position+=n,this.#r===e.byteLength&&(this.#e.shift(),this.#r=0),s}unread(t){if(t.byteLength!==0){if(this.#r>0){let e=this.#e[0];if(!e)throw new Error("archive reader queue is inconsistent");let i=e.subarray(this.#r);this.#e[0]=i,this.#r=0;}this.#e.unshift(t),this.position-=t.byteLength;}}async finish(){if(this.#e.length>0||await this.#s())throw new Error("archive contains trailing bytes");return {byteLength:this.#o,sha256:this.#t.digest("hex")}}async close(){try{await this.#i.return?.();}catch{}}async#s(){if(this.#n)return false;for(;;){let t;try{t=await this.#i.next();}catch{throw new E}if(t.done)return this.#n=true,false;if(!(t.value instanceof Uint8Array))throw new E;if(t.value.byteLength!==0){if(this.#t.update(t.value),this.#o+=t.value.byteLength,!Number.isSafeInteger(this.#o))throw new Error("archive byte length is unsafe");return this.#e.push(t.value),true}}}};function At(r){if(Symbol.asyncIterator in r)return r;let t=r;return {async*[Symbol.asyncIterator](){let e=t.getReader(),i=false;try{for(;;){let{value:n,done:s}=await e.read();if(s){i=!0;return}yield n;}}finally{if(!i)try{await e.cancel();}catch{}e.releaseLock();}}}}var xt=4*1024*1024,j=8,J=64*1024,Tt=16*1024,u=4,$=4,Ot=1,Vt=u+Ot,X=Vt+$,g=class extends Error{},k=class{#i;#t;#e=[];#r=0;#n;constructor(t,e={}){this.#i=t;let i=e.sortBudgetBytes??xt;if(this.#n=e.mergeFanIn??j,!Number.isSafeInteger(i)||i<X||!Number.isSafeInteger(this.#n)||this.#n<2||this.#n>j)throw new Error("checkpoint identity sort limits are invalid");this.#t=new _(i);}add(t){let e=Buffer.byteLength(t,"utf8");if(!this.#t.canFit(e))throw new Error("checkpoint durable identity exceeds the sort budget");if(this.#t.canAdd(e)){this.#t.add(t,e);return}return this.#o(t,e)}async finish(){if(this.#e.length===0){this.#t.sortAndAssertUnique(),this.#t.clear();return}for(this.#t.isEmpty||await this.#o();this.#e.length>this.#n;){let e=[];for(let i=0;i<this.#e.length;i+=this.#n){let n=this.#e.slice(i,i+this.#n),s=this.#s();await Ft(n,s),await Promise.all(n.map(o=>rm(o,{force:true}))),e.push(s);}this.#e=e;}let t;await tt(this.#e,e=>{if(t&&P(t,e)===0)throw new g;t=e;});}async#o(t,e){let i=this.#s();this.#t.sortAndAssertUnique(),await Mt(i,this.#t),this.#e.push(i),this.#t.clear(),t!==void 0&&e!==void 0&&this.#t.add(t,e);}#s(){let t=join(this.#i,`identity-run-${String(this.#r).padStart(8,"0")}.bin`);return this.#r+=1,t}},_=class{byteBudget;#i;#t;#e=0;#r=0;constructor(t){this.byteBudget=t;let e=Math.floor(t/X);this.#t=new Uint32Array(e),this.#i=Buffer.allocUnsafe(t-e*$);}get isEmpty(){return this.#r===0}canAdd(t){return this.canFit(t)&&this.#r<this.#t.length&&this.#e+u+t<=this.#i.length}canFit(t){return t<=4294967295&&this.#t.length>0&&u+t<=this.#i.length}add(t,e){if(!this.canAdd(e))throw new Error("checkpoint durable identity exceeds the sort budget");let i=this.#e;this.#t[this.#r]=i,this.#i.writeUInt32BE(e,i),this.#i.write(t,i+u,e,"utf8"),this.#e+=u+e,this.#r+=1;}sortAndAssertUnique(){let t=this.#t.subarray(0,this.#r);t.sort((e,i)=>this.#n(e,i));for(let e=1;e<t.length;e+=1){let i=t[e-1],n=t[e];if(i===void 0||n===void 0)throw new Error("checkpoint identity offset is missing");if(this.#n(i,n)===0)throw new g}}clear(){this.#e=0,this.#r=0;}forEachSorted(t){return Dt(this.#t.subarray(0,this.#r),e=>t(this.#s(e)))}#n(t,e){return P(this.#o(t),this.#o(e))}#o(t){let e=this.#i.readUInt32BE(t);return this.#i.subarray(t+u,t+u+e)}#s(t){let e=this.#i.readUInt32BE(t);return this.#i.subarray(t,t+u+e)}};async function Mt(r,t){await Q(r,async e=>{let i=new U(e);await t.forEachSorted(n=>i.write(n)),await i.finish();});}async function Ft(r,t){await Q(t,async e=>{let i=new U(e);await tt(r,n=>i.writeValue(n)),await i.finish();});}async function Q(r,t){await(await open(r,"wx",384)).close();let i=createWriteStream(r,{flags:"a",mode:384,highWaterMark:J});try{await t(i),i.end(),await once(i,"close");}catch(n){throw i.destroy(),n}}var U=class{#i;#t=Buffer.allocUnsafe(J);#e=0;constructor(t){this.#i=t;}write(t){if(t.byteLength>this.#t.length)return this.#r(t);if(this.#e+t.byteLength>this.#t.length)return this.#n(t);this.#t.set(t,this.#e),this.#e+=t.byteLength;}writeValue(t){let e=u+t.byteLength;if(e>this.#t.length)return this.#o(t);if(this.#e+e>this.#t.length)return this.#s(t);this.#c(t);}async finish(){await this.#a();}async#r(t){await this.#a(),await I(this.#i,t);}async#n(t){await this.#a(),this.#t.set(t,this.#e),this.#e+=t.byteLength;}async#o(t){await this.#a();let e=Buffer.allocUnsafe(u);e.writeUInt32BE(t.byteLength,0),await I(this.#i,e),await I(this.#i,t);}async#s(t){await this.#a(),this.#c(t);}async#a(){if(this.#e===0)return;let t=this.#t.subarray(0,this.#e);await I(this.#i,t),this.#e=0;}#c(t){this.#t.writeUInt32BE(t.byteLength,this.#e),this.#t.set(t,this.#e+u),this.#e+=u+t.byteLength;}};async function tt(r,t){let e=r.map(i=>new B(i));try{for(await Promise.all(e.map(i=>i.advance()));;){let i;for(let s of e)s.current&&(!i||P(s.current,i.current)<0)&&(i=s);if(!i?.current)return;let n=t(i.current);n&&await n,await i.advance();}}finally{for(let i of e)i.close();}}var B=class{#i;#t;#e=Buffer.alloc(0);#r=0;current;constructor(t){this.#i=createReadStream(t,{highWaterMark:Tt}),this.#t=this.#i[Symbol.asyncIterator]();}async advance(){let t=await this.#n(u);if(!t){this.current=void 0;return}let e=t.readUInt32BE(0);if(e===0)throw new Error("checkpoint identity run is invalid");let i=await this.#n(e);if(!i)throw new Error("checkpoint identity run is truncated");this.current=i;}close(){this.#i.destroy();}async#n(t){if(t===0)return Buffer.alloc(0);if(this.#e.length-this.#r>=t){let n=this.#e.subarray(this.#r,this.#r+t);return this.#r+=t,n}let e=Buffer.allocUnsafe(t),i=0;for(;i<t;){if(this.#r<this.#e.length){let s=Math.min(t-i,this.#e.length-this.#r);this.#e.copy(e,i,this.#r,this.#r+s),this.#r+=s,i+=s;continue}let n=await this.#t.next();if(n.done){if(i===0)return;throw new Error("checkpoint identity run is truncated")}this.#e=n.value,this.#r=0;}return e}};async function Dt(r,t){for(let e of r){let i=t(e);i&&await i;}}async function I(r,t){await new Promise((e,i)=>{r.write(t,n=>{n?i(n):e();});});}function P(r,t){let e=Math.min(r.length,t.length);for(let i=0;i<e;i+=1){let n=r[i],s=t[i];if(n===void 0||s===void 0)throw new Error("checkpoint identity byte is missing");let o=n-s;if(o!==0)return o}return r.length-t.length}var L=class{#i;#t=new Map;#e=new Map;#r=[];#n;constructor(t,e={}){this.#i=new k(t,{sortBudgetBytes:e.identitySortBudgetBytes,mergeFanIn:e.identityMergeFanIn});}openEntry(t){if(t===ha){let e=[];return {write:async i=>{e.push(i.slice());},finish:async()=>{this.#n=Buffer.concat(e);}}}return new N(t,this.#t,this.#e,this.#i,e=>this.#r.push(e))}async finish(){if(!this.#n)throw new Error("checkpoint manifest is missing");let t=await la(this.#n),e=t.streams.flatMap(i=>i.chunks.map(n=>({...n,shapeName:i.shapeName})));if(e.length!==this.#r.length)throw new Error("checkpoint chunk inventory does not match");for(let[i,n]of e.entries()){let s=this.#r[i];if(s.path!==n.path||s.shapeName!==n.shapeName||s.recordCount!==n.recordCount||s.byteLength!==n.byteLength||s.sha256!==n.sha256)throw new Error("checkpoint chunk integrity does not match")}for(let i of t.streams){let n=this.#t.get(i.shapeName);if(!n||pa(n)!==i.recordCount)throw new Error("checkpoint stream does not match its manifest")}if(this.#t.size!==t.streams.length)throw new Error("checkpoint contains an undeclared stream");return await this.#i.finish(),{manifest:t,chunkCount:e.length}}},N=class{#i;#t;#e;#r;#n;#o=createHash("sha256");#s=[];#a=0;#c;#h=0;#d=0;constructor(t,e,i,n,s){this.#i=t,this.#t=e,this.#e=i,this.#r=n,this.#n=s;}async write(t){if(this.#o.update(t),this.#d+=t.byteLength,!Number.isSafeInteger(this.#d))throw new Error("checkpoint chunk byte length is unsafe");let e=0;for(;e<t.byteLength;){let i=t.indexOf(10,e);if(i<0)break;let n=this.#u(this.#l(t.subarray(e,i+1)));n&&await n,e=i+1;}e<t.byteLength&&this.#f(t.subarray(e));}async finish(){if(this.#s.length!==0||this.#h===0||!this.#c)throw new Error("checkpoint chunk framing is invalid");if(this.#d>fa&&this.#h!==1)throw new Error("oversized checkpoint chunk has multiple rows");this.#n({path:this.#i,shapeName:this.#c,recordCount:this.#h,byteLength:this.#d,sha256:this.#o.digest("hex")});let t=this.#e.get(this.#c);if(!t)throw new Error("checkpoint stream chunk state is missing");t.previous={byteLength:this.#d};}#u(t){let e=ma(t),i=e.kind==="shape"?e.wref:e.shapeName;if(this.#c!==void 0&&this.#c!==i)throw new Error("checkpoint chunk mixes Shape streams");this.#c=i,this.#h===0&&this.#y(i,t.byteLength);let n=this.#t.get(i)??na(i);this.#t.set(i,n),oa(n,e);let s=this.#r.add(e.durableId);if(this.#h+=1,!Number.isSafeInteger(this.#h))throw new Error("checkpoint chunk row count is unsafe");return s}#f(t){if(t.byteLength!==0&&(this.#s.push(t.slice()),this.#a+=t.byteLength,!Number.isSafeInteger(this.#a)))throw new Error("checkpoint row byte length is unsafe")}#l(t){if(this.#s.length===0)return t;let e=Buffer.concat([...this.#s,t],this.#a+t.byteLength);return this.#s=[],this.#a=0,e}#y(t,e){let i=Number(this.#i.match(/part-(\d{10})\.jsonl$/)?.[1]??-1),n=this.#e.get(t)??{nextPart:0};if(i!==n.nextPart)throw new Error("checkpoint stream chunk parts are not contiguous");if(n.previous&&n.previous.byteLength<=fa&&n.previous.byteLength+e<=fa)throw new Error("checkpoint stream chunk closed before the byte limit");n.nextPart+=1,this.#e.set(t,n);}};async function Gt(r,t){return Kt(r,t)}async function Kt(r,t,e={}){let i=await mkdtemp(join(e.scratchParent??tmpdir(),"warmhub-checkpoint-verify-"));await chmod(i,448);let n,s;try{let o=new L(i,e),c=await G(r,p=>o.openEntry(p)),{manifest:h,chunkCount:f}=await o.finish();jt(t,c,h),n={valid:!0,checkpointId:h.checkpointId,repoSeq:h.repoSeq,recordCount:h.recordCount,chunkCount:f,totalBytes:c.byteLength,rootDigest:h.contentSha256,archiveDigest:c.sha256};}catch(o){s=Jt(o);}try{await rm(i,{recursive:!0,force:!0});}catch{s??=new d("scratch_cleanup_failed");}if(s)throw s;if(!n)throw new d("archive_invalid");return n}function jt(r,t,e){if(r&&(ka.parse(r.sha256),r.checkpointId!==e.checkpointId||r.repoSeq!==e.repoSeq||r.byteLength!==t.byteLength||r.sha256!==t.sha256))throw new d("archive_integrity_mismatch")}function Jt(r){if(r instanceof d)return r;if(r instanceof E)return new d("source_failed");if(r instanceof g)return new d("duplicate_durable_id");let t=r instanceof Error?r.message:"";return t.includes("manifest")?new d("manifest_invalid"):t.includes("chunk")||t.includes("row")||t.includes("Shape stream")?new d("chunk_invalid"):new d("archive_invalid")}export{d as RepositoryCheckpointVerificationError,Gt as verifyRepositoryCheckpointArchive};//# sourceMappingURL=checkpoint.js.map
2
2
  //# sourceMappingURL=checkpoint.js.map
@@ -15,7 +15,7 @@ import {z as z$1}from'zod';var NB="0123456789ABCDEFGHJKMNPQRSTVWXYZ",_B=new Uint
15
15
  `)+1&&e.runes[3]===O.MAX_RUNE&&(e.runes=new Int32Array(0),e.op=p.Op.ANY_CHAR_NOT_NL));}collapse(e,B){if(e.length===1)return e[0];let t=0;for(let o of e)t+=o.op===B?o.subs.length:1;let r=new Array(t).fill(null),i=0;for(let o of e)if(o.op===B){for(let C=0;C<o.subs.length;C++)r[i++]=o.subs[C];this.reuse(o);}else r[i++]=o;let s=this.newRegexp(B);if(s.subs=r,B===p.Op.ALTERNATE&&(s.subs=this.factor(s.subs),s.subs.length===1)){let o=s;s=s.subs[0],this.reuse(o);}return s}factor(e){if(e.length<2)return e;let B=0,t=e.length,r=0,i=null,s=0,o=0,C=0;for(let c=0;c<=t;c++){let E=null,h=0,g=0;if(c<t){let m=e[B+c];if(m.op===p.Op.CONCAT&&m.subs.length>0&&(m=m.subs[0]),m.op===p.Op.LITERAL&&(E=m.runes,h=m.runes.length,g=m.flags&d.FOLD_CASE),g===o){let S=0;for(;S<s&&S<h&&i[S]===E[S];)S++;if(S>0){s=S;continue}}}if(c!==C)if(c===C+1)e[r++]=e[B+C];else {let m=this.newRegexp(p.Op.LITERAL);m.flags=o,m.runes=i.slice(0,s);for(let N=C;N<c;N++)e[B+N]=this.removeLeadingString(e[B+N],s),this.checkLimits(e[B+N]);let S=this.collapse(e.slice(B+C,B+c),p.Op.ALTERNATE),R=this.newRegexp(p.Op.CONCAT);R.subs=[m,S],e[r++]=R;}C=c,i=E,s=h,o=g;}t=r,B=0,C=0,r=0;let u=null;for(let c=0;c<=t;c++){let E=null;if(!(c<t&&(E=A.leadingRegexp(e[B+c]),u!==null&&u.equals(E)&&(A.isCharClass(u)||u.op===p.Op.REPEAT&&u.min===u.max&&A.isCharClass(u.subs[0]))))){if(c!==C)if(c===C+1)e[r++]=e[B+C];else {let h=u;for(let S=C;S<c;S++){let R=S!==C;e[B+S]=this.removeLeadingRegexp(e[B+S],R),this.checkLimits(e[B+S]);}let g=this.collapse(e.slice(B+C,B+c),p.Op.ALTERNATE),m=this.newRegexp(p.Op.CONCAT);m.subs=[h,g],e[r++]=m;}C=c,u=E;}}t=r,B=0,C=0,r=0;for(let c=0;c<=t;c++)if(!(c<t&&A.isCharClass(e[B+c]))){if(c!==C)if(c===C+1)e[r++]=e[B+C];else {let E=C;for(let g=C+1;g<c;g++){let m=e[B+E],S=e[B+g];(m.op<S.op||m.op===S.op&&(m.runes!==null?m.runes.length:0)<(S.runes!==null?S.runes.length:0))&&(E=g);}let h=e[B+C];e[B+C]=e[B+E],e[B+E]=h;for(let g=C+1;g<c;g++)A.mergeCharClass(e[B+C],e[B+g]),this.reuse(e[B+g]);this.cleanAlt(e[B+C]),e[r++]=e[B+C];}c<t&&(e[r++]=e[B+c]),C=c+1;}t=r,B=0,C=0,r=0;for(let c=0;c<t;++c)c+1<t&&e[B+c].op===p.Op.EMPTY_MATCH&&e[B+c+1].op===p.Op.EMPTY_MATCH||(e[r++]=e[B+c]);return t=r,B=0,e.slice(B,t)}removeLeadingString(e,B){if(e.op===p.Op.CONCAT&&e.subs.length>0){let t=this.removeLeadingString(e.subs[0],B);if(e.subs[0]=t,t.op===p.Op.EMPTY_MATCH)switch(this.reuse(t),e.subs.length){case 0:case 1:e.op=p.Op.EMPTY_MATCH,e.subs=p.emptySubs();break;case 2:{let r=e;e=e.subs[1],this.reuse(r);break}default:e.subs=e.subs.slice(1,e.subs.length);}return e}return e.op===p.Op.LITERAL&&(e.runes=e.runes.slice(B,e.runes.length),e.runes.length===0&&(e.op=p.Op.EMPTY_MATCH)),e}removeLeadingRegexp(e,B){if(e.op===p.Op.CONCAT&&e.subs.length>0){switch(B&&this.reuse(e.subs[0]),e.subs=e.subs.slice(1,e.subs.length),e.subs.length){case 0:e.op=p.Op.EMPTY_MATCH,e.subs=p.emptySubs();break;case 1:{let t=e;e=e.subs[0],this.reuse(t);break}}return e}return B&&this.reuse(e),this.newRegexp(p.Op.EMPTY_MATCH)}parseInternal(){if((this.flags&d.LITERAL)!==0)return A.literalRegexp(this.wholeRegexp,this.flags);let e=-1,B=-1,t=-1,r=new Mi(this.wholeRegexp);for(;r.more();){let i=-1;e:switch(r.peek()){case D.CODES.get("("):if((this.flags&d.LOOKBEHIND)!==0){if(r.lookingAt("(?<=")){this.parsePosLookBehind(),r.skip(4);break}if(r.lookingAt("(?<!")){this.parseNegLookBehind(),r.skip(4);break}}if((this.flags&d.PERL_X)!==0&&r.lookingAt("(?")){this.parsePerlFlags(r);break}this.op(p.Op.LEFT_PAREN).cap=++this.numCap,r.skip(1);break;case D.CODES.get("|"):this.parseVerticalBar(),r.skip(1);break;case D.CODES.get(")"):this.parseRightParen(),r.skip(1);break;case D.CODES.get("^"):(this.flags&d.ONE_LINE)!==0?this.op(p.Op.BEGIN_TEXT):this.op(p.Op.BEGIN_LINE),r.skip(1);break;case D.CODES.get("$"):(this.flags&d.ONE_LINE)!==0?this.op(p.Op.END_TEXT).flags|=d.WAS_DOLLAR:this.op(p.Op.END_LINE),r.skip(1);break;case D.CODES.get("."):(this.flags&d.DOT_NL)!==0?this.op(p.Op.ANY_CHAR):this.op(p.Op.ANY_CHAR_NOT_NL),r.skip(1);break;case D.CODES.get("["):this.parseClass(r);break;case D.CODES.get("*"):case D.CODES.get("+"):case D.CODES.get("?"):{i=r.pos();let s=null;switch(r.pop()){case D.CODES.get("*"):s=p.Op.STAR;break;case D.CODES.get("+"):s=p.Op.PLUS;break;case D.CODES.get("?"):s=p.Op.QUEST;}this.repeat(s,B,t,i,r,e);break}case D.CODES.get("{"):{i=r.pos();let s=A.parseRepeat(r);if(s<0){r.rewindTo(i),this.literal(r.pop());break}B=s>>16,t=(s&O.MAX_BMP)<<16>>16,this.repeat(p.Op.REPEAT,B,t,i,r,e);break}case D.CODES.get("\\"):{let s=r.pos();if(r.skip(1),(this.flags&d.PERL_X)!==0&&r.more())switch(r.pop()){case D.CODES.get("A"):this.op(p.Op.BEGIN_TEXT);break e;case D.CODES.get("b"):this.op(p.Op.WORD_BOUNDARY);break e;case D.CODES.get("B"):this.op(p.Op.NO_WORD_BOUNDARY);break e;case D.CODES.get("C"):throw new P(A.ERR_INVALID_ESCAPE,"\\C");case D.CODES.get("Q"):{let u=r.rest(),c=u.indexOf("\\E");c>=0?(u=u.substring(0,c),r.skipString(u),r.skipString("\\E")):r.skipString(u);let E=0;for(;E<u.length;){let h=u.codePointAt(E);this.literal(h),E+=I.charCount(h);}break e}case D.CODES.get("z"):this.op(p.Op.END_TEXT);break e;default:r.rewindTo(s);}else r.rewindTo(s);let o=this.newRegexp(p.Op.CHAR_CLASS);if(o.flags=this.flags,r.lookingAt("\\p")||r.lookingAt("\\P")){let u=new oe;if(this.parseUnicodeClass(r,u)){o.runes=u.toArray(),this.push(o);break e}}let C=new oe;if(this.parsePerlClassEscape(r,C)){o.runes=C.toArray(),this.push(o);break e}r.rewindTo(s),this.reuse(o),this.literal(A.parseEscape(r));break}default:this.literal(r.pop());}e=i;}if(this.concat(),this.swapVerticalBar()&&this.pop(),this.alternate(),this.stack.length!==1)throw new P(A.ERR_MISSING_PAREN,this.wholeRegexp);return this.stack[0].namedGroups=this.namedGroups,this.stack[0]}parsePerlFlags(e){let B=e.pos(),t=e.rest();if(t.startsWith("(?P<")||t.startsWith("(?<")){let o=t.charAt(2)==="P"?4:3,C=t.indexOf(">");if(C<0)throw new P(A.ERR_INVALID_NAMED_CAPTURE,t);let u=t.substring(o,C);if(e.skipString(u),e.skip(o+1),!A.isValidCaptureName(u))throw new P(A.ERR_INVALID_NAMED_CAPTURE,t.substring(0,C+1));let c=this.op(p.Op.LEFT_PAREN);if(c.cap=++this.numCap,this.namedGroups[u])throw new P(A.ERR_DUPLICATE_NAMED_CAPTURE,u);this.namedGroups[u]=this.numCap,c.name=u;return}e.skip(2);let r=this.flags,i=1,s=false;e:for(;e.more();){let o=e.pop();switch(o){case D.CODES.get("i"):r|=d.FOLD_CASE,s=true;break;case D.CODES.get("m"):r&=-17,s=true;break;case D.CODES.get("s"):r|=d.DOT_NL,s=true;break;case D.CODES.get("U"):r|=d.NON_GREEDY,s=true;break;case D.CODES.get("-"):if(i<0)break e;i=-1,r=~r,s=false;break;case D.CODES.get(":"):case D.CODES.get(")"):if(i<0){if(!s)break e;r=~r;}o===D.CODES.get(":")&&this.op(p.Op.LEFT_PAREN),this.flags=r;return;default:break e}}throw new P(A.ERR_INVALID_PERL_OP,e.from(B))}parsePosLookBehind(){let e=this.newRegexp(p.Op.LEFT_PAREN);return e.flags=this.flags,e.lb=++this.nlb,this.push(e)}parseNegLookBehind(){let e=this.newRegexp(p.Op.LEFT_PAREN);return e.flags=this.flags,e.lb=-++this.nlb,this.push(e)}parseVerticalBar(){this.concat(),this.swapVerticalBar()||this.op(p.Op.VERTICAL_BAR);}swapVerticalBar(){let e=this.stack.length;if(e>=3&&this.stack[e-2].op===p.Op.VERTICAL_BAR&&A.isCharClass(this.stack[e-1])&&A.isCharClass(this.stack[e-3])){let B=this.stack[e-1],t=this.stack[e-3];if(B.op>t.op){let r=t;t=B,B=r,this.stack[e-3]=t;}return A.mergeCharClass(t,B),this.reuse(B),this.pop(),true}if(e>=2){let B=this.stack[e-1],t=this.stack[e-2];if(t.op===p.Op.VERTICAL_BAR)return e>=3&&this.cleanAlt(this.stack[e-3]),this.stack[e-2]=B,this.stack[e-1]=t,true}return false}parseRightParen(){if(this.concat(),this.swapVerticalBar()&&this.pop(),this.alternate(),this.stack.length<2)throw new P(A.ERR_UNEXPECTED_PAREN,this.wholeRegexp);let e=this.pop(),B=this.pop();if(B.op!==p.Op.LEFT_PAREN)throw new P(A.ERR_UNEXPECTED_PAREN,this.wholeRegexp);if(this.flags=B.flags,B.lb!==0){if(A.hasCapture(e))throw new P(A.ERR_INVALID_CAPTURE_IN_LOOKBEHIND,this.wholeRegexp);B.lb>0?B.op=p.Op.PLB:B.op=p.Op.NLB,B.subs=[e],this.push(B);return}B.cap===0?this.push(e):(B.op=p.Op.CAPTURE,B.subs=[e],this.push(B));}parsePerlClassEscape(e,B){let t=e.pos();if((this.flags&d.PERL_X)===0||!e.more()||e.pop()!==D.CODES.get("\\")||!e.more())return false;e.pop();let r=e.from(t),i=Zt.has(r)?Zt.get(r):null;return i===null?false:(B.appendGroup(i,(this.flags&d.FOLD_CASE)!==0),true)}parseNamedClass(e,B){let t=e.rest(),r=t.indexOf(":]");if(r<0)return false;let i=t.substring(0,r+2);e.skipString(i);let s=hn.has(i)?hn.get(i):null;if(s===null)throw new P(A.ERR_INVALID_CHAR_RANGE,i);return B.appendGroup(s,(this.flags&d.FOLD_CASE)!==0),true}parseUnicodeClass(e,B){let t=e.pos();if((this.flags&d.UNICODE_GROUPS)===0||!e.lookingAt("\\p")&&!e.lookingAt("\\P"))return false;e.skip(1);let r=1,i=e.pop();if(i===D.CODES.get("P")&&(r=-1),!e.more())throw e.rewindTo(t),new P(A.ERR_INVALID_CHAR_RANGE,e.rest());i=e.pop();let s;if(i!==D.CODES.get("{"))s=I.runeToString(i);else {let c=e.rest(),E=c.indexOf("}");if(E<0)throw e.rewindTo(t),new P(A.ERR_INVALID_CHAR_RANGE,e.rest());s=c.substring(0,E),e.skipString(s),e.skip(1);}s.length!==0&&s.codePointAt(0)===D.CODES.get("^")&&(r=0-r,s=s.substring(1));let o=A.unicodeTable(s);if(o===null)throw new P(A.ERR_INVALID_CHAR_RANGE,e.from(t));o.sign<0&&(r=0-r);let C=o.tab,u=o.fold;if((this.flags&d.FOLD_CASE)===0||u===null)B.appendTableWithSign(C,r);else {let c=new oe().appendTable(C).appendTable(u).cleanClass().toArray();B.appendClassWithSign(Array.from(c),r);}return true}parseClass(e){let B=e.pos();e.skip(1);let t=this.newRegexp(p.Op.CHAR_CLASS);t.flags=this.flags;let r=new oe,i=1;e.more()&&e.lookingAt("^")&&(i=-1,e.skip(1),(this.flags&d.CLASS_NL)===0&&r.appendRange(D.CODES.get(`
16
16
  `),D.CODES.get(`
17
17
  `)));let s=true;for(;!e.more()||e.peek()!==D.CODES.get("]")||s;){if(e.more()&&e.lookingAt("-")&&(this.flags&d.PERL_X)===0&&!s){let c=e.rest();if(c==="-"||!c.startsWith("-]"))throw e.rewindTo(B),new P(A.ERR_INVALID_CHAR_RANGE,e.rest())}s=false;let o=e.pos();if(e.lookingAt("[:")){if(this.parseNamedClass(e,r))continue;e.rewindTo(o);}if(this.parseUnicodeClass(e,r)||this.parsePerlClassEscape(e,r))continue;e.rewindTo(o);let C=A.parseClassChar(e,B),u=C;if(e.more()&&e.lookingAt("-")){if(e.skip(1),e.more()&&e.lookingAt("]"))e.skip(-1);else if(u=A.parseClassChar(e,B),u<C)throw new P(A.ERR_INVALID_CHAR_RANGE,e.from(o))}(this.flags&d.FOLD_CASE)===0?r.appendRange(C,u):r.appendFoldedRange(C,u);}e.skip(1),r.cleanClass(),i<0&&r.negateClass(),t.runes=r.toArray(),this.push(t);}},ki=class ae{static initTest(e){let B=ae.compile(e),t=new ae(B.expr,B.prog,B.numSubexp,B.longest);return t.cond=B.cond,t.prefix=B.prefix,t.prefixUTF8=B.prefixUTF8,t.prefixComplete=B.prefixComplete,t.prefixRune=B.prefixRune,t.prefilter=B.prefilter,t}static compile(e){return ae.compileImpl(e,d.PERL,false)}static compilePOSIX(e){return ae.compileImpl(e,d.POSIX,true)}static compileImpl(e,B,t){let r=Ne.parse(e,B),i=r.maxCap();r=_n.simplify(r);let s=Pi.build(r),o=Nn.compileRegexp(r),C=new ae(e,o,i,t);C.prefilter=s.type===F.Type.NONE?null:s;let[u,c]=o.prefix();return C.prefixComplete=u,C.prefix=c,C.prefixUTF8=I.stringToUtf8ByteArray(C.prefix),C.prefix.length>0&&(C.prefixRune=C.prefix.codePointAt(0)),C.namedGroups=r.namedGroups,C}static match(e,B){return ae.compile(e).match(B)}constructor(e,B,t=0,r=0){this.expr=e,this.prog=B,this.numSubexp=t,this.longest=r,this.cond=B.startCond(),this.prefix=null,this.prefixUTF8=null,this.prefixComplete=false,this.prefixRune=0,this.machinePool=[],this.dfa=new In(this.prog),this.onepass=jt.compile(this.prog),this.prefilter=null;}matchPrefixComplete(e,B,t,r){if((t===d.ANCHOR_START||t===d.ANCHOR_BOTH)&&B!==0)return null;let i=-1,s=-1,o=e.prefixLength(this);if(t===d.UNANCHORED){let C=e.index(this,B);if(C<0)return null;i=B+C,s=i+o;}else if(t===d.ANCHOR_BOTH){if(e.endPos()!==o||e.index(this,0)!==0)return null;i=0,s=o;}else if(t===d.ANCHOR_START){if(e.index(this,0)!==0)return null;i=0,s=o;}if(i<0)return null;if(r>0){let C=new Int32Array(r).fill(-1);return C[0]=i,C[1]=s,Array.from(C)}return []}createLookbehindState(){return this.prog.numLb>0?new Oi(this.prog):null}executeEngine(e,B,t,r,i=null){if(this.prefixComplete&&(r===0||this.numSubexp===0))return this.matchPrefixComplete(e,B,t,r);if(this.prefilter!==null&&t===d.UNANCHORED&&!this.prefilter.eval(e,B))return null;if(this.onepass!==null)return jt.execute(this,e,B,t,r);if(r>0)return this.prog.numLb===0&&e.endPos()<=qe.maxBitStateLen(this.prog)?qe.execute(this,e,B,t,r):this.doExecuteNFA(e,B,t,r,i);if(this.prog.numLb===0){let s=this.dfa.match(e,B,t);if(s!==null)return s?[]:null;if(e.endPos()<=qe.maxBitStateLen(this.prog))return qe.execute(this,e,B,t,r)}return this.doExecuteNFA(e,B,t,r,i)}numberOfCapturingGroups(){return this.numSubexp}numberOfInstructions(){return this.prog.numInst()}get(){return this.machinePool.length>0?this.machinePool.pop():null}reset(){this.machinePool.length=0;}put(e){this.machinePool.push(e);}toString(){return this.expr}doExecuteNFA(e,B,t,r,i=null){let s=this.get();s||(s=On.fromRE2(this)),s.init(r);let o=s.match(e,B,t,i)?s.submatches():null;return this.put(s),o}match(e){return this.executeEngine(w.fromUTF16(e),0,d.UNANCHORED,0)!==null}matchWithGroup(e,B,t,r,i,s=null){return e instanceof ce||(I.isByteArray(e)?e=le.utf8(e):e=le.utf16(e)),this.matchMachineInput(e,B,t,r,i,s)}matchMachineInput(e,B,t,r,i,s=null){if(B>t)return [false,null];let o=e.isUTF16Encoding()?w.fromUTF16(e.asCharSequence(),0,t):w.fromUTF8(e.asBytes(),0,t),C=this.executeEngine(o,B,r,2*i,s);return C===null?[false,null]:[true,C]}matchUTF8(e){return this.executeEngine(w.fromUTF8(e),0,d.UNANCHORED,0)!==null}replaceAll(e,B){return this.replaceAllFunc(e,()=>B,2*e.length+1)}replaceFirst(e,B){return this.replaceAllFunc(e,()=>B,1)}replaceAllFunc(e,B,t){let r=0,i=0,s="",o=w.fromUTF16(e),C=this.createLookbehindState(),u=0;for(;i<=e.length;){let c=this.executeEngine(o,i,d.UNANCHORED,2,C);if(c===null||c.length===0)break;s+=e.substring(r,c[0]),(c[1]>r||c[0]===0)&&(s+=B(e.substring(c[0],c[1])),u++),r=c[1];let E=o.step(i)&7;if(i+E>c[1]?i+=E:i+1>c[1]?i++:i=c[1],u>=t)break}return s+=e.substring(r),s}pad(e){if(e===null)return null;let B=(1+this.numSubexp)*2;if(e.length<B){let t=new Array(B).fill(-1);for(let r=0;r<e.length;r++)t[r]=e[r];e=t;}return e}allMatches(e,B,t=r=>r){let r=[],i=e.endPos();B<0&&(B=i+1);let s=0,o=0,C=-1,u=this.createLookbehindState();for(;o<B&&s<=i;){let c=this.executeEngine(e,s,d.UNANCHORED,this.prog.numCap,u);if(c===null||c.length===0)break;let E=true;if(c[1]===s){c[0]===C&&(E=false);let h=e.step(s);h<0?s=i+1:s+=h&7;}else s=c[1];C=c[1],E&&(r.push(t(this.pad(c))),o++);}return r}findUTF8(e){let B=this.executeEngine(w.fromUTF8(e),0,d.UNANCHORED,2);return B===null?null:e.slice(B[0],B[1])}findUTF8Index(e){let B=this.executeEngine(w.fromUTF8(e),0,d.UNANCHORED,2);return B===null?null:B.slice(0,2)}find(e){let B=this.executeEngine(w.fromUTF16(e),0,d.UNANCHORED,2);return B===null?"":e.substring(B[0],B[1])}findIndex(e){return this.executeEngine(w.fromUTF16(e),0,d.UNANCHORED,2)}findUTF8Submatch(e){let B=this.executeEngine(w.fromUTF8(e),0,d.UNANCHORED,this.prog.numCap);if(B===null)return null;let t=new Array(1+this.numSubexp).fill(null);for(let r=0;r<t.length;r++)2*r<B.length&&B[2*r]>=0&&(t[r]=e.slice(B[2*r],B[2*r+1]));return t}findUTF8SubmatchIndex(e){return this.pad(this.executeEngine(w.fromUTF8(e),0,d.UNANCHORED,this.prog.numCap))}findSubmatch(e){let B=this.executeEngine(w.fromUTF16(e),0,d.UNANCHORED,this.prog.numCap);if(B===null)return null;let t=new Array(1+this.numSubexp).fill(null);for(let r=0;r<t.length;r++)2*r<B.length&&B[2*r]>=0&&(t[r]=e.substring(B[2*r],B[2*r+1]));return t}findSubmatchIndex(e){return this.pad(this.executeEngine(w.fromUTF16(e),0,d.UNANCHORED,this.prog.numCap))}findAllUTF8(e,B){let t=this.allMatches(w.fromUTF8(e),B,r=>e.slice(r[0],r[1]));return t.length===0?null:t}findAllUTF8Index(e,B){let t=this.allMatches(w.fromUTF8(e),B,r=>r.slice(0,2));return t.length===0?null:t}findAll(e,B){let t=this.allMatches(w.fromUTF16(e),B,r=>e.substring(r[0],r[1]));return t.length===0?null:t}findAllIndex(e,B){let t=this.allMatches(w.fromUTF16(e),B,r=>r.slice(0,2));return t.length===0?null:t}findAllUTF8Submatch(e,B){let t=this.allMatches(w.fromUTF8(e),B,r=>{let i=new Array(r.length/2|0).fill(null);for(let s=0;s<i.length;s++)r[2*s]>=0&&(i[s]=e.slice(r[2*s],r[2*s+1]));return i});return t.length===0?null:t}findAllUTF8SubmatchIndex(e,B){let t=this.allMatches(w.fromUTF8(e),B);return t.length===0?null:t}findAllSubmatch(e,B){let t=this.allMatches(w.fromUTF16(e),B,r=>{let i=new Array(r.length/2|0).fill(null);for(let s=0;s<i.length;s++)r[2*s]>=0&&(i[s]=e.substring(r[2*s],r[2*s+1]));return i});return t.length===0?null:t}findAllSubmatchIndex(e,B){let t=this.allMatches(w.fromUTF16(e),B);return t.length===0?null:t}},Ui=class ge{static isHexadecimal(e){return "0"<=e&&e<="9"||"A"<=e&&e<="F"||"a"<=e&&e<="f"}static translate(e){let B="";if(e instanceof RegExp&&(e.ignoreCase&&(B+="i"),e.multiline&&(B+="m"),e.dotAll&&(B+="s"),e=e.source),typeof e!="string")return e;let t="",r=false,i=e.length;i===0&&(t="(?:)",r=true);let s=false,o=0;for(;o<i;){let u=e[o];if(u==="\\"){if(o+1<i)switch(u=e[o+1],u){case "\\":t+="\\\\",o+=2;continue;case "c":if(o+2<i){let h=e[o+2].charCodeAt(0);if(h>=65&&h<=90||h>=97&&h<=122){let g=h%32;t+="\\x",t+=(g>>4).toString(16).toUpperCase(),t+=(g&15).toString(16).toUpperCase(),o+=3,r=true;continue}}t+="c",o+=2,r=true;continue;case "u":if(o+2<i){if(e[o+2]==="{"){let h=o+3,g=false,m=false;for(;h<i;){let S=e[h];if(S==="}"){m=true;break}if(!ge.isHexadecimal(S))break;g=true,h++;}if(m&&g){t+="\\x",o+=2,r=true;continue}}else if(o+5<i){let h=true;for(let g=0;g<4;g++)if(!ge.isHexadecimal(e[o+2+g])){h=false;break}if(h){t+="\\x{"+e.substring(o+2,o+6)+"}",o+=6,r=true;continue}}}t+="u",o+=2,r=true;continue;case "x":{let h=false;if(o+2<i&&e[o+2]==="{"){let g=o+3,m=false,S=false;for(;g<i;){let R=e[g];if(R==="}"){S=true;break}if(!ge.isHexadecimal(R))break;m=true,g++;}S&&m&&(h=true);}else o+3<i&&ge.isHexadecimal(e[o+2])&&ge.isHexadecimal(e[o+3])&&(h=true);h?(t+="\\x",o+=2):(t+="x",o+=2,r=true);continue}case "n":case "r":case "t":case "a":case "f":case "v":case "d":case "D":case "s":case "S":case "w":case "W":case "b":case "B":case "p":case "P":case "A":case "z":case "Q":case "E":case "0":case "1":case "2":case "3":case "4":case "5":case "6":case "7":t+="\\"+u,o+=2;continue;default:{let h=e.codePointAt(o+1);if(h>=48&&h<=57||h>=65&&h<=90||h>=97&&h<=122){let g=I.charCount(h);t+=e.substring(o+1,o+1+g),o+=g+1,r=true;}else {t+="\\";let g=I.charCount(h);t+=e.substring(o+1,o+1+g),o+=g+1;}continue}}}else if(u==="/"){t+="\\/",o+=1,r=true;continue}else if(u==="[")s=true;else if(u==="]")s=false;else if(!s&&u==="("&&o+2<i&&e[o+1]==="?"&&e[o+2]==="<"&&o+3<i&&!"=!>)".includes(e[o+3])){t+="(?P<",o+=3,r=true;continue}let c=e.codePointAt(o),E=I.charCount(c);t+=e.substring(o,o+E),o+=E;}let C=r?t:e;return B.length>0?`(?${B})${C}`:C}},Fn=class U{static CASE_INSENSITIVE=z.CASE_INSENSITIVE;static DOTALL=z.DOTALL;static MULTILINE=z.MULTILINE;static DISABLE_UNICODE_GROUPS=z.DISABLE_UNICODE_GROUPS;static LONGEST_MATCH=z.LONGEST_MATCH;static LOOKBEHINDS=z.LOOKBEHINDS;static quote(e){return I.quoteMeta(e)}static quoteReplacement(e,B=false){return Kt.quoteReplacement(e,B)}static translateRegExp(e){return Ui.translate(e)}static compile(e,B=0){let t=e;if((B&U.CASE_INSENSITIVE)!==0&&(t=`(?i)${t}`),(B&U.DOTALL)!==0&&(t=`(?s)${t}`),(B&U.MULTILINE)!==0&&(t=`(?m)${t}`),(B&-544)!==0)throw new Si("Flags should only be a combination of MULTILINE, DOTALL, CASE_INSENSITIVE, DISABLE_UNICODE_GROUPS, LONGEST_MATCH, LOOKBEHINDS");let r=d.PERL;(B&U.DISABLE_UNICODE_GROUPS)!==0&&(r&=-129),(B&U.LOOKBEHINDS)!==0&&(r|=d.LOOKBEHIND);let i=new U(e,B);return i.re2Input=ki.compileImpl(t,r,(B&U.LONGEST_MATCH)!==0),i}static matches(e,B){return U.compile(e).testExact(B)}static initTest(e,B,t){if(e==null)throw new Error("pattern is null");if(t==null)throw new Error("re2 is null");let r=new U(e,B);return r.re2Input=t,r}constructor(e,B){this.patternInput=e,this.flagsInput=B,this.re2Input=null;}reset(){this.re2Input.reset();}flags(){return this.flagsInput}pattern(){return this.patternInput}re2(){return this.re2Input}matches(e){return this.testExact(e)}matcher(e){return I.isByteArray(e)&&(e=le.utf8(e)),new Kt(this,e)}test(e){return I.isByteArray(e)?this.re2Input.matchUTF8(e):this.re2Input.match(e)}testExact(e){let B=I.isByteArray(e)?w.fromUTF8(e):w.fromUTF16(e);return this.re2Input.executeEngine(B,0,d.ANCHOR_BOTH,0)!==null}exec(e){let B=this.matcher(e);if(!B.find())return null;let t=[B.group(0)];for(let i=1;i<=B.groupCount();i++){let s=B.group(i);t.push(s===null?void 0:s);}t.index=B.start(0),t.input=e;let r=this.namedGroups();if(Object.keys(r).length>0){let i=B.getNamedGroups();for(let s in i)i[s]===null&&(i[s]=void 0);t.groups=i;}else t.groups=void 0;return t}split(e,B=0){let t=this.matcher(e),r=[],i=0,s=0;for(;t.find();){if(s===0&&t.end()===0){s=t.end();continue}if(B>0&&r.length===B-1)break;if(s===t.start()){if(B===0){i+=1,s=t.end();continue}}else for(;i>0;)r.push(""),i-=1;r.push(t.substring(s,t.start())),s=t.end();}if(B===0&&s!==t.inputLength()){for(;i>0;)r.push(""),i-=1;r.push(t.substring(s,t.inputLength()));}return (B!==0||r.length===0&&!(s===t.inputLength()&&s>0))&&r.push(t.substring(s,t.inputLength())),r}*matchAll(e){let B=this.matcher(e);for(;B.find();){let t=[B.group(0)];for(let i=1;i<=B.groupCount();i++){let s=B.group(i);t.push(s===null?void 0:s);}t.index=B.start(0),t.input=e;let r=this.namedGroups();if(Object.keys(r).length>0){let i=B.getNamedGroups();for(let s in i)i[s]===null&&(i[s]=void 0);t.groups=i;}else t.groups=void 0;yield t;}}toString(){return this.patternInput}programSize(){return this.re2Input.numberOfInstructions()}groupCount(){return this.re2Input.numberOfCapturingGroups()}namedGroups(){return this.re2Input.namedGroups}equals(e){return this===e?true:e===null||this.constructor!==e.constructor?false:this.flagsInput===e.flagsInput&&this.patternInput===e.patternInput}};var JB=["number","string","boolean","wref","array"],VB=["identity","versioned","either"],vi=`${VB.slice(0,-1).join(", ")}, or ${VB.at(-1)}`,Ji=new Set(VB);function yn(n){return typeof n=="string"&&Ji.has(n)}function Ln(n,e){return !("binding"in e)||!("type"in e)||typeof e.type!="string"||!X.has(e.type)||typeof e.binding=="string"&&X.has(e.binding)?null:(e.type.endsWith("?")?e.type.slice(0,-1):e.type)!=="wref"?`Constraint "binding" at "${n}" is only valid for type "wref"`:yn(e.binding)?null:`"binding" at "${n}" must be ${vi}`}var Vi=new Set(JB),X=new Set([...JB,...JB.map(n=>`${n}?`)]);function Q(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}var be=new Set(["minLength","maxLength","pattern","enum"]),we=new Set(["minimum","maximum","integer"]),xe=new Set(["shape","binding"]),Pe=new Set(["items","minItems","maxItems"]),bn=new Set(["type","description"]),KB=new Set([...bn,...be,...we,...xe,...Pe]),Ki={string:be,number:we,wref:xe,array:Pe,boolean:new Set};function v(n){if(!Q(n)||!("type"in n)||typeof n.type!="string"||!X.has(n.type))return false;let e=n.type.endsWith("?")?n.type.slice(0,-1):n.type,B=Ki[e]??new Set;return !(!Object.keys(n).every(t=>bn.has(t)||B.has(t))||"minLength"in n&&typeof n.minLength!="number"||"maxLength"in n&&typeof n.maxLength!="number"||"pattern"in n&&typeof n.pattern!="string"||"pattern"in n&&typeof n.pattern=="string"&&X.has(n.pattern)&&e!=="string"||"enum"in n&&!Array.isArray(n.enum)||"minimum"in n&&typeof n.minimum!="number"||"maximum"in n&&typeof n.maximum!="number"||"integer"in n&&typeof n.integer!="boolean"||"shape"in n&&typeof n.shape!="string"||"binding"in n&&!yn(n.binding)||"shape"in n&&typeof n.shape=="string"&&X.has(n.shape)&&e!=="wref"||"items"in n&&typeof n.items=="number"||"items"in n&&typeof n.items=="boolean"||"minItems"in n&&typeof n.minItems!="number"||"maxItems"in n&&typeof n.maxItems!="number")}function Yi(n){return typeof n=="string"&&X.has(n)?n:v(n)?n.type:null}function wn(n){let e=Yi(n);if(!e)return null;let B=e.endsWith("?")?e.slice(0,-1):e;return Vi.has(B)?B:null}var q=64*1024,Ge=256,He=256,Wi="uses unsupported regex syntax",YB=`WarmHub content fields are limited to ${q} bytes. WarmHub is not a document store; store large documents in S3, Box, Drive, or another document system and reference them from WarmHub instead.`,ji=new TextEncoder;function ue(n){return ji.encode(n).byteLength}function WB(n,e){if(e.length*3<=q)return null;let B=ue(e);return B<=q?null:`Field "${n}" is ${B} bytes; ${YB}`}function Me(n,e,B){let t=WB(n,e);t&&B.push(t);}function BB(n){try{return new RegExp(n),!1}catch{return true}}function Qi(n){let e="",B=false;for(let t=0;t<n.length;t++){let r=n[t];if(r==="\\"){let i=n[t+1];if(B&&i==="b"){e+="\\x08",t++;continue}e+=r,i!==void 0&&(e+=i,t++);continue}r==="["?B=true:r==="]"&&(B=false),e+=r;}return e}function jB(n){try{return Fn.compile(Qi(n))}catch{return}}function xn(n){return jB(n)?void 0:Wi}function Z(n){return typeof n=="string"&&n.endsWith("?")?{spec:n.slice(0,-1),optionalByType:true}:v(n)&&typeof n.type=="string"&&n.type.endsWith("?")?{spec:{...n,type:n.type.slice(0,-1)},optionalByType:true}:{spec:n,optionalByType:false}}function tB(n,e){return n?.endsWith("?")||Z(e).optionalByType}var $i="X-WarmHub-Client-Flags",qi="X-WarmHub-Client-Flags-Honored",zi="compatibility-override";var Xi=/^[a-z0-9-]+$/;function Zi(n){return Xi.test(n)}function es(n){return [...new Set(n)].sort().join(",")}var Bs="X-WarmHub-Client",ts="X-WarmHub-Client-Minimum",ns=new Set(["auth.sync","commit.validate","live.issueTicket"]),rs="@warmhub/sdk-ts",is="warmhub-cli",ss="warmhub-sdk-py";function os(n,e){return `${n}/${e}`}var Cs=1e4;var as=["add","revise","retract","reaffirm","rename","redact","remove","restore","rewrite"];var cs=["shape","thing","assertion","collection"];function QB(n){let e=Jt(n);return e?{shapePrefix:e.shapeName,bareName:e.bareName}:null}var ps="X-WarmHub-Install-Repo",Es="X-WarmHub-Signature",hs="X-WarmHub-Timestamp",fs=/^[A-Za-z0-9\-._~]$/;function kn(n){let e="",B=new TextEncoder().encode(n);for(let t of B){let r=String.fromCharCode(t);fs.test(r)?e+=r:e+=`%${t.toString(16).toUpperCase().padStart(2,"0")}`;}return e}function gs(n){return typeof n=="boolean"?n?"true":"false":typeof n=="number"?JSON.stringify(n):n}function Ds(n){return n==="POST"||n==="PUT"||n==="PATCH"}function Un(n){let e=[];for(let[B,t]of Object.entries(n))t!=null&&e.push([B,gs(t)]);return e.sort(([B],[t])=>B<t?-1:B>t?1:0),e.map(([B,t])=>`${kn(B)}=${kn(t)}`).join("&")}function vn(n){let e="";for(let B of n)e+=B.toString(16).padStart(2,"0");return e}async function Jn(n){let e=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(n));return vn(new Uint8Array(e))}var Vn="e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";function Kn(n){return [n.method,n.path,n.canonicalQuery,n.installRepo,n.bodyHash,String(n.timestamp)].join(`
18
- `)}async function ds(n,e){let B=new TextEncoder,t=await crypto.subtle.importKey("raw",B.encode(n),{name:"HMAC",hash:"SHA-256"},false,["sign"]),r=await crypto.subtle.sign("HMAC",t,B.encode(e));return vn(new Uint8Array(r))}var ms=/^sha256=([0-9a-f]{64})$/,Ss=300;async function Os(n){let e=ms.exec(n.signature);if(!e)return {ok:false,reason:"invalid-format"};let B=e[1],t=n.toleranceSec??Ss;if(Math.abs(n.nowUnixSeconds-n.timestamp)>t)return {ok:false,reason:"expired"};let i=n.body.length===0?Vn:await Jn(n.body),s=Kn({method:n.method,path:n.path,canonicalQuery:Un(n.query),installRepo:n.installRepo,bodyHash:i,timestamp:n.timestamp}),o=await ds(n.secret,s);return As(B,o)?{ok:true}:{ok:false,reason:"invalid-signature"}}function As(n,e){if(n.length!==e.length)return false;let B=0;for(let t=0;t<n.length;t++)B|=n.charCodeAt(t)^e.charCodeAt(t);return B===0}var nB="org.member_added",rB="org.repo_created",iB="org.repo_published",Is="org.service_account_created",Ts="org.service_account_role_changed",Rs="org.service_account_disabled",Ns="org.service_account_enabled",_s="org.service_account_deleted",sB=[Is,Ts,Rs,Ns,_s];var Yn="commit",Wn="repo.renamed",$B="org.renamed",jn="thing.renamed",Qn="shape.renamed",$n=[Yn,Wn,$B,nB,rB,iB,...sB,jn,Qn];function Fs(n){return $n.includes(n)}var qn=["ready","degraded"];function Ls(n){return qn.includes(n)}var zn=["repo:read","repo:checkpoint-read","repo:checkpoint-generate","repo:write","repo:configure","repo:admin","repo:action-callback"];function bs(n){return zn.includes(n)}var er=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;function ws(n){return er.test(n)?n:null}function Xn(n){let e=er.exec(n);return {major:Number(e[1]),minor:Number(e[2]),patch:Number(e[3]),prerelease:e[4]?e[4].split("."):[]}}var Zn=/^(0|[1-9]\d*)$/;function xs(n,e){if(n.length===0&&e.length===0)return 0;if(n.length===0)return 1;if(e.length===0)return -1;let B=Math.min(n.length,e.length);for(let t=0;t<B;t++){let r=n[t],i=e[t];if(r===void 0||i===void 0)break;if(r===i)continue;let s=Zn.test(r),o=Zn.test(i);return s&&o?Number(r)<Number(i)?-1:1:s?-1:o?1:r<i?-1:1}return n.length===e.length?0:n.length<e.length?-1:1}function Ps(n,e){let B=Xn(n),t=Xn(e);return B.major!==t.major?B.major<t.major?-1:1:B.minor!==t.minor?B.minor<t.minor?-1:1:B.patch!==t.patch?B.patch<t.patch?-1:1:xs(B.prerelease,t.prerelease)}var Br=["initiated","active","uninstalled"];function Gs(n){return Br.includes(n)}var tr=["org","repo"];function Hs(n){return tr.includes(n)}var nr=["repo","component"];function Ms(n){return nr.includes(n)}var rr=["repo","component","skill"];function ks(n){return rr.includes(n)}var ir=["org:read","org:configure","org:admin","org:action-callback"];function Us(n){return ir.includes(n)}var vs="003e7e6c-2f1e-53ea-9dfa-627edd04a8cc",Js=/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;function sr(n){if(!Js.test(n))throw new Error("Operation-event submission ID must be a canonical UUID");let e=n.toLowerCase().replaceAll("-","");return Uint8Array.from({length:16},(B,t)=>Number.parseInt(e.slice(t*2,t*2+2),16))}function qB(n,e){return (n<<e|n>>>32-e)>>>0}function Vs(n){let e=n.length*8,B=Math.ceil((n.length+9)/64)*64,t=new Uint8Array(B);t.set(n),t[n.length]=128;let r=new DataView(t.buffer);r.setUint32(B-8,Math.floor(e/4294967296)),r.setUint32(B-4,e>>>0);let i=1732584193,s=4023233417,o=2562383102,C=271733878,u=3285377520,c=new Uint32Array(80);for(let g=0;g<B;g+=64){for(let x=0;x<16;x+=1)c[x]=r.getUint32(g+x*4);for(let x=16;x<80;x+=1)c[x]=qB((c[x-3]??0)^(c[x-8]??0)^(c[x-14]??0)^(c[x-16]??0),1);let m=i,S=s,R=o,N=C,b=u;for(let x=0;x<80;x+=1){let W,ee;x<20?(W=S&R|~S&N,ee=1518500249):x<40?(W=S^R^N,ee=1859775393):x<60?(W=S&R|S&N|R&N,ee=2400959708):(W=S^R^N,ee=3395469782);let ie=qB(m,5)+W+b+ee+(c[x]??0)>>>0;b=N,N=R,R=qB(S,30),S=m,m=ie;}i=i+m>>>0,s=s+S>>>0,o=o+R>>>0,C=C+N>>>0,u=u+b>>>0;}let E=new Uint8Array(20),h=new DataView(E.buffer);for(let[g,m]of [i,s,o,C,u].entries())h.setUint32(g*4,m);return E}function Ks(n){let e=Array.from(n,B=>B.toString(16).padStart(2,"0")).join("").slice(0,32);return `${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`}function Ys(n,e){if(!Number.isInteger(e)||e<0||e>2147483647)throw new Error("Stream chunk ordinal must be an integer from 0 through 2147483647");sr(n);let B=n.toLowerCase(),t=sr(vs),r=new TextEncoder().encode(`${B}:${e}`),i=Vs(Uint8Array.from([...t,...r])).slice(0,16);return i[6]=(i[6]??0)&15|80,i[8]=(i[8]??0)&63|128,Ks(i)}var or=["active","pending"];function Ws(n){return or.includes(n)}var Cr=["owner","admin","editor","viewer"];function js(n){return Cr.includes(n)}var zB=["Arc","Bond","Pair","Set","List"],ar=["Triple"],Qs=["Arc","Bond"],$s=["Set","List"],lr=[...Qs,...$s],cr=["Collection",...lr],qs=[...zB,...ar];function ur(n){return zB.includes(n)}function ke(n){return ar.includes(n)}function pr(n){return lr.includes(n)}function Ue(n){return cr.includes(n)}function ve(n){return qs.includes(n)}var zs=["Content"];var Xs=["Readme","Agents"],Zs=["LlmsTxt"],XB=n=>n==="Content";var ZB=n=>Xs.includes(n),et=n=>Zs.includes(n);var Er=["View"],eo=n=>Er.includes(n),hr=["LicenseSubject","LicenseDeclaration"],Bo=n=>hr.includes(n);function fr(n){return ve(n)||Ue(n)||eo(n)||Bo(n)}function Je(n){return zB.includes(n)||zs.includes(n)||Er.includes(n)||hr.includes(n)}var De={Collection:{fields:{}},Arc:{fields:{from:{type:"wref",binding:"either"},to:{type:"wref",binding:"either"}},composes:["Collection"]},Bond:{fields:{ends:{type:"array",items:{type:"wref",binding:"either"},minItems:2,maxItems:2}},composes:["Collection"]},Set:{fields:{members:{type:"array",items:{type:"wref",binding:"either"},minItems:1}},composes:["Collection"]},List:{fields:{items:{type:"array",items:{type:"wref",binding:"either"},minItems:1}},composes:["Collection"]}};var tt="com.warmhub.system";var oo={componentId:"string",name:"string",version:"string",source:"string","sourceKind?":"string","sourceRef?":"string","resolvedSha?":"string","registeredComponentRef?":"string",manifestHash:"string",state:"string",manifest:"string",installedAt:"string",installedByUserId:"string?","installId?":"string","updatedAt?":"string"},Co={};var gr={about:"wref"},Dr="CorrectedThing",ao={correctionLog:{type:"array",items:{reason:"string"},minItems:1}},dr="RedactedThing",mr={},Sr="File",Or={};var Bt=[{name:"ComponentInstall",fields:oo,installInfra:true},{name:"ComponentConfig",fields:Co,installInfra:true},{name:"Collection",...De.Collection},{name:"Arc",...De.Arc},{name:"Bond",...De.Bond},{name:"Set",...De.Set},{name:"List",...De.List},{name:"Assertion",fields:gr,priorVersions:[{fields:{}}]},{name:Dr,fields:ao,onDemand:true},{name:dr,fields:mr,onDemand:true,systemOnlyCertification:true},{name:Sr,fields:Or,onDemand:true}],de={component:{id:tt,name:"system",version:"1.0.0"},shapes:Bt.map(({name:n,fields:e,composes:B})=>({name:n,fields:e,...B?{composes:B}:{}})),credentials:[],subscriptions:[],seeds:[],health:{requires:{shapes:Bt.map(n=>n.name)}},teardown:{},runtimeAccess:{reads:[],writes:[]}};new Set(de.shapes.map(n=>n.name));var oB={componentId:tt,name:de.component.name,version:de.component.version,manifest:de,shapes:Bt};var lo=[oB],co=oB.shapes.filter(n=>n.installInfra!==true);co.filter(n=>n.onDemand!==true);new Set(lo.flatMap(n=>n.shapes.filter(e=>e.installInfra===true).map(e=>e.name)));var uo=new Set(de.shapes.map(n=>n.name));new Set(oB.shapes.filter(n=>n.systemOnlyCertification===true).map(n=>n.name));function Ar(n){return uo.has(n)}var Ir=["set","list"],po=["add","revise"];function nt(n){return `Collection "type" is invalid. Use one of: ${Ir.join(", ")}. Got: "${n}".`}var rt="Collection create requires a name. Collections are ordinary named things (ADR 0004).",it='about accepts a wref. Create the collection as its own named operation, then point the assertion at it. Prefer deterministic relationship names, for example: [{"operation":"add","name":"a-to-b","shapes":["Arc"],"data":{"from":"a","to":"b"}},{"operation":"add","name":"example","shapes":["Assertion"],"data":{"about":"a-to-b"}}]. For CLI usage, use wh commit submit --file with the two operations.';function Eo(n){return Ir.find(e=>e===n)??null}function ho(n){return n==null?"":typeof n=="string"||typeof n=="number"||typeof n=="boolean"||typeof n=="bigint"?String(n):Array.isArray(n)?"array":typeof n}function fo(n){return po.find(e=>e===n)??null}function Tr(n,e){let B=[];return B.push(...go(n,e)),B.push(...Do(n,e)),B.push(...mo(n,e)),B.push(...So(n,e)),B.push(...Ao(n,e)),B.push(...Io(n,e)),B.push(...To(n,e)),B}function go(n,e){let B=[],t=Ve(n)&&n.name?se(n.name):void 0,r=n.operation==="rename"&&Ve(n),i=n.operation==="restore"&&n.newName!==void 0&&re(n.newName),s=r||i,o=s&&n.newName?se(n.newName):void 0,C=n.operation==="add"?"created":n.operation==="rename"?"renamed":n.operation==="restore"?"restored":"revised",u=r&&t!==void 0&&fr(t)&&o!==void 0&&!ve(o)&&!Je(o);if(t&&ke(t)&&!u&&B.push({code:"RESERVED_NAME",operationIndex:e,message:`Shape "${t}" is a retired collection shape and cannot be written manually`}),o&&ke(o))B.push({code:"RESERVED_NAME",operationIndex:e,message:`Shape "${o}" is a retired collection shape and cannot be written manually`});else {let g=t&&(Je(t)||Ue(t))&&!u?t:o&&(Je(o)||Ue(o))?o:void 0;g&&(s||n.operation==="add"||n.operation==="revise")&&B.push({code:"RESERVED_NAME",operationIndex:e,message:`Shape "${g}" is a built-in shape and cannot be ${C} manually`});}let c=n.operation==="add"?t:s?o:void 0;c&&Ar(c)&&!Je(c)&&!Ue(c)&&B.push({code:"RESERVED_NAME",operationIndex:e,message:`Shape "${c}" is a system shape and cannot be ${C} manually`});let E=lB(n)?.shapes.find(ke);n.operation==="add"&&E!==void 0&&B.push({code:"VALIDATION_ERROR",operationIndex:e,message:`Cannot add under retired collection shape "${E}". Triple is read-only and retired for new collection writes.`});let h=aB(n);if(h&&ke(h.shapePrefix))B.push({code:"VALIDATION_ERROR",operationIndex:e,message:`Cannot add under retired collection shape "${h.shapePrefix}". Triple is read-only and retired for new collection writes.`});else if(n.kind==="thing"&&h&&(ur(h.shapePrefix)&&!pr(h.shapePrefix)||h.shapePrefix==="Collection")){let g=h.shapePrefix==="Collection",m=g?"Collection is abstract: name the Thing and state a concrete collection Shape (Arc, Bond, Set, List or Pair) instead":"Name the Thing and state the Shape instead",S=g?"Set":h.shapePrefix;B.push({code:"VALIDATION_ERROR",operationIndex:e,message:`Cannot add kind="thing" under built-in shape "${h.shapePrefix}". ${m}: {"operation":"add","name":"${h.bareName}","shapes":["${S}"],"data":{\u2026}}`});}return B}function st(n){return `Cannot add a Thing that declares the abstract built-in shape "Collection". State a concrete collection Shape (Arc, Bond, Set, List or Pair) instead: {"operation":"add","name":"${n}","shapes":["Set"],"data":{\u2026}}`}function ot(n){return `Content "${n}" is synthesized; writes are not allowed`}function Ct(n){return `Content "${n}" is not a recognized well-known content name`}function Do(n,e){return lB(n)?.shapes.includes("Collection")?[{code:"VALIDATION_ERROR",operationIndex:e,message:st(n.name??"")}]:[]}function Ve(n){return n.kind==="shape"||n.operation!=="add"&&n.name!==void 0&&re(n.name)}function aB(n){return n.operation!=="add"||!n.name||Ve(n)||n.kind==="collection"||n.declaredShapes!==void 0?null:QB(n.name)}function lB(n){return n.declaredShapes===void 0||!n.name||Ve(n)||n.operation!=="add"&&n.operation!=="revise"?null:{shapes:n.declaredShapes.map(e=>se(e.replace(/@.*$/,""))),name:n.name}}function CB(n,e){return {code:"RESERVED_NAME",operationIndex:e,message:bB(n)}}function mo(n,e){if(Ve(n)){let B=n.operation==="add"?n.name:n.operation==="rename"?n.newName:void 0;return B!==void 0&&We(se(B))?[CB(B,e)]:[]}if(n.operation==="add"&&n.name){let B=n.kind==="collection"||n.declaredShapes!==void 0?n.name:aB(n)?.bareName;return B!==void 0&&Te(B)?[CB(B,e)]:[]}return n.operation==="rename"&&n.newName!==void 0&&Te(n.newName)?[CB(n.newName,e)]:n.operation==="restore"&&n.newName!==void 0?(re(n.newName)?We(se(n.newName)):Te(n.newName))?[CB(n.newName,e)]:[]:[]}function So(n,e){if(n.kind!=="thing")return [];let B=lB(n);if(B)return Oo(B,e);let t=aB(n);if(!t||!XB(t.shapePrefix))return [];let r=t.bareName;return et(r)?[{code:"READ_ONLY_BUILTIN_CONTENT",operationIndex:e,message:`${t.shapePrefix} "${r}" is synthesized; writes are not allowed`}]:ZB(r)?[]:[{code:"UNKNOWN_CONTENT_NAME",operationIndex:e,message:`${t.shapePrefix} "${r}" is not a recognized well-known content name`}]}function Oo({shapes:n,name:e},B){return n.some(XB)?et(e)?[{code:"READ_ONLY_BUILTIN_CONTENT",operationIndex:B,message:ot(e)}]:ZB(e)?[]:[{code:"UNKNOWN_CONTENT_NAME",operationIndex:B,message:Ct(e)}]:[]}function Ao(n,e){let B=[],t=n.name;if(n.newName?.includes("+"))return B.push({code:"VALIDATION_ERROR",operationIndex:e,message:`Name "${n.newName}" contains reserved character "+". The "+" character is reserved for the historical collection auto-name namespace and is not allowed in user-supplied names.`}),B;if(t?.includes("+")){if(n.kind==="collection"&&n.operation==="add")return B.push({code:"VALIDATION_ERROR",operationIndex:e,message:`Name "${t}" contains reserved character "+". The "+" character is reserved for the historical collection auto-name namespace and is not allowed in user-supplied names.`}),B;if(n.kind==="collection"||n.operation!=="add")return B;let r=aB(n);if(r&&ve(r.shapePrefix)||lB(n)?.shapes.some(ve))return B;B.push({code:"VALIDATION_ERROR",operationIndex:e,message:`Name "${t}" contains reserved character "+". The "+" character is reserved for the historical collection auto-name namespace and is not allowed in user-supplied names.`});}return B}function Io(n,e){let B=[];return !n.about||typeof n.about=="string"||B.push({code:"VALIDATION_ERROR",operationIndex:e,message:it}),B}function To(n,e){let B=[];if(n.kind!=="collection"||fo(n.operation)===null)return B;let t=Eo(n.type);n.operation==="add"&&!n.name&&B.push({code:"VALIDATION_ERROR",operationIndex:e,message:rt}),t===null&&B.push({code:"VALIDATION_ERROR",operationIndex:e,message:nt(ho(n.type))});let r=Array.isArray(n.members)?n.members:null;if(r===null)B.push({code:"VALIDATION_ERROR",operationIndex:e,message:'Collection requires a "members" array'});else for(let i=0;i<r.length;i++)typeof r[i]!="string"&&B.push({code:"VALIDATION_ERROR",operationIndex:e,message:`Collection member at index ${i} must be a string`});if(t!==null&&r!==null){let i=Ro(t,r);i&&B.push({code:"VALIDATION_ERROR",operationIndex:e,message:i});}return B}function Ro(n,e){switch(n){case "set":case "list":return e.length<1?`${n==="set"?"Set":"List"} requires at least 1 member, got 0`:null;default:return n}}function No(n,e){return Tr(n,e)}var _o=new TextEncoder;async function cB(n){let e=new Uint8Array(await crypto.subtle.digest("SHA-256",Uint8Array.from(n)));return Array.from(e,B=>B.toString(16).padStart(2,"0")).join("")}function Ke(n){return te(n),_o.encode(n)}function te(n){for(let e=0;e<n.length;e+=1){let B=n.charCodeAt(e);if(B>=55296&&B<=56319){let t=n.charCodeAt(e+1);if(!(t>=56320&&t<=57343))throw new RangeError("Checkpoint text must be valid Unicode");e+=1;}else if(B>=56320&&B<=57343)throw new RangeError("Checkpoint text must be valid Unicode")}}function ne(n,e){te(n),te(e);let B=0,t=0;for(;B<n.length&&t<e.length;){let r=n.codePointAt(B),i=e.codePointAt(t);if(r===void 0||i===void 0)break;let s=r-i;if(s!==0)return s;B+=r>65535?2:1,t+=i>65535?2:1;}return B===n.length&&t===e.length?0:B===n.length?-1:1}var lt=67108864,pB=10,Nr="warmhub-repository-checkpoint",_r=4,Fo="repository-checkpoint.json";var Fr="application/json",yr="application/zip",Lr="application/x-ndjson",br=[yr,Fr,Lr];function yo(n){return br.includes(n)}var ct=z$1.string().regex(/^[0-9a-f]{64}$/),uB=z$1.number().int().nonnegative(),at=z$1.number().int().positive(),Lo=z$1.number().refine(n=>!Number.isInteger(n)||Number.isSafeInteger(n),"JSON integers must be safe integers"),me=z$1.lazy(()=>z$1.union([z$1.null(),z$1.boolean(),Lo,z$1.string(),z$1.array(me),z$1.record(z$1.string(),me)])),Rr=z$1.object({wref:z$1.string().min(1),durableId:z$1.string().min(1),version:z$1.number().int().positive(),active:z$1.literal(true),data:me}),wr=z$1.string().regex(/^[^\r\n]+@v[1-9]\d*(?![\s\S])/,"Checkpoint wref must be pinned with @vN"),bo=z$1.array(wr).superRefine((n,e)=>{for(let B=1;B<n.length;B+=1){let t=n[B-1],r=n[B];t!==void 0&&r!==void 0&&ne(t,r)>=0&&e.addIssue({code:"custom",path:[B],message:"Affirmed wrefs must be unique and strictly increasing"});}}),xr=z$1.array(z$1.object({shape:z$1.string().min(1),memberCount:uB}).strict()).min(1),ut=z$1.discriminatedUnion("kind",[Rr.extend({kind:z$1.literal("shape")}).strict(),Rr.extend({kind:z$1.literal("thing"),shapeName:z$1.string().min(1),collections:xr.optional(),aboutWref:wr.optional(),affirmedWrefs:bo.optional()}).strict().refine(n=>n.aboutWref===void 0==(n.affirmedWrefs===void 0),{message:"A checkpoint row carries aboutWref and affirmedWrefs together or not at all",path:["affirmedWrefs"]})]),Pr=z$1.object({part:uB,path:z$1.string().min(1),recordCount:at,byteLength:at,sha256:ct}).strict(),Gr=z$1.object({shapeName:z$1.string().min(1),recordCount:at,chunks:z$1.array(Pr).min(1)}).strict(),wo={format:z$1.literal(Nr),formatVersion:z$1.literal(_r),checkpointId:z$1.uuid(),repository:z$1.object({id:z$1.uuid(),org:z$1.string().min(1),repo:z$1.string().min(1)}).strict(),repoSeq:uB,complete:z$1.literal(true),recordCount:uB,streams:z$1.array(Gr)},pt=z$1.object(wo).strict(),EB=pt.extend({contentSha256:ct}).strict();function pe(n){if(!n||typeof n!="object")return JSON.stringify(n);if(Array.isArray(n))return `[${n.map(B=>pe(B)).join(",")}]`;let e=n;return `{${Object.keys(e).sort().map(B=>`${JSON.stringify(B)}:${pe(e[B])}`).join(",")}}`}new TextEncoder;var xo=new TextDecoder("utf-8",{fatal:true});function Et(n,e){if(n.length===0||n.at(-1)!==10)throw new Error(`${e} must end with one LF`);if(n.length>=3&&n[0]===239&&n[1]===187&&n[2]===191)throw new Error(`${e} must not contain a UTF-8 BOM`);for(let B=0;B<n.length-1;B+=1)if(n[B]===10||n[B]===13)throw new Error(`${e} must contain exactly one LF and no CR`)}function Se(n,e,B){Et(n,B);let t=xo.decode(n),r=e.parse(JSON.parse(t.slice(0,-1)));if(t!==`${pe(r)}
18
+ `)}async function ds(n,e){let B=new TextEncoder,t=await crypto.subtle.importKey("raw",B.encode(n),{name:"HMAC",hash:"SHA-256"},false,["sign"]),r=await crypto.subtle.sign("HMAC",t,B.encode(e));return vn(new Uint8Array(r))}var ms=/^sha256=([0-9a-f]{64})$/,Ss=300;async function Os(n){let e=ms.exec(n.signature);if(!e)return {ok:false,reason:"invalid-format"};let B=e[1],t=n.toleranceSec??Ss;if(Math.abs(n.nowUnixSeconds-n.timestamp)>t)return {ok:false,reason:"expired"};let i=n.body.length===0?Vn:await Jn(n.body),s=Kn({method:n.method,path:n.path,canonicalQuery:Un(n.query),installRepo:n.installRepo,bodyHash:i,timestamp:n.timestamp}),o=await ds(n.secret,s);return As(B,o)?{ok:true}:{ok:false,reason:"invalid-signature"}}function As(n,e){if(n.length!==e.length)return false;let B=0;for(let t=0;t<n.length;t++)B|=n.charCodeAt(t)^e.charCodeAt(t);return B===0}var nB="org.member_added",rB="org.repo_created",iB="org.repo_published",Is="org.service_account_created",Ts="org.service_account_role_changed",Rs="org.service_account_disabled",Ns="org.service_account_enabled",_s="org.service_account_deleted",sB=[Is,Ts,Rs,Ns,_s];var Yn="commit",Wn="repo.renamed",$B="org.renamed",jn="thing.renamed",Qn="shape.renamed",$n=[Yn,Wn,$B,nB,rB,iB,...sB,jn,Qn];function Fs(n){return $n.includes(n)}var qn=["ready","degraded"];function Ls(n){return qn.includes(n)}var zn=["repo:read","repo:checkpoint-read","repo:checkpoint-generate","repo:write","repo:configure","repo:admin","repo:action-callback"];function bs(n){return zn.includes(n)}var er=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;function ws(n){return er.test(n)?n:null}function Xn(n){let e=er.exec(n);return {major:Number(e[1]),minor:Number(e[2]),patch:Number(e[3]),prerelease:e[4]?e[4].split("."):[]}}var Zn=/^(0|[1-9]\d*)$/;function xs(n,e){if(n.length===0&&e.length===0)return 0;if(n.length===0)return 1;if(e.length===0)return -1;let B=Math.min(n.length,e.length);for(let t=0;t<B;t++){let r=n[t],i=e[t];if(r===void 0||i===void 0)break;if(r===i)continue;let s=Zn.test(r),o=Zn.test(i);return s&&o?Number(r)<Number(i)?-1:1:s?-1:o?1:r<i?-1:1}return n.length===e.length?0:n.length<e.length?-1:1}function Ps(n,e){let B=Xn(n),t=Xn(e);return B.major!==t.major?B.major<t.major?-1:1:B.minor!==t.minor?B.minor<t.minor?-1:1:B.patch!==t.patch?B.patch<t.patch?-1:1:xs(B.prerelease,t.prerelease)}var Br=["initiated","active","uninstalled"];function Gs(n){return Br.includes(n)}var tr=["org","repo"];function Hs(n){return tr.includes(n)}var nr=["repo","component"];function Ms(n){return nr.includes(n)}var rr=["repo","component","skill"];function ks(n){return rr.includes(n)}var ir=["org:read","org:configure","org:admin","org:action-callback","org:hub-curate"];function Us(n){return ir.includes(n)}var vs="003e7e6c-2f1e-53ea-9dfa-627edd04a8cc",Js=/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;function sr(n){if(!Js.test(n))throw new Error("Operation-event submission ID must be a canonical UUID");let e=n.toLowerCase().replaceAll("-","");return Uint8Array.from({length:16},(B,t)=>Number.parseInt(e.slice(t*2,t*2+2),16))}function qB(n,e){return (n<<e|n>>>32-e)>>>0}function Vs(n){let e=n.length*8,B=Math.ceil((n.length+9)/64)*64,t=new Uint8Array(B);t.set(n),t[n.length]=128;let r=new DataView(t.buffer);r.setUint32(B-8,Math.floor(e/4294967296)),r.setUint32(B-4,e>>>0);let i=1732584193,s=4023233417,o=2562383102,C=271733878,u=3285377520,c=new Uint32Array(80);for(let g=0;g<B;g+=64){for(let x=0;x<16;x+=1)c[x]=r.getUint32(g+x*4);for(let x=16;x<80;x+=1)c[x]=qB((c[x-3]??0)^(c[x-8]??0)^(c[x-14]??0)^(c[x-16]??0),1);let m=i,S=s,R=o,N=C,b=u;for(let x=0;x<80;x+=1){let W,ee;x<20?(W=S&R|~S&N,ee=1518500249):x<40?(W=S^R^N,ee=1859775393):x<60?(W=S&R|S&N|R&N,ee=2400959708):(W=S^R^N,ee=3395469782);let ie=qB(m,5)+W+b+ee+(c[x]??0)>>>0;b=N,N=R,R=qB(S,30),S=m,m=ie;}i=i+m>>>0,s=s+S>>>0,o=o+R>>>0,C=C+N>>>0,u=u+b>>>0;}let E=new Uint8Array(20),h=new DataView(E.buffer);for(let[g,m]of [i,s,o,C,u].entries())h.setUint32(g*4,m);return E}function Ks(n){let e=Array.from(n,B=>B.toString(16).padStart(2,"0")).join("").slice(0,32);return `${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`}function Ys(n,e){if(!Number.isInteger(e)||e<0||e>2147483647)throw new Error("Stream chunk ordinal must be an integer from 0 through 2147483647");sr(n);let B=n.toLowerCase(),t=sr(vs),r=new TextEncoder().encode(`${B}:${e}`),i=Vs(Uint8Array.from([...t,...r])).slice(0,16);return i[6]=(i[6]??0)&15|80,i[8]=(i[8]??0)&63|128,Ks(i)}var or=["active","pending"];function Ws(n){return or.includes(n)}var Cr=["owner","admin","editor","viewer"];function js(n){return Cr.includes(n)}var zB=["Arc","Bond","Pair","Set","List"],ar=["Triple"],Qs=["Arc","Bond"],$s=["Set","List"],lr=[...Qs,...$s],cr=["Collection",...lr],qs=[...zB,...ar];function ur(n){return zB.includes(n)}function ke(n){return ar.includes(n)}function pr(n){return lr.includes(n)}function Ue(n){return cr.includes(n)}function ve(n){return qs.includes(n)}var zs=["Content"];var Xs=["Readme","Agents"],Zs=["LlmsTxt"],XB=n=>n==="Content";var ZB=n=>Xs.includes(n),et=n=>Zs.includes(n);var Er=["View"],eo=n=>Er.includes(n),hr=["LicenseSubject","LicenseDeclaration"],Bo=n=>hr.includes(n);function fr(n){return ve(n)||Ue(n)||eo(n)||Bo(n)}function Je(n){return zB.includes(n)||zs.includes(n)||Er.includes(n)||hr.includes(n)}var De={Collection:{fields:{}},Arc:{fields:{from:{type:"wref",binding:"either"},to:{type:"wref",binding:"either"}},composes:["Collection"]},Bond:{fields:{ends:{type:"array",items:{type:"wref",binding:"either"},minItems:2,maxItems:2}},composes:["Collection"]},Set:{fields:{members:{type:"array",items:{type:"wref",binding:"either"},minItems:1}},composes:["Collection"]},List:{fields:{items:{type:"array",items:{type:"wref",binding:"either"},minItems:1}},composes:["Collection"]}};var tt="com.warmhub.system";var oo={componentId:"string",name:"string",version:"string",source:"string","sourceKind?":"string","sourceRef?":"string","resolvedSha?":"string","registeredComponentRef?":"string",manifestHash:"string",state:"string",manifest:"string",installedAt:"string",installedByUserId:"string?","installId?":"string","updatedAt?":"string"},Co={};var gr={about:"wref"},Dr="CorrectedThing",ao={correctionLog:{type:"array",items:{reason:"string"},minItems:1}},dr="RedactedThing",mr={},Sr="File",Or={};var Bt=[{name:"ComponentInstall",fields:oo,installInfra:true},{name:"ComponentConfig",fields:Co,installInfra:true},{name:"Collection",...De.Collection},{name:"Arc",...De.Arc},{name:"Bond",...De.Bond},{name:"Set",...De.Set},{name:"List",...De.List},{name:"Assertion",fields:gr,priorVersions:[{fields:{}}]},{name:Dr,fields:ao,onDemand:true},{name:dr,fields:mr,onDemand:true,systemOnlyCertification:true},{name:Sr,fields:Or,onDemand:true}],de={component:{id:tt,name:"system",version:"1.0.0"},shapes:Bt.map(({name:n,fields:e,composes:B})=>({name:n,fields:e,...B?{composes:B}:{}})),credentials:[],subscriptions:[],seeds:[],health:{requires:{shapes:Bt.map(n=>n.name)}},teardown:{},runtimeAccess:{reads:[],writes:[]}};new Set(de.shapes.map(n=>n.name));var oB={componentId:tt,name:de.component.name,version:de.component.version,manifest:de,shapes:Bt};var lo=[oB],co=oB.shapes.filter(n=>n.installInfra!==true);co.filter(n=>n.onDemand!==true);new Set(lo.flatMap(n=>n.shapes.filter(e=>e.installInfra===true).map(e=>e.name)));var uo=new Set(de.shapes.map(n=>n.name));new Set(oB.shapes.filter(n=>n.systemOnlyCertification===true).map(n=>n.name));function Ar(n){return uo.has(n)}var Ir=["set","list"],po=["add","revise"];function nt(n){return `Collection "type" is invalid. Use one of: ${Ir.join(", ")}. Got: "${n}".`}var rt="Collection create requires a name. Collections are ordinary named things (ADR 0004).",it='about accepts a wref. Create the collection as its own named operation, then point the assertion at it. Prefer deterministic relationship names, for example: [{"operation":"add","name":"a-to-b","shapes":["Arc"],"data":{"from":"a","to":"b"}},{"operation":"add","name":"example","shapes":["Assertion"],"data":{"about":"a-to-b"}}]. For CLI usage, use wh commit submit --file with the two operations.';function Eo(n){return Ir.find(e=>e===n)??null}function ho(n){return n==null?"":typeof n=="string"||typeof n=="number"||typeof n=="boolean"||typeof n=="bigint"?String(n):Array.isArray(n)?"array":typeof n}function fo(n){return po.find(e=>e===n)??null}function Tr(n,e){let B=[];return B.push(...go(n,e)),B.push(...Do(n,e)),B.push(...mo(n,e)),B.push(...So(n,e)),B.push(...Ao(n,e)),B.push(...Io(n,e)),B.push(...To(n,e)),B}function go(n,e){let B=[],t=Ve(n)&&n.name?se(n.name):void 0,r=n.operation==="rename"&&Ve(n),i=n.operation==="restore"&&n.newName!==void 0&&re(n.newName),s=r||i,o=s&&n.newName?se(n.newName):void 0,C=n.operation==="add"?"created":n.operation==="rename"?"renamed":n.operation==="restore"?"restored":"revised",u=r&&t!==void 0&&fr(t)&&o!==void 0&&!ve(o)&&!Je(o);if(t&&ke(t)&&!u&&B.push({code:"RESERVED_NAME",operationIndex:e,message:`Shape "${t}" is a retired collection shape and cannot be written manually`}),o&&ke(o))B.push({code:"RESERVED_NAME",operationIndex:e,message:`Shape "${o}" is a retired collection shape and cannot be written manually`});else {let g=t&&(Je(t)||Ue(t))&&!u?t:o&&(Je(o)||Ue(o))?o:void 0;g&&(s||n.operation==="add"||n.operation==="revise")&&B.push({code:"RESERVED_NAME",operationIndex:e,message:`Shape "${g}" is a built-in shape and cannot be ${C} manually`});}let c=n.operation==="add"?t:s?o:void 0;c&&Ar(c)&&!Je(c)&&!Ue(c)&&B.push({code:"RESERVED_NAME",operationIndex:e,message:`Shape "${c}" is a system shape and cannot be ${C} manually`});let E=lB(n)?.shapes.find(ke);n.operation==="add"&&E!==void 0&&B.push({code:"VALIDATION_ERROR",operationIndex:e,message:`Cannot add under retired collection shape "${E}". Triple is read-only and retired for new collection writes.`});let h=aB(n);if(h&&ke(h.shapePrefix))B.push({code:"VALIDATION_ERROR",operationIndex:e,message:`Cannot add under retired collection shape "${h.shapePrefix}". Triple is read-only and retired for new collection writes.`});else if(n.kind==="thing"&&h&&(ur(h.shapePrefix)&&!pr(h.shapePrefix)||h.shapePrefix==="Collection")){let g=h.shapePrefix==="Collection",m=g?"Collection is abstract: name the Thing and state a concrete collection Shape (Arc, Bond, Set, List or Pair) instead":"Name the Thing and state the Shape instead",S=g?"Set":h.shapePrefix;B.push({code:"VALIDATION_ERROR",operationIndex:e,message:`Cannot add kind="thing" under built-in shape "${h.shapePrefix}". ${m}: {"operation":"add","name":"${h.bareName}","shapes":["${S}"],"data":{\u2026}}`});}return B}function st(n){return `Cannot add a Thing that declares the abstract built-in shape "Collection". State a concrete collection Shape (Arc, Bond, Set, List or Pair) instead: {"operation":"add","name":"${n}","shapes":["Set"],"data":{\u2026}}`}function ot(n){return `Content "${n}" is synthesized; writes are not allowed`}function Ct(n){return `Content "${n}" is not a recognized well-known content name`}function Do(n,e){return lB(n)?.shapes.includes("Collection")?[{code:"VALIDATION_ERROR",operationIndex:e,message:st(n.name??"")}]:[]}function Ve(n){return n.kind==="shape"||n.operation!=="add"&&n.name!==void 0&&re(n.name)}function aB(n){return n.operation!=="add"||!n.name||Ve(n)||n.kind==="collection"||n.declaredShapes!==void 0?null:QB(n.name)}function lB(n){return n.declaredShapes===void 0||!n.name||Ve(n)||n.operation!=="add"&&n.operation!=="revise"?null:{shapes:n.declaredShapes.map(e=>se(e.replace(/@.*$/,""))),name:n.name}}function CB(n,e){return {code:"RESERVED_NAME",operationIndex:e,message:bB(n)}}function mo(n,e){if(Ve(n)){let B=n.operation==="add"?n.name:n.operation==="rename"?n.newName:void 0;return B!==void 0&&We(se(B))?[CB(B,e)]:[]}if(n.operation==="add"&&n.name){let B=n.kind==="collection"||n.declaredShapes!==void 0?n.name:aB(n)?.bareName;return B!==void 0&&Te(B)?[CB(B,e)]:[]}return n.operation==="rename"&&n.newName!==void 0&&Te(n.newName)?[CB(n.newName,e)]:n.operation==="restore"&&n.newName!==void 0?(re(n.newName)?We(se(n.newName)):Te(n.newName))?[CB(n.newName,e)]:[]:[]}function So(n,e){if(n.kind!=="thing")return [];let B=lB(n);if(B)return Oo(B,e);let t=aB(n);if(!t||!XB(t.shapePrefix))return [];let r=t.bareName;return et(r)?[{code:"READ_ONLY_BUILTIN_CONTENT",operationIndex:e,message:`${t.shapePrefix} "${r}" is synthesized; writes are not allowed`}]:ZB(r)?[]:[{code:"UNKNOWN_CONTENT_NAME",operationIndex:e,message:`${t.shapePrefix} "${r}" is not a recognized well-known content name`}]}function Oo({shapes:n,name:e},B){return n.some(XB)?et(e)?[{code:"READ_ONLY_BUILTIN_CONTENT",operationIndex:B,message:ot(e)}]:ZB(e)?[]:[{code:"UNKNOWN_CONTENT_NAME",operationIndex:B,message:Ct(e)}]:[]}function Ao(n,e){let B=[],t=n.name;if(n.newName?.includes("+"))return B.push({code:"VALIDATION_ERROR",operationIndex:e,message:`Name "${n.newName}" contains reserved character "+". The "+" character is reserved for the historical collection auto-name namespace and is not allowed in user-supplied names.`}),B;if(t?.includes("+")){if(n.kind==="collection"&&n.operation==="add")return B.push({code:"VALIDATION_ERROR",operationIndex:e,message:`Name "${t}" contains reserved character "+". The "+" character is reserved for the historical collection auto-name namespace and is not allowed in user-supplied names.`}),B;if(n.kind==="collection"||n.operation!=="add")return B;let r=aB(n);if(r&&ve(r.shapePrefix)||lB(n)?.shapes.some(ve))return B;B.push({code:"VALIDATION_ERROR",operationIndex:e,message:`Name "${t}" contains reserved character "+". The "+" character is reserved for the historical collection auto-name namespace and is not allowed in user-supplied names.`});}return B}function Io(n,e){let B=[];return !n.about||typeof n.about=="string"||B.push({code:"VALIDATION_ERROR",operationIndex:e,message:it}),B}function To(n,e){let B=[];if(n.kind!=="collection"||fo(n.operation)===null)return B;let t=Eo(n.type);n.operation==="add"&&!n.name&&B.push({code:"VALIDATION_ERROR",operationIndex:e,message:rt}),t===null&&B.push({code:"VALIDATION_ERROR",operationIndex:e,message:nt(ho(n.type))});let r=Array.isArray(n.members)?n.members:null;if(r===null)B.push({code:"VALIDATION_ERROR",operationIndex:e,message:'Collection requires a "members" array'});else for(let i=0;i<r.length;i++)typeof r[i]!="string"&&B.push({code:"VALIDATION_ERROR",operationIndex:e,message:`Collection member at index ${i} must be a string`});if(t!==null&&r!==null){let i=Ro(t,r);i&&B.push({code:"VALIDATION_ERROR",operationIndex:e,message:i});}return B}function Ro(n,e){switch(n){case "set":case "list":return e.length<1?`${n==="set"?"Set":"List"} requires at least 1 member, got 0`:null;default:return n}}function No(n,e){return Tr(n,e)}var _o=new TextEncoder;async function cB(n){let e=new Uint8Array(await crypto.subtle.digest("SHA-256",Uint8Array.from(n)));return Array.from(e,B=>B.toString(16).padStart(2,"0")).join("")}function Ke(n){return te(n),_o.encode(n)}function te(n){for(let e=0;e<n.length;e+=1){let B=n.charCodeAt(e);if(B>=55296&&B<=56319){let t=n.charCodeAt(e+1);if(!(t>=56320&&t<=57343))throw new RangeError("Checkpoint text must be valid Unicode");e+=1;}else if(B>=56320&&B<=57343)throw new RangeError("Checkpoint text must be valid Unicode")}}function ne(n,e){te(n),te(e);let B=0,t=0;for(;B<n.length&&t<e.length;){let r=n.codePointAt(B),i=e.codePointAt(t);if(r===void 0||i===void 0)break;let s=r-i;if(s!==0)return s;B+=r>65535?2:1,t+=i>65535?2:1;}return B===n.length&&t===e.length?0:B===n.length?-1:1}var lt=67108864,pB=10,Nr="warmhub-repository-checkpoint",_r=4,Fo="repository-checkpoint.json";var Fr="application/json",yr="application/zip",Lr="application/x-ndjson",br=[yr,Fr,Lr];function yo(n){return br.includes(n)}var ct=z$1.string().regex(/^[0-9a-f]{64}$/),uB=z$1.number().int().nonnegative(),at=z$1.number().int().positive(),Lo=z$1.number().refine(n=>!Number.isInteger(n)||Number.isSafeInteger(n),"JSON integers must be safe integers"),me=z$1.lazy(()=>z$1.union([z$1.null(),z$1.boolean(),Lo,z$1.string(),z$1.array(me),z$1.record(z$1.string(),me)])),Rr=z$1.object({wref:z$1.string().min(1),durableId:z$1.string().min(1),version:z$1.number().int().positive(),active:z$1.literal(true),data:me}),wr=z$1.string().regex(/^[^\r\n]+@v[1-9]\d*(?![\s\S])/,"Checkpoint wref must be pinned with @vN"),bo=z$1.array(wr).superRefine((n,e)=>{for(let B=1;B<n.length;B+=1){let t=n[B-1],r=n[B];t!==void 0&&r!==void 0&&ne(t,r)>=0&&e.addIssue({code:"custom",path:[B],message:"Affirmed wrefs must be unique and strictly increasing"});}}),xr=z$1.array(z$1.object({shape:z$1.string().min(1),memberCount:uB}).strict()).min(1),ut=z$1.discriminatedUnion("kind",[Rr.extend({kind:z$1.literal("shape")}).strict(),Rr.extend({kind:z$1.literal("thing"),shapeName:z$1.string().min(1),collections:xr.optional(),aboutWref:wr.optional(),affirmedWrefs:bo.optional()}).strict().refine(n=>n.aboutWref===void 0==(n.affirmedWrefs===void 0),{message:"A checkpoint row carries aboutWref and affirmedWrefs together or not at all",path:["affirmedWrefs"]})]),Pr=z$1.object({part:uB,path:z$1.string().min(1),recordCount:at,byteLength:at,sha256:ct}).strict(),Gr=z$1.object({shapeName:z$1.string().min(1),recordCount:at,chunks:z$1.array(Pr).min(1)}).strict(),wo={format:z$1.literal(Nr),formatVersion:z$1.literal(_r),checkpointId:z$1.uuid(),repository:z$1.object({id:z$1.uuid(),org:z$1.string().min(1),repo:z$1.string().min(1)}).strict(),repoSeq:uB,complete:z$1.literal(true),recordCount:uB,streams:z$1.array(Gr)},pt=z$1.object(wo).strict(),EB=pt.extend({contentSha256:ct}).strict();function pe(n){if(!n||typeof n!="object")return JSON.stringify(n);if(Array.isArray(n))return `[${n.map(B=>pe(B)).join(",")}]`;let e=n;return `{${Object.keys(e).sort().map(B=>`${JSON.stringify(B)}:${pe(e[B])}`).join(",")}}`}new TextEncoder;var xo=new TextDecoder("utf-8",{fatal:true});function Et(n,e){if(n.length===0||n.at(-1)!==10)throw new Error(`${e} must end with one LF`);if(n.length>=3&&n[0]===239&&n[1]===187&&n[2]===191)throw new Error(`${e} must not contain a UTF-8 BOM`);for(let B=0;B<n.length-1;B+=1)if(n[B]===10||n[B]===13)throw new Error(`${e} must contain exactly one LF and no CR`)}function Se(n,e,B){Et(n,B);let t=xo.decode(n),r=e.parse(JSON.parse(t.slice(0,-1)));if(t!==`${pe(r)}
19
19
  `)throw new Error(`${B} bytes are not canonical`);return r}var Hr=10**pB-1;async function Po(n){if(n.length===0)throw new RangeError("Checkpoint Shape name must not be empty");return cB(Ke(n))}async function Go(n,e){return Ho(e),`records/${await Po(n)}/part-${e.toString().padStart(pB,"0")}.jsonl`}async function Mr(n,e,B){let t=await Go(e,B);if(n!==t)throw new Error("Checkpoint chunk path does not match its Shape and part")}function Ho(n){if(!Number.isSafeInteger(n)||n<0||n>Hr)throw new RangeError(`Checkpoint chunk part must be an integer from 0 through ${Hr}`)}var Mo=new TextDecoder("utf-8",{fatal:true});async function ht(n){let e=EB.parse(n),{contentSha256:B,...t}=e;await vo(t);let r=await Uo(t);if(B!==r)throw new Error("Checkpoint manifest content digest does not match");return e}async function Ur(n){let e=await ht(n);return Ke(`${pe(e)}
20
20
  `)}async function ko(n){Et(n,"Checkpoint manifest");let e=Mo.decode(n),B=await ht(EB.parse(JSON.parse(e.slice(0,-1)))),t=await Ur(B);if(!Jo(n,t))throw new Error("Checkpoint manifest bytes are not canonical");return B}async function Uo(n){return cB(Ke(pe(n)))}async function vo(n){let e,B=0;for(let t of n.streams){if(e!==void 0&&ne(e,t.shapeName)>=0)throw new Error("Checkpoint manifest streams must be strictly increasing by Shape name");e=t.shapeName;let r=0;for(let[i,s]of t.chunks.entries()){if(s.part!==i)throw new Error("Checkpoint manifest chunk parts must be contiguous and zero-based");if(await Mr(s.path,t.shapeName,s.part),s.byteLength>lt&&s.recordCount!==1)throw new Error("An oversized checkpoint chunk must contain exactly one row");r=kr(r,s.recordCount);}if(t.recordCount!==r)throw new Error("Checkpoint manifest stream record count does not match");B=kr(B,t.recordCount);}if(n.recordCount!==B)throw new Error("Checkpoint manifest record count does not match")}function kr(n,e){let B=n+e;if(!Number.isSafeInteger(B))throw new RangeError("Checkpoint manifest count sum must be a safe integer");return B}function Jo(n,e){return n.length!==e.length?false:n.every((B,t)=>B===e[t])}function Ko(n){return Se(n,ut,"Checkpoint row")}function Yo(n){if(n.length===0)throw new Error("Checkpoint stream Shape name must not be empty");return te(n),{shapeName:n,recordCount:0,hasShapeDefinition:false}}function Wo(n,e){let B=e;if(te(B.wref),te(B.durableId),B.kind!=="shape"&&B.aboutWref!==void 0&&te(B.aboutWref),(B.kind==="shape"?B.wref:B.shapeName)!==n.shapeName)throw new Error("Checkpoint row is grouped under the wrong Shape stream");if(B.kind!=="shape"){let r=`${B.shapeName}/`;if(!B.wref.startsWith(r)||B.wref.length===r.length)throw new Error("Checkpoint row wref does not belong to its declared Shape")}if(n.previousWref!==void 0&&ne(n.previousWref,B.wref)>=0)throw new Error("Checkpoint stream rows must be strictly increasing by wref");return B.kind==="shape"&&(n.hasShapeDefinition=true),n.previousWref=B.wref,n.recordCount=Qo(n.recordCount),B}function jo(n){if(!n.hasShapeDefinition)throw new Error("Checkpoint stream must contain its matching Shape definition");return n.recordCount}function Qo(n){let e=n+1;if(!Number.isSafeInteger(e))throw new RangeError("Checkpoint stream record count must be a safe integer");return e}var ft=new Set([8203,8204,8205,8288,8294,8295,8296,8297,8234,8235,8236,8237,8238,8232,8233]);function gt(n){return n<=31||n===127||n>=128&&n<=159}function $o(n){return n<=65535?`\\u${n.toString(16).padStart(4,"0")}`:`\\u{${n.toString(16)}}`}function qo(n){for(let e of n){let B=e.codePointAt(0);if(B!==void 0&&(gt(B)||ft.has(B)||B===34))return true}return false}function zo(n){return n.length<=120?n:`${n.slice(0,120)}...<truncated>`}function vr(n){if(!qo(n))return n;let e=JSON.stringify(n).slice(1,-1),B="";for(let t of e){let r=t.codePointAt(0);r!==void 0&&(B+=gt(r)||ft.has(r)?$o(r):t);}return B}function H(n){return zo(vr(n))}function Xo(n){return vr(n)}function hB(n){if(n.length===0)return {unsafe:true,reason:"empty field name"};if(n!==n.trim())return {unsafe:true,reason:"leading or trailing whitespace"};for(let e of n){let B=e.codePointAt(0);if(B!==void 0){if(gt(B))return {unsafe:true,reason:`control character (U+${B.toString(16).padStart(4,"0").toUpperCase()})`};if(ft.has(B))return {unsafe:true,reason:`format or separator character (U+${B.toString(16).padStart(4,"0").toUpperCase()})`}}}return {unsafe:false}}function fB(n){return n.endsWith("?")?n.slice(0,-1):n}function Oe(...n){return Jr(H,n)}function gB(...n){return Jr(Xo,n)}function Jr(n,e){return e.map(B=>typeof B=="number"?`[${B}]`:n(B)).join(".").replace(/\.\[/g,"[")}function Ae(n,e,B,t){let r=Zo(e);if(typeof n=="string"){if(r.length>0)return;Me(t??"<value>",n,B);return}if(Array.isArray(n)){let s=r.filter(BC);if(r.length>0&&s.length===0)return;let o=DB(s.map(eC));for(let C=0;C<n.length;C++)Ae(n[C],o,B,`${t??"<value>"}[${C}]`);return}if(!Q(n))return;let i=DB(r.map(tC));if(!(r.length>0&&i.length===0))for(let[s,o]of Object.entries(n)){let C=t?Oe(t,s):H(s);Me(C,s,B),Ae(o,DB(i.map(u=>u.get(s))),B,C);}}function Zo(n){return DB(n.map(e=>Z(e).spec))}function DB(n){return n.filter(e=>e!==void 0)}function eC(n){if(Array.isArray(n))return n[0];if(v(n)&&n.type==="array")return n.items}function BC(n){return n==="array"||Array.isArray(n)?true:v(n)&&n.type==="array"}function tC(n){if(!Q(n)||v(n))return;let e=new Map;for(let[B,t]of Object.entries(n))e.set(B.endsWith("?")?B.slice(0,-1):B,t);return e}var dB=500;function dt(n){let e=new Set;for(let B of Object.keys(n))e.add(B.endsWith("?")?B.slice(0,-1):B);return e}function mt(n,e){let B=[],t=0;for(let r of Object.keys(n))e.has(r)||(t++,B.length<dB&&B.push(r));if(t!==0)return t>dB?{undeclaredFields:B,undeclaredFieldsTruncated:true,totalUndeclared:t}:{undeclaredFields:B}}function Kr(n,e={}){let B=Yr(n,e.enforceContentLimits!==false);return (t,r)=>{for(let i of B){let s=t[i.fieldName];if(s==null){i.isOptional||r.push(`Missing required field: "${i.displayName}"`);continue}i.validate(i.displayName,s,r);}}}function Yr(n,e){return Object.entries(n).map(([B,t])=>{let r=B.endsWith("?")?B.slice(0,-1):B,i=Z(t);return {fieldName:r,displayName:H(r),isOptional:tB(B,t),validate:Dt(i.spec,e)}})}function Dt(n,e){if(typeof n=="string")return (B,t,r)=>Vr(B,t,n,r,e);if(Array.isArray(n)){let B=n.length>0?Dt(Z(n[0]).spec,e):void 0;return (t,r,i)=>{if(!Array.isArray(r))i.push(`Field "${t}" expected array, got ${typeof r}`);else if(B)for(let s=0;s<r.length;s++)B(`${t}[${s}]`,r[s],i);}}if(v(n)){if((n.type.endsWith("?")?n.type.slice(0,-1):n.type)==="array"){let r="items"in n&&n.items!=null?Dt(Z(n.items).spec,e):void 0;return (i,s,o)=>{if(!Array.isArray(s)){o.push(`Field "${i}" expected array, got ${typeof s}`);return}if(typeof n.minItems=="number"&&s.length<n.minItems&&o.push(`Field "${i}" has ${s.length} items, minimum is ${n.minItems}`),typeof n.maxItems=="number"&&s.length>n.maxItems&&o.push(`Field "${i}" has ${s.length} items, maximum is ${n.maxItems}`),r)for(let C=0;C<s.length;C++)r(`${i}[${C}]`,s[C],o);}}let t=nC(n);return (r,i,s)=>{Vr(r,i,n.type,s,e),t(r,i,s);}}if(Q(n)){let B=Yr(n,e);return (t,r,i)=>{if(typeof r!="object"||r===null||Array.isArray(r)){i.push(`Field "${t}" expected object, got ${typeof r}`);return}let s=r;for(let o of B){let C=s[o.fieldName],u=Oe(t,o.fieldName);if(C==null){o.isOptional||i.push(`Missing required field: "${u}"`);continue}o.validate(u,C,i);}}}return ()=>{}}function nC(n){let e=typeof n.pattern=="string"?n.pattern:void 0,B=e===void 0?void 0:rC(e);return (t,r,i)=>{if(typeof r=="string"){if(typeof n.minLength=="number"&&r.length<n.minLength&&i.push(`Field "${t}" length ${r.length} is below minimum ${n.minLength}`),typeof n.maxLength=="number"&&r.length>n.maxLength&&i.push(`Field "${t}" length ${r.length} exceeds maximum ${n.maxLength}`),e!==void 0){let s=H(e);B?.kind==="unsupported"?i.push(`Field "${t}" has unsupported pattern "${s}"`):B?.kind==="invalid"?i.push(`Field "${t}" has invalid pattern "${s}" \u2014 skipping regex check`):B?.kind==="compiled"&&!B.regex.test(r)&&i.push(`Field "${t}" does not match pattern "${s}"`);}Array.isArray(n.enum)&&!n.enum.includes(r)&&i.push(`Field "${t}" value "${H(String(r))}" is not in allowed values: ${n.enum.map(s=>H(String(s))).join(", ")}`);}typeof r=="number"&&(typeof n.minimum=="number"&&r<n.minimum&&i.push(`Field "${t}" value ${r} is below minimum ${n.minimum}`),typeof n.maximum=="number"&&r>n.maximum&&i.push(`Field "${t}" value ${r} exceeds maximum ${n.maximum}`),n.integer===true&&!Number.isInteger(r)&&i.push(`Field "${t}" must be an integer, got ${r}`));}}function rC(n){if(BB(n))return {kind:"invalid"};let e=jB(n);return e?{kind:"compiled",regex:e}:{kind:"unsupported"}}function Vr(n,e,B,t,r){switch(B){case "number":typeof e!="number"&&t.push(`Field "${n}" expected number, got ${typeof e}`);break;case "string":typeof e!="string"?t.push(`Field "${n}" expected string, got ${typeof e}`):r&&Me(n,e,t);break;case "wref":typeof e!="string"&&t.push(`Field "${n}" expected string, got ${typeof e}`);break;case "boolean":typeof e!="boolean"&&t.push(`Field "${n}" expected boolean, got ${typeof e}`);break;case "array":Array.isArray(e)||t.push(`Field "${n}" expected array, got ${typeof e}`);break;}}function St(n){let e=n.map(r=>Kr(r.fields)),B=new Set;for(let r of n)for(let i of dt(r.fields))B.add(i);let t=n.map(r=>r.fields);return r=>{let i=r===null?{}:r;if(typeof i!="object"||Array.isArray(i))return {valid:false,errors:["Data must be a plain object"]};let s=i,o=[];for(let u of e)u(s,o);Ae(s,t,o);let C=mt(s,B);return o.length>0?C?{valid:false,errors:o,warnings:C}:{valid:false,errors:o}:C?{valid:true,warnings:C}:{valid:true}}}function Wr(n,e){return Ot(e)(n)}function Ot(n){return St([{name:"",fields:n}])}var iC=z$1.object({fieldPath:z$1.string(),wref:z$1.string(),reason:z$1.string()}),sC=z$1.object({fieldPath:z$1.string(),wref:z$1.string(),binding:z$1.literal("identity")}),oC=z$1.object({shape:z$1.string(),message:z$1.string(),removalMilestone:z$1.string()}),cC=z$1.object({undeclaredFields:z$1.array(z$1.string()).optional(),undeclaredFieldsTruncated:z$1.literal(true).optional(),totalUndeclared:z$1.number().int().nonnegative().optional(),coalescedWrefs:z$1.array(iC).optional(),coalescedWrefsTruncated:z$1.literal(true).optional(),totalCoalescedWrefs:z$1.number().int().nonnegative().optional(),deprecations:z$1.array(oC).optional(),ignoredVersionPins:z$1.array(sC).optional(),shapeless:z$1.literal(true).optional()});function At(n){return (n.endsWith("?")?n.slice(0,-1):n).toLowerCase()}function jr(n){return n.split(".").map(e=>At(e)).join(".")}function uC(n,e){return n.allowUnsafeFieldNamePaths.has(e)}function SB(n){return !(!Q(n)||Array.isArray(n)||v(n)||"type"in n&&typeof n.type=="string"&&X.has(n.type)&&Object.keys(n).every(e=>KB.has(e)))}function OB(n,e,B,t,r=e){let i=new Map;for(let[s,o]of Object.entries(n)){let C=fB(s),u=hB(C),c=Oe(e,s),E=gB(r,s);if(u.unsafe&&!uC(t,E)){B.push(`Invalid field name at "${c}": ${u.reason}`);continue}let h=At(s),g=i.get(h);if(g!==void 0){B.push(`${c}: duplicate field name. Shape already declares "${H(g)}" (case-insensitive match).`);continue}i.set(h,s),SB(o)?OB(o,c,B,t,E):It(c,E,o,B,t);}}function It(n,e,B,t,r){if(typeof B=="string"){X.has(B)||t.push(`Invalid type at "${n}": "${H(B)}" (expected number|string|boolean|wref|array, optionally with ? suffix)`);return}if(Array.isArray(B)){if(B.length!==1){t.push(`Invalid array type at "${n}": array type spec must have exactly 1 element`);return}It(`${n}[]`,`${e}[]`,B[0],t,r);return}if(Q(B)){let i=Ln(n,B);if(i){t.push(i);return}if(v(B)){pC(n,e,B,t,r);return}if("type"in B&&typeof B.type=="string"&&X.has(B.type)&&Object.keys(B).every(s=>KB.has(s))){let s=B.type.endsWith("?")?B.type.slice(0,-1):B.type,C=s==="string"?be:s==="number"?we:s==="wref"?xe:s==="array"?Pe:new Set,u=Object.keys(B).filter(E=>E!=="type"&&E!=="description"&&!C.has(E));if(u.length>0&&u.some(h=>{let g=B[h];return typeof g!="string"&&!Array.isArray(g)&&!Q(g)})){for(let h of u)t.push(`Constraint "${H(h)}" at "${n}" is not valid for type "${s}"`);return}if(u.length===0){let E=[];for(let[h,g]of Object.entries(B))h==="type"||h==="description"||C.has(h)&&((h==="minLength"||h==="maxLength"||h==="minimum"||h==="maximum"||h==="minItems"||h==="maxItems")&&typeof g!="number"?E.push(`Constraint "${h}" at "${n}" must be a number, got ${typeof g}`):h==="integer"&&typeof g!="boolean"?E.push(`Constraint "${h}" at "${n}" must be a boolean, got ${typeof g}`):h==="pattern"&&typeof g!="string"?E.push(`Constraint "${h}" at "${n}" must be a string, got ${typeof g}`):h==="enum"&&!Array.isArray(g)?E.push(`Constraint "${h}" at "${n}" must be an array, got ${typeof g}`):h==="shape"&&typeof g!="string"&&E.push(`Constraint "${h}" at "${n}" must be a string, got ${typeof g}`));if(E.length>0){t.push(...E);return}}if(Object.entries(B).some(([E,h])=>!(E==="type"||E==="description"||typeof h=="string"||Array.isArray(h)||Q(h)))){t.push(`Object at "${n}" looks like a typed field object (type: "${H(String(B.type))}") but has constraint values with invalid types. Check that constraint values match their expected types (e.g., minLength must be a number, not a string).`);return}}OB(B,n,t,r,e);return}t.push(`Invalid type at "${n}": expected string, array, or object, got ${typeof B}`);}function pC(n,e,B,t,r){let i=B.type;if(typeof i!="string"){t.push(`Invalid typed field object at "${n}": "type" must be a string`);return}if(!X.has(i)){t.push(`Invalid type at "${n}.type": "${H(i)}" (expected number|string|boolean|wref|array, optionally with ? suffix)`);return}"description"in B&&typeof B.description!="string"&&t.push(`Invalid typed field object at "${n}": "description" must be a string`);let s=i.endsWith("?")?i.slice(0,-1):i;for(let o of Object.keys(B)){if(o==="type"||o==="description")continue;let C=H(o);s==="string"?be.has(o)||t.push(`Constraint "${C}" at "${n}" is not valid for type "string"`):s==="number"?we.has(o)||t.push(`Constraint "${C}" at "${n}" is not valid for type "number"`):s==="wref"?xe.has(o)||t.push(`Constraint "${C}" at "${n}" is not valid for type "wref"`):s==="array"?Pe.has(o)||t.push(`Constraint "${C}" at "${n}" is not valid for type "array"`):t.push(`Constraint "${C}" at "${n}" is not valid for type "${s}"`);}if("minLength"in B&&(typeof B.minLength!="number"||!Number.isFinite(B.minLength)||B.minLength<0||!Number.isInteger(B.minLength))&&t.push(`"minLength" at "${n}" must be a non-negative finite integer`),"maxLength"in B&&(typeof B.maxLength!="number"||!Number.isFinite(B.maxLength)||B.maxLength<0||!Number.isInteger(B.maxLength))&&t.push(`"maxLength" at "${n}" must be a non-negative finite integer`),"minLength"in B&&"maxLength"in B&&typeof B.minLength=="number"&&typeof B.maxLength=="number"&&B.minLength>B.maxLength&&t.push(`"minLength" at "${n}" cannot exceed "maxLength"`),s==="string"&&typeof B.minLength=="number"&&Number.isFinite(B.minLength)&&Number.isInteger(B.minLength)&&B.minLength>q&&t.push(`"minLength" at "${n}" cannot exceed ${q}`),s==="string"&&typeof B.maxLength=="number"&&Number.isFinite(B.maxLength)&&Number.isInteger(B.maxLength)&&B.maxLength>q&&t.push(`"maxLength" at "${n}" cannot exceed ${q}`),"pattern"in B&&typeof B.pattern!="string"&&t.push(`"pattern" at "${n}" must be a string`),"pattern"in B&&typeof B.pattern=="string")if(BB(B.pattern))t.push(`"pattern" at "${n}" is not a valid regular expression`);else {let o=xn(B.pattern);o&&t.push(`"pattern" at "${n}" ${o}`);}if("enum"in B){if(!Array.isArray(B.enum)||B.enum.length===0||!B.enum.every(o=>typeof o=="string"))t.push(`"enum" at "${n}" must be a non-empty array of strings`);else if(s==="string")for(let o of B.enum){let C=ue(o);if(C>q){t.push(`"enum" value at "${n}" is ${C} bytes; string enum values cannot exceed ${q} bytes`);break}}}"minimum"in B&&(typeof B.minimum!="number"||!Number.isFinite(B.minimum))&&t.push(`"minimum" at "${n}" must be a finite number`),"maximum"in B&&(typeof B.maximum!="number"||!Number.isFinite(B.maximum))&&t.push(`"maximum" at "${n}" must be a finite number`),"minimum"in B&&"maximum"in B&&typeof B.minimum=="number"&&typeof B.maximum=="number"&&B.minimum>B.maximum&&t.push(`"minimum" at "${n}" cannot exceed "maximum"`),"integer"in B&&typeof B.integer!="boolean"&&t.push(`"integer" at "${n}" must be a boolean`),"shape"in B&&(typeof B.shape!="string"?t.push(`"shape" at "${n}" must be a string (shape name)`):B.shape===""&&t.push(`"shape" at "${n}" must not be empty`)),"minItems"in B&&(typeof B.minItems!="number"||!Number.isFinite(B.minItems)||B.minItems<0||!Number.isInteger(B.minItems))&&t.push(`"minItems" at "${n}" must be a non-negative finite integer`),"maxItems"in B&&(typeof B.maxItems!="number"||!Number.isFinite(B.maxItems)||B.maxItems<0||!Number.isInteger(B.maxItems))&&t.push(`"maxItems" at "${n}" must be a non-negative finite integer`),"minItems"in B&&"maxItems"in B&&typeof B.minItems=="number"&&typeof B.maxItems=="number"&&B.minItems>B.maxItems&&t.push(`"minItems" at "${n}" cannot exceed "maxItems"`),s==="array"&&("items"in B?It(`${n}.items`,`${e}.items`,B.items,t,r):t.push(`Typed array at "${n}" must have an "items" key specifying the element type`));}function EC(n={}){return {allowUnsafeFieldNamePaths:new Set(n.allowUnsafeFieldNamePaths??[])}}var hC=new Set(["fields","description","composes"]);function AB(n,e=""){let B=[];for(let[t,r]of Object.entries(n)){let i=t.endsWith("?")?t.slice(0,-1):t,s=e?`${e}.${i}`:i,o=wn(r);if(o==="string"||o==="wref"||o==="number"||o==="boolean"){B.push(s);continue}v(r)||Q(r)&&B.push(...AB(r,s));}return B}function Tt(n,e,B){if(Array.isArray(e)){e.length===1&&Tt(`${n}[]`,e[0],B);return}if(v(e)){let t=Z(e).spec;v(t)&&typeof t.type=="string"&&t.type==="array"&&"items"in t&&Tt(`${n}.items`,t.items,B);return}SB(e)&&Rt(e,n,B);}function Rt(n,e,B){for(let[t,r]of Object.entries(n)){let i=gB(e,t);hB(fB(t)).unsafe&&B.push(i),SB(r)?Rt(r,i,B):Tt(i,r,B);}}function Qr(n){if(typeof n!="object"||n===null||Array.isArray(n))return [];let e=n.fields;if(typeof e!="object"||e===null||Array.isArray(e))return [];let B=[];return Rt(e,"fields",B),B}function $r(n,e={}){if(typeof n!="object"||n===null||Array.isArray(n))return {valid:false,errors:["Shape definition must be a plain object"]};let B=n,t=[];for(let c of Object.keys(B))hC.has(c)||t.push(`Unsupported shape definition key "${H(c)}"`);if(!("fields"in B))return {valid:false,errors:['Shape definition must have a "fields" property']};let r=B.fields;if(typeof r!="object"||r===null||Array.isArray(r))return {valid:false,errors:['"fields" must be a plain object mapping field names to types']};let i=EC(e);OB(r,"fields",t,i);let s=AB(r),o=s.length,C=new Set,u=new Set;for(let c of s){let E=ue(c);E>He&&t.push(`Indexable field path "${H(c)}" is ${E} bytes; maximum is ${He}`);let h=jr(c);if(C.has(h)){u.add(h);continue}C.add(h);}for(let c of u)t.push(`Shape declares ambiguous indexable field path "${H(c)}"; dotted field names, optional-key suffixes, and case-insensitive folded paths must not collide with another indexable path`);return o>Ge&&t.push(`Shape declares ${o} indexable scalar fields; maximum is ${Ge}`),"description"in B&&typeof B.description!="string"&&t.push('"description" must be a string'),"composes"in B&&(!Array.isArray(B.composes)||!B.composes.every(c=>typeof c=="string"&&c.length>0))&&t.push('"composes" must be an array of non-empty Shape wrefs'),Ae(B,[],t),t.length>0?{valid:false,errors:t}:{valid:true}}var DC="invalid_token";var qr=[5,6],dC="application/x-ndjson",zr=z$1.string().regex(/^[0-9a-f]{64}$/),IB=z$1.number().int().nonnegative(),Xr=z$1.number().int().positive(),Zr=["shape","thing"],ei=["heads","ops"],_t=z$1.string().regex(/^[^\r\n]+@v[1-9]\d*(?![\s\S])/,"Shape certificate must be a pinned wref"),Ft=z$1.object({wref:z$1.string().min(1),v:Xr.optional(),durableId:z$1.string().min(1)}).strict();function Bi(n,e,B,t){let r;n.forEach((i,s)=>{let o=e(i);r!==void 0&&ne(r,o)>=0&&t.addIssue({code:"custom",path:[s],message:B}),r=o;});}var mC=z$1.array(_t).superRefine((n,e)=>{Bi(n.slice(1),t=>t,"Shape certificates after the first must be unique and strictly increasing",e);let B=n[0];B!==void 0&&n.indexOf(B,1)!==-1&&e.addIssue({code:"custom",path:[n.indexOf(B,1)],message:"The first Shape certificate must not repeat in the tail"});}),SC=z$1.array(Ft).superRefine((n,e)=>{Bi(n,B=>B.wref,"Affirmed references must be unique and strictly increasing",e);}),OC=z$1.array(z$1.object({shape:z$1.string().min(1),memberCount:z$1.number().int().nonnegative()}).strict()).min(1),ti={wref:z$1.string().min(1),durableId:z$1.string().min(1),version:Xr};function ni(n){let e={...ti,active:z$1.literal(true),data:n};return z$1.discriminatedUnion("kind",[z$1.object({...e,kind:z$1.literal("shape"),shapes:z$1.array(_t).max(0),retracted:z$1.literal(true).optional()}).strict(),z$1.object({...e,kind:z$1.literal("thing"),shapes:mC,collections:OC.optional(),about:Ft.optional(),affirmed:SC.optional()}).strict().refine(B=>B.about===void 0==(B.affirmed===void 0),{message:"An export row carries `about` and `affirmed` together or not at all",path:["affirmed"]})])}function AC(n){return ri(n)&&Nt(n)}function ri(n){if(n===null||typeof n!="object"||Array.isArray(n))return false;let e=Object.getPrototypeOf(n);return (e===Object.prototype||e===null)&&Object.getOwnPropertySymbols(n).length===0}function Nt(n){if(n===null)return true;let e=typeof n;if(e==="string"||e==="boolean")return true;if(e==="number"){let B=n;return Number.isFinite(B)&&(!Number.isInteger(B)||Number.isSafeInteger(B))}if(Array.isArray(n)){for(let B of n)if(!Nt(B))return false;return true}if(!ri(n))return false;for(let B of Object.keys(n))if(B==="__proto__"||!Nt(n[B]))return false;return true}var IC=ni(z$1.record(z$1.string(),me)),ii=z$1.object({...ti,kind:z$1.enum(Zr),active:z$1.literal(false)}).strict(),yt=z$1.union([IC,ii]);z$1.union([ni(z$1.custom(AC)),ii]);var Lt=z$1.object({kind:z$1.literal("header"),formatVersion:z$1.literal(qr),repo:z$1.string().regex(/^[^/\s]+\/[^/\s]+$/,'repo must be "<org>/<repo>"'),mode:z$1.enum(ei),sinceRepoSeq:IB,atRepoSeq:IB}).strict().refine(n=>n.atRepoSeq>=n.sinceRepoSeq,"atRepoSeq must not precede sinceRepoSeq"),bt=z$1.object({kind:z$1.literal("trailer"),recordCount:IB,contentSha256:zr,atRepoSeq:IB}).strict();function RC(n,e,B){let t=ne(n.durableId,e.durableId);return t!==0?t<0:B>=6&&n.kind==="shape"&&e.kind==="shape"&&n.version<e.version}function NC(n){return n.sinceRepoSeq>0}function _C(n){return Se(n,yt,"Repository export row")}function FC(n){return Se(n,Lt,"Repository export header")}function yC(n){return Se(n,bt,"Repository export trailer")}var LC=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),bC=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ie=64;function Be(n,e){return (n>>>e|n<<32-e)>>>0}var TB=class{#B=Uint32Array.from(bC);#t=new Uint32Array(64);#n=new Uint8Array(Ie);#e=0;#r=0;#i=false;update(e){if(this.#i)throw new Error("SHA-256 hasher is already finalized");if(this.#r+=e.length,!Number.isSafeInteger(this.#r))throw new RangeError("SHA-256 input length must be a safe integer");let B=0;if(this.#e>0){let t=Math.min(Ie-this.#e,e.length);if(this.#n.set(e.subarray(0,t),this.#e),this.#e+=t,B=t,this.#e<Ie)return;this.#s(this.#n,0),this.#e=0;}for(;B+Ie<=e.length;)this.#s(e,B),B+=Ie;B<e.length&&(this.#n.set(e.subarray(B),0),this.#e=e.length-B);}digestHex(){if(this.#i)throw new Error("SHA-256 hasher is already finalized");this.#i=true;let e=new Uint8Array(this.#e<56?64:128);e.set(this.#n.subarray(0,this.#e),0),e[this.#e]=128;let B=new DataView(e.buffer);B.setUint32(e.length-8,Math.floor(this.#r/536870912)),B.setUint32(e.length-4,this.#r<<3>>>0);for(let t=0;t<e.length;t+=Ie)this.#s(e,t);return Array.from(this.#B,t=>t.toString(16).padStart(8,"0")).join("")}#s(e,B){let t=this.#t;for(let g=0;g<16;g+=1){let m=B+g*4;t[g]=(e[m]<<24|e[m+1]<<16|e[m+2]<<8|e[m+3])>>>0;}for(let g=16;g<64;g+=1){let m=t[g-15],S=t[g-2],R=(Be(m,7)^Be(m,18)^m>>>3)>>>0,N=(Be(S,17)^Be(S,19)^S>>>10)>>>0;t[g]=t[g-16]+R+t[g-7]+N>>>0;}let r=this.#B,i=r[0],s=r[1],o=r[2],C=r[3],u=r[4],c=r[5],E=r[6],h=r[7];for(let g=0;g<64;g+=1){let m=(Be(u,6)^Be(u,11)^Be(u,25))>>>0,S=(u&c^~u&E)>>>0,R=h+m+S+LC[g]+t[g]>>>0,N=(Be(i,2)^Be(i,13)^Be(i,22))>>>0,b=(i&s^i&o^s&o)>>>0,x=N+b>>>0;h=E,E=c,c=u,u=C+R>>>0,C=o,o=s,s=i,i=R+x>>>0;}r[0]=i+r[0]>>>0,r[1]=s+r[1]>>>0,r[2]=o+r[2]>>>0,r[3]=C+r[3]>>>0,r[4]=u+r[4]>>>0,r[5]=c+r[5]>>>0,r[6]=E+r[6]>>>0,r[7]=h+r[7]>>>0;}};var RB=class{#B=new TB;#t=0;get rowCount(){return this.#t}update(e){this.#B.update(e),this.#t+=1;}finalize(){return this.#B.digestHex()}};function wC(){return new RB}/*! Bundled license information:
21
21
 
@@ -30,5 +30,5 @@ re2js/build/index.js:
30
30
  * @repository [object Object]
31
31
  * @license MIT
32
32
  *)
33
- */export{or as $,as as A,Wr as Aa,cs as B,ps as C,Es as D,hs as E,Ds as F,Os as G,$n as H,Fs as I,qn as J,Ls as K,zn as L,bs as M,ws as N,Ps as O,Br as P,Gs as Q,tr as R,Hs as S,nr as T,Ms as U,rr as V,ks as W,ir as X,Us as Y,Ys as Z,cC as _,DC as a,Ws as aa,MC as b,Cr as ba,ui as c,js as ca,Te as d,nt as da,bB as e,No as ea,re as f,lt as fa,Ei as g,pB as ga,hi as h,Fo as ha,fi as i,br as ia,Q as j,yo as ja,q as k,ct as ka,YB as l,ko as la,WB as m,Ko as ma,$i as n,Yo as na,qi as o,Wo as oa,zi as p,jo as pa,Zi as q,qr as qa,es as r,dC as ra,Bs as s,RC as sa,ts as t,NC as ta,ns as u,_C as ua,rs as v,FC as va,is as w,yC as wa,ss as x,wC as xa,os as y,Qr as ya,Cs as z,$r as za};//# sourceMappingURL=chunk-RVSU4CXH.js.map
34
- //# sourceMappingURL=chunk-RVSU4CXH.js.map
33
+ */export{or as $,as as A,Wr as Aa,cs as B,ps as C,Es as D,hs as E,Ds as F,Os as G,$n as H,Fs as I,qn as J,Ls as K,zn as L,bs as M,ws as N,Ps as O,Br as P,Gs as Q,tr as R,Hs as S,nr as T,Ms as U,rr as V,ks as W,ir as X,Us as Y,Ys as Z,cC as _,DC as a,Ws as aa,MC as b,Cr as ba,ui as c,js as ca,Te as d,nt as da,bB as e,No as ea,re as f,lt as fa,Ei as g,pB as ga,hi as h,Fo as ha,fi as i,br as ia,Q as j,yo as ja,q as k,ct as ka,YB as l,ko as la,WB as m,Ko as ma,$i as n,Yo as na,qi as o,Wo as oa,zi as p,jo as pa,Zi as q,qr as qa,es as r,dC as ra,Bs as s,RC as sa,ts as t,NC as ta,ns as u,_C as ua,rs as v,FC as va,is as w,yC as wa,ss as x,wC as xa,os as y,Qr as ya,Cs as z,$r as za};//# sourceMappingURL=chunk-BL6W7226.js.map
34
+ //# sourceMappingURL=chunk-BL6W7226.js.map