@aiquants/markdown-explorer 0.34.0 → 0.36.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 +608 -0
- package/README.md +121 -41
- package/dist/EditSurface-B70iRFkG.cjs +6 -0
- package/dist/EditSurface-BCFJRyIM.js +990 -0
- package/dist/ExplorerSplit-BNrHrIus.cjs +2 -0
- package/dist/ExplorerSplit-Bgccz2nm.js +1589 -0
- package/dist/MultiLayout-Bo9LAXiY.cjs +1 -0
- package/dist/{MultiLayout-kcZyVnvK.js → MultiLayout-Dy5TIC2t.js} +249 -248
- package/dist/{NativeScrollBar-pUbA4Zq3.cjs → NativeScrollBar-Bj-LKej0.cjs} +1 -1
- package/dist/{NativeScrollBar-UNed10Na.js → NativeScrollBar-DpZMYhmf.js} +2 -2
- package/dist/TreeLayout-DsSKW_Qj.js +103 -0
- package/dist/TreeLayout-T8sc_wg7.cjs +1 -0
- package/dist/client/MarkdownExplorer.d.cts +14 -1
- package/dist/client/MarkdownExplorer.d.ts +14 -1
- package/dist/client/edit/lineEndings.d.cts +4 -0
- package/dist/client/edit/lineEndings.d.ts +4 -0
- package/dist/client/hostContract.d.cts +67 -0
- package/dist/client/hostContract.d.ts +67 -0
- package/dist/core/config.d.cts +13 -0
- package/dist/core/config.d.ts +13 -0
- package/dist/core/contracts.d.cts +31 -4
- package/dist/core/contracts.d.ts +31 -4
- package/dist/core/dataRoute.d.cts +5 -1
- package/dist/core/dataRoute.d.ts +5 -1
- package/dist/core/documentId.d.cts +6 -0
- package/dist/core/documentId.d.ts +6 -0
- package/dist/core/draftAnswer.d.cts +23 -0
- package/dist/core/draftAnswer.d.ts +23 -0
- package/dist/core/labels.d.cts +78 -0
- package/dist/core/labels.d.ts +78 -0
- package/dist/core/location.d.cts +22 -2
- package/dist/core/location.d.ts +22 -2
- package/dist/core/ownUrls.d.cts +15 -0
- package/dist/core/ownUrls.d.ts +15 -0
- package/dist/core/treeSettings.d.cts +3 -2
- package/dist/core/treeSettings.d.ts +3 -2
- package/dist/core/viewSettings.d.cts +3 -1
- package/dist/core/viewSettings.d.ts +3 -1
- package/dist/describeValue-CLlVRO8d.js +17 -0
- package/dist/describeValue-Ccvhbt36.cjs +1 -0
- package/dist/explorerCore-B3RGmMG6.js +1083 -0
- package/dist/explorerCore-CUkyKtm8.cjs +1 -0
- package/dist/index-D0l_BJqb.js +5980 -0
- package/dist/index-lpL7GltU.cjs +18 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.js +53 -43
- package/dist/licenses/@heroicons/react/LICENSE +21 -0
- package/dist/licenses/entities/LICENSE +11 -0
- package/dist/licenses/parse5/LICENSE +19 -0
- package/dist/location-Dh6K-y7w.js +761 -0
- package/dist/location-DrOP6t1F.cjs +1 -0
- package/dist/lru-DC8GBmkX.js +39 -0
- package/dist/lru-SGmUyBQU.cjs +1 -0
- package/dist/{merge-C1MWvhCS.js → merge-BwcqBd4c.js} +1 -1
- package/dist/{merge-BziXxZkE.cjs → merge-Dckw7r9T.cjs} +1 -1
- package/dist/nestingGuardWorker.js +5511 -0
- package/dist/ownUrls-BTPGNhBt.cjs +1 -0
- package/dist/ownUrls-DD0cSCsF.js +409 -0
- package/dist/sanitizeJob-BYqzjFJC.js +21 -0
- package/dist/sanitizeJob-CudE1RUP.cjs +1 -0
- package/dist/sanitizePolicy-C-ehd0J_.cjs +2 -0
- package/dist/sanitizePolicy-DAPnUUVm.js +139 -0
- package/dist/sanitizeWorker.cjs +1 -1
- package/dist/sanitizeWorker.js +134 -139
- package/dist/sanitizerService-B8v4ap9t.js +240 -0
- package/dist/sanitizerService-DomN7lwC.cjs +1 -0
- package/dist/server/assetResponse.d.cts +60 -0
- package/dist/server/assetResponse.d.ts +60 -0
- package/dist/server/browser/browserPlatform.d.cts +12 -0
- package/dist/server/browser/browserPlatform.d.ts +12 -0
- package/dist/server/createMarkdownExplorer.d.cts +0 -10
- package/dist/server/createMarkdownExplorer.d.ts +0 -10
- package/dist/server/errors.d.cts +1 -1
- package/dist/server/errors.d.ts +1 -1
- package/dist/server/explorerCore.d.cts +12 -0
- package/dist/server/explorerCore.d.ts +12 -0
- package/dist/server/fileSystemSource.d.cts +1 -0
- package/dist/server/fileSystemSource.d.ts +1 -0
- package/dist/server/inProcessFetch.d.cts +5 -0
- package/dist/server/inProcessFetch.d.ts +5 -0
- package/dist/server/platform.d.cts +18 -0
- package/dist/server/platform.d.ts +18 -0
- package/dist/server/ports.d.cts +55 -5
- package/dist/server/ports.d.ts +55 -5
- package/dist/server/sanitizeProtocol.d.cts +3 -0
- package/dist/server/sanitizeProtocol.d.ts +3 -0
- package/dist/server/sanitizer.d.cts +5 -40
- package/dist/server/sanitizer.d.ts +5 -40
- package/dist/server/sanitizerOptions.d.cts +24 -0
- package/dist/server/sanitizerOptions.d.ts +24 -0
- package/dist/server/sanitizerService.d.cts +41 -0
- package/dist/server/sanitizerService.d.ts +41 -0
- package/dist/server/{workerPool.d.cts → workerJobs.d.cts} +0 -16
- package/dist/server/{workerPool.d.ts → workerJobs.d.ts} +0 -16
- package/dist/server.cjs +1 -1
- package/dist/server.d.cts +3 -1
- package/dist/server.d.ts +3 -1
- package/dist/server.js +270 -1343
- package/dist/serverBrowser.cjs +1 -0
- package/dist/serverBrowser.d.cts +1 -0
- package/dist/serverBrowser.d.ts +1 -0
- package/dist/serverBrowser.js +120 -0
- package/dist/serverCore.cjs +1 -0
- package/dist/serverCore.d.cts +14 -0
- package/dist/serverCore.d.ts +14 -0
- package/dist/serverCore.js +46 -0
- package/dist/storage-BpYsprog.cjs +1 -0
- package/dist/{storage-CmGHg7OA.js → storage-D1uSw-xj.js} +19 -18
- package/dist/storage.cjs +1 -1
- package/dist/storage.js +1 -1
- package/dist/styles/markdown-explorer.css +1 -1
- package/dist/{tapScrollCircle-DigcJCsu.cjs → tapScrollCircle-DyLInGck.cjs} +1 -1
- package/dist/{tapScrollCircle-D_BpaLwY.js → tapScrollCircle-smKLgRa2.js} +1 -1
- package/dist/testing.cjs +1 -0
- package/dist/testing.d.cts +11 -0
- package/dist/testing.d.ts +11 -0
- package/dist/testing.js +82 -0
- package/dist/useSplitPersistence-BUa_KMsV.cjs +1 -0
- package/dist/useSplitPersistence-pnb21dsr.js +44 -0
- package/docs/behavior/dom-hooks.md +5 -1
- package/docs/behavior/hosting.md +123 -0
- package/docs/behavior/layout.md +5 -3
- package/docs/behavior/localization.md +25 -8
- package/docs/behavior/security.md +55 -15
- package/docs/behavior/url-contract.md +30 -3
- package/package.json +48 -10
- package/dist/EditSurface-CF82jZQg.cjs +0 -6
- package/dist/EditSurface-CqHk2R3k.js +0 -982
- package/dist/ExplorerSplit-D325YGEf.cjs +0 -1
- package/dist/ExplorerSplit-DGH9bckm.js +0 -1500
- package/dist/MultiLayout-CzR7yJ0m.cjs +0 -1
- package/dist/TreeLayout-BnIU87HX.js +0 -96
- package/dist/TreeLayout-DtvIpuOe.cjs +0 -1
- package/dist/dataRoute-D6KiSHIc.js +0 -298
- package/dist/dataRoute-DwYtgyt6.cjs +0 -1
- package/dist/index-BDCbvHDs.cjs +0 -15
- package/dist/index-DR31S_-4.js +0 -5012
- package/dist/location-C44b9H1S.js +0 -676
- package/dist/location-hGLhCCg4.cjs +0 -1
- package/dist/sanitizePolicy-CwvyPpp5.js +0 -98
- package/dist/sanitizePolicy-T5T-3vV5.cjs +0 -1
- package/dist/storage-DM0EvkVf.cjs +0 -1
- package/dist/useSplitPersistence-DCeYbJMx.js +0 -38
- package/dist/useSplitPersistence-QGcvyMAa.cjs +0 -1
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { i as Y, d as M } from "./describeValue-CLlVRO8d.js";
|
|
2
|
+
import { M as J, c as G } from "./lru-DC8GBmkX.js";
|
|
3
|
+
import { r as U } from "./ownUrls-DD0cSCsF.js";
|
|
4
|
+
const Z = (r) => Math.max(1, r - 1), B = 1024 * 1024, X = 3e4, V = 4 * B, W = 64 * B, q = 2 ** 29, K = 3, ee = (r, o) => r + Z(o) + K, te = 4, v = 512, re = 64, oe = 4096, ne = 32, D = 4096, se = (r, o) => Math.floor(((o - re) * B - r * ne) / oe), k = (r, o, d, u) => {
|
|
5
|
+
if (o === void 0) return d;
|
|
6
|
+
if (typeof o != "number") throw new TypeError(`[markdown-explorer] sanitizer.${r} must be a number; got ${M(o)}`);
|
|
7
|
+
if (!Number.isSafeInteger(o) || o <= 0 || o > u) throw new RangeError(`[markdown-explorer] sanitizer.${r} must be an integer in 1..${String(u)}; got ${M(o)}`);
|
|
8
|
+
return o;
|
|
9
|
+
}, ae = (r, o) => {
|
|
10
|
+
if (r.jobsPerScope < o)
|
|
11
|
+
throw new RangeError(`[markdown-explorer] sanitizer.jobsPerScope must be at least multiView.maxPanels (${String(o)}), because a page sends the document of every panel to the sanitizer at once for one reader; got ${M(r.jobsPerScope)}`);
|
|
12
|
+
if (r.maxQueuedJobs < o)
|
|
13
|
+
throw new RangeError(`[markdown-explorer] sanitizer.maxQueuedJobs must be at least multiView.maxPanels (${String(o)}), because a reader whose page finds every worker busy waits with the document of every panel; got ${M(r.maxQueuedJobs)}`);
|
|
14
|
+
}, ie = Object.freeze(["workers", "workerHeapMb"]), he = (r, o) => {
|
|
15
|
+
if (r !== void 0 && !Y(r)) throw new TypeError("[markdown-explorer] sanitizer must be a plain object of { deadlineMs, maxHtmlBytes, cacheBytes, jobsPerScope, maxQueuedJobs }");
|
|
16
|
+
const d = r ?? {};
|
|
17
|
+
for (const T of ie)
|
|
18
|
+
if (d[T] !== void 0) throw new TypeError(`[markdown-explorer] sanitizer.${T} is an option of Node's worker threads; a browser runtime takes only { deadlineMs, maxHtmlBytes, cacheBytes, jobsPerScope, maxQueuedJobs }`);
|
|
19
|
+
const { deadlineMs: u, maxHtmlBytes: g, cacheBytes: w, jobsPerScope: f, maxQueuedJobs: S } = d, l = k("jobsPerScope", f, ee(o, 1), Number.MAX_SAFE_INTEGER), p = Object.freeze({
|
|
20
|
+
deadlineMs: k("deadlineMs", u, X, J),
|
|
21
|
+
maxHtmlBytes: k("maxHtmlBytes", g, V, q),
|
|
22
|
+
cacheBytes: k("cacheBytes", w, W, Number.MAX_SAFE_INTEGER),
|
|
23
|
+
jobsPerScope: l,
|
|
24
|
+
maxQueuedJobs: k("maxQueuedJobs", S, te * l, Number.MAX_SAFE_INTEGER)
|
|
25
|
+
});
|
|
26
|
+
if (ae(p, o), se(p.maxHtmlBytes, v) < D)
|
|
27
|
+
throw new RangeError(
|
|
28
|
+
`[markdown-explorer] sanitizer.maxHtmlBytes (${String(p.maxHtmlBytes)} bytes) must leave room for ${String(D)} parsed nodes in the node budget, which a browser runtime counts in a worker heap of ${String(v)} MiB; lower maxHtmlBytes`
|
|
29
|
+
);
|
|
30
|
+
return p;
|
|
31
|
+
}, C = Object.freeze({ status: "aborted" }), A = (r, o, d) => {
|
|
32
|
+
const u = (r.get(o) ?? 0) + d;
|
|
33
|
+
u === 0 ? r.delete(o) : r.set(o, u);
|
|
34
|
+
}, H = (r, o, d) => {
|
|
35
|
+
if (!Number.isSafeInteger(o) || o <= 0 || o > d) throw new RangeError(`[markdown-explorer] a worker pool's ${r} must be an integer in 1..${String(d)}; got ${M(o)}`);
|
|
36
|
+
}, ue = (r) => r !== null && typeof r == "object" && r.ready === !0 && !("id" in r), ce = (r, o) => r !== null && typeof r == "object" && r.id === o && "output" in r, Se = ({ start: r, size: o, deadlineMs: d, jobsPerScope: u, maxQueuedJobs: g }) => {
|
|
37
|
+
H("size", o, Number.MAX_SAFE_INTEGER), H("deadline", d, J), H("jobsPerScope", u, Number.MAX_SAFE_INTEGER), H("maxQueuedJobs", g, Number.MAX_SAFE_INTEGER);
|
|
38
|
+
const w = /* @__PURE__ */ new Set(), f = [], S = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), p = Z(o);
|
|
39
|
+
let T = 0;
|
|
40
|
+
const _ = (e, t) => {
|
|
41
|
+
const { job: n } = e;
|
|
42
|
+
e.timer !== null && clearTimeout(e.timer), e.timer = null, e.job = null, e.sent = !1, n !== null && (A(S, n.scope, -1), A(l, n.scope, -1), n.settle(t));
|
|
43
|
+
}, h = (e) => {
|
|
44
|
+
const [t] = f.splice(e, 1);
|
|
45
|
+
t?.detach();
|
|
46
|
+
}, I = () => {
|
|
47
|
+
let e = -1, t = p, n = Number.POSITIVE_INFINITY;
|
|
48
|
+
for (const [s, a] of f.entries()) {
|
|
49
|
+
const i = S.get(a.scope) ?? 0, c = l.get(a.scope) ?? 0;
|
|
50
|
+
(i < t || i === t && e >= 0 && c < n) && (e = s, t = i, n = c);
|
|
51
|
+
}
|
|
52
|
+
return e;
|
|
53
|
+
}, E = (e, t) => {
|
|
54
|
+
w.has(e) && (w.delete(e), _(e, t), e.worker.terminate().catch(() => {
|
|
55
|
+
}), x());
|
|
56
|
+
}, y = (e) => {
|
|
57
|
+
e.timer = setTimeout(() => {
|
|
58
|
+
E(e, { status: "timeout" });
|
|
59
|
+
}, d);
|
|
60
|
+
}, N = (e, t) => e.sent ? { status: "crashed", error: t } : { status: "unavailable", error: t }, R = (e, t) => {
|
|
61
|
+
e.sent = !0, y(e);
|
|
62
|
+
try {
|
|
63
|
+
e.worker.postMessage({ id: t.id, input: t.input });
|
|
64
|
+
} catch (n) {
|
|
65
|
+
_(e, { status: "crashed", error: n }), e.worker.unref();
|
|
66
|
+
}
|
|
67
|
+
}, L = () => {
|
|
68
|
+
const e = { worker: r(), job: null, sent: !1, timer: null, ready: !1 };
|
|
69
|
+
return e.worker.unref(), e.timer = setTimeout(() => {
|
|
70
|
+
E(e, { status: "unavailable", error: new Error(`[markdown-explorer] a worker did not start within ${String(d)} ms`) });
|
|
71
|
+
}, d), e.worker.listen({
|
|
72
|
+
message: (t) => {
|
|
73
|
+
if (!e.ready && ue(t)) {
|
|
74
|
+
e.ready = !0, e.timer !== null && clearTimeout(e.timer), e.timer = null, e.job === null ? e.worker.unref() : R(e, e.job), e.job === null && x();
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const { job: n } = e;
|
|
78
|
+
if (n === null || !ce(t, n.id)) {
|
|
79
|
+
E(e, N(e, new Error("[markdown-explorer] a worker sent a message that answers no job")));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
_(e, { status: "done", output: t.output }), e.worker.unref(), x();
|
|
83
|
+
},
|
|
84
|
+
failure: (t) => {
|
|
85
|
+
E(e, N(e, t));
|
|
86
|
+
}
|
|
87
|
+
}), w.add(e), e;
|
|
88
|
+
}, x = () => {
|
|
89
|
+
for (; ; ) {
|
|
90
|
+
const e = I(), t = f[e];
|
|
91
|
+
if (t === void 0) return;
|
|
92
|
+
let n;
|
|
93
|
+
for (const a of w)
|
|
94
|
+
if (a.job === null) {
|
|
95
|
+
n = a;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
if (n === void 0 && w.size < o)
|
|
99
|
+
try {
|
|
100
|
+
n = L();
|
|
101
|
+
} catch (a) {
|
|
102
|
+
h(e), A(l, t.scope, -1), t.settle({ status: "unavailable", error: a });
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (n === void 0) return;
|
|
106
|
+
h(e), A(S, t.scope, 1);
|
|
107
|
+
const s = n;
|
|
108
|
+
s.job = t, s.worker.ref(), s.ready && R(s, t);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
return {
|
|
112
|
+
run: (e, { scope: t, signal: n }) => new Promise((s) => {
|
|
113
|
+
if (n.aborted) {
|
|
114
|
+
s(C);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if ((l.get(t) ?? 0) >= u) {
|
|
118
|
+
s({ status: "refused", limit: "scope" });
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
T += 1;
|
|
122
|
+
const a = { id: T, input: e, scope: t, settle: s, detach: () => {
|
|
123
|
+
} };
|
|
124
|
+
f.push(a), A(l, t, 1), x();
|
|
125
|
+
const i = f.indexOf(a);
|
|
126
|
+
if (i < 0) return;
|
|
127
|
+
if (f.length > g) {
|
|
128
|
+
h(i), A(l, t, -1), s({ status: "refused", limit: "queue" });
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const c = () => {
|
|
132
|
+
const m = f.indexOf(a);
|
|
133
|
+
m < 0 || (h(m), A(l, t, -1), s(C));
|
|
134
|
+
};
|
|
135
|
+
n.addEventListener("abort", c, { once: !0 }), a.detach = () => {
|
|
136
|
+
n.removeEventListener("abort", c);
|
|
137
|
+
};
|
|
138
|
+
}),
|
|
139
|
+
workers: () => w.size
|
|
140
|
+
};
|
|
141
|
+
}, de = 4, le = ({ maxHtmlBytes: r }) => r, me = ({ maxHtmlBytes: r }) => de * r, fe = 1024, we = 64, P = Object.freeze({ status: "rejected", reason: "too-large", cause: null }), j = Object.freeze({ status: "rejected", reason: "failed", cause: null }), Ee = (r) => {
|
|
142
|
+
if (r === null || typeof r != "object") return !1;
|
|
143
|
+
const { status: o, html: d, message: u } = r;
|
|
144
|
+
return o === "sanitized" && typeof d == "string" || o === "too-large" || o === "error" && typeof u == "string";
|
|
145
|
+
}, F = (r) => ({ status: "rejected", reason: "failed", cause: new Error("[markdown-explorer] the HTML sanitizer could not measure a document", { cause: r }) }), Te = ({ iframeHosts: r, dataPath: o, ownUrls: d, limits: u, nodeBudget: g, measureHtml: w, classifyCrash: f, pool: S }) => {
|
|
146
|
+
if (!Number.isSafeInteger(g) || g <= 0) throw new RangeError(`[markdown-explorer] the HTML sanitizer's node budget must be a positive integer; got ${M(g)}`);
|
|
147
|
+
const l = Object.freeze([...r]), p = U(d), T = le(u), _ = me(u), h = G(fe, {
|
|
148
|
+
max: u.cacheBytes,
|
|
149
|
+
of: (e, t) => 2 * e.length + (t.status === "sanitized" ? 2 * t.html.length : we)
|
|
150
|
+
}), I = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ new Map(), y = (e) => {
|
|
151
|
+
I.get(e.key) === e && I.delete(e.key);
|
|
152
|
+
const t = E.get(e.hash);
|
|
153
|
+
t?.delete(e), t?.size === 0 && E.delete(e.hash);
|
|
154
|
+
}, N = async (e, t, n) => {
|
|
155
|
+
const s = await S.run({ html: e, iframeHosts: l, dataPath: o, ownUrls: p, maxNodes: g, maxAttributeChars: T, maxSanitizedChars: _ }, { scope: t, signal: n });
|
|
156
|
+
if (s.status === "refused") {
|
|
157
|
+
const i = s.limit === "scope" ? `its reader already has ${String(u.jobsPerScope)} documents being sanitized or waiting` : `${String(u.maxQueuedJobs)} documents are already waiting`;
|
|
158
|
+
return { outcome: { status: "rejected", reason: "failed", cause: new Error(`[markdown-explorer] the HTML sanitizer refused a document: ${i}`) }, lasting: !1 };
|
|
159
|
+
}
|
|
160
|
+
if (s.status === "aborted") return { outcome: j, lasting: !1 };
|
|
161
|
+
if (s.status === "timeout") return { outcome: { status: "rejected", reason: "too-large", cause: new Error(`[markdown-explorer] the HTML sanitizer did not finish within ${String(u.deadlineMs)} ms`) }, lasting: !0 };
|
|
162
|
+
if (s.status === "unavailable") return { outcome: { status: "rejected", reason: "failed", cause: new Error("[markdown-explorer] the HTML sanitizer worker could not start", { cause: s.error }) }, lasting: !1 };
|
|
163
|
+
if (s.status === "crashed") {
|
|
164
|
+
const i = f(s.error);
|
|
165
|
+
return i !== null ? { outcome: { status: "rejected", reason: i.reason, cause: new Error(i.message, { cause: s.error }) }, lasting: !0 } : { outcome: { status: "rejected", reason: "failed", cause: new Error("[markdown-explorer] the HTML sanitizer worker failed", { cause: s.error }) }, lasting: !0 };
|
|
166
|
+
}
|
|
167
|
+
const { output: a } = s;
|
|
168
|
+
return Ee(a) ? a.status === "too-large" ? { outcome: P, lasting: !0 } : a.status === "error" ? { outcome: { status: "rejected", reason: "failed", cause: new Error(`[markdown-explorer] the HTML sanitizer failed: ${a.message}`) }, lasting: !0 } : a.html.length > _ ? { outcome: { status: "rejected", reason: "too-large", cause: new Error(`[markdown-explorer] the HTML sanitizer's output of ${String(a.html.length)} characters exceeds its limit of ${String(_)}`) }, lasting: !0 } : { outcome: { status: "sanitized", html: a.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 };
|
|
169
|
+
}, R = (e, t, n, s) => {
|
|
170
|
+
let a = () => {
|
|
171
|
+
};
|
|
172
|
+
const i = new Promise((b) => {
|
|
173
|
+
a = b;
|
|
174
|
+
}), c = { hash: t, key: n, outcome: i, answer: a, controller: new AbortController(), waiters: 0 };
|
|
175
|
+
I.set(n, c);
|
|
176
|
+
const m = E.get(t);
|
|
177
|
+
return m === void 0 ? E.set(t, /* @__PURE__ */ new Set([c])) : m.add(c), N(e, s, c.controller.signal).catch((b) => ({ outcome: { status: "rejected", reason: "failed", cause: b instanceof Error ? b : new Error(String(b)) }, lasting: !0 })).then(({ outcome: b, lasting: Q }) => {
|
|
178
|
+
if (y(c), c.answer(b), !Q) return;
|
|
179
|
+
const O = h.get(t), $ = O ?? (b.status === "rejected" ? { ...b, cause: null } : b);
|
|
180
|
+
O === void 0 && h.set(t, $);
|
|
181
|
+
for (const z of E.get(t) ?? [])
|
|
182
|
+
y(z), z.answer($), z.controller.abort();
|
|
183
|
+
}), c;
|
|
184
|
+
}, L = (e, t) => new Promise((n) => {
|
|
185
|
+
e.waiters += 1;
|
|
186
|
+
const s = () => {
|
|
187
|
+
e.waiters -= 1, n(j), !(e.waiters > 0) && (y(e), e.controller.abort());
|
|
188
|
+
};
|
|
189
|
+
t.addEventListener("abort", s, { once: !0 }), e.outcome.then((a) => {
|
|
190
|
+
t.removeEventListener("abort", s), n(a);
|
|
191
|
+
});
|
|
192
|
+
}), x = (e, { utf8Bytes: t, hash: n }, s, a) => {
|
|
193
|
+
if (t > u.maxHtmlBytes) return Promise.resolve(P);
|
|
194
|
+
const i = h.get(n);
|
|
195
|
+
if (i !== void 0) return Promise.resolve(i);
|
|
196
|
+
if (a.aborted) return Promise.resolve(j);
|
|
197
|
+
const c = `${n}\0${s}`, m = I.get(c);
|
|
198
|
+
return L(m === void 0 ? R(e, n, c, s) : m, a);
|
|
199
|
+
};
|
|
200
|
+
return (e, { scope: t, signal: n }) => {
|
|
201
|
+
if (e.length > u.maxHtmlBytes) return Promise.resolve(P);
|
|
202
|
+
let s;
|
|
203
|
+
try {
|
|
204
|
+
s = w(e);
|
|
205
|
+
} catch (i) {
|
|
206
|
+
return Promise.resolve(F(i));
|
|
207
|
+
}
|
|
208
|
+
if (!(s instanceof Promise)) return x(e, s, t, n);
|
|
209
|
+
const a = s;
|
|
210
|
+
return new Promise((i) => {
|
|
211
|
+
const c = () => i(j);
|
|
212
|
+
n.addEventListener("abort", c, { once: !0 }), a.then(
|
|
213
|
+
(m) => {
|
|
214
|
+
n.removeEventListener("abort", c), i(x(e, m, t, n));
|
|
215
|
+
},
|
|
216
|
+
(m) => {
|
|
217
|
+
n.removeEventListener("abort", c), i(F(m));
|
|
218
|
+
}
|
|
219
|
+
);
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
export {
|
|
224
|
+
v as D,
|
|
225
|
+
q as M,
|
|
226
|
+
te as S,
|
|
227
|
+
Te as a,
|
|
228
|
+
H as b,
|
|
229
|
+
Se as c,
|
|
230
|
+
k as d,
|
|
231
|
+
ee as e,
|
|
232
|
+
W as f,
|
|
233
|
+
V as g,
|
|
234
|
+
se as h,
|
|
235
|
+
ce as i,
|
|
236
|
+
X as j,
|
|
237
|
+
ae as k,
|
|
238
|
+
D as l,
|
|
239
|
+
he as r
|
|
240
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const M=require("./describeValue-Ccvhbt36.cjs"),D=require("./lru-SGmUyBQU.cjs"),te=require("./ownUrls-BTPGNhBt.cjs"),Z=r=>Math.max(1,r-1),v=1024*1024,J=3e4,Y=4*v,X=64*v,Q=2**29,re=3,G=(r,o)=>r+Z(o)+re,V=4,z=512,oe=64,ne=4096,se=32,O=4096,q=(r,o)=>Math.floor(((o-oe)*v-r*se)/ne),R=(r,o,d,u)=>{if(o===void 0)return d;if(typeof o!="number")throw new TypeError(`[markdown-explorer] sanitizer.${r} must be a number; got ${M.describeValue(o)}`);if(!Number.isSafeInteger(o)||o<=0||o>u)throw new RangeError(`[markdown-explorer] sanitizer.${r} must be an integer in 1..${String(u)}; got ${M.describeValue(o)}`);return o},W=(r,o)=>{if(r.jobsPerScope<o)throw new RangeError(`[markdown-explorer] sanitizer.jobsPerScope must be at least multiView.maxPanels (${String(o)}), because a page sends the document of every panel to the sanitizer at once for one reader; got ${M.describeValue(r.jobsPerScope)}`);if(r.maxQueuedJobs<o)throw new RangeError(`[markdown-explorer] sanitizer.maxQueuedJobs must be at least multiView.maxPanels (${String(o)}), because a reader whose page finds every worker busy waits with the document of every panel; got ${M.describeValue(r.maxQueuedJobs)}`)},ae=Object.freeze(["workers","workerHeapMb"]),ie=(r,o)=>{if(r!==void 0&&!M.isPlainObject(r))throw new TypeError("[markdown-explorer] sanitizer must be a plain object of { deadlineMs, maxHtmlBytes, cacheBytes, jobsPerScope, maxQueuedJobs }");const d=r??{};for(const p of ae)if(d[p]!==void 0)throw new TypeError(`[markdown-explorer] sanitizer.${p} is an option of Node's worker threads; a browser runtime takes only { deadlineMs, maxHtmlBytes, cacheBytes, jobsPerScope, maxQueuedJobs }`);const{deadlineMs:u,maxHtmlBytes:S,cacheBytes:f,jobsPerScope:E,maxQueuedJobs:g}=d,l=R("jobsPerScope",E,G(o,1),Number.MAX_SAFE_INTEGER),_=Object.freeze({deadlineMs:R("deadlineMs",u,J,D.MAX_TIMER_MILLISECONDS),maxHtmlBytes:R("maxHtmlBytes",S,Y,Q),cacheBytes:R("cacheBytes",f,X,Number.MAX_SAFE_INTEGER),jobsPerScope:l,maxQueuedJobs:R("maxQueuedJobs",g,V*l,Number.MAX_SAFE_INTEGER)});if(W(_,o),q(_.maxHtmlBytes,z)<O)throw new RangeError(`[markdown-explorer] sanitizer.maxHtmlBytes (${String(_.maxHtmlBytes)} bytes) must leave room for ${String(O)} parsed nodes in the node budget, which a browser runtime counts in a worker heap of ${String(z)} MiB; lower maxHtmlBytes`);return _},U=Object.freeze({status:"aborted"}),I=(r,o,d)=>{const u=(r.get(o)??0)+d;u===0?r.delete(o):r.set(o,u)},L=(r,o,d)=>{if(!Number.isSafeInteger(o)||o<=0||o>d)throw new RangeError(`[markdown-explorer] a worker pool's ${r} must be an integer in 1..${String(d)}; got ${M.describeValue(o)}`)},ue=r=>r!==null&&typeof r=="object"&&r.ready===!0&&!("id"in r),K=(r,o)=>r!==null&&typeof r=="object"&&r.id===o&&"output"in r,ce=({start:r,size:o,deadlineMs:d,jobsPerScope:u,maxQueuedJobs:S})=>{L("size",o,Number.MAX_SAFE_INTEGER),L("deadline",d,D.MAX_TIMER_MILLISECONDS),L("jobsPerScope",u,Number.MAX_SAFE_INTEGER),L("maxQueuedJobs",S,Number.MAX_SAFE_INTEGER);const f=new Set,E=[],g=new Map,l=new Map,_=Z(o);let p=0;const h=(e,t)=>{const{job:n}=e;e.timer!==null&&clearTimeout(e.timer),e.timer=null,e.job=null,e.sent=!1,n!==null&&(I(g,n.scope,-1),I(l,n.scope,-1),n.settle(t))},T=e=>{const[t]=E.splice(e,1);t?.detach()},N=()=>{let e=-1,t=_,n=Number.POSITIVE_INFINITY;for(const[s,a]of E.entries()){const i=g.get(a.scope)??0,c=l.get(a.scope)??0;(i<t||i===t&&e>=0&&c<n)&&(e=s,t=i,n=c)}return e},w=(e,t)=>{f.has(e)&&(f.delete(e),h(e,t),e.worker.terminate().catch(()=>{}),A())},x=e=>{e.timer=setTimeout(()=>{w(e,{status:"timeout"})},d)},y=(e,t)=>e.sent?{status:"crashed",error:t}:{status:"unavailable",error:t},H=(e,t)=>{e.sent=!0,x(e);try{e.worker.postMessage({id:t.id,input:t.input})}catch(n){h(e,{status:"crashed",error:n}),e.worker.unref()}},B=()=>{const e={worker:r(),job:null,sent:!1,timer:null,ready:!1};return e.worker.unref(),e.timer=setTimeout(()=>{w(e,{status:"unavailable",error:new Error(`[markdown-explorer] a worker did not start within ${String(d)} ms`)})},d),e.worker.listen({message:t=>{if(!e.ready&&ue(t)){e.ready=!0,e.timer!==null&&clearTimeout(e.timer),e.timer=null,e.job===null?e.worker.unref():H(e,e.job),e.job===null&&A();return}const{job:n}=e;if(n===null||!K(t,n.id)){w(e,y(e,new Error("[markdown-explorer] a worker sent a message that answers no job")));return}h(e,{status:"done",output:t.output}),e.worker.unref(),A()},failure:t=>{w(e,y(e,t))}}),f.add(e),e},A=()=>{for(;;){const e=N(),t=E[e];if(t===void 0)return;let n;for(const a of f)if(a.job===null){n=a;break}if(n===void 0&&f.size<o)try{n=B()}catch(a){T(e),I(l,t.scope,-1),t.settle({status:"unavailable",error:a});continue}if(n===void 0)return;T(e),I(g,t.scope,1);const s=n;s.job=t,s.worker.ref(),s.ready&&H(s,t)}};return{run:(e,{scope:t,signal:n})=>new Promise(s=>{if(n.aborted){s(U);return}if((l.get(t)??0)>=u){s({status:"refused",limit:"scope"});return}p+=1;const a={id:p,input:e,scope:t,settle:s,detach:()=>{}};E.push(a),I(l,t,1),A();const i=E.indexOf(a);if(i<0)return;if(E.length>S){T(i),I(l,t,-1),s({status:"refused",limit:"queue"});return}const c=()=>{const m=E.indexOf(a);m<0||(T(m),I(l,t,-1),s(U))};n.addEventListener("abort",c,{once:!0}),a.detach=()=>{n.removeEventListener("abort",c)}}),workers:()=>f.size}},de=4,le=({maxHtmlBytes:r})=>r,me=({maxHtmlBytes:r})=>de*r,Ee=1024,fe=64,j=Object.freeze({status:"rejected",reason:"too-large",cause:null}),k=Object.freeze({status:"rejected",reason:"failed",cause:null}),we=r=>{if(r===null||typeof r!="object")return!1;const{status:o,html:d,message:u}=r;return o==="sanitized"&&typeof d=="string"||o==="too-large"||o==="error"&&typeof u=="string"},F=r=>({status:"rejected",reason:"failed",cause:new Error("[markdown-explorer] the HTML sanitizer could not measure a document",{cause:r})}),be=({iframeHosts:r,dataPath:o,ownUrls:d,limits:u,nodeBudget:S,measureHtml:f,classifyCrash:E,pool:g})=>{if(!Number.isSafeInteger(S)||S<=0)throw new RangeError(`[markdown-explorer] the HTML sanitizer's node budget must be a positive integer; got ${M.describeValue(S)}`);const l=Object.freeze([...r]),_=te.readOwnUrls(d),p=le(u),h=me(u),T=D.createLruCache(Ee,{max:u.cacheBytes,of:(e,t)=>2*e.length+(t.status==="sanitized"?2*t.html.length:fe)}),N=new Map,w=new Map,x=e=>{N.get(e.key)===e&&N.delete(e.key);const t=w.get(e.hash);t?.delete(e),t?.size===0&&w.delete(e.hash)},y=async(e,t,n)=>{const s=await g.run({html:e,iframeHosts:l,dataPath:o,ownUrls:_,maxNodes:S,maxAttributeChars:p,maxSanitizedChars:h},{scope:t,signal:n});if(s.status==="refused"){const i=s.limit==="scope"?`its reader already has ${String(u.jobsPerScope)} documents being sanitized or waiting`:`${String(u.maxQueuedJobs)} documents are already waiting`;return{outcome:{status:"rejected",reason:"failed",cause:new Error(`[markdown-explorer] the HTML sanitizer refused a document: ${i}`)},lasting:!1}}if(s.status==="aborted")return{outcome:k,lasting:!1};if(s.status==="timeout")return{outcome:{status:"rejected",reason:"too-large",cause:new Error(`[markdown-explorer] the HTML sanitizer did not finish within ${String(u.deadlineMs)} ms`)},lasting:!0};if(s.status==="unavailable")return{outcome:{status:"rejected",reason:"failed",cause:new Error("[markdown-explorer] the HTML sanitizer worker could not start",{cause:s.error})},lasting:!1};if(s.status==="crashed"){const i=E(s.error);return i!==null?{outcome:{status:"rejected",reason:i.reason,cause:new Error(i.message,{cause:s.error})},lasting:!0}:{outcome:{status:"rejected",reason:"failed",cause:new Error("[markdown-explorer] the HTML sanitizer worker failed",{cause:s.error})},lasting:!0}}const{output:a}=s;return we(a)?a.status==="too-large"?{outcome:j,lasting:!0}:a.status==="error"?{outcome:{status:"rejected",reason:"failed",cause:new Error(`[markdown-explorer] the HTML sanitizer failed: ${a.message}`)},lasting:!0}:a.html.length>h?{outcome:{status:"rejected",reason:"too-large",cause:new Error(`[markdown-explorer] the HTML sanitizer's output of ${String(a.html.length)} characters exceeds its limit of ${String(h)}`)},lasting:!0}:{outcome:{status:"sanitized",html:a.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}},H=(e,t,n,s)=>{let a=()=>{};const i=new Promise(b=>{a=b}),c={hash:t,key:n,outcome:i,answer:a,controller:new AbortController,waiters:0};N.set(n,c);const m=w.get(t);return m===void 0?w.set(t,new Set([c])):m.add(c),y(e,s,c.controller.signal).catch(b=>({outcome:{status:"rejected",reason:"failed",cause:b instanceof Error?b:new Error(String(b))},lasting:!0})).then(({outcome:b,lasting:ee})=>{if(x(c),c.answer(b),!ee)return;const $=T.get(t),C=$??(b.status==="rejected"?{...b,cause:null}:b);$===void 0&&T.set(t,C);for(const P of w.get(t)??[])x(P),P.answer(C),P.controller.abort()}),c},B=(e,t)=>new Promise(n=>{e.waiters+=1;const s=()=>{e.waiters-=1,n(k),!(e.waiters>0)&&(x(e),e.controller.abort())};t.addEventListener("abort",s,{once:!0}),e.outcome.then(a=>{t.removeEventListener("abort",s),n(a)})}),A=(e,{utf8Bytes:t,hash:n},s,a)=>{if(t>u.maxHtmlBytes)return Promise.resolve(j);const i=T.get(n);if(i!==void 0)return Promise.resolve(i);if(a.aborted)return Promise.resolve(k);const c=`${n}\0${s}`,m=N.get(c);return B(m===void 0?H(e,n,c,s):m,a)};return(e,{scope:t,signal:n})=>{if(e.length>u.maxHtmlBytes)return Promise.resolve(j);let s;try{s=f(e)}catch(i){return Promise.resolve(F(i))}if(!(s instanceof Promise))return A(e,s,t,n);const a=s;return new Promise(i=>{const c=()=>i(k);n.addEventListener("abort",c,{once:!0}),a.then(m=>{n.removeEventListener("abort",c),i(A(e,m,t,n))},m=>{n.removeEventListener("abort",c),i(F(m))})})}};exports.DEFAULT_SANITIZER_CACHE_BYTES=X;exports.DEFAULT_SANITIZER_DEADLINE_MS=J;exports.DEFAULT_SANITIZER_MAX_HTML_BYTES=Y;exports.DEFAULT_SANITIZER_WORKER_HEAP_MB=z;exports.MAX_HTML_BYTES=Q;exports.MIN_HTML_NODE_BUDGET=O;exports.SANITIZER_QUEUED_READERS=V;exports.assertAdmissionCoversPanels=W;exports.assertPoolLimit=L;exports.createHtmlSanitizerService=be;exports.createWorkerPoolCore=ce;exports.defaultSanitizerJobsPerScope=G;exports.htmlNodeBudgetOf=q;exports.isReplyTo=K;exports.readLimit=R;exports.resolveBrowserSanitizerLimits=ie;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ExplorerAssetFile, ExplorerByteRange } from "./ports.cjs";
|
|
2
|
+
export declare const ASSET_CONTENT_SECURITY_POLICIES: Readonly<{
|
|
3
|
+
readonly sandboxed: string;
|
|
4
|
+
readonly mediaDocument: string;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const browserMediaType: (contentType: string) => string | null;
|
|
7
|
+
export declare const EXPLORER_ASSET_CACHE_HEADERS: Readonly<Record<string, string>>;
|
|
8
|
+
export type AssetDelivery = {
|
|
9
|
+
readonly contentType: string;
|
|
10
|
+
readonly inline: boolean;
|
|
11
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
12
|
+
};
|
|
13
|
+
export declare const assetDelivery: (contentType: string, name: string) => AssetDelivery;
|
|
14
|
+
export declare const PLAIN_TEXT_ENCODING_WINDOW: number;
|
|
15
|
+
export declare const plainTextContentTypeOf: (encoding: string) => string;
|
|
16
|
+
export declare const plainTextHeadersOf: (name: string) => Readonly<Record<string, string>>;
|
|
17
|
+
export declare const plainTextValidatorOf: (version: string, legacyEncoding: string | null) => string;
|
|
18
|
+
export type ByteRangeSelection = {
|
|
19
|
+
readonly kind: "whole";
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: "partial";
|
|
22
|
+
readonly range: ExplorerByteRange;
|
|
23
|
+
} | {
|
|
24
|
+
readonly kind: "unsatisfiable";
|
|
25
|
+
};
|
|
26
|
+
export declare const selectByteRange: (headers: Headers, size: number, etag: string, maxRangeBytes: number | null) => ByteRangeSelection;
|
|
27
|
+
export type AssetPlan = {
|
|
28
|
+
readonly kind: "respond";
|
|
29
|
+
readonly response: Response;
|
|
30
|
+
} | {
|
|
31
|
+
readonly kind: "stream";
|
|
32
|
+
readonly status: 200 | 206;
|
|
33
|
+
readonly headers: Headers;
|
|
34
|
+
readonly range: ExplorerByteRange | null;
|
|
35
|
+
readonly length: number | null;
|
|
36
|
+
};
|
|
37
|
+
type RespondPlan = Extract<AssetPlan, {
|
|
38
|
+
readonly kind: "respond";
|
|
39
|
+
}>;
|
|
40
|
+
export type AssetBodySelection = {
|
|
41
|
+
readonly head: boolean;
|
|
42
|
+
readonly status: 200 | 206;
|
|
43
|
+
readonly headers: Headers;
|
|
44
|
+
readonly range: ExplorerByteRange | null;
|
|
45
|
+
readonly length: number | null;
|
|
46
|
+
};
|
|
47
|
+
export declare const assetPlanOf: (request: Request, file: ExplorerAssetFile, authHeaders: Headers, maxRangeBytes: number | null) => AssetPlan;
|
|
48
|
+
export declare const assetResponse: (request: Request, file: ExplorerAssetFile, authHeaders: Headers, maxRangeBytes: number | null) => Promise<Response>;
|
|
49
|
+
export declare const beginningTextEncodingOf: (file: ExplorerAssetFile, legacyEncoding: string | null) => Promise<string>;
|
|
50
|
+
export declare const plainTextPlanOf: (request: Request, file: ExplorerAssetFile, authHeaders: Headers, legacyEncoding: string | null, maxRangeBytes: number | null) => RespondPlan | {
|
|
51
|
+
readonly kind: "needs-encoding";
|
|
52
|
+
readonly selection: AssetBodySelection;
|
|
53
|
+
};
|
|
54
|
+
export declare const plainTextStreamPlanOf: (selection: AssetBodySelection, encoding: string) => AssetPlan;
|
|
55
|
+
export declare const plainTextResponse: (request: Request, file: ExplorerAssetFile, authHeaders: Headers, legacyEncoding: string | null, maxRangeBytes: number | null) => Promise<Response>;
|
|
56
|
+
export declare const workbookValidatorOf: (version: string) => string;
|
|
57
|
+
export declare const workbookResponse: (request: Request, file: ExplorerAssetFile, authHeaders: Headers) => Promise<Response>;
|
|
58
|
+
export declare const EXPLORER_ASSET_REDIRECT_HEADERS: Readonly<Record<string, string>>;
|
|
59
|
+
export declare const assetRedirectResponse: (url: string, authHeaders: Headers) => Response;
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ExplorerAssetFile, ExplorerByteRange } from "./ports.js";
|
|
2
|
+
export declare const ASSET_CONTENT_SECURITY_POLICIES: Readonly<{
|
|
3
|
+
readonly sandboxed: string;
|
|
4
|
+
readonly mediaDocument: string;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const browserMediaType: (contentType: string) => string | null;
|
|
7
|
+
export declare const EXPLORER_ASSET_CACHE_HEADERS: Readonly<Record<string, string>>;
|
|
8
|
+
export type AssetDelivery = {
|
|
9
|
+
readonly contentType: string;
|
|
10
|
+
readonly inline: boolean;
|
|
11
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
12
|
+
};
|
|
13
|
+
export declare const assetDelivery: (contentType: string, name: string) => AssetDelivery;
|
|
14
|
+
export declare const PLAIN_TEXT_ENCODING_WINDOW: number;
|
|
15
|
+
export declare const plainTextContentTypeOf: (encoding: string) => string;
|
|
16
|
+
export declare const plainTextHeadersOf: (name: string) => Readonly<Record<string, string>>;
|
|
17
|
+
export declare const plainTextValidatorOf: (version: string, legacyEncoding: string | null) => string;
|
|
18
|
+
export type ByteRangeSelection = {
|
|
19
|
+
readonly kind: "whole";
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: "partial";
|
|
22
|
+
readonly range: ExplorerByteRange;
|
|
23
|
+
} | {
|
|
24
|
+
readonly kind: "unsatisfiable";
|
|
25
|
+
};
|
|
26
|
+
export declare const selectByteRange: (headers: Headers, size: number, etag: string, maxRangeBytes: number | null) => ByteRangeSelection;
|
|
27
|
+
export type AssetPlan = {
|
|
28
|
+
readonly kind: "respond";
|
|
29
|
+
readonly response: Response;
|
|
30
|
+
} | {
|
|
31
|
+
readonly kind: "stream";
|
|
32
|
+
readonly status: 200 | 206;
|
|
33
|
+
readonly headers: Headers;
|
|
34
|
+
readonly range: ExplorerByteRange | null;
|
|
35
|
+
readonly length: number | null;
|
|
36
|
+
};
|
|
37
|
+
type RespondPlan = Extract<AssetPlan, {
|
|
38
|
+
readonly kind: "respond";
|
|
39
|
+
}>;
|
|
40
|
+
export type AssetBodySelection = {
|
|
41
|
+
readonly head: boolean;
|
|
42
|
+
readonly status: 200 | 206;
|
|
43
|
+
readonly headers: Headers;
|
|
44
|
+
readonly range: ExplorerByteRange | null;
|
|
45
|
+
readonly length: number | null;
|
|
46
|
+
};
|
|
47
|
+
export declare const assetPlanOf: (request: Request, file: ExplorerAssetFile, authHeaders: Headers, maxRangeBytes: number | null) => AssetPlan;
|
|
48
|
+
export declare const assetResponse: (request: Request, file: ExplorerAssetFile, authHeaders: Headers, maxRangeBytes: number | null) => Promise<Response>;
|
|
49
|
+
export declare const beginningTextEncodingOf: (file: ExplorerAssetFile, legacyEncoding: string | null) => Promise<string>;
|
|
50
|
+
export declare const plainTextPlanOf: (request: Request, file: ExplorerAssetFile, authHeaders: Headers, legacyEncoding: string | null, maxRangeBytes: number | null) => RespondPlan | {
|
|
51
|
+
readonly kind: "needs-encoding";
|
|
52
|
+
readonly selection: AssetBodySelection;
|
|
53
|
+
};
|
|
54
|
+
export declare const plainTextStreamPlanOf: (selection: AssetBodySelection, encoding: string) => AssetPlan;
|
|
55
|
+
export declare const plainTextResponse: (request: Request, file: ExplorerAssetFile, authHeaders: Headers, legacyEncoding: string | null, maxRangeBytes: number | null) => Promise<Response>;
|
|
56
|
+
export declare const workbookValidatorOf: (version: string) => string;
|
|
57
|
+
export declare const workbookResponse: (request: Request, file: ExplorerAssetFile, authHeaders: Headers) => Promise<Response>;
|
|
58
|
+
export declare const EXPLORER_ASSET_REDIRECT_HEADERS: Readonly<Record<string, string>>;
|
|
59
|
+
export declare const assetRedirectResponse: (url: string, authHeaders: Headers) => Response;
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PageFetchPort } from "@aiquants/markdown/link-cards";
|
|
2
|
+
import { ExplorerServerPlatform } from "../platform.cjs";
|
|
3
|
+
import { HtmlMeasure } from "../sanitizerService.cjs";
|
|
4
|
+
export type BrowserExplorerPlatformOptions = {
|
|
5
|
+
readonly principalKey: string;
|
|
6
|
+
readonly scope: string;
|
|
7
|
+
readonly window: Window & typeof globalThis;
|
|
8
|
+
readonly nestingGuardWorkerUrl: URL;
|
|
9
|
+
readonly pageFetch: PageFetchPort | null;
|
|
10
|
+
};
|
|
11
|
+
export declare const browserHtmlMeasureOf: (subtle: SubtleCrypto) => ((html: string) => Promise<HtmlMeasure>);
|
|
12
|
+
export declare const createBrowserExplorerPlatform: (options: BrowserExplorerPlatformOptions) => ExplorerServerPlatform;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PageFetchPort } from "@aiquants/markdown/link-cards";
|
|
2
|
+
import { ExplorerServerPlatform } from "../platform.js";
|
|
3
|
+
import { HtmlMeasure } from "../sanitizerService.js";
|
|
4
|
+
export type BrowserExplorerPlatformOptions = {
|
|
5
|
+
readonly principalKey: string;
|
|
6
|
+
readonly scope: string;
|
|
7
|
+
readonly window: Window & typeof globalThis;
|
|
8
|
+
readonly nestingGuardWorkerUrl: URL;
|
|
9
|
+
readonly pageFetch: PageFetchPort | null;
|
|
10
|
+
};
|
|
11
|
+
export declare const browserHtmlMeasureOf: (subtle: SubtleCrypto) => ((html: string) => Promise<HtmlMeasure>);
|
|
12
|
+
export declare const createBrowserExplorerPlatform: (options: BrowserExplorerPlatformOptions) => ExplorerServerPlatform;
|
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
import { HeadersFunction } from "react-router";
|
|
2
1
|
import { MarkdownExplorerServer, MarkdownExplorerServerConfig } from "./ports.cjs";
|
|
3
|
-
export declare const DEFAULT_DEFERRED_TIMEOUT_MS = 4000;
|
|
4
|
-
export declare const DEFAULT_TREE_CACHE: Readonly<{
|
|
5
|
-
ttlMs: 300000;
|
|
6
|
-
maxEntries: 64;
|
|
7
|
-
maxBytes: number;
|
|
8
|
-
}>;
|
|
9
|
-
export declare const MIN_SCOPE_SECRET_LENGTH = 32;
|
|
10
|
-
export declare const EXPLORER_DATA_RESPONSE_HEADERS: Readonly<Record<string, string>>;
|
|
11
|
-
export declare const carryLoaderHeaders: HeadersFunction;
|
|
12
2
|
export declare const createMarkdownExplorer: <P>(serverConfig: MarkdownExplorerServerConfig<P>) => MarkdownExplorerServer;
|
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
import { HeadersFunction } from "react-router";
|
|
2
1
|
import { MarkdownExplorerServer, MarkdownExplorerServerConfig } from "./ports.js";
|
|
3
|
-
export declare const DEFAULT_DEFERRED_TIMEOUT_MS = 4000;
|
|
4
|
-
export declare const DEFAULT_TREE_CACHE: Readonly<{
|
|
5
|
-
ttlMs: 300000;
|
|
6
|
-
maxEntries: 64;
|
|
7
|
-
maxBytes: number;
|
|
8
|
-
}>;
|
|
9
|
-
export declare const MIN_SCOPE_SECRET_LENGTH = 32;
|
|
10
|
-
export declare const EXPLORER_DATA_RESPONSE_HEADERS: Readonly<Record<string, string>>;
|
|
11
|
-
export declare const carryLoaderHeaders: HeadersFunction;
|
|
12
2
|
export declare const createMarkdownExplorer: <P>(serverConfig: MarkdownExplorerServerConfig<P>) => MarkdownExplorerServer;
|
package/dist/server/errors.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ExplorerFailure, ExplorerFailureReason } from "../core/contracts.cjs";
|
|
2
|
-
export type ExplorerOperation = "authenticate" | "tree" | "children" | "ancestors" | "reveal" | "document" | "text" | "edit" | "save" | "preview" | "revisions" | "revision" | "notices" | "refresh" | "boundary" | "asset";
|
|
2
|
+
export type ExplorerOperation = "authenticate" | "tree" | "children" | "ancestors" | "reveal" | "document" | "text" | "edit" | "save" | "preview" | "revisions" | "revision" | "notices" | "refresh" | "boundary" | "asset" | "issue-id" | "resolve-id";
|
|
3
3
|
export type ExplorerLogDetail = {
|
|
4
4
|
readonly operation: ExplorerOperation;
|
|
5
5
|
readonly sourceId?: string;
|
package/dist/server/errors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ExplorerFailure, ExplorerFailureReason } from "../core/contracts.js";
|
|
2
|
-
export type ExplorerOperation = "authenticate" | "tree" | "children" | "ancestors" | "reveal" | "document" | "text" | "edit" | "save" | "preview" | "revisions" | "revision" | "notices" | "refresh" | "boundary" | "asset";
|
|
2
|
+
export type ExplorerOperation = "authenticate" | "tree" | "children" | "ancestors" | "reveal" | "document" | "text" | "edit" | "save" | "preview" | "revisions" | "revision" | "notices" | "refresh" | "boundary" | "asset" | "issue-id" | "resolve-id";
|
|
3
3
|
export type ExplorerLogDetail = {
|
|
4
4
|
readonly operation: ExplorerOperation;
|
|
5
5
|
readonly sourceId?: string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { HeadersFunction } from "react-router";
|
|
2
|
+
import { ExplorerServerPlatform } from "./platform.cjs";
|
|
3
|
+
import { ExplorerServerCoreConfig, MarkdownExplorerServer } from "./ports.cjs";
|
|
4
|
+
export declare const DEFAULT_DEFERRED_TIMEOUT_MS = 4000;
|
|
5
|
+
export declare const DEFAULT_TREE_CACHE: Readonly<{
|
|
6
|
+
ttlMs: 300000;
|
|
7
|
+
maxEntries: 64;
|
|
8
|
+
maxBytes: number;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const EXPLORER_DATA_RESPONSE_HEADERS: Readonly<Record<string, string>>;
|
|
11
|
+
export declare const carryLoaderHeaders: HeadersFunction;
|
|
12
|
+
export declare const createExplorerServer: <P>(serverConfig: ExplorerServerCoreConfig<P>, platform: ExplorerServerPlatform) => MarkdownExplorerServer;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { HeadersFunction } from "react-router";
|
|
2
|
+
import { ExplorerServerPlatform } from "./platform.js";
|
|
3
|
+
import { ExplorerServerCoreConfig, MarkdownExplorerServer } from "./ports.js";
|
|
4
|
+
export declare const DEFAULT_DEFERRED_TIMEOUT_MS = 4000;
|
|
5
|
+
export declare const DEFAULT_TREE_CACHE: Readonly<{
|
|
6
|
+
ttlMs: 300000;
|
|
7
|
+
maxEntries: 64;
|
|
8
|
+
maxBytes: number;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const EXPLORER_DATA_RESPONSE_HEADERS: Readonly<Record<string, string>>;
|
|
11
|
+
export declare const carryLoaderHeaders: HeadersFunction;
|
|
12
|
+
export declare const createExplorerServer: <P>(serverConfig: ExplorerServerCoreConfig<P>, platform: ExplorerServerPlatform) => MarkdownExplorerServer;
|
|
@@ -12,6 +12,7 @@ export type FileSystemSourceOptions = {
|
|
|
12
12
|
readonly label: string;
|
|
13
13
|
readonly root: string;
|
|
14
14
|
readonly pathPrefix: string;
|
|
15
|
+
readonly lang: string;
|
|
15
16
|
readonly parse: (markdown: string, docPath: string) => Promise<{
|
|
16
17
|
readonly htmlContent: string;
|
|
17
18
|
readonly headings: readonly ExplorerHeading[];
|
|
@@ -12,6 +12,7 @@ export type FileSystemSourceOptions = {
|
|
|
12
12
|
readonly label: string;
|
|
13
13
|
readonly root: string;
|
|
14
14
|
readonly pathPrefix: string;
|
|
15
|
+
readonly lang: string;
|
|
15
16
|
readonly parse: (markdown: string, docPath: string) => Promise<{
|
|
16
17
|
readonly htmlContent: string;
|
|
17
18
|
readonly headings: readonly ExplorerHeading[];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { MarkdownExplorerServer } from "./ports.cjs";
|
|
2
|
+
export declare const createInProcessDataFetch: (server: Pick<MarkdownExplorerServer, "dataLoader" | "dataAction">, { dataPath, pageAddress }: {
|
|
3
|
+
readonly dataPath: string;
|
|
4
|
+
readonly pageAddress: string;
|
|
5
|
+
}) => typeof fetch;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { MarkdownExplorerServer } from "./ports.js";
|
|
2
|
+
export declare const createInProcessDataFetch: (server: Pick<MarkdownExplorerServer, "dataLoader" | "dataAction">, { dataPath, pageAddress }: {
|
|
3
|
+
readonly dataPath: string;
|
|
4
|
+
readonly pageAddress: string;
|
|
5
|
+
}) => typeof fetch;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LinkCardHandler } from "@aiquants/markdown/link-cards";
|
|
2
|
+
import { ExplorerOwnUrls } from "../core/ownUrls.cjs";
|
|
3
|
+
import { SanitizerLimitsInput } from "./sanitizerOptions.cjs";
|
|
4
|
+
import { HtmlSanitizerService } from "./sanitizerService.cjs";
|
|
5
|
+
export type ExplorerServerPlatform = {
|
|
6
|
+
readonly prepareScope: () => (principalKey: string) => string;
|
|
7
|
+
readonly createSanitizer: (setup: SanitizerSetup) => HtmlSanitizerService;
|
|
8
|
+
readonly createLinkCardHandler: (options: {
|
|
9
|
+
readonly authorize: (request: Request) => Promise<boolean>;
|
|
10
|
+
}) => LinkCardHandler;
|
|
11
|
+
};
|
|
12
|
+
export type SanitizerSetup = {
|
|
13
|
+
readonly options: SanitizerLimitsInput | undefined;
|
|
14
|
+
readonly maxPanels: number;
|
|
15
|
+
readonly iframeHosts: readonly string[];
|
|
16
|
+
readonly dataPath: string;
|
|
17
|
+
readonly ownUrls: ExplorerOwnUrls;
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LinkCardHandler } from "@aiquants/markdown/link-cards";
|
|
2
|
+
import { ExplorerOwnUrls } from "../core/ownUrls.js";
|
|
3
|
+
import { SanitizerLimitsInput } from "./sanitizerOptions.js";
|
|
4
|
+
import { HtmlSanitizerService } from "./sanitizerService.js";
|
|
5
|
+
export type ExplorerServerPlatform = {
|
|
6
|
+
readonly prepareScope: () => (principalKey: string) => string;
|
|
7
|
+
readonly createSanitizer: (setup: SanitizerSetup) => HtmlSanitizerService;
|
|
8
|
+
readonly createLinkCardHandler: (options: {
|
|
9
|
+
readonly authorize: (request: Request) => Promise<boolean>;
|
|
10
|
+
}) => LinkCardHandler;
|
|
11
|
+
};
|
|
12
|
+
export type SanitizerSetup = {
|
|
13
|
+
readonly options: SanitizerLimitsInput | undefined;
|
|
14
|
+
readonly maxPanels: number;
|
|
15
|
+
readonly iframeHosts: readonly string[];
|
|
16
|
+
readonly dataPath: string;
|
|
17
|
+
readonly ownUrls: ExplorerOwnUrls;
|
|
18
|
+
};
|