@agile-team/mach-report 2.5.0 → 2.7.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.
Files changed (86) hide show
  1. package/README.md +126 -16
  2. package/dist/ReportPreview-BdvoqdOd.cjs +6 -0
  3. package/dist/ReportPreview-COFkbeEM.js +3719 -0
  4. package/dist/_plugin-vue_export-helper-BHFhmbuH.cjs +1 -0
  5. package/dist/_plugin-vue_export-helper-CHgC5LLL.js +9 -0
  6. package/dist/analytics.cjs +1 -0
  7. package/dist/analytics.d.cts +276 -0
  8. package/dist/analytics.d.ts +276 -0
  9. package/dist/analytics.js +223 -0
  10. package/dist/assets-B9qJku3V.js +160 -0
  11. package/dist/assets-RZan7EyL.cjs +1 -0
  12. package/dist/capabilities-joSutDF8.js +63 -0
  13. package/dist/capabilities-xGTpnPjJ.cjs +1 -0
  14. package/dist/designer.cjs +1 -0
  15. package/dist/designer.d.cts +869 -0
  16. package/dist/designer.d.ts +869 -0
  17. package/dist/designer.js +628 -0
  18. package/dist/index.cjs +8 -5
  19. package/dist/index.d.cts +497 -9
  20. package/dist/index.d.ts +497 -9
  21. package/dist/index.js +1088 -1499
  22. package/dist/param-validation-BWNjLcN0.js +116 -0
  23. package/dist/param-validation-CiTxFeZ8.cjs +1 -0
  24. package/dist/pdf.cjs +48 -48
  25. package/dist/pdf.d.cts +119 -1
  26. package/dist/pdf.d.ts +119 -1
  27. package/dist/pdf.js +3932 -3868
  28. package/dist/{plugin-DMPLDpBY.cjs → plugin-9t_ZFwhz.cjs} +1 -1
  29. package/dist/{plugin-DDLcFWlk.js → plugin-s8Ay8kKk.js} +2 -2
  30. package/dist/progress-DD964VAB.js +102 -0
  31. package/dist/progress-KvhwXZ1Q.cjs +1 -0
  32. package/dist/render-plan-CckPEQyf.cjs +1 -0
  33. package/dist/{render-plan-CXBWRog4.js → render-plan-uzZYYSy1.js} +11 -10
  34. package/dist/report-params-B_VCihAh.js +12 -0
  35. package/dist/report-params-CjWrjPl6.cjs +1 -0
  36. package/dist/report-source-BXHNy_AD.js +755 -0
  37. package/dist/report-source-CCAvFE3t.cjs +1 -0
  38. package/dist/server/node.d.cts +320 -0
  39. package/dist/server/node.d.ts +320 -0
  40. package/dist/server-node.cjs +1 -0
  41. package/dist/server-node.js +303 -0
  42. package/dist/server.cjs +1 -0
  43. package/dist/server.d.cts +668 -0
  44. package/dist/server.d.ts +668 -0
  45. package/dist/server.js +245 -0
  46. package/dist/style-CpwiOPyB.cjs +1 -0
  47. package/dist/style-Dv5o_x6b.js +67 -0
  48. package/dist/style.css +1 -1
  49. package/dist/task-events-DQ276fn2.cjs +1 -0
  50. package/dist/task-events-Dpsvf_t2.js +47 -0
  51. package/dist/template-registry-DWExx0gU.cjs +1 -0
  52. package/dist/template-registry-NpOakidD.js +354 -0
  53. package/dist/textwrap-CnGsEum6.cjs +4 -0
  54. package/dist/textwrap-DOl04hCQ.js +110 -0
  55. package/dist/validate-DfHPD8wX.cjs +1 -0
  56. package/dist/validate-S6CgIm5d.js +148 -0
  57. package/dist/vue/async.d.cts +1507 -1538
  58. package/dist/vue/async.d.ts +1507 -1538
  59. package/dist/vue/index.d.cts +2376 -2347
  60. package/dist/vue/index.d.ts +2376 -2347
  61. package/dist/vue-async.cjs +1 -1
  62. package/dist/vue-async.js +3 -3
  63. package/dist/vue.cjs +1 -1
  64. package/dist/vue.js +184 -75
  65. package/dist/worker.cjs +1 -0
  66. package/dist/worker.d.cts +325 -0
  67. package/dist/worker.d.ts +325 -0
  68. package/dist/worker.js +158 -0
  69. package/dist/xlsx/node.d.cts +47 -0
  70. package/dist/xlsx/node.d.ts +47 -0
  71. package/dist/xlsx-node.cjs +221 -0
  72. package/dist/xlsx-node.js +36409 -0
  73. package/dist/xlsx.cjs +20 -20
  74. package/dist/xlsx.d.cts +87 -2
  75. package/dist/xlsx.d.ts +87 -2
  76. package/dist/xlsx.js +5987 -5840
  77. package/package.json +63 -3
  78. package/dist/ReportPreview-CBKLI--k.js +0 -2188
  79. package/dist/ReportPreview-ClM8h0pM.cjs +0 -6
  80. package/dist/grid-geometry-BNIvw52m.cjs +0 -1
  81. package/dist/grid-geometry-C8hGoe9o.js +0 -130
  82. package/dist/render-plan-CCTL4F9v.cjs +0 -1
  83. package/dist/report-params-B3Fia6JO.js +0 -10
  84. package/dist/report-params-D1gZ1DME.cjs +0 -1
  85. package/dist/textwrap-nH0UYU6D.js +0 -108
  86. package/dist/textwrap-oD-t4b4B.cjs +0 -4
@@ -0,0 +1,320 @@
1
+ /// <reference types="node" />
2
+
3
+ import { WorkerOptions as WorkerOptions_2 } from 'node:worker_threads';
4
+
5
+ declare type ComponentKind = "text" | "image" | "barcode" | "qrcode" | "chart" | "line" | "rect" | "ellipse";
6
+
7
+ declare interface ComponentStyle {
8
+ fontSizePx?: number;
9
+ fontSize?: number;
10
+ fontFamily?: string;
11
+ bold?: boolean;
12
+ italic?: boolean;
13
+ underline?: boolean;
14
+ color?: string;
15
+ backgroundColor?: string;
16
+ align?: "left" | "center" | "right" | "justify";
17
+ verticalAlign?: "top" | "middle" | "bottom";
18
+ lineColor?: string;
19
+ borderColor?: string;
20
+ lineWidthPt?: number;
21
+ borderTop?: boolean;
22
+ borderRight?: boolean;
23
+ borderBottom?: boolean;
24
+ borderLeft?: boolean;
25
+ lineHeight?: number;
26
+ letterSpacing?: number;
27
+ opacity?: number;
28
+ rotateDeg?: number;
29
+ }
30
+
31
+ /** 独立 worker_threads 适配器;worker 入口注册自己的模板/Provider,不把函数跨线程序列化。 */
32
+ export declare function createNodeReportExecutor(options: NodeReportExecutorOptions): ReportRuntimeExecutor;
33
+
34
+ declare interface GridCell {
35
+ text?: string;
36
+ rawText?: string;
37
+ /** 原始值,仅供 Excel raw 模式消费;不参与预览、分页与 PDF 绘制。 */
38
+ value?: string | number | boolean | null;
39
+ /** Excel 数字格式(例如 #,##0.00 / 0.00%),不改变 text。 */
40
+ numberFormat?: string;
41
+ /** 编辑输入类型;省略时只按原始值推断,数字字符串不会被转换为数值。 */
42
+ valueType?: "text" | "number" | "boolean";
43
+ /** 单元格级编辑控制;预览仍需显式开启 editing。 */
44
+ editable?: boolean;
45
+ source?: ReportCellSource;
46
+ /** Excel 公式保留元数据;当前引擎不计算公式,公式格始终只读。 */
47
+ formula?: string;
48
+ children?: PlanComponent[];
49
+ colSpan?: number;
50
+ rowSpan?: number;
51
+ style?: ComponentStyle;
52
+ }
53
+
54
+ export declare interface NodeReportExecutorOptions extends ReportWorkerOptions {
55
+ filename?: string | URL;
56
+ workerUrl?: string | URL;
57
+ workerOptions?: WorkerOptions_2;
58
+ }
59
+
60
+ declare interface PlanComponent {
61
+ kind: ComponentKind;
62
+ leftMm: number;
63
+ topMm: number;
64
+ widthMm: number;
65
+ heightMm: number;
66
+ nid?: string;
67
+ rkey?: string;
68
+ text?: string;
69
+ rawText?: string;
70
+ lines?: string[];
71
+ richParagraphs?: RichParagraph[];
72
+ imageData?: string;
73
+ /** 明确指定线段方向;省略保持历史水平线行为。 */
74
+ lineDirection?: "down" | "up";
75
+ grid?: PlanGrid;
76
+ table?: PlanTableFragment;
77
+ style?: ComponentStyle;
78
+ meta?: Record<string, unknown>;
79
+ /** MachReport 扩展字段:未知 kind 的兜底渲染标记 */
80
+ fallbackText?: string;
81
+ }
82
+
83
+ declare interface PlanGrid {
84
+ /** 行内允许 null 空位;渲染器按空单元格处理 */
85
+ cells: (GridCell | null)[][];
86
+ colWidthsMm?: number[];
87
+ rowHeightsMm?: number[];
88
+ gapMm?: number;
89
+ /** 单元格四边内距;旧静态网格默认 0.5mm,分页列表使用其真实测量内距。 */
90
+ paddingMm?: number;
91
+ }
92
+
93
+ declare interface PlanPage {
94
+ /** wide 表示完整自然列宽;页面仅为预览的垂直窗口分段。 */
95
+ layout?: "page" | "wide";
96
+ pageWidthMm: number;
97
+ pageHeightMm: number;
98
+ marginTopMm?: number;
99
+ marginBottomMm?: number;
100
+ marginLeftMm?: number;
101
+ marginRightMm?: number;
102
+ components: PlanComponent[];
103
+ }
104
+
105
+ /** 列表的逻辑行来源;用于连续 Excel 重组,避免按文本猜测重复表头。 */
106
+ declare interface PlanTableFragment {
107
+ /** 在整个计划中唯一的逻辑表身份;同一表的分页片段共享身份。 */
108
+ id: string;
109
+ /** 表头固定 -1;其余行(包括组头/小计/总计)从 0 连续递增。 */
110
+ rowIndex: number;
111
+ role: "header" | "body" | "group-header" | "subtotal" | "grand-total";
112
+ /** 按物理列顺序保存字段身份;不以表头显示文本判断列结构。 */
113
+ columnKeys: string[];
114
+ layout?: "page" | "wide";
115
+ title?: string;
116
+ /** 只有宿主声明稳定 rowKey 时生成,不能用显示顺序替代业务主键。 */
117
+ source?: Omit<ReportCellSource, "field" | "rowKey"> & {
118
+ rowKey?: string | number;
119
+ };
120
+ }
121
+
122
+ declare interface PreparedReport {
123
+ plan: RenderPlan;
124
+ diagnostics: ReportDiagnostic[];
125
+ stats: ReportRuntimeStats;
126
+ revisions: Record<string, {
127
+ revision?: string;
128
+ sourceToken?: string;
129
+ }>;
130
+ }
131
+
132
+ declare interface RenderPlan {
133
+ schemaVersion: string;
134
+ pages: PlanPage[];
135
+ }
136
+
137
+ /** 可持久化的业务身份与计划坐标独立;权限及并发校验仍由业务服务器执行。 */
138
+ declare interface ReportCellSource {
139
+ datasetId: string;
140
+ rowKey: string | number;
141
+ field: string;
142
+ revision?: string | number;
143
+ sourceToken?: string;
144
+ }
145
+
146
+ declare interface ReportDescription {
147
+ id: string;
148
+ params: ReportParamDef[];
149
+ paramsSchema: Record<string, unknown>;
150
+ datasetsSchema: Record<string, Record<string, unknown>>;
151
+ /** Provider 的可选远程能力;runtime 自身始终提供 PDF/XLSX 导出。 */
152
+ capabilities: {
153
+ save: boolean;
154
+ export: boolean;
155
+ templates: boolean;
156
+ };
157
+ }
158
+
159
+ declare interface ReportDiagnostic {
160
+ code: string;
161
+ message: string;
162
+ path?: string;
163
+ severity: "warning" | "error" | "info";
164
+ }
165
+
166
+ /** 报表参数定义(声明式,模板自描述参数面:渲染组件据此生成查询面板) */
167
+ declare interface ReportParamDef {
168
+ /** 参数名(传入 params,与数据集 SQL #{field} 绑定对应) */
169
+ field: string;
170
+ /** 显示名(缺省用 field) */
171
+ label?: string;
172
+ type?: "text" | "number" | "date" | "select";
173
+ /** select 选项 */
174
+ options?: Array<{
175
+ label: string;
176
+ value: string;
177
+ }>;
178
+ defaultValue?: string;
179
+ required?: boolean;
180
+ placeholder?: string;
181
+ /** 数字上下界;date 参数使用 YYYY-MM-DD 字符串(含边界)。 */
182
+ min?: number | string;
183
+ max?: number | string;
184
+ minLength?: number;
185
+ maxLength?: number;
186
+ }
187
+
188
+ declare interface ReportParamIssue {
189
+ code: ReportParamIssueCode;
190
+ path: string;
191
+ field: string;
192
+ message: string;
193
+ }
194
+
195
+ declare type ReportParamIssueCode = "definition" | "required" | "type" | "option" | "minimum" | "maximum" | "minLength" | "maxLength";
196
+
197
+ declare interface ReportParamValidation {
198
+ ok: boolean;
199
+ /** 保留历史取数契约的字符串形式;未知参数保留,不能代替接口权限白名单。 */
200
+ values: Record<string, string>;
201
+ /** JSON Schema 对应的规范值:number 参数转换为有限数字。 */
202
+ typedValues: Record<string, string | number>;
203
+ issues: ReportParamIssue[];
204
+ }
205
+
206
+ declare interface ReportRuntime {
207
+ describe(reportIds?: string[]): ReportDescription[];
208
+ validate(input: Omit<ReportRuntimeInput, "signal">): ReportParamValidation;
209
+ prepare(input: ReportRuntimeInput): Promise<PreparedReport>;
210
+ export(input: ReportRuntimeExportInput): Promise<ReportRuntimeExportResult>;
211
+ }
212
+
213
+ /** 可用 worker_threads/进程/RPC 实现;接收可序列化请求,signal 由桥接层映射为取消消息。 */
214
+ declare interface ReportRuntimeExecutor {
215
+ prepare(input: Omit<ReportRuntimeInput, "signal" | "onEvent">, signal?: AbortSignal, onEvent?: ReportTaskObserver): Promise<PreparedReport>;
216
+ export(input: Omit<ReportRuntimeExportInput, "signal" | "onEvent">, signal?: AbortSignal, onEvent?: ReportTaskObserver): Promise<ReportRuntimeExportResult>;
217
+ }
218
+
219
+ declare interface ReportRuntimeExportInput extends ReportRuntimeInput {
220
+ format: "pdf" | "xlsx";
221
+ /** strict 在编码前拒绝已识别的输出降级;默认保留诊断并继续。 */
222
+ fidelity?: "warn" | "strict";
223
+ /** PDF 中文需宿主显式提供有授权的字体;不隐式下载字体或资源。 */
224
+ pdf?: {
225
+ customFontBytes?: Uint8Array | ArrayBuffer;
226
+ customFontName?: string;
227
+ customFontFaces?: {
228
+ regular: Uint8Array | ArrayBuffer;
229
+ bold?: Uint8Array | ArrayBuffer;
230
+ italic?: Uint8Array | ArrayBuffer;
231
+ boldItalic?: Uint8Array | ArrayBuffer;
232
+ };
233
+ };
234
+ xlsx?: {
235
+ sheetMode?: "auto" | "pages" | "continuous";
236
+ valueMode?: "text" | "raw";
237
+ paperSize?: "auto" | "a3" | "a4" | "a5";
238
+ };
239
+ }
240
+
241
+ declare interface ReportRuntimeExportResult extends Omit<PreparedReport, "plan"> {
242
+ bytes: Uint8Array;
243
+ format: "pdf" | "xlsx";
244
+ contentType: string;
245
+ }
246
+
247
+ declare interface ReportRuntimeInput extends ReportTaskMonitoring {
248
+ reportIds: string[];
249
+ params?: Record<string, string>;
250
+ signal?: AbortSignal;
251
+ }
252
+
253
+ declare interface ReportRuntimeStats {
254
+ rows: number;
255
+ pages: number;
256
+ cells: number;
257
+ durationMs: number;
258
+ outputBytes?: number;
259
+ }
260
+
261
+ /** 阶段事件只包含可序列化值;不表示估算百分比,也不包含业务数据。 */
262
+ declare interface ReportTaskEvent {
263
+ taskId: string;
264
+ correlationId?: string;
265
+ stage: "query" | "validate" | "layout" | "encode";
266
+ status: "started" | "completed" | "failed";
267
+ reportId?: string;
268
+ completed?: number;
269
+ total?: number;
270
+ }
271
+
272
+ declare interface ReportTaskMonitoring {
273
+ taskId?: string;
274
+ correlationId?: string;
275
+ onEvent?: ReportTaskObserver;
276
+ }
277
+
278
+ declare type ReportTaskObserver = (event: ReportTaskEvent) => void;
279
+
280
+ export declare class ReportWorkerError extends Error {
281
+ readonly code?: string;
282
+ readonly path?: string;
283
+ readonly issues?: unknown;
284
+ readonly diagnostics?: unknown;
285
+ constructor(error: SerializedReportError);
286
+ }
287
+
288
+ declare interface ReportWorkerOptions {
289
+ timeoutMs?: number;
290
+ }
291
+
292
+ declare interface RichParagraph {
293
+ segments: RichSegment[];
294
+ align?: ComponentStyle["align"];
295
+ lineHeight?: number;
296
+ spaceBeforeMm?: number;
297
+ spaceAfterMm?: number;
298
+ indentMm?: number;
299
+ }
300
+
301
+ declare interface RichSegment {
302
+ kind?: "text" | "field";
303
+ text?: string;
304
+ field?: string;
305
+ style?: ComponentStyle;
306
+ }
307
+
308
+ declare interface SerializedReportError {
309
+ name: string;
310
+ message: string;
311
+ code?: string;
312
+ path?: string;
313
+ issues?: unknown;
314
+ diagnostics?: unknown;
315
+ }
316
+
317
+ /** Node Worker 入口调用;主线程调用会明确报错。 */
318
+ export declare function serveNodeReportWorker(runtime: ReportRuntime): () => void;
319
+
320
+ export { }
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("node:worker_threads");function P(e,t,r){if(!r?.aborted)try{const o=e?.({...t});o&&typeof o.then=="function"&&Promise.resolve(o).catch(()=>{})}catch{}}function T(e,t,r){e.editable!==void 0&&typeof e.editable!="boolean"&&r.push({path:`${t}.editable`,message:"编辑控制应为布尔值"}),e.valueType!==void 0&&!["text","number","boolean"].includes(e.valueType)&&r.push({path:`${t}.valueType`,message:"编辑类型应为 text、number 或 boolean"})}function v(e,t,r){T(e,t,r),x(e.source,`${t}.source`,r,!0),e.formula!==void 0&&typeof e.formula!="string"&&r.push({path:`${t}.formula`,message:"单元格公式应为字符串"})}function x(e,t,r,o=!1){if(e===void 0)return;if(!e||typeof e!="object"||Array.isArray(e)){r.push({path:t,message:"业务来源应为对象"});return}const s=e;for(const n of["datasetId",...o?["field"]:[]])(typeof s[n]!="string"||!s[n].trim())&&r.push({path:`${t}.${n}`,message:"业务标识应为非空字符串"});for(const n of["rowKey","revision"]){const i=s[n];i===void 0&&!(o&&n==="rowKey")||typeof i!="string"&&!(typeof i=="number"&&Number.isFinite(i))&&r.push({path:`${t}.${n}`,message:"业务键及修订号应为字符串或有限数字"})}s.sourceToken!==void 0&&typeof s.sourceToken!="string"&&r.push({path:`${t}.sourceToken`,message:"来源令牌应为字符串"})}const O=new Set(["text","image","barcode","qrcode","chart","line","rect","ellipse"]);function d(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function S(e,t,r,o){const s=e[t];(typeof s!="number"||!Number.isFinite(s))&&o.push({path:`${r}.${t}`,message:`应为有限数字,实际 ${JSON.stringify(s)}`})}function j(e,t,r){if(e!==void 0){const o=`${t}.table`;if(!d(e))r.push({path:o,message:"逻辑表来源应为对象"});else{x(e.source,`${o}.source`,r),(typeof e.id!="string"||!e.id.trim())&&r.push({path:`${o}.id`,message:"逻辑表 ID 应为非空字符串"});const s=e.role;["header","body","group-header","subtotal","grand-total"].includes(s)||r.push({path:`${o}.role`,message:"未知逻辑表行角色"});const n=e.rowIndex;(typeof n!="number"||!Number.isInteger(n)||(s==="header"?n!==-1:n<0))&&r.push({path:`${o}.rowIndex`,message:"表头索引应为 -1,内容行索引应为非负整数"}),(!Array.isArray(e.columnKeys)||e.columnKeys.some(i=>typeof i!="string"))&&r.push({path:`${o}.columnKeys`,message:"逻辑列字段应为字符串数组"}),e.layout!==void 0&&e.layout!=="page"&&e.layout!=="wide"&&r.push({path:`${o}.layout`,message:"布局应为 page 或 wide"}),e.title!==void 0&&typeof e.title!="string"&&r.push({path:`${o}.title`,message:"逻辑表名称应为字符串"})}}}function K(e,t,r,o){if(e!==void 0)if(!d(e)||!Array.isArray(e.cells))r.push({path:`${t}.grid.cells`,message:"grid.cells 应为二维数组"});else{const s=e.paddingMm;s!==void 0&&(typeof s!="number"||!Number.isFinite(s)||s<0)&&r.push({path:`${t}.grid.paddingMm`,message:"单元格内距应为有限非负数"}),e.cells.forEach((n,i)=>{if(!Array.isArray(n)){r.push({path:`${t}.grid.cells.${i}`,message:"行应为数组"});return}n.forEach((c,m)=>{if(c==null)return;const g=`${t}.grid.cells.${i}.${m}`;if(!d(c)){r.push({path:g,message:"网格单元格应为对象或 null"});return}v(c,g,r),Array.isArray(c.children)&&c.children.forEach((y,b)=>{I(y,`${t}.grid.cells.${i}.${m}.children.${b}`,r,o)})})})}}function _(e,t,r){e!==void 0&&(Array.isArray(e)?e.forEach((o,s)=>{(!d(o)||!Array.isArray(o.segments))&&r.push({path:`${t}.richParagraphs.${s}`,message:"段落缺少 segments 数组"})}):r.push({path:`${t}.richParagraphs`,message:"richParagraphs 应为数组"}))}function I(e,t,r,o=[]){if(!d(e)){r.push({path:t,message:"组件应为对象"});return}const s=e.kind;typeof s!="string"?r.push({path:`${t}.kind`,message:"组件缺少 kind 字符串"}):O.has(s)||o.push({path:`${t}.kind`,message:`未知组件类型 ${JSON.stringify(s)},将以兜底方式渲染`});for(const n of["leftMm","topMm","widthMm","heightMm"])S(e,n,t,r);typeof e.leftMm=="number"&&e.leftMm<-100&&r.push({path:`${t}.leftMm`,message:"几何数值异常(leftMm<-100)"});for(const n of["widthMm","heightMm"])typeof e[n]=="number"&&e[n]<0&&r.push({path:`${t}.${n}`,message:"组件尺寸不能为负数"});j(e.table,t,r),e.lineDirection!==void 0&&!["down","up"].includes(e.lineDirection)&&r.push({path:`${t}.lineDirection`,message:"线段方向应为 down 或 up"}),K(e.grid,t,r,o),_(e.richParagraphs,t,r)}function D(e,t,r,o=[]){if(!d(e)){r.push({path:t,message:"页应为对象"});return}const s=e.pageWidthMm,n=e.pageHeightMm;(typeof s!="number"||!Number.isFinite(s)||s<=0)&&r.push({path:`${t}.pageWidthMm`,message:`页宽非法: ${JSON.stringify(s)}`}),(typeof n!="number"||!(n>0&&n<5e3))&&r.push({path:`${t}.pageHeightMm`,message:`页高非法: ${JSON.stringify(n)}`}),e.layout!==void 0&&e.layout!=="page"&&e.layout!=="wide"&&r.push({path:`${t}.layout`,message:"布局应为 page 或 wide"});const i=e.components;Array.isArray(i)?Array.isArray(i)&&i.forEach((c,m)=>I(c,`${t}.components.${m}`,r,o)):r.push({path:`${t}.components`,message:"components 应为数组"})}function F(e){const t=[],r=[],o=d(e)?e.pages:void 0;if(!Array.isArray(o))t.push({path:"$.pages",message:e==null?"渲染计划为空":"渲染计划缺少 pages 数组"});else{o.forEach((n,i)=>D(n,`$.pages.${i}`,t,r)),o.length>2e3&&r.push({path:"$.pages",message:`页数异常大(${o.length} 页),渲染与打印耗时可能显著增加`});const s=o.reduce((n,i)=>n+(d(i)&&Array.isArray(i.components)?i.components.length:0),0);s>5e4&&r.push({path:"$.pages",message:`组件总数异常大(${s} 个),可能触发浏览器性能限制`})}return{ok:t.length===0,errors:t,warnings:r}}const l="mach-report-worker/1";class E extends Error{constructor(t){super(t.message),this.name=t.name,this.code=t.code,this.path=t.path,this.issues=t.issues,this.diagnostics=t.diagnostics}}function u(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function z(e){return u(e)?["rows","pages","cells"].every(t=>typeof e[t]=="number"&&Number.isSafeInteger(e[t])&&e[t]>=0)&&typeof e.durationMs=="number"&&Number.isFinite(e.durationMs)&&e.durationMs>=0:!1}function C(e){return Array.isArray(e)&&e.every(t=>u(t)&&typeof t.code=="string"&&typeof t.message=="string"&&["info","warning","error"].includes(t.severity))}function J(e){return u(e)&&Object.values(e).every(t=>u(t)&&(t.revision===void 0||typeof t.revision=="string")&&(t.sourceToken===void 0||typeof t.sourceToken=="string"))}function L(e,t){if(!u(e)||!z(e.stats)||!C(e.diagnostics)||!J(e.revisions))return!1;if(t==="prepare")return F(e.plan).ok;const r=e.format==="pdf"?"application/pdf":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";return e.bytes instanceof Uint8Array&&(e.format==="pdf"||e.format==="xlsx")&&e.contentType===r}function N(e){if(!e||typeof e!="object")return{message:String(e)};const t={};for(const r of["code","path","field","message"]){const o=e[r];typeof o=="string"&&(t[r]=o)}return t}function U(e){const t=N(e);if(!u(e))return t;for(const r of["format","severity","kind","nid"])typeof e[r]=="string"&&(t[r]=e[r]);for(const r of["pageIndex","componentIndex"])Number.isSafeInteger(e[r])&&e[r]>=0&&(t[r]=e[r]);return Array.isArray(e.componentPath)&&e.componentPath.every(r=>Number.isSafeInteger(r)&&r>=0)&&(t.componentPath=e.componentPath),t}function q(e){if(!(e instanceof Error))return{name:"Error",message:String(e)};const t=e;return{name:e.name,message:e.message,...typeof t.code=="string"?{code:t.code}:{},...typeof t.path=="string"?{path:t.path}:{},...Array.isArray(t.issues)?{issues:t.issues.map(N)}:{},...Array.isArray(t.diagnostics)?{diagnostics:t.diagnostics.map(U)}:{}}}function B(e){if(!e||typeof e!="object")return!1;const t=e;return t.protocol===l&&typeof t.id=="string"&&(t.operation==="prepare"||t.operation==="export")&&!!t.input&&typeof t.input=="object"}async function G(e,t,r){try{const o=t.operation==="prepare"?await e.prepare({...t.input,onEvent:r}):await e.export({...t.input,onEvent:r});return{protocol:l,id:t.id,result:o}}catch(o){return{protocol:l,id:t.id,error:q(o)}}}function H(e){const t=e.result;return!t||!("bytes"in t)||!(t.bytes.buffer instanceof ArrayBuffer)?[]:[t.bytes.buffer]}function Q(e,t){if(!u(e)||typeof e.taskId!="string"||!e.taskId||t.taskId!==void 0&&e.taskId!==t.taskId||e.correlationId!==t.correlationId||e.reportId!==void 0&&(typeof e.reportId!="string"||!t.reportIds.includes(e.reportId))||!["query","validate","layout","encode"].includes(e.stage)||!["started","completed","failed"].includes(e.status))return!1;for(const r of["completed","total"])if(e[r]!==void 0&&(typeof e[r]!="number"||!Number.isFinite(e[r])||e[r]<0))return!1;return e.completed===void 0||e.total===void 0||e.completed<=e.total}let V=0;function M(e){const t=new Error("报表 Worker 任务已取消");return t.name="AbortError",Object.defineProperty(t,"cause",{value:e}),t}function X(e,t){if(!e||typeof e!="object")return;const r=e;return r.protocol===l&&r.id===t?r:void 0}function Y(e,t={}){const r=t.timeoutMs??12e4;if(!Number.isFinite(r)||r<=0||r>2147483647)throw new RangeError("Worker timeoutMs 应为正有限数字,且不能超过 2147483647");const o=(s,n,i,c)=>i?.aborted?Promise.reject(M(i.reason)):new Promise((m,g)=>{let y;try{y=e()}catch(f){g(f);return}const b=`mach-report-${Date.now()}-${++V}`;let $=!1,k=()=>{},w;const p=(f,a)=>{$||($=!0,w&&clearTimeout(w),k(),i?.removeEventListener("abort",A),Promise.resolve().then(()=>y.terminate()).then(()=>f===void 0?m(a):g(f),h=>g(f??h)))},A=()=>p(M(i?.reason)),W=f=>{const a=X(f,b);if(!(!a||$)){if("type"in a&&a.type==="event"){const h="event"in a?a.event:void 0;Q(h,n)?P(c,h,i):p(new Error("报表 Worker 返回无效阶段事件"));return}a.error&&typeof a.error.name=="string"&&typeof a.error.message=="string"?p(new E(a.error)):L(a.result,s)&&(s!=="export"||"format"in a.result&&"format"in n&&a.result.format===n.format)?p(void 0,a.result):p(new Error("报表 Worker 返回无效响应"))}};try{if(k=y.subscribe(W,f=>p(f??new Error("报表 Worker 执行失败"))),$){k();return}if(i?.addEventListener("abort",A,{once:!0}),w=setTimeout(()=>p(new E({name:"ReportRuntimeError",code:"timeout",message:`报表 Worker 执行超过 ${r}ms`})),r),i?.aborted)A();else{const{onEvent:f,signal:a,...h}=n;y.postMessage({protocol:l,id:b,operation:s,input:h})}}catch(f){p(f)}});return{prepare:(s,n,i)=>o("prepare",s,n,i),export:(s,n,i)=>o("export",s,n,i)}}function Z(e){const t=e.filename??e.workerUrl;if(!t||e.filename&&e.workerUrl)throw new TypeError("请且仅请指定 filename 或 workerUrl");return Y(()=>{const r=new R.Worker(t,e.workerOptions);return{postMessage:o=>r.postMessage(o),terminate:()=>r.terminate(),subscribe:(o,s)=>{const n=i=>s(new Error(`报表 Worker 在响应前退出(code ${i})`));return r.on("message",o),r.on("error",s),r.on("messageerror",s),r.on("exit",n),()=>{r.off("message",o),r.off("error",s),r.off("messageerror",s),r.off("exit",n)}}}},e)}function ee(e){const t=R.parentPort;if(!t)throw new Error("serveNodeReportWorker 只能在 worker_threads 中调用");const r=o=>{B(o)&&G(e,o,s=>t.postMessage({protocol:l,id:o.id,type:"event",event:s})).then(s=>t.postMessage(s,H(s)))};return t.on("message",r),()=>t.off("message",r)}exports.ReportWorkerError=E;exports.createNodeReportExecutor=Z;exports.serveNodeReportWorker=ee;
@@ -0,0 +1,303 @@
1
+ import { parentPort as W, Worker as P } from "node:worker_threads";
2
+ function T(e, t, r) {
3
+ if (!r?.aborted)
4
+ try {
5
+ const o = e?.({ ...t });
6
+ o && typeof o.then == "function" && Promise.resolve(o).catch(() => {
7
+ });
8
+ } catch {
9
+ }
10
+ }
11
+ function v(e, t, r) {
12
+ e.editable !== void 0 && typeof e.editable != "boolean" && r.push({ path: `${t}.editable`, message: "编辑控制应为布尔值" }), e.valueType !== void 0 && !["text", "number", "boolean"].includes(e.valueType) && r.push({ path: `${t}.valueType`, message: "编辑类型应为 text、number 或 boolean" });
13
+ }
14
+ function O(e, t, r) {
15
+ v(e, t, r), x(e.source, `${t}.source`, r, !0), e.formula !== void 0 && typeof e.formula != "string" && r.push({ path: `${t}.formula`, message: "单元格公式应为字符串" });
16
+ }
17
+ function x(e, t, r, o = !1) {
18
+ if (e === void 0) return;
19
+ if (!e || typeof e != "object" || Array.isArray(e)) {
20
+ r.push({ path: t, message: "业务来源应为对象" });
21
+ return;
22
+ }
23
+ const s = e;
24
+ for (const n of ["datasetId", ...o ? ["field"] : []])
25
+ (typeof s[n] != "string" || !s[n].trim()) && r.push({ path: `${t}.${n}`, message: "业务标识应为非空字符串" });
26
+ for (const n of ["rowKey", "revision"]) {
27
+ const i = s[n];
28
+ i === void 0 && !(o && n === "rowKey") || typeof i != "string" && !(typeof i == "number" && Number.isFinite(i)) && r.push({ path: `${t}.${n}`, message: "业务键及修订号应为字符串或有限数字" });
29
+ }
30
+ s.sourceToken !== void 0 && typeof s.sourceToken != "string" && r.push({ path: `${t}.sourceToken`, message: "来源令牌应为字符串" });
31
+ }
32
+ const S = /* @__PURE__ */ new Set([
33
+ "text",
34
+ "image",
35
+ "barcode",
36
+ "qrcode",
37
+ "chart",
38
+ "line",
39
+ "rect",
40
+ "ellipse"
41
+ ]);
42
+ function d(e) {
43
+ return typeof e == "object" && e !== null && !Array.isArray(e);
44
+ }
45
+ function j(e, t, r, o) {
46
+ const s = e[t];
47
+ (typeof s != "number" || !Number.isFinite(s)) && o.push({ path: `${r}.${t}`, message: `应为有限数字,实际 ${JSON.stringify(s)}` });
48
+ }
49
+ function K(e, t, r) {
50
+ if (e !== void 0) {
51
+ const o = `${t}.table`;
52
+ if (!d(e)) r.push({ path: o, message: "逻辑表来源应为对象" });
53
+ else {
54
+ x(e.source, `${o}.source`, r), (typeof e.id != "string" || !e.id.trim()) && r.push({ path: `${o}.id`, message: "逻辑表 ID 应为非空字符串" });
55
+ const s = e.role;
56
+ ["header", "body", "group-header", "subtotal", "grand-total"].includes(s) || r.push({ path: `${o}.role`, message: "未知逻辑表行角色" });
57
+ const n = e.rowIndex;
58
+ (typeof n != "number" || !Number.isInteger(n) || (s === "header" ? n !== -1 : n < 0)) && r.push({ path: `${o}.rowIndex`, message: "表头索引应为 -1,内容行索引应为非负整数" }), (!Array.isArray(e.columnKeys) || e.columnKeys.some((i) => typeof i != "string")) && r.push({ path: `${o}.columnKeys`, message: "逻辑列字段应为字符串数组" }), e.layout !== void 0 && e.layout !== "page" && e.layout !== "wide" && r.push({ path: `${o}.layout`, message: "布局应为 page 或 wide" }), e.title !== void 0 && typeof e.title != "string" && r.push({ path: `${o}.title`, message: "逻辑表名称应为字符串" });
59
+ }
60
+ }
61
+ }
62
+ function D(e, t, r, o) {
63
+ if (e !== void 0)
64
+ if (!d(e) || !Array.isArray(e.cells))
65
+ r.push({ path: `${t}.grid.cells`, message: "grid.cells 应为二维数组" });
66
+ else {
67
+ const s = e.paddingMm;
68
+ s !== void 0 && (typeof s != "number" || !Number.isFinite(s) || s < 0) && r.push({ path: `${t}.grid.paddingMm`, message: "单元格内距应为有限非负数" }), e.cells.forEach((n, i) => {
69
+ if (!Array.isArray(n)) {
70
+ r.push({ path: `${t}.grid.cells.${i}`, message: "行应为数组" });
71
+ return;
72
+ }
73
+ n.forEach((c, m) => {
74
+ if (c == null) return;
75
+ const g = `${t}.grid.cells.${i}.${m}`;
76
+ if (!d(c)) {
77
+ r.push({ path: g, message: "网格单元格应为对象或 null" });
78
+ return;
79
+ }
80
+ O(c, g, r), Array.isArray(c.children) && c.children.forEach((y, $) => {
81
+ I(y, `${t}.grid.cells.${i}.${m}.children.${$}`, r, o);
82
+ });
83
+ });
84
+ });
85
+ }
86
+ }
87
+ function F(e, t, r) {
88
+ e !== void 0 && (Array.isArray(e) ? e.forEach((o, s) => {
89
+ (!d(o) || !Array.isArray(o.segments)) && r.push({ path: `${t}.richParagraphs.${s}`, message: "段落缺少 segments 数组" });
90
+ }) : r.push({ path: `${t}.richParagraphs`, message: "richParagraphs 应为数组" }));
91
+ }
92
+ function I(e, t, r, o = []) {
93
+ if (!d(e)) {
94
+ r.push({ path: t, message: "组件应为对象" });
95
+ return;
96
+ }
97
+ const s = e.kind;
98
+ typeof s != "string" ? r.push({ path: `${t}.kind`, message: "组件缺少 kind 字符串" }) : S.has(s) || o.push({
99
+ path: `${t}.kind`,
100
+ message: `未知组件类型 ${JSON.stringify(s)},将以兜底方式渲染`
101
+ });
102
+ for (const n of ["leftMm", "topMm", "widthMm", "heightMm"])
103
+ j(e, n, t, r);
104
+ typeof e.leftMm == "number" && e.leftMm < -100 && r.push({ path: `${t}.leftMm`, message: "几何数值异常(leftMm<-100)" });
105
+ for (const n of ["widthMm", "heightMm"])
106
+ typeof e[n] == "number" && e[n] < 0 && r.push({ path: `${t}.${n}`, message: "组件尺寸不能为负数" });
107
+ K(e.table, t, r), e.lineDirection !== void 0 && !["down", "up"].includes(e.lineDirection) && r.push({ path: `${t}.lineDirection`, message: "线段方向应为 down 或 up" }), D(e.grid, t, r, o), F(e.richParagraphs, t, r);
108
+ }
109
+ function _(e, t, r, o = []) {
110
+ if (!d(e)) {
111
+ r.push({ path: t, message: "页应为对象" });
112
+ return;
113
+ }
114
+ const s = e.pageWidthMm, n = e.pageHeightMm;
115
+ (typeof s != "number" || !Number.isFinite(s) || s <= 0) && r.push({ path: `${t}.pageWidthMm`, message: `页宽非法: ${JSON.stringify(s)}` }), (typeof n != "number" || !(n > 0 && n < 5e3)) && r.push({ path: `${t}.pageHeightMm`, message: `页高非法: ${JSON.stringify(n)}` }), e.layout !== void 0 && e.layout !== "page" && e.layout !== "wide" && r.push({ path: `${t}.layout`, message: "布局应为 page 或 wide" });
116
+ const i = e.components;
117
+ Array.isArray(i) ? Array.isArray(i) && i.forEach(
118
+ (c, m) => I(c, `${t}.components.${m}`, r, o)
119
+ ) : r.push({ path: `${t}.components`, message: "components 应为数组" });
120
+ }
121
+ function z(e) {
122
+ const t = [], r = [], o = d(e) ? e.pages : void 0;
123
+ if (!Array.isArray(o))
124
+ t.push({
125
+ path: "$.pages",
126
+ message: e == null ? "渲染计划为空" : "渲染计划缺少 pages 数组"
127
+ });
128
+ else {
129
+ o.forEach((n, i) => _(n, `$.pages.${i}`, t, r)), o.length > 2e3 && r.push({
130
+ path: "$.pages",
131
+ message: `页数异常大(${o.length} 页),渲染与打印耗时可能显著增加`
132
+ });
133
+ const s = o.reduce(
134
+ (n, i) => n + (d(i) && Array.isArray(i.components) ? i.components.length : 0),
135
+ 0
136
+ );
137
+ s > 5e4 && r.push({
138
+ path: "$.pages",
139
+ message: `组件总数异常大(${s} 个),可能触发浏览器性能限制`
140
+ });
141
+ }
142
+ return { ok: t.length === 0, errors: t, warnings: r };
143
+ }
144
+ const l = "mach-report-worker/1";
145
+ class E extends Error {
146
+ constructor(t) {
147
+ super(t.message), this.name = t.name, this.code = t.code, this.path = t.path, this.issues = t.issues, this.diagnostics = t.diagnostics;
148
+ }
149
+ }
150
+ function u(e) {
151
+ return !!e && typeof e == "object" && !Array.isArray(e);
152
+ }
153
+ function C(e) {
154
+ return u(e) ? ["rows", "pages", "cells"].every((t) => typeof e[t] == "number" && Number.isSafeInteger(e[t]) && e[t] >= 0) && typeof e.durationMs == "number" && Number.isFinite(e.durationMs) && e.durationMs >= 0 : !1;
155
+ }
156
+ function J(e) {
157
+ return Array.isArray(e) && e.every((t) => u(t) && typeof t.code == "string" && typeof t.message == "string" && ["info", "warning", "error"].includes(t.severity));
158
+ }
159
+ function L(e) {
160
+ return u(e) && Object.values(e).every((t) => u(t) && (t.revision === void 0 || typeof t.revision == "string") && (t.sourceToken === void 0 || typeof t.sourceToken == "string"));
161
+ }
162
+ function U(e, t) {
163
+ if (!u(e) || !C(e.stats) || !J(e.diagnostics) || !L(e.revisions)) return !1;
164
+ if (t === "prepare") return z(e.plan).ok;
165
+ const r = e.format === "pdf" ? "application/pdf" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
166
+ return e.bytes instanceof Uint8Array && (e.format === "pdf" || e.format === "xlsx") && e.contentType === r;
167
+ }
168
+ function R(e) {
169
+ if (!e || typeof e != "object") return { message: String(e) };
170
+ const t = {};
171
+ for (const r of ["code", "path", "field", "message"]) {
172
+ const o = e[r];
173
+ typeof o == "string" && (t[r] = o);
174
+ }
175
+ return t;
176
+ }
177
+ function q(e) {
178
+ const t = R(e);
179
+ if (!u(e)) return t;
180
+ for (const r of ["format", "severity", "kind", "nid"]) typeof e[r] == "string" && (t[r] = e[r]);
181
+ for (const r of ["pageIndex", "componentIndex"]) Number.isSafeInteger(e[r]) && e[r] >= 0 && (t[r] = e[r]);
182
+ return Array.isArray(e.componentPath) && e.componentPath.every((r) => Number.isSafeInteger(r) && r >= 0) && (t.componentPath = e.componentPath), t;
183
+ }
184
+ function B(e) {
185
+ if (!(e instanceof Error)) return { name: "Error", message: String(e) };
186
+ const t = e;
187
+ return {
188
+ name: e.name,
189
+ message: e.message,
190
+ ...typeof t.code == "string" ? { code: t.code } : {},
191
+ ...typeof t.path == "string" ? { path: t.path } : {},
192
+ ...Array.isArray(t.issues) ? { issues: t.issues.map(R) } : {},
193
+ ...Array.isArray(t.diagnostics) ? { diagnostics: t.diagnostics.map(q) } : {}
194
+ };
195
+ }
196
+ function G(e) {
197
+ if (!e || typeof e != "object") return !1;
198
+ const t = e;
199
+ return t.protocol === l && typeof t.id == "string" && (t.operation === "prepare" || t.operation === "export") && !!t.input && typeof t.input == "object";
200
+ }
201
+ async function H(e, t, r) {
202
+ try {
203
+ const o = t.operation === "prepare" ? await e.prepare({ ...t.input, onEvent: r }) : await e.export({ ...t.input, onEvent: r });
204
+ return { protocol: l, id: t.id, result: o };
205
+ } catch (o) {
206
+ return { protocol: l, id: t.id, error: B(o) };
207
+ }
208
+ }
209
+ function Q(e) {
210
+ const t = e.result;
211
+ return !t || !("bytes" in t) || !(t.bytes.buffer instanceof ArrayBuffer) ? [] : [t.bytes.buffer];
212
+ }
213
+ function V(e, t) {
214
+ if (!u(e) || typeof e.taskId != "string" || !e.taskId || t.taskId !== void 0 && e.taskId !== t.taskId || e.correlationId !== t.correlationId || e.reportId !== void 0 && (typeof e.reportId != "string" || !t.reportIds.includes(e.reportId)) || !["query", "validate", "layout", "encode"].includes(e.stage) || !["started", "completed", "failed"].includes(e.status)) return !1;
215
+ for (const r of ["completed", "total"]) if (e[r] !== void 0 && (typeof e[r] != "number" || !Number.isFinite(e[r]) || e[r] < 0)) return !1;
216
+ return e.completed === void 0 || e.total === void 0 || e.completed <= e.total;
217
+ }
218
+ let X = 0;
219
+ function M(e) {
220
+ const t = new Error("报表 Worker 任务已取消");
221
+ return t.name = "AbortError", Object.defineProperty(t, "cause", { value: e }), t;
222
+ }
223
+ function Y(e, t) {
224
+ if (!e || typeof e != "object") return;
225
+ const r = e;
226
+ return r.protocol === l && r.id === t ? r : void 0;
227
+ }
228
+ function Z(e, t = {}) {
229
+ const r = t.timeoutMs ?? 12e4;
230
+ if (!Number.isFinite(r) || r <= 0 || r > 2147483647) throw new RangeError("Worker timeoutMs 应为正有限数字,且不能超过 2147483647");
231
+ const o = (s, n, i, c) => i?.aborted ? Promise.reject(M(i.reason)) : new Promise((m, g) => {
232
+ let y;
233
+ try {
234
+ y = e();
235
+ } catch (f) {
236
+ g(f);
237
+ return;
238
+ }
239
+ const $ = `mach-report-${Date.now()}-${++X}`;
240
+ let b = !1, k = () => {
241
+ }, w;
242
+ const p = (f, a) => {
243
+ b || (b = !0, w && clearTimeout(w), k(), i?.removeEventListener("abort", A), Promise.resolve().then(() => y.terminate()).then(
244
+ () => f === void 0 ? m(a) : g(f),
245
+ (h) => g(f ?? h)
246
+ ));
247
+ }, A = () => p(M(i?.reason)), N = (f) => {
248
+ const a = Y(f, $);
249
+ if (!(!a || b)) {
250
+ if ("type" in a && a.type === "event") {
251
+ const h = "event" in a ? a.event : void 0;
252
+ V(h, n) ? T(c, h, i) : p(new Error("报表 Worker 返回无效阶段事件"));
253
+ return;
254
+ }
255
+ a.error && typeof a.error.name == "string" && typeof a.error.message == "string" ? p(new E(a.error)) : U(a.result, s) && (s !== "export" || "format" in a.result && "format" in n && a.result.format === n.format) ? p(void 0, a.result) : p(new Error("报表 Worker 返回无效响应"));
256
+ }
257
+ };
258
+ try {
259
+ if (k = y.subscribe(N, (f) => p(f ?? new Error("报表 Worker 执行失败"))), b) {
260
+ k();
261
+ return;
262
+ }
263
+ if (i?.addEventListener("abort", A, { once: !0 }), w = setTimeout(() => p(new E({ name: "ReportRuntimeError", code: "timeout", message: `报表 Worker 执行超过 ${r}ms` })), r), i?.aborted) A();
264
+ else {
265
+ const { onEvent: f, signal: a, ...h } = n;
266
+ y.postMessage({ protocol: l, id: $, operation: s, input: h });
267
+ }
268
+ } catch (f) {
269
+ p(f);
270
+ }
271
+ });
272
+ return { prepare: (s, n, i) => o("prepare", s, n, i), export: (s, n, i) => o("export", s, n, i) };
273
+ }
274
+ function te(e) {
275
+ const t = e.filename ?? e.workerUrl;
276
+ if (!t || e.filename && e.workerUrl) throw new TypeError("请且仅请指定 filename 或 workerUrl");
277
+ return Z(() => {
278
+ const r = new P(t, e.workerOptions);
279
+ return {
280
+ postMessage: (o) => r.postMessage(o),
281
+ terminate: () => r.terminate(),
282
+ subscribe: (o, s) => {
283
+ const n = (i) => s(new Error(`报表 Worker 在响应前退出(code ${i})`));
284
+ return r.on("message", o), r.on("error", s), r.on("messageerror", s), r.on("exit", n), () => {
285
+ r.off("message", o), r.off("error", s), r.off("messageerror", s), r.off("exit", n);
286
+ };
287
+ }
288
+ };
289
+ }, e);
290
+ }
291
+ function re(e) {
292
+ const t = W;
293
+ if (!t) throw new Error("serveNodeReportWorker 只能在 worker_threads 中调用");
294
+ const r = (o) => {
295
+ G(o) && H(e, o, (s) => t.postMessage({ protocol: l, id: o.id, type: "event", event: s })).then((s) => t.postMessage(s, Q(s)));
296
+ };
297
+ return t.on("message", r), () => t.off("message", r);
298
+ }
299
+ export {
300
+ E as ReportWorkerError,
301
+ te as createNodeReportExecutor,
302
+ re as serveNodeReportWorker
303
+ };