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