@silurus/ooxml 0.75.5 → 0.76.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/README.md +66 -28
- package/dist/bounded-raw-part-cache-C6ro6Ezf.js +254 -0
- package/dist/{find-cursor-Dc5iM6s7.js → canvas-viewer-mechanics-CwVSOYke.js} +192 -64
- package/dist/{document-pull-client-BcNYhoAG.js → document-pull-client-DQNen8c4.js} +3620 -3597
- package/dist/docx-DYRguRRi.js +1301 -0
- package/dist/docx.mjs +4 -6
- package/dist/docx_parser_bg.wasm +0 -0
- package/dist/index.mjs +3 -3
- package/dist/{line-distribute-B8sqT8kC.js → line-distribute-C1r2zvji.js} +141 -141
- package/dist/{line-metrics-D9gqQWHl.js → line-metrics-BdCACYlq.js} +4026 -1170
- package/dist/math.mjs +1 -1
- package/dist/node.mjs +779 -465
- package/dist/pptx-B-EJp83T.js +1735 -0
- package/dist/pptx.mjs +5 -7
- package/dist/pptx_parser_bg.wasm +0 -0
- package/dist/{render-CalC7GX4.js → render-CLcpSi0m.js} +11 -18
- package/dist/render-worker-host-Bkf1jUcW.js +27 -0
- package/dist/render-worker-host-CKOmXdyr.js +27 -0
- package/dist/render-worker-host-DWLyqwI3.js +27 -0
- package/dist/resource-measurement-E_S_iau4.js +119 -0
- package/dist/session-B4Y54cbT.js +730 -0
- package/dist/{renderer-B9R6F_QY.js → slide-pull-client-WCuYCjio.js} +973 -820
- package/dist/types/docx.d.ts +1181 -3994
- package/dist/types/index.d.ts +2733 -8171
- package/dist/types/math.d.ts +8 -33
- package/dist/types/node.d.ts +1852 -4433
- package/dist/types/pptx.d.ts +1030 -3678
- package/dist/types/xlsx.d.ts +1291 -3262
- package/dist/worksheet-pull-client-YzjJMOns.js +455 -0
- package/dist/xlsx-BBmmZNQn.js +6362 -0
- package/dist/xlsx.mjs +5 -7
- package/dist/xlsx_parser_bg.wasm +0 -0
- package/package.json +14 -7
- package/dist/bounded-raw-part-cache-BTfZD_Sz.js +0 -1248
- package/dist/docx-DjF8FgoP.js +0 -1274
- package/dist/duotone-bitmap-by-path-CWsSJkJu.js +0 -28
- package/dist/hyperlink-D85FexTa.js +0 -27
- package/dist/pptx-C17xP8AV.js +0 -1705
- package/dist/pptx-Dl8tOSmP.js +0 -822
- package/dist/preload-BEouWnlI.js +0 -132
- package/dist/render-worker-host-BG3a7brz.js +0 -27
- package/dist/render-worker-host-CsB-dPJv.js +0 -27
- package/dist/render-worker-host-Cyv5Hkbh.js +0 -27
- package/dist/resource-measurement-6aReN3K0.js +0 -93
- package/dist/slide-pull-client-D_T0AIoX.js +0 -175
- package/dist/svg-image-by-path-C1M3N2pT.js +0 -1623
- package/dist/worksheet-pull-worker-DCei8u-4.js +0 -347
- package/dist/xlsx-BaH9irS0.js +0 -5515
- /package/dist/{highlight-rect-cCvVU-MW.js → highlight-rect-CAkCWJ37.js} +0 -0
- /package/dist/{mathjax-Dqo857oC.js → mathjax-CMjda8Ip.js} +0 -0
- /package/dist/{transfer-3QEJrsJa.js → transfer-DCu4c2BL.js} +0 -0
- /package/dist/{visible-index-CKvgpUrf.js → visible-index-CgyJLAS_.js} +0 -0
|
@@ -1,1248 +0,0 @@
|
|
|
1
|
-
import { f as e } from "./svg-image-by-path-C1M3N2pT.js";
|
|
2
|
-
//#region packages/core/src/errors/ooxml-error.ts
|
|
3
|
-
var t = class e extends Error {
|
|
4
|
-
code;
|
|
5
|
-
constructor(t, n) {
|
|
6
|
-
super(n), this.name = "OoxmlError", this.code = t, Object.setPrototypeOf(this, e.prototype);
|
|
7
|
-
}
|
|
8
|
-
}, n = class e extends Error {
|
|
9
|
-
code = "ooxml-resource-limit";
|
|
10
|
-
details;
|
|
11
|
-
constructor(t, n) {
|
|
12
|
-
super(t), this.name = "OoxmlResourceLimitError";
|
|
13
|
-
let r = n.violation, i = Object.freeze({
|
|
14
|
-
format: r.format,
|
|
15
|
-
operation: r.operation,
|
|
16
|
-
resource: r.resource,
|
|
17
|
-
metric: r.metric,
|
|
18
|
-
...r.part === void 0 ? {} : { part: r.part },
|
|
19
|
-
limit: r.limit,
|
|
20
|
-
observed: r.observed,
|
|
21
|
-
configurable: r.configurable,
|
|
22
|
-
usage: Object.freeze({
|
|
23
|
-
archiveEntryCount: r.usage.archiveEntryCount,
|
|
24
|
-
declaredInflatedBytes: r.usage.declaredInflatedBytes,
|
|
25
|
-
...r.usage.largestInflatedEntryBytes === void 0 ? {} : { largestInflatedEntryBytes: r.usage.largestInflatedEntryBytes },
|
|
26
|
-
distinctInflatedBytes: r.usage.distinctInflatedBytes,
|
|
27
|
-
operationInflatedBytes: r.usage.operationInflatedBytes
|
|
28
|
-
})
|
|
29
|
-
});
|
|
30
|
-
this.details = Object.freeze({
|
|
31
|
-
stage: n.stage,
|
|
32
|
-
violation: i
|
|
33
|
-
}), Object.setPrototypeOf(this, e.prototype);
|
|
34
|
-
}
|
|
35
|
-
}, r = "https://fonts.googleapis.com/css2?family=Noto+Naskh+Arabic:wght@400;700&display=swap", i = "https://fonts.googleapis.com/css2?family=Noto+Sans+Arabic:wght@400;700&display=swap", a = {
|
|
36
|
-
calibri: {
|
|
37
|
-
url: "https://fonts.googleapis.com/css2?family=Carlito:ital,wght@0,400;0,700;1,400;1,700&display=swap",
|
|
38
|
-
loadFamily: "Carlito"
|
|
39
|
-
},
|
|
40
|
-
"calibri light": {
|
|
41
|
-
url: "https://fonts.googleapis.com/css2?family=Carlito:ital,wght@0,400;0,700;1,400;1,700&display=swap",
|
|
42
|
-
loadFamily: "Carlito"
|
|
43
|
-
},
|
|
44
|
-
cambria: {
|
|
45
|
-
url: "https://fonts.googleapis.com/css2?family=Caladea:ital,wght@0,400;0,700;1,400;1,700&display=swap",
|
|
46
|
-
loadFamily: "Caladea"
|
|
47
|
-
},
|
|
48
|
-
"cambria math": {
|
|
49
|
-
url: "https://fonts.googleapis.com/css2?family=Caladea:ital,wght@0,400;0,700;1,400;1,700&display=swap",
|
|
50
|
-
loadFamily: "Caladea"
|
|
51
|
-
},
|
|
52
|
-
"nunito sans": { url: "https://fonts.googleapis.com/css2?family=Nunito+Sans:ital,wght@0,400;0,700;1,400;1,700&display=swap" },
|
|
53
|
-
nunito: { url: "https://fonts.googleapis.com/css2?family=Nunito:ital,wght@0,400;0,700;1,400;1,700&display=swap" },
|
|
54
|
-
"open sans": { url: "https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,400;0,700;1,400;1,700&display=swap" },
|
|
55
|
-
roboto: { url: "https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700;1,400;1,700&display=swap" },
|
|
56
|
-
lato: { url: "https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,400;0,700;1,400;1,700&display=swap" },
|
|
57
|
-
montserrat: { url: "https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,400;0,700;1,400;1,700&display=swap" },
|
|
58
|
-
poppins: { url: "https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,400;0,700;1,400;1,700&display=swap" },
|
|
59
|
-
raleway: { url: "https://fonts.googleapis.com/css2?family=Raleway:ital,wght@0,400;0,700;1,400;1,700&display=swap" },
|
|
60
|
-
"playfair display": { url: "https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,700;1,400;1,700&display=swap" },
|
|
61
|
-
ubuntu: { url: "https://fonts.googleapis.com/css2?family=Ubuntu:ital,wght@0,400;0,700;1,400;1,700&display=swap" },
|
|
62
|
-
"sakkal majalla": {
|
|
63
|
-
url: r,
|
|
64
|
-
loadFamily: "Noto Naskh Arabic"
|
|
65
|
-
},
|
|
66
|
-
"traditional arabic": {
|
|
67
|
-
url: r,
|
|
68
|
-
loadFamily: "Noto Naskh Arabic"
|
|
69
|
-
},
|
|
70
|
-
"simplified arabic": {
|
|
71
|
-
url: r,
|
|
72
|
-
loadFamily: "Noto Naskh Arabic"
|
|
73
|
-
},
|
|
74
|
-
"arabic typesetting": {
|
|
75
|
-
url: r,
|
|
76
|
-
loadFamily: "Noto Naskh Arabic"
|
|
77
|
-
},
|
|
78
|
-
"univers next arabic": {
|
|
79
|
-
url: i,
|
|
80
|
-
loadFamily: "Noto Sans Arabic"
|
|
81
|
-
},
|
|
82
|
-
"noto naskh arabic": {
|
|
83
|
-
url: r,
|
|
84
|
-
loadFamily: "Noto Naskh Arabic"
|
|
85
|
-
},
|
|
86
|
-
"noto sans arabic": {
|
|
87
|
-
url: i,
|
|
88
|
-
loadFamily: "Noto Sans Arabic"
|
|
89
|
-
}
|
|
90
|
-
}, o = class e extends Error {
|
|
91
|
-
code = "parser-crashed";
|
|
92
|
-
constructor(t) {
|
|
93
|
-
super(t), this.name = "WasmTrapError", Object.setPrototypeOf(this, e.prototype);
|
|
94
|
-
}
|
|
95
|
-
}, s = "ooxml-insufficient-credit", c = "OOXML_INSUFFICIENT_CREDIT:";
|
|
96
|
-
function l(e) {
|
|
97
|
-
return typeof e == "number" && Number.isSafeInteger(e) && e > 0;
|
|
98
|
-
}
|
|
99
|
-
function u(e) {
|
|
100
|
-
if (!e || typeof e != "object" || Array.isArray(e)) return !1;
|
|
101
|
-
let t = e;
|
|
102
|
-
return l(t.requiredBytes) && l(t.offeredBytes) && t.requiredBytes > t.offeredBytes;
|
|
103
|
-
}
|
|
104
|
-
var d = class e extends RangeError {
|
|
105
|
-
code = s;
|
|
106
|
-
requiredBytes;
|
|
107
|
-
offeredBytes;
|
|
108
|
-
constructor(t) {
|
|
109
|
-
super(`Pull unit requires ${t.requiredBytes} bytes but credit is ${t.offeredBytes}`), this.name = "PullSessionInsufficientCreditError", this.requiredBytes = t.requiredBytes, this.offeredBytes = t.offeredBytes, Object.setPrototypeOf(this, e.prototype);
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
function f(e) {
|
|
113
|
-
if (e instanceof d) return e;
|
|
114
|
-
let t = e instanceof Error ? e.message : String(e);
|
|
115
|
-
if (!t.startsWith(c)) return;
|
|
116
|
-
let n;
|
|
117
|
-
try {
|
|
118
|
-
n = JSON.parse(t.slice(26));
|
|
119
|
-
} catch {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if (!n || typeof n != "object" || Array.isArray(n)) return;
|
|
123
|
-
let r = n;
|
|
124
|
-
if (!(r.code !== "ooxml-insufficient-credit" || !u(r))) return new d(r);
|
|
125
|
-
}
|
|
126
|
-
function ee(e, t, n) {
|
|
127
|
-
let r = f(e);
|
|
128
|
-
if (!(!r || r.offeredBytes !== t || r.requiredBytes > n)) return r;
|
|
129
|
-
}
|
|
130
|
-
function te(e, t, n) {
|
|
131
|
-
if (p(e)) return e.offeredBytes === t && e.requiredBytes <= n ? e.requiredBytes : void 0;
|
|
132
|
-
}
|
|
133
|
-
function p(e) {
|
|
134
|
-
return e instanceof d || !!e && typeof e == "object" && e.code === "ooxml-insufficient-credit" && u(e);
|
|
135
|
-
}
|
|
136
|
-
//#endregion
|
|
137
|
-
//#region packages/core/src/worker/error-wire.ts
|
|
138
|
-
var m = "OOXML_RESOURCE_LIMIT:", h = 128, ne = 256, re = 4096;
|
|
139
|
-
function g(e) {
|
|
140
|
-
return typeof e == "number" && Number.isSafeInteger(e) && e >= 0;
|
|
141
|
-
}
|
|
142
|
-
function _(e) {
|
|
143
|
-
if (!e || typeof e != "object" || Array.isArray(e)) return !1;
|
|
144
|
-
let t = e;
|
|
145
|
-
return g(t.archiveEntryCount) && g(t.declaredInflatedBytes) && (t.largestInflatedEntryBytes === void 0 || g(t.largestInflatedEntryBytes)) && g(t.distinctInflatedBytes) && g(t.operationInflatedBytes);
|
|
146
|
-
}
|
|
147
|
-
function ie(e) {
|
|
148
|
-
let t;
|
|
149
|
-
try {
|
|
150
|
-
t = JSON.parse(new TextDecoder().decode(e));
|
|
151
|
-
} catch {
|
|
152
|
-
throw TypeError("OOXML resource usage checkpoint is not valid JSON");
|
|
153
|
-
}
|
|
154
|
-
if (!_(t)) throw TypeError("OOXML resource usage checkpoint is invalid");
|
|
155
|
-
return t;
|
|
156
|
-
}
|
|
157
|
-
function ae(e) {
|
|
158
|
-
return e === "docx" || e === "xlsx" || e === "pptx";
|
|
159
|
-
}
|
|
160
|
-
function oe(e) {
|
|
161
|
-
return e === "container" || e === "decompression" || e === "parsing" || e === "serialization" || e === "layout" || e === "rendering" || e === "worker";
|
|
162
|
-
}
|
|
163
|
-
function v(e, t) {
|
|
164
|
-
return typeof e == "string" && e.length > 0 && e.length <= t && !/[\u0000-\u001f\u007f]/u.test(e);
|
|
165
|
-
}
|
|
166
|
-
function y(e) {
|
|
167
|
-
return v(e, h) && /^[a-z0-9][a-z0-9-]*$/u.test(e);
|
|
168
|
-
}
|
|
169
|
-
function se(e) {
|
|
170
|
-
return !v(e, re) || e.startsWith("/") || e.startsWith("\\") || e.includes("\\") || e.includes("?") || e.includes("#") || e.includes("://") || /^[a-z]:/iu.test(e) ? !1 : e.split("/").every((e) => e !== "" && e !== "." && e !== "..");
|
|
171
|
-
}
|
|
172
|
-
var b = new Map([
|
|
173
|
-
["archive-entry:declared-inflated-bytes", {
|
|
174
|
-
stage: "container",
|
|
175
|
-
part: "required"
|
|
176
|
-
}],
|
|
177
|
-
["archive-entry:actual-inflated-bytes", {
|
|
178
|
-
stage: "decompression",
|
|
179
|
-
part: "required"
|
|
180
|
-
}],
|
|
181
|
-
["archive:entry-count", {
|
|
182
|
-
stage: "container",
|
|
183
|
-
part: "forbidden",
|
|
184
|
-
configurable: !1
|
|
185
|
-
}],
|
|
186
|
-
["archive:central-directory-bytes", {
|
|
187
|
-
stage: "container",
|
|
188
|
-
part: "forbidden",
|
|
189
|
-
configurable: !1
|
|
190
|
-
}],
|
|
191
|
-
["archive:distinct-inflated-bytes", {
|
|
192
|
-
stage: "decompression",
|
|
193
|
-
part: "required"
|
|
194
|
-
}],
|
|
195
|
-
["xml-event:bytes", {
|
|
196
|
-
stage: "parsing",
|
|
197
|
-
part: "optional",
|
|
198
|
-
configurable: !1
|
|
199
|
-
}],
|
|
200
|
-
["xml-context:bytes", {
|
|
201
|
-
stage: "parsing",
|
|
202
|
-
part: "optional",
|
|
203
|
-
configurable: !1
|
|
204
|
-
}],
|
|
205
|
-
["xml-tree:depth", {
|
|
206
|
-
stage: "parsing",
|
|
207
|
-
part: "optional",
|
|
208
|
-
configurable: !1
|
|
209
|
-
}],
|
|
210
|
-
["worksheet-row:projected-bytes", {
|
|
211
|
-
stage: "parsing",
|
|
212
|
-
part: "optional",
|
|
213
|
-
configurable: !1
|
|
214
|
-
}],
|
|
215
|
-
["worksheet-shell:projected-bytes", {
|
|
216
|
-
stage: "parsing",
|
|
217
|
-
part: "optional",
|
|
218
|
-
configurable: !1
|
|
219
|
-
}]
|
|
220
|
-
]), ce = new Set([...b.keys()].map((e) => e.slice(0, e.indexOf(":")))), le = new Set([...b.keys()].map((e) => e.slice(e.indexOf(":") + 1)));
|
|
221
|
-
function ue(e) {
|
|
222
|
-
if (!e || typeof e != "object" || Array.isArray(e)) return !1;
|
|
223
|
-
let t = e;
|
|
224
|
-
return !ae(t.format) || !v(t.operation, ne) || !y(t.resource) || !y(t.metric) || !g(t.limit) || !g(t.observed) || typeof t.configurable != "boolean" || !_(t.usage) ? !1 : !("part" in t) || se(t.part);
|
|
225
|
-
}
|
|
226
|
-
function x(e) {
|
|
227
|
-
if (!e || typeof e != "object" || Array.isArray(e)) return !1;
|
|
228
|
-
let t = e;
|
|
229
|
-
if (!oe(t.stage) || !ue(t.violation)) return !1;
|
|
230
|
-
let n = t.violation, r = b.get(`${n.resource}:${n.metric}`);
|
|
231
|
-
return r ? t.stage !== r.stage || r.configurable === !1 && n.configurable !== !1 ? !1 : r.part === "required" ? n.part !== void 0 : r.part === "forbidden" ? n.part === void 0 : !0 : !(ce.has(n.resource) && le.has(n.metric));
|
|
232
|
-
}
|
|
233
|
-
function de(e) {
|
|
234
|
-
return {
|
|
235
|
-
archiveEntryCount: e.archiveEntryCount,
|
|
236
|
-
declaredInflatedBytes: e.declaredInflatedBytes,
|
|
237
|
-
...e.largestInflatedEntryBytes === void 0 ? {} : { largestInflatedEntryBytes: e.largestInflatedEntryBytes },
|
|
238
|
-
distinctInflatedBytes: e.distinctInflatedBytes,
|
|
239
|
-
operationInflatedBytes: e.operationInflatedBytes
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
function fe(e) {
|
|
243
|
-
if (!x(e)) return;
|
|
244
|
-
let t = e.violation, n = {
|
|
245
|
-
stage: e.stage,
|
|
246
|
-
violation: {
|
|
247
|
-
format: t.format,
|
|
248
|
-
operation: t.operation,
|
|
249
|
-
resource: t.resource,
|
|
250
|
-
metric: t.metric,
|
|
251
|
-
...t.part === void 0 ? {} : { part: t.part },
|
|
252
|
-
limit: t.limit,
|
|
253
|
-
observed: t.observed,
|
|
254
|
-
configurable: t.configurable,
|
|
255
|
-
usage: de(t.usage)
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
return x(n) ? n : void 0;
|
|
259
|
-
}
|
|
260
|
-
function S(e) {
|
|
261
|
-
let t = e.violation;
|
|
262
|
-
return `OOXML resource limit exceeded${t.part ? ` for ${t.part}` : ""}: ${t.metric} ${t.observed} > ${t.limit}`;
|
|
263
|
-
}
|
|
264
|
-
function C(e) {
|
|
265
|
-
let t = e instanceof Error ? e.message : String(e);
|
|
266
|
-
if (!t.startsWith(m)) return;
|
|
267
|
-
let r;
|
|
268
|
-
try {
|
|
269
|
-
r = JSON.parse(t.slice(21));
|
|
270
|
-
} catch {
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
if (!r || typeof r != "object") return;
|
|
274
|
-
let i = r;
|
|
275
|
-
if (!(i.code !== "ooxml-resource-limit" || !x(i.details))) return new n(S(i.details), i.details);
|
|
276
|
-
}
|
|
277
|
-
function pe(r) {
|
|
278
|
-
if (r instanceof e) return {
|
|
279
|
-
message: r.message,
|
|
280
|
-
errorName: r.name,
|
|
281
|
-
code: r.code,
|
|
282
|
-
decodedImage: {
|
|
283
|
-
metric: r.metric,
|
|
284
|
-
limit: r.limit,
|
|
285
|
-
observed: r.observed
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
let i = f(r);
|
|
289
|
-
if (i) return {
|
|
290
|
-
message: i.message,
|
|
291
|
-
errorName: i.name,
|
|
292
|
-
code: i.code,
|
|
293
|
-
insufficientCredit: {
|
|
294
|
-
requiredBytes: i.requiredBytes,
|
|
295
|
-
offeredBytes: i.offeredBytes
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
let a = r instanceof t || r instanceof n ? r : C(r);
|
|
299
|
-
if (a instanceof n) {
|
|
300
|
-
let e = fe(a.details);
|
|
301
|
-
return e ? {
|
|
302
|
-
message: typeof a.message == "string" ? a.message : S(e),
|
|
303
|
-
errorName: "OoxmlResourceLimitError",
|
|
304
|
-
code: "ooxml-resource-limit",
|
|
305
|
-
resourceLimit: e
|
|
306
|
-
} : {
|
|
307
|
-
message: "Invalid OOXML resource-limit error payload",
|
|
308
|
-
errorName: "Error"
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
if (a instanceof t) return {
|
|
312
|
-
message: typeof a.message == "string" ? a.message : String(a.message),
|
|
313
|
-
errorName: v(a.name, h) ? a.name : "OoxmlError",
|
|
314
|
-
...y(a.code) ? { code: a.code } : {}
|
|
315
|
-
};
|
|
316
|
-
let o = r instanceof Error ? r.message : String(r);
|
|
317
|
-
if (typeof o == "string" && o.startsWith(m)) return {
|
|
318
|
-
message: "Invalid OOXML resource-limit payload",
|
|
319
|
-
errorName: "Error"
|
|
320
|
-
};
|
|
321
|
-
let s = r instanceof Error ? r : Error(o), c = s;
|
|
322
|
-
return {
|
|
323
|
-
message: typeof s.message == "string" ? s.message : String(s.message),
|
|
324
|
-
errorName: v(s.name, h) ? s.name : "Error",
|
|
325
|
-
...typeof c.code == "string" ? { code: c.code } : {}
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
function w(e) {
|
|
329
|
-
try {
|
|
330
|
-
return pe(e);
|
|
331
|
-
} catch {
|
|
332
|
-
return {
|
|
333
|
-
message: "Worker operation failed with an unreadable error",
|
|
334
|
-
errorName: "Error"
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
var me = new Set([
|
|
339
|
-
"encrypted",
|
|
340
|
-
"invalid-password",
|
|
341
|
-
"unsupported-encryption",
|
|
342
|
-
"legacy-binary-format",
|
|
343
|
-
"not-ooxml"
|
|
344
|
-
]);
|
|
345
|
-
function T(r) {
|
|
346
|
-
if (r.code === "ooxml-decoded-image-limit" && r.decodedImage && (r.decodedImage.metric === "image-pixels" || r.decodedImage.metric === "active-decoded-bytes") && g(r.decodedImage.limit) && g(r.decodedImage.observed) && r.decodedImage.observed > r.decodedImage.limit) return new e(r.decodedImage.metric, r.decodedImage.limit, r.decodedImage.observed);
|
|
347
|
-
if (r.code === "ooxml-insufficient-credit" && u(r.insufficientCredit)) return new d(r.insufficientCredit);
|
|
348
|
-
if (r.code === "ooxml-resource-limit" && x(r.resourceLimit)) return new n(r.message, r.resourceLimit);
|
|
349
|
-
if (r.code && me.has(r.code)) return new t(r.code, r.message);
|
|
350
|
-
let i = r.errorName === "TypeError" ? TypeError(r.message) : r.errorName === "RangeError" ? RangeError(r.message) : Error(r.message);
|
|
351
|
-
return r.errorName && (i.name = r.errorName), r.code !== void 0 && Object.assign(i, { code: r.code }), i;
|
|
352
|
-
}
|
|
353
|
-
//#endregion
|
|
354
|
-
//#region packages/core/src/worker/resource-policy.generated.ts
|
|
355
|
-
var he = 134217728, ge = 268435456, _e = 67108864, ve = 67108864, ye = 67108864, E = 134217728, D = 134217728, O = 1e5, k = 25e4, A = 33554432, j = 67108864, M = 2e5, N = 5e5, P = 25e4, F = Object.freeze({
|
|
356
|
-
maxArchiveEntryBytes: he,
|
|
357
|
-
maxTotalInflatedBytes: ge
|
|
358
|
-
});
|
|
359
|
-
function I(e, t, n) {
|
|
360
|
-
if (t === void 0) return n;
|
|
361
|
-
if (t === null) return null;
|
|
362
|
-
if (!Number.isSafeInteger(t) || t <= 0) throw RangeError(`resourceLimits.${e} must be null or a positive safe integer number of bytes`);
|
|
363
|
-
return t;
|
|
364
|
-
}
|
|
365
|
-
function be(e) {
|
|
366
|
-
if (!(e === void 0 || !(e > 0))) {
|
|
367
|
-
if (!Number.isSafeInteger(e)) throw RangeError("maxZipEntryBytes must be a positive safe integer number of bytes");
|
|
368
|
-
return e;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
function L(e) {
|
|
372
|
-
let t = e.resourceLimits;
|
|
373
|
-
if (t !== void 0 && (typeof t != "object" || !t || Array.isArray(t))) throw TypeError("resourceLimits must be an object when provided");
|
|
374
|
-
let n = be(e.maxZipEntryBytes), r = t?.maxArchiveEntryBytes;
|
|
375
|
-
if (n !== void 0 && r !== void 0 && n !== r) throw RangeError("maxZipEntryBytes conflicts with resourceLimits.maxArchiveEntryBytes");
|
|
376
|
-
return Object.freeze({
|
|
377
|
-
maxArchiveEntryBytes: I("maxArchiveEntryBytes", r === void 0 ? n : r, F.maxArchiveEntryBytes),
|
|
378
|
-
maxTotalInflatedBytes: I("maxTotalInflatedBytes", t?.maxTotalInflatedBytes, F.maxTotalInflatedBytes)
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
function xe(e) {
|
|
382
|
-
if (e.debug !== void 0 && typeof e.debug != "boolean") throw TypeError("debug must be a boolean when provided");
|
|
383
|
-
if (e.onResourceMetrics !== void 0 && typeof e.onResourceMetrics != "function") throw TypeError("onResourceMetrics must be a function when provided");
|
|
384
|
-
return Object.freeze({
|
|
385
|
-
policy: L(e),
|
|
386
|
-
debug: e.debug ?? !1,
|
|
387
|
-
...e.onResourceMetrics ? { onResourceMetrics: e.onResourceMetrics } : {}
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
function Se(e) {
|
|
391
|
-
return [e.maxArchiveEntryBytes === null ? 0n : BigInt(e.maxArchiveEntryBytes), e.maxTotalInflatedBytes === null ? 0n : BigInt(e.maxTotalInflatedBytes)];
|
|
392
|
-
}
|
|
393
|
-
//#endregion
|
|
394
|
-
//#region packages/core/src/internal/console-tui.ts
|
|
395
|
-
var Ce = [
|
|
396
|
-
"font-family: \"SFMono-Regular\", Menlo, Monaco, Consolas, monospace",
|
|
397
|
-
"font-size: 12px",
|
|
398
|
-
"line-height: 1.35",
|
|
399
|
-
"font-variant-ligatures: none",
|
|
400
|
-
"letter-spacing: 0",
|
|
401
|
-
"white-space: pre"
|
|
402
|
-
].join(";");
|
|
403
|
-
function we(e) {
|
|
404
|
-
if (Te()) {
|
|
405
|
-
console.log(`%c${e}`, Ce);
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
console.log(e);
|
|
409
|
-
}
|
|
410
|
-
function Te() {
|
|
411
|
-
return typeof window < "u" && globalThis.process?.release?.name !== "node";
|
|
412
|
-
}
|
|
413
|
-
//#endregion
|
|
414
|
-
//#region packages/core/src/worker/resource-debug-view.ts
|
|
415
|
-
function Ee(e) {
|
|
416
|
-
let t = e.scope === "session" ? "SESSION" : "LOAD", n = e.status === "ok" ? e.scope === "session" ? "COMPLETE" : "READY" : "FAILED", r = [Oe(` OOXML ${t} ${e.format.toUpperCase()} ${n} `, 68)];
|
|
417
|
-
if (r.push(H(`mode ${e.mode.padEnd(8)} elapsed ${z(e.elapsedMs)}`, 68)), e.sourceBytes !== void 0 && r.push(H(`source ${R(e.sourceBytes)}`, 68)), r.push(V(" admission ", 68)), r.push(U("largest entry", e.usage?.largestInflatedEntryBytes, e.policy.maxArchiveEntryBytes, 68)), r.push(U("total inflated", e.usage?.distinctInflatedBytes, e.policy.maxTotalInflatedBytes, 68)), e.usage ? r.push(H(`entries ${B(e.usage.archiveEntryCount)} declared ${R(e.usage.declaredInflatedBytes)}`, 68)) : r.push(H("usage unavailable for this report", 68)), e.checkpoints.length > 0) {
|
|
418
|
-
r.push(V(" checkpoints ", 68));
|
|
419
|
-
for (let t of e.checkpoints) {
|
|
420
|
-
let e = t.usage ? R(t.usage.distinctInflatedBytes) : "—";
|
|
421
|
-
r.push(H(`${z(t.elapsedMs).padStart(8)} ${t.name.padEnd(25)} ${e.padStart(12)}`, 68));
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
if (e.outcome && Object.keys(e.outcome).length > 0 && (r.push(V(" result ", 68)), r.push(H(Object.entries(e.outcome).map(([e, t]) => `${e} ${B(t)}`).join(" "), 68))), e.error) {
|
|
425
|
-
r.push(V(" failure ", 68));
|
|
426
|
-
let t = [
|
|
427
|
-
e.error.code,
|
|
428
|
-
e.error.stage,
|
|
429
|
-
e.error.resource,
|
|
430
|
-
e.error.metric
|
|
431
|
-
].filter((e) => !!e).join(" · ");
|
|
432
|
-
r.push(H(t || "unclassified error", 68));
|
|
433
|
-
}
|
|
434
|
-
return r.push(`└${"─".repeat(68)}┘`), r.join("\n");
|
|
435
|
-
}
|
|
436
|
-
function De(e) {
|
|
437
|
-
we(Ee(e));
|
|
438
|
-
}
|
|
439
|
-
function R(e) {
|
|
440
|
-
if (!Number.isFinite(e) || e < 0) return "—";
|
|
441
|
-
let t = [
|
|
442
|
-
"B",
|
|
443
|
-
"KiB",
|
|
444
|
-
"MiB",
|
|
445
|
-
"GiB",
|
|
446
|
-
"TiB"
|
|
447
|
-
], n = e, r = 0;
|
|
448
|
-
for (; n >= 1024 && r < t.length - 1;) n /= 1024, r += 1;
|
|
449
|
-
let i = r === 0 || n >= 100 ? 0 : n >= 10 ? 1 : 2;
|
|
450
|
-
return `${n.toFixed(i)} ${t[r]}`;
|
|
451
|
-
}
|
|
452
|
-
function z(e) {
|
|
453
|
-
return e < 1e3 ? `${Math.round(e)} ms` : `${(e / 1e3).toFixed(2)} s`;
|
|
454
|
-
}
|
|
455
|
-
function B(e) {
|
|
456
|
-
return Number.isSafeInteger(e) ? e.toLocaleString("en-US") : "—";
|
|
457
|
-
}
|
|
458
|
-
function Oe(e, t) {
|
|
459
|
-
let n = e.slice(0, t);
|
|
460
|
-
return `┌${n}${"─".repeat(t - n.length)}┐`;
|
|
461
|
-
}
|
|
462
|
-
function V(e, t) {
|
|
463
|
-
let n = e.slice(0, t);
|
|
464
|
-
return `├${n}${"─".repeat(t - n.length)}┤`;
|
|
465
|
-
}
|
|
466
|
-
function H(e, t) {
|
|
467
|
-
let n = e.slice(0, t - 2);
|
|
468
|
-
return `│ ${n}${" ".repeat(t - n.length - 2)} │`;
|
|
469
|
-
}
|
|
470
|
-
function U(e, t, n, r) {
|
|
471
|
-
let i = t === void 0 || n === null || n <= 0 ? 0 : Math.min(1, t / n), a = Math.round(i * 16), o = `${"█".repeat(a)}${"░".repeat(16 - a)}`, s = `${t === void 0 ? "—" : R(t)} / ${n === null ? "public off" : R(n)}`;
|
|
472
|
-
return H(`${e.padEnd(14)} ${o} ${s}`, r);
|
|
473
|
-
}
|
|
474
|
-
//#endregion
|
|
475
|
-
//#region packages/core/src/worker/resource-debug.ts
|
|
476
|
-
var W = 1e3;
|
|
477
|
-
async function ke(e, t) {
|
|
478
|
-
e.observeUsage(await t(W));
|
|
479
|
-
let n = e.current();
|
|
480
|
-
if (!n) throw Error("OOXML resource metrics are not ready");
|
|
481
|
-
return n;
|
|
482
|
-
}
|
|
483
|
-
var Ae = class {
|
|
484
|
-
now;
|
|
485
|
-
startedAt;
|
|
486
|
-
policy;
|
|
487
|
-
checkpoints = [];
|
|
488
|
-
sourceBytes;
|
|
489
|
-
lastUsage;
|
|
490
|
-
mode;
|
|
491
|
-
finished = !1;
|
|
492
|
-
terminalStatus;
|
|
493
|
-
terminalError;
|
|
494
|
-
terminalOutcome;
|
|
495
|
-
terminalElapsedMs;
|
|
496
|
-
constructor(e) {
|
|
497
|
-
this.options = e, this.now = e.now ?? Me, this.startedAt = this.now(), this.policy = Object.freeze({
|
|
498
|
-
maxArchiveEntryBytes: e.policy.maxArchiveEntryBytes,
|
|
499
|
-
maxTotalInflatedBytes: e.policy.maxTotalInflatedBytes
|
|
500
|
-
}), this.mode = e.mode;
|
|
501
|
-
}
|
|
502
|
-
setMode(e) {
|
|
503
|
-
!this.options.enabled || this.finished || (this.mode = e);
|
|
504
|
-
}
|
|
505
|
-
setSourceBytes(e) {
|
|
506
|
-
this.options.enabled && (!Number.isSafeInteger(e) || e < 0 || (this.sourceBytes = e));
|
|
507
|
-
}
|
|
508
|
-
checkpoint(e, t) {
|
|
509
|
-
if (!this.options.enabled || this.finished) return;
|
|
510
|
-
t && (this.lastUsage = K(t));
|
|
511
|
-
let n = this.lastUsage;
|
|
512
|
-
this.checkpoints.push(Object.freeze({
|
|
513
|
-
name: Pe(e),
|
|
514
|
-
elapsedMs: q(this.startedAt, this.now()),
|
|
515
|
-
...n ? { usage: n } : {}
|
|
516
|
-
}));
|
|
517
|
-
}
|
|
518
|
-
observeUsage(e) {
|
|
519
|
-
!this.options.enabled || !e || (this.lastUsage = K(e));
|
|
520
|
-
}
|
|
521
|
-
current() {
|
|
522
|
-
if (!(!this.options.enabled || !this.terminalStatus)) return this.report(this.terminalStatus, this.terminalError, this.terminalOutcome);
|
|
523
|
-
}
|
|
524
|
-
succeed(e) {
|
|
525
|
-
return this.finish("ok", void 0, e);
|
|
526
|
-
}
|
|
527
|
-
fail(e) {
|
|
528
|
-
return this.finish("error", e);
|
|
529
|
-
}
|
|
530
|
-
finish(e, t, n) {
|
|
531
|
-
if (!this.options.enabled || this.finished) return;
|
|
532
|
-
this.finished = !0, this.terminalStatus = e, this.terminalError = t, this.terminalOutcome = n, this.terminalElapsedMs = q(this.startedAt, this.now());
|
|
533
|
-
let r = this.report(e, t, n);
|
|
534
|
-
return this.options.onMetrics && G(this.options.onMetrics, r), (this.options.emitToConsole ?? this.options.onMetrics === void 0) && G(De, r), r;
|
|
535
|
-
}
|
|
536
|
-
report(e, t, n) {
|
|
537
|
-
let r = Ne(t) ?? this.lastUsage;
|
|
538
|
-
return Object.freeze({
|
|
539
|
-
schemaVersion: 1,
|
|
540
|
-
scope: this.options.scope ?? "load",
|
|
541
|
-
format: this.options.format,
|
|
542
|
-
mode: this.mode,
|
|
543
|
-
status: e,
|
|
544
|
-
...this.sourceBytes === void 0 ? {} : { sourceBytes: this.sourceBytes },
|
|
545
|
-
elapsedMs: this.terminalElapsedMs ?? q(this.startedAt, this.now()),
|
|
546
|
-
policy: this.policy,
|
|
547
|
-
...r ? { usage: r } : {},
|
|
548
|
-
checkpoints: Object.freeze([...this.checkpoints]),
|
|
549
|
-
...n ? { outcome: Fe(n) } : {},
|
|
550
|
-
...e === "error" ? { error: J(t) } : {}
|
|
551
|
-
});
|
|
552
|
-
}
|
|
553
|
-
};
|
|
554
|
-
function G(e, t) {
|
|
555
|
-
try {
|
|
556
|
-
let n = e(t);
|
|
557
|
-
je(n) && Promise.resolve(n).catch(() => void 0);
|
|
558
|
-
} catch {}
|
|
559
|
-
}
|
|
560
|
-
function je(e) {
|
|
561
|
-
return (typeof e == "object" && !!e || typeof e == "function") && typeof e.then == "function";
|
|
562
|
-
}
|
|
563
|
-
function Me() {
|
|
564
|
-
return typeof performance > "u" ? Date.now() : performance.now();
|
|
565
|
-
}
|
|
566
|
-
function K(e) {
|
|
567
|
-
return Object.freeze({
|
|
568
|
-
archiveEntryCount: e.archiveEntryCount,
|
|
569
|
-
declaredInflatedBytes: e.declaredInflatedBytes,
|
|
570
|
-
...e.largestInflatedEntryBytes === void 0 ? {} : { largestInflatedEntryBytes: e.largestInflatedEntryBytes },
|
|
571
|
-
distinctInflatedBytes: e.distinctInflatedBytes,
|
|
572
|
-
operationInflatedBytes: e.operationInflatedBytes
|
|
573
|
-
});
|
|
574
|
-
}
|
|
575
|
-
function Ne(e) {
|
|
576
|
-
try {
|
|
577
|
-
return e instanceof n ? K(e.details.violation.usage) : void 0;
|
|
578
|
-
} catch {
|
|
579
|
-
return;
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
function q(e, t) {
|
|
583
|
-
return Math.max(0, Math.round((t - e) * 10) / 10);
|
|
584
|
-
}
|
|
585
|
-
function Pe(e) {
|
|
586
|
-
return e.replace(/[^a-z0-9 -]/giu, "").trim().slice(0, 32) || "checkpoint";
|
|
587
|
-
}
|
|
588
|
-
function Fe(e) {
|
|
589
|
-
return Object.freeze(Object.fromEntries(Object.entries(e).filter(([e, t]) => /^[a-z][a-z0-9-]{0,31}$/u.test(e) && Number.isSafeInteger(t) && t >= 0)));
|
|
590
|
-
}
|
|
591
|
-
function J(r) {
|
|
592
|
-
try {
|
|
593
|
-
if (r instanceof n) {
|
|
594
|
-
let e = r.details.violation;
|
|
595
|
-
return Object.freeze({
|
|
596
|
-
code: r.code,
|
|
597
|
-
stage: r.details.stage,
|
|
598
|
-
resource: e.resource,
|
|
599
|
-
metric: e.metric
|
|
600
|
-
});
|
|
601
|
-
}
|
|
602
|
-
if (r instanceof t || r instanceof e) return Object.freeze({ code: r.code });
|
|
603
|
-
if (r instanceof o || typeof r == "object" && r && r.code === "parser-crashed") return Object.freeze({ code: "parser-crashed" });
|
|
604
|
-
} catch {}
|
|
605
|
-
return Object.freeze({});
|
|
606
|
-
}
|
|
607
|
-
var Y = "ooxml-pull-v1";
|
|
608
|
-
function X(e, t) {
|
|
609
|
-
if (!Number.isSafeInteger(e) || e <= 0) throw RangeError(`${t} must be a positive safe integer`);
|
|
610
|
-
}
|
|
611
|
-
function Z(e) {
|
|
612
|
-
if (!(typeof e == "string" && e.length > 0 || typeof e == "number" && Number.isSafeInteger(e) && e > 0)) throw RangeError("session id must be a non-empty string or positive safe integer");
|
|
613
|
-
}
|
|
614
|
-
var Ie = class {
|
|
615
|
-
bridge;
|
|
616
|
-
options;
|
|
617
|
-
sequence = 0;
|
|
618
|
-
pulling = !1;
|
|
619
|
-
outstanding = !1;
|
|
620
|
-
ending = !1;
|
|
621
|
-
completed = !1;
|
|
622
|
-
lifecyclePromise;
|
|
623
|
-
usage;
|
|
624
|
-
orphanedRequestIds = /* @__PURE__ */ new Set();
|
|
625
|
-
transferDisposers = /* @__PURE__ */ new Set();
|
|
626
|
-
constructor(e, t) {
|
|
627
|
-
Z(t.sessionId), X(t.operationId, "operation id"), X(t.generation, "generation"), X(t.maxByteCredit, "max byte credit"), t.cancelGraceMs !== void 0 && X(t.cancelGraceMs, "cancel grace"), this.bridge = e, this.options = t;
|
|
628
|
-
}
|
|
629
|
-
async pull(e, t) {
|
|
630
|
-
if (this.validateCredit(e), this.ending || this.completed) throw Error("pull session is closed");
|
|
631
|
-
if (this.pulling) throw Error("a pull request is already in flight");
|
|
632
|
-
if (this.outstanding) throw Error("acknowledge the current chunk before the next pull");
|
|
633
|
-
this.pulling = !0;
|
|
634
|
-
let n = this.sequence;
|
|
635
|
-
try {
|
|
636
|
-
let r = await this.request((t) => ({
|
|
637
|
-
protocol: Y,
|
|
638
|
-
kind: "pull",
|
|
639
|
-
...this.identity(),
|
|
640
|
-
requestId: t,
|
|
641
|
-
sequence: n,
|
|
642
|
-
byteCredit: e
|
|
643
|
-
}), t);
|
|
644
|
-
if (this.validateResponseIdentity(r), r.usage && (this.usage = r.usage), r.kind === "error") throw T(r.error);
|
|
645
|
-
if (r.kind !== "chunk") throw Error(`expected chunk response, received ${r.kind}`);
|
|
646
|
-
if (this.ending) throw this.disposePayload(r.payload), Error("pull session is closed");
|
|
647
|
-
try {
|
|
648
|
-
this.validateChunk(r, n, e);
|
|
649
|
-
} catch (e) {
|
|
650
|
-
throw this.disposePayload(r.payload), e;
|
|
651
|
-
}
|
|
652
|
-
return this.outstanding = !0, this.makeChunk(r);
|
|
653
|
-
} catch (e) {
|
|
654
|
-
throw !p(e) && !this.ending && !this.completed && this.cancel("protocol-error").catch(() => void 0), e;
|
|
655
|
-
} finally {
|
|
656
|
-
this.pulling = !1;
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
cancel(e = "closed", t) {
|
|
660
|
-
return this.lifecyclePromise ? this.lifecyclePromise : (this.ending = !0, this.disposeAllTransferred(), this.lifecyclePromise = this.lifecycleControl(this.control("cancel", t, (t) => ({
|
|
661
|
-
protocol: Y,
|
|
662
|
-
kind: "cancel",
|
|
663
|
-
...this.identity(),
|
|
664
|
-
requestId: t,
|
|
665
|
-
reason: e
|
|
666
|
-
}))), this.lifecyclePromise);
|
|
667
|
-
}
|
|
668
|
-
close(e) {
|
|
669
|
-
return this.lifecyclePromise ? this.lifecyclePromise : (this.ending = !0, this.disposeAllTransferred(), this.lifecyclePromise = this.lifecycleControl(this.control("close", e, (e) => ({
|
|
670
|
-
protocol: Y,
|
|
671
|
-
kind: "close",
|
|
672
|
-
...this.identity(),
|
|
673
|
-
requestId: e
|
|
674
|
-
}))), this.lifecyclePromise);
|
|
675
|
-
}
|
|
676
|
-
get usageCheckpoint() {
|
|
677
|
-
return this.usage;
|
|
678
|
-
}
|
|
679
|
-
makeChunk(e) {
|
|
680
|
-
let t = !1, n, r, i = () => {
|
|
681
|
-
t || (t = !0, this.transferDisposers.delete(i), this.disposePayload(e.payload));
|
|
682
|
-
};
|
|
683
|
-
return this.transferDisposers.add(i), {
|
|
684
|
-
done: e.done,
|
|
685
|
-
sequence: e.sequence,
|
|
686
|
-
byteLength: e.byteLength,
|
|
687
|
-
payload: e.payload,
|
|
688
|
-
leaseId: e.leaseId,
|
|
689
|
-
usage: e.usage,
|
|
690
|
-
disposeTransferred: i,
|
|
691
|
-
ack: (t) => n || (this.ending ? Promise.resolve() : (n = this.control("ack", t, (t) => ({
|
|
692
|
-
protocol: Y,
|
|
693
|
-
kind: "ack",
|
|
694
|
-
...this.identity(),
|
|
695
|
-
requestId: t,
|
|
696
|
-
sequence: e.sequence
|
|
697
|
-
})).then(() => {
|
|
698
|
-
this.outstanding = !1, this.sequence++, e.done && (this.completed = !0);
|
|
699
|
-
}).catch((e) => {
|
|
700
|
-
throw this.ending || this.cancel("request-error").catch(() => void 0), e;
|
|
701
|
-
}), n)),
|
|
702
|
-
release: (t) => r || (e.leaseId === void 0 || this.ending ? Promise.resolve() : (r = this.control("release", t, (t) => ({
|
|
703
|
-
protocol: Y,
|
|
704
|
-
kind: "release",
|
|
705
|
-
...this.identity(),
|
|
706
|
-
requestId: t,
|
|
707
|
-
leaseId: e.leaseId
|
|
708
|
-
})).catch((e) => {
|
|
709
|
-
throw this.ending || this.cancel("request-error").catch(() => void 0), e;
|
|
710
|
-
}), r))
|
|
711
|
-
};
|
|
712
|
-
}
|
|
713
|
-
async control(e, t, n) {
|
|
714
|
-
let r = await this.request(n, t, e !== "cancel" && e !== "close");
|
|
715
|
-
if (this.validateResponseIdentity(r), r.usage && (this.usage = r.usage), r.kind === "error") {
|
|
716
|
-
if (r.error.code === "ooxml-stale-lifecycle" && (e === "cancel" || e === "close")) {
|
|
717
|
-
this.forgetLifecycleOrphans();
|
|
718
|
-
return;
|
|
719
|
-
}
|
|
720
|
-
throw T(r.error);
|
|
721
|
-
}
|
|
722
|
-
if (r.kind !== "accepted" || r.command !== e) throw Error(`expected ${e} acceptance`);
|
|
723
|
-
(e === "cancel" || e === "close") && this.forgetLifecycleOrphans();
|
|
724
|
-
}
|
|
725
|
-
request(e, t, n = !0) {
|
|
726
|
-
return this.bridge.request(e, void 0, {
|
|
727
|
-
timeoutMs: n ? t?.timeoutMs ?? this.options.timeoutMs : !1,
|
|
728
|
-
signal: t?.signal,
|
|
729
|
-
onOrphanedResponse: (e) => {
|
|
730
|
-
e.kind === "chunk" && this.disposePayload(e.payload);
|
|
731
|
-
},
|
|
732
|
-
onCancel: (e, n) => {
|
|
733
|
-
this.orphanedRequestIds.add(e);
|
|
734
|
-
try {
|
|
735
|
-
t?.onCancel?.(e, n);
|
|
736
|
-
} finally {
|
|
737
|
-
!this.ending && !this.completed && this.cancel(n).catch(() => void 0);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
});
|
|
741
|
-
}
|
|
742
|
-
identity() {
|
|
743
|
-
return {
|
|
744
|
-
sessionId: this.options.sessionId,
|
|
745
|
-
operationId: this.options.operationId,
|
|
746
|
-
generation: this.options.generation
|
|
747
|
-
};
|
|
748
|
-
}
|
|
749
|
-
validateResponseIdentity(e) {
|
|
750
|
-
if (e.protocol !== "ooxml-pull-v1" || e.sessionId !== this.options.sessionId || e.operationId !== this.options.operationId || e.generation !== this.options.generation) throw e.kind === "chunk" && this.disposePayload(e.payload), Error("stale or mismatched pull session response");
|
|
751
|
-
}
|
|
752
|
-
validateCredit(e) {
|
|
753
|
-
if (X(e, "byte credit"), e > this.options.maxByteCredit) throw RangeError(`byte credit exceeds session maximum ${this.options.maxByteCredit}`);
|
|
754
|
-
}
|
|
755
|
-
validateChunk(e, t, n) {
|
|
756
|
-
if (e.sequence !== t) throw Error("pull response sequence mismatch");
|
|
757
|
-
if (!Number.isSafeInteger(e.byteLength) || e.byteLength < 0) throw RangeError("chunk byte length must be a non-negative safe integer");
|
|
758
|
-
if (e.byteLength > n) throw RangeError("chunk exceeds byte credit");
|
|
759
|
-
e.leaseId !== void 0 && X(e.leaseId, "lease id");
|
|
760
|
-
}
|
|
761
|
-
disposeAllTransferred() {
|
|
762
|
-
for (let e of [...this.transferDisposers]) e();
|
|
763
|
-
}
|
|
764
|
-
lifecycleControl(e) {
|
|
765
|
-
let t = this.options.cancelGraceMs ?? 1e3, n, r = new Promise((e, r) => {
|
|
766
|
-
n = setTimeout(() => {
|
|
767
|
-
this.bridge.terminate(), r(/* @__PURE__ */ Error(`worker did not accept lifecycle command within ${t}ms`));
|
|
768
|
-
}, t);
|
|
769
|
-
});
|
|
770
|
-
return Promise.race([e, r]).catch((e) => {
|
|
771
|
-
throw this.bridge.terminate(), e;
|
|
772
|
-
}).finally(() => {
|
|
773
|
-
n !== void 0 && clearTimeout(n);
|
|
774
|
-
});
|
|
775
|
-
}
|
|
776
|
-
forgetLifecycleOrphans() {
|
|
777
|
-
this.bridge.forgetOrphaned(this.orphanedRequestIds), this.orphanedRequestIds.clear();
|
|
778
|
-
}
|
|
779
|
-
disposePayload(e) {
|
|
780
|
-
try {
|
|
781
|
-
this.options.disposeTransferred?.(e);
|
|
782
|
-
} catch {}
|
|
783
|
-
}
|
|
784
|
-
}, Le = class {
|
|
785
|
-
owner;
|
|
786
|
-
queue = Promise.resolve();
|
|
787
|
-
leases = /* @__PURE__ */ new Map();
|
|
788
|
-
retainedBytes = 0;
|
|
789
|
-
retainedCount = 0;
|
|
790
|
-
maxRetainedBytes;
|
|
791
|
-
maxRetainedCount;
|
|
792
|
-
cleanups = /* @__PURE__ */ new Set();
|
|
793
|
-
pendingFatalCleanups = [];
|
|
794
|
-
poisonRunning = !1;
|
|
795
|
-
fatal;
|
|
796
|
-
constructor(e) {
|
|
797
|
-
this.maxRetainedBytes = e?.maxRetainedBytes ?? 64 * 1024 * 1024, this.maxRetainedCount = e?.maxRetainedCount ?? 256, X(this.maxRetainedBytes, "max retained lease bytes"), X(this.maxRetainedCount, "max retained lease count");
|
|
798
|
-
}
|
|
799
|
-
enqueue(e) {
|
|
800
|
-
let t = this.queue.then(e, e);
|
|
801
|
-
return this.queue = t.then(() => void 0, () => void 0), t;
|
|
802
|
-
}
|
|
803
|
-
acquire(e) {
|
|
804
|
-
return this.owner === void 0 ? (this.owner = e, !0) : this.owner === e;
|
|
805
|
-
}
|
|
806
|
-
release(e) {
|
|
807
|
-
this.owner === e && (this.owner = void 0);
|
|
808
|
-
}
|
|
809
|
-
retainLease(e, t, n) {
|
|
810
|
-
if (!Number.isSafeInteger(n) || n < 0) throw RangeError("retained lease bytes are invalid");
|
|
811
|
-
let r = this.leases.get(e) ?? /* @__PURE__ */ new Map();
|
|
812
|
-
if (r.has(t)) throw Error("driver returned a duplicate lease id");
|
|
813
|
-
if (this.retainedCount + 1 > this.maxRetainedCount) throw RangeError("retained lease count exceeds limit");
|
|
814
|
-
if (this.retainedBytes + n > this.maxRetainedBytes) throw RangeError("retained lease bytes exceed limit");
|
|
815
|
-
r.set(t, n), this.leases.set(e, r), this.retainedCount++, this.retainedBytes += n;
|
|
816
|
-
}
|
|
817
|
-
releaseLease(e, t) {
|
|
818
|
-
let n = this.leases.get(e), r = n?.get(t);
|
|
819
|
-
r !== void 0 && (n?.delete(t), n?.size === 0 && this.leases.delete(e), this.retainedCount--, this.retainedBytes -= r);
|
|
820
|
-
}
|
|
821
|
-
registerCleanup(e) {
|
|
822
|
-
return this.fatal ? (this.poisonRunning ? this.pendingFatalCleanups.push(e) : this.enqueue(e).catch(() => void 0), () => void 0) : (this.cleanups.add(e), () => this.cleanups.delete(e));
|
|
823
|
-
}
|
|
824
|
-
get fatalError() {
|
|
825
|
-
return this.fatal;
|
|
826
|
-
}
|
|
827
|
-
get registeredHostCount() {
|
|
828
|
-
return this.cleanups.size;
|
|
829
|
-
}
|
|
830
|
-
async poison(e) {
|
|
831
|
-
if (this.fatal ??= e, this.poisonRunning) return this.fatal;
|
|
832
|
-
this.poisonRunning = !0, this.pendingFatalCleanups.push(...this.cleanups);
|
|
833
|
-
try {
|
|
834
|
-
let e;
|
|
835
|
-
for (; (e = this.pendingFatalCleanups.shift()) !== void 0;) await e().catch(() => void 0);
|
|
836
|
-
} finally {
|
|
837
|
-
this.poisonRunning = !1;
|
|
838
|
-
}
|
|
839
|
-
return this.fatal;
|
|
840
|
-
}
|
|
841
|
-
}, Re = class {
|
|
842
|
-
options;
|
|
843
|
-
coordinator;
|
|
844
|
-
coordinatorOwner = Symbol("pull-session-host");
|
|
845
|
-
unregisterCleanup;
|
|
846
|
-
sequence = 0;
|
|
847
|
-
unacked;
|
|
848
|
-
leases = /* @__PURE__ */ new Map();
|
|
849
|
-
activeDriverLeases = /* @__PURE__ */ new Set();
|
|
850
|
-
nextWireLeaseId;
|
|
851
|
-
cancelRequested = !1;
|
|
852
|
-
cancelComplete = !1;
|
|
853
|
-
closeRequested = !1;
|
|
854
|
-
closeComplete = !1;
|
|
855
|
-
driverCancelComplete = !1;
|
|
856
|
-
driverCloseComplete = !1;
|
|
857
|
-
completed = !1;
|
|
858
|
-
constructor(e) {
|
|
859
|
-
Z(e.sessionId), X(e.operationId, "operation id"), X(e.generation, "generation"), X(e.maxByteCredit, "max byte credit"), e.wireLeaseIdStart !== void 0 && X(e.wireLeaseIdStart, "wire lease id start"), this.options = e, this.coordinator = e.coordinator, this.nextWireLeaseId = e.wireLeaseIdStart ?? 1, this.unregisterCleanup = this.coordinator.registerCleanup(() => this.forceFatalCleanup());
|
|
860
|
-
}
|
|
861
|
-
dispatch(e, t) {
|
|
862
|
-
return this.coordinator.enqueue(async () => {
|
|
863
|
-
let n = await this.execute(e);
|
|
864
|
-
try {
|
|
865
|
-
t(n.response, n.transfer);
|
|
866
|
-
} catch (e) {
|
|
867
|
-
throw await this.rollbackFailedPost(n), e;
|
|
868
|
-
}
|
|
869
|
-
});
|
|
870
|
-
}
|
|
871
|
-
async rollbackFailedPost(e) {
|
|
872
|
-
let t = e.response;
|
|
873
|
-
if (t.kind === "chunk") {
|
|
874
|
-
let n = t.leaseId === void 0 ? void 0 : this.leases.get(t.leaseId);
|
|
875
|
-
try {
|
|
876
|
-
await this.options.driver.disposeInvalidChunk?.({
|
|
877
|
-
payload: t.payload,
|
|
878
|
-
byteLength: t.byteLength,
|
|
879
|
-
done: t.done,
|
|
880
|
-
leaseId: n?.driverLeaseId,
|
|
881
|
-
retainedBytes: n?.retainedBytes,
|
|
882
|
-
transfer: e.transfer
|
|
883
|
-
});
|
|
884
|
-
} catch {}
|
|
885
|
-
}
|
|
886
|
-
this.unacked = void 0, this.coordinator.release(this.coordinatorOwner);
|
|
887
|
-
for (let [e, t] of [...this.leases]) try {
|
|
888
|
-
await this.options.driver.releaseLease?.(t.driverLeaseId);
|
|
889
|
-
} catch {} finally {
|
|
890
|
-
this.leases.delete(e), this.activeDriverLeases.delete(t.driverLeaseId), this.coordinator.releaseLease(this.coordinatorOwner, e);
|
|
891
|
-
}
|
|
892
|
-
if (this.cancelRequested = !0, !this.driverCancelComplete) try {
|
|
893
|
-
await this.options.driver.cancel?.(), this.driverCancelComplete = !0;
|
|
894
|
-
} catch {}
|
|
895
|
-
this.unregisterCleanup();
|
|
896
|
-
}
|
|
897
|
-
async execute(e) {
|
|
898
|
-
try {
|
|
899
|
-
if (this.isStaleLifecycle(e)) {
|
|
900
|
-
let t = e.kind === "cancel" ? "cancel" : "close";
|
|
901
|
-
return this.sameOperationIdentity(e) ? { response: this.accepted(e, t, !0) } : { response: this.errorResponse(e, {
|
|
902
|
-
message: "stale lifecycle targets another session or operation",
|
|
903
|
-
errorName: "PullSessionProtocolError",
|
|
904
|
-
code: "ooxml-stale-lifecycle"
|
|
905
|
-
}) };
|
|
906
|
-
}
|
|
907
|
-
this.validateCommandIdentity(e);
|
|
908
|
-
let t = this.coordinator.fatalError;
|
|
909
|
-
if (t) return e.kind === "pull" ? { response: this.errorResponse(e, t) } : (e.kind === "cancel" ? await this.cancel() : e.kind === "close" ? await this.close() : e.kind === "release" && await this.release(e.leaseId), { response: this.accepted(e, e.kind) });
|
|
910
|
-
switch (e.kind) {
|
|
911
|
-
case "pull": return await this.pull(e);
|
|
912
|
-
case "ack": return await this.ack(e.sequence), { response: this.accepted(e, "ack") };
|
|
913
|
-
case "release": return await this.release(e.leaseId), { response: this.accepted(e, "release") };
|
|
914
|
-
case "cancel": return await this.cancel(), { response: this.accepted(e, "cancel") };
|
|
915
|
-
case "close": return await this.close(), { response: this.accepted(e, "close") };
|
|
916
|
-
}
|
|
917
|
-
} catch (t) {
|
|
918
|
-
let n = w(t);
|
|
919
|
-
return n.code === "ooxml-resource-limit" && (n = await this.coordinator.poison(n)), { response: this.errorResponse(e, n) };
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
async pull(e) {
|
|
923
|
-
if (this.closeRequested || this.cancelRequested || this.completed) throw Error("pull session is closed");
|
|
924
|
-
if (this.unacked) throw Error("previous chunk is not acknowledged");
|
|
925
|
-
if (!Number.isSafeInteger(e.sequence) || e.sequence < 0 || e.sequence !== this.sequence) throw Error("pull command sequence mismatch");
|
|
926
|
-
if (this.validateHostCredit(e.byteCredit), !this.coordinator.acquire(this.coordinatorOwner)) throw Error("another operation has an unacknowledged package chunk");
|
|
927
|
-
let t;
|
|
928
|
-
try {
|
|
929
|
-
t = await this.options.driver.pull(e.byteCredit);
|
|
930
|
-
} catch (e) {
|
|
931
|
-
throw this.coordinator.release(this.coordinatorOwner), e;
|
|
932
|
-
}
|
|
933
|
-
let n = !1, r = !1, i, a;
|
|
934
|
-
try {
|
|
935
|
-
let o = this.options.driver.measureChunk(t), s = this.arrayBufferTransferBytes(t.transfer);
|
|
936
|
-
if (o < s) throw RangeError("measured chunk bytes are below ArrayBuffer transfer bytes");
|
|
937
|
-
if (a = Math.max(o, s), t.leaseId !== void 0) {
|
|
938
|
-
if (X(t.leaseId, "lease id"), t.retainedBytes === void 0) throw Error("retained lease bytes are required");
|
|
939
|
-
if (this.activeDriverLeases.has(t.leaseId)) throw r = !0, Error("driver returned an active duplicate lease id");
|
|
940
|
-
i = this.allocateWireLeaseId(), this.coordinator.retainLease(this.coordinatorOwner, i, t.retainedBytes), this.leases.set(i, {
|
|
941
|
-
driverLeaseId: t.leaseId,
|
|
942
|
-
retainedBytes: t.retainedBytes
|
|
943
|
-
}), this.activeDriverLeases.add(t.leaseId), n = !0;
|
|
944
|
-
} else if (t.retainedBytes !== void 0) throw Error("retained lease bytes require a lease id");
|
|
945
|
-
if (!Number.isSafeInteger(a) || a < 0) throw RangeError("host chunk byte length must be a non-negative safe integer");
|
|
946
|
-
if (a > e.byteCredit) throw RangeError("host chunk exceeds byte credit");
|
|
947
|
-
} catch (e) {
|
|
948
|
-
let a;
|
|
949
|
-
try {
|
|
950
|
-
await this.options.driver.disposeInvalidChunk?.(t);
|
|
951
|
-
} catch (e) {
|
|
952
|
-
a = e;
|
|
953
|
-
}
|
|
954
|
-
if (n && i !== void 0) try {
|
|
955
|
-
await this.release(i);
|
|
956
|
-
} catch (e) {
|
|
957
|
-
a ??= e;
|
|
958
|
-
}
|
|
959
|
-
else if (t.leaseId !== void 0 && !r) try {
|
|
960
|
-
await this.options.driver.releaseLease?.(t.leaseId);
|
|
961
|
-
} catch (e) {
|
|
962
|
-
a ??= e;
|
|
963
|
-
}
|
|
964
|
-
if (r) try {
|
|
965
|
-
await this.cancel();
|
|
966
|
-
} catch (e) {
|
|
967
|
-
a ??= e;
|
|
968
|
-
}
|
|
969
|
-
throw this.coordinator.release(this.coordinatorOwner), a || e;
|
|
970
|
-
}
|
|
971
|
-
return this.unacked = {
|
|
972
|
-
sequence: this.sequence,
|
|
973
|
-
done: t.done
|
|
974
|
-
}, {
|
|
975
|
-
response: {
|
|
976
|
-
kind: "chunk",
|
|
977
|
-
protocol: Y,
|
|
978
|
-
...this.identity(),
|
|
979
|
-
requestId: e.requestId,
|
|
980
|
-
sequence: this.sequence,
|
|
981
|
-
byteLength: a,
|
|
982
|
-
done: t.done,
|
|
983
|
-
payload: t.payload,
|
|
984
|
-
leaseId: i,
|
|
985
|
-
usage: this.resourceUsage()
|
|
986
|
-
},
|
|
987
|
-
transfer: t.transfer
|
|
988
|
-
};
|
|
989
|
-
}
|
|
990
|
-
async ack(e) {
|
|
991
|
-
if (!Number.isSafeInteger(e) || e < 0) throw RangeError("invalid ack sequence");
|
|
992
|
-
if (e < this.sequence) return;
|
|
993
|
-
if (!this.unacked || e !== this.sequence) throw Error("ack sequence mismatch");
|
|
994
|
-
let t = this.unacked.done;
|
|
995
|
-
await this.options.driver.acknowledge?.(e), this.unacked = void 0, this.coordinator.release(this.coordinatorOwner), this.sequence++, t && (this.completed = !0, this.maybeUnregisterCompleted());
|
|
996
|
-
}
|
|
997
|
-
async release(e) {
|
|
998
|
-
X(e, "wire lease id");
|
|
999
|
-
let t = this.leases.get(e);
|
|
1000
|
-
t && (await this.options.driver.releaseLease?.(t.driverLeaseId), this.leases.delete(e), this.activeDriverLeases.delete(t.driverLeaseId), this.coordinator.releaseLease(this.coordinatorOwner, e), this.maybeUnregisterCompleted());
|
|
1001
|
-
}
|
|
1002
|
-
async cancel() {
|
|
1003
|
-
if (this.cancelComplete) return;
|
|
1004
|
-
this.cancelRequested = !0, this.unacked = void 0, this.coordinator.release(this.coordinatorOwner);
|
|
1005
|
-
let e;
|
|
1006
|
-
try {
|
|
1007
|
-
await this.releaseAllLeases();
|
|
1008
|
-
} catch (t) {
|
|
1009
|
-
e = t;
|
|
1010
|
-
}
|
|
1011
|
-
if (!this.driverCancelComplete) try {
|
|
1012
|
-
await this.options.driver.cancel?.(), this.driverCancelComplete = !0;
|
|
1013
|
-
} catch (t) {
|
|
1014
|
-
e ??= t;
|
|
1015
|
-
}
|
|
1016
|
-
if (e) throw e;
|
|
1017
|
-
this.cancelComplete = !0, this.unregisterCleanup();
|
|
1018
|
-
}
|
|
1019
|
-
async close() {
|
|
1020
|
-
if (this.closeComplete) return;
|
|
1021
|
-
this.closeRequested = !0, this.unacked = void 0, this.coordinator.release(this.coordinatorOwner);
|
|
1022
|
-
let e;
|
|
1023
|
-
try {
|
|
1024
|
-
await this.releaseAllLeases();
|
|
1025
|
-
} catch (t) {
|
|
1026
|
-
e = t;
|
|
1027
|
-
}
|
|
1028
|
-
if (!this.driverCloseComplete) try {
|
|
1029
|
-
await this.options.driver.close?.(), this.driverCloseComplete = !0;
|
|
1030
|
-
} catch (t) {
|
|
1031
|
-
e ??= t;
|
|
1032
|
-
}
|
|
1033
|
-
if (e) throw e;
|
|
1034
|
-
this.closeComplete = !0, this.unregisterCleanup();
|
|
1035
|
-
}
|
|
1036
|
-
async releaseAllLeases() {
|
|
1037
|
-
let e;
|
|
1038
|
-
for (let t of [...this.leases.keys()]) try {
|
|
1039
|
-
await this.release(t);
|
|
1040
|
-
} catch (t) {
|
|
1041
|
-
e ??= t;
|
|
1042
|
-
}
|
|
1043
|
-
if (e) throw e;
|
|
1044
|
-
}
|
|
1045
|
-
validateCommandIdentity(e) {
|
|
1046
|
-
if (e.protocol !== "ooxml-pull-v1" || e.sessionId !== this.options.sessionId || e.operationId !== this.options.operationId || e.generation !== this.options.generation || !Number.isSafeInteger(e.requestId) || e.requestId <= 0) throw Error("stale or mismatched pull session command");
|
|
1047
|
-
}
|
|
1048
|
-
validateHostCredit(e) {
|
|
1049
|
-
if (X(e, "byte credit"), e > this.options.maxByteCredit) throw RangeError("byte credit exceeds host maximum");
|
|
1050
|
-
}
|
|
1051
|
-
accepted(e, t, n = !1) {
|
|
1052
|
-
return {
|
|
1053
|
-
kind: "accepted",
|
|
1054
|
-
protocol: Y,
|
|
1055
|
-
...n ? {
|
|
1056
|
-
sessionId: e.sessionId,
|
|
1057
|
-
operationId: e.operationId,
|
|
1058
|
-
generation: e.generation
|
|
1059
|
-
} : this.identity(),
|
|
1060
|
-
requestId: e.requestId,
|
|
1061
|
-
command: t,
|
|
1062
|
-
usage: this.resourceUsage()
|
|
1063
|
-
};
|
|
1064
|
-
}
|
|
1065
|
-
identity() {
|
|
1066
|
-
return {
|
|
1067
|
-
sessionId: this.options.sessionId,
|
|
1068
|
-
operationId: this.options.operationId,
|
|
1069
|
-
generation: this.options.generation
|
|
1070
|
-
};
|
|
1071
|
-
}
|
|
1072
|
-
isStaleLifecycle(e) {
|
|
1073
|
-
return (e.kind === "cancel" || e.kind === "close") && e.protocol === "ooxml-pull-v1" && Number.isSafeInteger(e.requestId) && e.requestId > 0 && Number.isSafeInteger(e.generation) && e.generation > 0 && e.generation < this.options.generation;
|
|
1074
|
-
}
|
|
1075
|
-
sameOperationIdentity(e) {
|
|
1076
|
-
return e.sessionId === this.options.sessionId && e.operationId === this.options.operationId;
|
|
1077
|
-
}
|
|
1078
|
-
errorResponse(e, t) {
|
|
1079
|
-
return {
|
|
1080
|
-
kind: "error",
|
|
1081
|
-
protocol: Y,
|
|
1082
|
-
sessionId: e.sessionId,
|
|
1083
|
-
operationId: e.operationId,
|
|
1084
|
-
generation: e.generation,
|
|
1085
|
-
requestId: e.requestId,
|
|
1086
|
-
error: t,
|
|
1087
|
-
usage: this.errorResourceUsage()
|
|
1088
|
-
};
|
|
1089
|
-
}
|
|
1090
|
-
async forceFatalCleanup() {
|
|
1091
|
-
this.cancelRequested = !0, this.unacked = void 0, this.coordinator.release(this.coordinatorOwner);
|
|
1092
|
-
let e;
|
|
1093
|
-
for (let t of [...this.leases.keys()]) try {
|
|
1094
|
-
await this.release(t);
|
|
1095
|
-
} catch (t) {
|
|
1096
|
-
e ??= t;
|
|
1097
|
-
}
|
|
1098
|
-
if (!this.driverCancelComplete) try {
|
|
1099
|
-
await this.options.driver.cancel?.(), this.driverCancelComplete = !0;
|
|
1100
|
-
} catch (t) {
|
|
1101
|
-
e ??= t;
|
|
1102
|
-
}
|
|
1103
|
-
if (e) throw e;
|
|
1104
|
-
this.unregisterCleanup();
|
|
1105
|
-
}
|
|
1106
|
-
allocateWireLeaseId() {
|
|
1107
|
-
if (!Number.isSafeInteger(this.nextWireLeaseId) || this.nextWireLeaseId <= 0) throw RangeError("wire lease id space exhausted");
|
|
1108
|
-
return this.nextWireLeaseId++;
|
|
1109
|
-
}
|
|
1110
|
-
arrayBufferTransferBytes(e) {
|
|
1111
|
-
let t = 0;
|
|
1112
|
-
for (let n of e ?? []) if (n instanceof ArrayBuffer && (t += n.byteLength, !Number.isSafeInteger(t))) throw RangeError("ArrayBuffer transfer bytes overflow");
|
|
1113
|
-
return t;
|
|
1114
|
-
}
|
|
1115
|
-
maybeUnregisterCompleted() {
|
|
1116
|
-
this.completed && this.leases.size === 0 && this.unregisterCleanup();
|
|
1117
|
-
}
|
|
1118
|
-
resourceUsage() {
|
|
1119
|
-
return this.options.driver.resourceUsage?.();
|
|
1120
|
-
}
|
|
1121
|
-
errorResourceUsage() {
|
|
1122
|
-
try {
|
|
1123
|
-
return this.resourceUsage();
|
|
1124
|
-
} catch {
|
|
1125
|
-
return;
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
};
|
|
1129
|
-
//#endregion
|
|
1130
|
-
//#region packages/core/src/internal/bounded-async-lru-cache.ts
|
|
1131
|
-
function Q(e, t) {
|
|
1132
|
-
if (!Number.isSafeInteger(e) || e <= 0) throw TypeError(`${t} must be a positive safe integer`);
|
|
1133
|
-
}
|
|
1134
|
-
function ze(e) {
|
|
1135
|
-
if (!Number.isSafeInteger(e) || e < 0) throw TypeError("cache entry weight must be a non-negative safe integer");
|
|
1136
|
-
}
|
|
1137
|
-
var $ = class {
|
|
1138
|
-
#e;
|
|
1139
|
-
#t;
|
|
1140
|
-
#n;
|
|
1141
|
-
#r;
|
|
1142
|
-
#i = /* @__PURE__ */ new Map();
|
|
1143
|
-
#a = /* @__PURE__ */ new Map();
|
|
1144
|
-
#o = 0;
|
|
1145
|
-
constructor(e) {
|
|
1146
|
-
Q(e.maxEntries, "maxEntries"), Q(e.maxWeight, "maxWeight"), this.#e = e.maxEntries, this.#t = e.maxWeight, this.#n = e.measure, this.#r = e.onRemove;
|
|
1147
|
-
}
|
|
1148
|
-
get usage() {
|
|
1149
|
-
return {
|
|
1150
|
-
entries: this.#i.size,
|
|
1151
|
-
weight: this.#o,
|
|
1152
|
-
pending: this.#a.size
|
|
1153
|
-
};
|
|
1154
|
-
}
|
|
1155
|
-
has(e) {
|
|
1156
|
-
return this.#i.has(e);
|
|
1157
|
-
}
|
|
1158
|
-
get(e) {
|
|
1159
|
-
let t = this.#i.get(e);
|
|
1160
|
-
if (t !== void 0) return this.#i.delete(e), this.#i.set(e, t), t.value;
|
|
1161
|
-
}
|
|
1162
|
-
getOrLoad(e, t) {
|
|
1163
|
-
let n = this.get(e);
|
|
1164
|
-
if (n !== void 0 || this.#i.has(e)) return Promise.resolve(n);
|
|
1165
|
-
let r = this.#a.get(e);
|
|
1166
|
-
if (r !== void 0) return r.promise;
|
|
1167
|
-
let i = {}, a = Promise.resolve().then(t).then((t) => this.#c(e, i, t), (t) => {
|
|
1168
|
-
throw this.#s(e, i), t;
|
|
1169
|
-
});
|
|
1170
|
-
return this.#a.set(e, {
|
|
1171
|
-
token: i,
|
|
1172
|
-
promise: a
|
|
1173
|
-
}), a;
|
|
1174
|
-
}
|
|
1175
|
-
delete(e) {
|
|
1176
|
-
let t = this.#a.delete(e), n = this.#i.get(e);
|
|
1177
|
-
return n === void 0 ? t : (this.#i.delete(e), this.#o -= n.weight, this.#l(n.value, e, "deleted"), !0);
|
|
1178
|
-
}
|
|
1179
|
-
clear() {
|
|
1180
|
-
this.#a.clear();
|
|
1181
|
-
let e = [...this.#i];
|
|
1182
|
-
this.#i.clear(), this.#o = 0;
|
|
1183
|
-
for (let [t, n] of e) this.#l(n.value, t, "cleared");
|
|
1184
|
-
}
|
|
1185
|
-
#s(e, t) {
|
|
1186
|
-
this.#a.get(e)?.token === t && this.#a.delete(e);
|
|
1187
|
-
}
|
|
1188
|
-
#c(e, t, n) {
|
|
1189
|
-
if (this.#a.get(e)?.token !== t) return n;
|
|
1190
|
-
let r;
|
|
1191
|
-
try {
|
|
1192
|
-
r = this.#n(n), ze(r);
|
|
1193
|
-
} catch (n) {
|
|
1194
|
-
throw this.#s(e, t), n;
|
|
1195
|
-
}
|
|
1196
|
-
if (this.#a.get(e)?.token !== t || (this.#a.delete(e), r > this.#t)) return n;
|
|
1197
|
-
let i = [];
|
|
1198
|
-
for (; this.#i.size >= this.#e || r > this.#t - this.#o;) {
|
|
1199
|
-
let e = this.#i.entries().next().value;
|
|
1200
|
-
if (e === void 0) break;
|
|
1201
|
-
let [t, n] = e;
|
|
1202
|
-
this.#i.delete(t), this.#o -= n.weight, i.push([t, n]);
|
|
1203
|
-
}
|
|
1204
|
-
this.#i.set(e, {
|
|
1205
|
-
value: n,
|
|
1206
|
-
weight: r
|
|
1207
|
-
}), this.#o += r;
|
|
1208
|
-
for (let [e, t] of i) this.#l(t.value, e, "evicted");
|
|
1209
|
-
return n;
|
|
1210
|
-
}
|
|
1211
|
-
#l(e, t, n) {
|
|
1212
|
-
try {
|
|
1213
|
-
this.#r?.(e, t, n);
|
|
1214
|
-
} catch {}
|
|
1215
|
-
}
|
|
1216
|
-
}, Be = class {
|
|
1217
|
-
#e;
|
|
1218
|
-
constructor(e) {
|
|
1219
|
-
this.#e = new $({
|
|
1220
|
-
maxEntries: e.maxEntries,
|
|
1221
|
-
maxWeight: e.maxBytes,
|
|
1222
|
-
measure: (e) => e.size
|
|
1223
|
-
});
|
|
1224
|
-
}
|
|
1225
|
-
get usage() {
|
|
1226
|
-
let e = this.#e.usage;
|
|
1227
|
-
return {
|
|
1228
|
-
entries: e.entries,
|
|
1229
|
-
bytes: e.weight,
|
|
1230
|
-
pending: e.pending
|
|
1231
|
-
};
|
|
1232
|
-
}
|
|
1233
|
-
async get(e, t, n) {
|
|
1234
|
-
if (typeof e != "string" || e.length === 0) throw TypeError("raw package part path must be a non-empty string");
|
|
1235
|
-
if (typeof t != "string") throw TypeError("raw package part MIME type must be a string");
|
|
1236
|
-
let r = await this.#e.getOrLoad(e, async () => {
|
|
1237
|
-
let e = await n();
|
|
1238
|
-
if (!(e instanceof Blob)) throw TypeError("raw package part loader must return a Blob");
|
|
1239
|
-
return e;
|
|
1240
|
-
});
|
|
1241
|
-
return t === "" || r.type === t ? r : r.slice(0, r.size, t);
|
|
1242
|
-
}
|
|
1243
|
-
clear() {
|
|
1244
|
-
this.#e.clear();
|
|
1245
|
-
}
|
|
1246
|
-
};
|
|
1247
|
-
//#endregion
|
|
1248
|
-
export { te as A, j as C, C as D, T as E, t as M, n as N, w as O, A as S, ie as T, D as _, Re as a, M as b, Ae as c, L as d, Se as f, ye as g, E as h, Y as i, a as j, ee as k, ke as l, ve as m, $ as n, Le as o, _e as p, Ie as r, W as s, Be as t, xe as u, P as v, O as w, k as x, N as y };
|