@php-wasm/universal 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -96,5 +96,5 @@ ${JSON.stringify(t.headers,null,2)}
96
96
  * @license
97
97
  * Copyright 2019 Google LLC
98
98
  * SPDX-License-Identifier: Apache-2.0
99
- */const WireValueType={RAW:"RAW",HANDLER:"HANDLER"},MessageType={GET:"GET",SET:"SET",APPLY:"APPLY",CONSTRUCT:"CONSTRUCT",ENDPOINT:"ENDPOINT",RELEASE:"RELEASE"},isObject=t=>typeof t=="object"&&t!==null||typeof t=="function",proxyTransferHandler={canHandle:t=>isObject(t)&&t[proxyMarker],serialize(t){const{port1:e,port2:r}=new MessageChannel;return expose(t,e),[r,[r]]},deserialize(t){return t.start(),wrap(t)}},throwTransferHandler$1={canHandle:t=>isObject(t)&&throwMarker in t,serialize({value:t}){let e;return t instanceof Error?e={isError:!0,value:{message:t.message,name:t.name,stack:t.stack}}:e={isError:!1,value:t},[e,[]]},deserialize(t){throw t.isError?Object.assign(new Error(t.value.message),t.value):t.value}},transferHandlers=new Map([["proxy",proxyTransferHandler],["throw",throwTransferHandler$1]]);function isAllowedOrigin(t,e){for(const r of t)if(e===r||r==="*"||r instanceof RegExp&&r.test(e))return!0;return!1}function expose(t,e=globalThis,r=["*"],s){e.addEventListener("message",function n(i){if(!i||!i.data)return;if(!isAllowedOrigin(r,i.origin)){console.warn(`Invalid origin '${i.origin}' for comlink proxy`);return}const{id:o,type:a,path:l}={path:[],...i.data},c=(i.data.argumentList||[]).map(fromWireValue);let p;try{const h=l.slice(0,-1).reduce((w,b)=>w[b],t),y=l.reduce((w,b)=>w[b],t);switch(a){case MessageType.GET:p=y;break;case MessageType.SET:h[l.slice(-1)[0]]=fromWireValue(i.data.value),p=!0;break;case MessageType.APPLY:p=y.apply(h,c);break;case MessageType.CONSTRUCT:{const w=new y(...c);p=proxy(w)}break;case MessageType.ENDPOINT:{const{port1:w,port2:b}=new MessageChannel;expose(t,b),p=transfer(w,[w])}break;case MessageType.RELEASE:p=void 0;break;default:return}}catch(h){p={value:h,[throwMarker]:0}}Promise.resolve(p).catch(h=>({value:h,[throwMarker]:0})).then(h=>{const[y,w]=toWireValue(h);e.postMessage({...y,id:o},w),a===MessageType.RELEASE&&(e.removeEventListener("message",n),closeEndPoint(e),finalizer in t&&typeof t[finalizer]=="function"&&t[finalizer]())}).catch(()=>{const[h,y]=toWireValue({value:new TypeError("Unserializable return value"),[throwMarker]:0});e.postMessage({...h,id:o},y)}).finally(()=>{s==null||s(i)})}),e.start&&e.start()}function isMessagePort(t){return t.constructor.name==="MessagePort"}function closeEndPoint(t){isMessagePort(t)&&t.close()}function wrap(t,e){const r=new Map;return t.addEventListener("message",function(n){const{data:i}=n;if(!i||!i.id)return;const o=r.get(i.id);if(o)try{o(i)}finally{r.delete(i.id)}}),createProxy(t,r,[],e)}function throwIfProxyReleased(t){if(t)throw new Error("Proxy has been released and is not useable")}function releaseEndpoint(t){return requestResponseMessage(t,new Map,{type:MessageType.RELEASE}).then(()=>{closeEndPoint(t)})}const proxyCounter=new WeakMap,proxyFinalizers="FinalizationRegistry"in globalThis&&new FinalizationRegistry(t=>{const e=(proxyCounter.get(t)||0)-1;proxyCounter.set(t,e),e===0&&releaseEndpoint(t)});function registerProxy(t,e){const r=(proxyCounter.get(e)||0)+1;proxyCounter.set(e,r),proxyFinalizers&&proxyFinalizers.register(t,e,t)}function unregisterProxy(t){proxyFinalizers&&proxyFinalizers.unregister(t)}function createProxy(t,e,r=[],s=function(){}){let n=!1;const i=new Proxy(s,{get(o,a){if(throwIfProxyReleased(n),a===releaseProxy)return()=>{unregisterProxy(i),releaseEndpoint(t),e.clear(),n=!0};if(a==="then"){if(r.length===0)return{then:()=>i};const l=requestResponseMessage(t,e,{type:MessageType.GET,path:r.map(c=>c.toString())}).then(fromWireValue);return l.then.bind(l)}return createProxy(t,e,[...r,a])},set(o,a,l){throwIfProxyReleased(n);const[c,p]=toWireValue(l);return requestResponseMessage(t,e,{type:MessageType.SET,path:[...r,a].map(h=>h.toString()),value:c},p).then(fromWireValue)},apply(o,a,l){throwIfProxyReleased(n);const c=r[r.length-1];if(c===createEndpoint)return requestResponseMessage(t,e,{type:MessageType.ENDPOINT}).then(fromWireValue);if(c==="bind")return createProxy(t,e,r.slice(0,-1));const[p,h]=processArguments(l);return requestResponseMessage(t,e,{type:MessageType.APPLY,path:r.map(y=>y.toString()),argumentList:p},h).then(fromWireValue)},construct(o,a){throwIfProxyReleased(n);const[l,c]=processArguments(a);return requestResponseMessage(t,e,{type:MessageType.CONSTRUCT,path:r.map(p=>p.toString()),argumentList:l},c).then(fromWireValue)}});return registerProxy(i,t),i}function myFlat(t){return Array.prototype.concat.apply([],t)}function processArguments(t){const e=t.map(toWireValue);return[e.map(r=>r[0]),myFlat(e.map(r=>r[1]))]}const transferCache=new WeakMap;function transfer(t,e){return transferCache.set(t,e),t}function proxy(t){return Object.assign(t,{[proxyMarker]:!0})}function windowEndpoint(t,e=globalThis,r="*"){return{postMessage:(s,n)=>t.postMessage(s,r,n),addEventListener:e.addEventListener.bind(e),removeEventListener:e.removeEventListener.bind(e)}}function toWireValue(t){for(const[e,r]of transferHandlers)if(r.canHandle(t)){const[s,n]=r.serialize(t);return[{type:WireValueType.HANDLER,name:e,value:s},n]}return[{type:WireValueType.RAW,value:t},transferCache.get(t)||[]]}function fromWireValue(t){switch(t.type){case WireValueType.HANDLER:return transferHandlers.get(t.name).deserialize(t.value);case WireValueType.RAW:return t.value}}function requestResponseMessage(t,e,r,s){return new Promise(n=>{const i=generateUUID();e.set(i,n),t.start&&t.start(),t.postMessage({id:i,...r},s)})}function generateUUID(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}function nodeEndpoint(t){const e=new WeakMap;return{postMessage:t.postMessage.bind(t),addEventListener:(r,s)=>{const n=i=>{"handleEvent"in s?s.handleEvent({data:i}):s({data:i})};t.on("message",n),e.set(s,n)},removeEventListener:(r,s)=>{const n=e.get(s);n&&(t.off("message",n),e.delete(s))},start:t.start&&t.start.bind(t)}}const list=[Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError,AggregateError,globalThis.DOMException,globalThis.AssertionError,globalThis.SystemError].filter(Boolean).map(t=>[t.name,t]),errorConstructors=new Map(list);class NonError extends Error{constructor(e){super(NonError._prepareSuperMessage(e)),this.name="NonError"}static _prepareSuperMessage(e){try{return JSON.stringify(e)}catch{return String(e)}}}const errorProperties=[{property:"name",enumerable:!1},{property:"message",enumerable:!1},{property:"stack",enumerable:!1},{property:"code",enumerable:!0},{property:"cause",enumerable:!1},{property:"errors",enumerable:!1}],toJsonWasCalled=new WeakSet,toJSON=t=>{toJsonWasCalled.add(t);const e=t.toJSON();return toJsonWasCalled.delete(t),e},newError=t=>{const e=errorConstructors.get(t)??Error;return e===AggregateError?new e([]):new e},destroyCircular=({from:t,seen:e,to:r,forceEnumerable:s,maxDepth:n,depth:i,useToJSON:o,serialize:a})=>{if(r||(Array.isArray(t)?r=[]:!a&&isErrorLike(t)?r=newError(t.name):r={}),e.push(t),i>=n)return r;if(o&&typeof t.toJSON=="function"&&!toJsonWasCalled.has(t))return toJSON(t);const l=c=>destroyCircular({from:c,seen:[...e],forceEnumerable:s,maxDepth:n,depth:i,useToJSON:o,serialize:a});for(const[c,p]of Object.entries(t)){if(p&&p instanceof Uint8Array&&p.constructor.name==="Buffer"){r[c]="[object Buffer]";continue}if(p!==null&&typeof p=="object"&&typeof p.pipe=="function"){r[c]="[object Stream]";continue}if(typeof p!="function"){if(!p||typeof p!="object"){try{r[c]=p}catch{}continue}if(!e.includes(t[c])){i++,r[c]=l(t[c]);continue}r[c]="[Circular]"}}if(a||r instanceof Error)for(const{property:c,enumerable:p}of errorProperties)t[c]!==void 0&&t[c]!==null&&Object.defineProperty(r,c,{value:isErrorLike(t[c])||Array.isArray(t[c])?l(t[c]):t[c],enumerable:s?!0:p,configurable:!0,writable:!0});return r};function serializeError(t,e={}){const{maxDepth:r=Number.POSITIVE_INFINITY,useToJSON:s=!0}=e;return typeof t=="object"&&t!==null?destroyCircular({from:t,seen:[],forceEnumerable:!0,maxDepth:r,depth:0,useToJSON:s,serialize:!0}):typeof t=="function"?`[Function: ${t.name||"anonymous"}]`:t}function deserializeError(t,e={}){const{maxDepth:r=Number.POSITIVE_INFINITY}=e;return t instanceof Error?t:isMinimumViableSerializedError(t)?destroyCircular({from:t,seen:[],to:newError(t.name),maxDepth:r,depth:0,serialize:!1}):new NonError(t)}function isErrorLike(t){return!!t&&typeof t=="object"&&typeof t.name=="string"&&typeof t.message=="string"&&typeof t.stack=="string"}function isMinimumViableSerializedError(t){return!!t&&typeof t=="object"&&typeof t.message=="string"&&!Array.isArray(t)}async function consumeAPISync(t){setupTransferHandlers();const e=await NodeSABSyncReceiveMessageTransport.create();return wrapSync(t,e)}function consumeAPI(t,e=void 0){setupTransferHandlers();let r;(typeof document>"u"?require("url").pathToFileURL(__filename).href:_documentCurrentScript&&_documentCurrentScript.tagName.toUpperCase()==="SCRIPT"&&_documentCurrentScript.src||new URL("index.cjs",document.baseURI).href).startsWith("file://")?r=nodeEndpoint(t):r=t instanceof Worker?t:windowEndpoint(t,e);const n=wrap(r),i=proxyClone(n);return new Proxy(i,{get:(o,a)=>a==="isConnected"?async()=>{for(;;)try{await runWithTimeout(n.isConnected(),200);break}catch{}}:n[a]})}async function runWithTimeout(t,e){return new Promise((r,s)=>{setTimeout(s,e),t.then(r)})}function exposeAPI(t,e,r){const{setReady:s,setFailed:n,exposedApi:i}=prepareForExpose(t,e);let o;return r?o=nodeEndpoint(r):o=typeof window<"u"?windowEndpoint(self.parent):void 0,expose(i,o),[s,n,i]}async function exposeSyncAPI(t,e){const{setReady:r,setFailed:s,exposedApi:n}=prepareForExpose(t),i=await NodeSABSyncReceiveMessageTransport.create(),o=nodeEndpoint(e);return exposeSync(n,o,i),[r,s,n]}function prepareForExpose(t,e){setupTransferHandlers();const r=Promise.resolve();let s,n;const i=new Promise((l,c)=>{s=l,n=c}),o=proxyClone(t),a=new Proxy(o,{get:(l,c)=>c==="isConnected"?()=>r:c==="isReady"?()=>i:c in l?l[c]:e==null?void 0:e[c]});return{setReady:s,setFailed:n,exposedApi:a}}let isTransferHandlersSetup=!1;function setupTransferHandlers(){if(isTransferHandlersSetup)return;isTransferHandlersSetup=!0,transferHandlers.set("EVENT",{canHandle:r=>r instanceof CustomEvent,serialize:r=>[{detail:r.detail},[]],deserialize:r=>r}),transferHandlers.set("FUNCTION",{canHandle:r=>typeof r=="function",serialize(r){const{port1:s,port2:n}=new MessageChannel;return expose(r,s),[n,[n]]},deserialize(r){return r.start(),wrap(r)}}),transferHandlers.set("MESSAGE_PORT",{canHandle:r=>r instanceof MessagePort,serialize(r){return[r,[r]]},deserialize(r){return r}}),transferHandlers.set("PHPResponse",{canHandle:r=>typeof r=="object"&&r!==null&&"headers"in r&&"bytes"in r&&"errors"in r&&"exitCode"in r&&"httpStatusCode"in r,serialize(r){return[r.toRawData(),[]]},deserialize(r){return PHPResponse.fromRawData(r)}});const t=transferHandlers.get("throw"),e=t==null?void 0:t.serialize;t.serialize=({value:r})=>{const s=e({value:r});return r.response&&(s[0].value.response=r.response),r.source&&(s[0].value.source=r.source),s}}const throwTransferHandler=transferHandlers.get("throw"),throwTransferHandlerCustom={canHandle:throwTransferHandler.canHandle,serialize:({value:t})=>{let e;return t instanceof Error?(e={isError:!0,value:serializeError(t)},e.value.originalErrorClassName=t.constructor.name):e={isError:!1,value:t},[e,[]]},deserialize:t=>{if(t.isError){const e=deserializeError(t.value);throw new Error("Comlink method call failed",{cause:e})}throw t.value}};transferHandlers.set("throw",throwTransferHandlerCustom);function proxyClone(t){return new Proxy(t,{get(e,r){switch(typeof e[r]){case"function":return(...s)=>e[r](...s);case"object":return e[r]===null?e[r]:proxyClone(e[r]);case"undefined":case"number":case"string":return e[r];default:return proxy(e[r])}}})}exports.DEFAULT_BASE_URL=DEFAULT_BASE_URL;exports.FSHelpers=FSHelpers;exports.HttpCookieStore=HttpCookieStore;exports.LatestSupportedPHPVersion=LatestSupportedPHPVersion;exports.PHP=PHP;exports.PHPExecutionFailureError=PHPExecutionFailureError;exports.PHPProcessManager=PHPProcessManager;exports.PHPRequestHandler=PHPRequestHandler;exports.PHPResponse=PHPResponse;exports.PHPWorker=PHPWorker;exports.StreamedPHPResponse=StreamedPHPResponse;exports.SupportedPHPVersions=SupportedPHPVersions;exports.SupportedPHPVersionsList=SupportedPHPVersionsList;exports.UnhandledRejectionsTarget=UnhandledRejectionsTarget;exports.__private__dont__use=__private__dont__use;exports.applyRewriteRules=applyRewriteRules;exports.consumeAPI=consumeAPI;exports.consumeAPISync=consumeAPISync;exports.ensurePathPrefix=ensurePathPrefix;exports.exposeAPI=exposeAPI;exports.exposeSyncAPI=exposeSyncAPI;exports.getLoadedRuntime=getLoadedRuntime;exports.getPhpIniEntries=getPhpIniEntries;exports.isExitCode=isExitCode;exports.iterateFiles=iteratePhpFiles;exports.loadPHPRuntime=loadPHPRuntime;exports.prettyPrintFullStackTrace=prettyPrintFullStackTrace;exports.printDebugDetails=printDebugDetails;exports.printResponseDebugDetails=printResponseDebugDetails;exports.proxyFileSystem=proxyFileSystem;exports.removePathPrefix=removePathPrefix;exports.rotatePHPRuntime=rotatePHPRuntime;exports.sandboxedSpawnHandlerFactory=sandboxedSpawnHandlerFactory;exports.setPhpIniEntries=setPhpIniEntries;exports.toRelativeUrl=toRelativeUrl;exports.withPHPIniValues=withPHPIniValues;exports.writeFiles=writeFiles;exports.writeFilesStreamToPhp=writeFilesStreamToPhp;
99
+ */const WireValueType={RAW:"RAW",HANDLER:"HANDLER"},MessageType={GET:"GET",SET:"SET",APPLY:"APPLY",CONSTRUCT:"CONSTRUCT",ENDPOINT:"ENDPOINT",RELEASE:"RELEASE"},isObject=t=>typeof t=="object"&&t!==null||typeof t=="function",proxyTransferHandler={canHandle:t=>isObject(t)&&t[proxyMarker],serialize(t){const{port1:e,port2:r}=new MessageChannel;return expose(t,e),[r,[r]]},deserialize(t){return t.start(),wrap(t)}},throwTransferHandler$1={canHandle:t=>isObject(t)&&throwMarker in t,serialize({value:t}){let e;return t instanceof Error?e={isError:!0,value:{message:t.message,name:t.name,stack:t.stack}}:e={isError:!1,value:t},[e,[]]},deserialize(t){throw t.isError?Object.assign(new Error(t.value.message),t.value):t.value}},transferHandlers=new Map([["proxy",proxyTransferHandler],["throw",throwTransferHandler$1]]);function isAllowedOrigin(t,e){for(const r of t)if(e===r||r==="*"||r instanceof RegExp&&r.test(e))return!0;return!1}function expose(t,e=globalThis,r=["*"],s){e.addEventListener("message",function n(i){if(!i||!i.data)return;if(!isAllowedOrigin(r,i.origin)){console.warn(`Invalid origin '${i.origin}' for comlink proxy`);return}const{id:o,type:a,path:l}={path:[],...i.data},c=(i.data.argumentList||[]).map(fromWireValue);let p;try{const h=l.slice(0,-1).reduce((w,b)=>w[b],t),y=l.reduce((w,b)=>w[b],t);switch(a){case MessageType.GET:p=y;break;case MessageType.SET:h[l.slice(-1)[0]]=fromWireValue(i.data.value),p=!0;break;case MessageType.APPLY:p=y.apply(h,c);break;case MessageType.CONSTRUCT:{const w=new y(...c);p=proxy(w)}break;case MessageType.ENDPOINT:{const{port1:w,port2:b}=new MessageChannel;expose(t,b),p=transfer(w,[w])}break;case MessageType.RELEASE:p=void 0;break;default:return}}catch(h){p={value:h,[throwMarker]:0}}Promise.resolve(p).catch(h=>({value:h,[throwMarker]:0})).then(h=>{const[y,w]=toWireValue(h);e.postMessage({...y,id:o},w),a===MessageType.RELEASE&&(e.removeEventListener("message",n),closeEndPoint(e),finalizer in t&&typeof t[finalizer]=="function"&&t[finalizer]())}).catch(()=>{const[h,y]=toWireValue({value:new TypeError("Unserializable return value"),[throwMarker]:0});e.postMessage({...h,id:o},y)}).finally(()=>{s==null||s(i)})}),e.start&&e.start()}function isMessagePort(t){return t.constructor.name==="MessagePort"}function closeEndPoint(t){isMessagePort(t)&&t.close()}function wrap(t,e){const r=new Map;return t.addEventListener("message",function(n){const{data:i}=n;if(!i||!i.id)return;const o=r.get(i.id);if(o)try{o(i)}finally{r.delete(i.id)}}),createProxy(t,r,[],e)}function throwIfProxyReleased(t){if(t)throw new Error("Proxy has been released and is not useable")}function releaseEndpoint(t){return requestResponseMessage(t,new Map,{type:MessageType.RELEASE}).then(()=>{closeEndPoint(t)})}const proxyCounter=new WeakMap,proxyFinalizers="FinalizationRegistry"in globalThis&&new FinalizationRegistry(t=>{const e=(proxyCounter.get(t)||0)-1;proxyCounter.set(t,e),e===0&&releaseEndpoint(t)});function registerProxy(t,e){const r=(proxyCounter.get(e)||0)+1;proxyCounter.set(e,r),proxyFinalizers&&proxyFinalizers.register(t,e,t)}function unregisterProxy(t){proxyFinalizers&&proxyFinalizers.unregister(t)}function createProxy(t,e,r=[],s=function(){}){let n=!1;const i=new Proxy(s,{get(o,a){if(throwIfProxyReleased(n),a===releaseProxy)return()=>{unregisterProxy(i),releaseEndpoint(t),e.clear(),n=!0};if(a==="then"){if(r.length===0)return{then:()=>i};const l=requestResponseMessage(t,e,{type:MessageType.GET,path:r.map(c=>c.toString())}).then(fromWireValue);return l.then.bind(l)}return createProxy(t,e,[...r,a])},set(o,a,l){throwIfProxyReleased(n);const[c,p]=toWireValue(l);return requestResponseMessage(t,e,{type:MessageType.SET,path:[...r,a].map(h=>h.toString()),value:c},p).then(fromWireValue)},apply(o,a,l){throwIfProxyReleased(n);const c=r[r.length-1];if(c===createEndpoint)return requestResponseMessage(t,e,{type:MessageType.ENDPOINT}).then(fromWireValue);if(c==="bind")return createProxy(t,e,r.slice(0,-1));const[p,h]=processArguments(l);return requestResponseMessage(t,e,{type:MessageType.APPLY,path:r.map(y=>y.toString()),argumentList:p},h).then(fromWireValue)},construct(o,a){throwIfProxyReleased(n);const[l,c]=processArguments(a);return requestResponseMessage(t,e,{type:MessageType.CONSTRUCT,path:r.map(p=>p.toString()),argumentList:l},c).then(fromWireValue)}});return registerProxy(i,t),i}function myFlat(t){return Array.prototype.concat.apply([],t)}function processArguments(t){const e=t.map(toWireValue);return[e.map(r=>r[0]),myFlat(e.map(r=>r[1]))]}const transferCache=new WeakMap;function transfer(t,e){return transferCache.set(t,e),t}function proxy(t){return Object.assign(t,{[proxyMarker]:!0})}function windowEndpoint(t,e=globalThis,r="*"){return{postMessage:(s,n)=>t.postMessage(s,r,n),addEventListener:e.addEventListener.bind(e),removeEventListener:e.removeEventListener.bind(e)}}function toWireValue(t){for(const[e,r]of transferHandlers)if(r.canHandle(t)){const[s,n]=r.serialize(t);return[{type:WireValueType.HANDLER,name:e,value:s},n]}return[{type:WireValueType.RAW,value:t},transferCache.get(t)||[]]}function fromWireValue(t){switch(t.type){case WireValueType.HANDLER:return transferHandlers.get(t.name).deserialize(t.value);case WireValueType.RAW:return t.value}}function requestResponseMessage(t,e,r,s){return new Promise(n=>{const i=generateUUID();e.set(i,n),t.start&&t.start(),t.postMessage({id:i,...r},s)})}function generateUUID(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}function nodeEndpoint(t){const e=new WeakMap;return{postMessage:t.postMessage.bind(t),addEventListener:(r,s)=>{const n=i=>{"handleEvent"in s?s.handleEvent({data:i}):s({data:i})};t.on("message",n),e.set(s,n)},removeEventListener:(r,s)=>{const n=e.get(s);n&&(t.off("message",n),e.delete(s))},start:t.start&&t.start.bind(t)}}const list=[Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError,AggregateError,globalThis.DOMException,globalThis.AssertionError,globalThis.SystemError].filter(Boolean).map(t=>[t.name,t]),errorConstructors=new Map(list);class NonError extends Error{constructor(e){super(NonError._prepareSuperMessage(e)),this.name="NonError"}static _prepareSuperMessage(e){try{return JSON.stringify(e)}catch{return String(e)}}}const errorProperties=[{property:"name",enumerable:!1},{property:"message",enumerable:!1},{property:"stack",enumerable:!1},{property:"code",enumerable:!0},{property:"cause",enumerable:!1},{property:"errors",enumerable:!1}],toJsonWasCalled=new WeakSet,toJSON=t=>{toJsonWasCalled.add(t);const e=t.toJSON();return toJsonWasCalled.delete(t),e},newError=t=>{const e=errorConstructors.get(t)??Error;return e===AggregateError?new e([]):new e},destroyCircular=({from:t,seen:e,to:r,forceEnumerable:s,maxDepth:n,depth:i,useToJSON:o,serialize:a})=>{if(r||(Array.isArray(t)?r=[]:!a&&isErrorLike(t)?r=newError(t.name):r={}),e.push(t),i>=n)return r;if(o&&typeof t.toJSON=="function"&&!toJsonWasCalled.has(t))return toJSON(t);const l=c=>destroyCircular({from:c,seen:[...e],forceEnumerable:s,maxDepth:n,depth:i,useToJSON:o,serialize:a});for(const[c,p]of Object.entries(t)){if(p&&p instanceof Uint8Array&&p.constructor.name==="Buffer"){r[c]="[object Buffer]";continue}if(p!==null&&typeof p=="object"&&typeof p.pipe=="function"){r[c]="[object Stream]";continue}if(typeof p!="function"){if(!p||typeof p!="object"){try{r[c]=p}catch{}continue}if(!e.includes(t[c])){i++,r[c]=l(t[c]);continue}r[c]="[Circular]"}}if(a||r instanceof Error)for(const{property:c,enumerable:p}of errorProperties)t[c]!==void 0&&t[c]!==null&&Object.defineProperty(r,c,{value:isErrorLike(t[c])||Array.isArray(t[c])?l(t[c]):t[c],enumerable:s?!0:p,configurable:!0,writable:!0});return r};function serializeError(t,e={}){const{maxDepth:r=Number.POSITIVE_INFINITY,useToJSON:s=!0}=e;return typeof t=="object"&&t!==null?destroyCircular({from:t,seen:[],forceEnumerable:!0,maxDepth:r,depth:0,useToJSON:s,serialize:!0}):typeof t=="function"?`[Function: ${t.name||"anonymous"}]`:t}function deserializeError(t,e={}){const{maxDepth:r=Number.POSITIVE_INFINITY}=e;return t instanceof Error?t:isMinimumViableSerializedError(t)?destroyCircular({from:t,seen:[],to:newError(t.name),maxDepth:r,depth:0,serialize:!1}):new NonError(t)}function isErrorLike(t){return!!t&&typeof t=="object"&&typeof t.name=="string"&&typeof t.message=="string"&&typeof t.stack=="string"}function isMinimumViableSerializedError(t){return!!t&&typeof t=="object"&&typeof t.message=="string"&&!Array.isArray(t)}async function consumeAPISync(t){setupTransferHandlers();const e=await NodeSABSyncReceiveMessageTransport.create();return wrapSync(t,e)}function consumeAPI(t,e=void 0){setupTransferHandlers();let r;(typeof document>"u"?require("url").pathToFileURL(__filename).href:_documentCurrentScript&&_documentCurrentScript.tagName.toUpperCase()==="SCRIPT"&&_documentCurrentScript.src||new URL("index.cjs",document.baseURI).href).startsWith("file://")?r=nodeEndpoint(t):r=t instanceof Worker?t:windowEndpoint(t,e);const n=wrap(r),i=proxyClone(n);return new Proxy(i,{get:(o,a)=>a==="isConnected"?async()=>{for(;;)try{await runWithTimeout(n.isConnected(),200);break}catch{}}:n[a]})}async function runWithTimeout(t,e){return new Promise((r,s)=>{setTimeout(s,e),t.then(r)})}function exposeAPI(t,e,r){const{setReady:s,setFailed:n,exposedApi:i}=prepareForExpose(t,e);let o;return r?o=nodeEndpoint(r):o=typeof window<"u"?windowEndpoint(self.parent):void 0,expose(i,o),[s,n,i]}async function exposeSyncAPI(t,e){const{setReady:r,setFailed:s,exposedApi:n}=prepareForExpose(t),i=await NodeSABSyncReceiveMessageTransport.create(),o=nodeEndpoint(e);return exposeSync(n,o,i),[r,s,n]}function prepareForExpose(t,e){setupTransferHandlers();const r=Promise.resolve();let s,n;const i=new Promise((l,c)=>{s=l,n=c}),o=proxyClone(t),a=new Proxy(o,{get:(l,c)=>c==="isConnected"?()=>r:c==="isReady"?()=>i:c in l?l[c]:e==null?void 0:e[c]});return{setReady:s,setFailed:n,exposedApi:a}}let isTransferHandlersSetup=!1;function setupTransferHandlers(){if(isTransferHandlersSetup)return;isTransferHandlersSetup=!0,transferHandlers.set("EVENT",{canHandle:r=>r instanceof CustomEvent,serialize:r=>[{detail:r.detail},[]],deserialize:r=>r}),transferHandlers.set("FUNCTION",{canHandle:r=>typeof r=="function",serialize(r){const{port1:s,port2:n}=new MessageChannel;return expose(r,s),[n,[n]]},deserialize(r){return r.start(),wrap(r)}}),transferHandlers.set("MESSAGE_PORT",{canHandle:r=>r instanceof MessagePort,serialize(r){return[r,[r]]},deserialize(r){return r}}),transferHandlers.set("PHPResponse",{canHandle:r=>typeof r=="object"&&r!==null&&"headers"in r&&"bytes"in r&&"errors"in r&&"exitCode"in r&&"httpStatusCode"in r,serialize(r){return[r.toRawData(),[]]},deserialize(r){return PHPResponse.fromRawData(r)}});const t=transferHandlers.get("throw"),e=t==null?void 0:t.serialize;t.serialize=({value:r})=>{const s=e({value:r});return r.response&&(s[0].value.response=r.response),r.source&&(s[0].value.source=r.source),s}}const throwTransferHandler=transferHandlers.get("throw"),throwTransferHandlerCustom={canHandle:throwTransferHandler.canHandle,serialize:({value:t})=>{let e;return t instanceof Error?(e={isError:!0,value:serializeError(t)},e.value.originalErrorClassName=t.constructor.name):e={isError:!1,value:t},[e,[]]},deserialize:t=>{if(t.isError){const e=deserializeError(t.value),r=new Error("Comlink method call failed");let s=e;for(;s.cause;)s=s.cause;throw s.cause=r,e}throw t.value}};transferHandlers.set("throw",throwTransferHandlerCustom);function proxyClone(t){return new Proxy(t,{get(e,r){switch(typeof e[r]){case"function":return(...s)=>e[r](...s);case"object":return e[r]===null?e[r]:proxyClone(e[r]);case"undefined":case"number":case"string":return e[r];default:return proxy(e[r])}}})}exports.DEFAULT_BASE_URL=DEFAULT_BASE_URL;exports.FSHelpers=FSHelpers;exports.HttpCookieStore=HttpCookieStore;exports.LatestSupportedPHPVersion=LatestSupportedPHPVersion;exports.PHP=PHP;exports.PHPExecutionFailureError=PHPExecutionFailureError;exports.PHPProcessManager=PHPProcessManager;exports.PHPRequestHandler=PHPRequestHandler;exports.PHPResponse=PHPResponse;exports.PHPWorker=PHPWorker;exports.StreamedPHPResponse=StreamedPHPResponse;exports.SupportedPHPVersions=SupportedPHPVersions;exports.SupportedPHPVersionsList=SupportedPHPVersionsList;exports.UnhandledRejectionsTarget=UnhandledRejectionsTarget;exports.__private__dont__use=__private__dont__use;exports.applyRewriteRules=applyRewriteRules;exports.consumeAPI=consumeAPI;exports.consumeAPISync=consumeAPISync;exports.ensurePathPrefix=ensurePathPrefix;exports.exposeAPI=exposeAPI;exports.exposeSyncAPI=exposeSyncAPI;exports.getLoadedRuntime=getLoadedRuntime;exports.getPhpIniEntries=getPhpIniEntries;exports.isExitCode=isExitCode;exports.iterateFiles=iteratePhpFiles;exports.loadPHPRuntime=loadPHPRuntime;exports.prettyPrintFullStackTrace=prettyPrintFullStackTrace;exports.printDebugDetails=printDebugDetails;exports.printResponseDebugDetails=printResponseDebugDetails;exports.proxyFileSystem=proxyFileSystem;exports.removePathPrefix=removePathPrefix;exports.rotatePHPRuntime=rotatePHPRuntime;exports.sandboxedSpawnHandlerFactory=sandboxedSpawnHandlerFactory;exports.setPhpIniEntries=setPhpIniEntries;exports.toRelativeUrl=toRelativeUrl;exports.withPHPIniValues=withPHPIniValues;exports.writeFiles=writeFiles;exports.writeFilesStreamToPhp=writeFilesStreamToPhp;
100
100
  //# sourceMappingURL=index.cjs.map