@journeyapps/evaluator
Advanced tools
Comparing version 0.0.0-dev.5adc6f7.38d3f91 to 0.0.0-dev.5c49be1.abbc3a7
import { TokenExpression } from './token-expressions/TokenExpression'; | ||
import { AttributeValidationError } from '@journeyapps/core-xml'; | ||
import { TypeInterface } from './TypeInterface'; | ||
import { FormatStringScope } from './FormatStringScope'; | ||
/** | ||
@@ -16,4 +17,4 @@ * Construct a new format string expression. | ||
isConstant(): boolean; | ||
extractRelationshipStructure(type: any, depth?: number, into?: any): any; | ||
validate(scopeType: any): AttributeValidationError[]; | ||
extractRelationshipStructure(type: TypeInterface, depth?: number, into?: any): any; | ||
validate(scopeType: TypeInterface): AttributeValidationError[]; | ||
validateAndReturnRecordings(scopeType: TypeInterface): { | ||
@@ -26,4 +27,7 @@ type: string; | ||
valueOf(): string; | ||
evaluatePromise(scope: any, args?: any[]): Promise<string>; | ||
evaluate(scope: any): string; | ||
evaluatePromise(scope: FormatStringScope): Promise<string>; | ||
/** | ||
* If not all values are loaded yet, null is returned. | ||
*/ | ||
evaluate(scope: FormatStringScope): string; | ||
} |
@@ -12,1 +12,3 @@ export * from './token-expressions/ConstantTokenExpression'; | ||
export * from './ObjectRefInterface'; | ||
export * from './FormatStringScope'; | ||
export * from './VariableFormatStringScope'; |
@@ -5,2 +5,3 @@ /** | ||
import { TokenExpression } from './TokenExpression'; | ||
import { FormatStringScope } from '../FormatStringScope'; | ||
export declare class ConstantTokenExpression extends TokenExpression { | ||
@@ -17,2 +18,3 @@ constructor(expression: string, start?: number); | ||
valueOf(): string; | ||
tokenEvaluatePromise(scope: FormatStringScope): Promise<string>; | ||
} |
@@ -6,2 +6,3 @@ /** | ||
import { TokenExpression } from './TokenExpression'; | ||
import { FormatStringScope } from '../FormatStringScope'; | ||
export declare class FormatShorthandTokenExpression extends TokenExpression { | ||
@@ -12,2 +13,3 @@ inner: ShorthandTokenExpression; | ||
toString(): string; | ||
tokenEvaluatePromise(scope: FormatStringScope): Promise<string>; | ||
} |
@@ -6,2 +6,3 @@ /** | ||
import { ConstantTokenExpression } from './ConstantTokenExpression'; | ||
import { FormatStringScope } from '../FormatStringScope'; | ||
export declare class FunctionTokenExpression extends TokenExpression { | ||
@@ -13,2 +14,3 @@ /** | ||
constructor(expression: string, start?: number); | ||
stringify(): string; | ||
isFunction(): boolean; | ||
@@ -24,2 +26,3 @@ /** | ||
toConstant(includeEscapeTags?: boolean): ConstantTokenExpression; | ||
tokenEvaluatePromise(scope: FormatStringScope): Promise<string>; | ||
} |
@@ -6,2 +6,3 @@ /** | ||
import { ConstantTokenExpression } from './ConstantTokenExpression'; | ||
import { FormatStringScope } from '../FormatStringScope'; | ||
export declare class LegacyFunctionTokenExpression extends TokenExpression { | ||
@@ -15,2 +16,3 @@ constructor(expression: string, start?: number); | ||
toConstant(includeEscapeTags?: boolean): ConstantTokenExpression; | ||
tokenEvaluatePromise(scope: FormatStringScope): Promise<string>; | ||
} |
@@ -5,2 +5,3 @@ /** | ||
import { TokenExpression } from './TokenExpression'; | ||
import { FormatStringScope } from '../FormatStringScope'; | ||
export declare class PrimitiveConstantTokenExpression extends TokenExpression { | ||
@@ -17,2 +18,3 @@ constructor(expression: any, start?: number); | ||
valueOf(): any; | ||
tokenEvaluatePromise(scope: FormatStringScope): Promise<string>; | ||
} |
@@ -5,5 +5,7 @@ /** | ||
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. | ||
*/ | ||
export declare class TokenExpression { | ||
import { FormatStringScope } from '../FormatStringScope'; | ||
export declare abstract class TokenExpression { | ||
expression: string; | ||
@@ -9,3 +10,4 @@ start: number | undefined; | ||
isPrimitive: boolean; | ||
constructor(expression: string, start?: number); | ||
protected constructor(expression: string, start?: number); | ||
stringify(): string; | ||
toString(): string; | ||
@@ -18,2 +20,3 @@ isConstant(): boolean; | ||
isFunction(): boolean; | ||
abstract tokenEvaluatePromise(scope: FormatStringScope): Promise<string>; | ||
} |
@@ -5,4 +5,5 @@ import { TokenExpression } from './token-expressions/TokenExpression'; | ||
import { FormatShorthandTokenExpression } from './token-expressions/FormatShorthandTokenExpression'; | ||
import { FormatString } from './FormatString'; | ||
import { TypeInterface } from './TypeInterface'; | ||
import { LegacyFunctionTokenExpression } from './token-expressions/LegacyFunctionTokenExpression'; | ||
import { FormatString } from './FormatString'; | ||
export declare function unescape(s: string): string; | ||
@@ -36,2 +37,4 @@ 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,5 +5,7 @@ export interface TypeInterface { | ||
getVariableTypeAndNameWithParent(expression: string): any; | ||
getType(variable: any): any; | ||
getType(expression: string): TypeInterface | null; | ||
toJSON(): any; | ||
format(value: any, format?: string): string; | ||
options: object; | ||
stringify(): string; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FormatString = void 0; | ||
const tools_1 = require("./tools"); | ||
@@ -56,3 +57,3 @@ /** | ||
} | ||
var type = scopeType.getVariable(expression); | ||
var type = scopeType.getType(expression); | ||
if (type == null) { | ||
@@ -115,8 +116,64 @@ results.push({ | ||
} | ||
// Implemented elsewhere | ||
evaluatePromise(scope, args) { | ||
throw new Error('Not implemented'); | ||
evaluatePromise(scope) { | ||
const tokens = this.tokens; | ||
let promises = []; | ||
for (let i = 0; i < tokens.length; i++) { | ||
const token = tokens[i]; | ||
if (token.isConstant()) { | ||
// Constant tokens are skipped here (nothing to evaluate). | ||
} | ||
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; | ||
}); | ||
} | ||
/** | ||
* If not all values are loaded yet, null is returned. | ||
*/ | ||
evaluate(scope) { | ||
throw new Error('Not implemented'); | ||
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; | ||
} | ||
@@ -123,0 +180,0 @@ } |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./token-expressions/ConstantTokenExpression")); | ||
__export(require("./token-expressions/FormatShorthandTokenExpression")); | ||
__export(require("./token-expressions/FunctionTokenExpression")); | ||
__export(require("./token-expressions/LegacyFunctionTokenExpression")); | ||
__export(require("./token-expressions/PrimitiveConstantTokenExpression")); | ||
__export(require("./token-expressions/ShorthandTokenExpression")); | ||
__export(require("./token-expressions/TokenExpression")); | ||
__export(require("./FormatString")); | ||
__export(require("./tools")); | ||
__exportStar(require("./token-expressions/ConstantTokenExpression"), exports); | ||
__exportStar(require("./token-expressions/FormatShorthandTokenExpression"), exports); | ||
__exportStar(require("./token-expressions/FunctionTokenExpression"), exports); | ||
__exportStar(require("./token-expressions/LegacyFunctionTokenExpression"), exports); | ||
__exportStar(require("./token-expressions/PrimitiveConstantTokenExpression"), exports); | ||
__exportStar(require("./token-expressions/ShorthandTokenExpression"), exports); | ||
__exportStar(require("./token-expressions/TokenExpression"), exports); | ||
__exportStar(require("./FormatString"), exports); | ||
__exportStar(require("./tools"), exports); | ||
__exportStar(require("./TypeInterface"), exports); | ||
__exportStar(require("./ObjectRefInterface"), exports); | ||
__exportStar(require("./FormatStringScope"), exports); | ||
__exportStar(require("./VariableFormatStringScope"), exports); | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ConstantTokenExpression = void 0; | ||
/** | ||
@@ -27,4 +28,7 @@ * Constant token expression. | ||
} | ||
async tokenEvaluatePromise(scope) { | ||
return this.expression; | ||
} | ||
} | ||
exports.ConstantTokenExpression = ConstantTokenExpression; | ||
//# sourceMappingURL=ConstantTokenExpression.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FormatShorthandTokenExpression = void 0; | ||
/** | ||
@@ -8,2 +9,3 @@ * Shorthand token expression with format specifier. | ||
const TokenExpression_1 = require("./TokenExpression"); | ||
const tools_1 = require("../tools"); | ||
class FormatShorthandTokenExpression extends TokenExpression_1.TokenExpression { | ||
@@ -20,14 +22,15 @@ constructor(expression, format, start) { | ||
toString() { | ||
return ('[object ' + | ||
this.constructor.name + | ||
' <' + | ||
this.expression + | ||
', ' + | ||
this.start + | ||
', ' + | ||
this.format + | ||
'>]'); | ||
return '[object ' + this.constructor.name + ' <' + this.expression + ', ' + this.start + ', ' + this.format + '>]'; | ||
} | ||
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 |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FunctionTokenExpression = void 0; | ||
/** | ||
@@ -11,4 +12,4 @@ * JavaScript function token expression. | ||
// remove indicator prefix from expression | ||
var prefix = FunctionTokenExpression.PREFIX; | ||
var processedExpression = expression.trim(); | ||
const prefix = FunctionTokenExpression.PREFIX; | ||
let processedExpression = expression.trim(); | ||
if (processedExpression.indexOf(prefix) === 0) { | ||
@@ -19,2 +20,5 @@ processedExpression = processedExpression.substr(prefix.length); | ||
} | ||
stringify() { | ||
return `${FunctionTokenExpression.PREFIX}${this.expression}`; | ||
} | ||
isFunction() { | ||
@@ -34,7 +38,6 @@ return true; | ||
toConstant(includeEscapeTags) { | ||
if (typeof includeEscapeTags === 'undefined' || | ||
includeEscapeTags === null) { | ||
if (typeof includeEscapeTags === 'undefined' || includeEscapeTags === null) { | ||
includeEscapeTags = false; | ||
} | ||
var constantExpression = FunctionTokenExpression.PREFIX + this.expression; | ||
let constantExpression = FunctionTokenExpression.PREFIX + this.expression; | ||
if (includeEscapeTags) { | ||
@@ -45,3 +48,11 @@ 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; | ||
} | ||
} | ||
exports.FunctionTokenExpression = FunctionTokenExpression; | ||
/** | ||
@@ -51,3 +62,2 @@ * Prefix for function token expressions. | ||
FunctionTokenExpression.PREFIX = '$:'; | ||
exports.FunctionTokenExpression = FunctionTokenExpression; | ||
//# sourceMappingURL=FunctionTokenExpression.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LegacyFunctionTokenExpression = void 0; | ||
/** | ||
@@ -29,4 +30,7 @@ * Legacy function token expression. | ||
} | ||
tokenEvaluatePromise(scope) { | ||
throw new Error('not implemented'); | ||
} | ||
} | ||
exports.LegacyFunctionTokenExpression = LegacyFunctionTokenExpression; | ||
//# sourceMappingURL=LegacyFunctionTokenExpression.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PrimitiveConstantTokenExpression = void 0; | ||
/** | ||
@@ -28,4 +29,7 @@ * Non-String Constant token expression | ||
} | ||
async tokenEvaluatePromise(scope) { | ||
return this.expression; | ||
} | ||
} | ||
exports.PrimitiveConstantTokenExpression = PrimitiveConstantTokenExpression; | ||
//# sourceMappingURL=PrimitiveConstantTokenExpression.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ShorthandTokenExpression = void 0; | ||
/** | ||
@@ -7,2 +8,3 @@ * Shorthand token expression. | ||
const TokenExpression_1 = require("./TokenExpression"); | ||
const tools_1 = require("../tools"); | ||
class ShorthandTokenExpression extends TokenExpression_1.TokenExpression { | ||
@@ -15,4 +17,13 @@ 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. | ||
*/ | ||
exports.TokenExpression = void 0; | ||
class TokenExpression { | ||
@@ -16,10 +14,7 @@ constructor(expression, start) { | ||
} | ||
stringify() { | ||
return this.expression; | ||
} | ||
toString() { | ||
return ('[object ' + | ||
this.constructor.name + | ||
' <' + | ||
this.expression + | ||
', ' + | ||
this.start + | ||
'>]'); | ||
return '[object ' + this.constructor.name + ' <' + this.expression + ', ' + this.start + '>]'; | ||
} | ||
@@ -26,0 +21,0 @@ isConstant() { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports._deepMerge = exports._compile = exports.formatValueAsync = exports.formatValue = exports.actionableTokenExpression = exports.functionTokenExpression = exports.formatString = exports.extract = exports.deepMerge = exports.getObjectType = exports.compile = exports.parseEnclosingBraces = exports.unescape = void 0; | ||
const ConstantTokenExpression_1 = require("./token-expressions/ConstantTokenExpression"); | ||
@@ -7,4 +8,4 @@ const FunctionTokenExpression_1 = require("./token-expressions/FunctionTokenExpression"); | ||
const FormatShorthandTokenExpression_1 = require("./token-expressions/FormatShorthandTokenExpression"); | ||
const FormatString_1 = require("./FormatString"); | ||
const LegacyFunctionTokenExpression_1 = require("./token-expressions/LegacyFunctionTokenExpression"); | ||
const FormatString_1 = require("./FormatString"); | ||
function unescape(s) { | ||
@@ -262,2 +263,28 @@ 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.5adc6f7.38d3f91", | ||
"version": "0.0.0-dev.5c49be1.abbc3a7", | ||
"description": "Journey JS library", | ||
@@ -14,3 +14,3 @@ "main": "./dist/src/index.js", | ||
"dependencies": { | ||
"@journeyapps/core-xml": "0.0.0-dev.5adc6f7.38d3f91" | ||
"@journeyapps/core-xml": "0.0.0-dev.5c49be1.abbc3a7" | ||
}, | ||
@@ -21,3 +21,3 @@ "files": [ | ||
], | ||
"gitHead": "89596237034c7cae95a7715744a36f1d10505629" | ||
"gitHead": "2e1d25da8228965fd83f775e8adc3305573d39c8" | ||
} |
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
92761
46
1147
+ Added@journeyapps/core-xml@0.0.0-dev.5c49be1.abbc3a7(transitive)
- Removed@journeyapps/core-xml@0.0.0-dev.5adc6f7.38d3f91(transitive)