@journeyapps/evaluator
Advanced tools
Comparing version 0.0.0-dev.e1bb307.8f08b9e to 0.0.0-dev.e75b697.aeec42f
import { TokenExpression } from './token-expressions/TokenExpression'; | ||
import { AttributeValidationError } from '@journeyapps/core-xml'; | ||
import { TypeInterface } from './TypeInterface'; | ||
import { FormatStringScope } from './FormatStringScope'; | ||
/** | ||
@@ -17,4 +16,4 @@ * Construct a new format string expression. | ||
isConstant(): boolean; | ||
extractRelationshipStructure(type: TypeInterface, depth?: number, into?: any): any; | ||
validate(scopeType: TypeInterface): AttributeValidationError[]; | ||
extractRelationshipStructure(type: any, depth?: number, into?: any): any; | ||
validate(scopeType: any): AttributeValidationError[]; | ||
validateAndReturnRecordings(scopeType: TypeInterface): { | ||
@@ -27,7 +26,4 @@ type: string; | ||
valueOf(): string; | ||
evaluatePromise(scope: FormatStringScope): Promise<string>; | ||
/** | ||
* If not all values are loaded yet, null is returned. | ||
*/ | ||
evaluate(scope: FormatStringScope): string; | ||
evaluatePromise(scope: any, args?: any[]): Promise<string>; | ||
evaluate(scope: any): string; | ||
} |
@@ -12,3 +12,1 @@ export * from './token-expressions/ConstantTokenExpression'; | ||
export * from './ObjectRefInterface'; | ||
export * from './FormatStringScope'; | ||
export * from './VariableFormatStringScope'; |
@@ -5,3 +5,2 @@ /** | ||
import { TokenExpression } from './TokenExpression'; | ||
import { FormatStringScope } from '../FormatStringScope'; | ||
export declare class ConstantTokenExpression extends TokenExpression { | ||
@@ -18,3 +17,2 @@ constructor(expression: string, start?: number); | ||
valueOf(): string; | ||
tokenEvaluatePromise(scope: FormatStringScope): Promise<string>; | ||
} |
@@ -6,3 +6,2 @@ /** | ||
import { TokenExpression } from './TokenExpression'; | ||
import { FormatStringScope } from '../FormatStringScope'; | ||
export declare class FormatShorthandTokenExpression extends TokenExpression { | ||
@@ -13,3 +12,2 @@ inner: ShorthandTokenExpression; | ||
toString(): string; | ||
tokenEvaluatePromise(scope: FormatStringScope): Promise<string>; | ||
} |
@@ -6,3 +6,2 @@ /** | ||
import { ConstantTokenExpression } from './ConstantTokenExpression'; | ||
import { FormatStringScope } from '../FormatStringScope'; | ||
export declare class FunctionTokenExpression extends TokenExpression { | ||
@@ -24,3 +23,2 @@ /** | ||
toConstant(includeEscapeTags?: boolean): ConstantTokenExpression; | ||
tokenEvaluatePromise(scope: FormatStringScope): Promise<string>; | ||
} |
@@ -6,3 +6,2 @@ /** | ||
import { ConstantTokenExpression } from './ConstantTokenExpression'; | ||
import { FormatStringScope } from '../FormatStringScope'; | ||
export declare class LegacyFunctionTokenExpression extends TokenExpression { | ||
@@ -16,3 +15,2 @@ constructor(expression: string, start?: number); | ||
toConstant(includeEscapeTags?: boolean): ConstantTokenExpression; | ||
tokenEvaluatePromise(scope: FormatStringScope): Promise<string>; | ||
} |
@@ -5,3 +5,2 @@ /** | ||
import { TokenExpression } from './TokenExpression'; | ||
import { FormatStringScope } from '../FormatStringScope'; | ||
export declare class PrimitiveConstantTokenExpression extends TokenExpression { | ||
@@ -18,3 +17,2 @@ constructor(expression: any, start?: number); | ||
valueOf(): any; | ||
tokenEvaluatePromise(scope: FormatStringScope): Promise<string>; | ||
} |
@@ -5,7 +5,5 @@ /** | ||
import { TokenExpression } from './TokenExpression'; | ||
import { FormatStringScope } from '../FormatStringScope'; | ||
export declare class ShorthandTokenExpression extends TokenExpression { | ||
constructor(expression: string, start?: number); | ||
isShorthand(): boolean; | ||
tokenEvaluatePromise(scope: FormatStringScope): Promise<string>; | ||
} |
/** | ||
* Abstract base token expression class. | ||
*/ | ||
import { FormatStringScope } from '../FormatStringScope'; | ||
export declare abstract class TokenExpression { | ||
export declare class TokenExpression { | ||
expression: string; | ||
@@ -10,3 +9,3 @@ start: number | undefined; | ||
isPrimitive: boolean; | ||
protected constructor(expression: string, start?: number); | ||
constructor(expression: string, start?: number); | ||
toString(): string; | ||
@@ -19,3 +18,2 @@ isConstant(): boolean; | ||
isFunction(): boolean; | ||
abstract tokenEvaluatePromise(scope: FormatStringScope): Promise<string>; | ||
} |
@@ -5,5 +5,4 @@ import { TokenExpression } from './token-expressions/TokenExpression'; | ||
import { FormatShorthandTokenExpression } from './token-expressions/FormatShorthandTokenExpression'; | ||
import { LegacyFunctionTokenExpression } from './token-expressions/LegacyFunctionTokenExpression'; | ||
import { FormatString } from './FormatString'; | ||
import { TypeInterface } from './TypeInterface'; | ||
import { LegacyFunctionTokenExpression } from './token-expressions/LegacyFunctionTokenExpression'; | ||
export declare function unescape(s: string): string; | ||
@@ -37,4 +36,2 @@ export declare function parseEnclosingBraces(format: string): { | ||
export declare function actionableTokenExpression(expression: string): FunctionTokenExpression | ShorthandTokenExpression | FormatShorthandTokenExpression; | ||
export declare function formatValue(value: any, type: TypeInterface, format: string): string; | ||
export declare function formatValueAsync(value: any, type: TypeInterface, format: string): Promise<string>; | ||
export { compile as _compile, deepMerge as _deepMerge }; |
@@ -5,6 +5,5 @@ export interface TypeInterface { | ||
getVariableTypeAndNameWithParent(expression: string): any; | ||
getType(expression: string): TypeInterface | null; | ||
getType(variable: any): any; | ||
toJSON(): any; | ||
format(value: any, format?: string): string; | ||
options: object; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tools_1 = require("./tools"); | ||
; | ||
/** | ||
@@ -57,3 +56,3 @@ * Construct a new format string expression. | ||
} | ||
var type = scopeType.getType(expression); | ||
var type = scopeType.getVariable(expression); | ||
if (type == null) { | ||
@@ -117,64 +116,8 @@ results.push({ | ||
; | ||
evaluatePromise(scope) { | ||
const tokens = this.tokens; | ||
let promises = []; | ||
for (let i = 0; i < tokens.length; i++) { | ||
const token = tokens[i]; | ||
if (token.isConstant()) { | ||
// Nothing | ||
} | ||
else { | ||
const promise = token.tokenEvaluatePromise(scope); | ||
promises.push(promise); | ||
} | ||
} | ||
return Promise.all(promises).then(function (results) { | ||
let result = ''; | ||
let promiseIndex = 0; | ||
for (let i = 0; i < tokens.length; i++) { | ||
const token = tokens[i]; | ||
if (token.isConstant()) { | ||
result += token.valueOf(); | ||
} | ||
else { | ||
result += results[promiseIndex]; | ||
promiseIndex += 1; | ||
} | ||
} | ||
return result; | ||
}); | ||
// Implemented elsewhere | ||
evaluatePromise(scope, args) { | ||
throw new Error('Not implemented'); | ||
} | ||
/** | ||
* If not all values are loaded yet, null is returned. | ||
*/ | ||
evaluate(scope) { | ||
const tokens = this.tokens; | ||
let result = ''; | ||
for (let i = 0; i < tokens.length; i++) { | ||
const token = tokens[i]; | ||
if (token.isConstant()) { | ||
result += token.valueOf(); | ||
} | ||
else if (token.isFunction()) { | ||
// Not supported - return the original expression | ||
result += token.toConstant(true).valueOf(); | ||
} | ||
else { | ||
let expression = token.expression; | ||
if (expression.length > 0 && expression[0] == '?') { | ||
expression = expression.substring(1); | ||
} | ||
const value = scope.getValue(expression); | ||
if (value === undefined) { | ||
// Still loading | ||
return null; | ||
} | ||
else { | ||
const type = scope.getExpressionType(expression); | ||
const text = tools_1.formatValue(value, type, token.format); | ||
result += text; | ||
} | ||
} | ||
} | ||
return result; | ||
throw new Error('Not implemented'); | ||
} | ||
@@ -181,0 +124,0 @@ } |
@@ -15,3 +15,2 @@ "use strict"; | ||
__export(require("./tools")); | ||
__export(require("./VariableFormatStringScope")); | ||
//# sourceMappingURL=index.js.map |
@@ -27,7 +27,4 @@ "use strict"; | ||
} | ||
async tokenEvaluatePromise(scope) { | ||
return this.expression; | ||
} | ||
} | ||
exports.ConstantTokenExpression = ConstantTokenExpression; | ||
//# sourceMappingURL=ConstantTokenExpression.js.map |
@@ -8,3 +8,2 @@ "use strict"; | ||
const TokenExpression_1 = require("./TokenExpression"); | ||
const tools_1 = require("../tools"); | ||
class FormatShorthandTokenExpression extends TokenExpression_1.TokenExpression { | ||
@@ -31,13 +30,4 @@ constructor(expression, format, start) { | ||
} | ||
async tokenEvaluatePromise(scope) { | ||
let expression = this.expression; | ||
if (expression.length > 0 && expression[0] == '?') { | ||
expression = expression.substring(1); | ||
} | ||
const value = await scope.getValuePromise(expression); | ||
const type = scope.getExpressionType(expression); | ||
return tools_1.formatValueAsync(value, type, this.format); | ||
} | ||
} | ||
exports.FormatShorthandTokenExpression = FormatShorthandTokenExpression; | ||
//# sourceMappingURL=FormatShorthandTokenExpression.js.map |
@@ -11,4 +11,4 @@ "use strict"; | ||
// remove indicator prefix from expression | ||
const prefix = FunctionTokenExpression.PREFIX; | ||
let processedExpression = expression.trim(); | ||
var prefix = FunctionTokenExpression.PREFIX; | ||
var processedExpression = expression.trim(); | ||
if (processedExpression.indexOf(prefix) === 0) { | ||
@@ -37,3 +37,3 @@ processedExpression = processedExpression.substr(prefix.length); | ||
} | ||
let constantExpression = FunctionTokenExpression.PREFIX + this.expression; | ||
var constantExpression = FunctionTokenExpression.PREFIX + this.expression; | ||
if (includeEscapeTags) { | ||
@@ -44,9 +44,2 @@ constantExpression = '{' + constantExpression + '}'; | ||
} | ||
async tokenEvaluatePromise(scope) { | ||
const value = await scope.evaluateFunctionExpression(this.expression); | ||
// FIXME: FunctionTokenExpression is not only used for FormatStrings, but | ||
// also for other attributes, e.g. show-if. For those cases, we need the | ||
// original value, not a string, so we can't convert to a string here. | ||
return value; | ||
} | ||
} | ||
@@ -53,0 +46,0 @@ /** |
@@ -29,7 +29,4 @@ "use strict"; | ||
} | ||
tokenEvaluatePromise(scope) { | ||
throw new Error('not implemented'); | ||
} | ||
} | ||
exports.LegacyFunctionTokenExpression = LegacyFunctionTokenExpression; | ||
//# sourceMappingURL=LegacyFunctionTokenExpression.js.map |
@@ -28,7 +28,4 @@ "use strict"; | ||
} | ||
async tokenEvaluatePromise(scope) { | ||
return this.expression; | ||
} | ||
} | ||
exports.PrimitiveConstantTokenExpression = PrimitiveConstantTokenExpression; | ||
//# sourceMappingURL=PrimitiveConstantTokenExpression.js.map |
@@ -7,3 +7,2 @@ "use strict"; | ||
const TokenExpression_1 = require("./TokenExpression"); | ||
const tools_1 = require("../tools"); | ||
class ShorthandTokenExpression extends TokenExpression_1.TokenExpression { | ||
@@ -16,13 +15,4 @@ constructor(expression, start) { | ||
} | ||
async tokenEvaluatePromise(scope) { | ||
let expression = this.expression; | ||
if (expression.length > 0 && expression[0] == '?') { | ||
expression = expression.substring(1); | ||
} | ||
const value = await scope.getValuePromise(expression); | ||
const type = scope.getExpressionType(expression); | ||
return tools_1.formatValueAsync(value, type, this.format); | ||
} | ||
} | ||
exports.ShorthandTokenExpression = ShorthandTokenExpression; | ||
//# sourceMappingURL=ShorthandTokenExpression.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Abstract base token expression class. | ||
*/ | ||
class TokenExpression { | ||
@@ -4,0 +7,0 @@ constructor(expression, start) { |
@@ -7,4 +7,4 @@ "use strict"; | ||
const FormatShorthandTokenExpression_1 = require("./token-expressions/FormatShorthandTokenExpression"); | ||
const LegacyFunctionTokenExpression_1 = require("./token-expressions/LegacyFunctionTokenExpression"); | ||
const FormatString_1 = require("./FormatString"); | ||
const LegacyFunctionTokenExpression_1 = require("./token-expressions/LegacyFunctionTokenExpression"); | ||
function unescape(s) { | ||
@@ -262,28 +262,2 @@ var start = 0; | ||
exports.actionableTokenExpression = actionableTokenExpression; | ||
// Format an expression with a specific format. | ||
// Return a promise resolving with the formatted value. | ||
function formatValue(value, type, format) { | ||
if (value == null) { | ||
return ''; | ||
} | ||
else if (type != null) { | ||
return type.format(value, format); | ||
} | ||
else { | ||
// This should generally not happen. However, we still try to handle it gracefully. | ||
// This is useful for tests where we don't want to define the type for every variable. | ||
return value.toString(); | ||
} | ||
} | ||
exports.formatValue = formatValue; | ||
async function formatValueAsync(value, type, format) { | ||
if (value != null && typeof value._display == 'function') { | ||
// Object - recursive promise-based formatting. | ||
return value._display(); | ||
} | ||
else { | ||
return formatValue(value, type, format); | ||
} | ||
} | ||
exports.formatValueAsync = formatValueAsync; | ||
//# sourceMappingURL=tools.js.map |
{ | ||
"name": "@journeyapps/evaluator", | ||
"version": "0.0.0-dev.e1bb307.8f08b9e", | ||
"version": "0.0.0-dev.e75b697.aeec42f", | ||
"description": "Journey JS library", | ||
@@ -14,3 +14,3 @@ "main": "./dist/src/index.js", | ||
"dependencies": { | ||
"@journeyapps/core-xml": "0.0.0-dev.e1bb307.8f08b9e" | ||
"@journeyapps/core-xml": "0.0.0-dev.e75b697.aeec42f" | ||
}, | ||
@@ -21,3 +21,3 @@ "files": [ | ||
], | ||
"gitHead": "c4e4938d2eb360efe52455f2d8f6465ab90a309e" | ||
"gitHead": "083e0e6efde58efa4fb04cdcb64ea284cdde8011" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73125
40
821
+ Added@journeyapps/core-xml@0.0.0-dev.e75b697.aeec42f(transitive)
- Removed@journeyapps/core-xml@0.0.0-dev.e1bb307.8f08b9e(transitive)