@univerjs-pro/engine-formula-rust 1.0.0-beta.2

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.
@@ -0,0 +1,926 @@
1
+ import { Buffer } from "node:buffer";
2
+ import { FormulaDataModel, IAllRuntimeData, ICalculateFormulaService, IExecutionInProgressParams, IFeatureCalculationManagerService, IFeatureDirtyRangeType, IFormulaCurrentConfigService, IFormulaDatasetConfig, IFormulaDependencyGenerator, IFormulaDependencyTreeJson, IFormulaExecuteResultMap, IFormulaRuntimeService, IFormulaStringMap, IOtherFormulaManagerService, IRuntimeUnitDataType, ISetArrayFormulaDataMutationParams, ISetFormulaCalculationResultMutation, ISuperTableService, IUnitRowData, IUniverEngineFormulaConfig } from "@univerjs/engine-formula";
3
+ import { Dependency, Disposable, ICommandService, IConfigService, IUnitRange as IUnitRange$1, IWorkbookData, Injector, Nullable } from "@univerjs/core";
4
+ import { ExternalReferenceModel, IFormulaReferenceDataService, UniverProFormulaEnginePlugin } from "@univerjs-pro/engine-formula";
5
+ import { Subject } from "rxjs";
6
+ import { ISheetBlock, ISnapshot } from "@univerjs/protocol";
7
+ //#region src/binding.d.ts
8
+ interface INativeBinding {
9
+ formulaEngineExecute(inputJson: string): string;
10
+ formulaLexerTreeBuild(formula: string, transformSuffix?: boolean): string;
11
+ formulaSequenceNodesBuild(formula: string): string;
12
+ formulaCheckIfAddBracket(formula: string): number;
13
+ rustNumfmtFormat(inputJson: string): string;
14
+ rustNumfmtFormatBatch(inputJson: string): string;
15
+ rustNumfmtParse(inputJson: string): string;
16
+ rustNumfmtParseBatch(inputJson: string): string;
17
+ rustNumfmtParseMatrixBatch(inputJson: string): string;
18
+ rustNumfmtParseValue(inputJson: string): string;
19
+ rustNumfmtAnalyzeFormat(inputJson: string): string;
20
+ rustNumfmtAnalyzeBatch(inputJson: string): string;
21
+ rustNumfmtFormatInfo(inputJson: string): string;
22
+ rustNumfmtFormatDateInfo(inputJson: string): string;
23
+ rustNumfmtFormatColor(inputJson: string): string;
24
+ rustNumfmtDateToSerial(inputJson: string): string;
25
+ rustNumfmtDateFromSerial(inputJson: string): string;
26
+ rustNumfmtValidate(inputJson: string): string;
27
+ rustEngineLoadSnapshot(snapshotJson: string): string;
28
+ rustEngineLoadSnapshotBinary(snapshotBytes: Buffer): string;
29
+ rustEngineLoadSingleSheetColumnarSnapshot(unitId: string, workbookName: string | undefined | null, sheetId: string, sheetName: string | undefined | null, rowCount: number, columnCount: number, rows: Buffer, cols: Buffer, valueTags: Buffer, numbers: Buffer, valueStringOffsets: Buffer, valueStringBytes: Buffer, formulaOffsets: Buffer, formulaBytes: Buffer): string;
30
+ rustEngineApplyMutation(mutationJson: string): string;
31
+ rustEngineApplyMutationBinary(mutationBytes: Buffer): string;
32
+ rustEngineApplyNumberCellsColumnar(unitId: string, sheetId: string, rows: Buffer, cols: Buffer, values: Buffer): string;
33
+ rustEngineDisposeWorkbook(unitId: string): string;
34
+ rustEngineDisposeAllWorkbooks(): string;
35
+ rustEngineGetModelStats(): string;
36
+ rustEngineGetCell(unitId: string, sheetId: string, row: number, col: number): string;
37
+ rustEngineGetSheetState(unitId: string, sheetId: string): string;
38
+ rustEngineGetFormulaData(unitId?: string): string;
39
+ rustEngineBuildDependencyGraph(unitId?: string): string;
40
+ rustEngineGetDirtyDependencies(dirtyRangesJson: string, unitId?: string): string;
41
+ rustEngineSyncFormulaDependencies(inputJson: string): string;
42
+ rustEngineInspectFormulaDependencyGraph(): string;
43
+ rustEngineMarkFormulaDirty(inputJson: string): string;
44
+ rustEngineClearFormulaDependencies(inputJson: string): string;
45
+ rustEngineClearFormulaDirty(): string;
46
+ rustEngineExecuteDirtyFormulas(maxIteration?: number, includeCalculatedNodes?: boolean, includeRuntimeData?: boolean, includeResultBatches?: boolean): string;
47
+ rustEngineGetFormulaNumberResultsColumnar(unitId: string, sheetId: string, startColumn?: number, endColumn?: number): Buffer;
48
+ rustMaterializeWorkbookSnapshot(workbookJson: Buffer, unitId: string, rev: number, dirtyInputJson?: string): Promise<INativeMaterializedWorkbook>;
49
+ }
50
+ interface INativeMaterializedBlock {
51
+ id: string;
52
+ startRow: number;
53
+ endRow: number;
54
+ data: Buffer;
55
+ }
56
+ interface INativeMaterializedSheetBlocks {
57
+ sheetId: string;
58
+ blocks: INativeMaterializedBlock[];
59
+ }
60
+ interface INativeMaterializedWorkbook {
61
+ snapshotDraftJson: Buffer;
62
+ sheetBlocks: INativeMaterializedSheetBlocks[];
63
+ warningsJson: Buffer;
64
+ calculationStatsJson: Buffer;
65
+ }
66
+ type NativeBindingSource = '../native/index.js' | '../../../crates/univer-formula/index.js' | '@univerjs-pro/engine-formula-rust-binding';
67
+ declare function getNativeBindingSource(): NativeBindingSource | null;
68
+ declare function loadNativeBinding(): Promise<INativeBinding>;
69
+ declare function executeOnRust(inputJson: string): string;
70
+ declare function buildLexerTreeOnRust(formula: string, transformSuffix?: boolean): string;
71
+ declare function buildSequenceNodesOnRust(formula: string): string;
72
+ declare function checkIfAddBracketOnRust(formula: string): number;
73
+ declare function loadSnapshotOnRust(snapshotJson: string): string;
74
+ declare function applyMutationOnRust(mutationJson: string): string;
75
+ declare function disposeWorkbookOnRust(unitId: string): string;
76
+ declare function disposeAllWorkbooksOnRust(): string;
77
+ declare function getRustModelStats(): string;
78
+ declare function getRustCellOnRust(unitId: string, sheetId: string, row: number, col: number): string;
79
+ declare function getRustSheetStateOnRust(unitId: string, sheetId: string): string;
80
+ declare function getRustFormulaDataOnRust(unitId?: string): string;
81
+ declare function buildRustDependencyGraphOnRust(unitId?: string): string;
82
+ declare function getRustDirtyDependenciesOnRust(dirtyRangesJson: string, unitId?: string): string;
83
+ declare function syncRustFormulaDependenciesOnRust(inputJson: string): string;
84
+ declare function markRustFormulaDirtyOnRust(inputJson: string): string;
85
+ declare function clearRustFormulaDependenciesOnRust(inputJson: string): string;
86
+ declare function clearRustFormulaDirtyOnRust(): string;
87
+ declare function materializeWorkbookSnapshotOnRust(workbookJson: Buffer, unitId: string, rev: number, dirtyInputJson?: string): Promise<INativeMaterializedWorkbook>;
88
+ //#endregion
89
+ //#region src/types.d.ts
90
+ /**
91
+ * Serialized types exchanged between TS and Rust formula engine.
92
+ */
93
+ interface IFormulaEngineConfig {
94
+ maxIteration: number;
95
+ intervalCount: number;
96
+ }
97
+ interface IFormulaExecutionInput {
98
+ config: IFormulaEngineConfig;
99
+ formulaData: Record<string, Record<string, Record<number, Record<number, string | IRustFormulaDataItem>>>>;
100
+ unitData: Record<string, Record<string, ISheetData>>;
101
+ dirtyRanges: IUnitRange[];
102
+ definedNames: Record<string, IDefinedName>;
103
+ }
104
+ interface ISheetData {
105
+ cellData: Record<number, Record<number, ICellValue>>;
106
+ rowCount: number;
107
+ columnCount: number;
108
+ }
109
+ interface ICellValue {
110
+ v?: unknown;
111
+ t?: number;
112
+ p?: unknown;
113
+ f?: string;
114
+ si?: string;
115
+ ref?: string;
116
+ dynamicArrayRef?: string;
117
+ xf?: string;
118
+ s?: unknown;
119
+ displayPrecision?: number;
120
+ }
121
+ interface IUnitRange {
122
+ unitId: string;
123
+ sheetId: string;
124
+ range: IRange;
125
+ }
126
+ interface IRange {
127
+ startRow: number;
128
+ startColumn: number;
129
+ endRow: number;
130
+ endColumn: number;
131
+ }
132
+ interface IDefinedName {
133
+ name: string;
134
+ formula?: string;
135
+ range?: IRange;
136
+ }
137
+ interface IFormulaExecutionOutput {
138
+ runtimeData: Record<string, Record<string, Record<number, Record<number, unknown>>>>;
139
+ arrayFormulaRange: Record<string, Record<string, Record<number, Record<number, IRange>>>>;
140
+ cycleDependencies: ICycleDependencyInfo[];
141
+ errors: IExecutionError[];
142
+ }
143
+ interface ICycleDependencyInfo {
144
+ unitId: string;
145
+ sheetId: string;
146
+ row: number;
147
+ column: number;
148
+ }
149
+ interface IExecutionError {
150
+ unitId: string;
151
+ sheetId: string;
152
+ row: number;
153
+ column: number;
154
+ message: string;
155
+ }
156
+ interface IRustEngineSnapshot {
157
+ workbooks: IRustWorkbookSnapshot[];
158
+ }
159
+ interface IRustWorkbookSnapshot {
160
+ unitId: string;
161
+ name?: string;
162
+ sheets: IRustSheetSnapshot[];
163
+ calculation?: IRustWorkbookCalculationSnapshot;
164
+ resources?: Record<string, IRustResourceSnapshot>;
165
+ definedNames?: Record<string, IRustDefinedNameSnapshot>;
166
+ externalLinks?: IRustExternalLinkSnapshot[];
167
+ tables?: Record<string, IRustTableSnapshot>;
168
+ }
169
+ interface IRustResourceSnapshot {
170
+ name: string;
171
+ data: unknown;
172
+ }
173
+ interface IRustWorkbookCalculationSnapshot {
174
+ fullPrecision?: boolean;
175
+ }
176
+ interface IRustExternalLinkSnapshot {
177
+ aliases?: string[];
178
+ definedNames?: Record<string, IRustDefinedNameSnapshot>;
179
+ sheets: IRustExternalSheetSnapshot[];
180
+ tables?: Record<string, IRustTableSnapshot>;
181
+ target?: string;
182
+ unitId?: string;
183
+ }
184
+ interface IRustExternalSheetSnapshot {
185
+ name: string;
186
+ sheetId?: string;
187
+ rowCount: number;
188
+ columnCount: number;
189
+ cellData: Record<number, Record<number, ICellValue>>;
190
+ coverage?: IRange[];
191
+ }
192
+ interface IRustDefinedNameSnapshot {
193
+ id?: string;
194
+ name: string;
195
+ formulaOrRefString?: string;
196
+ localSheetId?: string;
197
+ }
198
+ interface IRustTableSnapshot {
199
+ sheetId: string;
200
+ range: {
201
+ startRow: number;
202
+ endRow: number;
203
+ startColumn: number;
204
+ endColumn: number;
205
+ };
206
+ columns: Array<{
207
+ displayName: string;
208
+ }>;
209
+ showHeader?: boolean;
210
+ showFooter?: boolean;
211
+ }
212
+ interface IRustSheetSnapshot {
213
+ sheetId: string;
214
+ name?: string;
215
+ rowCount: number;
216
+ columnCount: number;
217
+ transitionEvaluation?: boolean;
218
+ cellData: Record<number, Record<number, ICellValue>>;
219
+ rowData?: Record<number, IRustVisibilityData>;
220
+ columnData?: Record<number, IRustVisibilityData>;
221
+ }
222
+ interface IRustVisibilityData {
223
+ hd?: unknown;
224
+ }
225
+ interface IRustEngineMutation {
226
+ id: string;
227
+ params?: unknown;
228
+ dirtyRanges?: unknown[];
229
+ }
230
+ interface IRustEngineModelStats {
231
+ workbookCount: number;
232
+ sheetCount: number;
233
+ cellCount: number;
234
+ formulaCount: number;
235
+ definedNameCount: number;
236
+ tableCount: number;
237
+ typedValueCount: number;
238
+ jsonValueCount: number;
239
+ valueTileCount: number;
240
+ valueTileValueCount: number;
241
+ estimatedMemoryBytes: number;
242
+ revision: number;
243
+ applied: boolean;
244
+ }
245
+ interface IRustSheetState {
246
+ rowCount: number;
247
+ columnCount: number;
248
+ hiddenRows: number[];
249
+ hiddenCols: number[];
250
+ revision: number;
251
+ }
252
+ interface IRustFormulaStoreState {
253
+ formulaData: Record<string, Record<string, Record<number, Record<number, IRustFormulaDataItem>>>>;
254
+ arrayFormulaRange: Record<string, Record<string, Record<number, Record<number, IRange>>>>;
255
+ arrayFormulaCellData: Record<string, Record<string, Record<number, Record<number, ICellValue>>>>;
256
+ }
257
+ interface IRustFormulaDataItem {
258
+ f: string;
259
+ si?: string;
260
+ ref?: string;
261
+ x?: number;
262
+ y?: number;
263
+ }
264
+ interface IRustDependencyCell {
265
+ unitId: string;
266
+ sheetId: string;
267
+ row: number;
268
+ column: number;
269
+ }
270
+ interface IRustDependencyRange {
271
+ unitId: string;
272
+ sheetId: string;
273
+ startRow: number;
274
+ endRow: number;
275
+ startColumn: number;
276
+ endColumn: number;
277
+ }
278
+ interface IRustDependencyNode {
279
+ id: number;
280
+ unitId: string;
281
+ sheetId: string;
282
+ row: number;
283
+ column: number;
284
+ formula: string;
285
+ formulaId?: string;
286
+ offsetX: number;
287
+ offsetY: number;
288
+ precedentRanges: IRustDependencyRange[];
289
+ parents: number[];
290
+ children: number[];
291
+ dependents: IRustDependencyCell[];
292
+ }
293
+ interface IRustDependencyGraph {
294
+ stats: {
295
+ formulaCount: number;
296
+ precedentRangeCount: number;
297
+ formulaEdgeCount: number;
298
+ cycleCount: number;
299
+ errorCount: number;
300
+ };
301
+ nodes: IRustDependencyNode[];
302
+ edges: Array<{
303
+ from: IRustDependencyCell;
304
+ to: IRustDependencyCell;
305
+ }>;
306
+ calculationOrder: IRustDependencyCell[];
307
+ calculationForest: IRustDependencyCalculationTree[];
308
+ cycles: IRustDependencyCell[][];
309
+ errors: Array<{
310
+ unitId: string;
311
+ sheetId: string;
312
+ row: number;
313
+ column: number;
314
+ formula: string;
315
+ message: string;
316
+ }>;
317
+ }
318
+ interface IRustDependencyCalculationTree {
319
+ hasCycle: boolean;
320
+ plan: IRustDependencyCalculationPlanItem[];
321
+ levels: IRustDependencyCell[][];
322
+ }
323
+ type IRustDependencyCalculationPlanItem = {
324
+ type: 'nodes';
325
+ cells: IRustDependencyCell[];
326
+ } | {
327
+ type: 'cycle';
328
+ cells: IRustDependencyCell[];
329
+ };
330
+ interface IRustDependencyDirtyResult {
331
+ dirtyRanges: IRustDependencyRange[];
332
+ direct: IRustDependencyCell[];
333
+ affected: IRustDependencyCell[];
334
+ calculationForest: IRustDependencyCalculationTree[];
335
+ cycles: IRustDependencyCell[][];
336
+ errors: IRustDependencyGraph['errors'];
337
+ }
338
+ interface IRustFormulaDependencySyncInput {
339
+ rebuildSheetFormulas?: boolean;
340
+ featureCalculations?: IRustExternalFeatureCalculation[];
341
+ otherFormulas?: IRustExternalOtherFormula[];
342
+ externalReferences?: Record<string, {
343
+ schemaVersion: number;
344
+ references: Record<string, {
345
+ qualifier: string;
346
+ sourceUnitId: string;
347
+ sourceUnitType: number;
348
+ }>;
349
+ }>;
350
+ }
351
+ interface IRustExternalFeatureCalculation {
352
+ unitId: string;
353
+ sheetId: string;
354
+ featureId: string;
355
+ dependencyRanges: IRustDependencyRange[];
356
+ dirtyRanges?: IRustDependencyRange[];
357
+ runtimeCellData?: Record<string, Record<string, Record<number, Record<number, ICellValue | null>>>>;
358
+ }
359
+ interface IRustExternalOtherFormula {
360
+ unitId: string;
361
+ sheetId: string;
362
+ formulaId: string;
363
+ formula: string;
364
+ ranges: IRange[];
365
+ }
366
+ interface IRustFormulaDependencyDirtyInput {
367
+ forceCalculation?: boolean;
368
+ includeDirtyNodes?: boolean;
369
+ includeCalculationOrder?: boolean;
370
+ dirtyFormulaCells?: IRustDependencyRange[];
371
+ dirtyRanges?: IRustDependencyRange[];
372
+ dirtyUnitFeatureMap?: Record<string, Record<string, Record<string, boolean>>>;
373
+ dirtyUnitOtherFormulaMap?: Record<string, Record<string, Record<string, boolean>>>;
374
+ dirtyNameMap?: Record<string, Record<string, string>>;
375
+ dirtyDefinedNameMap?: Record<string, Record<string, string>>;
376
+ }
377
+ interface IRustFormulaDependencyClearInput {
378
+ unitId: string;
379
+ sheetId?: string;
380
+ clearSheetFormulas?: boolean;
381
+ clearFeatureFormulas?: boolean;
382
+ clearOtherFormulas?: boolean;
383
+ formulaCells?: Array<{
384
+ row: number;
385
+ col: number;
386
+ }>;
387
+ featureIds?: string[];
388
+ otherFormulaIds?: string[];
389
+ }
390
+ interface IRustFormulaDependencySyncOutput {
391
+ sheetFormulaCount: number;
392
+ featureFormulaCount: number;
393
+ otherFormulaCount: number;
394
+ errorCount: number;
395
+ errors: IRustDependencyGraph['errors'];
396
+ timings?: {
397
+ dependencyInputMs: number;
398
+ featureSyncMs: number;
399
+ analyzeMs: number;
400
+ cacheInsertMs: number;
401
+ graphSetMs: number;
402
+ dynamicPrewarmMs: number;
403
+ dynamicApplyMs: number;
404
+ otherFormulaMs: number;
405
+ totalMs: number;
406
+ };
407
+ }
408
+ interface IRustFormulaDependencyNodeOutput {
409
+ nodeType: 'cellFormula' | 'featureCalculation' | 'otherFormula';
410
+ label: string;
411
+ unitId?: string;
412
+ sheetId?: string;
413
+ row?: number;
414
+ column?: number;
415
+ formulaId?: string;
416
+ featureId?: string;
417
+ refOffsetX?: number;
418
+ refOffsetY?: number;
419
+ }
420
+ interface IRustFormulaDependencyInspectGraph {
421
+ nodes: IRustFormulaDependencyInspectNode[];
422
+ }
423
+ interface IRustFormulaDependencyInspectNode {
424
+ index: number;
425
+ node: IRustFormulaDependencyNodeOutput;
426
+ label: string;
427
+ precedents: string[];
428
+ dependents: string[];
429
+ }
430
+ interface IRustFormulaDependencyDirtyOutput {
431
+ dirtyNodes: IRustFormulaDependencyNodeOutput[];
432
+ calculationOrder: {
433
+ hasCycle: boolean;
434
+ calculationForest: Array<{
435
+ hasCycle: boolean;
436
+ plan: Array<{
437
+ type: string;
438
+ nodeIndex?: number;
439
+ nodeIndices?: number[];
440
+ }>;
441
+ levels: number[][];
442
+ }>;
443
+ };
444
+ }
445
+ interface IRustFormulaDependencyExecutionOutput {
446
+ runtimeData: Record<string, Record<string, Record<number, Record<number, unknown>>>>;
447
+ otherFormulaData?: Record<string, Record<string, Record<string, Record<number, Record<number, unknown>>>>>;
448
+ resultBatches: Array<{
449
+ unitId: string;
450
+ sheetId: string;
451
+ rows: number[];
452
+ cols: number[];
453
+ values: unknown[];
454
+ }>;
455
+ calculatedNodes: IRustFormulaDependencyNodeOutput[];
456
+ calculatedNodeCount: number;
457
+ errors: Array<{
458
+ unitId: string;
459
+ sheetId: string;
460
+ row: number;
461
+ column: number;
462
+ message: string;
463
+ }>;
464
+ needsData?: Array<{
465
+ unitId: string;
466
+ sheetId: string;
467
+ range: IRange;
468
+ }>;
469
+ tableNeedsData?: Array<{
470
+ unitId: string;
471
+ tableName: string;
472
+ ownerUnitId: string;
473
+ ownerSheetId: string;
474
+ row: number;
475
+ column: number;
476
+ formulaId?: string;
477
+ }>;
478
+ hasCycle: boolean;
479
+ cycleIterationCount: number;
480
+ parallelBatchCount: number;
481
+ parallelNodeCount: number;
482
+ functionProfile?: Array<{
483
+ name: string;
484
+ callCount: number;
485
+ totalMs: number;
486
+ avgUs: number;
487
+ }>;
488
+ timings: {
489
+ initialDynamicRefreshMs: number;
490
+ initialDynamicRefreshRequestCount: number;
491
+ buildValueDataMs: number;
492
+ planningMs: number;
493
+ taskBuildMs: number;
494
+ evaluateMs: number;
495
+ applyMs: number;
496
+ applyResultMaterializeMs: number;
497
+ applyValueDataMs: number;
498
+ applyWorkbookMs: number;
499
+ applyRuntimeDynamicPatchMs: number;
500
+ clearDirtyMs: number;
501
+ runtimeDynamicRefreshMs: number;
502
+ runtimeDynamicRefreshRequestCount: number;
503
+ finalOutputMs: number;
504
+ };
505
+ }
506
+ //#endregion
507
+ //#region src/services/rust-formula-projection.service.d.ts
508
+ declare const RUST_UPSERT_REFERENCE_DATA_MUTATION_ID = "formula.mutation.upsert-reference-data";
509
+ declare const RUST_UPSERT_PROJECTION_WORKBOOK_MUTATION_ID = "formula.mutation.upsert-projection-workbook";
510
+ declare const RUST_FORMULA_RELEVANT_MUTATIONS: Set<string>;
511
+ declare const RUST_INCREMENTAL_DEPENDENCY_MUTATIONS: Set<string>;
512
+ interface IRustProjectionWorkbookInput {
513
+ snapshot: IWorkbookData;
514
+ unitId?: string;
515
+ definedNames?: Record<string, IRustDefinedNameSnapshot>;
516
+ }
517
+ interface IFormulaCalculationError {
518
+ code: string;
519
+ message: string;
520
+ unitId?: string;
521
+ sheetId?: string;
522
+ row?: number;
523
+ column?: number;
524
+ }
525
+ interface IFormulaProjectionDesyncSignal {
526
+ reason: string;
527
+ message: string;
528
+ mutationId?: string;
529
+ }
530
+ interface IFormulaCalculationPatch {
531
+ unitData: ISetFormulaCalculationResultMutation['unitData'];
532
+ unitOtherData: ISetFormulaCalculationResultMutation['unitOtherData'];
533
+ arrayFormulaRange?: ISetArrayFormulaDataMutationParams['arrayFormulaRange'];
534
+ arrayFormulaCellData?: ISetArrayFormulaDataMutationParams['arrayFormulaCellData'];
535
+ errors?: IFormulaCalculationError[];
536
+ desync?: IFormulaProjectionDesyncSignal;
537
+ }
538
+ interface IRustFormulaProjectionLoadResult {
539
+ stats?: IRustEngineModelStats;
540
+ errors?: IFormulaCalculationError[];
541
+ desync?: IFormulaProjectionDesyncSignal;
542
+ }
543
+ interface IRustFormulaProjectionMutationResult {
544
+ stats?: IRustEngineModelStats;
545
+ dependencyInvalidated: boolean;
546
+ errors?: IFormulaCalculationError[];
547
+ desync?: IFormulaProjectionDesyncSignal;
548
+ }
549
+ declare function isRustFormulaRelevantMutation(id: string): boolean;
550
+ declare function isRustIncrementalDependencyMutation(id: string): boolean;
551
+ declare function serializeRuntimeWorkbookSnapshots(workbooks: readonly IRustProjectionWorkbookInput[]): IRustEngineSnapshot;
552
+ declare function serializeRuntimeWorkbookSnapshot(input: IRustProjectionWorkbookInput): IRustWorkbookSnapshot;
553
+ declare function createProjectionWorkbookUpsertMutation(input: IRustProjectionWorkbookInput): IRustEngineMutation;
554
+ declare function rustExecutionOutputToFormulaCalculationPatch(output: IRustFormulaDependencyExecutionOutput): IFormulaCalculationPatch;
555
+ declare function createFormulaProjectionDesyncSignal(reason: string, error: unknown, mutationId?: string): IFormulaProjectionDesyncSignal;
556
+ declare class RustFormulaProjectionService {
557
+ private _nativeLoaded;
558
+ load(workbooks: readonly IRustProjectionWorkbookInput[]): Promise<IRustFormulaProjectionLoadResult>;
559
+ applyMutation(mutation: IRustEngineMutation): Promise<IRustFormulaProjectionMutationResult>;
560
+ syncFormulaDependencies(input: IRustFormulaDependencySyncInput): Promise<unknown>;
561
+ markDirty(input: {
562
+ forceCalculation?: boolean;
563
+ includeDirtyNodes?: boolean;
564
+ includeCalculationOrder?: boolean;
565
+ dirtyRanges?: IRustDependencyRange[];
566
+ dirtyUnitFeatureMap?: Record<string, Record<string, Record<string, boolean>>>;
567
+ dirtyUnitOtherFormulaMap?: Record<string, Record<string, Record<string, boolean>>>;
568
+ dirtyNameMap?: Record<string, Record<string, string>>;
569
+ dirtyDefinedNameMap?: Record<string, Record<string, string>>;
570
+ }): Promise<unknown>;
571
+ calculateDirty(maxIteration?: number): Promise<IFormulaCalculationPatch>;
572
+ reset(): Promise<IRustFormulaProjectionLoadResult>;
573
+ disposeWorkbook(unitId: string): Promise<IRustFormulaProjectionLoadResult>;
574
+ private _ensureNativeLoaded;
575
+ }
576
+ //#endregion
577
+ //#region src/controllers/rust-engine-sync.controller.d.ts
578
+ /**
579
+ * Keeps Rust's in-memory formula workbook projection aligned with Univer.
580
+ *
581
+ * Rust projection loading is host-driven: the main/runtime adapter provides the
582
+ * initial workbook snapshot and subsequent formula-relevant mutations. This
583
+ * controller intentionally does not create or read worker-side Workbook units.
584
+ */
585
+ declare class RustEngineSyncController extends Disposable {
586
+ private readonly _commandService;
587
+ private _nativeReady;
588
+ private _snapshotLoaded;
589
+ private _projectionLoadPromise;
590
+ private _projectionDeltaBarrier;
591
+ private readonly _pendingMutations;
592
+ private readonly _projectionManagedTableUnits;
593
+ constructor(_commandService: ICommandService);
594
+ private _initialize;
595
+ loadProjection(workbooks: readonly IRustProjectionWorkbookInput[]): Promise<void>;
596
+ waitForProjectionLoad(): Promise<void>;
597
+ setProjectionDeltaBarrier(barrier: Promise<void>): void;
598
+ private _loadProjection;
599
+ applyProjectionMutation(mutation: IRustEngineMutation): void;
600
+ upsertProjectionWorkbook(workbook: IRustProjectionWorkbookInput): void;
601
+ setProjectionManagedTableUnit(unitId: string): void;
602
+ unsetProjectionManagedTableUnit(unitId: string): void;
603
+ upsertReferenceData(config: IFormulaDatasetConfig, needs: Array<NonNullable<IRustFormulaDependencyExecutionOutput['needsData']>[number] & {
604
+ dataUnitId?: string;
605
+ tableName?: string;
606
+ }>, tableService?: {
607
+ getTable(unitId: string, tableName: string): unknown;
608
+ }): number;
609
+ disposeProjectionWorkbook(unitId: string): void;
610
+ dispose(): void;
611
+ private _loadSerializedSnapshot;
612
+ private _queueOrSyncMutation;
613
+ private _flushPendingMutations;
614
+ private _syncMutation;
615
+ private _markProjectionDesynced;
616
+ private _shouldSyncMutation;
617
+ private _serializeMutation;
618
+ }
619
+ //#endregion
620
+ //#region src/numfmt.d.ts
621
+ type NumberFormatDateSystem = '1900' | '1904';
622
+ interface INumberFormatOptions {
623
+ locale?: string;
624
+ dateSystem?: NumberFormatDateSystem;
625
+ throws?: boolean;
626
+ invalid?: string;
627
+ overflow?: string;
628
+ dateErrorNumber?: boolean;
629
+ dateSpanLarge?: boolean;
630
+ leap1900?: boolean;
631
+ nbsp?: boolean;
632
+ skipChar?: string;
633
+ fillChar?: string;
634
+ bigintErrorNumber?: boolean;
635
+ ignoreTimezone?: boolean;
636
+ dateNf?: string;
637
+ }
638
+ interface INumberFormatDiagnostic {
639
+ code: string;
640
+ message?: string;
641
+ [key: string]: unknown;
642
+ }
643
+ interface IFormatNumberBatchInput {
644
+ formats: Array<{
645
+ id: number;
646
+ formatCode?: string;
647
+ numFmtId?: number;
648
+ options?: INumberFormatOptions;
649
+ }>;
650
+ values: Array<{
651
+ value: unknown;
652
+ valueType?: 'number' | 'text' | 'boolean' | 'date' | 'datetime' | 'bigint' | string;
653
+ formatId: number;
654
+ }>;
655
+ }
656
+ interface IFormatNumberBatchOutput {
657
+ values: Array<{
658
+ text: string;
659
+ color?: string;
660
+ style?: unknown;
661
+ diagnostics: INumberFormatDiagnostic[];
662
+ }>;
663
+ timingsMs?: Record<string, number>;
664
+ }
665
+ interface IParseNumberFormatBatchInput {
666
+ options: Array<INumberFormatOptions & {
667
+ id: number;
668
+ }>;
669
+ inputs: Array<{
670
+ input: string;
671
+ optionsId: number;
672
+ }>;
673
+ }
674
+ interface IParsedNumberFormatValue {
675
+ number?: number;
676
+ text?: string;
677
+ boolean?: boolean;
678
+ }
679
+ interface IParseNumberFormatBatchOutput {
680
+ values: Array<{
681
+ value: IParsedNumberFormatValue | null;
682
+ kind?: string;
683
+ inferredFormat?: string;
684
+ diagnostics: INumberFormatDiagnostic[];
685
+ }>;
686
+ timingsMs?: Record<string, number>;
687
+ }
688
+ interface IObjectMatrixPrimitiveType<T> {
689
+ [key: number]: IObjectArrayPrimitiveType<T>;
690
+ }
691
+ interface IObjectArrayPrimitiveType<T> {
692
+ [key: number]: T;
693
+ }
694
+ interface IParseNumberFormatMatrixCell {
695
+ v?: unknown;
696
+ }
697
+ interface IParseNumberFormatMatrixBatchInput {
698
+ option?: INumberFormatOptions;
699
+ matrix: IObjectMatrixPrimitiveType<IParseNumberFormatMatrixCell>;
700
+ }
701
+ interface IParsedNumberFormatMatrixValue {
702
+ value: IParsedNumberFormatValue | null;
703
+ kind?: string;
704
+ inferredFormat?: string;
705
+ diagnostics: INumberFormatDiagnostic[];
706
+ }
707
+ interface IParseNumberFormatMatrixBatchOutput {
708
+ values: IObjectMatrixPrimitiveType<IParsedNumberFormatMatrixValue>;
709
+ timingsMs?: Record<string, number>;
710
+ }
711
+ interface IAnalyzeNumberFormatBatchInput {
712
+ formats: Array<{
713
+ id: number;
714
+ formatCode: string;
715
+ }>;
716
+ }
717
+ interface INumberFormatAnalysis {
718
+ isDate?: boolean;
719
+ isTime?: boolean;
720
+ isPercent?: boolean;
721
+ isText?: boolean;
722
+ [key: string]: unknown;
723
+ }
724
+ interface IAnalyzeNumberFormatBatchOutput {
725
+ values: Array<{
726
+ id: number;
727
+ analysis: INumberFormatAnalysis | null;
728
+ diagnostics: INumberFormatDiagnostic[];
729
+ }>;
730
+ timingsMs?: Record<string, number>;
731
+ }
732
+ /**
733
+ * Formats many values with the Rust number-format engine.
734
+ *
735
+ * The native binding is loaded lazily on the first call, so callers do not need
736
+ * to call `loadNativeBinding()` before using this API. Binding or transport
737
+ * failures reject the promise; per-item formatting issues are returned in each
738
+ * item's `diagnostics` array.
739
+ */
740
+ declare function formatNumberBatch(input: IFormatNumberBatchInput): Promise<IFormatNumberBatchOutput>;
741
+ /**
742
+ * Parses many user-entered number-format strings with the Rust engine.
743
+ *
744
+ * This API is pure data-in/data-out and does not apply Univer mutations. The
745
+ * native binding is loaded lazily on the first call. Binding or transport
746
+ * failures reject the promise; per-item parse issues are returned in each
747
+ * item's `diagnostics` array.
748
+ */
749
+ declare function parseNumberFormatBatch(input: IParseNumberFormatBatchInput): Promise<IParseNumberFormatBatchOutput>;
750
+ /**
751
+ * Parses string `v` values from a Univer-style sparse object matrix.
752
+ *
753
+ * Non-string values and empty strings are skipped and therefore omitted from
754
+ * the returned sparse matrix. Row and column coordinates are preserved.
755
+ */
756
+ declare function parseNumberFormatMatrixBatch(input: IParseNumberFormatMatrixBatchInput): Promise<IParseNumberFormatMatrixBatchOutput>;
757
+ /**
758
+ * Analyzes many number-format patterns with the Rust engine.
759
+ *
760
+ * The native binding is loaded lazily on the first call, so callers can use the
761
+ * API directly as a Promise-returning utility. Binding or transport failures
762
+ * reject the promise; per-pattern analysis issues are returned in each item's
763
+ * `diagnostics` array.
764
+ */
765
+ declare function analyzeNumberFormatBatch(input: IAnalyzeNumberFormatBatchInput): Promise<IAnalyzeNumberFormatBatchOutput>;
766
+ //#endregion
767
+ //#region src/plugin.d.ts
768
+ interface IUniverRustFormulaEngineConfig extends IUniverEngineFormulaConfig {
769
+ /**
770
+ * Whether to use the Rust-backed formula engine.
771
+ * @default true
772
+ */
773
+ useRustEngine?: boolean;
774
+ }
775
+ /**
776
+ * Plugin that swaps the formula calculation core for a Rust implementation.
777
+ *
778
+ * Inherits from UniverFormulaEnginePlugin to keep all non-calculation services
779
+ * (FormulaDataModel, IFunctionService, controllers, etc.) intact.
780
+ *
781
+ * On the worker thread it overrides ICalculateFormulaService with
782
+ * RustCalculateFormulaService which delegates heavy computation to the Rust
783
+ * NAPI module.
784
+ */
785
+ declare class UniverRustFormulaEnginePlugin extends UniverProFormulaEnginePlugin {
786
+ protected readonly _config: Partial<IUniverRustFormulaEngineConfig>;
787
+ protected readonly _injector: Injector;
788
+ protected readonly _configService: IConfigService;
789
+ static packageName: string;
790
+ static version: string;
791
+ constructor(_config: Partial<IUniverRustFormulaEngineConfig> | undefined, _injector: Injector, _configService: IConfigService);
792
+ onReady(): void;
793
+ /**
794
+ * UniverProFormulaEnginePlugin invokes this hook before its single DI
795
+ * registration pass.
796
+ */
797
+ protected _extendFormulaExecutionDependencies(dependencies: Dependency[]): void;
798
+ }
799
+ //#endregion
800
+ //#region src/services/calculate-formula.service.d.ts
801
+ interface IRustCalculateFormulaService extends ICalculateFormulaService {}
802
+ declare const IRustCalculateFormulaService: import("@wendellhu/redi").IdentifierDecorator<IRustCalculateFormulaService>;
803
+ /**
804
+ * Rust-backed implementation of ICalculateFormulaService.
805
+ *
806
+ * This service acts as an adapter: it gathers all necessary data from the TS-side
807
+ * DI container, serializes it, sends it to the Rust engine via NAPI, then writes
808
+ * the results back into IFormulaRuntimeService.
809
+ */
810
+ declare class RustCalculateFormulaService extends Disposable implements IRustCalculateFormulaService {
811
+ protected readonly _configService: IConfigService;
812
+ protected readonly _currentConfigService: IFormulaCurrentConfigService;
813
+ protected readonly _runtimeService: IFormulaRuntimeService;
814
+ protected readonly _formulaDependencyGenerator: IFormulaDependencyGenerator;
815
+ protected readonly _featureCalculationManagerService: IFeatureCalculationManagerService;
816
+ protected readonly _otherFormulaManagerService: IOtherFormulaManagerService;
817
+ protected readonly _commandService: ICommandService;
818
+ private readonly _rustEngineSyncController;
819
+ private readonly _formulaDataModel;
820
+ private readonly _formulaReferenceDataService;
821
+ private readonly _excelExternalReferenceModel;
822
+ private readonly _superTableService;
823
+ protected readonly _executionInProgressListener$: Subject<IExecutionInProgressParams>;
824
+ readonly executionInProgressListener$: import("rxjs").Observable<IExecutionInProgressParams>;
825
+ protected readonly _executionCompleteListener$: Subject<IAllRuntimeData>;
826
+ readonly executionCompleteListener$: import("rxjs").Observable<IAllRuntimeData>;
827
+ private _executeLock;
828
+ private _nativeLoaded;
829
+ private _syncedSnapshotEpoch;
830
+ private _syncedDependencyInvalidationEpoch;
831
+ private _syncedExternalReferenceSignature;
832
+ private _externalFormulaDatasetConfig;
833
+ private _externalRequestCounter;
834
+ private _externalRequestGeneration;
835
+ private readonly _externalInflight;
836
+ private readonly _externalCompleted;
837
+ constructor(_configService: IConfigService, _currentConfigService: IFormulaCurrentConfigService, _runtimeService: IFormulaRuntimeService, _formulaDependencyGenerator: IFormulaDependencyGenerator, _featureCalculationManagerService: IFeatureCalculationManagerService, _otherFormulaManagerService: IOtherFormulaManagerService, _commandService: ICommandService, _rustEngineSyncController: RustEngineSyncController, _formulaDataModel: FormulaDataModel, _formulaReferenceDataService: IFormulaReferenceDataService, _excelExternalReferenceModel: ExternalReferenceModel, _superTableService: ISuperTableService);
838
+ dispose(): void;
839
+ stopFormulaExecution(): void;
840
+ setRuntimeFeatureCellData(featureId: string, featureData: IRuntimeUnitDataType): void;
841
+ setRuntimeFeatureRange(featureId: string, featureRange: IFeatureDirtyRangeType): void;
842
+ execute(formulaDatasetConfig: IFormulaDatasetConfig): Promise<void>;
843
+ private _executeStep;
844
+ private _resolveExternalReferenceNeeds;
845
+ private _loadExternalReferenceNeeds;
846
+ private _applyTableReferenceLoadError;
847
+ private _loadRustExternalReference;
848
+ private _materializeRustExternalReference;
849
+ private _resolveRustExternalBinding;
850
+ private _parseOoxmlExternalSyntheticUnitId;
851
+ private _buildRustInput;
852
+ private _syncRustFormulaDependencies;
853
+ private _syncRustFormulaDependencyDefinitions;
854
+ private _collectRustFormulaDependencySyncState;
855
+ private _markRustFormulaDirty;
856
+ private _dirtyFeatureMapFor;
857
+ private _featureKey;
858
+ private _featureSignatureMap;
859
+ private _serializeFeatureDirtyRanges;
860
+ private _serializeFormulaData;
861
+ private _serializeUnitData;
862
+ private _serializeCellData;
863
+ private _applyRustOutput;
864
+ private _applyRustDependencyOutput;
865
+ calculate(formulaString: string): Promise<{} | null>;
866
+ executeFormulas(formulas: IFormulaStringMap, rowData?: IUnitRowData): Promise<IFormulaExecuteResultMap>;
867
+ getAllDependencyJson(_rowData?: IUnitRowData): Promise<IFormulaDependencyTreeJson[]>;
868
+ getCellDependencyJson(unitId: string, sheetId: string, row: number, column: number, _rowData?: IUnitRowData): Promise<{
869
+ treeId: number;
870
+ formula: string;
871
+ row: number;
872
+ column: number;
873
+ unitId: string;
874
+ subUnitId: string;
875
+ refOffsetX: number;
876
+ refOffsetY: number;
877
+ rangeList: IUnitRange$1[];
878
+ refTreeId: number | undefined;
879
+ formulaId: Nullable<string>;
880
+ featureId: Nullable<string>;
881
+ type: Nullable<import("@univerjs/engine-formula").FormulaDependencyTreeType>;
882
+ children: IFormulaDependencyTreeJson[];
883
+ parents: IFormulaDependencyTreeJson[];
884
+ } | undefined>;
885
+ getRangeDependents(unitRanges: IUnitRange$1[]): Promise<IFormulaDependencyTreeJson[]>;
886
+ getInRangeFormulas(unitRanges: IUnitRange$1[]): Promise<IFormulaDependencyTreeJson[]>;
887
+ getDependentsAndInRangeFormulas(unitRanges: IUnitRange$1[]): Promise<{
888
+ dependents: IFormulaDependencyTreeJson[];
889
+ inRanges: IFormulaDependencyTreeJson[];
890
+ }>;
891
+ private _formulaStringMapToFormulaData;
892
+ private _formulaExecutionOutputToResultMap;
893
+ private _getRustDependencyGraph;
894
+ private _getRustInspectGraph;
895
+ private _rustAllDependencyJson;
896
+ private _rustGraphDependencyJson;
897
+ private _rustDependencyNodeToJson;
898
+ private _rustFormulaNodeToDependencyJson;
899
+ private _rustRangeToUnitRange;
900
+ private _serializeUnitRanges;
901
+ private _rustDependencyJsonByCell;
902
+ private _cellKey;
903
+ private _cellInUnitRanges;
904
+ private _uniqueDependencyJson;
905
+ }
906
+ //#endregion
907
+ //#region src/services/workbook-snapshot-materializer.d.ts
908
+ interface IMaterializedWorkbookSnapshot {
909
+ snapshot: ISnapshot;
910
+ sheetBlocks: Record<string, ISheetBlock[]>;
911
+ warnings: unknown[];
912
+ calculationStats: IMaterializationCalculationStats;
913
+ }
914
+ interface IMaterializationCalculationStats {
915
+ fullCalculation: boolean;
916
+ formulaNodeCount: number;
917
+ calculatedNodeCount: number;
918
+ hasCycle: boolean;
919
+ cycleIterationCount: number;
920
+ parallelBatchCount: number;
921
+ parallelNodeCount: number;
922
+ errorCount: number;
923
+ }
924
+ declare function materializeWorkbookSnapshot(workbook: IWorkbookData, unitID: string, rev: number, dirtyInput?: IRustFormulaDependencyDirtyInput): Promise<IMaterializedWorkbookSnapshot>;
925
+ //#endregion
926
+ export { type IAnalyzeNumberFormatBatchInput, type IAnalyzeNumberFormatBatchOutput, ICellValue, ICycleDependencyInfo, IDefinedName, IExecutionError, type IFormatNumberBatchInput, type IFormatNumberBatchOutput, type IFormulaCalculationError, type IFormulaCalculationPatch, IFormulaEngineConfig, IFormulaExecutionInput, IFormulaExecutionOutput, type IFormulaProjectionDesyncSignal, type IMaterializationCalculationStats, type IMaterializedWorkbookSnapshot, type INumberFormatAnalysis, type INumberFormatDiagnostic, type INumberFormatOptions, type IObjectArrayPrimitiveType, type IObjectMatrixPrimitiveType, type IParseNumberFormatBatchInput, type IParseNumberFormatBatchOutput, type IParseNumberFormatMatrixBatchInput, type IParseNumberFormatMatrixBatchOutput, type IParseNumberFormatMatrixCell, type IParsedNumberFormatMatrixValue, type IParsedNumberFormatValue, IRange, IRustCalculateFormulaService, IRustDefinedNameSnapshot, IRustDependencyCalculationPlanItem, IRustDependencyCalculationTree, IRustDependencyCell, IRustDependencyDirtyResult, IRustDependencyGraph, IRustDependencyNode, IRustDependencyRange, IRustEngineModelStats, IRustEngineMutation, IRustEngineSnapshot, IRustExternalFeatureCalculation, IRustExternalLinkSnapshot, IRustExternalOtherFormula, IRustExternalSheetSnapshot, IRustFormulaDataItem, IRustFormulaDependencyClearInput, IRustFormulaDependencyDirtyInput, IRustFormulaDependencyDirtyOutput, IRustFormulaDependencyExecutionOutput, IRustFormulaDependencyInspectGraph, IRustFormulaDependencyInspectNode, IRustFormulaDependencyNodeOutput, IRustFormulaDependencySyncInput, IRustFormulaDependencySyncOutput, type IRustFormulaProjectionLoadResult, type IRustFormulaProjectionMutationResult, IRustFormulaStoreState, type IRustProjectionWorkbookInput, IRustResourceSnapshot, IRustSheetSnapshot, IRustSheetState, IRustTableSnapshot, IRustVisibilityData, IRustWorkbookCalculationSnapshot, IRustWorkbookSnapshot, ISheetData, IUnitRange, type IUniverRustFormulaEngineConfig, type NumberFormatDateSystem, RUST_FORMULA_RELEVANT_MUTATIONS, RUST_INCREMENTAL_DEPENDENCY_MUTATIONS, RUST_UPSERT_PROJECTION_WORKBOOK_MUTATION_ID, RUST_UPSERT_REFERENCE_DATA_MUTATION_ID, RustCalculateFormulaService, RustEngineSyncController, RustFormulaProjectionService, UniverRustFormulaEnginePlugin, analyzeNumberFormatBatch, applyMutationOnRust, buildLexerTreeOnRust, buildRustDependencyGraphOnRust, buildSequenceNodesOnRust, checkIfAddBracketOnRust, clearRustFormulaDependenciesOnRust, clearRustFormulaDirtyOnRust, createFormulaProjectionDesyncSignal, createProjectionWorkbookUpsertMutation, disposeAllWorkbooksOnRust, disposeWorkbookOnRust, executeOnRust, formatNumberBatch, getNativeBindingSource, getRustCellOnRust, getRustDirtyDependenciesOnRust, getRustFormulaDataOnRust, getRustModelStats, getRustSheetStateOnRust, isRustFormulaRelevantMutation, isRustIncrementalDependencyMutation, loadNativeBinding, loadSnapshotOnRust, markRustFormulaDirtyOnRust, materializeWorkbookSnapshot, materializeWorkbookSnapshotOnRust, parseNumberFormatBatch, parseNumberFormatMatrixBatch, rustExecutionOutputToFormulaCalculationPatch, serializeRuntimeWorkbookSnapshot, serializeRuntimeWorkbookSnapshots, syncRustFormulaDependenciesOnRust };