You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

@php-wasm/universal

Package Overview
Dependencies
Maintainers
3
Versions
131
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@php-wasm/universal - npm Package Compare versions

Comparing version

to
0.2.0

lib/is-exit-code-zero.d.ts

358

index.js

@@ -23,3 +23,6 @@ const v = Symbol("error"), _ = Symbol("message");

const A = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : b;
class O extends EventTarget {
function I(s) {
return s instanceof Error ? "exitCode" in s && s?.exitCode === 0 || s?.name === "ExitStatus" && "status" in s && s.status === 0 : !1;
}
class N extends EventTarget {
constructor() {

@@ -38,30 +41,30 @@ super(...arguments), this.listenersCount = 0;

}
function I(n) {
n.asm = {
...n.asm
function $(s) {
s.asm = {
...s.asm
};
const e = new O();
for (const t in n.asm)
if (typeof n.asm[t] == "function") {
const r = n.asm[t];
n.asm[t] = function(...s) {
const e = new N();
for (const t in s.asm)
if (typeof s.asm[t] == "function") {
const r = s.asm[t];
s.asm[t] = function(...n) {
try {
return r(...s);
return r(...n);
} catch (o) {
if (!(o instanceof Error))
throw o;
if ("exitCode" in o && o?.exitCode === 0)
return;
const i = $(
const i = M(
o,
n.lastAsyncifyStackSource?.stack
s.lastAsyncifyStackSource?.stack
);
if (n.lastAsyncifyStackSource && (o.cause = n.lastAsyncifyStackSource), !e.hasListeners())
throw D(i), o;
e.dispatchEvent(
new A("error", {
error: o,
message: i
})
);
if (s.lastAsyncifyStackSource && (o.cause = s.lastAsyncifyStackSource), e.hasListeners()) {
e.dispatchEvent(
new A("error", {
error: o,
message: i
})
);
return;
}
throw I(o) || q(i), o;
}

@@ -73,8 +76,8 @@ };

let w = [];
function N() {
function L() {
return w;
}
function $(n, e) {
if (n.message === "unreachable") {
let t = L;
function M(s, e) {
if (s.message === "unreachable") {
let t = B;
e || (t += `

@@ -85,4 +88,4 @@

`), w = B(
e || n.stack || ""
`), w = W(
e || s.stack || ""
);

@@ -94,5 +97,5 @@ for (const r of w)

}
return n.message;
return s.message;
}
const L = `
const B = `
"unreachable" WASM instruction executed.

@@ -121,18 +124,18 @@

`, R = "\x1B[41m", M = "\x1B[1m", E = "\x1B[0m", S = "\x1B[K";
`, E = "\x1B[41m", D = "\x1B[1m", R = "\x1B[0m", S = "\x1B[K";
let x = !1;
function D(n) {
function q(s) {
if (!x) {
x = !0, console.log(`${R}
x = !0, console.log(`${E}
${S}
${M} WASM ERROR${E}${R}`);
for (const e of n.split(`
${D} WASM ERROR${R}${E}`);
for (const e of s.split(`
`))
console.log(`${S} ${e} `);
console.log(`${E}`);
console.log(`${R}`);
}
}
function B(n) {
function W(s) {
try {
const e = n.split(`
const e = s.split(`
`).slice(1).map((t) => {

@@ -153,4 +156,4 @@ const r = t.trim().substring(3).split(" ");

class g {
constructor(e, t, r, s = "", o = 0) {
this.httpStatusCode = e, this.headers = t, this.bytes = r, this.exitCode = o, this.errors = s;
constructor(e, t, r, n = "", o = 0) {
this.httpStatusCode = e, this.headers = t, this.bytes = r, this.exitCode = o, this.errors = n;
}

@@ -188,3 +191,3 @@ static fromRawData(e) {

}
const C = [
const H = [
"8.2",

@@ -199,4 +202,4 @@ "8.1",

"5.6"
], ee = C[0], te = C;
class q {
], re = H[0], se = H;
class j {
#e;

@@ -238,3 +241,3 @@ #t;

if (r.headers["set-cookie"] && this.#s(r.headers["set-cookie"]), this.#t.handleRedirects && r.headers.location && t < this.#t.maxRedirects) {
const s = new URL(
const n = new URL(
r.headers.location[0],

@@ -245,3 +248,3 @@ this.requestHandler.absoluteUrl

{
url: s.toString(),
url: n.toString(),
method: "GET",

@@ -276,4 +279,4 @@ headers: {}

continue;
const r = t.indexOf("="), s = t.substring(0, r), o = t.substring(r + 1).split(";")[0];
this.#e[s] = o;
const r = t.indexOf("="), n = t.substring(0, r), o = t.substring(r + 1).split(";")[0];
this.#e[n] = o;
} catch (r) {

@@ -290,3 +293,3 @@ console.error(r);

}
class W {
class z {
constructor({ concurrency: e }) {

@@ -319,13 +322,13 @@ this._running = 0, this.concurrency = e, this.queue = [];

}
const j = "http://example.com";
function T(n) {
return n.toString().substring(n.origin.length);
const G = "http://example.com";
function T(s) {
return s.toString().substring(s.origin.length);
}
function k(n, e) {
return !e || !n.startsWith(e) ? n : n.substring(e.length);
function k(s, e) {
return !e || !s.startsWith(e) ? s : s.substring(e.length);
}
function z(n, e) {
return !e || n.startsWith(e) ? n : e + n;
function V(s, e) {
return !e || s.startsWith(e) ? s : e + s;
}
class G {
class Y {
#e;

@@ -345,10 +348,10 @@ #t;

constructor(e, t = {}) {
this.#a = new W({ concurrency: 1 });
this.#a = new z({ concurrency: 1 });
const {
documentRoot: r = "/www/",
absoluteUrl: s = typeof location == "object" ? location?.href : "",
absoluteUrl: n = typeof location == "object" ? location?.href : "",
isStaticFilePath: o = () => !1
} = t;
this.php = e, this.#e = r, this.#l = o;
const i = new URL(s);
const i = new URL(n);
this.#s = i.hostname, this.#r = i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80, this.#t = (i.protocol || "").replace(":", "");

@@ -389,8 +392,8 @@ const l = this.#r !== 443 && this.#r !== 80;

e.url,
t ? void 0 : j
), s = k(
t ? void 0 : G
), n = k(
r.pathname,
this.#n
);
return this.#l(s) ? this.#c(s) : await this.#h(e, r);
return this.#l(n) ? this.#c(n) : await this.#h(e, r);
}

@@ -419,3 +422,3 @@ /**

// was tampered with.
"content-type": [Y(t)],
"content-type": [K(t)],
"accept-ranges": ["bytes"],

@@ -441,13 +444,13 @@ "cache-control": ["public, max-age=0"]

);
let s = "GET";
let n = "GET";
const o = {
host: this.#o,
...H(e.headers || {})
...U(e.headers || {})
}, i = [];
if (e.files && Object.keys(e.files).length) {
s = "POST";
for (const u in e.files) {
const m = e.files[u];
n = "POST";
for (const c in e.files) {
const m = e.files[c];
i.push({
key: u,
key: c,
name: m.name,

@@ -458,3 +461,3 @@ type: m.type,

}
o["content-type"]?.startsWith("multipart/form-data") && (e.formData = V(
o["content-type"]?.startsWith("multipart/form-data") && (e.formData = J(
e.body || ""

@@ -464,8 +467,8 @@ ), o["content-type"] = "application/x-www-form-urlencoded", delete e.body);

let l;
e.formData !== void 0 ? (s = "POST", o["content-type"] = o["content-type"] || "application/x-www-form-urlencoded", l = new URLSearchParams(
e.formData !== void 0 ? (n = "POST", o["content-type"] = o["content-type"] || "application/x-www-form-urlencoded", l = new URLSearchParams(
e.formData
).toString()) : l = e.body;
let c;
let h;
try {
c = this.#u(t.pathname);
h = this.#u(t.pathname);
} catch {

@@ -479,3 +482,3 @@ return new g(

return await this.php.run({
relativeUri: z(
relativeUri: V(
T(t),

@@ -485,6 +488,6 @@ this.#n

protocol: this.#t,
method: e.method || s,
method: e.method || n,
body: l,
fileInfos: i,
scriptPath: c,
scriptPath: h,
headers: o

@@ -516,19 +519,19 @@ });

}
function V(n) {
const e = {}, t = n.match(/--(.*)\r\n/);
function J(s) {
const e = {}, t = s.match(/--(.*)\r\n/);
if (!t)
return e;
const r = t[1], s = n.split(`--${r}`);
return s.shift(), s.pop(), s.forEach((o) => {
const r = t[1], n = s.split(`--${r}`);
return n.shift(), n.pop(), n.forEach((o) => {
const i = o.indexOf(`\r
\r
`), l = o.substring(0, i).trim(), c = o.substring(i + 4).trim(), u = l.match(/name="([^"]+)"/);
if (u) {
const m = u[1];
e[m] = c;
`), l = o.substring(0, i).trim(), h = o.substring(i + 4).trim(), c = l.match(/name="([^"]+)"/);
if (c) {
const m = c[1];
e[m] = h;
}
}), e;
}
function Y(n) {
switch (n.split(".").pop()) {
function K(s) {
switch (s.split(".").pop()) {
case "css":

@@ -572,3 +575,3 @@ return "text/css";

}
const F = {
const C = {
0: "No error occurred. System call completed successfully.",

@@ -652,13 +655,13 @@ 1: "Argument list too long.",

};
function p(n = "") {
return function(t, r, s) {
const o = s.value;
s.value = function(...i) {
function p(s = "") {
return function(t, r, n) {
const o = n.value;
n.value = function(...i) {
try {
return o.apply(this, i);
} catch (l) {
const c = typeof l == "object" ? l?.errno : null;
if (c in F) {
const u = F[c], m = typeof i[0] == "string" ? i[0] : null, U = m !== null ? n.replaceAll("{path}", m) : n;
throw new Error(`${U}: ${u}`, {
const h = typeof l == "object" ? l?.errno : null;
if (h in C) {
const c = C[h], m = typeof i[0] == "string" ? i[0] : null, O = m !== null ? s.replaceAll("{path}", m) : s;
throw new Error(`${O}: ${c}`, {
cause: l

@@ -672,11 +675,6 @@ });

}
async function re(n, e = {}, t = []) {
let r, s;
const o = new Promise((c) => {
s = c;
}), i = new Promise((c) => {
r = c;
}), l = n.init(K, {
async function ne(s, e = {}, t = []) {
const [r, n, o] = F(), [i, l] = F(), h = s.init(Q, {
onAbort(c) {
console.error("WASM aborted: "), console.error(c);
o(c), l(), console.error(c);
},

@@ -691,25 +689,32 @@ ENV: {},

onRuntimeInitialized() {
e.onRuntimeInitialized && e.onRuntimeInitialized(), r();
e.onRuntimeInitialized && e.onRuntimeInitialized(), n();
},
monitorRunDependencies(c) {
c === 0 && (delete l.monitorRunDependencies, s());
c === 0 && (delete h.monitorRunDependencies, l());
}
});
for (const { default: c } of t)
c(l);
return t.length || s(), await o, await i, P.push(l), P.length - 1;
return await Promise.all(
t.map(
({ default: c }) => c(h)
)
), t.length || l(), await i, await r, P.push(h), P.length - 1;
}
const P = [];
function J(n) {
return P[n];
function Z(s) {
return P[s];
}
const K = function() {
const Q = function() {
return typeof process < "u" && process.release?.name === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
}();
var Q = Object.defineProperty, X = Object.getOwnPropertyDescriptor, f = (n, e, t, r) => {
for (var s = r > 1 ? void 0 : r ? X(e, t) : e, o = n.length - 1, i; o >= 0; o--)
(i = n[o]) && (s = (r ? i(e, t, s) : i(s)) || s);
return r && s && Q(e, t, s), s;
}(), F = () => {
const s = [], e = new Promise((t, r) => {
s.push(t, r);
});
return s.unshift(e), s;
};
const h = "string", y = "number", a = Symbol("__private__dont__use");
var X = Object.defineProperty, ee = Object.getOwnPropertyDescriptor, f = (s, e, t, r) => {
for (var n = r > 1 ? void 0 : r ? ee(e, t) : e, o = s.length - 1, i; o >= 0; o--)
(i = s[o]) && (n = (r ? i(e, t, n) : i(n)) || n);
return r && n && X(e, t, n), n;
};
const u = "string", y = "number", a = Symbol("__private__dont__use");
class d {

@@ -724,4 +729,4 @@ /**

constructor(e, t) {
this.#e = [], this.#t = !1, this.#s = null, this.#r = {}, this.#o = [], e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new q(
new G(this, t)
this.#e = [], this.#t = !1, this.#s = null, this.#r = {}, this.#o = [], e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new j(
new Y(this, t)
));

@@ -759,9 +764,9 @@ }

throw new Error("PHP runtime already initialized.");
const t = J(e);
const t = Z(e);
if (!t)
throw new Error("Invalid PHP runtime id.");
this[a] = t, t.onMessage = (r) => {
for (const s of this.#o)
s(r);
}, this.#s = I(t);
for (const n of this.#o)
n(r);
}, this.#s = $(t);
}

@@ -800,7 +805,7 @@ /** @inheritDoc */

host: "example.com:443",
...H(e.headers || {})
...U(e.headers || {})
};
if (this.#l(t, e.protocol || "http"), this.#h(r), e.body && this.#u(e.body), e.fileInfos)
for (const s of e.fileInfos)
this.#f(s);
for (const n of e.fileInfos)
this.#f(n);
return e.code && this.#m(" ?>" + e.code), this.#p(), await this.#y();

@@ -817,3 +822,3 @@ }

null,
[h],
[u],
[e]

@@ -831,6 +836,6 @@ );

const t = JSON.parse(this.readFileAsText(e)), r = {};
for (const s of t.headers) {
if (!s.includes(": "))
for (const n of t.headers) {
if (!n.includes(": "))
continue;
const o = s.indexOf(": "), i = s.substring(0, o).toLowerCase(), l = s.substring(o + 2);
const o = n.indexOf(": "), i = n.substring(0, o).toLowerCase(), l = n.substring(o + 2);
i in r || (r[i] = []), r[i].push(l);

@@ -847,3 +852,3 @@ }

null,
[h],
[u],
[e]

@@ -855,3 +860,3 @@ ), e.includes("?")) {

null,
[h],
[u],
[t]

@@ -865,3 +870,3 @@ );

null,
[h],
[u],
[e]

@@ -885,3 +890,3 @@ );

null,
[h],
[u],
[e]

@@ -894,3 +899,3 @@ );

null,
[h],
[u],
[e.cookie]

@@ -900,3 +905,3 @@ ), e["content-type"] && this[a].ccall(

null,
[h],
[u],
[e["content-type"]]

@@ -921,3 +926,3 @@ ), e["content-length"] && this[a].ccall(

null,
[h],
[u],
[e]

@@ -935,3 +940,3 @@ ), this[a].ccall(

null,
[h],
[u],
[e]

@@ -948,3 +953,3 @@ );

null,
[h, h],
[u, u],
[e, this.#r[e]]

@@ -963,3 +968,3 @@ );

#f(e) {
const { key: t, name: r, type: s, data: o } = e, i = `/tmp/${Math.random().toFixed(20)}`;
const { key: t, name: r, type: n, data: o } = e, i = `/tmp/${Math.random().toFixed(20)}`;
this.writeFile(i, o);

@@ -970,4 +975,4 @@ const l = 0;

null,
[h, h, h, h, y, y],
[t, r, s, i, l, o.byteLength]
[u, u, u, u, y, y],
[t, r, n, i, l, o.byteLength]
);

@@ -979,3 +984,3 @@ }

null,
[h],
[u],
[e]

@@ -988,5 +993,5 @@ );

e = await new Promise((o, i) => {
t = (c) => {
const u = new Error("Rethrown");
u.cause = c.error, u.betterMessage = c.message, i(u);
t = (h) => {
const c = new Error("Rethrown");
c.cause = h.error, c.betterMessage = h.message, i(c);
}, this.#s?.addEventListener(

@@ -1005,4 +1010,4 @@ "error",

} catch (o) {
for (const u in this)
typeof this[u] == "function" && (this[u] = () => {
for (const c in this)
typeof this[c] == "function" && (this[c] = () => {
throw new Error(

@@ -1012,11 +1017,11 @@ "PHP runtime has crashed – see the earlier error for details."

});
this.functionsMaybeMissingFromAsyncify = N();
const i = o, l = "betterMessage" in i ? i.betterMessage : i.message, c = new Error(l);
throw c.cause = i, c;
this.functionsMaybeMissingFromAsyncify = L();
const i = o, l = "betterMessage" in i ? i.betterMessage : i.message, h = new Error(l);
throw h.cause = i, h;
} finally {
this.#s?.removeEventListener("error", t), this.#r = {};
}
const { headers: r, httpStatusCode: s } = this.#i();
const { headers: r, httpStatusCode: n } = this.#i();
return new g(
s,
n,
r,

@@ -1051,4 +1056,4 @@ this.readFileAsBuffer("/tmp/stdout"),

t?.recursive && this.listFiles(e).forEach((r) => {
const s = `${e}/${r}`;
this.isDir(s) ? this.rmdir(s, t) : this.unlink(s);
const n = `${e}/${r}`;
this.isDir(n) ? this.rmdir(n, t) : this.unlink(n);
}), this[a].FS.rmdir(e);

@@ -1061,7 +1066,7 @@ }

const r = this[a].FS.readdir(e).filter(
(s) => s !== "." && s !== ".."
(n) => n !== "." && n !== ".."
);
if (t.prependPath) {
const s = e.replace(/\/$/, "");
return r.map((o) => `${s}/${o}`);
const n = e.replace(/\/$/, "");
return r.map((o) => `${n}/${o}`);
}

@@ -1119,29 +1124,30 @@ return r;

], d.prototype, "fileExists", 1);
function H(n) {
function U(s) {
const e = {};
for (const t in n)
e[t.toLowerCase()] = n[t];
for (const t in s)
e[t.toLowerCase()] = s[t];
return e;
}
function Z(n) {
return !(n instanceof d);
function te(s) {
return !(s instanceof d);
}
function se(n) {
return !Z(n);
function oe(s) {
return !te(s);
}
export {
d as BasePHP,
j as DEFAULT_BASE_URL,
ee as LatestSupportedPHPVersion,
q as PHPBrowser,
G as PHPRequestHandler,
G as DEFAULT_BASE_URL,
re as LatestSupportedPHPVersion,
j as PHPBrowser,
Y as PHPRequestHandler,
g as PHPResponse,
C as SupportedPHPVersions,
te as SupportedPHPVersionsList,
O as UnhandledRejectionsTarget,
H as SupportedPHPVersions,
se as SupportedPHPVersionsList,
N as UnhandledRejectionsTarget,
a as __private__dont__use,
z as ensurePathPrefix,
Z as isLocalPHP,
se as isRemotePHP,
re as loadPHPRuntime,
V as ensurePathPrefix,
I as isExitCodeZero,
te as isLocalPHP,
oe as isRemotePHP,
ne as loadPHPRuntime,
k as removePathPrefix,

@@ -1148,0 +1154,0 @@ p as rethrowFileSystemError,

@@ -19,1 +19,2 @@ export type { FileInfo, IsomorphicLocalPHP, IsomorphicRemotePHP, MessageListener, PHPOutput, PHPRunOptions, UniversalPHP, ListFilesOptions, RmDirOptions, HTTPMethod, PHPRequest, PHPRequestHeaders, RequestHandler, } from './universal-php';

export { DEFAULT_BASE_URL, ensurePathPrefix, removePathPrefix, toRelativeUrl, } from './urls';
export { isExitCodeZero } from './is-exit-code-zero';

@@ -76,3 +76,3 @@ import { Remote } from 'comlink';

* php.writeFile("/www/index.php", `<?php echo file_get_contents("php://input");`);
* const result = await php.run({
* const result = await php.request({
* method: "GET",

@@ -315,3 +315,3 @@ * headers: {

* Arguments:
* $data – any extra information as a string
* $data (string) – Data to pass to JavaScript.
*

@@ -318,0 +318,0 @@ * @example

{
"name": "@php-wasm/universal",
"version": "0.1.61",
"version": "0.2.0",
"description": "PHP.wasm – emscripten bindings for PHP",

@@ -39,3 +39,7 @@ "repository": {

"license": "GPL-2.0-or-later",
"gitHead": "f2cd7382004f7b003904b5db1d33d37fd2b1bfab"
"gitHead": "cd4062de74f7f18058d3f962e124d0fdff78b5a7",
"engines": {
"node": ">=16.15.1",
"npm": ">=8.11.0"
}
}

Sorry, the diff of this file is not supported yet