@php-wasm/fs-journal 0.9.13 → 0.9.15
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 +1 -4
- package/index.js +113 -687
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`):JSON.stringify(r,null,2),C=[],F=r=>{C.push(r)},v=r=>{if(r.raw===!0)F(r.message);else{const e=W(typeof r.message=="object"?P(r.message):r.message,r.severity??"Info",r.prefix??"JavaScript");F(e)}};class M extends EventTarget{constructor(e=[]){super(),this.handlers=e,this.fatalErrorEvent="playground-fatal-error"}getLogs(){return this.handlers.includes(v)?[...C]:(this.error(`Logs aren't stored because the logToMemory handler isn't registered.
|
|
3
|
-
If you're using a custom logger instance, make sure to register logToMemory handler.
|
|
4
|
-
`),[])}logMessage(e,...t){for(const o of this.handlers)o(e,...t)}log(e,...t){this.logMessage({message:e,severity:void 0,prefix:"JavaScript",raw:!1},...t)}debug(e,...t){this.logMessage({message:e,severity:"Debug",prefix:"JavaScript",raw:!1},...t)}info(e,...t){this.logMessage({message:e,severity:"Info",prefix:"JavaScript",raw:!1},...t)}warn(e,...t){this.logMessage({message:e,severity:"Warn",prefix:"JavaScript",raw:!1},...t)}error(e,...t){this.logMessage({message:e,severity:"Error",prefix:"JavaScript",raw:!1},...t)}}const S=()=>{try{if(process.env.NODE_ENV==="test")return[v,R]}catch{}return[v,B,R]},b=new M(S()),w=r=>r.replace(/\t/g,""),W=(r,e,t)=>{const o=new Date,n=new Intl.DateTimeFormat("en-GB",{year:"numeric",month:"short",day:"2-digit",timeZone:"UTC"}).format(o).replace(/ /g,"-"),i=new Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1,timeZone:"UTC",timeZoneName:"short"}).format(o),s=n+" "+i;return r=w(r),`[${s}] ${t} ${e}: ${r}`},N=Symbol("SleepFinished");function L(r){return new Promise(e=>{setTimeout(()=>e(N),r)})}class $ extends Error{constructor(){super("Acquiring lock timed out")}}class _{constructor({concurrency:e,timeout:t}){this._running=0,this.concurrency=e,this.timeout=t,this.queue=[]}get remaining(){return this.concurrency-this.running}get running(){return this._running}async acquire(){for(;;)if(this._running>=this.concurrency){const e=new Promise(t=>{this.queue.push(t)});this.timeout!==void 0?await Promise.race([e,L(this.timeout)]).then(t=>{if(t===N)throw new $}):await e}else{this._running++;let e=!1;return()=>{e||(e=!0,this._running--,this.queue.length>0&&this.queue.shift()())}}}async run(e){const t=await this.acquire();try{return await e()}finally{t()}}}function g(...r){let e=r.join("/");const t=e[0]==="/",o=e.substring(e.length-1)==="/";return e=T(e),!e&&!t&&(e="."),e&&o&&(e+="/"),e}function q(r){if(r==="/")return"/";r=T(r);const e=r.lastIndexOf("/");return e===-1?"":e===0?"/":r.substr(0,e)}function j(r){if(r==="/")return"/";r=T(r);const e=r.lastIndexOf("/");return e===-1?r:r.substr(e+1)}function T(r){const e=r[0]==="/";return r=J(r.split("/").filter(t=>!!t),!e).join("/"),(e?"/":"")+r.replace(/\/$/,"")}function J(r,e){let t=0;for(let o=r.length-1;o>=0;o--){const n=r[o];n==="."?r.splice(o,1):n===".."?(r.splice(o,1),t++):t&&(r.splice(o,1),t--)}if(e)for(;t;t--)r.unshift("..");return r}var z=Object.defineProperty,U=Object.getOwnPropertyDescriptor,d=(r,e,t,o)=>{for(var n=o>1?void 0:o?U(e,t):e,i=r.length-1,s;i>=0;i--)(s=r[i])&&(n=(o?s(e,t,n):s(n))||n);return o&&n&&z(e,t,n),n};const f=class c{static readFileAsText(e,t){return new TextDecoder().decode(c.readFileAsBuffer(e,t))}static readFileAsBuffer(e,t){return e.readFile(t)}static writeFile(e,t,o){e.writeFile(t,o)}static unlink(e,t){e.unlink(t)}static mv(e,t,o){try{const n=e.lookupPath(t).node.mount,i=c.fileExists(e,o)?e.lookupPath(o).node.mount:e.lookupPath(q(o)).node.mount;n.mountpoint!==i.mountpoint?(c.copyRecursive(e,t,o),c.rmdir(e,t,{recursive:!0})):e.rename(t,o)}catch(n){const i=x(n);throw i?new Error(`Could not move ${t} to ${o}: ${i}`,{cause:n}):n}}static rmdir(e,t,o={recursive:!0}){o!=null&&o.recursive&&c.listFiles(e,t).forEach(n=>{const i=`${t}/${n}`;c.isDir(e,i)?c.rmdir(e,i,o):c.unlink(e,i)}),e.rmdir(t)}static listFiles(e,t,o={prependPath:!1}){if(!c.fileExists(e,t))return[];try{const n=e.readdir(t).filter(i=>i!=="."&&i!=="..");if(o.prependPath){const i=t.replace(/\/$/,"");return n.map(s=>`${i}/${s}`)}return n}catch(n){return b.error(n,{path:t}),[]}}static isDir(e,t){return c.fileExists(e,t)?e.isDir(e.lookupPath(t).node.mode):!1}static fileExists(e,t){try{return e.lookupPath(t),!0}catch{return!1}}static mkdir(e,t){e.mkdirTree(t)}static copyRecursive(e,t,o){const n=e.lookupPath(t).node;if(e.isDir(n.mode)){e.mkdirTree(o);const i=e.readdir(t).filter(s=>s!=="."&&s!=="..");for(const s of i)c.copyRecursive(e,g(t,s),g(o,s))}else e.writeFile(o,e.readFile(t))}};d([u('Could not read "{path}"')],f,"readFileAsText",1);d([u('Could not read "{path}"')],f,"readFileAsBuffer",1);d([u('Could not write to "{path}"')],f,"writeFile",1);d([u('Could not unlink "{path}"')],f,"unlink",1);d([u('Could not remove directory "{path}"')],f,"rmdir",1);d([u('Could not list files in "{path}"')],f,"listFiles",1);d([u('Could not stat "{path}"')],f,"isDir",1);d([u('Could not stat "{path}"')],f,"fileExists",1);d([u('Could not create directory "{path}"')],f,"mkdir",1);d([u('Could not copy files from "{path}"')],f,"copyRecursive",1);(function(){var r;return typeof process<"u"&&((r=process.release)==null?void 0:r.name)==="node"?"NODE":typeof window<"u"?"WEB":typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?"WORKER":"NODE"})();const p=Symbol("__private__dont__use");ReadableStream.prototype[Symbol.asyncIterator]||(ReadableStream.prototype[Symbol.asyncIterator]=async function*(){const r=this.getReader();try{for(;;){const{done:e,value:t}=await r.read();if(e)return;yield t}}finally{r.releaseLock()}},ReadableStream.prototype.iterate=ReadableStream.prototype[Symbol.asyncIterator]);function G(r,e,t=()=>{}){function o(){e=K(e);const i=r[p].FS,s=H(i,l=>{if(l.path.startsWith(e))t(l);else if(l.operation==="RENAME"&&l.toPath.startsWith(e))for(const y of D(r,l.path,l.toPath))t(y)}),a={};for(const[l]of Object.entries(s))a[l]=i[l];function m(){for(const[l,y]of Object.entries(s))i[l]=function(...k){return y(...k),a[l].apply(this,k)}}function h(){for(const[l,y]of Object.entries(a))r[p].FS[l]=y}r[p].journal={bind:m,unbind:h},m()}r.addEventListener("runtime.initialized",o),r[p]&&o();function n(){r[p].journal.unbind(),delete r[p].journal}return r.addEventListener("runtime.beforedestroy",n),function(){return r.removeEventListener("runtime.initialized",o),r.removeEventListener("runtime.beforedestroy",n),r[p].journal.unbind()}}const H=(r,e=()=>{})=>({write(t){e({operation:"WRITE",path:t.path,nodeType:"file"})},truncate(t){let o;typeof t=="string"?o=r.lookupPath(t,{follow:!0}).node:o=t,e({operation:"WRITE",path:r.getPath(o),nodeType:"file"})},unlink(t){e({operation:"DELETE",path:t,nodeType:"file"})},mknod(t,o){r.isFile(o)&&e({operation:"CREATE",path:t,nodeType:"file"})},mkdir(t){e({operation:"CREATE",path:t,nodeType:"directory"})},rmdir(t){e({operation:"DELETE",path:t,nodeType:"directory"})},rename(t,o){try{const n=r.lookupPath(t,{follow:!0}),i=r.lookupPath(o,{parent:!0}).path;e({operation:"RENAME",nodeType:r.isDir(n.node.mode)?"directory":"file",path:n.path,toPath:g(i,j(o))})}catch{}}});function Z(r,e){r[p].journal.unbind();try{for(const t of e)t.operation==="CREATE"?t.nodeType==="file"?r.writeFile(t.path," "):r.mkdir(t.path):t.operation==="DELETE"?t.nodeType==="file"?r.unlink(t.path):r.rmdir(t.path):t.operation==="WRITE"?r.writeFile(t.path,t.data):t.operation==="RENAME"&&r.mv(t.path,t.toPath)}finally{r[p].journal.bind()}}function*D(r,e,t){if(r.isDir(e)){yield{operation:"CREATE",path:t,nodeType:"directory"};for(const o of r.listFiles(e))yield*D(r,g(e,o),g(t,o))}else yield{operation:"CREATE",path:t,nodeType:"file"},yield{operation:"WRITE",nodeType:"file",path:t}}function K(r){return r.replace(/\/$/,"").replace(/\/\/+/g,"/")}function O(r){const e={};for(let t=r.length-1;t>=0;t--){for(let o=t-1;o>=0;o--){const n=V(r[t],r[o]);if(n==="none")continue;const i=r[t],s=r[o];if(i.operation==="RENAME"&&s.operation==="RENAME"){b.warn("[FS Journal] Normalizing a double rename is not yet supported:",{current:i,last:s});continue}(s.operation==="CREATE"||s.operation==="WRITE")&&(i.operation==="RENAME"?n==="same_node"?(e[o]=[],e[t]=[{...s,path:i.toPath},...e[t]||[]]):n==="descendant"&&(e[o]=[],e[t]=[{...s,path:g(i.toPath,s.path.substring(i.path.length))},...e[t]||[]]):i.operation==="WRITE"&&n==="same_node"?e[o]=[]:i.operation==="DELETE"&&n==="same_node"&&(e[o]=[],e[t]=[]))}if(Object.entries(e).length>0){const o=r.flatMap((n,i)=>i in e?e[i]:[n]);return O(o)}}return r}function V(r,e){const t=r.path,o=r.operation!=="WRITE"&&r.nodeType==="directory",n=e.operation!=="WRITE"&&e.nodeType==="directory",i=e.operation==="RENAME"?e.toPath:e.path;return i===t?"same_node":n&&t.startsWith(i+"/")?"ancestor":o&&i.startsWith(t+"/")?"descendant":"none"}async function Y(r,e){const o=e.filter(n=>n.operation==="WRITE").map(n=>X(r,n));return await Promise.all(o),e}const Q=new _({concurrency:15});async function X(r,e){const t=await Q.acquire();try{e.data=await r.readFileAsBuffer(e.path)}catch(o){b.warn(`Journal failed to hydrate a file on flush: the path ${e.path} no longer exists`),b.error(o)}t()}exports.hydrateUpdateFileOps=Y;exports.journalFSEvents=G;exports.normalizeFilesystemOperations=O;exports.replayFSJournal=Z;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@php-wasm/universal"),u=require("@php-wasm/util"),f=require("@php-wasm/logger");function T(t,n,e=()=>{}){function o(){n=b(n);const i=t[l.__private__dont__use].FS,s=m(i,a=>{if(a.path.startsWith(n))e(a);else if(a.operation==="RENAME"&&a.toPath.startsWith(n))for(const d of E(t,a.path,a.toPath))e(d)}),c={};for(const[a]of Object.entries(s))c[a]=i[a];function p(){for(const[a,d]of Object.entries(s))i[a]=function(..._){return d(..._),c[a].apply(this,_)}}function y(){for(const[a,d]of Object.entries(c))t[l.__private__dont__use].FS[a]=d}t[l.__private__dont__use].journal={bind:p,unbind:y},p()}t.addEventListener("runtime.initialized",o),t[l.__private__dont__use]&&o();function r(){t[l.__private__dont__use].journal.unbind(),delete t[l.__private__dont__use].journal}return t.addEventListener("runtime.beforedestroy",r),function(){return t.removeEventListener("runtime.initialized",o),t.removeEventListener("runtime.beforedestroy",r),t[l.__private__dont__use].journal.unbind()}}const m=(t,n=()=>{})=>({write(e){n({operation:"WRITE",path:e.path,nodeType:"file"})},truncate(e){let o;typeof e=="string"?o=t.lookupPath(e,{follow:!0}).node:o=e,n({operation:"WRITE",path:t.getPath(o),nodeType:"file"})},unlink(e){n({operation:"DELETE",path:e,nodeType:"file"})},mknod(e,o){t.isFile(o)&&n({operation:"CREATE",path:e,nodeType:"file"})},mkdir(e){n({operation:"CREATE",path:e,nodeType:"directory"})},rmdir(e){n({operation:"DELETE",path:e,nodeType:"directory"})},rename(e,o){try{const r=t.lookupPath(e,{follow:!0}),i=t.lookupPath(o,{parent:!0}).path;n({operation:"RENAME",nodeType:t.isDir(r.node.mode)?"directory":"file",path:r.path,toPath:u.joinPaths(i,u.basename(o))})}catch{}}});function R(t,n){t[l.__private__dont__use].journal.unbind();try{for(const e of n)e.operation==="CREATE"?e.nodeType==="file"?t.writeFile(e.path," "):t.mkdir(e.path):e.operation==="DELETE"?e.nodeType==="file"?t.unlink(e.path):t.rmdir(e.path):e.operation==="WRITE"?t.writeFile(e.path,e.data):e.operation==="RENAME"&&t.mv(e.path,e.toPath)}finally{t[l.__private__dont__use].journal.bind()}}function*E(t,n,e){if(t.isDir(n)){yield{operation:"CREATE",path:e,nodeType:"directory"};for(const o of t.listFiles(n))yield*E(t,u.joinPaths(n,o),u.joinPaths(e,o))}else yield{operation:"CREATE",path:e,nodeType:"file"},yield{operation:"WRITE",nodeType:"file",path:e}}function b(t){return t.replace(/\/$/,"").replace(/\/\/+/g,"/")}function h(t){const n={};for(let e=t.length-1;e>=0;e--){for(let o=e-1;o>=0;o--){const r=g(t[e],t[o]);if(r==="none")continue;const i=t[e],s=t[o];if(i.operation==="RENAME"&&s.operation==="RENAME"){f.logger.warn("[FS Journal] Normalizing a double rename is not yet supported:",{current:i,last:s});continue}(s.operation==="CREATE"||s.operation==="WRITE")&&(i.operation==="RENAME"?r==="same_node"?(n[o]=[],n[e]=[{...s,path:i.toPath},...n[e]||[]]):r==="descendant"&&(n[o]=[],n[e]=[{...s,path:u.joinPaths(i.toPath,s.path.substring(i.path.length))},...n[e]||[]]):i.operation==="WRITE"&&r==="same_node"?n[o]=[]:i.operation==="DELETE"&&r==="same_node"&&(n[o]=[],n[e]=[]))}if(Object.entries(n).length>0){const o=t.flatMap((r,i)=>i in n?n[i]:[r]);return h(o)}}return t}function g(t,n){const e=t.path,o=t.operation!=="WRITE"&&t.nodeType==="directory",r=n.operation!=="WRITE"&&n.nodeType==="directory",i=n.operation==="RENAME"?n.toPath:n.path;return i===e?"same_node":r&&e.startsWith(i+"/")?"ancestor":o&&i.startsWith(e+"/")?"descendant":"none"}async function v(t,n){const o=n.filter(r=>r.operation==="WRITE").map(r=>P(t,r));return await Promise.all(o),n}const F=new u.Semaphore({concurrency:15});async function P(t,n){const e=await F.acquire();try{n.data=await t.readFileAsBuffer(n.path)}catch(o){f.logger.warn(`Journal failed to hydrate a file on flush: the path ${n.path} no longer exists`),f.logger.error(o)}e()}exports.hydrateUpdateFileOps=v;exports.journalFSEvents=T;exports.normalizeFilesystemOperations=h;exports.replayFSJournal=R;
|
package/index.js
CHANGED
|
@@ -1,730 +1,156 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
typeof WorkerGlobalScope < "u" && // @ts-ignore
|
|
6
|
-
self instanceof WorkerGlobalScope ? "WORKER" : "NODE"
|
|
7
|
-
);
|
|
8
|
-
}();
|
|
9
|
-
if (C === "NODE") {
|
|
10
|
-
let r = function(t) {
|
|
11
|
-
return new Promise(function(o, n) {
|
|
12
|
-
t.onload = t.onerror = function(i) {
|
|
13
|
-
t.onload = t.onerror = null, i.type === "load" ? o(t.result) : n(new Error("Failed to read the blob/file"));
|
|
14
|
-
};
|
|
15
|
-
});
|
|
16
|
-
}, e = function() {
|
|
17
|
-
const t = new Uint8Array([1, 2, 3, 4]), n = new File([t], "test").stream();
|
|
18
|
-
try {
|
|
19
|
-
return n.getReader({ mode: "byob" }), !0;
|
|
20
|
-
} catch {
|
|
21
|
-
return !1;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
if (typeof File > "u") {
|
|
25
|
-
class t extends Blob {
|
|
26
|
-
constructor(n, i, s) {
|
|
27
|
-
super(n);
|
|
28
|
-
let a;
|
|
29
|
-
s != null && s.lastModified && (a = /* @__PURE__ */ new Date()), (!a || isNaN(a.getFullYear())) && (a = /* @__PURE__ */ new Date()), this.lastModifiedDate = a, this.lastModified = a.getMilliseconds(), this.name = i || "";
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
global.File = t;
|
|
33
|
-
}
|
|
34
|
-
typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
|
|
35
|
-
const o = new FileReader();
|
|
36
|
-
return o.readAsArrayBuffer(this), r(o);
|
|
37
|
-
}), typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
|
|
38
|
-
const o = new FileReader();
|
|
39
|
-
return o.readAsText(this), r(o);
|
|
40
|
-
}), (typeof Blob.prototype.stream > "u" || !e()) && (Blob.prototype.stream = function() {
|
|
41
|
-
let t = 0;
|
|
42
|
-
const o = this;
|
|
43
|
-
return new ReadableStream({
|
|
44
|
-
type: "bytes",
|
|
45
|
-
// 0.5 MB seems like a reasonable chunk size, let's adjust
|
|
46
|
-
// this if needed.
|
|
47
|
-
autoAllocateChunkSize: 512 * 1024,
|
|
48
|
-
async pull(n) {
|
|
49
|
-
const i = n.byobRequest.view, a = await o.slice(
|
|
50
|
-
t,
|
|
51
|
-
t + i.byteLength
|
|
52
|
-
).arrayBuffer(), m = new Uint8Array(a);
|
|
53
|
-
new Uint8Array(i.buffer).set(m);
|
|
54
|
-
const h = m.byteLength;
|
|
55
|
-
n.byobRequest.respond(h), t += h, t >= o.size && n.close();
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
if (C === "NODE" && typeof CustomEvent > "u") {
|
|
61
|
-
class r extends Event {
|
|
62
|
-
constructor(t, o = {}) {
|
|
63
|
-
super(t, o), this.detail = o.detail;
|
|
64
|
-
}
|
|
65
|
-
initCustomEvent() {
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
globalThis.CustomEvent = r;
|
|
69
|
-
}
|
|
70
|
-
const E = {
|
|
71
|
-
0: "No error occurred. System call completed successfully.",
|
|
72
|
-
1: "Argument list too long.",
|
|
73
|
-
2: "Permission denied.",
|
|
74
|
-
3: "Address in use.",
|
|
75
|
-
4: "Address not available.",
|
|
76
|
-
5: "Address family not supported.",
|
|
77
|
-
6: "Resource unavailable, or operation would block.",
|
|
78
|
-
7: "Connection already in progress.",
|
|
79
|
-
8: "Bad file descriptor.",
|
|
80
|
-
9: "Bad message.",
|
|
81
|
-
10: "Device or resource busy.",
|
|
82
|
-
11: "Operation canceled.",
|
|
83
|
-
12: "No child processes.",
|
|
84
|
-
13: "Connection aborted.",
|
|
85
|
-
14: "Connection refused.",
|
|
86
|
-
15: "Connection reset.",
|
|
87
|
-
16: "Resource deadlock would occur.",
|
|
88
|
-
17: "Destination address required.",
|
|
89
|
-
18: "Mathematics argument out of domain of function.",
|
|
90
|
-
19: "Reserved.",
|
|
91
|
-
20: "File exists.",
|
|
92
|
-
21: "Bad address.",
|
|
93
|
-
22: "File too large.",
|
|
94
|
-
23: "Host is unreachable.",
|
|
95
|
-
24: "Identifier removed.",
|
|
96
|
-
25: "Illegal byte sequence.",
|
|
97
|
-
26: "Operation in progress.",
|
|
98
|
-
27: "Interrupted function.",
|
|
99
|
-
28: "Invalid argument.",
|
|
100
|
-
29: "I/O error.",
|
|
101
|
-
30: "Socket is connected.",
|
|
102
|
-
31: "There is a directory under that path.",
|
|
103
|
-
32: "Too many levels of symbolic links.",
|
|
104
|
-
33: "File descriptor value too large.",
|
|
105
|
-
34: "Too many links.",
|
|
106
|
-
35: "Message too large.",
|
|
107
|
-
36: "Reserved.",
|
|
108
|
-
37: "Filename too long.",
|
|
109
|
-
38: "Network is down.",
|
|
110
|
-
39: "Connection aborted by network.",
|
|
111
|
-
40: "Network unreachable.",
|
|
112
|
-
41: "Too many files open in system.",
|
|
113
|
-
42: "No buffer space available.",
|
|
114
|
-
43: "No such device.",
|
|
115
|
-
44: "There is no such file or directory OR the parent directory does not exist.",
|
|
116
|
-
45: "Executable file format error.",
|
|
117
|
-
46: "No locks available.",
|
|
118
|
-
47: "Reserved.",
|
|
119
|
-
48: "Not enough space.",
|
|
120
|
-
49: "No message of the desired type.",
|
|
121
|
-
50: "Protocol not available.",
|
|
122
|
-
51: "No space left on device.",
|
|
123
|
-
52: "Function not supported.",
|
|
124
|
-
53: "The socket is not connected.",
|
|
125
|
-
54: "Not a directory or a symbolic link to a directory.",
|
|
126
|
-
55: "Directory not empty.",
|
|
127
|
-
56: "State not recoverable.",
|
|
128
|
-
57: "Not a socket.",
|
|
129
|
-
58: "Not supported, or operation not supported on socket.",
|
|
130
|
-
59: "Inappropriate I/O control operation.",
|
|
131
|
-
60: "No such device or address.",
|
|
132
|
-
61: "Value too large to be stored in data type.",
|
|
133
|
-
62: "Previous owner died.",
|
|
134
|
-
63: "Operation not permitted.",
|
|
135
|
-
64: "Broken pipe.",
|
|
136
|
-
65: "Protocol error.",
|
|
137
|
-
66: "Protocol not supported.",
|
|
138
|
-
67: "Protocol wrong type for socket.",
|
|
139
|
-
68: "Result too large.",
|
|
140
|
-
69: "Read-only file system.",
|
|
141
|
-
70: "Invalid seek.",
|
|
142
|
-
71: "No such process.",
|
|
143
|
-
72: "Reserved.",
|
|
144
|
-
73: "Connection timed out.",
|
|
145
|
-
74: "Text file busy.",
|
|
146
|
-
75: "Cross-device link.",
|
|
147
|
-
76: "Extension: Capabilities insufficient."
|
|
148
|
-
};
|
|
149
|
-
function O(r) {
|
|
150
|
-
const e = typeof r == "object" ? r == null ? void 0 : r.errno : null;
|
|
151
|
-
if (e in E)
|
|
152
|
-
return E[e];
|
|
153
|
-
}
|
|
154
|
-
function u(r = "") {
|
|
155
|
-
return function(t, o, n) {
|
|
156
|
-
const i = n.value;
|
|
157
|
-
n.value = function(...s) {
|
|
158
|
-
try {
|
|
159
|
-
return i.apply(this, s);
|
|
160
|
-
} catch (a) {
|
|
161
|
-
const m = typeof a == "object" ? a == null ? void 0 : a.errno : null;
|
|
162
|
-
if (m in E) {
|
|
163
|
-
const h = E[m], l = typeof s[1] == "string" ? s[1] : null, y = l !== null ? r.replaceAll("{path}", l) : r;
|
|
164
|
-
throw new Error(`${y}: ${h}`, {
|
|
165
|
-
cause: a
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
throw a;
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
const x = "playground-log", R = (r, ...e) => {
|
|
174
|
-
b.dispatchEvent(
|
|
175
|
-
new CustomEvent(x, {
|
|
176
|
-
detail: {
|
|
177
|
-
log: r,
|
|
178
|
-
args: e
|
|
179
|
-
}
|
|
180
|
-
})
|
|
181
|
-
);
|
|
182
|
-
}, I = (r, ...e) => {
|
|
183
|
-
switch (typeof r.message == "string" ? r.message = w(r.message) : r.message.message && typeof r.message.message == "string" && (r.message.message = w(r.message.message)), r.severity) {
|
|
184
|
-
case "Debug":
|
|
185
|
-
console.debug(r.message, ...e);
|
|
186
|
-
break;
|
|
187
|
-
case "Info":
|
|
188
|
-
console.info(r.message, ...e);
|
|
189
|
-
break;
|
|
190
|
-
case "Warn":
|
|
191
|
-
console.warn(r.message, ...e);
|
|
192
|
-
break;
|
|
193
|
-
case "Error":
|
|
194
|
-
console.error(r.message, ...e);
|
|
195
|
-
break;
|
|
196
|
-
case "Fatal":
|
|
197
|
-
console.error(r.message, ...e);
|
|
198
|
-
break;
|
|
199
|
-
default:
|
|
200
|
-
console.log(r.message, ...e);
|
|
201
|
-
}
|
|
202
|
-
}, B = (r) => r instanceof Error ? [r.message, r.stack].join(`
|
|
203
|
-
`) : JSON.stringify(r, null, 2), N = [], A = (r) => {
|
|
204
|
-
N.push(r);
|
|
205
|
-
}, v = (r) => {
|
|
206
|
-
if (r.raw === !0)
|
|
207
|
-
A(r.message);
|
|
208
|
-
else {
|
|
209
|
-
const e = W(
|
|
210
|
-
typeof r.message == "object" ? B(r.message) : r.message,
|
|
211
|
-
r.severity ?? "Info",
|
|
212
|
-
r.prefix ?? "JavaScript"
|
|
213
|
-
);
|
|
214
|
-
A(e);
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
class P extends EventTarget {
|
|
218
|
-
// constructor
|
|
219
|
-
constructor(e = []) {
|
|
220
|
-
super(), this.handlers = e, this.fatalErrorEvent = "playground-fatal-error";
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Get all logs.
|
|
224
|
-
* @returns string[]
|
|
225
|
-
*/
|
|
226
|
-
getLogs() {
|
|
227
|
-
return this.handlers.includes(v) ? [...N] : (this.error(`Logs aren't stored because the logToMemory handler isn't registered.
|
|
228
|
-
If you're using a custom logger instance, make sure to register logToMemory handler.
|
|
229
|
-
`), []);
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Log message with severity.
|
|
233
|
-
*
|
|
234
|
-
* @param message any
|
|
235
|
-
* @param severity LogSeverity
|
|
236
|
-
* @param raw boolean
|
|
237
|
-
* @param args any
|
|
238
|
-
*/
|
|
239
|
-
logMessage(e, ...t) {
|
|
240
|
-
for (const o of this.handlers)
|
|
241
|
-
o(e, ...t);
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Log message
|
|
245
|
-
*
|
|
246
|
-
* @param message any
|
|
247
|
-
* @param args any
|
|
248
|
-
*/
|
|
249
|
-
log(e, ...t) {
|
|
250
|
-
this.logMessage(
|
|
251
|
-
{
|
|
252
|
-
message: e,
|
|
253
|
-
severity: void 0,
|
|
254
|
-
prefix: "JavaScript",
|
|
255
|
-
raw: !1
|
|
256
|
-
},
|
|
257
|
-
...t
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Log debug message
|
|
262
|
-
*
|
|
263
|
-
* @param message any
|
|
264
|
-
* @param args any
|
|
265
|
-
*/
|
|
266
|
-
debug(e, ...t) {
|
|
267
|
-
this.logMessage(
|
|
268
|
-
{
|
|
269
|
-
message: e,
|
|
270
|
-
severity: "Debug",
|
|
271
|
-
prefix: "JavaScript",
|
|
272
|
-
raw: !1
|
|
273
|
-
},
|
|
274
|
-
...t
|
|
275
|
-
);
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Log info message
|
|
279
|
-
*
|
|
280
|
-
* @param message any
|
|
281
|
-
* @param args any
|
|
282
|
-
*/
|
|
283
|
-
info(e, ...t) {
|
|
284
|
-
this.logMessage(
|
|
285
|
-
{
|
|
286
|
-
message: e,
|
|
287
|
-
severity: "Info",
|
|
288
|
-
prefix: "JavaScript",
|
|
289
|
-
raw: !1
|
|
290
|
-
},
|
|
291
|
-
...t
|
|
292
|
-
);
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Log warning message
|
|
296
|
-
*
|
|
297
|
-
* @param message any
|
|
298
|
-
* @param args any
|
|
299
|
-
*/
|
|
300
|
-
warn(e, ...t) {
|
|
301
|
-
this.logMessage(
|
|
302
|
-
{
|
|
303
|
-
message: e,
|
|
304
|
-
severity: "Warn",
|
|
305
|
-
prefix: "JavaScript",
|
|
306
|
-
raw: !1
|
|
307
|
-
},
|
|
308
|
-
...t
|
|
309
|
-
);
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Log error message
|
|
313
|
-
*
|
|
314
|
-
* @param message any
|
|
315
|
-
* @param args any
|
|
316
|
-
*/
|
|
317
|
-
error(e, ...t) {
|
|
318
|
-
this.logMessage(
|
|
319
|
-
{
|
|
320
|
-
message: e,
|
|
321
|
-
severity: "Error",
|
|
322
|
-
prefix: "JavaScript",
|
|
323
|
-
raw: !1
|
|
324
|
-
},
|
|
325
|
-
...t
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
const M = () => {
|
|
330
|
-
try {
|
|
331
|
-
if (process.env.NODE_ENV === "test")
|
|
332
|
-
return [v, R];
|
|
333
|
-
} catch {
|
|
334
|
-
}
|
|
335
|
-
return [v, I, R];
|
|
336
|
-
}, b = new P(M()), w = (r) => r.replace(/\t/g, ""), W = (r, e, t) => {
|
|
337
|
-
const o = /* @__PURE__ */ new Date(), n = new Intl.DateTimeFormat("en-GB", {
|
|
338
|
-
year: "numeric",
|
|
339
|
-
month: "short",
|
|
340
|
-
day: "2-digit",
|
|
341
|
-
timeZone: "UTC"
|
|
342
|
-
}).format(o).replace(/ /g, "-"), i = new Intl.DateTimeFormat("en-GB", {
|
|
343
|
-
hour: "2-digit",
|
|
344
|
-
minute: "2-digit",
|
|
345
|
-
second: "2-digit",
|
|
346
|
-
hour12: !1,
|
|
347
|
-
timeZone: "UTC",
|
|
348
|
-
timeZoneName: "short"
|
|
349
|
-
}).format(o), s = n + " " + i;
|
|
350
|
-
return r = w(r), `[${s}] ${t} ${e}: ${r}`;
|
|
351
|
-
}, D = Symbol("SleepFinished");
|
|
352
|
-
function L(r) {
|
|
353
|
-
return new Promise((e) => {
|
|
354
|
-
setTimeout(() => e(D), r);
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
class S extends Error {
|
|
358
|
-
constructor() {
|
|
359
|
-
super("Acquiring lock timed out");
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
class $ {
|
|
363
|
-
constructor({ concurrency: e, timeout: t }) {
|
|
364
|
-
this._running = 0, this.concurrency = e, this.timeout = t, this.queue = [];
|
|
365
|
-
}
|
|
366
|
-
get remaining() {
|
|
367
|
-
return this.concurrency - this.running;
|
|
368
|
-
}
|
|
369
|
-
get running() {
|
|
370
|
-
return this._running;
|
|
371
|
-
}
|
|
372
|
-
async acquire() {
|
|
373
|
-
for (; ; )
|
|
374
|
-
if (this._running >= this.concurrency) {
|
|
375
|
-
const e = new Promise((t) => {
|
|
376
|
-
this.queue.push(t);
|
|
377
|
-
});
|
|
378
|
-
this.timeout !== void 0 ? await Promise.race([e, L(this.timeout)]).then(
|
|
379
|
-
(t) => {
|
|
380
|
-
if (t === D)
|
|
381
|
-
throw new S();
|
|
382
|
-
}
|
|
383
|
-
) : await e;
|
|
384
|
-
} else {
|
|
385
|
-
this._running++;
|
|
386
|
-
let e = !1;
|
|
387
|
-
return () => {
|
|
388
|
-
e || (e = !0, this._running--, this.queue.length > 0 && this.queue.shift()());
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
async run(e) {
|
|
393
|
-
const t = await this.acquire();
|
|
394
|
-
try {
|
|
395
|
-
return await e();
|
|
396
|
-
} finally {
|
|
397
|
-
t();
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
function g(...r) {
|
|
402
|
-
let e = r.join("/");
|
|
403
|
-
const t = e[0] === "/", o = e.substring(e.length - 1) === "/";
|
|
404
|
-
return e = T(e), !e && !t && (e = "."), e && o && (e += "/"), e;
|
|
405
|
-
}
|
|
406
|
-
function _(r) {
|
|
407
|
-
if (r === "/")
|
|
408
|
-
return "/";
|
|
409
|
-
r = T(r);
|
|
410
|
-
const e = r.lastIndexOf("/");
|
|
411
|
-
return e === -1 ? "" : e === 0 ? "/" : r.substr(0, e);
|
|
412
|
-
}
|
|
413
|
-
function q(r) {
|
|
414
|
-
if (r === "/")
|
|
415
|
-
return "/";
|
|
416
|
-
r = T(r);
|
|
417
|
-
const e = r.lastIndexOf("/");
|
|
418
|
-
return e === -1 ? r : r.substr(e + 1);
|
|
419
|
-
}
|
|
420
|
-
function T(r) {
|
|
421
|
-
const e = r[0] === "/";
|
|
422
|
-
return r = j(
|
|
423
|
-
r.split("/").filter((t) => !!t),
|
|
424
|
-
!e
|
|
425
|
-
).join("/"), (e ? "/" : "") + r.replace(/\/$/, "");
|
|
426
|
-
}
|
|
427
|
-
function j(r, e) {
|
|
428
|
-
let t = 0;
|
|
429
|
-
for (let o = r.length - 1; o >= 0; o--) {
|
|
430
|
-
const n = r[o];
|
|
431
|
-
n === "." ? r.splice(o, 1) : n === ".." ? (r.splice(o, 1), t++) : t && (r.splice(o, 1), t--);
|
|
432
|
-
}
|
|
433
|
-
if (e)
|
|
434
|
-
for (; t; t--)
|
|
435
|
-
r.unshift("..");
|
|
436
|
-
return r;
|
|
437
|
-
}
|
|
438
|
-
var J = Object.defineProperty, z = Object.getOwnPropertyDescriptor, d = (r, e, t, o) => {
|
|
439
|
-
for (var n = o > 1 ? void 0 : o ? z(e, t) : e, i = r.length - 1, s; i >= 0; i--)
|
|
440
|
-
(s = r[i]) && (n = (o ? s(e, t, n) : s(n)) || n);
|
|
441
|
-
return o && n && J(e, t, n), n;
|
|
442
|
-
};
|
|
443
|
-
const f = class c {
|
|
444
|
-
static readFileAsText(e, t) {
|
|
445
|
-
return new TextDecoder().decode(c.readFileAsBuffer(e, t));
|
|
446
|
-
}
|
|
447
|
-
static readFileAsBuffer(e, t) {
|
|
448
|
-
return e.readFile(t);
|
|
449
|
-
}
|
|
450
|
-
static writeFile(e, t, o) {
|
|
451
|
-
e.writeFile(t, o);
|
|
452
|
-
}
|
|
453
|
-
static unlink(e, t) {
|
|
454
|
-
e.unlink(t);
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* Moves a file or directory in the PHP filesystem to a
|
|
458
|
-
* new location.
|
|
459
|
-
*
|
|
460
|
-
* @param oldPath The path to rename.
|
|
461
|
-
* @param newPath The new path.
|
|
462
|
-
*/
|
|
463
|
-
static mv(e, t, o) {
|
|
464
|
-
try {
|
|
465
|
-
const n = e.lookupPath(t).node.mount, i = c.fileExists(e, o) ? e.lookupPath(o).node.mount : e.lookupPath(_(o)).node.mount;
|
|
466
|
-
n.mountpoint !== i.mountpoint ? (c.copyRecursive(e, t, o), c.rmdir(e, t, { recursive: !0 })) : e.rename(t, o);
|
|
467
|
-
} catch (n) {
|
|
468
|
-
const i = O(n);
|
|
469
|
-
throw i ? new Error(
|
|
470
|
-
`Could not move ${t} to ${o}: ${i}`,
|
|
471
|
-
{
|
|
472
|
-
cause: n
|
|
473
|
-
}
|
|
474
|
-
) : n;
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
static rmdir(e, t, o = { recursive: !0 }) {
|
|
478
|
-
o != null && o.recursive && c.listFiles(e, t).forEach((n) => {
|
|
479
|
-
const i = `${t}/${n}`;
|
|
480
|
-
c.isDir(e, i) ? c.rmdir(e, i, o) : c.unlink(e, i);
|
|
481
|
-
}), e.rmdir(t);
|
|
482
|
-
}
|
|
483
|
-
static listFiles(e, t, o = { prependPath: !1 }) {
|
|
484
|
-
if (!c.fileExists(e, t))
|
|
485
|
-
return [];
|
|
486
|
-
try {
|
|
487
|
-
const n = e.readdir(t).filter(
|
|
488
|
-
(i) => i !== "." && i !== ".."
|
|
489
|
-
);
|
|
490
|
-
if (o.prependPath) {
|
|
491
|
-
const i = t.replace(/\/$/, "");
|
|
492
|
-
return n.map((s) => `${i}/${s}`);
|
|
493
|
-
}
|
|
494
|
-
return n;
|
|
495
|
-
} catch (n) {
|
|
496
|
-
return b.error(n, { path: t }), [];
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
static isDir(e, t) {
|
|
500
|
-
return c.fileExists(e, t) ? e.isDir(e.lookupPath(t).node.mode) : !1;
|
|
501
|
-
}
|
|
502
|
-
static fileExists(e, t) {
|
|
503
|
-
try {
|
|
504
|
-
return e.lookupPath(t), !0;
|
|
505
|
-
} catch {
|
|
506
|
-
return !1;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
static mkdir(e, t) {
|
|
510
|
-
e.mkdirTree(t);
|
|
511
|
-
}
|
|
512
|
-
static copyRecursive(e, t, o) {
|
|
513
|
-
const n = e.lookupPath(t).node;
|
|
514
|
-
if (e.isDir(n.mode)) {
|
|
515
|
-
e.mkdirTree(o);
|
|
516
|
-
const i = e.readdir(t).filter(
|
|
517
|
-
(s) => s !== "." && s !== ".."
|
|
518
|
-
);
|
|
519
|
-
for (const s of i)
|
|
520
|
-
c.copyRecursive(
|
|
521
|
-
e,
|
|
522
|
-
g(t, s),
|
|
523
|
-
g(o, s)
|
|
524
|
-
);
|
|
525
|
-
} else
|
|
526
|
-
e.writeFile(o, e.readFile(t));
|
|
527
|
-
}
|
|
528
|
-
};
|
|
529
|
-
d([
|
|
530
|
-
u('Could not read "{path}"')
|
|
531
|
-
], f, "readFileAsText", 1);
|
|
532
|
-
d([
|
|
533
|
-
u('Could not read "{path}"')
|
|
534
|
-
], f, "readFileAsBuffer", 1);
|
|
535
|
-
d([
|
|
536
|
-
u('Could not write to "{path}"')
|
|
537
|
-
], f, "writeFile", 1);
|
|
538
|
-
d([
|
|
539
|
-
u('Could not unlink "{path}"')
|
|
540
|
-
], f, "unlink", 1);
|
|
541
|
-
d([
|
|
542
|
-
u('Could not remove directory "{path}"')
|
|
543
|
-
], f, "rmdir", 1);
|
|
544
|
-
d([
|
|
545
|
-
u('Could not list files in "{path}"')
|
|
546
|
-
], f, "listFiles", 1);
|
|
547
|
-
d([
|
|
548
|
-
u('Could not stat "{path}"')
|
|
549
|
-
], f, "isDir", 1);
|
|
550
|
-
d([
|
|
551
|
-
u('Could not stat "{path}"')
|
|
552
|
-
], f, "fileExists", 1);
|
|
553
|
-
d([
|
|
554
|
-
u('Could not create directory "{path}"')
|
|
555
|
-
], f, "mkdir", 1);
|
|
556
|
-
d([
|
|
557
|
-
u('Could not copy files from "{path}"')
|
|
558
|
-
], f, "copyRecursive", 1);
|
|
559
|
-
(function() {
|
|
560
|
-
var r;
|
|
561
|
-
return typeof process < "u" && ((r = process.release) == null ? void 0 : r.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
|
|
562
|
-
})();
|
|
563
|
-
const p = Symbol("__private__dont__use");
|
|
564
|
-
ReadableStream.prototype[Symbol.asyncIterator] || (ReadableStream.prototype[Symbol.asyncIterator] = async function* () {
|
|
565
|
-
const r = this.getReader();
|
|
566
|
-
try {
|
|
567
|
-
for (; ; ) {
|
|
568
|
-
const { done: e, value: t } = await r.read();
|
|
569
|
-
if (e)
|
|
570
|
-
return;
|
|
571
|
-
yield t;
|
|
572
|
-
}
|
|
573
|
-
} finally {
|
|
574
|
-
r.releaseLock();
|
|
575
|
-
}
|
|
576
|
-
}, ReadableStream.prototype.iterate = // @ts-ignore
|
|
577
|
-
ReadableStream.prototype[Symbol.asyncIterator]);
|
|
578
|
-
function Y(r, e, t = () => {
|
|
1
|
+
import { __private__dont__use as l } from "@php-wasm/universal";
|
|
2
|
+
import { Semaphore as T, joinPaths as u, basename as y } from "@php-wasm/util";
|
|
3
|
+
import { logger as c } from "@php-wasm/logger";
|
|
4
|
+
function I(t, n, e = () => {
|
|
579
5
|
}) {
|
|
580
6
|
function o() {
|
|
581
|
-
|
|
582
|
-
const i =
|
|
583
|
-
if (
|
|
584
|
-
|
|
585
|
-
else if (
|
|
586
|
-
for (const
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
7
|
+
n = b(n);
|
|
8
|
+
const i = t[l].FS, s = R(i, (a) => {
|
|
9
|
+
if (a.path.startsWith(n))
|
|
10
|
+
e(a);
|
|
11
|
+
else if (a.operation === "RENAME" && a.toPath.startsWith(n))
|
|
12
|
+
for (const f of m(
|
|
13
|
+
t,
|
|
14
|
+
a.path,
|
|
15
|
+
a.toPath
|
|
590
16
|
))
|
|
591
|
-
|
|
592
|
-
}),
|
|
593
|
-
for (const [
|
|
594
|
-
a
|
|
595
|
-
function
|
|
596
|
-
for (const [
|
|
597
|
-
i[
|
|
598
|
-
return
|
|
17
|
+
e(f);
|
|
18
|
+
}), d = {};
|
|
19
|
+
for (const [a] of Object.entries(s))
|
|
20
|
+
d[a] = i[a];
|
|
21
|
+
function p() {
|
|
22
|
+
for (const [a, f] of Object.entries(s))
|
|
23
|
+
i[a] = function(...E) {
|
|
24
|
+
return f(...E), d[a].apply(this, E);
|
|
599
25
|
};
|
|
600
26
|
}
|
|
601
27
|
function h() {
|
|
602
|
-
for (const [
|
|
603
|
-
|
|
28
|
+
for (const [a, f] of Object.entries(d))
|
|
29
|
+
t[l].FS[a] = f;
|
|
604
30
|
}
|
|
605
|
-
|
|
606
|
-
bind:
|
|
31
|
+
t[l].journal = {
|
|
32
|
+
bind: p,
|
|
607
33
|
unbind: h
|
|
608
|
-
},
|
|
34
|
+
}, p();
|
|
609
35
|
}
|
|
610
|
-
|
|
611
|
-
function
|
|
612
|
-
|
|
36
|
+
t.addEventListener("runtime.initialized", o), t[l] && o();
|
|
37
|
+
function r() {
|
|
38
|
+
t[l].journal.unbind(), delete t[l].journal;
|
|
613
39
|
}
|
|
614
|
-
return
|
|
615
|
-
return
|
|
40
|
+
return t.addEventListener("runtime.beforedestroy", r), function() {
|
|
41
|
+
return t.removeEventListener("runtime.initialized", o), t.removeEventListener("runtime.beforedestroy", r), t[l].journal.unbind();
|
|
616
42
|
};
|
|
617
43
|
}
|
|
618
|
-
const
|
|
44
|
+
const R = (t, n = () => {
|
|
619
45
|
}) => ({
|
|
620
|
-
write(
|
|
621
|
-
|
|
46
|
+
write(e) {
|
|
47
|
+
n({
|
|
622
48
|
operation: "WRITE",
|
|
623
|
-
path:
|
|
49
|
+
path: e.path,
|
|
624
50
|
nodeType: "file"
|
|
625
51
|
});
|
|
626
52
|
},
|
|
627
|
-
truncate(
|
|
53
|
+
truncate(e) {
|
|
628
54
|
let o;
|
|
629
|
-
typeof
|
|
55
|
+
typeof e == "string" ? o = t.lookupPath(e, {
|
|
630
56
|
follow: !0
|
|
631
|
-
}).node : o =
|
|
57
|
+
}).node : o = e, n({
|
|
632
58
|
operation: "WRITE",
|
|
633
|
-
path:
|
|
59
|
+
path: t.getPath(o),
|
|
634
60
|
nodeType: "file"
|
|
635
61
|
});
|
|
636
62
|
},
|
|
637
|
-
unlink(
|
|
638
|
-
|
|
63
|
+
unlink(e) {
|
|
64
|
+
n({
|
|
639
65
|
operation: "DELETE",
|
|
640
|
-
path:
|
|
66
|
+
path: e,
|
|
641
67
|
nodeType: "file"
|
|
642
68
|
});
|
|
643
69
|
},
|
|
644
|
-
mknod(
|
|
645
|
-
|
|
70
|
+
mknod(e, o) {
|
|
71
|
+
t.isFile(o) && n({
|
|
646
72
|
operation: "CREATE",
|
|
647
|
-
path:
|
|
73
|
+
path: e,
|
|
648
74
|
nodeType: "file"
|
|
649
75
|
});
|
|
650
76
|
},
|
|
651
|
-
mkdir(
|
|
652
|
-
|
|
77
|
+
mkdir(e) {
|
|
78
|
+
n({
|
|
653
79
|
operation: "CREATE",
|
|
654
|
-
path:
|
|
80
|
+
path: e,
|
|
655
81
|
nodeType: "directory"
|
|
656
82
|
});
|
|
657
83
|
},
|
|
658
|
-
rmdir(
|
|
659
|
-
|
|
84
|
+
rmdir(e) {
|
|
85
|
+
n({
|
|
660
86
|
operation: "DELETE",
|
|
661
|
-
path:
|
|
87
|
+
path: e,
|
|
662
88
|
nodeType: "directory"
|
|
663
89
|
});
|
|
664
90
|
},
|
|
665
|
-
rename(
|
|
91
|
+
rename(e, o) {
|
|
666
92
|
try {
|
|
667
|
-
const
|
|
93
|
+
const r = t.lookupPath(e, {
|
|
668
94
|
follow: !0
|
|
669
|
-
}), i =
|
|
95
|
+
}), i = t.lookupPath(o, {
|
|
670
96
|
parent: !0
|
|
671
97
|
}).path;
|
|
672
|
-
|
|
98
|
+
n({
|
|
673
99
|
operation: "RENAME",
|
|
674
|
-
nodeType:
|
|
675
|
-
path:
|
|
676
|
-
toPath:
|
|
100
|
+
nodeType: t.isDir(r.node.mode) ? "directory" : "file",
|
|
101
|
+
path: r.path,
|
|
102
|
+
toPath: u(i, y(o))
|
|
677
103
|
});
|
|
678
104
|
} catch {
|
|
679
105
|
}
|
|
680
106
|
}
|
|
681
107
|
});
|
|
682
|
-
function
|
|
683
|
-
|
|
108
|
+
function L(t, n) {
|
|
109
|
+
t[l].journal.unbind();
|
|
684
110
|
try {
|
|
685
|
-
for (const
|
|
686
|
-
|
|
111
|
+
for (const e of n)
|
|
112
|
+
e.operation === "CREATE" ? e.nodeType === "file" ? t.writeFile(e.path, " ") : t.mkdir(e.path) : e.operation === "DELETE" ? e.nodeType === "file" ? t.unlink(e.path) : t.rmdir(e.path) : e.operation === "WRITE" ? t.writeFile(e.path, e.data) : e.operation === "RENAME" && t.mv(e.path, e.toPath);
|
|
687
113
|
} finally {
|
|
688
|
-
|
|
114
|
+
t[l].journal.bind();
|
|
689
115
|
}
|
|
690
116
|
}
|
|
691
|
-
function*
|
|
692
|
-
if (
|
|
117
|
+
function* m(t, n, e) {
|
|
118
|
+
if (t.isDir(n)) {
|
|
693
119
|
yield {
|
|
694
120
|
operation: "CREATE",
|
|
695
|
-
path:
|
|
121
|
+
path: e,
|
|
696
122
|
nodeType: "directory"
|
|
697
123
|
};
|
|
698
|
-
for (const o of
|
|
699
|
-
yield*
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
124
|
+
for (const o of t.listFiles(n))
|
|
125
|
+
yield* m(
|
|
126
|
+
t,
|
|
127
|
+
u(n, o),
|
|
128
|
+
u(e, o)
|
|
703
129
|
);
|
|
704
130
|
} else
|
|
705
131
|
yield {
|
|
706
132
|
operation: "CREATE",
|
|
707
|
-
path:
|
|
133
|
+
path: e,
|
|
708
134
|
nodeType: "file"
|
|
709
135
|
}, yield {
|
|
710
136
|
operation: "WRITE",
|
|
711
137
|
nodeType: "file",
|
|
712
|
-
path:
|
|
138
|
+
path: e
|
|
713
139
|
};
|
|
714
140
|
}
|
|
715
|
-
function
|
|
716
|
-
return
|
|
141
|
+
function b(t) {
|
|
142
|
+
return t.replace(/\/$/, "").replace(/\/\/+/g, "/");
|
|
717
143
|
}
|
|
718
|
-
function
|
|
719
|
-
const
|
|
720
|
-
for (let
|
|
721
|
-
for (let o =
|
|
722
|
-
const
|
|
723
|
-
if (
|
|
144
|
+
function k(t) {
|
|
145
|
+
const n = {};
|
|
146
|
+
for (let e = t.length - 1; e >= 0; e--) {
|
|
147
|
+
for (let o = e - 1; o >= 0; o--) {
|
|
148
|
+
const r = A(t[e], t[o]);
|
|
149
|
+
if (r === "none")
|
|
724
150
|
continue;
|
|
725
|
-
const i =
|
|
151
|
+
const i = t[e], s = t[o];
|
|
726
152
|
if (i.operation === "RENAME" && s.operation === "RENAME") {
|
|
727
|
-
|
|
153
|
+
c.warn(
|
|
728
154
|
"[FS Journal] Normalizing a double rename is not yet supported:",
|
|
729
155
|
{
|
|
730
156
|
current: i,
|
|
@@ -733,55 +159,55 @@ function U(r) {
|
|
|
733
159
|
);
|
|
734
160
|
continue;
|
|
735
161
|
}
|
|
736
|
-
(s.operation === "CREATE" || s.operation === "WRITE") && (i.operation === "RENAME" ?
|
|
162
|
+
(s.operation === "CREATE" || s.operation === "WRITE") && (i.operation === "RENAME" ? r === "same_node" ? (n[o] = [], n[e] = [
|
|
737
163
|
{
|
|
738
164
|
...s,
|
|
739
165
|
path: i.toPath
|
|
740
166
|
},
|
|
741
|
-
...e
|
|
742
|
-
]) :
|
|
167
|
+
...n[e] || []
|
|
168
|
+
]) : r === "descendant" && (n[o] = [], n[e] = [
|
|
743
169
|
{
|
|
744
170
|
...s,
|
|
745
|
-
path:
|
|
171
|
+
path: u(
|
|
746
172
|
i.toPath,
|
|
747
173
|
s.path.substring(i.path.length)
|
|
748
174
|
)
|
|
749
175
|
},
|
|
750
|
-
...e
|
|
751
|
-
]) : i.operation === "WRITE" &&
|
|
176
|
+
...n[e] || []
|
|
177
|
+
]) : i.operation === "WRITE" && r === "same_node" ? n[o] = [] : i.operation === "DELETE" && r === "same_node" && (n[o] = [], n[e] = []));
|
|
752
178
|
}
|
|
753
|
-
if (Object.entries(
|
|
754
|
-
const o =
|
|
755
|
-
return
|
|
179
|
+
if (Object.entries(n).length > 0) {
|
|
180
|
+
const o = t.flatMap((r, i) => i in n ? n[i] : [r]);
|
|
181
|
+
return k(o);
|
|
756
182
|
}
|
|
757
183
|
}
|
|
758
|
-
return
|
|
184
|
+
return t;
|
|
759
185
|
}
|
|
760
|
-
function
|
|
761
|
-
const
|
|
762
|
-
return i ===
|
|
186
|
+
function A(t, n) {
|
|
187
|
+
const e = t.path, o = t.operation !== "WRITE" && t.nodeType === "directory", r = n.operation !== "WRITE" && n.nodeType === "directory", i = n.operation === "RENAME" ? n.toPath : n.path;
|
|
188
|
+
return i === e ? "same_node" : r && e.startsWith(i + "/") ? "ancestor" : o && i.startsWith(e + "/") ? "descendant" : "none";
|
|
763
189
|
}
|
|
764
|
-
async function
|
|
765
|
-
const o =
|
|
766
|
-
(
|
|
767
|
-
).map((
|
|
768
|
-
return await Promise.all(o),
|
|
190
|
+
async function O(t, n) {
|
|
191
|
+
const o = n.filter(
|
|
192
|
+
(r) => r.operation === "WRITE"
|
|
193
|
+
).map((r) => P(t, r));
|
|
194
|
+
return await Promise.all(o), n;
|
|
769
195
|
}
|
|
770
|
-
const
|
|
771
|
-
async function
|
|
772
|
-
const
|
|
196
|
+
const F = new T({ concurrency: 15 });
|
|
197
|
+
async function P(t, n) {
|
|
198
|
+
const e = await F.acquire();
|
|
773
199
|
try {
|
|
774
|
-
|
|
200
|
+
n.data = await t.readFileAsBuffer(n.path);
|
|
775
201
|
} catch (o) {
|
|
776
|
-
|
|
777
|
-
`Journal failed to hydrate a file on flush: the path ${
|
|
778
|
-
),
|
|
202
|
+
c.warn(
|
|
203
|
+
`Journal failed to hydrate a file on flush: the path ${n.path} no longer exists`
|
|
204
|
+
), c.error(o);
|
|
779
205
|
}
|
|
780
|
-
|
|
206
|
+
e();
|
|
781
207
|
}
|
|
782
208
|
export {
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
209
|
+
O as hydrateUpdateFileOps,
|
|
210
|
+
I as journalFSEvents,
|
|
211
|
+
k as normalizeFilesystemOperations,
|
|
212
|
+
L as replayFSJournal
|
|
787
213
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/fs-journal",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.15",
|
|
4
4
|
"description": "Bindings to journal the PHP filesystem",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"main": "./index.cjs",
|
|
37
37
|
"module": "./index.js",
|
|
38
38
|
"license": "GPL-2.0-or-later",
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "62c0b6769e8922ec6ec1fdb985a69c4e86d070a2",
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">=18.18.0",
|
|
42
42
|
"npm": ">=8.11.0"
|