@aiquants/markdown-explorer 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +6 -3
- package/dist/{EditSurface-CaS1O6Nt.js → EditSurface-1Jf0CG-f.js} +1 -1
- package/dist/{EditSurface-5nbW7NTP.cjs → EditSurface-B-l3Do_C.cjs} +1 -1
- package/dist/{ExplorerSplit-C9Y02nvj.js → ExplorerSplit-D0zf7Cr_.js} +2 -2
- package/dist/{ExplorerSplit-D60N3_X7.cjs → ExplorerSplit-WX8afxrQ.cjs} +1 -1
- package/dist/{MultiLayout-CqTyFZ_i.cjs → MultiLayout-Bq10p3a3.cjs} +1 -1
- package/dist/{MultiLayout-DBpUTcCQ.js → MultiLayout-Jy9BKofx.js} +4 -4
- package/dist/{NativeScrollBar-CiVlg2ob.js → NativeScrollBar-CyiyL47o.js} +1 -1
- package/dist/{NativeScrollBar-QlOtnddZ.cjs → NativeScrollBar-Dt6xH5Mb.cjs} +1 -1
- package/dist/{TreeLayout-bk-Ziybl.js → TreeLayout-8pRo1ANN.js} +3 -3
- package/dist/{TreeLayout-uwvAgr-t.cjs → TreeLayout-kVWFEKJD.cjs} +1 -1
- package/dist/core/labels.d.cts +3 -0
- package/dist/core/labels.d.ts +3 -0
- package/dist/dataRoute-8pyILcjL.cjs +1 -0
- package/dist/dataRoute-Csl1WBDz.js +278 -0
- package/dist/{index-etFEpIE_.js → index-CfcJEnrC.js} +1126 -1027
- package/dist/index-sNJrKoGN.cjs +13 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +14 -14
- package/dist/{location-DmzVAFvo.cjs → location-CRYkEWiC.cjs} +1 -1
- package/dist/{location-Q4sgRrUm.js → location-Dc1qNEGm.js} +1 -1
- package/dist/{merge-BR4jKpIc.cjs → merge-D0aGvFKC.cjs} +1 -1
- package/dist/{merge-DfI0ro2L.js → merge-SRCxtHk2.js} +1 -1
- package/dist/sanitizeWorker.cjs +1 -1
- package/dist/sanitizeWorker.js +1 -1
- package/dist/server.cjs +1 -1
- package/dist/server.js +632 -621
- package/docs/behavior/dom-hooks.md +2 -1
- package/docs/behavior/layout.md +3 -2
- package/docs/behavior/localization.md +1 -0
- package/docs/behavior/security.md +2 -1
- package/docs/behavior/url-contract.md +1 -0
- package/package.json +1 -1
- package/dist/dataRoute-CcZ8PK00.cjs +0 -1
- package/dist/dataRoute-D1vE1wFW.js +0 -270
- package/dist/index-Dlkzr6Zn.cjs +0 -13
package/dist/server.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { b as Et, c as
|
|
2
|
-
import { D as
|
|
3
|
-
import { createHash as
|
|
4
|
-
import { createLinkCardHandler as
|
|
1
|
+
import { b as Et, c as er, f as Te, d as tr, g as rr, h as nr, j as or, E as bt, k as he, r as sr, l as ir, i as q, m as ar, n as cr, o as ur, p as Tt, q as dr, s as lr, t as Me, u as fr, v as mr, w as pr, x as ie, y as Q, e as He, z as wr, A as hr } from "./dataRoute-Csl1WBDz.js";
|
|
2
|
+
import { D as rs, M as ns, B as os } from "./dataRoute-Csl1WBDz.js";
|
|
3
|
+
import { createHash as yr, createHmac as gr } from "node:crypto";
|
|
4
|
+
import { createLinkCardHandler as Er } from "@aiquants/markdown/server";
|
|
5
5
|
import { crossOriginRefusal as kt, NO_CROSS_ORIGIN_NAVIGATION as St } from "@aiquants/request-isolation";
|
|
6
|
-
import { data as Fe, redirect as
|
|
7
|
-
import { w as
|
|
8
|
-
import { existsSync as
|
|
9
|
-
import { extname as
|
|
6
|
+
import { data as Fe, redirect as br } from "react-router";
|
|
7
|
+
import { w as Tr, d as kr, r as Sr, i as xr, a as Or, p as Rr, b as vr, f as _r, N as Nr } from "./location-Dc1qNEGm.js";
|
|
8
|
+
import { existsSync as Ar, statSync as Ir, realpathSync as Pr, constants as fe } from "node:fs";
|
|
9
|
+
import { extname as Mr, isAbsolute as Ue, relative as Xe, sep as Je, join as $r, resolve as Lr } from "node:path";
|
|
10
10
|
import { fileURLToPath as xe } from "node:url";
|
|
11
|
-
import { Worker as
|
|
12
|
-
import { open as xt, lstat as
|
|
13
|
-
import { Readable as
|
|
14
|
-
const Ge = Object.freeze({ kind: "anonymous" }),
|
|
11
|
+
import { Worker as jr } from "node:worker_threads";
|
|
12
|
+
import { open as xt, lstat as zr, realpath as Dr, readdir as Cr } from "node:fs/promises";
|
|
13
|
+
import { Readable as Br } from "node:stream";
|
|
14
|
+
const Ge = Object.freeze({ kind: "anonymous" }), Zo = Object.freeze({
|
|
15
15
|
authenticate: async () => ({ status: "signed-in", principal: Ge }),
|
|
16
16
|
principalKey: () => Ge.kind,
|
|
17
17
|
signedOutPage: (e, t) => new Response(null, { status: 401, headers: t })
|
|
18
|
-
}),
|
|
18
|
+
}), Hr = "application/octet-stream", Ot = "application/pdf", Fr = /* @__PURE__ */ new Set([
|
|
19
19
|
"image/png",
|
|
20
20
|
"image/apng",
|
|
21
21
|
"image/jpeg",
|
|
@@ -42,7 +42,7 @@ const Ge = Object.freeze({ kind: "anonymous" }), Wo = Object.freeze({
|
|
|
42
42
|
"video/ogg",
|
|
43
43
|
"video/quicktime",
|
|
44
44
|
Ot
|
|
45
|
-
]), Rt = "default-src 'none'; media-src 'self'; style-src 'unsafe-inline'",
|
|
45
|
+
]), Rt = "default-src 'none'; media-src 'self'; style-src 'unsafe-inline'", vt = `${Rt}; sandbox`, Ur = `${Rt}; sandbox allow-same-origin`, Ye = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/u, Xr = /^[\t\n\r ]+|[\t\n\r ]+$/gu, Ie = /^[\t ]+|[\t ]+$/gu, Jr = (e) => {
|
|
46
46
|
const t = [];
|
|
47
47
|
let r = "", n = 0;
|
|
48
48
|
for (; ; ) {
|
|
@@ -57,68 +57,77 @@ const Ge = Object.freeze({ kind: "anonymous" }), Wo = Object.freeze({
|
|
|
57
57
|
if (t.push(r.replace(Ie, "")), r = "", n >= e.length) return t;
|
|
58
58
|
n += 1;
|
|
59
59
|
}
|
|
60
|
-
},
|
|
61
|
-
const t = e.replace(
|
|
60
|
+
}, Gr = (e) => {
|
|
61
|
+
const t = e.replace(Xr, ""), r = t.indexOf("/");
|
|
62
62
|
if (r < 0) return null;
|
|
63
|
-
const n = t.slice(0, r), a = t.indexOf(";", r + 1),
|
|
64
|
-
return Ye.test(n) && Ye.test(
|
|
65
|
-
},
|
|
63
|
+
const n = t.slice(0, r), a = t.indexOf(";", r + 1), i = t.slice(r + 1, a < 0 ? t.length : a).replace(/[\t\n\r ]+$/u, "");
|
|
64
|
+
return Ye.test(n) && Ye.test(i) ? `${n}/${i}`.toLowerCase() : null;
|
|
65
|
+
}, Yr = (e) => {
|
|
66
66
|
let t = null;
|
|
67
|
-
for (const r of
|
|
68
|
-
const n =
|
|
67
|
+
for (const r of Jr(e)) {
|
|
68
|
+
const n = Gr(r);
|
|
69
69
|
n !== null && n !== "*/*" && (t = n);
|
|
70
70
|
}
|
|
71
71
|
return t;
|
|
72
|
-
},
|
|
72
|
+
}, Wr = /['()*]/gu, _t = (e) => encodeURIComponent(e).replace(Wr, (t) => `%${t.charCodeAt(0).toString(16).toUpperCase()}`), Kr = Object.freeze({
|
|
73
73
|
"Cache-Control": "private, max-age=60, stale-while-revalidate=600, no-transform",
|
|
74
74
|
Vary: "Cookie"
|
|
75
|
-
}),
|
|
76
|
-
const r =
|
|
75
|
+
}), Vr = (e, t) => {
|
|
76
|
+
const r = Yr(e), n = r !== null && Fr.has(r), a = n && (r.startsWith("audio/") || r.startsWith("video/"));
|
|
77
77
|
return {
|
|
78
|
-
contentType: r === null ?
|
|
78
|
+
contentType: r === null ? Hr : r,
|
|
79
79
|
inline: n,
|
|
80
80
|
headers: {
|
|
81
81
|
"X-Content-Type-Options": "nosniff",
|
|
82
|
-
"Content-Disposition": `${n ? "inline" : "attachment"}; filename*=UTF-8''${
|
|
83
|
-
...r === Ot ? {} : { "Content-Security-Policy": a ?
|
|
82
|
+
"Content-Disposition": `${n ? "inline" : "attachment"}; filename*=UTF-8''${_t(t)}`,
|
|
83
|
+
...r === Ot ? {} : { "Content-Security-Policy": a ? Ur : vt },
|
|
84
84
|
"Cross-Origin-Resource-Policy": "same-origin"
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
|
-
},
|
|
87
|
+
}, Zr = "text/plain; charset=utf-8", Qr = (e) => ({
|
|
88
|
+
contentType: Zr,
|
|
89
|
+
inline: !0,
|
|
90
|
+
headers: {
|
|
91
|
+
"X-Content-Type-Options": "nosniff",
|
|
92
|
+
"Content-Disposition": `inline; filename*=UTF-8''${_t(e)}`,
|
|
93
|
+
"Content-Security-Policy": vt,
|
|
94
|
+
"Cross-Origin-Resource-Policy": "same-origin"
|
|
95
|
+
}
|
|
96
|
+
}), qr = /^bytes=(?:(\d+)-(\d*)|-(\d+))$/iu, ye = Object.freeze({ kind: "whole" }), We = Object.freeze({ kind: "unsatisfiable" }), en = (e, t, r) => {
|
|
88
97
|
const n = e.get("Range");
|
|
89
|
-
if (n === null) return
|
|
98
|
+
if (n === null) return ye;
|
|
90
99
|
const a = e.get("If-Range");
|
|
91
|
-
if (a !== null && a !== r) return
|
|
92
|
-
const
|
|
93
|
-
if (
|
|
94
|
-
const [,
|
|
100
|
+
if (a !== null && a !== r) return ye;
|
|
101
|
+
const i = qr.exec(n);
|
|
102
|
+
if (i === null) return ye;
|
|
103
|
+
const [, c, m, h] = i;
|
|
95
104
|
if (h !== void 0) {
|
|
96
|
-
const
|
|
97
|
-
if (
|
|
98
|
-
const
|
|
99
|
-
return { kind: "partial", range: { offset:
|
|
105
|
+
const y = Number(h);
|
|
106
|
+
if (y === 0) return We;
|
|
107
|
+
const T = Math.max(0, t - y);
|
|
108
|
+
return { kind: "partial", range: { offset: T, length: t - T } };
|
|
100
109
|
}
|
|
101
|
-
const S = Number(
|
|
102
|
-
return w < S ?
|
|
103
|
-
}, Ke = "W/",
|
|
110
|
+
const S = Number(c), w = m === "" ? Number.POSITIVE_INFINITY : Number(m);
|
|
111
|
+
return w < S ? ye : S >= t ? We : { kind: "partial", range: { offset: S, length: Math.min(w, t - 1) - S + 1 } };
|
|
112
|
+
}, Ke = "W/", tn = (e) => {
|
|
104
113
|
const t = [];
|
|
105
114
|
let r = 0, n = !1;
|
|
106
115
|
for (let a = 0; a < e.length; a += 1)
|
|
107
116
|
e[a] === '"' ? n = !n : e[a] === "," && !n && (t.push(e.slice(r, a).replace(Ie, "")), r = a + 1);
|
|
108
117
|
return t.push(e.slice(r).replace(Ie, "")), t;
|
|
109
|
-
}, Ve = (e) => e.startsWith(Ke) ? e.slice(Ke.length) : e,
|
|
118
|
+
}, Ve = (e) => e.startsWith(Ke) ? e.slice(Ke.length) : e, rn = (e, t) => {
|
|
110
119
|
if (e === null) return !1;
|
|
111
|
-
const r =
|
|
120
|
+
const r = tn(e);
|
|
112
121
|
if (r.length === 1 && r[0] === "*") return !0;
|
|
113
122
|
const n = Ve(t);
|
|
114
123
|
return r.some((a) => Ve(a) === n);
|
|
115
|
-
},
|
|
124
|
+
}, nn = (e, t) => {
|
|
116
125
|
let r = t;
|
|
117
126
|
return e.pipeThrough(
|
|
118
127
|
new TransformStream({
|
|
119
128
|
transform: (n, a) => {
|
|
120
|
-
const
|
|
121
|
-
r -=
|
|
129
|
+
const i = n.byteLength > r ? n.subarray(0, r) : n;
|
|
130
|
+
r -= i.byteLength, a.enqueue(i), r === 0 && a.terminate();
|
|
122
131
|
},
|
|
123
132
|
flush: (n) => {
|
|
124
133
|
r > 0 && n.error(new RangeError("[markdown-explorer] the asset ended before its declared length"));
|
|
@@ -127,33 +136,33 @@ const Ge = Object.freeze({ kind: "anonymous" }), Wo = Object.freeze({
|
|
|
127
136
|
);
|
|
128
137
|
}, Oe = async (e, t, r, n, a) => {
|
|
129
138
|
if (n !== null && r.set("Content-Length", String(n)), e.method.toUpperCase() === "HEAD") return new Response(null, { status: t, headers: r });
|
|
130
|
-
const
|
|
131
|
-
return new Response(n === null ?
|
|
132
|
-
},
|
|
139
|
+
const i = await a();
|
|
140
|
+
return new Response(n === null ? i : nn(i, n), { status: t, headers: r });
|
|
141
|
+
}, on = (e, t) => {
|
|
133
142
|
const r = new Headers(e);
|
|
134
143
|
for (const [n, a] of Object.entries({ "Accept-Ranges": "bytes", "Content-Range": `bytes */${t}`, "Cache-Control": "private, no-store", "X-Content-Type-Options": "nosniff" })) r.set(n, a);
|
|
135
144
|
return new Response(null, { status: 416, headers: r });
|
|
136
|
-
},
|
|
137
|
-
const
|
|
138
|
-
for (const [
|
|
139
|
-
if (
|
|
140
|
-
if (
|
|
145
|
+
}, sn = async (e, t, r, n) => {
|
|
146
|
+
const a = `"${t.version}"`, i = n === "text" ? Qr(t.name) : Vr(t.contentType, t.name), c = new Headers(r);
|
|
147
|
+
for (const [S, w] of Object.entries({ ...i.headers, ...Kr, ETag: a })) c.set(S, w);
|
|
148
|
+
if (rn(e.headers.get("If-None-Match"), a)) return new Response(null, { status: 304, headers: c });
|
|
149
|
+
if (c.set("Content-Type", i.contentType), t.size === null) return Oe(e, 200, c, null, () => t.open(null));
|
|
141
150
|
if (t.size === 0)
|
|
142
|
-
return
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
if (
|
|
146
|
-
if (
|
|
147
|
-
const { range:
|
|
148
|
-
return
|
|
151
|
+
return c.set("Content-Length", "0"), new Response(null, { status: 200, headers: c });
|
|
152
|
+
c.set("Accept-Ranges", "bytes");
|
|
153
|
+
const m = en(e.headers, t.size, a);
|
|
154
|
+
if (m.kind === "unsatisfiable") return on(r, t.size);
|
|
155
|
+
if (m.kind === "whole") return Oe(e, 200, c, t.size, () => t.open(null));
|
|
156
|
+
const { range: h } = m;
|
|
157
|
+
return c.set("Content-Range", `bytes ${h.offset}-${h.offset + h.length - 1}/${t.size}`), Oe(e, 206, c, h.length, () => t.open(h));
|
|
149
158
|
}, Re = (e, t) => {
|
|
150
159
|
const r = new AbortController(), n = t(AbortSignal.any([e.signal, r.signal]));
|
|
151
160
|
return new Promise((a) => {
|
|
152
|
-
let
|
|
153
|
-
const
|
|
154
|
-
a(e.late),
|
|
161
|
+
let i;
|
|
162
|
+
const c = setTimeout(() => {
|
|
163
|
+
a(e.late), i = setTimeout(() => r.abort(), e.handOverMs);
|
|
155
164
|
}, e.timeoutMs), m = () => {
|
|
156
|
-
clearTimeout(
|
|
165
|
+
clearTimeout(c), clearTimeout(i);
|
|
157
166
|
};
|
|
158
167
|
n.then(
|
|
159
168
|
(h) => {
|
|
@@ -164,66 +173,66 @@ const Ge = Object.freeze({ kind: "anonymous" }), Wo = Object.freeze({
|
|
|
164
173
|
}
|
|
165
174
|
);
|
|
166
175
|
});
|
|
167
|
-
},
|
|
176
|
+
}, an = Object.freeze({
|
|
168
177
|
error: (e, t) => {
|
|
169
178
|
console.error(e, t);
|
|
170
179
|
}
|
|
171
|
-
}),
|
|
180
|
+
}), Nt = /* @__PURE__ */ Symbol.for("@aiquants/markdown-explorer:ExplorerError");
|
|
172
181
|
class ke extends Error {
|
|
173
182
|
reason;
|
|
174
183
|
code;
|
|
175
184
|
constructor(t, r = {}) {
|
|
176
185
|
if (!Et(t)) throw new RangeError(`[markdown-explorer] ExplorerError needs a failure reason; got ${JSON.stringify(t)}`);
|
|
177
|
-
if (r.code !== void 0 && !
|
|
178
|
-
super(`[markdown-explorer] ${t}`, r.cause === void 0 ? void 0 : { cause: r.cause }), this.name = "ExplorerError", this.reason = t, this.code = r.code, Object.defineProperty(this,
|
|
186
|
+
if (r.code !== void 0 && !er(r.code)) throw new RangeError(`[markdown-explorer] an ExplorerError code must be 1 to 64 lowercase letters, digits or hyphens; got ${JSON.stringify(r.code)}`);
|
|
187
|
+
super(`[markdown-explorer] ${t}`, r.cause === void 0 ? void 0 : { cause: r.cause }), this.name = "ExplorerError", this.reason = t, this.code = r.code, Object.defineProperty(this, Nt, { value: !0 });
|
|
179
188
|
}
|
|
180
189
|
}
|
|
181
|
-
const
|
|
190
|
+
const cn = (e) => e instanceof Error && Object.hasOwn(e, Nt) && Et(e.reason), un = (e) => typeof e == "object" && e !== null && e.name === "AbortError", $e = (e, t, r) => {
|
|
182
191
|
try {
|
|
183
192
|
e.error(t, r);
|
|
184
193
|
} catch (n) {
|
|
185
194
|
console.error("[markdown-explorer] the logger threw while reporting a failure", { operation: r.operation, error: n });
|
|
186
195
|
}
|
|
187
|
-
}, oe = (e, t) => $e(e, `[markdown-explorer] ${t.operation} failed`, t),
|
|
196
|
+
}, oe = (e, t) => $e(e, `[markdown-explorer] ${t.operation} failed`, t), dn = (e, t) => $e(e, `[markdown-explorer] ${t.operation} left out an entry`, t), ve = (e, t) => $e(e, `[markdown-explorer] ${t.operation} refused a path the deny rules match`, { ...t, error: new RangeError("[markdown-explorer] the path matches a deny rule") }), Ze = (e, t) => {
|
|
188
197
|
e === null || typeof e != "object" && typeof e != "function" || Promise.resolve(e).then(void 0, t);
|
|
189
|
-
}, G = (e, t, r, n) =>
|
|
198
|
+
}, G = (e, t, r, n) => cn(e) ? Te(e.reason, e.code) : (un(e) || r.aborted || oe(n, { ...t, error: e }), { reason: "failed" }), Qe = 2 * 1024 * 1024, qe = 256 * 1024 * 1024, ln = async (e, t) => {
|
|
190
199
|
const r = e.getReader(), n = new Uint8Array(t);
|
|
191
200
|
let a = 0;
|
|
192
201
|
for (; a < t; ) {
|
|
193
|
-
const { done:
|
|
194
|
-
if (
|
|
195
|
-
const m =
|
|
202
|
+
const { done: i, value: c } = await r.read();
|
|
203
|
+
if (i) return n.subarray(0, a);
|
|
204
|
+
const m = c.subarray(0, t - a);
|
|
196
205
|
n.set(m, a), a += m.byteLength;
|
|
197
206
|
}
|
|
198
207
|
return r.cancel().catch(() => {
|
|
199
208
|
}), n;
|
|
200
|
-
},
|
|
209
|
+
}, fn = async (e, t) => {
|
|
201
210
|
if (e.size === 0) return { text: "", truncated: !1 };
|
|
202
|
-
const r = e.size !== null && e.size > t, n = e.size === null ? t + 1 : Math.min(e.size, t), a = await
|
|
211
|
+
const r = e.size !== null && e.size > t, n = e.size === null ? t + 1 : Math.min(e.size, t), a = await ln(await e.open(r ? { offset: 0, length: t } : null), n);
|
|
203
212
|
if (e.size !== null && a.byteLength < n) throw new RangeError("[markdown-explorer] the file ended before the length its asset port reported");
|
|
204
|
-
const
|
|
205
|
-
return
|
|
213
|
+
const i = r || a.byteLength > t, c = i ? a.subarray(0, t) : a;
|
|
214
|
+
return c.includes(0) ? null : { text: new TextDecoder("utf-8").decode(c, { stream: i }), truncated: i };
|
|
206
215
|
}, et = (e, t) => {
|
|
207
216
|
if (!Number.isSafeInteger(t) || t <= 0) throw new RangeError(`[markdown-explorer] a cache ${e} must be a positive integer; got ${String(t)}`);
|
|
208
|
-
},
|
|
217
|
+
}, At = (e, t) => {
|
|
209
218
|
et("capacity", e), t !== void 0 && et("weight budget", t.max);
|
|
210
219
|
const r = /* @__PURE__ */ new Map();
|
|
211
220
|
let n = 0;
|
|
212
|
-
const a = (
|
|
213
|
-
const
|
|
214
|
-
|
|
221
|
+
const a = (i) => {
|
|
222
|
+
const c = r.get(i);
|
|
223
|
+
c !== void 0 && (r.delete(i), n -= c.weight);
|
|
215
224
|
};
|
|
216
225
|
return {
|
|
217
|
-
get: (
|
|
218
|
-
const
|
|
219
|
-
if (
|
|
220
|
-
return r.delete(
|
|
226
|
+
get: (i) => {
|
|
227
|
+
const c = r.get(i);
|
|
228
|
+
if (c !== void 0)
|
|
229
|
+
return r.delete(i), r.set(i, c), c.value;
|
|
221
230
|
},
|
|
222
|
-
set: (
|
|
223
|
-
a(
|
|
224
|
-
const m = t === void 0 ? 0 : t.of(
|
|
231
|
+
set: (i, c) => {
|
|
232
|
+
a(i);
|
|
233
|
+
const m = t === void 0 ? 0 : t.of(i, c);
|
|
225
234
|
if (!(t !== void 0 && m > t.max)) {
|
|
226
|
-
r.set(
|
|
235
|
+
r.set(i, { value: c, weight: m }), n += m;
|
|
227
236
|
for (const h of r.keys()) {
|
|
228
237
|
if (r.size <= e && (t === void 0 || n <= t.max)) break;
|
|
229
238
|
a(h);
|
|
@@ -234,366 +243,366 @@ const on = (e) => e instanceof Error && Object.hasOwn(e, vt) && Et(e.reason), sn
|
|
|
234
243
|
size: () => r.size,
|
|
235
244
|
weight: () => n
|
|
236
245
|
};
|
|
237
|
-
},
|
|
246
|
+
}, It = (e) => Math.max(1, e - 1), mn = 2147483647, tt = Object.freeze({ status: "aborted" }), ce = (e, t, r) => {
|
|
238
247
|
const n = (e.get(t) ?? 0) + r;
|
|
239
248
|
n === 0 ? e.delete(t) : e.set(t, n);
|
|
240
249
|
}, de = (e, t, r) => {
|
|
241
250
|
if (!Number.isSafeInteger(t) || t <= 0 || t > r) throw new RangeError(`[markdown-explorer] a worker pool's ${e} must be an integer in 1..${String(r)}; got ${String(t)}`);
|
|
242
|
-
},
|
|
243
|
-
de("size", t, Number.MAX_SAFE_INTEGER), de("deadline", r,
|
|
244
|
-
const
|
|
245
|
-
let
|
|
246
|
-
const v = (p,
|
|
251
|
+
}, pn = (e) => e !== null && typeof e == "object" && e.ready === !0 && !("id" in e), wn = (e, t) => e !== null && typeof e == "object" && e.id === t && "output" in e, hn = ({ url: e, size: t, deadlineMs: r, jobsPerScope: n, maxQueuedJobs: a, heapLimits: i }) => {
|
|
252
|
+
de("size", t, Number.MAX_SAFE_INTEGER), de("deadline", r, mn), de("jobsPerScope", n, Number.MAX_SAFE_INTEGER), de("maxQueuedJobs", a, Number.MAX_SAFE_INTEGER), de("maxOldGenerationSizeMb", i.maxOldGenerationSizeMb, Number.MAX_SAFE_INTEGER), de("maxYoungGenerationSizeMb", i.maxYoungGenerationSizeMb, Number.MAX_SAFE_INTEGER);
|
|
253
|
+
const c = Object.freeze({ maxOldGenerationSizeMb: i.maxOldGenerationSizeMb, maxYoungGenerationSizeMb: i.maxYoungGenerationSizeMb }), m = /* @__PURE__ */ new Set(), h = [], S = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Map(), y = It(t);
|
|
254
|
+
let T = 0;
|
|
255
|
+
const v = (p, g) => {
|
|
247
256
|
const { job: E } = p;
|
|
248
|
-
p.timer !== null && clearTimeout(p.timer), p.timer = null, p.job = null, p.sent = !1, E !== null && (ce(S, E.scope, -1), ce(w, E.scope, -1), E.settle(
|
|
257
|
+
p.timer !== null && clearTimeout(p.timer), p.timer = null, p.job = null, p.sent = !1, E !== null && (ce(S, E.scope, -1), ce(w, E.scope, -1), E.settle(g));
|
|
249
258
|
}, $ = (p) => {
|
|
250
|
-
const [
|
|
251
|
-
|
|
252
|
-
},
|
|
253
|
-
let p = -1,
|
|
254
|
-
for (const [R,
|
|
255
|
-
const
|
|
256
|
-
(
|
|
259
|
+
const [g] = h.splice(p, 1);
|
|
260
|
+
g?.detach();
|
|
261
|
+
}, N = () => {
|
|
262
|
+
let p = -1, g = y, E = Number.POSITIVE_INFINITY;
|
|
263
|
+
for (const [R, k] of h.entries()) {
|
|
264
|
+
const A = S.get(k.scope) ?? 0, M = w.get(k.scope) ?? 0;
|
|
265
|
+
(A < g || A === g && p >= 0 && M < E) && (p = R, g = A, E = M);
|
|
257
266
|
}
|
|
258
267
|
return p;
|
|
259
|
-
}, _ = (p,
|
|
260
|
-
m.has(p) && (m.delete(p), v(p,
|
|
261
|
-
}),
|
|
268
|
+
}, _ = (p, g) => {
|
|
269
|
+
m.has(p) && (m.delete(p), v(p, g), p.worker.terminate().catch(() => {
|
|
270
|
+
}), H());
|
|
262
271
|
}, z = (p) => {
|
|
263
272
|
p.timer = setTimeout(() => {
|
|
264
273
|
_(p, { status: "timeout" });
|
|
265
274
|
}, r);
|
|
266
|
-
}, O = (p,
|
|
275
|
+
}, O = (p, g) => p.sent ? { status: "crashed", error: g } : { status: "unavailable", error: g }, P = (p, g) => {
|
|
267
276
|
p.sent = !0, z(p);
|
|
268
277
|
try {
|
|
269
|
-
p.worker.postMessage({ id:
|
|
278
|
+
p.worker.postMessage({ id: g.id, input: g.input });
|
|
270
279
|
} catch (E) {
|
|
271
280
|
v(p, { status: "crashed", error: E }), p.worker.unref();
|
|
272
281
|
}
|
|
273
|
-
},
|
|
274
|
-
const p = { worker: new
|
|
282
|
+
}, B = () => {
|
|
283
|
+
const p = { worker: new jr(e, { resourceLimits: c }), job: null, sent: !1, timer: null, ready: !1 };
|
|
275
284
|
return p.worker.unref(), p.timer = setTimeout(() => {
|
|
276
285
|
_(p, { status: "unavailable", error: new Error(`[markdown-explorer] a worker did not start within ${String(r)} ms`) });
|
|
277
|
-
}, r), p.worker.on("message", (
|
|
278
|
-
if (!p.ready &&
|
|
279
|
-
p.ready = !0, p.timer !== null && clearTimeout(p.timer), p.timer = null, p.job === null ? p.worker.unref() : P(p, p.job), p.job === null &&
|
|
286
|
+
}, r), p.worker.on("message", (g) => {
|
|
287
|
+
if (!p.ready && pn(g)) {
|
|
288
|
+
p.ready = !0, p.timer !== null && clearTimeout(p.timer), p.timer = null, p.job === null ? p.worker.unref() : P(p, p.job), p.job === null && H();
|
|
280
289
|
return;
|
|
281
290
|
}
|
|
282
291
|
const { job: E } = p;
|
|
283
|
-
if (E === null || !
|
|
292
|
+
if (E === null || !wn(g, E.id)) {
|
|
284
293
|
_(p, O(p, new Error("[markdown-explorer] a worker sent a message that answers no job")));
|
|
285
294
|
return;
|
|
286
295
|
}
|
|
287
|
-
v(p, { status: "done", output:
|
|
288
|
-
}), p.worker.on("error", (
|
|
289
|
-
_(p, O(p,
|
|
290
|
-
}), p.worker.on("messageerror", (
|
|
291
|
-
_(p, O(p,
|
|
292
|
-
}), p.worker.on("exit", (
|
|
293
|
-
_(p, O(p, new Error(`[markdown-explorer] a worker exited with code ${String(
|
|
296
|
+
v(p, { status: "done", output: g.output }), p.worker.unref(), H();
|
|
297
|
+
}), p.worker.on("error", (g) => {
|
|
298
|
+
_(p, O(p, g));
|
|
299
|
+
}), p.worker.on("messageerror", (g) => {
|
|
300
|
+
_(p, O(p, g));
|
|
301
|
+
}), p.worker.on("exit", (g) => {
|
|
302
|
+
_(p, O(p, new Error(`[markdown-explorer] a worker exited with code ${String(g)}`)));
|
|
294
303
|
}), m.add(p), p;
|
|
295
|
-
},
|
|
304
|
+
}, H = () => {
|
|
296
305
|
for (; ; ) {
|
|
297
|
-
const p =
|
|
298
|
-
if (
|
|
306
|
+
const p = N(), g = h[p];
|
|
307
|
+
if (g === void 0) return;
|
|
299
308
|
let E;
|
|
300
|
-
for (const
|
|
301
|
-
if (
|
|
302
|
-
E =
|
|
309
|
+
for (const k of m)
|
|
310
|
+
if (k.job === null) {
|
|
311
|
+
E = k;
|
|
303
312
|
break;
|
|
304
313
|
}
|
|
305
314
|
if (E === void 0 && m.size < t)
|
|
306
315
|
try {
|
|
307
|
-
E =
|
|
308
|
-
} catch (
|
|
309
|
-
$(p), ce(w,
|
|
316
|
+
E = B();
|
|
317
|
+
} catch (k) {
|
|
318
|
+
$(p), ce(w, g.scope, -1), g.settle({ status: "unavailable", error: k });
|
|
310
319
|
continue;
|
|
311
320
|
}
|
|
312
321
|
if (E === void 0) return;
|
|
313
|
-
$(p), ce(S,
|
|
322
|
+
$(p), ce(S, g.scope, 1);
|
|
314
323
|
const R = E;
|
|
315
|
-
R.job =
|
|
324
|
+
R.job = g, R.worker.ref(), R.ready && P(R, g);
|
|
316
325
|
}
|
|
317
326
|
};
|
|
318
327
|
return {
|
|
319
|
-
run: (p, { scope:
|
|
328
|
+
run: (p, { scope: g, signal: E }) => new Promise((R) => {
|
|
320
329
|
if (E.aborted) {
|
|
321
330
|
R(tt);
|
|
322
331
|
return;
|
|
323
332
|
}
|
|
324
|
-
if ((w.get(
|
|
333
|
+
if ((w.get(g) ?? 0) >= n) {
|
|
325
334
|
R({ status: "refused", limit: "scope" });
|
|
326
335
|
return;
|
|
327
336
|
}
|
|
328
|
-
|
|
329
|
-
const
|
|
337
|
+
T += 1;
|
|
338
|
+
const k = { id: T, input: p, scope: g, settle: R, detach: () => {
|
|
330
339
|
} };
|
|
331
|
-
h.push(
|
|
332
|
-
const
|
|
333
|
-
if (
|
|
340
|
+
h.push(k), ce(w, g, 1), H();
|
|
341
|
+
const A = h.indexOf(k);
|
|
342
|
+
if (A < 0) return;
|
|
334
343
|
if (h.length > a) {
|
|
335
|
-
$(
|
|
344
|
+
$(A), ce(w, g, -1), R({ status: "refused", limit: "queue" });
|
|
336
345
|
return;
|
|
337
346
|
}
|
|
338
347
|
const M = () => {
|
|
339
|
-
const U = h.indexOf(
|
|
340
|
-
U < 0 || ($(U), ce(w,
|
|
348
|
+
const U = h.indexOf(k);
|
|
349
|
+
U < 0 || ($(U), ce(w, g, -1), R(tt));
|
|
341
350
|
};
|
|
342
|
-
E.addEventListener("abort", M, { once: !0 }),
|
|
351
|
+
E.addEventListener("abort", M, { once: !0 }), k.detach = () => {
|
|
343
352
|
E.removeEventListener("abort", M);
|
|
344
353
|
};
|
|
345
354
|
}),
|
|
346
355
|
workers: () => m.size
|
|
347
356
|
};
|
|
348
|
-
}, Le = 1024 * 1024,
|
|
357
|
+
}, Le = 1024 * 1024, yn = 3e4, gn = 4 * Le, En = 64 * Le, bn = 3, Tn = 2, kn = (e, t) => e + It(t) + bn, Sn = 4, xn = 32, On = 512, Rn = 64, vn = 4096, _n = 32, rt = 4096, Nn = 4, Pt = ({ workerHeapMb: e, maxHtmlBytes: t }) => Math.floor(((e - Rn) * Le - t * _n) / vn), An = ({ maxHtmlBytes: e }) => e, In = ({ maxHtmlBytes: e }) => Nn * e, Pn = 1024, Mn = 2147483647, $n = 64, Ln = 2 ** 29, jn = 1024 * 1024, zn = 64, nt = Object.freeze({ status: "rejected", reason: "too-large", cause: null }), _e = Object.freeze({ status: "rejected", reason: "failed", cause: null }), ue = (e, t, r, n) => {
|
|
349
358
|
if (t === void 0) return r;
|
|
350
359
|
if (typeof t != "number") throw new TypeError(`[markdown-explorer] sanitizer.${e} must be a number; got ${typeof t}`);
|
|
351
360
|
if (!Number.isSafeInteger(t) || t <= 0 || t > n) throw new RangeError(`[markdown-explorer] sanitizer.${e} must be an integer in 1..${String(n)}; got ${String(t)}`);
|
|
352
361
|
return t;
|
|
353
|
-
},
|
|
362
|
+
}, Dn = (e, t) => {
|
|
354
363
|
if (e !== void 0 && (e === null || typeof e != "object")) throw new TypeError("[markdown-explorer] sanitizer must be an object of { workers, deadlineMs, maxHtmlBytes, cacheBytes, workerHeapMb, jobsPerScope, maxQueuedJobs }");
|
|
355
|
-
const { workers: r, deadlineMs: n, maxHtmlBytes: a, cacheBytes:
|
|
364
|
+
const { workers: r, deadlineMs: n, maxHtmlBytes: a, cacheBytes: i, workerHeapMb: c, jobsPerScope: m, maxQueuedJobs: h } = e ?? {}, S = ue("workers", r, Tn, $n), w = ue("jobsPerScope", m, kn(t, S), Number.MAX_SAFE_INTEGER), y = Object.freeze({
|
|
356
365
|
workers: S,
|
|
357
|
-
deadlineMs: ue("deadlineMs", n,
|
|
358
|
-
maxHtmlBytes: ue("maxHtmlBytes", a,
|
|
359
|
-
cacheBytes: ue("cacheBytes",
|
|
360
|
-
workerHeapMb: ue("workerHeapMb",
|
|
366
|
+
deadlineMs: ue("deadlineMs", n, yn, Mn),
|
|
367
|
+
maxHtmlBytes: ue("maxHtmlBytes", a, gn, Ln),
|
|
368
|
+
cacheBytes: ue("cacheBytes", i, En, Number.MAX_SAFE_INTEGER),
|
|
369
|
+
workerHeapMb: ue("workerHeapMb", c, On, jn),
|
|
361
370
|
jobsPerScope: w,
|
|
362
|
-
maxQueuedJobs: ue("maxQueuedJobs", h,
|
|
371
|
+
maxQueuedJobs: ue("maxQueuedJobs", h, Sn * w, Number.MAX_SAFE_INTEGER)
|
|
363
372
|
});
|
|
364
|
-
if (
|
|
365
|
-
throw new RangeError(`[markdown-explorer] sanitizer.jobsPerScope must be at least multiView.maxPanels (${String(t)}), because a page sends the document of every panel to the sanitizer at once for one reader; got ${String(
|
|
366
|
-
if (
|
|
367
|
-
throw new RangeError(`[markdown-explorer] sanitizer.maxQueuedJobs must be at least multiView.maxPanels (${String(t)}), because a reader whose page finds every worker busy waits with the document of every panel; got ${String(
|
|
368
|
-
if (
|
|
373
|
+
if (y.jobsPerScope < t)
|
|
374
|
+
throw new RangeError(`[markdown-explorer] sanitizer.jobsPerScope must be at least multiView.maxPanels (${String(t)}), because a page sends the document of every panel to the sanitizer at once for one reader; got ${String(y.jobsPerScope)}`);
|
|
375
|
+
if (y.maxQueuedJobs < t)
|
|
376
|
+
throw new RangeError(`[markdown-explorer] sanitizer.maxQueuedJobs must be at least multiView.maxPanels (${String(t)}), because a reader whose page finds every worker busy waits with the document of every panel; got ${String(y.maxQueuedJobs)}`);
|
|
377
|
+
if (Pt(y) < rt)
|
|
369
378
|
throw new RangeError(
|
|
370
|
-
`[markdown-explorer] sanitizer.workerHeapMb (${String(
|
|
379
|
+
`[markdown-explorer] sanitizer.workerHeapMb (${String(y.workerHeapMb)} MiB) must leave room for ${String(rt)} parsed nodes beside HTML of sanitizer.maxHtmlBytes (${String(y.maxHtmlBytes)} bytes); raise workerHeapMb or lower maxHtmlBytes`
|
|
371
380
|
);
|
|
372
|
-
return
|
|
373
|
-
},
|
|
374
|
-
const e = import.meta.url, t = new URL(`./sanitizeWorker${
|
|
375
|
-
if (!
|
|
381
|
+
return y;
|
|
382
|
+
}, Cn = () => {
|
|
383
|
+
const e = import.meta.url, t = new URL(`./sanitizeWorker${Mr(xe(e))}`, e);
|
|
384
|
+
if (!Ar(xe(t))) throw new Error(`[markdown-explorer] the HTML sanitizer worker is missing: ${xe(t)}`);
|
|
376
385
|
return t;
|
|
377
|
-
}, ot = /* @__PURE__ */ new Map(),
|
|
386
|
+
}, ot = /* @__PURE__ */ new Map(), Bn = (e, t) => {
|
|
378
387
|
const r = [e.href, t.workers, t.deadlineMs, t.workerHeapMb, t.jobsPerScope, t.maxQueuedJobs].map(String).join("\0");
|
|
379
388
|
let n = ot.get(r);
|
|
380
|
-
return n === void 0 && (n =
|
|
389
|
+
return n === void 0 && (n = hn({
|
|
381
390
|
url: e,
|
|
382
391
|
size: t.workers,
|
|
383
392
|
deadlineMs: t.deadlineMs,
|
|
384
393
|
jobsPerScope: t.jobsPerScope,
|
|
385
394
|
maxQueuedJobs: t.maxQueuedJobs,
|
|
386
|
-
heapLimits: { maxOldGenerationSizeMb: t.workerHeapMb, maxYoungGenerationSizeMb:
|
|
395
|
+
heapLimits: { maxOldGenerationSizeMb: t.workerHeapMb, maxYoungGenerationSizeMb: xn }
|
|
387
396
|
}), ot.set(r, n)), n;
|
|
388
|
-
},
|
|
397
|
+
}, Hn = (e) => {
|
|
389
398
|
if (e === null || typeof e != "object") return !1;
|
|
390
399
|
const { status: t, html: r, message: n } = e;
|
|
391
400
|
return t === "sanitized" && typeof r == "string" || t === "too-large" || t === "error" && typeof n == "string";
|
|
392
|
-
},
|
|
393
|
-
const a = Object.freeze([...e]),
|
|
401
|
+
}, Fn = (e) => e instanceof Error && e.code === "ERR_WORKER_OUT_OF_MEMORY", Un = ({ iframeHosts: e, dataPath: t, options: r, pool: n }) => {
|
|
402
|
+
const a = Object.freeze([...e]), i = Pt(r), c = An(r), m = In(r), h = At(Pn, {
|
|
394
403
|
max: r.cacheBytes,
|
|
395
|
-
of: (
|
|
396
|
-
}), S = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Map(),
|
|
397
|
-
S.get(
|
|
398
|
-
const _ = w.get(
|
|
399
|
-
_?.delete(
|
|
400
|
-
},
|
|
401
|
-
const O = await n.run({ html:
|
|
404
|
+
of: (N, _) => 2 * N.length + (_.status === "sanitized" ? 2 * _.html.length : zn)
|
|
405
|
+
}), S = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Map(), y = (N) => {
|
|
406
|
+
S.get(N.key) === N && S.delete(N.key);
|
|
407
|
+
const _ = w.get(N.hash);
|
|
408
|
+
_?.delete(N), _?.size === 0 && w.delete(N.hash);
|
|
409
|
+
}, T = async (N, _, z) => {
|
|
410
|
+
const O = await n.run({ html: N, iframeHosts: a, dataPath: t, maxNodes: i, maxAttributeChars: c, maxSanitizedChars: m }, { scope: _, signal: z });
|
|
402
411
|
if (O.status === "refused") {
|
|
403
|
-
const
|
|
404
|
-
return { outcome: { status: "rejected", reason: "failed", cause: new Error(`[markdown-explorer] the HTML sanitizer refused a document: ${
|
|
412
|
+
const B = O.limit === "scope" ? `its reader already has ${String(r.jobsPerScope)} documents being sanitized or waiting` : `${String(r.maxQueuedJobs)} documents are already waiting`;
|
|
413
|
+
return { outcome: { status: "rejected", reason: "failed", cause: new Error(`[markdown-explorer] the HTML sanitizer refused a document: ${B}`) }, lasting: !1 };
|
|
405
414
|
}
|
|
406
415
|
if (O.status === "aborted") return { outcome: _e, lasting: !1 };
|
|
407
416
|
if (O.status === "timeout") return { outcome: { status: "rejected", reason: "too-large", cause: new Error(`[markdown-explorer] the HTML sanitizer did not finish within ${String(r.deadlineMs)} ms`) }, lasting: !0 };
|
|
408
417
|
if (O.status === "unavailable") return { outcome: { status: "rejected", reason: "failed", cause: new Error("[markdown-explorer] the HTML sanitizer worker could not start", { cause: O.error }) }, lasting: !1 };
|
|
409
|
-
if (O.status === "crashed" &&
|
|
418
|
+
if (O.status === "crashed" && Fn(O.error))
|
|
410
419
|
return { outcome: { status: "rejected", reason: "too-large", cause: new Error(`[markdown-explorer] the HTML sanitizer ran out of its ${String(r.workerHeapMb)} MiB worker heap`, { cause: O.error }) }, lasting: !0 };
|
|
411
420
|
if (O.status === "crashed") return { outcome: { status: "rejected", reason: "failed", cause: new Error("[markdown-explorer] the HTML sanitizer worker failed", { cause: O.error }) }, lasting: !0 };
|
|
412
421
|
const { output: P } = O;
|
|
413
|
-
return
|
|
414
|
-
}, v = (
|
|
422
|
+
return Hn(P) ? P.status === "too-large" ? { outcome: nt, lasting: !0 } : P.status === "error" ? { outcome: { status: "rejected", reason: "failed", cause: new Error(`[markdown-explorer] the HTML sanitizer failed: ${P.message}`) }, lasting: !0 } : P.html.length > m ? { outcome: { status: "rejected", reason: "too-large", cause: new Error(`[markdown-explorer] the HTML sanitizer's output of ${String(P.html.length)} characters exceeds its limit of ${String(m)}`) }, lasting: !0 } : { outcome: { status: "sanitized", html: P.html }, lasting: !0 } : { outcome: { status: "rejected", reason: "failed", cause: new Error("[markdown-explorer] the HTML sanitizer worker answered something that is not an outcome") }, lasting: !0 };
|
|
423
|
+
}, v = (N, _, z, O) => {
|
|
415
424
|
let P = () => {
|
|
416
425
|
};
|
|
417
|
-
const
|
|
418
|
-
P =
|
|
419
|
-
}),
|
|
420
|
-
S.set(z,
|
|
426
|
+
const B = new Promise((g) => {
|
|
427
|
+
P = g;
|
|
428
|
+
}), H = { hash: _, key: z, outcome: B, answer: P, controller: new AbortController(), waiters: 0 };
|
|
429
|
+
S.set(z, H);
|
|
421
430
|
const p = w.get(_);
|
|
422
|
-
return p === void 0 ? w.set(_, /* @__PURE__ */ new Set([
|
|
423
|
-
if (
|
|
424
|
-
const R = h.get(_),
|
|
425
|
-
R === void 0 && h.set(_,
|
|
426
|
-
for (const
|
|
427
|
-
|
|
428
|
-
}),
|
|
429
|
-
}, $ = (
|
|
430
|
-
|
|
431
|
+
return p === void 0 ? w.set(_, /* @__PURE__ */ new Set([H])) : p.add(H), T(N, O, H.controller.signal).catch((g) => ({ outcome: { status: "rejected", reason: "failed", cause: g instanceof Error ? g : new Error(String(g)) }, lasting: !0 })).then(({ outcome: g, lasting: E }) => {
|
|
432
|
+
if (y(H), H.answer(g), !E) return;
|
|
433
|
+
const R = h.get(_), k = R ?? (g.status === "rejected" ? { ...g, cause: null } : g);
|
|
434
|
+
R === void 0 && h.set(_, k);
|
|
435
|
+
for (const A of w.get(_) ?? [])
|
|
436
|
+
y(A), A.answer(k), A.controller.abort();
|
|
437
|
+
}), H;
|
|
438
|
+
}, $ = (N, _) => new Promise((z) => {
|
|
439
|
+
N.waiters += 1;
|
|
431
440
|
const O = () => {
|
|
432
|
-
|
|
441
|
+
N.waiters -= 1, z(_e), !(N.waiters > 0) && (y(N), N.controller.abort());
|
|
433
442
|
};
|
|
434
|
-
_.addEventListener("abort", O, { once: !0 }),
|
|
443
|
+
_.addEventListener("abort", O, { once: !0 }), N.outcome.then((P) => {
|
|
435
444
|
_.removeEventListener("abort", O), z(P);
|
|
436
445
|
});
|
|
437
446
|
});
|
|
438
|
-
return (
|
|
439
|
-
if (
|
|
440
|
-
const O =
|
|
447
|
+
return (N, { scope: _, signal: z }) => {
|
|
448
|
+
if (N.length > r.maxHtmlBytes || Buffer.byteLength(N, "utf8") > r.maxHtmlBytes) return Promise.resolve(nt);
|
|
449
|
+
const O = yr("sha256").update(N, "utf8").digest("base64"), P = h.get(O);
|
|
441
450
|
if (P !== void 0) return Promise.resolve(P);
|
|
442
451
|
if (z.aborted) return Promise.resolve(_e);
|
|
443
|
-
const
|
|
444
|
-
return $(
|
|
452
|
+
const B = `${O}\0${_}`, H = S.get(B);
|
|
453
|
+
return $(H === void 0 ? v(N, O, B, _) : H, z);
|
|
445
454
|
};
|
|
446
|
-
}, Se = (e) => ({ result: e, json: JSON.stringify(e) }),
|
|
447
|
-
const a =
|
|
448
|
-
const
|
|
449
|
-
const p = Se(
|
|
450
|
-
return !(v.superseded ||
|
|
455
|
+
}, Se = (e) => ({ result: e, json: JSON.stringify(e) }), Ne = Object.freeze(Se(Object.freeze({ status: "error", failure: Object.freeze({ reason: "failed" }) }))), Xn = (e) => e.status === "ok" && e.entries.length > 0, Jn = ({ ttlMs: e, maxEntries: t, maxBytes: r, now: n }) => {
|
|
456
|
+
const a = At(t, { max: r, of: (w, y) => 2 * y.tree.json.length }), i = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), m = (w, y) => {
|
|
457
|
+
const T = new AbortController(), v = { waiters: 0, superseded: !1, started: !1, loadTree: y }, $ = c.get(w), N = (B, H) => {
|
|
458
|
+
const p = Se(B);
|
|
459
|
+
return !(v.superseded || T.signal.aborted) && Xn(B) && a.set(w, { tree: p, loadedAt: H }), p;
|
|
451
460
|
}, z = (async () => {
|
|
452
|
-
if ($ !== void 0 && await $,
|
|
453
|
-
const
|
|
454
|
-
return v.started = !0,
|
|
461
|
+
if ($ !== void 0 && await $, T.signal.aborted) return Ne;
|
|
462
|
+
const B = n();
|
|
463
|
+
return v.started = !0, N(await v.loadTree(T.signal, B), B);
|
|
455
464
|
})().finally(() => {
|
|
456
|
-
|
|
457
|
-
}), O = { promise: z, controller:
|
|
458
|
-
|
|
465
|
+
i.get(w) === O && i.delete(w);
|
|
466
|
+
}), O = { promise: z, controller: T, state: v };
|
|
467
|
+
i.set(w, O);
|
|
459
468
|
const P = z.then(
|
|
460
469
|
() => {
|
|
461
470
|
},
|
|
462
471
|
() => {
|
|
463
472
|
}
|
|
464
473
|
);
|
|
465
|
-
return
|
|
466
|
-
|
|
474
|
+
return c.set(w, P), P.then(() => {
|
|
475
|
+
c.get(w) === P && c.delete(w);
|
|
467
476
|
}), O;
|
|
468
|
-
}, h = (w,
|
|
469
|
-
|
|
477
|
+
}, h = (w, y, T) => {
|
|
478
|
+
y.state.waiters += 1;
|
|
470
479
|
const v = () => {
|
|
471
|
-
|
|
480
|
+
y.state.waiters -= 1, !(y.state.waiters > 0) && (i.get(w) === y && i.delete(w), y.controller.abort());
|
|
472
481
|
};
|
|
473
|
-
return
|
|
474
|
-
|
|
482
|
+
return T.addEventListener("abort", v, { once: !0 }), y.promise.finally(() => {
|
|
483
|
+
T.removeEventListener("abort", v);
|
|
475
484
|
});
|
|
476
485
|
}, S = (w) => {
|
|
477
486
|
a.delete(w);
|
|
478
|
-
const
|
|
479
|
-
|
|
487
|
+
const y = i.get(w);
|
|
488
|
+
y?.state.started && (y.state.superseded = !0, i.delete(w));
|
|
480
489
|
};
|
|
481
490
|
return {
|
|
482
|
-
load: (w,
|
|
483
|
-
if (
|
|
491
|
+
load: (w, y, T) => {
|
|
492
|
+
if (y.aborted) return Promise.resolve(Ne);
|
|
484
493
|
const v = a.get(w);
|
|
485
494
|
if (v !== void 0) {
|
|
486
495
|
if (n() - v.loadedAt < e) return Promise.resolve(v.tree);
|
|
487
496
|
a.delete(w);
|
|
488
497
|
}
|
|
489
|
-
const $ =
|
|
490
|
-
return h(w, $ === void 0 ? m(w,
|
|
498
|
+
const $ = i.get(w);
|
|
499
|
+
return h(w, $ === void 0 ? m(w, T) : $, y);
|
|
491
500
|
},
|
|
492
|
-
refresh: (w,
|
|
493
|
-
if (
|
|
501
|
+
refresh: (w, y, T) => {
|
|
502
|
+
if (y.aborted) return Promise.resolve(Ne);
|
|
494
503
|
S(w);
|
|
495
|
-
const v =
|
|
496
|
-
return v === void 0 ? h(w, m(w,
|
|
504
|
+
const v = i.get(w);
|
|
505
|
+
return v === void 0 ? h(w, m(w, T), y) : (v.state.loadTree = T, h(w, v, y));
|
|
497
506
|
},
|
|
498
507
|
forget: S
|
|
499
508
|
};
|
|
500
|
-
},
|
|
509
|
+
}, Gn = (e) => ({
|
|
501
510
|
load: (t, r, n) => n(r, e()).then(Se),
|
|
502
511
|
refresh: (t, r, n) => n(r, e()).then(Se),
|
|
503
512
|
forget: () => {
|
|
504
513
|
}
|
|
505
514
|
}), x = (e) => {
|
|
506
515
|
throw new TypeError(`[markdown-explorer] ${e}`);
|
|
507
|
-
},
|
|
516
|
+
}, Yn = (e) => {
|
|
508
517
|
if (e === null || typeof e != "object") return null;
|
|
509
518
|
const { name: t, path: r } = e;
|
|
510
519
|
return typeof t != "string" || typeof r != "string" ? null : t === "" ? { path: r, reason: "an empty name" } : q(r) ? null : { path: r, reason: "a path the browser cannot address (empty, too long, a lone surrogate, a control character or a backslash)" };
|
|
511
|
-
},
|
|
520
|
+
}, Wn = (e, t, r, n) => {
|
|
512
521
|
if (e === null) return null;
|
|
513
522
|
if (!Array.isArray(e)) throw new TypeError(`[markdown-explorer] a source's ancestors must be null or an array of folder paths; got ${typeof e}`);
|
|
514
523
|
const a = /* @__PURE__ */ new Set();
|
|
515
|
-
for (const
|
|
516
|
-
if (typeof
|
|
517
|
-
if (r.deniesPath(
|
|
518
|
-
if (!n(
|
|
519
|
-
if (
|
|
520
|
-
if (a.has(
|
|
521
|
-
a.add(
|
|
524
|
+
for (const i of e) {
|
|
525
|
+
if (typeof i != "string" || !q(i)) throw new TypeError("[markdown-explorer] a source's ancestors held a path the explorer does not accept");
|
|
526
|
+
if (r.deniesPath(i)) throw new TypeError("[markdown-explorer] a source's ancestors held a denied path");
|
|
527
|
+
if (!n(i)) throw new TypeError("[markdown-explorer] a source's ancestors held a path outside the source's boundary");
|
|
528
|
+
if (i === t) throw new TypeError("[markdown-explorer] a source's ancestors held the document itself");
|
|
529
|
+
if (a.has(i)) throw new TypeError("[markdown-explorer] a source's ancestors held a path twice");
|
|
530
|
+
a.add(i);
|
|
522
531
|
}
|
|
523
532
|
return Object.freeze([...a]);
|
|
524
|
-
},
|
|
525
|
-
const
|
|
533
|
+
}, Kn = (e, t, r, n, a) => {
|
|
534
|
+
const i = /* @__PURE__ */ new Set(), c = (h) => {
|
|
526
535
|
if (!Array.isArray(h)) return x("a source returned entries that are not an array");
|
|
527
536
|
const S = [];
|
|
528
537
|
for (const w of h) {
|
|
529
|
-
const
|
|
530
|
-
|
|
538
|
+
const y = m(w);
|
|
539
|
+
y !== null && S.push(y);
|
|
531
540
|
}
|
|
532
541
|
return S;
|
|
533
542
|
}, m = (h) => {
|
|
534
|
-
const S =
|
|
543
|
+
const S = Yn(h);
|
|
535
544
|
if (S !== null)
|
|
536
545
|
return n(S), null;
|
|
537
|
-
const w =
|
|
546
|
+
const w = cr(h);
|
|
538
547
|
if (w !== null) return x(w);
|
|
539
|
-
const
|
|
540
|
-
if (
|
|
541
|
-
const { name:
|
|
542
|
-
if (t.deniesName(
|
|
548
|
+
const y = h;
|
|
549
|
+
if (i.has(y)) return x("a source returned entries that contain themselves");
|
|
550
|
+
const { name: T, path: v, type: $, mimeType: N, children: _, lazy: z } = y;
|
|
551
|
+
if (t.deniesName(T) || t.deniesPath(v)) return null;
|
|
543
552
|
if (!a(v))
|
|
544
553
|
return n({ path: v, reason: "a path outside the source's boundary" }), null;
|
|
545
|
-
const O =
|
|
554
|
+
const O = N === void 0 ? { name: T, path: v } : { name: T, path: v, mimeType: N };
|
|
546
555
|
if ($ === "file") return { ...O, type: $ };
|
|
547
556
|
if (z === !0)
|
|
548
557
|
return r ? { ...O, type: $, lazy: !0, children: [] } : x("a lazy directory came from a source without a children function");
|
|
549
558
|
if (_ === void 0) return { ...O, type: $ };
|
|
550
|
-
|
|
551
|
-
const P =
|
|
552
|
-
return
|
|
559
|
+
i.add(y);
|
|
560
|
+
const P = c(_);
|
|
561
|
+
return i.delete(y), { ...O, type: $, children: P };
|
|
553
562
|
};
|
|
554
|
-
return
|
|
555
|
-
},
|
|
563
|
+
return c(e);
|
|
564
|
+
}, Vn = /^[\x21\x23-\x7E]{1,256}$/u, Mt = (e) => typeof e == "string" && Vn.test(e), Zn = /* @__PURE__ */ new Set(["text", "image", "media", "file"]), Qn = (e) => typeof e == "string" && Zn.has(e), qn = (e, t, r) => {
|
|
556
565
|
if (e !== null && typeof e == "object") {
|
|
557
|
-
const
|
|
558
|
-
if (
|
|
559
|
-
if (Object.hasOwn(
|
|
560
|
-
if (typeof
|
|
561
|
-
if (!
|
|
562
|
-
const m = t(
|
|
563
|
-
switch (
|
|
566
|
+
const i = e, { kind: c } = i;
|
|
567
|
+
if (Qn(c)) {
|
|
568
|
+
if (Object.hasOwn(i, "url")) return x(`a ${c} document carries its version, not a url`);
|
|
569
|
+
if (typeof i.name != "string") return x("a document needs a name string");
|
|
570
|
+
if (!Mt(i.version)) return x(`a ${c} document needs a version of 1 to 256 visible ASCII characters other than '"'`);
|
|
571
|
+
const m = t(i.version);
|
|
572
|
+
switch (c) {
|
|
564
573
|
case "image":
|
|
565
574
|
case "file":
|
|
566
|
-
return { kind:
|
|
575
|
+
return { kind: c, name: i.name, url: m };
|
|
567
576
|
case "media": {
|
|
568
|
-
const { mediaType: h } =
|
|
569
|
-
return
|
|
577
|
+
const { mediaType: h } = i;
|
|
578
|
+
return nr(h) ? { kind: c, name: i.name, url: m, mediaType: h } : x(`unknown media type ${typeof h == "string" ? JSON.stringify(h.slice(0, 64)) : typeof h}`);
|
|
570
579
|
}
|
|
571
580
|
case "text":
|
|
572
|
-
return typeof
|
|
581
|
+
return typeof i.text != "string" || typeof i.truncated != "boolean" ? x("a text document needs text and truncated") : { kind: c, name: i.name, text: i.text, truncated: i.truncated, url: m };
|
|
573
582
|
}
|
|
574
583
|
}
|
|
575
584
|
}
|
|
576
|
-
const n =
|
|
585
|
+
const n = or(e);
|
|
577
586
|
if (n !== null) return x(n);
|
|
578
587
|
const a = e;
|
|
579
588
|
switch (a.kind) {
|
|
580
589
|
case "failure": {
|
|
581
|
-
const { reason:
|
|
582
|
-
return { kind: "failure", failure: Te(
|
|
590
|
+
const { reason: i, code: c } = a.failure;
|
|
591
|
+
return { kind: "failure", failure: Te(i, c) };
|
|
583
592
|
}
|
|
584
593
|
case "markdown":
|
|
585
|
-
return a.headings.length > bt ? { kind: "failure", failure: Te("too-large") } : a.edit?.kind === "inline" && !r ? x("a markdown document offers inline editing, but the server has no edit ports") : { kind: "unsanitized-markdown", name: a.name, html: a.htmlContent, headings: a.headings.map(({ text:
|
|
594
|
+
return a.headings.length > bt ? { kind: "failure", failure: Te("too-large") } : a.edit?.kind === "inline" && !r ? x("a markdown document offers inline editing, but the server has no edit ports") : { kind: "unsanitized-markdown", name: a.name, html: a.htmlContent, headings: a.headings.map(({ text: i, depth: c, id: m }) => ({ text: i, depth: c, id: m })), edit: eo(a.edit) };
|
|
586
595
|
}
|
|
587
|
-
},
|
|
596
|
+
}, eo = (e) => e === null ? null : e.kind === "inline" ? { kind: "inline" } : { kind: "external", href: e.href }, je = (e, t, r) => typeof e != "string" ? x(`${r} needs a text string`) : e.includes("\0") ? x(`${r} holds NUL, which no text editor can keep`) : new TextEncoder().encode(e).byteLength > t ? x(`${r} is over editMaxBytes (${t} bytes); refuse a longer source with ExplorerError "too-large"`) : e, $t = (e) => ar(e.href) ? { kind: "grant", href: e.href } : x("a grant needs a root-relative href"), to = (e, t) => {
|
|
588
597
|
if (e === null || typeof e != "object") return x("an edit source must be an object");
|
|
589
598
|
const r = e;
|
|
590
|
-
return r.kind === "grant" ?
|
|
591
|
-
},
|
|
599
|
+
return r.kind === "grant" ? $t(r) : r.kind !== "edit" ? x(`an edit source's kind must be "edit" or "grant"`) : he(r.version) ? typeof r.history != "boolean" ? x("an edit source needs history") : { kind: "edit", text: je(r.text, t, "an edit source"), version: r.version, history: r.history } : x("an edit source needs a version of 1 to 1024 characters");
|
|
600
|
+
}, ro = (e, t) => {
|
|
592
601
|
if (e === null || typeof e != "object") return x("a save result must be an object");
|
|
593
602
|
const r = e;
|
|
594
603
|
switch (r.kind) {
|
|
595
604
|
case "grant":
|
|
596
|
-
return
|
|
605
|
+
return $t(r);
|
|
597
606
|
case "saved":
|
|
598
607
|
return he(r.version) ? { kind: "saved", version: r.version } : x("a saved result needs a version of 1 to 1024 characters");
|
|
599
608
|
case "conflict":
|
|
@@ -601,97 +610,97 @@ const on = (e) => e instanceof Error && Object.hasOwn(e, vt) && Et(e.reason), sn
|
|
|
601
610
|
default:
|
|
602
611
|
return x(`a save result's kind must be "saved", "conflict" or "grant"`);
|
|
603
612
|
}
|
|
604
|
-
},
|
|
613
|
+
}, no = (e) => {
|
|
605
614
|
if (e === null || typeof e != "object") return x("a preview must be an object");
|
|
606
615
|
const { htmlContent: t, headings: r } = e;
|
|
607
616
|
if (typeof t != "string" || !Array.isArray(r)) return x("a preview needs htmlContent and headings");
|
|
608
617
|
if (r.length > bt) return { kind: "failure", failure: Te("too-large") };
|
|
609
618
|
for (const n of r) {
|
|
610
|
-
const a =
|
|
619
|
+
const a = ir(n);
|
|
611
620
|
if (a !== null) return x(a);
|
|
612
621
|
}
|
|
613
|
-
return { html: t, headings: r.map(({ text: n, depth: a, id:
|
|
614
|
-
},
|
|
622
|
+
return { html: t, headings: r.map(({ text: n, depth: a, id: i }) => ({ text: n, depth: a, id: i })) };
|
|
623
|
+
}, oo = (e) => {
|
|
615
624
|
if (!Array.isArray(e)) return x("revisions must be an array");
|
|
616
625
|
const t = /* @__PURE__ */ new Set();
|
|
617
626
|
return e.map((r) => {
|
|
618
|
-
const n =
|
|
627
|
+
const n = sr(r);
|
|
619
628
|
if (n !== null) return x(n);
|
|
620
|
-
const { id: a, modifiedAt:
|
|
621
|
-
return t.has(a) ? x(`two revisions share the id ${JSON.stringify(a.slice(0, 64))}`) : (t.add(a), { id: a, modifiedAt:
|
|
629
|
+
const { id: a, modifiedAt: i, size: c, author: m, kept: h, current: S } = r;
|
|
630
|
+
return t.has(a) ? x(`two revisions share the id ${JSON.stringify(a.slice(0, 64))}`) : (t.add(a), { id: a, modifiedAt: i, size: c, author: m, kept: h, current: S });
|
|
622
631
|
});
|
|
623
|
-
},
|
|
632
|
+
}, so = (e, t) => je(e, t, "a revision"), st = (e) => {
|
|
624
633
|
if (e === null || typeof e != "object") return x("an asset file must be an object");
|
|
625
|
-
const { name: t, contentType: r, size: n, version: a, open:
|
|
626
|
-
return typeof t != "string" || t === "" ? x("an asset file needs a non-empty name") : typeof r != "string" ? x("an asset file needs a contentType string ('' when unknown)") : n !== null && !(typeof n == "number" && Number.isSafeInteger(n) && n >= 0) ? x("an asset file's size must be null or a non-negative safe integer") :
|
|
627
|
-
},
|
|
634
|
+
const { name: t, contentType: r, size: n, version: a, open: i } = e;
|
|
635
|
+
return typeof t != "string" || t === "" ? x("an asset file needs a non-empty name") : typeof r != "string" ? x("an asset file needs a contentType string ('' when unknown)") : n !== null && !(typeof n == "number" && Number.isSafeInteger(n) && n >= 0) ? x("an asset file's size must be null or a non-negative safe integer") : Mt(a) ? typeof i != "function" ? x("an asset file needs an open function") : Object.freeze({ name: t, contentType: r, size: n, version: a, open: i }) : x(`an asset file needs a version of 1 to 256 visible ASCII characters other than '"'`);
|
|
636
|
+
}, io = (e) => Array.isArray(e) ? e.map((t) => {
|
|
628
637
|
if (t === null || typeof t != "object") return x("a notice must be an object");
|
|
629
|
-
const { id: r, tone: n, title: a, body:
|
|
638
|
+
const { id: r, tone: n, title: a, body: i, action: c } = t;
|
|
630
639
|
if (typeof r != "string" || r === "" || typeof a != "string") return x("a notice needs an id and a title");
|
|
631
|
-
if (!
|
|
632
|
-
if (
|
|
633
|
-
const h = { id: r, tone: n, title: a, ...
|
|
634
|
-
if (
|
|
635
|
-
if (
|
|
636
|
-
const { label: S, href: w } =
|
|
637
|
-
return typeof S != "string" || !
|
|
638
|
-
}) : x("notices must be an array"),
|
|
640
|
+
if (!tr(n)) return x(`unknown notice tone ${typeof n == "string" ? JSON.stringify(n.slice(0, 64)) : typeof n}`);
|
|
641
|
+
if (i !== void 0 && typeof i != "string") return x("a notice body must be a string");
|
|
642
|
+
const h = { id: r, tone: n, title: a, ...i === void 0 ? {} : { body: i } };
|
|
643
|
+
if (c === void 0) return h;
|
|
644
|
+
if (c === null || typeof c != "object") return x("a notice action must be an object");
|
|
645
|
+
const { label: S, href: w } = c;
|
|
646
|
+
return typeof S != "string" || !rr(w, ur) ? x("a notice action needs a label and an http(s), mailto or relative href") : { ...h, action: { label: S, href: w } };
|
|
647
|
+
}) : x("notices must be an array"), ao = 4e3, ge = Object.freeze({ ttlMs: 3e5, maxEntries: 64, maxBytes: 64 * 1024 * 1024 }), it = 32, Lt = "private, no-store", co = Object.freeze({
|
|
639
648
|
"Content-Type": "application/json; charset=utf-8",
|
|
640
|
-
"Cache-Control":
|
|
649
|
+
"Cache-Control": Lt,
|
|
641
650
|
"X-Content-Type-Options": "nosniff",
|
|
642
651
|
"Content-Security-Policy": "default-src 'none'; frame-ancestors 'none'; sandbox",
|
|
643
652
|
"Cross-Origin-Resource-Policy": "same-origin"
|
|
644
|
-
}),
|
|
653
|
+
}), uo = 22, lo = 2147483647, Ae = Object.freeze([]), fo = Object.freeze({ status: "ok", source: null, ancestors: null }), at = Object.freeze(["contains", "confirm"]), ct = Object.freeze({ readOnly: !1 }), mo = Object.freeze({ readOnly: !0 }), K = (e, t, r) => {
|
|
645
654
|
if (!(r && t === void 0) && typeof t != "function")
|
|
646
655
|
throw new TypeError(`[markdown-explorer] ${e} must be a function; got ${typeof t}`);
|
|
647
656
|
}, le = (e, t, r) => {
|
|
648
657
|
if (typeof t != "number") throw new TypeError(`[markdown-explorer] ${e} must be a number; got ${typeof t}`);
|
|
649
658
|
if (!Number.isSafeInteger(t) || t <= 0 || t > r) throw new RangeError(`[markdown-explorer] ${e} must be an integer in 1..${String(r)}; got ${String(t)}`);
|
|
650
659
|
return t;
|
|
651
|
-
},
|
|
660
|
+
}, po = (e) => {
|
|
652
661
|
if (e === null || typeof e != "object" || !Object.isFrozen(e)) throw new TypeError("[markdown-explorer] config must be the value returned by defineExplorerConfig");
|
|
653
|
-
return
|
|
662
|
+
return Sr(e);
|
|
654
663
|
}, ut = (e) => {
|
|
655
664
|
try {
|
|
656
665
|
return new Headers(e);
|
|
657
666
|
} catch {
|
|
658
667
|
throw new TypeError("[markdown-explorer] authenticate returned headers that are not a valid headers init (their values are not logged)");
|
|
659
668
|
}
|
|
660
|
-
}, dt = (e) => e instanceof Response ? new TypeError(`[markdown-explorer] authenticate threw a Response (status ${String(e.status)}), which a data request does not follow`) : e,
|
|
669
|
+
}, dt = (e) => e instanceof Response ? new TypeError(`[markdown-explorer] authenticate threw a Response (status ${String(e.status)}), which a data request does not follow`) : e, wo = (e) => {
|
|
661
670
|
if (typeof e != "string") throw new TypeError(`[markdown-explorer] scopeSecret must be a string; got ${typeof e}`);
|
|
662
671
|
if (e.length < it) throw new RangeError(`[markdown-explorer] scopeSecret must have at least ${String(it)} characters; got ${String(e.length)}`);
|
|
663
672
|
return e;
|
|
664
|
-
},
|
|
665
|
-
if (!
|
|
673
|
+
}, ho = (e, t) => {
|
|
674
|
+
if (!_r(t)) throw new TypeError(`[markdown-explorer] ${e}.boundary must be a plain object { contains, confirm? }`);
|
|
666
675
|
for (const r of Object.keys(t))
|
|
667
676
|
if (!at.includes(r)) throw new RangeError(`[markdown-explorer] ${e}.boundary.${r} is not an option; expected ${at.join(", ")}`);
|
|
668
677
|
K(`${e}.boundary.contains`, t.contains, !1), K(`${e}.boundary.confirm`, t.confirm, !0);
|
|
669
|
-
},
|
|
678
|
+
}, yo = (e) => {
|
|
670
679
|
if (!Array.isArray(e)) throw new TypeError("[markdown-explorer] sources must be an array");
|
|
671
680
|
const t = e;
|
|
672
681
|
if (t.length === 0) throw new RangeError("[markdown-explorer] sources must hold at least one source");
|
|
673
682
|
const r = /* @__PURE__ */ new Set();
|
|
674
683
|
for (const [n, a] of t.entries()) {
|
|
675
684
|
if (a === null || typeof a != "object") throw new TypeError(`[markdown-explorer] sources[${String(n)}] must be an object`);
|
|
676
|
-
const { id:
|
|
677
|
-
if (!
|
|
678
|
-
throw new RangeError(`[markdown-explorer] sources[${String(n)}].id must use lowercase letters, digits and "-" and start with a letter or digit; got ${typeof
|
|
679
|
-
const
|
|
680
|
-
if (r.has(
|
|
681
|
-
if (r.add(
|
|
682
|
-
if (typeof
|
|
683
|
-
if (
|
|
685
|
+
const { id: i, label: c, boundary: m, tree: h, children: S, ancestors: w, cacheScope: y } = a;
|
|
686
|
+
if (!xr(i))
|
|
687
|
+
throw new RangeError(`[markdown-explorer] sources[${String(n)}].id must use lowercase letters, digits and "-" and start with a letter or digit; got ${typeof i == "string" ? JSON.stringify(i) : typeof i}`);
|
|
688
|
+
const T = `source ${JSON.stringify(i)}`;
|
|
689
|
+
if (r.has(i)) throw new RangeError(`[markdown-explorer] source ids must be unique; ${JSON.stringify(i)} repeats at sources[${String(n)}]`);
|
|
690
|
+
if (r.add(i), typeof c != "string" && typeof c != "function") throw new TypeError(`[markdown-explorer] ${T}.label must be a string or a function`);
|
|
691
|
+
if (typeof c == "string" && c.trim() === "") throw new RangeError(`[markdown-explorer] ${T}.label must not be blank`);
|
|
692
|
+
if (ho(T, m), K(`${T}.tree`, h, !1), K(`${T}.children`, S, !0), K(`${T}.ancestors`, w, !0), y !== void 0 && y !== "principal" && y !== "shared") throw new RangeError(`[markdown-explorer] ${T}.cacheScope must be "principal" or "shared"; got ${JSON.stringify(y)}`);
|
|
684
693
|
}
|
|
685
694
|
return t;
|
|
686
|
-
},
|
|
695
|
+
}, go = (e) => {
|
|
687
696
|
if (e === !1) return !1;
|
|
688
|
-
if (e === void 0) return
|
|
697
|
+
if (e === void 0) return ge;
|
|
689
698
|
if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] treeCache must be { ttlMs, maxEntries, maxBytes } or false");
|
|
690
699
|
const { ttlMs: t, maxEntries: r, maxBytes: n } = e;
|
|
691
700
|
return {
|
|
692
|
-
ttlMs: t === void 0 ?
|
|
693
|
-
maxEntries: r === void 0 ?
|
|
694
|
-
maxBytes: n === void 0 ?
|
|
701
|
+
ttlMs: t === void 0 ? ge.ttlMs : le("treeCache.ttlMs", t, Number.MAX_SAFE_INTEGER),
|
|
702
|
+
maxEntries: r === void 0 ? ge.maxEntries : le("treeCache.maxEntries", r, Number.MAX_SAFE_INTEGER),
|
|
703
|
+
maxBytes: n === void 0 ? ge.maxBytes : le("treeCache.maxBytes", n, Number.MAX_SAFE_INTEGER)
|
|
695
704
|
};
|
|
696
705
|
}, lt = (e) => {
|
|
697
706
|
if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] authenticate must resolve to { status, ... }");
|
|
@@ -703,374 +712,376 @@ const on = (e) => e instanceof Error && Object.hasOwn(e, vt) && Et(e.reason), sn
|
|
|
703
712
|
return t;
|
|
704
713
|
}, mt = (e, t) => {
|
|
705
714
|
if (typeof t != "string" || t === "") throw new TypeError("[markdown-explorer] principalKey must return a non-empty string");
|
|
706
|
-
return
|
|
707
|
-
},
|
|
715
|
+
return gr("sha256", e).update(t, "utf8").digest("base64url").slice(0, uo);
|
|
716
|
+
}, Eo = (e) => e.view === "multi" ? e.docs : e.doc === null ? [] : [e.doc], ae = (e, t) => {
|
|
708
717
|
const r = e.getAll(t), [n] = r;
|
|
709
718
|
return r.length === 1 && n !== void 0 && n !== "" ? n : null;
|
|
710
719
|
}, W = (e, t, r, n = {}) => {
|
|
711
720
|
const a = new Headers(r);
|
|
712
|
-
for (const [
|
|
721
|
+
for (const [i, c] of Object.entries({ ...co, ...n })) a.set(i, c);
|
|
713
722
|
return new Response(t, { status: e, headers: a });
|
|
714
|
-
}, j = (e, t, r) => W(
|
|
715
|
-
const r =
|
|
723
|
+
}, j = (e, t, r) => W(lr[e.reason], JSON.stringify({ failure: e }), t, r), bo = /* @__PURE__ */ new Set(["refresh", "save", "preview"]), To = /* @__PURE__ */ new Set(["edit", "save", "preview", "revisions", "revision"]), pt = (e, t) => {
|
|
724
|
+
const r = bo.has(t) ? ["POST"] : ["GET", "HEAD"];
|
|
716
725
|
return r.includes(e.method.toUpperCase()) ? null : W(405, JSON.stringify({ failure: { reason: "invalid" } }), void 0, { Allow: r.join(", ") });
|
|
717
|
-
}, wt = (e) => e.headers.get(Me) ===
|
|
718
|
-
const [r, ...n] = (e.headers.get("Content-Type") ?? "").split(";").map((
|
|
719
|
-
if (r !==
|
|
720
|
-
const
|
|
721
|
-
if (Number.isFinite(
|
|
726
|
+
}, wt = (e) => e.headers.get(Me) === fr && kt(e, St) === void 0, ko = (e) => e.headers.get(Me) === mr && kt(e, St) === void 0, So = async (e, t) => {
|
|
727
|
+
const [r, ...n] = (e.headers.get("Content-Type") ?? "").split(";").map((T) => T.trim().toLowerCase()), a = n.find((T) => T.startsWith("charset="));
|
|
728
|
+
if (r !== hr || a !== void 0 && a !== "charset=utf-8") return { status: "error", failure: { reason: "invalid" } };
|
|
729
|
+
const i = Number(e.headers.get("Content-Length") ?? "0");
|
|
730
|
+
if (Number.isFinite(i) && i > t) return { status: "error", failure: { reason: "too-large" } };
|
|
722
731
|
if (e.body === null) return { status: "ok", text: "" };
|
|
723
|
-
const
|
|
732
|
+
const c = e.body.getReader(), m = [];
|
|
724
733
|
let h = 0;
|
|
725
734
|
for (; ; ) {
|
|
726
|
-
const { done:
|
|
727
|
-
if (
|
|
735
|
+
const { done: T, value: v } = await c.read();
|
|
736
|
+
if (T) break;
|
|
728
737
|
if (h += v.byteLength, h > t)
|
|
729
|
-
return await
|
|
738
|
+
return await c.cancel(), { status: "error", failure: { reason: "too-large" } };
|
|
730
739
|
m.push(v);
|
|
731
740
|
}
|
|
732
741
|
const S = new Uint8Array(h);
|
|
733
742
|
let w = 0;
|
|
734
|
-
for (const
|
|
735
|
-
S.set(
|
|
736
|
-
let
|
|
743
|
+
for (const T of m)
|
|
744
|
+
S.set(T, w), w += T.byteLength;
|
|
745
|
+
let y;
|
|
737
746
|
try {
|
|
738
|
-
|
|
747
|
+
y = new TextDecoder("utf-8", { fatal: !0 }).decode(S);
|
|
739
748
|
} catch {
|
|
740
749
|
return { status: "error", failure: { reason: "invalid" } };
|
|
741
750
|
}
|
|
742
|
-
return
|
|
743
|
-
},
|
|
751
|
+
return y.includes("\0") ? { status: "error", failure: { reason: "invalid" } } : { status: "ok", text: y };
|
|
752
|
+
}, xo = (e) => {
|
|
744
753
|
if (e === void 0) return;
|
|
745
754
|
if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] edit must be an object of the editor's ports");
|
|
746
755
|
const t = e;
|
|
747
756
|
for (const r of ["source", "save", "preview", "revisions", "revision"]) K(`edit.${r}`, t[r], !1);
|
|
748
757
|
return e;
|
|
749
|
-
},
|
|
758
|
+
}, Oo = ({ parentHeaders: e, loaderHeaders: t, errorHeaders: r }) => {
|
|
750
759
|
const n = new Headers(), a = r === void 0 ? [e, t] : [e, t, r];
|
|
751
|
-
for (const
|
|
752
|
-
for (const [
|
|
753
|
-
|
|
760
|
+
for (const i of a)
|
|
761
|
+
for (const [c, m] of i)
|
|
762
|
+
c !== "set-cookie" && n.set(c, m);
|
|
754
763
|
return n;
|
|
755
|
-
},
|
|
764
|
+
}, Qo = (e) => {
|
|
756
765
|
if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] the server configuration must be an object");
|
|
757
|
-
const t =
|
|
766
|
+
const t = po(e.config), r = wo(e.scopeSecret);
|
|
758
767
|
K("authenticate", e.authenticate, !1), K("principalKey", e.principalKey, !1), K("document", e.document, !1), K("asset", e.asset, !1), K("signedOutPage", e.signedOutPage, !1), K("forbiddenPage", e.forbiddenPage, !0), K("notices", e.notices, !0), K("onTreeRefreshed", e.onTreeRefreshed, !0);
|
|
759
|
-
const n =
|
|
768
|
+
const n = yo(e.sources), a = Tr(
|
|
760
769
|
t,
|
|
761
770
|
n.map((o) => o.id)
|
|
762
|
-
),
|
|
763
|
-
if (
|
|
771
|
+
), i = e.logger;
|
|
772
|
+
if (i !== void 0 && (i === null || typeof i != "object" || typeof i.error != "function"))
|
|
764
773
|
throw new TypeError("[markdown-explorer] logger must be an object with an error function");
|
|
765
|
-
const
|
|
774
|
+
const c = e.logger === void 0 ? an : e.logger, m = Tt(e.deny), h = e.deferredTimeoutMs === void 0 ? ao : le("deferredTimeoutMs", e.deferredTimeoutMs, lo), S = e.textMaxBytes === void 0 ? Qe : le("textMaxBytes", e.textMaxBytes, qe), w = xo(e.edit);
|
|
766
775
|
if (w === void 0 && e.editMaxBytes !== void 0) throw new TypeError("[markdown-explorer] editMaxBytes needs the edit ports");
|
|
767
|
-
const
|
|
776
|
+
const y = e.editMaxBytes === void 0 ? Qe : le("editMaxBytes", e.editMaxBytes, qe), T = go(e.treeCache), v = () => Date.now(), $ = T === !1 ? Gn(v) : Jn({ ...T, now: v }), N = Dn(e.sanitizer, t.multiView.maxPanels), _ = Un({ iframeHosts: t.iframeHosts, dataPath: t.dataPath, options: N, pool: Bn(Cn(), N) }), z = new Map(n.map((o) => [o.id, o])), O = kr(t), { authenticate: P, principalKey: B, signedOutPage: H, forbiddenPage: p, onTreeRefreshed: g } = e, E = (o, u) => {
|
|
768
777
|
if (typeof o.label == "string") return o.label;
|
|
769
|
-
const
|
|
770
|
-
if (typeof
|
|
771
|
-
return
|
|
772
|
-
}, R = (o,
|
|
773
|
-
const
|
|
778
|
+
const s = o.label(u);
|
|
779
|
+
if (typeof s != "string" || s.trim() === "") throw new TypeError(`[markdown-explorer] the label of source ${JSON.stringify(o.id)} must be a non-blank string`);
|
|
780
|
+
return s;
|
|
781
|
+
}, R = (o, u) => o.cacheScope === "shared" ? o.id : `${o.id}\0${u}`, k = (o, u) => {
|
|
782
|
+
const s = (l) => oe(c, { operation: "boundary", sourceId: o.id, path: u, error: l });
|
|
774
783
|
let d;
|
|
775
784
|
try {
|
|
776
|
-
d = o.boundary.contains(
|
|
785
|
+
d = o.boundary.contains(u);
|
|
777
786
|
} catch (l) {
|
|
778
|
-
return
|
|
787
|
+
return s(l), !1;
|
|
779
788
|
}
|
|
780
|
-
return typeof d == "boolean" ? d : (Ze(d,
|
|
781
|
-
},
|
|
789
|
+
return typeof d == "boolean" ? d : (Ze(d, s), s(new TypeError(`[markdown-explorer] boundary.contains of source ${JSON.stringify(o.id)} must return a boolean; got ${typeof d}`)), !1);
|
|
790
|
+
}, A = async (o, u, s) => {
|
|
782
791
|
const { confirm: d } = o.boundary;
|
|
783
|
-
if (d === void 0) return { status: "inside", readPath:
|
|
792
|
+
if (d === void 0) return { status: "inside", readPath: s };
|
|
784
793
|
let l;
|
|
785
794
|
try {
|
|
786
|
-
l = await d(
|
|
795
|
+
l = await d(u, s);
|
|
787
796
|
} catch (F) {
|
|
788
|
-
return { status: "error", failure: G(F, { operation: "boundary", sourceId: o.id, path:
|
|
797
|
+
return { status: "error", failure: G(F, { operation: "boundary", sourceId: o.id, path: s }, u.signal, c) };
|
|
789
798
|
}
|
|
790
|
-
const f = (F) => (oe(
|
|
799
|
+
const f = (F) => (oe(c, { operation: "boundary", sourceId: o.id, path: s, error: new TypeError(`[markdown-explorer] boundary.confirm of source ${JSON.stringify(o.id)} ${F}`) }), { status: "outside" });
|
|
791
800
|
if (l === null || typeof l != "object") return f(`must resolve to { inside, readPath? }; got ${l === null ? "null" : typeof l}`);
|
|
792
|
-
const { inside:
|
|
793
|
-
return
|
|
794
|
-
}, M = async (o,
|
|
795
|
-
const
|
|
796
|
-
if (
|
|
797
|
-
if (
|
|
801
|
+
const { inside: b, readPath: I } = l;
|
|
802
|
+
return b === !1 ? { status: "outside" } : b !== !0 || typeof I != "string" ? f("must resolve to { inside: false } or { inside: true, readPath: string }") : !q(I) || m.deniesPath(I) ? (oe(c, { operation: "boundary", sourceId: o.id, path: s, error: new RangeError(`[markdown-explorer] boundary.confirm of source ${JSON.stringify(o.id)} answered a readPath the explorer does not serve (unacceptable or denied)`) }), { status: "error", failure: { reason: "failed" } }) : { status: "inside", readPath: I };
|
|
803
|
+
}, M = async (o, u) => {
|
|
804
|
+
const s = n.filter((l) => k(l, u));
|
|
805
|
+
if (s.length === 0) return { status: "error", failure: { reason: "forbidden" } };
|
|
806
|
+
if (s.some((l) => l.boundary.confirm === void 0)) return { status: "inside", readPath: u };
|
|
798
807
|
let d = null;
|
|
799
|
-
for (const l of
|
|
800
|
-
const f = await
|
|
808
|
+
for (const l of s) {
|
|
809
|
+
const f = await A(l, o, u);
|
|
801
810
|
if (f.status === "inside") return f;
|
|
802
811
|
f.status === "error" && d === null && (d = f.failure);
|
|
803
812
|
}
|
|
804
813
|
return { status: "error", failure: d === null ? { reason: "forbidden" } : d };
|
|
805
|
-
}, U = (o,
|
|
806
|
-
const d = ({ path: l, reason: f }) =>
|
|
814
|
+
}, U = (o, u, s) => {
|
|
815
|
+
const d = ({ path: l, reason: f }) => dn(c, { operation: s.operation, sourceId: s.sourceId, path: l, error: new TypeError(`[markdown-explorer] an entry with ${f} was left out`) });
|
|
807
816
|
try {
|
|
808
|
-
return { status: "ok", entries:
|
|
817
|
+
return { status: "ok", entries: Kn(o, m, u.children !== void 0, d, (l) => k(u, l)) };
|
|
809
818
|
} catch (l) {
|
|
810
|
-
return oe(
|
|
819
|
+
return oe(c, { ...s, error: l }), { status: "error", failure: { reason: "failed" } };
|
|
811
820
|
}
|
|
812
|
-
}, L = async (o,
|
|
821
|
+
}, L = async (o, u, s) => {
|
|
813
822
|
let d;
|
|
814
823
|
try {
|
|
815
|
-
d = await o.tree(
|
|
824
|
+
d = await o.tree(u);
|
|
816
825
|
} catch (f) {
|
|
817
|
-
return { status: "error", failure: G(f, { operation: "tree", sourceId: o.id },
|
|
826
|
+
return { status: "error", failure: G(f, { operation: "tree", sourceId: o.id }, u.signal, c) };
|
|
818
827
|
}
|
|
819
828
|
const l = U(d, o, { operation: "tree", sourceId: o.id });
|
|
820
|
-
return l.status === "ok" ? { status: "ok", entries: l.entries, loadedAt:
|
|
821
|
-
},
|
|
822
|
-
if (
|
|
823
|
-
const
|
|
829
|
+
return l.status === "ok" ? { status: "ok", entries: l.entries, loadedAt: s } : l;
|
|
830
|
+
}, X = (o, u, s, d) => (l, f) => L(o, { principal: u, request: s, signal: l, refresh: d }, f), V = (o, u, s, d, l) => $.load(R(o, s), l, X(o, u, d, !1)), J = (o, u, s, d) => $.refresh(R(o, s), d.signal, X(o, u, d, !0)), se = (o, u) => {
|
|
831
|
+
if (g === void 0) return;
|
|
832
|
+
const s = (d) => oe(c, { operation: "refresh", sourceId: o.id, error: d });
|
|
824
833
|
try {
|
|
825
|
-
Ze(
|
|
834
|
+
Ze(g(u), s);
|
|
826
835
|
} catch (d) {
|
|
827
|
-
|
|
836
|
+
s(d);
|
|
828
837
|
}
|
|
829
|
-
}, D = async (o,
|
|
830
|
-
if (m.deniesPath(d) || !
|
|
831
|
-
const l = await
|
|
838
|
+
}, D = async (o, u, s, d) => {
|
|
839
|
+
if (m.deniesPath(d) || !k(o, d)) return { status: "error", failure: { reason: "forbidden" } };
|
|
840
|
+
const l = await A(o, s, d);
|
|
832
841
|
if (l.status === "outside") return { status: "error", failure: { reason: "forbidden" } };
|
|
833
842
|
if (l.status === "error") return { status: "error", failure: l.failure };
|
|
834
843
|
let f;
|
|
835
844
|
try {
|
|
836
|
-
f = await
|
|
837
|
-
} catch (
|
|
838
|
-
return { status: "error", failure: G(
|
|
845
|
+
f = await u(s, d, l.readPath);
|
|
846
|
+
} catch (b) {
|
|
847
|
+
return { status: "error", failure: G(b, { operation: "children", sourceId: o.id, path: d }, s.signal, c) };
|
|
839
848
|
}
|
|
840
849
|
return U(f, o, { operation: "children", sourceId: o.id, path: d });
|
|
841
|
-
}, Z = async (o,
|
|
842
|
-
const l = await
|
|
850
|
+
}, Z = async (o, u, s, d) => {
|
|
851
|
+
const l = await A(o, s, d);
|
|
843
852
|
if (l.status === "outside") return { status: "ok", ancestors: null };
|
|
844
853
|
if (l.status === "error") return { status: "error", failure: l.failure };
|
|
845
854
|
let f;
|
|
846
855
|
try {
|
|
847
|
-
f = await
|
|
848
|
-
} catch (
|
|
849
|
-
return { status: "error", failure: G(
|
|
856
|
+
f = await u(s, d, l.readPath, { maxDepth: t.revealDocument.maxDepth });
|
|
857
|
+
} catch (b) {
|
|
858
|
+
return { status: "error", failure: G(b, { operation: "ancestors", sourceId: o.id, path: d }, s.signal, c) };
|
|
850
859
|
}
|
|
851
860
|
if (Array.isArray(f) && f.length > t.revealDocument.maxDepth) return { status: "ok", ancestors: null };
|
|
852
861
|
try {
|
|
853
|
-
return { status: "ok", ancestors:
|
|
854
|
-
} catch (
|
|
855
|
-
return oe(
|
|
862
|
+
return { status: "ok", ancestors: Wn(f, d, m, (b) => k(o, b)) };
|
|
863
|
+
} catch (b) {
|
|
864
|
+
return oe(c, { operation: "ancestors", sourceId: o.id, path: d, error: b }), { status: "error", failure: { reason: "failed" } };
|
|
856
865
|
}
|
|
857
|
-
}, ee = async (o,
|
|
858
|
-
if (m.deniesPath(
|
|
866
|
+
}, ee = async (o, u, s, d) => m.deniesPath(d) ? { status: "error", failure: { reason: "forbidden" } } : k(o, d) ? Z(o, u, s, d) : { status: "ok", ancestors: null }, te = async (o, u, s) => {
|
|
867
|
+
if (m.deniesPath(s)) return { status: "error", failure: { reason: "forbidden" } };
|
|
859
868
|
for (const d of [o, ...n.filter((l) => l !== o)]) {
|
|
860
|
-
if (
|
|
869
|
+
if (u.signal.aborted) break;
|
|
861
870
|
const l = d.ancestors;
|
|
862
|
-
if (l === void 0 || !
|
|
863
|
-
const f = await Z(d, l,
|
|
871
|
+
if (l === void 0 || !k(d, s)) continue;
|
|
872
|
+
const f = await Z(d, l, u, s);
|
|
864
873
|
if (f.status === "ok" && f.ancestors !== null) return { status: "ok", source: d.id, ancestors: f.ancestors };
|
|
865
874
|
}
|
|
866
|
-
return
|
|
867
|
-
}, me = async (o,
|
|
868
|
-
if (m.deniesPath(
|
|
869
|
-
const d = await M(o,
|
|
875
|
+
return fo;
|
|
876
|
+
}, me = async (o, u, s) => {
|
|
877
|
+
if (m.deniesPath(s)) return Q("forbidden");
|
|
878
|
+
const d = await M(o, s);
|
|
870
879
|
if (d.status === "error") return { kind: "failure", failure: d.failure };
|
|
871
880
|
let l;
|
|
872
881
|
try {
|
|
873
|
-
l = await e.document(o,
|
|
882
|
+
l = await e.document(o, s, d.readPath);
|
|
874
883
|
} catch (I) {
|
|
875
|
-
return { kind: "failure", failure: G(I, { operation: "document", path:
|
|
884
|
+
return { kind: "failure", failure: G(I, { operation: "document", path: s }, o.signal, c) };
|
|
876
885
|
}
|
|
877
886
|
let f;
|
|
878
887
|
try {
|
|
879
|
-
f =
|
|
888
|
+
f = qn(l, (I) => He(t.dataPath, s, I), w !== void 0);
|
|
880
889
|
} catch (I) {
|
|
881
|
-
return oe(
|
|
890
|
+
return oe(c, { operation: "document", path: s, error: I }), Q("failed");
|
|
882
891
|
}
|
|
883
892
|
if (f.kind !== "unsanitized-markdown") return f;
|
|
884
|
-
const
|
|
885
|
-
return
|
|
886
|
-
},
|
|
887
|
-
if (e.notices === void 0) return
|
|
893
|
+
const b = await _(f.html, { scope: u, signal: o.signal });
|
|
894
|
+
return b.status === "sanitized" ? { kind: "markdown", name: f.name, htmlContent: b.html, headings: f.headings, edit: f.edit } : (b.cause !== null && oe(c, { operation: "document", path: s, error: b.cause }), Q(b.reason));
|
|
895
|
+
}, Ht = async (o) => {
|
|
896
|
+
if (e.notices === void 0) return Ae;
|
|
888
897
|
try {
|
|
889
|
-
return
|
|
890
|
-
} catch (
|
|
891
|
-
return G(
|
|
898
|
+
return io(await e.notices(o));
|
|
899
|
+
} catch (u) {
|
|
900
|
+
return G(u, { operation: "notices" }, o.signal, c), Ae;
|
|
892
901
|
}
|
|
893
|
-
},
|
|
894
|
-
const d = ae(
|
|
895
|
-
if (d === null || !q(d)) return j({ reason: "invalid" },
|
|
902
|
+
}, Ft = async (o, u, s) => {
|
|
903
|
+
const d = ae(u, ie.path);
|
|
904
|
+
if (d === null || !q(d)) return j({ reason: "invalid" }, s);
|
|
905
|
+
const l = wr(u);
|
|
906
|
+
if (l === null) return j({ reason: "invalid" }, s);
|
|
896
907
|
if (m.deniesPath(d))
|
|
897
|
-
return ve(
|
|
898
|
-
const
|
|
899
|
-
if (
|
|
908
|
+
return ve(c, { operation: "asset", path: d }), j({ reason: "forbidden" }, s);
|
|
909
|
+
const f = await M(o, d);
|
|
910
|
+
if (f.status === "error") return j(f.failure, s);
|
|
900
911
|
try {
|
|
901
|
-
const
|
|
902
|
-
return await
|
|
903
|
-
} catch (
|
|
904
|
-
return j(G(
|
|
912
|
+
const b = st(await e.asset(o, d, f.readPath));
|
|
913
|
+
return await sn(o.request, b, s, l);
|
|
914
|
+
} catch (b) {
|
|
915
|
+
return j(G(b, { operation: "asset", path: d }, o.signal, c), s);
|
|
905
916
|
}
|
|
906
|
-
},
|
|
907
|
-
if (m.deniesPath(
|
|
908
|
-
return ve(
|
|
909
|
-
const
|
|
910
|
-
if (
|
|
917
|
+
}, Ut = async (o, u) => {
|
|
918
|
+
if (m.deniesPath(u))
|
|
919
|
+
return ve(c, { operation: "text", path: u }), Q("forbidden");
|
|
920
|
+
const s = await M(o, u);
|
|
921
|
+
if (s.status === "error") return { kind: "failure", failure: s.failure };
|
|
911
922
|
try {
|
|
912
|
-
const d = st(await e.asset(o,
|
|
913
|
-
return l === null ? Q("unsupported") : { kind: "text", name: d.name, text: l.text, truncated: l.truncated, url:
|
|
923
|
+
const d = st(await e.asset(o, u, s.readPath)), l = await fn(d, S);
|
|
924
|
+
return l === null ? Q("unsupported") : { kind: "text", name: d.name, text: l.text, truncated: l.truncated, url: He(t.dataPath, u, d.version) };
|
|
914
925
|
} catch (d) {
|
|
915
|
-
return { kind: "failure", failure: G(d, { operation: "text", path:
|
|
926
|
+
return { kind: "failure", failure: G(d, { operation: "text", path: u }, o.signal, c) };
|
|
916
927
|
}
|
|
917
|
-
}, pe = async (o,
|
|
918
|
-
const d = await pe(
|
|
928
|
+
}, pe = async (o, u, s) => m.deniesPath(s) ? (ve(c, { operation: u, path: s }), { status: "error", failure: { reason: "forbidden" } }) : M(o, s), Xt = async (o, u, s) => {
|
|
929
|
+
const d = await pe(u, "edit", s);
|
|
919
930
|
if (d.status === "error") return { kind: "failure", failure: d.failure };
|
|
920
931
|
try {
|
|
921
|
-
return
|
|
932
|
+
return to(await o.source(u, s, d.readPath), y);
|
|
922
933
|
} catch (l) {
|
|
923
|
-
return { kind: "failure", failure: G(l, { operation: "edit", path:
|
|
934
|
+
return { kind: "failure", failure: G(l, { operation: "edit", path: s }, u.signal, c) };
|
|
924
935
|
}
|
|
925
|
-
},
|
|
926
|
-
const f = await pe(
|
|
936
|
+
}, Jt = async (o, u, s, d, l) => {
|
|
937
|
+
const f = await pe(u, "save", s);
|
|
927
938
|
if (f.status === "error") return { kind: "failure", failure: f.failure };
|
|
928
939
|
try {
|
|
929
|
-
return
|
|
930
|
-
} catch (
|
|
931
|
-
return { kind: "failure", failure: G(
|
|
940
|
+
return ro(await o.save(u, s, f.readPath, { text: l, baseVersion: d }), y);
|
|
941
|
+
} catch (b) {
|
|
942
|
+
return { kind: "failure", failure: G(b, { operation: "save", path: s }, u.signal, c) };
|
|
932
943
|
}
|
|
933
|
-
},
|
|
934
|
-
const f = await pe(
|
|
944
|
+
}, Gt = async (o, u, s, d, l) => {
|
|
945
|
+
const f = await pe(u, "preview", d);
|
|
935
946
|
if (f.status === "error") return { kind: "failure", failure: f.failure };
|
|
936
|
-
let
|
|
947
|
+
let b;
|
|
937
948
|
try {
|
|
938
|
-
|
|
949
|
+
b = no(await o.preview(u, d, f.readPath, l));
|
|
939
950
|
} catch (F) {
|
|
940
|
-
return { kind: "failure", failure: G(F, { operation: "preview", path: d },
|
|
951
|
+
return { kind: "failure", failure: G(F, { operation: "preview", path: d }, u.signal, c) };
|
|
941
952
|
}
|
|
942
|
-
if ("kind" in
|
|
943
|
-
const I = await _(
|
|
944
|
-
return I.status === "sanitized" ? { kind: "preview", htmlContent: I.html, headings:
|
|
945
|
-
},
|
|
946
|
-
const d = await pe(
|
|
953
|
+
if ("kind" in b) return b.kind === "failure" ? b : Q("failed");
|
|
954
|
+
const I = await _(b.html, { scope: s, signal: u.signal });
|
|
955
|
+
return I.status === "sanitized" ? { kind: "preview", htmlContent: I.html, headings: b.headings } : (I.cause !== null && oe(c, { operation: "preview", path: d, error: I.cause }), Q(I.reason));
|
|
956
|
+
}, Yt = async (o, u, s) => {
|
|
957
|
+
const d = await pe(u, "revisions", s);
|
|
947
958
|
if (d.status === "error") return { kind: "failure", failure: d.failure };
|
|
948
959
|
try {
|
|
949
|
-
return { kind: "revisions", revisions:
|
|
960
|
+
return { kind: "revisions", revisions: oo(await o.revisions(u, s, d.readPath)) };
|
|
950
961
|
} catch (l) {
|
|
951
|
-
return { kind: "failure", failure: G(l, { operation: "revisions", path:
|
|
962
|
+
return { kind: "failure", failure: G(l, { operation: "revisions", path: s }, u.signal, c) };
|
|
952
963
|
}
|
|
953
|
-
},
|
|
954
|
-
const l = await pe(
|
|
964
|
+
}, Wt = async (o, u, s, d) => {
|
|
965
|
+
const l = await pe(u, "revision", s);
|
|
955
966
|
if (l.status === "error") return { kind: "failure", failure: l.failure };
|
|
956
967
|
try {
|
|
957
|
-
return { kind: "revision", id: d, text:
|
|
968
|
+
return { kind: "revision", id: d, text: so(await o.revision(u, s, l.readPath, d), y) };
|
|
958
969
|
} catch (f) {
|
|
959
|
-
return { kind: "failure", failure: G(f, { operation: "revision", path:
|
|
970
|
+
return { kind: "failure", failure: G(f, { operation: "revision", path: s }, u.signal, c) };
|
|
960
971
|
}
|
|
961
|
-
},
|
|
962
|
-
const
|
|
963
|
-
if (
|
|
964
|
-
if (
|
|
965
|
-
if (
|
|
966
|
-
if (
|
|
972
|
+
}, Kt = async (o, u, s, d, l, f) => {
|
|
973
|
+
const b = ae(l, ie.path);
|
|
974
|
+
if (b === null || !q(b)) return j({ reason: "invalid" }, f);
|
|
975
|
+
if (u === "edit") return W(200, JSON.stringify(await Xt(o, s, b)), f);
|
|
976
|
+
if (u === "revisions") return W(200, JSON.stringify(await Yt(o, s, b)), f);
|
|
977
|
+
if (u === "revision") {
|
|
967
978
|
const re = ae(l, ie.revision);
|
|
968
|
-
return he(re) ? W(200, JSON.stringify(await
|
|
979
|
+
return he(re) ? W(200, JSON.stringify(await Wt(o, s, b, re)), f) : j({ reason: "invalid" }, f);
|
|
969
980
|
}
|
|
970
981
|
const I = ae(l, ie.base);
|
|
971
|
-
if (
|
|
972
|
-
const F = await
|
|
973
|
-
return F.status === "error" ? j(F.failure, f) :
|
|
974
|
-
},
|
|
982
|
+
if (u === "save" && !he(I)) return j({ reason: "invalid" }, f);
|
|
983
|
+
const F = await So(s.request, y);
|
|
984
|
+
return F.status === "error" ? j(F.failure, f) : u === "preview" ? W(200, JSON.stringify(await Gt(o, s, d, b, F.text)), f) : W(200, JSON.stringify(await Jt(o, s, b, I, F.text)), f);
|
|
985
|
+
}, Vt = async ({ request: o, url: u, params: s }) => {
|
|
975
986
|
const d = lt(await P(o, ct)), l = ut(d.headers);
|
|
976
|
-
if (l.set("Cache-Control",
|
|
987
|
+
if (l.set("Cache-Control", Lt), d.status === "signed-out") throw ft("signedOutPage", H(o, l));
|
|
977
988
|
if (d.status === "forbidden") throw p === void 0 ? Fe(null, { status: 403, headers: l }) : ft("forbiddenPage", p(o, l));
|
|
978
|
-
const f =
|
|
979
|
-
if (f.kind === "redirect") throw
|
|
980
|
-
const { location:
|
|
981
|
-
if (re === void 0) throw new RangeError(`[markdown-explorer] no source for ${JSON.stringify(
|
|
989
|
+
const f = Or(a, s["*"], u.searchParams);
|
|
990
|
+
if (f.kind === "redirect") throw br(f.href, { headers: l });
|
|
991
|
+
const { location: b } = f, { principal: I } = d, F = mt(r, B(I)), re = z.get(b.source);
|
|
992
|
+
if (re === void 0) throw new RangeError(`[markdown-explorer] no source for ${JSON.stringify(b.source)}`);
|
|
982
993
|
const we = { signal: o.signal, timeoutMs: h, late: null, handOverMs: h }, ne = {
|
|
983
994
|
scope: F,
|
|
984
995
|
sources: n.map((C) => ({ id: C.id, label: E(C, I) })),
|
|
985
|
-
settings:
|
|
986
|
-
tree:
|
|
987
|
-
sourceId:
|
|
996
|
+
settings: Rr(vr(o.headers.get("Cookie"), t.settingsCookie), O),
|
|
997
|
+
tree: b.view === "single" ? null : {
|
|
998
|
+
sourceId: b.source,
|
|
988
999
|
result: Re(we, (C) => V(re, I, F, o, C).then((Y) => Y.result))
|
|
989
1000
|
},
|
|
990
|
-
documents:
|
|
991
|
-
notices: Re({ signal: o.signal, timeoutMs: h, late:
|
|
1001
|
+
documents: Eo(b).map((C) => ({ path: C, document: Re(we, (Y) => me({ principal: I, request: o, signal: Y, refresh: !1 }, F, C)) })),
|
|
1002
|
+
notices: Re({ signal: o.signal, timeoutMs: h, late: Ae, handOverMs: 0 }, (C) => Ht({ principal: I, request: o, signal: C, refresh: !1 }))
|
|
992
1003
|
};
|
|
993
1004
|
return Fe(ne, { headers: l });
|
|
994
|
-
}, ze = async (o,
|
|
995
|
-
const
|
|
996
|
-
return { authentication:
|
|
997
|
-
},
|
|
1005
|
+
}, ze = async (o, u) => {
|
|
1006
|
+
const s = lt(await P(o, u));
|
|
1007
|
+
return { authentication: s, headers: ut(s.headers) };
|
|
1008
|
+
}, Zt = async (o, u, s) => {
|
|
998
1009
|
let d;
|
|
999
1010
|
try {
|
|
1000
|
-
d = await ze(
|
|
1011
|
+
d = await ze(u, ct);
|
|
1001
1012
|
} catch (Y) {
|
|
1002
|
-
return j(G(dt(Y), { operation: "authenticate" },
|
|
1013
|
+
return j(G(dt(Y), { operation: "authenticate" }, u.signal, c));
|
|
1003
1014
|
}
|
|
1004
1015
|
const { authentication: l, headers: f } = d;
|
|
1005
1016
|
if (l.status === "signed-out") return j({ reason: "unauthorized" }, f);
|
|
1006
1017
|
if (l.status === "forbidden") return j({ reason: "forbidden" }, f);
|
|
1007
|
-
const { principal:
|
|
1008
|
-
if (o === "asset") return
|
|
1009
|
-
const I = mt(r,
|
|
1010
|
-
f.set(
|
|
1011
|
-
const F = { principal:
|
|
1018
|
+
const { principal: b } = l;
|
|
1019
|
+
if (o === "asset") return Ft({ principal: b, request: u, signal: u.signal, refresh: !1 }, s, f);
|
|
1020
|
+
const I = mt(r, B(b));
|
|
1021
|
+
f.set(pr, I);
|
|
1022
|
+
const F = { principal: b, request: u, signal: u.signal, refresh: !1 }, re = () => j({ reason: "invalid" }, f);
|
|
1012
1023
|
if (o === "document") {
|
|
1013
|
-
const Y = ae(
|
|
1024
|
+
const Y = ae(s, ie.path);
|
|
1014
1025
|
if (Y === null || !q(Y)) return re();
|
|
1015
|
-
const
|
|
1016
|
-
return
|
|
1026
|
+
const Be = u.headers.has(Me);
|
|
1027
|
+
return Be && !wt(u) ? j({ reason: "forbidden" }, f) : W(200, JSON.stringify(await me({ ...F, refresh: Be }, I, Y)), f);
|
|
1017
1028
|
}
|
|
1018
1029
|
if (o === "text") {
|
|
1019
|
-
const Y = ae(
|
|
1020
|
-
return Y === null || !q(Y) ? re() : W(200, JSON.stringify(await
|
|
1030
|
+
const Y = ae(s, ie.path);
|
|
1031
|
+
return Y === null || !q(Y) ? re() : W(200, JSON.stringify(await Ut(F, Y)), f);
|
|
1021
1032
|
}
|
|
1022
1033
|
if (o === "edit" || o === "save" || o === "preview" || o === "revisions" || o === "revision")
|
|
1023
|
-
return w === void 0 ? j({ reason: "not-found" }, f) :
|
|
1024
|
-
const we = ae(
|
|
1034
|
+
return w === void 0 ? j({ reason: "not-found" }, f) : Kt(w, o, F, I, s, f);
|
|
1035
|
+
const we = ae(s, ie.source), ne = ae(s, ie.path);
|
|
1025
1036
|
if (we === null || (o === "children" || o === "ancestors" || o === "reveal") && (ne === null || !q(ne))) return re();
|
|
1026
1037
|
const C = z.get(we);
|
|
1027
1038
|
if (C === void 0) return j({ reason: "not-found" }, f);
|
|
1028
|
-
if (o === "tree") return W(200, (await V(C,
|
|
1039
|
+
if (o === "tree") return W(200, (await V(C, b, I, u, u.signal)).json, f);
|
|
1029
1040
|
if (o === "refresh") {
|
|
1030
|
-
const Y = await
|
|
1031
|
-
return
|
|
1041
|
+
const Y = await J(C, b, I, u);
|
|
1042
|
+
return u.signal.aborted || se(C, R(C, I)), W(200, Y.json, f);
|
|
1032
1043
|
}
|
|
1033
1044
|
return o === "ancestors" ? C.ancestors === void 0 || ne === null ? j({ reason: "not-found" }, f) : W(200, JSON.stringify(await ee(C, C.ancestors, F, ne)), f) : o === "reveal" ? ne === null ? re() : W(200, JSON.stringify(await te(C, F, ne)), f) : C.children === void 0 || ne === null ? j({ reason: "not-found" }, f) : W(200, JSON.stringify(await D(C, C.children, F, ne)), f);
|
|
1034
|
-
},
|
|
1035
|
-
const { authentication:
|
|
1036
|
-
if (!
|
|
1037
|
-
return
|
|
1038
|
-
}, De = t.embeds.linkCardEndpoint === null ? null :
|
|
1045
|
+
}, Qt = async (o) => {
|
|
1046
|
+
const { authentication: u, headers: s } = await ze(o, mo);
|
|
1047
|
+
if (!s.keys().next().done) throw new TypeError("[markdown-explorer] authenticate returned headers in read-only mode; a read-only authentication must only read the session (none was forwarded)");
|
|
1048
|
+
return u.status === "signed-in";
|
|
1049
|
+
}, De = t.embeds.linkCardEndpoint === null ? null : Er({ authorize: Qt }), qt = async (o, u) => {
|
|
1039
1050
|
try {
|
|
1040
|
-
return await o(
|
|
1041
|
-
} catch (
|
|
1042
|
-
return j(G(dt(
|
|
1051
|
+
return await o(u);
|
|
1052
|
+
} catch (s) {
|
|
1053
|
+
return j(G(dt(s), { operation: "authenticate" }, u.signal, c));
|
|
1043
1054
|
}
|
|
1044
|
-
}, Ce = async (o,
|
|
1055
|
+
}, Ce = async (o, u, s) => {
|
|
1045
1056
|
if (new URL(o.url).pathname.endsWith(".data")) return j({ reason: "not-found" });
|
|
1046
|
-
if (!
|
|
1047
|
-
if (
|
|
1057
|
+
if (!dr(s)) return j({ reason: "not-found" });
|
|
1058
|
+
if (s === "link-card") {
|
|
1048
1059
|
if (De === null) return j({ reason: "not-found" });
|
|
1049
|
-
const l = pt(o,
|
|
1050
|
-
return l !== null ? l :
|
|
1060
|
+
const l = pt(o, s);
|
|
1061
|
+
return l !== null ? l : qt(De, o);
|
|
1051
1062
|
}
|
|
1052
|
-
if (
|
|
1053
|
-
const d = pt(o,
|
|
1063
|
+
if (To.has(s) && w === void 0) return j({ reason: "not-found" });
|
|
1064
|
+
const d = pt(o, s);
|
|
1054
1065
|
if (d !== null) return d;
|
|
1055
|
-
if (
|
|
1056
|
-
if ((
|
|
1066
|
+
if (s === "refresh" && !wt(o)) return j({ reason: "forbidden" });
|
|
1067
|
+
if ((s === "save" || s === "preview") && !ko(o)) return j({ reason: "forbidden" });
|
|
1057
1068
|
try {
|
|
1058
|
-
return await
|
|
1069
|
+
return await Zt(s, o, u.searchParams);
|
|
1059
1070
|
} catch (l) {
|
|
1060
|
-
return j(G(l, { operation:
|
|
1071
|
+
return j(G(l, { operation: s }, o.signal, c));
|
|
1061
1072
|
}
|
|
1062
1073
|
};
|
|
1063
1074
|
return Object.freeze({
|
|
1064
|
-
loader:
|
|
1065
|
-
headers:
|
|
1066
|
-
dataLoader: ({ request: o, url:
|
|
1067
|
-
dataAction: ({ request: o, url:
|
|
1075
|
+
loader: Vt,
|
|
1076
|
+
headers: Oo,
|
|
1077
|
+
dataLoader: ({ request: o, url: u, params: s }) => Ce(o, u, s["*"]),
|
|
1078
|
+
dataAction: ({ request: o, url: u, params: s }) => Ce(o, u, s["*"]),
|
|
1068
1079
|
forgetTree: (o) => {
|
|
1069
1080
|
if (typeof o != "string") throw new TypeError(`[markdown-explorer] forgetTree needs the string key onTreeRefreshed received; got ${typeof o}`);
|
|
1070
1081
|
$.forget(o);
|
|
1071
1082
|
}
|
|
1072
1083
|
});
|
|
1073
|
-
}, Ee = Object.freeze({ maxEntries: 2e4, maxDocumentBytes: 2 * 1024 * 1024, textPreviewBytes: 8 * 1024, walkConcurrency: 8 }),
|
|
1084
|
+
}, Ee = Object.freeze({ maxEntries: 2e4, maxDocumentBytes: 2 * 1024 * 1024, textPreviewBytes: 8 * 1024, walkConcurrency: 8 }), Ro = /* @__PURE__ */ new Set(["md", "markdown", "mdx"]), jt = new Map([
|
|
1074
1085
|
...[
|
|
1075
1086
|
["png", "image/png"],
|
|
1076
1087
|
["jpg", "image/jpeg"],
|
|
@@ -1105,7 +1116,7 @@ const on = (e) => e instanceof Error && Object.hasOwn(e, vt) && Et(e.reason), sn
|
|
|
1105
1116
|
["wma", "audio/x-ms-wma"]
|
|
1106
1117
|
].map(([e, t]) => [e, { kind: "media", mediaType: "audio", contentType: t }]),
|
|
1107
1118
|
["pdf", { kind: "media", mediaType: "pdf", contentType: "application/pdf" }]
|
|
1108
|
-
]),
|
|
1119
|
+
]), vo = /* @__PURE__ */ new Set([
|
|
1109
1120
|
"txt",
|
|
1110
1121
|
"text",
|
|
1111
1122
|
"log",
|
|
@@ -1230,7 +1241,7 @@ const on = (e) => e instanceof Error && Object.hasOwn(e, vt) && Et(e.reason), sn
|
|
|
1230
1241
|
"eslintrc",
|
|
1231
1242
|
"babelrc",
|
|
1232
1243
|
"mailmap"
|
|
1233
|
-
]),
|
|
1244
|
+
]), _o = /* @__PURE__ */ new Set([
|
|
1234
1245
|
"readme",
|
|
1235
1246
|
"license",
|
|
1236
1247
|
"licence",
|
|
@@ -1251,16 +1262,16 @@ const on = (e) => e instanceof Error && Object.hasOwn(e, vt) && Et(e.reason), sn
|
|
|
1251
1262
|
"jenkinsfile",
|
|
1252
1263
|
"brewfile",
|
|
1253
1264
|
"codeowners"
|
|
1254
|
-
]),
|
|
1265
|
+
]), zt = typeof fe.O_NOFOLLOW == "number" ? fe.O_NOFOLLOW : 0, Dt = typeof fe.O_NONBLOCK == "number" ? fe.O_NONBLOCK : 0, ht = (e) => `${e.size}-${e.mtimeNs}`, No = (e) => e !== "" && e !== "." && e !== ".." && !e.includes(":") && !e.endsWith(".") && !e.endsWith(" "), yt = (e) => q(e) && e === e.normalize("NFC") && e.split("/").every(No), Ct = (e) => {
|
|
1255
1266
|
const t = e.toLowerCase(), r = t.lastIndexOf(".");
|
|
1256
1267
|
return r < 0 ? "" : t.slice(r + 1);
|
|
1257
|
-
},
|
|
1258
|
-
const t =
|
|
1259
|
-
if (
|
|
1260
|
-
const r =
|
|
1268
|
+
}, Ao = (e) => {
|
|
1269
|
+
const t = Ct(e);
|
|
1270
|
+
if (Ro.has(t)) return { kind: "markdown" };
|
|
1271
|
+
const r = jt.get(t);
|
|
1261
1272
|
if (r !== void 0) return r.kind === "image" ? { kind: "image" } : { kind: "media", mediaType: r.mediaType };
|
|
1262
1273
|
const n = e.toLowerCase();
|
|
1263
|
-
return
|
|
1274
|
+
return vo.has(t) || !n.includes(".") && _o.has(n) ? { kind: "text" } : { kind: "file" };
|
|
1264
1275
|
}, Pe = (e) => {
|
|
1265
1276
|
switch (typeof e == "object" && e !== null ? e.code : void 0) {
|
|
1266
1277
|
case "ENOENT":
|
|
@@ -1277,34 +1288,34 @@ const on = (e) => e instanceof Error && Object.hasOwn(e, vt) && Et(e.reason), sn
|
|
|
1277
1288
|
default:
|
|
1278
1289
|
return null;
|
|
1279
1290
|
}
|
|
1280
|
-
},
|
|
1291
|
+
}, Bt = (e) => {
|
|
1281
1292
|
const t = Pe(e);
|
|
1282
1293
|
return t === null ? e : new ke(t);
|
|
1283
|
-
},
|
|
1294
|
+
}, Io = (e) => {
|
|
1284
1295
|
const t = typeof e == "object" && e !== null ? e.code : void 0;
|
|
1285
1296
|
return t === "EACCES" || t === "EPERM" || t === "ENOENT" || t === "ENOTDIR";
|
|
1286
|
-
},
|
|
1297
|
+
}, gt = async (e, t) => {
|
|
1287
1298
|
const r = [];
|
|
1288
1299
|
for await (const n of e.createReadStream({ start: 0, end: t - 1, autoClose: !1 }))
|
|
1289
1300
|
r.push(n);
|
|
1290
1301
|
return Buffer.concat(r);
|
|
1291
|
-
},
|
|
1302
|
+
}, Po = (e, t) => e !== null ? { start: e.offset, end: e.offset + e.length - 1 } : t === 0n ? {} : { start: 0, end: Number(t) - 1 }, Mo = async (e, t, r, n) => {
|
|
1292
1303
|
let a;
|
|
1293
1304
|
try {
|
|
1294
|
-
a = await xt(e, fe.O_RDONLY |
|
|
1305
|
+
a = await xt(e, fe.O_RDONLY | zt | Dt);
|
|
1295
1306
|
const h = await a.stat({ bigint: !0 });
|
|
1296
1307
|
if (!h.isFile() || h.ino !== t.ino || h.dev !== t.dev || h.size !== t.size || h.mtimeNs !== t.mtimeNs) throw new ke("not-found");
|
|
1297
1308
|
} catch (h) {
|
|
1298
|
-
throw await a?.close(),
|
|
1309
|
+
throw await a?.close(), Bt(h);
|
|
1299
1310
|
}
|
|
1300
|
-
const
|
|
1301
|
-
|
|
1311
|
+
const i = a.createReadStream(Po(r, t.size)), c = Br.toWeb(i), m = () => {
|
|
1312
|
+
i.destroy(n.reason);
|
|
1302
1313
|
};
|
|
1303
|
-
return n.aborted ? m() : n.addEventListener("abort", m, { once: !0 }),
|
|
1304
|
-
},
|
|
1305
|
-
const r =
|
|
1314
|
+
return n.aborted ? m() : n.addEventListener("abort", m, { once: !0 }), c;
|
|
1315
|
+
}, $o = (e, t) => {
|
|
1316
|
+
const r = Nr.compare(e, t);
|
|
1306
1317
|
return r !== 0 ? r : e === t ? 0 : e < t ? -1 : 1;
|
|
1307
|
-
},
|
|
1318
|
+
}, Lo = (e) => {
|
|
1308
1319
|
let t = 0;
|
|
1309
1320
|
const r = [];
|
|
1310
1321
|
return async (n) => {
|
|
@@ -1316,160 +1327,160 @@ const on = (e) => e instanceof Error && Object.hasOwn(e, vt) && Et(e.reason), sn
|
|
|
1316
1327
|
a === void 0 ? t -= 1 : a();
|
|
1317
1328
|
}
|
|
1318
1329
|
};
|
|
1319
|
-
},
|
|
1330
|
+
}, jo = (e, t) => {
|
|
1320
1331
|
if (e.isSymbolicLink()) return "symbolic-link";
|
|
1321
1332
|
if (!(e.isDirectory() || e.isFile())) return "special-file";
|
|
1322
1333
|
const { name: r } = e;
|
|
1323
1334
|
return r !== r.normalize("NFC") ? "not-nfc" : r.includes(":") ? "colon" : r.endsWith(".") || r.endsWith(" ") ? "trailing-dot-or-space" : q(r) ? q(t) ? null : "path-too-long" : "control-character-or-backslash";
|
|
1324
|
-
},
|
|
1335
|
+
}, zo = /* @__PURE__ */ new Set(["id", "label", "root", "pathPrefix", "parse", "deny", "maxEntries", "maxDocumentBytes", "textPreviewBytes", "walkConcurrency", "cacheScope", "reportSkipped"]), be = (e, t, r) => {
|
|
1325
1336
|
if (t === void 0) return r;
|
|
1326
1337
|
if (typeof t != "number" || !Number.isSafeInteger(t) || t <= 0) throw new RangeError(`[markdown-explorer] ${e} must be a positive integer; got ${String(t)}`);
|
|
1327
1338
|
return t;
|
|
1328
|
-
},
|
|
1339
|
+
}, qo = (e) => {
|
|
1329
1340
|
if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] createFileSystemSource needs an options object");
|
|
1330
1341
|
for (const E of Object.keys(e))
|
|
1331
|
-
if (
|
|
1342
|
+
if (!zo.has(E)) throw new TypeError(`[markdown-explorer] createFileSystemSource does not know the option ${JSON.stringify(E)}`);
|
|
1332
1343
|
const { id: t, label: r, root: n, parse: a } = e;
|
|
1333
1344
|
if (typeof t != "string" || t === "") throw new TypeError("[markdown-explorer] a file-system source needs a non-empty id");
|
|
1334
1345
|
if (typeof r != "string" || r.trim() === "") throw new TypeError("[markdown-explorer] a file-system source needs a non-blank label");
|
|
1335
1346
|
if (typeof a != "function") throw new TypeError("[markdown-explorer] a file-system source needs a parse function");
|
|
1336
1347
|
if (typeof n != "string" || !Ue(n)) throw new RangeError(`[markdown-explorer] root must be an absolute path; got ${JSON.stringify(n)}`);
|
|
1337
|
-
let
|
|
1348
|
+
let i;
|
|
1338
1349
|
try {
|
|
1339
|
-
|
|
1350
|
+
i = Ir(n).isDirectory();
|
|
1340
1351
|
} catch (E) {
|
|
1341
1352
|
throw new RangeError(`[markdown-explorer] root does not exist: ${n}`, { cause: E });
|
|
1342
1353
|
}
|
|
1343
|
-
if (!
|
|
1344
|
-
const
|
|
1354
|
+
if (!i) throw new RangeError(`[markdown-explorer] root is not a directory: ${n}`);
|
|
1355
|
+
const c = Pr(n), m = e.pathPrefix;
|
|
1345
1356
|
if (typeof m != "string") throw new TypeError('[markdown-explorer] pathPrefix is required: "" for a source over the whole root, or relative segments ending with "/"');
|
|
1346
|
-
if (m !== "" && !(m.endsWith("/") &&
|
|
1357
|
+
if (m !== "" && !(m.endsWith("/") && yt(m.slice(0, -1))))
|
|
1347
1358
|
throw new RangeError(`[markdown-explorer] pathPrefix must be empty or relative segments ending with "/"; got ${JSON.stringify(m)}`);
|
|
1348
|
-
const h = Tt(e.deny), S = be("maxEntries", e.maxEntries, Ee.maxEntries), w = be("maxDocumentBytes", e.maxDocumentBytes, Ee.maxDocumentBytes),
|
|
1359
|
+
const h = Tt(e.deny), S = be("maxEntries", e.maxEntries, Ee.maxEntries), w = be("maxDocumentBytes", e.maxDocumentBytes, Ee.maxDocumentBytes), y = be("textPreviewBytes", e.textPreviewBytes, Ee.textPreviewBytes), T = be("walkConcurrency", e.walkConcurrency, Ee.walkConcurrency), v = e.cacheScope === void 0 ? "principal" : e.cacheScope;
|
|
1349
1360
|
if (v !== "principal" && v !== "shared") throw new RangeError(`[markdown-explorer] cacheScope must be "principal" or "shared"; got ${JSON.stringify(v)}`);
|
|
1350
1361
|
const $ = e.reportSkipped;
|
|
1351
1362
|
if ($ !== void 0 && typeof $ != "function") throw new TypeError("[markdown-explorer] reportSkipped must be a function");
|
|
1352
|
-
const
|
|
1363
|
+
const N = $ === void 0 ? (E) => {
|
|
1353
1364
|
console.warn(`[markdown-explorer] the file-system source ${JSON.stringify(E.sourceId)} does not list ${JSON.stringify(E.path)}: ${E.reason}`);
|
|
1354
1365
|
} : $, _ = /* @__PURE__ */ new Set(), z = (E) => {
|
|
1355
|
-
const R =
|
|
1356
|
-
return
|
|
1366
|
+
const R = Lr(c, ...E.split("/")), k = Xe(c, R);
|
|
1367
|
+
return k === "" || k === ".." || k.startsWith(`..${Je}`) || Ue(k) ? null : R;
|
|
1357
1368
|
}, O = (E, R) => {
|
|
1358
|
-
const
|
|
1359
|
-
_.has(
|
|
1369
|
+
const k = `${R}\0${E}`;
|
|
1370
|
+
_.has(k) || _.size >= S || (_.add(k), N({ sourceId: t, path: E, reason: R }));
|
|
1360
1371
|
}, P = async ({ signal: E }) => {
|
|
1361
1372
|
E.throwIfAborted();
|
|
1362
|
-
const R = new AbortController(),
|
|
1373
|
+
const R = new AbortController(), k = () => {
|
|
1363
1374
|
R.abort(E.reason);
|
|
1364
1375
|
};
|
|
1365
|
-
E.addEventListener("abort",
|
|
1366
|
-
const
|
|
1376
|
+
E.addEventListener("abort", k, { once: !0 });
|
|
1377
|
+
const A = Lo(T);
|
|
1367
1378
|
let M = 0;
|
|
1368
|
-
const U = async (L,
|
|
1369
|
-
const V = await
|
|
1379
|
+
const U = async (L, X) => {
|
|
1380
|
+
const V = await A(async () => {
|
|
1370
1381
|
R.signal.throwIfAborted();
|
|
1371
1382
|
try {
|
|
1372
|
-
return await
|
|
1383
|
+
return await Cr(L, { withFileTypes: !0 });
|
|
1373
1384
|
} catch (D) {
|
|
1374
|
-
if (
|
|
1385
|
+
if (X === "" || !Io(D)) throw D;
|
|
1375
1386
|
return null;
|
|
1376
1387
|
}
|
|
1377
1388
|
});
|
|
1378
1389
|
if (R.signal.throwIfAborted(), V === null)
|
|
1379
|
-
return O(`${m}${
|
|
1380
|
-
const
|
|
1390
|
+
return O(`${m}${X}`, "unreadable-directory"), null;
|
|
1391
|
+
const J = [];
|
|
1381
1392
|
for (const D of V) {
|
|
1382
1393
|
if (h.deniesName(D.name)) continue;
|
|
1383
|
-
const Z =
|
|
1394
|
+
const Z = X === "" ? D.name : `${X}/${D.name}`, ee = `${m}${Z}`, te = jo(D, ee);
|
|
1384
1395
|
if (te !== null) {
|
|
1385
1396
|
O(ee, te);
|
|
1386
1397
|
continue;
|
|
1387
1398
|
}
|
|
1388
|
-
|
|
1399
|
+
J.push({ dirent: D, relativePath: Z, path: ee });
|
|
1389
1400
|
}
|
|
1390
|
-
if (M +=
|
|
1391
|
-
return
|
|
1392
|
-
|
|
1401
|
+
if (M += J.length, M > S) throw new ke("too-large");
|
|
1402
|
+
return J.sort((D, Z) => $o(D.dirent.name, Z.dirent.name)), (await Promise.all(
|
|
1403
|
+
J.map(async ({ dirent: D, relativePath: Z, path: ee }) => {
|
|
1393
1404
|
if (!D.isDirectory()) return { name: D.name, path: ee, type: "file" };
|
|
1394
|
-
const te = await U(
|
|
1405
|
+
const te = await U($r(L, D.name), Z);
|
|
1395
1406
|
return te === null ? null : { name: D.name, path: ee, type: "directory", children: te };
|
|
1396
1407
|
})
|
|
1397
1408
|
)).filter((D) => D !== null);
|
|
1398
1409
|
};
|
|
1399
1410
|
try {
|
|
1400
|
-
const L = await U(
|
|
1411
|
+
const L = await U(c, "");
|
|
1401
1412
|
if (L === null) throw new Error("[markdown-explorer] the source's root could not be listed");
|
|
1402
1413
|
return L;
|
|
1403
1414
|
} catch (L) {
|
|
1404
1415
|
throw R.abort(), L;
|
|
1405
1416
|
} finally {
|
|
1406
|
-
E.removeEventListener("abort",
|
|
1417
|
+
E.removeEventListener("abort", k);
|
|
1407
1418
|
}
|
|
1408
|
-
},
|
|
1419
|
+
}, B = async (E) => {
|
|
1409
1420
|
if (!E.startsWith(m)) return { status: "refused", reason: "not-found" };
|
|
1410
1421
|
const R = E.slice(m.length);
|
|
1411
|
-
if (!
|
|
1422
|
+
if (!yt(R)) return { status: "refused", reason: "invalid" };
|
|
1412
1423
|
if (h.deniesPath(R)) return { status: "refused", reason: "forbidden" };
|
|
1413
|
-
const
|
|
1414
|
-
if (
|
|
1415
|
-
const
|
|
1416
|
-
if (
|
|
1417
|
-
if (!
|
|
1418
|
-
const M = await
|
|
1419
|
-
return M !==
|
|
1420
|
-
},
|
|
1421
|
-
let
|
|
1424
|
+
const k = z(R);
|
|
1425
|
+
if (k === null) return { status: "refused", reason: "forbidden" };
|
|
1426
|
+
const A = await zr(k, { bigint: !0 });
|
|
1427
|
+
if (A.isSymbolicLink()) return { status: "refused", reason: "forbidden" };
|
|
1428
|
+
if (!A.isFile()) return { status: "refused", reason: "unsupported" };
|
|
1429
|
+
const M = await Dr(k);
|
|
1430
|
+
return M !== k || h.deniesPath(Xe(c, M).split(Je).join("/")) ? { status: "refused", reason: "forbidden" } : { status: "file", target: k, name: R.slice(R.lastIndexOf("/") + 1), stats: A };
|
|
1431
|
+
}, H = async (E, R, k) => {
|
|
1432
|
+
let A;
|
|
1422
1433
|
try {
|
|
1423
|
-
const M = await
|
|
1434
|
+
const M = await B(k);
|
|
1424
1435
|
if (M.status === "refused") return Q(M.reason);
|
|
1425
|
-
const { target: U, name: L, stats:
|
|
1426
|
-
if (V.kind === "image") return { kind: "image", name: L, version:
|
|
1427
|
-
if (V.kind === "media") return { kind: "media", name: L, mediaType: V.mediaType, version:
|
|
1428
|
-
if (V.kind === "file") return { kind: "file", name: L, version:
|
|
1429
|
-
|
|
1430
|
-
const se = await
|
|
1431
|
-
if (!se.isFile() || se.ino !==
|
|
1436
|
+
const { target: U, name: L, stats: X } = M, V = Ao(L), J = ht(X);
|
|
1437
|
+
if (V.kind === "image") return { kind: "image", name: L, version: J };
|
|
1438
|
+
if (V.kind === "media") return { kind: "media", name: L, mediaType: V.mediaType, version: J };
|
|
1439
|
+
if (V.kind === "file") return { kind: "file", name: L, version: J };
|
|
1440
|
+
A = await xt(U, fe.O_RDONLY | zt | Dt);
|
|
1441
|
+
const se = await A.stat({ bigint: !0 });
|
|
1442
|
+
if (!se.isFile() || se.ino !== X.ino || se.dev !== X.dev) return Q("forbidden");
|
|
1432
1443
|
if (V.kind === "markdown") {
|
|
1433
1444
|
if (se.size > BigInt(w)) return Q("too-large");
|
|
1434
|
-
const te = await
|
|
1445
|
+
const te = await gt(A, w + 1);
|
|
1435
1446
|
if (te.length > w) return Q("too-large");
|
|
1436
1447
|
const me = await a(new TextDecoder("utf-8").decode(te), R);
|
|
1437
1448
|
return { kind: "markdown", name: L, htmlContent: me.htmlContent, headings: me.headings, edit: null };
|
|
1438
1449
|
}
|
|
1439
|
-
const D = await
|
|
1440
|
-
if (D.includes(0)) return { kind: "file", name: L, version:
|
|
1441
|
-
const Z = se.size > BigInt(
|
|
1442
|
-
return { kind: "text", name: L, text: ee, truncated: Z, version:
|
|
1450
|
+
const D = await gt(A, y);
|
|
1451
|
+
if (D.includes(0)) return { kind: "file", name: L, version: J };
|
|
1452
|
+
const Z = se.size > BigInt(y), ee = new TextDecoder("utf-8").decode(D, { stream: Z });
|
|
1453
|
+
return { kind: "text", name: L, text: ee, truncated: Z, version: J };
|
|
1443
1454
|
} catch (M) {
|
|
1444
1455
|
const U = Pe(M);
|
|
1445
1456
|
if (U === null) throw M;
|
|
1446
1457
|
return Q(U);
|
|
1447
1458
|
} finally {
|
|
1448
|
-
await
|
|
1459
|
+
await A?.close();
|
|
1449
1460
|
}
|
|
1450
|
-
}, p = async (E, R,
|
|
1451
|
-
let
|
|
1461
|
+
}, p = async (E, R, k) => {
|
|
1462
|
+
let A;
|
|
1452
1463
|
try {
|
|
1453
|
-
|
|
1454
|
-
} catch (
|
|
1455
|
-
throw
|
|
1464
|
+
A = await B(k);
|
|
1465
|
+
} catch (J) {
|
|
1466
|
+
throw Bt(J);
|
|
1456
1467
|
}
|
|
1457
|
-
if (
|
|
1458
|
-
const { target: M, name: U, stats: L } =
|
|
1459
|
-
return { name: U, contentType: V, size: Number(L.size), version: ht(L), open: (
|
|
1460
|
-
},
|
|
1461
|
-
let
|
|
1468
|
+
if (A.status === "refused") throw new ke(A.reason);
|
|
1469
|
+
const { target: M, name: U, stats: L } = A, X = jt.get(Ct(U)), V = X === void 0 ? "" : X.contentType;
|
|
1470
|
+
return { name: U, contentType: V, size: Number(L.size), version: ht(L), open: (J) => Mo(M, L, J, E.signal) };
|
|
1471
|
+
}, g = async (E, R, k) => {
|
|
1472
|
+
let A;
|
|
1462
1473
|
try {
|
|
1463
|
-
|
|
1474
|
+
A = await B(k);
|
|
1464
1475
|
} catch (L) {
|
|
1465
1476
|
if (Pe(L) !== null) return null;
|
|
1466
1477
|
throw L;
|
|
1467
1478
|
}
|
|
1468
|
-
if (
|
|
1469
|
-
const M =
|
|
1479
|
+
if (A.status === "refused") return null;
|
|
1480
|
+
const M = k.slice(m.length).split("/");
|
|
1470
1481
|
if (M.some((L) => h.deniesName(L))) return null;
|
|
1471
1482
|
const U = M.slice(0, -1);
|
|
1472
|
-
return U.map((L,
|
|
1483
|
+
return U.map((L, X) => `${m}${U.slice(0, X + 1).join("/")}`);
|
|
1473
1484
|
};
|
|
1474
1485
|
return Object.freeze({
|
|
1475
1486
|
id: t,
|
|
@@ -1477,18 +1488,18 @@ const on = (e) => e instanceof Error && Object.hasOwn(e, vt) && Et(e.reason), sn
|
|
|
1477
1488
|
cacheScope: v,
|
|
1478
1489
|
boundary: Object.freeze({ contains: (E) => E.startsWith(m) }),
|
|
1479
1490
|
tree: P,
|
|
1480
|
-
ancestors:
|
|
1481
|
-
document:
|
|
1491
|
+
ancestors: g,
|
|
1492
|
+
document: H,
|
|
1482
1493
|
asset: p
|
|
1483
1494
|
});
|
|
1484
1495
|
};
|
|
1485
1496
|
export {
|
|
1486
|
-
|
|
1497
|
+
rs as DEFAULT_DENIED_PATH_SEGMENTS,
|
|
1487
1498
|
ke as ExplorerError,
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1499
|
+
ns as MAX_DOCUMENT_PATH_LENGTH,
|
|
1500
|
+
Zo as anonymousAccess,
|
|
1501
|
+
qo as createFileSystemSource,
|
|
1502
|
+
Qo as createMarkdownExplorer,
|
|
1492
1503
|
q as isAcceptableDocumentPath,
|
|
1493
|
-
|
|
1504
|
+
os as isDeniedPath
|
|
1494
1505
|
};
|