Skip to content

Commit

Permalink
Change some utility functions in Adaptive-Expressions to internal (#2796
Browse files Browse the repository at this point in the history
)

* make some util func internal in AE

* minr doc format change

* rename dateFunc

* dateFunc export in index.ts
  • Loading branch information
cosmicshuai authored Sep 25, 2020
1 parent ca751f7 commit 6d34e8b
Show file tree
Hide file tree
Showing 78 changed files with 635 additions and 536 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Expression } from '../expression';
import { ExpressionEvaluator, ValueWithError } from '../expressionEvaluator';
import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { MemoryInterface } from '../memory/memoryInterface';
import { SimpleObjectMemory } from '../memory/simpleObjectMemory';
import { Options } from '../options';
Expand All @@ -34,7 +35,7 @@ export class Accessor extends ExpressionEvaluator {

if (left == undefined) {
// fully converted to path, so we just delegate to memory scope
return { value: FunctionUtils.wrapGetValue(state, path, options), error: undefined };
return { value: InternalFunctionUtils.wrapGetValue(state, path, options), error: undefined };
} else {
let newScope: any;
let err: string;
Expand All @@ -43,7 +44,7 @@ export class Accessor extends ExpressionEvaluator {
return { value: undefined, error: err };
}

return { value: FunctionUtils.wrapGetValue(new SimpleObjectMemory(newScope), path, options), error: undefined };
return { value: InternalFunctionUtils.wrapGetValue(new SimpleObjectMemory(newScope), path, options), error: undefined };
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Expression } from '../expression';
import { ExpressionEvaluator, ValueWithError } from '../expressionEvaluator';
import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { MemoryInterface } from '../memory/memoryInterface';
import { Options } from '../options';
import { ReturnType } from '../returnType';
Expand Down Expand Up @@ -45,7 +46,7 @@ export class AddToTime extends ExpressionEvaluator {
let result: string;
let error: string;
let parsed: any;
({ value: parsed, error } = FunctionUtils.parseTimestamp(timeStamp));
({ value: parsed, error } = InternalFunctionUtils.parseTimestamp(timeStamp));
if (!error) {
let dt: any = moment(parsed).utc();
let addedTime = dt;
Expand Down Expand Up @@ -94,7 +95,7 @@ export class AddToTime extends ExpressionEvaluator {

if (!error) {
addedTime = dt.add(interval, timeUnitMark);
({ value: result, error } = FunctionUtils.returnFormattedTimeStampStr(addedTime, format));
({ value: result, error } = InternalFunctionUtils.returnFormattedTimeStampStr(addedTime, format));
}
}

Expand Down
3 changes: 2 additions & 1 deletion libraries/adaptive-expressions/src/builtinFunctions/and.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Expression } from '../expression';
import { ExpressionEvaluator, ValueWithError } from '../expressionEvaluator';
import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { MemoryInterface } from '../memory/memoryInterface';
import { Options } from '../options';
import { ReturnType } from '../returnType';
Expand All @@ -30,7 +31,7 @@ export class And extends ExpressionEvaluator {
newOptions.nullSubstitution = undefined;
({ value: result, error } = child.tryEvaluate(state, newOptions));
if (!error) {
if (FunctionUtils.isLogicTrue(result)) {
if (InternalFunctionUtils.isLogicTrue(result)) {
result = true;
} else {
result = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { EvaluateExpressionDelegate, ExpressionEvaluator } from '../expressionEvaluator';
import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { ReturnType } from '../returnType';

import atob = require('atob-lite');
Expand All @@ -25,7 +26,7 @@ export class Base64ToBinary extends ExpressionEvaluator {
return FunctionUtils.apply(
(args: Readonly<any>): Uint8Array => {
const raw = atob(args[0].toString());
return FunctionUtils.toBinary(raw);
return InternalFunctionUtils.toBinary(raw);
}, FunctionUtils.verifyString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { EvaluateExpressionDelegate, ExpressionEvaluator } from '../expressionEvaluator';
import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { ReturnType } from '../returnType';

/**
Expand All @@ -20,6 +21,6 @@ export class Binary extends ExpressionEvaluator {
}

private static evaluator(): EvaluateExpressionDelegate {
return FunctionUtils.apply((args: any[]): Uint8Array => FunctionUtils.toBinary(args[0]), FunctionUtils.verifyString);
return FunctionUtils.apply((args: any[]): Uint8Array => InternalFunctionUtils.toBinary(args[0]), FunctionUtils.verifyString);
}
}
3 changes: 2 additions & 1 deletion libraries/adaptive-expressions/src/builtinFunctions/bool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { ComparisonEvaluator } from './comparisonEvaluator';

/**
Expand All @@ -19,6 +20,6 @@ export class Bool extends ComparisonEvaluator {
}

private static func(args: any[]): boolean {
return FunctionUtils.isLogicTrue(args[0]);
return InternalFunctionUtils.isLogicTrue(args[0]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Expression } from '../expression';
import { ExpressionEvaluator, ValueWithError } from '../expressionEvaluator';
import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { MemoryInterface } from '../memory/memoryInterface';
import { Options } from '../options';
import { ReturnType } from '../returnType';
Expand All @@ -36,7 +37,7 @@ export class Contains extends ExpressionEvaluator {
found = (args[0] as Map<string, any>).get(args[1]) !== undefined;
} else if (typeof args[1] === 'string') {
let value: any;
({ value, error } = FunctionUtils.accessProperty(args[0], args[1]));
({ value, error } = InternalFunctionUtils.accessProperty(args[0], args[1]));
found = !error && value !== undefined;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Expression } from '../expression';
import { ExpressionEvaluator, ValueWithError } from '../expressionEvaluator';
import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { MemoryInterface } from '../memory/memoryInterface';
import { Options } from '../options';
import { ReturnType } from '../returnType';
Expand Down Expand Up @@ -48,7 +49,7 @@ export class ConvertFromUTC extends ExpressionEvaluator {
private static evalConvertFromUTC(timeStamp: string, destinationTimeZone: string, format?: string): ValueWithError {
let result: string;
let error: string;
error = FunctionUtils.verifyISOTimestamp(timeStamp);
error = InternalFunctionUtils.verifyISOTimestamp(timeStamp);
const timeZone: string = TimeZoneConverter.windowsToIana(destinationTimeZone);
if (!TimeZoneConverter.verifyTimeZoneStr(timeZone)) {
error = `${destinationTimeZone} is not a valid timezone`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { EvaluateExpressionDelegate, ExpressionEvaluator } from '../expressionEvaluator';
import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { ReturnType } from '../returnType';

/**
Expand All @@ -20,6 +21,6 @@ export class CountWord extends ExpressionEvaluator {
}

private static evaluator(): EvaluateExpressionDelegate {
return FunctionUtils.apply((args: any[]): number => FunctionUtils.parseStringOrUndefined(args[0]).trim().split(/\s+/).length, FunctionUtils.verifyStringOrNull);
return FunctionUtils.apply((args: any[]): number => InternalFunctionUtils.parseStringOrUndefined(args[0]).trim().split(/\s+/).length, FunctionUtils.verifyStringOrNull);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { EvaluateExpressionDelegate, ExpressionEvaluator } from '../expressionEvaluator';
import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { ReturnType } from '../returnType';

/**
Expand All @@ -20,6 +21,6 @@ export class DataUriToBinary extends ExpressionEvaluator {
}

private static evaluator(): EvaluateExpressionDelegate {
return FunctionUtils.apply((args: any[]): Uint8Array => FunctionUtils.toBinary(args[0]), FunctionUtils.verifyString);
return FunctionUtils.apply((args: any[]): Uint8Array => InternalFunctionUtils.toBinary(args[0]), FunctionUtils.verifyString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import moment from 'moment';
import { EvaluateExpressionDelegate, ExpressionEvaluator } from '../expressionEvaluator';
import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { ReturnType } from '../returnType';

/**
Expand All @@ -23,7 +24,7 @@ export class DateFunc extends ExpressionEvaluator {

private static evaluator(): EvaluateExpressionDelegate {
return FunctionUtils.applyWithError(
(args: any[]): any => FunctionUtils.parseTimestamp(args[0], (timestamp: Date): string => moment(timestamp).utc().format('M/DD/YYYY')),
(args: any[]): any => InternalFunctionUtils.parseTimestamp(args[0], (timestamp: Date): string => moment(timestamp).utc().format('M/DD/YYYY')),
FunctionUtils.verifyString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Expression } from '../expression';
import { EvaluateExpressionDelegate, ExpressionEvaluator } from '../expressionEvaluator';
import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { ReturnType } from '../returnType';

/**
Expand All @@ -28,10 +29,10 @@ export class DateReadBack extends ExpressionEvaluator {
let value: any;
let error: string;
const dateFormat = 'YYYY-MM-DD';
({ value, error } = FunctionUtils.parseTimestamp(args[0]));
({ value, error } = InternalFunctionUtils.parseTimestamp(args[0]));
if (!error) {
const timestamp1: Date = new Date(value.format(dateFormat));
({ value, error } = FunctionUtils.parseTimestamp(args[1]));
({ value, error } = InternalFunctionUtils.parseTimestamp(args[1]));
const timestamp2: string = value.format(dateFormat);
const timex: TimexProperty = new TimexProperty(timestamp2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Expression } from '../expression';
import { ExpressionEvaluator, ValueWithError } from '../expressionEvaluator';
import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { MemoryInterface } from '../memory/memoryInterface';
import { Options } from '../options';
import { ReturnType } from '../returnType';
Expand All @@ -30,9 +31,9 @@ export class DateTimeDiff extends ExpressionEvaluator {
let args: any[];
({ args, error } = FunctionUtils.evaluateChildren(expr, state, options));
if (!error) {
({ value: dateTimeStart, error: error } = FunctionUtils.ticks(args[0]));
({ value: dateTimeStart, error: error } = InternalFunctionUtils.ticks(args[0]));
if (!error) {
({ value: dateTimeEnd, error: error } = FunctionUtils.ticks(args[1]));
({ value: dateTimeEnd, error: error } = InternalFunctionUtils.ticks(args[1]));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { EvaluateExpressionDelegate, ExpressionEvaluator } from '../expressionEvaluator';
import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { ReturnType } from '../returnType';

/**
Expand All @@ -21,7 +22,7 @@ export class DayOfMonth extends ExpressionEvaluator {

private static evaluator(): EvaluateExpressionDelegate {
return FunctionUtils.applyWithError(
(args: any[]): any => FunctionUtils.parseTimestamp(args[0], (timestamp: Date): number => timestamp.getUTCDate()),
(args: any[]): any => InternalFunctionUtils.parseTimestamp(args[0], (timestamp: Date): number => timestamp.getUTCDate()),
FunctionUtils.verifyString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { EvaluateExpressionDelegate, ExpressionEvaluator } from '../expressionEvaluator';
import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { ReturnType } from '../returnType';

/**
Expand All @@ -21,7 +22,7 @@ export class DayOfWeek extends ExpressionEvaluator {

private static evaluator(): EvaluateExpressionDelegate {
return FunctionUtils.applyWithError(
(args: any[]): any => FunctionUtils.parseTimestamp(args[0], (timestamp: Date): number => timestamp.getUTCDay()),
(args: any[]): any => InternalFunctionUtils.parseTimestamp(args[0], (timestamp: Date): number => timestamp.getUTCDay()),
FunctionUtils.verifyString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import moment from 'moment';
import { EvaluateExpressionDelegate, ExpressionEvaluator } from '../expressionEvaluator';
import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { ReturnType } from '../returnType';

/**
Expand All @@ -23,7 +24,7 @@ export class DayOfYear extends ExpressionEvaluator {

private static evaluator(): EvaluateExpressionDelegate {
return FunctionUtils.applyWithError(
(args: any[]): any => FunctionUtils.parseTimestamp(args[0], (timestamp: Date): number => moment(timestamp).utc().dayOfYear()),
(args: any[]): any => InternalFunctionUtils.parseTimestamp(args[0], (timestamp: Date): number => moment(timestamp).utc().dayOfYear()),
FunctionUtils.verifyString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Expression } from '../expression';
import { ExpressionEvaluator, ValueWithError } from '../expressionEvaluator';
import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { MemoryInterface } from '../memory/memoryInterface';
import { Options } from '../options';
import { ReturnType } from '../returnType';
Expand Down Expand Up @@ -37,9 +38,9 @@ export class Element extends ExpressionEvaluator {
({ value: idxValue, error } = index.tryEvaluate(state, newOptions));
if (!error) {
if (Number.isInteger(idxValue)) {
({ value, error } = FunctionUtils.accessIndex(inst, Number(idxValue)));
({ value, error } = InternalFunctionUtils.accessIndex(inst, Number(idxValue)));
} else if (typeof idxValue === 'string') {
({ value, error } = FunctionUtils.accessProperty(inst, idxValue.toString()));
({ value, error } = InternalFunctionUtils.accessProperty(inst, idxValue.toString()));
} else {
error = `Could not coerce ${index} to an int or string.`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Expression } from '../expression';
import { EvaluateExpressionDelegate, ExpressionEvaluator } from '../expressionEvaluator';
import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { ReturnType } from '../returnType';

/**
Expand All @@ -22,7 +23,7 @@ export class EndsWith extends ExpressionEvaluator {
}

private static evaluator(): EvaluateExpressionDelegate {
return FunctionUtils.apply((args: any[]): boolean => FunctionUtils.parseStringOrUndefined(args[0]).endsWith(FunctionUtils.parseStringOrUndefined(args[1])), FunctionUtils.verifyStringOrNull);
return FunctionUtils.apply((args: any[]): boolean => InternalFunctionUtils.parseStringOrUndefined(args[0]).endsWith(InternalFunctionUtils.parseStringOrUndefined(args[1])), FunctionUtils.verifyStringOrNull);
}

private static validator(expression: Expression): void {
Expand Down
3 changes: 2 additions & 1 deletion libraries/adaptive-expressions/src/builtinFunctions/equal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { ComparisonEvaluator } from './comparisonEvaluator';

/**
Expand All @@ -16,6 +17,6 @@ import { ComparisonEvaluator } from './comparisonEvaluator';
*/
export class Equal extends ComparisonEvaluator {
public constructor() {
super(ExpressionType.Equal, FunctionUtils.isEqual, FunctionUtils.validateBinary);
super(ExpressionType.Equal, InternalFunctionUtils.isEqual, FunctionUtils.validateBinary);
}
}
3 changes: 2 additions & 1 deletion libraries/adaptive-expressions/src/builtinFunctions/first.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { EvaluateExpressionDelegate, ExpressionEvaluator } from '../expressionEvaluator';
import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { ReturnType } from '../returnType';

/**
Expand All @@ -28,7 +29,7 @@ export class First extends ExpressionEvaluator {
}

if (Array.isArray(args[0]) && args[0].length > 0) {
first = FunctionUtils.accessIndex(args[0], 0).value;
first = InternalFunctionUtils.accessIndex(args[0], 0).value;
}

return first;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

import { ExpressionEvaluator } from '../expressionEvaluator';
import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { ReturnType } from '../returnType';

/**
* Operate on each element and return the new collection.
*/
export class Foreach extends ExpressionEvaluator {
public constructor() {
super(ExpressionType.Foreach, FunctionUtils.foreach, ReturnType.Array, FunctionUtils.validateForeach);
super(ExpressionType.Foreach, InternalFunctionUtils.foreach, ReturnType.Array, InternalFunctionUtils.validateForeach);
}
}
Loading

0 comments on commit 6d34e8b

Please sign in to comment.