@univerjs/engine-formula 0.5.2 → 0.5.3

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,7 @@
1
+ import { ICellData, Nullable } from '@univerjs/core';
2
+ /**
3
+ * Examine if a cell is empty (null) in the formula-related modules. This is not
4
+ * interchangable with {@link isNullCell} from the core package, because for
5
+ * formulas, "custom" field is meaningless.
6
+ */
7
+ export declare function isNullCellForFormula(cell: Nullable<ICellData>): boolean;
@@ -32,7 +32,14 @@ export declare class FunctionNode extends BaseAstNode {
32
32
  * the LOOKUP function will continue using the last value of the result_vector for lookup and returning results after the last value of the lookup_vector.
33
33
  */
34
34
  private _lookupCompatibility;
35
+ /**
36
+ * Transform the result of a custom function to a NodeValueType.
37
+ */
38
+ private _handleCustomResult;
39
+ private _handleAddressFunction;
40
+ private _mapVariantsToValues;
35
41
  private _calculate;
42
+ private _calculateAsync;
36
43
  private _setDefinedNamesForFunction;
37
44
  private _setRefInfo;
38
45
  private _setRefData;
@@ -2,6 +2,7 @@ import { FormulaAstLRU } from '../../basics/cache-lru';
2
2
  import { compareToken } from '../../basics/token';
3
3
  import { BaseValueObject, ErrorValueObject } from './base-value-object';
4
4
  export type PrimitiveValueType = string | boolean | number | null;
5
+ export type FormulaFunctionValueType = PrimitiveValueType | PrimitiveValueType[][];
5
6
  export declare class NullValueObject extends BaseValueObject {
6
7
  private static _instance;
7
8
  static create(): NullValueObject;
@@ -4,10 +4,11 @@ import { FormulaExecutedStateType, IExecutionInProgressParams } from '@univerjs/
4
4
  * This interface class provides methods to modify the behavior of the operation formula.
5
5
  */
6
6
  export declare class FFormula extends FBase {
7
- private readonly _commandService;
7
+ protected readonly _commandService: ICommandService;
8
8
  protected readonly _injector: Injector;
9
9
  protected readonly _configService: IConfigService;
10
10
  constructor(_commandService: ICommandService, _injector: Injector, _configService: IConfigService);
11
+ _initialize(): void;
11
12
  /**
12
13
  * Start the calculation of the formula.
13
14
  */
@@ -3,10 +3,10 @@ import { IFunctionNames } from '../basics/function';
3
3
  import { BaseReferenceObject, FunctionVariantType, NodeValueType } from '../engine/reference-object/base-reference-object';
4
4
  import { ArrayBinarySearchType, ArrayOrderSearchType } from '../engine/utils/compare';
5
5
  import { ArrayValueObject } from '../engine/value-object/array-value-object';
6
+ import { FormulaFunctionValueType } from '../engine/value-object/primitive-object';
6
7
  import { FormulaDataModel } from '../models/formula-data.model';
7
8
  import { IDefinedNameMapItem } from '../services/defined-names.service';
8
9
  import { BaseValueObject, ErrorValueObject } from '../engine/value-object/base-value-object';
9
- import { PrimitiveValueType } from '../engine/value-object/primitive-object';
10
10
  export declare class BaseFunction {
11
11
  private _name;
12
12
  private _unitId;
@@ -87,7 +87,7 @@ export declare class BaseFunction {
87
87
  isAddress(): boolean;
88
88
  isCustom(): boolean;
89
89
  setRefInfo(unitId: string, subUnitId: string, row: number, column: number): void;
90
- calculateCustom(...arg: Array<PrimitiveValueType | PrimitiveValueType[][]>): PrimitiveValueType | PrimitiveValueType[][];
90
+ calculateCustom(...arg: Array<FormulaFunctionValueType>): FormulaFunctionValueType | Promise<FormulaFunctionValueType>;
91
91
  calculate(...arg: BaseValueObject[]): NodeValueType;
92
92
  checkArrayType(variant: FunctionVariantType): boolean;
93
93
  /**
@@ -2,3 +2,6 @@ import { BaseFunction } from './base-function';
2
2
  export declare class CustomFunction extends BaseFunction {
3
3
  isCustom(): boolean;
4
4
  }
5
+ export declare class AsyncCustomFunction extends CustomFunction {
6
+ isAsync(): boolean;
7
+ }
@@ -61,7 +61,7 @@ export { handleRefStringInfo } from './engine/utils/reference';
61
61
  export { generateStringWithSequence, type ISequenceNode, sequenceNodeType } from './engine/utils/sequence';
62
62
  export { ArrayValueObject, ValueObjectFactory } from './engine/value-object/array-value-object';
63
63
  export { BaseValueObject, ErrorValueObject } from './engine/value-object/base-value-object';
64
- export type { PrimitiveValueType } from './engine/value-object/primitive-object';
64
+ export type { FormulaFunctionValueType, PrimitiveValueType } from './engine/value-object/primitive-object';
65
65
  export { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from './engine/value-object/primitive-object';
66
66
  export { functionArray } from './functions/array/function-map';
67
67
  export { FUNCTION_NAMES_ARRAY } from './functions/array/function-names';
@@ -70,7 +70,7 @@ export { functionCompatibility } from './functions/compatibility/function-map';
70
70
  export { FUNCTION_NAMES_COMPATIBILITY } from './functions/compatibility/function-names';
71
71
  export { functionCube } from './functions/cube/function-map';
72
72
  export { FUNCTION_NAMES_CUBE } from './functions/cube/function-names';
73
- export { CustomFunction } from './functions/custom-function';
73
+ export { AsyncCustomFunction, CustomFunction } from './functions/custom-function';
74
74
  export { functionDatabase } from './functions/database/function-map';
75
75
  export { FUNCTION_NAMES_DATABASE } from './functions/database/function-names';
76
76
  export { functionDate } from './functions/date/function-map';
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(a,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("@univerjs/core"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-formula"],n):(a=typeof globalThis<"u"?globalThis:a||self,n(a.UniverEngineFormulaFacade={},a.UniverCore,a.UniverEngineFormula))})(this,function(a,n,r){"use strict";var m=Object.defineProperty,d=Object.getOwnPropertyDescriptor,f=(u,e,t,i)=>{for(var o=i>1?void 0:i?d(e,t):e,s=u.length-1,l;s>=0;s--)(l=u[s])&&(o=(i?l(e,t,o):l(o))||o);return i&&o&&m(e,t,o),o},c=(u,e)=>(t,i)=>e(t,i,u);a.FFormula=class extends n.FBase{constructor(e,t,i){super(),this._commandService=e,this._injector=t,this._configService=i}executeCalculation(){this._commandService.executeCommand(r.SetFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})}stopCalculation(){this._commandService.executeCommand(r.SetFormulaCalculationStopMutation.id,{})}calculationStart(e){return this._commandService.onCommandExecuted(t=>{if(t.id===r.SetFormulaCalculationStartMutation.id){const i=t.params;e(i.forceCalculation)}})}calculationEnd(e){return this._commandService.onCommandExecuted(t=>{if(t.id!==r.SetFormulaCalculationNotificationMutation.id)return;const i=t.params;i.functionsExecutedState!==void 0&&e(i.functionsExecutedState)})}onCalculationEnd(){return new Promise((e,t)=>{const i=setTimeout(()=>{t(new Error("Calculation end timeout"))},3e4),o=this.calculationEnd(()=>{clearTimeout(i),o.dispose(),e()})})}calculationProcessing(e){return this._commandService.onCommandExecuted(t=>{if(t.id!==r.SetFormulaCalculationNotificationMutation.id)return;const i=t.params;i.stageInfo!==void 0&&e(i.stageInfo)})}setMaxIteration(e){this._configService.setConfig(r.ENGINE_FORMULA_CYCLE_REFERENCE_COUNT,e)}},a.FFormula=f([c(0,n.Inject(n.ICommandService)),c(1,n.Inject(n.Injector)),c(2,n.IConfigService)],a.FFormula);class v extends n.FUniver{getFormula(){return this._injector.createInstance(a.FFormula)}}n.FUniver.extend(v),Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
1
+ (function(a,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("@univerjs/core"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-formula"],n):(a=typeof globalThis<"u"?globalThis:a||self,n(a.UniverEngineFormulaFacade={},a.UniverCore,a.UniverEngineFormula))})(this,function(a,n,r){"use strict";var m=Object.defineProperty,d=Object.getOwnPropertyDescriptor,f=(u,e,t,i)=>{for(var o=i>1?void 0:i?d(e,t):e,s=u.length-1,l;s>=0;s--)(l=u[s])&&(o=(i?l(e,t,o):l(o))||o);return i&&o&&m(e,t,o),o},c=(u,e)=>(t,i)=>e(t,i,u);a.FFormula=class extends n.FBase{constructor(e,t,i){super(),this._commandService=e,this._injector=t,this._configService=i,this._initialize()}_initialize(){}executeCalculation(){this._commandService.executeCommand(r.SetFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})}stopCalculation(){this._commandService.executeCommand(r.SetFormulaCalculationStopMutation.id,{})}calculationStart(e){return this._commandService.onCommandExecuted(t=>{if(t.id===r.SetFormulaCalculationStartMutation.id){const i=t.params;e(i.forceCalculation)}})}calculationEnd(e){return this._commandService.onCommandExecuted(t=>{if(t.id!==r.SetFormulaCalculationNotificationMutation.id)return;const i=t.params;i.functionsExecutedState!==void 0&&e(i.functionsExecutedState)})}onCalculationEnd(){return new Promise((e,t)=>{const i=setTimeout(()=>{t(new Error("Calculation end timeout"))},3e4),o=this.calculationEnd(()=>{clearTimeout(i),o.dispose(),e()})})}calculationProcessing(e){return this._commandService.onCommandExecuted(t=>{if(t.id!==r.SetFormulaCalculationNotificationMutation.id)return;const i=t.params;i.stageInfo!==void 0&&e(i.stageInfo)})}setMaxIteration(e){this._configService.setConfig(r.ENGINE_FORMULA_CYCLE_REFERENCE_COUNT,e)}},a.FFormula=f([c(0,n.Inject(n.ICommandService)),c(1,n.Inject(n.Injector)),c(2,n.IConfigService)],a.FFormula);class v extends n.FUniver{getFormula(){return this._injector.createInstance(a.FFormula)}}n.FUniver.extend(v),Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});