MCPcopy Create free account
hub / github.com/apitable/apitable / Max

Class Max

packages/core/src/formula_parser/functions/numeric.ts:240–292  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

238}
239
240export class Max extends NumericFunc {
241 static override acceptValueType = new Set([BasicValueType.DateTime, BasicValueType.Array, ...FormulaFunc.acceptValueType]);
242
243 static override validateParams(_params: AstNode[]) {
244 //
245 }
246
247 static override getReturnType(params: AstNode[]) {
248 params && this.validateParams(params);
249 if (!params) {
250 return BasicValueType.Number;
251 }
252
253 if (isArrayNodes(params)) {
254 const innerValueType = (params[0] as ValueOperandNodeBase).innerValueType;
255 if (innerValueType === BasicValueType.DateTime) {
256 return BasicValueType.DateTime;
257 }
258 return BasicValueType.Number;
259 }
260
261 // All parameters are date type, return date type
262 if (params.every(node => node.valueType === BasicValueType.DateTime)) {
263 return BasicValueType.DateTime;
264 }
265
266 return BasicValueType.Number;
267 }
268
269 static override func(params: IFormulaParam<number>[]): NumericType {
270 return this.calc(params, max);
271 }
272
273 static calc(params: IFormulaParam<number>[], calcFn: (collection: any[]) => any): NumericType {
274 // If there is only one parameter and it is an array, it means that the value of the array type field is summed
275 if (isArrayParam(params)) {
276 if (!params[0].value) {
277 return null;
278 }
279 const v = calcFn(params[0].value.map(Number).filter(d => !isNaN(d)));
280 return v == null ? null : Number(v);
281 }
282
283 // If the return value is DateTime, the node of DateTime type should be filtered out,
284 // otherwise the timestamp will be introduced to disturb the calculation result
285 if (this.getReturnType(params.map(p => p.node)) !== BasicValueType.DateTime) {
286 params = params.filter(p => p.node.valueType !== BasicValueType.DateTime);
287 }
288
289 const v = calcFn(params.map(p => Number(p.value)).filter(d => !isNaN(d)));
290 return v == null ? 0 : Number(v);
291 }
292}
293
294// The Min function is different from Max only in the calculation method calcFn
295export class Min extends Max {

Callers 4

page.ro.tsFile · 0.85
AssetUploadQueryRoClass · 0.85
NodeListQueryRoClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected