@evotecit/officeimo 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +1222 -2
- package/bundles/officeimo-canopyx.js +11741 -0
- package/bundles/officeimo-canopyx.mjs +11639 -0
- package/bundles/officeimo-csv.js +1264 -0
- package/bundles/officeimo-csv.mjs +1239 -0
- package/bundles/officeimo-datatables.js +12018 -0
- package/bundles/officeimo-datatables.mjs +11915 -0
- package/bundles/officeimo-execution.js +1513 -0
- package/bundles/officeimo-execution.mjs +1489 -0
- package/bundles/officeimo-pdf.js +7009 -0
- package/bundles/officeimo-pdf.mjs +6946 -0
- package/bundles/officeimo-xlsx.js +5344 -0
- package/bundles/officeimo-xlsx.mjs +5290 -0
- package/bundles/officeimo.js +11468 -0
- package/bundles/officeimo.mjs +11369 -0
- package/dist/core/dates.d.ts +1 -0
- package/dist/core/dates.js +16 -0
- package/dist/core/errors.d.ts +12 -0
- package/dist/core/errors.js +31 -0
- package/dist/core/grouped-report.d.ts +87 -0
- package/dist/core/grouped-report.js +252 -0
- package/dist/core/index.d.ts +74 -0
- package/dist/core/index.js +37 -0
- package/dist/core/iteration.d.ts +7 -0
- package/dist/core/iteration.js +149 -0
- package/dist/core/limits.d.ts +7 -0
- package/dist/core/limits.js +56 -0
- package/dist/core/links.d.ts +5 -0
- package/dist/core/links.js +14 -0
- package/dist/core/presentation.d.ts +29 -0
- package/dist/core/presentation.js +59 -0
- package/dist/core/progress.d.ts +1 -0
- package/dist/core/progress.js +10 -0
- package/dist/core/sinks.d.ts +33 -0
- package/dist/core/sinks.js +102 -0
- package/dist/core/table.d.ts +8 -0
- package/dist/core/table.js +1 -0
- package/dist/core/value-text.d.ts +7 -0
- package/dist/core/value-text.js +13 -0
- package/dist/csv/index.d.ts +44 -0
- package/dist/csv/index.js +133 -0
- package/dist/csv/options.d.ts +1 -0
- package/dist/csv/options.js +8 -0
- package/dist/csv/structured-rows.d.ts +3 -0
- package/dist/csv/structured-rows.js +15 -0
- package/dist/execution/host.d.ts +5 -0
- package/dist/execution/host.js +164 -0
- package/dist/execution/index.d.ts +3 -0
- package/dist/execution/index.js +2 -0
- package/dist/execution/protocol.d.ts +48 -0
- package/dist/execution/protocol.js +173 -0
- package/dist/execution/types.d.ts +42 -0
- package/dist/execution/types.js +1 -0
- package/dist/execution/worker.d.ts +3 -0
- package/dist/execution/worker.js +147 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +14 -0
- package/dist/integrations/canopyx/dates.d.ts +1 -0
- package/dist/integrations/canopyx/dates.js +34 -0
- package/dist/integrations/canopyx/index.d.ts +10 -0
- package/dist/integrations/canopyx/index.js +45 -0
- package/dist/integrations/canopyx/source.d.ts +3 -0
- package/dist/integrations/canopyx/source.js +122 -0
- package/dist/integrations/canopyx/types.d.ts +83 -0
- package/dist/integrations/canopyx/types.js +1 -0
- package/dist/integrations/datatables/api.d.ts +1 -0
- package/dist/integrations/datatables/api.js +27 -0
- package/dist/integrations/datatables/headings.d.ts +1 -0
- package/dist/integrations/datatables/headings.js +65 -0
- package/dist/integrations/datatables/index.d.ts +12 -0
- package/dist/integrations/datatables/index.js +167 -0
- package/dist/integrations/datatables/snapshot.d.ts +3 -0
- package/dist/integrations/datatables/snapshot.js +206 -0
- package/dist/integrations/datatables/types.d.ts +98 -0
- package/dist/integrations/datatables/types.js +1 -0
- package/dist/integrations/options.d.ts +13 -0
- package/dist/integrations/options.js +34 -0
- package/dist/internal/capture.d.ts +4 -0
- package/dist/internal/capture.js +14 -0
- package/dist/internal/columns.d.ts +27 -0
- package/dist/internal/columns.js +1 -0
- package/dist/internal/crc32.d.ts +6 -0
- package/dist/internal/crc32.js +17 -0
- package/dist/internal/export-values.d.ts +3 -0
- package/dist/internal/export-values.js +14 -0
- package/dist/internal/rows.d.ts +6 -0
- package/dist/internal/rows.js +77 -0
- package/dist/internal/table-spans.d.ts +11 -0
- package/dist/internal/table-spans.js +58 -0
- package/dist/internal/totals.d.ts +15 -0
- package/dist/internal/totals.js +42 -0
- package/dist/opc/index.d.ts +67 -0
- package/dist/opc/index.js +233 -0
- package/dist/opc/properties.d.ts +15 -0
- package/dist/opc/properties.js +18 -0
- package/dist/opc/uri.d.ts +5 -0
- package/dist/opc/uri.js +41 -0
- package/dist/pdf/annotations.d.ts +1 -0
- package/dist/pdf/annotations.js +38 -0
- package/dist/pdf/binary.d.ts +6 -0
- package/dist/pdf/binary.js +24 -0
- package/dist/pdf/document-drawings.d.ts +15 -0
- package/dist/pdf/document-drawings.js +237 -0
- package/dist/pdf/document-grouped.d.ts +1 -0
- package/dist/pdf/document-grouped.js +244 -0
- package/dist/pdf/document-images.d.ts +19 -0
- package/dist/pdf/document-images.js +125 -0
- package/dist/pdf/document-types.d.ts +160 -0
- package/dist/pdf/document-types.js +1 -0
- package/dist/pdf/document-vectors.d.ts +11 -0
- package/dist/pdf/document-vectors.js +77 -0
- package/dist/pdf/document.d.ts +9 -0
- package/dist/pdf/document.js +270 -0
- package/dist/pdf/drawing-types.d.ts +53 -0
- package/dist/pdf/drawing-types.js +1 -0
- package/dist/pdf/font-resources.d.ts +43 -0
- package/dist/pdf/font-resources.js +202 -0
- package/dist/pdf/font-support.d.ts +1 -0
- package/dist/pdf/font-support.js +60 -0
- package/dist/pdf/font.d.ts +17 -0
- package/dist/pdf/font.js +56 -0
- package/dist/pdf/grouped-table.d.ts +6 -0
- package/dist/pdf/grouped-table.js +40 -0
- package/dist/pdf/grouped-types.d.ts +34 -0
- package/dist/pdf/grouped-types.js +1 -0
- package/dist/pdf/grouped.d.ts +10 -0
- package/dist/pdf/grouped.js +37 -0
- package/dist/pdf/index.d.ts +22 -0
- package/dist/pdf/index.js +8 -0
- package/dist/pdf/inline-text.d.ts +30 -0
- package/dist/pdf/inline-text.js +183 -0
- package/dist/pdf/inline-types.d.ts +15 -0
- package/dist/pdf/inline-types.js +1 -0
- package/dist/pdf/list-layout.d.ts +6 -0
- package/dist/pdf/list-layout.js +49 -0
- package/dist/pdf/objects.d.ts +2 -0
- package/dist/pdf/objects.js +320 -0
- package/dist/pdf/outlines.d.ts +1 -0
- package/dist/pdf/outlines.js +55 -0
- package/dist/pdf/page-context.d.ts +1 -0
- package/dist/pdf/page-context.js +12 -0
- package/dist/pdf/pages.d.ts +1 -0
- package/dist/pdf/pages.js +678 -0
- package/dist/pdf/paragraph-layout.d.ts +21 -0
- package/dist/pdf/paragraph-layout.js +71 -0
- package/dist/pdf/paragraph-styles.d.ts +1 -0
- package/dist/pdf/paragraph-styles.js +66 -0
- package/dist/pdf/png.d.ts +9 -0
- package/dist/pdf/png.js +259 -0
- package/dist/pdf/preflight.d.ts +7 -0
- package/dist/pdf/preflight.js +32 -0
- package/dist/pdf/presentation-settings.d.ts +5 -0
- package/dist/pdf/presentation-settings.js +28 -0
- package/dist/pdf/providers/harfbuzz.d.ts +60 -0
- package/dist/pdf/providers/harfbuzz.js +112 -0
- package/dist/pdf/providers/unicode13-profile.d.ts +2 -0
- package/dist/pdf/providers/unicode13-profile.js +115 -0
- package/dist/pdf/section-types.d.ts +15 -0
- package/dist/pdf/section-types.js +40 -0
- package/dist/pdf/session.d.ts +25 -0
- package/dist/pdf/session.js +55 -0
- package/dist/pdf/settings.d.ts +17 -0
- package/dist/pdf/settings.js +196 -0
- package/dist/pdf/shaped-text.d.ts +5 -0
- package/dist/pdf/shaped-text.js +205 -0
- package/dist/pdf/standard-widths.d.ts +1 -0
- package/dist/pdf/standard-widths.js +317 -0
- package/dist/pdf/structure-parent-tree.d.ts +1 -0
- package/dist/pdf/structure-parent-tree.js +57 -0
- package/dist/pdf/structure.d.ts +6 -0
- package/dist/pdf/structure.js +302 -0
- package/dist/pdf/table-band-flow.d.ts +34 -0
- package/dist/pdf/table-band-flow.js +129 -0
- package/dist/pdf/table-band-plan.d.ts +10 -0
- package/dist/pdf/table-band-plan.js +83 -0
- package/dist/pdf/table-layout.d.ts +75 -0
- package/dist/pdf/table-layout.js +217 -0
- package/dist/pdf/table-structure.d.ts +1 -0
- package/dist/pdf/table-structure.js +108 -0
- package/dist/pdf/text-shaping-types.d.ts +39 -0
- package/dist/pdf/text-shaping-types.js +1 -0
- package/dist/pdf/text.d.ts +13 -0
- package/dist/pdf/text.js +101 -0
- package/dist/pdf/truetype-subset.d.ts +5 -0
- package/dist/pdf/truetype-subset.js +217 -0
- package/dist/pdf/truetype.d.ts +1 -0
- package/dist/pdf/truetype.js +235 -0
- package/dist/pdf/types.d.ts +171 -0
- package/dist/pdf/types.js +1 -0
- package/dist/pdf/write.d.ts +6 -0
- package/dist/pdf/write.js +57 -0
- package/dist/pdf/xref.d.ts +1 -0
- package/dist/pdf/xref.js +30 -0
- package/dist/xlsx/attachments.d.ts +30 -0
- package/dist/xlsx/attachments.js +67 -0
- package/dist/xlsx/chart-bindings.d.ts +1 -0
- package/dist/xlsx/chart-bindings.js +122 -0
- package/dist/xlsx/chart-types.d.ts +73 -0
- package/dist/xlsx/chart-types.js +1 -0
- package/dist/xlsx/chart-xml.d.ts +2 -0
- package/dist/xlsx/chart-xml.js +103 -0
- package/dist/xlsx/charts.d.ts +1 -0
- package/dist/xlsx/charts.js +159 -0
- package/dist/xlsx/conditional-formatting.d.ts +1 -0
- package/dist/xlsx/conditional-formatting.js +158 -0
- package/dist/xlsx/conditional-types.d.ts +64 -0
- package/dist/xlsx/conditional-types.js +1 -0
- package/dist/xlsx/data-row-ranges.d.ts +5 -0
- package/dist/xlsx/data-row-ranges.js +39 -0
- package/dist/xlsx/differential-styles.d.ts +1 -0
- package/dist/xlsx/differential-styles.js +102 -0
- package/dist/xlsx/formula.d.ts +8 -0
- package/dist/xlsx/formula.js +104 -0
- package/dist/xlsx/grouped-layout.d.ts +61 -0
- package/dist/xlsx/grouped-layout.js +79 -0
- package/dist/xlsx/grouped.d.ts +16 -0
- package/dist/xlsx/grouped.js +161 -0
- package/dist/xlsx/index.d.ts +24 -0
- package/dist/xlsx/index.js +10 -0
- package/dist/xlsx/layout.d.ts +1 -0
- package/dist/xlsx/layout.js +186 -0
- package/dist/xlsx/options.d.ts +1 -0
- package/dist/xlsx/options.js +16 -0
- package/dist/xlsx/portable.d.ts +27 -0
- package/dist/xlsx/portable.js +44 -0
- package/dist/xlsx/preservation.d.ts +1 -0
- package/dist/xlsx/preservation.js +60 -0
- package/dist/xlsx/ranges.d.ts +1 -0
- package/dist/xlsx/ranges.js +24 -0
- package/dist/xlsx/regions.d.ts +1 -0
- package/dist/xlsx/regions.js +97 -0
- package/dist/xlsx/structured-rows.d.ts +11 -0
- package/dist/xlsx/structured-rows.js +28 -0
- package/dist/xlsx/style-xml.d.ts +1 -0
- package/dist/xlsx/style-xml.js +6 -0
- package/dist/xlsx/styles.d.ts +70 -0
- package/dist/xlsx/styles.js +203 -0
- package/dist/xlsx/table.d.ts +12 -0
- package/dist/xlsx/table.js +35 -0
- package/dist/xlsx/types.d.ts +180 -0
- package/dist/xlsx/types.js +1 -0
- package/dist/xlsx/validation-types.d.ts +18 -0
- package/dist/xlsx/validation-types.js +1 -0
- package/dist/xlsx/validation.d.ts +1 -0
- package/dist/xlsx/validation.js +92 -0
- package/dist/xlsx/values.d.ts +13 -0
- package/dist/xlsx/values.js +87 -0
- package/dist/xlsx/workbook.d.ts +50 -0
- package/dist/xlsx/workbook.js +452 -0
- package/dist/xlsx/worksheet.d.ts +71 -0
- package/dist/xlsx/worksheet.js +700 -0
- package/dist/xlsx/write.d.ts +15 -0
- package/dist/xlsx/write.js +47 -0
- package/dist/xml/index.d.ts +24 -0
- package/dist/xml/index.js +74 -0
- package/dist/zip/entry.d.ts +39 -0
- package/dist/zip/entry.js +122 -0
- package/dist/zip/index.d.ts +44 -0
- package/dist/zip/index.js +248 -0
- package/package.json +104 -4
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { beginTask, checkAbort, consumeRows, taskYieldDue, withAbort } from "../core/iteration.js";
|
|
2
|
+
import { BlobByteSink, ChunkedTextSink, withDestination } from "../core/sinks.js";
|
|
3
|
+
import { ExportBudget, boundedSink } from "../core/limits.js";
|
|
4
|
+
import { ExportCell } from "../core/presentation.js";
|
|
5
|
+
import { isDate } from "../core/dates.js";
|
|
6
|
+
import { notifyProgress } from "../core/progress.js";
|
|
7
|
+
import { copyColumns, createRowProjector } from "../internal/rows.js";
|
|
8
|
+
import { csvStructuredRows } from "./structured-rows.js";
|
|
9
|
+
import { captureBooleanText } from "../core/value-text.js";
|
|
10
|
+
import { captureCsvOptions } from "./options.js";
|
|
11
|
+
export { saveBlob } from "../core/index.js";
|
|
12
|
+
export { ExportCell } from "../core/presentation.js";
|
|
13
|
+
function csvField(value, delimiter, protect, quote, booleanText, nullValue) {
|
|
14
|
+
if (value == null && nullValue !== undefined)
|
|
15
|
+
value = nullValue;
|
|
16
|
+
let text;
|
|
17
|
+
if (value == null)
|
|
18
|
+
text = "";
|
|
19
|
+
else if (isDate(value))
|
|
20
|
+
text = Number.isFinite(value.getTime()) ? value.toISOString() : "";
|
|
21
|
+
else if (typeof value === "boolean")
|
|
22
|
+
text = booleanText[value ? "true" : "false"];
|
|
23
|
+
else if (typeof value === "number")
|
|
24
|
+
text = Number.isFinite(value) ? String(value) : "";
|
|
25
|
+
else if (typeof value === "string")
|
|
26
|
+
text = value;
|
|
27
|
+
else {
|
|
28
|
+
if (typeof value.then === "function")
|
|
29
|
+
void Promise.resolve(value).catch(() => { });
|
|
30
|
+
throw new TypeError("CSV cells and formatter results must be synchronous strings, numbers, booleans, Dates or null.");
|
|
31
|
+
}
|
|
32
|
+
if (protect && (typeof value === "string" || typeof value === "boolean") && /^ *[=+\-@\t\r\n]/.test(text))
|
|
33
|
+
text = "'" + text;
|
|
34
|
+
return quote === "all" || (quote === "strings" && typeof value === "string") || text.includes(delimiter) || /["\r\n]/.test(text)
|
|
35
|
+
? '"' + text.replace(/"/g, '""') + '"' : text;
|
|
36
|
+
}
|
|
37
|
+
export async function writeCsvTo(rows, destination, configuration) {
|
|
38
|
+
const options = captureCsvOptions(configuration);
|
|
39
|
+
return withDestination(destination, sink => write(rows, sink, options));
|
|
40
|
+
}
|
|
41
|
+
async function write(rows, sink, options) {
|
|
42
|
+
beginTask();
|
|
43
|
+
const columns = copyColumns(options.columns).map(c => Object.freeze(c)), delimiter = options.delimiter ?? ",", lineEnding = options.lineEnding ?? "\r\n", quote = options.quote ?? "minimal";
|
|
44
|
+
const booleanText = captureBooleanText(options.booleanText);
|
|
45
|
+
if (![",", ";", "\t"].includes(delimiter))
|
|
46
|
+
throw new RangeError("Delimiter must be comma, semicolon or tab.");
|
|
47
|
+
if (!["\r\n", "\n", "\r"].includes(lineEnding))
|
|
48
|
+
throw new RangeError("Invalid line ending.");
|
|
49
|
+
if (!["minimal", "all", "strings"].includes(quote))
|
|
50
|
+
throw new RangeError("Quoting must be minimal, all or strings.");
|
|
51
|
+
if (options.valueMode !== undefined && !["raw", "display"].includes(options.valueMode))
|
|
52
|
+
throw new RangeError("valueMode must be raw or display.");
|
|
53
|
+
if (options.nullValue !== undefined && typeof options.nullValue !== "string")
|
|
54
|
+
throw new TypeError("nullValue must be a string.");
|
|
55
|
+
if (options.spanMode !== undefined && options.spanMode !== "repeat" && options.spanMode !== "anchors")
|
|
56
|
+
throw new TypeError("CSV spanMode must be repeat or anchors.");
|
|
57
|
+
const headings = options.includeHeader === false ? [] : options.headerRows === undefined ? columns.length ? [columns.map(c => c.header)] : [] : csvStructuredRows(options.headerRows, columns.length, options.spanMode);
|
|
58
|
+
const footers = options.footer === undefined ? [] : csvStructuredRows(options.footer.rows, columns.length, options.spanMode);
|
|
59
|
+
for (const column of columns)
|
|
60
|
+
if (column.valueFormatter !== undefined && typeof column.valueFormatter !== "function")
|
|
61
|
+
throw new TypeError("CSV value formatters must be functions.");
|
|
62
|
+
const budget = new ExportBudget(options.limits);
|
|
63
|
+
let bytes = 0;
|
|
64
|
+
const accepted = sink;
|
|
65
|
+
sink = boundedSink({ async write(chunk) { await accepted.write(chunk); bytes += chunk.byteLength; } }, budget);
|
|
66
|
+
const project = createRowProjector(columns, undefined, options.signal);
|
|
67
|
+
const hasFormatters = columns.some(column => column.valueFormatter);
|
|
68
|
+
const signal = options.signal, protect = options.formulaInjectionProtection !== false, buffer = new ChunkedTextSink(sink, signal);
|
|
69
|
+
checkAbort(signal);
|
|
70
|
+
if (options.bom)
|
|
71
|
+
await withAbort(Promise.resolve(sink.write(new Uint8Array([239, 187, 191]))), signal);
|
|
72
|
+
let count = 0;
|
|
73
|
+
const resolved = (value) => value !== null && typeof value === "object" && value instanceof ExportCell ? options.valueMode === "display" && value.text !== undefined ? value.text : value.value : value;
|
|
74
|
+
function record(values, header = false, first = 0, snapshot) {
|
|
75
|
+
if (!header && hasFormatters && first === 0)
|
|
76
|
+
snapshot = Object.freeze(columns.map((_, i) => resolved(values[i])));
|
|
77
|
+
let text = "";
|
|
78
|
+
for (let i = first; i < columns.length; i++) {
|
|
79
|
+
checkAbort(signal);
|
|
80
|
+
const column = columns[i];
|
|
81
|
+
const raw = resolved(values[i]);
|
|
82
|
+
let value = !header && column.valueFormatter ? column.valueFormatter(raw, { rowIndex: count, columnIndex: i, column, values: snapshot }) : raw;
|
|
83
|
+
if (value == null && options.nullValue !== undefined)
|
|
84
|
+
value = options.nullValue;
|
|
85
|
+
budget.cell(typeof value === "boolean" ? booleanText[value ? "true" : "false"] : value);
|
|
86
|
+
checkAbort(signal);
|
|
87
|
+
text += (i ? delimiter : "") + csvField(value, delimiter, protect, quote, booleanText, options.nullValue);
|
|
88
|
+
if (text.length >= buffer.chunkSize || (i & 127) === 127 && taskYieldDue()) {
|
|
89
|
+
if (buffer.append(text))
|
|
90
|
+
return buffer.flush().then(() => record(values, header, i + 1, snapshot));
|
|
91
|
+
text = "";
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (buffer.append(text + lineEnding))
|
|
95
|
+
return buffer.flush().then(() => { notifyProgress(options.onProgress, { phase: "rows", rows: count + (header ? 0 : 1) }); });
|
|
96
|
+
}
|
|
97
|
+
for (const heading of headings)
|
|
98
|
+
await record(heading, true);
|
|
99
|
+
await consumeRows(rows, signal, row => {
|
|
100
|
+
budget.row(count + 1);
|
|
101
|
+
const pending = record(project(row, count));
|
|
102
|
+
if (pending)
|
|
103
|
+
return pending.then(() => { count++; });
|
|
104
|
+
count++;
|
|
105
|
+
});
|
|
106
|
+
for (const footer of footers)
|
|
107
|
+
await record(footer, true);
|
|
108
|
+
await buffer.close();
|
|
109
|
+
notifyProgress(options.onProgress, { phase: "complete", rows: count, bytes });
|
|
110
|
+
checkAbort(signal);
|
|
111
|
+
return { rows: count, columns: columns.length, bytes };
|
|
112
|
+
}
|
|
113
|
+
export async function writeCsv(rows, configuration) {
|
|
114
|
+
const options = captureCsvOptions(configuration);
|
|
115
|
+
const sink = new BlobByteSink();
|
|
116
|
+
try {
|
|
117
|
+
let completedRows = 0;
|
|
118
|
+
await write(rows, sink, { ...options, onProgress: p => {
|
|
119
|
+
if (p.phase === "complete")
|
|
120
|
+
completedRows = p.rows;
|
|
121
|
+
else
|
|
122
|
+
notifyProgress(options.onProgress, p);
|
|
123
|
+
} });
|
|
124
|
+
const blob = sink.toBlob("text/csv;charset=utf-8");
|
|
125
|
+
notifyProgress(options.onProgress, { phase: "complete", rows: completedRows, bytes: blob.size });
|
|
126
|
+
checkAbort(options.signal);
|
|
127
|
+
return blob;
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
sink.discard();
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { captureFields } from "../internal/capture.js";
|
|
2
|
+
/** @internal Share the format's capture policy with thin adapters before they compose options. */
|
|
3
|
+
export function captureCsvOptions(input) {
|
|
4
|
+
if (!input || typeof input !== "object")
|
|
5
|
+
throw new TypeError("CSV options are required.");
|
|
6
|
+
return captureFields(input, ["columns", "signal", "limits", "onProgress", "valueMode", "delimiter", "lineEnding", "bom", "includeHeader", "headerRows",
|
|
7
|
+
"footer", "spanMode", "formulaInjectionProtection", "quote", "nullValue", "booleanText"]);
|
|
8
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ExportValue, TableSpanRows } from "../core/index.js";
|
|
2
|
+
/** Snapshot small report matrices; flattening is an explicit format decision, never inferred from labels. */
|
|
3
|
+
export declare function csvStructuredRows(rows: TableSpanRows, columns: number, mode: "repeat" | "anchors" | undefined): readonly (readonly ExportValue[])[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { captureTableSpans, tableSpans } from "../internal/table-spans.js";
|
|
2
|
+
/** Snapshot small report matrices; flattening is an explicit format decision, never inferred from labels. */
|
|
3
|
+
export function csvStructuredRows(rows, columns, mode) {
|
|
4
|
+
const anchors = tableSpans(captureTableSpans(rows, columns), columns), output = anchors.map(() => Array(columns).fill(""));
|
|
5
|
+
for (let row = 0; row < anchors.length; row++)
|
|
6
|
+
for (const anchor of anchors[row]) {
|
|
7
|
+
if ((anchor.span > 1 || anchor.rowSpan > 1) && mode === undefined)
|
|
8
|
+
throw new TypeError("CSV spanned headings/footers require an explicit spanMode: repeat or anchors.");
|
|
9
|
+
const value = anchor.value;
|
|
10
|
+
for (let r = row; r < row + (mode === "repeat" ? anchor.rowSpan : 1); r++)
|
|
11
|
+
for (let c = anchor.first; c < anchor.first + (mode === "repeat" ? anchor.span : 1); c++)
|
|
12
|
+
output[r][c] = value;
|
|
13
|
+
}
|
|
14
|
+
return output;
|
|
15
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ExportResult, OutputDestination } from "../core/index.js";
|
|
2
|
+
import type { ExportWorkerEndpoint, WorkerExportOptions, WorkerExportRows } from "./types.js";
|
|
3
|
+
/** Execute through a host-owned worker with bounded rows, acknowledged bytes and coalesced progress.
|
|
4
|
+
* The host owns the worker, source I/O and partial destination bytes. No caller-owned buffer is transferred. */
|
|
5
|
+
export declare function executeWorkerExport(endpoint: ExportWorkerEndpoint, rows: WorkerExportRows, destination: OutputDestination, options?: WorkerExportOptions): Promise<ExportResult>;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { checkAbort, inputRows, withAbort } from "../core/iteration.js";
|
|
2
|
+
import { withDestination } from "../core/sinks.js";
|
|
3
|
+
import { notifyProgress } from "../core/progress.js";
|
|
4
|
+
import { OfficeIMOError } from "../core/errors.js";
|
|
5
|
+
import { bounds, captureInput, captureProgress, captureRow, message, protocol, restoreError, result, wireError } from "./protocol.js";
|
|
6
|
+
import { captureFields } from "../internal/capture.js";
|
|
7
|
+
const active = new WeakSet();
|
|
8
|
+
let sequence = 0;
|
|
9
|
+
/** Execute through a host-owned worker with bounded rows, acknowledged bytes and coalesced progress.
|
|
10
|
+
* The host owns the worker, source I/O and partial destination bytes. No caller-owned buffer is transferred. */
|
|
11
|
+
export async function executeWorkerExport(endpoint, rows, destination, options = {}) {
|
|
12
|
+
const captured = captureFields(options, ["input", "signal", "onProgress", "batchRows", "maxBatchCells", "maxBatchCharacters", "maxChunkBytes", "maxSetupBytes", "maxSetupNodes"]);
|
|
13
|
+
const signal = captured.signal, onProgress = captured.onProgress;
|
|
14
|
+
checkAbort(signal);
|
|
15
|
+
const limits = bounds(captured), input = captureInput(captured.input, limits);
|
|
16
|
+
if (active.has(endpoint))
|
|
17
|
+
throw new OfficeIMOError("INVALID_STATE", "A worker endpoint already has an active export.");
|
|
18
|
+
active.add(endpoint);
|
|
19
|
+
try {
|
|
20
|
+
return await withDestination(destination, sink => new Promise((resolve, reject) => {
|
|
21
|
+
const lifetime = new AbortController();
|
|
22
|
+
const job = "export-" + ++sequence, iterator = inputRows(rows, lifetime.signal);
|
|
23
|
+
let settled = false, reading = false, writing = false, exhausted = false, acceptedBytes = 0;
|
|
24
|
+
let pending;
|
|
25
|
+
const post = (payload) => endpoint.postMessage({ protocol, job, ...payload });
|
|
26
|
+
function cleanup() {
|
|
27
|
+
endpoint.removeEventListener("message", receive);
|
|
28
|
+
endpoint.removeEventListener("error", broken);
|
|
29
|
+
endpoint.removeEventListener("messageerror", broken);
|
|
30
|
+
signal?.removeEventListener("abort", aborted);
|
|
31
|
+
// A producer's stuck or rejected cleanup must not replace or delay export completion.
|
|
32
|
+
if (!exhausted)
|
|
33
|
+
void iterator.return(undefined).catch(() => { });
|
|
34
|
+
pending = undefined;
|
|
35
|
+
}
|
|
36
|
+
function fail(error) {
|
|
37
|
+
if (settled)
|
|
38
|
+
return;
|
|
39
|
+
settled = true;
|
|
40
|
+
// A terminal worker/transport failure must also release a pending producer
|
|
41
|
+
// when the caller did not supply or abort its own signal.
|
|
42
|
+
lifetime.abort(error);
|
|
43
|
+
try {
|
|
44
|
+
post({ kind: "cancel", error: wireError(error) });
|
|
45
|
+
}
|
|
46
|
+
catch { /* A disconnected worker cannot receive cancellation. */ }
|
|
47
|
+
cleanup();
|
|
48
|
+
reject(error);
|
|
49
|
+
}
|
|
50
|
+
const aborted = () => { try {
|
|
51
|
+
checkAbort(signal);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
fail(error);
|
|
55
|
+
} };
|
|
56
|
+
const broken = event => fail(new Error(event.message || "Worker messaging failed."));
|
|
57
|
+
async function read(id) {
|
|
58
|
+
if (reading)
|
|
59
|
+
throw new OfficeIMOError("INVALID_STATE", "Only one worker row request may be pending.");
|
|
60
|
+
reading = true;
|
|
61
|
+
try {
|
|
62
|
+
const batch = [];
|
|
63
|
+
let cells = 0, characters = 0;
|
|
64
|
+
while (batch.length < limits.batchRows && !exhausted) {
|
|
65
|
+
let next = pending;
|
|
66
|
+
pending = undefined;
|
|
67
|
+
if (!next) {
|
|
68
|
+
const item = await withAbort(iterator.next(), lifetime.signal);
|
|
69
|
+
if (settled)
|
|
70
|
+
return;
|
|
71
|
+
if (item.done) {
|
|
72
|
+
exhausted = true;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
if (!Array.isArray(item.value) || item.value.length > limits.maxBatchCells)
|
|
76
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "A worker row exceeds its message cell budget.");
|
|
77
|
+
next = captureRow(item.value);
|
|
78
|
+
}
|
|
79
|
+
if (next.cells.length > limits.maxBatchCells || next.characters > limits.maxBatchCharacters)
|
|
80
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "A worker row exceeds its message budget.");
|
|
81
|
+
if (batch.length && (cells + next.cells.length > limits.maxBatchCells || characters + next.characters > limits.maxBatchCharacters)) {
|
|
82
|
+
pending = next;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
batch.push(next.cells);
|
|
86
|
+
cells += next.cells.length;
|
|
87
|
+
characters += next.characters;
|
|
88
|
+
}
|
|
89
|
+
if (!settled)
|
|
90
|
+
post({ kind: "rows", id, rows: batch, done: exhausted });
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
reading = false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async function write(data) {
|
|
97
|
+
if (writing || !(data.bytes instanceof Uint8Array) || data.bytes.length > limits.maxChunkBytes)
|
|
98
|
+
throw new OfficeIMOError("INVALID_STATE", "Invalid or overlapping worker output chunk.");
|
|
99
|
+
writing = true;
|
|
100
|
+
try {
|
|
101
|
+
await withAbort(Promise.resolve(sink.write(data.bytes)), lifetime.signal);
|
|
102
|
+
if (!settled) {
|
|
103
|
+
acceptedBytes += data.bytes.length;
|
|
104
|
+
post({ kind: "ack", id: data.id });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
writing = false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const receive = event => {
|
|
112
|
+
const data = message(event.data);
|
|
113
|
+
if (settled || !data || data.job !== job)
|
|
114
|
+
return;
|
|
115
|
+
try {
|
|
116
|
+
if (data.kind === "complete") {
|
|
117
|
+
const completed = result(data.result);
|
|
118
|
+
if (writing || reading || completed.bytes !== acceptedBytes)
|
|
119
|
+
throw new OfficeIMOError("INVALID_STATE", "Worker completion does not match acknowledged output.");
|
|
120
|
+
settled = true;
|
|
121
|
+
cleanup();
|
|
122
|
+
resolve(completed);
|
|
123
|
+
}
|
|
124
|
+
else if (data.kind === "failed")
|
|
125
|
+
fail(restoreError(data.error));
|
|
126
|
+
else {
|
|
127
|
+
if (!Number.isSafeInteger(data.id) || data.id < 1)
|
|
128
|
+
throw new TypeError("Invalid worker request identifier.");
|
|
129
|
+
if (data.kind === "requestRows")
|
|
130
|
+
void read(data.id).catch(fail);
|
|
131
|
+
else if (data.kind === "output")
|
|
132
|
+
void write(data).catch(fail);
|
|
133
|
+
else if (data.kind === "progress") {
|
|
134
|
+
if (!data.progress)
|
|
135
|
+
throw new TypeError("Invalid worker progress.");
|
|
136
|
+
notifyProgress(onProgress, captureProgress(data.progress, limits));
|
|
137
|
+
post({ kind: "ack", id: data.id });
|
|
138
|
+
}
|
|
139
|
+
else
|
|
140
|
+
throw new TypeError("Unexpected worker export message.");
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
fail(error);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
endpoint.addEventListener("message", receive);
|
|
148
|
+
endpoint.addEventListener("error", broken);
|
|
149
|
+
endpoint.addEventListener("messageerror", broken);
|
|
150
|
+
signal?.addEventListener("abort", aborted, { once: true });
|
|
151
|
+
try {
|
|
152
|
+
endpoint.start?.();
|
|
153
|
+
checkAbort(signal);
|
|
154
|
+
post({ kind: "start", input, bounds: limits });
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
fail(error);
|
|
158
|
+
}
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
161
|
+
finally {
|
|
162
|
+
active.delete(endpoint);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { CellValue, ErrorCode, ExportProgress, ExportResult, ExportValue } from "../core/index.js";
|
|
2
|
+
import type { ExportCellOptions } from "../core/presentation.js";
|
|
3
|
+
import type { WorkerExportOptions } from "./types.js";
|
|
4
|
+
export declare const protocol = "@evotecit/officeimo/worker-export/1";
|
|
5
|
+
export interface Bounds {
|
|
6
|
+
readonly batchRows: number;
|
|
7
|
+
readonly maxBatchCells: number;
|
|
8
|
+
readonly maxBatchCharacters: number;
|
|
9
|
+
readonly maxChunkBytes: number;
|
|
10
|
+
readonly maxSetupBytes: number;
|
|
11
|
+
readonly maxSetupNodes: number;
|
|
12
|
+
}
|
|
13
|
+
export interface WireCell {
|
|
14
|
+
readonly value: CellValue;
|
|
15
|
+
readonly options?: ExportCellOptions;
|
|
16
|
+
}
|
|
17
|
+
export interface WireMessage {
|
|
18
|
+
readonly protocol: typeof protocol;
|
|
19
|
+
readonly job: string;
|
|
20
|
+
readonly kind: string;
|
|
21
|
+
readonly id?: number;
|
|
22
|
+
readonly input?: unknown;
|
|
23
|
+
readonly bounds?: Bounds;
|
|
24
|
+
readonly rows?: readonly (readonly WireCell[])[];
|
|
25
|
+
readonly done?: boolean;
|
|
26
|
+
readonly bytes?: Uint8Array;
|
|
27
|
+
readonly progress?: ExportProgress;
|
|
28
|
+
readonly result?: ExportResult;
|
|
29
|
+
readonly error?: {
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly message: string;
|
|
32
|
+
readonly code?: ErrorCode;
|
|
33
|
+
readonly feature?: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export declare function message(value: unknown): WireMessage | undefined;
|
|
37
|
+
export declare function bounds(options: WorkerExportOptions): Bounds;
|
|
38
|
+
/** Snapshot portable setup before messaging. Font objects, functions, accessors and cyclic live objects stay in their host. */
|
|
39
|
+
export declare function captureInput(input: unknown, limits: Bounds): unknown;
|
|
40
|
+
export declare function captureRow(row: readonly ExportValue[]): {
|
|
41
|
+
readonly cells: readonly WireCell[];
|
|
42
|
+
readonly characters: number;
|
|
43
|
+
};
|
|
44
|
+
export declare function restoreRows(rows: WireMessage["rows"], limits: Bounds): readonly (readonly ExportValue[])[];
|
|
45
|
+
export declare function captureProgress(value: ExportProgress, limits: Bounds): ExportProgress;
|
|
46
|
+
export declare function wireError(error: unknown): NonNullable<WireMessage["error"]>;
|
|
47
|
+
export declare function restoreError(error: WireMessage["error"]): Error;
|
|
48
|
+
export declare function result(value: ExportResult | undefined): ExportResult;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { ExportCell, NotSupportedError, OfficeIMOError } from "../core/index.js";
|
|
2
|
+
import { assertExportValue, assertScalar, copyCellPresentation } from "../core/presentation.js";
|
|
3
|
+
import { copyExportLink } from "../core/links.js";
|
|
4
|
+
import { isDate } from "../core/dates.js";
|
|
5
|
+
export const protocol = "@evotecit/officeimo/worker-export/1";
|
|
6
|
+
export function message(value) {
|
|
7
|
+
if (!value || typeof value !== "object")
|
|
8
|
+
return undefined;
|
|
9
|
+
const candidate = value;
|
|
10
|
+
return candidate.protocol === protocol && typeof candidate.job === "string" && typeof candidate.kind === "string" ? candidate : undefined;
|
|
11
|
+
}
|
|
12
|
+
export function bounds(options) {
|
|
13
|
+
const result = { batchRows: options.batchRows ?? 64, maxBatchCells: options.maxBatchCells ?? 65536,
|
|
14
|
+
maxBatchCharacters: options.maxBatchCharacters ?? 1000000, maxChunkBytes: options.maxChunkBytes ?? 65536,
|
|
15
|
+
maxSetupBytes: options.maxSetupBytes ?? 16 * 1024 * 1024, maxSetupNodes: options.maxSetupNodes ?? 100000 };
|
|
16
|
+
for (const [name, value] of Object.entries(result))
|
|
17
|
+
if (!Number.isSafeInteger(value) || value < 1)
|
|
18
|
+
throw new RangeError(name + " must be a positive safe integer.");
|
|
19
|
+
return Object.freeze(result);
|
|
20
|
+
}
|
|
21
|
+
/** Snapshot portable setup before messaging. Font objects, functions, accessors and cyclic live objects stay in their host. */
|
|
22
|
+
export function captureInput(input, limits) {
|
|
23
|
+
let nodes = 0, bytes = 0;
|
|
24
|
+
const ancestors = new Set();
|
|
25
|
+
function accept(additional = 0) {
|
|
26
|
+
bytes += additional;
|
|
27
|
+
if (bytes > limits.maxSetupBytes || ++nodes > limits.maxSetupNodes)
|
|
28
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "Worker configuration exceeds its message budget.");
|
|
29
|
+
}
|
|
30
|
+
function copy(value, depth) {
|
|
31
|
+
if (depth > 32)
|
|
32
|
+
throw new RangeError("Worker configuration nesting exceeds 32 levels.");
|
|
33
|
+
accept(typeof value === "string" ? value.length * 2 : 0);
|
|
34
|
+
if (value == null || ["string", "number", "boolean"].includes(typeof value))
|
|
35
|
+
return value;
|
|
36
|
+
if (isDate(value)) {
|
|
37
|
+
accept(8);
|
|
38
|
+
return new Date(value.getTime());
|
|
39
|
+
}
|
|
40
|
+
if (ArrayBuffer.isView(value) && Object.prototype.toString.call(value) === "[object Uint8Array]") {
|
|
41
|
+
accept(value.byteLength);
|
|
42
|
+
return new Uint8Array(value);
|
|
43
|
+
}
|
|
44
|
+
if (typeof value !== "object")
|
|
45
|
+
throw new TypeError("Worker configuration requires portable data without functions or symbols.");
|
|
46
|
+
if (ancestors.has(value))
|
|
47
|
+
throw new TypeError("Worker configuration cannot contain cycles.");
|
|
48
|
+
const prototype = Object.getPrototypeOf(value);
|
|
49
|
+
const constructor = prototype == null ? undefined : Object.getOwnPropertyDescriptor(prototype, "constructor")?.value;
|
|
50
|
+
const plain = prototype === null || Object.getPrototypeOf(prototype) === null && typeof constructor === "function" &&
|
|
51
|
+
Function.prototype.toString.call(constructor) === Function.prototype.toString.call(Object);
|
|
52
|
+
if (!Array.isArray(value) && !plain)
|
|
53
|
+
throw new TypeError("Worker configuration supports plain records, arrays, Dates and Uint8Array bytes; reconstruct font instances in the worker.");
|
|
54
|
+
ancestors.add(value);
|
|
55
|
+
try {
|
|
56
|
+
if (Array.isArray(value)) {
|
|
57
|
+
if (value.length > limits.maxSetupNodes - nodes)
|
|
58
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "Worker configuration exceeds its message budget.");
|
|
59
|
+
const snapshot = [];
|
|
60
|
+
for (let i = 0; i < value.length; i++) {
|
|
61
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, String(i));
|
|
62
|
+
if (descriptor && !Object.prototype.hasOwnProperty.call(descriptor, "value"))
|
|
63
|
+
throw new TypeError("Worker configuration cannot contain accessors.");
|
|
64
|
+
snapshot.push(copy(descriptor?.value, depth + 1));
|
|
65
|
+
}
|
|
66
|
+
return snapshot;
|
|
67
|
+
}
|
|
68
|
+
const snapshot = {};
|
|
69
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
70
|
+
if (typeof key !== "string")
|
|
71
|
+
throw new TypeError("Worker configuration keys must be strings.");
|
|
72
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
73
|
+
if (!descriptor.enumerable)
|
|
74
|
+
continue;
|
|
75
|
+
if (!Object.prototype.hasOwnProperty.call(descriptor, "value"))
|
|
76
|
+
throw new TypeError("Worker configuration cannot contain accessors.");
|
|
77
|
+
accept(key.length * 2);
|
|
78
|
+
Object.defineProperty(snapshot, key, { value: copy(descriptor.value, depth + 1), enumerable: true, configurable: true, writable: true });
|
|
79
|
+
}
|
|
80
|
+
return snapshot;
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
ancestors.delete(value);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return copy(input, 0);
|
|
87
|
+
}
|
|
88
|
+
export function captureRow(row) {
|
|
89
|
+
if (!Array.isArray(row))
|
|
90
|
+
throw new TypeError("Worker export rows must be projected arrays.");
|
|
91
|
+
let characters = 0;
|
|
92
|
+
const scalar = (value) => {
|
|
93
|
+
if (typeof value === "string")
|
|
94
|
+
characters += value.length;
|
|
95
|
+
return isDate(value) ? new Date(value.getTime()) : value;
|
|
96
|
+
};
|
|
97
|
+
const cells = row.map(value => {
|
|
98
|
+
assertExportValue(value);
|
|
99
|
+
if (!(value instanceof ExportCell))
|
|
100
|
+
return { value: scalar(value) };
|
|
101
|
+
const cellValue = value.value, text = value.text, presentation = value.presentation, link = value.link;
|
|
102
|
+
assertScalar(cellValue);
|
|
103
|
+
if (text !== undefined && typeof text !== "string")
|
|
104
|
+
throw new TypeError("Display text must be a string.");
|
|
105
|
+
const options = {
|
|
106
|
+
...(text === undefined ? {} : { text }),
|
|
107
|
+
...(presentation === undefined ? {} : { presentation: copyCellPresentation(presentation) }),
|
|
108
|
+
...(link === undefined ? {} : { link: copyExportLink(link) })
|
|
109
|
+
};
|
|
110
|
+
characters += text?.length ?? 0;
|
|
111
|
+
for (const entry of Object.values(options.presentation ?? {}))
|
|
112
|
+
if (typeof entry === "string")
|
|
113
|
+
characters += entry.length;
|
|
114
|
+
characters += (options.link?.target.length ?? 0) + (options.link?.tooltip?.length ?? 0);
|
|
115
|
+
return { value: scalar(cellValue), options };
|
|
116
|
+
});
|
|
117
|
+
return { cells, characters };
|
|
118
|
+
}
|
|
119
|
+
export function restoreRows(rows, limits) {
|
|
120
|
+
if (!Array.isArray(rows) || rows.length > limits.batchRows)
|
|
121
|
+
throw new TypeError("Invalid worker row batch.");
|
|
122
|
+
let cells = 0, characters = 0;
|
|
123
|
+
return rows.map(row => {
|
|
124
|
+
if (!Array.isArray(row))
|
|
125
|
+
throw new TypeError("Invalid worker row.");
|
|
126
|
+
if (cells + row.length > limits.maxBatchCells)
|
|
127
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "Worker row batch exceeds its message budget.");
|
|
128
|
+
const restored = row.map((cell) => {
|
|
129
|
+
if (!cell || typeof cell !== "object")
|
|
130
|
+
throw new TypeError("Invalid worker cell.");
|
|
131
|
+
const value = cell.options === undefined ? cell.value : new ExportCell(cell.value, cell.options);
|
|
132
|
+
assertExportValue(value);
|
|
133
|
+
return value;
|
|
134
|
+
});
|
|
135
|
+
const captured = captureRow(restored);
|
|
136
|
+
cells += row.length;
|
|
137
|
+
characters += captured.characters;
|
|
138
|
+
if (cells > limits.maxBatchCells || characters > limits.maxBatchCharacters)
|
|
139
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "Worker row batch exceeds its message budget.");
|
|
140
|
+
return restored;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
export function captureProgress(value, limits) {
|
|
144
|
+
if (!value || !["rows", "complete"].includes(value.phase) || !Number.isSafeInteger(value.rows) || value.rows < 0)
|
|
145
|
+
throw new TypeError("Invalid worker progress.");
|
|
146
|
+
for (const key of ["bytes", "sheetRows", "totalRows"])
|
|
147
|
+
if (value[key] !== undefined && (!Number.isSafeInteger(value[key]) || value[key] < 0))
|
|
148
|
+
throw new TypeError("Invalid worker progress count.");
|
|
149
|
+
if (value.sheetName !== undefined && (typeof value.sheetName !== "string" || value.sheetName.length > limits.maxBatchCharacters))
|
|
150
|
+
throw new TypeError("Invalid or oversized worker sheet name.");
|
|
151
|
+
return { phase: value.phase, rows: value.rows,
|
|
152
|
+
...(value.bytes === undefined ? {} : { bytes: value.bytes }), ...(value.sheetRows === undefined ? {} : { sheetRows: value.sheetRows }),
|
|
153
|
+
...(value.totalRows === undefined ? {} : { totalRows: value.totalRows }), ...(value.sheetName === undefined ? {} : { sheetName: value.sheetName }) };
|
|
154
|
+
}
|
|
155
|
+
export function wireError(error) {
|
|
156
|
+
return { name: error instanceof Error ? error.name : "Error", message: error instanceof Error ? error.message : String(error),
|
|
157
|
+
...(error instanceof OfficeIMOError ? { code: error.code } : {}), ...(error instanceof NotSupportedError ? { feature: error.feature } : {}) };
|
|
158
|
+
}
|
|
159
|
+
export function restoreError(error) {
|
|
160
|
+
if (!error || typeof error.message !== "string")
|
|
161
|
+
return new Error("Worker export failed.");
|
|
162
|
+
const result = error.code === "NOT_SUPPORTED" && typeof error.feature === "string" ? new NotSupportedError(error.feature)
|
|
163
|
+
: error.code === undefined ? new Error(error.message) : new OfficeIMOError(error.code, error.message);
|
|
164
|
+
result.message = error.message;
|
|
165
|
+
if (typeof error.name === "string")
|
|
166
|
+
result.name = error.name;
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
export function result(value) {
|
|
170
|
+
if (!value || [value.rows, value.columns, value.bytes].some(n => !Number.isSafeInteger(n) || n < 0))
|
|
171
|
+
throw new TypeError("Invalid worker export result.");
|
|
172
|
+
return { rows: value.rows, columns: value.columns, bytes: value.bytes };
|
|
173
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ByteSink, ExportProgress, ExportResult, ExportValue } from "../core/index.js";
|
|
2
|
+
/** A host-created Worker, MessagePort or worker-global messaging surface. Ownership stays with the host. */
|
|
3
|
+
export interface ExportWorkerEndpoint {
|
|
4
|
+
postMessage(message: unknown): void;
|
|
5
|
+
addEventListener(type: string, listener: EventListener): void;
|
|
6
|
+
removeEventListener(type: string, listener: EventListener): void;
|
|
7
|
+
start?(): void;
|
|
8
|
+
}
|
|
9
|
+
/** Portable, already projected table rows. Live grids and domain callbacks remain in their owning host. */
|
|
10
|
+
export type WorkerExportRows = Iterable<readonly ExportValue[]> | AsyncIterable<readonly ExportValue[]>;
|
|
11
|
+
/** Bounds the messages in flight, independently of a format writer's document limits. */
|
|
12
|
+
export interface WorkerExportOptions {
|
|
13
|
+
/** Structured-cloneable operation configuration. Functions and live grids cannot cross a worker boundary. */
|
|
14
|
+
readonly input?: unknown;
|
|
15
|
+
readonly signal?: AbortSignal;
|
|
16
|
+
readonly onProgress?: (progress: ExportProgress) => void;
|
|
17
|
+
/** At most this many rows in one request; defaults to 64. */
|
|
18
|
+
readonly batchRows?: number;
|
|
19
|
+
/** Includes every selected cell in a batch; defaults to 65,536. One row must fit. */
|
|
20
|
+
readonly maxBatchCells?: number;
|
|
21
|
+
/** UTF-16 units of values, display text, links and presentation strings; defaults to 1,000,000. */
|
|
22
|
+
readonly maxBatchCharacters?: number;
|
|
23
|
+
/** At most this many output bytes await destination acknowledgement; defaults to 65,536. */
|
|
24
|
+
readonly maxChunkBytes?: number;
|
|
25
|
+
/** UTF-16 string storage plus binary bytes in portable operation configuration; defaults to 16 MiB. */
|
|
26
|
+
readonly maxSetupBytes?: number;
|
|
27
|
+
/** Configuration values, array entries and object fields; defaults to 100,000, with depth limited to 32. */
|
|
28
|
+
readonly maxSetupNodes?: number;
|
|
29
|
+
}
|
|
30
|
+
/** One worker operation; call the normal format writer with these rows, sink, signal and progress callback. */
|
|
31
|
+
export interface WorkerExportContext {
|
|
32
|
+
readonly input: unknown;
|
|
33
|
+
readonly rows: AsyncIterable<readonly ExportValue[]>;
|
|
34
|
+
readonly sink: ByteSink;
|
|
35
|
+
readonly signal: AbortSignal;
|
|
36
|
+
readonly onProgress: (progress: ExportProgress) => void;
|
|
37
|
+
}
|
|
38
|
+
export type WorkerExportOperation = (context: WorkerExportContext) => Promise<ExportResult>;
|
|
39
|
+
/** Removes only the library's listeners and cancels the current operation; it never terminates the host's worker. */
|
|
40
|
+
export interface WorkerExportHandler {
|
|
41
|
+
dispose(reason?: unknown): void;
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ExportWorkerEndpoint, WorkerExportHandler, WorkerExportOperation } from "./types.js";
|
|
2
|
+
/** Install reusable transport on a host-created worker. The operation owns format selection and ordinary writer options. */
|
|
3
|
+
export declare function handleWorkerExports(endpoint: ExportWorkerEndpoint, operation: WorkerExportOperation): WorkerExportHandler;
|